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>
42 #include <rte_errno.h>
44 #include <rte_pmd_ixgbe.h>
47 #include <rte_pmd_i40e.h>
50 #include <rte_pmd_bnxt.h>
53 #include <rte_hexdump.h>
56 #include "cmdline_mtr.h"
58 #define ETHDEV_FWVERS_LEN 32
60 #ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
61 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
63 #define CLOCK_TYPE_ID CLOCK_MONOTONIC
66 #define NS_PER_SEC 1E9
68 static char *flowtype_to_str(uint16_t flow_type);
71 enum tx_pkt_split split;
75 .split = TX_PKT_SPLIT_OFF,
79 .split = TX_PKT_SPLIT_ON,
83 .split = TX_PKT_SPLIT_RND,
88 const struct rss_type_info rss_type_table[] = {
89 { "all", ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP | ETH_RSS_TCP |
90 ETH_RSS_UDP | ETH_RSS_SCTP | ETH_RSS_L2_PAYLOAD |
91 ETH_RSS_L2TPV3 | ETH_RSS_ESP | ETH_RSS_AH | ETH_RSS_PFCP |
92 ETH_RSS_GTPU | ETH_RSS_ECPRI | ETH_RSS_MPLS},
94 { "eth", ETH_RSS_ETH },
95 { "l2-src-only", ETH_RSS_L2_SRC_ONLY },
96 { "l2-dst-only", ETH_RSS_L2_DST_ONLY },
97 { "vlan", ETH_RSS_VLAN },
98 { "s-vlan", ETH_RSS_S_VLAN },
99 { "c-vlan", ETH_RSS_C_VLAN },
100 { "ipv4", ETH_RSS_IPV4 },
101 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
102 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
103 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
104 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
105 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
106 { "ipv6", ETH_RSS_IPV6 },
107 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
108 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
109 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
110 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
111 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
112 { "l2-payload", ETH_RSS_L2_PAYLOAD },
113 { "ipv6-ex", ETH_RSS_IPV6_EX },
114 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
115 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
116 { "port", ETH_RSS_PORT },
117 { "vxlan", ETH_RSS_VXLAN },
118 { "geneve", ETH_RSS_GENEVE },
119 { "nvgre", ETH_RSS_NVGRE },
120 { "ip", ETH_RSS_IP },
121 { "udp", ETH_RSS_UDP },
122 { "tcp", ETH_RSS_TCP },
123 { "sctp", ETH_RSS_SCTP },
124 { "tunnel", ETH_RSS_TUNNEL },
125 { "l3-pre32", RTE_ETH_RSS_L3_PRE32 },
126 { "l3-pre40", RTE_ETH_RSS_L3_PRE40 },
127 { "l3-pre48", RTE_ETH_RSS_L3_PRE48 },
128 { "l3-pre56", RTE_ETH_RSS_L3_PRE56 },
129 { "l3-pre64", RTE_ETH_RSS_L3_PRE64 },
130 { "l3-pre96", RTE_ETH_RSS_L3_PRE96 },
131 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
132 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
133 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
134 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
135 { "esp", ETH_RSS_ESP },
136 { "ah", ETH_RSS_AH },
137 { "l2tpv3", ETH_RSS_L2TPV3 },
138 { "pfcp", ETH_RSS_PFCP },
139 { "pppoe", ETH_RSS_PPPOE },
140 { "gtpu", ETH_RSS_GTPU },
141 { "ecpri", ETH_RSS_ECPRI },
142 { "mpls", ETH_RSS_MPLS },
143 { "ipv4-chksum", ETH_RSS_IPV4_CHKSUM },
144 { "l4-chksum", ETH_RSS_L4_CHKSUM },
148 static const struct {
149 enum rte_eth_fec_mode mode;
151 } fec_mode_name[] = {
153 .mode = RTE_ETH_FEC_NOFEC,
157 .mode = RTE_ETH_FEC_AUTO,
161 .mode = RTE_ETH_FEC_BASER,
165 .mode = RTE_ETH_FEC_RS,
171 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
173 char buf[RTE_ETHER_ADDR_FMT_SIZE];
174 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
175 printf("%s%s", name, buf);
179 nic_stats_display(portid_t port_id)
181 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
182 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
183 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
184 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
185 static uint64_t prev_ns[RTE_MAX_ETHPORTS];
186 struct timespec cur_time;
187 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
189 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
190 struct rte_eth_stats stats;
192 static const char *nic_stats_border = "########################";
194 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
198 rte_eth_stats_get(port_id, &stats);
199 printf("\n %s NIC statistics for port %-2d %s\n",
200 nic_stats_border, port_id, nic_stats_border);
202 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
203 "%-"PRIu64"\n", stats.ipackets, stats.imissed, stats.ibytes);
204 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
205 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
206 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
207 "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
210 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
213 ns = cur_time.tv_sec * NS_PER_SEC;
214 ns += cur_time.tv_nsec;
216 if (prev_ns[port_id] != 0)
217 diff_ns = ns - prev_ns[port_id];
218 prev_ns[port_id] = ns;
221 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
222 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
223 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
224 (stats.opackets - prev_pkts_tx[port_id]) : 0;
225 prev_pkts_rx[port_id] = stats.ipackets;
226 prev_pkts_tx[port_id] = stats.opackets;
227 mpps_rx = diff_ns > 0 ?
228 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
229 mpps_tx = diff_ns > 0 ?
230 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
232 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
233 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
234 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
235 (stats.obytes - prev_bytes_tx[port_id]) : 0;
236 prev_bytes_rx[port_id] = stats.ibytes;
237 prev_bytes_tx[port_id] = stats.obytes;
238 mbps_rx = diff_ns > 0 ?
239 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
240 mbps_tx = diff_ns > 0 ?
241 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
243 printf("\n Throughput (since last show)\n");
244 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
245 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
246 mpps_tx, mbps_tx * 8);
248 printf(" %s############################%s\n",
249 nic_stats_border, nic_stats_border);
253 nic_stats_clear(portid_t port_id)
257 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
262 ret = rte_eth_stats_reset(port_id);
265 "%s: Error: failed to reset stats (port %u): %s",
266 __func__, port_id, strerror(-ret));
270 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
275 "%s: Error: failed to get stats (port %u): %s",
276 __func__, port_id, strerror(ret));
279 printf("\n NIC statistics for port %d cleared\n", port_id);
283 nic_xstats_display(portid_t port_id)
285 struct rte_eth_xstat *xstats;
286 int cnt_xstats, idx_xstat;
287 struct rte_eth_xstat_name *xstats_names;
289 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
293 printf("###### NIC extended statistics for port %-2d\n", port_id);
294 if (!rte_eth_dev_is_valid_port(port_id)) {
295 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
300 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
301 if (cnt_xstats < 0) {
302 fprintf(stderr, "Error: Cannot get count of xstats\n");
306 /* Get id-name lookup table */
307 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
308 if (xstats_names == NULL) {
309 fprintf(stderr, "Cannot allocate memory for xstats lookup\n");
312 if (cnt_xstats != rte_eth_xstats_get_names(
313 port_id, xstats_names, cnt_xstats)) {
314 fprintf(stderr, "Error: Cannot get xstats lookup\n");
319 /* Get stats themselves */
320 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
321 if (xstats == NULL) {
322 fprintf(stderr, "Cannot allocate memory for xstats\n");
326 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
327 fprintf(stderr, "Error: Unable to get xstats\n");
334 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
335 if (xstats_hide_zero && !xstats[idx_xstat].value)
337 printf("%s: %"PRIu64"\n",
338 xstats_names[idx_xstat].name,
339 xstats[idx_xstat].value);
346 nic_xstats_clear(portid_t port_id)
350 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
355 ret = rte_eth_xstats_reset(port_id);
358 "%s: Error: failed to reset xstats (port %u): %s\n",
359 __func__, port_id, strerror(-ret));
363 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
367 fprintf(stderr, "%s: Error: failed to get stats (port %u): %s",
368 __func__, port_id, strerror(ret));
374 get_queue_state_name(uint8_t queue_state)
376 if (queue_state == RTE_ETH_QUEUE_STATE_STOPPED)
378 else if (queue_state == RTE_ETH_QUEUE_STATE_STARTED)
380 else if (queue_state == RTE_ETH_QUEUE_STATE_HAIRPIN)
387 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
389 struct rte_eth_burst_mode mode;
390 struct rte_eth_rxq_info qinfo;
392 static const char *info_border = "*********************";
394 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
397 "Failed to retrieve information for port: %u, RX queue: %hu\nerror desc: %s(%d)\n",
398 port_id, queue_id, strerror(-rc), rc);
402 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
403 info_border, port_id, queue_id, info_border);
405 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
406 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
407 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
408 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
409 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
410 printf("\nRX drop packets: %s",
411 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
412 printf("\nRX deferred start: %s",
413 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
414 printf("\nRX scattered packets: %s",
415 (qinfo.scattered_rx != 0) ? "on" : "off");
416 printf("\nRx queue state: %s", get_queue_state_name(qinfo.queue_state));
417 if (qinfo.rx_buf_size != 0)
418 printf("\nRX buffer size: %hu", qinfo.rx_buf_size);
419 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
421 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
422 printf("\nBurst mode: %s%s",
424 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
425 " (per queue)" : "");
431 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
433 struct rte_eth_burst_mode mode;
434 struct rte_eth_txq_info qinfo;
436 static const char *info_border = "*********************";
438 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
441 "Failed to retrieve information for port: %u, TX queue: %hu\nerror desc: %s(%d)\n",
442 port_id, queue_id, strerror(-rc), rc);
446 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
447 info_border, port_id, queue_id, info_border);
449 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
450 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
451 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
452 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
453 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
454 printf("\nTX deferred start: %s",
455 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
456 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
457 printf("\nTx queue state: %s", get_queue_state_name(qinfo.queue_state));
459 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
460 printf("\nBurst mode: %s%s",
462 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
463 " (per queue)" : "");
468 static int bus_match_all(const struct rte_bus *bus, const void *data)
476 device_infos_display_speeds(uint32_t speed_capa)
478 printf("\n\tDevice speed capability:");
479 if (speed_capa == ETH_LINK_SPEED_AUTONEG)
480 printf(" Autonegotiate (all speeds)");
481 if (speed_capa & ETH_LINK_SPEED_FIXED)
482 printf(" Disable autonegotiate (fixed speed) ");
483 if (speed_capa & ETH_LINK_SPEED_10M_HD)
484 printf(" 10 Mbps half-duplex ");
485 if (speed_capa & ETH_LINK_SPEED_10M)
486 printf(" 10 Mbps full-duplex ");
487 if (speed_capa & ETH_LINK_SPEED_100M_HD)
488 printf(" 100 Mbps half-duplex ");
489 if (speed_capa & ETH_LINK_SPEED_100M)
490 printf(" 100 Mbps full-duplex ");
491 if (speed_capa & ETH_LINK_SPEED_1G)
493 if (speed_capa & ETH_LINK_SPEED_2_5G)
494 printf(" 2.5 Gbps ");
495 if (speed_capa & ETH_LINK_SPEED_5G)
497 if (speed_capa & ETH_LINK_SPEED_10G)
499 if (speed_capa & ETH_LINK_SPEED_20G)
501 if (speed_capa & ETH_LINK_SPEED_25G)
503 if (speed_capa & ETH_LINK_SPEED_40G)
505 if (speed_capa & ETH_LINK_SPEED_50G)
507 if (speed_capa & ETH_LINK_SPEED_56G)
509 if (speed_capa & ETH_LINK_SPEED_100G)
510 printf(" 100 Gbps ");
511 if (speed_capa & ETH_LINK_SPEED_200G)
512 printf(" 200 Gbps ");
516 device_infos_display(const char *identifier)
518 static const char *info_border = "*********************";
519 struct rte_bus *start = NULL, *next;
520 struct rte_dev_iterator dev_iter;
521 char name[RTE_ETH_NAME_MAX_LEN];
522 struct rte_ether_addr mac_addr;
523 struct rte_device *dev;
524 struct rte_devargs da;
526 struct rte_eth_dev_info dev_info;
529 memset(&da, 0, sizeof(da));
533 if (rte_devargs_parsef(&da, "%s", identifier)) {
534 fprintf(stderr, "cannot parse identifier\n");
539 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
542 if (identifier && da.bus != next)
545 /* Skip buses that don't have iterate method */
546 if (!next->dev_iterate)
549 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
550 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
554 /* Check for matching device if identifier is present */
556 strncmp(da.name, dev->name, strlen(dev->name)))
558 printf("\n%s Infos for device %s %s\n",
559 info_border, dev->name, info_border);
560 printf("Bus name: %s", dev->bus->name);
561 printf("\nDriver name: %s", dev->driver->name);
562 printf("\nDevargs: %s",
563 dev->devargs ? dev->devargs->args : "");
564 printf("\nConnect to socket: %d", dev->numa_node);
567 /* List ports with matching device name */
568 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
569 printf("\n\tPort id: %-2d", port_id);
570 if (eth_macaddr_get_print_err(port_id,
572 print_ethaddr("\n\tMAC address: ",
574 rte_eth_dev_get_name_by_port(port_id, name);
575 printf("\n\tDevice name: %s", name);
576 if (rte_eth_dev_info_get(port_id, &dev_info) == 0)
577 device_infos_display_speeds(dev_info.speed_capa);
582 rte_devargs_reset(&da);
586 port_infos_display(portid_t port_id)
588 struct rte_port *port;
589 struct rte_ether_addr mac_addr;
590 struct rte_eth_link link;
591 struct rte_eth_dev_info dev_info;
593 struct rte_mempool * mp;
594 static const char *info_border = "*********************";
596 char name[RTE_ETH_NAME_MAX_LEN];
598 char fw_version[ETHDEV_FWVERS_LEN];
600 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
604 port = &ports[port_id];
605 ret = eth_link_get_nowait_print_err(port_id, &link);
609 ret = eth_dev_info_get_print_err(port_id, &dev_info);
613 printf("\n%s Infos for port %-2d %s\n",
614 info_border, port_id, info_border);
615 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
616 print_ethaddr("MAC address: ", &mac_addr);
617 rte_eth_dev_get_name_by_port(port_id, name);
618 printf("\nDevice name: %s", name);
619 printf("\nDriver name: %s", dev_info.driver_name);
621 if (rte_eth_dev_fw_version_get(port_id, fw_version,
622 ETHDEV_FWVERS_LEN) == 0)
623 printf("\nFirmware-version: %s", fw_version);
625 printf("\nFirmware-version: %s", "not available");
627 if (dev_info.device->devargs && dev_info.device->devargs->args)
628 printf("\nDevargs: %s", dev_info.device->devargs->args);
629 printf("\nConnect to socket: %u", port->socket_id);
631 if (port_numa[port_id] != NUMA_NO_CONFIG) {
632 mp = mbuf_pool_find(port_numa[port_id], 0);
634 printf("\nmemory allocation on the socket: %d",
637 printf("\nmemory allocation on the socket: %u",port->socket_id);
639 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
640 printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
641 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
642 ("full-duplex") : ("half-duplex"));
643 printf("Autoneg status: %s\n", (link.link_autoneg == ETH_LINK_AUTONEG) ?
646 if (!rte_eth_dev_get_mtu(port_id, &mtu))
647 printf("MTU: %u\n", mtu);
649 printf("Promiscuous mode: %s\n",
650 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
651 printf("Allmulticast mode: %s\n",
652 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
653 printf("Maximum number of MAC addresses: %u\n",
654 (unsigned int)(port->dev_info.max_mac_addrs));
655 printf("Maximum number of MAC addresses of hash filtering: %u\n",
656 (unsigned int)(port->dev_info.max_hash_mac_addrs));
658 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
659 if (vlan_offload >= 0){
660 printf("VLAN offload: \n");
661 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
662 printf(" strip on, ");
664 printf(" strip off, ");
666 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
667 printf("filter on, ");
669 printf("filter off, ");
671 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
672 printf("extend on, ");
674 printf("extend off, ");
676 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
677 printf("qinq strip on\n");
679 printf("qinq strip off\n");
682 if (dev_info.hash_key_size > 0)
683 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
684 if (dev_info.reta_size > 0)
685 printf("Redirection table size: %u\n", dev_info.reta_size);
686 if (!dev_info.flow_type_rss_offloads)
687 printf("No RSS offload flow type is supported.\n");
692 printf("Supported RSS offload flow types:\n");
693 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
694 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
695 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
697 p = flowtype_to_str(i);
701 printf(" user defined %d\n", i);
705 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
706 printf("Maximum configurable length of RX packet: %u\n",
707 dev_info.max_rx_pktlen);
708 printf("Maximum configurable size of LRO aggregated packet: %u\n",
709 dev_info.max_lro_pkt_size);
710 if (dev_info.max_vfs)
711 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
712 if (dev_info.max_vmdq_pools)
713 printf("Maximum number of VMDq pools: %u\n",
714 dev_info.max_vmdq_pools);
716 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
717 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
718 printf("Max possible number of RXDs per queue: %hu\n",
719 dev_info.rx_desc_lim.nb_max);
720 printf("Min possible number of RXDs per queue: %hu\n",
721 dev_info.rx_desc_lim.nb_min);
722 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
724 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
725 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
726 printf("Max possible number of TXDs per queue: %hu\n",
727 dev_info.tx_desc_lim.nb_max);
728 printf("Min possible number of TXDs per queue: %hu\n",
729 dev_info.tx_desc_lim.nb_min);
730 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
731 printf("Max segment number per packet: %hu\n",
732 dev_info.tx_desc_lim.nb_seg_max);
733 printf("Max segment number per MTU/TSO: %hu\n",
734 dev_info.tx_desc_lim.nb_mtu_seg_max);
736 /* Show switch info only if valid switch domain and port id is set */
737 if (dev_info.switch_info.domain_id !=
738 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
739 if (dev_info.switch_info.name)
740 printf("Switch name: %s\n", dev_info.switch_info.name);
742 printf("Switch domain Id: %u\n",
743 dev_info.switch_info.domain_id);
744 printf("Switch Port Id: %u\n",
745 dev_info.switch_info.port_id);
750 port_summary_header_display(void)
752 uint16_t port_number;
754 port_number = rte_eth_dev_count_avail();
755 printf("Number of available ports: %i\n", port_number);
756 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
757 "Driver", "Status", "Link");
761 port_summary_display(portid_t port_id)
763 struct rte_ether_addr mac_addr;
764 struct rte_eth_link link;
765 struct rte_eth_dev_info dev_info;
766 char name[RTE_ETH_NAME_MAX_LEN];
769 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
774 ret = eth_link_get_nowait_print_err(port_id, &link);
778 ret = eth_dev_info_get_print_err(port_id, &dev_info);
782 rte_eth_dev_get_name_by_port(port_id, name);
783 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
787 printf("%-4d " RTE_ETHER_ADDR_PRT_FMT " %-12s %-14s %-8s %s\n",
788 port_id, RTE_ETHER_ADDR_BYTES(&mac_addr), name,
789 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
790 rte_eth_link_speed_to_str(link.link_speed));
794 port_eeprom_display(portid_t port_id)
796 struct rte_dev_eeprom_info einfo;
798 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
803 int len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
804 if (len_eeprom < 0) {
805 switch (len_eeprom) {
807 fprintf(stderr, "port index %d invalid\n", port_id);
810 fprintf(stderr, "operation not supported by device\n");
813 fprintf(stderr, "device is removed\n");
816 fprintf(stderr, "Unable to get EEPROM: %d\n",
823 char buf[len_eeprom];
825 einfo.length = len_eeprom;
828 ret = rte_eth_dev_get_eeprom(port_id, &einfo);
832 fprintf(stderr, "port index %d invalid\n", port_id);
835 fprintf(stderr, "operation not supported by device\n");
838 fprintf(stderr, "device is removed\n");
841 fprintf(stderr, "Unable to get EEPROM: %d\n", ret);
846 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
847 printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
851 port_module_eeprom_display(portid_t port_id)
853 struct rte_eth_dev_module_info minfo;
854 struct rte_dev_eeprom_info einfo;
857 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
863 ret = rte_eth_dev_get_module_info(port_id, &minfo);
867 fprintf(stderr, "port index %d invalid\n", port_id);
870 fprintf(stderr, "operation not supported by device\n");
873 fprintf(stderr, "device is removed\n");
876 fprintf(stderr, "Unable to get module EEPROM: %d\n",
883 char buf[minfo.eeprom_len];
885 einfo.length = minfo.eeprom_len;
888 ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
892 fprintf(stderr, "port index %d invalid\n", port_id);
895 fprintf(stderr, "operation not supported by device\n");
898 fprintf(stderr, "device is removed\n");
901 fprintf(stderr, "Unable to get module EEPROM: %d\n",
908 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
909 printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
913 port_id_is_invalid(portid_t port_id, enum print_warning warning)
917 if (port_id == (portid_t)RTE_PORT_ALL)
920 RTE_ETH_FOREACH_DEV(pid)
924 if (warning == ENABLED_WARN)
925 fprintf(stderr, "Invalid port %d\n", port_id);
930 void print_valid_ports(void)
934 printf("The valid ports array is [");
935 RTE_ETH_FOREACH_DEV(pid) {
942 vlan_id_is_invalid(uint16_t vlan_id)
946 fprintf(stderr, "Invalid vlan_id %d (must be < 4096)\n", vlan_id);
951 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
953 const struct rte_pci_device *pci_dev;
954 const struct rte_bus *bus;
959 "Port register offset 0x%X not aligned on a 4-byte boundary\n",
960 (unsigned int)reg_off);
964 if (!ports[port_id].dev_info.device) {
965 fprintf(stderr, "Invalid device\n");
969 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
970 if (bus && !strcmp(bus->name, "pci")) {
971 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
973 fprintf(stderr, "Not a PCI device\n");
977 pci_len = pci_dev->mem_resource[0].len;
978 if (reg_off >= pci_len) {
980 "Port %d: register offset %u (0x%X) out of port PCI resource (length=%"PRIu64")\n",
981 port_id, (unsigned int)reg_off, (unsigned int)reg_off,
989 reg_bit_pos_is_invalid(uint8_t bit_pos)
993 fprintf(stderr, "Invalid bit position %d (must be <= 31)\n", bit_pos);
997 #define display_port_and_reg_off(port_id, reg_off) \
998 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1001 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1003 display_port_and_reg_off(port_id, (unsigned)reg_off);
1004 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1008 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1013 if (port_id_is_invalid(port_id, ENABLED_WARN))
1015 if (port_reg_off_is_invalid(port_id, reg_off))
1017 if (reg_bit_pos_is_invalid(bit_x))
1019 reg_v = port_id_pci_reg_read(port_id, reg_off);
1020 display_port_and_reg_off(port_id, (unsigned)reg_off);
1021 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1025 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1026 uint8_t bit1_pos, uint8_t bit2_pos)
1032 if (port_id_is_invalid(port_id, ENABLED_WARN))
1034 if (port_reg_off_is_invalid(port_id, reg_off))
1036 if (reg_bit_pos_is_invalid(bit1_pos))
1038 if (reg_bit_pos_is_invalid(bit2_pos))
1040 if (bit1_pos > bit2_pos)
1041 l_bit = bit2_pos, h_bit = bit1_pos;
1043 l_bit = bit1_pos, h_bit = bit2_pos;
1045 reg_v = port_id_pci_reg_read(port_id, reg_off);
1048 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1049 display_port_and_reg_off(port_id, (unsigned)reg_off);
1050 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1051 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1055 port_reg_display(portid_t port_id, uint32_t reg_off)
1059 if (port_id_is_invalid(port_id, ENABLED_WARN))
1061 if (port_reg_off_is_invalid(port_id, reg_off))
1063 reg_v = port_id_pci_reg_read(port_id, reg_off);
1064 display_port_reg_value(port_id, reg_off, reg_v);
1068 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1073 if (port_id_is_invalid(port_id, ENABLED_WARN))
1075 if (port_reg_off_is_invalid(port_id, reg_off))
1077 if (reg_bit_pos_is_invalid(bit_pos))
1080 fprintf(stderr, "Invalid bit value %d (must be 0 or 1)\n",
1084 reg_v = port_id_pci_reg_read(port_id, reg_off);
1086 reg_v &= ~(1 << bit_pos);
1088 reg_v |= (1 << bit_pos);
1089 port_id_pci_reg_write(port_id, reg_off, reg_v);
1090 display_port_reg_value(port_id, reg_off, reg_v);
1094 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1095 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1102 if (port_id_is_invalid(port_id, ENABLED_WARN))
1104 if (port_reg_off_is_invalid(port_id, reg_off))
1106 if (reg_bit_pos_is_invalid(bit1_pos))
1108 if (reg_bit_pos_is_invalid(bit2_pos))
1110 if (bit1_pos > bit2_pos)
1111 l_bit = bit2_pos, h_bit = bit1_pos;
1113 l_bit = bit1_pos, h_bit = bit2_pos;
1115 if ((h_bit - l_bit) < 31)
1116 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1120 if (value > max_v) {
1121 fprintf(stderr, "Invalid value %u (0x%x) must be < %u (0x%x)\n",
1122 (unsigned)value, (unsigned)value,
1123 (unsigned)max_v, (unsigned)max_v);
1126 reg_v = port_id_pci_reg_read(port_id, reg_off);
1127 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1128 reg_v |= (value << l_bit); /* Set changed bits */
1129 port_id_pci_reg_write(port_id, reg_off, reg_v);
1130 display_port_reg_value(port_id, reg_off, reg_v);
1134 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1136 if (port_id_is_invalid(port_id, ENABLED_WARN))
1138 if (port_reg_off_is_invalid(port_id, reg_off))
1140 port_id_pci_reg_write(port_id, reg_off, reg_v);
1141 display_port_reg_value(port_id, reg_off, reg_v);
1145 port_mtu_set(portid_t port_id, uint16_t mtu)
1148 struct rte_port *rte_port = &ports[port_id];
1149 struct rte_eth_dev_info dev_info;
1150 uint16_t eth_overhead;
1153 if (port_id_is_invalid(port_id, ENABLED_WARN))
1156 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1160 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1162 "Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1163 mtu, dev_info.min_mtu, dev_info.max_mtu);
1166 diag = rte_eth_dev_set_mtu(port_id, mtu);
1168 fprintf(stderr, "Set MTU failed. diag=%d\n", diag);
1169 else if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1171 * Ether overhead in driver is equal to the difference of
1172 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1173 * device supports jumbo frame.
1175 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1176 if (mtu > RTE_ETHER_MTU) {
1177 rte_port->dev_conf.rxmode.offloads |=
1178 DEV_RX_OFFLOAD_JUMBO_FRAME;
1179 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1182 rte_port->dev_conf.rxmode.offloads &=
1183 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1187 /* Generic flow management functions. */
1189 static struct port_flow_tunnel *
1190 port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
1192 struct port_flow_tunnel *flow_tunnel;
1194 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1195 if (flow_tunnel->id == port_tunnel_id)
1205 port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
1208 switch (tunnel->type) {
1212 case RTE_FLOW_ITEM_TYPE_VXLAN:
1220 struct port_flow_tunnel *
1221 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
1223 struct rte_port *port = &ports[port_id];
1224 struct port_flow_tunnel *flow_tunnel;
1226 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1227 if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
1236 void port_flow_tunnel_list(portid_t port_id)
1238 struct rte_port *port = &ports[port_id];
1239 struct port_flow_tunnel *flt;
1241 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1242 printf("port %u tunnel #%u type=%s",
1243 port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
1244 if (flt->tunnel.tun_id)
1245 printf(" id=%" PRIu64, flt->tunnel.tun_id);
1250 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
1252 struct rte_port *port = &ports[port_id];
1253 struct port_flow_tunnel *flt;
1255 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1256 if (flt->id == tunnel_id)
1260 LIST_REMOVE(flt, chain);
1262 printf("port %u: flow tunnel #%u destroyed\n",
1263 port_id, tunnel_id);
1267 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
1269 struct rte_port *port = &ports[port_id];
1270 enum rte_flow_item_type type;
1271 struct port_flow_tunnel *flt;
1273 if (!strcmp(ops->type, "vxlan"))
1274 type = RTE_FLOW_ITEM_TYPE_VXLAN;
1276 fprintf(stderr, "cannot offload \"%s\" tunnel type\n",
1280 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1281 if (flt->tunnel.type == type)
1285 flt = calloc(1, sizeof(*flt));
1287 fprintf(stderr, "failed to allocate port flt object\n");
1290 flt->tunnel.type = type;
1291 flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
1292 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
1293 LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
1295 printf("port %d: flow tunnel #%u type %s\n",
1296 port_id, flt->id, ops->type);
1299 /** Generate a port_flow entry from attributes/pattern/actions. */
1300 static struct port_flow *
1301 port_flow_new(const struct rte_flow_attr *attr,
1302 const struct rte_flow_item *pattern,
1303 const struct rte_flow_action *actions,
1304 struct rte_flow_error *error)
1306 const struct rte_flow_conv_rule rule = {
1308 .pattern_ro = pattern,
1309 .actions_ro = actions,
1311 struct port_flow *pf;
1314 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1317 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1320 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1324 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1331 /** Print a message out of a flow error. */
1333 port_flow_complain(struct rte_flow_error *error)
1335 static const char *const errstrlist[] = {
1336 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1337 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1338 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1339 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1340 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1341 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1342 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1343 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1344 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1345 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1346 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1347 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1348 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1349 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1350 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1351 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1352 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1356 int err = rte_errno;
1358 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1359 !errstrlist[error->type])
1360 errstr = "unknown type";
1362 errstr = errstrlist[error->type];
1363 fprintf(stderr, "%s(): Caught PMD error type %d (%s): %s%s: %s\n",
1364 __func__, error->type, errstr,
1365 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1366 error->cause), buf) : "",
1367 error->message ? error->message : "(no stated reason)",
1373 rss_config_display(struct rte_flow_action_rss *rss_conf)
1377 if (rss_conf == NULL) {
1378 fprintf(stderr, "Invalid rule\n");
1384 if (rss_conf->queue_num == 0)
1386 for (i = 0; i < rss_conf->queue_num; i++)
1387 printf(" %d", rss_conf->queue[i]);
1390 printf(" function: ");
1391 switch (rss_conf->func) {
1392 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1393 printf("default\n");
1395 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1396 printf("toeplitz\n");
1398 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1399 printf("simple_xor\n");
1401 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1402 printf("symmetric_toeplitz\n");
1405 printf("Unknown function\n");
1409 printf(" types:\n");
1410 if (rss_conf->types == 0) {
1414 for (i = 0; rss_type_table[i].str; i++) {
1415 if ((rss_conf->types &
1416 rss_type_table[i].rss_type) ==
1417 rss_type_table[i].rss_type &&
1418 rss_type_table[i].rss_type != 0)
1419 printf(" %s\n", rss_type_table[i].str);
1423 static struct port_indirect_action *
1424 action_get_by_id(portid_t port_id, uint32_t id)
1426 struct rte_port *port;
1427 struct port_indirect_action **ppia;
1428 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 ppia = &port->actions_list;
1436 if ((*ppia)->id == id) {
1440 ppia = &(*ppia)->next;
1444 "Failed to find indirect action #%u on port %u\n",
1450 action_alloc(portid_t port_id, uint32_t id,
1451 struct port_indirect_action **action)
1453 struct rte_port *port;
1454 struct port_indirect_action **ppia;
1455 struct port_indirect_action *pia = NULL;
1458 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1459 port_id == (portid_t)RTE_PORT_ALL)
1461 port = &ports[port_id];
1462 if (id == UINT32_MAX) {
1463 /* taking first available ID */
1464 if (port->actions_list) {
1465 if (port->actions_list->id == UINT32_MAX - 1) {
1467 "Highest indirect action ID is already assigned, delete it first\n");
1470 id = port->actions_list->id + 1;
1475 pia = calloc(1, sizeof(*pia));
1478 "Allocation of port %u indirect action failed\n",
1482 ppia = &port->actions_list;
1483 while (*ppia && (*ppia)->id > id)
1484 ppia = &(*ppia)->next;
1485 if (*ppia && (*ppia)->id == id) {
1487 "Indirect action #%u is already assigned, delete it first\n",
1499 /** Create indirect action */
1501 port_action_handle_create(portid_t port_id, uint32_t id,
1502 const struct rte_flow_indir_action_conf *conf,
1503 const struct rte_flow_action *action)
1505 struct port_indirect_action *pia;
1507 struct rte_flow_error error;
1509 ret = action_alloc(port_id, id, &pia);
1512 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
1513 struct rte_flow_action_age *age =
1514 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
1516 pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
1517 age->context = &pia->age_type;
1518 } else if (action->type == RTE_FLOW_ACTION_TYPE_CONNTRACK) {
1519 struct rte_flow_action_conntrack *ct =
1520 (struct rte_flow_action_conntrack *)(uintptr_t)(action->conf);
1522 memcpy(ct, &conntrack_context, sizeof(*ct));
1524 /* Poisoning to make sure PMDs update it in case of error. */
1525 memset(&error, 0x22, sizeof(error));
1526 pia->handle = rte_flow_action_handle_create(port_id, conf, action,
1529 uint32_t destroy_id = pia->id;
1530 port_action_handle_destroy(port_id, 1, &destroy_id);
1531 return port_flow_complain(&error);
1533 pia->type = action->type;
1534 printf("Indirect action #%u created\n", pia->id);
1538 /** Destroy indirect action */
1540 port_action_handle_destroy(portid_t port_id,
1542 const uint32_t *actions)
1544 struct rte_port *port;
1545 struct port_indirect_action **tmp;
1549 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1550 port_id == (portid_t)RTE_PORT_ALL)
1552 port = &ports[port_id];
1553 tmp = &port->actions_list;
1557 for (i = 0; i != n; ++i) {
1558 struct rte_flow_error error;
1559 struct port_indirect_action *pia = *tmp;
1561 if (actions[i] != pia->id)
1564 * Poisoning to make sure PMDs update it in case
1567 memset(&error, 0x33, sizeof(error));
1569 if (pia->handle && rte_flow_action_handle_destroy(
1570 port_id, pia->handle, &error)) {
1571 ret = port_flow_complain(&error);
1575 printf("Indirect action #%u destroyed\n", pia->id);
1580 tmp = &(*tmp)->next;
1587 /** Get indirect action by port + id */
1588 struct rte_flow_action_handle *
1589 port_action_handle_get_by_id(portid_t port_id, uint32_t id)
1592 struct port_indirect_action *pia = action_get_by_id(port_id, id);
1594 return (pia) ? pia->handle : NULL;
1597 /** Update indirect action */
1599 port_action_handle_update(portid_t port_id, uint32_t id,
1600 const struct rte_flow_action *action)
1602 struct rte_flow_error error;
1603 struct rte_flow_action_handle *action_handle;
1604 struct port_indirect_action *pia;
1607 action_handle = port_action_handle_get_by_id(port_id, id);
1610 pia = action_get_by_id(port_id, id);
1613 switch (pia->type) {
1614 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1615 update = action->conf;
1621 if (rte_flow_action_handle_update(port_id, action_handle, update,
1623 return port_flow_complain(&error);
1625 printf("Indirect action #%u updated\n", id);
1630 port_action_handle_query(portid_t port_id, uint32_t id)
1632 struct rte_flow_error error;
1633 struct port_indirect_action *pia;
1635 struct rte_flow_query_count count;
1636 struct rte_flow_query_age age;
1637 struct rte_flow_action_conntrack ct;
1640 pia = action_get_by_id(port_id, id);
1643 switch (pia->type) {
1644 case RTE_FLOW_ACTION_TYPE_AGE:
1645 case RTE_FLOW_ACTION_TYPE_COUNT:
1649 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1650 id, pia->type, port_id);
1653 /* Poisoning to make sure PMDs update it in case of error. */
1654 memset(&error, 0x55, sizeof(error));
1655 memset(&query, 0, sizeof(query));
1656 if (rte_flow_action_handle_query(port_id, pia->handle, &query, &error))
1657 return port_flow_complain(&error);
1658 switch (pia->type) {
1659 case RTE_FLOW_ACTION_TYPE_AGE:
1660 printf("Indirect AGE action:\n"
1662 " sec_since_last_hit_valid: %u\n"
1663 " sec_since_last_hit: %" PRIu32 "\n",
1665 query.age.sec_since_last_hit_valid,
1666 query.age.sec_since_last_hit);
1668 case RTE_FLOW_ACTION_TYPE_COUNT:
1669 printf("Indirect COUNT action:\n"
1672 " hits: %" PRIu64 "\n"
1673 " bytes: %" PRIu64 "\n",
1674 query.count.hits_set,
1675 query.count.bytes_set,
1679 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1680 printf("Conntrack Context:\n"
1681 " Peer: %u, Flow dir: %s, Enable: %u\n"
1682 " Live: %u, SACK: %u, CACK: %u\n"
1683 " Packet dir: %s, Liberal: %u, State: %u\n"
1684 " Factor: %u, Retrans: %u, TCP flags: %u\n"
1685 " Last Seq: %u, Last ACK: %u\n"
1686 " Last Win: %u, Last End: %u\n",
1688 query.ct.is_original_dir ? "Original" : "Reply",
1689 query.ct.enable, query.ct.live_connection,
1690 query.ct.selective_ack, query.ct.challenge_ack_passed,
1691 query.ct.last_direction ? "Original" : "Reply",
1692 query.ct.liberal_mode, query.ct.state,
1693 query.ct.max_ack_window, query.ct.retransmission_limit,
1694 query.ct.last_index, query.ct.last_seq,
1695 query.ct.last_ack, query.ct.last_window,
1697 printf(" Original Dir:\n"
1698 " scale: %u, fin: %u, ack seen: %u\n"
1699 " unacked data: %u\n Sent end: %u,"
1700 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1701 query.ct.original_dir.scale,
1702 query.ct.original_dir.close_initiated,
1703 query.ct.original_dir.last_ack_seen,
1704 query.ct.original_dir.data_unacked,
1705 query.ct.original_dir.sent_end,
1706 query.ct.original_dir.reply_end,
1707 query.ct.original_dir.max_win,
1708 query.ct.original_dir.max_ack);
1709 printf(" Reply Dir:\n"
1710 " scale: %u, fin: %u, ack seen: %u\n"
1711 " unacked data: %u\n Sent end: %u,"
1712 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1713 query.ct.reply_dir.scale,
1714 query.ct.reply_dir.close_initiated,
1715 query.ct.reply_dir.last_ack_seen,
1716 query.ct.reply_dir.data_unacked,
1717 query.ct.reply_dir.sent_end,
1718 query.ct.reply_dir.reply_end,
1719 query.ct.reply_dir.max_win,
1720 query.ct.reply_dir.max_ack);
1724 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1725 id, pia->type, port_id);
1731 static struct port_flow_tunnel *
1732 port_flow_tunnel_offload_cmd_prep(portid_t port_id,
1733 const struct rte_flow_item *pattern,
1734 const struct rte_flow_action *actions,
1735 const struct tunnel_ops *tunnel_ops)
1738 struct rte_port *port;
1739 struct port_flow_tunnel *pft;
1740 struct rte_flow_error error;
1742 port = &ports[port_id];
1743 pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
1745 fprintf(stderr, "failed to locate port flow tunnel #%u\n",
1749 if (tunnel_ops->actions) {
1750 uint32_t num_actions;
1751 const struct rte_flow_action *aptr;
1753 ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
1755 &pft->num_pmd_actions,
1758 port_flow_complain(&error);
1761 for (aptr = actions, num_actions = 1;
1762 aptr->type != RTE_FLOW_ACTION_TYPE_END;
1763 aptr++, num_actions++);
1764 pft->actions = malloc(
1765 (num_actions + pft->num_pmd_actions) *
1766 sizeof(actions[0]));
1767 if (!pft->actions) {
1768 rte_flow_tunnel_action_decap_release(
1769 port_id, pft->actions,
1770 pft->num_pmd_actions, &error);
1773 rte_memcpy(pft->actions, pft->pmd_actions,
1774 pft->num_pmd_actions * sizeof(actions[0]));
1775 rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
1776 num_actions * sizeof(actions[0]));
1778 if (tunnel_ops->items) {
1780 const struct rte_flow_item *iptr;
1782 ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
1784 &pft->num_pmd_items,
1787 port_flow_complain(&error);
1790 for (iptr = pattern, num_items = 1;
1791 iptr->type != RTE_FLOW_ITEM_TYPE_END;
1792 iptr++, num_items++);
1793 pft->items = malloc((num_items + pft->num_pmd_items) *
1794 sizeof(pattern[0]));
1796 rte_flow_tunnel_item_release(
1797 port_id, pft->pmd_items,
1798 pft->num_pmd_items, &error);
1801 rte_memcpy(pft->items, pft->pmd_items,
1802 pft->num_pmd_items * sizeof(pattern[0]));
1803 rte_memcpy(pft->items + pft->num_pmd_items, pattern,
1804 num_items * sizeof(pattern[0]));
1811 port_flow_tunnel_offload_cmd_release(portid_t port_id,
1812 const struct tunnel_ops *tunnel_ops,
1813 struct port_flow_tunnel *pft)
1815 struct rte_flow_error error;
1817 if (tunnel_ops->actions) {
1819 rte_flow_tunnel_action_decap_release(
1820 port_id, pft->pmd_actions,
1821 pft->num_pmd_actions, &error);
1822 pft->actions = NULL;
1823 pft->pmd_actions = NULL;
1825 if (tunnel_ops->items) {
1827 rte_flow_tunnel_item_release(port_id, pft->pmd_items,
1831 pft->pmd_items = NULL;
1835 /** Add port meter policy */
1837 port_meter_policy_add(portid_t port_id, uint32_t policy_id,
1838 const struct rte_flow_action *actions)
1840 struct rte_mtr_error error;
1841 const struct rte_flow_action *act = actions;
1842 const struct rte_flow_action *start;
1843 struct rte_mtr_meter_policy_params policy;
1844 uint32_t i = 0, act_n;
1847 for (i = 0; i < RTE_COLORS; i++) {
1848 for (act_n = 0, start = act;
1849 act->type != RTE_FLOW_ACTION_TYPE_END; act++)
1851 if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
1852 policy.actions[i] = start;
1854 policy.actions[i] = NULL;
1857 ret = rte_mtr_meter_policy_add(port_id,
1861 print_mtr_err_msg(&error);
1865 /** Validate flow rule. */
1867 port_flow_validate(portid_t port_id,
1868 const struct rte_flow_attr *attr,
1869 const struct rte_flow_item *pattern,
1870 const struct rte_flow_action *actions,
1871 const struct tunnel_ops *tunnel_ops)
1873 struct rte_flow_error error;
1874 struct port_flow_tunnel *pft = NULL;
1876 /* Poisoning to make sure PMDs update it in case of error. */
1877 memset(&error, 0x11, sizeof(error));
1878 if (tunnel_ops->enabled) {
1879 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
1880 actions, tunnel_ops);
1884 pattern = pft->items;
1886 actions = pft->actions;
1888 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1889 return port_flow_complain(&error);
1890 if (tunnel_ops->enabled)
1891 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
1892 printf("Flow rule validated\n");
1896 /** Return age action structure if exists, otherwise NULL. */
1897 static struct rte_flow_action_age *
1898 age_action_get(const struct rte_flow_action *actions)
1900 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1901 switch (actions->type) {
1902 case RTE_FLOW_ACTION_TYPE_AGE:
1903 return (struct rte_flow_action_age *)
1904 (uintptr_t)actions->conf;
1912 /** Create flow rule. */
1914 port_flow_create(portid_t port_id,
1915 const struct rte_flow_attr *attr,
1916 const struct rte_flow_item *pattern,
1917 const struct rte_flow_action *actions,
1918 const struct tunnel_ops *tunnel_ops)
1920 struct rte_flow *flow;
1921 struct rte_port *port;
1922 struct port_flow *pf;
1924 struct rte_flow_error error;
1925 struct port_flow_tunnel *pft = NULL;
1926 struct rte_flow_action_age *age = age_action_get(actions);
1928 port = &ports[port_id];
1929 if (port->flow_list) {
1930 if (port->flow_list->id == UINT32_MAX) {
1932 "Highest rule ID is already assigned, delete it first");
1935 id = port->flow_list->id + 1;
1937 if (tunnel_ops->enabled) {
1938 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
1939 actions, tunnel_ops);
1943 pattern = pft->items;
1945 actions = pft->actions;
1947 pf = port_flow_new(attr, pattern, actions, &error);
1949 return port_flow_complain(&error);
1951 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
1952 age->context = &pf->age_type;
1954 /* Poisoning to make sure PMDs update it in case of error. */
1955 memset(&error, 0x22, sizeof(error));
1956 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1958 if (tunnel_ops->enabled)
1959 port_flow_tunnel_offload_cmd_release(port_id,
1962 return port_flow_complain(&error);
1964 pf->next = port->flow_list;
1967 port->flow_list = pf;
1968 if (tunnel_ops->enabled)
1969 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
1970 printf("Flow rule #%u created\n", pf->id);
1974 /** Destroy a number of flow rules. */
1976 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1978 struct rte_port *port;
1979 struct port_flow **tmp;
1983 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1984 port_id == (portid_t)RTE_PORT_ALL)
1986 port = &ports[port_id];
1987 tmp = &port->flow_list;
1991 for (i = 0; i != n; ++i) {
1992 struct rte_flow_error error;
1993 struct port_flow *pf = *tmp;
1995 if (rule[i] != pf->id)
1998 * Poisoning to make sure PMDs update it in case
2001 memset(&error, 0x33, sizeof(error));
2002 if (rte_flow_destroy(port_id, pf->flow, &error)) {
2003 ret = port_flow_complain(&error);
2006 printf("Flow rule #%u destroyed\n", pf->id);
2012 tmp = &(*tmp)->next;
2018 /** Remove all flow rules. */
2020 port_flow_flush(portid_t port_id)
2022 struct rte_flow_error error;
2023 struct rte_port *port;
2026 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2027 port_id == (portid_t)RTE_PORT_ALL)
2030 port = &ports[port_id];
2032 if (port->flow_list == NULL)
2035 /* Poisoning to make sure PMDs update it in case of error. */
2036 memset(&error, 0x44, sizeof(error));
2037 if (rte_flow_flush(port_id, &error)) {
2038 port_flow_complain(&error);
2041 while (port->flow_list) {
2042 struct port_flow *pf = port->flow_list->next;
2044 free(port->flow_list);
2045 port->flow_list = pf;
2050 /** Dump flow rules. */
2052 port_flow_dump(portid_t port_id, bool dump_all, uint32_t rule_id,
2053 const char *file_name)
2056 FILE *file = stdout;
2057 struct rte_flow_error error;
2058 struct rte_port *port;
2059 struct port_flow *pflow;
2060 struct rte_flow *tmpFlow = NULL;
2063 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2064 port_id == (portid_t)RTE_PORT_ALL)
2068 port = &ports[port_id];
2069 pflow = port->flow_list;
2071 if (rule_id != pflow->id) {
2072 pflow = pflow->next;
2074 tmpFlow = pflow->flow;
2080 if (found == false) {
2081 fprintf(stderr, "Failed to dump to flow %d\n", rule_id);
2086 if (file_name && strlen(file_name)) {
2087 file = fopen(file_name, "w");
2089 fprintf(stderr, "Failed to create file %s: %s\n",
2090 file_name, strerror(errno));
2096 ret = rte_flow_dev_dump(port_id, tmpFlow, file, &error);
2098 ret = rte_flow_dev_dump(port_id, NULL, file, &error);
2100 port_flow_complain(&error);
2101 fprintf(stderr, "Failed to dump flow: %s\n", strerror(-ret));
2103 printf("Flow dump finished\n");
2104 if (file_name && strlen(file_name))
2109 /** Query a flow rule. */
2111 port_flow_query(portid_t port_id, uint32_t rule,
2112 const struct rte_flow_action *action)
2114 struct rte_flow_error error;
2115 struct rte_port *port;
2116 struct port_flow *pf;
2119 struct rte_flow_query_count count;
2120 struct rte_flow_action_rss rss_conf;
2121 struct rte_flow_query_age age;
2125 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2126 port_id == (portid_t)RTE_PORT_ALL)
2128 port = &ports[port_id];
2129 for (pf = port->flow_list; pf; pf = pf->next)
2133 fprintf(stderr, "Flow rule #%u not found\n", rule);
2136 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2137 &name, sizeof(name),
2138 (void *)(uintptr_t)action->type, &error);
2140 return port_flow_complain(&error);
2141 switch (action->type) {
2142 case RTE_FLOW_ACTION_TYPE_COUNT:
2143 case RTE_FLOW_ACTION_TYPE_RSS:
2144 case RTE_FLOW_ACTION_TYPE_AGE:
2147 fprintf(stderr, "Cannot query action type %d (%s)\n",
2148 action->type, name);
2151 /* Poisoning to make sure PMDs update it in case of error. */
2152 memset(&error, 0x55, sizeof(error));
2153 memset(&query, 0, sizeof(query));
2154 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
2155 return port_flow_complain(&error);
2156 switch (action->type) {
2157 case RTE_FLOW_ACTION_TYPE_COUNT:
2161 " hits: %" PRIu64 "\n"
2162 " bytes: %" PRIu64 "\n",
2164 query.count.hits_set,
2165 query.count.bytes_set,
2169 case RTE_FLOW_ACTION_TYPE_RSS:
2170 rss_config_display(&query.rss_conf);
2172 case RTE_FLOW_ACTION_TYPE_AGE:
2175 " sec_since_last_hit_valid: %u\n"
2176 " sec_since_last_hit: %" PRIu32 "\n",
2179 query.age.sec_since_last_hit_valid,
2180 query.age.sec_since_last_hit);
2184 "Cannot display result for action type %d (%s)\n",
2185 action->type, name);
2191 /** List simply and destroy all aged flows. */
2193 port_flow_aged(portid_t port_id, uint8_t destroy)
2196 int nb_context, total = 0, idx;
2197 struct rte_flow_error error;
2198 enum age_action_context_type *type;
2200 struct port_flow *pf;
2201 struct port_indirect_action *pia;
2204 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2205 port_id == (portid_t)RTE_PORT_ALL)
2207 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
2208 printf("Port %u total aged flows: %d\n", port_id, total);
2210 port_flow_complain(&error);
2215 contexts = malloc(sizeof(void *) * total);
2216 if (contexts == NULL) {
2217 fprintf(stderr, "Cannot allocate contexts for aged flow\n");
2220 printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
2221 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
2222 if (nb_context != total) {
2224 "Port:%d get aged flows count(%d) != total(%d)\n",
2225 port_id, nb_context, total);
2230 for (idx = 0; idx < nb_context; idx++) {
2231 if (!contexts[idx]) {
2232 fprintf(stderr, "Error: get Null context in port %u\n",
2236 type = (enum age_action_context_type *)contexts[idx];
2238 case ACTION_AGE_CONTEXT_TYPE_FLOW:
2239 ctx.pf = container_of(type, struct port_flow, age_type);
2240 printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
2244 ctx.pf->rule.attr->group,
2245 ctx.pf->rule.attr->priority,
2246 ctx.pf->rule.attr->ingress ? 'i' : '-',
2247 ctx.pf->rule.attr->egress ? 'e' : '-',
2248 ctx.pf->rule.attr->transfer ? 't' : '-');
2249 if (destroy && !port_flow_destroy(port_id, 1,
2253 case ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION:
2254 ctx.pia = container_of(type,
2255 struct port_indirect_action, age_type);
2256 printf("%-20s\t%" PRIu32 "\n", "Indirect action",
2260 fprintf(stderr, "Error: invalid context type %u\n",
2265 printf("\n%d flows destroyed\n", total);
2269 /** List flow rules. */
2271 port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group)
2273 struct rte_port *port;
2274 struct port_flow *pf;
2275 struct port_flow *list = NULL;
2278 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2279 port_id == (portid_t)RTE_PORT_ALL)
2281 port = &ports[port_id];
2282 if (!port->flow_list)
2284 /* Sort flows by group, priority and ID. */
2285 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
2286 struct port_flow **tmp;
2287 const struct rte_flow_attr *curr = pf->rule.attr;
2290 /* Filter out unwanted groups. */
2291 for (i = 0; i != n; ++i)
2292 if (curr->group == group[i])
2297 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
2298 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
2300 if (curr->group > comp->group ||
2301 (curr->group == comp->group &&
2302 curr->priority > comp->priority) ||
2303 (curr->group == comp->group &&
2304 curr->priority == comp->priority &&
2305 pf->id > (*tmp)->id))
2312 printf("ID\tGroup\tPrio\tAttr\tRule\n");
2313 for (pf = list; pf != NULL; pf = pf->tmp) {
2314 const struct rte_flow_item *item = pf->rule.pattern;
2315 const struct rte_flow_action *action = pf->rule.actions;
2318 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
2320 pf->rule.attr->group,
2321 pf->rule.attr->priority,
2322 pf->rule.attr->ingress ? 'i' : '-',
2323 pf->rule.attr->egress ? 'e' : '-',
2324 pf->rule.attr->transfer ? 't' : '-');
2325 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
2326 if ((uint32_t)item->type > INT_MAX)
2327 name = "PMD_INTERNAL";
2328 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
2329 &name, sizeof(name),
2330 (void *)(uintptr_t)item->type,
2333 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
2334 printf("%s ", name);
2338 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
2339 if ((uint32_t)action->type > INT_MAX)
2340 name = "PMD_INTERNAL";
2341 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2342 &name, sizeof(name),
2343 (void *)(uintptr_t)action->type,
2346 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
2347 printf(" %s", name);
2354 /** Restrict ingress traffic to the defined flow rules. */
2356 port_flow_isolate(portid_t port_id, int set)
2358 struct rte_flow_error error;
2360 /* Poisoning to make sure PMDs update it in case of error. */
2361 memset(&error, 0x66, sizeof(error));
2362 if (rte_flow_isolate(port_id, set, &error))
2363 return port_flow_complain(&error);
2364 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
2366 set ? "now restricted" : "not restricted anymore");
2371 * RX/TX ring descriptors display functions.
2374 rx_queue_id_is_invalid(queueid_t rxq_id)
2376 if (rxq_id < nb_rxq)
2378 fprintf(stderr, "Invalid RX queue %d (must be < nb_rxq=%d)\n",
2384 tx_queue_id_is_invalid(queueid_t txq_id)
2386 if (txq_id < nb_txq)
2388 fprintf(stderr, "Invalid TX queue %d (must be < nb_txq=%d)\n",
2394 get_rx_ring_size(portid_t port_id, queueid_t rxq_id, uint16_t *ring_size)
2396 struct rte_port *port = &ports[port_id];
2397 struct rte_eth_rxq_info rx_qinfo;
2400 ret = rte_eth_rx_queue_info_get(port_id, rxq_id, &rx_qinfo);
2402 *ring_size = rx_qinfo.nb_desc;
2406 if (ret != -ENOTSUP)
2409 * If the rte_eth_rx_queue_info_get is not support for this PMD,
2410 * ring_size stored in testpmd will be used for validity verification.
2411 * When configure the rxq by rte_eth_rx_queue_setup with nb_rx_desc
2412 * being 0, it will use a default value provided by PMDs to setup this
2413 * rxq. If the default value is 0, it will use the
2414 * RTE_ETH_DEV_FALLBACK_RX_RINGSIZE to setup this rxq.
2416 if (port->nb_rx_desc[rxq_id])
2417 *ring_size = port->nb_rx_desc[rxq_id];
2418 else if (port->dev_info.default_rxportconf.ring_size)
2419 *ring_size = port->dev_info.default_rxportconf.ring_size;
2421 *ring_size = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
2426 get_tx_ring_size(portid_t port_id, queueid_t txq_id, uint16_t *ring_size)
2428 struct rte_port *port = &ports[port_id];
2429 struct rte_eth_txq_info tx_qinfo;
2432 ret = rte_eth_tx_queue_info_get(port_id, txq_id, &tx_qinfo);
2434 *ring_size = tx_qinfo.nb_desc;
2438 if (ret != -ENOTSUP)
2441 * If the rte_eth_tx_queue_info_get is not support for this PMD,
2442 * ring_size stored in testpmd will be used for validity verification.
2443 * When configure the txq by rte_eth_tx_queue_setup with nb_tx_desc
2444 * being 0, it will use a default value provided by PMDs to setup this
2445 * txq. If the default value is 0, it will use the
2446 * RTE_ETH_DEV_FALLBACK_TX_RINGSIZE to setup this txq.
2448 if (port->nb_tx_desc[txq_id])
2449 *ring_size = port->nb_tx_desc[txq_id];
2450 else if (port->dev_info.default_txportconf.ring_size)
2451 *ring_size = port->dev_info.default_txportconf.ring_size;
2453 *ring_size = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
2458 rx_desc_id_is_invalid(portid_t port_id, queueid_t rxq_id, uint16_t rxdesc_id)
2463 ret = get_rx_ring_size(port_id, rxq_id, &ring_size);
2467 if (rxdesc_id < ring_size)
2470 fprintf(stderr, "Invalid RX descriptor %u (must be < ring_size=%u)\n",
2471 rxdesc_id, ring_size);
2476 tx_desc_id_is_invalid(portid_t port_id, queueid_t txq_id, uint16_t txdesc_id)
2481 ret = get_tx_ring_size(port_id, txq_id, &ring_size);
2485 if (txdesc_id < ring_size)
2488 fprintf(stderr, "Invalid TX descriptor %u (must be < ring_size=%u)\n",
2489 txdesc_id, ring_size);
2493 static const struct rte_memzone *
2494 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
2496 char mz_name[RTE_MEMZONE_NAMESIZE];
2497 const struct rte_memzone *mz;
2499 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
2500 port_id, q_id, ring_name);
2501 mz = rte_memzone_lookup(mz_name);
2504 "%s ring memory zoneof (port %d, queue %d) not found (zone name = %s\n",
2505 ring_name, port_id, q_id, mz_name);
2509 union igb_ring_dword {
2512 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
2522 struct igb_ring_desc_32_bytes {
2523 union igb_ring_dword lo_dword;
2524 union igb_ring_dword hi_dword;
2525 union igb_ring_dword resv1;
2526 union igb_ring_dword resv2;
2529 struct igb_ring_desc_16_bytes {
2530 union igb_ring_dword lo_dword;
2531 union igb_ring_dword hi_dword;
2535 ring_rxd_display_dword(union igb_ring_dword dword)
2537 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
2538 (unsigned)dword.words.hi);
2542 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
2543 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2546 __rte_unused portid_t port_id,
2550 struct igb_ring_desc_16_bytes *ring =
2551 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2552 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2554 struct rte_eth_dev_info dev_info;
2556 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2560 if (strstr(dev_info.driver_name, "i40e") != NULL) {
2561 /* 32 bytes RX descriptor, i40e only */
2562 struct igb_ring_desc_32_bytes *ring =
2563 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
2564 ring[desc_id].lo_dword.dword =
2565 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2566 ring_rxd_display_dword(ring[desc_id].lo_dword);
2567 ring[desc_id].hi_dword.dword =
2568 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2569 ring_rxd_display_dword(ring[desc_id].hi_dword);
2570 ring[desc_id].resv1.dword =
2571 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
2572 ring_rxd_display_dword(ring[desc_id].resv1);
2573 ring[desc_id].resv2.dword =
2574 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
2575 ring_rxd_display_dword(ring[desc_id].resv2);
2580 /* 16 bytes RX descriptor */
2581 ring[desc_id].lo_dword.dword =
2582 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2583 ring_rxd_display_dword(ring[desc_id].lo_dword);
2584 ring[desc_id].hi_dword.dword =
2585 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2586 ring_rxd_display_dword(ring[desc_id].hi_dword);
2590 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
2592 struct igb_ring_desc_16_bytes *ring;
2593 struct igb_ring_desc_16_bytes txd;
2595 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2596 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2597 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2598 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
2599 (unsigned)txd.lo_dword.words.lo,
2600 (unsigned)txd.lo_dword.words.hi,
2601 (unsigned)txd.hi_dword.words.lo,
2602 (unsigned)txd.hi_dword.words.hi);
2606 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
2608 const struct rte_memzone *rx_mz;
2610 if (rx_desc_id_is_invalid(port_id, rxq_id, rxd_id))
2612 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
2615 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
2619 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
2621 const struct rte_memzone *tx_mz;
2623 if (tx_desc_id_is_invalid(port_id, txq_id, txd_id))
2625 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
2628 ring_tx_descriptor_display(tx_mz, txd_id);
2632 fwd_lcores_config_display(void)
2636 printf("List of forwarding lcores:");
2637 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
2638 printf(" %2u", fwd_lcores_cpuids[lc_id]);
2642 rxtx_config_display(void)
2647 printf(" %s packet forwarding%s packets/burst=%d\n",
2648 cur_fwd_eng->fwd_mode_name,
2649 retry_enabled == 0 ? "" : " with retry",
2652 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
2653 printf(" packet len=%u - nb packet segments=%d\n",
2654 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
2656 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
2657 nb_fwd_lcores, nb_fwd_ports);
2659 RTE_ETH_FOREACH_DEV(pid) {
2660 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
2661 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
2662 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
2663 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
2664 struct rte_eth_rxq_info rx_qinfo;
2665 struct rte_eth_txq_info tx_qinfo;
2666 uint16_t rx_free_thresh_tmp;
2667 uint16_t tx_free_thresh_tmp;
2668 uint16_t tx_rs_thresh_tmp;
2669 uint16_t nb_rx_desc_tmp;
2670 uint16_t nb_tx_desc_tmp;
2671 uint64_t offloads_tmp;
2672 uint8_t pthresh_tmp;
2673 uint8_t hthresh_tmp;
2674 uint8_t wthresh_tmp;
2677 /* per port config */
2678 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
2679 (unsigned int)pid, nb_rxq, nb_txq);
2681 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
2682 ports[pid].dev_conf.rxmode.offloads,
2683 ports[pid].dev_conf.txmode.offloads);
2685 /* per rx queue config only for first queue to be less verbose */
2686 for (qid = 0; qid < 1; qid++) {
2687 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
2689 nb_rx_desc_tmp = nb_rx_desc[qid];
2690 rx_free_thresh_tmp =
2691 rx_conf[qid].rx_free_thresh;
2692 pthresh_tmp = rx_conf[qid].rx_thresh.pthresh;
2693 hthresh_tmp = rx_conf[qid].rx_thresh.hthresh;
2694 wthresh_tmp = rx_conf[qid].rx_thresh.wthresh;
2695 offloads_tmp = rx_conf[qid].offloads;
2697 nb_rx_desc_tmp = rx_qinfo.nb_desc;
2698 rx_free_thresh_tmp =
2699 rx_qinfo.conf.rx_free_thresh;
2700 pthresh_tmp = rx_qinfo.conf.rx_thresh.pthresh;
2701 hthresh_tmp = rx_qinfo.conf.rx_thresh.hthresh;
2702 wthresh_tmp = rx_qinfo.conf.rx_thresh.wthresh;
2703 offloads_tmp = rx_qinfo.conf.offloads;
2706 printf(" RX queue: %d\n", qid);
2707 printf(" RX desc=%d - RX free threshold=%d\n",
2708 nb_rx_desc_tmp, rx_free_thresh_tmp);
2709 printf(" RX threshold registers: pthresh=%d hthresh=%d "
2711 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2712 printf(" RX Offloads=0x%"PRIx64"\n", offloads_tmp);
2715 /* per tx queue config only for first queue to be less verbose */
2716 for (qid = 0; qid < 1; qid++) {
2717 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
2719 nb_tx_desc_tmp = nb_tx_desc[qid];
2720 tx_free_thresh_tmp =
2721 tx_conf[qid].tx_free_thresh;
2722 pthresh_tmp = tx_conf[qid].tx_thresh.pthresh;
2723 hthresh_tmp = tx_conf[qid].tx_thresh.hthresh;
2724 wthresh_tmp = tx_conf[qid].tx_thresh.wthresh;
2725 offloads_tmp = tx_conf[qid].offloads;
2726 tx_rs_thresh_tmp = tx_conf[qid].tx_rs_thresh;
2728 nb_tx_desc_tmp = tx_qinfo.nb_desc;
2729 tx_free_thresh_tmp =
2730 tx_qinfo.conf.tx_free_thresh;
2731 pthresh_tmp = tx_qinfo.conf.tx_thresh.pthresh;
2732 hthresh_tmp = tx_qinfo.conf.tx_thresh.hthresh;
2733 wthresh_tmp = tx_qinfo.conf.tx_thresh.wthresh;
2734 offloads_tmp = tx_qinfo.conf.offloads;
2735 tx_rs_thresh_tmp = tx_qinfo.conf.tx_rs_thresh;
2738 printf(" TX queue: %d\n", qid);
2739 printf(" TX desc=%d - TX free threshold=%d\n",
2740 nb_tx_desc_tmp, tx_free_thresh_tmp);
2741 printf(" TX threshold registers: pthresh=%d hthresh=%d "
2743 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2744 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
2745 offloads_tmp, tx_rs_thresh_tmp);
2751 port_rss_reta_info(portid_t port_id,
2752 struct rte_eth_rss_reta_entry64 *reta_conf,
2753 uint16_t nb_entries)
2755 uint16_t i, idx, shift;
2758 if (port_id_is_invalid(port_id, ENABLED_WARN))
2761 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
2764 "Failed to get RSS RETA info, return code = %d\n",
2769 for (i = 0; i < nb_entries; i++) {
2770 idx = i / RTE_RETA_GROUP_SIZE;
2771 shift = i % RTE_RETA_GROUP_SIZE;
2772 if (!(reta_conf[idx].mask & (1ULL << shift)))
2774 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
2775 i, reta_conf[idx].reta[shift]);
2780 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
2784 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
2786 struct rte_eth_rss_conf rss_conf = {0};
2787 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
2791 struct rte_eth_dev_info dev_info;
2792 uint8_t hash_key_size;
2795 if (port_id_is_invalid(port_id, ENABLED_WARN))
2798 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2802 if (dev_info.hash_key_size > 0 &&
2803 dev_info.hash_key_size <= sizeof(rss_key))
2804 hash_key_size = dev_info.hash_key_size;
2807 "dev_info did not provide a valid hash key size\n");
2811 /* Get RSS hash key if asked to display it */
2812 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2813 rss_conf.rss_key_len = hash_key_size;
2814 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2818 fprintf(stderr, "port index %d invalid\n", port_id);
2821 fprintf(stderr, "operation not supported by device\n");
2824 fprintf(stderr, "operation failed - diag=%d\n", diag);
2829 rss_hf = rss_conf.rss_hf;
2831 printf("RSS disabled\n");
2834 printf("RSS functions:\n ");
2835 for (i = 0; rss_type_table[i].str; i++) {
2836 if (rss_hf & rss_type_table[i].rss_type)
2837 printf("%s ", rss_type_table[i].str);
2842 printf("RSS key:\n");
2843 for (i = 0; i < hash_key_size; i++)
2844 printf("%02X", rss_key[i]);
2849 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2850 uint8_t hash_key_len)
2852 struct rte_eth_rss_conf rss_conf;
2856 rss_conf.rss_key = NULL;
2857 rss_conf.rss_key_len = hash_key_len;
2858 rss_conf.rss_hf = 0;
2859 for (i = 0; rss_type_table[i].str; i++) {
2860 if (!strcmp(rss_type_table[i].str, rss_type))
2861 rss_conf.rss_hf = rss_type_table[i].rss_type;
2863 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2865 rss_conf.rss_key = hash_key;
2866 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2873 fprintf(stderr, "port index %d invalid\n", port_id);
2876 fprintf(stderr, "operation not supported by device\n");
2879 fprintf(stderr, "operation failed - diag=%d\n", diag);
2885 * Setup forwarding configuration for each logical core.
2888 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2890 streamid_t nb_fs_per_lcore;
2898 nb_fs = cfg->nb_fwd_streams;
2899 nb_fc = cfg->nb_fwd_lcores;
2900 if (nb_fs <= nb_fc) {
2901 nb_fs_per_lcore = 1;
2904 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2905 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2908 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2910 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2911 fwd_lcores[lc_id]->stream_idx = sm_id;
2912 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2913 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2917 * Assign extra remaining streams, if any.
2919 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2920 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2921 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2922 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2923 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2928 fwd_topology_tx_port_get(portid_t rxp)
2930 static int warning_once = 1;
2932 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2934 switch (port_topology) {
2936 case PORT_TOPOLOGY_PAIRED:
2937 if ((rxp & 0x1) == 0) {
2938 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2942 "\nWarning! port-topology=paired and odd forward ports number, the last port will pair with itself.\n\n");
2948 case PORT_TOPOLOGY_CHAINED:
2949 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2950 case PORT_TOPOLOGY_LOOP:
2956 simple_fwd_config_setup(void)
2960 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2961 cur_fwd_config.nb_fwd_streams =
2962 (streamid_t) cur_fwd_config.nb_fwd_ports;
2964 /* reinitialize forwarding streams */
2968 * In the simple forwarding test, the number of forwarding cores
2969 * must be lower or equal to the number of forwarding ports.
2971 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2972 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2973 cur_fwd_config.nb_fwd_lcores =
2974 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2975 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2977 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2978 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2979 fwd_streams[i]->rx_queue = 0;
2980 fwd_streams[i]->tx_port =
2981 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2982 fwd_streams[i]->tx_queue = 0;
2983 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2984 fwd_streams[i]->retry_enabled = retry_enabled;
2989 * For the RSS forwarding test all streams distributed over lcores. Each stream
2990 * being composed of a RX queue to poll on a RX port for input messages,
2991 * associated with a TX queue of a TX port where to send forwarded packets.
2994 rss_fwd_config_setup(void)
3007 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3008 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3009 cur_fwd_config.nb_fwd_streams =
3010 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
3012 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3013 cur_fwd_config.nb_fwd_lcores =
3014 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3016 /* reinitialize forwarding streams */
3019 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3021 if (proc_id > 0 && nb_q % num_procs != 0)
3022 printf("Warning! queue numbers should be multiple of processes, or packet loss will happen.\n");
3025 * In multi-process, All queues are allocated to different
3026 * processes based on num_procs and proc_id. For example:
3027 * if supports 4 queues(nb_q), 2 processes(num_procs),
3028 * the 0~1 queue for primary process.
3029 * the 2~3 queue for secondary process.
3031 start = proc_id * nb_q / num_procs;
3032 end = start + nb_q / num_procs;
3035 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
3036 struct fwd_stream *fs;
3038 fs = fwd_streams[sm_id];
3039 txp = fwd_topology_tx_port_get(rxp);
3040 fs->rx_port = fwd_ports_ids[rxp];
3042 fs->tx_port = fwd_ports_ids[txp];
3044 fs->peer_addr = fs->tx_port;
3045 fs->retry_enabled = retry_enabled;
3047 if (rxp < nb_fwd_ports)
3057 get_fwd_port_total_tc_num(void)
3059 struct rte_eth_dcb_info dcb_info;
3060 uint16_t total_tc_num = 0;
3063 for (i = 0; i < nb_fwd_ports; i++) {
3064 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[i], &dcb_info);
3065 total_tc_num += dcb_info.nb_tcs;
3068 return total_tc_num;
3072 * For the DCB forwarding test, each core is assigned on each traffic class.
3074 * Each core is assigned a multi-stream, each stream being composed of
3075 * a RX queue to poll on a RX port for input messages, associated with
3076 * a TX queue of a TX port where to send forwarded packets. All RX and
3077 * TX queues are mapping to the same traffic class.
3078 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
3082 dcb_fwd_config_setup(void)
3084 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
3085 portid_t txp, rxp = 0;
3086 queueid_t txq, rxq = 0;
3088 uint16_t nb_rx_queue, nb_tx_queue;
3089 uint16_t i, j, k, sm_id = 0;
3090 uint16_t total_tc_num;
3091 struct rte_port *port;
3097 * The fwd_config_setup() is called when the port is RTE_PORT_STARTED
3098 * or RTE_PORT_STOPPED.
3100 * Re-configure ports to get updated mapping between tc and queue in
3101 * case the queue number of the port is changed. Skip for started ports
3102 * since modifying queue number and calling dev_configure need to stop
3105 for (pid = 0; pid < nb_fwd_ports; pid++) {
3106 if (port_is_started(pid) == 1)
3110 ret = rte_eth_dev_configure(pid, nb_rxq, nb_txq,
3114 "Failed to re-configure port %d, ret = %d.\n",
3120 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3121 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3122 cur_fwd_config.nb_fwd_streams =
3123 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3124 total_tc_num = get_fwd_port_total_tc_num();
3125 if (cur_fwd_config.nb_fwd_lcores > total_tc_num)
3126 cur_fwd_config.nb_fwd_lcores = total_tc_num;
3128 /* reinitialize forwarding streams */
3132 /* get the dcb info on the first RX and TX ports */
3133 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3134 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3136 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3137 fwd_lcores[lc_id]->stream_nb = 0;
3138 fwd_lcores[lc_id]->stream_idx = sm_id;
3139 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
3140 /* if the nb_queue is zero, means this tc is
3141 * not enabled on the POOL
3143 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
3145 k = fwd_lcores[lc_id]->stream_nb +
3146 fwd_lcores[lc_id]->stream_idx;
3147 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
3148 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
3149 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3150 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
3151 for (j = 0; j < nb_rx_queue; j++) {
3152 struct fwd_stream *fs;
3154 fs = fwd_streams[k + j];
3155 fs->rx_port = fwd_ports_ids[rxp];
3156 fs->rx_queue = rxq + j;
3157 fs->tx_port = fwd_ports_ids[txp];
3158 fs->tx_queue = txq + j % nb_tx_queue;
3159 fs->peer_addr = fs->tx_port;
3160 fs->retry_enabled = retry_enabled;
3162 fwd_lcores[lc_id]->stream_nb +=
3163 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3165 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
3168 if (tc < rxp_dcb_info.nb_tcs)
3170 /* Restart from TC 0 on next RX port */
3172 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
3174 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
3177 if (rxp >= nb_fwd_ports)
3179 /* get the dcb information on next RX and TX ports */
3180 if ((rxp & 0x1) == 0)
3181 txp = (portid_t) (rxp + 1);
3183 txp = (portid_t) (rxp - 1);
3184 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3185 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3190 icmp_echo_config_setup(void)
3197 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
3198 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
3199 (nb_txq * nb_fwd_ports);
3201 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3202 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3203 cur_fwd_config.nb_fwd_streams =
3204 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3205 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3206 cur_fwd_config.nb_fwd_lcores =
3207 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3208 if (verbose_level > 0) {
3209 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
3211 cur_fwd_config.nb_fwd_lcores,
3212 cur_fwd_config.nb_fwd_ports,
3213 cur_fwd_config.nb_fwd_streams);
3216 /* reinitialize forwarding streams */
3218 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3220 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3221 if (verbose_level > 0)
3222 printf(" core=%d: \n", lc_id);
3223 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3224 struct fwd_stream *fs;
3225 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3226 fs->rx_port = fwd_ports_ids[rxp];
3228 fs->tx_port = fs->rx_port;
3230 fs->peer_addr = fs->tx_port;
3231 fs->retry_enabled = retry_enabled;
3232 if (verbose_level > 0)
3233 printf(" stream=%d port=%d rxq=%d txq=%d\n",
3234 sm_id, fs->rx_port, fs->rx_queue,
3236 rxq = (queueid_t) (rxq + 1);
3237 if (rxq == nb_rxq) {
3239 rxp = (portid_t) (rxp + 1);
3246 fwd_config_setup(void)
3248 struct rte_port *port;
3252 cur_fwd_config.fwd_eng = cur_fwd_eng;
3253 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
3254 icmp_echo_config_setup();
3258 if ((nb_rxq > 1) && (nb_txq > 1)){
3260 for (i = 0; i < nb_fwd_ports; i++) {
3261 pt_id = fwd_ports_ids[i];
3262 port = &ports[pt_id];
3263 if (!port->dcb_flag) {
3265 "In DCB mode, all forwarding ports must be configured in this mode.\n");
3269 if (nb_fwd_lcores == 1) {
3271 "In DCB mode,the nb forwarding cores should be larger than 1.\n");
3275 dcb_fwd_config_setup();
3277 rss_fwd_config_setup();
3280 simple_fwd_config_setup();
3284 mp_alloc_to_str(uint8_t mode)
3287 case MP_ALLOC_NATIVE:
3293 case MP_ALLOC_XMEM_HUGE:
3303 pkt_fwd_config_display(struct fwd_config *cfg)
3305 struct fwd_stream *fs;
3309 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
3310 "NUMA support %s, MP allocation mode: %s\n",
3311 cfg->fwd_eng->fwd_mode_name,
3312 retry_enabled == 0 ? "" : " with retry",
3313 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
3314 numa_support == 1 ? "enabled" : "disabled",
3315 mp_alloc_to_str(mp_alloc_type));
3318 printf("TX retry num: %u, delay between TX retries: %uus\n",
3319 burst_tx_retry_num, burst_tx_delay_time);
3320 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
3321 printf("Logical Core %u (socket %u) forwards packets on "
3323 fwd_lcores_cpuids[lc_id],
3324 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
3325 fwd_lcores[lc_id]->stream_nb);
3326 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3327 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3328 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
3329 "P=%d/Q=%d (socket %u) ",
3330 fs->rx_port, fs->rx_queue,
3331 ports[fs->rx_port].socket_id,
3332 fs->tx_port, fs->tx_queue,
3333 ports[fs->tx_port].socket_id);
3334 print_ethaddr("peer=",
3335 &peer_eth_addrs[fs->peer_addr]);
3343 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
3345 struct rte_ether_addr new_peer_addr;
3346 if (!rte_eth_dev_is_valid_port(port_id)) {
3347 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
3350 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
3351 fprintf(stderr, "Error: Invalid ethernet address: %s\n",
3355 peer_eth_addrs[port_id] = new_peer_addr;
3359 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
3362 unsigned int lcore_cpuid;
3367 for (i = 0; i < nb_lc; i++) {
3368 lcore_cpuid = lcorelist[i];
3369 if (! rte_lcore_is_enabled(lcore_cpuid)) {
3370 fprintf(stderr, "lcore %u not enabled\n", lcore_cpuid);
3373 if (lcore_cpuid == rte_get_main_lcore()) {
3375 "lcore %u cannot be masked on for running packet forwarding, which is the main lcore and reserved for command line parsing only\n",
3380 fwd_lcores_cpuids[i] = lcore_cpuid;
3382 if (record_now == 0) {
3386 nb_cfg_lcores = (lcoreid_t) nb_lc;
3387 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
3388 printf("previous number of forwarding cores %u - changed to "
3389 "number of configured cores %u\n",
3390 (unsigned int) nb_fwd_lcores, nb_lc);
3391 nb_fwd_lcores = (lcoreid_t) nb_lc;
3398 set_fwd_lcores_mask(uint64_t lcoremask)
3400 unsigned int lcorelist[64];
3404 if (lcoremask == 0) {
3405 fprintf(stderr, "Invalid NULL mask of cores\n");
3409 for (i = 0; i < 64; i++) {
3410 if (! ((uint64_t)(1ULL << i) & lcoremask))
3412 lcorelist[nb_lc++] = i;
3414 return set_fwd_lcores_list(lcorelist, nb_lc);
3418 set_fwd_lcores_number(uint16_t nb_lc)
3420 if (test_done == 0) {
3421 fprintf(stderr, "Please stop forwarding first\n");
3424 if (nb_lc > nb_cfg_lcores) {
3426 "nb fwd cores %u > %u (max. number of configured lcores) - ignored\n",
3427 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
3430 nb_fwd_lcores = (lcoreid_t) nb_lc;
3431 printf("Number of forwarding cores set to %u\n",
3432 (unsigned int) nb_fwd_lcores);
3436 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
3444 for (i = 0; i < nb_pt; i++) {
3445 port_id = (portid_t) portlist[i];
3446 if (port_id_is_invalid(port_id, ENABLED_WARN))
3449 fwd_ports_ids[i] = port_id;
3451 if (record_now == 0) {
3455 nb_cfg_ports = (portid_t) nb_pt;
3456 if (nb_fwd_ports != (portid_t) nb_pt) {
3457 printf("previous number of forwarding ports %u - changed to "
3458 "number of configured ports %u\n",
3459 (unsigned int) nb_fwd_ports, nb_pt);
3460 nb_fwd_ports = (portid_t) nb_pt;
3465 * Parse the user input and obtain the list of forwarding ports
3468 * String containing the user input. User can specify
3469 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
3470 * For example, if the user wants to use all the available
3471 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
3472 * If the user wants to use only the ports 1,2 then the input
3474 * valid characters are '-' and ','
3475 * @param[out] values
3476 * This array will be filled with a list of port IDs
3477 * based on the user input
3478 * Note that duplicate entries are discarded and only the first
3479 * count entries in this array are port IDs and all the rest
3480 * will contain default values
3481 * @param[in] maxsize
3482 * This parameter denotes 2 things
3483 * 1) Number of elements in the values array
3484 * 2) Maximum value of each element in the values array
3486 * On success, returns total count of parsed port IDs
3487 * On failure, returns 0
3490 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
3492 unsigned int count = 0;
3496 unsigned int marked[maxsize];
3498 if (list == NULL || values == NULL)
3501 for (i = 0; i < (int)maxsize; i++)
3507 /*Remove the blank spaces if any*/
3508 while (isblank(*list))
3513 value = strtol(list, &end, 10);
3514 if (errno || end == NULL)
3516 if (value < 0 || value >= (int)maxsize)
3518 while (isblank(*end))
3520 if (*end == '-' && min == INT_MAX) {
3522 } else if ((*end == ',') || (*end == '\0')) {
3526 for (i = min; i <= max; i++) {
3527 if (count < maxsize) {
3539 } while (*end != '\0');
3545 parse_fwd_portlist(const char *portlist)
3547 unsigned int portcount;
3548 unsigned int portindex[RTE_MAX_ETHPORTS];
3549 unsigned int i, valid_port_count = 0;
3551 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
3553 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
3556 * Here we verify the validity of the ports
3557 * and thereby calculate the total number of
3560 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
3561 if (rte_eth_dev_is_valid_port(portindex[i])) {
3562 portindex[valid_port_count] = portindex[i];
3567 set_fwd_ports_list(portindex, valid_port_count);
3571 set_fwd_ports_mask(uint64_t portmask)
3573 unsigned int portlist[64];
3577 if (portmask == 0) {
3578 fprintf(stderr, "Invalid NULL mask of ports\n");
3582 RTE_ETH_FOREACH_DEV(i) {
3583 if (! ((uint64_t)(1ULL << i) & portmask))
3585 portlist[nb_pt++] = i;
3587 set_fwd_ports_list(portlist, nb_pt);
3591 set_fwd_ports_number(uint16_t nb_pt)
3593 if (nb_pt > nb_cfg_ports) {
3595 "nb fwd ports %u > %u (number of configured ports) - ignored\n",
3596 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
3599 nb_fwd_ports = (portid_t) nb_pt;
3600 printf("Number of forwarding ports set to %u\n",
3601 (unsigned int) nb_fwd_ports);
3605 port_is_forwarding(portid_t port_id)
3609 if (port_id_is_invalid(port_id, ENABLED_WARN))
3612 for (i = 0; i < nb_fwd_ports; i++) {
3613 if (fwd_ports_ids[i] == port_id)
3621 set_nb_pkt_per_burst(uint16_t nb)
3623 if (nb > MAX_PKT_BURST) {
3625 "nb pkt per burst: %u > %u (maximum packet per burst) ignored\n",
3626 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
3629 nb_pkt_per_burst = nb;
3630 printf("Number of packets per burst set to %u\n",
3631 (unsigned int) nb_pkt_per_burst);
3635 tx_split_get_name(enum tx_pkt_split split)
3639 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3640 if (tx_split_name[i].split == split)
3641 return tx_split_name[i].name;
3647 set_tx_pkt_split(const char *name)
3651 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3652 if (strcmp(tx_split_name[i].name, name) == 0) {
3653 tx_pkt_split = tx_split_name[i].split;
3657 fprintf(stderr, "unknown value: \"%s\"\n", name);
3661 parse_fec_mode(const char *name, uint32_t *fec_capa)
3665 for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
3666 if (strcmp(fec_mode_name[i].name, name) == 0) {
3668 RTE_ETH_FEC_MODE_TO_CAPA(fec_mode_name[i].mode);
3676 show_fec_capability(unsigned int num, struct rte_eth_fec_capa *speed_fec_capa)
3680 printf("FEC capabilities:\n");
3682 for (i = 0; i < num; i++) {
3684 rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
3686 for (j = 0; j < RTE_DIM(fec_mode_name); j++) {
3687 if (RTE_ETH_FEC_MODE_TO_CAPA(j) &
3688 speed_fec_capa[i].capa)
3689 printf("%s ", fec_mode_name[j].name);
3696 show_rx_pkt_offsets(void)
3701 printf("Number of offsets: %u\n", n);
3703 printf("Segment offsets: ");
3704 for (i = 0; i != n - 1; i++)
3705 printf("%hu,", rx_pkt_seg_offsets[i]);
3706 printf("%hu\n", rx_pkt_seg_lengths[i]);
3711 set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs)
3715 if (nb_offs >= MAX_SEGS_BUFFER_SPLIT) {
3716 printf("nb segments per RX packets=%u >= "
3717 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_offs);
3722 * No extra check here, the segment length will be checked by PMD
3723 * in the extended queue setup.
3725 for (i = 0; i < nb_offs; i++) {
3726 if (seg_offsets[i] >= UINT16_MAX) {
3727 printf("offset[%u]=%u > UINT16_MAX - give up\n",
3733 for (i = 0; i < nb_offs; i++)
3734 rx_pkt_seg_offsets[i] = (uint16_t) seg_offsets[i];
3736 rx_pkt_nb_offs = (uint8_t) nb_offs;
3740 show_rx_pkt_segments(void)
3745 printf("Number of segments: %u\n", n);
3747 printf("Segment sizes: ");
3748 for (i = 0; i != n - 1; i++)
3749 printf("%hu,", rx_pkt_seg_lengths[i]);
3750 printf("%hu\n", rx_pkt_seg_lengths[i]);
3755 set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
3759 if (nb_segs >= MAX_SEGS_BUFFER_SPLIT) {
3760 printf("nb segments per RX packets=%u >= "
3761 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs);
3766 * No extra check here, the segment length will be checked by PMD
3767 * in the extended queue setup.
3769 for (i = 0; i < nb_segs; i++) {
3770 if (seg_lengths[i] >= UINT16_MAX) {
3771 printf("length[%u]=%u > UINT16_MAX - give up\n",
3777 for (i = 0; i < nb_segs; i++)
3778 rx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3780 rx_pkt_nb_segs = (uint8_t) nb_segs;
3784 show_tx_pkt_segments(void)
3790 split = tx_split_get_name(tx_pkt_split);
3792 printf("Number of segments: %u\n", n);
3793 printf("Segment sizes: ");
3794 for (i = 0; i != n - 1; i++)
3795 printf("%hu,", tx_pkt_seg_lengths[i]);
3796 printf("%hu\n", tx_pkt_seg_lengths[i]);
3797 printf("Split packet: %s\n", split);
3801 nb_segs_is_invalid(unsigned int nb_segs)
3808 RTE_ETH_FOREACH_DEV(port_id) {
3809 for (queue_id = 0; queue_id < nb_txq; queue_id++) {
3810 ret = get_tx_ring_size(port_id, queue_id, &ring_size);
3812 /* Port may not be initialized yet, can't say
3813 * the port is invalid in this stage.
3817 if (ring_size < nb_segs) {
3818 printf("nb segments per TX packets=%u >= TX "
3819 "queue(%u) ring_size=%u - txpkts ignored\n",
3820 nb_segs, queue_id, ring_size);
3830 set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
3832 uint16_t tx_pkt_len;
3836 * For single segment settings failed check is ignored.
3837 * It is a very basic capability to send the single segment
3838 * packets, suppose it is always supported.
3840 if (nb_segs > 1 && nb_segs_is_invalid(nb_segs)) {
3842 "Tx segment size(%u) is not supported - txpkts ignored\n",
3847 if (nb_segs > RTE_MAX_SEGS_PER_PKT) {
3849 "Tx segment size(%u) is bigger than max number of segment(%u)\n",
3850 nb_segs, RTE_MAX_SEGS_PER_PKT);
3855 * Check that each segment length is greater or equal than
3856 * the mbuf data size.
3857 * Check also that the total packet length is greater or equal than the
3858 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
3862 for (i = 0; i < nb_segs; i++) {
3863 if (seg_lengths[i] > mbuf_data_size[0]) {
3865 "length[%u]=%u > mbuf_data_size=%u - give up\n",
3866 i, seg_lengths[i], mbuf_data_size[0]);
3869 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
3871 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
3872 fprintf(stderr, "total packet length=%u < %d - give up\n",
3873 (unsigned) tx_pkt_len,
3874 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
3878 for (i = 0; i < nb_segs; i++)
3879 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3881 tx_pkt_length = tx_pkt_len;
3882 tx_pkt_nb_segs = (uint8_t) nb_segs;
3886 show_tx_pkt_times(void)
3888 printf("Interburst gap: %u\n", tx_pkt_times_inter);
3889 printf("Intraburst gap: %u\n", tx_pkt_times_intra);
3893 set_tx_pkt_times(unsigned int *tx_times)
3895 tx_pkt_times_inter = tx_times[0];
3896 tx_pkt_times_intra = tx_times[1];
3900 setup_gro(const char *onoff, portid_t port_id)
3902 if (!rte_eth_dev_is_valid_port(port_id)) {
3903 fprintf(stderr, "invalid port id %u\n", port_id);
3906 if (test_done == 0) {
3908 "Before enable/disable GRO, please stop forwarding first\n");
3911 if (strcmp(onoff, "on") == 0) {
3912 if (gro_ports[port_id].enable != 0) {
3914 "Port %u has enabled GRO. Please disable GRO first\n",
3918 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3919 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
3920 gro_ports[port_id].param.max_flow_num =
3921 GRO_DEFAULT_FLOW_NUM;
3922 gro_ports[port_id].param.max_item_per_flow =
3923 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
3925 gro_ports[port_id].enable = 1;
3927 if (gro_ports[port_id].enable == 0) {
3928 fprintf(stderr, "Port %u has disabled GRO\n", port_id);
3931 gro_ports[port_id].enable = 0;
3936 setup_gro_flush_cycles(uint8_t cycles)
3938 if (test_done == 0) {
3940 "Before change flush interval for GRO, please stop forwarding first.\n");
3944 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
3945 GRO_DEFAULT_FLUSH_CYCLES) {
3947 "The flushing cycle be in the range of 1 to %u. Revert to the default value %u.\n",
3948 GRO_MAX_FLUSH_CYCLES, GRO_DEFAULT_FLUSH_CYCLES);
3949 cycles = GRO_DEFAULT_FLUSH_CYCLES;
3952 gro_flush_cycles = cycles;
3956 show_gro(portid_t port_id)
3958 struct rte_gro_param *param;
3959 uint32_t max_pkts_num;
3961 param = &gro_ports[port_id].param;
3963 if (!rte_eth_dev_is_valid_port(port_id)) {
3964 fprintf(stderr, "Invalid port id %u.\n", port_id);
3967 if (gro_ports[port_id].enable) {
3968 printf("GRO type: TCP/IPv4\n");
3969 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3970 max_pkts_num = param->max_flow_num *
3971 param->max_item_per_flow;
3973 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
3974 printf("Max number of packets to perform GRO: %u\n",
3976 printf("Flushing cycles: %u\n", gro_flush_cycles);
3978 printf("Port %u doesn't enable GRO.\n", port_id);
3982 setup_gso(const char *mode, portid_t port_id)
3984 if (!rte_eth_dev_is_valid_port(port_id)) {
3985 fprintf(stderr, "invalid port id %u\n", port_id);
3988 if (strcmp(mode, "on") == 0) {
3989 if (test_done == 0) {
3991 "before enabling GSO, please stop forwarding first\n");
3994 gso_ports[port_id].enable = 1;
3995 } else if (strcmp(mode, "off") == 0) {
3996 if (test_done == 0) {
3998 "before disabling GSO, please stop forwarding first\n");
4001 gso_ports[port_id].enable = 0;
4006 list_pkt_forwarding_modes(void)
4008 static char fwd_modes[128] = "";
4009 const char *separator = "|";
4010 struct fwd_engine *fwd_eng;
4013 if (strlen (fwd_modes) == 0) {
4014 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4015 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4016 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4017 strncat(fwd_modes, separator,
4018 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4020 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4027 list_pkt_forwarding_retry_modes(void)
4029 static char fwd_modes[128] = "";
4030 const char *separator = "|";
4031 struct fwd_engine *fwd_eng;
4034 if (strlen(fwd_modes) == 0) {
4035 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4036 if (fwd_eng == &rx_only_engine)
4038 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4040 strlen(fwd_modes) - 1);
4041 strncat(fwd_modes, separator,
4043 strlen(fwd_modes) - 1);
4045 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4052 set_pkt_forwarding_mode(const char *fwd_mode_name)
4054 struct fwd_engine *fwd_eng;
4058 while ((fwd_eng = fwd_engines[i]) != NULL) {
4059 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
4060 printf("Set %s packet forwarding mode%s\n",
4062 retry_enabled == 0 ? "" : " with retry");
4063 cur_fwd_eng = fwd_eng;
4068 fprintf(stderr, "Invalid %s packet forwarding mode\n", fwd_mode_name);
4072 add_rx_dump_callbacks(portid_t portid)
4074 struct rte_eth_dev_info dev_info;
4078 if (port_id_is_invalid(portid, ENABLED_WARN))
4081 ret = eth_dev_info_get_print_err(portid, &dev_info);
4085 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4086 if (!ports[portid].rx_dump_cb[queue])
4087 ports[portid].rx_dump_cb[queue] =
4088 rte_eth_add_rx_callback(portid, queue,
4089 dump_rx_pkts, NULL);
4093 add_tx_dump_callbacks(portid_t portid)
4095 struct rte_eth_dev_info dev_info;
4099 if (port_id_is_invalid(portid, ENABLED_WARN))
4102 ret = eth_dev_info_get_print_err(portid, &dev_info);
4106 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4107 if (!ports[portid].tx_dump_cb[queue])
4108 ports[portid].tx_dump_cb[queue] =
4109 rte_eth_add_tx_callback(portid, queue,
4110 dump_tx_pkts, NULL);
4114 remove_rx_dump_callbacks(portid_t portid)
4116 struct rte_eth_dev_info dev_info;
4120 if (port_id_is_invalid(portid, ENABLED_WARN))
4123 ret = eth_dev_info_get_print_err(portid, &dev_info);
4127 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4128 if (ports[portid].rx_dump_cb[queue]) {
4129 rte_eth_remove_rx_callback(portid, queue,
4130 ports[portid].rx_dump_cb[queue]);
4131 ports[portid].rx_dump_cb[queue] = NULL;
4136 remove_tx_dump_callbacks(portid_t portid)
4138 struct rte_eth_dev_info dev_info;
4142 if (port_id_is_invalid(portid, ENABLED_WARN))
4145 ret = eth_dev_info_get_print_err(portid, &dev_info);
4149 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4150 if (ports[portid].tx_dump_cb[queue]) {
4151 rte_eth_remove_tx_callback(portid, queue,
4152 ports[portid].tx_dump_cb[queue]);
4153 ports[portid].tx_dump_cb[queue] = NULL;
4158 configure_rxtx_dump_callbacks(uint16_t verbose)
4162 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4163 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
4167 RTE_ETH_FOREACH_DEV(portid)
4169 if (verbose == 1 || verbose > 2)
4170 add_rx_dump_callbacks(portid);
4172 remove_rx_dump_callbacks(portid);
4174 add_tx_dump_callbacks(portid);
4176 remove_tx_dump_callbacks(portid);
4181 set_verbose_level(uint16_t vb_level)
4183 printf("Change verbose level from %u to %u\n",
4184 (unsigned int) verbose_level, (unsigned int) vb_level);
4185 verbose_level = vb_level;
4186 configure_rxtx_dump_callbacks(verbose_level);
4190 vlan_extend_set(portid_t port_id, int on)
4194 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4196 if (port_id_is_invalid(port_id, ENABLED_WARN))
4199 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4202 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
4203 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
4205 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
4206 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
4209 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4212 "rx_vlan_extend_set(port_pi=%d, on=%d) failed diag=%d\n",
4216 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4220 rx_vlan_strip_set(portid_t port_id, int on)
4224 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4226 if (port_id_is_invalid(port_id, ENABLED_WARN))
4229 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4232 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
4233 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
4235 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
4236 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
4239 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4242 "%s(port_pi=%d, on=%d) failed diag=%d\n",
4243 __func__, port_id, on, diag);
4246 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4250 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
4254 if (port_id_is_invalid(port_id, ENABLED_WARN))
4257 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
4260 "%s(port_pi=%d, queue_id=%d, on=%d) failed diag=%d\n",
4261 __func__, port_id, queue_id, on, diag);
4265 rx_vlan_filter_set(portid_t port_id, int on)
4269 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4271 if (port_id_is_invalid(port_id, ENABLED_WARN))
4274 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4277 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
4278 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
4280 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
4281 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
4284 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4287 "%s(port_pi=%d, on=%d) failed diag=%d\n",
4288 __func__, port_id, on, diag);
4291 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4295 rx_vlan_qinq_strip_set(portid_t port_id, int on)
4299 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4301 if (port_id_is_invalid(port_id, ENABLED_WARN))
4304 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4307 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
4308 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
4310 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
4311 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
4314 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4316 fprintf(stderr, "%s(port_pi=%d, on=%d) failed diag=%d\n",
4317 __func__, port_id, on, diag);
4320 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4324 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
4328 if (port_id_is_invalid(port_id, ENABLED_WARN))
4330 if (vlan_id_is_invalid(vlan_id))
4332 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
4336 "rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed diag=%d\n",
4337 port_id, vlan_id, on, diag);
4342 rx_vlan_all_filter_set(portid_t port_id, int on)
4346 if (port_id_is_invalid(port_id, ENABLED_WARN))
4348 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
4349 if (rx_vft_set(port_id, vlan_id, on))
4355 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
4359 if (port_id_is_invalid(port_id, ENABLED_WARN))
4362 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
4367 "tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed diag=%d\n",
4368 port_id, vlan_type, tp_id, diag);
4372 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
4374 struct rte_eth_dev_info dev_info;
4377 if (vlan_id_is_invalid(vlan_id))
4380 if (ports[port_id].dev_conf.txmode.offloads &
4381 DEV_TX_OFFLOAD_QINQ_INSERT) {
4382 fprintf(stderr, "Error, as QinQ has been enabled.\n");
4386 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4390 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
4392 "Error: vlan insert is not supported by port %d\n",
4397 tx_vlan_reset(port_id);
4398 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
4399 ports[port_id].tx_vlan_id = vlan_id;
4403 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
4405 struct rte_eth_dev_info dev_info;
4408 if (vlan_id_is_invalid(vlan_id))
4410 if (vlan_id_is_invalid(vlan_id_outer))
4413 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4417 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
4419 "Error: qinq insert not supported by port %d\n",
4424 tx_vlan_reset(port_id);
4425 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
4426 DEV_TX_OFFLOAD_QINQ_INSERT);
4427 ports[port_id].tx_vlan_id = vlan_id;
4428 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
4432 tx_vlan_reset(portid_t port_id)
4434 ports[port_id].dev_conf.txmode.offloads &=
4435 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
4436 DEV_TX_OFFLOAD_QINQ_INSERT);
4437 ports[port_id].tx_vlan_id = 0;
4438 ports[port_id].tx_vlan_id_outer = 0;
4442 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
4444 if (port_id_is_invalid(port_id, ENABLED_WARN))
4447 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
4451 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
4455 if (port_id_is_invalid(port_id, ENABLED_WARN))
4458 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
4461 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
4462 fprintf(stderr, "map_value not in required range 0..%d\n",
4463 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
4467 if (!is_rx) { /* tx */
4468 ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, queue_id,
4472 "failed to set tx queue stats mapping.\n");
4476 ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, queue_id,
4480 "failed to set rx queue stats mapping.\n");
4487 set_xstats_hide_zero(uint8_t on_off)
4489 xstats_hide_zero = on_off;
4493 set_record_core_cycles(uint8_t on_off)
4495 record_core_cycles = on_off;
4499 set_record_burst_stats(uint8_t on_off)
4501 record_burst_stats = on_off;
4505 flowtype_to_str(uint16_t flow_type)
4507 struct flow_type_info {
4513 static struct flow_type_info flowtype_str_table[] = {
4514 {"raw", RTE_ETH_FLOW_RAW},
4515 {"ipv4", RTE_ETH_FLOW_IPV4},
4516 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
4517 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
4518 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
4519 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
4520 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
4521 {"ipv6", RTE_ETH_FLOW_IPV6},
4522 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
4523 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
4524 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
4525 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
4526 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
4527 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
4528 {"port", RTE_ETH_FLOW_PORT},
4529 {"vxlan", RTE_ETH_FLOW_VXLAN},
4530 {"geneve", RTE_ETH_FLOW_GENEVE},
4531 {"nvgre", RTE_ETH_FLOW_NVGRE},
4532 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
4535 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
4536 if (flowtype_str_table[i].ftype == flow_type)
4537 return flowtype_str_table[i].str;
4543 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
4546 print_fdir_mask(struct rte_eth_fdir_masks *mask)
4548 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
4550 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4551 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
4552 " tunnel_id: 0x%08x",
4553 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
4554 rte_be_to_cpu_32(mask->tunnel_id_mask));
4555 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
4556 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
4557 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
4558 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
4560 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
4561 rte_be_to_cpu_16(mask->src_port_mask),
4562 rte_be_to_cpu_16(mask->dst_port_mask));
4564 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4565 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
4566 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
4567 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
4568 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
4570 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4571 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
4572 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
4573 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
4574 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
4581 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4583 struct rte_eth_flex_payload_cfg *cfg;
4586 for (i = 0; i < flex_conf->nb_payloads; i++) {
4587 cfg = &flex_conf->flex_set[i];
4588 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
4590 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
4591 printf("\n L2_PAYLOAD: ");
4592 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
4593 printf("\n L3_PAYLOAD: ");
4594 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
4595 printf("\n L4_PAYLOAD: ");
4597 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
4598 for (j = 0; j < num; j++)
4599 printf(" %-5u", cfg->src_offset[j]);
4605 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4607 struct rte_eth_fdir_flex_mask *mask;
4611 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
4612 mask = &flex_conf->flex_mask[i];
4613 p = flowtype_to_str(mask->flow_type);
4614 printf("\n %s:\t", p ? p : "unknown");
4615 for (j = 0; j < num; j++)
4616 printf(" %02x", mask->mask[j]);
4622 print_fdir_flow_type(uint32_t flow_types_mask)
4627 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
4628 if (!(flow_types_mask & (1 << i)))
4630 p = flowtype_to_str(i);
4640 get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info,
4641 struct rte_eth_fdir_stats *fdir_stat)
4646 if (ret == -ENOTSUP) {
4647 ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info);
4649 ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat);
4652 #ifdef RTE_NET_IXGBE
4653 if (ret == -ENOTSUP) {
4654 ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info);
4656 ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat);
4663 fprintf(stderr, "\n FDIR is not supported on port %-2d\n",
4667 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
4674 fdir_get_infos(portid_t port_id)
4676 struct rte_eth_fdir_stats fdir_stat;
4677 struct rte_eth_fdir_info fdir_info;
4679 static const char *fdir_stats_border = "########################";
4681 if (port_id_is_invalid(port_id, ENABLED_WARN))
4684 memset(&fdir_info, 0, sizeof(fdir_info));
4685 memset(&fdir_stat, 0, sizeof(fdir_stat));
4686 if (get_fdir_info(port_id, &fdir_info, &fdir_stat))
4689 printf("\n %s FDIR infos for port %-2d %s\n",
4690 fdir_stats_border, port_id, fdir_stats_border);
4692 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
4693 printf(" PERFECT\n");
4694 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
4695 printf(" PERFECT-MAC-VLAN\n");
4696 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4697 printf(" PERFECT-TUNNEL\n");
4698 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
4699 printf(" SIGNATURE\n");
4701 printf(" DISABLE\n");
4702 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
4703 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
4704 printf(" SUPPORTED FLOW TYPE: ");
4705 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
4707 printf(" FLEX PAYLOAD INFO:\n");
4708 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
4709 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
4710 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
4711 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
4712 fdir_info.flex_payload_unit,
4713 fdir_info.max_flex_payload_segment_num,
4714 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
4716 print_fdir_mask(&fdir_info.mask);
4717 if (fdir_info.flex_conf.nb_payloads > 0) {
4718 printf(" FLEX PAYLOAD SRC OFFSET:");
4719 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4721 if (fdir_info.flex_conf.nb_flexmasks > 0) {
4722 printf(" FLEX MASK CFG:");
4723 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4725 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
4726 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
4727 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
4728 fdir_info.guarant_spc, fdir_info.best_spc);
4729 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
4730 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
4731 " add: %-10"PRIu64" remove: %"PRIu64"\n"
4732 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
4733 fdir_stat.collision, fdir_stat.free,
4734 fdir_stat.maxhash, fdir_stat.maxlen,
4735 fdir_stat.add, fdir_stat.remove,
4736 fdir_stat.f_add, fdir_stat.f_remove);
4737 printf(" %s############################%s\n",
4738 fdir_stats_border, fdir_stats_border);
4741 #endif /* RTE_NET_I40E || RTE_NET_IXGBE */
4744 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
4746 struct rte_port *port;
4747 struct rte_eth_fdir_flex_conf *flex_conf;
4750 port = &ports[port_id];
4751 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
4752 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
4753 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
4758 if (i >= RTE_ETH_FLOW_MAX) {
4759 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
4760 idx = flex_conf->nb_flexmasks;
4761 flex_conf->nb_flexmasks++;
4764 "The flex mask table is full. Can not set flex mask for flow_type(%u).",
4769 rte_memcpy(&flex_conf->flex_mask[idx],
4771 sizeof(struct rte_eth_fdir_flex_mask));
4775 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
4777 struct rte_port *port;
4778 struct rte_eth_fdir_flex_conf *flex_conf;
4781 port = &ports[port_id];
4782 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
4783 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
4784 if (cfg->type == flex_conf->flex_set[i].type) {
4789 if (i >= RTE_ETH_PAYLOAD_MAX) {
4790 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
4791 idx = flex_conf->nb_payloads;
4792 flex_conf->nb_payloads++;
4795 "The flex payload table is full. Can not set flex payload for type(%u).",
4800 rte_memcpy(&flex_conf->flex_set[idx],
4802 sizeof(struct rte_eth_flex_payload_cfg));
4807 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
4809 #ifdef RTE_NET_IXGBE
4813 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
4815 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
4820 "rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
4821 is_rx ? "rx" : "tx", port_id, diag);
4824 fprintf(stderr, "VF %s setting not supported for port %d\n",
4825 is_rx ? "Rx" : "Tx", port_id);
4831 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
4834 struct rte_eth_link link;
4837 if (port_id_is_invalid(port_id, ENABLED_WARN))
4839 ret = eth_link_get_nowait_print_err(port_id, &link);
4842 if (link.link_speed != ETH_SPEED_NUM_UNKNOWN &&
4843 rate > link.link_speed) {
4845 "Invalid rate value:%u bigger than link speed: %u\n",
4846 rate, link.link_speed);
4849 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
4853 "rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
4859 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
4861 int diag = -ENOTSUP;
4865 RTE_SET_USED(q_msk);
4867 #ifdef RTE_NET_IXGBE
4868 if (diag == -ENOTSUP)
4869 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
4873 if (diag == -ENOTSUP)
4874 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
4880 "%s for port_id=%d failed diag=%d\n",
4881 __func__, port_id, diag);
4886 * Functions to manage the set of filtered Multicast MAC addresses.
4888 * A pool of filtered multicast MAC addresses is associated with each port.
4889 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
4890 * The address of the pool and the number of valid multicast MAC addresses
4891 * recorded in the pool are stored in the fields "mc_addr_pool" and
4892 * "mc_addr_nb" of the "rte_port" data structure.
4894 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
4895 * to be supplied a contiguous array of multicast MAC addresses.
4896 * To comply with this constraint, the set of multicast addresses recorded
4897 * into the pool are systematically compacted at the beginning of the pool.
4898 * Hence, when a multicast address is removed from the pool, all following
4899 * addresses, if any, are copied back to keep the set contiguous.
4901 #define MCAST_POOL_INC 32
4904 mcast_addr_pool_extend(struct rte_port *port)
4906 struct rte_ether_addr *mc_pool;
4907 size_t mc_pool_size;
4910 * If a free entry is available at the end of the pool, just
4911 * increment the number of recorded multicast addresses.
4913 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
4919 * [re]allocate a pool with MCAST_POOL_INC more entries.
4920 * The previous test guarantees that port->mc_addr_nb is a multiple
4921 * of MCAST_POOL_INC.
4923 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
4925 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
4927 if (mc_pool == NULL) {
4929 "allocation of pool of %u multicast addresses failed\n",
4930 port->mc_addr_nb + MCAST_POOL_INC);
4934 port->mc_addr_pool = mc_pool;
4941 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
4943 if (mcast_addr_pool_extend(port) != 0)
4945 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
4949 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
4952 if (addr_idx == port->mc_addr_nb) {
4953 /* No need to recompact the set of multicast addressses. */
4954 if (port->mc_addr_nb == 0) {
4955 /* free the pool of multicast addresses. */
4956 free(port->mc_addr_pool);
4957 port->mc_addr_pool = NULL;
4961 memmove(&port->mc_addr_pool[addr_idx],
4962 &port->mc_addr_pool[addr_idx + 1],
4963 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
4967 eth_port_multicast_addr_list_set(portid_t port_id)
4969 struct rte_port *port;
4972 port = &ports[port_id];
4973 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
4977 "rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
4978 port_id, port->mc_addr_nb, diag);
4984 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
4986 struct rte_port *port;
4989 if (port_id_is_invalid(port_id, ENABLED_WARN))
4992 port = &ports[port_id];
4995 * Check that the added multicast MAC address is not already recorded
4996 * in the pool of multicast addresses.
4998 for (i = 0; i < port->mc_addr_nb; i++) {
4999 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
5001 "multicast address already filtered by port\n");
5006 mcast_addr_pool_append(port, mc_addr);
5007 if (eth_port_multicast_addr_list_set(port_id) < 0)
5008 /* Rollback on failure, remove the address from the pool */
5009 mcast_addr_pool_remove(port, i);
5013 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
5015 struct rte_port *port;
5018 if (port_id_is_invalid(port_id, ENABLED_WARN))
5021 port = &ports[port_id];
5024 * Search the pool of multicast MAC addresses for the removed address.
5026 for (i = 0; i < port->mc_addr_nb; i++) {
5027 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
5030 if (i == port->mc_addr_nb) {
5031 fprintf(stderr, "multicast address not filtered by port %d\n",
5036 mcast_addr_pool_remove(port, i);
5037 if (eth_port_multicast_addr_list_set(port_id) < 0)
5038 /* Rollback on failure, add the address back into the pool */
5039 mcast_addr_pool_append(port, mc_addr);
5043 port_dcb_info_display(portid_t port_id)
5045 struct rte_eth_dcb_info dcb_info;
5048 static const char *border = "================";
5050 if (port_id_is_invalid(port_id, ENABLED_WARN))
5053 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
5055 fprintf(stderr, "\n Failed to get dcb infos on port %-2d\n",
5059 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
5060 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
5062 for (i = 0; i < dcb_info.nb_tcs; i++)
5064 printf("\n Priority : ");
5065 for (i = 0; i < dcb_info.nb_tcs; i++)
5066 printf("\t%4d", dcb_info.prio_tc[i]);
5067 printf("\n BW percent :");
5068 for (i = 0; i < dcb_info.nb_tcs; i++)
5069 printf("\t%4d%%", dcb_info.tc_bws[i]);
5070 printf("\n RXQ base : ");
5071 for (i = 0; i < dcb_info.nb_tcs; i++)
5072 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
5073 printf("\n RXQ number :");
5074 for (i = 0; i < dcb_info.nb_tcs; i++)
5075 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
5076 printf("\n TXQ base : ");
5077 for (i = 0; i < dcb_info.nb_tcs; i++)
5078 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
5079 printf("\n TXQ number :");
5080 for (i = 0; i < dcb_info.nb_tcs; i++)
5081 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
5086 open_file(const char *file_path, uint32_t *size)
5088 int fd = open(file_path, O_RDONLY);
5090 uint8_t *buf = NULL;
5098 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
5102 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
5104 fprintf(stderr, "%s: File operations failed\n", __func__);
5108 pkg_size = st_buf.st_size;
5111 fprintf(stderr, "%s: File operations failed\n", __func__);
5115 buf = (uint8_t *)malloc(pkg_size);
5118 fprintf(stderr, "%s: Failed to malloc memory\n", __func__);
5122 ret = read(fd, buf, pkg_size);
5125 fprintf(stderr, "%s: File read operation failed\n", __func__);
5139 save_file(const char *file_path, uint8_t *buf, uint32_t size)
5141 FILE *fh = fopen(file_path, "wb");
5144 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
5148 if (fwrite(buf, 1, size, fh) != size) {
5150 fprintf(stderr, "%s: File write operation failed\n", __func__);
5160 close_file(uint8_t *buf)
5171 port_queue_region_info_display(portid_t port_id, void *buf)
5175 struct rte_pmd_i40e_queue_regions *info =
5176 (struct rte_pmd_i40e_queue_regions *)buf;
5177 static const char *queue_region_info_stats_border = "-------";
5179 if (!info->queue_region_number)
5180 printf("there is no region has been set before");
5182 printf("\n %s All queue region info for port=%2d %s",
5183 queue_region_info_stats_border, port_id,
5184 queue_region_info_stats_border);
5185 printf("\n queue_region_number: %-14u \n",
5186 info->queue_region_number);
5188 for (i = 0; i < info->queue_region_number; i++) {
5189 printf("\n region_id: %-14u queue_number: %-14u "
5190 "queue_start_index: %-14u \n",
5191 info->region[i].region_id,
5192 info->region[i].queue_num,
5193 info->region[i].queue_start_index);
5195 printf(" user_priority_num is %-14u :",
5196 info->region[i].user_priority_num);
5197 for (j = 0; j < info->region[i].user_priority_num; j++)
5198 printf(" %-14u ", info->region[i].user_priority[j]);
5200 printf("\n flowtype_num is %-14u :",
5201 info->region[i].flowtype_num);
5202 for (j = 0; j < info->region[i].flowtype_num; j++)
5203 printf(" %-14u ", info->region[i].hw_flowtype[j]);
5206 RTE_SET_USED(port_id);
5214 show_macs(portid_t port_id)
5216 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5217 struct rte_eth_dev_info dev_info;
5218 struct rte_ether_addr *addr;
5219 uint32_t i, num_macs = 0;
5220 struct rte_eth_dev *dev;
5222 dev = &rte_eth_devices[port_id];
5224 if (eth_dev_info_get_print_err(port_id, &dev_info))
5227 for (i = 0; i < dev_info.max_mac_addrs; i++) {
5228 addr = &dev->data->mac_addrs[i];
5230 /* skip zero address */
5231 if (rte_is_zero_ether_addr(addr))
5237 printf("Number of MAC address added: %d\n", num_macs);
5239 for (i = 0; i < dev_info.max_mac_addrs; i++) {
5240 addr = &dev->data->mac_addrs[i];
5242 /* skip zero address */
5243 if (rte_is_zero_ether_addr(addr))
5246 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5247 printf(" %s\n", buf);
5252 show_mcast_macs(portid_t port_id)
5254 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5255 struct rte_ether_addr *addr;
5256 struct rte_port *port;
5259 port = &ports[port_id];
5261 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
5263 for (i = 0; i < port->mc_addr_nb; i++) {
5264 addr = &port->mc_addr_pool[i];
5266 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5267 printf(" %s\n", buf);