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_atomic.h>
30 #include <rte_branch_prediction.h>
31 #include <rte_common.h>
32 #include <rte_mempool.h>
33 #include <rte_malloc.h>
35 #include <rte_errno.h>
36 #include <rte_spinlock.h>
37 #include <rte_string_fns.h>
38 #include <rte_kvargs.h>
39 #include <rte_class.h>
40 #include <rte_ether.h>
41 #include <rte_telemetry.h>
43 #include "rte_ethdev_trace.h"
44 #include "rte_ethdev.h"
45 #include "rte_ethdev_driver.h"
46 #include "ethdev_profile.h"
47 #include "ethdev_private.h"
49 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
50 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
52 /* spinlock for eth device callbacks */
53 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
55 /* spinlock for add/remove rx callbacks */
56 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
58 /* spinlock for add/remove tx callbacks */
59 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
61 /* spinlock for shared data allocation */
62 static rte_spinlock_t rte_eth_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
64 /* store statistics names and its offset in stats structure */
65 struct rte_eth_xstats_name_off {
66 char name[RTE_ETH_XSTATS_NAME_SIZE];
70 /* Shared memory between primary and secondary processes. */
72 uint64_t next_owner_id;
73 rte_spinlock_t ownership_lock;
74 struct rte_eth_dev_data data[RTE_MAX_ETHPORTS];
75 } *rte_eth_dev_shared_data;
77 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
78 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
79 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
80 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
81 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
82 {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
83 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
84 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
85 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
89 #define RTE_NB_STATS RTE_DIM(rte_stats_strings)
91 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
92 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
93 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
94 {"errors", offsetof(struct rte_eth_stats, q_errors)},
97 #define RTE_NB_RXQ_STATS RTE_DIM(rte_rxq_stats_strings)
99 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
100 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
101 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
103 #define RTE_NB_TXQ_STATS RTE_DIM(rte_txq_stats_strings)
105 #define RTE_RX_OFFLOAD_BIT2STR(_name) \
106 { DEV_RX_OFFLOAD_##_name, #_name }
108 static const struct {
111 } rte_rx_offload_names[] = {
112 RTE_RX_OFFLOAD_BIT2STR(VLAN_STRIP),
113 RTE_RX_OFFLOAD_BIT2STR(IPV4_CKSUM),
114 RTE_RX_OFFLOAD_BIT2STR(UDP_CKSUM),
115 RTE_RX_OFFLOAD_BIT2STR(TCP_CKSUM),
116 RTE_RX_OFFLOAD_BIT2STR(TCP_LRO),
117 RTE_RX_OFFLOAD_BIT2STR(QINQ_STRIP),
118 RTE_RX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
119 RTE_RX_OFFLOAD_BIT2STR(MACSEC_STRIP),
120 RTE_RX_OFFLOAD_BIT2STR(HEADER_SPLIT),
121 RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
122 RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
123 RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
124 RTE_RX_OFFLOAD_BIT2STR(SCATTER),
125 RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
126 RTE_RX_OFFLOAD_BIT2STR(SECURITY),
127 RTE_RX_OFFLOAD_BIT2STR(KEEP_CRC),
128 RTE_RX_OFFLOAD_BIT2STR(SCTP_CKSUM),
129 RTE_RX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
130 RTE_RX_OFFLOAD_BIT2STR(RSS_HASH),
133 #undef RTE_RX_OFFLOAD_BIT2STR
135 #define RTE_TX_OFFLOAD_BIT2STR(_name) \
136 { DEV_TX_OFFLOAD_##_name, #_name }
138 static const struct {
141 } rte_tx_offload_names[] = {
142 RTE_TX_OFFLOAD_BIT2STR(VLAN_INSERT),
143 RTE_TX_OFFLOAD_BIT2STR(IPV4_CKSUM),
144 RTE_TX_OFFLOAD_BIT2STR(UDP_CKSUM),
145 RTE_TX_OFFLOAD_BIT2STR(TCP_CKSUM),
146 RTE_TX_OFFLOAD_BIT2STR(SCTP_CKSUM),
147 RTE_TX_OFFLOAD_BIT2STR(TCP_TSO),
148 RTE_TX_OFFLOAD_BIT2STR(UDP_TSO),
149 RTE_TX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
150 RTE_TX_OFFLOAD_BIT2STR(QINQ_INSERT),
151 RTE_TX_OFFLOAD_BIT2STR(VXLAN_TNL_TSO),
152 RTE_TX_OFFLOAD_BIT2STR(GRE_TNL_TSO),
153 RTE_TX_OFFLOAD_BIT2STR(IPIP_TNL_TSO),
154 RTE_TX_OFFLOAD_BIT2STR(GENEVE_TNL_TSO),
155 RTE_TX_OFFLOAD_BIT2STR(MACSEC_INSERT),
156 RTE_TX_OFFLOAD_BIT2STR(MT_LOCKFREE),
157 RTE_TX_OFFLOAD_BIT2STR(MULTI_SEGS),
158 RTE_TX_OFFLOAD_BIT2STR(MBUF_FAST_FREE),
159 RTE_TX_OFFLOAD_BIT2STR(SECURITY),
160 RTE_TX_OFFLOAD_BIT2STR(UDP_TNL_TSO),
161 RTE_TX_OFFLOAD_BIT2STR(IP_TNL_TSO),
162 RTE_TX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
163 RTE_TX_OFFLOAD_BIT2STR(SEND_ON_TIMESTAMP),
166 #undef RTE_TX_OFFLOAD_BIT2STR
169 * The user application callback description.
171 * It contains callback address to be registered by user application,
172 * the pointer to the parameters for callback, and the event type.
174 struct rte_eth_dev_callback {
175 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
176 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
177 void *cb_arg; /**< Parameter for callback */
178 void *ret_param; /**< Return parameter */
179 enum rte_eth_event_type event; /**< Interrupt event type */
180 uint32_t active; /**< Callback is executing */
189 rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
192 struct rte_devargs devargs = {.args = NULL};
193 const char *bus_param_key;
194 char *bus_str = NULL;
195 char *cls_str = NULL;
198 memset(iter, 0, sizeof(*iter));
201 * The devargs string may use various syntaxes:
202 * - 0000:08:00.0,representor=[1-3]
203 * - pci:0000:06:00.0,representor=[0,5]
204 * - class=eth,mac=00:11:22:33:44:55
205 * A new syntax is in development (not yet supported):
206 * - bus=X,paramX=x/class=Y,paramY=y/driver=Z,paramZ=z
210 * Handle pure class filter (i.e. without any bus-level argument),
211 * from future new syntax.
212 * rte_devargs_parse() is not yet supporting the new syntax,
213 * that's why this simple case is temporarily parsed here.
215 #define iter_anybus_str "class=eth,"
216 if (strncmp(devargs_str, iter_anybus_str,
217 strlen(iter_anybus_str)) == 0) {
218 iter->cls_str = devargs_str + strlen(iter_anybus_str);
222 /* Split bus, device and parameters. */
223 ret = rte_devargs_parse(&devargs, devargs_str);
228 * Assume parameters of old syntax can match only at ethdev level.
229 * Extra parameters will be ignored, thanks to "+" prefix.
231 str_size = strlen(devargs.args) + 2;
232 cls_str = malloc(str_size);
233 if (cls_str == NULL) {
237 ret = snprintf(cls_str, str_size, "+%s", devargs.args);
238 if (ret != str_size - 1) {
242 iter->cls_str = cls_str;
243 free(devargs.args); /* allocated by rte_devargs_parse() */
246 iter->bus = devargs.bus;
247 if (iter->bus->dev_iterate == NULL) {
252 /* Convert bus args to new syntax for use with new API dev_iterate. */
253 if (strcmp(iter->bus->name, "vdev") == 0) {
254 bus_param_key = "name";
255 } else if (strcmp(iter->bus->name, "pci") == 0) {
256 bus_param_key = "addr";
261 str_size = strlen(bus_param_key) + strlen(devargs.name) + 2;
262 bus_str = malloc(str_size);
263 if (bus_str == NULL) {
267 ret = snprintf(bus_str, str_size, "%s=%s",
268 bus_param_key, devargs.name);
269 if (ret != str_size - 1) {
273 iter->bus_str = bus_str;
276 iter->cls = rte_class_find_by_name("eth");
281 RTE_ETHDEV_LOG(ERR, "Bus %s does not support iterating.\n",
290 rte_eth_iterator_next(struct rte_dev_iterator *iter)
292 if (iter->cls == NULL) /* invalid ethdev iterator */
293 return RTE_MAX_ETHPORTS;
295 do { /* loop to try all matching rte_device */
296 /* If not pure ethdev filter and */
297 if (iter->bus != NULL &&
298 /* not in middle of rte_eth_dev iteration, */
299 iter->class_device == NULL) {
300 /* get next rte_device to try. */
301 iter->device = iter->bus->dev_iterate(
302 iter->device, iter->bus_str, iter);
303 if (iter->device == NULL)
304 break; /* no more rte_device candidate */
306 /* A device is matching bus part, need to check ethdev part. */
307 iter->class_device = iter->cls->dev_iterate(
308 iter->class_device, iter->cls_str, iter);
309 if (iter->class_device != NULL)
310 return eth_dev_to_id(iter->class_device); /* match */
311 } while (iter->bus != NULL); /* need to try next rte_device */
313 /* No more ethdev port to iterate. */
314 rte_eth_iterator_cleanup(iter);
315 return RTE_MAX_ETHPORTS;
319 rte_eth_iterator_cleanup(struct rte_dev_iterator *iter)
321 if (iter->bus_str == NULL)
322 return; /* nothing to free in pure class filter */
323 free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */
324 free(RTE_CAST_FIELD(iter, cls_str, char *)); /* workaround const */
325 memset(iter, 0, sizeof(*iter));
329 rte_eth_find_next(uint16_t port_id)
331 while (port_id < RTE_MAX_ETHPORTS &&
332 rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)
335 if (port_id >= RTE_MAX_ETHPORTS)
336 return RTE_MAX_ETHPORTS;
342 * Macro to iterate over all valid ports for internal usage.
343 * Note: RTE_ETH_FOREACH_DEV is different because filtering owned ports.
345 #define RTE_ETH_FOREACH_VALID_DEV(port_id) \
346 for (port_id = rte_eth_find_next(0); \
347 port_id < RTE_MAX_ETHPORTS; \
348 port_id = rte_eth_find_next(port_id + 1))
351 rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
353 port_id = rte_eth_find_next(port_id);
354 while (port_id < RTE_MAX_ETHPORTS &&
355 rte_eth_devices[port_id].device != parent)
356 port_id = rte_eth_find_next(port_id + 1);
362 rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id)
364 RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS);
365 return rte_eth_find_next_of(port_id,
366 rte_eth_devices[ref_port_id].device);
370 rte_eth_dev_shared_data_prepare(void)
372 const unsigned flags = 0;
373 const struct rte_memzone *mz;
375 rte_spinlock_lock(&rte_eth_shared_data_lock);
377 if (rte_eth_dev_shared_data == NULL) {
378 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
379 /* Allocate port data and ownership shared memory. */
380 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
381 sizeof(*rte_eth_dev_shared_data),
382 rte_socket_id(), flags);
384 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
386 rte_panic("Cannot allocate ethdev shared data\n");
388 rte_eth_dev_shared_data = mz->addr;
389 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
390 rte_eth_dev_shared_data->next_owner_id =
391 RTE_ETH_DEV_NO_OWNER + 1;
392 rte_spinlock_init(&rte_eth_dev_shared_data->ownership_lock);
393 memset(rte_eth_dev_shared_data->data, 0,
394 sizeof(rte_eth_dev_shared_data->data));
398 rte_spinlock_unlock(&rte_eth_shared_data_lock);
402 is_allocated(const struct rte_eth_dev *ethdev)
404 return ethdev->data->name[0] != '\0';
407 static struct rte_eth_dev *
408 _rte_eth_dev_allocated(const char *name)
412 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
413 if (rte_eth_devices[i].data != NULL &&
414 strcmp(rte_eth_devices[i].data->name, name) == 0)
415 return &rte_eth_devices[i];
421 rte_eth_dev_allocated(const char *name)
423 struct rte_eth_dev *ethdev;
425 rte_eth_dev_shared_data_prepare();
427 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
429 ethdev = _rte_eth_dev_allocated(name);
431 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
437 rte_eth_dev_find_free_port(void)
441 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
442 /* Using shared name field to find a free port. */
443 if (rte_eth_dev_shared_data->data[i].name[0] == '\0') {
444 RTE_ASSERT(rte_eth_devices[i].state ==
449 return RTE_MAX_ETHPORTS;
452 static struct rte_eth_dev *
453 eth_dev_get(uint16_t port_id)
455 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
457 eth_dev->data = &rte_eth_dev_shared_data->data[port_id];
463 rte_eth_dev_allocate(const char *name)
466 struct rte_eth_dev *eth_dev = NULL;
469 name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN);
471 RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n");
475 if (name_len >= RTE_ETH_NAME_MAX_LEN) {
476 RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n");
480 rte_eth_dev_shared_data_prepare();
482 /* Synchronize port creation between primary and secondary threads. */
483 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
485 if (_rte_eth_dev_allocated(name) != NULL) {
487 "Ethernet device with name %s already allocated\n",
492 port_id = rte_eth_dev_find_free_port();
493 if (port_id == RTE_MAX_ETHPORTS) {
495 "Reached maximum number of Ethernet ports\n");
499 eth_dev = eth_dev_get(port_id);
500 strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
501 eth_dev->data->port_id = port_id;
502 eth_dev->data->mtu = RTE_ETHER_MTU;
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 memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
570 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
576 rte_eth_dev_is_valid_port(uint16_t port_id)
578 if (port_id >= RTE_MAX_ETHPORTS ||
579 (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED))
586 rte_eth_is_valid_owner_id(uint64_t owner_id)
588 if (owner_id == RTE_ETH_DEV_NO_OWNER ||
589 rte_eth_dev_shared_data->next_owner_id <= owner_id)
595 rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
597 port_id = rte_eth_find_next(port_id);
598 while (port_id < RTE_MAX_ETHPORTS &&
599 rte_eth_devices[port_id].data->owner.id != owner_id)
600 port_id = rte_eth_find_next(port_id + 1);
606 rte_eth_dev_owner_new(uint64_t *owner_id)
608 rte_eth_dev_shared_data_prepare();
610 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
612 *owner_id = rte_eth_dev_shared_data->next_owner_id++;
614 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
619 _rte_eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id,
620 const struct rte_eth_dev_owner *new_owner)
622 struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
623 struct rte_eth_dev_owner *port_owner;
625 if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) {
626 RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
631 if (!rte_eth_is_valid_owner_id(new_owner->id) &&
632 !rte_eth_is_valid_owner_id(old_owner_id)) {
634 "Invalid owner old_id=%016"PRIx64" new_id=%016"PRIx64"\n",
635 old_owner_id, new_owner->id);
639 port_owner = &rte_eth_devices[port_id].data->owner;
640 if (port_owner->id != old_owner_id) {
642 "Cannot set owner to port %u already owned by %s_%016"PRIX64"\n",
643 port_id, port_owner->name, port_owner->id);
647 /* can not truncate (same structure) */
648 strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN);
650 port_owner->id = new_owner->id;
652 RTE_ETHDEV_LOG(DEBUG, "Port %u owner is %s_%016"PRIx64"\n",
653 port_id, new_owner->name, new_owner->id);
659 rte_eth_dev_owner_set(const uint16_t port_id,
660 const struct rte_eth_dev_owner *owner)
664 rte_eth_dev_shared_data_prepare();
666 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
668 ret = _rte_eth_dev_owner_set(port_id, RTE_ETH_DEV_NO_OWNER, owner);
670 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
675 rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id)
677 const struct rte_eth_dev_owner new_owner = (struct rte_eth_dev_owner)
678 {.id = RTE_ETH_DEV_NO_OWNER, .name = ""};
681 rte_eth_dev_shared_data_prepare();
683 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
685 ret = _rte_eth_dev_owner_set(port_id, owner_id, &new_owner);
687 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
692 rte_eth_dev_owner_delete(const uint64_t owner_id)
697 rte_eth_dev_shared_data_prepare();
699 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
701 if (rte_eth_is_valid_owner_id(owner_id)) {
702 for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++)
703 if (rte_eth_devices[port_id].data->owner.id == owner_id)
704 memset(&rte_eth_devices[port_id].data->owner, 0,
705 sizeof(struct rte_eth_dev_owner));
706 RTE_ETHDEV_LOG(NOTICE,
707 "All port owners owned by %016"PRIx64" identifier have removed\n",
711 "Invalid owner id=%016"PRIx64"\n",
716 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
722 rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
725 struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
727 rte_eth_dev_shared_data_prepare();
729 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
731 if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) {
732 RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
736 rte_memcpy(owner, ðdev->data->owner, sizeof(*owner));
739 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
744 rte_eth_dev_socket_id(uint16_t port_id)
746 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
747 return rte_eth_devices[port_id].data->numa_node;
751 rte_eth_dev_get_sec_ctx(uint16_t port_id)
753 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
754 return rte_eth_devices[port_id].security_ctx;
758 rte_eth_dev_count_avail(void)
765 RTE_ETH_FOREACH_DEV(p)
772 rte_eth_dev_count_total(void)
774 uint16_t port, count = 0;
776 RTE_ETH_FOREACH_VALID_DEV(port)
783 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
787 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
790 RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
794 /* shouldn't check 'rte_eth_devices[i].data',
795 * because it might be overwritten by VDEV PMD */
796 tmp = rte_eth_dev_shared_data->data[port_id].name;
802 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
807 RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
811 RTE_ETH_FOREACH_VALID_DEV(pid)
812 if (!strcmp(name, rte_eth_dev_shared_data->data[pid].name)) {
821 eth_err(uint16_t port_id, int ret)
825 if (rte_eth_dev_is_removed(port_id))
831 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
833 uint16_t old_nb_queues = dev->data->nb_rx_queues;
837 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
838 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
839 sizeof(dev->data->rx_queues[0]) * nb_queues,
840 RTE_CACHE_LINE_SIZE);
841 if (dev->data->rx_queues == NULL) {
842 dev->data->nb_rx_queues = 0;
845 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
846 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
848 rxq = dev->data->rx_queues;
850 for (i = nb_queues; i < old_nb_queues; i++)
851 (*dev->dev_ops->rx_queue_release)(rxq[i]);
852 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
853 RTE_CACHE_LINE_SIZE);
856 if (nb_queues > old_nb_queues) {
857 uint16_t new_qs = nb_queues - old_nb_queues;
859 memset(rxq + old_nb_queues, 0,
860 sizeof(rxq[0]) * new_qs);
863 dev->data->rx_queues = rxq;
865 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
866 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
868 rxq = dev->data->rx_queues;
870 for (i = nb_queues; i < old_nb_queues; i++)
871 (*dev->dev_ops->rx_queue_release)(rxq[i]);
873 rte_free(dev->data->rx_queues);
874 dev->data->rx_queues = NULL;
876 dev->data->nb_rx_queues = nb_queues;
881 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
883 struct rte_eth_dev *dev;
885 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
887 dev = &rte_eth_devices[port_id];
888 if (!dev->data->dev_started) {
890 "Port %u must be started before start any queue\n",
895 if (rx_queue_id >= dev->data->nb_rx_queues) {
896 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
900 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
902 if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) {
904 "Can't start Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n",
905 rx_queue_id, port_id);
909 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
911 "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n",
912 rx_queue_id, port_id);
916 return eth_err(port_id, dev->dev_ops->rx_queue_start(dev,
922 rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
924 struct rte_eth_dev *dev;
926 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
928 dev = &rte_eth_devices[port_id];
929 if (rx_queue_id >= dev->data->nb_rx_queues) {
930 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
934 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
936 if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) {
938 "Can't stop Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n",
939 rx_queue_id, port_id);
943 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
945 "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n",
946 rx_queue_id, port_id);
950 return eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id));
955 rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
957 struct rte_eth_dev *dev;
959 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
961 dev = &rte_eth_devices[port_id];
962 if (!dev->data->dev_started) {
964 "Port %u must be started before start any queue\n",
969 if (tx_queue_id >= dev->data->nb_tx_queues) {
970 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
974 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
976 if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) {
978 "Can't start Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n",
979 tx_queue_id, port_id);
983 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
985 "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n",
986 tx_queue_id, port_id);
990 return eth_err(port_id, dev->dev_ops->tx_queue_start(dev, tx_queue_id));
994 rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
996 struct rte_eth_dev *dev;
998 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1000 dev = &rte_eth_devices[port_id];
1001 if (tx_queue_id >= dev->data->nb_tx_queues) {
1002 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
1006 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
1008 if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) {
1009 RTE_ETHDEV_LOG(INFO,
1010 "Can't stop Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n",
1011 tx_queue_id, port_id);
1015 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
1016 RTE_ETHDEV_LOG(INFO,
1017 "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n",
1018 tx_queue_id, port_id);
1022 return eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id));
1027 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
1029 uint16_t old_nb_queues = dev->data->nb_tx_queues;
1033 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
1034 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
1035 sizeof(dev->data->tx_queues[0]) * nb_queues,
1036 RTE_CACHE_LINE_SIZE);
1037 if (dev->data->tx_queues == NULL) {
1038 dev->data->nb_tx_queues = 0;
1041 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
1042 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
1044 txq = dev->data->tx_queues;
1046 for (i = nb_queues; i < old_nb_queues; i++)
1047 (*dev->dev_ops->tx_queue_release)(txq[i]);
1048 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
1049 RTE_CACHE_LINE_SIZE);
1052 if (nb_queues > old_nb_queues) {
1053 uint16_t new_qs = nb_queues - old_nb_queues;
1055 memset(txq + old_nb_queues, 0,
1056 sizeof(txq[0]) * new_qs);
1059 dev->data->tx_queues = txq;
1061 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
1062 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
1064 txq = dev->data->tx_queues;
1066 for (i = nb_queues; i < old_nb_queues; i++)
1067 (*dev->dev_ops->tx_queue_release)(txq[i]);
1069 rte_free(dev->data->tx_queues);
1070 dev->data->tx_queues = NULL;
1072 dev->data->nb_tx_queues = nb_queues;
1077 rte_eth_speed_bitflag(uint32_t speed, int duplex)
1080 case ETH_SPEED_NUM_10M:
1081 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
1082 case ETH_SPEED_NUM_100M:
1083 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
1084 case ETH_SPEED_NUM_1G:
1085 return ETH_LINK_SPEED_1G;
1086 case ETH_SPEED_NUM_2_5G:
1087 return ETH_LINK_SPEED_2_5G;
1088 case ETH_SPEED_NUM_5G:
1089 return ETH_LINK_SPEED_5G;
1090 case ETH_SPEED_NUM_10G:
1091 return ETH_LINK_SPEED_10G;
1092 case ETH_SPEED_NUM_20G:
1093 return ETH_LINK_SPEED_20G;
1094 case ETH_SPEED_NUM_25G:
1095 return ETH_LINK_SPEED_25G;
1096 case ETH_SPEED_NUM_40G:
1097 return ETH_LINK_SPEED_40G;
1098 case ETH_SPEED_NUM_50G:
1099 return ETH_LINK_SPEED_50G;
1100 case ETH_SPEED_NUM_56G:
1101 return ETH_LINK_SPEED_56G;
1102 case ETH_SPEED_NUM_100G:
1103 return ETH_LINK_SPEED_100G;
1104 case ETH_SPEED_NUM_200G:
1105 return ETH_LINK_SPEED_200G;
1112 rte_eth_dev_rx_offload_name(uint64_t offload)
1114 const char *name = "UNKNOWN";
1117 for (i = 0; i < RTE_DIM(rte_rx_offload_names); ++i) {
1118 if (offload == rte_rx_offload_names[i].offload) {
1119 name = rte_rx_offload_names[i].name;
1128 rte_eth_dev_tx_offload_name(uint64_t offload)
1130 const char *name = "UNKNOWN";
1133 for (i = 0; i < RTE_DIM(rte_tx_offload_names); ++i) {
1134 if (offload == rte_tx_offload_names[i].offload) {
1135 name = rte_tx_offload_names[i].name;
1144 check_lro_pkt_size(uint16_t port_id, uint32_t config_size,
1145 uint32_t max_rx_pkt_len, uint32_t dev_info_size)
1149 if (dev_info_size == 0) {
1150 if (config_size != max_rx_pkt_len) {
1151 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size"
1152 " %u != %u is not allowed\n",
1153 port_id, config_size, max_rx_pkt_len);
1156 } else if (config_size > dev_info_size) {
1157 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size %u "
1158 "> max allowed value %u\n", port_id, config_size,
1161 } else if (config_size < RTE_ETHER_MIN_LEN) {
1162 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size %u "
1163 "< min allowed value %u\n", port_id, config_size,
1164 (unsigned int)RTE_ETHER_MIN_LEN);
1171 * Validate offloads that are requested through rte_eth_dev_configure against
1172 * the offloads successfully set by the ethernet device.
1175 * The port identifier of the Ethernet device.
1176 * @param req_offloads
1177 * The offloads that have been requested through `rte_eth_dev_configure`.
1178 * @param set_offloads
1179 * The offloads successfully set by the ethernet device.
1180 * @param offload_type
1181 * The offload type i.e. Rx/Tx string.
1182 * @param offload_name
1183 * The function that prints the offload name.
1185 * - (0) if validation successful.
1186 * - (-EINVAL) if requested offload has been silently disabled.
1190 validate_offloads(uint16_t port_id, uint64_t req_offloads,
1191 uint64_t set_offloads, const char *offload_type,
1192 const char *(*offload_name)(uint64_t))
1194 uint64_t offloads_diff = req_offloads ^ set_offloads;
1198 while (offloads_diff != 0) {
1199 /* Check if any offload is requested but not enabled. */
1200 offload = 1ULL << __builtin_ctzll(offloads_diff);
1201 if (offload & req_offloads) {
1203 "Port %u failed to enable %s offload %s\n",
1204 port_id, offload_type, offload_name(offload));
1208 /* Check if offload couldn't be disabled. */
1209 if (offload & set_offloads) {
1210 RTE_ETHDEV_LOG(DEBUG,
1211 "Port %u %s offload %s is not requested but enabled\n",
1212 port_id, offload_type, offload_name(offload));
1215 offloads_diff &= ~offload;
1222 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1223 const struct rte_eth_conf *dev_conf)
1225 struct rte_eth_dev *dev;
1226 struct rte_eth_dev_info dev_info;
1227 struct rte_eth_conf orig_conf;
1231 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1233 dev = &rte_eth_devices[port_id];
1235 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1237 if (dev->data->dev_started) {
1239 "Port %u must be stopped to allow configuration\n",
1244 /* Store original config, as rollback required on failure */
1245 memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf));
1248 * Copy the dev_conf parameter into the dev structure.
1249 * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get
1251 if (dev_conf != &dev->data->dev_conf)
1252 memcpy(&dev->data->dev_conf, dev_conf,
1253 sizeof(dev->data->dev_conf));
1255 ret = rte_eth_dev_info_get(port_id, &dev_info);
1259 /* If number of queues specified by application for both Rx and Tx is
1260 * zero, use driver preferred values. This cannot be done individually
1261 * as it is valid for either Tx or Rx (but not both) to be zero.
1262 * If driver does not provide any preferred valued, fall back on
1265 if (nb_rx_q == 0 && nb_tx_q == 0) {
1266 nb_rx_q = dev_info.default_rxportconf.nb_queues;
1268 nb_rx_q = RTE_ETH_DEV_FALLBACK_RX_NBQUEUES;
1269 nb_tx_q = dev_info.default_txportconf.nb_queues;
1271 nb_tx_q = RTE_ETH_DEV_FALLBACK_TX_NBQUEUES;
1274 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1276 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
1277 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1282 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1284 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
1285 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1291 * Check that the numbers of RX and TX queues are not greater
1292 * than the maximum number of RX and TX queues supported by the
1293 * configured device.
1295 if (nb_rx_q > dev_info.max_rx_queues) {
1296 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_rx_queues=%u > %u\n",
1297 port_id, nb_rx_q, dev_info.max_rx_queues);
1302 if (nb_tx_q > dev_info.max_tx_queues) {
1303 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_tx_queues=%u > %u\n",
1304 port_id, nb_tx_q, dev_info.max_tx_queues);
1309 /* Check that the device supports requested interrupts */
1310 if ((dev_conf->intr_conf.lsc == 1) &&
1311 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
1312 RTE_ETHDEV_LOG(ERR, "Driver %s does not support lsc\n",
1313 dev->device->driver->name);
1317 if ((dev_conf->intr_conf.rmv == 1) &&
1318 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
1319 RTE_ETHDEV_LOG(ERR, "Driver %s does not support rmv\n",
1320 dev->device->driver->name);
1326 * If jumbo frames are enabled, check that the maximum RX packet
1327 * length is supported by the configured device.
1329 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1330 if (dev_conf->rxmode.max_rx_pkt_len > dev_info.max_rx_pktlen) {
1332 "Ethdev port_id=%u max_rx_pkt_len %u > max valid value %u\n",
1333 port_id, dev_conf->rxmode.max_rx_pkt_len,
1334 dev_info.max_rx_pktlen);
1337 } else if (dev_conf->rxmode.max_rx_pkt_len < RTE_ETHER_MIN_LEN) {
1339 "Ethdev port_id=%u max_rx_pkt_len %u < min valid value %u\n",
1340 port_id, dev_conf->rxmode.max_rx_pkt_len,
1341 (unsigned int)RTE_ETHER_MIN_LEN);
1346 if (dev_conf->rxmode.max_rx_pkt_len < RTE_ETHER_MIN_LEN ||
1347 dev_conf->rxmode.max_rx_pkt_len > RTE_ETHER_MAX_LEN)
1348 /* Use default value */
1349 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1354 * If LRO is enabled, check that the maximum aggregated packet
1355 * size is supported by the configured device.
1357 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_TCP_LRO) {
1358 if (dev_conf->rxmode.max_lro_pkt_size == 0)
1359 dev->data->dev_conf.rxmode.max_lro_pkt_size =
1360 dev->data->dev_conf.rxmode.max_rx_pkt_len;
1361 ret = check_lro_pkt_size(port_id,
1362 dev->data->dev_conf.rxmode.max_lro_pkt_size,
1363 dev->data->dev_conf.rxmode.max_rx_pkt_len,
1364 dev_info.max_lro_pkt_size);
1369 /* Any requested offloading must be within its device capabilities */
1370 if ((dev_conf->rxmode.offloads & dev_info.rx_offload_capa) !=
1371 dev_conf->rxmode.offloads) {
1373 "Ethdev port_id=%u requested Rx offloads 0x%"PRIx64" doesn't match Rx offloads "
1374 "capabilities 0x%"PRIx64" in %s()\n",
1375 port_id, dev_conf->rxmode.offloads,
1376 dev_info.rx_offload_capa,
1381 if ((dev_conf->txmode.offloads & dev_info.tx_offload_capa) !=
1382 dev_conf->txmode.offloads) {
1384 "Ethdev port_id=%u requested Tx offloads 0x%"PRIx64" doesn't match Tx offloads "
1385 "capabilities 0x%"PRIx64" in %s()\n",
1386 port_id, dev_conf->txmode.offloads,
1387 dev_info.tx_offload_capa,
1393 dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf =
1394 rte_eth_rss_hf_refine(dev_conf->rx_adv_conf.rss_conf.rss_hf);
1396 /* Check that device supports requested rss hash functions. */
1397 if ((dev_info.flow_type_rss_offloads |
1398 dev_conf->rx_adv_conf.rss_conf.rss_hf) !=
1399 dev_info.flow_type_rss_offloads) {
1401 "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n",
1402 port_id, dev_conf->rx_adv_conf.rss_conf.rss_hf,
1403 dev_info.flow_type_rss_offloads);
1408 /* Check if Rx RSS distribution is disabled but RSS hash is enabled. */
1409 if (((dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) == 0) &&
1410 (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_RSS_HASH)) {
1412 "Ethdev port_id=%u config invalid Rx mq_mode without RSS but %s offload is requested\n",
1414 rte_eth_dev_rx_offload_name(DEV_RX_OFFLOAD_RSS_HASH));
1420 * Setup new number of RX/TX queues and reconfigure device.
1422 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1425 "Port%u rte_eth_dev_rx_queue_config = %d\n",
1431 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1434 "Port%u rte_eth_dev_tx_queue_config = %d\n",
1436 rte_eth_dev_rx_queue_config(dev, 0);
1441 diag = (*dev->dev_ops->dev_configure)(dev);
1443 RTE_ETHDEV_LOG(ERR, "Port%u dev_configure = %d\n",
1445 ret = eth_err(port_id, diag);
1449 /* Initialize Rx profiling if enabled at compilation time. */
1450 diag = __rte_eth_dev_profile_init(port_id, dev);
1452 RTE_ETHDEV_LOG(ERR, "Port%u __rte_eth_dev_profile_init = %d\n",
1454 ret = eth_err(port_id, diag);
1458 /* Validate Rx offloads. */
1459 diag = validate_offloads(port_id,
1460 dev_conf->rxmode.offloads,
1461 dev->data->dev_conf.rxmode.offloads, "Rx",
1462 rte_eth_dev_rx_offload_name);
1468 /* Validate Tx offloads. */
1469 diag = validate_offloads(port_id,
1470 dev_conf->txmode.offloads,
1471 dev->data->dev_conf.txmode.offloads, "Tx",
1472 rte_eth_dev_tx_offload_name);
1478 rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0);
1481 rte_eth_dev_rx_queue_config(dev, 0);
1482 rte_eth_dev_tx_queue_config(dev, 0);
1484 memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf));
1486 rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret);
1491 rte_eth_dev_internal_reset(struct rte_eth_dev *dev)
1493 if (dev->data->dev_started) {
1494 RTE_ETHDEV_LOG(ERR, "Port %u must be stopped to allow reset\n",
1495 dev->data->port_id);
1499 rte_eth_dev_rx_queue_config(dev, 0);
1500 rte_eth_dev_tx_queue_config(dev, 0);
1502 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
1506 rte_eth_dev_mac_restore(struct rte_eth_dev *dev,
1507 struct rte_eth_dev_info *dev_info)
1509 struct rte_ether_addr *addr;
1514 /* replay MAC address configuration including default MAC */
1515 addr = &dev->data->mac_addrs[0];
1516 if (*dev->dev_ops->mac_addr_set != NULL)
1517 (*dev->dev_ops->mac_addr_set)(dev, addr);
1518 else if (*dev->dev_ops->mac_addr_add != NULL)
1519 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
1521 if (*dev->dev_ops->mac_addr_add != NULL) {
1522 for (i = 1; i < dev_info->max_mac_addrs; i++) {
1523 addr = &dev->data->mac_addrs[i];
1525 /* skip zero address */
1526 if (rte_is_zero_ether_addr(addr))
1530 pool_mask = dev->data->mac_pool_sel[i];
1533 if (pool_mask & 1ULL)
1534 (*dev->dev_ops->mac_addr_add)(dev,
1538 } while (pool_mask);
1544 rte_eth_dev_config_restore(struct rte_eth_dev *dev,
1545 struct rte_eth_dev_info *dev_info, uint16_t port_id)
1549 if (!(*dev_info->dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR))
1550 rte_eth_dev_mac_restore(dev, dev_info);
1552 /* replay promiscuous configuration */
1554 * use callbacks directly since we don't need port_id check and
1555 * would like to bypass the same value set
1557 if (rte_eth_promiscuous_get(port_id) == 1 &&
1558 *dev->dev_ops->promiscuous_enable != NULL) {
1559 ret = eth_err(port_id,
1560 (*dev->dev_ops->promiscuous_enable)(dev));
1561 if (ret != 0 && ret != -ENOTSUP) {
1563 "Failed to enable promiscuous mode for device (port %u): %s\n",
1564 port_id, rte_strerror(-ret));
1567 } else if (rte_eth_promiscuous_get(port_id) == 0 &&
1568 *dev->dev_ops->promiscuous_disable != NULL) {
1569 ret = eth_err(port_id,
1570 (*dev->dev_ops->promiscuous_disable)(dev));
1571 if (ret != 0 && ret != -ENOTSUP) {
1573 "Failed to disable promiscuous mode for device (port %u): %s\n",
1574 port_id, rte_strerror(-ret));
1579 /* replay all multicast configuration */
1581 * use callbacks directly since we don't need port_id check and
1582 * would like to bypass the same value set
1584 if (rte_eth_allmulticast_get(port_id) == 1 &&
1585 *dev->dev_ops->allmulticast_enable != NULL) {
1586 ret = eth_err(port_id,
1587 (*dev->dev_ops->allmulticast_enable)(dev));
1588 if (ret != 0 && ret != -ENOTSUP) {
1590 "Failed to enable allmulticast mode for device (port %u): %s\n",
1591 port_id, rte_strerror(-ret));
1594 } else if (rte_eth_allmulticast_get(port_id) == 0 &&
1595 *dev->dev_ops->allmulticast_disable != NULL) {
1596 ret = eth_err(port_id,
1597 (*dev->dev_ops->allmulticast_disable)(dev));
1598 if (ret != 0 && ret != -ENOTSUP) {
1600 "Failed to disable allmulticast mode for device (port %u): %s\n",
1601 port_id, rte_strerror(-ret));
1610 rte_eth_dev_start(uint16_t port_id)
1612 struct rte_eth_dev *dev;
1613 struct rte_eth_dev_info dev_info;
1617 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1619 dev = &rte_eth_devices[port_id];
1621 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1623 if (dev->data->dev_started != 0) {
1624 RTE_ETHDEV_LOG(INFO,
1625 "Device with port_id=%"PRIu16" already started\n",
1630 ret = rte_eth_dev_info_get(port_id, &dev_info);
1634 /* Lets restore MAC now if device does not support live change */
1635 if (*dev_info.dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR)
1636 rte_eth_dev_mac_restore(dev, &dev_info);
1638 diag = (*dev->dev_ops->dev_start)(dev);
1640 dev->data->dev_started = 1;
1642 return eth_err(port_id, diag);
1644 ret = rte_eth_dev_config_restore(dev, &dev_info, port_id);
1647 "Error during restoring configuration for device (port %u): %s\n",
1648 port_id, rte_strerror(-ret));
1649 rte_eth_dev_stop(port_id);
1653 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1654 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1655 (*dev->dev_ops->link_update)(dev, 0);
1658 rte_ethdev_trace_start(port_id);
1663 rte_eth_dev_stop(uint16_t port_id)
1665 struct rte_eth_dev *dev;
1667 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1668 dev = &rte_eth_devices[port_id];
1670 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1672 if (dev->data->dev_started == 0) {
1673 RTE_ETHDEV_LOG(INFO,
1674 "Device with port_id=%"PRIu16" already stopped\n",
1679 dev->data->dev_started = 0;
1680 (*dev->dev_ops->dev_stop)(dev);
1681 rte_ethdev_trace_stop(port_id);
1685 rte_eth_dev_set_link_up(uint16_t port_id)
1687 struct rte_eth_dev *dev;
1689 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1691 dev = &rte_eth_devices[port_id];
1693 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1694 return eth_err(port_id, (*dev->dev_ops->dev_set_link_up)(dev));
1698 rte_eth_dev_set_link_down(uint16_t port_id)
1700 struct rte_eth_dev *dev;
1702 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1704 dev = &rte_eth_devices[port_id];
1706 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1707 return eth_err(port_id, (*dev->dev_ops->dev_set_link_down)(dev));
1711 rte_eth_dev_close(uint16_t port_id)
1713 struct rte_eth_dev *dev;
1715 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1716 dev = &rte_eth_devices[port_id];
1718 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1719 dev->data->dev_started = 0;
1720 (*dev->dev_ops->dev_close)(dev);
1722 rte_ethdev_trace_close(port_id);
1723 rte_eth_dev_release_port(dev);
1727 rte_eth_dev_reset(uint16_t port_id)
1729 struct rte_eth_dev *dev;
1732 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1733 dev = &rte_eth_devices[port_id];
1735 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1737 rte_eth_dev_stop(port_id);
1738 ret = dev->dev_ops->dev_reset(dev);
1740 return eth_err(port_id, ret);
1744 rte_eth_dev_is_removed(uint16_t port_id)
1746 struct rte_eth_dev *dev;
1749 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
1751 dev = &rte_eth_devices[port_id];
1753 if (dev->state == RTE_ETH_DEV_REMOVED)
1756 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->is_removed, 0);
1758 ret = dev->dev_ops->is_removed(dev);
1760 /* Device is physically removed. */
1761 dev->state = RTE_ETH_DEV_REMOVED;
1767 rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1768 uint16_t nb_rx_desc, unsigned int socket_id,
1769 const struct rte_eth_rxconf *rx_conf,
1770 struct rte_mempool *mp)
1773 uint32_t mbp_buf_size;
1774 struct rte_eth_dev *dev;
1775 struct rte_eth_dev_info dev_info;
1776 struct rte_eth_rxconf local_conf;
1779 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1781 dev = &rte_eth_devices[port_id];
1782 if (rx_queue_id >= dev->data->nb_rx_queues) {
1783 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
1788 RTE_ETHDEV_LOG(ERR, "Invalid null mempool pointer\n");
1792 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1795 * Check the size of the mbuf data buffer.
1796 * This value must be provided in the private data of the memory pool.
1797 * First check that the memory pool has a valid private data.
1799 ret = rte_eth_dev_info_get(port_id, &dev_info);
1803 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1804 RTE_ETHDEV_LOG(ERR, "%s private_data_size %d < %d\n",
1805 mp->name, (int)mp->private_data_size,
1806 (int)sizeof(struct rte_pktmbuf_pool_private));
1809 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1811 if (mbp_buf_size < dev_info.min_rx_bufsize + RTE_PKTMBUF_HEADROOM) {
1813 "%s mbuf_data_room_size %d < %d (RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)=%d)\n",
1814 mp->name, (int)mbp_buf_size,
1815 (int)(RTE_PKTMBUF_HEADROOM + dev_info.min_rx_bufsize),
1816 (int)RTE_PKTMBUF_HEADROOM,
1817 (int)dev_info.min_rx_bufsize);
1821 /* Use default specified by driver, if nb_rx_desc is zero */
1822 if (nb_rx_desc == 0) {
1823 nb_rx_desc = dev_info.default_rxportconf.ring_size;
1824 /* If driver default is also zero, fall back on EAL default */
1825 if (nb_rx_desc == 0)
1826 nb_rx_desc = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
1829 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1830 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1831 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1834 "Invalid value for nb_rx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n",
1835 nb_rx_desc, dev_info.rx_desc_lim.nb_max,
1836 dev_info.rx_desc_lim.nb_min,
1837 dev_info.rx_desc_lim.nb_align);
1841 if (dev->data->dev_started &&
1842 !(dev_info.dev_capa &
1843 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP))
1846 if (dev->data->dev_started &&
1847 (dev->data->rx_queue_state[rx_queue_id] !=
1848 RTE_ETH_QUEUE_STATE_STOPPED))
1851 rxq = dev->data->rx_queues;
1852 if (rxq[rx_queue_id]) {
1853 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1855 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1856 rxq[rx_queue_id] = NULL;
1859 if (rx_conf == NULL)
1860 rx_conf = &dev_info.default_rxconf;
1862 local_conf = *rx_conf;
1865 * If an offloading has already been enabled in
1866 * rte_eth_dev_configure(), it has been enabled on all queues,
1867 * so there is no need to enable it in this queue again.
1868 * The local_conf.offloads input to underlying PMD only carries
1869 * those offloadings which are only enabled on this queue and
1870 * not enabled on all queues.
1872 local_conf.offloads &= ~dev->data->dev_conf.rxmode.offloads;
1875 * New added offloadings for this queue are those not enabled in
1876 * rte_eth_dev_configure() and they must be per-queue type.
1877 * A pure per-port offloading can't be enabled on a queue while
1878 * disabled on another queue. A pure per-port offloading can't
1879 * be enabled for any queue as new added one if it hasn't been
1880 * enabled in rte_eth_dev_configure().
1882 if ((local_conf.offloads & dev_info.rx_queue_offload_capa) !=
1883 local_conf.offloads) {
1885 "Ethdev port_id=%d rx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
1886 "within per-queue offload capabilities 0x%"PRIx64" in %s()\n",
1887 port_id, rx_queue_id, local_conf.offloads,
1888 dev_info.rx_queue_offload_capa,
1894 * If LRO is enabled, check that the maximum aggregated packet
1895 * size is supported by the configured device.
1897 if (local_conf.offloads & DEV_RX_OFFLOAD_TCP_LRO) {
1898 if (dev->data->dev_conf.rxmode.max_lro_pkt_size == 0)
1899 dev->data->dev_conf.rxmode.max_lro_pkt_size =
1900 dev->data->dev_conf.rxmode.max_rx_pkt_len;
1901 int ret = check_lro_pkt_size(port_id,
1902 dev->data->dev_conf.rxmode.max_lro_pkt_size,
1903 dev->data->dev_conf.rxmode.max_rx_pkt_len,
1904 dev_info.max_lro_pkt_size);
1909 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1910 socket_id, &local_conf, mp);
1912 if (!dev->data->min_rx_buf_size ||
1913 dev->data->min_rx_buf_size > mbp_buf_size)
1914 dev->data->min_rx_buf_size = mbp_buf_size;
1917 rte_ethdev_trace_rxq_setup(port_id, rx_queue_id, nb_rx_desc, mp,
1919 return eth_err(port_id, ret);
1923 rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1924 uint16_t nb_rx_desc,
1925 const struct rte_eth_hairpin_conf *conf)
1928 struct rte_eth_dev *dev;
1929 struct rte_eth_hairpin_cap cap;
1934 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1936 dev = &rte_eth_devices[port_id];
1937 if (rx_queue_id >= dev->data->nb_rx_queues) {
1938 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
1941 ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
1944 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_hairpin_queue_setup,
1946 /* if nb_rx_desc is zero use max number of desc from the driver. */
1947 if (nb_rx_desc == 0)
1948 nb_rx_desc = cap.max_nb_desc;
1949 if (nb_rx_desc > cap.max_nb_desc) {
1951 "Invalid value for nb_rx_desc(=%hu), should be: <= %hu",
1952 nb_rx_desc, cap.max_nb_desc);
1955 if (conf->peer_count > cap.max_rx_2_tx) {
1957 "Invalid value for number of peers for Rx queue(=%hu), should be: <= %hu",
1958 conf->peer_count, cap.max_rx_2_tx);
1961 if (conf->peer_count == 0) {
1963 "Invalid value for number of peers for Rx queue(=%hu), should be: > 0",
1967 for (i = 0, count = 0; i < dev->data->nb_rx_queues &&
1968 cap.max_nb_queues != UINT16_MAX; i++) {
1969 if (i == rx_queue_id || rte_eth_dev_is_rx_hairpin_queue(dev, i))
1972 if (count > cap.max_nb_queues) {
1973 RTE_ETHDEV_LOG(ERR, "To many Rx hairpin queues max is %d",
1977 if (dev->data->dev_started)
1979 rxq = dev->data->rx_queues;
1980 if (rxq[rx_queue_id] != NULL) {
1981 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1983 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1984 rxq[rx_queue_id] = NULL;
1986 ret = (*dev->dev_ops->rx_hairpin_queue_setup)(dev, rx_queue_id,
1989 dev->data->rx_queue_state[rx_queue_id] =
1990 RTE_ETH_QUEUE_STATE_HAIRPIN;
1991 return eth_err(port_id, ret);
1995 rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
1996 uint16_t nb_tx_desc, unsigned int socket_id,
1997 const struct rte_eth_txconf *tx_conf)
1999 struct rte_eth_dev *dev;
2000 struct rte_eth_dev_info dev_info;
2001 struct rte_eth_txconf local_conf;
2005 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2007 dev = &rte_eth_devices[port_id];
2008 if (tx_queue_id >= dev->data->nb_tx_queues) {
2009 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
2013 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
2015 ret = rte_eth_dev_info_get(port_id, &dev_info);
2019 /* Use default specified by driver, if nb_tx_desc is zero */
2020 if (nb_tx_desc == 0) {
2021 nb_tx_desc = dev_info.default_txportconf.ring_size;
2022 /* If driver default is zero, fall back on EAL default */
2023 if (nb_tx_desc == 0)
2024 nb_tx_desc = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
2026 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
2027 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
2028 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
2030 "Invalid value for nb_tx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n",
2031 nb_tx_desc, dev_info.tx_desc_lim.nb_max,
2032 dev_info.tx_desc_lim.nb_min,
2033 dev_info.tx_desc_lim.nb_align);
2037 if (dev->data->dev_started &&
2038 !(dev_info.dev_capa &
2039 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP))
2042 if (dev->data->dev_started &&
2043 (dev->data->tx_queue_state[tx_queue_id] !=
2044 RTE_ETH_QUEUE_STATE_STOPPED))
2047 txq = dev->data->tx_queues;
2048 if (txq[tx_queue_id]) {
2049 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
2051 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
2052 txq[tx_queue_id] = NULL;
2055 if (tx_conf == NULL)
2056 tx_conf = &dev_info.default_txconf;
2058 local_conf = *tx_conf;
2061 * If an offloading has already been enabled in
2062 * rte_eth_dev_configure(), it has been enabled on all queues,
2063 * so there is no need to enable it in this queue again.
2064 * The local_conf.offloads input to underlying PMD only carries
2065 * those offloadings which are only enabled on this queue and
2066 * not enabled on all queues.
2068 local_conf.offloads &= ~dev->data->dev_conf.txmode.offloads;
2071 * New added offloadings for this queue are those not enabled in
2072 * rte_eth_dev_configure() and they must be per-queue type.
2073 * A pure per-port offloading can't be enabled on a queue while
2074 * disabled on another queue. A pure per-port offloading can't
2075 * be enabled for any queue as new added one if it hasn't been
2076 * enabled in rte_eth_dev_configure().
2078 if ((local_conf.offloads & dev_info.tx_queue_offload_capa) !=
2079 local_conf.offloads) {
2081 "Ethdev port_id=%d tx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
2082 "within per-queue offload capabilities 0x%"PRIx64" in %s()\n",
2083 port_id, tx_queue_id, local_conf.offloads,
2084 dev_info.tx_queue_offload_capa,
2089 rte_ethdev_trace_txq_setup(port_id, tx_queue_id, nb_tx_desc, tx_conf);
2090 return eth_err(port_id, (*dev->dev_ops->tx_queue_setup)(dev,
2091 tx_queue_id, nb_tx_desc, socket_id, &local_conf));
2095 rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
2096 uint16_t nb_tx_desc,
2097 const struct rte_eth_hairpin_conf *conf)
2099 struct rte_eth_dev *dev;
2100 struct rte_eth_hairpin_cap cap;
2106 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2107 dev = &rte_eth_devices[port_id];
2108 if (tx_queue_id >= dev->data->nb_tx_queues) {
2109 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
2112 ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
2115 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_hairpin_queue_setup,
2117 /* if nb_rx_desc is zero use max number of desc from the driver. */
2118 if (nb_tx_desc == 0)
2119 nb_tx_desc = cap.max_nb_desc;
2120 if (nb_tx_desc > cap.max_nb_desc) {
2122 "Invalid value for nb_tx_desc(=%hu), should be: <= %hu",
2123 nb_tx_desc, cap.max_nb_desc);
2126 if (conf->peer_count > cap.max_tx_2_rx) {
2128 "Invalid value for number of peers for Tx queue(=%hu), should be: <= %hu",
2129 conf->peer_count, cap.max_tx_2_rx);
2132 if (conf->peer_count == 0) {
2134 "Invalid value for number of peers for Tx queue(=%hu), should be: > 0",
2138 for (i = 0, count = 0; i < dev->data->nb_tx_queues &&
2139 cap.max_nb_queues != UINT16_MAX; i++) {
2140 if (i == tx_queue_id || rte_eth_dev_is_tx_hairpin_queue(dev, i))
2143 if (count > cap.max_nb_queues) {
2144 RTE_ETHDEV_LOG(ERR, "To many Tx hairpin queues max is %d",
2148 if (dev->data->dev_started)
2150 txq = dev->data->tx_queues;
2151 if (txq[tx_queue_id] != NULL) {
2152 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
2154 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
2155 txq[tx_queue_id] = NULL;
2157 ret = (*dev->dev_ops->tx_hairpin_queue_setup)
2158 (dev, tx_queue_id, nb_tx_desc, conf);
2160 dev->data->tx_queue_state[tx_queue_id] =
2161 RTE_ETH_QUEUE_STATE_HAIRPIN;
2162 return eth_err(port_id, ret);
2166 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
2167 void *userdata __rte_unused)
2169 rte_pktmbuf_free_bulk(pkts, unsent);
2173 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
2176 uint64_t *count = userdata;
2178 rte_pktmbuf_free_bulk(pkts, unsent);
2183 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
2184 buffer_tx_error_fn cbfn, void *userdata)
2186 buffer->error_callback = cbfn;
2187 buffer->error_userdata = userdata;
2192 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
2199 buffer->size = size;
2200 if (buffer->error_callback == NULL) {
2201 ret = rte_eth_tx_buffer_set_err_callback(
2202 buffer, rte_eth_tx_buffer_drop_callback, NULL);
2209 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
2211 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2214 /* Validate Input Data. Bail if not valid or not supported. */
2215 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2216 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
2218 /* Call driver to free pending mbufs. */
2219 ret = (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
2221 return eth_err(port_id, ret);
2225 rte_eth_promiscuous_enable(uint16_t port_id)
2227 struct rte_eth_dev *dev;
2230 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2231 dev = &rte_eth_devices[port_id];
2233 if (dev->data->promiscuous == 1)
2236 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_enable, -ENOTSUP);
2238 diag = (*dev->dev_ops->promiscuous_enable)(dev);
2239 dev->data->promiscuous = (diag == 0) ? 1 : 0;
2241 return eth_err(port_id, diag);
2245 rte_eth_promiscuous_disable(uint16_t port_id)
2247 struct rte_eth_dev *dev;
2250 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2251 dev = &rte_eth_devices[port_id];
2253 if (dev->data->promiscuous == 0)
2256 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_disable, -ENOTSUP);
2258 dev->data->promiscuous = 0;
2259 diag = (*dev->dev_ops->promiscuous_disable)(dev);
2261 dev->data->promiscuous = 1;
2263 return eth_err(port_id, diag);
2267 rte_eth_promiscuous_get(uint16_t port_id)
2269 struct rte_eth_dev *dev;
2271 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2273 dev = &rte_eth_devices[port_id];
2274 return dev->data->promiscuous;
2278 rte_eth_allmulticast_enable(uint16_t port_id)
2280 struct rte_eth_dev *dev;
2283 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2284 dev = &rte_eth_devices[port_id];
2286 if (dev->data->all_multicast == 1)
2289 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_enable, -ENOTSUP);
2290 diag = (*dev->dev_ops->allmulticast_enable)(dev);
2291 dev->data->all_multicast = (diag == 0) ? 1 : 0;
2293 return eth_err(port_id, diag);
2297 rte_eth_allmulticast_disable(uint16_t port_id)
2299 struct rte_eth_dev *dev;
2302 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2303 dev = &rte_eth_devices[port_id];
2305 if (dev->data->all_multicast == 0)
2308 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_disable, -ENOTSUP);
2309 dev->data->all_multicast = 0;
2310 diag = (*dev->dev_ops->allmulticast_disable)(dev);
2312 dev->data->all_multicast = 1;
2314 return eth_err(port_id, diag);
2318 rte_eth_allmulticast_get(uint16_t port_id)
2320 struct rte_eth_dev *dev;
2322 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2324 dev = &rte_eth_devices[port_id];
2325 return dev->data->all_multicast;
2329 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
2331 struct rte_eth_dev *dev;
2333 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2334 dev = &rte_eth_devices[port_id];
2336 if (dev->data->dev_conf.intr_conf.lsc &&
2337 dev->data->dev_started)
2338 rte_eth_linkstatus_get(dev, eth_link);
2340 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
2341 (*dev->dev_ops->link_update)(dev, 1);
2342 *eth_link = dev->data->dev_link;
2349 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
2351 struct rte_eth_dev *dev;
2353 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2354 dev = &rte_eth_devices[port_id];
2356 if (dev->data->dev_conf.intr_conf.lsc &&
2357 dev->data->dev_started)
2358 rte_eth_linkstatus_get(dev, eth_link);
2360 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
2361 (*dev->dev_ops->link_update)(dev, 0);
2362 *eth_link = dev->data->dev_link;
2369 rte_eth_link_speed_to_str(uint32_t link_speed)
2371 switch (link_speed) {
2372 case ETH_SPEED_NUM_NONE: return "None";
2373 case ETH_SPEED_NUM_10M: return "10 Mbps";
2374 case ETH_SPEED_NUM_100M: return "100 Mbps";
2375 case ETH_SPEED_NUM_1G: return "1 Gbps";
2376 case ETH_SPEED_NUM_2_5G: return "2.5 Gbps";
2377 case ETH_SPEED_NUM_5G: return "5 Gbps";
2378 case ETH_SPEED_NUM_10G: return "10 Gbps";
2379 case ETH_SPEED_NUM_20G: return "20 Gbps";
2380 case ETH_SPEED_NUM_25G: return "25 Gbps";
2381 case ETH_SPEED_NUM_40G: return "40 Gbps";
2382 case ETH_SPEED_NUM_50G: return "50 Gbps";
2383 case ETH_SPEED_NUM_56G: return "56 Gbps";
2384 case ETH_SPEED_NUM_100G: return "100 Gbps";
2385 case ETH_SPEED_NUM_200G: return "200 Gbps";
2386 case ETH_SPEED_NUM_UNKNOWN: return "Unknown";
2387 default: return "Invalid";
2392 rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link)
2394 if (eth_link->link_status == ETH_LINK_DOWN)
2395 return snprintf(str, len, "Link down");
2397 return snprintf(str, len, "Link up at %s %s %s",
2398 rte_eth_link_speed_to_str(eth_link->link_speed),
2399 (eth_link->link_duplex == ETH_LINK_FULL_DUPLEX) ?
2401 (eth_link->link_autoneg == ETH_LINK_AUTONEG) ?
2402 "Autoneg" : "Fixed");
2406 rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
2408 struct rte_eth_dev *dev;
2410 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2412 dev = &rte_eth_devices[port_id];
2413 memset(stats, 0, sizeof(*stats));
2415 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
2416 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
2417 return eth_err(port_id, (*dev->dev_ops->stats_get)(dev, stats));
2421 rte_eth_stats_reset(uint16_t port_id)
2423 struct rte_eth_dev *dev;
2426 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2427 dev = &rte_eth_devices[port_id];
2429 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
2430 ret = (*dev->dev_ops->stats_reset)(dev);
2432 return eth_err(port_id, ret);
2434 dev->data->rx_mbuf_alloc_failed = 0;
2440 get_xstats_basic_count(struct rte_eth_dev *dev)
2442 uint16_t nb_rxqs, nb_txqs;
2445 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2446 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2448 count = RTE_NB_STATS;
2449 count += nb_rxqs * RTE_NB_RXQ_STATS;
2450 count += nb_txqs * RTE_NB_TXQ_STATS;
2456 get_xstats_count(uint16_t port_id)
2458 struct rte_eth_dev *dev;
2461 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2462 dev = &rte_eth_devices[port_id];
2463 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
2464 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
2467 return eth_err(port_id, count);
2469 if (dev->dev_ops->xstats_get_names != NULL) {
2470 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
2472 return eth_err(port_id, count);
2477 count += get_xstats_basic_count(dev);
2483 rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
2486 int cnt_xstats, idx_xstat;
2488 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2491 RTE_ETHDEV_LOG(ERR, "Id pointer is NULL\n");
2496 RTE_ETHDEV_LOG(ERR, "xstat_name pointer is NULL\n");
2501 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
2502 if (cnt_xstats < 0) {
2503 RTE_ETHDEV_LOG(ERR, "Cannot get count of xstats\n");
2507 /* Get id-name lookup table */
2508 struct rte_eth_xstat_name xstats_names[cnt_xstats];
2510 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
2511 port_id, xstats_names, cnt_xstats, NULL)) {
2512 RTE_ETHDEV_LOG(ERR, "Cannot get xstats lookup\n");
2516 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
2517 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
2526 /* retrieve basic stats names */
2528 rte_eth_basic_stats_get_names(struct rte_eth_dev *dev,
2529 struct rte_eth_xstat_name *xstats_names)
2531 int cnt_used_entries = 0;
2532 uint32_t idx, id_queue;
2535 for (idx = 0; idx < RTE_NB_STATS; idx++) {
2536 strlcpy(xstats_names[cnt_used_entries].name,
2537 rte_stats_strings[idx].name,
2538 sizeof(xstats_names[0].name));
2541 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2542 for (id_queue = 0; id_queue < num_q; id_queue++) {
2543 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
2544 snprintf(xstats_names[cnt_used_entries].name,
2545 sizeof(xstats_names[0].name),
2547 id_queue, rte_rxq_stats_strings[idx].name);
2552 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2553 for (id_queue = 0; id_queue < num_q; id_queue++) {
2554 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
2555 snprintf(xstats_names[cnt_used_entries].name,
2556 sizeof(xstats_names[0].name),
2558 id_queue, rte_txq_stats_strings[idx].name);
2562 return cnt_used_entries;
2565 /* retrieve ethdev extended statistics names */
2567 rte_eth_xstats_get_names_by_id(uint16_t port_id,
2568 struct rte_eth_xstat_name *xstats_names, unsigned int size,
2571 struct rte_eth_xstat_name *xstats_names_copy;
2572 unsigned int no_basic_stat_requested = 1;
2573 unsigned int no_ext_stat_requested = 1;
2574 unsigned int expected_entries;
2575 unsigned int basic_count;
2576 struct rte_eth_dev *dev;
2580 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2581 dev = &rte_eth_devices[port_id];
2583 basic_count = get_xstats_basic_count(dev);
2584 ret = get_xstats_count(port_id);
2587 expected_entries = (unsigned int)ret;
2589 /* Return max number of stats if no ids given */
2592 return expected_entries;
2593 else if (xstats_names && size < expected_entries)
2594 return expected_entries;
2597 if (ids && !xstats_names)
2600 if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
2601 uint64_t ids_copy[size];
2603 for (i = 0; i < size; i++) {
2604 if (ids[i] < basic_count) {
2605 no_basic_stat_requested = 0;
2610 * Convert ids to xstats ids that PMD knows.
2611 * ids known by user are basic + extended stats.
2613 ids_copy[i] = ids[i] - basic_count;
2616 if (no_basic_stat_requested)
2617 return (*dev->dev_ops->xstats_get_names_by_id)(dev,
2618 xstats_names, ids_copy, size);
2621 /* Retrieve all stats */
2623 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
2625 if (num_stats < 0 || num_stats > (int)expected_entries)
2628 return expected_entries;
2631 xstats_names_copy = calloc(expected_entries,
2632 sizeof(struct rte_eth_xstat_name));
2634 if (!xstats_names_copy) {
2635 RTE_ETHDEV_LOG(ERR, "Can't allocate memory\n");
2640 for (i = 0; i < size; i++) {
2641 if (ids[i] >= basic_count) {
2642 no_ext_stat_requested = 0;
2648 /* Fill xstats_names_copy structure */
2649 if (ids && no_ext_stat_requested) {
2650 rte_eth_basic_stats_get_names(dev, xstats_names_copy);
2652 ret = rte_eth_xstats_get_names(port_id, xstats_names_copy,
2655 free(xstats_names_copy);
2661 for (i = 0; i < size; i++) {
2662 if (ids[i] >= expected_entries) {
2663 RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n");
2664 free(xstats_names_copy);
2667 xstats_names[i] = xstats_names_copy[ids[i]];
2670 free(xstats_names_copy);
2675 rte_eth_xstats_get_names(uint16_t port_id,
2676 struct rte_eth_xstat_name *xstats_names,
2679 struct rte_eth_dev *dev;
2680 int cnt_used_entries;
2681 int cnt_expected_entries;
2682 int cnt_driver_entries;
2684 cnt_expected_entries = get_xstats_count(port_id);
2685 if (xstats_names == NULL || cnt_expected_entries < 0 ||
2686 (int)size < cnt_expected_entries)
2687 return cnt_expected_entries;
2689 /* port_id checked in get_xstats_count() */
2690 dev = &rte_eth_devices[port_id];
2692 cnt_used_entries = rte_eth_basic_stats_get_names(
2695 if (dev->dev_ops->xstats_get_names != NULL) {
2696 /* If there are any driver-specific xstats, append them
2699 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
2701 xstats_names + cnt_used_entries,
2702 size - cnt_used_entries);
2703 if (cnt_driver_entries < 0)
2704 return eth_err(port_id, cnt_driver_entries);
2705 cnt_used_entries += cnt_driver_entries;
2708 return cnt_used_entries;
2713 rte_eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats)
2715 struct rte_eth_dev *dev;
2716 struct rte_eth_stats eth_stats;
2717 unsigned int count = 0, i, q;
2718 uint64_t val, *stats_ptr;
2719 uint16_t nb_rxqs, nb_txqs;
2722 ret = rte_eth_stats_get(port_id, ð_stats);
2726 dev = &rte_eth_devices[port_id];
2728 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2729 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2732 for (i = 0; i < RTE_NB_STATS; i++) {
2733 stats_ptr = RTE_PTR_ADD(ð_stats,
2734 rte_stats_strings[i].offset);
2736 xstats[count++].value = val;
2740 for (q = 0; q < nb_rxqs; q++) {
2741 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
2742 stats_ptr = RTE_PTR_ADD(ð_stats,
2743 rte_rxq_stats_strings[i].offset +
2744 q * sizeof(uint64_t));
2746 xstats[count++].value = val;
2751 for (q = 0; q < nb_txqs; q++) {
2752 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
2753 stats_ptr = RTE_PTR_ADD(ð_stats,
2754 rte_txq_stats_strings[i].offset +
2755 q * sizeof(uint64_t));
2757 xstats[count++].value = val;
2763 /* retrieve ethdev extended statistics */
2765 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
2766 uint64_t *values, unsigned int size)
2768 unsigned int no_basic_stat_requested = 1;
2769 unsigned int no_ext_stat_requested = 1;
2770 unsigned int num_xstats_filled;
2771 unsigned int basic_count;
2772 uint16_t expected_entries;
2773 struct rte_eth_dev *dev;
2777 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2778 ret = get_xstats_count(port_id);
2781 expected_entries = (uint16_t)ret;
2782 struct rte_eth_xstat xstats[expected_entries];
2783 dev = &rte_eth_devices[port_id];
2784 basic_count = get_xstats_basic_count(dev);
2786 /* Return max number of stats if no ids given */
2789 return expected_entries;
2790 else if (values && size < expected_entries)
2791 return expected_entries;
2797 if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
2798 unsigned int basic_count = get_xstats_basic_count(dev);
2799 uint64_t ids_copy[size];
2801 for (i = 0; i < size; i++) {
2802 if (ids[i] < basic_count) {
2803 no_basic_stat_requested = 0;
2808 * Convert ids to xstats ids that PMD knows.
2809 * ids known by user are basic + extended stats.
2811 ids_copy[i] = ids[i] - basic_count;
2814 if (no_basic_stat_requested)
2815 return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy,
2820 for (i = 0; i < size; i++) {
2821 if (ids[i] >= basic_count) {
2822 no_ext_stat_requested = 0;
2828 /* Fill the xstats structure */
2829 if (ids && no_ext_stat_requested)
2830 ret = rte_eth_basic_stats_get(port_id, xstats);
2832 ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
2836 num_xstats_filled = (unsigned int)ret;
2838 /* Return all stats */
2840 for (i = 0; i < num_xstats_filled; i++)
2841 values[i] = xstats[i].value;
2842 return expected_entries;
2846 for (i = 0; i < size; i++) {
2847 if (ids[i] >= expected_entries) {
2848 RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n");
2851 values[i] = xstats[ids[i]].value;
2857 rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
2860 struct rte_eth_dev *dev;
2861 unsigned int count = 0, i;
2862 signed int xcount = 0;
2863 uint16_t nb_rxqs, nb_txqs;
2866 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2868 dev = &rte_eth_devices[port_id];
2870 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2871 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2873 /* Return generic statistics */
2874 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
2875 (nb_txqs * RTE_NB_TXQ_STATS);
2877 /* implemented by the driver */
2878 if (dev->dev_ops->xstats_get != NULL) {
2879 /* Retrieve the xstats from the driver at the end of the
2882 xcount = (*dev->dev_ops->xstats_get)(dev,
2883 xstats ? xstats + count : NULL,
2884 (n > count) ? n - count : 0);
2887 return eth_err(port_id, xcount);
2890 if (n < count + xcount || xstats == NULL)
2891 return count + xcount;
2893 /* now fill the xstats structure */
2894 ret = rte_eth_basic_stats_get(port_id, xstats);
2899 for (i = 0; i < count; i++)
2901 /* add an offset to driver-specific stats */
2902 for ( ; i < count + xcount; i++)
2903 xstats[i].id += count;
2905 return count + xcount;
2908 /* reset ethdev extended statistics */
2910 rte_eth_xstats_reset(uint16_t port_id)
2912 struct rte_eth_dev *dev;
2914 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2915 dev = &rte_eth_devices[port_id];
2917 /* implemented by the driver */
2918 if (dev->dev_ops->xstats_reset != NULL)
2919 return eth_err(port_id, (*dev->dev_ops->xstats_reset)(dev));
2921 /* fallback to default */
2922 return rte_eth_stats_reset(port_id);
2926 set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
2929 struct rte_eth_dev *dev;
2931 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2933 dev = &rte_eth_devices[port_id];
2935 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
2937 if (is_rx && (queue_id >= dev->data->nb_rx_queues))
2940 if (!is_rx && (queue_id >= dev->data->nb_tx_queues))
2943 if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
2946 return (*dev->dev_ops->queue_stats_mapping_set)
2947 (dev, queue_id, stat_idx, is_rx);
2952 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
2955 return eth_err(port_id, set_queue_stats_mapping(port_id, tx_queue_id,
2956 stat_idx, STAT_QMAP_TX));
2961 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
2964 return eth_err(port_id, set_queue_stats_mapping(port_id, rx_queue_id,
2965 stat_idx, STAT_QMAP_RX));
2969 rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
2971 struct rte_eth_dev *dev;
2973 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2974 dev = &rte_eth_devices[port_id];
2976 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
2977 return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev,
2978 fw_version, fw_size));
2982 rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
2984 struct rte_eth_dev *dev;
2985 const struct rte_eth_desc_lim lim = {
2986 .nb_max = UINT16_MAX,
2989 .nb_seg_max = UINT16_MAX,
2990 .nb_mtu_seg_max = UINT16_MAX,
2995 * Init dev_info before port_id check since caller does not have
2996 * return status and does not know if get is successful or not.
2998 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
2999 dev_info->switch_info.domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
3001 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3002 dev = &rte_eth_devices[port_id];
3004 dev_info->rx_desc_lim = lim;
3005 dev_info->tx_desc_lim = lim;
3006 dev_info->device = dev->device;
3007 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3008 dev_info->max_mtu = UINT16_MAX;
3010 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3011 diag = (*dev->dev_ops->dev_infos_get)(dev, dev_info);
3013 /* Cleanup already filled in device information */
3014 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
3015 return eth_err(port_id, diag);
3018 /* Maximum number of queues should be <= RTE_MAX_QUEUES_PER_PORT */
3019 dev_info->max_rx_queues = RTE_MIN(dev_info->max_rx_queues,
3020 RTE_MAX_QUEUES_PER_PORT);
3021 dev_info->max_tx_queues = RTE_MIN(dev_info->max_tx_queues,
3022 RTE_MAX_QUEUES_PER_PORT);
3024 dev_info->driver_name = dev->device->driver->name;
3025 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
3026 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
3028 dev_info->dev_flags = &dev->data->dev_flags;
3034 rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
3035 uint32_t *ptypes, int num)
3038 struct rte_eth_dev *dev;
3039 const uint32_t *all_ptypes;
3041 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3042 dev = &rte_eth_devices[port_id];
3043 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
3044 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
3049 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
3050 if (all_ptypes[i] & ptype_mask) {
3052 ptypes[j] = all_ptypes[i];
3060 rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask,
3061 uint32_t *set_ptypes, unsigned int num)
3063 const uint32_t valid_ptype_masks[] = {
3067 RTE_PTYPE_TUNNEL_MASK,
3068 RTE_PTYPE_INNER_L2_MASK,
3069 RTE_PTYPE_INNER_L3_MASK,
3070 RTE_PTYPE_INNER_L4_MASK,
3072 const uint32_t *all_ptypes;
3073 struct rte_eth_dev *dev;
3074 uint32_t unused_mask;
3078 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3079 dev = &rte_eth_devices[port_id];
3081 if (num > 0 && set_ptypes == NULL)
3084 if (*dev->dev_ops->dev_supported_ptypes_get == NULL ||
3085 *dev->dev_ops->dev_ptypes_set == NULL) {
3090 if (ptype_mask == 0) {
3091 ret = (*dev->dev_ops->dev_ptypes_set)(dev,
3096 unused_mask = ptype_mask;
3097 for (i = 0; i < RTE_DIM(valid_ptype_masks); i++) {
3098 uint32_t mask = ptype_mask & valid_ptype_masks[i];
3099 if (mask && mask != valid_ptype_masks[i]) {
3103 unused_mask &= ~valid_ptype_masks[i];
3111 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
3112 if (all_ptypes == NULL) {
3118 * Accommodate as many set_ptypes as possible. If the supplied
3119 * set_ptypes array is insufficient fill it partially.
3121 for (i = 0, j = 0; set_ptypes != NULL &&
3122 (all_ptypes[i] != RTE_PTYPE_UNKNOWN); ++i) {
3123 if (ptype_mask & all_ptypes[i]) {
3125 set_ptypes[j] = all_ptypes[i];
3133 if (set_ptypes != NULL && j < num)
3134 set_ptypes[j] = RTE_PTYPE_UNKNOWN;
3136 return (*dev->dev_ops->dev_ptypes_set)(dev, ptype_mask);
3140 set_ptypes[0] = RTE_PTYPE_UNKNOWN;
3146 rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
3148 struct rte_eth_dev *dev;
3150 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3151 dev = &rte_eth_devices[port_id];
3152 rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
3158 rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
3160 struct rte_eth_dev *dev;
3162 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3164 dev = &rte_eth_devices[port_id];
3165 *mtu = dev->data->mtu;
3170 rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
3173 struct rte_eth_dev_info dev_info;
3174 struct rte_eth_dev *dev;
3176 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3177 dev = &rte_eth_devices[port_id];
3178 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
3181 * Check if the device supports dev_infos_get, if it does not
3182 * skip min_mtu/max_mtu validation here as this requires values
3183 * that are populated within the call to rte_eth_dev_info_get()
3184 * which relies on dev->dev_ops->dev_infos_get.
3186 if (*dev->dev_ops->dev_infos_get != NULL) {
3187 ret = rte_eth_dev_info_get(port_id, &dev_info);
3191 if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu)
3195 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
3197 dev->data->mtu = mtu;
3199 return eth_err(port_id, ret);
3203 rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
3205 struct rte_eth_dev *dev;
3208 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3209 dev = &rte_eth_devices[port_id];
3210 if (!(dev->data->dev_conf.rxmode.offloads &
3211 DEV_RX_OFFLOAD_VLAN_FILTER)) {
3212 RTE_ETHDEV_LOG(ERR, "Port %u: vlan-filtering disabled\n",
3217 if (vlan_id > 4095) {
3218 RTE_ETHDEV_LOG(ERR, "Port_id=%u invalid vlan_id=%u > 4095\n",
3222 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
3224 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
3226 struct rte_vlan_filter_conf *vfc;
3230 vfc = &dev->data->vlan_filter_conf;
3231 vidx = vlan_id / 64;
3232 vbit = vlan_id % 64;
3235 vfc->ids[vidx] |= UINT64_C(1) << vbit;
3237 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
3240 return eth_err(port_id, ret);
3244 rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
3247 struct rte_eth_dev *dev;
3249 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3250 dev = &rte_eth_devices[port_id];
3251 if (rx_queue_id >= dev->data->nb_rx_queues) {
3252 RTE_ETHDEV_LOG(ERR, "Invalid rx_queue_id=%u\n", rx_queue_id);
3256 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
3257 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
3263 rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
3264 enum rte_vlan_type vlan_type,
3267 struct rte_eth_dev *dev;
3269 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3270 dev = &rte_eth_devices[port_id];
3271 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
3273 return eth_err(port_id, (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type,
3278 rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
3280 struct rte_eth_dev_info dev_info;
3281 struct rte_eth_dev *dev;
3285 uint64_t orig_offloads;
3286 uint64_t dev_offloads;
3287 uint64_t new_offloads;
3289 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3290 dev = &rte_eth_devices[port_id];
3292 /* save original values in case of failure */
3293 orig_offloads = dev->data->dev_conf.rxmode.offloads;
3294 dev_offloads = orig_offloads;
3296 /* check which option changed by application */
3297 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
3298 org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
3301 dev_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3303 dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3304 mask |= ETH_VLAN_STRIP_MASK;
3307 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
3308 org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER);
3311 dev_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3313 dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3314 mask |= ETH_VLAN_FILTER_MASK;
3317 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
3318 org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND);
3321 dev_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3323 dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3324 mask |= ETH_VLAN_EXTEND_MASK;
3327 cur = !!(offload_mask & ETH_QINQ_STRIP_OFFLOAD);
3328 org = !!(dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP);
3331 dev_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3333 dev_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3334 mask |= ETH_QINQ_STRIP_MASK;
3341 ret = rte_eth_dev_info_get(port_id, &dev_info);
3345 /* Rx VLAN offloading must be within its device capabilities */
3346 if ((dev_offloads & dev_info.rx_offload_capa) != dev_offloads) {
3347 new_offloads = dev_offloads & ~orig_offloads;
3349 "Ethdev port_id=%u requested new added VLAN offloads "
3350 "0x%" PRIx64 " must be within Rx offloads capabilities "
3351 "0x%" PRIx64 " in %s()\n",
3352 port_id, new_offloads, dev_info.rx_offload_capa,
3357 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
3358 dev->data->dev_conf.rxmode.offloads = dev_offloads;
3359 ret = (*dev->dev_ops->vlan_offload_set)(dev, mask);
3361 /* hit an error restore original values */
3362 dev->data->dev_conf.rxmode.offloads = orig_offloads;
3365 return eth_err(port_id, ret);
3369 rte_eth_dev_get_vlan_offload(uint16_t port_id)
3371 struct rte_eth_dev *dev;
3372 uint64_t *dev_offloads;
3375 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3376 dev = &rte_eth_devices[port_id];
3377 dev_offloads = &dev->data->dev_conf.rxmode.offloads;
3379 if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
3380 ret |= ETH_VLAN_STRIP_OFFLOAD;
3382 if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
3383 ret |= ETH_VLAN_FILTER_OFFLOAD;
3385 if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
3386 ret |= ETH_VLAN_EXTEND_OFFLOAD;
3388 if (*dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP)
3389 ret |= ETH_QINQ_STRIP_OFFLOAD;
3395 rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
3397 struct rte_eth_dev *dev;
3399 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3400 dev = &rte_eth_devices[port_id];
3401 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
3403 return eth_err(port_id, (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on));
3407 rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
3409 struct rte_eth_dev *dev;
3411 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3412 dev = &rte_eth_devices[port_id];
3413 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
3414 memset(fc_conf, 0, sizeof(*fc_conf));
3415 return eth_err(port_id, (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf));
3419 rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
3421 struct rte_eth_dev *dev;
3423 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3424 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
3425 RTE_ETHDEV_LOG(ERR, "Invalid send_xon, only 0/1 allowed\n");
3429 dev = &rte_eth_devices[port_id];
3430 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
3431 return eth_err(port_id, (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf));
3435 rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
3436 struct rte_eth_pfc_conf *pfc_conf)
3438 struct rte_eth_dev *dev;
3440 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3441 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
3442 RTE_ETHDEV_LOG(ERR, "Invalid priority, only 0-7 allowed\n");
3446 dev = &rte_eth_devices[port_id];
3447 /* High water, low water validation are device specific */
3448 if (*dev->dev_ops->priority_flow_ctrl_set)
3449 return eth_err(port_id, (*dev->dev_ops->priority_flow_ctrl_set)
3455 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
3463 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
3464 for (i = 0; i < num; i++) {
3465 if (reta_conf[i].mask)
3473 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
3477 uint16_t i, idx, shift;
3483 RTE_ETHDEV_LOG(ERR, "No receive queue is available\n");
3487 for (i = 0; i < reta_size; i++) {
3488 idx = i / RTE_RETA_GROUP_SIZE;
3489 shift = i % RTE_RETA_GROUP_SIZE;
3490 if ((reta_conf[idx].mask & (1ULL << shift)) &&
3491 (reta_conf[idx].reta[shift] >= max_rxq)) {
3493 "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
3495 reta_conf[idx].reta[shift], max_rxq);
3504 rte_eth_dev_rss_reta_update(uint16_t port_id,
3505 struct rte_eth_rss_reta_entry64 *reta_conf,
3508 struct rte_eth_dev *dev;
3511 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3512 /* Check mask bits */
3513 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
3517 dev = &rte_eth_devices[port_id];
3519 /* Check entry value */
3520 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
3521 dev->data->nb_rx_queues);
3525 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
3526 return eth_err(port_id, (*dev->dev_ops->reta_update)(dev, reta_conf,
3531 rte_eth_dev_rss_reta_query(uint16_t port_id,
3532 struct rte_eth_rss_reta_entry64 *reta_conf,
3535 struct rte_eth_dev *dev;
3538 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3540 /* Check mask bits */
3541 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
3545 dev = &rte_eth_devices[port_id];
3546 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
3547 return eth_err(port_id, (*dev->dev_ops->reta_query)(dev, reta_conf,
3552 rte_eth_dev_rss_hash_update(uint16_t port_id,
3553 struct rte_eth_rss_conf *rss_conf)
3555 struct rte_eth_dev *dev;
3556 struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
3559 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3561 ret = rte_eth_dev_info_get(port_id, &dev_info);
3565 rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf);
3567 dev = &rte_eth_devices[port_id];
3568 if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) !=
3569 dev_info.flow_type_rss_offloads) {
3571 "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n",
3572 port_id, rss_conf->rss_hf,
3573 dev_info.flow_type_rss_offloads);
3576 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
3577 return eth_err(port_id, (*dev->dev_ops->rss_hash_update)(dev,
3582 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
3583 struct rte_eth_rss_conf *rss_conf)
3585 struct rte_eth_dev *dev;
3587 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3588 dev = &rte_eth_devices[port_id];
3589 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
3590 return eth_err(port_id, (*dev->dev_ops->rss_hash_conf_get)(dev,
3595 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
3596 struct rte_eth_udp_tunnel *udp_tunnel)
3598 struct rte_eth_dev *dev;
3600 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3601 if (udp_tunnel == NULL) {
3602 RTE_ETHDEV_LOG(ERR, "Invalid udp_tunnel parameter\n");
3606 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
3607 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
3611 dev = &rte_eth_devices[port_id];
3612 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
3613 return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_add)(dev,
3618 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
3619 struct rte_eth_udp_tunnel *udp_tunnel)
3621 struct rte_eth_dev *dev;
3623 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3624 dev = &rte_eth_devices[port_id];
3626 if (udp_tunnel == NULL) {
3627 RTE_ETHDEV_LOG(ERR, "Invalid udp_tunnel parameter\n");
3631 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
3632 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
3636 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
3637 return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_del)(dev,
3642 rte_eth_led_on(uint16_t port_id)
3644 struct rte_eth_dev *dev;
3646 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3647 dev = &rte_eth_devices[port_id];
3648 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
3649 return eth_err(port_id, (*dev->dev_ops->dev_led_on)(dev));
3653 rte_eth_led_off(uint16_t port_id)
3655 struct rte_eth_dev *dev;
3657 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3658 dev = &rte_eth_devices[port_id];
3659 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
3660 return eth_err(port_id, (*dev->dev_ops->dev_led_off)(dev));
3664 rte_eth_fec_get_capability(uint16_t port_id,
3665 struct rte_eth_fec_capa *speed_fec_capa,
3668 struct rte_eth_dev *dev;
3671 if (speed_fec_capa == NULL && num > 0)
3674 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3675 dev = &rte_eth_devices[port_id];
3676 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get_capability, -ENOTSUP);
3677 ret = (*dev->dev_ops->fec_get_capability)(dev, speed_fec_capa, num);
3683 rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa)
3685 struct rte_eth_dev *dev;
3687 if (fec_capa == NULL)
3690 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3691 dev = &rte_eth_devices[port_id];
3692 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get, -ENOTSUP);
3693 return eth_err(port_id, (*dev->dev_ops->fec_get)(dev, fec_capa));
3697 rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa)
3699 struct rte_eth_dev *dev;
3701 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3702 dev = &rte_eth_devices[port_id];
3703 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_set, -ENOTSUP);
3704 return eth_err(port_id, (*dev->dev_ops->fec_set)(dev, fec_capa));
3708 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
3712 get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
3714 struct rte_eth_dev_info dev_info;
3715 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3719 ret = rte_eth_dev_info_get(port_id, &dev_info);
3723 for (i = 0; i < dev_info.max_mac_addrs; i++)
3724 if (memcmp(addr, &dev->data->mac_addrs[i],
3725 RTE_ETHER_ADDR_LEN) == 0)
3731 static const struct rte_ether_addr null_mac_addr;
3734 rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
3737 struct rte_eth_dev *dev;
3742 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3743 dev = &rte_eth_devices[port_id];
3744 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
3746 if (rte_is_zero_ether_addr(addr)) {
3747 RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n",
3751 if (pool >= ETH_64_POOLS) {
3752 RTE_ETHDEV_LOG(ERR, "Pool id must be 0-%d\n", ETH_64_POOLS - 1);
3756 index = get_mac_addr_index(port_id, addr);
3758 index = get_mac_addr_index(port_id, &null_mac_addr);
3760 RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n",
3765 pool_mask = dev->data->mac_pool_sel[index];
3767 /* Check if both MAC address and pool is already there, and do nothing */
3768 if (pool_mask & (1ULL << pool))
3773 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
3776 /* Update address in NIC data structure */
3777 rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]);
3779 /* Update pool bitmap in NIC data structure */
3780 dev->data->mac_pool_sel[index] |= (1ULL << pool);
3783 return eth_err(port_id, ret);
3787 rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
3789 struct rte_eth_dev *dev;
3792 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3793 dev = &rte_eth_devices[port_id];
3794 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
3796 index = get_mac_addr_index(port_id, addr);
3799 "Port %u: Cannot remove default MAC address\n",
3802 } else if (index < 0)
3803 return 0; /* Do nothing if address wasn't found */
3806 (*dev->dev_ops->mac_addr_remove)(dev, index);
3808 /* Update address in NIC data structure */
3809 rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
3811 /* reset pool bitmap */
3812 dev->data->mac_pool_sel[index] = 0;
3818 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
3820 struct rte_eth_dev *dev;
3823 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3825 if (!rte_is_valid_assigned_ether_addr(addr))
3828 dev = &rte_eth_devices[port_id];
3829 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
3831 ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
3835 /* Update default address in NIC data structure */
3836 rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
3843 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
3847 get_hash_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
3849 struct rte_eth_dev_info dev_info;
3850 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3854 ret = rte_eth_dev_info_get(port_id, &dev_info);
3858 if (!dev->data->hash_mac_addrs)
3861 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
3862 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
3863 RTE_ETHER_ADDR_LEN) == 0)
3870 rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
3875 struct rte_eth_dev *dev;
3877 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3879 dev = &rte_eth_devices[port_id];
3880 if (rte_is_zero_ether_addr(addr)) {
3881 RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n",
3886 index = get_hash_mac_addr_index(port_id, addr);
3887 /* Check if it's already there, and do nothing */
3888 if ((index >= 0) && on)
3894 "Port %u: the MAC address was not set in UTA\n",
3899 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
3901 RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n",
3907 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
3908 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
3910 /* Update address in NIC data structure */
3912 rte_ether_addr_copy(addr,
3913 &dev->data->hash_mac_addrs[index]);
3915 rte_ether_addr_copy(&null_mac_addr,
3916 &dev->data->hash_mac_addrs[index]);
3919 return eth_err(port_id, ret);
3923 rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
3925 struct rte_eth_dev *dev;
3927 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3929 dev = &rte_eth_devices[port_id];
3931 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
3932 return eth_err(port_id, (*dev->dev_ops->uc_all_hash_table_set)(dev,
3936 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
3939 struct rte_eth_dev *dev;
3940 struct rte_eth_dev_info dev_info;
3941 struct rte_eth_link link;
3944 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3946 ret = rte_eth_dev_info_get(port_id, &dev_info);
3950 dev = &rte_eth_devices[port_id];
3951 link = dev->data->dev_link;
3953 if (queue_idx > dev_info.max_tx_queues) {
3955 "Set queue rate limit:port %u: invalid queue id=%u\n",
3956 port_id, queue_idx);
3960 if (tx_rate > link.link_speed) {
3962 "Set queue rate limit:invalid tx_rate=%u, bigger than link speed= %d\n",
3963 tx_rate, link.link_speed);
3967 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
3968 return eth_err(port_id, (*dev->dev_ops->set_queue_rate_limit)(dev,
3969 queue_idx, tx_rate));
3973 rte_eth_mirror_rule_set(uint16_t port_id,
3974 struct rte_eth_mirror_conf *mirror_conf,
3975 uint8_t rule_id, uint8_t on)
3977 struct rte_eth_dev *dev;
3979 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3980 if (mirror_conf->rule_type == 0) {
3981 RTE_ETHDEV_LOG(ERR, "Mirror rule type can not be 0\n");
3985 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
3986 RTE_ETHDEV_LOG(ERR, "Invalid dst pool, pool id must be 0-%d\n",
3991 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
3992 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
3993 (mirror_conf->pool_mask == 0)) {
3995 "Invalid mirror pool, pool mask can not be 0\n");
3999 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
4000 mirror_conf->vlan.vlan_mask == 0) {
4002 "Invalid vlan mask, vlan mask can not be 0\n");
4006 dev = &rte_eth_devices[port_id];
4007 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
4009 return eth_err(port_id, (*dev->dev_ops->mirror_rule_set)(dev,
4010 mirror_conf, rule_id, on));
4014 rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
4016 struct rte_eth_dev *dev;
4018 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4020 dev = &rte_eth_devices[port_id];
4021 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
4023 return eth_err(port_id, (*dev->dev_ops->mirror_rule_reset)(dev,
4027 RTE_INIT(eth_dev_init_cb_lists)
4031 for (i = 0; i < RTE_MAX_ETHPORTS; i++)
4032 TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
4036 rte_eth_dev_callback_register(uint16_t port_id,
4037 enum rte_eth_event_type event,
4038 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
4040 struct rte_eth_dev *dev;
4041 struct rte_eth_dev_callback *user_cb;
4042 uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
4048 if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
4049 RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id);
4053 if (port_id == RTE_ETH_ALL) {
4055 last_port = RTE_MAX_ETHPORTS - 1;
4057 next_port = last_port = port_id;
4060 rte_spinlock_lock(&rte_eth_dev_cb_lock);
4063 dev = &rte_eth_devices[next_port];
4065 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
4066 if (user_cb->cb_fn == cb_fn &&
4067 user_cb->cb_arg == cb_arg &&
4068 user_cb->event == event) {
4073 /* create a new callback. */
4074 if (user_cb == NULL) {
4075 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
4076 sizeof(struct rte_eth_dev_callback), 0);
4077 if (user_cb != NULL) {
4078 user_cb->cb_fn = cb_fn;
4079 user_cb->cb_arg = cb_arg;
4080 user_cb->event = event;
4081 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs),
4084 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4085 rte_eth_dev_callback_unregister(port_id, event,
4091 } while (++next_port <= last_port);
4093 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4098 rte_eth_dev_callback_unregister(uint16_t port_id,
4099 enum rte_eth_event_type event,
4100 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
4103 struct rte_eth_dev *dev;
4104 struct rte_eth_dev_callback *cb, *next;
4105 uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
4111 if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
4112 RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id);
4116 if (port_id == RTE_ETH_ALL) {
4118 last_port = RTE_MAX_ETHPORTS - 1;
4120 next_port = last_port = port_id;
4123 rte_spinlock_lock(&rte_eth_dev_cb_lock);
4126 dev = &rte_eth_devices[next_port];
4128 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL;
4131 next = TAILQ_NEXT(cb, next);
4133 if (cb->cb_fn != cb_fn || cb->event != event ||
4134 (cb_arg != (void *)-1 && cb->cb_arg != cb_arg))
4138 * if this callback is not executing right now,
4141 if (cb->active == 0) {
4142 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
4148 } while (++next_port <= last_port);
4150 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4155 rte_eth_dev_callback_process(struct rte_eth_dev *dev,
4156 enum rte_eth_event_type event, void *ret_param)
4158 struct rte_eth_dev_callback *cb_lst;
4159 struct rte_eth_dev_callback dev_cb;
4162 rte_spinlock_lock(&rte_eth_dev_cb_lock);
4163 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
4164 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
4168 if (ret_param != NULL)
4169 dev_cb.ret_param = ret_param;
4171 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4172 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
4173 dev_cb.cb_arg, dev_cb.ret_param);
4174 rte_spinlock_lock(&rte_eth_dev_cb_lock);
4177 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
4182 rte_eth_dev_probing_finish(struct rte_eth_dev *dev)
4187 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_NEW, NULL);
4189 dev->state = RTE_ETH_DEV_ATTACHED;
4193 rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
4196 struct rte_eth_dev *dev;
4197 struct rte_intr_handle *intr_handle;
4201 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4203 dev = &rte_eth_devices[port_id];
4205 if (!dev->intr_handle) {
4206 RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
4210 intr_handle = dev->intr_handle;
4211 if (!intr_handle->intr_vec) {
4212 RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
4216 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
4217 vec = intr_handle->intr_vec[qid];
4218 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
4219 if (rc && rc != -EEXIST) {
4221 "p %u q %u rx ctl error op %d epfd %d vec %u\n",
4222 port_id, qid, op, epfd, vec);
4230 rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
4232 struct rte_intr_handle *intr_handle;
4233 struct rte_eth_dev *dev;
4234 unsigned int efd_idx;
4238 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
4240 dev = &rte_eth_devices[port_id];
4242 if (queue_id >= dev->data->nb_rx_queues) {
4243 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4247 if (!dev->intr_handle) {
4248 RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
4252 intr_handle = dev->intr_handle;
4253 if (!intr_handle->intr_vec) {
4254 RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
4258 vec = intr_handle->intr_vec[queue_id];
4259 efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ?
4260 (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec;
4261 fd = intr_handle->efds[efd_idx];
4267 eth_dma_mzone_name(char *name, size_t len, uint16_t port_id, uint16_t queue_id,
4268 const char *ring_name)
4270 return snprintf(name, len, "eth_p%d_q%d_%s",
4271 port_id, queue_id, ring_name);
4274 const struct rte_memzone *
4275 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
4276 uint16_t queue_id, size_t size, unsigned align,
4279 char z_name[RTE_MEMZONE_NAMESIZE];
4280 const struct rte_memzone *mz;
4283 rc = eth_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id,
4284 queue_id, ring_name);
4285 if (rc >= RTE_MEMZONE_NAMESIZE) {
4286 RTE_ETHDEV_LOG(ERR, "ring name too long\n");
4287 rte_errno = ENAMETOOLONG;
4291 mz = rte_memzone_lookup(z_name);
4293 if ((socket_id != SOCKET_ID_ANY && socket_id != mz->socket_id) ||
4295 ((uintptr_t)mz->addr & (align - 1)) != 0) {
4297 "memzone %s does not justify the requested attributes\n",
4305 return rte_memzone_reserve_aligned(z_name, size, socket_id,
4306 RTE_MEMZONE_IOVA_CONTIG, align);
4310 rte_eth_dma_zone_free(const struct rte_eth_dev *dev, const char *ring_name,
4313 char z_name[RTE_MEMZONE_NAMESIZE];
4314 const struct rte_memzone *mz;
4317 rc = eth_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id,
4318 queue_id, ring_name);
4319 if (rc >= RTE_MEMZONE_NAMESIZE) {
4320 RTE_ETHDEV_LOG(ERR, "ring name too long\n");
4321 return -ENAMETOOLONG;
4324 mz = rte_memzone_lookup(z_name);
4326 rc = rte_memzone_free(mz);
4334 rte_eth_dev_create(struct rte_device *device, const char *name,
4335 size_t priv_data_size,
4336 ethdev_bus_specific_init ethdev_bus_specific_init,
4337 void *bus_init_params,
4338 ethdev_init_t ethdev_init, void *init_params)
4340 struct rte_eth_dev *ethdev;
4343 RTE_FUNC_PTR_OR_ERR_RET(*ethdev_init, -EINVAL);
4345 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
4346 ethdev = rte_eth_dev_allocate(name);
4350 if (priv_data_size) {
4351 ethdev->data->dev_private = rte_zmalloc_socket(
4352 name, priv_data_size, RTE_CACHE_LINE_SIZE,
4355 if (!ethdev->data->dev_private) {
4357 "failed to allocate private data\n");
4363 ethdev = rte_eth_dev_attach_secondary(name);
4366 "secondary process attach failed, ethdev doesn't exist\n");
4371 ethdev->device = device;
4373 if (ethdev_bus_specific_init) {
4374 retval = ethdev_bus_specific_init(ethdev, bus_init_params);
4377 "ethdev bus specific initialisation failed\n");
4382 retval = ethdev_init(ethdev, init_params);
4384 RTE_ETHDEV_LOG(ERR, "ethdev initialisation failed\n");
4388 rte_eth_dev_probing_finish(ethdev);
4393 rte_eth_dev_release_port(ethdev);
4398 rte_eth_dev_destroy(struct rte_eth_dev *ethdev,
4399 ethdev_uninit_t ethdev_uninit)
4403 ethdev = rte_eth_dev_allocated(ethdev->data->name);
4407 RTE_FUNC_PTR_OR_ERR_RET(*ethdev_uninit, -EINVAL);
4409 ret = ethdev_uninit(ethdev);
4413 return rte_eth_dev_release_port(ethdev);
4417 rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
4418 int epfd, int op, void *data)
4421 struct rte_eth_dev *dev;
4422 struct rte_intr_handle *intr_handle;
4425 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4427 dev = &rte_eth_devices[port_id];
4428 if (queue_id >= dev->data->nb_rx_queues) {
4429 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4433 if (!dev->intr_handle) {
4434 RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
4438 intr_handle = dev->intr_handle;
4439 if (!intr_handle->intr_vec) {
4440 RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
4444 vec = intr_handle->intr_vec[queue_id];
4445 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
4446 if (rc && rc != -EEXIST) {
4448 "p %u q %u rx ctl error op %d epfd %d vec %u\n",
4449 port_id, queue_id, op, epfd, vec);
4457 rte_eth_dev_rx_intr_enable(uint16_t port_id,
4460 struct rte_eth_dev *dev;
4462 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4464 dev = &rte_eth_devices[port_id];
4466 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
4467 return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_enable)(dev,
4472 rte_eth_dev_rx_intr_disable(uint16_t port_id,
4475 struct rte_eth_dev *dev;
4477 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4479 dev = &rte_eth_devices[port_id];
4481 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
4482 return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_disable)(dev,
4488 rte_eth_dev_filter_supported(uint16_t port_id,
4489 enum rte_filter_type filter_type)
4491 struct rte_eth_dev *dev;
4493 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4495 dev = &rte_eth_devices[port_id];
4496 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
4497 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
4498 RTE_ETH_FILTER_NOP, NULL);
4502 rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
4503 enum rte_filter_op filter_op, void *arg)
4505 struct rte_eth_dev *dev;
4507 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4509 dev = &rte_eth_devices[port_id];
4510 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
4511 return eth_err(port_id, (*dev->dev_ops->filter_ctrl)(dev, filter_type,
4515 const struct rte_eth_rxtx_callback *
4516 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
4517 rte_rx_callback_fn fn, void *user_param)
4519 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4520 rte_errno = ENOTSUP;
4523 struct rte_eth_dev *dev;
4525 /* check input parameters */
4526 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
4527 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
4531 dev = &rte_eth_devices[port_id];
4532 if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
4536 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
4544 cb->param = user_param;
4546 rte_spinlock_lock(&rte_eth_rx_cb_lock);
4547 /* Add the callbacks in fifo order. */
4548 struct rte_eth_rxtx_callback *tail =
4549 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
4552 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
4559 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
4564 const struct rte_eth_rxtx_callback *
4565 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
4566 rte_rx_callback_fn fn, void *user_param)
4568 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4569 rte_errno = ENOTSUP;
4572 /* check input parameters */
4573 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
4574 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
4579 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
4587 cb->param = user_param;
4589 rte_spinlock_lock(&rte_eth_rx_cb_lock);
4590 /* Add the callbacks at first position */
4591 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
4593 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
4594 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
4599 const struct rte_eth_rxtx_callback *
4600 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
4601 rte_tx_callback_fn fn, void *user_param)
4603 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4604 rte_errno = ENOTSUP;
4607 struct rte_eth_dev *dev;
4609 /* check input parameters */
4610 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
4611 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
4616 dev = &rte_eth_devices[port_id];
4617 if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
4622 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
4630 cb->param = user_param;
4632 rte_spinlock_lock(&rte_eth_tx_cb_lock);
4633 /* Add the callbacks in fifo order. */
4634 struct rte_eth_rxtx_callback *tail =
4635 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
4638 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
4645 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
4651 rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
4652 const struct rte_eth_rxtx_callback *user_cb)
4654 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4657 /* Check input parameters. */
4658 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
4659 if (user_cb == NULL ||
4660 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
4663 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
4664 struct rte_eth_rxtx_callback *cb;
4665 struct rte_eth_rxtx_callback **prev_cb;
4668 rte_spinlock_lock(&rte_eth_rx_cb_lock);
4669 prev_cb = &dev->post_rx_burst_cbs[queue_id];
4670 for (; *prev_cb != NULL; prev_cb = &cb->next) {
4672 if (cb == user_cb) {
4673 /* Remove the user cb from the callback list. */
4674 *prev_cb = cb->next;
4679 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
4685 rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
4686 const struct rte_eth_rxtx_callback *user_cb)
4688 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4691 /* Check input parameters. */
4692 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
4693 if (user_cb == NULL ||
4694 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
4697 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
4699 struct rte_eth_rxtx_callback *cb;
4700 struct rte_eth_rxtx_callback **prev_cb;
4702 rte_spinlock_lock(&rte_eth_tx_cb_lock);
4703 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
4704 for (; *prev_cb != NULL; prev_cb = &cb->next) {
4706 if (cb == user_cb) {
4707 /* Remove the user cb from the callback list. */
4708 *prev_cb = cb->next;
4713 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
4719 rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
4720 struct rte_eth_rxq_info *qinfo)
4722 struct rte_eth_dev *dev;
4724 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4729 dev = &rte_eth_devices[port_id];
4730 if (queue_id >= dev->data->nb_rx_queues) {
4731 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4735 if (dev->data->rx_queues == NULL ||
4736 dev->data->rx_queues[queue_id] == NULL) {
4738 "Rx queue %"PRIu16" of device with port_id=%"
4739 PRIu16" has not been setup\n",
4744 if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
4745 RTE_ETHDEV_LOG(INFO,
4746 "Can't get hairpin Rx queue %"PRIu16" info of device with port_id=%"PRIu16"\n",
4751 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
4753 memset(qinfo, 0, sizeof(*qinfo));
4754 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
4759 rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
4760 struct rte_eth_txq_info *qinfo)
4762 struct rte_eth_dev *dev;
4764 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4769 dev = &rte_eth_devices[port_id];
4770 if (queue_id >= dev->data->nb_tx_queues) {
4771 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id);
4775 if (dev->data->tx_queues == NULL ||
4776 dev->data->tx_queues[queue_id] == NULL) {
4778 "Tx queue %"PRIu16" of device with port_id=%"
4779 PRIu16" has not been setup\n",
4784 if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
4785 RTE_ETHDEV_LOG(INFO,
4786 "Can't get hairpin Tx queue %"PRIu16" info of device with port_id=%"PRIu16"\n",
4791 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
4793 memset(qinfo, 0, sizeof(*qinfo));
4794 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
4800 rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
4801 struct rte_eth_burst_mode *mode)
4803 struct rte_eth_dev *dev;
4805 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4810 dev = &rte_eth_devices[port_id];
4812 if (queue_id >= dev->data->nb_rx_queues) {
4813 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4817 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_burst_mode_get, -ENOTSUP);
4818 memset(mode, 0, sizeof(*mode));
4819 return eth_err(port_id,
4820 dev->dev_ops->rx_burst_mode_get(dev, queue_id, mode));
4824 rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
4825 struct rte_eth_burst_mode *mode)
4827 struct rte_eth_dev *dev;
4829 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4834 dev = &rte_eth_devices[port_id];
4836 if (queue_id >= dev->data->nb_tx_queues) {
4837 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id);
4841 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_burst_mode_get, -ENOTSUP);
4842 memset(mode, 0, sizeof(*mode));
4843 return eth_err(port_id,
4844 dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode));
4848 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
4849 struct rte_ether_addr *mc_addr_set,
4850 uint32_t nb_mc_addr)
4852 struct rte_eth_dev *dev;
4854 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4856 dev = &rte_eth_devices[port_id];
4857 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
4858 return eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev,
4859 mc_addr_set, nb_mc_addr));
4863 rte_eth_timesync_enable(uint16_t port_id)
4865 struct rte_eth_dev *dev;
4867 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4868 dev = &rte_eth_devices[port_id];
4870 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
4871 return eth_err(port_id, (*dev->dev_ops->timesync_enable)(dev));
4875 rte_eth_timesync_disable(uint16_t port_id)
4877 struct rte_eth_dev *dev;
4879 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4880 dev = &rte_eth_devices[port_id];
4882 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
4883 return eth_err(port_id, (*dev->dev_ops->timesync_disable)(dev));
4887 rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
4890 struct rte_eth_dev *dev;
4892 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4893 dev = &rte_eth_devices[port_id];
4895 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
4896 return eth_err(port_id, (*dev->dev_ops->timesync_read_rx_timestamp)
4897 (dev, timestamp, flags));
4901 rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
4902 struct timespec *timestamp)
4904 struct rte_eth_dev *dev;
4906 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4907 dev = &rte_eth_devices[port_id];
4909 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
4910 return eth_err(port_id, (*dev->dev_ops->timesync_read_tx_timestamp)
4915 rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
4917 struct rte_eth_dev *dev;
4919 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4920 dev = &rte_eth_devices[port_id];
4922 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
4923 return eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev,
4928 rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
4930 struct rte_eth_dev *dev;
4932 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4933 dev = &rte_eth_devices[port_id];
4935 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
4936 return eth_err(port_id, (*dev->dev_ops->timesync_read_time)(dev,
4941 rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
4943 struct rte_eth_dev *dev;
4945 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4946 dev = &rte_eth_devices[port_id];
4948 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
4949 return eth_err(port_id, (*dev->dev_ops->timesync_write_time)(dev,
4954 rte_eth_read_clock(uint16_t port_id, uint64_t *clock)
4956 struct rte_eth_dev *dev;
4958 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4959 dev = &rte_eth_devices[port_id];
4961 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->read_clock, -ENOTSUP);
4962 return eth_err(port_id, (*dev->dev_ops->read_clock)(dev, clock));
4966 rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
4968 struct rte_eth_dev *dev;
4970 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4972 dev = &rte_eth_devices[port_id];
4973 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
4974 return eth_err(port_id, (*dev->dev_ops->get_reg)(dev, info));
4978 rte_eth_dev_get_eeprom_length(uint16_t port_id)
4980 struct rte_eth_dev *dev;
4982 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4984 dev = &rte_eth_devices[port_id];
4985 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
4986 return eth_err(port_id, (*dev->dev_ops->get_eeprom_length)(dev));
4990 rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
4992 struct rte_eth_dev *dev;
4994 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4996 dev = &rte_eth_devices[port_id];
4997 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
4998 return eth_err(port_id, (*dev->dev_ops->get_eeprom)(dev, info));
5002 rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
5004 struct rte_eth_dev *dev;
5006 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5008 dev = &rte_eth_devices[port_id];
5009 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
5010 return eth_err(port_id, (*dev->dev_ops->set_eeprom)(dev, info));
5014 rte_eth_dev_get_module_info(uint16_t port_id,
5015 struct rte_eth_dev_module_info *modinfo)
5017 struct rte_eth_dev *dev;
5019 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5021 dev = &rte_eth_devices[port_id];
5022 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_info, -ENOTSUP);
5023 return (*dev->dev_ops->get_module_info)(dev, modinfo);
5027 rte_eth_dev_get_module_eeprom(uint16_t port_id,
5028 struct rte_dev_eeprom_info *info)
5030 struct rte_eth_dev *dev;
5032 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5034 dev = &rte_eth_devices[port_id];
5035 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_eeprom, -ENOTSUP);
5036 return (*dev->dev_ops->get_module_eeprom)(dev, info);
5040 rte_eth_dev_get_dcb_info(uint16_t port_id,
5041 struct rte_eth_dcb_info *dcb_info)
5043 struct rte_eth_dev *dev;
5045 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5047 dev = &rte_eth_devices[port_id];
5048 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
5050 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
5051 return eth_err(port_id, (*dev->dev_ops->get_dcb_info)(dev, dcb_info));
5055 rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
5056 struct rte_eth_l2_tunnel_conf *l2_tunnel)
5058 struct rte_eth_dev *dev;
5060 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5061 if (l2_tunnel == NULL) {
5062 RTE_ETHDEV_LOG(ERR, "Invalid l2_tunnel parameter\n");
5066 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
5067 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
5071 dev = &rte_eth_devices[port_id];
5072 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
5074 return eth_err(port_id, (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev,
5079 rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
5080 struct rte_eth_l2_tunnel_conf *l2_tunnel,
5084 struct rte_eth_dev *dev;
5086 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5088 if (l2_tunnel == NULL) {
5089 RTE_ETHDEV_LOG(ERR, "Invalid l2_tunnel parameter\n");
5093 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
5094 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
5099 RTE_ETHDEV_LOG(ERR, "Mask should have a value\n");
5103 dev = &rte_eth_devices[port_id];
5104 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
5106 return eth_err(port_id, (*dev->dev_ops->l2_tunnel_offload_set)(dev,
5107 l2_tunnel, mask, en));
5111 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
5112 const struct rte_eth_desc_lim *desc_lim)
5114 if (desc_lim->nb_align != 0)
5115 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
5117 if (desc_lim->nb_max != 0)
5118 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
5120 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
5124 rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
5125 uint16_t *nb_rx_desc,
5126 uint16_t *nb_tx_desc)
5128 struct rte_eth_dev_info dev_info;
5131 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5133 ret = rte_eth_dev_info_get(port_id, &dev_info);
5137 if (nb_rx_desc != NULL)
5138 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
5140 if (nb_tx_desc != NULL)
5141 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
5147 rte_eth_dev_hairpin_capability_get(uint16_t port_id,
5148 struct rte_eth_hairpin_cap *cap)
5150 struct rte_eth_dev *dev;
5152 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
5154 dev = &rte_eth_devices[port_id];
5155 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_cap_get, -ENOTSUP);
5156 memset(cap, 0, sizeof(*cap));
5157 return eth_err(port_id, (*dev->dev_ops->hairpin_cap_get)(dev, cap));
5161 rte_eth_dev_is_rx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id)
5163 if (dev->data->rx_queue_state[queue_id] ==
5164 RTE_ETH_QUEUE_STATE_HAIRPIN)
5170 rte_eth_dev_is_tx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id)
5172 if (dev->data->tx_queue_state[queue_id] ==
5173 RTE_ETH_QUEUE_STATE_HAIRPIN)
5179 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
5181 struct rte_eth_dev *dev;
5183 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5188 dev = &rte_eth_devices[port_id];
5190 if (*dev->dev_ops->pool_ops_supported == NULL)
5191 return 1; /* all pools are supported */
5193 return (*dev->dev_ops->pool_ops_supported)(dev, pool);
5197 * A set of values to describe the possible states of a switch domain.
5199 enum rte_eth_switch_domain_state {
5200 RTE_ETH_SWITCH_DOMAIN_UNUSED = 0,
5201 RTE_ETH_SWITCH_DOMAIN_ALLOCATED
5205 * Array of switch domains available for allocation. Array is sized to
5206 * RTE_MAX_ETHPORTS elements as there cannot be more active switch domains than
5207 * ethdev ports in a single process.
5209 static struct rte_eth_dev_switch {
5210 enum rte_eth_switch_domain_state state;
5211 } rte_eth_switch_domains[RTE_MAX_ETHPORTS];
5214 rte_eth_switch_domain_alloc(uint16_t *domain_id)
5218 *domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
5220 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
5221 if (rte_eth_switch_domains[i].state ==
5222 RTE_ETH_SWITCH_DOMAIN_UNUSED) {
5223 rte_eth_switch_domains[i].state =
5224 RTE_ETH_SWITCH_DOMAIN_ALLOCATED;
5234 rte_eth_switch_domain_free(uint16_t domain_id)
5236 if (domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID ||
5237 domain_id >= RTE_MAX_ETHPORTS)
5240 if (rte_eth_switch_domains[domain_id].state !=
5241 RTE_ETH_SWITCH_DOMAIN_ALLOCATED)
5244 rte_eth_switch_domains[domain_id].state = RTE_ETH_SWITCH_DOMAIN_UNUSED;
5250 rte_eth_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
5253 struct rte_kvargs_pair *pair;
5256 arglist->str = strdup(str_in);
5257 if (arglist->str == NULL)
5260 letter = arglist->str;
5263 pair = &arglist->pairs[0];
5266 case 0: /* Initial */
5269 else if (*letter == '\0')
5276 case 1: /* Parsing key */
5277 if (*letter == '=') {
5279 pair->value = letter + 1;
5281 } else if (*letter == ',' || *letter == '\0')
5286 case 2: /* Parsing value */
5289 else if (*letter == ',') {
5292 pair = &arglist->pairs[arglist->count];
5294 } else if (*letter == '\0') {
5297 pair = &arglist->pairs[arglist->count];
5302 case 3: /* Parsing list */
5305 else if (*letter == '\0')
5314 rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
5316 struct rte_kvargs args;
5317 struct rte_kvargs_pair *pair;
5321 memset(eth_da, 0, sizeof(*eth_da));
5323 result = rte_eth_devargs_tokenise(&args, dargs);
5327 for (i = 0; i < args.count; i++) {
5328 pair = &args.pairs[i];
5329 if (strcmp("representor", pair->key) == 0) {
5330 result = rte_eth_devargs_parse_list(pair->value,
5331 rte_eth_devargs_parse_representor_ports,
5346 handle_port_list(const char *cmd __rte_unused,
5347 const char *params __rte_unused,
5348 struct rte_tel_data *d)
5352 rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
5353 RTE_ETH_FOREACH_DEV(port_id)
5354 rte_tel_data_add_array_int(d, port_id);
5359 add_port_queue_stats(struct rte_tel_data *d, uint64_t *q_stats,
5360 const char *stat_name)
5363 struct rte_tel_data *q_data = rte_tel_data_alloc();
5364 rte_tel_data_start_array(q_data, RTE_TEL_U64_VAL);
5365 for (q = 0; q < RTE_ETHDEV_QUEUE_STAT_CNTRS; q++)
5366 rte_tel_data_add_array_u64(q_data, q_stats[q]);
5367 rte_tel_data_add_dict_container(d, stat_name, q_data, 0);
5370 #define ADD_DICT_STAT(stats, s) rte_tel_data_add_dict_u64(d, #s, stats.s)
5373 handle_port_stats(const char *cmd __rte_unused,
5375 struct rte_tel_data *d)
5377 struct rte_eth_stats stats;
5380 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
5383 port_id = atoi(params);
5384 if (!rte_eth_dev_is_valid_port(port_id))
5387 ret = rte_eth_stats_get(port_id, &stats);
5391 rte_tel_data_start_dict(d);
5392 ADD_DICT_STAT(stats, ipackets);
5393 ADD_DICT_STAT(stats, opackets);
5394 ADD_DICT_STAT(stats, ibytes);
5395 ADD_DICT_STAT(stats, obytes);
5396 ADD_DICT_STAT(stats, imissed);
5397 ADD_DICT_STAT(stats, ierrors);
5398 ADD_DICT_STAT(stats, oerrors);
5399 ADD_DICT_STAT(stats, rx_nombuf);
5400 add_port_queue_stats(d, stats.q_ipackets, "q_ipackets");
5401 add_port_queue_stats(d, stats.q_opackets, "q_opackets");
5402 add_port_queue_stats(d, stats.q_ibytes, "q_ibytes");
5403 add_port_queue_stats(d, stats.q_obytes, "q_obytes");
5404 add_port_queue_stats(d, stats.q_errors, "q_errors");
5410 handle_port_xstats(const char *cmd __rte_unused,
5412 struct rte_tel_data *d)
5414 struct rte_eth_xstat *eth_xstats;
5415 struct rte_eth_xstat_name *xstat_names;
5416 int port_id, num_xstats;
5420 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
5423 port_id = strtoul(params, &end_param, 0);
5424 if (*end_param != '\0')
5425 RTE_ETHDEV_LOG(NOTICE,
5426 "Extra parameters passed to ethdev telemetry command, ignoring");
5427 if (!rte_eth_dev_is_valid_port(port_id))
5430 num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
5434 /* use one malloc for both names and stats */
5435 eth_xstats = malloc((sizeof(struct rte_eth_xstat) +
5436 sizeof(struct rte_eth_xstat_name)) * num_xstats);
5437 if (eth_xstats == NULL)
5439 xstat_names = (void *)ð_xstats[num_xstats];
5441 ret = rte_eth_xstats_get_names(port_id, xstat_names, num_xstats);
5442 if (ret < 0 || ret > num_xstats) {
5447 ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
5448 if (ret < 0 || ret > num_xstats) {
5453 rte_tel_data_start_dict(d);
5454 for (i = 0; i < num_xstats; i++)
5455 rte_tel_data_add_dict_u64(d, xstat_names[i].name,
5456 eth_xstats[i].value);
5461 handle_port_link_status(const char *cmd __rte_unused,
5463 struct rte_tel_data *d)
5465 static const char *status_str = "status";
5467 struct rte_eth_link link;
5470 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
5473 port_id = strtoul(params, &end_param, 0);
5474 if (*end_param != '\0')
5475 RTE_ETHDEV_LOG(NOTICE,
5476 "Extra parameters passed to ethdev telemetry command, ignoring");
5477 if (!rte_eth_dev_is_valid_port(port_id))
5480 ret = rte_eth_link_get(port_id, &link);
5484 rte_tel_data_start_dict(d);
5485 if (!link.link_status) {
5486 rte_tel_data_add_dict_string(d, status_str, "DOWN");
5489 rte_tel_data_add_dict_string(d, status_str, "UP");
5490 rte_tel_data_add_dict_u64(d, "speed", link.link_speed);
5491 rte_tel_data_add_dict_string(d, "duplex",
5492 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
5493 "full-duplex" : "half-duplex");
5497 RTE_LOG_REGISTER(rte_eth_dev_logtype, lib.ethdev, INFO);
5499 RTE_INIT(ethdev_init_telemetry)
5501 rte_telemetry_register_cmd("/ethdev/list", handle_port_list,
5502 "Returns list of available ethdev ports. Takes no parameters");
5503 rte_telemetry_register_cmd("/ethdev/stats", handle_port_stats,
5504 "Returns the common stats for a port. Parameters: int port_id");
5505 rte_telemetry_register_cmd("/ethdev/xstats", handle_port_xstats,
5506 "Returns the extended stats for a port. Parameters: int port_id");
5507 rte_telemetry_register_cmd("/ethdev/link_status",
5508 handle_port_link_status,
5509 "Returns the link status for a port. Parameters: int port_id");