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>
42 #include "rte_ethdev.h"
43 #include "rte_ethdev_driver.h"
44 #include "ethdev_profile.h"
45 #include "ethdev_private.h"
47 int rte_eth_dev_logtype;
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 (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
91 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
92 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
93 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
94 {"errors", offsetof(struct rte_eth_stats, q_errors)},
97 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
98 sizeof(rte_rxq_stats_strings[0]))
100 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
101 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
102 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
104 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
105 sizeof(rte_txq_stats_strings[0]))
107 #define RTE_RX_OFFLOAD_BIT2STR(_name) \
108 { DEV_RX_OFFLOAD_##_name, #_name }
110 static const struct {
113 } rte_rx_offload_names[] = {
114 RTE_RX_OFFLOAD_BIT2STR(VLAN_STRIP),
115 RTE_RX_OFFLOAD_BIT2STR(IPV4_CKSUM),
116 RTE_RX_OFFLOAD_BIT2STR(UDP_CKSUM),
117 RTE_RX_OFFLOAD_BIT2STR(TCP_CKSUM),
118 RTE_RX_OFFLOAD_BIT2STR(TCP_LRO),
119 RTE_RX_OFFLOAD_BIT2STR(QINQ_STRIP),
120 RTE_RX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
121 RTE_RX_OFFLOAD_BIT2STR(MACSEC_STRIP),
122 RTE_RX_OFFLOAD_BIT2STR(HEADER_SPLIT),
123 RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
124 RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
125 RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
126 RTE_RX_OFFLOAD_BIT2STR(SCATTER),
127 RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
128 RTE_RX_OFFLOAD_BIT2STR(SECURITY),
129 RTE_RX_OFFLOAD_BIT2STR(KEEP_CRC),
130 RTE_RX_OFFLOAD_BIT2STR(SCTP_CKSUM),
131 RTE_RX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
134 #undef RTE_RX_OFFLOAD_BIT2STR
136 #define RTE_TX_OFFLOAD_BIT2STR(_name) \
137 { DEV_TX_OFFLOAD_##_name, #_name }
139 static const struct {
142 } rte_tx_offload_names[] = {
143 RTE_TX_OFFLOAD_BIT2STR(VLAN_INSERT),
144 RTE_TX_OFFLOAD_BIT2STR(IPV4_CKSUM),
145 RTE_TX_OFFLOAD_BIT2STR(UDP_CKSUM),
146 RTE_TX_OFFLOAD_BIT2STR(TCP_CKSUM),
147 RTE_TX_OFFLOAD_BIT2STR(SCTP_CKSUM),
148 RTE_TX_OFFLOAD_BIT2STR(TCP_TSO),
149 RTE_TX_OFFLOAD_BIT2STR(UDP_TSO),
150 RTE_TX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
151 RTE_TX_OFFLOAD_BIT2STR(QINQ_INSERT),
152 RTE_TX_OFFLOAD_BIT2STR(VXLAN_TNL_TSO),
153 RTE_TX_OFFLOAD_BIT2STR(GRE_TNL_TSO),
154 RTE_TX_OFFLOAD_BIT2STR(IPIP_TNL_TSO),
155 RTE_TX_OFFLOAD_BIT2STR(GENEVE_TNL_TSO),
156 RTE_TX_OFFLOAD_BIT2STR(MACSEC_INSERT),
157 RTE_TX_OFFLOAD_BIT2STR(MT_LOCKFREE),
158 RTE_TX_OFFLOAD_BIT2STR(MULTI_SEGS),
159 RTE_TX_OFFLOAD_BIT2STR(MBUF_FAST_FREE),
160 RTE_TX_OFFLOAD_BIT2STR(SECURITY),
161 RTE_TX_OFFLOAD_BIT2STR(UDP_TNL_TSO),
162 RTE_TX_OFFLOAD_BIT2STR(IP_TNL_TSO),
163 RTE_TX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
164 RTE_TX_OFFLOAD_BIT2STR(MATCH_METADATA),
167 #undef RTE_TX_OFFLOAD_BIT2STR
169 static const struct {
172 } rte_burst_option_names[] = {
173 { RTE_ETH_BURST_SCALAR, "Scalar" },
174 { RTE_ETH_BURST_VECTOR, "Vector" },
176 { RTE_ETH_BURST_ALTIVEC, "AltiVec" },
177 { RTE_ETH_BURST_NEON, "Neon" },
178 { RTE_ETH_BURST_SSE, "SSE" },
179 { RTE_ETH_BURST_AVX2, "AVX2" },
180 { RTE_ETH_BURST_AVX512, "AVX512" },
182 { RTE_ETH_BURST_SCATTERED, "Scattered" },
183 { RTE_ETH_BURST_BULK_ALLOC, "Bulk Alloc" },
184 { RTE_ETH_BURST_SIMPLE, "Simple" },
185 { RTE_ETH_BURST_PER_QUEUE, "Per Queue" },
189 * The user application callback description.
191 * It contains callback address to be registered by user application,
192 * the pointer to the parameters for callback, and the event type.
194 struct rte_eth_dev_callback {
195 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
196 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
197 void *cb_arg; /**< Parameter for callback */
198 void *ret_param; /**< Return parameter */
199 enum rte_eth_event_type event; /**< Interrupt event type */
200 uint32_t active; /**< Callback is executing */
209 rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
212 struct rte_devargs devargs = {.args = NULL};
213 const char *bus_param_key;
214 char *bus_str = NULL;
215 char *cls_str = NULL;
218 memset(iter, 0, sizeof(*iter));
221 * The devargs string may use various syntaxes:
222 * - 0000:08:00.0,representor=[1-3]
223 * - pci:0000:06:00.0,representor=[0,5]
224 * - class=eth,mac=00:11:22:33:44:55
225 * A new syntax is in development (not yet supported):
226 * - bus=X,paramX=x/class=Y,paramY=y/driver=Z,paramZ=z
230 * Handle pure class filter (i.e. without any bus-level argument),
231 * from future new syntax.
232 * rte_devargs_parse() is not yet supporting the new syntax,
233 * that's why this simple case is temporarily parsed here.
235 #define iter_anybus_str "class=eth,"
236 if (strncmp(devargs_str, iter_anybus_str,
237 strlen(iter_anybus_str)) == 0) {
238 iter->cls_str = devargs_str + strlen(iter_anybus_str);
242 /* Split bus, device and parameters. */
243 ret = rte_devargs_parse(&devargs, devargs_str);
248 * Assume parameters of old syntax can match only at ethdev level.
249 * Extra parameters will be ignored, thanks to "+" prefix.
251 str_size = strlen(devargs.args) + 2;
252 cls_str = malloc(str_size);
253 if (cls_str == NULL) {
257 ret = snprintf(cls_str, str_size, "+%s", devargs.args);
258 if (ret != str_size - 1) {
262 iter->cls_str = cls_str;
263 free(devargs.args); /* allocated by rte_devargs_parse() */
266 iter->bus = devargs.bus;
267 if (iter->bus->dev_iterate == NULL) {
272 /* Convert bus args to new syntax for use with new API dev_iterate. */
273 if (strcmp(iter->bus->name, "vdev") == 0) {
274 bus_param_key = "name";
275 } else if (strcmp(iter->bus->name, "pci") == 0) {
276 bus_param_key = "addr";
281 str_size = strlen(bus_param_key) + strlen(devargs.name) + 2;
282 bus_str = malloc(str_size);
283 if (bus_str == NULL) {
287 ret = snprintf(bus_str, str_size, "%s=%s",
288 bus_param_key, devargs.name);
289 if (ret != str_size - 1) {
293 iter->bus_str = bus_str;
296 iter->cls = rte_class_find_by_name("eth");
301 RTE_LOG(ERR, EAL, "Bus %s does not support iterating.\n",
310 rte_eth_iterator_next(struct rte_dev_iterator *iter)
312 if (iter->cls == NULL) /* invalid ethdev iterator */
313 return RTE_MAX_ETHPORTS;
315 do { /* loop to try all matching rte_device */
316 /* If not pure ethdev filter and */
317 if (iter->bus != NULL &&
318 /* not in middle of rte_eth_dev iteration, */
319 iter->class_device == NULL) {
320 /* get next rte_device to try. */
321 iter->device = iter->bus->dev_iterate(
322 iter->device, iter->bus_str, iter);
323 if (iter->device == NULL)
324 break; /* no more rte_device candidate */
326 /* A device is matching bus part, need to check ethdev part. */
327 iter->class_device = iter->cls->dev_iterate(
328 iter->class_device, iter->cls_str, iter);
329 if (iter->class_device != NULL)
330 return eth_dev_to_id(iter->class_device); /* match */
331 } while (iter->bus != NULL); /* need to try next rte_device */
333 /* No more ethdev port to iterate. */
334 rte_eth_iterator_cleanup(iter);
335 return RTE_MAX_ETHPORTS;
339 rte_eth_iterator_cleanup(struct rte_dev_iterator *iter)
341 if (iter->bus_str == NULL)
342 return; /* nothing to free in pure class filter */
343 free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */
344 free(RTE_CAST_FIELD(iter, cls_str, char *)); /* workaround const */
345 memset(iter, 0, sizeof(*iter));
349 rte_eth_find_next(uint16_t port_id)
351 while (port_id < RTE_MAX_ETHPORTS &&
352 rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)
355 if (port_id >= RTE_MAX_ETHPORTS)
356 return RTE_MAX_ETHPORTS;
362 * Macro to iterate over all valid ports for internal usage.
363 * Note: RTE_ETH_FOREACH_DEV is different because filtering owned ports.
365 #define RTE_ETH_FOREACH_VALID_DEV(port_id) \
366 for (port_id = rte_eth_find_next(0); \
367 port_id < RTE_MAX_ETHPORTS; \
368 port_id = rte_eth_find_next(port_id + 1))
371 rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
373 port_id = rte_eth_find_next(port_id);
374 while (port_id < RTE_MAX_ETHPORTS &&
375 rte_eth_devices[port_id].device != parent)
376 port_id = rte_eth_find_next(port_id + 1);
382 rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id)
384 RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS);
385 return rte_eth_find_next_of(port_id,
386 rte_eth_devices[ref_port_id].device);
390 rte_eth_dev_shared_data_prepare(void)
392 const unsigned flags = 0;
393 const struct rte_memzone *mz;
395 rte_spinlock_lock(&rte_eth_shared_data_lock);
397 if (rte_eth_dev_shared_data == NULL) {
398 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
399 /* Allocate port data and ownership shared memory. */
400 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
401 sizeof(*rte_eth_dev_shared_data),
402 rte_socket_id(), flags);
404 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
406 rte_panic("Cannot allocate ethdev shared data\n");
408 rte_eth_dev_shared_data = mz->addr;
409 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
410 rte_eth_dev_shared_data->next_owner_id =
411 RTE_ETH_DEV_NO_OWNER + 1;
412 rte_spinlock_init(&rte_eth_dev_shared_data->ownership_lock);
413 memset(rte_eth_dev_shared_data->data, 0,
414 sizeof(rte_eth_dev_shared_data->data));
418 rte_spinlock_unlock(&rte_eth_shared_data_lock);
422 is_allocated(const struct rte_eth_dev *ethdev)
424 return ethdev->data->name[0] != '\0';
427 static struct rte_eth_dev *
428 _rte_eth_dev_allocated(const char *name)
432 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
433 if (rte_eth_devices[i].data != NULL &&
434 strcmp(rte_eth_devices[i].data->name, name) == 0)
435 return &rte_eth_devices[i];
441 rte_eth_dev_allocated(const char *name)
443 struct rte_eth_dev *ethdev;
445 rte_eth_dev_shared_data_prepare();
447 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
449 ethdev = _rte_eth_dev_allocated(name);
451 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
457 rte_eth_dev_find_free_port(void)
461 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
462 /* Using shared name field to find a free port. */
463 if (rte_eth_dev_shared_data->data[i].name[0] == '\0') {
464 RTE_ASSERT(rte_eth_devices[i].state ==
469 return RTE_MAX_ETHPORTS;
472 static struct rte_eth_dev *
473 eth_dev_get(uint16_t port_id)
475 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
477 eth_dev->data = &rte_eth_dev_shared_data->data[port_id];
483 rte_eth_dev_allocate(const char *name)
486 struct rte_eth_dev *eth_dev = NULL;
489 name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN);
491 RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n");
495 if (name_len >= RTE_ETH_NAME_MAX_LEN) {
496 RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n");
500 rte_eth_dev_shared_data_prepare();
502 /* Synchronize port creation between primary and secondary threads. */
503 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
505 if (_rte_eth_dev_allocated(name) != NULL) {
507 "Ethernet device with name %s already allocated\n",
512 port_id = rte_eth_dev_find_free_port();
513 if (port_id == RTE_MAX_ETHPORTS) {
515 "Reached maximum number of Ethernet ports\n");
519 eth_dev = eth_dev_get(port_id);
520 strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
521 eth_dev->data->port_id = port_id;
522 eth_dev->data->mtu = RTE_ETHER_MTU;
525 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
531 * Attach to a port already registered by the primary process, which
532 * makes sure that the same device would have the same port id both
533 * in the primary and secondary process.
536 rte_eth_dev_attach_secondary(const char *name)
539 struct rte_eth_dev *eth_dev = NULL;
541 rte_eth_dev_shared_data_prepare();
543 /* Synchronize port attachment to primary port creation and release. */
544 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
546 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
547 if (strcmp(rte_eth_dev_shared_data->data[i].name, name) == 0)
550 if (i == RTE_MAX_ETHPORTS) {
552 "Device %s is not driven by the primary process\n",
555 eth_dev = eth_dev_get(i);
556 RTE_ASSERT(eth_dev->data->port_id == i);
559 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
564 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
569 rte_eth_dev_shared_data_prepare();
571 if (eth_dev->state != RTE_ETH_DEV_UNUSED)
572 _rte_eth_dev_callback_process(eth_dev,
573 RTE_ETH_EVENT_DESTROY, NULL);
575 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
577 eth_dev->state = RTE_ETH_DEV_UNUSED;
579 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
580 rte_free(eth_dev->data->rx_queues);
581 rte_free(eth_dev->data->tx_queues);
582 rte_free(eth_dev->data->mac_addrs);
583 rte_free(eth_dev->data->hash_mac_addrs);
584 rte_free(eth_dev->data->dev_private);
585 memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
588 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
594 rte_eth_dev_is_valid_port(uint16_t port_id)
596 if (port_id >= RTE_MAX_ETHPORTS ||
597 (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED))
604 rte_eth_is_valid_owner_id(uint64_t owner_id)
606 if (owner_id == RTE_ETH_DEV_NO_OWNER ||
607 rte_eth_dev_shared_data->next_owner_id <= owner_id)
613 rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
615 port_id = rte_eth_find_next(port_id);
616 while (port_id < RTE_MAX_ETHPORTS &&
617 rte_eth_devices[port_id].data->owner.id != owner_id)
618 port_id = rte_eth_find_next(port_id + 1);
624 rte_eth_dev_owner_new(uint64_t *owner_id)
626 rte_eth_dev_shared_data_prepare();
628 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
630 *owner_id = rte_eth_dev_shared_data->next_owner_id++;
632 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
637 _rte_eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id,
638 const struct rte_eth_dev_owner *new_owner)
640 struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
641 struct rte_eth_dev_owner *port_owner;
643 if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) {
644 RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
649 if (!rte_eth_is_valid_owner_id(new_owner->id) &&
650 !rte_eth_is_valid_owner_id(old_owner_id)) {
652 "Invalid owner old_id=%016"PRIx64" new_id=%016"PRIx64"\n",
653 old_owner_id, new_owner->id);
657 port_owner = &rte_eth_devices[port_id].data->owner;
658 if (port_owner->id != old_owner_id) {
660 "Cannot set owner to port %u already owned by %s_%016"PRIX64"\n",
661 port_id, port_owner->name, port_owner->id);
665 /* can not truncate (same structure) */
666 strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN);
668 port_owner->id = new_owner->id;
670 RTE_ETHDEV_LOG(DEBUG, "Port %u owner is %s_%016"PRIx64"\n",
671 port_id, new_owner->name, new_owner->id);
677 rte_eth_dev_owner_set(const uint16_t port_id,
678 const struct rte_eth_dev_owner *owner)
682 rte_eth_dev_shared_data_prepare();
684 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
686 ret = _rte_eth_dev_owner_set(port_id, RTE_ETH_DEV_NO_OWNER, owner);
688 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
693 rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id)
695 const struct rte_eth_dev_owner new_owner = (struct rte_eth_dev_owner)
696 {.id = RTE_ETH_DEV_NO_OWNER, .name = ""};
699 rte_eth_dev_shared_data_prepare();
701 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
703 ret = _rte_eth_dev_owner_set(port_id, owner_id, &new_owner);
705 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
710 rte_eth_dev_owner_delete(const uint64_t owner_id)
715 rte_eth_dev_shared_data_prepare();
717 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
719 if (rte_eth_is_valid_owner_id(owner_id)) {
720 for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++)
721 if (rte_eth_devices[port_id].data->owner.id == owner_id)
722 memset(&rte_eth_devices[port_id].data->owner, 0,
723 sizeof(struct rte_eth_dev_owner));
724 RTE_ETHDEV_LOG(NOTICE,
725 "All port owners owned by %016"PRIx64" identifier have removed\n",
729 "Invalid owner id=%016"PRIx64"\n",
734 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
740 rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
743 struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
745 rte_eth_dev_shared_data_prepare();
747 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
749 if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) {
750 RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
754 rte_memcpy(owner, ðdev->data->owner, sizeof(*owner));
757 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
762 rte_eth_dev_socket_id(uint16_t port_id)
764 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
765 return rte_eth_devices[port_id].data->numa_node;
769 rte_eth_dev_get_sec_ctx(uint16_t port_id)
771 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
772 return rte_eth_devices[port_id].security_ctx;
776 rte_eth_dev_count(void)
778 return rte_eth_dev_count_avail();
782 rte_eth_dev_count_avail(void)
789 RTE_ETH_FOREACH_DEV(p)
796 rte_eth_dev_count_total(void)
798 uint16_t port, count = 0;
800 RTE_ETH_FOREACH_VALID_DEV(port)
807 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
811 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
814 RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
818 /* shouldn't check 'rte_eth_devices[i].data',
819 * because it might be overwritten by VDEV PMD */
820 tmp = rte_eth_dev_shared_data->data[port_id].name;
826 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
831 RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
835 RTE_ETH_FOREACH_VALID_DEV(pid)
836 if (!strcmp(name, rte_eth_dev_shared_data->data[pid].name)) {
845 eth_err(uint16_t port_id, int ret)
849 if (rte_eth_dev_is_removed(port_id))
855 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
857 uint16_t old_nb_queues = dev->data->nb_rx_queues;
861 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
862 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
863 sizeof(dev->data->rx_queues[0]) * nb_queues,
864 RTE_CACHE_LINE_SIZE);
865 if (dev->data->rx_queues == NULL) {
866 dev->data->nb_rx_queues = 0;
869 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
870 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
872 rxq = dev->data->rx_queues;
874 for (i = nb_queues; i < old_nb_queues; i++)
875 (*dev->dev_ops->rx_queue_release)(rxq[i]);
876 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
877 RTE_CACHE_LINE_SIZE);
880 if (nb_queues > old_nb_queues) {
881 uint16_t new_qs = nb_queues - old_nb_queues;
883 memset(rxq + old_nb_queues, 0,
884 sizeof(rxq[0]) * new_qs);
887 dev->data->rx_queues = rxq;
889 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
890 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
892 rxq = dev->data->rx_queues;
894 for (i = nb_queues; i < old_nb_queues; i++)
895 (*dev->dev_ops->rx_queue_release)(rxq[i]);
897 rte_free(dev->data->rx_queues);
898 dev->data->rx_queues = NULL;
900 dev->data->nb_rx_queues = nb_queues;
905 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
907 struct rte_eth_dev *dev;
909 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
911 dev = &rte_eth_devices[port_id];
912 if (!dev->data->dev_started) {
914 "Port %u must be started before start any queue\n",
919 if (rx_queue_id >= dev->data->nb_rx_queues) {
920 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
924 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
926 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
928 "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n",
929 rx_queue_id, port_id);
933 return eth_err(port_id, dev->dev_ops->rx_queue_start(dev,
939 rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
941 struct rte_eth_dev *dev;
943 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
945 dev = &rte_eth_devices[port_id];
946 if (rx_queue_id >= dev->data->nb_rx_queues) {
947 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
951 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
953 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
955 "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n",
956 rx_queue_id, port_id);
960 return eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id));
965 rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
967 struct rte_eth_dev *dev;
969 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
971 dev = &rte_eth_devices[port_id];
972 if (!dev->data->dev_started) {
974 "Port %u must be started before start any queue\n",
979 if (tx_queue_id >= dev->data->nb_tx_queues) {
980 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
984 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
986 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
988 "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n",
989 tx_queue_id, port_id);
993 return eth_err(port_id, dev->dev_ops->tx_queue_start(dev, tx_queue_id));
997 rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
999 struct rte_eth_dev *dev;
1001 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1003 dev = &rte_eth_devices[port_id];
1004 if (tx_queue_id >= dev->data->nb_tx_queues) {
1005 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
1009 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
1011 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
1012 RTE_ETHDEV_LOG(INFO,
1013 "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n",
1014 tx_queue_id, port_id);
1018 return eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id));
1023 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
1025 uint16_t old_nb_queues = dev->data->nb_tx_queues;
1029 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
1030 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
1031 sizeof(dev->data->tx_queues[0]) * nb_queues,
1032 RTE_CACHE_LINE_SIZE);
1033 if (dev->data->tx_queues == NULL) {
1034 dev->data->nb_tx_queues = 0;
1037 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
1038 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
1040 txq = dev->data->tx_queues;
1042 for (i = nb_queues; i < old_nb_queues; i++)
1043 (*dev->dev_ops->tx_queue_release)(txq[i]);
1044 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
1045 RTE_CACHE_LINE_SIZE);
1048 if (nb_queues > old_nb_queues) {
1049 uint16_t new_qs = nb_queues - old_nb_queues;
1051 memset(txq + old_nb_queues, 0,
1052 sizeof(txq[0]) * new_qs);
1055 dev->data->tx_queues = txq;
1057 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
1058 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
1060 txq = dev->data->tx_queues;
1062 for (i = nb_queues; i < old_nb_queues; i++)
1063 (*dev->dev_ops->tx_queue_release)(txq[i]);
1065 rte_free(dev->data->tx_queues);
1066 dev->data->tx_queues = NULL;
1068 dev->data->nb_tx_queues = nb_queues;
1073 rte_eth_speed_bitflag(uint32_t speed, int duplex)
1076 case ETH_SPEED_NUM_10M:
1077 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
1078 case ETH_SPEED_NUM_100M:
1079 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
1080 case ETH_SPEED_NUM_1G:
1081 return ETH_LINK_SPEED_1G;
1082 case ETH_SPEED_NUM_2_5G:
1083 return ETH_LINK_SPEED_2_5G;
1084 case ETH_SPEED_NUM_5G:
1085 return ETH_LINK_SPEED_5G;
1086 case ETH_SPEED_NUM_10G:
1087 return ETH_LINK_SPEED_10G;
1088 case ETH_SPEED_NUM_20G:
1089 return ETH_LINK_SPEED_20G;
1090 case ETH_SPEED_NUM_25G:
1091 return ETH_LINK_SPEED_25G;
1092 case ETH_SPEED_NUM_40G:
1093 return ETH_LINK_SPEED_40G;
1094 case ETH_SPEED_NUM_50G:
1095 return ETH_LINK_SPEED_50G;
1096 case ETH_SPEED_NUM_56G:
1097 return ETH_LINK_SPEED_56G;
1098 case ETH_SPEED_NUM_100G:
1099 return ETH_LINK_SPEED_100G;
1106 rte_eth_dev_rx_offload_name(uint64_t offload)
1108 const char *name = "UNKNOWN";
1111 for (i = 0; i < RTE_DIM(rte_rx_offload_names); ++i) {
1112 if (offload == rte_rx_offload_names[i].offload) {
1113 name = rte_rx_offload_names[i].name;
1122 rte_eth_dev_tx_offload_name(uint64_t offload)
1124 const char *name = "UNKNOWN";
1127 for (i = 0; i < RTE_DIM(rte_tx_offload_names); ++i) {
1128 if (offload == rte_tx_offload_names[i].offload) {
1129 name = rte_tx_offload_names[i].name;
1138 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1139 const struct rte_eth_conf *dev_conf)
1141 struct rte_eth_dev *dev;
1142 struct rte_eth_dev_info dev_info;
1143 struct rte_eth_conf orig_conf;
1147 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1149 dev = &rte_eth_devices[port_id];
1151 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1153 if (dev->data->dev_started) {
1155 "Port %u must be stopped to allow configuration\n",
1160 /* Store original config, as rollback required on failure */
1161 memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf));
1164 * Copy the dev_conf parameter into the dev structure.
1165 * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get
1167 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
1169 ret = rte_eth_dev_info_get(port_id, &dev_info);
1173 /* If number of queues specified by application for both Rx and Tx is
1174 * zero, use driver preferred values. This cannot be done individually
1175 * as it is valid for either Tx or Rx (but not both) to be zero.
1176 * If driver does not provide any preferred valued, fall back on
1179 if (nb_rx_q == 0 && nb_tx_q == 0) {
1180 nb_rx_q = dev_info.default_rxportconf.nb_queues;
1182 nb_rx_q = RTE_ETH_DEV_FALLBACK_RX_NBQUEUES;
1183 nb_tx_q = dev_info.default_txportconf.nb_queues;
1185 nb_tx_q = RTE_ETH_DEV_FALLBACK_TX_NBQUEUES;
1188 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1190 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
1191 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1196 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1198 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
1199 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1205 * Check that the numbers of RX and TX queues are not greater
1206 * than the maximum number of RX and TX queues supported by the
1207 * configured device.
1209 if (nb_rx_q > dev_info.max_rx_queues) {
1210 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_rx_queues=%u > %u\n",
1211 port_id, nb_rx_q, dev_info.max_rx_queues);
1216 if (nb_tx_q > dev_info.max_tx_queues) {
1217 RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_tx_queues=%u > %u\n",
1218 port_id, nb_tx_q, dev_info.max_tx_queues);
1223 /* Check that the device supports requested interrupts */
1224 if ((dev_conf->intr_conf.lsc == 1) &&
1225 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
1226 RTE_ETHDEV_LOG(ERR, "Driver %s does not support lsc\n",
1227 dev->device->driver->name);
1231 if ((dev_conf->intr_conf.rmv == 1) &&
1232 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
1233 RTE_ETHDEV_LOG(ERR, "Driver %s does not support rmv\n",
1234 dev->device->driver->name);
1240 * If jumbo frames are enabled, check that the maximum RX packet
1241 * length is supported by the configured device.
1243 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1244 if (dev_conf->rxmode.max_rx_pkt_len > dev_info.max_rx_pktlen) {
1246 "Ethdev port_id=%u max_rx_pkt_len %u > max valid value %u\n",
1247 port_id, dev_conf->rxmode.max_rx_pkt_len,
1248 dev_info.max_rx_pktlen);
1251 } else if (dev_conf->rxmode.max_rx_pkt_len < RTE_ETHER_MIN_LEN) {
1253 "Ethdev port_id=%u max_rx_pkt_len %u < min valid value %u\n",
1254 port_id, dev_conf->rxmode.max_rx_pkt_len,
1255 (unsigned int)RTE_ETHER_MIN_LEN);
1260 if (dev_conf->rxmode.max_rx_pkt_len < RTE_ETHER_MIN_LEN ||
1261 dev_conf->rxmode.max_rx_pkt_len > RTE_ETHER_MAX_LEN)
1262 /* Use default value */
1263 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1267 /* Any requested offloading must be within its device capabilities */
1268 if ((dev_conf->rxmode.offloads & dev_info.rx_offload_capa) !=
1269 dev_conf->rxmode.offloads) {
1271 "Ethdev port_id=%u requested Rx offloads 0x%"PRIx64" doesn't match Rx offloads "
1272 "capabilities 0x%"PRIx64" in %s()\n",
1273 port_id, dev_conf->rxmode.offloads,
1274 dev_info.rx_offload_capa,
1279 if ((dev_conf->txmode.offloads & dev_info.tx_offload_capa) !=
1280 dev_conf->txmode.offloads) {
1282 "Ethdev port_id=%u requested Tx offloads 0x%"PRIx64" doesn't match Tx offloads "
1283 "capabilities 0x%"PRIx64" in %s()\n",
1284 port_id, dev_conf->txmode.offloads,
1285 dev_info.tx_offload_capa,
1291 dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf =
1292 rte_eth_rss_hf_refine(dev_conf->rx_adv_conf.rss_conf.rss_hf);
1294 /* Check that device supports requested rss hash functions. */
1295 if ((dev_info.flow_type_rss_offloads |
1296 dev_conf->rx_adv_conf.rss_conf.rss_hf) !=
1297 dev_info.flow_type_rss_offloads) {
1299 "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n",
1300 port_id, dev_conf->rx_adv_conf.rss_conf.rss_hf,
1301 dev_info.flow_type_rss_offloads);
1307 * Setup new number of RX/TX queues and reconfigure device.
1309 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1312 "Port%u rte_eth_dev_rx_queue_config = %d\n",
1318 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1321 "Port%u rte_eth_dev_tx_queue_config = %d\n",
1323 rte_eth_dev_rx_queue_config(dev, 0);
1328 diag = (*dev->dev_ops->dev_configure)(dev);
1330 RTE_ETHDEV_LOG(ERR, "Port%u dev_configure = %d\n",
1332 rte_eth_dev_rx_queue_config(dev, 0);
1333 rte_eth_dev_tx_queue_config(dev, 0);
1334 ret = eth_err(port_id, diag);
1338 /* Initialize Rx profiling if enabled at compilation time. */
1339 diag = __rte_eth_dev_profile_init(port_id, dev);
1341 RTE_ETHDEV_LOG(ERR, "Port%u __rte_eth_dev_profile_init = %d\n",
1343 rte_eth_dev_rx_queue_config(dev, 0);
1344 rte_eth_dev_tx_queue_config(dev, 0);
1345 ret = eth_err(port_id, diag);
1352 memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf));
1358 _rte_eth_dev_reset(struct rte_eth_dev *dev)
1360 if (dev->data->dev_started) {
1361 RTE_ETHDEV_LOG(ERR, "Port %u must be stopped to allow reset\n",
1362 dev->data->port_id);
1366 rte_eth_dev_rx_queue_config(dev, 0);
1367 rte_eth_dev_tx_queue_config(dev, 0);
1369 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
1373 rte_eth_dev_mac_restore(struct rte_eth_dev *dev,
1374 struct rte_eth_dev_info *dev_info)
1376 struct rte_ether_addr *addr;
1381 /* replay MAC address configuration including default MAC */
1382 addr = &dev->data->mac_addrs[0];
1383 if (*dev->dev_ops->mac_addr_set != NULL)
1384 (*dev->dev_ops->mac_addr_set)(dev, addr);
1385 else if (*dev->dev_ops->mac_addr_add != NULL)
1386 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
1388 if (*dev->dev_ops->mac_addr_add != NULL) {
1389 for (i = 1; i < dev_info->max_mac_addrs; i++) {
1390 addr = &dev->data->mac_addrs[i];
1392 /* skip zero address */
1393 if (rte_is_zero_ether_addr(addr))
1397 pool_mask = dev->data->mac_pool_sel[i];
1400 if (pool_mask & 1ULL)
1401 (*dev->dev_ops->mac_addr_add)(dev,
1405 } while (pool_mask);
1411 rte_eth_dev_config_restore(struct rte_eth_dev *dev,
1412 struct rte_eth_dev_info *dev_info, uint16_t port_id)
1416 if (!(*dev_info->dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR))
1417 rte_eth_dev_mac_restore(dev, dev_info);
1419 /* replay promiscuous configuration */
1421 * use callbacks directly since we don't need port_id check and
1422 * would like to bypass the same value set
1424 if (rte_eth_promiscuous_get(port_id) == 1 &&
1425 *dev->dev_ops->promiscuous_enable != NULL) {
1426 ret = eth_err(port_id,
1427 (*dev->dev_ops->promiscuous_enable)(dev));
1428 if (ret != 0 && ret != -ENOTSUP) {
1430 "Failed to enable promiscuous mode for device (port %u): %s\n",
1431 port_id, rte_strerror(-ret));
1434 } else if (rte_eth_promiscuous_get(port_id) == 0 &&
1435 *dev->dev_ops->promiscuous_disable != NULL) {
1436 ret = eth_err(port_id,
1437 (*dev->dev_ops->promiscuous_disable)(dev));
1438 if (ret != 0 && ret != -ENOTSUP) {
1440 "Failed to disable promiscuous mode for device (port %u): %s\n",
1441 port_id, rte_strerror(-ret));
1446 /* replay all multicast configuration */
1448 * use callbacks directly since we don't need port_id check and
1449 * would like to bypass the same value set
1451 if (rte_eth_allmulticast_get(port_id) == 1 &&
1452 *dev->dev_ops->allmulticast_enable != NULL) {
1453 ret = eth_err(port_id,
1454 (*dev->dev_ops->allmulticast_enable)(dev));
1455 if (ret != 0 && ret != -ENOTSUP) {
1457 "Failed to enable allmulticast mode for device (port %u): %s\n",
1458 port_id, rte_strerror(-ret));
1461 } else if (rte_eth_allmulticast_get(port_id) == 0 &&
1462 *dev->dev_ops->allmulticast_disable != NULL) {
1463 ret = eth_err(port_id,
1464 (*dev->dev_ops->allmulticast_disable)(dev));
1465 if (ret != 0 && ret != -ENOTSUP) {
1467 "Failed to disable allmulticast mode for device (port %u): %s\n",
1468 port_id, rte_strerror(-ret));
1477 rte_eth_dev_start(uint16_t port_id)
1479 struct rte_eth_dev *dev;
1480 struct rte_eth_dev_info dev_info;
1484 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1486 dev = &rte_eth_devices[port_id];
1488 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1490 if (dev->data->dev_started != 0) {
1491 RTE_ETHDEV_LOG(INFO,
1492 "Device with port_id=%"PRIu16" already started\n",
1497 ret = rte_eth_dev_info_get(port_id, &dev_info);
1501 /* Lets restore MAC now if device does not support live change */
1502 if (*dev_info.dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR)
1503 rte_eth_dev_mac_restore(dev, &dev_info);
1505 diag = (*dev->dev_ops->dev_start)(dev);
1507 dev->data->dev_started = 1;
1509 return eth_err(port_id, diag);
1511 ret = rte_eth_dev_config_restore(dev, &dev_info, port_id);
1514 "Error during restoring configuration for device (port %u): %s\n",
1515 port_id, rte_strerror(-ret));
1516 rte_eth_dev_stop(port_id);
1520 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1521 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1522 (*dev->dev_ops->link_update)(dev, 0);
1528 rte_eth_dev_stop(uint16_t port_id)
1530 struct rte_eth_dev *dev;
1532 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1533 dev = &rte_eth_devices[port_id];
1535 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1537 if (dev->data->dev_started == 0) {
1538 RTE_ETHDEV_LOG(INFO,
1539 "Device with port_id=%"PRIu16" already stopped\n",
1544 dev->data->dev_started = 0;
1545 (*dev->dev_ops->dev_stop)(dev);
1549 rte_eth_dev_set_link_up(uint16_t port_id)
1551 struct rte_eth_dev *dev;
1553 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1555 dev = &rte_eth_devices[port_id];
1557 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1558 return eth_err(port_id, (*dev->dev_ops->dev_set_link_up)(dev));
1562 rte_eth_dev_set_link_down(uint16_t port_id)
1564 struct rte_eth_dev *dev;
1566 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1568 dev = &rte_eth_devices[port_id];
1570 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1571 return eth_err(port_id, (*dev->dev_ops->dev_set_link_down)(dev));
1575 rte_eth_dev_close(uint16_t port_id)
1577 struct rte_eth_dev *dev;
1579 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1580 dev = &rte_eth_devices[port_id];
1582 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1583 dev->data->dev_started = 0;
1584 (*dev->dev_ops->dev_close)(dev);
1586 /* check behaviour flag - temporary for PMD migration */
1587 if ((dev->data->dev_flags & RTE_ETH_DEV_CLOSE_REMOVE) != 0) {
1588 /* new behaviour: send event + reset state + free all data */
1589 rte_eth_dev_release_port(dev);
1592 RTE_ETHDEV_LOG(DEBUG, "Port closing is using an old behaviour.\n"
1593 "The driver %s should migrate to the new behaviour.\n",
1594 dev->device->driver->name);
1595 /* old behaviour: only free queue arrays */
1596 dev->data->nb_rx_queues = 0;
1597 rte_free(dev->data->rx_queues);
1598 dev->data->rx_queues = NULL;
1599 dev->data->nb_tx_queues = 0;
1600 rte_free(dev->data->tx_queues);
1601 dev->data->tx_queues = NULL;
1605 rte_eth_dev_reset(uint16_t port_id)
1607 struct rte_eth_dev *dev;
1610 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1611 dev = &rte_eth_devices[port_id];
1613 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1615 rte_eth_dev_stop(port_id);
1616 ret = dev->dev_ops->dev_reset(dev);
1618 return eth_err(port_id, ret);
1622 rte_eth_dev_is_removed(uint16_t port_id)
1624 struct rte_eth_dev *dev;
1627 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
1629 dev = &rte_eth_devices[port_id];
1631 if (dev->state == RTE_ETH_DEV_REMOVED)
1634 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->is_removed, 0);
1636 ret = dev->dev_ops->is_removed(dev);
1638 /* Device is physically removed. */
1639 dev->state = RTE_ETH_DEV_REMOVED;
1645 rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1646 uint16_t nb_rx_desc, unsigned int socket_id,
1647 const struct rte_eth_rxconf *rx_conf,
1648 struct rte_mempool *mp)
1651 uint32_t mbp_buf_size;
1652 struct rte_eth_dev *dev;
1653 struct rte_eth_dev_info dev_info;
1654 struct rte_eth_rxconf local_conf;
1657 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1659 dev = &rte_eth_devices[port_id];
1660 if (rx_queue_id >= dev->data->nb_rx_queues) {
1661 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
1666 RTE_ETHDEV_LOG(ERR, "Invalid null mempool pointer\n");
1670 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1673 * Check the size of the mbuf data buffer.
1674 * This value must be provided in the private data of the memory pool.
1675 * First check that the memory pool has a valid private data.
1677 ret = rte_eth_dev_info_get(port_id, &dev_info);
1681 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1682 RTE_ETHDEV_LOG(ERR, "%s private_data_size %d < %d\n",
1683 mp->name, (int)mp->private_data_size,
1684 (int)sizeof(struct rte_pktmbuf_pool_private));
1687 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1689 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1691 "%s mbuf_data_room_size %d < %d (RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)=%d)\n",
1692 mp->name, (int)mbp_buf_size,
1693 (int)(RTE_PKTMBUF_HEADROOM + dev_info.min_rx_bufsize),
1694 (int)RTE_PKTMBUF_HEADROOM,
1695 (int)dev_info.min_rx_bufsize);
1699 /* Use default specified by driver, if nb_rx_desc is zero */
1700 if (nb_rx_desc == 0) {
1701 nb_rx_desc = dev_info.default_rxportconf.ring_size;
1702 /* If driver default is also zero, fall back on EAL default */
1703 if (nb_rx_desc == 0)
1704 nb_rx_desc = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
1707 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1708 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1709 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1712 "Invalid value for nb_rx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n",
1713 nb_rx_desc, dev_info.rx_desc_lim.nb_max,
1714 dev_info.rx_desc_lim.nb_min,
1715 dev_info.rx_desc_lim.nb_align);
1719 if (dev->data->dev_started &&
1720 !(dev_info.dev_capa &
1721 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP))
1724 if (dev->data->dev_started &&
1725 (dev->data->rx_queue_state[rx_queue_id] !=
1726 RTE_ETH_QUEUE_STATE_STOPPED))
1729 rxq = dev->data->rx_queues;
1730 if (rxq[rx_queue_id]) {
1731 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1733 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1734 rxq[rx_queue_id] = NULL;
1737 if (rx_conf == NULL)
1738 rx_conf = &dev_info.default_rxconf;
1740 local_conf = *rx_conf;
1743 * If an offloading has already been enabled in
1744 * rte_eth_dev_configure(), it has been enabled on all queues,
1745 * so there is no need to enable it in this queue again.
1746 * The local_conf.offloads input to underlying PMD only carries
1747 * those offloadings which are only enabled on this queue and
1748 * not enabled on all queues.
1750 local_conf.offloads &= ~dev->data->dev_conf.rxmode.offloads;
1753 * New added offloadings for this queue are those not enabled in
1754 * rte_eth_dev_configure() and they must be per-queue type.
1755 * A pure per-port offloading can't be enabled on a queue while
1756 * disabled on another queue. A pure per-port offloading can't
1757 * be enabled for any queue as new added one if it hasn't been
1758 * enabled in rte_eth_dev_configure().
1760 if ((local_conf.offloads & dev_info.rx_queue_offload_capa) !=
1761 local_conf.offloads) {
1763 "Ethdev port_id=%d rx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
1764 "within per-queue offload capabilities 0x%"PRIx64" in %s()\n",
1765 port_id, rx_queue_id, local_conf.offloads,
1766 dev_info.rx_queue_offload_capa,
1771 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1772 socket_id, &local_conf, mp);
1774 if (!dev->data->min_rx_buf_size ||
1775 dev->data->min_rx_buf_size > mbp_buf_size)
1776 dev->data->min_rx_buf_size = mbp_buf_size;
1779 return eth_err(port_id, ret);
1783 rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
1784 uint16_t nb_tx_desc, unsigned int socket_id,
1785 const struct rte_eth_txconf *tx_conf)
1787 struct rte_eth_dev *dev;
1788 struct rte_eth_dev_info dev_info;
1789 struct rte_eth_txconf local_conf;
1793 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1795 dev = &rte_eth_devices[port_id];
1796 if (tx_queue_id >= dev->data->nb_tx_queues) {
1797 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
1801 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1803 ret = rte_eth_dev_info_get(port_id, &dev_info);
1807 /* Use default specified by driver, if nb_tx_desc is zero */
1808 if (nb_tx_desc == 0) {
1809 nb_tx_desc = dev_info.default_txportconf.ring_size;
1810 /* If driver default is zero, fall back on EAL default */
1811 if (nb_tx_desc == 0)
1812 nb_tx_desc = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
1814 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1815 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1816 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1818 "Invalid value for nb_tx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n",
1819 nb_tx_desc, dev_info.tx_desc_lim.nb_max,
1820 dev_info.tx_desc_lim.nb_min,
1821 dev_info.tx_desc_lim.nb_align);
1825 if (dev->data->dev_started &&
1826 !(dev_info.dev_capa &
1827 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP))
1830 if (dev->data->dev_started &&
1831 (dev->data->tx_queue_state[tx_queue_id] !=
1832 RTE_ETH_QUEUE_STATE_STOPPED))
1835 txq = dev->data->tx_queues;
1836 if (txq[tx_queue_id]) {
1837 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1839 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1840 txq[tx_queue_id] = NULL;
1843 if (tx_conf == NULL)
1844 tx_conf = &dev_info.default_txconf;
1846 local_conf = *tx_conf;
1849 * If an offloading has already been enabled in
1850 * rte_eth_dev_configure(), it has been enabled on all queues,
1851 * so there is no need to enable it in this queue again.
1852 * The local_conf.offloads input to underlying PMD only carries
1853 * those offloadings which are only enabled on this queue and
1854 * not enabled on all queues.
1856 local_conf.offloads &= ~dev->data->dev_conf.txmode.offloads;
1859 * New added offloadings for this queue are those not enabled in
1860 * rte_eth_dev_configure() and they must be per-queue type.
1861 * A pure per-port offloading can't be enabled on a queue while
1862 * disabled on another queue. A pure per-port offloading can't
1863 * be enabled for any queue as new added one if it hasn't been
1864 * enabled in rte_eth_dev_configure().
1866 if ((local_conf.offloads & dev_info.tx_queue_offload_capa) !=
1867 local_conf.offloads) {
1869 "Ethdev port_id=%d tx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
1870 "within per-queue offload capabilities 0x%"PRIx64" in %s()\n",
1871 port_id, tx_queue_id, local_conf.offloads,
1872 dev_info.tx_queue_offload_capa,
1877 return eth_err(port_id, (*dev->dev_ops->tx_queue_setup)(dev,
1878 tx_queue_id, nb_tx_desc, socket_id, &local_conf));
1882 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1883 void *userdata __rte_unused)
1887 for (i = 0; i < unsent; i++)
1888 rte_pktmbuf_free(pkts[i]);
1892 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1895 uint64_t *count = userdata;
1898 for (i = 0; i < unsent; i++)
1899 rte_pktmbuf_free(pkts[i]);
1905 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1906 buffer_tx_error_fn cbfn, void *userdata)
1908 buffer->error_callback = cbfn;
1909 buffer->error_userdata = userdata;
1914 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1921 buffer->size = size;
1922 if (buffer->error_callback == NULL) {
1923 ret = rte_eth_tx_buffer_set_err_callback(
1924 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1931 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
1933 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1936 /* Validate Input Data. Bail if not valid or not supported. */
1937 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1938 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1940 /* Call driver to free pending mbufs. */
1941 ret = (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1943 return eth_err(port_id, ret);
1947 rte_eth_promiscuous_enable(uint16_t port_id)
1949 struct rte_eth_dev *dev;
1952 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1953 dev = &rte_eth_devices[port_id];
1955 if (dev->data->promiscuous == 1)
1958 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_enable, -ENOTSUP);
1960 diag = (*dev->dev_ops->promiscuous_enable)(dev);
1961 dev->data->promiscuous = (diag == 0) ? 1 : 0;
1963 return eth_err(port_id, diag);
1967 rte_eth_promiscuous_disable(uint16_t port_id)
1969 struct rte_eth_dev *dev;
1972 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1973 dev = &rte_eth_devices[port_id];
1975 if (dev->data->promiscuous == 0)
1978 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_disable, -ENOTSUP);
1980 dev->data->promiscuous = 0;
1981 diag = (*dev->dev_ops->promiscuous_disable)(dev);
1983 dev->data->promiscuous = 1;
1985 return eth_err(port_id, diag);
1989 rte_eth_promiscuous_get(uint16_t port_id)
1991 struct rte_eth_dev *dev;
1993 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1995 dev = &rte_eth_devices[port_id];
1996 return dev->data->promiscuous;
2000 rte_eth_allmulticast_enable(uint16_t port_id)
2002 struct rte_eth_dev *dev;
2005 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2006 dev = &rte_eth_devices[port_id];
2008 if (dev->data->all_multicast == 1)
2011 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_enable, -ENOTSUP);
2012 diag = (*dev->dev_ops->allmulticast_enable)(dev);
2013 dev->data->all_multicast = (diag == 0) ? 1 : 0;
2015 return eth_err(port_id, diag);
2019 rte_eth_allmulticast_disable(uint16_t port_id)
2021 struct rte_eth_dev *dev;
2024 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2025 dev = &rte_eth_devices[port_id];
2027 if (dev->data->all_multicast == 0)
2030 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_disable, -ENOTSUP);
2031 dev->data->all_multicast = 0;
2032 diag = (*dev->dev_ops->allmulticast_disable)(dev);
2034 dev->data->all_multicast = 1;
2036 return eth_err(port_id, diag);
2040 rte_eth_allmulticast_get(uint16_t port_id)
2042 struct rte_eth_dev *dev;
2044 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2046 dev = &rte_eth_devices[port_id];
2047 return dev->data->all_multicast;
2051 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
2053 struct rte_eth_dev *dev;
2055 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2056 dev = &rte_eth_devices[port_id];
2058 if (dev->data->dev_conf.intr_conf.lsc &&
2059 dev->data->dev_started)
2060 rte_eth_linkstatus_get(dev, eth_link);
2062 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
2063 (*dev->dev_ops->link_update)(dev, 1);
2064 *eth_link = dev->data->dev_link;
2071 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
2073 struct rte_eth_dev *dev;
2075 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2076 dev = &rte_eth_devices[port_id];
2078 if (dev->data->dev_conf.intr_conf.lsc &&
2079 dev->data->dev_started)
2080 rte_eth_linkstatus_get(dev, eth_link);
2082 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
2083 (*dev->dev_ops->link_update)(dev, 0);
2084 *eth_link = dev->data->dev_link;
2091 rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
2093 struct rte_eth_dev *dev;
2095 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2097 dev = &rte_eth_devices[port_id];
2098 memset(stats, 0, sizeof(*stats));
2100 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
2101 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
2102 return eth_err(port_id, (*dev->dev_ops->stats_get)(dev, stats));
2106 rte_eth_stats_reset(uint16_t port_id)
2108 struct rte_eth_dev *dev;
2111 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2112 dev = &rte_eth_devices[port_id];
2114 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
2115 ret = (*dev->dev_ops->stats_reset)(dev);
2117 return eth_err(port_id, ret);
2119 dev->data->rx_mbuf_alloc_failed = 0;
2125 get_xstats_basic_count(struct rte_eth_dev *dev)
2127 uint16_t nb_rxqs, nb_txqs;
2130 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2131 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2133 count = RTE_NB_STATS;
2134 count += nb_rxqs * RTE_NB_RXQ_STATS;
2135 count += nb_txqs * RTE_NB_TXQ_STATS;
2141 get_xstats_count(uint16_t port_id)
2143 struct rte_eth_dev *dev;
2146 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2147 dev = &rte_eth_devices[port_id];
2148 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
2149 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
2152 return eth_err(port_id, count);
2154 if (dev->dev_ops->xstats_get_names != NULL) {
2155 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
2157 return eth_err(port_id, count);
2162 count += get_xstats_basic_count(dev);
2168 rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
2171 int cnt_xstats, idx_xstat;
2173 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2176 RTE_ETHDEV_LOG(ERR, "Id pointer is NULL\n");
2181 RTE_ETHDEV_LOG(ERR, "xstat_name pointer is NULL\n");
2186 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
2187 if (cnt_xstats < 0) {
2188 RTE_ETHDEV_LOG(ERR, "Cannot get count of xstats\n");
2192 /* Get id-name lookup table */
2193 struct rte_eth_xstat_name xstats_names[cnt_xstats];
2195 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
2196 port_id, xstats_names, cnt_xstats, NULL)) {
2197 RTE_ETHDEV_LOG(ERR, "Cannot get xstats lookup\n");
2201 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
2202 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
2211 /* retrieve basic stats names */
2213 rte_eth_basic_stats_get_names(struct rte_eth_dev *dev,
2214 struct rte_eth_xstat_name *xstats_names)
2216 int cnt_used_entries = 0;
2217 uint32_t idx, id_queue;
2220 for (idx = 0; idx < RTE_NB_STATS; idx++) {
2221 strlcpy(xstats_names[cnt_used_entries].name,
2222 rte_stats_strings[idx].name,
2223 sizeof(xstats_names[0].name));
2226 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2227 for (id_queue = 0; id_queue < num_q; id_queue++) {
2228 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
2229 snprintf(xstats_names[cnt_used_entries].name,
2230 sizeof(xstats_names[0].name),
2232 id_queue, rte_rxq_stats_strings[idx].name);
2237 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2238 for (id_queue = 0; id_queue < num_q; id_queue++) {
2239 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
2240 snprintf(xstats_names[cnt_used_entries].name,
2241 sizeof(xstats_names[0].name),
2243 id_queue, rte_txq_stats_strings[idx].name);
2247 return cnt_used_entries;
2250 /* retrieve ethdev extended statistics names */
2252 rte_eth_xstats_get_names_by_id(uint16_t port_id,
2253 struct rte_eth_xstat_name *xstats_names, unsigned int size,
2256 struct rte_eth_xstat_name *xstats_names_copy;
2257 unsigned int no_basic_stat_requested = 1;
2258 unsigned int no_ext_stat_requested = 1;
2259 unsigned int expected_entries;
2260 unsigned int basic_count;
2261 struct rte_eth_dev *dev;
2265 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2266 dev = &rte_eth_devices[port_id];
2268 basic_count = get_xstats_basic_count(dev);
2269 ret = get_xstats_count(port_id);
2272 expected_entries = (unsigned int)ret;
2274 /* Return max number of stats if no ids given */
2277 return expected_entries;
2278 else if (xstats_names && size < expected_entries)
2279 return expected_entries;
2282 if (ids && !xstats_names)
2285 if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
2286 uint64_t ids_copy[size];
2288 for (i = 0; i < size; i++) {
2289 if (ids[i] < basic_count) {
2290 no_basic_stat_requested = 0;
2295 * Convert ids to xstats ids that PMD knows.
2296 * ids known by user are basic + extended stats.
2298 ids_copy[i] = ids[i] - basic_count;
2301 if (no_basic_stat_requested)
2302 return (*dev->dev_ops->xstats_get_names_by_id)(dev,
2303 xstats_names, ids_copy, size);
2306 /* Retrieve all stats */
2308 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
2310 if (num_stats < 0 || num_stats > (int)expected_entries)
2313 return expected_entries;
2316 xstats_names_copy = calloc(expected_entries,
2317 sizeof(struct rte_eth_xstat_name));
2319 if (!xstats_names_copy) {
2320 RTE_ETHDEV_LOG(ERR, "Can't allocate memory\n");
2325 for (i = 0; i < size; i++) {
2326 if (ids[i] >= basic_count) {
2327 no_ext_stat_requested = 0;
2333 /* Fill xstats_names_copy structure */
2334 if (ids && no_ext_stat_requested) {
2335 rte_eth_basic_stats_get_names(dev, xstats_names_copy);
2337 ret = rte_eth_xstats_get_names(port_id, xstats_names_copy,
2340 free(xstats_names_copy);
2346 for (i = 0; i < size; i++) {
2347 if (ids[i] >= expected_entries) {
2348 RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n");
2349 free(xstats_names_copy);
2352 xstats_names[i] = xstats_names_copy[ids[i]];
2355 free(xstats_names_copy);
2360 rte_eth_xstats_get_names(uint16_t port_id,
2361 struct rte_eth_xstat_name *xstats_names,
2364 struct rte_eth_dev *dev;
2365 int cnt_used_entries;
2366 int cnt_expected_entries;
2367 int cnt_driver_entries;
2369 cnt_expected_entries = get_xstats_count(port_id);
2370 if (xstats_names == NULL || cnt_expected_entries < 0 ||
2371 (int)size < cnt_expected_entries)
2372 return cnt_expected_entries;
2374 /* port_id checked in get_xstats_count() */
2375 dev = &rte_eth_devices[port_id];
2377 cnt_used_entries = rte_eth_basic_stats_get_names(
2380 if (dev->dev_ops->xstats_get_names != NULL) {
2381 /* If there are any driver-specific xstats, append them
2384 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
2386 xstats_names + cnt_used_entries,
2387 size - cnt_used_entries);
2388 if (cnt_driver_entries < 0)
2389 return eth_err(port_id, cnt_driver_entries);
2390 cnt_used_entries += cnt_driver_entries;
2393 return cnt_used_entries;
2398 rte_eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats)
2400 struct rte_eth_dev *dev;
2401 struct rte_eth_stats eth_stats;
2402 unsigned int count = 0, i, q;
2403 uint64_t val, *stats_ptr;
2404 uint16_t nb_rxqs, nb_txqs;
2407 ret = rte_eth_stats_get(port_id, ð_stats);
2411 dev = &rte_eth_devices[port_id];
2413 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2414 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2417 for (i = 0; i < RTE_NB_STATS; i++) {
2418 stats_ptr = RTE_PTR_ADD(ð_stats,
2419 rte_stats_strings[i].offset);
2421 xstats[count++].value = val;
2425 for (q = 0; q < nb_rxqs; q++) {
2426 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
2427 stats_ptr = RTE_PTR_ADD(ð_stats,
2428 rte_rxq_stats_strings[i].offset +
2429 q * sizeof(uint64_t));
2431 xstats[count++].value = val;
2436 for (q = 0; q < nb_txqs; q++) {
2437 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
2438 stats_ptr = RTE_PTR_ADD(ð_stats,
2439 rte_txq_stats_strings[i].offset +
2440 q * sizeof(uint64_t));
2442 xstats[count++].value = val;
2448 /* retrieve ethdev extended statistics */
2450 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
2451 uint64_t *values, unsigned int size)
2453 unsigned int no_basic_stat_requested = 1;
2454 unsigned int no_ext_stat_requested = 1;
2455 unsigned int num_xstats_filled;
2456 unsigned int basic_count;
2457 uint16_t expected_entries;
2458 struct rte_eth_dev *dev;
2462 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2463 ret = get_xstats_count(port_id);
2466 expected_entries = (uint16_t)ret;
2467 struct rte_eth_xstat xstats[expected_entries];
2468 dev = &rte_eth_devices[port_id];
2469 basic_count = get_xstats_basic_count(dev);
2471 /* Return max number of stats if no ids given */
2474 return expected_entries;
2475 else if (values && size < expected_entries)
2476 return expected_entries;
2482 if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
2483 unsigned int basic_count = get_xstats_basic_count(dev);
2484 uint64_t ids_copy[size];
2486 for (i = 0; i < size; i++) {
2487 if (ids[i] < basic_count) {
2488 no_basic_stat_requested = 0;
2493 * Convert ids to xstats ids that PMD knows.
2494 * ids known by user are basic + extended stats.
2496 ids_copy[i] = ids[i] - basic_count;
2499 if (no_basic_stat_requested)
2500 return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy,
2505 for (i = 0; i < size; i++) {
2506 if (ids[i] >= basic_count) {
2507 no_ext_stat_requested = 0;
2513 /* Fill the xstats structure */
2514 if (ids && no_ext_stat_requested)
2515 ret = rte_eth_basic_stats_get(port_id, xstats);
2517 ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
2521 num_xstats_filled = (unsigned int)ret;
2523 /* Return all stats */
2525 for (i = 0; i < num_xstats_filled; i++)
2526 values[i] = xstats[i].value;
2527 return expected_entries;
2531 for (i = 0; i < size; i++) {
2532 if (ids[i] >= expected_entries) {
2533 RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n");
2536 values[i] = xstats[ids[i]].value;
2542 rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
2545 struct rte_eth_dev *dev;
2546 unsigned int count = 0, i;
2547 signed int xcount = 0;
2548 uint16_t nb_rxqs, nb_txqs;
2551 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2553 dev = &rte_eth_devices[port_id];
2555 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2556 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2558 /* Return generic statistics */
2559 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
2560 (nb_txqs * RTE_NB_TXQ_STATS);
2562 /* implemented by the driver */
2563 if (dev->dev_ops->xstats_get != NULL) {
2564 /* Retrieve the xstats from the driver at the end of the
2567 xcount = (*dev->dev_ops->xstats_get)(dev,
2568 xstats ? xstats + count : NULL,
2569 (n > count) ? n - count : 0);
2572 return eth_err(port_id, xcount);
2575 if (n < count + xcount || xstats == NULL)
2576 return count + xcount;
2578 /* now fill the xstats structure */
2579 ret = rte_eth_basic_stats_get(port_id, xstats);
2584 for (i = 0; i < count; i++)
2586 /* add an offset to driver-specific stats */
2587 for ( ; i < count + xcount; i++)
2588 xstats[i].id += count;
2590 return count + xcount;
2593 /* reset ethdev extended statistics */
2595 rte_eth_xstats_reset(uint16_t port_id)
2597 struct rte_eth_dev *dev;
2599 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2600 dev = &rte_eth_devices[port_id];
2602 /* implemented by the driver */
2603 if (dev->dev_ops->xstats_reset != NULL)
2604 return eth_err(port_id, (*dev->dev_ops->xstats_reset)(dev));
2606 /* fallback to default */
2607 return rte_eth_stats_reset(port_id);
2611 set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
2614 struct rte_eth_dev *dev;
2616 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2618 dev = &rte_eth_devices[port_id];
2620 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
2622 if (is_rx && (queue_id >= dev->data->nb_rx_queues))
2625 if (!is_rx && (queue_id >= dev->data->nb_tx_queues))
2628 if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
2631 return (*dev->dev_ops->queue_stats_mapping_set)
2632 (dev, queue_id, stat_idx, is_rx);
2637 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
2640 return eth_err(port_id, set_queue_stats_mapping(port_id, tx_queue_id,
2641 stat_idx, STAT_QMAP_TX));
2646 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
2649 return eth_err(port_id, set_queue_stats_mapping(port_id, rx_queue_id,
2650 stat_idx, STAT_QMAP_RX));
2654 rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
2656 struct rte_eth_dev *dev;
2658 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2659 dev = &rte_eth_devices[port_id];
2661 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
2662 return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev,
2663 fw_version, fw_size));
2667 rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
2669 struct rte_eth_dev *dev;
2670 const struct rte_eth_desc_lim lim = {
2671 .nb_max = UINT16_MAX,
2674 .nb_seg_max = UINT16_MAX,
2675 .nb_mtu_seg_max = UINT16_MAX,
2680 * Init dev_info before port_id check since caller does not have
2681 * return status and does not know if get is successful or not.
2683 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
2685 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2686 dev = &rte_eth_devices[port_id];
2688 dev_info->rx_desc_lim = lim;
2689 dev_info->tx_desc_lim = lim;
2690 dev_info->device = dev->device;
2691 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
2692 dev_info->max_mtu = UINT16_MAX;
2694 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
2695 diag = (*dev->dev_ops->dev_infos_get)(dev, dev_info);
2697 /* Cleanup already filled in device information */
2698 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
2699 return eth_err(port_id, diag);
2702 dev_info->driver_name = dev->device->driver->name;
2703 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
2704 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
2706 dev_info->dev_flags = &dev->data->dev_flags;
2712 rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
2713 uint32_t *ptypes, int num)
2716 struct rte_eth_dev *dev;
2717 const uint32_t *all_ptypes;
2719 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2720 dev = &rte_eth_devices[port_id];
2721 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
2722 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
2727 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
2728 if (all_ptypes[i] & ptype_mask) {
2730 ptypes[j] = all_ptypes[i];
2738 rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
2740 struct rte_eth_dev *dev;
2742 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2743 dev = &rte_eth_devices[port_id];
2744 rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
2751 rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
2753 struct rte_eth_dev *dev;
2755 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2757 dev = &rte_eth_devices[port_id];
2758 *mtu = dev->data->mtu;
2763 rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
2766 struct rte_eth_dev_info dev_info;
2767 struct rte_eth_dev *dev;
2769 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2770 dev = &rte_eth_devices[port_id];
2771 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
2774 * Check if the device supports dev_infos_get, if it does not
2775 * skip min_mtu/max_mtu validation here as this requires values
2776 * that are populated within the call to rte_eth_dev_info_get()
2777 * which relies on dev->dev_ops->dev_infos_get.
2779 if (*dev->dev_ops->dev_infos_get != NULL) {
2780 ret = rte_eth_dev_info_get(port_id, &dev_info);
2784 if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu)
2788 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
2790 dev->data->mtu = mtu;
2792 return eth_err(port_id, ret);
2796 rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
2798 struct rte_eth_dev *dev;
2801 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2802 dev = &rte_eth_devices[port_id];
2803 if (!(dev->data->dev_conf.rxmode.offloads &
2804 DEV_RX_OFFLOAD_VLAN_FILTER)) {
2805 RTE_ETHDEV_LOG(ERR, "Port %u: vlan-filtering disabled\n",
2810 if (vlan_id > 4095) {
2811 RTE_ETHDEV_LOG(ERR, "Port_id=%u invalid vlan_id=%u > 4095\n",
2815 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2817 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2819 struct rte_vlan_filter_conf *vfc;
2823 vfc = &dev->data->vlan_filter_conf;
2824 vidx = vlan_id / 64;
2825 vbit = vlan_id % 64;
2828 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2830 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2833 return eth_err(port_id, ret);
2837 rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
2840 struct rte_eth_dev *dev;
2842 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2843 dev = &rte_eth_devices[port_id];
2844 if (rx_queue_id >= dev->data->nb_rx_queues) {
2845 RTE_ETHDEV_LOG(ERR, "Invalid rx_queue_id=%u\n", rx_queue_id);
2849 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2850 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2856 rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
2857 enum rte_vlan_type vlan_type,
2860 struct rte_eth_dev *dev;
2862 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2863 dev = &rte_eth_devices[port_id];
2864 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2866 return eth_err(port_id, (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type,
2871 rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
2873 struct rte_eth_dev *dev;
2877 uint64_t orig_offloads;
2878 uint64_t *dev_offloads;
2880 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2881 dev = &rte_eth_devices[port_id];
2883 /* save original values in case of failure */
2884 orig_offloads = dev->data->dev_conf.rxmode.offloads;
2885 dev_offloads = &dev->data->dev_conf.rxmode.offloads;
2887 /*check which option changed by application*/
2888 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2889 org = !!(*dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
2892 *dev_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2894 *dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2895 mask |= ETH_VLAN_STRIP_MASK;
2898 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2899 org = !!(*dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER);
2902 *dev_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2904 *dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2905 mask |= ETH_VLAN_FILTER_MASK;
2908 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2909 org = !!(*dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND);
2912 *dev_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2914 *dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2915 mask |= ETH_VLAN_EXTEND_MASK;
2918 cur = !!(offload_mask & ETH_QINQ_STRIP_OFFLOAD);
2919 org = !!(*dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP);
2922 *dev_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
2924 *dev_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
2925 mask |= ETH_QINQ_STRIP_MASK;
2932 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2933 ret = (*dev->dev_ops->vlan_offload_set)(dev, mask);
2935 /* hit an error restore original values */
2936 *dev_offloads = orig_offloads;
2939 return eth_err(port_id, ret);
2943 rte_eth_dev_get_vlan_offload(uint16_t port_id)
2945 struct rte_eth_dev *dev;
2946 uint64_t *dev_offloads;
2949 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2950 dev = &rte_eth_devices[port_id];
2951 dev_offloads = &dev->data->dev_conf.rxmode.offloads;
2953 if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
2954 ret |= ETH_VLAN_STRIP_OFFLOAD;
2956 if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
2957 ret |= ETH_VLAN_FILTER_OFFLOAD;
2959 if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
2960 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2962 if (*dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP)
2963 ret |= ETH_QINQ_STRIP_OFFLOAD;
2969 rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
2971 struct rte_eth_dev *dev;
2973 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2974 dev = &rte_eth_devices[port_id];
2975 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2977 return eth_err(port_id, (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on));
2981 rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2983 struct rte_eth_dev *dev;
2985 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2986 dev = &rte_eth_devices[port_id];
2987 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2988 memset(fc_conf, 0, sizeof(*fc_conf));
2989 return eth_err(port_id, (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf));
2993 rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2995 struct rte_eth_dev *dev;
2997 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2998 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2999 RTE_ETHDEV_LOG(ERR, "Invalid send_xon, only 0/1 allowed\n");
3003 dev = &rte_eth_devices[port_id];
3004 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
3005 return eth_err(port_id, (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf));
3009 rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
3010 struct rte_eth_pfc_conf *pfc_conf)
3012 struct rte_eth_dev *dev;
3014 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3015 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
3016 RTE_ETHDEV_LOG(ERR, "Invalid priority, only 0-7 allowed\n");
3020 dev = &rte_eth_devices[port_id];
3021 /* High water, low water validation are device specific */
3022 if (*dev->dev_ops->priority_flow_ctrl_set)
3023 return eth_err(port_id, (*dev->dev_ops->priority_flow_ctrl_set)
3029 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
3037 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
3038 for (i = 0; i < num; i++) {
3039 if (reta_conf[i].mask)
3047 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
3051 uint16_t i, idx, shift;
3057 RTE_ETHDEV_LOG(ERR, "No receive queue is available\n");
3061 for (i = 0; i < reta_size; i++) {
3062 idx = i / RTE_RETA_GROUP_SIZE;
3063 shift = i % RTE_RETA_GROUP_SIZE;
3064 if ((reta_conf[idx].mask & (1ULL << shift)) &&
3065 (reta_conf[idx].reta[shift] >= max_rxq)) {
3067 "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
3069 reta_conf[idx].reta[shift], max_rxq);
3078 rte_eth_dev_rss_reta_update(uint16_t port_id,
3079 struct rte_eth_rss_reta_entry64 *reta_conf,
3082 struct rte_eth_dev *dev;
3085 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3086 /* Check mask bits */
3087 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
3091 dev = &rte_eth_devices[port_id];
3093 /* Check entry value */
3094 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
3095 dev->data->nb_rx_queues);
3099 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
3100 return eth_err(port_id, (*dev->dev_ops->reta_update)(dev, reta_conf,
3105 rte_eth_dev_rss_reta_query(uint16_t port_id,
3106 struct rte_eth_rss_reta_entry64 *reta_conf,
3109 struct rte_eth_dev *dev;
3112 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3114 /* Check mask bits */
3115 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
3119 dev = &rte_eth_devices[port_id];
3120 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
3121 return eth_err(port_id, (*dev->dev_ops->reta_query)(dev, reta_conf,
3126 rte_eth_dev_rss_hash_update(uint16_t port_id,
3127 struct rte_eth_rss_conf *rss_conf)
3129 struct rte_eth_dev *dev;
3130 struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
3133 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3135 ret = rte_eth_dev_info_get(port_id, &dev_info);
3139 rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf);
3141 dev = &rte_eth_devices[port_id];
3142 if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) !=
3143 dev_info.flow_type_rss_offloads) {
3145 "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n",
3146 port_id, rss_conf->rss_hf,
3147 dev_info.flow_type_rss_offloads);
3150 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
3151 return eth_err(port_id, (*dev->dev_ops->rss_hash_update)(dev,
3156 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
3157 struct rte_eth_rss_conf *rss_conf)
3159 struct rte_eth_dev *dev;
3161 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3162 dev = &rte_eth_devices[port_id];
3163 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
3164 return eth_err(port_id, (*dev->dev_ops->rss_hash_conf_get)(dev,
3169 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
3170 struct rte_eth_udp_tunnel *udp_tunnel)
3172 struct rte_eth_dev *dev;
3174 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3175 if (udp_tunnel == NULL) {
3176 RTE_ETHDEV_LOG(ERR, "Invalid udp_tunnel parameter\n");
3180 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
3181 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
3185 dev = &rte_eth_devices[port_id];
3186 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
3187 return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_add)(dev,
3192 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
3193 struct rte_eth_udp_tunnel *udp_tunnel)
3195 struct rte_eth_dev *dev;
3197 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3198 dev = &rte_eth_devices[port_id];
3200 if (udp_tunnel == NULL) {
3201 RTE_ETHDEV_LOG(ERR, "Invalid udp_tunnel parameter\n");
3205 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
3206 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
3210 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
3211 return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_del)(dev,
3216 rte_eth_led_on(uint16_t port_id)
3218 struct rte_eth_dev *dev;
3220 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3221 dev = &rte_eth_devices[port_id];
3222 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
3223 return eth_err(port_id, (*dev->dev_ops->dev_led_on)(dev));
3227 rte_eth_led_off(uint16_t port_id)
3229 struct rte_eth_dev *dev;
3231 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3232 dev = &rte_eth_devices[port_id];
3233 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
3234 return eth_err(port_id, (*dev->dev_ops->dev_led_off)(dev));
3238 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
3242 get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
3244 struct rte_eth_dev_info dev_info;
3245 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3249 ret = rte_eth_dev_info_get(port_id, &dev_info);
3253 for (i = 0; i < dev_info.max_mac_addrs; i++)
3254 if (memcmp(addr, &dev->data->mac_addrs[i],
3255 RTE_ETHER_ADDR_LEN) == 0)
3261 static const struct rte_ether_addr null_mac_addr;
3264 rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
3267 struct rte_eth_dev *dev;
3272 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3273 dev = &rte_eth_devices[port_id];
3274 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
3276 if (rte_is_zero_ether_addr(addr)) {
3277 RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n",
3281 if (pool >= ETH_64_POOLS) {
3282 RTE_ETHDEV_LOG(ERR, "Pool id must be 0-%d\n", ETH_64_POOLS - 1);
3286 index = get_mac_addr_index(port_id, addr);
3288 index = get_mac_addr_index(port_id, &null_mac_addr);
3290 RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n",
3295 pool_mask = dev->data->mac_pool_sel[index];
3297 /* Check if both MAC address and pool is already there, and do nothing */
3298 if (pool_mask & (1ULL << pool))
3303 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
3306 /* Update address in NIC data structure */
3307 rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]);
3309 /* Update pool bitmap in NIC data structure */
3310 dev->data->mac_pool_sel[index] |= (1ULL << pool);
3313 return eth_err(port_id, ret);
3317 rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
3319 struct rte_eth_dev *dev;
3322 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3323 dev = &rte_eth_devices[port_id];
3324 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
3326 index = get_mac_addr_index(port_id, addr);
3329 "Port %u: Cannot remove default MAC address\n",
3332 } else if (index < 0)
3333 return 0; /* Do nothing if address wasn't found */
3336 (*dev->dev_ops->mac_addr_remove)(dev, index);
3338 /* Update address in NIC data structure */
3339 rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
3341 /* reset pool bitmap */
3342 dev->data->mac_pool_sel[index] = 0;
3348 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
3350 struct rte_eth_dev *dev;
3353 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3355 if (!rte_is_valid_assigned_ether_addr(addr))
3358 dev = &rte_eth_devices[port_id];
3359 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
3361 ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
3365 /* Update default address in NIC data structure */
3366 rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
3373 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
3377 get_hash_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
3379 struct rte_eth_dev_info dev_info;
3380 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3384 ret = rte_eth_dev_info_get(port_id, &dev_info);
3388 if (!dev->data->hash_mac_addrs)
3391 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
3392 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
3393 RTE_ETHER_ADDR_LEN) == 0)
3400 rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
3405 struct rte_eth_dev *dev;
3407 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3409 dev = &rte_eth_devices[port_id];
3410 if (rte_is_zero_ether_addr(addr)) {
3411 RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n",
3416 index = get_hash_mac_addr_index(port_id, addr);
3417 /* Check if it's already there, and do nothing */
3418 if ((index >= 0) && on)
3424 "Port %u: the MAC address was not set in UTA\n",
3429 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
3431 RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n",
3437 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
3438 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
3440 /* Update address in NIC data structure */
3442 rte_ether_addr_copy(addr,
3443 &dev->data->hash_mac_addrs[index]);
3445 rte_ether_addr_copy(&null_mac_addr,
3446 &dev->data->hash_mac_addrs[index]);
3449 return eth_err(port_id, ret);
3453 rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
3455 struct rte_eth_dev *dev;
3457 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3459 dev = &rte_eth_devices[port_id];
3461 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
3462 return eth_err(port_id, (*dev->dev_ops->uc_all_hash_table_set)(dev,
3466 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
3469 struct rte_eth_dev *dev;
3470 struct rte_eth_dev_info dev_info;
3471 struct rte_eth_link link;
3474 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3476 ret = rte_eth_dev_info_get(port_id, &dev_info);
3480 dev = &rte_eth_devices[port_id];
3481 link = dev->data->dev_link;
3483 if (queue_idx > dev_info.max_tx_queues) {
3485 "Set queue rate limit:port %u: invalid queue id=%u\n",
3486 port_id, queue_idx);
3490 if (tx_rate > link.link_speed) {
3492 "Set queue rate limit:invalid tx_rate=%u, bigger than link speed= %d\n",
3493 tx_rate, link.link_speed);
3497 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
3498 return eth_err(port_id, (*dev->dev_ops->set_queue_rate_limit)(dev,
3499 queue_idx, tx_rate));
3503 rte_eth_mirror_rule_set(uint16_t port_id,
3504 struct rte_eth_mirror_conf *mirror_conf,
3505 uint8_t rule_id, uint8_t on)
3507 struct rte_eth_dev *dev;
3509 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3510 if (mirror_conf->rule_type == 0) {
3511 RTE_ETHDEV_LOG(ERR, "Mirror rule type can not be 0\n");
3515 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
3516 RTE_ETHDEV_LOG(ERR, "Invalid dst pool, pool id must be 0-%d\n",
3521 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
3522 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
3523 (mirror_conf->pool_mask == 0)) {
3525 "Invalid mirror pool, pool mask can not be 0\n");
3529 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
3530 mirror_conf->vlan.vlan_mask == 0) {
3532 "Invalid vlan mask, vlan mask can not be 0\n");
3536 dev = &rte_eth_devices[port_id];
3537 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
3539 return eth_err(port_id, (*dev->dev_ops->mirror_rule_set)(dev,
3540 mirror_conf, rule_id, on));
3544 rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
3546 struct rte_eth_dev *dev;
3548 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3550 dev = &rte_eth_devices[port_id];
3551 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
3553 return eth_err(port_id, (*dev->dev_ops->mirror_rule_reset)(dev,
3557 RTE_INIT(eth_dev_init_cb_lists)
3561 for (i = 0; i < RTE_MAX_ETHPORTS; i++)
3562 TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
3566 rte_eth_dev_callback_register(uint16_t port_id,
3567 enum rte_eth_event_type event,
3568 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
3570 struct rte_eth_dev *dev;
3571 struct rte_eth_dev_callback *user_cb;
3572 uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
3578 if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
3579 RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id);
3583 if (port_id == RTE_ETH_ALL) {
3585 last_port = RTE_MAX_ETHPORTS - 1;
3587 next_port = last_port = port_id;
3590 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3593 dev = &rte_eth_devices[next_port];
3595 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
3596 if (user_cb->cb_fn == cb_fn &&
3597 user_cb->cb_arg == cb_arg &&
3598 user_cb->event == event) {
3603 /* create a new callback. */
3604 if (user_cb == NULL) {
3605 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
3606 sizeof(struct rte_eth_dev_callback), 0);
3607 if (user_cb != NULL) {
3608 user_cb->cb_fn = cb_fn;
3609 user_cb->cb_arg = cb_arg;
3610 user_cb->event = event;
3611 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs),
3614 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3615 rte_eth_dev_callback_unregister(port_id, event,
3621 } while (++next_port <= last_port);
3623 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3628 rte_eth_dev_callback_unregister(uint16_t port_id,
3629 enum rte_eth_event_type event,
3630 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
3633 struct rte_eth_dev *dev;
3634 struct rte_eth_dev_callback *cb, *next;
3635 uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
3641 if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
3642 RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id);
3646 if (port_id == RTE_ETH_ALL) {
3648 last_port = RTE_MAX_ETHPORTS - 1;
3650 next_port = last_port = port_id;
3653 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3656 dev = &rte_eth_devices[next_port];
3658 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL;
3661 next = TAILQ_NEXT(cb, next);
3663 if (cb->cb_fn != cb_fn || cb->event != event ||
3664 (cb->cb_arg != (void *)-1 && cb->cb_arg != cb_arg))
3668 * if this callback is not executing right now,
3671 if (cb->active == 0) {
3672 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
3678 } while (++next_port <= last_port);
3680 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3685 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3686 enum rte_eth_event_type event, void *ret_param)
3688 struct rte_eth_dev_callback *cb_lst;
3689 struct rte_eth_dev_callback dev_cb;
3692 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3693 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
3694 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3698 if (ret_param != NULL)
3699 dev_cb.ret_param = ret_param;
3701 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3702 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3703 dev_cb.cb_arg, dev_cb.ret_param);
3704 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3707 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3712 rte_eth_dev_probing_finish(struct rte_eth_dev *dev)
3717 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_NEW, NULL);
3719 dev->state = RTE_ETH_DEV_ATTACHED;
3723 rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
3726 struct rte_eth_dev *dev;
3727 struct rte_intr_handle *intr_handle;
3731 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3733 dev = &rte_eth_devices[port_id];
3735 if (!dev->intr_handle) {
3736 RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
3740 intr_handle = dev->intr_handle;
3741 if (!intr_handle->intr_vec) {
3742 RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
3746 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
3747 vec = intr_handle->intr_vec[qid];
3748 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3749 if (rc && rc != -EEXIST) {
3751 "p %u q %u rx ctl error op %d epfd %d vec %u\n",
3752 port_id, qid, op, epfd, vec);
3760 rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
3762 struct rte_intr_handle *intr_handle;
3763 struct rte_eth_dev *dev;
3764 unsigned int efd_idx;
3768 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
3770 dev = &rte_eth_devices[port_id];
3772 if (queue_id >= dev->data->nb_rx_queues) {
3773 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
3777 if (!dev->intr_handle) {
3778 RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
3782 intr_handle = dev->intr_handle;
3783 if (!intr_handle->intr_vec) {
3784 RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
3788 vec = intr_handle->intr_vec[queue_id];
3789 efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ?
3790 (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec;
3791 fd = intr_handle->efds[efd_idx];
3796 const struct rte_memzone *
3797 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
3798 uint16_t queue_id, size_t size, unsigned align,
3801 char z_name[RTE_MEMZONE_NAMESIZE];
3802 const struct rte_memzone *mz;
3805 rc = snprintf(z_name, sizeof(z_name), "eth_p%d_q%d_%s",
3806 dev->data->port_id, queue_id, ring_name);
3807 if (rc >= RTE_MEMZONE_NAMESIZE) {
3808 RTE_ETHDEV_LOG(ERR, "ring name too long\n");
3809 rte_errno = ENAMETOOLONG;
3813 mz = rte_memzone_lookup(z_name);
3817 return rte_memzone_reserve_aligned(z_name, size, socket_id,
3818 RTE_MEMZONE_IOVA_CONTIG, align);
3822 rte_eth_dev_create(struct rte_device *device, const char *name,
3823 size_t priv_data_size,
3824 ethdev_bus_specific_init ethdev_bus_specific_init,
3825 void *bus_init_params,
3826 ethdev_init_t ethdev_init, void *init_params)
3828 struct rte_eth_dev *ethdev;
3831 RTE_FUNC_PTR_OR_ERR_RET(*ethdev_init, -EINVAL);
3833 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3834 ethdev = rte_eth_dev_allocate(name);
3838 if (priv_data_size) {
3839 ethdev->data->dev_private = rte_zmalloc_socket(
3840 name, priv_data_size, RTE_CACHE_LINE_SIZE,
3843 if (!ethdev->data->dev_private) {
3844 RTE_LOG(ERR, EAL, "failed to allocate private data");
3850 ethdev = rte_eth_dev_attach_secondary(name);
3852 RTE_LOG(ERR, EAL, "secondary process attach failed, "
3853 "ethdev doesn't exist");
3858 ethdev->device = device;
3860 if (ethdev_bus_specific_init) {
3861 retval = ethdev_bus_specific_init(ethdev, bus_init_params);
3864 "ethdev bus specific initialisation failed");
3869 retval = ethdev_init(ethdev, init_params);
3871 RTE_LOG(ERR, EAL, "ethdev initialisation failed");
3875 rte_eth_dev_probing_finish(ethdev);
3880 rte_eth_dev_release_port(ethdev);
3885 rte_eth_dev_destroy(struct rte_eth_dev *ethdev,
3886 ethdev_uninit_t ethdev_uninit)
3890 ethdev = rte_eth_dev_allocated(ethdev->data->name);
3894 RTE_FUNC_PTR_OR_ERR_RET(*ethdev_uninit, -EINVAL);
3896 ret = ethdev_uninit(ethdev);
3900 return rte_eth_dev_release_port(ethdev);
3904 rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
3905 int epfd, int op, void *data)
3908 struct rte_eth_dev *dev;
3909 struct rte_intr_handle *intr_handle;
3912 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3914 dev = &rte_eth_devices[port_id];
3915 if (queue_id >= dev->data->nb_rx_queues) {
3916 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
3920 if (!dev->intr_handle) {
3921 RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
3925 intr_handle = dev->intr_handle;
3926 if (!intr_handle->intr_vec) {
3927 RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
3931 vec = intr_handle->intr_vec[queue_id];
3932 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3933 if (rc && rc != -EEXIST) {
3935 "p %u q %u rx ctl error op %d epfd %d vec %u\n",
3936 port_id, queue_id, op, epfd, vec);
3944 rte_eth_dev_rx_intr_enable(uint16_t port_id,
3947 struct rte_eth_dev *dev;
3949 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3951 dev = &rte_eth_devices[port_id];
3953 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
3954 return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_enable)(dev,
3959 rte_eth_dev_rx_intr_disable(uint16_t port_id,
3962 struct rte_eth_dev *dev;
3964 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3966 dev = &rte_eth_devices[port_id];
3968 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
3969 return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_disable)(dev,
3975 rte_eth_dev_filter_supported(uint16_t port_id,
3976 enum rte_filter_type filter_type)
3978 struct rte_eth_dev *dev;
3980 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3982 dev = &rte_eth_devices[port_id];
3983 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3984 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3985 RTE_ETH_FILTER_NOP, NULL);
3989 rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
3990 enum rte_filter_op filter_op, void *arg)
3992 struct rte_eth_dev *dev;
3994 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3996 dev = &rte_eth_devices[port_id];
3997 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3998 return eth_err(port_id, (*dev->dev_ops->filter_ctrl)(dev, filter_type,
4002 const struct rte_eth_rxtx_callback *
4003 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
4004 rte_rx_callback_fn fn, void *user_param)
4006 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4007 rte_errno = ENOTSUP;
4010 /* check input parameters */
4011 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
4012 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
4016 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
4024 cb->param = user_param;
4026 rte_spinlock_lock(&rte_eth_rx_cb_lock);
4027 /* Add the callbacks in fifo order. */
4028 struct rte_eth_rxtx_callback *tail =
4029 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
4032 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
4039 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
4044 const struct rte_eth_rxtx_callback *
4045 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
4046 rte_rx_callback_fn fn, void *user_param)
4048 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4049 rte_errno = ENOTSUP;
4052 /* check input parameters */
4053 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
4054 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
4059 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
4067 cb->param = user_param;
4069 rte_spinlock_lock(&rte_eth_rx_cb_lock);
4070 /* Add the callbacks at fisrt position*/
4071 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
4073 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
4074 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
4079 const struct rte_eth_rxtx_callback *
4080 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
4081 rte_tx_callback_fn fn, void *user_param)
4083 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4084 rte_errno = ENOTSUP;
4087 /* check input parameters */
4088 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
4089 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
4094 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
4102 cb->param = user_param;
4104 rte_spinlock_lock(&rte_eth_tx_cb_lock);
4105 /* Add the callbacks in fifo order. */
4106 struct rte_eth_rxtx_callback *tail =
4107 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
4110 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
4117 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
4123 rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
4124 const struct rte_eth_rxtx_callback *user_cb)
4126 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4129 /* Check input parameters. */
4130 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
4131 if (user_cb == NULL ||
4132 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
4135 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
4136 struct rte_eth_rxtx_callback *cb;
4137 struct rte_eth_rxtx_callback **prev_cb;
4140 rte_spinlock_lock(&rte_eth_rx_cb_lock);
4141 prev_cb = &dev->post_rx_burst_cbs[queue_id];
4142 for (; *prev_cb != NULL; prev_cb = &cb->next) {
4144 if (cb == user_cb) {
4145 /* Remove the user cb from the callback list. */
4146 *prev_cb = cb->next;
4151 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
4157 rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
4158 const struct rte_eth_rxtx_callback *user_cb)
4160 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4163 /* Check input parameters. */
4164 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
4165 if (user_cb == NULL ||
4166 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
4169 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
4171 struct rte_eth_rxtx_callback *cb;
4172 struct rte_eth_rxtx_callback **prev_cb;
4174 rte_spinlock_lock(&rte_eth_tx_cb_lock);
4175 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
4176 for (; *prev_cb != NULL; prev_cb = &cb->next) {
4178 if (cb == user_cb) {
4179 /* Remove the user cb from the callback list. */
4180 *prev_cb = cb->next;
4185 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
4191 rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
4192 struct rte_eth_rxq_info *qinfo)
4194 struct rte_eth_dev *dev;
4196 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4201 dev = &rte_eth_devices[port_id];
4202 if (queue_id >= dev->data->nb_rx_queues) {
4203 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4207 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
4209 memset(qinfo, 0, sizeof(*qinfo));
4210 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
4215 rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
4216 struct rte_eth_txq_info *qinfo)
4218 struct rte_eth_dev *dev;
4220 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4225 dev = &rte_eth_devices[port_id];
4226 if (queue_id >= dev->data->nb_tx_queues) {
4227 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id);
4231 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
4233 memset(qinfo, 0, sizeof(*qinfo));
4234 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
4240 rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
4241 struct rte_eth_burst_mode *mode)
4243 struct rte_eth_dev *dev;
4245 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4250 dev = &rte_eth_devices[port_id];
4252 if (queue_id >= dev->data->nb_rx_queues) {
4253 RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
4257 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_burst_mode_get, -ENOTSUP);
4258 memset(mode, 0, sizeof(*mode));
4259 return eth_err(port_id,
4260 dev->dev_ops->rx_burst_mode_get(dev, queue_id, mode));
4264 rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
4265 struct rte_eth_burst_mode *mode)
4267 struct rte_eth_dev *dev;
4269 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4274 dev = &rte_eth_devices[port_id];
4276 if (queue_id >= dev->data->nb_tx_queues) {
4277 RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id);
4281 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_burst_mode_get, -ENOTSUP);
4282 memset(mode, 0, sizeof(*mode));
4283 return eth_err(port_id,
4284 dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode));
4288 rte_eth_burst_mode_option_name(uint64_t option)
4290 const char *name = "";
4293 for (i = 0; i < RTE_DIM(rte_burst_option_names); ++i) {
4294 if (option == rte_burst_option_names[i].option) {
4295 name = rte_burst_option_names[i].name;
4304 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
4305 struct rte_ether_addr *mc_addr_set,
4306 uint32_t nb_mc_addr)
4308 struct rte_eth_dev *dev;
4310 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4312 dev = &rte_eth_devices[port_id];
4313 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
4314 return eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev,
4315 mc_addr_set, nb_mc_addr));
4319 rte_eth_timesync_enable(uint16_t port_id)
4321 struct rte_eth_dev *dev;
4323 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4324 dev = &rte_eth_devices[port_id];
4326 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
4327 return eth_err(port_id, (*dev->dev_ops->timesync_enable)(dev));
4331 rte_eth_timesync_disable(uint16_t port_id)
4333 struct rte_eth_dev *dev;
4335 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4336 dev = &rte_eth_devices[port_id];
4338 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
4339 return eth_err(port_id, (*dev->dev_ops->timesync_disable)(dev));
4343 rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
4346 struct rte_eth_dev *dev;
4348 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4349 dev = &rte_eth_devices[port_id];
4351 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
4352 return eth_err(port_id, (*dev->dev_ops->timesync_read_rx_timestamp)
4353 (dev, timestamp, flags));
4357 rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
4358 struct timespec *timestamp)
4360 struct rte_eth_dev *dev;
4362 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4363 dev = &rte_eth_devices[port_id];
4365 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
4366 return eth_err(port_id, (*dev->dev_ops->timesync_read_tx_timestamp)
4371 rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
4373 struct rte_eth_dev *dev;
4375 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4376 dev = &rte_eth_devices[port_id];
4378 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
4379 return eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev,
4384 rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
4386 struct rte_eth_dev *dev;
4388 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4389 dev = &rte_eth_devices[port_id];
4391 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
4392 return eth_err(port_id, (*dev->dev_ops->timesync_read_time)(dev,
4397 rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
4399 struct rte_eth_dev *dev;
4401 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4402 dev = &rte_eth_devices[port_id];
4404 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
4405 return eth_err(port_id, (*dev->dev_ops->timesync_write_time)(dev,
4410 rte_eth_read_clock(uint16_t port_id, uint64_t *clock)
4412 struct rte_eth_dev *dev;
4414 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4415 dev = &rte_eth_devices[port_id];
4417 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->read_clock, -ENOTSUP);
4418 return eth_err(port_id, (*dev->dev_ops->read_clock)(dev, clock));
4422 rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
4424 struct rte_eth_dev *dev;
4426 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4428 dev = &rte_eth_devices[port_id];
4429 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
4430 return eth_err(port_id, (*dev->dev_ops->get_reg)(dev, info));
4434 rte_eth_dev_get_eeprom_length(uint16_t port_id)
4436 struct rte_eth_dev *dev;
4438 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4440 dev = &rte_eth_devices[port_id];
4441 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
4442 return eth_err(port_id, (*dev->dev_ops->get_eeprom_length)(dev));
4446 rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
4448 struct rte_eth_dev *dev;
4450 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4452 dev = &rte_eth_devices[port_id];
4453 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
4454 return eth_err(port_id, (*dev->dev_ops->get_eeprom)(dev, info));
4458 rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
4460 struct rte_eth_dev *dev;
4462 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4464 dev = &rte_eth_devices[port_id];
4465 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
4466 return eth_err(port_id, (*dev->dev_ops->set_eeprom)(dev, info));
4470 rte_eth_dev_get_module_info(uint16_t port_id,
4471 struct rte_eth_dev_module_info *modinfo)
4473 struct rte_eth_dev *dev;
4475 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4477 dev = &rte_eth_devices[port_id];
4478 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_info, -ENOTSUP);
4479 return (*dev->dev_ops->get_module_info)(dev, modinfo);
4483 rte_eth_dev_get_module_eeprom(uint16_t port_id,
4484 struct rte_dev_eeprom_info *info)
4486 struct rte_eth_dev *dev;
4488 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4490 dev = &rte_eth_devices[port_id];
4491 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_eeprom, -ENOTSUP);
4492 return (*dev->dev_ops->get_module_eeprom)(dev, info);
4496 rte_eth_dev_get_dcb_info(uint16_t port_id,
4497 struct rte_eth_dcb_info *dcb_info)
4499 struct rte_eth_dev *dev;
4501 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4503 dev = &rte_eth_devices[port_id];
4504 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
4506 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
4507 return eth_err(port_id, (*dev->dev_ops->get_dcb_info)(dev, dcb_info));
4511 rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
4512 struct rte_eth_l2_tunnel_conf *l2_tunnel)
4514 struct rte_eth_dev *dev;
4516 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4517 if (l2_tunnel == NULL) {
4518 RTE_ETHDEV_LOG(ERR, "Invalid l2_tunnel parameter\n");
4522 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
4523 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
4527 dev = &rte_eth_devices[port_id];
4528 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
4530 return eth_err(port_id, (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev,
4535 rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
4536 struct rte_eth_l2_tunnel_conf *l2_tunnel,
4540 struct rte_eth_dev *dev;
4542 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4544 if (l2_tunnel == NULL) {
4545 RTE_ETHDEV_LOG(ERR, "Invalid l2_tunnel parameter\n");
4549 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
4550 RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
4555 RTE_ETHDEV_LOG(ERR, "Mask should have a value\n");
4559 dev = &rte_eth_devices[port_id];
4560 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
4562 return eth_err(port_id, (*dev->dev_ops->l2_tunnel_offload_set)(dev,
4563 l2_tunnel, mask, en));
4567 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
4568 const struct rte_eth_desc_lim *desc_lim)
4570 if (desc_lim->nb_align != 0)
4571 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
4573 if (desc_lim->nb_max != 0)
4574 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
4576 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
4580 rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
4581 uint16_t *nb_rx_desc,
4582 uint16_t *nb_tx_desc)
4584 struct rte_eth_dev_info dev_info;
4587 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4589 ret = rte_eth_dev_info_get(port_id, &dev_info);
4593 if (nb_rx_desc != NULL)
4594 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
4596 if (nb_tx_desc != NULL)
4597 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
4603 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
4605 struct rte_eth_dev *dev;
4607 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4612 dev = &rte_eth_devices[port_id];
4614 if (*dev->dev_ops->pool_ops_supported == NULL)
4615 return 1; /* all pools are supported */
4617 return (*dev->dev_ops->pool_ops_supported)(dev, pool);
4621 * A set of values to describe the possible states of a switch domain.
4623 enum rte_eth_switch_domain_state {
4624 RTE_ETH_SWITCH_DOMAIN_UNUSED = 0,
4625 RTE_ETH_SWITCH_DOMAIN_ALLOCATED
4629 * Array of switch domains available for allocation. Array is sized to
4630 * RTE_MAX_ETHPORTS elements as there cannot be more active switch domains than
4631 * ethdev ports in a single process.
4633 static struct rte_eth_dev_switch {
4634 enum rte_eth_switch_domain_state state;
4635 } rte_eth_switch_domains[RTE_MAX_ETHPORTS];
4638 rte_eth_switch_domain_alloc(uint16_t *domain_id)
4642 *domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
4644 for (i = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID + 1;
4645 i < RTE_MAX_ETHPORTS; i++) {
4646 if (rte_eth_switch_domains[i].state ==
4647 RTE_ETH_SWITCH_DOMAIN_UNUSED) {
4648 rte_eth_switch_domains[i].state =
4649 RTE_ETH_SWITCH_DOMAIN_ALLOCATED;
4659 rte_eth_switch_domain_free(uint16_t domain_id)
4661 if (domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID ||
4662 domain_id >= RTE_MAX_ETHPORTS)
4665 if (rte_eth_switch_domains[domain_id].state !=
4666 RTE_ETH_SWITCH_DOMAIN_ALLOCATED)
4669 rte_eth_switch_domains[domain_id].state = RTE_ETH_SWITCH_DOMAIN_UNUSED;
4675 rte_eth_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
4678 struct rte_kvargs_pair *pair;
4681 arglist->str = strdup(str_in);
4682 if (arglist->str == NULL)
4685 letter = arglist->str;
4688 pair = &arglist->pairs[0];
4691 case 0: /* Initial */
4694 else if (*letter == '\0')
4701 case 1: /* Parsing key */
4702 if (*letter == '=') {
4704 pair->value = letter + 1;
4706 } else if (*letter == ',' || *letter == '\0')
4711 case 2: /* Parsing value */
4714 else if (*letter == ',') {
4717 pair = &arglist->pairs[arglist->count];
4719 } else if (*letter == '\0') {
4722 pair = &arglist->pairs[arglist->count];
4727 case 3: /* Parsing list */
4730 else if (*letter == '\0')
4739 rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
4741 struct rte_kvargs args;
4742 struct rte_kvargs_pair *pair;
4746 memset(eth_da, 0, sizeof(*eth_da));
4748 result = rte_eth_devargs_tokenise(&args, dargs);
4752 for (i = 0; i < args.count; i++) {
4753 pair = &args.pairs[i];
4754 if (strcmp("representor", pair->key) == 0) {
4755 result = rte_eth_devargs_parse_list(pair->value,
4756 rte_eth_devargs_parse_representor_ports,
4770 RTE_INIT(ethdev_init_log)
4772 rte_eth_dev_logtype = rte_log_register("lib.ethdev");
4773 if (rte_eth_dev_logtype >= 0)
4774 rte_log_set_level(rte_eth_dev_logtype, RTE_LOG_INFO);