1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation.
3 * Copyright 2013-2014 6WIND S.A.
13 #include <sys/queue.h>
14 #include <sys/types.h>
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_debug.h>
23 #include <rte_memory.h>
24 #include <rte_memcpy.h>
25 #include <rte_memzone.h>
26 #include <rte_launch.h>
28 #include <rte_per_lcore.h>
29 #include <rte_lcore.h>
30 #include <rte_atomic.h>
31 #include <rte_branch_prediction.h>
32 #include <rte_mempool.h>
34 #include <rte_interrupts.h>
36 #include <rte_ether.h>
37 #include <rte_ethdev.h>
38 #include <rte_string_fns.h>
39 #include <rte_cycles.h>
41 #include <rte_errno.h>
43 #include <rte_pmd_ixgbe.h>
46 #include <rte_pmd_i40e.h>
49 #include <rte_pmd_bnxt.h>
52 #include <rte_hexdump.h>
56 #define ETHDEV_FWVERS_LEN 32
58 #ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
59 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
61 #define CLOCK_TYPE_ID CLOCK_MONOTONIC
64 #define NS_PER_SEC 1E9
66 static char *flowtype_to_str(uint16_t flow_type);
69 enum tx_pkt_split split;
73 .split = TX_PKT_SPLIT_OFF,
77 .split = TX_PKT_SPLIT_ON,
81 .split = TX_PKT_SPLIT_RND,
86 const struct rss_type_info rss_type_table[] = {
87 { "all", ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP | ETH_RSS_TCP |
88 ETH_RSS_UDP | ETH_RSS_SCTP | ETH_RSS_L2_PAYLOAD |
89 ETH_RSS_L2TPV3 | ETH_RSS_ESP | ETH_RSS_AH | ETH_RSS_PFCP |
90 ETH_RSS_GTPU | ETH_RSS_ECPRI | ETH_RSS_MPLS},
92 { "eth", ETH_RSS_ETH },
93 { "l2-src-only", ETH_RSS_L2_SRC_ONLY },
94 { "l2-dst-only", ETH_RSS_L2_DST_ONLY },
95 { "vlan", ETH_RSS_VLAN },
96 { "s-vlan", ETH_RSS_S_VLAN },
97 { "c-vlan", ETH_RSS_C_VLAN },
98 { "ipv4", ETH_RSS_IPV4 },
99 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
100 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
101 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
102 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
103 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
104 { "ipv6", ETH_RSS_IPV6 },
105 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
106 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
107 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
108 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
109 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
110 { "l2-payload", ETH_RSS_L2_PAYLOAD },
111 { "ipv6-ex", ETH_RSS_IPV6_EX },
112 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
113 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
114 { "port", ETH_RSS_PORT },
115 { "vxlan", ETH_RSS_VXLAN },
116 { "geneve", ETH_RSS_GENEVE },
117 { "nvgre", ETH_RSS_NVGRE },
118 { "ip", ETH_RSS_IP },
119 { "udp", ETH_RSS_UDP },
120 { "tcp", ETH_RSS_TCP },
121 { "sctp", ETH_RSS_SCTP },
122 { "tunnel", ETH_RSS_TUNNEL },
123 { "l3-pre32", RTE_ETH_RSS_L3_PRE32 },
124 { "l3-pre40", RTE_ETH_RSS_L3_PRE40 },
125 { "l3-pre48", RTE_ETH_RSS_L3_PRE48 },
126 { "l3-pre56", RTE_ETH_RSS_L3_PRE56 },
127 { "l3-pre64", RTE_ETH_RSS_L3_PRE64 },
128 { "l3-pre96", RTE_ETH_RSS_L3_PRE96 },
129 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
130 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
131 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
132 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
133 { "esp", ETH_RSS_ESP },
134 { "ah", ETH_RSS_AH },
135 { "l2tpv3", ETH_RSS_L2TPV3 },
136 { "pfcp", ETH_RSS_PFCP },
137 { "pppoe", ETH_RSS_PPPOE },
138 { "gtpu", ETH_RSS_GTPU },
139 { "ecpri", ETH_RSS_ECPRI },
140 { "mpls", ETH_RSS_MPLS },
144 static const struct {
145 enum rte_eth_fec_mode mode;
147 } fec_mode_name[] = {
149 .mode = RTE_ETH_FEC_NOFEC,
153 .mode = RTE_ETH_FEC_AUTO,
157 .mode = RTE_ETH_FEC_BASER,
161 .mode = RTE_ETH_FEC_RS,
167 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
169 char buf[RTE_ETHER_ADDR_FMT_SIZE];
170 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
171 printf("%s%s", name, buf);
175 nic_stats_display(portid_t port_id)
177 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
178 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
179 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
180 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
181 static uint64_t prev_ns[RTE_MAX_ETHPORTS];
182 struct timespec cur_time;
183 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
185 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
186 struct rte_eth_stats stats;
188 static const char *nic_stats_border = "########################";
190 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
194 rte_eth_stats_get(port_id, &stats);
195 printf("\n %s NIC statistics for port %-2d %s\n",
196 nic_stats_border, port_id, nic_stats_border);
198 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
199 "%-"PRIu64"\n", stats.ipackets, stats.imissed, stats.ibytes);
200 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
201 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
202 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
203 "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
206 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
209 ns = cur_time.tv_sec * NS_PER_SEC;
210 ns += cur_time.tv_nsec;
212 if (prev_ns[port_id] != 0)
213 diff_ns = ns - prev_ns[port_id];
214 prev_ns[port_id] = ns;
217 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
218 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
219 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
220 (stats.opackets - prev_pkts_tx[port_id]) : 0;
221 prev_pkts_rx[port_id] = stats.ipackets;
222 prev_pkts_tx[port_id] = stats.opackets;
223 mpps_rx = diff_ns > 0 ?
224 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
225 mpps_tx = diff_ns > 0 ?
226 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
228 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
229 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
230 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
231 (stats.obytes - prev_bytes_tx[port_id]) : 0;
232 prev_bytes_rx[port_id] = stats.ibytes;
233 prev_bytes_tx[port_id] = stats.obytes;
234 mbps_rx = diff_ns > 0 ?
235 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
236 mbps_tx = diff_ns > 0 ?
237 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
239 printf("\n Throughput (since last show)\n");
240 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
241 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
242 mpps_tx, mbps_tx * 8);
244 printf(" %s############################%s\n",
245 nic_stats_border, nic_stats_border);
249 nic_stats_clear(portid_t port_id)
253 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
258 ret = rte_eth_stats_reset(port_id);
260 printf("%s: Error: failed to reset stats (port %u): %s",
261 __func__, port_id, strerror(-ret));
265 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
269 printf("%s: Error: failed to get stats (port %u): %s",
270 __func__, port_id, strerror(ret));
273 printf("\n NIC statistics for port %d cleared\n", port_id);
277 nic_xstats_display(portid_t port_id)
279 struct rte_eth_xstat *xstats;
280 int cnt_xstats, idx_xstat;
281 struct rte_eth_xstat_name *xstats_names;
283 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
287 printf("###### NIC extended statistics for port %-2d\n", port_id);
288 if (!rte_eth_dev_is_valid_port(port_id)) {
289 printf("Error: Invalid port number %i\n", port_id);
294 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
295 if (cnt_xstats < 0) {
296 printf("Error: Cannot get count of xstats\n");
300 /* Get id-name lookup table */
301 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
302 if (xstats_names == NULL) {
303 printf("Cannot allocate memory for xstats lookup\n");
306 if (cnt_xstats != rte_eth_xstats_get_names(
307 port_id, xstats_names, cnt_xstats)) {
308 printf("Error: Cannot get xstats lookup\n");
313 /* Get stats themselves */
314 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
315 if (xstats == NULL) {
316 printf("Cannot allocate memory for xstats\n");
320 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
321 printf("Error: Unable to get xstats\n");
328 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
329 if (xstats_hide_zero && !xstats[idx_xstat].value)
331 printf("%s: %"PRIu64"\n",
332 xstats_names[idx_xstat].name,
333 xstats[idx_xstat].value);
340 nic_xstats_clear(portid_t port_id)
344 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
349 ret = rte_eth_xstats_reset(port_id);
351 printf("%s: Error: failed to reset xstats (port %u): %s",
352 __func__, port_id, strerror(-ret));
356 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
360 printf("%s: Error: failed to get stats (port %u): %s",
361 __func__, port_id, strerror(ret));
367 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
369 struct rte_eth_burst_mode mode;
370 struct rte_eth_rxq_info qinfo;
372 static const char *info_border = "*********************";
374 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
376 printf("Failed to retrieve information for port: %u, "
377 "RX queue: %hu\nerror desc: %s(%d)\n",
378 port_id, queue_id, strerror(-rc), rc);
382 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
383 info_border, port_id, queue_id, info_border);
385 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
386 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
387 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
388 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
389 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
390 printf("\nRX drop packets: %s",
391 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
392 printf("\nRX deferred start: %s",
393 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
394 printf("\nRX scattered packets: %s",
395 (qinfo.scattered_rx != 0) ? "on" : "off");
396 if (qinfo.rx_buf_size != 0)
397 printf("\nRX buffer size: %hu", qinfo.rx_buf_size);
398 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
400 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
401 printf("\nBurst mode: %s%s",
403 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
404 " (per queue)" : "");
410 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
412 struct rte_eth_burst_mode mode;
413 struct rte_eth_txq_info qinfo;
415 static const char *info_border = "*********************";
417 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
419 printf("Failed to retrieve information for port: %u, "
420 "TX queue: %hu\nerror desc: %s(%d)\n",
421 port_id, queue_id, strerror(-rc), rc);
425 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
426 info_border, port_id, queue_id, info_border);
428 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
429 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
430 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
431 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
432 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
433 printf("\nTX deferred start: %s",
434 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
435 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
437 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
438 printf("\nBurst mode: %s%s",
440 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
441 " (per queue)" : "");
446 static int bus_match_all(const struct rte_bus *bus, const void *data)
454 device_infos_display_speeds(uint32_t speed_capa)
456 printf("\n\tDevice speed capability:");
457 if (speed_capa == ETH_LINK_SPEED_AUTONEG)
458 printf(" Autonegotiate (all speeds)");
459 if (speed_capa & ETH_LINK_SPEED_FIXED)
460 printf(" Disable autonegotiate (fixed speed) ");
461 if (speed_capa & ETH_LINK_SPEED_10M_HD)
462 printf(" 10 Mbps half-duplex ");
463 if (speed_capa & ETH_LINK_SPEED_10M)
464 printf(" 10 Mbps full-duplex ");
465 if (speed_capa & ETH_LINK_SPEED_100M_HD)
466 printf(" 100 Mbps half-duplex ");
467 if (speed_capa & ETH_LINK_SPEED_100M)
468 printf(" 100 Mbps full-duplex ");
469 if (speed_capa & ETH_LINK_SPEED_1G)
471 if (speed_capa & ETH_LINK_SPEED_2_5G)
472 printf(" 2.5 Gbps ");
473 if (speed_capa & ETH_LINK_SPEED_5G)
475 if (speed_capa & ETH_LINK_SPEED_10G)
477 if (speed_capa & ETH_LINK_SPEED_20G)
479 if (speed_capa & ETH_LINK_SPEED_25G)
481 if (speed_capa & ETH_LINK_SPEED_40G)
483 if (speed_capa & ETH_LINK_SPEED_50G)
485 if (speed_capa & ETH_LINK_SPEED_56G)
487 if (speed_capa & ETH_LINK_SPEED_100G)
488 printf(" 100 Gbps ");
489 if (speed_capa & ETH_LINK_SPEED_200G)
490 printf(" 200 Gbps ");
494 device_infos_display(const char *identifier)
496 static const char *info_border = "*********************";
497 struct rte_bus *start = NULL, *next;
498 struct rte_dev_iterator dev_iter;
499 char name[RTE_ETH_NAME_MAX_LEN];
500 struct rte_ether_addr mac_addr;
501 struct rte_device *dev;
502 struct rte_devargs da;
504 struct rte_eth_dev_info dev_info;
507 memset(&da, 0, sizeof(da));
511 if (rte_devargs_parsef(&da, "%s", identifier)) {
512 printf("cannot parse identifier\n");
517 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
520 if (identifier && da.bus != next)
523 /* Skip buses that don't have iterate method */
524 if (!next->dev_iterate)
527 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
528 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
532 /* Check for matching device if identifier is present */
534 strncmp(da.name, dev->name, strlen(dev->name)))
536 printf("\n%s Infos for device %s %s\n",
537 info_border, dev->name, info_border);
538 printf("Bus name: %s", dev->bus->name);
539 printf("\nDriver name: %s", dev->driver->name);
540 printf("\nDevargs: %s",
541 dev->devargs ? dev->devargs->args : "");
542 printf("\nConnect to socket: %d", dev->numa_node);
545 /* List ports with matching device name */
546 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
547 printf("\n\tPort id: %-2d", port_id);
548 if (eth_macaddr_get_print_err(port_id,
550 print_ethaddr("\n\tMAC address: ",
552 rte_eth_dev_get_name_by_port(port_id, name);
553 printf("\n\tDevice name: %s", name);
554 if (rte_eth_dev_info_get(port_id, &dev_info) == 0)
555 device_infos_display_speeds(dev_info.speed_capa);
560 rte_devargs_reset(&da);
564 port_infos_display(portid_t port_id)
566 struct rte_port *port;
567 struct rte_ether_addr mac_addr;
568 struct rte_eth_link link;
569 struct rte_eth_dev_info dev_info;
571 struct rte_mempool * mp;
572 static const char *info_border = "*********************";
574 char name[RTE_ETH_NAME_MAX_LEN];
576 char fw_version[ETHDEV_FWVERS_LEN];
578 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
582 port = &ports[port_id];
583 ret = eth_link_get_nowait_print_err(port_id, &link);
587 ret = eth_dev_info_get_print_err(port_id, &dev_info);
591 printf("\n%s Infos for port %-2d %s\n",
592 info_border, port_id, info_border);
593 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
594 print_ethaddr("MAC address: ", &mac_addr);
595 rte_eth_dev_get_name_by_port(port_id, name);
596 printf("\nDevice name: %s", name);
597 printf("\nDriver name: %s", dev_info.driver_name);
599 if (rte_eth_dev_fw_version_get(port_id, fw_version,
600 ETHDEV_FWVERS_LEN) == 0)
601 printf("\nFirmware-version: %s", fw_version);
603 printf("\nFirmware-version: %s", "not available");
605 if (dev_info.device->devargs && dev_info.device->devargs->args)
606 printf("\nDevargs: %s", dev_info.device->devargs->args);
607 printf("\nConnect to socket: %u", port->socket_id);
609 if (port_numa[port_id] != NUMA_NO_CONFIG) {
610 mp = mbuf_pool_find(port_numa[port_id], 0);
612 printf("\nmemory allocation on the socket: %d",
615 printf("\nmemory allocation on the socket: %u",port->socket_id);
617 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
618 printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
619 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
620 ("full-duplex") : ("half-duplex"));
621 printf("Autoneg status: %s\n", (link.link_autoneg == ETH_LINK_AUTONEG) ?
624 if (!rte_eth_dev_get_mtu(port_id, &mtu))
625 printf("MTU: %u\n", mtu);
627 printf("Promiscuous mode: %s\n",
628 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
629 printf("Allmulticast mode: %s\n",
630 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
631 printf("Maximum number of MAC addresses: %u\n",
632 (unsigned int)(port->dev_info.max_mac_addrs));
633 printf("Maximum number of MAC addresses of hash filtering: %u\n",
634 (unsigned int)(port->dev_info.max_hash_mac_addrs));
636 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
637 if (vlan_offload >= 0){
638 printf("VLAN offload: \n");
639 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
640 printf(" strip on, ");
642 printf(" strip off, ");
644 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
645 printf("filter on, ");
647 printf("filter off, ");
649 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
650 printf("extend on, ");
652 printf("extend off, ");
654 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
655 printf("qinq strip on\n");
657 printf("qinq strip off\n");
660 if (dev_info.hash_key_size > 0)
661 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
662 if (dev_info.reta_size > 0)
663 printf("Redirection table size: %u\n", dev_info.reta_size);
664 if (!dev_info.flow_type_rss_offloads)
665 printf("No RSS offload flow type is supported.\n");
670 printf("Supported RSS offload flow types:\n");
671 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
672 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
673 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
675 p = flowtype_to_str(i);
679 printf(" user defined %d\n", i);
683 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
684 printf("Maximum configurable length of RX packet: %u\n",
685 dev_info.max_rx_pktlen);
686 printf("Maximum configurable size of LRO aggregated packet: %u\n",
687 dev_info.max_lro_pkt_size);
688 if (dev_info.max_vfs)
689 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
690 if (dev_info.max_vmdq_pools)
691 printf("Maximum number of VMDq pools: %u\n",
692 dev_info.max_vmdq_pools);
694 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
695 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
696 printf("Max possible number of RXDs per queue: %hu\n",
697 dev_info.rx_desc_lim.nb_max);
698 printf("Min possible number of RXDs per queue: %hu\n",
699 dev_info.rx_desc_lim.nb_min);
700 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
702 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
703 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
704 printf("Max possible number of TXDs per queue: %hu\n",
705 dev_info.tx_desc_lim.nb_max);
706 printf("Min possible number of TXDs per queue: %hu\n",
707 dev_info.tx_desc_lim.nb_min);
708 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
709 printf("Max segment number per packet: %hu\n",
710 dev_info.tx_desc_lim.nb_seg_max);
711 printf("Max segment number per MTU/TSO: %hu\n",
712 dev_info.tx_desc_lim.nb_mtu_seg_max);
714 /* Show switch info only if valid switch domain and port id is set */
715 if (dev_info.switch_info.domain_id !=
716 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
717 if (dev_info.switch_info.name)
718 printf("Switch name: %s\n", dev_info.switch_info.name);
720 printf("Switch domain Id: %u\n",
721 dev_info.switch_info.domain_id);
722 printf("Switch Port Id: %u\n",
723 dev_info.switch_info.port_id);
728 port_summary_header_display(void)
730 uint16_t port_number;
732 port_number = rte_eth_dev_count_avail();
733 printf("Number of available ports: %i\n", port_number);
734 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
735 "Driver", "Status", "Link");
739 port_summary_display(portid_t port_id)
741 struct rte_ether_addr mac_addr;
742 struct rte_eth_link link;
743 struct rte_eth_dev_info dev_info;
744 char name[RTE_ETH_NAME_MAX_LEN];
747 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
752 ret = eth_link_get_nowait_print_err(port_id, &link);
756 ret = eth_dev_info_get_print_err(port_id, &dev_info);
760 rte_eth_dev_get_name_by_port(port_id, name);
761 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
765 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %s\n",
766 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
767 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
768 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
769 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
770 rte_eth_link_speed_to_str(link.link_speed));
774 port_eeprom_display(portid_t port_id)
776 struct rte_dev_eeprom_info einfo;
778 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
783 int len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
784 if (len_eeprom < 0) {
785 switch (len_eeprom) {
787 printf("port index %d invalid\n", port_id);
790 printf("operation not supported by device\n");
793 printf("device is removed\n");
796 printf("Unable to get EEPROM: %d\n", len_eeprom);
802 char buf[len_eeprom];
804 einfo.length = len_eeprom;
807 ret = rte_eth_dev_get_eeprom(port_id, &einfo);
811 printf("port index %d invalid\n", port_id);
814 printf("operation not supported by device\n");
817 printf("device is removed\n");
820 printf("Unable to get EEPROM: %d\n", ret);
825 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
826 printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
830 port_module_eeprom_display(portid_t port_id)
832 struct rte_eth_dev_module_info minfo;
833 struct rte_dev_eeprom_info einfo;
836 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
842 ret = rte_eth_dev_get_module_info(port_id, &minfo);
846 printf("port index %d invalid\n", port_id);
849 printf("operation not supported by device\n");
852 printf("device is removed\n");
855 printf("Unable to get module EEPROM: %d\n", ret);
861 char buf[minfo.eeprom_len];
863 einfo.length = minfo.eeprom_len;
866 ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
870 printf("port index %d invalid\n", port_id);
873 printf("operation not supported by device\n");
876 printf("device is removed\n");
879 printf("Unable to get module EEPROM: %d\n", ret);
885 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
886 printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
890 port_id_is_invalid(portid_t port_id, enum print_warning warning)
894 if (port_id == (portid_t)RTE_PORT_ALL)
897 RTE_ETH_FOREACH_DEV(pid)
901 if (warning == ENABLED_WARN)
902 printf("Invalid port %d\n", port_id);
907 void print_valid_ports(void)
911 printf("The valid ports array is [");
912 RTE_ETH_FOREACH_DEV(pid) {
919 vlan_id_is_invalid(uint16_t vlan_id)
923 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
928 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
930 const struct rte_pci_device *pci_dev;
931 const struct rte_bus *bus;
935 printf("Port register offset 0x%X not aligned on a 4-byte "
941 if (!ports[port_id].dev_info.device) {
942 printf("Invalid device\n");
946 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
947 if (bus && !strcmp(bus->name, "pci")) {
948 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
950 printf("Not a PCI device\n");
954 pci_len = pci_dev->mem_resource[0].len;
955 if (reg_off >= pci_len) {
956 printf("Port %d: register offset %u (0x%X) out of port PCI "
957 "resource (length=%"PRIu64")\n",
958 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
965 reg_bit_pos_is_invalid(uint8_t bit_pos)
969 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
973 #define display_port_and_reg_off(port_id, reg_off) \
974 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
977 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
979 display_port_and_reg_off(port_id, (unsigned)reg_off);
980 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
984 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
989 if (port_id_is_invalid(port_id, ENABLED_WARN))
991 if (port_reg_off_is_invalid(port_id, reg_off))
993 if (reg_bit_pos_is_invalid(bit_x))
995 reg_v = port_id_pci_reg_read(port_id, reg_off);
996 display_port_and_reg_off(port_id, (unsigned)reg_off);
997 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1001 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1002 uint8_t bit1_pos, uint8_t bit2_pos)
1008 if (port_id_is_invalid(port_id, ENABLED_WARN))
1010 if (port_reg_off_is_invalid(port_id, reg_off))
1012 if (reg_bit_pos_is_invalid(bit1_pos))
1014 if (reg_bit_pos_is_invalid(bit2_pos))
1016 if (bit1_pos > bit2_pos)
1017 l_bit = bit2_pos, h_bit = bit1_pos;
1019 l_bit = bit1_pos, h_bit = bit2_pos;
1021 reg_v = port_id_pci_reg_read(port_id, reg_off);
1024 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1025 display_port_and_reg_off(port_id, (unsigned)reg_off);
1026 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1027 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1031 port_reg_display(portid_t port_id, uint32_t reg_off)
1035 if (port_id_is_invalid(port_id, ENABLED_WARN))
1037 if (port_reg_off_is_invalid(port_id, reg_off))
1039 reg_v = port_id_pci_reg_read(port_id, reg_off);
1040 display_port_reg_value(port_id, reg_off, reg_v);
1044 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1049 if (port_id_is_invalid(port_id, ENABLED_WARN))
1051 if (port_reg_off_is_invalid(port_id, reg_off))
1053 if (reg_bit_pos_is_invalid(bit_pos))
1056 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1059 reg_v = port_id_pci_reg_read(port_id, reg_off);
1061 reg_v &= ~(1 << bit_pos);
1063 reg_v |= (1 << bit_pos);
1064 port_id_pci_reg_write(port_id, reg_off, reg_v);
1065 display_port_reg_value(port_id, reg_off, reg_v);
1069 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1070 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1077 if (port_id_is_invalid(port_id, ENABLED_WARN))
1079 if (port_reg_off_is_invalid(port_id, reg_off))
1081 if (reg_bit_pos_is_invalid(bit1_pos))
1083 if (reg_bit_pos_is_invalid(bit2_pos))
1085 if (bit1_pos > bit2_pos)
1086 l_bit = bit2_pos, h_bit = bit1_pos;
1088 l_bit = bit1_pos, h_bit = bit2_pos;
1090 if ((h_bit - l_bit) < 31)
1091 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1095 if (value > max_v) {
1096 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1097 (unsigned)value, (unsigned)value,
1098 (unsigned)max_v, (unsigned)max_v);
1101 reg_v = port_id_pci_reg_read(port_id, reg_off);
1102 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1103 reg_v |= (value << l_bit); /* Set changed bits */
1104 port_id_pci_reg_write(port_id, reg_off, reg_v);
1105 display_port_reg_value(port_id, reg_off, reg_v);
1109 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1111 if (port_id_is_invalid(port_id, ENABLED_WARN))
1113 if (port_reg_off_is_invalid(port_id, reg_off))
1115 port_id_pci_reg_write(port_id, reg_off, reg_v);
1116 display_port_reg_value(port_id, reg_off, reg_v);
1120 port_mtu_set(portid_t port_id, uint16_t mtu)
1123 struct rte_port *rte_port = &ports[port_id];
1124 struct rte_eth_dev_info dev_info;
1125 uint16_t eth_overhead;
1128 if (port_id_is_invalid(port_id, ENABLED_WARN))
1131 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1135 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1136 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1137 mtu, dev_info.min_mtu, dev_info.max_mtu);
1140 diag = rte_eth_dev_set_mtu(port_id, mtu);
1142 printf("Set MTU failed. diag=%d\n", diag);
1143 else if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1145 * Ether overhead in driver is equal to the difference of
1146 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1147 * device supports jumbo frame.
1149 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1150 if (mtu > RTE_ETHER_MTU) {
1151 rte_port->dev_conf.rxmode.offloads |=
1152 DEV_RX_OFFLOAD_JUMBO_FRAME;
1153 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1156 rte_port->dev_conf.rxmode.offloads &=
1157 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1161 /* Generic flow management functions. */
1163 static struct port_flow_tunnel *
1164 port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
1166 struct port_flow_tunnel *flow_tunnel;
1168 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1169 if (flow_tunnel->id == port_tunnel_id)
1179 port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
1182 switch (tunnel->type) {
1186 case RTE_FLOW_ITEM_TYPE_VXLAN:
1194 struct port_flow_tunnel *
1195 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
1197 struct rte_port *port = &ports[port_id];
1198 struct port_flow_tunnel *flow_tunnel;
1200 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1201 if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
1210 void port_flow_tunnel_list(portid_t port_id)
1212 struct rte_port *port = &ports[port_id];
1213 struct port_flow_tunnel *flt;
1215 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1216 printf("port %u tunnel #%u type=%s",
1217 port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
1218 if (flt->tunnel.tun_id)
1219 printf(" id=%" PRIu64, flt->tunnel.tun_id);
1224 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
1226 struct rte_port *port = &ports[port_id];
1227 struct port_flow_tunnel *flt;
1229 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1230 if (flt->id == tunnel_id)
1234 LIST_REMOVE(flt, chain);
1236 printf("port %u: flow tunnel #%u destroyed\n",
1237 port_id, tunnel_id);
1241 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
1243 struct rte_port *port = &ports[port_id];
1244 enum rte_flow_item_type type;
1245 struct port_flow_tunnel *flt;
1247 if (!strcmp(ops->type, "vxlan"))
1248 type = RTE_FLOW_ITEM_TYPE_VXLAN;
1250 printf("cannot offload \"%s\" tunnel type\n", ops->type);
1253 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1254 if (flt->tunnel.type == type)
1258 flt = calloc(1, sizeof(*flt));
1260 printf("failed to allocate port flt object\n");
1263 flt->tunnel.type = type;
1264 flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
1265 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
1266 LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
1268 printf("port %d: flow tunnel #%u type %s\n",
1269 port_id, flt->id, ops->type);
1272 /** Generate a port_flow entry from attributes/pattern/actions. */
1273 static struct port_flow *
1274 port_flow_new(const struct rte_flow_attr *attr,
1275 const struct rte_flow_item *pattern,
1276 const struct rte_flow_action *actions,
1277 struct rte_flow_error *error)
1279 const struct rte_flow_conv_rule rule = {
1281 .pattern_ro = pattern,
1282 .actions_ro = actions,
1284 struct port_flow *pf;
1287 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1290 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1293 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1297 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1304 /** Print a message out of a flow error. */
1306 port_flow_complain(struct rte_flow_error *error)
1308 static const char *const errstrlist[] = {
1309 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1310 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1311 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1312 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1313 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1314 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1315 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1316 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1317 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1318 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1319 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1320 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1321 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1322 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1323 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1324 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1325 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1329 int err = rte_errno;
1331 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1332 !errstrlist[error->type])
1333 errstr = "unknown type";
1335 errstr = errstrlist[error->type];
1336 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1337 error->type, errstr,
1338 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1339 error->cause), buf) : "",
1340 error->message ? error->message : "(no stated reason)",
1346 rss_config_display(struct rte_flow_action_rss *rss_conf)
1350 if (rss_conf == NULL) {
1351 printf("Invalid rule\n");
1357 if (rss_conf->queue_num == 0)
1359 for (i = 0; i < rss_conf->queue_num; i++)
1360 printf(" %d", rss_conf->queue[i]);
1363 printf(" function: ");
1364 switch (rss_conf->func) {
1365 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1366 printf("default\n");
1368 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1369 printf("toeplitz\n");
1371 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1372 printf("simple_xor\n");
1374 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1375 printf("symmetric_toeplitz\n");
1378 printf("Unknown function\n");
1382 printf(" types:\n");
1383 if (rss_conf->types == 0) {
1387 for (i = 0; rss_type_table[i].str; i++) {
1388 if ((rss_conf->types &
1389 rss_type_table[i].rss_type) ==
1390 rss_type_table[i].rss_type &&
1391 rss_type_table[i].rss_type != 0)
1392 printf(" %s\n", rss_type_table[i].str);
1396 static struct port_indirect_action *
1397 action_get_by_id(portid_t port_id, uint32_t id)
1399 struct rte_port *port;
1400 struct port_indirect_action **ppia;
1401 struct port_indirect_action *pia = NULL;
1403 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1404 port_id == (portid_t)RTE_PORT_ALL)
1406 port = &ports[port_id];
1407 ppia = &port->actions_list;
1409 if ((*ppia)->id == id) {
1413 ppia = &(*ppia)->next;
1416 printf("Failed to find indirect action #%u on port %u\n",
1422 action_alloc(portid_t port_id, uint32_t id,
1423 struct port_indirect_action **action)
1425 struct rte_port *port;
1426 struct port_indirect_action **ppia;
1427 struct port_indirect_action *pia = NULL;
1430 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1431 port_id == (portid_t)RTE_PORT_ALL)
1433 port = &ports[port_id];
1434 if (id == UINT32_MAX) {
1435 /* taking first available ID */
1436 if (port->actions_list) {
1437 if (port->actions_list->id == UINT32_MAX - 1) {
1438 printf("Highest indirect action ID is already"
1439 " assigned, delete it first\n");
1442 id = port->actions_list->id + 1;
1447 pia = calloc(1, sizeof(*pia));
1449 printf("Allocation of port %u indirect action failed\n",
1453 ppia = &port->actions_list;
1454 while (*ppia && (*ppia)->id > id)
1455 ppia = &(*ppia)->next;
1456 if (*ppia && (*ppia)->id == id) {
1457 printf("Indirect action #%u is already assigned,"
1458 " delete it first\n", id);
1469 /** Create indirect action */
1471 port_action_handle_create(portid_t port_id, uint32_t id,
1472 const struct rte_flow_indir_action_conf *conf,
1473 const struct rte_flow_action *action)
1475 struct port_indirect_action *pia;
1477 struct rte_flow_error error;
1479 ret = action_alloc(port_id, id, &pia);
1482 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
1483 struct rte_flow_action_age *age =
1484 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
1486 pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
1487 age->context = &pia->age_type;
1488 } else if (action->type == RTE_FLOW_ACTION_TYPE_CONNTRACK) {
1489 struct rte_flow_action_conntrack *ct =
1490 (struct rte_flow_action_conntrack *)(uintptr_t)(action->conf);
1492 memcpy(ct, &conntrack_context, sizeof(*ct));
1494 /* Poisoning to make sure PMDs update it in case of error. */
1495 memset(&error, 0x22, sizeof(error));
1496 pia->handle = rte_flow_action_handle_create(port_id, conf, action,
1499 uint32_t destroy_id = pia->id;
1500 port_action_handle_destroy(port_id, 1, &destroy_id);
1501 return port_flow_complain(&error);
1503 pia->type = action->type;
1504 printf("Indirect action #%u created\n", pia->id);
1508 /** Destroy indirect action */
1510 port_action_handle_destroy(portid_t port_id,
1512 const uint32_t *actions)
1514 struct rte_port *port;
1515 struct port_indirect_action **tmp;
1519 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1520 port_id == (portid_t)RTE_PORT_ALL)
1522 port = &ports[port_id];
1523 tmp = &port->actions_list;
1527 for (i = 0; i != n; ++i) {
1528 struct rte_flow_error error;
1529 struct port_indirect_action *pia = *tmp;
1531 if (actions[i] != pia->id)
1534 * Poisoning to make sure PMDs update it in case
1537 memset(&error, 0x33, sizeof(error));
1539 if (pia->handle && rte_flow_action_handle_destroy(
1540 port_id, pia->handle, &error)) {
1541 ret = port_flow_complain(&error);
1545 printf("Indirect action #%u destroyed\n", pia->id);
1550 tmp = &(*tmp)->next;
1557 /** Get indirect action by port + id */
1558 struct rte_flow_action_handle *
1559 port_action_handle_get_by_id(portid_t port_id, uint32_t id)
1562 struct port_indirect_action *pia = action_get_by_id(port_id, id);
1564 return (pia) ? pia->handle : NULL;
1567 /** Update indirect action */
1569 port_action_handle_update(portid_t port_id, uint32_t id,
1570 const struct rte_flow_action *action)
1572 struct rte_flow_error error;
1573 struct rte_flow_action_handle *action_handle;
1574 struct port_indirect_action *pia;
1577 action_handle = port_action_handle_get_by_id(port_id, id);
1580 pia = action_get_by_id(port_id, id);
1583 switch (pia->type) {
1584 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1585 update = action->conf;
1591 if (rte_flow_action_handle_update(port_id, action_handle, update,
1593 return port_flow_complain(&error);
1595 printf("Indirect action #%u updated\n", id);
1600 port_action_handle_query(portid_t port_id, uint32_t id)
1602 struct rte_flow_error error;
1603 struct port_indirect_action *pia;
1604 uint64_t default_data;
1608 pia = action_get_by_id(port_id, id);
1611 switch (pia->type) {
1612 case RTE_FLOW_ACTION_TYPE_RSS:
1613 case RTE_FLOW_ACTION_TYPE_AGE:
1614 data = &default_data;
1617 printf("Indirect action %u (type: %d) on port %u doesn't"
1618 " support query\n", id, pia->type, port_id);
1621 if (rte_flow_action_handle_query(port_id, pia->handle, data, &error))
1622 ret = port_flow_complain(&error);
1623 switch (pia->type) {
1624 case RTE_FLOW_ACTION_TYPE_RSS:
1626 printf("Shared RSS action:\n\trefs:%u\n",
1627 *((uint32_t *)data));
1630 case RTE_FLOW_ACTION_TYPE_AGE:
1632 struct rte_flow_query_age *resp = data;
1636 " sec_since_last_hit_valid: %u\n"
1637 " sec_since_last_hit: %" PRIu32 "\n",
1639 resp->sec_since_last_hit_valid,
1640 resp->sec_since_last_hit);
1644 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1646 struct rte_flow_action_conntrack *ct = data;
1648 printf("Conntrack Context:\n"
1649 " Peer: %u, Flow dir: %s, Enable: %u\n"
1650 " Live: %u, SACK: %u, CACK: %u\n"
1651 " Packet dir: %s, Liberal: %u, State: %u\n"
1652 " Factor: %u, Retrans: %u, TCP flags: %u\n"
1653 " Last Seq: %u, Last ACK: %u\n"
1654 " Last Win: %u, Last End: %u\n",
1656 ct->is_original_dir ? "Original" : "Reply",
1657 ct->enable, ct->live_connection,
1658 ct->selective_ack, ct->challenge_ack_passed,
1659 ct->last_direction ? "Original" : "Reply",
1660 ct->liberal_mode, ct->state,
1661 ct->max_ack_window, ct->retransmission_limit,
1662 ct->last_index, ct->last_seq, ct->last_ack,
1663 ct->last_window, ct->last_end);
1664 printf(" Original Dir:\n"
1665 " scale: %u, fin: %u, ack seen: %u\n"
1666 " unacked data: %u\n Sent end: %u,"
1667 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1668 ct->original_dir.scale,
1669 ct->original_dir.close_initiated,
1670 ct->original_dir.last_ack_seen,
1671 ct->original_dir.data_unacked,
1672 ct->original_dir.sent_end,
1673 ct->original_dir.reply_end,
1674 ct->original_dir.max_win,
1675 ct->original_dir.max_ack);
1676 printf(" Reply Dir:\n"
1677 " scale: %u, fin: %u, ack seen: %u\n"
1678 " unacked data: %u\n Sent end: %u,"
1679 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1680 ct->reply_dir.scale,
1681 ct->reply_dir.close_initiated,
1682 ct->reply_dir.last_ack_seen,
1683 ct->reply_dir.data_unacked,
1684 ct->reply_dir.sent_end, ct->reply_dir.reply_end,
1685 ct->reply_dir.max_win, ct->reply_dir.max_ack);
1690 printf("Indirect action %u (type: %d) on port %u doesn't"
1691 " support query\n", id, pia->type, port_id);
1697 static struct port_flow_tunnel *
1698 port_flow_tunnel_offload_cmd_prep(portid_t port_id,
1699 const struct rte_flow_item *pattern,
1700 const struct rte_flow_action *actions,
1701 const struct tunnel_ops *tunnel_ops)
1704 struct rte_port *port;
1705 struct port_flow_tunnel *pft;
1706 struct rte_flow_error error;
1708 port = &ports[port_id];
1709 pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
1711 printf("failed to locate port flow tunnel #%u\n",
1715 if (tunnel_ops->actions) {
1716 uint32_t num_actions;
1717 const struct rte_flow_action *aptr;
1719 ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
1721 &pft->num_pmd_actions,
1724 port_flow_complain(&error);
1727 for (aptr = actions, num_actions = 1;
1728 aptr->type != RTE_FLOW_ACTION_TYPE_END;
1729 aptr++, num_actions++);
1730 pft->actions = malloc(
1731 (num_actions + pft->num_pmd_actions) *
1732 sizeof(actions[0]));
1733 if (!pft->actions) {
1734 rte_flow_tunnel_action_decap_release(
1735 port_id, pft->actions,
1736 pft->num_pmd_actions, &error);
1739 rte_memcpy(pft->actions, pft->pmd_actions,
1740 pft->num_pmd_actions * sizeof(actions[0]));
1741 rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
1742 num_actions * sizeof(actions[0]));
1744 if (tunnel_ops->items) {
1746 const struct rte_flow_item *iptr;
1748 ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
1750 &pft->num_pmd_items,
1753 port_flow_complain(&error);
1756 for (iptr = pattern, num_items = 1;
1757 iptr->type != RTE_FLOW_ITEM_TYPE_END;
1758 iptr++, num_items++);
1759 pft->items = malloc((num_items + pft->num_pmd_items) *
1760 sizeof(pattern[0]));
1762 rte_flow_tunnel_item_release(
1763 port_id, pft->pmd_items,
1764 pft->num_pmd_items, &error);
1767 rte_memcpy(pft->items, pft->pmd_items,
1768 pft->num_pmd_items * sizeof(pattern[0]));
1769 rte_memcpy(pft->items + pft->num_pmd_items, pattern,
1770 num_items * sizeof(pattern[0]));
1777 port_flow_tunnel_offload_cmd_release(portid_t port_id,
1778 const struct tunnel_ops *tunnel_ops,
1779 struct port_flow_tunnel *pft)
1781 struct rte_flow_error error;
1783 if (tunnel_ops->actions) {
1785 rte_flow_tunnel_action_decap_release(
1786 port_id, pft->pmd_actions,
1787 pft->num_pmd_actions, &error);
1788 pft->actions = NULL;
1789 pft->pmd_actions = NULL;
1791 if (tunnel_ops->items) {
1793 rte_flow_tunnel_item_release(port_id, pft->pmd_items,
1797 pft->pmd_items = NULL;
1801 /** Validate flow rule. */
1803 port_flow_validate(portid_t port_id,
1804 const struct rte_flow_attr *attr,
1805 const struct rte_flow_item *pattern,
1806 const struct rte_flow_action *actions,
1807 const struct tunnel_ops *tunnel_ops)
1809 struct rte_flow_error error;
1810 struct port_flow_tunnel *pft = NULL;
1812 /* Poisoning to make sure PMDs update it in case of error. */
1813 memset(&error, 0x11, sizeof(error));
1814 if (tunnel_ops->enabled) {
1815 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
1816 actions, tunnel_ops);
1820 pattern = pft->items;
1822 actions = pft->actions;
1824 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1825 return port_flow_complain(&error);
1826 if (tunnel_ops->enabled)
1827 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
1828 printf("Flow rule validated\n");
1832 /** Return age action structure if exists, otherwise NULL. */
1833 static struct rte_flow_action_age *
1834 age_action_get(const struct rte_flow_action *actions)
1836 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1837 switch (actions->type) {
1838 case RTE_FLOW_ACTION_TYPE_AGE:
1839 return (struct rte_flow_action_age *)
1840 (uintptr_t)actions->conf;
1848 /** Create flow rule. */
1850 port_flow_create(portid_t port_id,
1851 const struct rte_flow_attr *attr,
1852 const struct rte_flow_item *pattern,
1853 const struct rte_flow_action *actions,
1854 const struct tunnel_ops *tunnel_ops)
1856 struct rte_flow *flow;
1857 struct rte_port *port;
1858 struct port_flow *pf;
1860 struct rte_flow_error error;
1861 struct port_flow_tunnel *pft = NULL;
1862 struct rte_flow_action_age *age = age_action_get(actions);
1864 port = &ports[port_id];
1865 if (port->flow_list) {
1866 if (port->flow_list->id == UINT32_MAX) {
1867 printf("Highest rule ID is already assigned, delete"
1871 id = port->flow_list->id + 1;
1873 if (tunnel_ops->enabled) {
1874 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
1875 actions, tunnel_ops);
1879 pattern = pft->items;
1881 actions = pft->actions;
1883 pf = port_flow_new(attr, pattern, actions, &error);
1885 return port_flow_complain(&error);
1887 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
1888 age->context = &pf->age_type;
1890 /* Poisoning to make sure PMDs update it in case of error. */
1891 memset(&error, 0x22, sizeof(error));
1892 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1895 return port_flow_complain(&error);
1897 pf->next = port->flow_list;
1900 port->flow_list = pf;
1901 if (tunnel_ops->enabled)
1902 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
1903 printf("Flow rule #%u created\n", pf->id);
1907 /** Destroy a number of flow rules. */
1909 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1911 struct rte_port *port;
1912 struct port_flow **tmp;
1916 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1917 port_id == (portid_t)RTE_PORT_ALL)
1919 port = &ports[port_id];
1920 tmp = &port->flow_list;
1924 for (i = 0; i != n; ++i) {
1925 struct rte_flow_error error;
1926 struct port_flow *pf = *tmp;
1928 if (rule[i] != pf->id)
1931 * Poisoning to make sure PMDs update it in case
1934 memset(&error, 0x33, sizeof(error));
1935 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1936 ret = port_flow_complain(&error);
1939 printf("Flow rule #%u destroyed\n", pf->id);
1945 tmp = &(*tmp)->next;
1951 /** Remove all flow rules. */
1953 port_flow_flush(portid_t port_id)
1955 struct rte_flow_error error;
1956 struct rte_port *port;
1959 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1960 port_id == (portid_t)RTE_PORT_ALL)
1963 port = &ports[port_id];
1965 if (port->flow_list == NULL)
1968 /* Poisoning to make sure PMDs update it in case of error. */
1969 memset(&error, 0x44, sizeof(error));
1970 if (rte_flow_flush(port_id, &error)) {
1971 port_flow_complain(&error);
1974 while (port->flow_list) {
1975 struct port_flow *pf = port->flow_list->next;
1977 free(port->flow_list);
1978 port->flow_list = pf;
1983 /** Dump flow rules. */
1985 port_flow_dump(portid_t port_id, bool dump_all, uint32_t rule_id,
1986 const char *file_name)
1989 FILE *file = stdout;
1990 struct rte_flow_error error;
1991 struct rte_port *port;
1992 struct port_flow *pflow;
1993 struct rte_flow *tmpFlow = NULL;
1996 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1997 port_id == (portid_t)RTE_PORT_ALL)
2001 port = &ports[port_id];
2002 pflow = port->flow_list;
2004 if (rule_id != pflow->id) {
2005 pflow = pflow->next;
2007 tmpFlow = pflow->flow;
2013 if (found == false) {
2014 printf("Failed to dump to flow %d\n", rule_id);
2019 if (file_name && strlen(file_name)) {
2020 file = fopen(file_name, "w");
2022 printf("Failed to create file %s: %s\n", file_name,
2029 ret = rte_flow_dev_dump(port_id, tmpFlow, file, &error);
2031 ret = rte_flow_dev_dump(port_id, NULL, file, &error);
2033 port_flow_complain(&error);
2034 printf("Failed to dump flow: %s\n", strerror(-ret));
2036 printf("Flow dump finished\n");
2037 if (file_name && strlen(file_name))
2042 /** Query a flow rule. */
2044 port_flow_query(portid_t port_id, uint32_t rule,
2045 const struct rte_flow_action *action)
2047 struct rte_flow_error error;
2048 struct rte_port *port;
2049 struct port_flow *pf;
2052 struct rte_flow_query_count count;
2053 struct rte_flow_action_rss rss_conf;
2054 struct rte_flow_query_age age;
2058 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2059 port_id == (portid_t)RTE_PORT_ALL)
2061 port = &ports[port_id];
2062 for (pf = port->flow_list; pf; pf = pf->next)
2066 printf("Flow rule #%u not found\n", rule);
2069 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2070 &name, sizeof(name),
2071 (void *)(uintptr_t)action->type, &error);
2073 return port_flow_complain(&error);
2074 switch (action->type) {
2075 case RTE_FLOW_ACTION_TYPE_COUNT:
2076 case RTE_FLOW_ACTION_TYPE_RSS:
2077 case RTE_FLOW_ACTION_TYPE_AGE:
2080 printf("Cannot query action type %d (%s)\n",
2081 action->type, name);
2084 /* Poisoning to make sure PMDs update it in case of error. */
2085 memset(&error, 0x55, sizeof(error));
2086 memset(&query, 0, sizeof(query));
2087 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
2088 return port_flow_complain(&error);
2089 switch (action->type) {
2090 case RTE_FLOW_ACTION_TYPE_COUNT:
2094 " hits: %" PRIu64 "\n"
2095 " bytes: %" PRIu64 "\n",
2097 query.count.hits_set,
2098 query.count.bytes_set,
2102 case RTE_FLOW_ACTION_TYPE_RSS:
2103 rss_config_display(&query.rss_conf);
2105 case RTE_FLOW_ACTION_TYPE_AGE:
2108 " sec_since_last_hit_valid: %u\n"
2109 " sec_since_last_hit: %" PRIu32 "\n",
2112 query.age.sec_since_last_hit_valid,
2113 query.age.sec_since_last_hit);
2116 printf("Cannot display result for action type %d (%s)\n",
2117 action->type, name);
2123 /** List simply and destroy all aged flows. */
2125 port_flow_aged(portid_t port_id, uint8_t destroy)
2128 int nb_context, total = 0, idx;
2129 struct rte_flow_error error;
2130 enum age_action_context_type *type;
2132 struct port_flow *pf;
2133 struct port_indirect_action *pia;
2136 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2137 port_id == (portid_t)RTE_PORT_ALL)
2139 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
2140 printf("Port %u total aged flows: %d\n", port_id, total);
2142 port_flow_complain(&error);
2147 contexts = malloc(sizeof(void *) * total);
2148 if (contexts == NULL) {
2149 printf("Cannot allocate contexts for aged flow\n");
2152 printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
2153 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
2154 if (nb_context != total) {
2155 printf("Port:%d get aged flows count(%d) != total(%d)\n",
2156 port_id, nb_context, total);
2161 for (idx = 0; idx < nb_context; idx++) {
2162 if (!contexts[idx]) {
2163 printf("Error: get Null context in port %u\n", port_id);
2166 type = (enum age_action_context_type *)contexts[idx];
2168 case ACTION_AGE_CONTEXT_TYPE_FLOW:
2169 ctx.pf = container_of(type, struct port_flow, age_type);
2170 printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
2174 ctx.pf->rule.attr->group,
2175 ctx.pf->rule.attr->priority,
2176 ctx.pf->rule.attr->ingress ? 'i' : '-',
2177 ctx.pf->rule.attr->egress ? 'e' : '-',
2178 ctx.pf->rule.attr->transfer ? 't' : '-');
2179 if (destroy && !port_flow_destroy(port_id, 1,
2183 case ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION:
2184 ctx.pia = container_of(type,
2185 struct port_indirect_action, age_type);
2186 printf("%-20s\t%" PRIu32 "\n", "Indirect action",
2190 printf("Error: invalid context type %u\n", port_id);
2194 printf("\n%d flows destroyed\n", total);
2198 /** List flow rules. */
2200 port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group)
2202 struct rte_port *port;
2203 struct port_flow *pf;
2204 struct port_flow *list = NULL;
2207 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2208 port_id == (portid_t)RTE_PORT_ALL)
2210 port = &ports[port_id];
2211 if (!port->flow_list)
2213 /* Sort flows by group, priority and ID. */
2214 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
2215 struct port_flow **tmp;
2216 const struct rte_flow_attr *curr = pf->rule.attr;
2219 /* Filter out unwanted groups. */
2220 for (i = 0; i != n; ++i)
2221 if (curr->group == group[i])
2226 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
2227 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
2229 if (curr->group > comp->group ||
2230 (curr->group == comp->group &&
2231 curr->priority > comp->priority) ||
2232 (curr->group == comp->group &&
2233 curr->priority == comp->priority &&
2234 pf->id > (*tmp)->id))
2241 printf("ID\tGroup\tPrio\tAttr\tRule\n");
2242 for (pf = list; pf != NULL; pf = pf->tmp) {
2243 const struct rte_flow_item *item = pf->rule.pattern;
2244 const struct rte_flow_action *action = pf->rule.actions;
2247 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
2249 pf->rule.attr->group,
2250 pf->rule.attr->priority,
2251 pf->rule.attr->ingress ? 'i' : '-',
2252 pf->rule.attr->egress ? 'e' : '-',
2253 pf->rule.attr->transfer ? 't' : '-');
2254 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
2255 if ((uint32_t)item->type > INT_MAX)
2256 name = "PMD_INTERNAL";
2257 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
2258 &name, sizeof(name),
2259 (void *)(uintptr_t)item->type,
2262 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
2263 printf("%s ", name);
2267 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
2268 if ((uint32_t)action->type > INT_MAX)
2269 name = "PMD_INTERNAL";
2270 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2271 &name, sizeof(name),
2272 (void *)(uintptr_t)action->type,
2275 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
2276 printf(" %s", name);
2283 /** Restrict ingress traffic to the defined flow rules. */
2285 port_flow_isolate(portid_t port_id, int set)
2287 struct rte_flow_error error;
2289 /* Poisoning to make sure PMDs update it in case of error. */
2290 memset(&error, 0x66, sizeof(error));
2291 if (rte_flow_isolate(port_id, set, &error))
2292 return port_flow_complain(&error);
2293 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
2295 set ? "now restricted" : "not restricted anymore");
2300 * RX/TX ring descriptors display functions.
2303 rx_queue_id_is_invalid(queueid_t rxq_id)
2305 if (rxq_id < nb_rxq)
2307 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
2312 tx_queue_id_is_invalid(queueid_t txq_id)
2314 if (txq_id < nb_txq)
2316 printf("Invalid TX queue %d (must be < nb_txq=%d)\n", txq_id, nb_txq);
2321 get_rx_ring_size(portid_t port_id, queueid_t rxq_id, uint16_t *ring_size)
2323 struct rte_port *port = &ports[port_id];
2324 struct rte_eth_rxq_info rx_qinfo;
2327 ret = rte_eth_rx_queue_info_get(port_id, rxq_id, &rx_qinfo);
2329 *ring_size = rx_qinfo.nb_desc;
2333 if (ret != -ENOTSUP)
2336 * If the rte_eth_rx_queue_info_get is not support for this PMD,
2337 * ring_size stored in testpmd will be used for validity verification.
2338 * When configure the rxq by rte_eth_rx_queue_setup with nb_rx_desc
2339 * being 0, it will use a default value provided by PMDs to setup this
2340 * rxq. If the default value is 0, it will use the
2341 * RTE_ETH_DEV_FALLBACK_RX_RINGSIZE to setup this rxq.
2343 if (port->nb_rx_desc[rxq_id])
2344 *ring_size = port->nb_rx_desc[rxq_id];
2345 else if (port->dev_info.default_rxportconf.ring_size)
2346 *ring_size = port->dev_info.default_rxportconf.ring_size;
2348 *ring_size = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
2353 get_tx_ring_size(portid_t port_id, queueid_t txq_id, uint16_t *ring_size)
2355 struct rte_port *port = &ports[port_id];
2356 struct rte_eth_txq_info tx_qinfo;
2359 ret = rte_eth_tx_queue_info_get(port_id, txq_id, &tx_qinfo);
2361 *ring_size = tx_qinfo.nb_desc;
2365 if (ret != -ENOTSUP)
2368 * If the rte_eth_tx_queue_info_get is not support for this PMD,
2369 * ring_size stored in testpmd will be used for validity verification.
2370 * When configure the txq by rte_eth_tx_queue_setup with nb_tx_desc
2371 * being 0, it will use a default value provided by PMDs to setup this
2372 * txq. If the default value is 0, it will use the
2373 * RTE_ETH_DEV_FALLBACK_TX_RINGSIZE to setup this txq.
2375 if (port->nb_tx_desc[txq_id])
2376 *ring_size = port->nb_tx_desc[txq_id];
2377 else if (port->dev_info.default_txportconf.ring_size)
2378 *ring_size = port->dev_info.default_txportconf.ring_size;
2380 *ring_size = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
2385 rx_desc_id_is_invalid(portid_t port_id, queueid_t rxq_id, uint16_t rxdesc_id)
2390 ret = get_rx_ring_size(port_id, rxq_id, &ring_size);
2394 if (rxdesc_id < ring_size)
2397 printf("Invalid RX descriptor %u (must be < ring_size=%u)\n",
2398 rxdesc_id, ring_size);
2403 tx_desc_id_is_invalid(portid_t port_id, queueid_t txq_id, uint16_t txdesc_id)
2408 ret = get_tx_ring_size(port_id, txq_id, &ring_size);
2412 if (txdesc_id < ring_size)
2415 printf("Invalid TX descriptor %u (must be < ring_size=%u)\n",
2416 txdesc_id, ring_size);
2420 static const struct rte_memzone *
2421 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
2423 char mz_name[RTE_MEMZONE_NAMESIZE];
2424 const struct rte_memzone *mz;
2426 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
2427 port_id, q_id, ring_name);
2428 mz = rte_memzone_lookup(mz_name);
2430 printf("%s ring memory zoneof (port %d, queue %d) not"
2431 "found (zone name = %s\n",
2432 ring_name, port_id, q_id, mz_name);
2436 union igb_ring_dword {
2439 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
2449 struct igb_ring_desc_32_bytes {
2450 union igb_ring_dword lo_dword;
2451 union igb_ring_dword hi_dword;
2452 union igb_ring_dword resv1;
2453 union igb_ring_dword resv2;
2456 struct igb_ring_desc_16_bytes {
2457 union igb_ring_dword lo_dword;
2458 union igb_ring_dword hi_dword;
2462 ring_rxd_display_dword(union igb_ring_dword dword)
2464 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
2465 (unsigned)dword.words.hi);
2469 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
2470 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2473 __rte_unused portid_t port_id,
2477 struct igb_ring_desc_16_bytes *ring =
2478 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2479 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2481 struct rte_eth_dev_info dev_info;
2483 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2487 if (strstr(dev_info.driver_name, "i40e") != NULL) {
2488 /* 32 bytes RX descriptor, i40e only */
2489 struct igb_ring_desc_32_bytes *ring =
2490 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
2491 ring[desc_id].lo_dword.dword =
2492 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2493 ring_rxd_display_dword(ring[desc_id].lo_dword);
2494 ring[desc_id].hi_dword.dword =
2495 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2496 ring_rxd_display_dword(ring[desc_id].hi_dword);
2497 ring[desc_id].resv1.dword =
2498 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
2499 ring_rxd_display_dword(ring[desc_id].resv1);
2500 ring[desc_id].resv2.dword =
2501 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
2502 ring_rxd_display_dword(ring[desc_id].resv2);
2507 /* 16 bytes RX descriptor */
2508 ring[desc_id].lo_dword.dword =
2509 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2510 ring_rxd_display_dword(ring[desc_id].lo_dword);
2511 ring[desc_id].hi_dword.dword =
2512 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2513 ring_rxd_display_dword(ring[desc_id].hi_dword);
2517 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
2519 struct igb_ring_desc_16_bytes *ring;
2520 struct igb_ring_desc_16_bytes txd;
2522 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2523 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2524 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2525 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
2526 (unsigned)txd.lo_dword.words.lo,
2527 (unsigned)txd.lo_dword.words.hi,
2528 (unsigned)txd.hi_dword.words.lo,
2529 (unsigned)txd.hi_dword.words.hi);
2533 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
2535 const struct rte_memzone *rx_mz;
2537 if (rx_desc_id_is_invalid(port_id, rxq_id, rxd_id))
2539 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
2542 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
2546 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
2548 const struct rte_memzone *tx_mz;
2550 if (tx_desc_id_is_invalid(port_id, txq_id, txd_id))
2552 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
2555 ring_tx_descriptor_display(tx_mz, txd_id);
2559 fwd_lcores_config_display(void)
2563 printf("List of forwarding lcores:");
2564 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
2565 printf(" %2u", fwd_lcores_cpuids[lc_id]);
2569 rxtx_config_display(void)
2574 printf(" %s packet forwarding%s packets/burst=%d\n",
2575 cur_fwd_eng->fwd_mode_name,
2576 retry_enabled == 0 ? "" : " with retry",
2579 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
2580 printf(" packet len=%u - nb packet segments=%d\n",
2581 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
2583 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
2584 nb_fwd_lcores, nb_fwd_ports);
2586 RTE_ETH_FOREACH_DEV(pid) {
2587 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
2588 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
2589 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
2590 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
2591 struct rte_eth_rxq_info rx_qinfo;
2592 struct rte_eth_txq_info tx_qinfo;
2593 uint16_t rx_free_thresh_tmp;
2594 uint16_t tx_free_thresh_tmp;
2595 uint16_t tx_rs_thresh_tmp;
2596 uint16_t nb_rx_desc_tmp;
2597 uint16_t nb_tx_desc_tmp;
2598 uint64_t offloads_tmp;
2599 uint8_t pthresh_tmp;
2600 uint8_t hthresh_tmp;
2601 uint8_t wthresh_tmp;
2604 /* per port config */
2605 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
2606 (unsigned int)pid, nb_rxq, nb_txq);
2608 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
2609 ports[pid].dev_conf.rxmode.offloads,
2610 ports[pid].dev_conf.txmode.offloads);
2612 /* per rx queue config only for first queue to be less verbose */
2613 for (qid = 0; qid < 1; qid++) {
2614 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
2616 nb_rx_desc_tmp = nb_rx_desc[qid];
2617 rx_free_thresh_tmp =
2618 rx_conf[qid].rx_free_thresh;
2619 pthresh_tmp = rx_conf[qid].rx_thresh.pthresh;
2620 hthresh_tmp = rx_conf[qid].rx_thresh.hthresh;
2621 wthresh_tmp = rx_conf[qid].rx_thresh.wthresh;
2622 offloads_tmp = rx_conf[qid].offloads;
2624 nb_rx_desc_tmp = rx_qinfo.nb_desc;
2625 rx_free_thresh_tmp =
2626 rx_qinfo.conf.rx_free_thresh;
2627 pthresh_tmp = rx_qinfo.conf.rx_thresh.pthresh;
2628 hthresh_tmp = rx_qinfo.conf.rx_thresh.hthresh;
2629 wthresh_tmp = rx_qinfo.conf.rx_thresh.wthresh;
2630 offloads_tmp = rx_qinfo.conf.offloads;
2633 printf(" RX queue: %d\n", qid);
2634 printf(" RX desc=%d - RX free threshold=%d\n",
2635 nb_rx_desc_tmp, rx_free_thresh_tmp);
2636 printf(" RX threshold registers: pthresh=%d hthresh=%d "
2638 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2639 printf(" RX Offloads=0x%"PRIx64"\n", offloads_tmp);
2642 /* per tx queue config only for first queue to be less verbose */
2643 for (qid = 0; qid < 1; qid++) {
2644 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
2646 nb_tx_desc_tmp = nb_tx_desc[qid];
2647 tx_free_thresh_tmp =
2648 tx_conf[qid].tx_free_thresh;
2649 pthresh_tmp = tx_conf[qid].tx_thresh.pthresh;
2650 hthresh_tmp = tx_conf[qid].tx_thresh.hthresh;
2651 wthresh_tmp = tx_conf[qid].tx_thresh.wthresh;
2652 offloads_tmp = tx_conf[qid].offloads;
2653 tx_rs_thresh_tmp = tx_conf[qid].tx_rs_thresh;
2655 nb_tx_desc_tmp = tx_qinfo.nb_desc;
2656 tx_free_thresh_tmp =
2657 tx_qinfo.conf.tx_free_thresh;
2658 pthresh_tmp = tx_qinfo.conf.tx_thresh.pthresh;
2659 hthresh_tmp = tx_qinfo.conf.tx_thresh.hthresh;
2660 wthresh_tmp = tx_qinfo.conf.tx_thresh.wthresh;
2661 offloads_tmp = tx_qinfo.conf.offloads;
2662 tx_rs_thresh_tmp = tx_qinfo.conf.tx_rs_thresh;
2665 printf(" TX queue: %d\n", qid);
2666 printf(" TX desc=%d - TX free threshold=%d\n",
2667 nb_tx_desc_tmp, tx_free_thresh_tmp);
2668 printf(" TX threshold registers: pthresh=%d hthresh=%d "
2670 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2671 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
2672 offloads_tmp, tx_rs_thresh_tmp);
2678 port_rss_reta_info(portid_t port_id,
2679 struct rte_eth_rss_reta_entry64 *reta_conf,
2680 uint16_t nb_entries)
2682 uint16_t i, idx, shift;
2685 if (port_id_is_invalid(port_id, ENABLED_WARN))
2688 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
2690 printf("Failed to get RSS RETA info, return code = %d\n", ret);
2694 for (i = 0; i < nb_entries; i++) {
2695 idx = i / RTE_RETA_GROUP_SIZE;
2696 shift = i % RTE_RETA_GROUP_SIZE;
2697 if (!(reta_conf[idx].mask & (1ULL << shift)))
2699 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
2700 i, reta_conf[idx].reta[shift]);
2705 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
2709 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
2711 struct rte_eth_rss_conf rss_conf = {0};
2712 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
2716 struct rte_eth_dev_info dev_info;
2717 uint8_t hash_key_size;
2720 if (port_id_is_invalid(port_id, ENABLED_WARN))
2723 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2727 if (dev_info.hash_key_size > 0 &&
2728 dev_info.hash_key_size <= sizeof(rss_key))
2729 hash_key_size = dev_info.hash_key_size;
2731 printf("dev_info did not provide a valid hash key size\n");
2735 /* Get RSS hash key if asked to display it */
2736 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2737 rss_conf.rss_key_len = hash_key_size;
2738 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2742 printf("port index %d invalid\n", port_id);
2745 printf("operation not supported by device\n");
2748 printf("operation failed - diag=%d\n", diag);
2753 rss_hf = rss_conf.rss_hf;
2755 printf("RSS disabled\n");
2758 printf("RSS functions:\n ");
2759 for (i = 0; rss_type_table[i].str; i++) {
2760 if (rss_hf & rss_type_table[i].rss_type)
2761 printf("%s ", rss_type_table[i].str);
2766 printf("RSS key:\n");
2767 for (i = 0; i < hash_key_size; i++)
2768 printf("%02X", rss_key[i]);
2773 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2774 uint8_t hash_key_len)
2776 struct rte_eth_rss_conf rss_conf;
2780 rss_conf.rss_key = NULL;
2781 rss_conf.rss_key_len = hash_key_len;
2782 rss_conf.rss_hf = 0;
2783 for (i = 0; rss_type_table[i].str; i++) {
2784 if (!strcmp(rss_type_table[i].str, rss_type))
2785 rss_conf.rss_hf = rss_type_table[i].rss_type;
2787 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2789 rss_conf.rss_key = hash_key;
2790 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2797 printf("port index %d invalid\n", port_id);
2800 printf("operation not supported by device\n");
2803 printf("operation failed - diag=%d\n", diag);
2809 * Setup forwarding configuration for each logical core.
2812 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2814 streamid_t nb_fs_per_lcore;
2822 nb_fs = cfg->nb_fwd_streams;
2823 nb_fc = cfg->nb_fwd_lcores;
2824 if (nb_fs <= nb_fc) {
2825 nb_fs_per_lcore = 1;
2828 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2829 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2832 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2834 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2835 fwd_lcores[lc_id]->stream_idx = sm_id;
2836 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2837 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2841 * Assign extra remaining streams, if any.
2843 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2844 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2845 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2846 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2847 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2852 fwd_topology_tx_port_get(portid_t rxp)
2854 static int warning_once = 1;
2856 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2858 switch (port_topology) {
2860 case PORT_TOPOLOGY_PAIRED:
2861 if ((rxp & 0x1) == 0) {
2862 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2865 printf("\nWarning! port-topology=paired"
2866 " and odd forward ports number,"
2867 " the last port will pair with"
2874 case PORT_TOPOLOGY_CHAINED:
2875 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2876 case PORT_TOPOLOGY_LOOP:
2882 simple_fwd_config_setup(void)
2886 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2887 cur_fwd_config.nb_fwd_streams =
2888 (streamid_t) cur_fwd_config.nb_fwd_ports;
2890 /* reinitialize forwarding streams */
2894 * In the simple forwarding test, the number of forwarding cores
2895 * must be lower or equal to the number of forwarding ports.
2897 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2898 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2899 cur_fwd_config.nb_fwd_lcores =
2900 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2901 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2903 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2904 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2905 fwd_streams[i]->rx_queue = 0;
2906 fwd_streams[i]->tx_port =
2907 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2908 fwd_streams[i]->tx_queue = 0;
2909 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2910 fwd_streams[i]->retry_enabled = retry_enabled;
2915 * For the RSS forwarding test all streams distributed over lcores. Each stream
2916 * being composed of a RX queue to poll on a RX port for input messages,
2917 * associated with a TX queue of a TX port where to send forwarded packets.
2920 rss_fwd_config_setup(void)
2931 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2932 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2933 cur_fwd_config.nb_fwd_streams =
2934 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2936 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2937 cur_fwd_config.nb_fwd_lcores =
2938 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2940 /* reinitialize forwarding streams */
2943 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2945 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2946 struct fwd_stream *fs;
2948 fs = fwd_streams[sm_id];
2949 txp = fwd_topology_tx_port_get(rxp);
2950 fs->rx_port = fwd_ports_ids[rxp];
2952 fs->tx_port = fwd_ports_ids[txp];
2954 fs->peer_addr = fs->tx_port;
2955 fs->retry_enabled = retry_enabled;
2957 if (rxp < nb_fwd_ports)
2965 * For the DCB forwarding test, each core is assigned on each traffic class.
2967 * Each core is assigned a multi-stream, each stream being composed of
2968 * a RX queue to poll on a RX port for input messages, associated with
2969 * a TX queue of a TX port where to send forwarded packets. All RX and
2970 * TX queues are mapping to the same traffic class.
2971 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2975 dcb_fwd_config_setup(void)
2977 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2978 portid_t txp, rxp = 0;
2979 queueid_t txq, rxq = 0;
2981 uint16_t nb_rx_queue, nb_tx_queue;
2982 uint16_t i, j, k, sm_id = 0;
2985 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2986 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2987 cur_fwd_config.nb_fwd_streams =
2988 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2990 /* reinitialize forwarding streams */
2994 /* get the dcb info on the first RX and TX ports */
2995 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2996 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2998 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2999 fwd_lcores[lc_id]->stream_nb = 0;
3000 fwd_lcores[lc_id]->stream_idx = sm_id;
3001 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
3002 /* if the nb_queue is zero, means this tc is
3003 * not enabled on the POOL
3005 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
3007 k = fwd_lcores[lc_id]->stream_nb +
3008 fwd_lcores[lc_id]->stream_idx;
3009 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
3010 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
3011 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3012 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
3013 for (j = 0; j < nb_rx_queue; j++) {
3014 struct fwd_stream *fs;
3016 fs = fwd_streams[k + j];
3017 fs->rx_port = fwd_ports_ids[rxp];
3018 fs->rx_queue = rxq + j;
3019 fs->tx_port = fwd_ports_ids[txp];
3020 fs->tx_queue = txq + j % nb_tx_queue;
3021 fs->peer_addr = fs->tx_port;
3022 fs->retry_enabled = retry_enabled;
3024 fwd_lcores[lc_id]->stream_nb +=
3025 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3027 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
3030 if (tc < rxp_dcb_info.nb_tcs)
3032 /* Restart from TC 0 on next RX port */
3034 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
3036 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
3039 if (rxp >= nb_fwd_ports)
3041 /* get the dcb information on next RX and TX ports */
3042 if ((rxp & 0x1) == 0)
3043 txp = (portid_t) (rxp + 1);
3045 txp = (portid_t) (rxp - 1);
3046 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3047 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3052 icmp_echo_config_setup(void)
3059 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
3060 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
3061 (nb_txq * nb_fwd_ports);
3063 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3064 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3065 cur_fwd_config.nb_fwd_streams =
3066 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3067 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3068 cur_fwd_config.nb_fwd_lcores =
3069 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3070 if (verbose_level > 0) {
3071 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
3073 cur_fwd_config.nb_fwd_lcores,
3074 cur_fwd_config.nb_fwd_ports,
3075 cur_fwd_config.nb_fwd_streams);
3078 /* reinitialize forwarding streams */
3080 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3082 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3083 if (verbose_level > 0)
3084 printf(" core=%d: \n", lc_id);
3085 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3086 struct fwd_stream *fs;
3087 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3088 fs->rx_port = fwd_ports_ids[rxp];
3090 fs->tx_port = fs->rx_port;
3092 fs->peer_addr = fs->tx_port;
3093 fs->retry_enabled = retry_enabled;
3094 if (verbose_level > 0)
3095 printf(" stream=%d port=%d rxq=%d txq=%d\n",
3096 sm_id, fs->rx_port, fs->rx_queue,
3098 rxq = (queueid_t) (rxq + 1);
3099 if (rxq == nb_rxq) {
3101 rxp = (portid_t) (rxp + 1);
3108 fwd_config_setup(void)
3110 cur_fwd_config.fwd_eng = cur_fwd_eng;
3111 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
3112 icmp_echo_config_setup();
3116 if ((nb_rxq > 1) && (nb_txq > 1)){
3118 dcb_fwd_config_setup();
3120 rss_fwd_config_setup();
3123 simple_fwd_config_setup();
3127 mp_alloc_to_str(uint8_t mode)
3130 case MP_ALLOC_NATIVE:
3136 case MP_ALLOC_XMEM_HUGE:
3146 pkt_fwd_config_display(struct fwd_config *cfg)
3148 struct fwd_stream *fs;
3152 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
3153 "NUMA support %s, MP allocation mode: %s\n",
3154 cfg->fwd_eng->fwd_mode_name,
3155 retry_enabled == 0 ? "" : " with retry",
3156 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
3157 numa_support == 1 ? "enabled" : "disabled",
3158 mp_alloc_to_str(mp_alloc_type));
3161 printf("TX retry num: %u, delay between TX retries: %uus\n",
3162 burst_tx_retry_num, burst_tx_delay_time);
3163 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
3164 printf("Logical Core %u (socket %u) forwards packets on "
3166 fwd_lcores_cpuids[lc_id],
3167 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
3168 fwd_lcores[lc_id]->stream_nb);
3169 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3170 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3171 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
3172 "P=%d/Q=%d (socket %u) ",
3173 fs->rx_port, fs->rx_queue,
3174 ports[fs->rx_port].socket_id,
3175 fs->tx_port, fs->tx_queue,
3176 ports[fs->tx_port].socket_id);
3177 print_ethaddr("peer=",
3178 &peer_eth_addrs[fs->peer_addr]);
3186 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
3188 struct rte_ether_addr new_peer_addr;
3189 if (!rte_eth_dev_is_valid_port(port_id)) {
3190 printf("Error: Invalid port number %i\n", port_id);
3193 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
3194 printf("Error: Invalid ethernet address: %s\n", peer_addr);
3197 peer_eth_addrs[port_id] = new_peer_addr;
3201 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
3204 unsigned int lcore_cpuid;
3209 for (i = 0; i < nb_lc; i++) {
3210 lcore_cpuid = lcorelist[i];
3211 if (! rte_lcore_is_enabled(lcore_cpuid)) {
3212 printf("lcore %u not enabled\n", lcore_cpuid);
3215 if (lcore_cpuid == rte_get_main_lcore()) {
3216 printf("lcore %u cannot be masked on for running "
3217 "packet forwarding, which is the main lcore "
3218 "and reserved for command line parsing only\n",
3223 fwd_lcores_cpuids[i] = lcore_cpuid;
3225 if (record_now == 0) {
3229 nb_cfg_lcores = (lcoreid_t) nb_lc;
3230 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
3231 printf("previous number of forwarding cores %u - changed to "
3232 "number of configured cores %u\n",
3233 (unsigned int) nb_fwd_lcores, nb_lc);
3234 nb_fwd_lcores = (lcoreid_t) nb_lc;
3241 set_fwd_lcores_mask(uint64_t lcoremask)
3243 unsigned int lcorelist[64];
3247 if (lcoremask == 0) {
3248 printf("Invalid NULL mask of cores\n");
3252 for (i = 0; i < 64; i++) {
3253 if (! ((uint64_t)(1ULL << i) & lcoremask))
3255 lcorelist[nb_lc++] = i;
3257 return set_fwd_lcores_list(lcorelist, nb_lc);
3261 set_fwd_lcores_number(uint16_t nb_lc)
3263 if (test_done == 0) {
3264 printf("Please stop forwarding first\n");
3267 if (nb_lc > nb_cfg_lcores) {
3268 printf("nb fwd cores %u > %u (max. number of configured "
3269 "lcores) - ignored\n",
3270 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
3273 nb_fwd_lcores = (lcoreid_t) nb_lc;
3274 printf("Number of forwarding cores set to %u\n",
3275 (unsigned int) nb_fwd_lcores);
3279 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
3287 for (i = 0; i < nb_pt; i++) {
3288 port_id = (portid_t) portlist[i];
3289 if (port_id_is_invalid(port_id, ENABLED_WARN))
3292 fwd_ports_ids[i] = port_id;
3294 if (record_now == 0) {
3298 nb_cfg_ports = (portid_t) nb_pt;
3299 if (nb_fwd_ports != (portid_t) nb_pt) {
3300 printf("previous number of forwarding ports %u - changed to "
3301 "number of configured ports %u\n",
3302 (unsigned int) nb_fwd_ports, nb_pt);
3303 nb_fwd_ports = (portid_t) nb_pt;
3308 * Parse the user input and obtain the list of forwarding ports
3311 * String containing the user input. User can specify
3312 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
3313 * For example, if the user wants to use all the available
3314 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
3315 * If the user wants to use only the ports 1,2 then the input
3317 * valid characters are '-' and ','
3318 * @param[out] values
3319 * This array will be filled with a list of port IDs
3320 * based on the user input
3321 * Note that duplicate entries are discarded and only the first
3322 * count entries in this array are port IDs and all the rest
3323 * will contain default values
3324 * @param[in] maxsize
3325 * This parameter denotes 2 things
3326 * 1) Number of elements in the values array
3327 * 2) Maximum value of each element in the values array
3329 * On success, returns total count of parsed port IDs
3330 * On failure, returns 0
3333 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
3335 unsigned int count = 0;
3339 unsigned int marked[maxsize];
3341 if (list == NULL || values == NULL)
3344 for (i = 0; i < (int)maxsize; i++)
3350 /*Remove the blank spaces if any*/
3351 while (isblank(*list))
3356 value = strtol(list, &end, 10);
3357 if (errno || end == NULL)
3359 if (value < 0 || value >= (int)maxsize)
3361 while (isblank(*end))
3363 if (*end == '-' && min == INT_MAX) {
3365 } else if ((*end == ',') || (*end == '\0')) {
3369 for (i = min; i <= max; i++) {
3370 if (count < maxsize) {
3382 } while (*end != '\0');
3388 parse_fwd_portlist(const char *portlist)
3390 unsigned int portcount;
3391 unsigned int portindex[RTE_MAX_ETHPORTS];
3392 unsigned int i, valid_port_count = 0;
3394 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
3396 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
3399 * Here we verify the validity of the ports
3400 * and thereby calculate the total number of
3403 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
3404 if (rte_eth_dev_is_valid_port(portindex[i])) {
3405 portindex[valid_port_count] = portindex[i];
3410 set_fwd_ports_list(portindex, valid_port_count);
3414 set_fwd_ports_mask(uint64_t portmask)
3416 unsigned int portlist[64];
3420 if (portmask == 0) {
3421 printf("Invalid NULL mask of ports\n");
3425 RTE_ETH_FOREACH_DEV(i) {
3426 if (! ((uint64_t)(1ULL << i) & portmask))
3428 portlist[nb_pt++] = i;
3430 set_fwd_ports_list(portlist, nb_pt);
3434 set_fwd_ports_number(uint16_t nb_pt)
3436 if (nb_pt > nb_cfg_ports) {
3437 printf("nb fwd ports %u > %u (number of configured "
3438 "ports) - ignored\n",
3439 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
3442 nb_fwd_ports = (portid_t) nb_pt;
3443 printf("Number of forwarding ports set to %u\n",
3444 (unsigned int) nb_fwd_ports);
3448 port_is_forwarding(portid_t port_id)
3452 if (port_id_is_invalid(port_id, ENABLED_WARN))
3455 for (i = 0; i < nb_fwd_ports; i++) {
3456 if (fwd_ports_ids[i] == port_id)
3464 set_nb_pkt_per_burst(uint16_t nb)
3466 if (nb > MAX_PKT_BURST) {
3467 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
3469 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
3472 nb_pkt_per_burst = nb;
3473 printf("Number of packets per burst set to %u\n",
3474 (unsigned int) nb_pkt_per_burst);
3478 tx_split_get_name(enum tx_pkt_split split)
3482 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3483 if (tx_split_name[i].split == split)
3484 return tx_split_name[i].name;
3490 set_tx_pkt_split(const char *name)
3494 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3495 if (strcmp(tx_split_name[i].name, name) == 0) {
3496 tx_pkt_split = tx_split_name[i].split;
3500 printf("unknown value: \"%s\"\n", name);
3504 parse_fec_mode(const char *name, uint32_t *mode)
3508 for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
3509 if (strcmp(fec_mode_name[i].name, name) == 0) {
3510 *mode = RTE_ETH_FEC_MODE_TO_CAPA(fec_mode_name[i].mode);
3518 show_fec_capability(unsigned int num, struct rte_eth_fec_capa *speed_fec_capa)
3522 printf("FEC capabilities:\n");
3524 for (i = 0; i < num; i++) {
3526 rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
3528 for (j = 0; j < RTE_DIM(fec_mode_name); j++) {
3529 if (RTE_ETH_FEC_MODE_TO_CAPA(j) &
3530 speed_fec_capa[i].capa)
3531 printf("%s ", fec_mode_name[j].name);
3538 show_rx_pkt_offsets(void)
3543 printf("Number of offsets: %u\n", n);
3545 printf("Segment offsets: ");
3546 for (i = 0; i != n - 1; i++)
3547 printf("%hu,", rx_pkt_seg_offsets[i]);
3548 printf("%hu\n", rx_pkt_seg_lengths[i]);
3553 set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs)
3557 if (nb_offs >= MAX_SEGS_BUFFER_SPLIT) {
3558 printf("nb segments per RX packets=%u >= "
3559 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_offs);
3564 * No extra check here, the segment length will be checked by PMD
3565 * in the extended queue setup.
3567 for (i = 0; i < nb_offs; i++) {
3568 if (seg_offsets[i] >= UINT16_MAX) {
3569 printf("offset[%u]=%u > UINT16_MAX - give up\n",
3575 for (i = 0; i < nb_offs; i++)
3576 rx_pkt_seg_offsets[i] = (uint16_t) seg_offsets[i];
3578 rx_pkt_nb_offs = (uint8_t) nb_offs;
3582 show_rx_pkt_segments(void)
3587 printf("Number of segments: %u\n", n);
3589 printf("Segment sizes: ");
3590 for (i = 0; i != n - 1; i++)
3591 printf("%hu,", rx_pkt_seg_lengths[i]);
3592 printf("%hu\n", rx_pkt_seg_lengths[i]);
3597 set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
3601 if (nb_segs >= MAX_SEGS_BUFFER_SPLIT) {
3602 printf("nb segments per RX packets=%u >= "
3603 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs);
3608 * No extra check here, the segment length will be checked by PMD
3609 * in the extended queue setup.
3611 for (i = 0; i < nb_segs; i++) {
3612 if (seg_lengths[i] >= UINT16_MAX) {
3613 printf("length[%u]=%u > UINT16_MAX - give up\n",
3619 for (i = 0; i < nb_segs; i++)
3620 rx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3622 rx_pkt_nb_segs = (uint8_t) nb_segs;
3626 show_tx_pkt_segments(void)
3632 split = tx_split_get_name(tx_pkt_split);
3634 printf("Number of segments: %u\n", n);
3635 printf("Segment sizes: ");
3636 for (i = 0; i != n - 1; i++)
3637 printf("%hu,", tx_pkt_seg_lengths[i]);
3638 printf("%hu\n", tx_pkt_seg_lengths[i]);
3639 printf("Split packet: %s\n", split);
3643 nb_segs_is_invalid(unsigned int nb_segs)
3650 RTE_ETH_FOREACH_DEV(port_id) {
3651 for (queue_id = 0; queue_id < nb_txq; queue_id++) {
3652 ret = get_tx_ring_size(port_id, queue_id, &ring_size);
3657 if (ring_size < nb_segs) {
3658 printf("nb segments per TX packets=%u >= "
3659 "TX queue(%u) ring_size=%u - ignored\n",
3660 nb_segs, queue_id, ring_size);
3670 set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
3672 uint16_t tx_pkt_len;
3675 if (nb_segs_is_invalid(nb_segs))
3679 * Check that each segment length is greater or equal than
3680 * the mbuf data sise.
3681 * Check also that the total packet length is greater or equal than the
3682 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
3686 for (i = 0; i < nb_segs; i++) {
3687 if (seg_lengths[i] > mbuf_data_size[0]) {
3688 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
3689 i, seg_lengths[i], mbuf_data_size[0]);
3692 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
3694 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
3695 printf("total packet length=%u < %d - give up\n",
3696 (unsigned) tx_pkt_len,
3697 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
3701 for (i = 0; i < nb_segs; i++)
3702 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3704 tx_pkt_length = tx_pkt_len;
3705 tx_pkt_nb_segs = (uint8_t) nb_segs;
3709 show_tx_pkt_times(void)
3711 printf("Interburst gap: %u\n", tx_pkt_times_inter);
3712 printf("Intraburst gap: %u\n", tx_pkt_times_intra);
3716 set_tx_pkt_times(unsigned int *tx_times)
3718 tx_pkt_times_inter = tx_times[0];
3719 tx_pkt_times_intra = tx_times[1];
3723 setup_gro(const char *onoff, portid_t port_id)
3725 if (!rte_eth_dev_is_valid_port(port_id)) {
3726 printf("invalid port id %u\n", port_id);
3729 if (test_done == 0) {
3730 printf("Before enable/disable GRO,"
3731 " please stop forwarding first\n");
3734 if (strcmp(onoff, "on") == 0) {
3735 if (gro_ports[port_id].enable != 0) {
3736 printf("Port %u has enabled GRO. Please"
3737 " disable GRO first\n", port_id);
3740 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3741 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
3742 gro_ports[port_id].param.max_flow_num =
3743 GRO_DEFAULT_FLOW_NUM;
3744 gro_ports[port_id].param.max_item_per_flow =
3745 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
3747 gro_ports[port_id].enable = 1;
3749 if (gro_ports[port_id].enable == 0) {
3750 printf("Port %u has disabled GRO\n", port_id);
3753 gro_ports[port_id].enable = 0;
3758 setup_gro_flush_cycles(uint8_t cycles)
3760 if (test_done == 0) {
3761 printf("Before change flush interval for GRO,"
3762 " please stop forwarding first.\n");
3766 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
3767 GRO_DEFAULT_FLUSH_CYCLES) {
3768 printf("The flushing cycle be in the range"
3769 " of 1 to %u. Revert to the default"
3771 GRO_MAX_FLUSH_CYCLES,
3772 GRO_DEFAULT_FLUSH_CYCLES);
3773 cycles = GRO_DEFAULT_FLUSH_CYCLES;
3776 gro_flush_cycles = cycles;
3780 show_gro(portid_t port_id)
3782 struct rte_gro_param *param;
3783 uint32_t max_pkts_num;
3785 param = &gro_ports[port_id].param;
3787 if (!rte_eth_dev_is_valid_port(port_id)) {
3788 printf("Invalid port id %u.\n", port_id);
3791 if (gro_ports[port_id].enable) {
3792 printf("GRO type: TCP/IPv4\n");
3793 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3794 max_pkts_num = param->max_flow_num *
3795 param->max_item_per_flow;
3797 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
3798 printf("Max number of packets to perform GRO: %u\n",
3800 printf("Flushing cycles: %u\n", gro_flush_cycles);
3802 printf("Port %u doesn't enable GRO.\n", port_id);
3806 setup_gso(const char *mode, portid_t port_id)
3808 if (!rte_eth_dev_is_valid_port(port_id)) {
3809 printf("invalid port id %u\n", port_id);
3812 if (strcmp(mode, "on") == 0) {
3813 if (test_done == 0) {
3814 printf("before enabling GSO,"
3815 " please stop forwarding first\n");
3818 gso_ports[port_id].enable = 1;
3819 } else if (strcmp(mode, "off") == 0) {
3820 if (test_done == 0) {
3821 printf("before disabling GSO,"
3822 " please stop forwarding first\n");
3825 gso_ports[port_id].enable = 0;
3830 list_pkt_forwarding_modes(void)
3832 static char fwd_modes[128] = "";
3833 const char *separator = "|";
3834 struct fwd_engine *fwd_eng;
3837 if (strlen (fwd_modes) == 0) {
3838 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3839 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3840 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3841 strncat(fwd_modes, separator,
3842 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3844 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3851 list_pkt_forwarding_retry_modes(void)
3853 static char fwd_modes[128] = "";
3854 const char *separator = "|";
3855 struct fwd_engine *fwd_eng;
3858 if (strlen(fwd_modes) == 0) {
3859 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3860 if (fwd_eng == &rx_only_engine)
3862 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3864 strlen(fwd_modes) - 1);
3865 strncat(fwd_modes, separator,
3867 strlen(fwd_modes) - 1);
3869 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3876 set_pkt_forwarding_mode(const char *fwd_mode_name)
3878 struct fwd_engine *fwd_eng;
3882 while ((fwd_eng = fwd_engines[i]) != NULL) {
3883 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
3884 printf("Set %s packet forwarding mode%s\n",
3886 retry_enabled == 0 ? "" : " with retry");
3887 cur_fwd_eng = fwd_eng;
3892 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
3896 add_rx_dump_callbacks(portid_t portid)
3898 struct rte_eth_dev_info dev_info;
3902 if (port_id_is_invalid(portid, ENABLED_WARN))
3905 ret = eth_dev_info_get_print_err(portid, &dev_info);
3909 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3910 if (!ports[portid].rx_dump_cb[queue])
3911 ports[portid].rx_dump_cb[queue] =
3912 rte_eth_add_rx_callback(portid, queue,
3913 dump_rx_pkts, NULL);
3917 add_tx_dump_callbacks(portid_t portid)
3919 struct rte_eth_dev_info dev_info;
3923 if (port_id_is_invalid(portid, ENABLED_WARN))
3926 ret = eth_dev_info_get_print_err(portid, &dev_info);
3930 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3931 if (!ports[portid].tx_dump_cb[queue])
3932 ports[portid].tx_dump_cb[queue] =
3933 rte_eth_add_tx_callback(portid, queue,
3934 dump_tx_pkts, NULL);
3938 remove_rx_dump_callbacks(portid_t portid)
3940 struct rte_eth_dev_info dev_info;
3944 if (port_id_is_invalid(portid, ENABLED_WARN))
3947 ret = eth_dev_info_get_print_err(portid, &dev_info);
3951 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3952 if (ports[portid].rx_dump_cb[queue]) {
3953 rte_eth_remove_rx_callback(portid, queue,
3954 ports[portid].rx_dump_cb[queue]);
3955 ports[portid].rx_dump_cb[queue] = NULL;
3960 remove_tx_dump_callbacks(portid_t portid)
3962 struct rte_eth_dev_info dev_info;
3966 if (port_id_is_invalid(portid, ENABLED_WARN))
3969 ret = eth_dev_info_get_print_err(portid, &dev_info);
3973 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3974 if (ports[portid].tx_dump_cb[queue]) {
3975 rte_eth_remove_tx_callback(portid, queue,
3976 ports[portid].tx_dump_cb[queue]);
3977 ports[portid].tx_dump_cb[queue] = NULL;
3982 configure_rxtx_dump_callbacks(uint16_t verbose)
3986 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3987 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
3991 RTE_ETH_FOREACH_DEV(portid)
3993 if (verbose == 1 || verbose > 2)
3994 add_rx_dump_callbacks(portid);
3996 remove_rx_dump_callbacks(portid);
3998 add_tx_dump_callbacks(portid);
4000 remove_tx_dump_callbacks(portid);
4005 set_verbose_level(uint16_t vb_level)
4007 printf("Change verbose level from %u to %u\n",
4008 (unsigned int) verbose_level, (unsigned int) vb_level);
4009 verbose_level = vb_level;
4010 configure_rxtx_dump_callbacks(verbose_level);
4014 vlan_extend_set(portid_t port_id, int on)
4018 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4020 if (port_id_is_invalid(port_id, ENABLED_WARN))
4023 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4026 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
4027 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
4029 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
4030 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
4033 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4035 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
4036 "diag=%d\n", port_id, on, diag);
4039 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4043 rx_vlan_strip_set(portid_t port_id, int on)
4047 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4049 if (port_id_is_invalid(port_id, ENABLED_WARN))
4052 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4055 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
4056 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
4058 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
4059 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
4062 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4064 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
4065 "diag=%d\n", port_id, on, diag);
4068 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4072 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
4076 if (port_id_is_invalid(port_id, ENABLED_WARN))
4079 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
4081 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
4082 "diag=%d\n", port_id, queue_id, on, diag);
4086 rx_vlan_filter_set(portid_t port_id, int on)
4090 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4092 if (port_id_is_invalid(port_id, ENABLED_WARN))
4095 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4098 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
4099 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
4101 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
4102 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
4105 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4107 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
4108 "diag=%d\n", port_id, on, diag);
4111 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4115 rx_vlan_qinq_strip_set(portid_t port_id, int on)
4119 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4121 if (port_id_is_invalid(port_id, ENABLED_WARN))
4124 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4127 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
4128 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
4130 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
4131 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
4134 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4136 printf("%s(port_pi=%d, on=%d) failed "
4137 "diag=%d\n", __func__, port_id, on, diag);
4140 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4144 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
4148 if (port_id_is_invalid(port_id, ENABLED_WARN))
4150 if (vlan_id_is_invalid(vlan_id))
4152 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
4155 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
4157 port_id, vlan_id, on, diag);
4162 rx_vlan_all_filter_set(portid_t port_id, int on)
4166 if (port_id_is_invalid(port_id, ENABLED_WARN))
4168 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
4169 if (rx_vft_set(port_id, vlan_id, on))
4175 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
4179 if (port_id_is_invalid(port_id, ENABLED_WARN))
4182 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
4186 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
4188 port_id, vlan_type, tp_id, diag);
4192 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
4194 struct rte_eth_dev_info dev_info;
4197 if (vlan_id_is_invalid(vlan_id))
4200 if (ports[port_id].dev_conf.txmode.offloads &
4201 DEV_TX_OFFLOAD_QINQ_INSERT) {
4202 printf("Error, as QinQ has been enabled.\n");
4206 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4210 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
4211 printf("Error: vlan insert is not supported by port %d\n",
4216 tx_vlan_reset(port_id);
4217 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
4218 ports[port_id].tx_vlan_id = vlan_id;
4222 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
4224 struct rte_eth_dev_info dev_info;
4227 if (vlan_id_is_invalid(vlan_id))
4229 if (vlan_id_is_invalid(vlan_id_outer))
4232 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4236 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
4237 printf("Error: qinq insert not supported by port %d\n",
4242 tx_vlan_reset(port_id);
4243 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
4244 DEV_TX_OFFLOAD_QINQ_INSERT);
4245 ports[port_id].tx_vlan_id = vlan_id;
4246 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
4250 tx_vlan_reset(portid_t port_id)
4252 ports[port_id].dev_conf.txmode.offloads &=
4253 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
4254 DEV_TX_OFFLOAD_QINQ_INSERT);
4255 ports[port_id].tx_vlan_id = 0;
4256 ports[port_id].tx_vlan_id_outer = 0;
4260 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
4262 if (port_id_is_invalid(port_id, ENABLED_WARN))
4265 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
4269 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
4273 if (port_id_is_invalid(port_id, ENABLED_WARN))
4276 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
4279 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
4280 printf("map_value not in required range 0..%d\n",
4281 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
4285 if (!is_rx) { /* tx */
4286 ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, queue_id,
4289 printf("failed to set tx queue stats mapping.\n");
4293 ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, queue_id,
4296 printf("failed to set rx queue stats mapping.\n");
4303 set_xstats_hide_zero(uint8_t on_off)
4305 xstats_hide_zero = on_off;
4309 set_record_core_cycles(uint8_t on_off)
4311 record_core_cycles = on_off;
4315 set_record_burst_stats(uint8_t on_off)
4317 record_burst_stats = on_off;
4321 print_fdir_mask(struct rte_eth_fdir_masks *mask)
4323 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
4325 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4326 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
4327 " tunnel_id: 0x%08x",
4328 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
4329 rte_be_to_cpu_32(mask->tunnel_id_mask));
4330 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
4331 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
4332 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
4333 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
4335 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
4336 rte_be_to_cpu_16(mask->src_port_mask),
4337 rte_be_to_cpu_16(mask->dst_port_mask));
4339 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4340 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
4341 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
4342 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
4343 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
4345 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4346 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
4347 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
4348 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
4349 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
4356 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4358 struct rte_eth_flex_payload_cfg *cfg;
4361 for (i = 0; i < flex_conf->nb_payloads; i++) {
4362 cfg = &flex_conf->flex_set[i];
4363 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
4365 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
4366 printf("\n L2_PAYLOAD: ");
4367 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
4368 printf("\n L3_PAYLOAD: ");
4369 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
4370 printf("\n L4_PAYLOAD: ");
4372 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
4373 for (j = 0; j < num; j++)
4374 printf(" %-5u", cfg->src_offset[j]);
4380 flowtype_to_str(uint16_t flow_type)
4382 struct flow_type_info {
4388 static struct flow_type_info flowtype_str_table[] = {
4389 {"raw", RTE_ETH_FLOW_RAW},
4390 {"ipv4", RTE_ETH_FLOW_IPV4},
4391 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
4392 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
4393 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
4394 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
4395 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
4396 {"ipv6", RTE_ETH_FLOW_IPV6},
4397 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
4398 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
4399 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
4400 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
4401 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
4402 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
4403 {"port", RTE_ETH_FLOW_PORT},
4404 {"vxlan", RTE_ETH_FLOW_VXLAN},
4405 {"geneve", RTE_ETH_FLOW_GENEVE},
4406 {"nvgre", RTE_ETH_FLOW_NVGRE},
4407 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
4410 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
4411 if (flowtype_str_table[i].ftype == flow_type)
4412 return flowtype_str_table[i].str;
4418 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
4421 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4423 struct rte_eth_fdir_flex_mask *mask;
4427 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
4428 mask = &flex_conf->flex_mask[i];
4429 p = flowtype_to_str(mask->flow_type);
4430 printf("\n %s:\t", p ? p : "unknown");
4431 for (j = 0; j < num; j++)
4432 printf(" %02x", mask->mask[j]);
4438 print_fdir_flow_type(uint32_t flow_types_mask)
4443 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
4444 if (!(flow_types_mask & (1 << i)))
4446 p = flowtype_to_str(i);
4456 get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info,
4457 struct rte_eth_fdir_stats *fdir_stat)
4462 if (ret == -ENOTSUP) {
4463 ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info);
4465 ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat);
4468 #ifdef RTE_NET_IXGBE
4469 if (ret == -ENOTSUP) {
4470 ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info);
4472 ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat);
4479 printf("\n FDIR is not supported on port %-2d\n",
4483 printf("programming error: (%s)\n", strerror(-ret));
4490 fdir_get_infos(portid_t port_id)
4492 struct rte_eth_fdir_stats fdir_stat;
4493 struct rte_eth_fdir_info fdir_info;
4495 static const char *fdir_stats_border = "########################";
4497 if (port_id_is_invalid(port_id, ENABLED_WARN))
4500 memset(&fdir_info, 0, sizeof(fdir_info));
4501 memset(&fdir_stat, 0, sizeof(fdir_stat));
4502 if (get_fdir_info(port_id, &fdir_info, &fdir_stat))
4505 printf("\n %s FDIR infos for port %-2d %s\n",
4506 fdir_stats_border, port_id, fdir_stats_border);
4508 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
4509 printf(" PERFECT\n");
4510 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
4511 printf(" PERFECT-MAC-VLAN\n");
4512 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4513 printf(" PERFECT-TUNNEL\n");
4514 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
4515 printf(" SIGNATURE\n");
4517 printf(" DISABLE\n");
4518 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
4519 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
4520 printf(" SUPPORTED FLOW TYPE: ");
4521 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
4523 printf(" FLEX PAYLOAD INFO:\n");
4524 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
4525 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
4526 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
4527 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
4528 fdir_info.flex_payload_unit,
4529 fdir_info.max_flex_payload_segment_num,
4530 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
4532 print_fdir_mask(&fdir_info.mask);
4533 if (fdir_info.flex_conf.nb_payloads > 0) {
4534 printf(" FLEX PAYLOAD SRC OFFSET:");
4535 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4537 if (fdir_info.flex_conf.nb_flexmasks > 0) {
4538 printf(" FLEX MASK CFG:");
4539 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4541 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
4542 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
4543 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
4544 fdir_info.guarant_spc, fdir_info.best_spc);
4545 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
4546 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
4547 " add: %-10"PRIu64" remove: %"PRIu64"\n"
4548 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
4549 fdir_stat.collision, fdir_stat.free,
4550 fdir_stat.maxhash, fdir_stat.maxlen,
4551 fdir_stat.add, fdir_stat.remove,
4552 fdir_stat.f_add, fdir_stat.f_remove);
4553 printf(" %s############################%s\n",
4554 fdir_stats_border, fdir_stats_border);
4557 #endif /* RTE_NET_I40E || RTE_NET_IXGBE */
4560 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
4562 struct rte_port *port;
4563 struct rte_eth_fdir_flex_conf *flex_conf;
4566 port = &ports[port_id];
4567 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
4568 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
4569 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
4574 if (i >= RTE_ETH_FLOW_MAX) {
4575 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
4576 idx = flex_conf->nb_flexmasks;
4577 flex_conf->nb_flexmasks++;
4579 printf("The flex mask table is full. Can not set flex"
4580 " mask for flow_type(%u).", cfg->flow_type);
4584 rte_memcpy(&flex_conf->flex_mask[idx],
4586 sizeof(struct rte_eth_fdir_flex_mask));
4590 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
4592 struct rte_port *port;
4593 struct rte_eth_fdir_flex_conf *flex_conf;
4596 port = &ports[port_id];
4597 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
4598 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
4599 if (cfg->type == flex_conf->flex_set[i].type) {
4604 if (i >= RTE_ETH_PAYLOAD_MAX) {
4605 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
4606 idx = flex_conf->nb_payloads;
4607 flex_conf->nb_payloads++;
4609 printf("The flex payload table is full. Can not set"
4610 " flex payload for type(%u).", cfg->type);
4614 rte_memcpy(&flex_conf->flex_set[idx],
4616 sizeof(struct rte_eth_flex_payload_cfg));
4621 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
4623 #ifdef RTE_NET_IXGBE
4627 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
4629 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
4633 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
4634 is_rx ? "rx" : "tx", port_id, diag);
4637 printf("VF %s setting not supported for port %d\n",
4638 is_rx ? "Rx" : "Tx", port_id);
4644 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
4647 struct rte_eth_link link;
4650 if (port_id_is_invalid(port_id, ENABLED_WARN))
4652 ret = eth_link_get_nowait_print_err(port_id, &link);
4655 if (link.link_speed != ETH_SPEED_NUM_UNKNOWN &&
4656 rate > link.link_speed) {
4657 printf("Invalid rate value:%u bigger than link speed: %u\n",
4658 rate, link.link_speed);
4661 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
4664 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
4670 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
4672 int diag = -ENOTSUP;
4676 RTE_SET_USED(q_msk);
4678 #ifdef RTE_NET_IXGBE
4679 if (diag == -ENOTSUP)
4680 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
4684 if (diag == -ENOTSUP)
4685 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
4690 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
4696 * Functions to manage the set of filtered Multicast MAC addresses.
4698 * A pool of filtered multicast MAC addresses is associated with each port.
4699 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
4700 * The address of the pool and the number of valid multicast MAC addresses
4701 * recorded in the pool are stored in the fields "mc_addr_pool" and
4702 * "mc_addr_nb" of the "rte_port" data structure.
4704 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
4705 * to be supplied a contiguous array of multicast MAC addresses.
4706 * To comply with this constraint, the set of multicast addresses recorded
4707 * into the pool are systematically compacted at the beginning of the pool.
4708 * Hence, when a multicast address is removed from the pool, all following
4709 * addresses, if any, are copied back to keep the set contiguous.
4711 #define MCAST_POOL_INC 32
4714 mcast_addr_pool_extend(struct rte_port *port)
4716 struct rte_ether_addr *mc_pool;
4717 size_t mc_pool_size;
4720 * If a free entry is available at the end of the pool, just
4721 * increment the number of recorded multicast addresses.
4723 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
4729 * [re]allocate a pool with MCAST_POOL_INC more entries.
4730 * The previous test guarantees that port->mc_addr_nb is a multiple
4731 * of MCAST_POOL_INC.
4733 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
4735 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
4737 if (mc_pool == NULL) {
4738 printf("allocation of pool of %u multicast addresses failed\n",
4739 port->mc_addr_nb + MCAST_POOL_INC);
4743 port->mc_addr_pool = mc_pool;
4750 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
4752 if (mcast_addr_pool_extend(port) != 0)
4754 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
4758 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
4761 if (addr_idx == port->mc_addr_nb) {
4762 /* No need to recompact the set of multicast addressses. */
4763 if (port->mc_addr_nb == 0) {
4764 /* free the pool of multicast addresses. */
4765 free(port->mc_addr_pool);
4766 port->mc_addr_pool = NULL;
4770 memmove(&port->mc_addr_pool[addr_idx],
4771 &port->mc_addr_pool[addr_idx + 1],
4772 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
4776 eth_port_multicast_addr_list_set(portid_t port_id)
4778 struct rte_port *port;
4781 port = &ports[port_id];
4782 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
4785 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
4786 port_id, port->mc_addr_nb, diag);
4792 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
4794 struct rte_port *port;
4797 if (port_id_is_invalid(port_id, ENABLED_WARN))
4800 port = &ports[port_id];
4803 * Check that the added multicast MAC address is not already recorded
4804 * in the pool of multicast addresses.
4806 for (i = 0; i < port->mc_addr_nb; i++) {
4807 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
4808 printf("multicast address already filtered by port\n");
4813 mcast_addr_pool_append(port, mc_addr);
4814 if (eth_port_multicast_addr_list_set(port_id) < 0)
4815 /* Rollback on failure, remove the address from the pool */
4816 mcast_addr_pool_remove(port, i);
4820 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
4822 struct rte_port *port;
4825 if (port_id_is_invalid(port_id, ENABLED_WARN))
4828 port = &ports[port_id];
4831 * Search the pool of multicast MAC addresses for the removed address.
4833 for (i = 0; i < port->mc_addr_nb; i++) {
4834 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
4837 if (i == port->mc_addr_nb) {
4838 printf("multicast address not filtered by port %d\n", port_id);
4842 mcast_addr_pool_remove(port, i);
4843 if (eth_port_multicast_addr_list_set(port_id) < 0)
4844 /* Rollback on failure, add the address back into the pool */
4845 mcast_addr_pool_append(port, mc_addr);
4849 port_dcb_info_display(portid_t port_id)
4851 struct rte_eth_dcb_info dcb_info;
4854 static const char *border = "================";
4856 if (port_id_is_invalid(port_id, ENABLED_WARN))
4859 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
4861 printf("\n Failed to get dcb infos on port %-2d\n",
4865 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
4866 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
4868 for (i = 0; i < dcb_info.nb_tcs; i++)
4870 printf("\n Priority : ");
4871 for (i = 0; i < dcb_info.nb_tcs; i++)
4872 printf("\t%4d", dcb_info.prio_tc[i]);
4873 printf("\n BW percent :");
4874 for (i = 0; i < dcb_info.nb_tcs; i++)
4875 printf("\t%4d%%", dcb_info.tc_bws[i]);
4876 printf("\n RXQ base : ");
4877 for (i = 0; i < dcb_info.nb_tcs; i++)
4878 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
4879 printf("\n RXQ number :");
4880 for (i = 0; i < dcb_info.nb_tcs; i++)
4881 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
4882 printf("\n TXQ base : ");
4883 for (i = 0; i < dcb_info.nb_tcs; i++)
4884 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
4885 printf("\n TXQ number :");
4886 for (i = 0; i < dcb_info.nb_tcs; i++)
4887 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
4892 open_file(const char *file_path, uint32_t *size)
4894 int fd = open(file_path, O_RDONLY);
4896 uint8_t *buf = NULL;
4904 printf("%s: Failed to open %s\n", __func__, file_path);
4908 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
4910 printf("%s: File operations failed\n", __func__);
4914 pkg_size = st_buf.st_size;
4917 printf("%s: File operations failed\n", __func__);
4921 buf = (uint8_t *)malloc(pkg_size);
4924 printf("%s: Failed to malloc memory\n", __func__);
4928 ret = read(fd, buf, pkg_size);
4931 printf("%s: File read operation failed\n", __func__);
4945 save_file(const char *file_path, uint8_t *buf, uint32_t size)
4947 FILE *fh = fopen(file_path, "wb");
4950 printf("%s: Failed to open %s\n", __func__, file_path);
4954 if (fwrite(buf, 1, size, fh) != size) {
4956 printf("%s: File write operation failed\n", __func__);
4966 close_file(uint8_t *buf)
4977 port_queue_region_info_display(portid_t port_id, void *buf)
4981 struct rte_pmd_i40e_queue_regions *info =
4982 (struct rte_pmd_i40e_queue_regions *)buf;
4983 static const char *queue_region_info_stats_border = "-------";
4985 if (!info->queue_region_number)
4986 printf("there is no region has been set before");
4988 printf("\n %s All queue region info for port=%2d %s",
4989 queue_region_info_stats_border, port_id,
4990 queue_region_info_stats_border);
4991 printf("\n queue_region_number: %-14u \n",
4992 info->queue_region_number);
4994 for (i = 0; i < info->queue_region_number; i++) {
4995 printf("\n region_id: %-14u queue_number: %-14u "
4996 "queue_start_index: %-14u \n",
4997 info->region[i].region_id,
4998 info->region[i].queue_num,
4999 info->region[i].queue_start_index);
5001 printf(" user_priority_num is %-14u :",
5002 info->region[i].user_priority_num);
5003 for (j = 0; j < info->region[i].user_priority_num; j++)
5004 printf(" %-14u ", info->region[i].user_priority[j]);
5006 printf("\n flowtype_num is %-14u :",
5007 info->region[i].flowtype_num);
5008 for (j = 0; j < info->region[i].flowtype_num; j++)
5009 printf(" %-14u ", info->region[i].hw_flowtype[j]);
5012 RTE_SET_USED(port_id);
5020 show_macs(portid_t port_id)
5022 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5023 struct rte_eth_dev_info dev_info;
5024 struct rte_ether_addr *addr;
5025 uint32_t i, num_macs = 0;
5026 struct rte_eth_dev *dev;
5028 dev = &rte_eth_devices[port_id];
5030 if (eth_dev_info_get_print_err(port_id, &dev_info))
5033 for (i = 0; i < dev_info.max_mac_addrs; i++) {
5034 addr = &dev->data->mac_addrs[i];
5036 /* skip zero address */
5037 if (rte_is_zero_ether_addr(addr))
5043 printf("Number of MAC address added: %d\n", num_macs);
5045 for (i = 0; i < dev_info.max_mac_addrs; i++) {
5046 addr = &dev->data->mac_addrs[i];
5048 /* skip zero address */
5049 if (rte_is_zero_ether_addr(addr))
5052 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5053 printf(" %s\n", buf);
5058 show_mcast_macs(portid_t port_id)
5060 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5061 struct rte_ether_addr *addr;
5062 struct rte_port *port;
5065 port = &ports[port_id];
5067 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
5069 for (i = 0; i < port->mc_addr_nb; i++) {
5070 addr = &port->mc_addr_pool[i];
5072 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5073 printf(" %s\n", buf);