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 },
146 static const struct {
147 enum rte_eth_fec_mode mode;
149 } fec_mode_name[] = {
151 .mode = RTE_ETH_FEC_NOFEC,
155 .mode = RTE_ETH_FEC_AUTO,
159 .mode = RTE_ETH_FEC_BASER,
163 .mode = RTE_ETH_FEC_RS,
169 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
171 char buf[RTE_ETHER_ADDR_FMT_SIZE];
172 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
173 printf("%s%s", name, buf);
177 nic_stats_display(portid_t port_id)
179 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
180 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
181 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
182 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
183 static uint64_t prev_ns[RTE_MAX_ETHPORTS];
184 struct timespec cur_time;
185 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
187 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
188 struct rte_eth_stats stats;
190 static const char *nic_stats_border = "########################";
192 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
196 rte_eth_stats_get(port_id, &stats);
197 printf("\n %s NIC statistics for port %-2d %s\n",
198 nic_stats_border, port_id, nic_stats_border);
200 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
201 "%-"PRIu64"\n", stats.ipackets, stats.imissed, stats.ibytes);
202 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
203 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
204 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
205 "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
208 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
211 ns = cur_time.tv_sec * NS_PER_SEC;
212 ns += cur_time.tv_nsec;
214 if (prev_ns[port_id] != 0)
215 diff_ns = ns - prev_ns[port_id];
216 prev_ns[port_id] = ns;
219 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
220 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
221 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
222 (stats.opackets - prev_pkts_tx[port_id]) : 0;
223 prev_pkts_rx[port_id] = stats.ipackets;
224 prev_pkts_tx[port_id] = stats.opackets;
225 mpps_rx = diff_ns > 0 ?
226 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
227 mpps_tx = diff_ns > 0 ?
228 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
230 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
231 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
232 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
233 (stats.obytes - prev_bytes_tx[port_id]) : 0;
234 prev_bytes_rx[port_id] = stats.ibytes;
235 prev_bytes_tx[port_id] = stats.obytes;
236 mbps_rx = diff_ns > 0 ?
237 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
238 mbps_tx = diff_ns > 0 ?
239 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
241 printf("\n Throughput (since last show)\n");
242 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
243 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
244 mpps_tx, mbps_tx * 8);
246 printf(" %s############################%s\n",
247 nic_stats_border, nic_stats_border);
251 nic_stats_clear(portid_t port_id)
255 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
260 ret = rte_eth_stats_reset(port_id);
263 "%s: Error: failed to reset stats (port %u): %s",
264 __func__, port_id, strerror(-ret));
268 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
273 "%s: Error: failed to get stats (port %u): %s",
274 __func__, port_id, strerror(ret));
277 printf("\n NIC statistics for port %d cleared\n", port_id);
281 nic_xstats_display(portid_t port_id)
283 struct rte_eth_xstat *xstats;
284 int cnt_xstats, idx_xstat;
285 struct rte_eth_xstat_name *xstats_names;
287 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
291 printf("###### NIC extended statistics for port %-2d\n", port_id);
292 if (!rte_eth_dev_is_valid_port(port_id)) {
293 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
298 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
299 if (cnt_xstats < 0) {
300 fprintf(stderr, "Error: Cannot get count of xstats\n");
304 /* Get id-name lookup table */
305 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
306 if (xstats_names == NULL) {
307 fprintf(stderr, "Cannot allocate memory for xstats lookup\n");
310 if (cnt_xstats != rte_eth_xstats_get_names(
311 port_id, xstats_names, cnt_xstats)) {
312 fprintf(stderr, "Error: Cannot get xstats lookup\n");
317 /* Get stats themselves */
318 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
319 if (xstats == NULL) {
320 fprintf(stderr, "Cannot allocate memory for xstats\n");
324 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
325 fprintf(stderr, "Error: Unable to get xstats\n");
332 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
333 if (xstats_hide_zero && !xstats[idx_xstat].value)
335 printf("%s: %"PRIu64"\n",
336 xstats_names[idx_xstat].name,
337 xstats[idx_xstat].value);
344 nic_xstats_clear(portid_t port_id)
348 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
353 ret = rte_eth_xstats_reset(port_id);
356 "%s: Error: failed to reset xstats (port %u): %s\n",
357 __func__, port_id, strerror(-ret));
361 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
365 fprintf(stderr, "%s: Error: failed to get stats (port %u): %s",
366 __func__, port_id, strerror(ret));
372 get_queue_state_name(uint8_t queue_state)
374 if (queue_state == RTE_ETH_QUEUE_STATE_STOPPED)
376 else if (queue_state == RTE_ETH_QUEUE_STATE_STARTED)
378 else if (queue_state == RTE_ETH_QUEUE_STATE_HAIRPIN)
385 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
387 struct rte_eth_burst_mode mode;
388 struct rte_eth_rxq_info qinfo;
390 static const char *info_border = "*********************";
392 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
395 "Failed to retrieve information for port: %u, RX queue: %hu\nerror desc: %s(%d)\n",
396 port_id, queue_id, strerror(-rc), rc);
400 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
401 info_border, port_id, queue_id, info_border);
403 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
404 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
405 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
406 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
407 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
408 printf("\nRX drop packets: %s",
409 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
410 printf("\nRX deferred start: %s",
411 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
412 printf("\nRX scattered packets: %s",
413 (qinfo.scattered_rx != 0) ? "on" : "off");
414 printf("\nRx queue state: %s", get_queue_state_name(qinfo.queue_state));
415 if (qinfo.rx_buf_size != 0)
416 printf("\nRX buffer size: %hu", qinfo.rx_buf_size);
417 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
419 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
420 printf("\nBurst mode: %s%s",
422 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
423 " (per queue)" : "");
429 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
431 struct rte_eth_burst_mode mode;
432 struct rte_eth_txq_info qinfo;
434 static const char *info_border = "*********************";
436 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
439 "Failed to retrieve information for port: %u, TX queue: %hu\nerror desc: %s(%d)\n",
440 port_id, queue_id, strerror(-rc), rc);
444 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
445 info_border, port_id, queue_id, info_border);
447 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
448 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
449 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
450 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
451 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
452 printf("\nTX deferred start: %s",
453 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
454 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
455 printf("\nTx queue state: %s", get_queue_state_name(qinfo.queue_state));
457 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
458 printf("\nBurst mode: %s%s",
460 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
461 " (per queue)" : "");
466 static int bus_match_all(const struct rte_bus *bus, const void *data)
474 device_infos_display_speeds(uint32_t speed_capa)
476 printf("\n\tDevice speed capability:");
477 if (speed_capa == ETH_LINK_SPEED_AUTONEG)
478 printf(" Autonegotiate (all speeds)");
479 if (speed_capa & ETH_LINK_SPEED_FIXED)
480 printf(" Disable autonegotiate (fixed speed) ");
481 if (speed_capa & ETH_LINK_SPEED_10M_HD)
482 printf(" 10 Mbps half-duplex ");
483 if (speed_capa & ETH_LINK_SPEED_10M)
484 printf(" 10 Mbps full-duplex ");
485 if (speed_capa & ETH_LINK_SPEED_100M_HD)
486 printf(" 100 Mbps half-duplex ");
487 if (speed_capa & ETH_LINK_SPEED_100M)
488 printf(" 100 Mbps full-duplex ");
489 if (speed_capa & ETH_LINK_SPEED_1G)
491 if (speed_capa & ETH_LINK_SPEED_2_5G)
492 printf(" 2.5 Gbps ");
493 if (speed_capa & ETH_LINK_SPEED_5G)
495 if (speed_capa & ETH_LINK_SPEED_10G)
497 if (speed_capa & ETH_LINK_SPEED_20G)
499 if (speed_capa & ETH_LINK_SPEED_25G)
501 if (speed_capa & ETH_LINK_SPEED_40G)
503 if (speed_capa & ETH_LINK_SPEED_50G)
505 if (speed_capa & ETH_LINK_SPEED_56G)
507 if (speed_capa & ETH_LINK_SPEED_100G)
508 printf(" 100 Gbps ");
509 if (speed_capa & ETH_LINK_SPEED_200G)
510 printf(" 200 Gbps ");
514 device_infos_display(const char *identifier)
516 static const char *info_border = "*********************";
517 struct rte_bus *start = NULL, *next;
518 struct rte_dev_iterator dev_iter;
519 char name[RTE_ETH_NAME_MAX_LEN];
520 struct rte_ether_addr mac_addr;
521 struct rte_device *dev;
522 struct rte_devargs da;
524 struct rte_eth_dev_info dev_info;
527 memset(&da, 0, sizeof(da));
531 if (rte_devargs_parsef(&da, "%s", identifier)) {
532 fprintf(stderr, "cannot parse identifier\n");
537 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
540 if (identifier && da.bus != next)
543 /* Skip buses that don't have iterate method */
544 if (!next->dev_iterate)
547 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
548 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
552 /* Check for matching device if identifier is present */
554 strncmp(da.name, dev->name, strlen(dev->name)))
556 printf("\n%s Infos for device %s %s\n",
557 info_border, dev->name, info_border);
558 printf("Bus name: %s", dev->bus->name);
559 printf("\nDriver name: %s", dev->driver->name);
560 printf("\nDevargs: %s",
561 dev->devargs ? dev->devargs->args : "");
562 printf("\nConnect to socket: %d", dev->numa_node);
565 /* List ports with matching device name */
566 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
567 printf("\n\tPort id: %-2d", port_id);
568 if (eth_macaddr_get_print_err(port_id,
570 print_ethaddr("\n\tMAC address: ",
572 rte_eth_dev_get_name_by_port(port_id, name);
573 printf("\n\tDevice name: %s", name);
574 if (rte_eth_dev_info_get(port_id, &dev_info) == 0)
575 device_infos_display_speeds(dev_info.speed_capa);
580 rte_devargs_reset(&da);
584 port_infos_display(portid_t port_id)
586 struct rte_port *port;
587 struct rte_ether_addr mac_addr;
588 struct rte_eth_link link;
589 struct rte_eth_dev_info dev_info;
591 struct rte_mempool * mp;
592 static const char *info_border = "*********************";
594 char name[RTE_ETH_NAME_MAX_LEN];
596 char fw_version[ETHDEV_FWVERS_LEN];
598 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
602 port = &ports[port_id];
603 ret = eth_link_get_nowait_print_err(port_id, &link);
607 ret = eth_dev_info_get_print_err(port_id, &dev_info);
611 printf("\n%s Infos for port %-2d %s\n",
612 info_border, port_id, info_border);
613 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
614 print_ethaddr("MAC address: ", &mac_addr);
615 rte_eth_dev_get_name_by_port(port_id, name);
616 printf("\nDevice name: %s", name);
617 printf("\nDriver name: %s", dev_info.driver_name);
619 if (rte_eth_dev_fw_version_get(port_id, fw_version,
620 ETHDEV_FWVERS_LEN) == 0)
621 printf("\nFirmware-version: %s", fw_version);
623 printf("\nFirmware-version: %s", "not available");
625 if (dev_info.device->devargs && dev_info.device->devargs->args)
626 printf("\nDevargs: %s", dev_info.device->devargs->args);
627 printf("\nConnect to socket: %u", port->socket_id);
629 if (port_numa[port_id] != NUMA_NO_CONFIG) {
630 mp = mbuf_pool_find(port_numa[port_id], 0);
632 printf("\nmemory allocation on the socket: %d",
635 printf("\nmemory allocation on the socket: %u",port->socket_id);
637 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
638 printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
639 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
640 ("full-duplex") : ("half-duplex"));
641 printf("Autoneg status: %s\n", (link.link_autoneg == ETH_LINK_AUTONEG) ?
644 if (!rte_eth_dev_get_mtu(port_id, &mtu))
645 printf("MTU: %u\n", mtu);
647 printf("Promiscuous mode: %s\n",
648 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
649 printf("Allmulticast mode: %s\n",
650 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
651 printf("Maximum number of MAC addresses: %u\n",
652 (unsigned int)(port->dev_info.max_mac_addrs));
653 printf("Maximum number of MAC addresses of hash filtering: %u\n",
654 (unsigned int)(port->dev_info.max_hash_mac_addrs));
656 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
657 if (vlan_offload >= 0){
658 printf("VLAN offload: \n");
659 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
660 printf(" strip on, ");
662 printf(" strip off, ");
664 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
665 printf("filter on, ");
667 printf("filter off, ");
669 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
670 printf("extend on, ");
672 printf("extend off, ");
674 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
675 printf("qinq strip on\n");
677 printf("qinq strip off\n");
680 if (dev_info.hash_key_size > 0)
681 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
682 if (dev_info.reta_size > 0)
683 printf("Redirection table size: %u\n", dev_info.reta_size);
684 if (!dev_info.flow_type_rss_offloads)
685 printf("No RSS offload flow type is supported.\n");
690 printf("Supported RSS offload flow types:\n");
691 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
692 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
693 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
695 p = flowtype_to_str(i);
699 printf(" user defined %d\n", i);
703 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
704 printf("Maximum configurable length of RX packet: %u\n",
705 dev_info.max_rx_pktlen);
706 printf("Maximum configurable size of LRO aggregated packet: %u\n",
707 dev_info.max_lro_pkt_size);
708 if (dev_info.max_vfs)
709 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
710 if (dev_info.max_vmdq_pools)
711 printf("Maximum number of VMDq pools: %u\n",
712 dev_info.max_vmdq_pools);
714 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
715 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
716 printf("Max possible number of RXDs per queue: %hu\n",
717 dev_info.rx_desc_lim.nb_max);
718 printf("Min possible number of RXDs per queue: %hu\n",
719 dev_info.rx_desc_lim.nb_min);
720 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
722 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
723 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
724 printf("Max possible number of TXDs per queue: %hu\n",
725 dev_info.tx_desc_lim.nb_max);
726 printf("Min possible number of TXDs per queue: %hu\n",
727 dev_info.tx_desc_lim.nb_min);
728 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
729 printf("Max segment number per packet: %hu\n",
730 dev_info.tx_desc_lim.nb_seg_max);
731 printf("Max segment number per MTU/TSO: %hu\n",
732 dev_info.tx_desc_lim.nb_mtu_seg_max);
734 /* Show switch info only if valid switch domain and port id is set */
735 if (dev_info.switch_info.domain_id !=
736 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
737 if (dev_info.switch_info.name)
738 printf("Switch name: %s\n", dev_info.switch_info.name);
740 printf("Switch domain Id: %u\n",
741 dev_info.switch_info.domain_id);
742 printf("Switch Port Id: %u\n",
743 dev_info.switch_info.port_id);
748 port_summary_header_display(void)
750 uint16_t port_number;
752 port_number = rte_eth_dev_count_avail();
753 printf("Number of available ports: %i\n", port_number);
754 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
755 "Driver", "Status", "Link");
759 port_summary_display(portid_t port_id)
761 struct rte_ether_addr mac_addr;
762 struct rte_eth_link link;
763 struct rte_eth_dev_info dev_info;
764 char name[RTE_ETH_NAME_MAX_LEN];
767 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
772 ret = eth_link_get_nowait_print_err(port_id, &link);
776 ret = eth_dev_info_get_print_err(port_id, &dev_info);
780 rte_eth_dev_get_name_by_port(port_id, name);
781 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
785 printf("%-4d " RTE_ETHER_ADDR_PRT_FMT " %-12s %-14s %-8s %s\n",
786 port_id, RTE_ETHER_ADDR_BYTES(&mac_addr), name,
787 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
788 rte_eth_link_speed_to_str(link.link_speed));
792 port_eeprom_display(portid_t port_id)
794 struct rte_dev_eeprom_info einfo;
796 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
801 int len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
802 if (len_eeprom < 0) {
803 switch (len_eeprom) {
805 fprintf(stderr, "port index %d invalid\n", port_id);
808 fprintf(stderr, "operation not supported by device\n");
811 fprintf(stderr, "device is removed\n");
814 fprintf(stderr, "Unable to get EEPROM: %d\n",
821 char buf[len_eeprom];
823 einfo.length = len_eeprom;
826 ret = rte_eth_dev_get_eeprom(port_id, &einfo);
830 fprintf(stderr, "port index %d invalid\n", port_id);
833 fprintf(stderr, "operation not supported by device\n");
836 fprintf(stderr, "device is removed\n");
839 fprintf(stderr, "Unable to get EEPROM: %d\n", ret);
844 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
845 printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
849 port_module_eeprom_display(portid_t port_id)
851 struct rte_eth_dev_module_info minfo;
852 struct rte_dev_eeprom_info einfo;
855 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
861 ret = rte_eth_dev_get_module_info(port_id, &minfo);
865 fprintf(stderr, "port index %d invalid\n", port_id);
868 fprintf(stderr, "operation not supported by device\n");
871 fprintf(stderr, "device is removed\n");
874 fprintf(stderr, "Unable to get module EEPROM: %d\n",
881 char buf[minfo.eeprom_len];
883 einfo.length = minfo.eeprom_len;
886 ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
890 fprintf(stderr, "port index %d invalid\n", port_id);
893 fprintf(stderr, "operation not supported by device\n");
896 fprintf(stderr, "device is removed\n");
899 fprintf(stderr, "Unable to get module EEPROM: %d\n",
906 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
907 printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
911 port_id_is_invalid(portid_t port_id, enum print_warning warning)
915 if (port_id == (portid_t)RTE_PORT_ALL)
918 RTE_ETH_FOREACH_DEV(pid)
922 if (warning == ENABLED_WARN)
923 fprintf(stderr, "Invalid port %d\n", port_id);
928 void print_valid_ports(void)
932 printf("The valid ports array is [");
933 RTE_ETH_FOREACH_DEV(pid) {
940 vlan_id_is_invalid(uint16_t vlan_id)
944 fprintf(stderr, "Invalid vlan_id %d (must be < 4096)\n", vlan_id);
949 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
951 const struct rte_pci_device *pci_dev;
952 const struct rte_bus *bus;
957 "Port register offset 0x%X not aligned on a 4-byte boundary\n",
958 (unsigned int)reg_off);
962 if (!ports[port_id].dev_info.device) {
963 fprintf(stderr, "Invalid device\n");
967 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
968 if (bus && !strcmp(bus->name, "pci")) {
969 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
971 fprintf(stderr, "Not a PCI device\n");
975 pci_len = pci_dev->mem_resource[0].len;
976 if (reg_off >= pci_len) {
978 "Port %d: register offset %u (0x%X) out of port PCI resource (length=%"PRIu64")\n",
979 port_id, (unsigned int)reg_off, (unsigned int)reg_off,
987 reg_bit_pos_is_invalid(uint8_t bit_pos)
991 fprintf(stderr, "Invalid bit position %d (must be <= 31)\n", bit_pos);
995 #define display_port_and_reg_off(port_id, reg_off) \
996 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
999 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1001 display_port_and_reg_off(port_id, (unsigned)reg_off);
1002 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1006 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1011 if (port_id_is_invalid(port_id, ENABLED_WARN))
1013 if (port_reg_off_is_invalid(port_id, reg_off))
1015 if (reg_bit_pos_is_invalid(bit_x))
1017 reg_v = port_id_pci_reg_read(port_id, reg_off);
1018 display_port_and_reg_off(port_id, (unsigned)reg_off);
1019 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1023 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1024 uint8_t bit1_pos, uint8_t bit2_pos)
1030 if (port_id_is_invalid(port_id, ENABLED_WARN))
1032 if (port_reg_off_is_invalid(port_id, reg_off))
1034 if (reg_bit_pos_is_invalid(bit1_pos))
1036 if (reg_bit_pos_is_invalid(bit2_pos))
1038 if (bit1_pos > bit2_pos)
1039 l_bit = bit2_pos, h_bit = bit1_pos;
1041 l_bit = bit1_pos, h_bit = bit2_pos;
1043 reg_v = port_id_pci_reg_read(port_id, reg_off);
1046 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1047 display_port_and_reg_off(port_id, (unsigned)reg_off);
1048 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1049 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1053 port_reg_display(portid_t port_id, uint32_t reg_off)
1057 if (port_id_is_invalid(port_id, ENABLED_WARN))
1059 if (port_reg_off_is_invalid(port_id, reg_off))
1061 reg_v = port_id_pci_reg_read(port_id, reg_off);
1062 display_port_reg_value(port_id, reg_off, reg_v);
1066 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1071 if (port_id_is_invalid(port_id, ENABLED_WARN))
1073 if (port_reg_off_is_invalid(port_id, reg_off))
1075 if (reg_bit_pos_is_invalid(bit_pos))
1078 fprintf(stderr, "Invalid bit value %d (must be 0 or 1)\n",
1082 reg_v = port_id_pci_reg_read(port_id, reg_off);
1084 reg_v &= ~(1 << bit_pos);
1086 reg_v |= (1 << bit_pos);
1087 port_id_pci_reg_write(port_id, reg_off, reg_v);
1088 display_port_reg_value(port_id, reg_off, reg_v);
1092 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1093 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1100 if (port_id_is_invalid(port_id, ENABLED_WARN))
1102 if (port_reg_off_is_invalid(port_id, reg_off))
1104 if (reg_bit_pos_is_invalid(bit1_pos))
1106 if (reg_bit_pos_is_invalid(bit2_pos))
1108 if (bit1_pos > bit2_pos)
1109 l_bit = bit2_pos, h_bit = bit1_pos;
1111 l_bit = bit1_pos, h_bit = bit2_pos;
1113 if ((h_bit - l_bit) < 31)
1114 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1118 if (value > max_v) {
1119 fprintf(stderr, "Invalid value %u (0x%x) must be < %u (0x%x)\n",
1120 (unsigned)value, (unsigned)value,
1121 (unsigned)max_v, (unsigned)max_v);
1124 reg_v = port_id_pci_reg_read(port_id, reg_off);
1125 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1126 reg_v |= (value << l_bit); /* Set changed bits */
1127 port_id_pci_reg_write(port_id, reg_off, reg_v);
1128 display_port_reg_value(port_id, reg_off, reg_v);
1132 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1134 if (port_id_is_invalid(port_id, ENABLED_WARN))
1136 if (port_reg_off_is_invalid(port_id, reg_off))
1138 port_id_pci_reg_write(port_id, reg_off, reg_v);
1139 display_port_reg_value(port_id, reg_off, reg_v);
1143 port_mtu_set(portid_t port_id, uint16_t mtu)
1146 struct rte_port *rte_port = &ports[port_id];
1147 struct rte_eth_dev_info dev_info;
1148 uint16_t eth_overhead;
1151 if (port_id_is_invalid(port_id, ENABLED_WARN))
1154 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1158 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1160 "Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1161 mtu, dev_info.min_mtu, dev_info.max_mtu);
1164 diag = rte_eth_dev_set_mtu(port_id, mtu);
1166 fprintf(stderr, "Set MTU failed. diag=%d\n", diag);
1167 else if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1169 * Ether overhead in driver is equal to the difference of
1170 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1171 * device supports jumbo frame.
1173 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1174 if (mtu > RTE_ETHER_MTU) {
1175 rte_port->dev_conf.rxmode.offloads |=
1176 DEV_RX_OFFLOAD_JUMBO_FRAME;
1177 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1180 rte_port->dev_conf.rxmode.offloads &=
1181 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1185 /* Generic flow management functions. */
1187 static struct port_flow_tunnel *
1188 port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
1190 struct port_flow_tunnel *flow_tunnel;
1192 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1193 if (flow_tunnel->id == port_tunnel_id)
1203 port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
1206 switch (tunnel->type) {
1210 case RTE_FLOW_ITEM_TYPE_VXLAN:
1218 struct port_flow_tunnel *
1219 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
1221 struct rte_port *port = &ports[port_id];
1222 struct port_flow_tunnel *flow_tunnel;
1224 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1225 if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
1234 void port_flow_tunnel_list(portid_t port_id)
1236 struct rte_port *port = &ports[port_id];
1237 struct port_flow_tunnel *flt;
1239 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1240 printf("port %u tunnel #%u type=%s",
1241 port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
1242 if (flt->tunnel.tun_id)
1243 printf(" id=%" PRIu64, flt->tunnel.tun_id);
1248 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
1250 struct rte_port *port = &ports[port_id];
1251 struct port_flow_tunnel *flt;
1253 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1254 if (flt->id == tunnel_id)
1258 LIST_REMOVE(flt, chain);
1260 printf("port %u: flow tunnel #%u destroyed\n",
1261 port_id, tunnel_id);
1265 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
1267 struct rte_port *port = &ports[port_id];
1268 enum rte_flow_item_type type;
1269 struct port_flow_tunnel *flt;
1271 if (!strcmp(ops->type, "vxlan"))
1272 type = RTE_FLOW_ITEM_TYPE_VXLAN;
1274 fprintf(stderr, "cannot offload \"%s\" tunnel type\n",
1278 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1279 if (flt->tunnel.type == type)
1283 flt = calloc(1, sizeof(*flt));
1285 fprintf(stderr, "failed to allocate port flt object\n");
1288 flt->tunnel.type = type;
1289 flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
1290 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
1291 LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
1293 printf("port %d: flow tunnel #%u type %s\n",
1294 port_id, flt->id, ops->type);
1297 /** Generate a port_flow entry from attributes/pattern/actions. */
1298 static struct port_flow *
1299 port_flow_new(const struct rte_flow_attr *attr,
1300 const struct rte_flow_item *pattern,
1301 const struct rte_flow_action *actions,
1302 struct rte_flow_error *error)
1304 const struct rte_flow_conv_rule rule = {
1306 .pattern_ro = pattern,
1307 .actions_ro = actions,
1309 struct port_flow *pf;
1312 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1315 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1318 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1322 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1329 /** Print a message out of a flow error. */
1331 port_flow_complain(struct rte_flow_error *error)
1333 static const char *const errstrlist[] = {
1334 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1335 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1336 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1337 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1338 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1339 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1340 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1341 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1342 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1343 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1344 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1345 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1346 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1347 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1348 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1349 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1350 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1354 int err = rte_errno;
1356 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1357 !errstrlist[error->type])
1358 errstr = "unknown type";
1360 errstr = errstrlist[error->type];
1361 fprintf(stderr, "%s(): Caught PMD error type %d (%s): %s%s: %s\n",
1362 __func__, error->type, errstr,
1363 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1364 error->cause), buf) : "",
1365 error->message ? error->message : "(no stated reason)",
1371 rss_config_display(struct rte_flow_action_rss *rss_conf)
1375 if (rss_conf == NULL) {
1376 fprintf(stderr, "Invalid rule\n");
1382 if (rss_conf->queue_num == 0)
1384 for (i = 0; i < rss_conf->queue_num; i++)
1385 printf(" %d", rss_conf->queue[i]);
1388 printf(" function: ");
1389 switch (rss_conf->func) {
1390 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1391 printf("default\n");
1393 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1394 printf("toeplitz\n");
1396 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1397 printf("simple_xor\n");
1399 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1400 printf("symmetric_toeplitz\n");
1403 printf("Unknown function\n");
1407 printf(" types:\n");
1408 if (rss_conf->types == 0) {
1412 for (i = 0; rss_type_table[i].str; i++) {
1413 if ((rss_conf->types &
1414 rss_type_table[i].rss_type) ==
1415 rss_type_table[i].rss_type &&
1416 rss_type_table[i].rss_type != 0)
1417 printf(" %s\n", rss_type_table[i].str);
1421 static struct port_indirect_action *
1422 action_get_by_id(portid_t port_id, uint32_t id)
1424 struct rte_port *port;
1425 struct port_indirect_action **ppia;
1426 struct port_indirect_action *pia = NULL;
1428 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1429 port_id == (portid_t)RTE_PORT_ALL)
1431 port = &ports[port_id];
1432 ppia = &port->actions_list;
1434 if ((*ppia)->id == id) {
1438 ppia = &(*ppia)->next;
1442 "Failed to find indirect action #%u on port %u\n",
1448 action_alloc(portid_t port_id, uint32_t id,
1449 struct port_indirect_action **action)
1451 struct rte_port *port;
1452 struct port_indirect_action **ppia;
1453 struct port_indirect_action *pia = NULL;
1456 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1457 port_id == (portid_t)RTE_PORT_ALL)
1459 port = &ports[port_id];
1460 if (id == UINT32_MAX) {
1461 /* taking first available ID */
1462 if (port->actions_list) {
1463 if (port->actions_list->id == UINT32_MAX - 1) {
1465 "Highest indirect action ID is already assigned, delete it first\n");
1468 id = port->actions_list->id + 1;
1473 pia = calloc(1, sizeof(*pia));
1476 "Allocation of port %u indirect action failed\n",
1480 ppia = &port->actions_list;
1481 while (*ppia && (*ppia)->id > id)
1482 ppia = &(*ppia)->next;
1483 if (*ppia && (*ppia)->id == id) {
1485 "Indirect action #%u is already assigned, delete it first\n",
1497 /** Create indirect action */
1499 port_action_handle_create(portid_t port_id, uint32_t id,
1500 const struct rte_flow_indir_action_conf *conf,
1501 const struct rte_flow_action *action)
1503 struct port_indirect_action *pia;
1505 struct rte_flow_error error;
1507 ret = action_alloc(port_id, id, &pia);
1510 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
1511 struct rte_flow_action_age *age =
1512 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
1514 pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
1515 age->context = &pia->age_type;
1516 } else if (action->type == RTE_FLOW_ACTION_TYPE_CONNTRACK) {
1517 struct rte_flow_action_conntrack *ct =
1518 (struct rte_flow_action_conntrack *)(uintptr_t)(action->conf);
1520 memcpy(ct, &conntrack_context, sizeof(*ct));
1522 /* Poisoning to make sure PMDs update it in case of error. */
1523 memset(&error, 0x22, sizeof(error));
1524 pia->handle = rte_flow_action_handle_create(port_id, conf, action,
1527 uint32_t destroy_id = pia->id;
1528 port_action_handle_destroy(port_id, 1, &destroy_id);
1529 return port_flow_complain(&error);
1531 pia->type = action->type;
1532 printf("Indirect action #%u created\n", pia->id);
1536 /** Destroy indirect action */
1538 port_action_handle_destroy(portid_t port_id,
1540 const uint32_t *actions)
1542 struct rte_port *port;
1543 struct port_indirect_action **tmp;
1547 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1548 port_id == (portid_t)RTE_PORT_ALL)
1550 port = &ports[port_id];
1551 tmp = &port->actions_list;
1555 for (i = 0; i != n; ++i) {
1556 struct rte_flow_error error;
1557 struct port_indirect_action *pia = *tmp;
1559 if (actions[i] != pia->id)
1562 * Poisoning to make sure PMDs update it in case
1565 memset(&error, 0x33, sizeof(error));
1567 if (pia->handle && rte_flow_action_handle_destroy(
1568 port_id, pia->handle, &error)) {
1569 ret = port_flow_complain(&error);
1573 printf("Indirect action #%u destroyed\n", pia->id);
1578 tmp = &(*tmp)->next;
1585 /** Get indirect action by port + id */
1586 struct rte_flow_action_handle *
1587 port_action_handle_get_by_id(portid_t port_id, uint32_t id)
1590 struct port_indirect_action *pia = action_get_by_id(port_id, id);
1592 return (pia) ? pia->handle : NULL;
1595 /** Update indirect action */
1597 port_action_handle_update(portid_t port_id, uint32_t id,
1598 const struct rte_flow_action *action)
1600 struct rte_flow_error error;
1601 struct rte_flow_action_handle *action_handle;
1602 struct port_indirect_action *pia;
1605 action_handle = port_action_handle_get_by_id(port_id, id);
1608 pia = action_get_by_id(port_id, id);
1611 switch (pia->type) {
1612 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1613 update = action->conf;
1619 if (rte_flow_action_handle_update(port_id, action_handle, update,
1621 return port_flow_complain(&error);
1623 printf("Indirect action #%u updated\n", id);
1628 port_action_handle_query(portid_t port_id, uint32_t id)
1630 struct rte_flow_error error;
1631 struct port_indirect_action *pia;
1633 struct rte_flow_query_count count;
1634 struct rte_flow_query_age age;
1635 struct rte_flow_action_conntrack ct;
1638 pia = action_get_by_id(port_id, id);
1641 switch (pia->type) {
1642 case RTE_FLOW_ACTION_TYPE_AGE:
1643 case RTE_FLOW_ACTION_TYPE_COUNT:
1647 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1648 id, pia->type, port_id);
1651 /* Poisoning to make sure PMDs update it in case of error. */
1652 memset(&error, 0x55, sizeof(error));
1653 memset(&query, 0, sizeof(query));
1654 if (rte_flow_action_handle_query(port_id, pia->handle, &query, &error))
1655 return port_flow_complain(&error);
1656 switch (pia->type) {
1657 case RTE_FLOW_ACTION_TYPE_AGE:
1658 printf("Indirect AGE action:\n"
1660 " sec_since_last_hit_valid: %u\n"
1661 " sec_since_last_hit: %" PRIu32 "\n",
1663 query.age.sec_since_last_hit_valid,
1664 query.age.sec_since_last_hit);
1666 case RTE_FLOW_ACTION_TYPE_COUNT:
1667 printf("Indirect COUNT action:\n"
1670 " hits: %" PRIu64 "\n"
1671 " bytes: %" PRIu64 "\n",
1672 query.count.hits_set,
1673 query.count.bytes_set,
1677 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1678 printf("Conntrack Context:\n"
1679 " Peer: %u, Flow dir: %s, Enable: %u\n"
1680 " Live: %u, SACK: %u, CACK: %u\n"
1681 " Packet dir: %s, Liberal: %u, State: %u\n"
1682 " Factor: %u, Retrans: %u, TCP flags: %u\n"
1683 " Last Seq: %u, Last ACK: %u\n"
1684 " Last Win: %u, Last End: %u\n",
1686 query.ct.is_original_dir ? "Original" : "Reply",
1687 query.ct.enable, query.ct.live_connection,
1688 query.ct.selective_ack, query.ct.challenge_ack_passed,
1689 query.ct.last_direction ? "Original" : "Reply",
1690 query.ct.liberal_mode, query.ct.state,
1691 query.ct.max_ack_window, query.ct.retransmission_limit,
1692 query.ct.last_index, query.ct.last_seq,
1693 query.ct.last_ack, query.ct.last_window,
1695 printf(" Original Dir:\n"
1696 " scale: %u, fin: %u, ack seen: %u\n"
1697 " unacked data: %u\n Sent end: %u,"
1698 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1699 query.ct.original_dir.scale,
1700 query.ct.original_dir.close_initiated,
1701 query.ct.original_dir.last_ack_seen,
1702 query.ct.original_dir.data_unacked,
1703 query.ct.original_dir.sent_end,
1704 query.ct.original_dir.reply_end,
1705 query.ct.original_dir.max_win,
1706 query.ct.original_dir.max_ack);
1707 printf(" Reply Dir:\n"
1708 " scale: %u, fin: %u, ack seen: %u\n"
1709 " unacked data: %u\n Sent end: %u,"
1710 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1711 query.ct.reply_dir.scale,
1712 query.ct.reply_dir.close_initiated,
1713 query.ct.reply_dir.last_ack_seen,
1714 query.ct.reply_dir.data_unacked,
1715 query.ct.reply_dir.sent_end,
1716 query.ct.reply_dir.reply_end,
1717 query.ct.reply_dir.max_win,
1718 query.ct.reply_dir.max_ack);
1722 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1723 id, pia->type, port_id);
1729 static struct port_flow_tunnel *
1730 port_flow_tunnel_offload_cmd_prep(portid_t port_id,
1731 const struct rte_flow_item *pattern,
1732 const struct rte_flow_action *actions,
1733 const struct tunnel_ops *tunnel_ops)
1736 struct rte_port *port;
1737 struct port_flow_tunnel *pft;
1738 struct rte_flow_error error;
1740 port = &ports[port_id];
1741 pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
1743 fprintf(stderr, "failed to locate port flow tunnel #%u\n",
1747 if (tunnel_ops->actions) {
1748 uint32_t num_actions;
1749 const struct rte_flow_action *aptr;
1751 ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
1753 &pft->num_pmd_actions,
1756 port_flow_complain(&error);
1759 for (aptr = actions, num_actions = 1;
1760 aptr->type != RTE_FLOW_ACTION_TYPE_END;
1761 aptr++, num_actions++);
1762 pft->actions = malloc(
1763 (num_actions + pft->num_pmd_actions) *
1764 sizeof(actions[0]));
1765 if (!pft->actions) {
1766 rte_flow_tunnel_action_decap_release(
1767 port_id, pft->actions,
1768 pft->num_pmd_actions, &error);
1771 rte_memcpy(pft->actions, pft->pmd_actions,
1772 pft->num_pmd_actions * sizeof(actions[0]));
1773 rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
1774 num_actions * sizeof(actions[0]));
1776 if (tunnel_ops->items) {
1778 const struct rte_flow_item *iptr;
1780 ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
1782 &pft->num_pmd_items,
1785 port_flow_complain(&error);
1788 for (iptr = pattern, num_items = 1;
1789 iptr->type != RTE_FLOW_ITEM_TYPE_END;
1790 iptr++, num_items++);
1791 pft->items = malloc((num_items + pft->num_pmd_items) *
1792 sizeof(pattern[0]));
1794 rte_flow_tunnel_item_release(
1795 port_id, pft->pmd_items,
1796 pft->num_pmd_items, &error);
1799 rte_memcpy(pft->items, pft->pmd_items,
1800 pft->num_pmd_items * sizeof(pattern[0]));
1801 rte_memcpy(pft->items + pft->num_pmd_items, pattern,
1802 num_items * sizeof(pattern[0]));
1809 port_flow_tunnel_offload_cmd_release(portid_t port_id,
1810 const struct tunnel_ops *tunnel_ops,
1811 struct port_flow_tunnel *pft)
1813 struct rte_flow_error error;
1815 if (tunnel_ops->actions) {
1817 rte_flow_tunnel_action_decap_release(
1818 port_id, pft->pmd_actions,
1819 pft->num_pmd_actions, &error);
1820 pft->actions = NULL;
1821 pft->pmd_actions = NULL;
1823 if (tunnel_ops->items) {
1825 rte_flow_tunnel_item_release(port_id, pft->pmd_items,
1829 pft->pmd_items = NULL;
1833 /** Add port meter policy */
1835 port_meter_policy_add(portid_t port_id, uint32_t policy_id,
1836 const struct rte_flow_action *actions)
1838 struct rte_mtr_error error;
1839 const struct rte_flow_action *act = actions;
1840 const struct rte_flow_action *start;
1841 struct rte_mtr_meter_policy_params policy;
1842 uint32_t i = 0, act_n;
1845 for (i = 0; i < RTE_COLORS; i++) {
1846 for (act_n = 0, start = act;
1847 act->type != RTE_FLOW_ACTION_TYPE_END; act++)
1849 if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
1850 policy.actions[i] = start;
1852 policy.actions[i] = NULL;
1855 ret = rte_mtr_meter_policy_add(port_id,
1859 print_mtr_err_msg(&error);
1863 /** Validate flow rule. */
1865 port_flow_validate(portid_t port_id,
1866 const struct rte_flow_attr *attr,
1867 const struct rte_flow_item *pattern,
1868 const struct rte_flow_action *actions,
1869 const struct tunnel_ops *tunnel_ops)
1871 struct rte_flow_error error;
1872 struct port_flow_tunnel *pft = NULL;
1874 /* Poisoning to make sure PMDs update it in case of error. */
1875 memset(&error, 0x11, sizeof(error));
1876 if (tunnel_ops->enabled) {
1877 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
1878 actions, tunnel_ops);
1882 pattern = pft->items;
1884 actions = pft->actions;
1886 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1887 return port_flow_complain(&error);
1888 if (tunnel_ops->enabled)
1889 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
1890 printf("Flow rule validated\n");
1894 /** Return age action structure if exists, otherwise NULL. */
1895 static struct rte_flow_action_age *
1896 age_action_get(const struct rte_flow_action *actions)
1898 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1899 switch (actions->type) {
1900 case RTE_FLOW_ACTION_TYPE_AGE:
1901 return (struct rte_flow_action_age *)
1902 (uintptr_t)actions->conf;
1910 /** Create flow rule. */
1912 port_flow_create(portid_t port_id,
1913 const struct rte_flow_attr *attr,
1914 const struct rte_flow_item *pattern,
1915 const struct rte_flow_action *actions,
1916 const struct tunnel_ops *tunnel_ops)
1918 struct rte_flow *flow;
1919 struct rte_port *port;
1920 struct port_flow *pf;
1922 struct rte_flow_error error;
1923 struct port_flow_tunnel *pft = NULL;
1924 struct rte_flow_action_age *age = age_action_get(actions);
1926 port = &ports[port_id];
1927 if (port->flow_list) {
1928 if (port->flow_list->id == UINT32_MAX) {
1930 "Highest rule ID is already assigned, delete it first");
1933 id = port->flow_list->id + 1;
1935 if (tunnel_ops->enabled) {
1936 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
1937 actions, tunnel_ops);
1941 pattern = pft->items;
1943 actions = pft->actions;
1945 pf = port_flow_new(attr, pattern, actions, &error);
1947 return port_flow_complain(&error);
1949 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
1950 age->context = &pf->age_type;
1952 /* Poisoning to make sure PMDs update it in case of error. */
1953 memset(&error, 0x22, sizeof(error));
1954 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1956 if (tunnel_ops->enabled)
1957 port_flow_tunnel_offload_cmd_release(port_id,
1960 return port_flow_complain(&error);
1962 pf->next = port->flow_list;
1965 port->flow_list = pf;
1966 if (tunnel_ops->enabled)
1967 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
1968 printf("Flow rule #%u created\n", pf->id);
1972 /** Destroy a number of flow rules. */
1974 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1976 struct rte_port *port;
1977 struct port_flow **tmp;
1981 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1982 port_id == (portid_t)RTE_PORT_ALL)
1984 port = &ports[port_id];
1985 tmp = &port->flow_list;
1989 for (i = 0; i != n; ++i) {
1990 struct rte_flow_error error;
1991 struct port_flow *pf = *tmp;
1993 if (rule[i] != pf->id)
1996 * Poisoning to make sure PMDs update it in case
1999 memset(&error, 0x33, sizeof(error));
2000 if (rte_flow_destroy(port_id, pf->flow, &error)) {
2001 ret = port_flow_complain(&error);
2004 printf("Flow rule #%u destroyed\n", pf->id);
2010 tmp = &(*tmp)->next;
2016 /** Remove all flow rules. */
2018 port_flow_flush(portid_t port_id)
2020 struct rte_flow_error error;
2021 struct rte_port *port;
2024 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2025 port_id == (portid_t)RTE_PORT_ALL)
2028 port = &ports[port_id];
2030 if (port->flow_list == NULL)
2033 /* Poisoning to make sure PMDs update it in case of error. */
2034 memset(&error, 0x44, sizeof(error));
2035 if (rte_flow_flush(port_id, &error)) {
2036 port_flow_complain(&error);
2039 while (port->flow_list) {
2040 struct port_flow *pf = port->flow_list->next;
2042 free(port->flow_list);
2043 port->flow_list = pf;
2048 /** Dump flow rules. */
2050 port_flow_dump(portid_t port_id, bool dump_all, uint32_t rule_id,
2051 const char *file_name)
2054 FILE *file = stdout;
2055 struct rte_flow_error error;
2056 struct rte_port *port;
2057 struct port_flow *pflow;
2058 struct rte_flow *tmpFlow = NULL;
2061 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2062 port_id == (portid_t)RTE_PORT_ALL)
2066 port = &ports[port_id];
2067 pflow = port->flow_list;
2069 if (rule_id != pflow->id) {
2070 pflow = pflow->next;
2072 tmpFlow = pflow->flow;
2078 if (found == false) {
2079 fprintf(stderr, "Failed to dump to flow %d\n", rule_id);
2084 if (file_name && strlen(file_name)) {
2085 file = fopen(file_name, "w");
2087 fprintf(stderr, "Failed to create file %s: %s\n",
2088 file_name, strerror(errno));
2094 ret = rte_flow_dev_dump(port_id, tmpFlow, file, &error);
2096 ret = rte_flow_dev_dump(port_id, NULL, file, &error);
2098 port_flow_complain(&error);
2099 fprintf(stderr, "Failed to dump flow: %s\n", strerror(-ret));
2101 printf("Flow dump finished\n");
2102 if (file_name && strlen(file_name))
2107 /** Query a flow rule. */
2109 port_flow_query(portid_t port_id, uint32_t rule,
2110 const struct rte_flow_action *action)
2112 struct rte_flow_error error;
2113 struct rte_port *port;
2114 struct port_flow *pf;
2117 struct rte_flow_query_count count;
2118 struct rte_flow_action_rss rss_conf;
2119 struct rte_flow_query_age age;
2123 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2124 port_id == (portid_t)RTE_PORT_ALL)
2126 port = &ports[port_id];
2127 for (pf = port->flow_list; pf; pf = pf->next)
2131 fprintf(stderr, "Flow rule #%u not found\n", rule);
2134 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2135 &name, sizeof(name),
2136 (void *)(uintptr_t)action->type, &error);
2138 return port_flow_complain(&error);
2139 switch (action->type) {
2140 case RTE_FLOW_ACTION_TYPE_COUNT:
2141 case RTE_FLOW_ACTION_TYPE_RSS:
2142 case RTE_FLOW_ACTION_TYPE_AGE:
2145 fprintf(stderr, "Cannot query action type %d (%s)\n",
2146 action->type, name);
2149 /* Poisoning to make sure PMDs update it in case of error. */
2150 memset(&error, 0x55, sizeof(error));
2151 memset(&query, 0, sizeof(query));
2152 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
2153 return port_flow_complain(&error);
2154 switch (action->type) {
2155 case RTE_FLOW_ACTION_TYPE_COUNT:
2159 " hits: %" PRIu64 "\n"
2160 " bytes: %" PRIu64 "\n",
2162 query.count.hits_set,
2163 query.count.bytes_set,
2167 case RTE_FLOW_ACTION_TYPE_RSS:
2168 rss_config_display(&query.rss_conf);
2170 case RTE_FLOW_ACTION_TYPE_AGE:
2173 " sec_since_last_hit_valid: %u\n"
2174 " sec_since_last_hit: %" PRIu32 "\n",
2177 query.age.sec_since_last_hit_valid,
2178 query.age.sec_since_last_hit);
2182 "Cannot display result for action type %d (%s)\n",
2183 action->type, name);
2189 /** List simply and destroy all aged flows. */
2191 port_flow_aged(portid_t port_id, uint8_t destroy)
2194 int nb_context, total = 0, idx;
2195 struct rte_flow_error error;
2196 enum age_action_context_type *type;
2198 struct port_flow *pf;
2199 struct port_indirect_action *pia;
2202 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2203 port_id == (portid_t)RTE_PORT_ALL)
2205 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
2206 printf("Port %u total aged flows: %d\n", port_id, total);
2208 port_flow_complain(&error);
2213 contexts = malloc(sizeof(void *) * total);
2214 if (contexts == NULL) {
2215 fprintf(stderr, "Cannot allocate contexts for aged flow\n");
2218 printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
2219 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
2220 if (nb_context != total) {
2222 "Port:%d get aged flows count(%d) != total(%d)\n",
2223 port_id, nb_context, total);
2228 for (idx = 0; idx < nb_context; idx++) {
2229 if (!contexts[idx]) {
2230 fprintf(stderr, "Error: get Null context in port %u\n",
2234 type = (enum age_action_context_type *)contexts[idx];
2236 case ACTION_AGE_CONTEXT_TYPE_FLOW:
2237 ctx.pf = container_of(type, struct port_flow, age_type);
2238 printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
2242 ctx.pf->rule.attr->group,
2243 ctx.pf->rule.attr->priority,
2244 ctx.pf->rule.attr->ingress ? 'i' : '-',
2245 ctx.pf->rule.attr->egress ? 'e' : '-',
2246 ctx.pf->rule.attr->transfer ? 't' : '-');
2247 if (destroy && !port_flow_destroy(port_id, 1,
2251 case ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION:
2252 ctx.pia = container_of(type,
2253 struct port_indirect_action, age_type);
2254 printf("%-20s\t%" PRIu32 "\n", "Indirect action",
2258 fprintf(stderr, "Error: invalid context type %u\n",
2263 printf("\n%d flows destroyed\n", total);
2267 /** List flow rules. */
2269 port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group)
2271 struct rte_port *port;
2272 struct port_flow *pf;
2273 struct port_flow *list = NULL;
2276 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2277 port_id == (portid_t)RTE_PORT_ALL)
2279 port = &ports[port_id];
2280 if (!port->flow_list)
2282 /* Sort flows by group, priority and ID. */
2283 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
2284 struct port_flow **tmp;
2285 const struct rte_flow_attr *curr = pf->rule.attr;
2288 /* Filter out unwanted groups. */
2289 for (i = 0; i != n; ++i)
2290 if (curr->group == group[i])
2295 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
2296 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
2298 if (curr->group > comp->group ||
2299 (curr->group == comp->group &&
2300 curr->priority > comp->priority) ||
2301 (curr->group == comp->group &&
2302 curr->priority == comp->priority &&
2303 pf->id > (*tmp)->id))
2310 printf("ID\tGroup\tPrio\tAttr\tRule\n");
2311 for (pf = list; pf != NULL; pf = pf->tmp) {
2312 const struct rte_flow_item *item = pf->rule.pattern;
2313 const struct rte_flow_action *action = pf->rule.actions;
2316 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
2318 pf->rule.attr->group,
2319 pf->rule.attr->priority,
2320 pf->rule.attr->ingress ? 'i' : '-',
2321 pf->rule.attr->egress ? 'e' : '-',
2322 pf->rule.attr->transfer ? 't' : '-');
2323 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
2324 if ((uint32_t)item->type > INT_MAX)
2325 name = "PMD_INTERNAL";
2326 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
2327 &name, sizeof(name),
2328 (void *)(uintptr_t)item->type,
2331 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
2332 printf("%s ", name);
2336 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
2337 if ((uint32_t)action->type > INT_MAX)
2338 name = "PMD_INTERNAL";
2339 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2340 &name, sizeof(name),
2341 (void *)(uintptr_t)action->type,
2344 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
2345 printf(" %s", name);
2352 /** Restrict ingress traffic to the defined flow rules. */
2354 port_flow_isolate(portid_t port_id, int set)
2356 struct rte_flow_error error;
2358 /* Poisoning to make sure PMDs update it in case of error. */
2359 memset(&error, 0x66, sizeof(error));
2360 if (rte_flow_isolate(port_id, set, &error))
2361 return port_flow_complain(&error);
2362 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
2364 set ? "now restricted" : "not restricted anymore");
2369 * RX/TX ring descriptors display functions.
2372 rx_queue_id_is_invalid(queueid_t rxq_id)
2374 if (rxq_id < nb_rxq)
2376 fprintf(stderr, "Invalid RX queue %d (must be < nb_rxq=%d)\n",
2382 tx_queue_id_is_invalid(queueid_t txq_id)
2384 if (txq_id < nb_txq)
2386 fprintf(stderr, "Invalid TX queue %d (must be < nb_txq=%d)\n",
2392 get_rx_ring_size(portid_t port_id, queueid_t rxq_id, uint16_t *ring_size)
2394 struct rte_port *port = &ports[port_id];
2395 struct rte_eth_rxq_info rx_qinfo;
2398 ret = rte_eth_rx_queue_info_get(port_id, rxq_id, &rx_qinfo);
2400 *ring_size = rx_qinfo.nb_desc;
2404 if (ret != -ENOTSUP)
2407 * If the rte_eth_rx_queue_info_get is not support for this PMD,
2408 * ring_size stored in testpmd will be used for validity verification.
2409 * When configure the rxq by rte_eth_rx_queue_setup with nb_rx_desc
2410 * being 0, it will use a default value provided by PMDs to setup this
2411 * rxq. If the default value is 0, it will use the
2412 * RTE_ETH_DEV_FALLBACK_RX_RINGSIZE to setup this rxq.
2414 if (port->nb_rx_desc[rxq_id])
2415 *ring_size = port->nb_rx_desc[rxq_id];
2416 else if (port->dev_info.default_rxportconf.ring_size)
2417 *ring_size = port->dev_info.default_rxportconf.ring_size;
2419 *ring_size = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
2424 get_tx_ring_size(portid_t port_id, queueid_t txq_id, uint16_t *ring_size)
2426 struct rte_port *port = &ports[port_id];
2427 struct rte_eth_txq_info tx_qinfo;
2430 ret = rte_eth_tx_queue_info_get(port_id, txq_id, &tx_qinfo);
2432 *ring_size = tx_qinfo.nb_desc;
2436 if (ret != -ENOTSUP)
2439 * If the rte_eth_tx_queue_info_get is not support for this PMD,
2440 * ring_size stored in testpmd will be used for validity verification.
2441 * When configure the txq by rte_eth_tx_queue_setup with nb_tx_desc
2442 * being 0, it will use a default value provided by PMDs to setup this
2443 * txq. If the default value is 0, it will use the
2444 * RTE_ETH_DEV_FALLBACK_TX_RINGSIZE to setup this txq.
2446 if (port->nb_tx_desc[txq_id])
2447 *ring_size = port->nb_tx_desc[txq_id];
2448 else if (port->dev_info.default_txportconf.ring_size)
2449 *ring_size = port->dev_info.default_txportconf.ring_size;
2451 *ring_size = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
2456 rx_desc_id_is_invalid(portid_t port_id, queueid_t rxq_id, uint16_t rxdesc_id)
2461 ret = get_rx_ring_size(port_id, rxq_id, &ring_size);
2465 if (rxdesc_id < ring_size)
2468 fprintf(stderr, "Invalid RX descriptor %u (must be < ring_size=%u)\n",
2469 rxdesc_id, ring_size);
2474 tx_desc_id_is_invalid(portid_t port_id, queueid_t txq_id, uint16_t txdesc_id)
2479 ret = get_tx_ring_size(port_id, txq_id, &ring_size);
2483 if (txdesc_id < ring_size)
2486 fprintf(stderr, "Invalid TX descriptor %u (must be < ring_size=%u)\n",
2487 txdesc_id, ring_size);
2491 static const struct rte_memzone *
2492 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
2494 char mz_name[RTE_MEMZONE_NAMESIZE];
2495 const struct rte_memzone *mz;
2497 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
2498 port_id, q_id, ring_name);
2499 mz = rte_memzone_lookup(mz_name);
2502 "%s ring memory zoneof (port %d, queue %d) not found (zone name = %s\n",
2503 ring_name, port_id, q_id, mz_name);
2507 union igb_ring_dword {
2510 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
2520 struct igb_ring_desc_32_bytes {
2521 union igb_ring_dword lo_dword;
2522 union igb_ring_dword hi_dword;
2523 union igb_ring_dword resv1;
2524 union igb_ring_dword resv2;
2527 struct igb_ring_desc_16_bytes {
2528 union igb_ring_dword lo_dword;
2529 union igb_ring_dword hi_dword;
2533 ring_rxd_display_dword(union igb_ring_dword dword)
2535 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
2536 (unsigned)dword.words.hi);
2540 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
2541 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2544 __rte_unused portid_t port_id,
2548 struct igb_ring_desc_16_bytes *ring =
2549 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2550 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2552 struct rte_eth_dev_info dev_info;
2554 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2558 if (strstr(dev_info.driver_name, "i40e") != NULL) {
2559 /* 32 bytes RX descriptor, i40e only */
2560 struct igb_ring_desc_32_bytes *ring =
2561 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
2562 ring[desc_id].lo_dword.dword =
2563 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2564 ring_rxd_display_dword(ring[desc_id].lo_dword);
2565 ring[desc_id].hi_dword.dword =
2566 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2567 ring_rxd_display_dword(ring[desc_id].hi_dword);
2568 ring[desc_id].resv1.dword =
2569 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
2570 ring_rxd_display_dword(ring[desc_id].resv1);
2571 ring[desc_id].resv2.dword =
2572 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
2573 ring_rxd_display_dword(ring[desc_id].resv2);
2578 /* 16 bytes RX descriptor */
2579 ring[desc_id].lo_dword.dword =
2580 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2581 ring_rxd_display_dword(ring[desc_id].lo_dword);
2582 ring[desc_id].hi_dword.dword =
2583 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2584 ring_rxd_display_dword(ring[desc_id].hi_dword);
2588 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
2590 struct igb_ring_desc_16_bytes *ring;
2591 struct igb_ring_desc_16_bytes txd;
2593 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2594 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2595 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2596 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
2597 (unsigned)txd.lo_dword.words.lo,
2598 (unsigned)txd.lo_dword.words.hi,
2599 (unsigned)txd.hi_dword.words.lo,
2600 (unsigned)txd.hi_dword.words.hi);
2604 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
2606 const struct rte_memzone *rx_mz;
2608 if (rx_desc_id_is_invalid(port_id, rxq_id, rxd_id))
2610 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
2613 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
2617 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
2619 const struct rte_memzone *tx_mz;
2621 if (tx_desc_id_is_invalid(port_id, txq_id, txd_id))
2623 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
2626 ring_tx_descriptor_display(tx_mz, txd_id);
2630 fwd_lcores_config_display(void)
2634 printf("List of forwarding lcores:");
2635 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
2636 printf(" %2u", fwd_lcores_cpuids[lc_id]);
2640 rxtx_config_display(void)
2645 printf(" %s packet forwarding%s packets/burst=%d\n",
2646 cur_fwd_eng->fwd_mode_name,
2647 retry_enabled == 0 ? "" : " with retry",
2650 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
2651 printf(" packet len=%u - nb packet segments=%d\n",
2652 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
2654 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
2655 nb_fwd_lcores, nb_fwd_ports);
2657 RTE_ETH_FOREACH_DEV(pid) {
2658 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
2659 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
2660 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
2661 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
2662 struct rte_eth_rxq_info rx_qinfo;
2663 struct rte_eth_txq_info tx_qinfo;
2664 uint16_t rx_free_thresh_tmp;
2665 uint16_t tx_free_thresh_tmp;
2666 uint16_t tx_rs_thresh_tmp;
2667 uint16_t nb_rx_desc_tmp;
2668 uint16_t nb_tx_desc_tmp;
2669 uint64_t offloads_tmp;
2670 uint8_t pthresh_tmp;
2671 uint8_t hthresh_tmp;
2672 uint8_t wthresh_tmp;
2675 /* per port config */
2676 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
2677 (unsigned int)pid, nb_rxq, nb_txq);
2679 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
2680 ports[pid].dev_conf.rxmode.offloads,
2681 ports[pid].dev_conf.txmode.offloads);
2683 /* per rx queue config only for first queue to be less verbose */
2684 for (qid = 0; qid < 1; qid++) {
2685 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
2687 nb_rx_desc_tmp = nb_rx_desc[qid];
2688 rx_free_thresh_tmp =
2689 rx_conf[qid].rx_free_thresh;
2690 pthresh_tmp = rx_conf[qid].rx_thresh.pthresh;
2691 hthresh_tmp = rx_conf[qid].rx_thresh.hthresh;
2692 wthresh_tmp = rx_conf[qid].rx_thresh.wthresh;
2693 offloads_tmp = rx_conf[qid].offloads;
2695 nb_rx_desc_tmp = rx_qinfo.nb_desc;
2696 rx_free_thresh_tmp =
2697 rx_qinfo.conf.rx_free_thresh;
2698 pthresh_tmp = rx_qinfo.conf.rx_thresh.pthresh;
2699 hthresh_tmp = rx_qinfo.conf.rx_thresh.hthresh;
2700 wthresh_tmp = rx_qinfo.conf.rx_thresh.wthresh;
2701 offloads_tmp = rx_qinfo.conf.offloads;
2704 printf(" RX queue: %d\n", qid);
2705 printf(" RX desc=%d - RX free threshold=%d\n",
2706 nb_rx_desc_tmp, rx_free_thresh_tmp);
2707 printf(" RX threshold registers: pthresh=%d hthresh=%d "
2709 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2710 printf(" RX Offloads=0x%"PRIx64"\n", offloads_tmp);
2713 /* per tx queue config only for first queue to be less verbose */
2714 for (qid = 0; qid < 1; qid++) {
2715 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
2717 nb_tx_desc_tmp = nb_tx_desc[qid];
2718 tx_free_thresh_tmp =
2719 tx_conf[qid].tx_free_thresh;
2720 pthresh_tmp = tx_conf[qid].tx_thresh.pthresh;
2721 hthresh_tmp = tx_conf[qid].tx_thresh.hthresh;
2722 wthresh_tmp = tx_conf[qid].tx_thresh.wthresh;
2723 offloads_tmp = tx_conf[qid].offloads;
2724 tx_rs_thresh_tmp = tx_conf[qid].tx_rs_thresh;
2726 nb_tx_desc_tmp = tx_qinfo.nb_desc;
2727 tx_free_thresh_tmp =
2728 tx_qinfo.conf.tx_free_thresh;
2729 pthresh_tmp = tx_qinfo.conf.tx_thresh.pthresh;
2730 hthresh_tmp = tx_qinfo.conf.tx_thresh.hthresh;
2731 wthresh_tmp = tx_qinfo.conf.tx_thresh.wthresh;
2732 offloads_tmp = tx_qinfo.conf.offloads;
2733 tx_rs_thresh_tmp = tx_qinfo.conf.tx_rs_thresh;
2736 printf(" TX queue: %d\n", qid);
2737 printf(" TX desc=%d - TX free threshold=%d\n",
2738 nb_tx_desc_tmp, tx_free_thresh_tmp);
2739 printf(" TX threshold registers: pthresh=%d hthresh=%d "
2741 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2742 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
2743 offloads_tmp, tx_rs_thresh_tmp);
2749 port_rss_reta_info(portid_t port_id,
2750 struct rte_eth_rss_reta_entry64 *reta_conf,
2751 uint16_t nb_entries)
2753 uint16_t i, idx, shift;
2756 if (port_id_is_invalid(port_id, ENABLED_WARN))
2759 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
2762 "Failed to get RSS RETA info, return code = %d\n",
2767 for (i = 0; i < nb_entries; i++) {
2768 idx = i / RTE_RETA_GROUP_SIZE;
2769 shift = i % RTE_RETA_GROUP_SIZE;
2770 if (!(reta_conf[idx].mask & (1ULL << shift)))
2772 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
2773 i, reta_conf[idx].reta[shift]);
2778 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
2782 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
2784 struct rte_eth_rss_conf rss_conf = {0};
2785 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
2789 struct rte_eth_dev_info dev_info;
2790 uint8_t hash_key_size;
2793 if (port_id_is_invalid(port_id, ENABLED_WARN))
2796 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2800 if (dev_info.hash_key_size > 0 &&
2801 dev_info.hash_key_size <= sizeof(rss_key))
2802 hash_key_size = dev_info.hash_key_size;
2805 "dev_info did not provide a valid hash key size\n");
2809 /* Get RSS hash key if asked to display it */
2810 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2811 rss_conf.rss_key_len = hash_key_size;
2812 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2816 fprintf(stderr, "port index %d invalid\n", port_id);
2819 fprintf(stderr, "operation not supported by device\n");
2822 fprintf(stderr, "operation failed - diag=%d\n", diag);
2827 rss_hf = rss_conf.rss_hf;
2829 printf("RSS disabled\n");
2832 printf("RSS functions:\n ");
2833 for (i = 0; rss_type_table[i].str; i++) {
2834 if (rss_hf & rss_type_table[i].rss_type)
2835 printf("%s ", rss_type_table[i].str);
2840 printf("RSS key:\n");
2841 for (i = 0; i < hash_key_size; i++)
2842 printf("%02X", rss_key[i]);
2847 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2848 uint8_t hash_key_len)
2850 struct rte_eth_rss_conf rss_conf;
2854 rss_conf.rss_key = NULL;
2855 rss_conf.rss_key_len = hash_key_len;
2856 rss_conf.rss_hf = 0;
2857 for (i = 0; rss_type_table[i].str; i++) {
2858 if (!strcmp(rss_type_table[i].str, rss_type))
2859 rss_conf.rss_hf = rss_type_table[i].rss_type;
2861 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2863 rss_conf.rss_key = hash_key;
2864 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2871 fprintf(stderr, "port index %d invalid\n", port_id);
2874 fprintf(stderr, "operation not supported by device\n");
2877 fprintf(stderr, "operation failed - diag=%d\n", diag);
2883 * Setup forwarding configuration for each logical core.
2886 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2888 streamid_t nb_fs_per_lcore;
2896 nb_fs = cfg->nb_fwd_streams;
2897 nb_fc = cfg->nb_fwd_lcores;
2898 if (nb_fs <= nb_fc) {
2899 nb_fs_per_lcore = 1;
2902 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2903 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2906 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2908 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2909 fwd_lcores[lc_id]->stream_idx = sm_id;
2910 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2911 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2915 * Assign extra remaining streams, if any.
2917 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2918 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2919 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2920 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2921 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2926 fwd_topology_tx_port_get(portid_t rxp)
2928 static int warning_once = 1;
2930 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2932 switch (port_topology) {
2934 case PORT_TOPOLOGY_PAIRED:
2935 if ((rxp & 0x1) == 0) {
2936 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2940 "\nWarning! port-topology=paired and odd forward ports number, the last port will pair with itself.\n\n");
2946 case PORT_TOPOLOGY_CHAINED:
2947 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2948 case PORT_TOPOLOGY_LOOP:
2954 simple_fwd_config_setup(void)
2958 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2959 cur_fwd_config.nb_fwd_streams =
2960 (streamid_t) cur_fwd_config.nb_fwd_ports;
2962 /* reinitialize forwarding streams */
2966 * In the simple forwarding test, the number of forwarding cores
2967 * must be lower or equal to the number of forwarding ports.
2969 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2970 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2971 cur_fwd_config.nb_fwd_lcores =
2972 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2973 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2975 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2976 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2977 fwd_streams[i]->rx_queue = 0;
2978 fwd_streams[i]->tx_port =
2979 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2980 fwd_streams[i]->tx_queue = 0;
2981 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2982 fwd_streams[i]->retry_enabled = retry_enabled;
2987 * For the RSS forwarding test all streams distributed over lcores. Each stream
2988 * being composed of a RX queue to poll on a RX port for input messages,
2989 * associated with a TX queue of a TX port where to send forwarded packets.
2992 rss_fwd_config_setup(void)
3005 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3006 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3007 cur_fwd_config.nb_fwd_streams =
3008 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
3010 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3011 cur_fwd_config.nb_fwd_lcores =
3012 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3014 /* reinitialize forwarding streams */
3017 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3019 if (proc_id > 0 && nb_q % num_procs != 0)
3020 printf("Warning! queue numbers should be multiple of processes, or packet loss will happen.\n");
3023 * In multi-process, All queues are allocated to different
3024 * processes based on num_procs and proc_id. For example:
3025 * if supports 4 queues(nb_q), 2 processes(num_procs),
3026 * the 0~1 queue for primary process.
3027 * the 2~3 queue for secondary process.
3029 start = proc_id * nb_q / num_procs;
3030 end = start + nb_q / num_procs;
3033 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
3034 struct fwd_stream *fs;
3036 fs = fwd_streams[sm_id];
3037 txp = fwd_topology_tx_port_get(rxp);
3038 fs->rx_port = fwd_ports_ids[rxp];
3040 fs->tx_port = fwd_ports_ids[txp];
3042 fs->peer_addr = fs->tx_port;
3043 fs->retry_enabled = retry_enabled;
3045 if (rxp < nb_fwd_ports)
3055 get_fwd_port_total_tc_num(void)
3057 struct rte_eth_dcb_info dcb_info;
3058 uint16_t total_tc_num = 0;
3061 for (i = 0; i < nb_fwd_ports; i++) {
3062 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[i], &dcb_info);
3063 total_tc_num += dcb_info.nb_tcs;
3066 return total_tc_num;
3070 * For the DCB forwarding test, each core is assigned on each traffic class.
3072 * Each core is assigned a multi-stream, each stream being composed of
3073 * a RX queue to poll on a RX port for input messages, associated with
3074 * a TX queue of a TX port where to send forwarded packets. All RX and
3075 * TX queues are mapping to the same traffic class.
3076 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
3080 dcb_fwd_config_setup(void)
3082 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
3083 portid_t txp, rxp = 0;
3084 queueid_t txq, rxq = 0;
3086 uint16_t nb_rx_queue, nb_tx_queue;
3087 uint16_t i, j, k, sm_id = 0;
3088 uint16_t total_tc_num;
3089 struct rte_port *port;
3095 * The fwd_config_setup() is called when the port is RTE_PORT_STARTED
3096 * or RTE_PORT_STOPPED.
3098 * Re-configure ports to get updated mapping between tc and queue in
3099 * case the queue number of the port is changed. Skip for started ports
3100 * since modifying queue number and calling dev_configure need to stop
3103 for (pid = 0; pid < nb_fwd_ports; pid++) {
3104 if (port_is_started(pid) == 1)
3108 ret = rte_eth_dev_configure(pid, nb_rxq, nb_txq,
3112 "Failed to re-configure port %d, ret = %d.\n",
3118 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3119 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3120 cur_fwd_config.nb_fwd_streams =
3121 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3122 total_tc_num = get_fwd_port_total_tc_num();
3123 if (cur_fwd_config.nb_fwd_lcores > total_tc_num)
3124 cur_fwd_config.nb_fwd_lcores = total_tc_num;
3126 /* reinitialize forwarding streams */
3130 /* get the dcb info on the first RX and TX ports */
3131 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3132 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3134 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3135 fwd_lcores[lc_id]->stream_nb = 0;
3136 fwd_lcores[lc_id]->stream_idx = sm_id;
3137 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
3138 /* if the nb_queue is zero, means this tc is
3139 * not enabled on the POOL
3141 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
3143 k = fwd_lcores[lc_id]->stream_nb +
3144 fwd_lcores[lc_id]->stream_idx;
3145 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
3146 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
3147 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3148 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
3149 for (j = 0; j < nb_rx_queue; j++) {
3150 struct fwd_stream *fs;
3152 fs = fwd_streams[k + j];
3153 fs->rx_port = fwd_ports_ids[rxp];
3154 fs->rx_queue = rxq + j;
3155 fs->tx_port = fwd_ports_ids[txp];
3156 fs->tx_queue = txq + j % nb_tx_queue;
3157 fs->peer_addr = fs->tx_port;
3158 fs->retry_enabled = retry_enabled;
3160 fwd_lcores[lc_id]->stream_nb +=
3161 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3163 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
3166 if (tc < rxp_dcb_info.nb_tcs)
3168 /* Restart from TC 0 on next RX port */
3170 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
3172 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
3175 if (rxp >= nb_fwd_ports)
3177 /* get the dcb information on next RX and TX ports */
3178 if ((rxp & 0x1) == 0)
3179 txp = (portid_t) (rxp + 1);
3181 txp = (portid_t) (rxp - 1);
3182 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3183 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3188 icmp_echo_config_setup(void)
3195 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
3196 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
3197 (nb_txq * nb_fwd_ports);
3199 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3200 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3201 cur_fwd_config.nb_fwd_streams =
3202 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3203 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3204 cur_fwd_config.nb_fwd_lcores =
3205 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3206 if (verbose_level > 0) {
3207 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
3209 cur_fwd_config.nb_fwd_lcores,
3210 cur_fwd_config.nb_fwd_ports,
3211 cur_fwd_config.nb_fwd_streams);
3214 /* reinitialize forwarding streams */
3216 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3218 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3219 if (verbose_level > 0)
3220 printf(" core=%d: \n", lc_id);
3221 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3222 struct fwd_stream *fs;
3223 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3224 fs->rx_port = fwd_ports_ids[rxp];
3226 fs->tx_port = fs->rx_port;
3228 fs->peer_addr = fs->tx_port;
3229 fs->retry_enabled = retry_enabled;
3230 if (verbose_level > 0)
3231 printf(" stream=%d port=%d rxq=%d txq=%d\n",
3232 sm_id, fs->rx_port, fs->rx_queue,
3234 rxq = (queueid_t) (rxq + 1);
3235 if (rxq == nb_rxq) {
3237 rxp = (portid_t) (rxp + 1);
3244 fwd_config_setup(void)
3246 struct rte_port *port;
3250 cur_fwd_config.fwd_eng = cur_fwd_eng;
3251 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
3252 icmp_echo_config_setup();
3256 if ((nb_rxq > 1) && (nb_txq > 1)){
3258 for (i = 0; i < nb_fwd_ports; i++) {
3259 pt_id = fwd_ports_ids[i];
3260 port = &ports[pt_id];
3261 if (!port->dcb_flag) {
3263 "In DCB mode, all forwarding ports must be configured in this mode.\n");
3267 if (nb_fwd_lcores == 1) {
3269 "In DCB mode,the nb forwarding cores should be larger than 1.\n");
3273 dcb_fwd_config_setup();
3275 rss_fwd_config_setup();
3278 simple_fwd_config_setup();
3282 mp_alloc_to_str(uint8_t mode)
3285 case MP_ALLOC_NATIVE:
3291 case MP_ALLOC_XMEM_HUGE:
3301 pkt_fwd_config_display(struct fwd_config *cfg)
3303 struct fwd_stream *fs;
3307 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
3308 "NUMA support %s, MP allocation mode: %s\n",
3309 cfg->fwd_eng->fwd_mode_name,
3310 retry_enabled == 0 ? "" : " with retry",
3311 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
3312 numa_support == 1 ? "enabled" : "disabled",
3313 mp_alloc_to_str(mp_alloc_type));
3316 printf("TX retry num: %u, delay between TX retries: %uus\n",
3317 burst_tx_retry_num, burst_tx_delay_time);
3318 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
3319 printf("Logical Core %u (socket %u) forwards packets on "
3321 fwd_lcores_cpuids[lc_id],
3322 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
3323 fwd_lcores[lc_id]->stream_nb);
3324 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3325 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3326 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
3327 "P=%d/Q=%d (socket %u) ",
3328 fs->rx_port, fs->rx_queue,
3329 ports[fs->rx_port].socket_id,
3330 fs->tx_port, fs->tx_queue,
3331 ports[fs->tx_port].socket_id);
3332 print_ethaddr("peer=",
3333 &peer_eth_addrs[fs->peer_addr]);
3341 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
3343 struct rte_ether_addr new_peer_addr;
3344 if (!rte_eth_dev_is_valid_port(port_id)) {
3345 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
3348 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
3349 fprintf(stderr, "Error: Invalid ethernet address: %s\n",
3353 peer_eth_addrs[port_id] = new_peer_addr;
3357 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
3360 unsigned int lcore_cpuid;
3365 for (i = 0; i < nb_lc; i++) {
3366 lcore_cpuid = lcorelist[i];
3367 if (! rte_lcore_is_enabled(lcore_cpuid)) {
3368 fprintf(stderr, "lcore %u not enabled\n", lcore_cpuid);
3371 if (lcore_cpuid == rte_get_main_lcore()) {
3373 "lcore %u cannot be masked on for running packet forwarding, which is the main lcore and reserved for command line parsing only\n",
3378 fwd_lcores_cpuids[i] = lcore_cpuid;
3380 if (record_now == 0) {
3384 nb_cfg_lcores = (lcoreid_t) nb_lc;
3385 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
3386 printf("previous number of forwarding cores %u - changed to "
3387 "number of configured cores %u\n",
3388 (unsigned int) nb_fwd_lcores, nb_lc);
3389 nb_fwd_lcores = (lcoreid_t) nb_lc;
3396 set_fwd_lcores_mask(uint64_t lcoremask)
3398 unsigned int lcorelist[64];
3402 if (lcoremask == 0) {
3403 fprintf(stderr, "Invalid NULL mask of cores\n");
3407 for (i = 0; i < 64; i++) {
3408 if (! ((uint64_t)(1ULL << i) & lcoremask))
3410 lcorelist[nb_lc++] = i;
3412 return set_fwd_lcores_list(lcorelist, nb_lc);
3416 set_fwd_lcores_number(uint16_t nb_lc)
3418 if (test_done == 0) {
3419 fprintf(stderr, "Please stop forwarding first\n");
3422 if (nb_lc > nb_cfg_lcores) {
3424 "nb fwd cores %u > %u (max. number of configured lcores) - ignored\n",
3425 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
3428 nb_fwd_lcores = (lcoreid_t) nb_lc;
3429 printf("Number of forwarding cores set to %u\n",
3430 (unsigned int) nb_fwd_lcores);
3434 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
3442 for (i = 0; i < nb_pt; i++) {
3443 port_id = (portid_t) portlist[i];
3444 if (port_id_is_invalid(port_id, ENABLED_WARN))
3447 fwd_ports_ids[i] = port_id;
3449 if (record_now == 0) {
3453 nb_cfg_ports = (portid_t) nb_pt;
3454 if (nb_fwd_ports != (portid_t) nb_pt) {
3455 printf("previous number of forwarding ports %u - changed to "
3456 "number of configured ports %u\n",
3457 (unsigned int) nb_fwd_ports, nb_pt);
3458 nb_fwd_ports = (portid_t) nb_pt;
3463 * Parse the user input and obtain the list of forwarding ports
3466 * String containing the user input. User can specify
3467 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
3468 * For example, if the user wants to use all the available
3469 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
3470 * If the user wants to use only the ports 1,2 then the input
3472 * valid characters are '-' and ','
3473 * @param[out] values
3474 * This array will be filled with a list of port IDs
3475 * based on the user input
3476 * Note that duplicate entries are discarded and only the first
3477 * count entries in this array are port IDs and all the rest
3478 * will contain default values
3479 * @param[in] maxsize
3480 * This parameter denotes 2 things
3481 * 1) Number of elements in the values array
3482 * 2) Maximum value of each element in the values array
3484 * On success, returns total count of parsed port IDs
3485 * On failure, returns 0
3488 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
3490 unsigned int count = 0;
3494 unsigned int marked[maxsize];
3496 if (list == NULL || values == NULL)
3499 for (i = 0; i < (int)maxsize; i++)
3505 /*Remove the blank spaces if any*/
3506 while (isblank(*list))
3511 value = strtol(list, &end, 10);
3512 if (errno || end == NULL)
3514 if (value < 0 || value >= (int)maxsize)
3516 while (isblank(*end))
3518 if (*end == '-' && min == INT_MAX) {
3520 } else if ((*end == ',') || (*end == '\0')) {
3524 for (i = min; i <= max; i++) {
3525 if (count < maxsize) {
3537 } while (*end != '\0');
3543 parse_fwd_portlist(const char *portlist)
3545 unsigned int portcount;
3546 unsigned int portindex[RTE_MAX_ETHPORTS];
3547 unsigned int i, valid_port_count = 0;
3549 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
3551 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
3554 * Here we verify the validity of the ports
3555 * and thereby calculate the total number of
3558 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
3559 if (rte_eth_dev_is_valid_port(portindex[i])) {
3560 portindex[valid_port_count] = portindex[i];
3565 set_fwd_ports_list(portindex, valid_port_count);
3569 set_fwd_ports_mask(uint64_t portmask)
3571 unsigned int portlist[64];
3575 if (portmask == 0) {
3576 fprintf(stderr, "Invalid NULL mask of ports\n");
3580 RTE_ETH_FOREACH_DEV(i) {
3581 if (! ((uint64_t)(1ULL << i) & portmask))
3583 portlist[nb_pt++] = i;
3585 set_fwd_ports_list(portlist, nb_pt);
3589 set_fwd_ports_number(uint16_t nb_pt)
3591 if (nb_pt > nb_cfg_ports) {
3593 "nb fwd ports %u > %u (number of configured ports) - ignored\n",
3594 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
3597 nb_fwd_ports = (portid_t) nb_pt;
3598 printf("Number of forwarding ports set to %u\n",
3599 (unsigned int) nb_fwd_ports);
3603 port_is_forwarding(portid_t port_id)
3607 if (port_id_is_invalid(port_id, ENABLED_WARN))
3610 for (i = 0; i < nb_fwd_ports; i++) {
3611 if (fwd_ports_ids[i] == port_id)
3619 set_nb_pkt_per_burst(uint16_t nb)
3621 if (nb > MAX_PKT_BURST) {
3623 "nb pkt per burst: %u > %u (maximum packet per burst) ignored\n",
3624 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
3627 nb_pkt_per_burst = nb;
3628 printf("Number of packets per burst set to %u\n",
3629 (unsigned int) nb_pkt_per_burst);
3633 tx_split_get_name(enum tx_pkt_split split)
3637 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3638 if (tx_split_name[i].split == split)
3639 return tx_split_name[i].name;
3645 set_tx_pkt_split(const char *name)
3649 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3650 if (strcmp(tx_split_name[i].name, name) == 0) {
3651 tx_pkt_split = tx_split_name[i].split;
3655 fprintf(stderr, "unknown value: \"%s\"\n", name);
3659 parse_fec_mode(const char *name, uint32_t *fec_capa)
3663 for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
3664 if (strcmp(fec_mode_name[i].name, name) == 0) {
3666 RTE_ETH_FEC_MODE_TO_CAPA(fec_mode_name[i].mode);
3674 show_fec_capability(unsigned int num, struct rte_eth_fec_capa *speed_fec_capa)
3678 printf("FEC capabilities:\n");
3680 for (i = 0; i < num; i++) {
3682 rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
3684 for (j = 0; j < RTE_DIM(fec_mode_name); j++) {
3685 if (RTE_ETH_FEC_MODE_TO_CAPA(j) &
3686 speed_fec_capa[i].capa)
3687 printf("%s ", fec_mode_name[j].name);
3694 show_rx_pkt_offsets(void)
3699 printf("Number of offsets: %u\n", n);
3701 printf("Segment offsets: ");
3702 for (i = 0; i != n - 1; i++)
3703 printf("%hu,", rx_pkt_seg_offsets[i]);
3704 printf("%hu\n", rx_pkt_seg_lengths[i]);
3709 set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs)
3713 if (nb_offs >= MAX_SEGS_BUFFER_SPLIT) {
3714 printf("nb segments per RX packets=%u >= "
3715 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_offs);
3720 * No extra check here, the segment length will be checked by PMD
3721 * in the extended queue setup.
3723 for (i = 0; i < nb_offs; i++) {
3724 if (seg_offsets[i] >= UINT16_MAX) {
3725 printf("offset[%u]=%u > UINT16_MAX - give up\n",
3731 for (i = 0; i < nb_offs; i++)
3732 rx_pkt_seg_offsets[i] = (uint16_t) seg_offsets[i];
3734 rx_pkt_nb_offs = (uint8_t) nb_offs;
3738 show_rx_pkt_segments(void)
3743 printf("Number of segments: %u\n", n);
3745 printf("Segment sizes: ");
3746 for (i = 0; i != n - 1; i++)
3747 printf("%hu,", rx_pkt_seg_lengths[i]);
3748 printf("%hu\n", rx_pkt_seg_lengths[i]);
3753 set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
3757 if (nb_segs >= MAX_SEGS_BUFFER_SPLIT) {
3758 printf("nb segments per RX packets=%u >= "
3759 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs);
3764 * No extra check here, the segment length will be checked by PMD
3765 * in the extended queue setup.
3767 for (i = 0; i < nb_segs; i++) {
3768 if (seg_lengths[i] >= UINT16_MAX) {
3769 printf("length[%u]=%u > UINT16_MAX - give up\n",
3775 for (i = 0; i < nb_segs; i++)
3776 rx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3778 rx_pkt_nb_segs = (uint8_t) nb_segs;
3782 show_tx_pkt_segments(void)
3788 split = tx_split_get_name(tx_pkt_split);
3790 printf("Number of segments: %u\n", n);
3791 printf("Segment sizes: ");
3792 for (i = 0; i != n - 1; i++)
3793 printf("%hu,", tx_pkt_seg_lengths[i]);
3794 printf("%hu\n", tx_pkt_seg_lengths[i]);
3795 printf("Split packet: %s\n", split);
3799 nb_segs_is_invalid(unsigned int nb_segs)
3806 RTE_ETH_FOREACH_DEV(port_id) {
3807 for (queue_id = 0; queue_id < nb_txq; queue_id++) {
3808 ret = get_tx_ring_size(port_id, queue_id, &ring_size);
3810 /* Port may not be initialized yet, can't say
3811 * the port is invalid in this stage.
3815 if (ring_size < nb_segs) {
3816 printf("nb segments per TX packets=%u >= TX "
3817 "queue(%u) ring_size=%u - txpkts ignored\n",
3818 nb_segs, queue_id, ring_size);
3828 set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
3830 uint16_t tx_pkt_len;
3834 * For single segment settings failed check is ignored.
3835 * It is a very basic capability to send the single segment
3836 * packets, suppose it is always supported.
3838 if (nb_segs > 1 && nb_segs_is_invalid(nb_segs)) {
3840 "Tx segment size(%u) is not supported - txpkts ignored\n",
3845 if (nb_segs > RTE_MAX_SEGS_PER_PKT) {
3847 "Tx segment size(%u) is bigger than max number of segment(%u)\n",
3848 nb_segs, RTE_MAX_SEGS_PER_PKT);
3853 * Check that each segment length is greater or equal than
3854 * the mbuf data size.
3855 * Check also that the total packet length is greater or equal than the
3856 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
3860 for (i = 0; i < nb_segs; i++) {
3861 if (seg_lengths[i] > mbuf_data_size[0]) {
3863 "length[%u]=%u > mbuf_data_size=%u - give up\n",
3864 i, seg_lengths[i], mbuf_data_size[0]);
3867 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
3869 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
3870 fprintf(stderr, "total packet length=%u < %d - give up\n",
3871 (unsigned) tx_pkt_len,
3872 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
3876 for (i = 0; i < nb_segs; i++)
3877 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3879 tx_pkt_length = tx_pkt_len;
3880 tx_pkt_nb_segs = (uint8_t) nb_segs;
3884 show_tx_pkt_times(void)
3886 printf("Interburst gap: %u\n", tx_pkt_times_inter);
3887 printf("Intraburst gap: %u\n", tx_pkt_times_intra);
3891 set_tx_pkt_times(unsigned int *tx_times)
3893 tx_pkt_times_inter = tx_times[0];
3894 tx_pkt_times_intra = tx_times[1];
3898 setup_gro(const char *onoff, portid_t port_id)
3900 if (!rte_eth_dev_is_valid_port(port_id)) {
3901 fprintf(stderr, "invalid port id %u\n", port_id);
3904 if (test_done == 0) {
3906 "Before enable/disable GRO, please stop forwarding first\n");
3909 if (strcmp(onoff, "on") == 0) {
3910 if (gro_ports[port_id].enable != 0) {
3912 "Port %u has enabled GRO. Please disable GRO first\n",
3916 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3917 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
3918 gro_ports[port_id].param.max_flow_num =
3919 GRO_DEFAULT_FLOW_NUM;
3920 gro_ports[port_id].param.max_item_per_flow =
3921 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
3923 gro_ports[port_id].enable = 1;
3925 if (gro_ports[port_id].enable == 0) {
3926 fprintf(stderr, "Port %u has disabled GRO\n", port_id);
3929 gro_ports[port_id].enable = 0;
3934 setup_gro_flush_cycles(uint8_t cycles)
3936 if (test_done == 0) {
3938 "Before change flush interval for GRO, please stop forwarding first.\n");
3942 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
3943 GRO_DEFAULT_FLUSH_CYCLES) {
3945 "The flushing cycle be in the range of 1 to %u. Revert to the default value %u.\n",
3946 GRO_MAX_FLUSH_CYCLES, GRO_DEFAULT_FLUSH_CYCLES);
3947 cycles = GRO_DEFAULT_FLUSH_CYCLES;
3950 gro_flush_cycles = cycles;
3954 show_gro(portid_t port_id)
3956 struct rte_gro_param *param;
3957 uint32_t max_pkts_num;
3959 param = &gro_ports[port_id].param;
3961 if (!rte_eth_dev_is_valid_port(port_id)) {
3962 fprintf(stderr, "Invalid port id %u.\n", port_id);
3965 if (gro_ports[port_id].enable) {
3966 printf("GRO type: TCP/IPv4\n");
3967 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3968 max_pkts_num = param->max_flow_num *
3969 param->max_item_per_flow;
3971 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
3972 printf("Max number of packets to perform GRO: %u\n",
3974 printf("Flushing cycles: %u\n", gro_flush_cycles);
3976 printf("Port %u doesn't enable GRO.\n", port_id);
3980 setup_gso(const char *mode, portid_t port_id)
3982 if (!rte_eth_dev_is_valid_port(port_id)) {
3983 fprintf(stderr, "invalid port id %u\n", port_id);
3986 if (strcmp(mode, "on") == 0) {
3987 if (test_done == 0) {
3989 "before enabling GSO, please stop forwarding first\n");
3992 gso_ports[port_id].enable = 1;
3993 } else if (strcmp(mode, "off") == 0) {
3994 if (test_done == 0) {
3996 "before disabling GSO, please stop forwarding first\n");
3999 gso_ports[port_id].enable = 0;
4004 list_pkt_forwarding_modes(void)
4006 static char fwd_modes[128] = "";
4007 const char *separator = "|";
4008 struct fwd_engine *fwd_eng;
4011 if (strlen (fwd_modes) == 0) {
4012 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4013 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4014 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4015 strncat(fwd_modes, separator,
4016 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4018 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4025 list_pkt_forwarding_retry_modes(void)
4027 static char fwd_modes[128] = "";
4028 const char *separator = "|";
4029 struct fwd_engine *fwd_eng;
4032 if (strlen(fwd_modes) == 0) {
4033 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4034 if (fwd_eng == &rx_only_engine)
4036 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4038 strlen(fwd_modes) - 1);
4039 strncat(fwd_modes, separator,
4041 strlen(fwd_modes) - 1);
4043 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4050 set_pkt_forwarding_mode(const char *fwd_mode_name)
4052 struct fwd_engine *fwd_eng;
4056 while ((fwd_eng = fwd_engines[i]) != NULL) {
4057 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
4058 printf("Set %s packet forwarding mode%s\n",
4060 retry_enabled == 0 ? "" : " with retry");
4061 cur_fwd_eng = fwd_eng;
4066 fprintf(stderr, "Invalid %s packet forwarding mode\n", fwd_mode_name);
4070 add_rx_dump_callbacks(portid_t portid)
4072 struct rte_eth_dev_info dev_info;
4076 if (port_id_is_invalid(portid, ENABLED_WARN))
4079 ret = eth_dev_info_get_print_err(portid, &dev_info);
4083 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4084 if (!ports[portid].rx_dump_cb[queue])
4085 ports[portid].rx_dump_cb[queue] =
4086 rte_eth_add_rx_callback(portid, queue,
4087 dump_rx_pkts, NULL);
4091 add_tx_dump_callbacks(portid_t portid)
4093 struct rte_eth_dev_info dev_info;
4097 if (port_id_is_invalid(portid, ENABLED_WARN))
4100 ret = eth_dev_info_get_print_err(portid, &dev_info);
4104 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4105 if (!ports[portid].tx_dump_cb[queue])
4106 ports[portid].tx_dump_cb[queue] =
4107 rte_eth_add_tx_callback(portid, queue,
4108 dump_tx_pkts, NULL);
4112 remove_rx_dump_callbacks(portid_t portid)
4114 struct rte_eth_dev_info dev_info;
4118 if (port_id_is_invalid(portid, ENABLED_WARN))
4121 ret = eth_dev_info_get_print_err(portid, &dev_info);
4125 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4126 if (ports[portid].rx_dump_cb[queue]) {
4127 rte_eth_remove_rx_callback(portid, queue,
4128 ports[portid].rx_dump_cb[queue]);
4129 ports[portid].rx_dump_cb[queue] = NULL;
4134 remove_tx_dump_callbacks(portid_t portid)
4136 struct rte_eth_dev_info dev_info;
4140 if (port_id_is_invalid(portid, ENABLED_WARN))
4143 ret = eth_dev_info_get_print_err(portid, &dev_info);
4147 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4148 if (ports[portid].tx_dump_cb[queue]) {
4149 rte_eth_remove_tx_callback(portid, queue,
4150 ports[portid].tx_dump_cb[queue]);
4151 ports[portid].tx_dump_cb[queue] = NULL;
4156 configure_rxtx_dump_callbacks(uint16_t verbose)
4160 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4161 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
4165 RTE_ETH_FOREACH_DEV(portid)
4167 if (verbose == 1 || verbose > 2)
4168 add_rx_dump_callbacks(portid);
4170 remove_rx_dump_callbacks(portid);
4172 add_tx_dump_callbacks(portid);
4174 remove_tx_dump_callbacks(portid);
4179 set_verbose_level(uint16_t vb_level)
4181 printf("Change verbose level from %u to %u\n",
4182 (unsigned int) verbose_level, (unsigned int) vb_level);
4183 verbose_level = vb_level;
4184 configure_rxtx_dump_callbacks(verbose_level);
4188 vlan_extend_set(portid_t port_id, int on)
4192 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4194 if (port_id_is_invalid(port_id, ENABLED_WARN))
4197 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4200 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
4201 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
4203 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
4204 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
4207 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4210 "rx_vlan_extend_set(port_pi=%d, on=%d) failed diag=%d\n",
4214 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4218 rx_vlan_strip_set(portid_t port_id, int on)
4222 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4224 if (port_id_is_invalid(port_id, ENABLED_WARN))
4227 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4230 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
4231 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
4233 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
4234 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
4237 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4240 "%s(port_pi=%d, on=%d) failed diag=%d\n",
4241 __func__, port_id, on, diag);
4244 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4248 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
4252 if (port_id_is_invalid(port_id, ENABLED_WARN))
4255 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
4258 "%s(port_pi=%d, queue_id=%d, on=%d) failed diag=%d\n",
4259 __func__, port_id, queue_id, on, diag);
4263 rx_vlan_filter_set(portid_t port_id, int on)
4267 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4269 if (port_id_is_invalid(port_id, ENABLED_WARN))
4272 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4275 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
4276 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
4278 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
4279 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
4282 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4285 "%s(port_pi=%d, on=%d) failed diag=%d\n",
4286 __func__, port_id, on, diag);
4289 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4293 rx_vlan_qinq_strip_set(portid_t port_id, int on)
4297 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4299 if (port_id_is_invalid(port_id, ENABLED_WARN))
4302 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4305 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
4306 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
4308 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
4309 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
4312 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4314 fprintf(stderr, "%s(port_pi=%d, on=%d) failed diag=%d\n",
4315 __func__, port_id, on, diag);
4318 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4322 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
4326 if (port_id_is_invalid(port_id, ENABLED_WARN))
4328 if (vlan_id_is_invalid(vlan_id))
4330 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
4334 "rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed diag=%d\n",
4335 port_id, vlan_id, on, diag);
4340 rx_vlan_all_filter_set(portid_t port_id, int on)
4344 if (port_id_is_invalid(port_id, ENABLED_WARN))
4346 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
4347 if (rx_vft_set(port_id, vlan_id, on))
4353 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
4357 if (port_id_is_invalid(port_id, ENABLED_WARN))
4360 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
4365 "tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed diag=%d\n",
4366 port_id, vlan_type, tp_id, diag);
4370 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
4372 struct rte_eth_dev_info dev_info;
4375 if (vlan_id_is_invalid(vlan_id))
4378 if (ports[port_id].dev_conf.txmode.offloads &
4379 DEV_TX_OFFLOAD_QINQ_INSERT) {
4380 fprintf(stderr, "Error, as QinQ has been enabled.\n");
4384 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4388 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
4390 "Error: vlan insert is not supported by port %d\n",
4395 tx_vlan_reset(port_id);
4396 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
4397 ports[port_id].tx_vlan_id = vlan_id;
4401 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
4403 struct rte_eth_dev_info dev_info;
4406 if (vlan_id_is_invalid(vlan_id))
4408 if (vlan_id_is_invalid(vlan_id_outer))
4411 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4415 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
4417 "Error: qinq insert not supported by port %d\n",
4422 tx_vlan_reset(port_id);
4423 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
4424 DEV_TX_OFFLOAD_QINQ_INSERT);
4425 ports[port_id].tx_vlan_id = vlan_id;
4426 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
4430 tx_vlan_reset(portid_t port_id)
4432 ports[port_id].dev_conf.txmode.offloads &=
4433 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
4434 DEV_TX_OFFLOAD_QINQ_INSERT);
4435 ports[port_id].tx_vlan_id = 0;
4436 ports[port_id].tx_vlan_id_outer = 0;
4440 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
4442 if (port_id_is_invalid(port_id, ENABLED_WARN))
4445 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
4449 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
4453 if (port_id_is_invalid(port_id, ENABLED_WARN))
4456 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
4459 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
4460 fprintf(stderr, "map_value not in required range 0..%d\n",
4461 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
4465 if (!is_rx) { /* tx */
4466 ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, queue_id,
4470 "failed to set tx queue stats mapping.\n");
4474 ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, queue_id,
4478 "failed to set rx queue stats mapping.\n");
4485 set_xstats_hide_zero(uint8_t on_off)
4487 xstats_hide_zero = on_off;
4491 set_record_core_cycles(uint8_t on_off)
4493 record_core_cycles = on_off;
4497 set_record_burst_stats(uint8_t on_off)
4499 record_burst_stats = on_off;
4503 flowtype_to_str(uint16_t flow_type)
4505 struct flow_type_info {
4511 static struct flow_type_info flowtype_str_table[] = {
4512 {"raw", RTE_ETH_FLOW_RAW},
4513 {"ipv4", RTE_ETH_FLOW_IPV4},
4514 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
4515 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
4516 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
4517 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
4518 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
4519 {"ipv6", RTE_ETH_FLOW_IPV6},
4520 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
4521 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
4522 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
4523 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
4524 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
4525 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
4526 {"port", RTE_ETH_FLOW_PORT},
4527 {"vxlan", RTE_ETH_FLOW_VXLAN},
4528 {"geneve", RTE_ETH_FLOW_GENEVE},
4529 {"nvgre", RTE_ETH_FLOW_NVGRE},
4530 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
4533 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
4534 if (flowtype_str_table[i].ftype == flow_type)
4535 return flowtype_str_table[i].str;
4541 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
4544 print_fdir_mask(struct rte_eth_fdir_masks *mask)
4546 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
4548 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4549 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
4550 " tunnel_id: 0x%08x",
4551 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
4552 rte_be_to_cpu_32(mask->tunnel_id_mask));
4553 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
4554 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
4555 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
4556 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
4558 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
4559 rte_be_to_cpu_16(mask->src_port_mask),
4560 rte_be_to_cpu_16(mask->dst_port_mask));
4562 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4563 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
4564 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
4565 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
4566 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
4568 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4569 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
4570 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
4571 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
4572 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
4579 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4581 struct rte_eth_flex_payload_cfg *cfg;
4584 for (i = 0; i < flex_conf->nb_payloads; i++) {
4585 cfg = &flex_conf->flex_set[i];
4586 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
4588 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
4589 printf("\n L2_PAYLOAD: ");
4590 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
4591 printf("\n L3_PAYLOAD: ");
4592 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
4593 printf("\n L4_PAYLOAD: ");
4595 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
4596 for (j = 0; j < num; j++)
4597 printf(" %-5u", cfg->src_offset[j]);
4603 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4605 struct rte_eth_fdir_flex_mask *mask;
4609 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
4610 mask = &flex_conf->flex_mask[i];
4611 p = flowtype_to_str(mask->flow_type);
4612 printf("\n %s:\t", p ? p : "unknown");
4613 for (j = 0; j < num; j++)
4614 printf(" %02x", mask->mask[j]);
4620 print_fdir_flow_type(uint32_t flow_types_mask)
4625 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
4626 if (!(flow_types_mask & (1 << i)))
4628 p = flowtype_to_str(i);
4638 get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info,
4639 struct rte_eth_fdir_stats *fdir_stat)
4644 if (ret == -ENOTSUP) {
4645 ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info);
4647 ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat);
4650 #ifdef RTE_NET_IXGBE
4651 if (ret == -ENOTSUP) {
4652 ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info);
4654 ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat);
4661 fprintf(stderr, "\n FDIR is not supported on port %-2d\n",
4665 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
4672 fdir_get_infos(portid_t port_id)
4674 struct rte_eth_fdir_stats fdir_stat;
4675 struct rte_eth_fdir_info fdir_info;
4677 static const char *fdir_stats_border = "########################";
4679 if (port_id_is_invalid(port_id, ENABLED_WARN))
4682 memset(&fdir_info, 0, sizeof(fdir_info));
4683 memset(&fdir_stat, 0, sizeof(fdir_stat));
4684 if (get_fdir_info(port_id, &fdir_info, &fdir_stat))
4687 printf("\n %s FDIR infos for port %-2d %s\n",
4688 fdir_stats_border, port_id, fdir_stats_border);
4690 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
4691 printf(" PERFECT\n");
4692 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
4693 printf(" PERFECT-MAC-VLAN\n");
4694 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4695 printf(" PERFECT-TUNNEL\n");
4696 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
4697 printf(" SIGNATURE\n");
4699 printf(" DISABLE\n");
4700 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
4701 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
4702 printf(" SUPPORTED FLOW TYPE: ");
4703 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
4705 printf(" FLEX PAYLOAD INFO:\n");
4706 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
4707 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
4708 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
4709 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
4710 fdir_info.flex_payload_unit,
4711 fdir_info.max_flex_payload_segment_num,
4712 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
4714 print_fdir_mask(&fdir_info.mask);
4715 if (fdir_info.flex_conf.nb_payloads > 0) {
4716 printf(" FLEX PAYLOAD SRC OFFSET:");
4717 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4719 if (fdir_info.flex_conf.nb_flexmasks > 0) {
4720 printf(" FLEX MASK CFG:");
4721 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4723 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
4724 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
4725 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
4726 fdir_info.guarant_spc, fdir_info.best_spc);
4727 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
4728 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
4729 " add: %-10"PRIu64" remove: %"PRIu64"\n"
4730 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
4731 fdir_stat.collision, fdir_stat.free,
4732 fdir_stat.maxhash, fdir_stat.maxlen,
4733 fdir_stat.add, fdir_stat.remove,
4734 fdir_stat.f_add, fdir_stat.f_remove);
4735 printf(" %s############################%s\n",
4736 fdir_stats_border, fdir_stats_border);
4739 #endif /* RTE_NET_I40E || RTE_NET_IXGBE */
4742 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
4744 struct rte_port *port;
4745 struct rte_eth_fdir_flex_conf *flex_conf;
4748 port = &ports[port_id];
4749 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
4750 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
4751 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
4756 if (i >= RTE_ETH_FLOW_MAX) {
4757 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
4758 idx = flex_conf->nb_flexmasks;
4759 flex_conf->nb_flexmasks++;
4762 "The flex mask table is full. Can not set flex mask for flow_type(%u).",
4767 rte_memcpy(&flex_conf->flex_mask[idx],
4769 sizeof(struct rte_eth_fdir_flex_mask));
4773 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
4775 struct rte_port *port;
4776 struct rte_eth_fdir_flex_conf *flex_conf;
4779 port = &ports[port_id];
4780 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
4781 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
4782 if (cfg->type == flex_conf->flex_set[i].type) {
4787 if (i >= RTE_ETH_PAYLOAD_MAX) {
4788 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
4789 idx = flex_conf->nb_payloads;
4790 flex_conf->nb_payloads++;
4793 "The flex payload table is full. Can not set flex payload for type(%u).",
4798 rte_memcpy(&flex_conf->flex_set[idx],
4800 sizeof(struct rte_eth_flex_payload_cfg));
4805 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
4807 #ifdef RTE_NET_IXGBE
4811 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
4813 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
4818 "rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
4819 is_rx ? "rx" : "tx", port_id, diag);
4822 fprintf(stderr, "VF %s setting not supported for port %d\n",
4823 is_rx ? "Rx" : "Tx", port_id);
4829 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
4832 struct rte_eth_link link;
4835 if (port_id_is_invalid(port_id, ENABLED_WARN))
4837 ret = eth_link_get_nowait_print_err(port_id, &link);
4840 if (link.link_speed != ETH_SPEED_NUM_UNKNOWN &&
4841 rate > link.link_speed) {
4843 "Invalid rate value:%u bigger than link speed: %u\n",
4844 rate, link.link_speed);
4847 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
4851 "rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
4857 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
4859 int diag = -ENOTSUP;
4863 RTE_SET_USED(q_msk);
4865 #ifdef RTE_NET_IXGBE
4866 if (diag == -ENOTSUP)
4867 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
4871 if (diag == -ENOTSUP)
4872 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
4878 "%s for port_id=%d failed diag=%d\n",
4879 __func__, port_id, diag);
4884 * Functions to manage the set of filtered Multicast MAC addresses.
4886 * A pool of filtered multicast MAC addresses is associated with each port.
4887 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
4888 * The address of the pool and the number of valid multicast MAC addresses
4889 * recorded in the pool are stored in the fields "mc_addr_pool" and
4890 * "mc_addr_nb" of the "rte_port" data structure.
4892 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
4893 * to be supplied a contiguous array of multicast MAC addresses.
4894 * To comply with this constraint, the set of multicast addresses recorded
4895 * into the pool are systematically compacted at the beginning of the pool.
4896 * Hence, when a multicast address is removed from the pool, all following
4897 * addresses, if any, are copied back to keep the set contiguous.
4899 #define MCAST_POOL_INC 32
4902 mcast_addr_pool_extend(struct rte_port *port)
4904 struct rte_ether_addr *mc_pool;
4905 size_t mc_pool_size;
4908 * If a free entry is available at the end of the pool, just
4909 * increment the number of recorded multicast addresses.
4911 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
4917 * [re]allocate a pool with MCAST_POOL_INC more entries.
4918 * The previous test guarantees that port->mc_addr_nb is a multiple
4919 * of MCAST_POOL_INC.
4921 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
4923 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
4925 if (mc_pool == NULL) {
4927 "allocation of pool of %u multicast addresses failed\n",
4928 port->mc_addr_nb + MCAST_POOL_INC);
4932 port->mc_addr_pool = mc_pool;
4939 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
4941 if (mcast_addr_pool_extend(port) != 0)
4943 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
4947 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
4950 if (addr_idx == port->mc_addr_nb) {
4951 /* No need to recompact the set of multicast addressses. */
4952 if (port->mc_addr_nb == 0) {
4953 /* free the pool of multicast addresses. */
4954 free(port->mc_addr_pool);
4955 port->mc_addr_pool = NULL;
4959 memmove(&port->mc_addr_pool[addr_idx],
4960 &port->mc_addr_pool[addr_idx + 1],
4961 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
4965 eth_port_multicast_addr_list_set(portid_t port_id)
4967 struct rte_port *port;
4970 port = &ports[port_id];
4971 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
4975 "rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
4976 port_id, port->mc_addr_nb, diag);
4982 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
4984 struct rte_port *port;
4987 if (port_id_is_invalid(port_id, ENABLED_WARN))
4990 port = &ports[port_id];
4993 * Check that the added multicast MAC address is not already recorded
4994 * in the pool of multicast addresses.
4996 for (i = 0; i < port->mc_addr_nb; i++) {
4997 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
4999 "multicast address already filtered by port\n");
5004 mcast_addr_pool_append(port, mc_addr);
5005 if (eth_port_multicast_addr_list_set(port_id) < 0)
5006 /* Rollback on failure, remove the address from the pool */
5007 mcast_addr_pool_remove(port, i);
5011 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
5013 struct rte_port *port;
5016 if (port_id_is_invalid(port_id, ENABLED_WARN))
5019 port = &ports[port_id];
5022 * Search the pool of multicast MAC addresses for the removed address.
5024 for (i = 0; i < port->mc_addr_nb; i++) {
5025 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
5028 if (i == port->mc_addr_nb) {
5029 fprintf(stderr, "multicast address not filtered by port %d\n",
5034 mcast_addr_pool_remove(port, i);
5035 if (eth_port_multicast_addr_list_set(port_id) < 0)
5036 /* Rollback on failure, add the address back into the pool */
5037 mcast_addr_pool_append(port, mc_addr);
5041 port_dcb_info_display(portid_t port_id)
5043 struct rte_eth_dcb_info dcb_info;
5046 static const char *border = "================";
5048 if (port_id_is_invalid(port_id, ENABLED_WARN))
5051 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
5053 fprintf(stderr, "\n Failed to get dcb infos on port %-2d\n",
5057 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
5058 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
5060 for (i = 0; i < dcb_info.nb_tcs; i++)
5062 printf("\n Priority : ");
5063 for (i = 0; i < dcb_info.nb_tcs; i++)
5064 printf("\t%4d", dcb_info.prio_tc[i]);
5065 printf("\n BW percent :");
5066 for (i = 0; i < dcb_info.nb_tcs; i++)
5067 printf("\t%4d%%", dcb_info.tc_bws[i]);
5068 printf("\n RXQ base : ");
5069 for (i = 0; i < dcb_info.nb_tcs; i++)
5070 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
5071 printf("\n RXQ number :");
5072 for (i = 0; i < dcb_info.nb_tcs; i++)
5073 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
5074 printf("\n TXQ base : ");
5075 for (i = 0; i < dcb_info.nb_tcs; i++)
5076 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
5077 printf("\n TXQ number :");
5078 for (i = 0; i < dcb_info.nb_tcs; i++)
5079 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
5084 open_file(const char *file_path, uint32_t *size)
5086 int fd = open(file_path, O_RDONLY);
5088 uint8_t *buf = NULL;
5096 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
5100 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
5102 fprintf(stderr, "%s: File operations failed\n", __func__);
5106 pkg_size = st_buf.st_size;
5109 fprintf(stderr, "%s: File operations failed\n", __func__);
5113 buf = (uint8_t *)malloc(pkg_size);
5116 fprintf(stderr, "%s: Failed to malloc memory\n", __func__);
5120 ret = read(fd, buf, pkg_size);
5123 fprintf(stderr, "%s: File read operation failed\n", __func__);
5137 save_file(const char *file_path, uint8_t *buf, uint32_t size)
5139 FILE *fh = fopen(file_path, "wb");
5142 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
5146 if (fwrite(buf, 1, size, fh) != size) {
5148 fprintf(stderr, "%s: File write operation failed\n", __func__);
5158 close_file(uint8_t *buf)
5169 port_queue_region_info_display(portid_t port_id, void *buf)
5173 struct rte_pmd_i40e_queue_regions *info =
5174 (struct rte_pmd_i40e_queue_regions *)buf;
5175 static const char *queue_region_info_stats_border = "-------";
5177 if (!info->queue_region_number)
5178 printf("there is no region has been set before");
5180 printf("\n %s All queue region info for port=%2d %s",
5181 queue_region_info_stats_border, port_id,
5182 queue_region_info_stats_border);
5183 printf("\n queue_region_number: %-14u \n",
5184 info->queue_region_number);
5186 for (i = 0; i < info->queue_region_number; i++) {
5187 printf("\n region_id: %-14u queue_number: %-14u "
5188 "queue_start_index: %-14u \n",
5189 info->region[i].region_id,
5190 info->region[i].queue_num,
5191 info->region[i].queue_start_index);
5193 printf(" user_priority_num is %-14u :",
5194 info->region[i].user_priority_num);
5195 for (j = 0; j < info->region[i].user_priority_num; j++)
5196 printf(" %-14u ", info->region[i].user_priority[j]);
5198 printf("\n flowtype_num is %-14u :",
5199 info->region[i].flowtype_num);
5200 for (j = 0; j < info->region[i].flowtype_num; j++)
5201 printf(" %-14u ", info->region[i].hw_flowtype[j]);
5204 RTE_SET_USED(port_id);
5212 show_macs(portid_t port_id)
5214 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5215 struct rte_eth_dev_info dev_info;
5216 struct rte_ether_addr *addr;
5217 uint32_t i, num_macs = 0;
5218 struct rte_eth_dev *dev;
5220 dev = &rte_eth_devices[port_id];
5222 if (eth_dev_info_get_print_err(port_id, &dev_info))
5225 for (i = 0; i < dev_info.max_mac_addrs; i++) {
5226 addr = &dev->data->mac_addrs[i];
5228 /* skip zero address */
5229 if (rte_is_zero_ether_addr(addr))
5235 printf("Number of MAC address added: %d\n", num_macs);
5237 for (i = 0; i < dev_info.max_mac_addrs; i++) {
5238 addr = &dev->data->mac_addrs[i];
5240 /* skip zero address */
5241 if (rte_is_zero_ether_addr(addr))
5244 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5245 printf(" %s\n", buf);
5250 show_mcast_macs(portid_t port_id)
5252 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5253 struct rte_ether_addr *addr;
5254 struct rte_port *port;
5257 port = &ports[port_id];
5259 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
5261 for (i = 0; i < port->mc_addr_nb; i++) {
5262 addr = &port->mc_addr_pool[i];
5264 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5265 printf(" %s\n", buf);