1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
16 #include <netinet/in.h>
18 #include <rte_byteorder.h>
20 #include <rte_debug.h>
21 #include <rte_interrupts.h>
22 #include <rte_memory.h>
23 #include <rte_memcpy.h>
24 #include <rte_memzone.h>
25 #include <rte_launch.h>
27 #include <rte_per_lcore.h>
28 #include <rte_lcore.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>
37 #include <rte_kvargs.h>
38 #include <rte_class.h>
39 #include <rte_ether.h>
40 #include <rte_telemetry.h>
42 #include "rte_ethdev_trace.h"
43 #include "rte_ethdev.h"
44 #include "rte_ethdev_driver.h"
45 #include "ethdev_profile.h"
46 #include "ethdev_private.h"
48 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
49 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
51 /* spinlock for eth device callbacks */
52 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
54 /* spinlock for add/remove rx callbacks */
55 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
57 /* spinlock for add/remove tx callbacks */
58 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
60 /* spinlock for shared data allocation */
61 static rte_spinlock_t rte_eth_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
63 /* store statistics names and its offset in stats structure */
64 struct rte_eth_xstats_name_off {
65 char name[RTE_ETH_XSTATS_NAME_SIZE];
69 /* Shared memory between primary and secondary processes. */
71 uint64_t next_owner_id;
72 rte_spinlock_t ownership_lock;
73 struct rte_eth_dev_data data[RTE_MAX_ETHPORTS];
74 } *rte_eth_dev_shared_data;
76 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
77 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
78 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
79 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
80 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
81 {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
82 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
83 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
84 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
88 #define RTE_NB_STATS RTE_DIM(rte_stats_strings)
90 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
91 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
92 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
93 {"errors", offsetof(struct rte_eth_stats, q_errors)},
96 #define RTE_NB_RXQ_STATS RTE_DIM(rte_rxq_stats_strings)
98 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
99 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
100 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
102 #define RTE_NB_TXQ_STATS RTE_DIM(rte_txq_stats_strings)
104 #define RTE_RX_OFFLOAD_BIT2STR(_name) \
105 { DEV_RX_OFFLOAD_##_name, #_name }
107 static const struct {
110 } rte_rx_offload_names[] = {
111 RTE_RX_OFFLOAD_BIT2STR(VLAN_STRIP),
112 RTE_RX_OFFLOAD_BIT2STR(IPV4_CKSUM),
113 RTE_RX_OFFLOAD_BIT2STR(UDP_CKSUM),
114 RTE_RX_OFFLOAD_BIT2STR(TCP_CKSUM),
115 RTE_RX_OFFLOAD_BIT2STR(TCP_LRO),
116 RTE_RX_OFFLOAD_BIT2STR(QINQ_STRIP),
117 RTE_RX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
118 RTE_RX_OFFLOAD_BIT2STR(MACSEC_STRIP),
119 RTE_RX_OFFLOAD_BIT2STR(HEADER_SPLIT),
120 RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
121 RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
122 RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
123 RTE_RX_OFFLOAD_BIT2STR(SCATTER),
124 RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
125 RTE_RX_OFFLOAD_BIT2STR(SECURITY),
126 RTE_RX_OFFLOAD_BIT2STR(KEEP_CRC),
127 RTE_RX_OFFLOAD_BIT2STR(SCTP_CKSUM),
128 RTE_RX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
129 RTE_RX_OFFLOAD_BIT2STR(RSS_HASH),
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),
159 RTE_TX_OFFLOAD_BIT2STR(UDP_TNL_TSO),
160 RTE_TX_OFFLOAD_BIT2STR(IP_TNL_TSO),
161 RTE_TX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
162 RTE_TX_OFFLOAD_BIT2STR(SEND_ON_TIMESTAMP),
165 #undef RTE_TX_OFFLOAD_BIT2STR
168 * The user application callback description.
170 * It contains callback address to be registered by user application,
171 * the pointer to the parameters for callback, and the event type.
173 struct rte_eth_dev_callback {
174 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
175 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
176 void *cb_arg; /**< Parameter for callback */
177 void *ret_param; /**< Return parameter */
178 enum rte_eth_event_type event; /**< Interrupt event type */
179 uint32_t active; /**< Callback is executing */
188 rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
191 struct rte_devargs devargs = {.args = NULL};
192 const char *bus_param_key;
193 char *bus_str = NULL;
194 char *cls_str = NULL;
197 memset(iter, 0, sizeof(*iter));
200 * The devargs string may use various syntaxes:
201 * - 0000:08:00.0,representor=[1-3]
202 * - pci:0000:06:00.0,representor=[0,5]
203 * - class=eth,mac=00:11:22:33:44:55
204 * A new syntax is in development (not yet supported):
205 * - bus=X,paramX=x/class=Y,paramY=y/driver=Z,paramZ=z
209 * Handle pure class filter (i.e. without any bus-level argument),
210 * from future new syntax.
211 * rte_devargs_parse() is not yet supporting the new syntax,
212 * that's why this simple case is temporarily parsed here.
214 #define iter_anybus_str "class=eth,"
215 if (strncmp(devargs_str, iter_anybus_str,
216 strlen(iter_anybus_str)) == 0) {
217 iter->cls_str = devargs_str + strlen(iter_anybus_str);
221 /* Split bus, device and parameters. */
222 ret = rte_devargs_parse(&devargs, devargs_str);
227 * Assume parameters of old syntax can match only at ethdev level.
228 * Extra parameters will be ignored, thanks to "+" prefix.
230 str_size = strlen(devargs.args) + 2;
231 cls_str = malloc(str_size);
232 if (cls_str == NULL) {
236 ret = snprintf(cls_str, str_size, "+%s", devargs.args);
237 if (ret != str_size - 1) {
241 iter->cls_str = cls_str;
242 free(devargs.args); /* allocated by rte_devargs_parse() */
245 iter->bus = devargs.bus;
246 if (iter->bus->dev_iterate == NULL) {
251 /* Convert bus args to new syntax for use with new API dev_iterate. */
252 if (strcmp(iter->bus->name, "vdev") == 0) {
253 bus_param_key = "name";
254 } else if (strcmp(iter->bus->name, "pci") == 0) {
255 bus_param_key = "addr";
260 str_size = strlen(bus_param_key) + strlen(devargs.name) + 2;
261 bus_str = malloc(str_size);
262 if (bus_str == NULL) {
266 ret = snprintf(bus_str, str_size, "%s=%s",
267 bus_param_key, devargs.name);
268 if (ret != str_size - 1) {
272 iter->bus_str = bus_str;
275 iter->cls = rte_class_find_by_name("eth");
280 RTE_ETHDEV_LOG(ERR, "Bus %s does not support iterating.\n",
289 rte_eth_iterator_next(struct rte_dev_iterator *iter)
291 if (iter->cls == NULL) /* invalid ethdev iterator */
292 return RTE_MAX_ETHPORTS;
294 do { /* loop to try all matching rte_device */
295 /* If not pure ethdev filter and */
296 if (iter->bus != NULL &&
297 /* not in middle of rte_eth_dev iteration, */
298 iter->class_device == NULL) {
299 /* get next rte_device to try. */
300 iter->device = iter->bus->dev_iterate(
301 iter->device, iter->bus_str, iter);
302 if (iter->device == NULL)
303 break; /* no more rte_device candidate */
305 /* A device is matching bus part, need to check ethdev part. */
306 iter->class_device = iter->cls->dev_iterate(
307 iter->class_device, iter->cls_str, iter);
308 if (iter->class_device != NULL)
309 return eth_dev_to_id(iter->class_device); /* match */
310 } while (iter->bus != NULL); /* need to try next rte_device */
312 /* No more ethdev port to iterate. */
313 rte_eth_iterator_cleanup(iter);
314 return RTE_MAX_ETHPORTS;
318 rte_eth_iterator_cleanup(struct rte_dev_iterator *iter)
320 if (iter->bus_str == NULL)
321 return; /* nothing to free in pure class filter */
322 free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */
323 free(RTE_CAST_FIELD(iter, cls_str, char *)); /* workaround const */
324 memset(iter, 0, sizeof(*iter));
328 rte_eth_find_next(uint16_t port_id)
330 while (port_id < RTE_MAX_ETHPORTS &&
331 rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)
334 if (port_id >= RTE_MAX_ETHPORTS)
335 return RTE_MAX_ETHPORTS;
341 * Macro to iterate over all valid ports for internal usage.
342 * Note: RTE_ETH_FOREACH_DEV is different because filtering owned ports.
344 #define RTE_ETH_FOREACH_VALID_DEV(port_id) \
345 for (port_id = rte_eth_find_next(0); \
346 port_id < RTE_MAX_ETHPORTS; \
347 port_id = rte_eth_find_next(port_id + 1))
350 rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
352 port_id = rte_eth_find_next(port_id);
353 while (port_id < RTE_MAX_ETHPORTS &&
354 rte_eth_devices[port_id].device != parent)
355 port_id = rte_eth_find_next(port_id + 1);
361 rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id)
363 RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS);
364 return rte_eth_find_next_of(port_id,
365 rte_eth_devices[ref_port_id].device);
369 rte_eth_dev_shared_data_prepare(void)
371 const unsigned flags = 0;
372 const struct rte_memzone *mz;
374 rte_spinlock_lock(&rte_eth_shared_data_lock);
376 if (rte_eth_dev_shared_data == NULL) {
377 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
378 /* Allocate port data and ownership shared memory. */
379 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
380 sizeof(*rte_eth_dev_shared_data),
381 rte_socket_id(), flags);
383 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
385 rte_panic("Cannot allocate ethdev shared data\n");
387 rte_eth_dev_shared_data = mz->addr;
388 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
389 rte_eth_dev_shared_data->next_owner_id =
390 RTE_ETH_DEV_NO_OWNER + 1;
391 rte_spinlock_init(&rte_eth_dev_shared_data->ownership_lock);
392 memset(rte_eth_dev_shared_data->data, 0,
393 sizeof(rte_eth_dev_shared_data->data));
397 rte_spinlock_unlock(&rte_eth_shared_data_lock);
401 is_allocated(const struct rte_eth_dev *ethdev)
403 return ethdev->data->name[0] != '\0';
406 static struct rte_eth_dev *
407 _rte_eth_dev_allocated(const char *name)
411 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
412 if (rte_eth_devices[i].data != NULL &&
413 strcmp(rte_eth_devices[i].data->name, name) == 0)
414 return &rte_eth_devices[i];
420 rte_eth_dev_allocated(const char *name)
422 struct rte_eth_dev *ethdev;
424 rte_eth_dev_shared_data_prepare();
426 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
428 ethdev = _rte_eth_dev_allocated(name);
430 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
436 rte_eth_dev_find_free_port(void)
440 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
441 /* Using shared name field to find a free port. */
442 if (rte_eth_dev_shared_data->data[i].name[0] == '\0') {
443 RTE_ASSERT(rte_eth_devices[i].state ==
448 return RTE_MAX_ETHPORTS;
451 static struct rte_eth_dev *
452 eth_dev_get(uint16_t port_id)
454 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
456 eth_dev->data = &rte_eth_dev_shared_data->data[port_id];
462 rte_eth_dev_allocate(const char *name)
465 struct rte_eth_dev *eth_dev = NULL;
468 name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN);
470 RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n");
474 if (name_len >= RTE_ETH_NAME_MAX_LEN) {
475 RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n");
479 rte_eth_dev_shared_data_prepare();
481 /* Synchronize port creation between primary and secondary threads. */
482 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
484 if (_rte_eth_dev_allocated(name) != NULL) {
486 "Ethernet device with name %s already allocated\n",
491 port_id = rte_eth_dev_find_free_port();
492 if (port_id == RTE_MAX_ETHPORTS) {
494 "Reached maximum number of Ethernet ports\n");
498 eth_dev = eth_dev_get(port_id);
499 strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
500 eth_dev->data->port_id = port_id;
501 eth_dev->data->mtu = RTE_ETHER_MTU;
502 pthread_mutex_init(ð_dev->data->flow_ops_mutex, NULL);
505 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
511 * Attach to a port already registered by the primary process, which
512 * makes sure that the same device would have the same port id both
513 * in the primary and secondary process.
516 rte_eth_dev_attach_secondary(const char *name)
519 struct rte_eth_dev *eth_dev = NULL;
521 rte_eth_dev_shared_data_prepare();
523 /* Synchronize port attachment to primary port creation and release. */
524 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
526 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
527 if (strcmp(rte_eth_dev_shared_data->data[i].name, name) == 0)
530 if (i == RTE_MAX_ETHPORTS) {
532 "Device %s is not driven by the primary process\n",
535 eth_dev = eth_dev_get(i);
536 RTE_ASSERT(eth_dev->data->port_id == i);
539 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
544 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
549 rte_eth_dev_shared_data_prepare();
551 if (eth_dev->state != RTE_ETH_DEV_UNUSED)
552 rte_eth_dev_callback_process(eth_dev,
553 RTE_ETH_EVENT_DESTROY, NULL);
555 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
557 eth_dev->state = RTE_ETH_DEV_UNUSED;
558 eth_dev->device = NULL;
559 eth_dev->intr_handle = NULL;
561 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
562 rte_free(eth_dev->data->rx_queues);
563 rte_free(eth_dev->data->tx_queues);
564 rte_free(eth_dev->data->mac_addrs);
565 rte_free(eth_dev->data->hash_mac_addrs);
566 rte_free(eth_dev->data->dev_private);
567 pthread_mutex_destroy(ð_dev->data->flow_ops_mutex);
568 memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
571 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
577 rte_eth_dev_is_valid_port(uint16_t port_id)
579 if (port_id >= RTE_MAX_ETHPORTS ||
580 (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED))
587 rte_eth_is_valid_owner_id(uint64_t owner_id)
589 if (owner_id == RTE_ETH_DEV_NO_OWNER ||
590 rte_eth_dev_shared_data->next_owner_id <= owner_id)
596 rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
598 port_id = rte_eth_find_next(port_id);
599 while (port_id < RTE_MAX_ETHPORTS &&
600 rte_eth_devices[port_id].data->owner.id != owner_id)
601 port_id = rte_eth_find_next(port_id + 1);
607 rte_eth_dev_owner_new(uint64_t *owner_id)
609 rte_eth_dev_shared_data_prepare();
611 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
613 *owner_id = rte_eth_dev_shared_data->next_owner_id++;
615 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
620 _rte_eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id,
621 const struct rte_eth_dev_owner *new_owner)
623 struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
624 struct rte_eth_dev_owner *port_owner;
626 if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) {
627 RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
632 if (!rte_eth_is_valid_owner_id(new_owner->id) &&
633 !rte_eth_is_valid_owner_id(old_owner_id)) {
635 "Invalid owner old_id=%016"PRIx64" new_id=%016"PRIx64"\n",
636 old_owner_id, new_owner->id);
640 port_owner = &rte_eth_devices[port_id].data->owner;
641 if (port_owner->id != old_owner_id) {
643 "Cannot set owner to port %u already owned by %s_%016"PRIX64"\n",
644 port_id, port_owner->name, port_owner->id);
648 /* can not truncate (same structure) */
649 strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN);
651 port_owner->id = new_owner->id;
653 RTE_ETHDEV_LOG(DEBUG, "Port %u owner is %s_%016"PRIx64"\n",
654 port_id, new_owner->name, new_owner->id);
660 rte_eth_dev_owner_set(const uint16_t port_id,
661 const struct rte_eth_dev_owner *owner)
665 rte_eth_dev_shared_data_prepare();
667 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
669 ret = _rte_eth_dev_owner_set(port_id, RTE_ETH_DEV_NO_OWNER, owner);
671 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
676 rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id)
678 const struct rte_eth_dev_owner new_owner = (struct rte_eth_dev_owner)
679 {.id = RTE_ETH_DEV_NO_OWNER, .name = ""};
682 rte_eth_dev_shared_data_prepare();
684 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
686 ret = _rte_eth_dev_owner_set(port_id, owner_id, &new_owner);
688 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
693 rte_eth_dev_owner_delete(const uint64_t owner_id)
698 rte_eth_dev_shared_data_prepare();
700 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
702 if (rte_eth_is_valid_owner_id(owner_id)) {
703 for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++)
704 if (rte_eth_devices[port_id].data->owner.id == owner_id)
705 memset(&rte_eth_devices[port_id].data->owner, 0,
706 sizeof(struct rte_eth_dev_owner));
707 RTE_ETHDEV_LOG(NOTICE,
708 "All port owners owned by %016"PRIx64" identifier have removed\n",
712 "Invalid owner id=%016"PRIx64"\n",
717 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
723 rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
726 struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
728 rte_eth_dev_shared_data_prepare();
730 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
732 if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) {
733 RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
737 rte_memcpy(owner, ðdev->data->owner, sizeof(*owner));
740 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
745 rte_eth_dev_socket_id(uint16_t port_id)
747 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
748 return rte_eth_devices[port_id].data->numa_node;
752 rte_eth_dev_get_sec_ctx(uint16_t port_id)
754 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
755 return rte_eth_devices[port_id].security_ctx;
759 rte_eth_dev_count_avail(void)
766 RTE_ETH_FOREACH_DEV(p)
773 rte_eth_dev_count_total(void)
775 uint16_t port, count = 0;
777 RTE_ETH_FOREACH_VALID_DEV(port)
784 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
788 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
791 RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
795 /* shouldn't check 'rte_eth_devices[i].data',
796 * because it might be overwritten by VDEV PMD */
797 tmp = rte_eth_dev_shared_data->data[port_id].name;
803 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
808 RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
812 RTE_ETH_FOREACH_VALID_DEV(pid)
813 if (!strcmp(name, rte_eth_dev_shared_data->data[pid].name)) {
822 eth_err(uint16_t port_id, int ret)
826 if (rte_eth_dev_is_removed(port_id))
832 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
834 uint16_t old_nb_queues = dev->data->nb_rx_queues;
838 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
839 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
840 sizeof(dev->data->rx_queues[0]) * nb_queues,
841 RTE_CACHE_LINE_SIZE);
842 if (dev->data->rx_queues == NULL) {
843 dev->data->nb_rx_queues = 0;
846 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
847 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
849 rxq = dev->data->rx_queues;
851 for (i = nb_queues; i < old_nb_queues; i++)
852 (*dev->dev_ops->rx_queue_release)(rxq[i]);
853 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
854 RTE_CACHE_LINE_SIZE);
857 if (nb_queues > old_nb_queues) {
858 uint16_t new_qs = nb_queues - old_nb_queues;
860 memset(rxq + old_nb_queues, 0,
861 sizeof(rxq[0]) * new_qs);
864 dev->data->rx_queues = rxq;
866 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
867 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
869 rxq = dev->data->rx_queues;
871 for (i = nb_queues; i < old_nb_queues; i++)
872 (*dev->dev_ops->rx_queue_release)(rxq[i]);
874 rte_free(dev->data->rx_queues);
875 dev->data->rx_queues = NULL;
877 dev->data->nb_rx_queues = nb_queues;
882 eth_dev_validate_rx_queue(const struct rte_eth_dev *dev, uint16_t rx_queue_id)
886 if (rx_queue_id >= dev->data->nb_rx_queues) {
887 port_id = dev->data->port_id;
889 "Invalid Rx queue_id=%u of device with port_id=%u\n",
890 rx_queue_id, port_id);
894 if (dev->data->rx_queues[rx_queue_id] == NULL) {
895 port_id = dev->data->port_id;
897 "Queue %u of device with port_id=%u has not been setup\n",
898 rx_queue_id, port_id);
906 eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id)
910 if (tx_queue_id >= dev->data->nb_tx_queues) {
911 port_id = dev->data->port_id;
913 "Invalid Tx queue_id=%u of device with port_id=%u\n",
914 tx_queue_id, port_id);
918 if (dev->data->tx_queues[tx_queue_id] == NULL) {
919 port_id = dev->data->port_id;
921 "Queue %u of device with port_id=%u has not been setup\n",
922 tx_queue_id, port_id);
930 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
932 struct rte_eth_dev *dev;
935 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
937 dev = &rte_eth_devices[port_id];
938 if (!dev->data->dev_started) {
940 "Port %u must be started before start any queue\n",
945 ret = eth_dev_validate_rx_queue(dev, rx_queue_id);
949 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
951 if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) {
953 "Can't start Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n",
954 rx_queue_id, port_id);
958 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
960 "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n",
961 rx_queue_id, port_id);
965 return eth_err(port_id, dev->dev_ops->rx_queue_start(dev,
971 rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
973 struct rte_eth_dev *dev;
976 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
978 dev = &rte_eth_devices[port_id];
980 ret = eth_dev_validate_rx_queue(dev, rx_queue_id);
984 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
986 if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) {
988 "Can't stop Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n",
989 rx_queue_id, port_id);
993 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
995 "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n",
996 rx_queue_id, port_id);
1000 return eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id));
1005 rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
1007 struct rte_eth_dev *dev;
1010 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1012 dev = &rte_eth_devices[port_id];
1013 if (!dev->data->dev_started) {
1015 "Port %u must be started before start any queue\n",
1020 ret = eth_dev_validate_tx_queue(dev, tx_queue_id);
1024 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
1026 if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) {
1027 RTE_ETHDEV_LOG(INFO,
1028 "Can't start Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n",
1029 tx_queue_id, port_id);
1033 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
1034 RTE_ETHDEV_LOG(INFO,
1035 "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n",
1036 tx_queue_id, port_id);
1040 return eth_err(port_id, dev->dev_ops->tx_queue_start(dev, tx_queue_id));
1044 rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
1046 struct rte_eth_dev *dev;
1049 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1051 dev = &rte_eth_devices[port_id];
1053 ret = eth_dev_validate_tx_queue(dev, tx_queue_id);
1057 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
1059 if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) {
1060 RTE_ETHDEV_LOG(INFO,
1061 "Can't stop Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n",
1062 tx_queue_id, port_id);
1066 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
1067 RTE_ETHDEV_LOG(INFO,
1068 "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n",
1069 tx_queue_id, port_id);
1073 return eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id));
1078 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
1080 uint16_t old_nb_queues = dev->data->nb_tx_queues;
1084 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
1085 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
1086 sizeof(dev->data->tx_queues[0]) * nb_queues,
1087 RTE_CACHE_LINE_SIZE);
1088 if (dev->data->tx_queues == NULL) {
1089 dev->data->nb_tx_queues = 0;
1092 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
1093 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
1095 txq = dev->data->tx_queues;
1097 for (i = nb_queues; i < old_nb_queues; i++)
1098 (*dev->dev_ops->tx_queue_release)(txq[i]);
1099 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
1100 RTE_CACHE_LINE_SIZE);
1103 if (nb_queues > old_nb_queues) {
1104 uint16_t new_qs = nb_queues - old_nb_queues;
1106 memset(txq + old_nb_queues, 0,
1107 sizeof(txq[0]) * new_qs);
1110 dev->data->tx_queues = txq;
1112 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
1113 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
1115 txq = dev->data->tx_queues;
1117 for (i = nb_queues; i < old_nb_queues; i++)
1118 (*dev->dev_ops->tx_queue_release)(txq[i]);
1120 rte_free(dev->data->tx_queues);
1121 dev->data->tx_queues = NULL;
1123 dev->data->nb_tx_queues = nb_queues;
1128 rte_eth_speed_bitflag(uint32_t speed, int duplex)
1131 case ETH_SPEED_NUM_10M:
1132 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
1133 case ETH_SPEED_NUM_100M:
1134 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
1135 case ETH_SPEED_NUM_1G:
1136 return ETH_LINK_SPEED_1G;
1137 case ETH_SPEED_NUM_2_5G:
1138 return ETH_LINK_SPEED_2_5G;
1139 case ETH_SPEED_NUM_5G:
1140 return ETH_LINK_SPEED_5G;
1141 case ETH_SPEED_NUM_10G:
1142 return ETH_LINK_SPEED_10G;
1143 case ETH_SPEED_NUM_20G:
1144 return ETH_LINK_SPEED_20G;
1145 case ETH_SPEED_NUM_25G:
1146 return ETH_LINK_SPEED_25G;
1147 case ETH_SPEED_NUM_40G:
1148 return ETH_LINK_SPEED_40G;
1149 case ETH_SPEED_NUM_50G:
1150 return ETH_LINK_SPEED_50G;
1151 case ETH_SPEED_NUM_56G:
1152 return ETH_LINK_SPEED_56G;
1153 case ETH_SPEED_NUM_100G:
1154 return ETH_LINK_SPEED_100G;
1155 case ETH_SPEED_NUM_200G:
1156 return ETH_LINK_SPEED_200G;
1163 rte_eth_dev_rx_offload_name(uint64_t offload)
1165 const char *name = "UNKNOWN";
1168 for (i = 0; i < RTE_DIM(rte_rx_offload_names); ++i) {
1169 if (offload == rte_rx_offload_names[i].offload) {
1170 name = rte_rx_offload_names[i].name;
1179 rte_eth_dev_tx_offload_name(uint64_t offload)
1181 const char *name = "UNKNOWN";
1184 for (i = 0; i < RTE_DIM(rte_tx_offload_names); ++i) {
1185 if (offload == rte_tx_offload_names[i].offload) {
1186 name = rte_tx_offload_names[i].name;
1195 check_lro_pkt_size(uint16_t port_id, uint32_t config_size,
1196 uint32_t max_rx_pkt_len, uint32_t dev_info_size)
1200 if (dev_info_size == 0) {
1201 if (config_size != max_rx_pkt_len) {
1202 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size"
1203 " %u != %u is not allowed\n",
1204 port_id, config_size, max_rx_pkt_len);
1207 } else if (config_size > dev_info_size) {
1208 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size %u "
1209 "> max allowed value %u\n", port_id, config_size,
1212 } else if (config_size < RTE_ETHER_MIN_LEN) {
1213 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size %u "
1214 "< min allowed value %u\n", port_id, config_size,
1215 (unsigned int)RTE_ETHER_MIN_LEN);
1222 * Validate offloads that are requested through rte_eth_dev_configure against
1223 * the offloads successfully set by the ethernet device.
1226 * The port identifier of the Ethernet device.
1227 * @param req_offloads
1228 * The offloads that have been requested through `rte_eth_dev_configure`.
1229 * @param set_offloads
1230 * The offloads successfully set by the ethernet device.
1231 * @param offload_type
1232 * The offload type i.e. Rx/Tx string.
1233 * @param offload_name
1234 * The function that prints the offload name.
1236 * - (0) if validation successful.
1237 * - (-EINVAL) if requested offload has been silently disabled.
1241 validate_offloads(uint16_t port_id, uint64_t req_offloads,
1242 uint64_t set_offloads, const char *offload_type,
1243 const char *(*offload_name)(uint64_t))
1245 uint64_t offloads_diff = req_offloads ^ set_offloads;
1249 while (offloads_diff != 0) {
1250 /* Check if any offload is requested but not enabled. */
1251 offload = 1ULL << __builtin_ctzll(offloads_diff);
1252 if (offload & req_offloads) {
1254 "Port %u failed to enable %s offload %s\n",
1255 port_id, offload_type, offload_name(offload));
1259 /* Check if offload couldn't be disabled. */
1260 if (offload & set_offloads) {
1261 RTE_ETHDEV_LOG(DEBUG,
1262 "Port %u %s offload %s is not requested but enabled\n",
1263 port_id, offload_type, offload_name(offload));
1266 offloads_diff &= ~offload;
1273 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1274 const struct rte_eth_conf *dev_conf)
1276 struct rte_eth_dev *dev;
1277 struct rte_eth_dev_info dev_info;
1278 struct rte_eth_conf orig_conf;
1282 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1284 dev = &rte_eth_devices[port_id];
1286 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1288 if (dev->data->dev_started) {
1290 "Port %u must be stopped to allow configuration\n",
1295 /* Store original config, as rollback required on failure */
1296 memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf));
1299 * Copy the dev_conf parameter into the dev structure.
1300 * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get
1302 if (dev_conf != &dev->data->dev_conf)
1303 memcpy(&dev->data->dev_conf, dev_conf,
1304 sizeof(dev->data->dev_conf));
1306 ret = rte_eth_dev_info_get(port_id, &dev_info);
1310 /* If number of queues specified by application for both Rx and Tx is
1311 * zero, use driver preferred values. This cannot be done individually
1312 * as it is valid for either Tx or Rx (but not both) to be zero.
1313 * If driver does not provide any preferred valued, fall back on
1316 if (nb_rx_q == 0 && nb_tx_q == 0) {
1317 nb_rx_q = dev_info.default_rxportconf.nb_queues;
1319 nb_rx_q = RTE_ETH_DEV_FALLBACK_RX_NBQUEUES;
1320 nb_tx_q = dev_info.default_txportconf.nb_queues;
1322 nb_tx_q = RTE_ETH_DEV_FALLBACK_TX_NBQUEUES;
1325 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1327 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
1328 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1333 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1335 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
1336 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1342 * Check that the numbers of RX and TX queues are not greater
1343 * than the maximum number of RX and TX queues supported by the
1344 * configured device.
1346 if (nb_rx_q > dev_info.max_rx_queues) {
1347 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_rx_queues=%u > %u\n",
1348 port_id, nb_rx_q, dev_info.max_rx_queues);
1353 if (nb_tx_q > dev_info.max_tx_queues) {
1354 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_tx_queues=%u > %u\n",
1355 port_id, nb_tx_q, dev_info.max_tx_queues);
1360 /* Check that the device supports requested interrupts */
1361 if ((dev_conf->intr_conf.lsc == 1) &&
1362 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
1363 RTE_ETHDEV_LOG(ERR, "Driver %s does not support lsc\n",
1364 dev->device->driver->name);
1368 if ((dev_conf->intr_conf.rmv == 1) &&
1369 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
1370 RTE_ETHDEV_LOG(ERR, "Driver %s does not support rmv\n",
1371 dev->device->driver->name);
1377 * If jumbo frames are enabled, check that the maximum RX packet
1378 * length is supported by the configured device.
1380 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1381 if (dev_conf->rxmode.max_rx_pkt_len > dev_info.max_rx_pktlen) {
1383 "Ethdev port_id=%u max_rx_pkt_len %u > max valid value %u\n",
1384 port_id, dev_conf->rxmode.max_rx_pkt_len,
1385 dev_info.max_rx_pktlen);
1388 } else if (dev_conf->rxmode.max_rx_pkt_len < RTE_ETHER_MIN_LEN) {
1390 "Ethdev port_id=%u max_rx_pkt_len %u < min valid value %u\n",
1391 port_id, dev_conf->rxmode.max_rx_pkt_len,
1392 (unsigned int)RTE_ETHER_MIN_LEN);
1397 if (dev_conf->rxmode.max_rx_pkt_len < RTE_ETHER_MIN_LEN ||
1398 dev_conf->rxmode.max_rx_pkt_len > RTE_ETHER_MAX_LEN)
1399 /* Use default value */
1400 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1405 * If LRO is enabled, check that the maximum aggregated packet
1406 * size is supported by the configured device.
1408 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_TCP_LRO) {
1409 if (dev_conf->rxmode.max_lro_pkt_size == 0)
1410 dev->data->dev_conf.rxmode.max_lro_pkt_size =
1411 dev->data->dev_conf.rxmode.max_rx_pkt_len;
1412 ret = check_lro_pkt_size(port_id,
1413 dev->data->dev_conf.rxmode.max_lro_pkt_size,
1414 dev->data->dev_conf.rxmode.max_rx_pkt_len,
1415 dev_info.max_lro_pkt_size);
1420 /* Any requested offloading must be within its device capabilities */
1421 if ((dev_conf->rxmode.offloads & dev_info.rx_offload_capa) !=
1422 dev_conf->rxmode.offloads) {
1424 "Ethdev port_id=%u requested Rx offloads 0x%"PRIx64" doesn't match Rx offloads "
1425 "capabilities 0x%"PRIx64" in %s()\n",
1426 port_id, dev_conf->rxmode.offloads,
1427 dev_info.rx_offload_capa,
1432 if ((dev_conf->txmode.offloads & dev_info.tx_offload_capa) !=
1433 dev_conf->txmode.offloads) {
1435 "Ethdev port_id=%u requested Tx offloads 0x%"PRIx64" doesn't match Tx offloads "
1436 "capabilities 0x%"PRIx64" in %s()\n",
1437 port_id, dev_conf->txmode.offloads,
1438 dev_info.tx_offload_capa,
1444 dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf =
1445 rte_eth_rss_hf_refine(dev_conf->rx_adv_conf.rss_conf.rss_hf);
1447 /* Check that device supports requested rss hash functions. */
1448 if ((dev_info.flow_type_rss_offloads |
1449 dev_conf->rx_adv_conf.rss_conf.rss_hf) !=
1450 dev_info.flow_type_rss_offloads) {
1452 "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n",
1453 port_id, dev_conf->rx_adv_conf.rss_conf.rss_hf,
1454 dev_info.flow_type_rss_offloads);
1459 /* Check if Rx RSS distribution is disabled but RSS hash is enabled. */
1460 if (((dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) == 0) &&
1461 (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_RSS_HASH)) {
1463 "Ethdev port_id=%u config invalid Rx mq_mode without RSS but %s offload is requested\n",
1465 rte_eth_dev_rx_offload_name(DEV_RX_OFFLOAD_RSS_HASH));
1471 * Setup new number of RX/TX queues and reconfigure device.
1473 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1476 "Port%u rte_eth_dev_rx_queue_config = %d\n",
1482 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1485 "Port%u rte_eth_dev_tx_queue_config = %d\n",
1487 rte_eth_dev_rx_queue_config(dev, 0);
1492 diag = (*dev->dev_ops->dev_configure)(dev);
1494 RTE_ETHDEV_LOG(ERR, "Port%u dev_configure = %d\n",
1496 ret = eth_err(port_id, diag);
1500 /* Initialize Rx profiling if enabled at compilation time. */
1501 diag = __rte_eth_dev_profile_init(port_id, dev);
1503 RTE_ETHDEV_LOG(ERR, "Port%u __rte_eth_dev_profile_init = %d\n",
1505 ret = eth_err(port_id, diag);
1509 /* Validate Rx offloads. */
1510 diag = validate_offloads(port_id,
1511 dev_conf->rxmode.offloads,
1512 dev->data->dev_conf.rxmode.offloads, "Rx",
1513 rte_eth_dev_rx_offload_name);
1519 /* Validate Tx offloads. */
1520 diag = validate_offloads(port_id,
1521 dev_conf->txmode.offloads,
1522 dev->data->dev_conf.txmode.offloads, "Tx",
1523 rte_eth_dev_tx_offload_name);
1529 rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0);
1532 rte_eth_dev_rx_queue_config(dev, 0);
1533 rte_eth_dev_tx_queue_config(dev, 0);
1535 memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf));
1537 rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret);
1542 rte_eth_dev_internal_reset(struct rte_eth_dev *dev)
1544 if (dev->data->dev_started) {
1545 RTE_ETHDEV_LOG(ERR, "Port %u must be stopped to allow reset\n",
1546 dev->data->port_id);
1550 rte_eth_dev_rx_queue_config(dev, 0);
1551 rte_eth_dev_tx_queue_config(dev, 0);
1553 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
1557 rte_eth_dev_mac_restore(struct rte_eth_dev *dev,
1558 struct rte_eth_dev_info *dev_info)
1560 struct rte_ether_addr *addr;
1565 /* replay MAC address configuration including default MAC */
1566 addr = &dev->data->mac_addrs[0];
1567 if (*dev->dev_ops->mac_addr_set != NULL)
1568 (*dev->dev_ops->mac_addr_set)(dev, addr);
1569 else if (*dev->dev_ops->mac_addr_add != NULL)
1570 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
1572 if (*dev->dev_ops->mac_addr_add != NULL) {
1573 for (i = 1; i < dev_info->max_mac_addrs; i++) {
1574 addr = &dev->data->mac_addrs[i];
1576 /* skip zero address */
1577 if (rte_is_zero_ether_addr(addr))
1581 pool_mask = dev->data->mac_pool_sel[i];
1584 if (pool_mask & 1ULL)
1585 (*dev->dev_ops->mac_addr_add)(dev,
1589 } while (pool_mask);
1595 rte_eth_dev_config_restore(struct rte_eth_dev *dev,
1596 struct rte_eth_dev_info *dev_info, uint16_t port_id)
1600 if (!(*dev_info->dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR))
1601 rte_eth_dev_mac_restore(dev, dev_info);
1603 /* replay promiscuous configuration */
1605 * use callbacks directly since we don't need port_id check and
1606 * would like to bypass the same value set
1608 if (rte_eth_promiscuous_get(port_id) == 1 &&
1609 *dev->dev_ops->promiscuous_enable != NULL) {
1610 ret = eth_err(port_id,
1611 (*dev->dev_ops->promiscuous_enable)(dev));
1612 if (ret != 0 && ret != -ENOTSUP) {
1614 "Failed to enable promiscuous mode for device (port %u): %s\n",
1615 port_id, rte_strerror(-ret));
1618 } else if (rte_eth_promiscuous_get(port_id) == 0 &&
1619 *dev->dev_ops->promiscuous_disable != NULL) {
1620 ret = eth_err(port_id,
1621 (*dev->dev_ops->promiscuous_disable)(dev));
1622 if (ret != 0 && ret != -ENOTSUP) {
1624 "Failed to disable promiscuous mode for device (port %u): %s\n",
1625 port_id, rte_strerror(-ret));
1630 /* replay all multicast configuration */
1632 * use callbacks directly since we don't need port_id check and
1633 * would like to bypass the same value set
1635 if (rte_eth_allmulticast_get(port_id) == 1 &&
1636 *dev->dev_ops->allmulticast_enable != NULL) {
1637 ret = eth_err(port_id,
1638 (*dev->dev_ops->allmulticast_enable)(dev));
1639 if (ret != 0 && ret != -ENOTSUP) {
1641 "Failed to enable allmulticast mode for device (port %u): %s\n",
1642 port_id, rte_strerror(-ret));
1645 } else if (rte_eth_allmulticast_get(port_id) == 0 &&
1646 *dev->dev_ops->allmulticast_disable != NULL) {
1647 ret = eth_err(port_id,
1648 (*dev->dev_ops->allmulticast_disable)(dev));
1649 if (ret != 0 && ret != -ENOTSUP) {
1651 "Failed to disable allmulticast mode for device (port %u): %s\n",
1652 port_id, rte_strerror(-ret));
1661 rte_eth_dev_start(uint16_t port_id)
1663 struct rte_eth_dev *dev;
1664 struct rte_eth_dev_info dev_info;
1668 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1670 dev = &rte_eth_devices[port_id];
1672 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1674 if (dev->data->dev_started != 0) {
1675 RTE_ETHDEV_LOG(INFO,
1676 "Device with port_id=%"PRIu16" already started\n",
1681 ret = rte_eth_dev_info_get(port_id, &dev_info);
1685 /* Lets restore MAC now if device does not support live change */
1686 if (*dev_info.dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR)
1687 rte_eth_dev_mac_restore(dev, &dev_info);
1689 diag = (*dev->dev_ops->dev_start)(dev);
1691 dev->data->dev_started = 1;
1693 return eth_err(port_id, diag);
1695 ret = rte_eth_dev_config_restore(dev, &dev_info, port_id);
1698 "Error during restoring configuration for device (port %u): %s\n",
1699 port_id, rte_strerror(-ret));
1700 rte_eth_dev_stop(port_id);
1704 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1705 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1706 (*dev->dev_ops->link_update)(dev, 0);
1709 rte_ethdev_trace_start(port_id);
1714 rte_eth_dev_stop(uint16_t port_id)
1716 struct rte_eth_dev *dev;
1718 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1719 dev = &rte_eth_devices[port_id];
1721 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1723 if (dev->data->dev_started == 0) {
1724 RTE_ETHDEV_LOG(INFO,
1725 "Device with port_id=%"PRIu16" already stopped\n",
1730 dev->data->dev_started = 0;
1731 (*dev->dev_ops->dev_stop)(dev);
1732 rte_ethdev_trace_stop(port_id);
1736 rte_eth_dev_set_link_up(uint16_t port_id)
1738 struct rte_eth_dev *dev;
1740 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1742 dev = &rte_eth_devices[port_id];
1744 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1745 return eth_err(port_id, (*dev->dev_ops->dev_set_link_up)(dev));
1749 rte_eth_dev_set_link_down(uint16_t port_id)
1751 struct rte_eth_dev *dev;
1753 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1755 dev = &rte_eth_devices[port_id];
1757 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1758 return eth_err(port_id, (*dev->dev_ops->dev_set_link_down)(dev));
1762 rte_eth_dev_close(uint16_t port_id)
1764 struct rte_eth_dev *dev;
1766 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1767 dev = &rte_eth_devices[port_id];
1769 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1770 dev->data->dev_started = 0;
1771 (*dev->dev_ops->dev_close)(dev);
1773 rte_ethdev_trace_close(port_id);
1774 rte_eth_dev_release_port(dev);
1778 rte_eth_dev_reset(uint16_t port_id)
1780 struct rte_eth_dev *dev;
1783 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1784 dev = &rte_eth_devices[port_id];
1786 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1788 rte_eth_dev_stop(port_id);
1789 ret = dev->dev_ops->dev_reset(dev);
1791 return eth_err(port_id, ret);
1795 rte_eth_dev_is_removed(uint16_t port_id)
1797 struct rte_eth_dev *dev;
1800 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
1802 dev = &rte_eth_devices[port_id];
1804 if (dev->state == RTE_ETH_DEV_REMOVED)
1807 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->is_removed, 0);
1809 ret = dev->dev_ops->is_removed(dev);
1811 /* Device is physically removed. */
1812 dev->state = RTE_ETH_DEV_REMOVED;
1818 rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1819 uint16_t nb_rx_desc, unsigned int socket_id,
1820 const struct rte_eth_rxconf *rx_conf,
1821 struct rte_mempool *mp)
1824 uint32_t mbp_buf_size;
1825 struct rte_eth_dev *dev;
1826 struct rte_eth_dev_info dev_info;
1827 struct rte_eth_rxconf local_conf;
1830 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1832 dev = &rte_eth_devices[port_id];
1833 if (rx_queue_id >= dev->data->nb_rx_queues) {
1834 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
1839 RTE_ETHDEV_LOG(ERR, "Invalid null mempool pointer\n");
1843 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1846 * Check the size of the mbuf data buffer.
1847 * This value must be provided in the private data of the memory pool.
1848 * First check that the memory pool has a valid private data.
1850 ret = rte_eth_dev_info_get(port_id, &dev_info);
1854 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1855 RTE_ETHDEV_LOG(ERR, "%s private_data_size %d < %d\n",
1856 mp->name, (int)mp->private_data_size,
1857 (int)sizeof(struct rte_pktmbuf_pool_private));
1860 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1862 if (mbp_buf_size < dev_info.min_rx_bufsize + RTE_PKTMBUF_HEADROOM) {
1864 "%s mbuf_data_room_size %d < %d (RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)=%d)\n",
1865 mp->name, (int)mbp_buf_size,
1866 (int)(RTE_PKTMBUF_HEADROOM + dev_info.min_rx_bufsize),
1867 (int)RTE_PKTMBUF_HEADROOM,
1868 (int)dev_info.min_rx_bufsize);
1872 /* Use default specified by driver, if nb_rx_desc is zero */
1873 if (nb_rx_desc == 0) {
1874 nb_rx_desc = dev_info.default_rxportconf.ring_size;
1875 /* If driver default is also zero, fall back on EAL default */
1876 if (nb_rx_desc == 0)
1877 nb_rx_desc = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
1880 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1881 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1882 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1885 "Invalid value for nb_rx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n",
1886 nb_rx_desc, dev_info.rx_desc_lim.nb_max,
1887 dev_info.rx_desc_lim.nb_min,
1888 dev_info.rx_desc_lim.nb_align);
1892 if (dev->data->dev_started &&
1893 !(dev_info.dev_capa &
1894 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP))
1897 if (dev->data->dev_started &&
1898 (dev->data->rx_queue_state[rx_queue_id] !=
1899 RTE_ETH_QUEUE_STATE_STOPPED))
1902 rxq = dev->data->rx_queues;
1903 if (rxq[rx_queue_id]) {
1904 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1906 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1907 rxq[rx_queue_id] = NULL;
1910 if (rx_conf == NULL)
1911 rx_conf = &dev_info.default_rxconf;
1913 local_conf = *rx_conf;
1916 * If an offloading has already been enabled in
1917 * rte_eth_dev_configure(), it has been enabled on all queues,
1918 * so there is no need to enable it in this queue again.
1919 * The local_conf.offloads input to underlying PMD only carries
1920 * those offloadings which are only enabled on this queue and
1921 * not enabled on all queues.
1923 local_conf.offloads &= ~dev->data->dev_conf.rxmode.offloads;
1926 * New added offloadings for this queue are those not enabled in
1927 * rte_eth_dev_configure() and they must be per-queue type.
1928 * A pure per-port offloading can't be enabled on a queue while
1929 * disabled on another queue. A pure per-port offloading can't
1930 * be enabled for any queue as new added one if it hasn't been
1931 * enabled in rte_eth_dev_configure().
1933 if ((local_conf.offloads & dev_info.rx_queue_offload_capa) !=
1934 local_conf.offloads) {
1936 "Ethdev port_id=%d rx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
1937 "within per-queue offload capabilities 0x%"PRIx64" in %s()\n",
1938 port_id, rx_queue_id, local_conf.offloads,
1939 dev_info.rx_queue_offload_capa,
1945 * If LRO is enabled, check that the maximum aggregated packet
1946 * size is supported by the configured device.
1948 if (local_conf.offloads & DEV_RX_OFFLOAD_TCP_LRO) {
1949 if (dev->data->dev_conf.rxmode.max_lro_pkt_size == 0)
1950 dev->data->dev_conf.rxmode.max_lro_pkt_size =
1951 dev->data->dev_conf.rxmode.max_rx_pkt_len;
1952 int ret = check_lro_pkt_size(port_id,
1953 dev->data->dev_conf.rxmode.max_lro_pkt_size,
1954 dev->data->dev_conf.rxmode.max_rx_pkt_len,
1955 dev_info.max_lro_pkt_size);
1960 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1961 socket_id, &local_conf, mp);
1963 if (!dev->data->min_rx_buf_size ||
1964 dev->data->min_rx_buf_size > mbp_buf_size)
1965 dev->data->min_rx_buf_size = mbp_buf_size;
1968 rte_ethdev_trace_rxq_setup(port_id, rx_queue_id, nb_rx_desc, mp,
1970 return eth_err(port_id, ret);
1974 rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1975 uint16_t nb_rx_desc,
1976 const struct rte_eth_hairpin_conf *conf)
1979 struct rte_eth_dev *dev;
1980 struct rte_eth_hairpin_cap cap;
1985 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1987 dev = &rte_eth_devices[port_id];
1988 if (rx_queue_id >= dev->data->nb_rx_queues) {
1989 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
1992 ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
1995 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_hairpin_queue_setup,
1997 /* if nb_rx_desc is zero use max number of desc from the driver. */
1998 if (nb_rx_desc == 0)
1999 nb_rx_desc = cap.max_nb_desc;
2000 if (nb_rx_desc > cap.max_nb_desc) {
2002 "Invalid value for nb_rx_desc(=%hu), should be: <= %hu",
2003 nb_rx_desc, cap.max_nb_desc);
2006 if (conf->peer_count > cap.max_rx_2_tx) {
2008 "Invalid value for number of peers for Rx queue(=%u), should be: <= %hu",
2009 conf->peer_count, cap.max_rx_2_tx);
2012 if (conf->peer_count == 0) {
2014 "Invalid value for number of peers for Rx queue(=%u), should be: > 0",
2018 for (i = 0, count = 0; i < dev->data->nb_rx_queues &&
2019 cap.max_nb_queues != UINT16_MAX; i++) {
2020 if (i == rx_queue_id || rte_eth_dev_is_rx_hairpin_queue(dev, i))
2023 if (count > cap.max_nb_queues) {
2024 RTE_ETHDEV_LOG(ERR, "To many Rx hairpin queues max is %d",
2028 if (dev->data->dev_started)
2030 rxq = dev->data->rx_queues;
2031 if (rxq[rx_queue_id] != NULL) {
2032 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
2034 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
2035 rxq[rx_queue_id] = NULL;
2037 ret = (*dev->dev_ops->rx_hairpin_queue_setup)(dev, rx_queue_id,
2040 dev->data->rx_queue_state[rx_queue_id] =
2041 RTE_ETH_QUEUE_STATE_HAIRPIN;
2042 return eth_err(port_id, ret);
2046 rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
2047 uint16_t nb_tx_desc, unsigned int socket_id,
2048 const struct rte_eth_txconf *tx_conf)
2050 struct rte_eth_dev *dev;
2051 struct rte_eth_dev_info dev_info;
2052 struct rte_eth_txconf local_conf;
2056 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2058 dev = &rte_eth_devices[port_id];
2059 if (tx_queue_id >= dev->data->nb_tx_queues) {
2060 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
2064 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
2066 ret = rte_eth_dev_info_get(port_id, &dev_info);
2070 /* Use default specified by driver, if nb_tx_desc is zero */
2071 if (nb_tx_desc == 0) {
2072 nb_tx_desc = dev_info.default_txportconf.ring_size;
2073 /* If driver default is zero, fall back on EAL default */
2074 if (nb_tx_desc == 0)
2075 nb_tx_desc = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
2077 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
2078 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
2079 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
2081 "Invalid value for nb_tx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n",
2082 nb_tx_desc, dev_info.tx_desc_lim.nb_max,
2083 dev_info.tx_desc_lim.nb_min,
2084 dev_info.tx_desc_lim.nb_align);
2088 if (dev->data->dev_started &&
2089 !(dev_info.dev_capa &
2090 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP))
2093 if (dev->data->dev_started &&
2094 (dev->data->tx_queue_state[tx_queue_id] !=
2095 RTE_ETH_QUEUE_STATE_STOPPED))
2098 txq = dev->data->tx_queues;
2099 if (txq[tx_queue_id]) {
2100 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
2102 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
2103 txq[tx_queue_id] = NULL;
2106 if (tx_conf == NULL)
2107 tx_conf = &dev_info.default_txconf;
2109 local_conf = *tx_conf;
2112 * If an offloading has already been enabled in
2113 * rte_eth_dev_configure(), it has been enabled on all queues,
2114 * so there is no need to enable it in this queue again.
2115 * The local_conf.offloads input to underlying PMD only carries
2116 * those offloadings which are only enabled on this queue and
2117 * not enabled on all queues.
2119 local_conf.offloads &= ~dev->data->dev_conf.txmode.offloads;
2122 * New added offloadings for this queue are those not enabled in
2123 * rte_eth_dev_configure() and they must be per-queue type.
2124 * A pure per-port offloading can't be enabled on a queue while
2125 * disabled on another queue. A pure per-port offloading can't
2126 * be enabled for any queue as new added one if it hasn't been
2127 * enabled in rte_eth_dev_configure().
2129 if ((local_conf.offloads & dev_info.tx_queue_offload_capa) !=
2130 local_conf.offloads) {
2132 "Ethdev port_id=%d tx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
2133 "within per-queue offload capabilities 0x%"PRIx64" in %s()\n",
2134 port_id, tx_queue_id, local_conf.offloads,
2135 dev_info.tx_queue_offload_capa,
2140 rte_ethdev_trace_txq_setup(port_id, tx_queue_id, nb_tx_desc, tx_conf);
2141 return eth_err(port_id, (*dev->dev_ops->tx_queue_setup)(dev,
2142 tx_queue_id, nb_tx_desc, socket_id, &local_conf));
2146 rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
2147 uint16_t nb_tx_desc,
2148 const struct rte_eth_hairpin_conf *conf)
2150 struct rte_eth_dev *dev;
2151 struct rte_eth_hairpin_cap cap;
2157 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2158 dev = &rte_eth_devices[port_id];
2159 if (tx_queue_id >= dev->data->nb_tx_queues) {
2160 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
2163 ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
2166 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_hairpin_queue_setup,
2168 /* if nb_rx_desc is zero use max number of desc from the driver. */
2169 if (nb_tx_desc == 0)
2170 nb_tx_desc = cap.max_nb_desc;
2171 if (nb_tx_desc > cap.max_nb_desc) {
2173 "Invalid value for nb_tx_desc(=%hu), should be: <= %hu",
2174 nb_tx_desc, cap.max_nb_desc);
2177 if (conf->peer_count > cap.max_tx_2_rx) {
2179 "Invalid value for number of peers for Tx queue(=%u), should be: <= %hu",
2180 conf->peer_count, cap.max_tx_2_rx);
2183 if (conf->peer_count == 0) {
2185 "Invalid value for number of peers for Tx queue(=%u), should be: > 0",
2189 for (i = 0, count = 0; i < dev->data->nb_tx_queues &&
2190 cap.max_nb_queues != UINT16_MAX; i++) {
2191 if (i == tx_queue_id || rte_eth_dev_is_tx_hairpin_queue(dev, i))
2194 if (count > cap.max_nb_queues) {
2195 RTE_ETHDEV_LOG(ERR, "To many Tx hairpin queues max is %d",
2199 if (dev->data->dev_started)
2201 txq = dev->data->tx_queues;
2202 if (txq[tx_queue_id] != NULL) {
2203 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
2205 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
2206 txq[tx_queue_id] = NULL;
2208 ret = (*dev->dev_ops->tx_hairpin_queue_setup)
2209 (dev, tx_queue_id, nb_tx_desc, conf);
2211 dev->data->tx_queue_state[tx_queue_id] =
2212 RTE_ETH_QUEUE_STATE_HAIRPIN;
2213 return eth_err(port_id, ret);
2217 rte_eth_hairpin_bind(uint16_t tx_port, uint16_t rx_port)
2219 struct rte_eth_dev *dev;
2222 RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
2223 dev = &rte_eth_devices[tx_port];
2224 if (dev->data->dev_started == 0) {
2225 RTE_ETHDEV_LOG(ERR, "Tx port %d is not started\n", tx_port);
2229 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_bind, -ENOTSUP);
2230 ret = (*dev->dev_ops->hairpin_bind)(dev, rx_port);
2232 RTE_ETHDEV_LOG(ERR, "Failed to bind hairpin Tx %d"
2233 " to Rx %d (%d - all ports)\n",
2234 tx_port, rx_port, RTE_MAX_ETHPORTS);
2240 rte_eth_hairpin_unbind(uint16_t tx_port, uint16_t rx_port)
2242 struct rte_eth_dev *dev;
2245 RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
2246 dev = &rte_eth_devices[tx_port];
2247 if (dev->data->dev_started == 0) {
2248 RTE_ETHDEV_LOG(ERR, "Tx port %d is already stopped\n", tx_port);
2252 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_unbind, -ENOTSUP);
2253 ret = (*dev->dev_ops->hairpin_unbind)(dev, rx_port);
2255 RTE_ETHDEV_LOG(ERR, "Failed to unbind hairpin Tx %d"
2256 " from Rx %d (%d - all ports)\n",
2257 tx_port, rx_port, RTE_MAX_ETHPORTS);
2263 rte_eth_hairpin_get_peer_ports(uint16_t port_id, uint16_t *peer_ports,
2264 size_t len, uint32_t direction)
2266 struct rte_eth_dev *dev;
2269 if (peer_ports == NULL || len == 0)
2272 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2273 dev = &rte_eth_devices[port_id];
2274 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_get_peer_ports,
2277 ret = (*dev->dev_ops->hairpin_get_peer_ports)(dev, peer_ports,
2280 RTE_ETHDEV_LOG(ERR, "Failed to get %d hairpin peer %s ports\n",
2281 port_id, direction ? "Rx" : "Tx");
2287 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
2288 void *userdata __rte_unused)
2290 rte_pktmbuf_free_bulk(pkts, unsent);
2294 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
2297 uint64_t *count = userdata;
2299 rte_pktmbuf_free_bulk(pkts, unsent);
2304 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
2305 buffer_tx_error_fn cbfn, void *userdata)
2307 buffer->error_callback = cbfn;
2308 buffer->error_userdata = userdata;
2313 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
2320 buffer->size = size;
2321 if (buffer->error_callback == NULL) {
2322 ret = rte_eth_tx_buffer_set_err_callback(
2323 buffer, rte_eth_tx_buffer_drop_callback, NULL);
2330 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
2332 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2335 /* Validate Input Data. Bail if not valid or not supported. */
2336 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2337 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
2339 /* Call driver to free pending mbufs. */
2340 ret = (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
2342 return eth_err(port_id, ret);
2346 rte_eth_promiscuous_enable(uint16_t port_id)
2348 struct rte_eth_dev *dev;
2351 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2352 dev = &rte_eth_devices[port_id];
2354 if (dev->data->promiscuous == 1)
2357 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_enable, -ENOTSUP);
2359 diag = (*dev->dev_ops->promiscuous_enable)(dev);
2360 dev->data->promiscuous = (diag == 0) ? 1 : 0;
2362 return eth_err(port_id, diag);
2366 rte_eth_promiscuous_disable(uint16_t port_id)
2368 struct rte_eth_dev *dev;
2371 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2372 dev = &rte_eth_devices[port_id];
2374 if (dev->data->promiscuous == 0)
2377 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_disable, -ENOTSUP);
2379 dev->data->promiscuous = 0;
2380 diag = (*dev->dev_ops->promiscuous_disable)(dev);
2382 dev->data->promiscuous = 1;
2384 return eth_err(port_id, diag);
2388 rte_eth_promiscuous_get(uint16_t port_id)
2390 struct rte_eth_dev *dev;
2392 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2394 dev = &rte_eth_devices[port_id];
2395 return dev->data->promiscuous;
2399 rte_eth_allmulticast_enable(uint16_t port_id)
2401 struct rte_eth_dev *dev;
2404 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2405 dev = &rte_eth_devices[port_id];
2407 if (dev->data->all_multicast == 1)
2410 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_enable, -ENOTSUP);
2411 diag = (*dev->dev_ops->allmulticast_enable)(dev);
2412 dev->data->all_multicast = (diag == 0) ? 1 : 0;
2414 return eth_err(port_id, diag);
2418 rte_eth_allmulticast_disable(uint16_t port_id)
2420 struct rte_eth_dev *dev;
2423 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2424 dev = &rte_eth_devices[port_id];
2426 if (dev->data->all_multicast == 0)
2429 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_disable, -ENOTSUP);
2430 dev->data->all_multicast = 0;
2431 diag = (*dev->dev_ops->allmulticast_disable)(dev);
2433 dev->data->all_multicast = 1;
2435 return eth_err(port_id, diag);
2439 rte_eth_allmulticast_get(uint16_t port_id)
2441 struct rte_eth_dev *dev;
2443 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2445 dev = &rte_eth_devices[port_id];
2446 return dev->data->all_multicast;
2450 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
2452 struct rte_eth_dev *dev;
2454 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2455 dev = &rte_eth_devices[port_id];
2457 if (dev->data->dev_conf.intr_conf.lsc &&
2458 dev->data->dev_started)
2459 rte_eth_linkstatus_get(dev, eth_link);
2461 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
2462 (*dev->dev_ops->link_update)(dev, 1);
2463 *eth_link = dev->data->dev_link;
2470 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
2472 struct rte_eth_dev *dev;
2474 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2475 dev = &rte_eth_devices[port_id];
2477 if (dev->data->dev_conf.intr_conf.lsc &&
2478 dev->data->dev_started)
2479 rte_eth_linkstatus_get(dev, eth_link);
2481 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
2482 (*dev->dev_ops->link_update)(dev, 0);
2483 *eth_link = dev->data->dev_link;
2490 rte_eth_link_speed_to_str(uint32_t link_speed)
2492 switch (link_speed) {
2493 case ETH_SPEED_NUM_NONE: return "None";
2494 case ETH_SPEED_NUM_10M: return "10 Mbps";
2495 case ETH_SPEED_NUM_100M: return "100 Mbps";
2496 case ETH_SPEED_NUM_1G: return "1 Gbps";
2497 case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
2498 case ETH_SPEED_NUM_5G: return "5 Gbps";
2499 case ETH_SPEED_NUM_10G: return "10 Gbps";
2500 case ETH_SPEED_NUM_20G: return "20 Gbps";
2501 case ETH_SPEED_NUM_25G: return "25 Gbps";
2502 case ETH_SPEED_NUM_40G: return "40 Gbps";
2503 case ETH_SPEED_NUM_50G: return "50 Gbps";
2504 case ETH_SPEED_NUM_56G: return "56 Gbps";
2505 case ETH_SPEED_NUM_100G: return "100 Gbps";
2506 case ETH_SPEED_NUM_200G: return "200 Gbps";
2507 case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
2508 default: return "Invalid";
2513 rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link)
2515 if (eth_link->link_status == ETH_LINK_DOWN)
2516 return snprintf(str, len, "Link down");
2518 return snprintf(str, len, "Link up at %s %s %s",
2519 rte_eth_link_speed_to_str(eth_link->link_speed),
2520 (eth_link->link_duplex == ETH_LINK_FULL_DUPLEX) ?
2522 (eth_link->link_autoneg == ETH_LINK_AUTONEG) ?
2523 "Autoneg" : "Fixed");
2527 rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
2529 struct rte_eth_dev *dev;
2531 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2533 dev = &rte_eth_devices[port_id];
2534 memset(stats, 0, sizeof(*stats));
2536 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
2537 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
2538 return eth_err(port_id, (*dev->dev_ops->stats_get)(dev, stats));
2542 rte_eth_stats_reset(uint16_t port_id)
2544 struct rte_eth_dev *dev;
2547 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2548 dev = &rte_eth_devices[port_id];
2550 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
2551 ret = (*dev->dev_ops->stats_reset)(dev);
2553 return eth_err(port_id, ret);
2555 dev->data->rx_mbuf_alloc_failed = 0;
2561 get_xstats_basic_count(struct rte_eth_dev *dev)
2563 uint16_t nb_rxqs, nb_txqs;
2566 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2567 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2569 count = RTE_NB_STATS;
2570 count += nb_rxqs * RTE_NB_RXQ_STATS;
2571 count += nb_txqs * RTE_NB_TXQ_STATS;
2577 get_xstats_count(uint16_t port_id)
2579 struct rte_eth_dev *dev;
2582 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2583 dev = &rte_eth_devices[port_id];
2584 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
2585 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
2588 return eth_err(port_id, count);
2590 if (dev->dev_ops->xstats_get_names != NULL) {
2591 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
2593 return eth_err(port_id, count);
2598 count += get_xstats_basic_count(dev);
2604 rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
2607 int cnt_xstats, idx_xstat;
2609 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2612 RTE_ETHDEV_LOG(ERR, "Id pointer is NULL\n");
2617 RTE_ETHDEV_LOG(ERR, "xstat_name pointer is NULL\n");
2622 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
2623 if (cnt_xstats < 0) {
2624 RTE_ETHDEV_LOG(ERR, "Cannot get count of xstats\n");
2628 /* Get id-name lookup table */
2629 struct rte_eth_xstat_name xstats_names[cnt_xstats];
2631 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
2632 port_id, xstats_names, cnt_xstats, NULL)) {
2633 RTE_ETHDEV_LOG(ERR, "Cannot get xstats lookup\n");
2637 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
2638 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
2647 /* retrieve basic stats names */
2649 rte_eth_basic_stats_get_names(struct rte_eth_dev *dev,
2650 struct rte_eth_xstat_name *xstats_names)
2652 int cnt_used_entries = 0;
2653 uint32_t idx, id_queue;
2656 for (idx = 0; idx < RTE_NB_STATS; idx++) {
2657 strlcpy(xstats_names[cnt_used_entries].name,
2658 rte_stats_strings[idx].name,
2659 sizeof(xstats_names[0].name));
2662 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2663 for (id_queue = 0; id_queue < num_q; id_queue++) {
2664 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
2665 snprintf(xstats_names[cnt_used_entries].name,
2666 sizeof(xstats_names[0].name),
2668 id_queue, rte_rxq_stats_strings[idx].name);
2673 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2674 for (id_queue = 0; id_queue < num_q; id_queue++) {
2675 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
2676 snprintf(xstats_names[cnt_used_entries].name,
2677 sizeof(xstats_names[0].name),
2679 id_queue, rte_txq_stats_strings[idx].name);
2683 return cnt_used_entries;
2686 /* retrieve ethdev extended statistics names */
2688 rte_eth_xstats_get_names_by_id(uint16_t port_id,
2689 struct rte_eth_xstat_name *xstats_names, unsigned int size,
2692 struct rte_eth_xstat_name *xstats_names_copy;
2693 unsigned int no_basic_stat_requested = 1;
2694 unsigned int no_ext_stat_requested = 1;
2695 unsigned int expected_entries;
2696 unsigned int basic_count;
2697 struct rte_eth_dev *dev;
2701 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2702 dev = &rte_eth_devices[port_id];
2704 basic_count = get_xstats_basic_count(dev);
2705 ret = get_xstats_count(port_id);
2708 expected_entries = (unsigned int)ret;
2710 /* Return max number of stats if no ids given */
2713 return expected_entries;
2714 else if (xstats_names && size < expected_entries)
2715 return expected_entries;
2718 if (ids && !xstats_names)
2721 if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
2722 uint64_t ids_copy[size];
2724 for (i = 0; i < size; i++) {
2725 if (ids[i] < basic_count) {
2726 no_basic_stat_requested = 0;
2731 * Convert ids to xstats ids that PMD knows.
2732 * ids known by user are basic + extended stats.
2734 ids_copy[i] = ids[i] - basic_count;
2737 if (no_basic_stat_requested)
2738 return (*dev->dev_ops->xstats_get_names_by_id)(dev,
2739 xstats_names, ids_copy, size);
2742 /* Retrieve all stats */
2744 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
2746 if (num_stats < 0 || num_stats > (int)expected_entries)
2749 return expected_entries;
2752 xstats_names_copy = calloc(expected_entries,
2753 sizeof(struct rte_eth_xstat_name));
2755 if (!xstats_names_copy) {
2756 RTE_ETHDEV_LOG(ERR, "Can't allocate memory\n");
2761 for (i = 0; i < size; i++) {
2762 if (ids[i] >= basic_count) {
2763 no_ext_stat_requested = 0;
2769 /* Fill xstats_names_copy structure */
2770 if (ids && no_ext_stat_requested) {
2771 rte_eth_basic_stats_get_names(dev, xstats_names_copy);
2773 ret = rte_eth_xstats_get_names(port_id, xstats_names_copy,
2776 free(xstats_names_copy);
2782 for (i = 0; i < size; i++) {
2783 if (ids[i] >= expected_entries) {
2784 RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n");
2785 free(xstats_names_copy);
2788 xstats_names[i] = xstats_names_copy[ids[i]];
2791 free(xstats_names_copy);
2796 rte_eth_xstats_get_names(uint16_t port_id,
2797 struct rte_eth_xstat_name *xstats_names,
2800 struct rte_eth_dev *dev;
2801 int cnt_used_entries;
2802 int cnt_expected_entries;
2803 int cnt_driver_entries;
2805 cnt_expected_entries = get_xstats_count(port_id);
2806 if (xstats_names == NULL || cnt_expected_entries < 0 ||
2807 (int)size < cnt_expected_entries)
2808 return cnt_expected_entries;
2810 /* port_id checked in get_xstats_count() */
2811 dev = &rte_eth_devices[port_id];
2813 cnt_used_entries = rte_eth_basic_stats_get_names(
2816 if (dev->dev_ops->xstats_get_names != NULL) {
2817 /* If there are any driver-specific xstats, append them
2820 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
2822 xstats_names + cnt_used_entries,
2823 size - cnt_used_entries);
2824 if (cnt_driver_entries < 0)
2825 return eth_err(port_id, cnt_driver_entries);
2826 cnt_used_entries += cnt_driver_entries;
2829 return cnt_used_entries;
2834 rte_eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats)
2836 struct rte_eth_dev *dev;
2837 struct rte_eth_stats eth_stats;
2838 unsigned int count = 0, i, q;
2839 uint64_t val, *stats_ptr;
2840 uint16_t nb_rxqs, nb_txqs;
2843 ret = rte_eth_stats_get(port_id, ð_stats);
2847 dev = &rte_eth_devices[port_id];
2849 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2850 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2853 for (i = 0; i < RTE_NB_STATS; i++) {
2854 stats_ptr = RTE_PTR_ADD(ð_stats,
2855 rte_stats_strings[i].offset);
2857 xstats[count++].value = val;
2861 for (q = 0; q < nb_rxqs; q++) {
2862 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
2863 stats_ptr = RTE_PTR_ADD(ð_stats,
2864 rte_rxq_stats_strings[i].offset +
2865 q * sizeof(uint64_t));
2867 xstats[count++].value = val;
2872 for (q = 0; q < nb_txqs; q++) {
2873 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
2874 stats_ptr = RTE_PTR_ADD(ð_stats,
2875 rte_txq_stats_strings[i].offset +
2876 q * sizeof(uint64_t));
2878 xstats[count++].value = val;
2884 /* retrieve ethdev extended statistics */
2886 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
2887 uint64_t *values, unsigned int size)
2889 unsigned int no_basic_stat_requested = 1;
2890 unsigned int no_ext_stat_requested = 1;
2891 unsigned int num_xstats_filled;
2892 unsigned int basic_count;
2893 uint16_t expected_entries;
2894 struct rte_eth_dev *dev;
2898 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2899 ret = get_xstats_count(port_id);
2902 expected_entries = (uint16_t)ret;
2903 struct rte_eth_xstat xstats[expected_entries];
2904 dev = &rte_eth_devices[port_id];
2905 basic_count = get_xstats_basic_count(dev);
2907 /* Return max number of stats if no ids given */
2910 return expected_entries;
2911 else if (values && size < expected_entries)
2912 return expected_entries;
2918 if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
2919 unsigned int basic_count = get_xstats_basic_count(dev);
2920 uint64_t ids_copy[size];
2922 for (i = 0; i < size; i++) {
2923 if (ids[i] < basic_count) {
2924 no_basic_stat_requested = 0;
2929 * Convert ids to xstats ids that PMD knows.
2930 * ids known by user are basic + extended stats.
2932 ids_copy[i] = ids[i] - basic_count;
2935 if (no_basic_stat_requested)
2936 return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy,
2941 for (i = 0; i < size; i++) {
2942 if (ids[i] >= basic_count) {
2943 no_ext_stat_requested = 0;
2949 /* Fill the xstats structure */
2950 if (ids && no_ext_stat_requested)
2951 ret = rte_eth_basic_stats_get(port_id, xstats);
2953 ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
2957 num_xstats_filled = (unsigned int)ret;
2959 /* Return all stats */
2961 for (i = 0; i < num_xstats_filled; i++)
2962 values[i] = xstats[i].value;
2963 return expected_entries;
2967 for (i = 0; i < size; i++) {
2968 if (ids[i] >= expected_entries) {
2969 RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n");
2972 values[i] = xstats[ids[i]].value;
2978 rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
2981 struct rte_eth_dev *dev;
2982 unsigned int count = 0, i;
2983 signed int xcount = 0;
2984 uint16_t nb_rxqs, nb_txqs;
2987 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2989 dev = &rte_eth_devices[port_id];
2991 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2992 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2994 /* Return generic statistics */
2995 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
2996 (nb_txqs * RTE_NB_TXQ_STATS);
2998 /* implemented by the driver */
2999 if (dev->dev_ops->xstats_get != NULL) {
3000 /* Retrieve the xstats from the driver at the end of the
3003 xcount = (*dev->dev_ops->xstats_get)(dev,
3004 xstats ? xstats + count : NULL,
3005 (n > count) ? n - count : 0);
3008 return eth_err(port_id, xcount);
3011 if (n < count + xcount || xstats == NULL)
3012 return count + xcount;
3014 /* now fill the xstats structure */
3015 ret = rte_eth_basic_stats_get(port_id, xstats);
3020 for (i = 0; i < count; i++)
3022 /* add an offset to driver-specific stats */
3023 for ( ; i < count + xcount; i++)
3024 xstats[i].id += count;
3026 return count + xcount;
3029 /* reset ethdev extended statistics */
3031 rte_eth_xstats_reset(uint16_t port_id)
3033 struct rte_eth_dev *dev;
3035 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3036 dev = &rte_eth_devices[port_id];
3038 /* implemented by the driver */
3039 if (dev->dev_ops->xstats_reset != NULL)
3040 return eth_err(port_id, (*dev->dev_ops->xstats_reset)(dev));
3042 /* fallback to default */
3043 return rte_eth_stats_reset(port_id);
3047 set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
3050 struct rte_eth_dev *dev;
3052 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3054 dev = &rte_eth_devices[port_id];
3056 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
3058 if (is_rx && (queue_id >= dev->data->nb_rx_queues))
3061 if (!is_rx && (queue_id >= dev->data->nb_tx_queues))
3064 if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
3067 return (*dev->dev_ops->queue_stats_mapping_set)
3068 (dev, queue_id, stat_idx, is_rx);
3073 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
3076 return eth_err(port_id, set_queue_stats_mapping(port_id, tx_queue_id,
3077 stat_idx, STAT_QMAP_TX));
3082 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
3085 return eth_err(port_id, set_queue_stats_mapping(port_id, rx_queue_id,
3086 stat_idx, STAT_QMAP_RX));
3090 rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
3092 struct rte_eth_dev *dev;
3094 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3095 dev = &rte_eth_devices[port_id];
3097 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
3098 return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev,
3099 fw_version, fw_size));
3103 rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
3105 struct rte_eth_dev *dev;
3106 const struct rte_eth_desc_lim lim = {
3107 .nb_max = UINT16_MAX,
3110 .nb_seg_max = UINT16_MAX,
3111 .nb_mtu_seg_max = UINT16_MAX,
3116 * Init dev_info before port_id check since caller does not have
3117 * return status and does not know if get is successful or not.
3119 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
3120 dev_info->switch_info.domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
3122 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3123 dev = &rte_eth_devices[port_id];
3125 dev_info->rx_desc_lim = lim;
3126 dev_info->tx_desc_lim = lim;
3127 dev_info->device = dev->device;
3128 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3129 dev_info->max_mtu = UINT16_MAX;
3131 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3132 diag = (*dev->dev_ops->dev_infos_get)(dev, dev_info);
3134 /* Cleanup already filled in device information */
3135 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
3136 return eth_err(port_id, diag);
3139 /* Maximum number of queues should be <= RTE_MAX_QUEUES_PER_PORT */
3140 dev_info->max_rx_queues = RTE_MIN(dev_info->max_rx_queues,
3141 RTE_MAX_QUEUES_PER_PORT);
3142 dev_info->max_tx_queues = RTE_MIN(dev_info->max_tx_queues,
3143 RTE_MAX_QUEUES_PER_PORT);
3145 dev_info->driver_name = dev->device->driver->name;
3146 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
3147 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
3149 dev_info->dev_flags = &dev->data->dev_flags;
3155 rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
3156 uint32_t *ptypes, int num)
3159 struct rte_eth_dev *dev;
3160 const uint32_t *all_ptypes;
3162 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3163 dev = &rte_eth_devices[port_id];
3164 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
3165 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
3170 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
3171 if (all_ptypes[i] & ptype_mask) {
3173 ptypes[j] = all_ptypes[i];
3181 rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask,
3182 uint32_t *set_ptypes, unsigned int num)
3184 const uint32_t valid_ptype_masks[] = {
3188 RTE_PTYPE_TUNNEL_MASK,
3189 RTE_PTYPE_INNER_L2_MASK,
3190 RTE_PTYPE_INNER_L3_MASK,
3191 RTE_PTYPE_INNER_L4_MASK,
3193 const uint32_t *all_ptypes;
3194 struct rte_eth_dev *dev;
3195 uint32_t unused_mask;
3199 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3200 dev = &rte_eth_devices[port_id];
3202 if (num > 0 && set_ptypes == NULL)
3205 if (*dev->dev_ops->dev_supported_ptypes_get == NULL ||
3206 *dev->dev_ops->dev_ptypes_set == NULL) {
3211 if (ptype_mask == 0) {
3212 ret = (*dev->dev_ops->dev_ptypes_set)(dev,
3217 unused_mask = ptype_mask;
3218 for (i = 0; i < RTE_DIM(valid_ptype_masks); i++) {
3219 uint32_t mask = ptype_mask & valid_ptype_masks[i];
3220 if (mask && mask != valid_ptype_masks[i]) {
3224 unused_mask &= ~valid_ptype_masks[i];
3232 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
3233 if (all_ptypes == NULL) {
3239 * Accommodate as many set_ptypes as possible. If the supplied
3240 * set_ptypes array is insufficient fill it partially.
3242 for (i = 0, j = 0; set_ptypes != NULL &&
3243 (all_ptypes[i] != RTE_PTYPE_UNKNOWN); ++i) {
3244 if (ptype_mask & all_ptypes[i]) {
3246 set_ptypes[j] = all_ptypes[i];
3254 if (set_ptypes != NULL && j < num)
3255 set_ptypes[j] = RTE_PTYPE_UNKNOWN;
3257 return (*dev->dev_ops->dev_ptypes_set)(dev, ptype_mask);
3261 set_ptypes[0] = RTE_PTYPE_UNKNOWN;
3267 rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
3269 struct rte_eth_dev *dev;
3271 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3272 dev = &rte_eth_devices[port_id];
3273 rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
3279 rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
3281 struct rte_eth_dev *dev;
3283 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3285 dev = &rte_eth_devices[port_id];
3286 *mtu = dev->data->mtu;
3291 rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
3294 struct rte_eth_dev_info dev_info;
3295 struct rte_eth_dev *dev;
3297 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3298 dev = &rte_eth_devices[port_id];
3299 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
3302 * Check if the device supports dev_infos_get, if it does not
3303 * skip min_mtu/max_mtu validation here as this requires values
3304 * that are populated within the call to rte_eth_dev_info_get()
3305 * which relies on dev->dev_ops->dev_infos_get.
3307 if (*dev->dev_ops->dev_infos_get != NULL) {
3308 ret = rte_eth_dev_info_get(port_id, &dev_info);
3312 if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu)
3316 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
3318 dev->data->mtu = mtu;
3320 return eth_err(port_id, ret);
3324 rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
3326 struct rte_eth_dev *dev;
3329 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3330 dev = &rte_eth_devices[port_id];
3331 if (!(dev->data->dev_conf.rxmode.offloads &
3332 DEV_RX_OFFLOAD_VLAN_FILTER)) {
3333 RTE_ETHDEV_LOG(ERR, "Port %u: vlan-filtering disabled\n",
3338 if (vlan_id > 4095) {
3339 RTE_ETHDEV_LOG(ERR, "Port_id=%u invalid vlan_id=%u > 4095\n",
3343 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
3345 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
3347 struct rte_vlan_filter_conf *vfc;
3351 vfc = &dev->data->vlan_filter_conf;
3352 vidx = vlan_id / 64;
3353 vbit = vlan_id % 64;
3356 vfc->ids[vidx] |= UINT64_C(1) << vbit;
3358 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
3361 return eth_err(port_id, ret);
3365 rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
3368 struct rte_eth_dev *dev;
3370 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3371 dev = &rte_eth_devices[port_id];
3372 if (rx_queue_id >= dev->data->nb_rx_queues) {
3373 RTE_ETHDEV_LOG(ERR, "Invalid rx_queue_id=%u\n", rx_queue_id);
3377 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
3378 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
3384 rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
3385 enum rte_vlan_type vlan_type,
3388 struct rte_eth_dev *dev;
3390 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3391 dev = &rte_eth_devices[port_id];
3392 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
3394 return eth_err(port_id, (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type,
3399 rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
3401 struct rte_eth_dev_info dev_info;
3402 struct rte_eth_dev *dev;
3406 uint64_t orig_offloads;
3407 uint64_t dev_offloads;
3408 uint64_t new_offloads;
3410 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3411 dev = &rte_eth_devices[port_id];
3413 /* save original values in case of failure */
3414 orig_offloads = dev->data->dev_conf.rxmode.offloads;
3415 dev_offloads = orig_offloads;
3417 /* check which option changed by application */
3418 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
3419 org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
3422 dev_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3424 dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3425 mask |= ETH_VLAN_STRIP_MASK;
3428 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
3429 org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER);
3432 dev_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3434 dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3435 mask |= ETH_VLAN_FILTER_MASK;
3438 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
3439 org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND);
3442 dev_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3444 dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3445 mask |= ETH_VLAN_EXTEND_MASK;
3448 cur = !!(offload_mask & ETH_QINQ_STRIP_OFFLOAD);
3449 org = !!(dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP);
3452 dev_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3454 dev_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3455 mask |= ETH_QINQ_STRIP_MASK;
3462 ret = rte_eth_dev_info_get(port_id, &dev_info);
3466 /* Rx VLAN offloading must be within its device capabilities */
3467 if ((dev_offloads & dev_info.rx_offload_capa) != dev_offloads) {
3468 new_offloads = dev_offloads & ~orig_offloads;
3470 "Ethdev port_id=%u requested new added VLAN offloads "
3471 "0x%" PRIx64 " must be within Rx offloads capabilities "
3472 "0x%" PRIx64 " in %s()\n",
3473 port_id, new_offloads, dev_info.rx_offload_capa,
3478 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
3479 dev->data->dev_conf.rxmode.offloads = dev_offloads;
3480 ret = (*dev->dev_ops->vlan_offload_set)(dev, mask);
3482 /* hit an error restore original values */
3483 dev->data->dev_conf.rxmode.offloads = orig_offloads;
3486 return eth_err(port_id, ret);
3490 rte_eth_dev_get_vlan_offload(uint16_t port_id)
3492 struct rte_eth_dev *dev;
3493 uint64_t *dev_offloads;
3496 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3497 dev = &rte_eth_devices[port_id];
3498 dev_offloads = &dev->data->dev_conf.rxmode.offloads;
3500 if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
3501 ret |= ETH_VLAN_STRIP_OFFLOAD;
3503 if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
3504 ret |= ETH_VLAN_FILTER_OFFLOAD;
3506 if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
3507 ret |= ETH_VLAN_EXTEND_OFFLOAD;
3509 if (*dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP)
3510 ret |= ETH_QINQ_STRIP_OFFLOAD;
3516 rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
3518 struct rte_eth_dev *dev;
3520 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3521 dev = &rte_eth_devices[port_id];
3522 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
3524 return eth_err(port_id, (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on));
3528 rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
3530 struct rte_eth_dev *dev;
3532 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3533 dev = &rte_eth_devices[port_id];
3534 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
3535 memset(fc_conf, 0, sizeof(*fc_conf));
3536 return eth_err(port_id, (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf));
3540 rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
3542 struct rte_eth_dev *dev;
3544 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3545 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
3546 RTE_ETHDEV_LOG(ERR, "Invalid send_xon, only 0/1 allowed\n");
3550 dev = &rte_eth_devices[port_id];
3551 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
3552 return eth_err(port_id, (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf));
3556 rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
3557 struct rte_eth_pfc_conf *pfc_conf)
3559 struct rte_eth_dev *dev;
3561 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3562 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
3563 RTE_ETHDEV_LOG(ERR, "Invalid priority, only 0-7 allowed\n");
3567 dev = &rte_eth_devices[port_id];
3568 /* High water, low water validation are device specific */
3569 if (*dev->dev_ops->priority_flow_ctrl_set)
3570 return eth_err(port_id, (*dev->dev_ops->priority_flow_ctrl_set)
3576 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
3584 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
3585 for (i = 0; i < num; i++) {
3586 if (reta_conf[i].mask)
3594 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
3598 uint16_t i, idx, shift;
3604 RTE_ETHDEV_LOG(ERR, "No receive queue is available\n");
3608 for (i = 0; i < reta_size; i++) {
3609 idx = i / RTE_RETA_GROUP_SIZE;
3610 shift = i % RTE_RETA_GROUP_SIZE;
3611 if ((reta_conf[idx].mask & (1ULL << shift)) &&
3612 (reta_conf[idx].reta[shift] >= max_rxq)) {
3614 "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
3616 reta_conf[idx].reta[shift], max_rxq);
3625 rte_eth_dev_rss_reta_update(uint16_t port_id,
3626 struct rte_eth_rss_reta_entry64 *reta_conf,
3629 struct rte_eth_dev *dev;
3632 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3633 /* Check mask bits */
3634 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
3638 dev = &rte_eth_devices[port_id];
3640 /* Check entry value */
3641 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
3642 dev->data->nb_rx_queues);
3646 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
3647 return eth_err(port_id, (*dev->dev_ops->reta_update)(dev, reta_conf,
3652 rte_eth_dev_rss_reta_query(uint16_t port_id,
3653 struct rte_eth_rss_reta_entry64 *reta_conf,
3656 struct rte_eth_dev *dev;
3659 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3661 /* Check mask bits */
3662 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
3666 dev = &rte_eth_devices[port_id];
3667 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
3668 return eth_err(port_id, (*dev->dev_ops->reta_query)(dev, reta_conf,
3673 rte_eth_dev_rss_hash_update(uint16_t port_id,
3674 struct rte_eth_rss_conf *rss_conf)
3676 struct rte_eth_dev *dev;
3677 struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
3680 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3682 ret = rte_eth_dev_info_get(port_id, &dev_info);
3686 rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf);
3688 dev = &rte_eth_devices[port_id];
3689 if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) !=
3690 dev_info.flow_type_rss_offloads) {
3692 "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n",
3693 port_id, rss_conf->rss_hf,
3694 dev_info.flow_type_rss_offloads);
3697 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
3698 return eth_err(port_id, (*dev->dev_ops->rss_hash_update)(dev,
3703 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
3704 struct rte_eth_rss_conf *rss_conf)
3706 struct rte_eth_dev *dev;
3708 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3709 dev = &rte_eth_devices[port_id];
3710 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
3711 return eth_err(port_id, (*dev->dev_ops->rss_hash_conf_get)(dev,
3716 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
3717 struct rte_eth_udp_tunnel *udp_tunnel)
3719 struct rte_eth_dev *dev;
3721 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3722 if (udp_tunnel == NULL) {
3723 RTE_ETHDEV_LOG(ERR, "Invalid udp_tunnel parameter\n");
3727 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
3728 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
3732 dev = &rte_eth_devices[port_id];
3733 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
3734 return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_add)(dev,
3739 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
3740 struct rte_eth_udp_tunnel *udp_tunnel)
3742 struct rte_eth_dev *dev;
3744 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3745 dev = &rte_eth_devices[port_id];
3747 if (udp_tunnel == NULL) {
3748 RTE_ETHDEV_LOG(ERR, "Invalid udp_tunnel parameter\n");
3752 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
3753 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
3757 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
3758 return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_del)(dev,
3763 rte_eth_led_on(uint16_t port_id)
3765 struct rte_eth_dev *dev;
3767 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3768 dev = &rte_eth_devices[port_id];
3769 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
3770 return eth_err(port_id, (*dev->dev_ops->dev_led_on)(dev));
3774 rte_eth_led_off(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];
3780 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
3781 return eth_err(port_id, (*dev->dev_ops->dev_led_off)(dev));
3785 rte_eth_fec_get_capability(uint16_t port_id,
3786 struct rte_eth_fec_capa *speed_fec_capa,
3789 struct rte_eth_dev *dev;
3792 if (speed_fec_capa == NULL && num > 0)
3795 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3796 dev = &rte_eth_devices[port_id];
3797 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get_capability, -ENOTSUP);
3798 ret = (*dev->dev_ops->fec_get_capability)(dev, speed_fec_capa, num);
3804 rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa)
3806 struct rte_eth_dev *dev;
3808 if (fec_capa == NULL)
3811 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3812 dev = &rte_eth_devices[port_id];
3813 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get, -ENOTSUP);
3814 return eth_err(port_id, (*dev->dev_ops->fec_get)(dev, fec_capa));
3818 rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa)
3820 struct rte_eth_dev *dev;
3822 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3823 dev = &rte_eth_devices[port_id];
3824 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_set, -ENOTSUP);
3825 return eth_err(port_id, (*dev->dev_ops->fec_set)(dev, fec_capa));
3829 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
3833 get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
3835 struct rte_eth_dev_info dev_info;
3836 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3840 ret = rte_eth_dev_info_get(port_id, &dev_info);
3844 for (i = 0; i < dev_info.max_mac_addrs; i++)
3845 if (memcmp(addr, &dev->data->mac_addrs[i],
3846 RTE_ETHER_ADDR_LEN) == 0)
3852 static const struct rte_ether_addr null_mac_addr;
3855 rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
3858 struct rte_eth_dev *dev;
3863 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3864 dev = &rte_eth_devices[port_id];
3865 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
3867 if (rte_is_zero_ether_addr(addr)) {
3868 RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n",
3872 if (pool >= ETH_64_POOLS) {
3873 RTE_ETHDEV_LOG(ERR, "Pool id must be 0-%d\n", ETH_64_POOLS - 1);
3877 index = get_mac_addr_index(port_id, addr);
3879 index = get_mac_addr_index(port_id, &null_mac_addr);
3881 RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n",
3886 pool_mask = dev->data->mac_pool_sel[index];
3888 /* Check if both MAC address and pool is already there, and do nothing */
3889 if (pool_mask & (1ULL << pool))
3894 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
3897 /* Update address in NIC data structure */
3898 rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]);
3900 /* Update pool bitmap in NIC data structure */
3901 dev->data->mac_pool_sel[index] |= (1ULL << pool);
3904 return eth_err(port_id, ret);
3908 rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
3910 struct rte_eth_dev *dev;
3913 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3914 dev = &rte_eth_devices[port_id];
3915 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
3917 index = get_mac_addr_index(port_id, addr);
3920 "Port %u: Cannot remove default MAC address\n",
3923 } else if (index < 0)
3924 return 0; /* Do nothing if address wasn't found */
3927 (*dev->dev_ops->mac_addr_remove)(dev, index);
3929 /* Update address in NIC data structure */
3930 rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
3932 /* reset pool bitmap */
3933 dev->data->mac_pool_sel[index] = 0;
3939 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
3941 struct rte_eth_dev *dev;
3944 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3946 if (!rte_is_valid_assigned_ether_addr(addr))
3949 dev = &rte_eth_devices[port_id];
3950 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
3952 ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
3956 /* Update default address in NIC data structure */
3957 rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
3964 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
3968 get_hash_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
3970 struct rte_eth_dev_info dev_info;
3971 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3975 ret = rte_eth_dev_info_get(port_id, &dev_info);
3979 if (!dev->data->hash_mac_addrs)
3982 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
3983 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
3984 RTE_ETHER_ADDR_LEN) == 0)
3991 rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
3996 struct rte_eth_dev *dev;
3998 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4000 dev = &rte_eth_devices[port_id];
4001 if (rte_is_zero_ether_addr(addr)) {
4002 RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n",
4007 index = get_hash_mac_addr_index(port_id, addr);
4008 /* Check if it's already there, and do nothing */
4009 if ((index >= 0) && on)
4015 "Port %u: the MAC address was not set in UTA\n",
4020 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
4022 RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n",
4028 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
4029 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
4031 /* Update address in NIC data structure */
4033 rte_ether_addr_copy(addr,
4034 &dev->data->hash_mac_addrs[index]);
4036 rte_ether_addr_copy(&null_mac_addr,
4037 &dev->data->hash_mac_addrs[index]);
4040 return eth_err(port_id, ret);
4044 rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
4046 struct rte_eth_dev *dev;
4048 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4050 dev = &rte_eth_devices[port_id];
4052 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
4053 return eth_err(port_id, (*dev->dev_ops->uc_all_hash_table_set)(dev,
4057 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
4060 struct rte_eth_dev *dev;
4061 struct rte_eth_dev_info dev_info;
4062 struct rte_eth_link link;
4065 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4067 ret = rte_eth_dev_info_get(port_id, &dev_info);
4071 dev = &rte_eth_devices[port_id];
4072 link = dev->data->dev_link;
4074 if (queue_idx > dev_info.max_tx_queues) {
4076 "Set queue rate limit:port %u: invalid queue id=%u\n",
4077 port_id, queue_idx);
4081 if (tx_rate > link.link_speed) {
4083 "Set queue rate limit:invalid tx_rate=%u, bigger than link speed= %d\n",
4084 tx_rate, link.link_speed);
4088 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
4089 return eth_err(port_id, (*dev->dev_ops->set_queue_rate_limit)(dev,
4090 queue_idx, tx_rate));
4094 rte_eth_mirror_rule_set(uint16_t port_id,
4095 struct rte_eth_mirror_conf *mirror_conf,
4096 uint8_t rule_id, uint8_t on)
4098 struct rte_eth_dev *dev;
4100 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4101 if (mirror_conf->rule_type == 0) {
4102 RTE_ETHDEV_LOG(ERR, "Mirror rule type can not be 0\n");
4106 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
4107 RTE_ETHDEV_LOG(ERR, "Invalid dst pool, pool id must be 0-%d\n",
4112 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
4113 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
4114 (mirror_conf->pool_mask == 0)) {
4116 "Invalid mirror pool, pool mask can not be 0\n");
4120 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
4121 mirror_conf->vlan.vlan_mask == 0) {
4123 "Invalid vlan mask, vlan mask can not be 0\n");
4127 dev = &rte_eth_devices[port_id];
4128 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
4130 return eth_err(port_id, (*dev->dev_ops->mirror_rule_set)(dev,
4131 mirror_conf, rule_id, on));
4135 rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
4137 struct rte_eth_dev *dev;
4139 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4141 dev = &rte_eth_devices[port_id];
4142 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
4144 return eth_err(port_id, (*dev->dev_ops->mirror_rule_reset)(dev,
4148 RTE_INIT(eth_dev_init_cb_lists)
4152 for (i = 0; i < RTE_MAX_ETHPORTS; i++)
4153 TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
4157 rte_eth_dev_callback_register(uint16_t port_id,
4158 enum rte_eth_event_type event,
4159 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
4161 struct rte_eth_dev *dev;
4162 struct rte_eth_dev_callback *user_cb;
4163 uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
4169 if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
4170 RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id);
4174 if (port_id == RTE_ETH_ALL) {
4176 last_port = RTE_MAX_ETHPORTS - 1;
4178 next_port = last_port = port_id;
4181 rte_spinlock_lock(&rte_eth_dev_cb_lock);
4184 dev = &rte_eth_devices[next_port];
4186 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
4187 if (user_cb->cb_fn == cb_fn &&
4188 user_cb->cb_arg == cb_arg &&
4189 user_cb->event == event) {
4194 /* create a new callback. */
4195 if (user_cb == NULL) {
4196 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
4197 sizeof(struct rte_eth_dev_callback), 0);
4198 if (user_cb != NULL) {
4199 user_cb->cb_fn = cb_fn;
4200 user_cb->cb_arg = cb_arg;
4201 user_cb->event = event;
4202 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs),
4205 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4206 rte_eth_dev_callback_unregister(port_id, event,
4212 } while (++next_port <= last_port);
4214 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4219 rte_eth_dev_callback_unregister(uint16_t port_id,
4220 enum rte_eth_event_type event,
4221 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
4224 struct rte_eth_dev *dev;
4225 struct rte_eth_dev_callback *cb, *next;
4226 uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
4232 if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
4233 RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id);
4237 if (port_id == RTE_ETH_ALL) {
4239 last_port = RTE_MAX_ETHPORTS - 1;
4241 next_port = last_port = port_id;
4244 rte_spinlock_lock(&rte_eth_dev_cb_lock);
4247 dev = &rte_eth_devices[next_port];
4249 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL;
4252 next = TAILQ_NEXT(cb, next);
4254 if (cb->cb_fn != cb_fn || cb->event != event ||
4255 (cb_arg != (void *)-1 && cb->cb_arg != cb_arg))
4259 * if this callback is not executing right now,
4262 if (cb->active == 0) {
4263 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
4269 } while (++next_port <= last_port);
4271 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4276 rte_eth_dev_callback_process(struct rte_eth_dev *dev,
4277 enum rte_eth_event_type event, void *ret_param)
4279 struct rte_eth_dev_callback *cb_lst;
4280 struct rte_eth_dev_callback dev_cb;
4283 rte_spinlock_lock(&rte_eth_dev_cb_lock);
4284 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
4285 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
4289 if (ret_param != NULL)
4290 dev_cb.ret_param = ret_param;
4292 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4293 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
4294 dev_cb.cb_arg, dev_cb.ret_param);
4295 rte_spinlock_lock(&rte_eth_dev_cb_lock);
4298 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4303 rte_eth_dev_probing_finish(struct rte_eth_dev *dev)
4308 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_NEW, NULL);
4310 dev->state = RTE_ETH_DEV_ATTACHED;
4314 rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
4317 struct rte_eth_dev *dev;
4318 struct rte_intr_handle *intr_handle;
4322 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4324 dev = &rte_eth_devices[port_id];
4326 if (!dev->intr_handle) {
4327 RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
4331 intr_handle = dev->intr_handle;
4332 if (!intr_handle->intr_vec) {
4333 RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
4337 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
4338 vec = intr_handle->intr_vec[qid];
4339 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
4340 if (rc && rc != -EEXIST) {
4342 "p %u q %u rx ctl error op %d epfd %d vec %u\n",
4343 port_id, qid, op, epfd, vec);
4351 rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
4353 struct rte_intr_handle *intr_handle;
4354 struct rte_eth_dev *dev;
4355 unsigned int efd_idx;
4359 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
4361 dev = &rte_eth_devices[port_id];
4363 if (queue_id >= dev->data->nb_rx_queues) {
4364 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4368 if (!dev->intr_handle) {
4369 RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
4373 intr_handle = dev->intr_handle;
4374 if (!intr_handle->intr_vec) {
4375 RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
4379 vec = intr_handle->intr_vec[queue_id];
4380 efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ?
4381 (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec;
4382 fd = intr_handle->efds[efd_idx];
4388 eth_dma_mzone_name(char *name, size_t len, uint16_t port_id, uint16_t queue_id,
4389 const char *ring_name)
4391 return snprintf(name, len, "eth_p%d_q%d_%s",
4392 port_id, queue_id, ring_name);
4395 const struct rte_memzone *
4396 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
4397 uint16_t queue_id, size_t size, unsigned align,
4400 char z_name[RTE_MEMZONE_NAMESIZE];
4401 const struct rte_memzone *mz;
4404 rc = eth_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id,
4405 queue_id, ring_name);
4406 if (rc >= RTE_MEMZONE_NAMESIZE) {
4407 RTE_ETHDEV_LOG(ERR, "ring name too long\n");
4408 rte_errno = ENAMETOOLONG;
4412 mz = rte_memzone_lookup(z_name);
4414 if ((socket_id != SOCKET_ID_ANY && socket_id != mz->socket_id) ||
4416 ((uintptr_t)mz->addr & (align - 1)) != 0) {
4418 "memzone %s does not justify the requested attributes\n",
4426 return rte_memzone_reserve_aligned(z_name, size, socket_id,
4427 RTE_MEMZONE_IOVA_CONTIG, align);
4431 rte_eth_dma_zone_free(const struct rte_eth_dev *dev, const char *ring_name,
4434 char z_name[RTE_MEMZONE_NAMESIZE];
4435 const struct rte_memzone *mz;
4438 rc = eth_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id,
4439 queue_id, ring_name);
4440 if (rc >= RTE_MEMZONE_NAMESIZE) {
4441 RTE_ETHDEV_LOG(ERR, "ring name too long\n");
4442 return -ENAMETOOLONG;
4445 mz = rte_memzone_lookup(z_name);
4447 rc = rte_memzone_free(mz);
4455 rte_eth_dev_create(struct rte_device *device, const char *name,
4456 size_t priv_data_size,
4457 ethdev_bus_specific_init ethdev_bus_specific_init,
4458 void *bus_init_params,
4459 ethdev_init_t ethdev_init, void *init_params)
4461 struct rte_eth_dev *ethdev;
4464 RTE_FUNC_PTR_OR_ERR_RET(*ethdev_init, -EINVAL);
4466 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
4467 ethdev = rte_eth_dev_allocate(name);
4471 if (priv_data_size) {
4472 ethdev->data->dev_private = rte_zmalloc_socket(
4473 name, priv_data_size, RTE_CACHE_LINE_SIZE,
4476 if (!ethdev->data->dev_private) {
4478 "failed to allocate private data\n");
4484 ethdev = rte_eth_dev_attach_secondary(name);
4487 "secondary process attach failed, ethdev doesn't exist\n");
4492 ethdev->device = device;
4494 if (ethdev_bus_specific_init) {
4495 retval = ethdev_bus_specific_init(ethdev, bus_init_params);
4498 "ethdev bus specific initialisation failed\n");
4503 retval = ethdev_init(ethdev, init_params);
4505 RTE_ETHDEV_LOG(ERR, "ethdev initialisation failed\n");
4509 rte_eth_dev_probing_finish(ethdev);
4514 rte_eth_dev_release_port(ethdev);
4519 rte_eth_dev_destroy(struct rte_eth_dev *ethdev,
4520 ethdev_uninit_t ethdev_uninit)
4524 ethdev = rte_eth_dev_allocated(ethdev->data->name);
4528 RTE_FUNC_PTR_OR_ERR_RET(*ethdev_uninit, -EINVAL);
4530 ret = ethdev_uninit(ethdev);
4534 return rte_eth_dev_release_port(ethdev);
4538 rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
4539 int epfd, int op, void *data)
4542 struct rte_eth_dev *dev;
4543 struct rte_intr_handle *intr_handle;
4546 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4548 dev = &rte_eth_devices[port_id];
4549 if (queue_id >= dev->data->nb_rx_queues) {
4550 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4554 if (!dev->intr_handle) {
4555 RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
4559 intr_handle = dev->intr_handle;
4560 if (!intr_handle->intr_vec) {
4561 RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
4565 vec = intr_handle->intr_vec[queue_id];
4566 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
4567 if (rc && rc != -EEXIST) {
4569 "p %u q %u rx ctl error op %d epfd %d vec %u\n",
4570 port_id, queue_id, op, epfd, vec);
4578 rte_eth_dev_rx_intr_enable(uint16_t port_id,
4581 struct rte_eth_dev *dev;
4584 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4586 dev = &rte_eth_devices[port_id];
4588 ret = eth_dev_validate_rx_queue(dev, queue_id);
4592 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
4593 return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_enable)(dev,
4598 rte_eth_dev_rx_intr_disable(uint16_t port_id,
4601 struct rte_eth_dev *dev;
4604 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4606 dev = &rte_eth_devices[port_id];
4608 ret = eth_dev_validate_rx_queue(dev, queue_id);
4612 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
4613 return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_disable)(dev,
4619 rte_eth_dev_filter_supported(uint16_t port_id,
4620 enum rte_filter_type filter_type)
4622 struct rte_eth_dev *dev;
4624 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4626 dev = &rte_eth_devices[port_id];
4627 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
4628 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
4629 RTE_ETH_FILTER_NOP, NULL);
4633 rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
4634 enum rte_filter_op filter_op, void *arg)
4636 struct rte_eth_dev *dev;
4638 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4640 dev = &rte_eth_devices[port_id];
4641 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
4642 return eth_err(port_id, (*dev->dev_ops->filter_ctrl)(dev, filter_type,
4646 const struct rte_eth_rxtx_callback *
4647 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
4648 rte_rx_callback_fn fn, void *user_param)
4650 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4651 rte_errno = ENOTSUP;
4654 struct rte_eth_dev *dev;
4656 /* check input parameters */
4657 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
4658 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
4662 dev = &rte_eth_devices[port_id];
4663 if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
4667 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
4675 cb->param = user_param;
4677 rte_spinlock_lock(&rte_eth_rx_cb_lock);
4678 /* Add the callbacks in fifo order. */
4679 struct rte_eth_rxtx_callback *tail =
4680 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
4683 /* Stores to cb->fn and cb->param should complete before
4684 * cb is visible to data plane.
4687 &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
4688 cb, __ATOMIC_RELEASE);
4693 /* Stores to cb->fn and cb->param should complete before
4694 * cb is visible to data plane.
4696 __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE);
4698 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
4703 const struct rte_eth_rxtx_callback *
4704 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
4705 rte_rx_callback_fn fn, void *user_param)
4707 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4708 rte_errno = ENOTSUP;
4711 /* check input parameters */
4712 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
4713 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
4718 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
4726 cb->param = user_param;
4728 rte_spinlock_lock(&rte_eth_rx_cb_lock);
4729 /* Add the callbacks at first position */
4730 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
4731 /* Stores to cb->fn, cb->param and cb->next should complete before
4732 * cb is visible to data plane threads.
4735 &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
4736 cb, __ATOMIC_RELEASE);
4737 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
4742 const struct rte_eth_rxtx_callback *
4743 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
4744 rte_tx_callback_fn fn, void *user_param)
4746 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4747 rte_errno = ENOTSUP;
4750 struct rte_eth_dev *dev;
4752 /* check input parameters */
4753 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
4754 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
4759 dev = &rte_eth_devices[port_id];
4760 if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
4765 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
4773 cb->param = user_param;
4775 rte_spinlock_lock(&rte_eth_tx_cb_lock);
4776 /* Add the callbacks in fifo order. */
4777 struct rte_eth_rxtx_callback *tail =
4778 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
4781 /* Stores to cb->fn and cb->param should complete before
4782 * cb is visible to data plane.
4785 &rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id],
4786 cb, __ATOMIC_RELEASE);
4791 /* Stores to cb->fn and cb->param should complete before
4792 * cb is visible to data plane.
4794 __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE);
4796 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
4802 rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
4803 const struct rte_eth_rxtx_callback *user_cb)
4805 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4808 /* Check input parameters. */
4809 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
4810 if (user_cb == NULL ||
4811 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
4814 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
4815 struct rte_eth_rxtx_callback *cb;
4816 struct rte_eth_rxtx_callback **prev_cb;
4819 rte_spinlock_lock(&rte_eth_rx_cb_lock);
4820 prev_cb = &dev->post_rx_burst_cbs[queue_id];
4821 for (; *prev_cb != NULL; prev_cb = &cb->next) {
4823 if (cb == user_cb) {
4824 /* Remove the user cb from the callback list. */
4825 __atomic_store_n(prev_cb, cb->next, __ATOMIC_RELAXED);
4830 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
4836 rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
4837 const struct rte_eth_rxtx_callback *user_cb)
4839 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4842 /* Check input parameters. */
4843 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
4844 if (user_cb == NULL ||
4845 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
4848 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
4850 struct rte_eth_rxtx_callback *cb;
4851 struct rte_eth_rxtx_callback **prev_cb;
4853 rte_spinlock_lock(&rte_eth_tx_cb_lock);
4854 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
4855 for (; *prev_cb != NULL; prev_cb = &cb->next) {
4857 if (cb == user_cb) {
4858 /* Remove the user cb from the callback list. */
4859 __atomic_store_n(prev_cb, cb->next, __ATOMIC_RELAXED);
4864 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
4870 rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
4871 struct rte_eth_rxq_info *qinfo)
4873 struct rte_eth_dev *dev;
4875 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4880 dev = &rte_eth_devices[port_id];
4881 if (queue_id >= dev->data->nb_rx_queues) {
4882 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4886 if (dev->data->rx_queues == NULL ||
4887 dev->data->rx_queues[queue_id] == NULL) {
4889 "Rx queue %"PRIu16" of device with port_id=%"
4890 PRIu16" has not been setup\n",
4895 if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
4896 RTE_ETHDEV_LOG(INFO,
4897 "Can't get hairpin Rx queue %"PRIu16" info of device with port_id=%"PRIu16"\n",
4902 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
4904 memset(qinfo, 0, sizeof(*qinfo));
4905 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
4910 rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
4911 struct rte_eth_txq_info *qinfo)
4913 struct rte_eth_dev *dev;
4915 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4920 dev = &rte_eth_devices[port_id];
4921 if (queue_id >= dev->data->nb_tx_queues) {
4922 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id);
4926 if (dev->data->tx_queues == NULL ||
4927 dev->data->tx_queues[queue_id] == NULL) {
4929 "Tx queue %"PRIu16" of device with port_id=%"
4930 PRIu16" has not been setup\n",
4935 if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
4936 RTE_ETHDEV_LOG(INFO,
4937 "Can't get hairpin Tx queue %"PRIu16" info of device with port_id=%"PRIu16"\n",
4942 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
4944 memset(qinfo, 0, sizeof(*qinfo));
4945 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
4951 rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
4952 struct rte_eth_burst_mode *mode)
4954 struct rte_eth_dev *dev;
4956 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4961 dev = &rte_eth_devices[port_id];
4963 if (queue_id >= dev->data->nb_rx_queues) {
4964 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4968 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_burst_mode_get, -ENOTSUP);
4969 memset(mode, 0, sizeof(*mode));
4970 return eth_err(port_id,
4971 dev->dev_ops->rx_burst_mode_get(dev, queue_id, mode));
4975 rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
4976 struct rte_eth_burst_mode *mode)
4978 struct rte_eth_dev *dev;
4980 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4985 dev = &rte_eth_devices[port_id];
4987 if (queue_id >= dev->data->nb_tx_queues) {
4988 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id);
4992 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_burst_mode_get, -ENOTSUP);
4993 memset(mode, 0, sizeof(*mode));
4994 return eth_err(port_id,
4995 dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode));
4999 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
5000 struct rte_ether_addr *mc_addr_set,
5001 uint32_t nb_mc_addr)
5003 struct rte_eth_dev *dev;
5005 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5007 dev = &rte_eth_devices[port_id];
5008 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
5009 return eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev,
5010 mc_addr_set, nb_mc_addr));
5014 rte_eth_timesync_enable(uint16_t port_id)
5016 struct rte_eth_dev *dev;
5018 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5019 dev = &rte_eth_devices[port_id];
5021 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
5022 return eth_err(port_id, (*dev->dev_ops->timesync_enable)(dev));
5026 rte_eth_timesync_disable(uint16_t port_id)
5028 struct rte_eth_dev *dev;
5030 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5031 dev = &rte_eth_devices[port_id];
5033 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
5034 return eth_err(port_id, (*dev->dev_ops->timesync_disable)(dev));
5038 rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
5041 struct rte_eth_dev *dev;
5043 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5044 dev = &rte_eth_devices[port_id];
5046 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
5047 return eth_err(port_id, (*dev->dev_ops->timesync_read_rx_timestamp)
5048 (dev, timestamp, flags));
5052 rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
5053 struct timespec *timestamp)
5055 struct rte_eth_dev *dev;
5057 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5058 dev = &rte_eth_devices[port_id];
5060 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
5061 return eth_err(port_id, (*dev->dev_ops->timesync_read_tx_timestamp)
5066 rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
5068 struct rte_eth_dev *dev;
5070 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5071 dev = &rte_eth_devices[port_id];
5073 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
5074 return eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev,
5079 rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
5081 struct rte_eth_dev *dev;
5083 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5084 dev = &rte_eth_devices[port_id];
5086 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
5087 return eth_err(port_id, (*dev->dev_ops->timesync_read_time)(dev,
5092 rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
5094 struct rte_eth_dev *dev;
5096 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5097 dev = &rte_eth_devices[port_id];
5099 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
5100 return eth_err(port_id, (*dev->dev_ops->timesync_write_time)(dev,
5105 rte_eth_read_clock(uint16_t port_id, uint64_t *clock)
5107 struct rte_eth_dev *dev;
5109 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5110 dev = &rte_eth_devices[port_id];
5112 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->read_clock, -ENOTSUP);
5113 return eth_err(port_id, (*dev->dev_ops->read_clock)(dev, clock));
5117 rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
5119 struct rte_eth_dev *dev;
5121 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5123 dev = &rte_eth_devices[port_id];
5124 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
5125 return eth_err(port_id, (*dev->dev_ops->get_reg)(dev, info));
5129 rte_eth_dev_get_eeprom_length(uint16_t port_id)
5131 struct rte_eth_dev *dev;
5133 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5135 dev = &rte_eth_devices[port_id];
5136 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
5137 return eth_err(port_id, (*dev->dev_ops->get_eeprom_length)(dev));
5141 rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
5143 struct rte_eth_dev *dev;
5145 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5147 dev = &rte_eth_devices[port_id];
5148 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
5149 return eth_err(port_id, (*dev->dev_ops->get_eeprom)(dev, info));
5153 rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
5155 struct rte_eth_dev *dev;
5157 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5159 dev = &rte_eth_devices[port_id];
5160 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
5161 return eth_err(port_id, (*dev->dev_ops->set_eeprom)(dev, info));
5165 rte_eth_dev_get_module_info(uint16_t port_id,
5166 struct rte_eth_dev_module_info *modinfo)
5168 struct rte_eth_dev *dev;
5170 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5172 dev = &rte_eth_devices[port_id];
5173 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_info, -ENOTSUP);
5174 return (*dev->dev_ops->get_module_info)(dev, modinfo);
5178 rte_eth_dev_get_module_eeprom(uint16_t port_id,
5179 struct rte_dev_eeprom_info *info)
5181 struct rte_eth_dev *dev;
5183 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5185 dev = &rte_eth_devices[port_id];
5186 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_eeprom, -ENOTSUP);
5187 return (*dev->dev_ops->get_module_eeprom)(dev, info);
5191 rte_eth_dev_get_dcb_info(uint16_t port_id,
5192 struct rte_eth_dcb_info *dcb_info)
5194 struct rte_eth_dev *dev;
5196 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5198 dev = &rte_eth_devices[port_id];
5199 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
5201 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
5202 return eth_err(port_id, (*dev->dev_ops->get_dcb_info)(dev, dcb_info));
5206 rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
5207 struct rte_eth_l2_tunnel_conf *l2_tunnel)
5209 struct rte_eth_dev *dev;
5211 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5212 if (l2_tunnel == NULL) {
5213 RTE_ETHDEV_LOG(ERR, "Invalid l2_tunnel parameter\n");
5217 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
5218 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
5222 dev = &rte_eth_devices[port_id];
5223 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
5225 return eth_err(port_id, (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev,
5230 rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
5231 struct rte_eth_l2_tunnel_conf *l2_tunnel,
5235 struct rte_eth_dev *dev;
5237 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5239 if (l2_tunnel == NULL) {
5240 RTE_ETHDEV_LOG(ERR, "Invalid l2_tunnel parameter\n");
5244 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
5245 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
5250 RTE_ETHDEV_LOG(ERR, "Mask should have a value\n");
5254 dev = &rte_eth_devices[port_id];
5255 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
5257 return eth_err(port_id, (*dev->dev_ops->l2_tunnel_offload_set)(dev,
5258 l2_tunnel, mask, en));
5262 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
5263 const struct rte_eth_desc_lim *desc_lim)
5265 if (desc_lim->nb_align != 0)
5266 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
5268 if (desc_lim->nb_max != 0)
5269 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
5271 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
5275 rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
5276 uint16_t *nb_rx_desc,
5277 uint16_t *nb_tx_desc)
5279 struct rte_eth_dev_info dev_info;
5282 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5284 ret = rte_eth_dev_info_get(port_id, &dev_info);
5288 if (nb_rx_desc != NULL)
5289 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
5291 if (nb_tx_desc != NULL)
5292 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
5298 rte_eth_dev_hairpin_capability_get(uint16_t port_id,
5299 struct rte_eth_hairpin_cap *cap)
5301 struct rte_eth_dev *dev;
5303 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
5305 dev = &rte_eth_devices[port_id];
5306 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_cap_get, -ENOTSUP);
5307 memset(cap, 0, sizeof(*cap));
5308 return eth_err(port_id, (*dev->dev_ops->hairpin_cap_get)(dev, cap));
5312 rte_eth_dev_is_rx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id)
5314 if (dev->data->rx_queue_state[queue_id] ==
5315 RTE_ETH_QUEUE_STATE_HAIRPIN)
5321 rte_eth_dev_is_tx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id)
5323 if (dev->data->tx_queue_state[queue_id] ==
5324 RTE_ETH_QUEUE_STATE_HAIRPIN)
5330 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
5332 struct rte_eth_dev *dev;
5334 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5339 dev = &rte_eth_devices[port_id];
5341 if (*dev->dev_ops->pool_ops_supported == NULL)
5342 return 1; /* all pools are supported */
5344 return (*dev->dev_ops->pool_ops_supported)(dev, pool);
5348 * A set of values to describe the possible states of a switch domain.
5350 enum rte_eth_switch_domain_state {
5351 RTE_ETH_SWITCH_DOMAIN_UNUSED = 0,
5352 RTE_ETH_SWITCH_DOMAIN_ALLOCATED
5356 * Array of switch domains available for allocation. Array is sized to
5357 * RTE_MAX_ETHPORTS elements as there cannot be more active switch domains than
5358 * ethdev ports in a single process.
5360 static struct rte_eth_dev_switch {
5361 enum rte_eth_switch_domain_state state;
5362 } rte_eth_switch_domains[RTE_MAX_ETHPORTS];
5365 rte_eth_switch_domain_alloc(uint16_t *domain_id)
5369 *domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
5371 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
5372 if (rte_eth_switch_domains[i].state ==
5373 RTE_ETH_SWITCH_DOMAIN_UNUSED) {
5374 rte_eth_switch_domains[i].state =
5375 RTE_ETH_SWITCH_DOMAIN_ALLOCATED;
5385 rte_eth_switch_domain_free(uint16_t domain_id)
5387 if (domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID ||
5388 domain_id >= RTE_MAX_ETHPORTS)
5391 if (rte_eth_switch_domains[domain_id].state !=
5392 RTE_ETH_SWITCH_DOMAIN_ALLOCATED)
5395 rte_eth_switch_domains[domain_id].state = RTE_ETH_SWITCH_DOMAIN_UNUSED;
5401 rte_eth_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
5404 struct rte_kvargs_pair *pair;
5407 arglist->str = strdup(str_in);
5408 if (arglist->str == NULL)
5411 letter = arglist->str;
5414 pair = &arglist->pairs[0];
5417 case 0: /* Initial */
5420 else if (*letter == '\0')
5427 case 1: /* Parsing key */
5428 if (*letter == '=') {
5430 pair->value = letter + 1;
5432 } else if (*letter == ',' || *letter == '\0')
5437 case 2: /* Parsing value */
5440 else if (*letter == ',') {
5443 pair = &arglist->pairs[arglist->count];
5445 } else if (*letter == '\0') {
5448 pair = &arglist->pairs[arglist->count];
5453 case 3: /* Parsing list */
5456 else if (*letter == '\0')
5465 rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
5467 struct rte_kvargs args;
5468 struct rte_kvargs_pair *pair;
5472 memset(eth_da, 0, sizeof(*eth_da));
5474 result = rte_eth_devargs_tokenise(&args, dargs);
5478 for (i = 0; i < args.count; i++) {
5479 pair = &args.pairs[i];
5480 if (strcmp("representor", pair->key) == 0) {
5481 result = rte_eth_devargs_parse_list(pair->value,
5482 rte_eth_devargs_parse_representor_ports,
5497 handle_port_list(const char *cmd __rte_unused,
5498 const char *params __rte_unused,
5499 struct rte_tel_data *d)
5503 rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
5504 RTE_ETH_FOREACH_DEV(port_id)
5505 rte_tel_data_add_array_int(d, port_id);
5510 add_port_queue_stats(struct rte_tel_data *d, uint64_t *q_stats,
5511 const char *stat_name)
5514 struct rte_tel_data *q_data = rte_tel_data_alloc();
5515 rte_tel_data_start_array(q_data, RTE_TEL_U64_VAL);
5516 for (q = 0; q < RTE_ETHDEV_QUEUE_STAT_CNTRS; q++)
5517 rte_tel_data_add_array_u64(q_data, q_stats[q]);
5518 rte_tel_data_add_dict_container(d, stat_name, q_data, 0);
5521 #define ADD_DICT_STAT(stats, s) rte_tel_data_add_dict_u64(d, #s, stats.s)
5524 handle_port_stats(const char *cmd __rte_unused,
5526 struct rte_tel_data *d)
5528 struct rte_eth_stats stats;
5531 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
5534 port_id = atoi(params);
5535 if (!rte_eth_dev_is_valid_port(port_id))
5538 ret = rte_eth_stats_get(port_id, &stats);
5542 rte_tel_data_start_dict(d);
5543 ADD_DICT_STAT(stats, ipackets);
5544 ADD_DICT_STAT(stats, opackets);
5545 ADD_DICT_STAT(stats, ibytes);
5546 ADD_DICT_STAT(stats, obytes);
5547 ADD_DICT_STAT(stats, imissed);
5548 ADD_DICT_STAT(stats, ierrors);
5549 ADD_DICT_STAT(stats, oerrors);
5550 ADD_DICT_STAT(stats, rx_nombuf);
5551 add_port_queue_stats(d, stats.q_ipackets, "q_ipackets");
5552 add_port_queue_stats(d, stats.q_opackets, "q_opackets");
5553 add_port_queue_stats(d, stats.q_ibytes, "q_ibytes");
5554 add_port_queue_stats(d, stats.q_obytes, "q_obytes");
5555 add_port_queue_stats(d, stats.q_errors, "q_errors");
5561 handle_port_xstats(const char *cmd __rte_unused,
5563 struct rte_tel_data *d)
5565 struct rte_eth_xstat *eth_xstats;
5566 struct rte_eth_xstat_name *xstat_names;
5567 int port_id, num_xstats;
5571 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
5574 port_id = strtoul(params, &end_param, 0);
5575 if (*end_param != '\0')
5576 RTE_ETHDEV_LOG(NOTICE,
5577 "Extra parameters passed to ethdev telemetry command, ignoring");
5578 if (!rte_eth_dev_is_valid_port(port_id))
5581 num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
5585 /* use one malloc for both names and stats */
5586 eth_xstats = malloc((sizeof(struct rte_eth_xstat) +
5587 sizeof(struct rte_eth_xstat_name)) * num_xstats);
5588 if (eth_xstats == NULL)
5590 xstat_names = (void *)ð_xstats[num_xstats];
5592 ret = rte_eth_xstats_get_names(port_id, xstat_names, num_xstats);
5593 if (ret < 0 || ret > num_xstats) {
5598 ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
5599 if (ret < 0 || ret > num_xstats) {
5604 rte_tel_data_start_dict(d);
5605 for (i = 0; i < num_xstats; i++)
5606 rte_tel_data_add_dict_u64(d, xstat_names[i].name,
5607 eth_xstats[i].value);
5612 handle_port_link_status(const char *cmd __rte_unused,
5614 struct rte_tel_data *d)
5616 static const char *status_str = "status";
5618 struct rte_eth_link link;
5621 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
5624 port_id = strtoul(params, &end_param, 0);
5625 if (*end_param != '\0')
5626 RTE_ETHDEV_LOG(NOTICE,
5627 "Extra parameters passed to ethdev telemetry command, ignoring");
5628 if (!rte_eth_dev_is_valid_port(port_id))
5631 ret = rte_eth_link_get(port_id, &link);
5635 rte_tel_data_start_dict(d);
5636 if (!link.link_status) {
5637 rte_tel_data_add_dict_string(d, status_str, "DOWN");
5640 rte_tel_data_add_dict_string(d, status_str, "UP");
5641 rte_tel_data_add_dict_u64(d, "speed", link.link_speed);
5642 rte_tel_data_add_dict_string(d, "duplex",
5643 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
5644 "full-duplex" : "half-duplex");
5648 RTE_LOG_REGISTER(rte_eth_dev_logtype, lib.ethdev, INFO);
5650 RTE_INIT(ethdev_init_telemetry)
5652 rte_telemetry_register_cmd("/ethdev/list", handle_port_list,
5653 "Returns list of available ethdev ports. Takes no parameters");
5654 rte_telemetry_register_cmd("/ethdev/stats", handle_port_stats,
5655 "Returns the common stats for a port. Parameters: int port_id");
5656 rte_telemetry_register_cmd("/ethdev/xstats", handle_port_xstats,
5657 "Returns the extended stats for a port. Parameters: int port_id");
5658 rte_telemetry_register_cmd("/ethdev/link_status",
5659 handle_port_link_status,
5660 "Returns the link status for a port. Parameters: int port_id");