1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation.
3 * Copyright 2013-2014 6WIND S.A.
13 #include <sys/queue.h>
14 #include <sys/types.h>
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_debug.h>
23 #include <rte_memory.h>
24 #include <rte_memcpy.h>
25 #include <rte_memzone.h>
26 #include <rte_launch.h>
28 #include <rte_per_lcore.h>
29 #include <rte_lcore.h>
30 #include <rte_atomic.h>
31 #include <rte_branch_prediction.h>
32 #include <rte_mempool.h>
34 #include <rte_interrupts.h>
36 #include <rte_ether.h>
37 #include <rte_ethdev.h>
38 #include <rte_string_fns.h>
39 #include <rte_cycles.h>
41 #include <rte_errno.h>
43 #include <rte_pmd_ixgbe.h>
46 #include <rte_pmd_i40e.h>
49 #include <rte_pmd_bnxt.h>
52 #include <rte_hexdump.h>
56 #define ETHDEV_FWVERS_LEN 32
58 #ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
59 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
61 #define CLOCK_TYPE_ID CLOCK_MONOTONIC
64 #define NS_PER_SEC 1E9
66 static char *flowtype_to_str(uint16_t flow_type);
69 enum tx_pkt_split split;
73 .split = TX_PKT_SPLIT_OFF,
77 .split = TX_PKT_SPLIT_ON,
81 .split = TX_PKT_SPLIT_RND,
86 const struct rss_type_info rss_type_table[] = {
87 { "all", ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP | ETH_RSS_TCP |
88 ETH_RSS_UDP | ETH_RSS_SCTP | ETH_RSS_L2_PAYLOAD |
89 ETH_RSS_L2TPV3 | ETH_RSS_ESP | ETH_RSS_AH | ETH_RSS_PFCP |
90 ETH_RSS_GTPU | ETH_RSS_ECPRI},
92 { "eth", ETH_RSS_ETH },
93 { "l2-src-only", ETH_RSS_L2_SRC_ONLY },
94 { "l2-dst-only", ETH_RSS_L2_DST_ONLY },
95 { "vlan", ETH_RSS_VLAN },
96 { "s-vlan", ETH_RSS_S_VLAN },
97 { "c-vlan", ETH_RSS_C_VLAN },
98 { "ipv4", ETH_RSS_IPV4 },
99 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
100 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
101 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
102 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
103 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
104 { "ipv6", ETH_RSS_IPV6 },
105 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
106 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
107 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
108 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
109 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
110 { "l2-payload", ETH_RSS_L2_PAYLOAD },
111 { "ipv6-ex", ETH_RSS_IPV6_EX },
112 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
113 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
114 { "port", ETH_RSS_PORT },
115 { "vxlan", ETH_RSS_VXLAN },
116 { "geneve", ETH_RSS_GENEVE },
117 { "nvgre", ETH_RSS_NVGRE },
118 { "ip", ETH_RSS_IP },
119 { "udp", ETH_RSS_UDP },
120 { "tcp", ETH_RSS_TCP },
121 { "sctp", ETH_RSS_SCTP },
122 { "tunnel", ETH_RSS_TUNNEL },
123 { "l3-pre32", RTE_ETH_RSS_L3_PRE32 },
124 { "l3-pre40", RTE_ETH_RSS_L3_PRE40 },
125 { "l3-pre48", RTE_ETH_RSS_L3_PRE48 },
126 { "l3-pre56", RTE_ETH_RSS_L3_PRE56 },
127 { "l3-pre64", RTE_ETH_RSS_L3_PRE64 },
128 { "l3-pre96", RTE_ETH_RSS_L3_PRE96 },
129 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
130 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
131 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
132 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
133 { "esp", ETH_RSS_ESP },
134 { "ah", ETH_RSS_AH },
135 { "l2tpv3", ETH_RSS_L2TPV3 },
136 { "pfcp", ETH_RSS_PFCP },
137 { "pppoe", ETH_RSS_PPPOE },
138 { "gtpu", ETH_RSS_GTPU },
139 { "ecpri", ETH_RSS_ECPRI },
143 static const struct {
144 enum rte_eth_fec_mode mode;
146 } fec_mode_name[] = {
148 .mode = RTE_ETH_FEC_NOFEC,
152 .mode = RTE_ETH_FEC_AUTO,
156 .mode = RTE_ETH_FEC_BASER,
160 .mode = RTE_ETH_FEC_RS,
166 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
168 char buf[RTE_ETHER_ADDR_FMT_SIZE];
169 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
170 printf("%s%s", name, buf);
174 nic_stats_display(portid_t port_id)
176 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
177 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
178 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
179 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
180 static uint64_t prev_ns[RTE_MAX_ETHPORTS];
181 struct timespec cur_time;
182 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
184 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
185 struct rte_eth_stats stats;
187 static const char *nic_stats_border = "########################";
189 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
193 rte_eth_stats_get(port_id, &stats);
194 printf("\n %s NIC statistics for port %-2d %s\n",
195 nic_stats_border, port_id, nic_stats_border);
197 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
198 "%-"PRIu64"\n", stats.ipackets, stats.imissed, stats.ibytes);
199 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
200 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
201 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
202 "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
205 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
208 ns = cur_time.tv_sec * NS_PER_SEC;
209 ns += cur_time.tv_nsec;
211 if (prev_ns[port_id] != 0)
212 diff_ns = ns - prev_ns[port_id];
213 prev_ns[port_id] = ns;
216 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
217 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
218 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
219 (stats.opackets - prev_pkts_tx[port_id]) : 0;
220 prev_pkts_rx[port_id] = stats.ipackets;
221 prev_pkts_tx[port_id] = stats.opackets;
222 mpps_rx = diff_ns > 0 ?
223 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
224 mpps_tx = diff_ns > 0 ?
225 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
227 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
228 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
229 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
230 (stats.obytes - prev_bytes_tx[port_id]) : 0;
231 prev_bytes_rx[port_id] = stats.ibytes;
232 prev_bytes_tx[port_id] = stats.obytes;
233 mbps_rx = diff_ns > 0 ?
234 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
235 mbps_tx = diff_ns > 0 ?
236 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
238 printf("\n Throughput (since last show)\n");
239 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
240 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
241 mpps_tx, mbps_tx * 8);
243 printf(" %s############################%s\n",
244 nic_stats_border, nic_stats_border);
248 nic_stats_clear(portid_t port_id)
252 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
257 ret = rte_eth_stats_reset(port_id);
259 printf("%s: Error: failed to reset stats (port %u): %s",
260 __func__, port_id, strerror(-ret));
264 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
268 printf("%s: Error: failed to get stats (port %u): %s",
269 __func__, port_id, strerror(ret));
272 printf("\n NIC statistics for port %d cleared\n", port_id);
276 nic_xstats_display(portid_t port_id)
278 struct rte_eth_xstat *xstats;
279 int cnt_xstats, idx_xstat;
280 struct rte_eth_xstat_name *xstats_names;
282 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
286 printf("###### NIC extended statistics for port %-2d\n", port_id);
287 if (!rte_eth_dev_is_valid_port(port_id)) {
288 printf("Error: Invalid port number %i\n", port_id);
293 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
294 if (cnt_xstats < 0) {
295 printf("Error: Cannot get count of xstats\n");
299 /* Get id-name lookup table */
300 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
301 if (xstats_names == NULL) {
302 printf("Cannot allocate memory for xstats lookup\n");
305 if (cnt_xstats != rte_eth_xstats_get_names(
306 port_id, xstats_names, cnt_xstats)) {
307 printf("Error: Cannot get xstats lookup\n");
312 /* Get stats themselves */
313 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
314 if (xstats == NULL) {
315 printf("Cannot allocate memory for xstats\n");
319 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
320 printf("Error: Unable to get xstats\n");
327 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
328 if (xstats_hide_zero && !xstats[idx_xstat].value)
330 printf("%s: %"PRIu64"\n",
331 xstats_names[idx_xstat].name,
332 xstats[idx_xstat].value);
339 nic_xstats_clear(portid_t port_id)
343 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
348 ret = rte_eth_xstats_reset(port_id);
350 printf("%s: Error: failed to reset xstats (port %u): %s",
351 __func__, port_id, strerror(-ret));
355 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
359 printf("%s: Error: failed to get stats (port %u): %s",
360 __func__, port_id, strerror(ret));
366 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
368 struct rte_eth_burst_mode mode;
369 struct rte_eth_rxq_info qinfo;
371 static const char *info_border = "*********************";
373 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
375 printf("Failed to retrieve information for port: %u, "
376 "RX queue: %hu\nerror desc: %s(%d)\n",
377 port_id, queue_id, strerror(-rc), rc);
381 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
382 info_border, port_id, queue_id, info_border);
384 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
385 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
386 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
387 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
388 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
389 printf("\nRX drop packets: %s",
390 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
391 printf("\nRX deferred start: %s",
392 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
393 printf("\nRX scattered packets: %s",
394 (qinfo.scattered_rx != 0) ? "on" : "off");
395 if (qinfo.rx_buf_size != 0)
396 printf("\nRX buffer size: %hu", qinfo.rx_buf_size);
397 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
399 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
400 printf("\nBurst mode: %s%s",
402 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
403 " (per queue)" : "");
409 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
411 struct rte_eth_burst_mode mode;
412 struct rte_eth_txq_info qinfo;
414 static const char *info_border = "*********************";
416 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
418 printf("Failed to retrieve information for port: %u, "
419 "TX queue: %hu\nerror desc: %s(%d)\n",
420 port_id, queue_id, strerror(-rc), rc);
424 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
425 info_border, port_id, queue_id, info_border);
427 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
428 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
429 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
430 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
431 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
432 printf("\nTX deferred start: %s",
433 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
434 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
436 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
437 printf("\nBurst mode: %s%s",
439 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
440 " (per queue)" : "");
445 static int bus_match_all(const struct rte_bus *bus, const void *data)
453 device_infos_display_speeds(uint32_t speed_capa)
455 printf("\n\tDevice speed capability:");
456 if (speed_capa == ETH_LINK_SPEED_AUTONEG)
457 printf(" Autonegotiate (all speeds)");
458 if (speed_capa & ETH_LINK_SPEED_FIXED)
459 printf(" Disable autonegotiate (fixed speed) ");
460 if (speed_capa & ETH_LINK_SPEED_10M_HD)
461 printf(" 10 Mbps half-duplex ");
462 if (speed_capa & ETH_LINK_SPEED_10M)
463 printf(" 10 Mbps full-duplex ");
464 if (speed_capa & ETH_LINK_SPEED_100M_HD)
465 printf(" 100 Mbps half-duplex ");
466 if (speed_capa & ETH_LINK_SPEED_100M)
467 printf(" 100 Mbps full-duplex ");
468 if (speed_capa & ETH_LINK_SPEED_1G)
470 if (speed_capa & ETH_LINK_SPEED_2_5G)
471 printf(" 2.5 Gbps ");
472 if (speed_capa & ETH_LINK_SPEED_5G)
474 if (speed_capa & ETH_LINK_SPEED_10G)
476 if (speed_capa & ETH_LINK_SPEED_20G)
478 if (speed_capa & ETH_LINK_SPEED_25G)
480 if (speed_capa & ETH_LINK_SPEED_40G)
482 if (speed_capa & ETH_LINK_SPEED_50G)
484 if (speed_capa & ETH_LINK_SPEED_56G)
486 if (speed_capa & ETH_LINK_SPEED_100G)
487 printf(" 100 Gbps ");
488 if (speed_capa & ETH_LINK_SPEED_200G)
489 printf(" 200 Gbps ");
493 device_infos_display(const char *identifier)
495 static const char *info_border = "*********************";
496 struct rte_bus *start = NULL, *next;
497 struct rte_dev_iterator dev_iter;
498 char name[RTE_ETH_NAME_MAX_LEN];
499 struct rte_ether_addr mac_addr;
500 struct rte_device *dev;
501 struct rte_devargs da;
503 struct rte_eth_dev_info dev_info;
506 memset(&da, 0, sizeof(da));
510 if (rte_devargs_parsef(&da, "%s", identifier)) {
511 printf("cannot parse identifier\n");
518 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
521 if (identifier && da.bus != next)
524 /* Skip buses that don't have iterate method */
525 if (!next->dev_iterate)
528 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
529 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
533 /* Check for matching device if identifier is present */
535 strncmp(da.name, dev->name, strlen(dev->name)))
537 printf("\n%s Infos for device %s %s\n",
538 info_border, dev->name, info_border);
539 printf("Bus name: %s", dev->bus->name);
540 printf("\nDriver name: %s", dev->driver->name);
541 printf("\nDevargs: %s",
542 dev->devargs ? dev->devargs->args : "");
543 printf("\nConnect to socket: %d", dev->numa_node);
546 /* List ports with matching device name */
547 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
548 printf("\n\tPort id: %-2d", port_id);
549 if (eth_macaddr_get_print_err(port_id,
551 print_ethaddr("\n\tMAC address: ",
553 rte_eth_dev_get_name_by_port(port_id, name);
554 printf("\n\tDevice name: %s", name);
555 if (rte_eth_dev_info_get(port_id, &dev_info) == 0)
556 device_infos_display_speeds(dev_info.speed_capa);
564 port_infos_display(portid_t port_id)
566 struct rte_port *port;
567 struct rte_ether_addr mac_addr;
568 struct rte_eth_link link;
569 struct rte_eth_dev_info dev_info;
571 struct rte_mempool * mp;
572 static const char *info_border = "*********************";
574 char name[RTE_ETH_NAME_MAX_LEN];
576 char fw_version[ETHDEV_FWVERS_LEN];
578 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
582 port = &ports[port_id];
583 ret = eth_link_get_nowait_print_err(port_id, &link);
587 ret = eth_dev_info_get_print_err(port_id, &dev_info);
591 printf("\n%s Infos for port %-2d %s\n",
592 info_border, port_id, info_border);
593 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
594 print_ethaddr("MAC address: ", &mac_addr);
595 rte_eth_dev_get_name_by_port(port_id, name);
596 printf("\nDevice name: %s", name);
597 printf("\nDriver name: %s", dev_info.driver_name);
599 if (rte_eth_dev_fw_version_get(port_id, fw_version,
600 ETHDEV_FWVERS_LEN) == 0)
601 printf("\nFirmware-version: %s", fw_version);
603 printf("\nFirmware-version: %s", "not available");
605 if (dev_info.device->devargs && dev_info.device->devargs->args)
606 printf("\nDevargs: %s", dev_info.device->devargs->args);
607 printf("\nConnect to socket: %u", port->socket_id);
609 if (port_numa[port_id] != NUMA_NO_CONFIG) {
610 mp = mbuf_pool_find(port_numa[port_id], 0);
612 printf("\nmemory allocation on the socket: %d",
615 printf("\nmemory allocation on the socket: %u",port->socket_id);
617 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
618 printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
619 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
620 ("full-duplex") : ("half-duplex"));
622 if (!rte_eth_dev_get_mtu(port_id, &mtu))
623 printf("MTU: %u\n", mtu);
625 printf("Promiscuous mode: %s\n",
626 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
627 printf("Allmulticast mode: %s\n",
628 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
629 printf("Maximum number of MAC addresses: %u\n",
630 (unsigned int)(port->dev_info.max_mac_addrs));
631 printf("Maximum number of MAC addresses of hash filtering: %u\n",
632 (unsigned int)(port->dev_info.max_hash_mac_addrs));
634 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
635 if (vlan_offload >= 0){
636 printf("VLAN offload: \n");
637 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
638 printf(" strip on, ");
640 printf(" strip off, ");
642 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
643 printf("filter on, ");
645 printf("filter off, ");
647 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
648 printf("extend on, ");
650 printf("extend off, ");
652 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
653 printf("qinq strip on\n");
655 printf("qinq strip off\n");
658 if (dev_info.hash_key_size > 0)
659 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
660 if (dev_info.reta_size > 0)
661 printf("Redirection table size: %u\n", dev_info.reta_size);
662 if (!dev_info.flow_type_rss_offloads)
663 printf("No RSS offload flow type is supported.\n");
668 printf("Supported RSS offload flow types:\n");
669 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
670 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
671 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
673 p = flowtype_to_str(i);
677 printf(" user defined %d\n", i);
681 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
682 printf("Maximum configurable length of RX packet: %u\n",
683 dev_info.max_rx_pktlen);
684 printf("Maximum configurable size of LRO aggregated packet: %u\n",
685 dev_info.max_lro_pkt_size);
686 if (dev_info.max_vfs)
687 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
688 if (dev_info.max_vmdq_pools)
689 printf("Maximum number of VMDq pools: %u\n",
690 dev_info.max_vmdq_pools);
692 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
693 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
694 printf("Max possible number of RXDs per queue: %hu\n",
695 dev_info.rx_desc_lim.nb_max);
696 printf("Min possible number of RXDs per queue: %hu\n",
697 dev_info.rx_desc_lim.nb_min);
698 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
700 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
701 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
702 printf("Max possible number of TXDs per queue: %hu\n",
703 dev_info.tx_desc_lim.nb_max);
704 printf("Min possible number of TXDs per queue: %hu\n",
705 dev_info.tx_desc_lim.nb_min);
706 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
707 printf("Max segment number per packet: %hu\n",
708 dev_info.tx_desc_lim.nb_seg_max);
709 printf("Max segment number per MTU/TSO: %hu\n",
710 dev_info.tx_desc_lim.nb_mtu_seg_max);
712 /* Show switch info only if valid switch domain and port id is set */
713 if (dev_info.switch_info.domain_id !=
714 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
715 if (dev_info.switch_info.name)
716 printf("Switch name: %s\n", dev_info.switch_info.name);
718 printf("Switch domain Id: %u\n",
719 dev_info.switch_info.domain_id);
720 printf("Switch Port Id: %u\n",
721 dev_info.switch_info.port_id);
726 port_summary_header_display(void)
728 uint16_t port_number;
730 port_number = rte_eth_dev_count_avail();
731 printf("Number of available ports: %i\n", port_number);
732 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
733 "Driver", "Status", "Link");
737 port_summary_display(portid_t port_id)
739 struct rte_ether_addr mac_addr;
740 struct rte_eth_link link;
741 struct rte_eth_dev_info dev_info;
742 char name[RTE_ETH_NAME_MAX_LEN];
745 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
750 ret = eth_link_get_nowait_print_err(port_id, &link);
754 ret = eth_dev_info_get_print_err(port_id, &dev_info);
758 rte_eth_dev_get_name_by_port(port_id, name);
759 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
763 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %s\n",
764 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
765 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
766 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
767 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
768 rte_eth_link_speed_to_str(link.link_speed));
772 port_eeprom_display(portid_t port_id)
774 struct rte_dev_eeprom_info einfo;
776 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
781 int len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
782 if (len_eeprom < 0) {
783 switch (len_eeprom) {
785 printf("port index %d invalid\n", port_id);
788 printf("operation not supported by device\n");
791 printf("device is removed\n");
794 printf("Unable to get EEPROM: %d\n", len_eeprom);
800 char buf[len_eeprom];
802 einfo.length = len_eeprom;
805 ret = rte_eth_dev_get_eeprom(port_id, &einfo);
809 printf("port index %d invalid\n", port_id);
812 printf("operation not supported by device\n");
815 printf("device is removed\n");
818 printf("Unable to get EEPROM: %d\n", ret);
823 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
824 printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
828 port_module_eeprom_display(portid_t port_id)
830 struct rte_eth_dev_module_info minfo;
831 struct rte_dev_eeprom_info einfo;
834 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
840 ret = rte_eth_dev_get_module_info(port_id, &minfo);
844 printf("port index %d invalid\n", port_id);
847 printf("operation not supported by device\n");
850 printf("device is removed\n");
853 printf("Unable to get module EEPROM: %d\n", ret);
859 char buf[minfo.eeprom_len];
861 einfo.length = minfo.eeprom_len;
864 ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
868 printf("port index %d invalid\n", port_id);
871 printf("operation not supported by device\n");
874 printf("device is removed\n");
877 printf("Unable to get module EEPROM: %d\n", ret);
883 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
884 printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
888 port_offload_cap_display(portid_t port_id)
890 struct rte_eth_dev_info dev_info;
891 static const char *info_border = "************";
894 if (port_id_is_invalid(port_id, ENABLED_WARN))
897 ret = eth_dev_info_get_print_err(port_id, &dev_info);
901 printf("\n%s Port %d supported offload features: %s\n",
902 info_border, port_id, info_border);
904 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
905 printf("VLAN stripped: ");
906 if (ports[port_id].dev_conf.rxmode.offloads &
907 DEV_RX_OFFLOAD_VLAN_STRIP)
913 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
914 printf("Double VLANs stripped: ");
915 if (ports[port_id].dev_conf.rxmode.offloads &
916 DEV_RX_OFFLOAD_QINQ_STRIP)
922 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
923 printf("RX IPv4 checksum: ");
924 if (ports[port_id].dev_conf.rxmode.offloads &
925 DEV_RX_OFFLOAD_IPV4_CKSUM)
931 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
932 printf("RX UDP checksum: ");
933 if (ports[port_id].dev_conf.rxmode.offloads &
934 DEV_RX_OFFLOAD_UDP_CKSUM)
940 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
941 printf("RX TCP checksum: ");
942 if (ports[port_id].dev_conf.rxmode.offloads &
943 DEV_RX_OFFLOAD_TCP_CKSUM)
949 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) {
950 printf("RX SCTP checksum: ");
951 if (ports[port_id].dev_conf.rxmode.offloads &
952 DEV_RX_OFFLOAD_SCTP_CKSUM)
958 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
959 printf("RX Outer IPv4 checksum: ");
960 if (ports[port_id].dev_conf.rxmode.offloads &
961 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
967 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) {
968 printf("RX Outer UDP checksum: ");
969 if (ports[port_id].dev_conf.rxmode.offloads &
970 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM)
976 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
977 printf("Large receive offload: ");
978 if (ports[port_id].dev_conf.rxmode.offloads &
979 DEV_RX_OFFLOAD_TCP_LRO)
985 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
986 printf("HW timestamp: ");
987 if (ports[port_id].dev_conf.rxmode.offloads &
988 DEV_RX_OFFLOAD_TIMESTAMP)
994 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) {
995 printf("Rx Keep CRC: ");
996 if (ports[port_id].dev_conf.rxmode.offloads &
997 DEV_RX_OFFLOAD_KEEP_CRC)
1003 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) {
1004 printf("RX offload security: ");
1005 if (ports[port_id].dev_conf.rxmode.offloads &
1006 DEV_RX_OFFLOAD_SECURITY)
1012 if (dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) {
1013 printf("RX offload buffer split: ");
1014 if (ports[port_id].dev_conf.rxmode.offloads &
1015 RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)
1021 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
1022 printf("VLAN insert: ");
1023 if (ports[port_id].dev_conf.txmode.offloads &
1024 DEV_TX_OFFLOAD_VLAN_INSERT)
1030 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
1031 printf("Double VLANs insert: ");
1032 if (ports[port_id].dev_conf.txmode.offloads &
1033 DEV_TX_OFFLOAD_QINQ_INSERT)
1039 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
1040 printf("TX IPv4 checksum: ");
1041 if (ports[port_id].dev_conf.txmode.offloads &
1042 DEV_TX_OFFLOAD_IPV4_CKSUM)
1048 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
1049 printf("TX UDP checksum: ");
1050 if (ports[port_id].dev_conf.txmode.offloads &
1051 DEV_TX_OFFLOAD_UDP_CKSUM)
1057 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
1058 printf("TX TCP checksum: ");
1059 if (ports[port_id].dev_conf.txmode.offloads &
1060 DEV_TX_OFFLOAD_TCP_CKSUM)
1066 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
1067 printf("TX SCTP checksum: ");
1068 if (ports[port_id].dev_conf.txmode.offloads &
1069 DEV_TX_OFFLOAD_SCTP_CKSUM)
1075 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
1076 printf("TX Outer IPv4 checksum: ");
1077 if (ports[port_id].dev_conf.txmode.offloads &
1078 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
1084 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
1085 printf("TX TCP segmentation: ");
1086 if (ports[port_id].dev_conf.txmode.offloads &
1087 DEV_TX_OFFLOAD_TCP_TSO)
1093 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
1094 printf("TX UDP segmentation: ");
1095 if (ports[port_id].dev_conf.txmode.offloads &
1096 DEV_TX_OFFLOAD_UDP_TSO)
1102 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
1103 printf("TSO for VXLAN tunnel packet: ");
1104 if (ports[port_id].dev_conf.txmode.offloads &
1105 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
1111 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
1112 printf("TSO for GRE tunnel packet: ");
1113 if (ports[port_id].dev_conf.txmode.offloads &
1114 DEV_TX_OFFLOAD_GRE_TNL_TSO)
1120 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
1121 printf("TSO for IPIP tunnel packet: ");
1122 if (ports[port_id].dev_conf.txmode.offloads &
1123 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
1129 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
1130 printf("TSO for GENEVE tunnel packet: ");
1131 if (ports[port_id].dev_conf.txmode.offloads &
1132 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
1138 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) {
1139 printf("IP tunnel TSO: ");
1140 if (ports[port_id].dev_conf.txmode.offloads &
1141 DEV_TX_OFFLOAD_IP_TNL_TSO)
1147 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) {
1148 printf("UDP tunnel TSO: ");
1149 if (ports[port_id].dev_conf.txmode.offloads &
1150 DEV_TX_OFFLOAD_UDP_TNL_TSO)
1156 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
1157 printf("TX Outer UDP checksum: ");
1158 if (ports[port_id].dev_conf.txmode.offloads &
1159 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
1165 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
1166 printf("Tx scheduling on timestamp: ");
1167 if (ports[port_id].dev_conf.txmode.offloads &
1168 DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP)
1177 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1181 if (port_id == (portid_t)RTE_PORT_ALL)
1184 RTE_ETH_FOREACH_DEV(pid)
1188 if (warning == ENABLED_WARN)
1189 printf("Invalid port %d\n", port_id);
1194 void print_valid_ports(void)
1198 printf("The valid ports array is [");
1199 RTE_ETH_FOREACH_DEV(pid) {
1206 vlan_id_is_invalid(uint16_t vlan_id)
1210 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1215 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1217 const struct rte_pci_device *pci_dev;
1218 const struct rte_bus *bus;
1221 if (reg_off & 0x3) {
1222 printf("Port register offset 0x%X not aligned on a 4-byte "
1228 if (!ports[port_id].dev_info.device) {
1229 printf("Invalid device\n");
1233 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1234 if (bus && !strcmp(bus->name, "pci")) {
1235 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1237 printf("Not a PCI device\n");
1241 pci_len = pci_dev->mem_resource[0].len;
1242 if (reg_off >= pci_len) {
1243 printf("Port %d: register offset %u (0x%X) out of port PCI "
1244 "resource (length=%"PRIu64")\n",
1245 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
1252 reg_bit_pos_is_invalid(uint8_t bit_pos)
1256 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
1260 #define display_port_and_reg_off(port_id, reg_off) \
1261 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1264 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1266 display_port_and_reg_off(port_id, (unsigned)reg_off);
1267 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1271 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1276 if (port_id_is_invalid(port_id, ENABLED_WARN))
1278 if (port_reg_off_is_invalid(port_id, reg_off))
1280 if (reg_bit_pos_is_invalid(bit_x))
1282 reg_v = port_id_pci_reg_read(port_id, reg_off);
1283 display_port_and_reg_off(port_id, (unsigned)reg_off);
1284 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1288 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1289 uint8_t bit1_pos, uint8_t bit2_pos)
1295 if (port_id_is_invalid(port_id, ENABLED_WARN))
1297 if (port_reg_off_is_invalid(port_id, reg_off))
1299 if (reg_bit_pos_is_invalid(bit1_pos))
1301 if (reg_bit_pos_is_invalid(bit2_pos))
1303 if (bit1_pos > bit2_pos)
1304 l_bit = bit2_pos, h_bit = bit1_pos;
1306 l_bit = bit1_pos, h_bit = bit2_pos;
1308 reg_v = port_id_pci_reg_read(port_id, reg_off);
1311 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1312 display_port_and_reg_off(port_id, (unsigned)reg_off);
1313 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1314 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1318 port_reg_display(portid_t port_id, uint32_t reg_off)
1322 if (port_id_is_invalid(port_id, ENABLED_WARN))
1324 if (port_reg_off_is_invalid(port_id, reg_off))
1326 reg_v = port_id_pci_reg_read(port_id, reg_off);
1327 display_port_reg_value(port_id, reg_off, reg_v);
1331 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1336 if (port_id_is_invalid(port_id, ENABLED_WARN))
1338 if (port_reg_off_is_invalid(port_id, reg_off))
1340 if (reg_bit_pos_is_invalid(bit_pos))
1343 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1346 reg_v = port_id_pci_reg_read(port_id, reg_off);
1348 reg_v &= ~(1 << bit_pos);
1350 reg_v |= (1 << bit_pos);
1351 port_id_pci_reg_write(port_id, reg_off, reg_v);
1352 display_port_reg_value(port_id, reg_off, reg_v);
1356 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1357 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1364 if (port_id_is_invalid(port_id, ENABLED_WARN))
1366 if (port_reg_off_is_invalid(port_id, reg_off))
1368 if (reg_bit_pos_is_invalid(bit1_pos))
1370 if (reg_bit_pos_is_invalid(bit2_pos))
1372 if (bit1_pos > bit2_pos)
1373 l_bit = bit2_pos, h_bit = bit1_pos;
1375 l_bit = bit1_pos, h_bit = bit2_pos;
1377 if ((h_bit - l_bit) < 31)
1378 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1382 if (value > max_v) {
1383 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1384 (unsigned)value, (unsigned)value,
1385 (unsigned)max_v, (unsigned)max_v);
1388 reg_v = port_id_pci_reg_read(port_id, reg_off);
1389 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1390 reg_v |= (value << l_bit); /* Set changed bits */
1391 port_id_pci_reg_write(port_id, reg_off, reg_v);
1392 display_port_reg_value(port_id, reg_off, reg_v);
1396 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1398 if (port_id_is_invalid(port_id, ENABLED_WARN))
1400 if (port_reg_off_is_invalid(port_id, reg_off))
1402 port_id_pci_reg_write(port_id, reg_off, reg_v);
1403 display_port_reg_value(port_id, reg_off, reg_v);
1407 port_mtu_set(portid_t port_id, uint16_t mtu)
1410 struct rte_port *rte_port = &ports[port_id];
1411 struct rte_eth_dev_info dev_info;
1412 uint16_t eth_overhead;
1415 if (port_id_is_invalid(port_id, ENABLED_WARN))
1418 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1422 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1423 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1424 mtu, dev_info.min_mtu, dev_info.max_mtu);
1427 diag = rte_eth_dev_set_mtu(port_id, mtu);
1429 printf("Set MTU failed. diag=%d\n", diag);
1430 else if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1432 * Ether overhead in driver is equal to the difference of
1433 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1434 * device supports jumbo frame.
1436 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1437 if (mtu > RTE_ETHER_MTU) {
1438 rte_port->dev_conf.rxmode.offloads |=
1439 DEV_RX_OFFLOAD_JUMBO_FRAME;
1440 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1443 rte_port->dev_conf.rxmode.offloads &=
1444 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1448 /* Generic flow management functions. */
1450 static struct port_flow_tunnel *
1451 port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
1453 struct port_flow_tunnel *flow_tunnel;
1455 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1456 if (flow_tunnel->id == port_tunnel_id)
1466 port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
1469 switch (tunnel->type) {
1473 case RTE_FLOW_ITEM_TYPE_VXLAN:
1481 struct port_flow_tunnel *
1482 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
1484 struct rte_port *port = &ports[port_id];
1485 struct port_flow_tunnel *flow_tunnel;
1487 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1488 if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
1497 void port_flow_tunnel_list(portid_t port_id)
1499 struct rte_port *port = &ports[port_id];
1500 struct port_flow_tunnel *flt;
1502 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1503 printf("port %u tunnel #%u type=%s",
1504 port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
1505 if (flt->tunnel.tun_id)
1506 printf(" id=%" PRIu64, flt->tunnel.tun_id);
1511 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
1513 struct rte_port *port = &ports[port_id];
1514 struct port_flow_tunnel *flt;
1516 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1517 if (flt->id == tunnel_id)
1521 LIST_REMOVE(flt, chain);
1523 printf("port %u: flow tunnel #%u destroyed\n",
1524 port_id, tunnel_id);
1528 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
1530 struct rte_port *port = &ports[port_id];
1531 enum rte_flow_item_type type;
1532 struct port_flow_tunnel *flt;
1534 if (!strcmp(ops->type, "vxlan"))
1535 type = RTE_FLOW_ITEM_TYPE_VXLAN;
1537 printf("cannot offload \"%s\" tunnel type\n", ops->type);
1540 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1541 if (flt->tunnel.type == type)
1545 flt = calloc(1, sizeof(*flt));
1547 printf("failed to allocate port flt object\n");
1550 flt->tunnel.type = type;
1551 flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
1552 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
1553 LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
1555 printf("port %d: flow tunnel #%u type %s\n",
1556 port_id, flt->id, ops->type);
1559 /** Generate a port_flow entry from attributes/pattern/actions. */
1560 static struct port_flow *
1561 port_flow_new(const struct rte_flow_attr *attr,
1562 const struct rte_flow_item *pattern,
1563 const struct rte_flow_action *actions,
1564 struct rte_flow_error *error)
1566 const struct rte_flow_conv_rule rule = {
1568 .pattern_ro = pattern,
1569 .actions_ro = actions,
1571 struct port_flow *pf;
1574 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1577 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1580 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1584 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1591 /** Print a message out of a flow error. */
1593 port_flow_complain(struct rte_flow_error *error)
1595 static const char *const errstrlist[] = {
1596 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1597 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1598 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1599 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1600 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1601 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1602 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1603 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1604 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1605 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1606 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1607 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1608 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1609 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1610 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1611 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1612 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1616 int err = rte_errno;
1618 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1619 !errstrlist[error->type])
1620 errstr = "unknown type";
1622 errstr = errstrlist[error->type];
1623 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1624 error->type, errstr,
1625 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1626 error->cause), buf) : "",
1627 error->message ? error->message : "(no stated reason)",
1633 rss_config_display(struct rte_flow_action_rss *rss_conf)
1637 if (rss_conf == NULL) {
1638 printf("Invalid rule\n");
1644 if (rss_conf->queue_num == 0)
1646 for (i = 0; i < rss_conf->queue_num; i++)
1647 printf(" %d", rss_conf->queue[i]);
1650 printf(" function: ");
1651 switch (rss_conf->func) {
1652 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1653 printf("default\n");
1655 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1656 printf("toeplitz\n");
1658 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1659 printf("simple_xor\n");
1661 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1662 printf("symmetric_toeplitz\n");
1665 printf("Unknown function\n");
1669 printf(" types:\n");
1670 if (rss_conf->types == 0) {
1674 for (i = 0; rss_type_table[i].str; i++) {
1675 if ((rss_conf->types &
1676 rss_type_table[i].rss_type) ==
1677 rss_type_table[i].rss_type &&
1678 rss_type_table[i].rss_type != 0)
1679 printf(" %s\n", rss_type_table[i].str);
1683 static struct port_shared_action *
1684 action_get_by_id(portid_t port_id, uint32_t id)
1686 struct rte_port *port;
1687 struct port_shared_action **ppsa;
1688 struct port_shared_action *psa = NULL;
1690 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1691 port_id == (portid_t)RTE_PORT_ALL)
1693 port = &ports[port_id];
1694 ppsa = &port->actions_list;
1696 if ((*ppsa)->id == id) {
1700 ppsa = &(*ppsa)->next;
1703 printf("Failed to find shared action #%u on port %u\n",
1709 action_alloc(portid_t port_id, uint32_t id,
1710 struct port_shared_action **action)
1712 struct rte_port *port;
1713 struct port_shared_action **ppsa;
1714 struct port_shared_action *psa = NULL;
1717 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1718 port_id == (portid_t)RTE_PORT_ALL)
1720 port = &ports[port_id];
1721 if (id == UINT32_MAX) {
1722 /* taking first available ID */
1723 if (port->actions_list) {
1724 if (port->actions_list->id == UINT32_MAX - 1) {
1725 printf("Highest shared action ID is already"
1726 " assigned, delete it first\n");
1729 id = port->actions_list->id + 1;
1734 psa = calloc(1, sizeof(*psa));
1736 printf("Allocation of port %u shared action failed\n",
1740 ppsa = &port->actions_list;
1741 while (*ppsa && (*ppsa)->id > id)
1742 ppsa = &(*ppsa)->next;
1743 if (*ppsa && (*ppsa)->id == id) {
1744 printf("Shared action #%u is already assigned,"
1745 " delete it first\n", id);
1756 /** Create shared action */
1758 port_shared_action_create(portid_t port_id, uint32_t id,
1759 const struct rte_flow_shared_action_conf *conf,
1760 const struct rte_flow_action *action)
1762 struct port_shared_action *psa;
1764 struct rte_flow_error error;
1766 ret = action_alloc(port_id, id, &psa);
1769 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
1770 struct rte_flow_action_age *age =
1771 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
1773 psa->age_type = ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION;
1774 age->context = &psa->age_type;
1776 /* Poisoning to make sure PMDs update it in case of error. */
1777 memset(&error, 0x22, sizeof(error));
1778 psa->action = rte_flow_shared_action_create(port_id, conf, action,
1781 uint32_t destroy_id = psa->id;
1782 port_shared_action_destroy(port_id, 1, &destroy_id);
1783 return port_flow_complain(&error);
1785 psa->type = action->type;
1786 printf("Shared action #%u created\n", psa->id);
1790 /** Destroy shared action */
1792 port_shared_action_destroy(portid_t port_id,
1794 const uint32_t *actions)
1796 struct rte_port *port;
1797 struct port_shared_action **tmp;
1801 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1802 port_id == (portid_t)RTE_PORT_ALL)
1804 port = &ports[port_id];
1805 tmp = &port->actions_list;
1809 for (i = 0; i != n; ++i) {
1810 struct rte_flow_error error;
1811 struct port_shared_action *psa = *tmp;
1813 if (actions[i] != psa->id)
1816 * Poisoning to make sure PMDs update it in case
1819 memset(&error, 0x33, sizeof(error));
1821 if (psa->action && rte_flow_shared_action_destroy(
1822 port_id, psa->action, &error)) {
1823 ret = port_flow_complain(&error);
1827 printf("Shared action #%u destroyed\n", psa->id);
1832 tmp = &(*tmp)->next;
1839 /** Get shared action by port + id */
1840 struct rte_flow_shared_action *
1841 port_shared_action_get_by_id(portid_t port_id, uint32_t id)
1844 struct port_shared_action *psa = action_get_by_id(port_id, id);
1846 return (psa) ? psa->action : NULL;
1849 /** Update shared action */
1851 port_shared_action_update(portid_t port_id, uint32_t id,
1852 const struct rte_flow_action *action)
1854 struct rte_flow_error error;
1855 struct rte_flow_shared_action *shared_action;
1857 shared_action = port_shared_action_get_by_id(port_id, id);
1860 if (rte_flow_shared_action_update(port_id, shared_action, action,
1862 return port_flow_complain(&error);
1864 printf("Shared action #%u updated\n", id);
1869 port_shared_action_query(portid_t port_id, uint32_t id)
1871 struct rte_flow_error error;
1872 struct port_shared_action *psa;
1873 uint64_t default_data;
1877 psa = action_get_by_id(port_id, id);
1880 switch (psa->type) {
1881 case RTE_FLOW_ACTION_TYPE_RSS:
1882 case RTE_FLOW_ACTION_TYPE_AGE:
1883 data = &default_data;
1886 printf("Shared action %u (type: %d) on port %u doesn't support"
1887 " query\n", id, psa->type, port_id);
1890 if (rte_flow_shared_action_query(port_id, psa->action, data, &error))
1891 ret = port_flow_complain(&error);
1892 switch (psa->type) {
1893 case RTE_FLOW_ACTION_TYPE_RSS:
1895 printf("Shared RSS action:\n\trefs:%u\n",
1896 *((uint32_t *)data));
1899 case RTE_FLOW_ACTION_TYPE_AGE:
1901 struct rte_flow_query_age *resp = data;
1905 " sec_since_last_hit_valid: %u\n"
1906 " sec_since_last_hit: %" PRIu32 "\n",
1908 resp->sec_since_last_hit_valid,
1909 resp->sec_since_last_hit);
1914 printf("Shared action %u (type: %d) on port %u doesn't support"
1915 " query\n", id, psa->type, port_id);
1921 static struct port_flow_tunnel *
1922 port_flow_tunnel_offload_cmd_prep(portid_t port_id,
1923 const struct rte_flow_item *pattern,
1924 const struct rte_flow_action *actions,
1925 const struct tunnel_ops *tunnel_ops)
1928 struct rte_port *port;
1929 struct port_flow_tunnel *pft;
1930 struct rte_flow_error error;
1932 port = &ports[port_id];
1933 pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
1935 printf("failed to locate port flow tunnel #%u\n",
1939 if (tunnel_ops->actions) {
1940 uint32_t num_actions;
1941 const struct rte_flow_action *aptr;
1943 ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
1945 &pft->num_pmd_actions,
1948 port_flow_complain(&error);
1951 for (aptr = actions, num_actions = 1;
1952 aptr->type != RTE_FLOW_ACTION_TYPE_END;
1953 aptr++, num_actions++);
1954 pft->actions = malloc(
1955 (num_actions + pft->num_pmd_actions) *
1956 sizeof(actions[0]));
1957 if (!pft->actions) {
1958 rte_flow_tunnel_action_decap_release(
1959 port_id, pft->actions,
1960 pft->num_pmd_actions, &error);
1963 rte_memcpy(pft->actions, pft->pmd_actions,
1964 pft->num_pmd_actions * sizeof(actions[0]));
1965 rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
1966 num_actions * sizeof(actions[0]));
1968 if (tunnel_ops->items) {
1970 const struct rte_flow_item *iptr;
1972 ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
1974 &pft->num_pmd_items,
1977 port_flow_complain(&error);
1980 for (iptr = pattern, num_items = 1;
1981 iptr->type != RTE_FLOW_ITEM_TYPE_END;
1982 iptr++, num_items++);
1983 pft->items = malloc((num_items + pft->num_pmd_items) *
1984 sizeof(pattern[0]));
1986 rte_flow_tunnel_item_release(
1987 port_id, pft->pmd_items,
1988 pft->num_pmd_items, &error);
1991 rte_memcpy(pft->items, pft->pmd_items,
1992 pft->num_pmd_items * sizeof(pattern[0]));
1993 rte_memcpy(pft->items + pft->num_pmd_items, pattern,
1994 num_items * sizeof(pattern[0]));
2001 port_flow_tunnel_offload_cmd_release(portid_t port_id,
2002 const struct tunnel_ops *tunnel_ops,
2003 struct port_flow_tunnel *pft)
2005 struct rte_flow_error error;
2007 if (tunnel_ops->actions) {
2009 rte_flow_tunnel_action_decap_release(
2010 port_id, pft->pmd_actions,
2011 pft->num_pmd_actions, &error);
2012 pft->actions = NULL;
2013 pft->pmd_actions = NULL;
2015 if (tunnel_ops->items) {
2017 rte_flow_tunnel_item_release(port_id, pft->pmd_items,
2021 pft->pmd_items = NULL;
2025 /** Validate flow rule. */
2027 port_flow_validate(portid_t port_id,
2028 const struct rte_flow_attr *attr,
2029 const struct rte_flow_item *pattern,
2030 const struct rte_flow_action *actions,
2031 const struct tunnel_ops *tunnel_ops)
2033 struct rte_flow_error error;
2034 struct port_flow_tunnel *pft = NULL;
2036 /* Poisoning to make sure PMDs update it in case of error. */
2037 memset(&error, 0x11, sizeof(error));
2038 if (tunnel_ops->enabled) {
2039 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2040 actions, tunnel_ops);
2044 pattern = pft->items;
2046 actions = pft->actions;
2048 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
2049 return port_flow_complain(&error);
2050 if (tunnel_ops->enabled)
2051 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2052 printf("Flow rule validated\n");
2056 /** Return age action structure if exists, otherwise NULL. */
2057 static struct rte_flow_action_age *
2058 age_action_get(const struct rte_flow_action *actions)
2060 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2061 switch (actions->type) {
2062 case RTE_FLOW_ACTION_TYPE_AGE:
2063 return (struct rte_flow_action_age *)
2064 (uintptr_t)actions->conf;
2072 /** Create flow rule. */
2074 port_flow_create(portid_t port_id,
2075 const struct rte_flow_attr *attr,
2076 const struct rte_flow_item *pattern,
2077 const struct rte_flow_action *actions,
2078 const struct tunnel_ops *tunnel_ops)
2080 struct rte_flow *flow;
2081 struct rte_port *port;
2082 struct port_flow *pf;
2084 struct rte_flow_error error;
2085 struct port_flow_tunnel *pft = NULL;
2086 struct rte_flow_action_age *age = age_action_get(actions);
2088 port = &ports[port_id];
2089 if (port->flow_list) {
2090 if (port->flow_list->id == UINT32_MAX) {
2091 printf("Highest rule ID is already assigned, delete"
2095 id = port->flow_list->id + 1;
2097 if (tunnel_ops->enabled) {
2098 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2099 actions, tunnel_ops);
2103 pattern = pft->items;
2105 actions = pft->actions;
2107 pf = port_flow_new(attr, pattern, actions, &error);
2109 return port_flow_complain(&error);
2111 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
2112 age->context = &pf->age_type;
2114 /* Poisoning to make sure PMDs update it in case of error. */
2115 memset(&error, 0x22, sizeof(error));
2116 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
2119 return port_flow_complain(&error);
2121 pf->next = port->flow_list;
2124 port->flow_list = pf;
2125 if (tunnel_ops->enabled)
2126 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2127 printf("Flow rule #%u created\n", pf->id);
2131 /** Destroy a number of flow rules. */
2133 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
2135 struct rte_port *port;
2136 struct port_flow **tmp;
2140 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2141 port_id == (portid_t)RTE_PORT_ALL)
2143 port = &ports[port_id];
2144 tmp = &port->flow_list;
2148 for (i = 0; i != n; ++i) {
2149 struct rte_flow_error error;
2150 struct port_flow *pf = *tmp;
2152 if (rule[i] != pf->id)
2155 * Poisoning to make sure PMDs update it in case
2158 memset(&error, 0x33, sizeof(error));
2159 if (rte_flow_destroy(port_id, pf->flow, &error)) {
2160 ret = port_flow_complain(&error);
2163 printf("Flow rule #%u destroyed\n", pf->id);
2169 tmp = &(*tmp)->next;
2175 /** Remove all flow rules. */
2177 port_flow_flush(portid_t port_id)
2179 struct rte_flow_error error;
2180 struct rte_port *port;
2183 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2184 port_id == (portid_t)RTE_PORT_ALL)
2187 port = &ports[port_id];
2189 if (port->flow_list == NULL)
2192 /* Poisoning to make sure PMDs update it in case of error. */
2193 memset(&error, 0x44, sizeof(error));
2194 if (rte_flow_flush(port_id, &error)) {
2195 port_flow_complain(&error);
2198 while (port->flow_list) {
2199 struct port_flow *pf = port->flow_list->next;
2201 free(port->flow_list);
2202 port->flow_list = pf;
2207 /** Dump all flow rules. */
2209 port_flow_dump(portid_t port_id, const char *file_name)
2212 FILE *file = stdout;
2213 struct rte_flow_error error;
2215 if (file_name && strlen(file_name)) {
2216 file = fopen(file_name, "w");
2218 printf("Failed to create file %s: %s\n", file_name,
2223 ret = rte_flow_dev_dump(port_id, file, &error);
2225 port_flow_complain(&error);
2226 printf("Failed to dump flow: %s\n", strerror(-ret));
2228 printf("Flow dump finished\n");
2229 if (file_name && strlen(file_name))
2234 /** Query a flow rule. */
2236 port_flow_query(portid_t port_id, uint32_t rule,
2237 const struct rte_flow_action *action)
2239 struct rte_flow_error error;
2240 struct rte_port *port;
2241 struct port_flow *pf;
2244 struct rte_flow_query_count count;
2245 struct rte_flow_action_rss rss_conf;
2246 struct rte_flow_query_age age;
2250 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2251 port_id == (portid_t)RTE_PORT_ALL)
2253 port = &ports[port_id];
2254 for (pf = port->flow_list; pf; pf = pf->next)
2258 printf("Flow rule #%u not found\n", rule);
2261 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2262 &name, sizeof(name),
2263 (void *)(uintptr_t)action->type, &error);
2265 return port_flow_complain(&error);
2266 switch (action->type) {
2267 case RTE_FLOW_ACTION_TYPE_COUNT:
2268 case RTE_FLOW_ACTION_TYPE_RSS:
2269 case RTE_FLOW_ACTION_TYPE_AGE:
2272 printf("Cannot query action type %d (%s)\n",
2273 action->type, name);
2276 /* Poisoning to make sure PMDs update it in case of error. */
2277 memset(&error, 0x55, sizeof(error));
2278 memset(&query, 0, sizeof(query));
2279 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
2280 return port_flow_complain(&error);
2281 switch (action->type) {
2282 case RTE_FLOW_ACTION_TYPE_COUNT:
2286 " hits: %" PRIu64 "\n"
2287 " bytes: %" PRIu64 "\n",
2289 query.count.hits_set,
2290 query.count.bytes_set,
2294 case RTE_FLOW_ACTION_TYPE_RSS:
2295 rss_config_display(&query.rss_conf);
2297 case RTE_FLOW_ACTION_TYPE_AGE:
2300 " sec_since_last_hit_valid: %u\n"
2301 " sec_since_last_hit: %" PRIu32 "\n",
2304 query.age.sec_since_last_hit_valid,
2305 query.age.sec_since_last_hit);
2308 printf("Cannot display result for action type %d (%s)\n",
2309 action->type, name);
2315 /** List simply and destroy all aged flows. */
2317 port_flow_aged(portid_t port_id, uint8_t destroy)
2320 int nb_context, total = 0, idx;
2321 struct rte_flow_error error;
2322 enum age_action_context_type *type;
2324 struct port_flow *pf;
2325 struct port_shared_action *psa;
2328 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2329 port_id == (portid_t)RTE_PORT_ALL)
2331 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
2332 printf("Port %u total aged flows: %d\n", port_id, total);
2334 port_flow_complain(&error);
2339 contexts = malloc(sizeof(void *) * total);
2340 if (contexts == NULL) {
2341 printf("Cannot allocate contexts for aged flow\n");
2344 printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
2345 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
2346 if (nb_context != total) {
2347 printf("Port:%d get aged flows count(%d) != total(%d)\n",
2348 port_id, nb_context, total);
2353 for (idx = 0; idx < nb_context; idx++) {
2354 if (!contexts[idx]) {
2355 printf("Error: get Null context in port %u\n", port_id);
2358 type = (enum age_action_context_type *)contexts[idx];
2360 case ACTION_AGE_CONTEXT_TYPE_FLOW:
2361 ctx.pf = container_of(type, struct port_flow, age_type);
2362 printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
2366 ctx.pf->rule.attr->group,
2367 ctx.pf->rule.attr->priority,
2368 ctx.pf->rule.attr->ingress ? 'i' : '-',
2369 ctx.pf->rule.attr->egress ? 'e' : '-',
2370 ctx.pf->rule.attr->transfer ? 't' : '-');
2371 if (destroy && !port_flow_destroy(port_id, 1,
2375 case ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION:
2376 ctx.psa = container_of(type, struct port_shared_action,
2378 printf("%-20s\t%" PRIu32 "\n", "Shared action",
2382 printf("Error: invalid context type %u\n", port_id);
2386 printf("\n%d flows destroyed\n", total);
2390 /** List flow rules. */
2392 port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group)
2394 struct rte_port *port;
2395 struct port_flow *pf;
2396 struct port_flow *list = NULL;
2399 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2400 port_id == (portid_t)RTE_PORT_ALL)
2402 port = &ports[port_id];
2403 if (!port->flow_list)
2405 /* Sort flows by group, priority and ID. */
2406 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
2407 struct port_flow **tmp;
2408 const struct rte_flow_attr *curr = pf->rule.attr;
2411 /* Filter out unwanted groups. */
2412 for (i = 0; i != n; ++i)
2413 if (curr->group == group[i])
2418 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
2419 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
2421 if (curr->group > comp->group ||
2422 (curr->group == comp->group &&
2423 curr->priority > comp->priority) ||
2424 (curr->group == comp->group &&
2425 curr->priority == comp->priority &&
2426 pf->id > (*tmp)->id))
2433 printf("ID\tGroup\tPrio\tAttr\tRule\n");
2434 for (pf = list; pf != NULL; pf = pf->tmp) {
2435 const struct rte_flow_item *item = pf->rule.pattern;
2436 const struct rte_flow_action *action = pf->rule.actions;
2439 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
2441 pf->rule.attr->group,
2442 pf->rule.attr->priority,
2443 pf->rule.attr->ingress ? 'i' : '-',
2444 pf->rule.attr->egress ? 'e' : '-',
2445 pf->rule.attr->transfer ? 't' : '-');
2446 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
2447 if ((uint32_t)item->type > INT_MAX)
2448 name = "PMD_INTERNAL";
2449 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
2450 &name, sizeof(name),
2451 (void *)(uintptr_t)item->type,
2454 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
2455 printf("%s ", name);
2459 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
2460 if ((uint32_t)action->type > INT_MAX)
2461 name = "PMD_INTERNAL";
2462 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2463 &name, sizeof(name),
2464 (void *)(uintptr_t)action->type,
2467 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
2468 printf(" %s", name);
2475 /** Restrict ingress traffic to the defined flow rules. */
2477 port_flow_isolate(portid_t port_id, int set)
2479 struct rte_flow_error error;
2481 /* Poisoning to make sure PMDs update it in case of error. */
2482 memset(&error, 0x66, sizeof(error));
2483 if (rte_flow_isolate(port_id, set, &error))
2484 return port_flow_complain(&error);
2485 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
2487 set ? "now restricted" : "not restricted anymore");
2492 * RX/TX ring descriptors display functions.
2495 rx_queue_id_is_invalid(queueid_t rxq_id)
2497 if (rxq_id < nb_rxq)
2499 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
2504 tx_queue_id_is_invalid(queueid_t txq_id)
2506 if (txq_id < nb_txq)
2508 printf("Invalid TX queue %d (must be < nb_txq=%d)\n", txq_id, nb_txq);
2513 get_rx_ring_size(portid_t port_id, queueid_t rxq_id, uint16_t *ring_size)
2515 struct rte_port *port = &ports[port_id];
2516 struct rte_eth_rxq_info rx_qinfo;
2519 ret = rte_eth_rx_queue_info_get(port_id, rxq_id, &rx_qinfo);
2521 *ring_size = rx_qinfo.nb_desc;
2525 if (ret != -ENOTSUP)
2528 * If the rte_eth_rx_queue_info_get is not support for this PMD,
2529 * ring_size stored in testpmd will be used for validity verification.
2530 * When configure the rxq by rte_eth_rx_queue_setup with nb_rx_desc
2531 * being 0, it will use a default value provided by PMDs to setup this
2532 * rxq. If the default value is 0, it will use the
2533 * RTE_ETH_DEV_FALLBACK_RX_RINGSIZE to setup this rxq.
2535 if (port->nb_rx_desc[rxq_id])
2536 *ring_size = port->nb_rx_desc[rxq_id];
2537 else if (port->dev_info.default_rxportconf.ring_size)
2538 *ring_size = port->dev_info.default_rxportconf.ring_size;
2540 *ring_size = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
2545 get_tx_ring_size(portid_t port_id, queueid_t txq_id, uint16_t *ring_size)
2547 struct rte_port *port = &ports[port_id];
2548 struct rte_eth_txq_info tx_qinfo;
2551 ret = rte_eth_tx_queue_info_get(port_id, txq_id, &tx_qinfo);
2553 *ring_size = tx_qinfo.nb_desc;
2557 if (ret != -ENOTSUP)
2560 * If the rte_eth_tx_queue_info_get is not support for this PMD,
2561 * ring_size stored in testpmd will be used for validity verification.
2562 * When configure the txq by rte_eth_tx_queue_setup with nb_tx_desc
2563 * being 0, it will use a default value provided by PMDs to setup this
2564 * txq. If the default value is 0, it will use the
2565 * RTE_ETH_DEV_FALLBACK_TX_RINGSIZE to setup this txq.
2567 if (port->nb_tx_desc[txq_id])
2568 *ring_size = port->nb_tx_desc[txq_id];
2569 else if (port->dev_info.default_txportconf.ring_size)
2570 *ring_size = port->dev_info.default_txportconf.ring_size;
2572 *ring_size = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
2577 rx_desc_id_is_invalid(portid_t port_id, queueid_t rxq_id, uint16_t rxdesc_id)
2582 ret = get_rx_ring_size(port_id, rxq_id, &ring_size);
2586 if (rxdesc_id < ring_size)
2589 printf("Invalid RX descriptor %u (must be < ring_size=%u)\n",
2590 rxdesc_id, ring_size);
2595 tx_desc_id_is_invalid(portid_t port_id, queueid_t txq_id, uint16_t txdesc_id)
2600 ret = get_tx_ring_size(port_id, txq_id, &ring_size);
2604 if (txdesc_id < ring_size)
2607 printf("Invalid TX descriptor %u (must be < ring_size=%u)\n",
2608 txdesc_id, ring_size);
2612 static const struct rte_memzone *
2613 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
2615 char mz_name[RTE_MEMZONE_NAMESIZE];
2616 const struct rte_memzone *mz;
2618 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
2619 port_id, q_id, ring_name);
2620 mz = rte_memzone_lookup(mz_name);
2622 printf("%s ring memory zoneof (port %d, queue %d) not"
2623 "found (zone name = %s\n",
2624 ring_name, port_id, q_id, mz_name);
2628 union igb_ring_dword {
2631 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
2641 struct igb_ring_desc_32_bytes {
2642 union igb_ring_dword lo_dword;
2643 union igb_ring_dword hi_dword;
2644 union igb_ring_dword resv1;
2645 union igb_ring_dword resv2;
2648 struct igb_ring_desc_16_bytes {
2649 union igb_ring_dword lo_dword;
2650 union igb_ring_dword hi_dword;
2654 ring_rxd_display_dword(union igb_ring_dword dword)
2656 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
2657 (unsigned)dword.words.hi);
2661 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
2662 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2665 __rte_unused portid_t port_id,
2669 struct igb_ring_desc_16_bytes *ring =
2670 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2671 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2673 struct rte_eth_dev_info dev_info;
2675 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2679 if (strstr(dev_info.driver_name, "i40e") != NULL) {
2680 /* 32 bytes RX descriptor, i40e only */
2681 struct igb_ring_desc_32_bytes *ring =
2682 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
2683 ring[desc_id].lo_dword.dword =
2684 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2685 ring_rxd_display_dword(ring[desc_id].lo_dword);
2686 ring[desc_id].hi_dword.dword =
2687 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2688 ring_rxd_display_dword(ring[desc_id].hi_dword);
2689 ring[desc_id].resv1.dword =
2690 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
2691 ring_rxd_display_dword(ring[desc_id].resv1);
2692 ring[desc_id].resv2.dword =
2693 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
2694 ring_rxd_display_dword(ring[desc_id].resv2);
2699 /* 16 bytes RX descriptor */
2700 ring[desc_id].lo_dword.dword =
2701 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2702 ring_rxd_display_dword(ring[desc_id].lo_dword);
2703 ring[desc_id].hi_dword.dword =
2704 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2705 ring_rxd_display_dword(ring[desc_id].hi_dword);
2709 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
2711 struct igb_ring_desc_16_bytes *ring;
2712 struct igb_ring_desc_16_bytes txd;
2714 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2715 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2716 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2717 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
2718 (unsigned)txd.lo_dword.words.lo,
2719 (unsigned)txd.lo_dword.words.hi,
2720 (unsigned)txd.hi_dword.words.lo,
2721 (unsigned)txd.hi_dword.words.hi);
2725 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
2727 const struct rte_memzone *rx_mz;
2729 if (rx_desc_id_is_invalid(port_id, rxq_id, rxd_id))
2731 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
2734 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
2738 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
2740 const struct rte_memzone *tx_mz;
2742 if (tx_desc_id_is_invalid(port_id, txq_id, txd_id))
2744 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
2747 ring_tx_descriptor_display(tx_mz, txd_id);
2751 fwd_lcores_config_display(void)
2755 printf("List of forwarding lcores:");
2756 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
2757 printf(" %2u", fwd_lcores_cpuids[lc_id]);
2761 rxtx_config_display(void)
2766 printf(" %s packet forwarding%s packets/burst=%d\n",
2767 cur_fwd_eng->fwd_mode_name,
2768 retry_enabled == 0 ? "" : " with retry",
2771 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
2772 printf(" packet len=%u - nb packet segments=%d\n",
2773 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
2775 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
2776 nb_fwd_lcores, nb_fwd_ports);
2778 RTE_ETH_FOREACH_DEV(pid) {
2779 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
2780 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
2781 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
2782 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
2783 struct rte_eth_rxq_info rx_qinfo;
2784 struct rte_eth_txq_info tx_qinfo;
2785 uint16_t rx_free_thresh_tmp;
2786 uint16_t tx_free_thresh_tmp;
2787 uint16_t tx_rs_thresh_tmp;
2788 uint16_t nb_rx_desc_tmp;
2789 uint16_t nb_tx_desc_tmp;
2790 uint64_t offloads_tmp;
2791 uint8_t pthresh_tmp;
2792 uint8_t hthresh_tmp;
2793 uint8_t wthresh_tmp;
2796 /* per port config */
2797 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
2798 (unsigned int)pid, nb_rxq, nb_txq);
2800 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
2801 ports[pid].dev_conf.rxmode.offloads,
2802 ports[pid].dev_conf.txmode.offloads);
2804 /* per rx queue config only for first queue to be less verbose */
2805 for (qid = 0; qid < 1; qid++) {
2806 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
2808 nb_rx_desc_tmp = nb_rx_desc[qid];
2809 rx_free_thresh_tmp =
2810 rx_conf[qid].rx_free_thresh;
2811 pthresh_tmp = rx_conf[qid].rx_thresh.pthresh;
2812 hthresh_tmp = rx_conf[qid].rx_thresh.hthresh;
2813 wthresh_tmp = rx_conf[qid].rx_thresh.wthresh;
2814 offloads_tmp = rx_conf[qid].offloads;
2816 nb_rx_desc_tmp = rx_qinfo.nb_desc;
2817 rx_free_thresh_tmp =
2818 rx_qinfo.conf.rx_free_thresh;
2819 pthresh_tmp = rx_qinfo.conf.rx_thresh.pthresh;
2820 hthresh_tmp = rx_qinfo.conf.rx_thresh.hthresh;
2821 wthresh_tmp = rx_qinfo.conf.rx_thresh.wthresh;
2822 offloads_tmp = rx_qinfo.conf.offloads;
2825 printf(" RX queue: %d\n", qid);
2826 printf(" RX desc=%d - RX free threshold=%d\n",
2827 nb_rx_desc_tmp, rx_free_thresh_tmp);
2828 printf(" RX threshold registers: pthresh=%d hthresh=%d "
2830 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2831 printf(" RX Offloads=0x%"PRIx64"\n", offloads_tmp);
2834 /* per tx queue config only for first queue to be less verbose */
2835 for (qid = 0; qid < 1; qid++) {
2836 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
2838 nb_tx_desc_tmp = nb_tx_desc[qid];
2839 tx_free_thresh_tmp =
2840 tx_conf[qid].tx_free_thresh;
2841 pthresh_tmp = tx_conf[qid].tx_thresh.pthresh;
2842 hthresh_tmp = tx_conf[qid].tx_thresh.hthresh;
2843 wthresh_tmp = tx_conf[qid].tx_thresh.wthresh;
2844 offloads_tmp = tx_conf[qid].offloads;
2845 tx_rs_thresh_tmp = tx_conf[qid].tx_rs_thresh;
2847 nb_tx_desc_tmp = tx_qinfo.nb_desc;
2848 tx_free_thresh_tmp =
2849 tx_qinfo.conf.tx_free_thresh;
2850 pthresh_tmp = tx_qinfo.conf.tx_thresh.pthresh;
2851 hthresh_tmp = tx_qinfo.conf.tx_thresh.hthresh;
2852 wthresh_tmp = tx_qinfo.conf.tx_thresh.wthresh;
2853 offloads_tmp = tx_qinfo.conf.offloads;
2854 tx_rs_thresh_tmp = tx_qinfo.conf.tx_rs_thresh;
2857 printf(" TX queue: %d\n", qid);
2858 printf(" TX desc=%d - TX free threshold=%d\n",
2859 nb_tx_desc_tmp, tx_free_thresh_tmp);
2860 printf(" TX threshold registers: pthresh=%d hthresh=%d "
2862 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2863 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
2864 offloads_tmp, tx_rs_thresh_tmp);
2870 port_rss_reta_info(portid_t port_id,
2871 struct rte_eth_rss_reta_entry64 *reta_conf,
2872 uint16_t nb_entries)
2874 uint16_t i, idx, shift;
2877 if (port_id_is_invalid(port_id, ENABLED_WARN))
2880 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
2882 printf("Failed to get RSS RETA info, return code = %d\n", ret);
2886 for (i = 0; i < nb_entries; i++) {
2887 idx = i / RTE_RETA_GROUP_SIZE;
2888 shift = i % RTE_RETA_GROUP_SIZE;
2889 if (!(reta_conf[idx].mask & (1ULL << shift)))
2891 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
2892 i, reta_conf[idx].reta[shift]);
2897 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
2901 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
2903 struct rte_eth_rss_conf rss_conf = {0};
2904 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
2908 struct rte_eth_dev_info dev_info;
2909 uint8_t hash_key_size;
2912 if (port_id_is_invalid(port_id, ENABLED_WARN))
2915 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2919 if (dev_info.hash_key_size > 0 &&
2920 dev_info.hash_key_size <= sizeof(rss_key))
2921 hash_key_size = dev_info.hash_key_size;
2923 printf("dev_info did not provide a valid hash key size\n");
2927 /* Get RSS hash key if asked to display it */
2928 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2929 rss_conf.rss_key_len = hash_key_size;
2930 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2934 printf("port index %d invalid\n", port_id);
2937 printf("operation not supported by device\n");
2940 printf("operation failed - diag=%d\n", diag);
2945 rss_hf = rss_conf.rss_hf;
2947 printf("RSS disabled\n");
2950 printf("RSS functions:\n ");
2951 for (i = 0; rss_type_table[i].str; i++) {
2952 if (rss_hf & rss_type_table[i].rss_type)
2953 printf("%s ", rss_type_table[i].str);
2958 printf("RSS key:\n");
2959 for (i = 0; i < hash_key_size; i++)
2960 printf("%02X", rss_key[i]);
2965 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2968 struct rte_eth_rss_conf rss_conf;
2972 rss_conf.rss_key = NULL;
2973 rss_conf.rss_key_len = hash_key_len;
2974 rss_conf.rss_hf = 0;
2975 for (i = 0; rss_type_table[i].str; i++) {
2976 if (!strcmp(rss_type_table[i].str, rss_type))
2977 rss_conf.rss_hf = rss_type_table[i].rss_type;
2979 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2981 rss_conf.rss_key = hash_key;
2982 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2989 printf("port index %d invalid\n", port_id);
2992 printf("operation not supported by device\n");
2995 printf("operation failed - diag=%d\n", diag);
3001 * Setup forwarding configuration for each logical core.
3004 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
3006 streamid_t nb_fs_per_lcore;
3014 nb_fs = cfg->nb_fwd_streams;
3015 nb_fc = cfg->nb_fwd_lcores;
3016 if (nb_fs <= nb_fc) {
3017 nb_fs_per_lcore = 1;
3020 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
3021 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
3024 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
3026 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
3027 fwd_lcores[lc_id]->stream_idx = sm_id;
3028 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
3029 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
3033 * Assign extra remaining streams, if any.
3035 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
3036 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
3037 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
3038 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
3039 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
3044 fwd_topology_tx_port_get(portid_t rxp)
3046 static int warning_once = 1;
3048 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
3050 switch (port_topology) {
3052 case PORT_TOPOLOGY_PAIRED:
3053 if ((rxp & 0x1) == 0) {
3054 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
3057 printf("\nWarning! port-topology=paired"
3058 " and odd forward ports number,"
3059 " the last port will pair with"
3066 case PORT_TOPOLOGY_CHAINED:
3067 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
3068 case PORT_TOPOLOGY_LOOP:
3074 simple_fwd_config_setup(void)
3078 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
3079 cur_fwd_config.nb_fwd_streams =
3080 (streamid_t) cur_fwd_config.nb_fwd_ports;
3082 /* reinitialize forwarding streams */
3086 * In the simple forwarding test, the number of forwarding cores
3087 * must be lower or equal to the number of forwarding ports.
3089 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3090 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
3091 cur_fwd_config.nb_fwd_lcores =
3092 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
3093 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3095 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
3096 fwd_streams[i]->rx_port = fwd_ports_ids[i];
3097 fwd_streams[i]->rx_queue = 0;
3098 fwd_streams[i]->tx_port =
3099 fwd_ports_ids[fwd_topology_tx_port_get(i)];
3100 fwd_streams[i]->tx_queue = 0;
3101 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
3102 fwd_streams[i]->retry_enabled = retry_enabled;
3107 * For the RSS forwarding test all streams distributed over lcores. Each stream
3108 * being composed of a RX queue to poll on a RX port for input messages,
3109 * associated with a TX queue of a TX port where to send forwarded packets.
3112 rss_fwd_config_setup(void)
3123 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3124 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3125 cur_fwd_config.nb_fwd_streams =
3126 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
3128 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3129 cur_fwd_config.nb_fwd_lcores =
3130 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3132 /* reinitialize forwarding streams */
3135 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3137 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
3138 struct fwd_stream *fs;
3140 fs = fwd_streams[sm_id];
3141 txp = fwd_topology_tx_port_get(rxp);
3142 fs->rx_port = fwd_ports_ids[rxp];
3144 fs->tx_port = fwd_ports_ids[txp];
3146 fs->peer_addr = fs->tx_port;
3147 fs->retry_enabled = retry_enabled;
3149 if (rxp < nb_fwd_ports)
3157 * For the DCB forwarding test, each core is assigned on each traffic class.
3159 * Each core is assigned a multi-stream, each stream being composed of
3160 * a RX queue to poll on a RX port for input messages, associated with
3161 * a TX queue of a TX port where to send forwarded packets. All RX and
3162 * TX queues are mapping to the same traffic class.
3163 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
3167 dcb_fwd_config_setup(void)
3169 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
3170 portid_t txp, rxp = 0;
3171 queueid_t txq, rxq = 0;
3173 uint16_t nb_rx_queue, nb_tx_queue;
3174 uint16_t i, j, k, sm_id = 0;
3177 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3178 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3179 cur_fwd_config.nb_fwd_streams =
3180 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3182 /* reinitialize forwarding streams */
3186 /* get the dcb info on the first RX and TX ports */
3187 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3188 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3190 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3191 fwd_lcores[lc_id]->stream_nb = 0;
3192 fwd_lcores[lc_id]->stream_idx = sm_id;
3193 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
3194 /* if the nb_queue is zero, means this tc is
3195 * not enabled on the POOL
3197 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
3199 k = fwd_lcores[lc_id]->stream_nb +
3200 fwd_lcores[lc_id]->stream_idx;
3201 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
3202 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
3203 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3204 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
3205 for (j = 0; j < nb_rx_queue; j++) {
3206 struct fwd_stream *fs;
3208 fs = fwd_streams[k + j];
3209 fs->rx_port = fwd_ports_ids[rxp];
3210 fs->rx_queue = rxq + j;
3211 fs->tx_port = fwd_ports_ids[txp];
3212 fs->tx_queue = txq + j % nb_tx_queue;
3213 fs->peer_addr = fs->tx_port;
3214 fs->retry_enabled = retry_enabled;
3216 fwd_lcores[lc_id]->stream_nb +=
3217 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3219 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
3222 if (tc < rxp_dcb_info.nb_tcs)
3224 /* Restart from TC 0 on next RX port */
3226 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
3228 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
3231 if (rxp >= nb_fwd_ports)
3233 /* get the dcb information on next RX and TX ports */
3234 if ((rxp & 0x1) == 0)
3235 txp = (portid_t) (rxp + 1);
3237 txp = (portid_t) (rxp - 1);
3238 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3239 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3244 icmp_echo_config_setup(void)
3251 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
3252 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
3253 (nb_txq * nb_fwd_ports);
3255 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3256 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3257 cur_fwd_config.nb_fwd_streams =
3258 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3259 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3260 cur_fwd_config.nb_fwd_lcores =
3261 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3262 if (verbose_level > 0) {
3263 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
3265 cur_fwd_config.nb_fwd_lcores,
3266 cur_fwd_config.nb_fwd_ports,
3267 cur_fwd_config.nb_fwd_streams);
3270 /* reinitialize forwarding streams */
3272 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3274 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3275 if (verbose_level > 0)
3276 printf(" core=%d: \n", lc_id);
3277 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3278 struct fwd_stream *fs;
3279 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3280 fs->rx_port = fwd_ports_ids[rxp];
3282 fs->tx_port = fs->rx_port;
3284 fs->peer_addr = fs->tx_port;
3285 fs->retry_enabled = retry_enabled;
3286 if (verbose_level > 0)
3287 printf(" stream=%d port=%d rxq=%d txq=%d\n",
3288 sm_id, fs->rx_port, fs->rx_queue,
3290 rxq = (queueid_t) (rxq + 1);
3291 if (rxq == nb_rxq) {
3293 rxp = (portid_t) (rxp + 1);
3300 fwd_config_setup(void)
3302 cur_fwd_config.fwd_eng = cur_fwd_eng;
3303 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
3304 icmp_echo_config_setup();
3308 if ((nb_rxq > 1) && (nb_txq > 1)){
3310 dcb_fwd_config_setup();
3312 rss_fwd_config_setup();
3315 simple_fwd_config_setup();
3319 mp_alloc_to_str(uint8_t mode)
3322 case MP_ALLOC_NATIVE:
3328 case MP_ALLOC_XMEM_HUGE:
3338 pkt_fwd_config_display(struct fwd_config *cfg)
3340 struct fwd_stream *fs;
3344 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
3345 "NUMA support %s, MP allocation mode: %s\n",
3346 cfg->fwd_eng->fwd_mode_name,
3347 retry_enabled == 0 ? "" : " with retry",
3348 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
3349 numa_support == 1 ? "enabled" : "disabled",
3350 mp_alloc_to_str(mp_alloc_type));
3353 printf("TX retry num: %u, delay between TX retries: %uus\n",
3354 burst_tx_retry_num, burst_tx_delay_time);
3355 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
3356 printf("Logical Core %u (socket %u) forwards packets on "
3358 fwd_lcores_cpuids[lc_id],
3359 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
3360 fwd_lcores[lc_id]->stream_nb);
3361 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3362 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3363 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
3364 "P=%d/Q=%d (socket %u) ",
3365 fs->rx_port, fs->rx_queue,
3366 ports[fs->rx_port].socket_id,
3367 fs->tx_port, fs->tx_queue,
3368 ports[fs->tx_port].socket_id);
3369 print_ethaddr("peer=",
3370 &peer_eth_addrs[fs->peer_addr]);
3378 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
3380 struct rte_ether_addr new_peer_addr;
3381 if (!rte_eth_dev_is_valid_port(port_id)) {
3382 printf("Error: Invalid port number %i\n", port_id);
3385 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
3386 printf("Error: Invalid ethernet address: %s\n", peer_addr);
3389 peer_eth_addrs[port_id] = new_peer_addr;
3393 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
3396 unsigned int lcore_cpuid;
3401 for (i = 0; i < nb_lc; i++) {
3402 lcore_cpuid = lcorelist[i];
3403 if (! rte_lcore_is_enabled(lcore_cpuid)) {
3404 printf("lcore %u not enabled\n", lcore_cpuid);
3407 if (lcore_cpuid == rte_get_main_lcore()) {
3408 printf("lcore %u cannot be masked on for running "
3409 "packet forwarding, which is the main lcore "
3410 "and reserved for command line parsing only\n",
3415 fwd_lcores_cpuids[i] = lcore_cpuid;
3417 if (record_now == 0) {
3421 nb_cfg_lcores = (lcoreid_t) nb_lc;
3422 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
3423 printf("previous number of forwarding cores %u - changed to "
3424 "number of configured cores %u\n",
3425 (unsigned int) nb_fwd_lcores, nb_lc);
3426 nb_fwd_lcores = (lcoreid_t) nb_lc;
3433 set_fwd_lcores_mask(uint64_t lcoremask)
3435 unsigned int lcorelist[64];
3439 if (lcoremask == 0) {
3440 printf("Invalid NULL mask of cores\n");
3444 for (i = 0; i < 64; i++) {
3445 if (! ((uint64_t)(1ULL << i) & lcoremask))
3447 lcorelist[nb_lc++] = i;
3449 return set_fwd_lcores_list(lcorelist, nb_lc);
3453 set_fwd_lcores_number(uint16_t nb_lc)
3455 if (test_done == 0) {
3456 printf("Please stop forwarding first\n");
3459 if (nb_lc > nb_cfg_lcores) {
3460 printf("nb fwd cores %u > %u (max. number of configured "
3461 "lcores) - ignored\n",
3462 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
3465 nb_fwd_lcores = (lcoreid_t) nb_lc;
3466 printf("Number of forwarding cores set to %u\n",
3467 (unsigned int) nb_fwd_lcores);
3471 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
3479 for (i = 0; i < nb_pt; i++) {
3480 port_id = (portid_t) portlist[i];
3481 if (port_id_is_invalid(port_id, ENABLED_WARN))
3484 fwd_ports_ids[i] = port_id;
3486 if (record_now == 0) {
3490 nb_cfg_ports = (portid_t) nb_pt;
3491 if (nb_fwd_ports != (portid_t) nb_pt) {
3492 printf("previous number of forwarding ports %u - changed to "
3493 "number of configured ports %u\n",
3494 (unsigned int) nb_fwd_ports, nb_pt);
3495 nb_fwd_ports = (portid_t) nb_pt;
3500 * Parse the user input and obtain the list of forwarding ports
3503 * String containing the user input. User can specify
3504 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
3505 * For example, if the user wants to use all the available
3506 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
3507 * If the user wants to use only the ports 1,2 then the input
3509 * valid characters are '-' and ','
3510 * @param[out] values
3511 * This array will be filled with a list of port IDs
3512 * based on the user input
3513 * Note that duplicate entries are discarded and only the first
3514 * count entries in this array are port IDs and all the rest
3515 * will contain default values
3516 * @param[in] maxsize
3517 * This parameter denotes 2 things
3518 * 1) Number of elements in the values array
3519 * 2) Maximum value of each element in the values array
3521 * On success, returns total count of parsed port IDs
3522 * On failure, returns 0
3525 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
3527 unsigned int count = 0;
3531 unsigned int marked[maxsize];
3533 if (list == NULL || values == NULL)
3536 for (i = 0; i < (int)maxsize; i++)
3542 /*Remove the blank spaces if any*/
3543 while (isblank(*list))
3548 value = strtol(list, &end, 10);
3549 if (errno || end == NULL)
3551 if (value < 0 || value >= (int)maxsize)
3553 while (isblank(*end))
3555 if (*end == '-' && min == INT_MAX) {
3557 } else if ((*end == ',') || (*end == '\0')) {
3561 for (i = min; i <= max; i++) {
3562 if (count < maxsize) {
3574 } while (*end != '\0');
3580 parse_fwd_portlist(const char *portlist)
3582 unsigned int portcount;
3583 unsigned int portindex[RTE_MAX_ETHPORTS];
3584 unsigned int i, valid_port_count = 0;
3586 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
3588 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
3591 * Here we verify the validity of the ports
3592 * and thereby calculate the total number of
3595 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
3596 if (rte_eth_dev_is_valid_port(portindex[i])) {
3597 portindex[valid_port_count] = portindex[i];
3602 set_fwd_ports_list(portindex, valid_port_count);
3606 set_fwd_ports_mask(uint64_t portmask)
3608 unsigned int portlist[64];
3612 if (portmask == 0) {
3613 printf("Invalid NULL mask of ports\n");
3617 RTE_ETH_FOREACH_DEV(i) {
3618 if (! ((uint64_t)(1ULL << i) & portmask))
3620 portlist[nb_pt++] = i;
3622 set_fwd_ports_list(portlist, nb_pt);
3626 set_fwd_ports_number(uint16_t nb_pt)
3628 if (nb_pt > nb_cfg_ports) {
3629 printf("nb fwd ports %u > %u (number of configured "
3630 "ports) - ignored\n",
3631 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
3634 nb_fwd_ports = (portid_t) nb_pt;
3635 printf("Number of forwarding ports set to %u\n",
3636 (unsigned int) nb_fwd_ports);
3640 port_is_forwarding(portid_t port_id)
3644 if (port_id_is_invalid(port_id, ENABLED_WARN))
3647 for (i = 0; i < nb_fwd_ports; i++) {
3648 if (fwd_ports_ids[i] == port_id)
3656 set_nb_pkt_per_burst(uint16_t nb)
3658 if (nb > MAX_PKT_BURST) {
3659 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
3661 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
3664 nb_pkt_per_burst = nb;
3665 printf("Number of packets per burst set to %u\n",
3666 (unsigned int) nb_pkt_per_burst);
3670 tx_split_get_name(enum tx_pkt_split split)
3674 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3675 if (tx_split_name[i].split == split)
3676 return tx_split_name[i].name;
3682 set_tx_pkt_split(const char *name)
3686 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3687 if (strcmp(tx_split_name[i].name, name) == 0) {
3688 tx_pkt_split = tx_split_name[i].split;
3692 printf("unknown value: \"%s\"\n", name);
3696 parse_fec_mode(const char *name, uint32_t *mode)
3700 for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
3701 if (strcmp(fec_mode_name[i].name, name) == 0) {
3702 *mode = RTE_ETH_FEC_MODE_TO_CAPA(fec_mode_name[i].mode);
3710 show_fec_capability(unsigned int num, struct rte_eth_fec_capa *speed_fec_capa)
3714 printf("FEC capabilities:\n");
3716 for (i = 0; i < num; i++) {
3718 rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
3720 for (j = 0; j < RTE_DIM(fec_mode_name); j++) {
3721 if (RTE_ETH_FEC_MODE_TO_CAPA(j) &
3722 speed_fec_capa[i].capa)
3723 printf("%s ", fec_mode_name[j].name);
3730 show_rx_pkt_offsets(void)
3735 printf("Number of offsets: %u\n", n);
3737 printf("Segment offsets: ");
3738 for (i = 0; i != n - 1; i++)
3739 printf("%hu,", rx_pkt_seg_offsets[i]);
3740 printf("%hu\n", rx_pkt_seg_lengths[i]);
3745 set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs)
3749 if (nb_offs >= MAX_SEGS_BUFFER_SPLIT) {
3750 printf("nb segments per RX packets=%u >= "
3751 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_offs);
3756 * No extra check here, the segment length will be checked by PMD
3757 * in the extended queue setup.
3759 for (i = 0; i < nb_offs; i++) {
3760 if (seg_offsets[i] >= UINT16_MAX) {
3761 printf("offset[%u]=%u > UINT16_MAX - give up\n",
3767 for (i = 0; i < nb_offs; i++)
3768 rx_pkt_seg_offsets[i] = (uint16_t) seg_offsets[i];
3770 rx_pkt_nb_offs = (uint8_t) nb_offs;
3774 show_rx_pkt_segments(void)
3779 printf("Number of segments: %u\n", n);
3781 printf("Segment sizes: ");
3782 for (i = 0; i != n - 1; i++)
3783 printf("%hu,", rx_pkt_seg_lengths[i]);
3784 printf("%hu\n", rx_pkt_seg_lengths[i]);
3789 set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
3793 if (nb_segs >= MAX_SEGS_BUFFER_SPLIT) {
3794 printf("nb segments per RX packets=%u >= "
3795 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs);
3800 * No extra check here, the segment length will be checked by PMD
3801 * in the extended queue setup.
3803 for (i = 0; i < nb_segs; i++) {
3804 if (seg_lengths[i] >= UINT16_MAX) {
3805 printf("length[%u]=%u > UINT16_MAX - give up\n",
3811 for (i = 0; i < nb_segs; i++)
3812 rx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3814 rx_pkt_nb_segs = (uint8_t) nb_segs;
3818 show_tx_pkt_segments(void)
3824 split = tx_split_get_name(tx_pkt_split);
3826 printf("Number of segments: %u\n", n);
3827 printf("Segment sizes: ");
3828 for (i = 0; i != n - 1; i++)
3829 printf("%hu,", tx_pkt_seg_lengths[i]);
3830 printf("%hu\n", tx_pkt_seg_lengths[i]);
3831 printf("Split packet: %s\n", split);
3835 nb_segs_is_invalid(unsigned int nb_segs)
3842 RTE_ETH_FOREACH_DEV(port_id) {
3843 for (queue_id = 0; queue_id < nb_txq; queue_id++) {
3844 ret = get_tx_ring_size(port_id, queue_id, &ring_size);
3849 if (ring_size < nb_segs) {
3850 printf("nb segments per TX packets=%u >= "
3851 "TX queue(%u) ring_size=%u - ignored\n",
3852 nb_segs, queue_id, ring_size);
3862 set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
3864 uint16_t tx_pkt_len;
3867 if (nb_segs_is_invalid(nb_segs))
3871 * Check that each segment length is greater or equal than
3872 * the mbuf data sise.
3873 * Check also that the total packet length is greater or equal than the
3874 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
3878 for (i = 0; i < nb_segs; i++) {
3879 if (seg_lengths[i] > mbuf_data_size[0]) {
3880 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
3881 i, seg_lengths[i], mbuf_data_size[0]);
3884 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
3886 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
3887 printf("total packet length=%u < %d - give up\n",
3888 (unsigned) tx_pkt_len,
3889 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
3893 for (i = 0; i < nb_segs; i++)
3894 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3896 tx_pkt_length = tx_pkt_len;
3897 tx_pkt_nb_segs = (uint8_t) nb_segs;
3901 show_tx_pkt_times(void)
3903 printf("Interburst gap: %u\n", tx_pkt_times_inter);
3904 printf("Intraburst gap: %u\n", tx_pkt_times_intra);
3908 set_tx_pkt_times(unsigned int *tx_times)
3910 tx_pkt_times_inter = tx_times[0];
3911 tx_pkt_times_intra = tx_times[1];
3915 setup_gro(const char *onoff, portid_t port_id)
3917 if (!rte_eth_dev_is_valid_port(port_id)) {
3918 printf("invalid port id %u\n", port_id);
3921 if (test_done == 0) {
3922 printf("Before enable/disable GRO,"
3923 " please stop forwarding first\n");
3926 if (strcmp(onoff, "on") == 0) {
3927 if (gro_ports[port_id].enable != 0) {
3928 printf("Port %u has enabled GRO. Please"
3929 " disable GRO first\n", port_id);
3932 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3933 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
3934 gro_ports[port_id].param.max_flow_num =
3935 GRO_DEFAULT_FLOW_NUM;
3936 gro_ports[port_id].param.max_item_per_flow =
3937 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
3939 gro_ports[port_id].enable = 1;
3941 if (gro_ports[port_id].enable == 0) {
3942 printf("Port %u has disabled GRO\n", port_id);
3945 gro_ports[port_id].enable = 0;
3950 setup_gro_flush_cycles(uint8_t cycles)
3952 if (test_done == 0) {
3953 printf("Before change flush interval for GRO,"
3954 " please stop forwarding first.\n");
3958 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
3959 GRO_DEFAULT_FLUSH_CYCLES) {
3960 printf("The flushing cycle be in the range"
3961 " of 1 to %u. Revert to the default"
3963 GRO_MAX_FLUSH_CYCLES,
3964 GRO_DEFAULT_FLUSH_CYCLES);
3965 cycles = GRO_DEFAULT_FLUSH_CYCLES;
3968 gro_flush_cycles = cycles;
3972 show_gro(portid_t port_id)
3974 struct rte_gro_param *param;
3975 uint32_t max_pkts_num;
3977 param = &gro_ports[port_id].param;
3979 if (!rte_eth_dev_is_valid_port(port_id)) {
3980 printf("Invalid port id %u.\n", port_id);
3983 if (gro_ports[port_id].enable) {
3984 printf("GRO type: TCP/IPv4\n");
3985 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3986 max_pkts_num = param->max_flow_num *
3987 param->max_item_per_flow;
3989 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
3990 printf("Max number of packets to perform GRO: %u\n",
3992 printf("Flushing cycles: %u\n", gro_flush_cycles);
3994 printf("Port %u doesn't enable GRO.\n", port_id);
3998 setup_gso(const char *mode, portid_t port_id)
4000 if (!rte_eth_dev_is_valid_port(port_id)) {
4001 printf("invalid port id %u\n", port_id);
4004 if (strcmp(mode, "on") == 0) {
4005 if (test_done == 0) {
4006 printf("before enabling GSO,"
4007 " please stop forwarding first\n");
4010 gso_ports[port_id].enable = 1;
4011 } else if (strcmp(mode, "off") == 0) {
4012 if (test_done == 0) {
4013 printf("before disabling GSO,"
4014 " please stop forwarding first\n");
4017 gso_ports[port_id].enable = 0;
4022 list_pkt_forwarding_modes(void)
4024 static char fwd_modes[128] = "";
4025 const char *separator = "|";
4026 struct fwd_engine *fwd_eng;
4029 if (strlen (fwd_modes) == 0) {
4030 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4031 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4032 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4033 strncat(fwd_modes, separator,
4034 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4036 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4043 list_pkt_forwarding_retry_modes(void)
4045 static char fwd_modes[128] = "";
4046 const char *separator = "|";
4047 struct fwd_engine *fwd_eng;
4050 if (strlen(fwd_modes) == 0) {
4051 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4052 if (fwd_eng == &rx_only_engine)
4054 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4056 strlen(fwd_modes) - 1);
4057 strncat(fwd_modes, separator,
4059 strlen(fwd_modes) - 1);
4061 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4068 set_pkt_forwarding_mode(const char *fwd_mode_name)
4070 struct fwd_engine *fwd_eng;
4074 while ((fwd_eng = fwd_engines[i]) != NULL) {
4075 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
4076 printf("Set %s packet forwarding mode%s\n",
4078 retry_enabled == 0 ? "" : " with retry");
4079 cur_fwd_eng = fwd_eng;
4084 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
4088 add_rx_dump_callbacks(portid_t portid)
4090 struct rte_eth_dev_info dev_info;
4094 if (port_id_is_invalid(portid, ENABLED_WARN))
4097 ret = eth_dev_info_get_print_err(portid, &dev_info);
4101 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4102 if (!ports[portid].rx_dump_cb[queue])
4103 ports[portid].rx_dump_cb[queue] =
4104 rte_eth_add_rx_callback(portid, queue,
4105 dump_rx_pkts, NULL);
4109 add_tx_dump_callbacks(portid_t portid)
4111 struct rte_eth_dev_info dev_info;
4115 if (port_id_is_invalid(portid, ENABLED_WARN))
4118 ret = eth_dev_info_get_print_err(portid, &dev_info);
4122 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4123 if (!ports[portid].tx_dump_cb[queue])
4124 ports[portid].tx_dump_cb[queue] =
4125 rte_eth_add_tx_callback(portid, queue,
4126 dump_tx_pkts, NULL);
4130 remove_rx_dump_callbacks(portid_t portid)
4132 struct rte_eth_dev_info dev_info;
4136 if (port_id_is_invalid(portid, ENABLED_WARN))
4139 ret = eth_dev_info_get_print_err(portid, &dev_info);
4143 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4144 if (ports[portid].rx_dump_cb[queue]) {
4145 rte_eth_remove_rx_callback(portid, queue,
4146 ports[portid].rx_dump_cb[queue]);
4147 ports[portid].rx_dump_cb[queue] = NULL;
4152 remove_tx_dump_callbacks(portid_t portid)
4154 struct rte_eth_dev_info dev_info;
4158 if (port_id_is_invalid(portid, ENABLED_WARN))
4161 ret = eth_dev_info_get_print_err(portid, &dev_info);
4165 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4166 if (ports[portid].tx_dump_cb[queue]) {
4167 rte_eth_remove_tx_callback(portid, queue,
4168 ports[portid].tx_dump_cb[queue]);
4169 ports[portid].tx_dump_cb[queue] = NULL;
4174 configure_rxtx_dump_callbacks(uint16_t verbose)
4178 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4179 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
4183 RTE_ETH_FOREACH_DEV(portid)
4185 if (verbose == 1 || verbose > 2)
4186 add_rx_dump_callbacks(portid);
4188 remove_rx_dump_callbacks(portid);
4190 add_tx_dump_callbacks(portid);
4192 remove_tx_dump_callbacks(portid);
4197 set_verbose_level(uint16_t vb_level)
4199 printf("Change verbose level from %u to %u\n",
4200 (unsigned int) verbose_level, (unsigned int) vb_level);
4201 verbose_level = vb_level;
4202 configure_rxtx_dump_callbacks(verbose_level);
4206 vlan_extend_set(portid_t port_id, int on)
4210 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4212 if (port_id_is_invalid(port_id, ENABLED_WARN))
4215 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4218 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
4219 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
4221 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
4222 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
4225 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4227 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
4228 "diag=%d\n", port_id, on, diag);
4231 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4235 rx_vlan_strip_set(portid_t port_id, int on)
4239 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4241 if (port_id_is_invalid(port_id, ENABLED_WARN))
4244 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4247 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
4248 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
4250 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
4251 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
4254 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4256 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
4257 "diag=%d\n", port_id, on, diag);
4260 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4264 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
4268 if (port_id_is_invalid(port_id, ENABLED_WARN))
4271 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
4273 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
4274 "diag=%d\n", port_id, queue_id, on, diag);
4278 rx_vlan_filter_set(portid_t port_id, int on)
4282 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4284 if (port_id_is_invalid(port_id, ENABLED_WARN))
4287 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4290 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
4291 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
4293 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
4294 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
4297 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4299 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
4300 "diag=%d\n", port_id, on, diag);
4303 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4307 rx_vlan_qinq_strip_set(portid_t port_id, int on)
4311 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4313 if (port_id_is_invalid(port_id, ENABLED_WARN))
4316 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4319 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
4320 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
4322 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
4323 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
4326 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4328 printf("%s(port_pi=%d, on=%d) failed "
4329 "diag=%d\n", __func__, port_id, on, diag);
4332 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4336 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
4340 if (port_id_is_invalid(port_id, ENABLED_WARN))
4342 if (vlan_id_is_invalid(vlan_id))
4344 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
4347 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
4349 port_id, vlan_id, on, diag);
4354 rx_vlan_all_filter_set(portid_t port_id, int on)
4358 if (port_id_is_invalid(port_id, ENABLED_WARN))
4360 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
4361 if (rx_vft_set(port_id, vlan_id, on))
4367 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
4371 if (port_id_is_invalid(port_id, ENABLED_WARN))
4374 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
4378 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
4380 port_id, vlan_type, tp_id, diag);
4384 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
4386 struct rte_eth_dev_info dev_info;
4389 if (vlan_id_is_invalid(vlan_id))
4392 if (ports[port_id].dev_conf.txmode.offloads &
4393 DEV_TX_OFFLOAD_QINQ_INSERT) {
4394 printf("Error, as QinQ has been enabled.\n");
4398 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4402 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
4403 printf("Error: vlan insert is not supported by port %d\n",
4408 tx_vlan_reset(port_id);
4409 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
4410 ports[port_id].tx_vlan_id = vlan_id;
4414 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
4416 struct rte_eth_dev_info dev_info;
4419 if (vlan_id_is_invalid(vlan_id))
4421 if (vlan_id_is_invalid(vlan_id_outer))
4424 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4428 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
4429 printf("Error: qinq insert not supported by port %d\n",
4434 tx_vlan_reset(port_id);
4435 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
4436 DEV_TX_OFFLOAD_QINQ_INSERT);
4437 ports[port_id].tx_vlan_id = vlan_id;
4438 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
4442 tx_vlan_reset(portid_t port_id)
4444 ports[port_id].dev_conf.txmode.offloads &=
4445 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
4446 DEV_TX_OFFLOAD_QINQ_INSERT);
4447 ports[port_id].tx_vlan_id = 0;
4448 ports[port_id].tx_vlan_id_outer = 0;
4452 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
4454 if (port_id_is_invalid(port_id, ENABLED_WARN))
4457 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
4461 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
4465 if (port_id_is_invalid(port_id, ENABLED_WARN))
4468 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
4471 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
4472 printf("map_value not in required range 0..%d\n",
4473 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
4477 if (!is_rx) { /* tx */
4478 ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, queue_id,
4481 printf("failed to set tx queue stats mapping.\n");
4485 ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, queue_id,
4488 printf("failed to set rx queue stats mapping.\n");
4495 set_xstats_hide_zero(uint8_t on_off)
4497 xstats_hide_zero = on_off;
4501 set_record_core_cycles(uint8_t on_off)
4503 record_core_cycles = on_off;
4507 set_record_burst_stats(uint8_t on_off)
4509 record_burst_stats = on_off;
4513 print_fdir_mask(struct rte_eth_fdir_masks *mask)
4515 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
4517 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4518 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
4519 " tunnel_id: 0x%08x",
4520 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
4521 rte_be_to_cpu_32(mask->tunnel_id_mask));
4522 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
4523 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
4524 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
4525 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
4527 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
4528 rte_be_to_cpu_16(mask->src_port_mask),
4529 rte_be_to_cpu_16(mask->dst_port_mask));
4531 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4532 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
4533 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
4534 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
4535 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
4537 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4538 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
4539 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
4540 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
4541 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
4548 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4550 struct rte_eth_flex_payload_cfg *cfg;
4553 for (i = 0; i < flex_conf->nb_payloads; i++) {
4554 cfg = &flex_conf->flex_set[i];
4555 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
4557 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
4558 printf("\n L2_PAYLOAD: ");
4559 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
4560 printf("\n L3_PAYLOAD: ");
4561 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
4562 printf("\n L4_PAYLOAD: ");
4564 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
4565 for (j = 0; j < num; j++)
4566 printf(" %-5u", cfg->src_offset[j]);
4572 flowtype_to_str(uint16_t flow_type)
4574 struct flow_type_info {
4580 static struct flow_type_info flowtype_str_table[] = {
4581 {"raw", RTE_ETH_FLOW_RAW},
4582 {"ipv4", RTE_ETH_FLOW_IPV4},
4583 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
4584 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
4585 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
4586 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
4587 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
4588 {"ipv6", RTE_ETH_FLOW_IPV6},
4589 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
4590 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
4591 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
4592 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
4593 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
4594 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
4595 {"port", RTE_ETH_FLOW_PORT},
4596 {"vxlan", RTE_ETH_FLOW_VXLAN},
4597 {"geneve", RTE_ETH_FLOW_GENEVE},
4598 {"nvgre", RTE_ETH_FLOW_NVGRE},
4599 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
4602 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
4603 if (flowtype_str_table[i].ftype == flow_type)
4604 return flowtype_str_table[i].str;
4610 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
4613 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4615 struct rte_eth_fdir_flex_mask *mask;
4619 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
4620 mask = &flex_conf->flex_mask[i];
4621 p = flowtype_to_str(mask->flow_type);
4622 printf("\n %s:\t", p ? p : "unknown");
4623 for (j = 0; j < num; j++)
4624 printf(" %02x", mask->mask[j]);
4630 print_fdir_flow_type(uint32_t flow_types_mask)
4635 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
4636 if (!(flow_types_mask & (1 << i)))
4638 p = flowtype_to_str(i);
4648 get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info,
4649 struct rte_eth_fdir_stats *fdir_stat)
4654 if (ret == -ENOTSUP) {
4655 ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info);
4657 ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat);
4660 #ifdef RTE_NET_IXGBE
4661 if (ret == -ENOTSUP) {
4662 ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info);
4664 ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat);
4671 printf("\n FDIR is not supported on port %-2d\n",
4675 printf("programming error: (%s)\n", strerror(-ret));
4682 fdir_get_infos(portid_t port_id)
4684 struct rte_eth_fdir_stats fdir_stat;
4685 struct rte_eth_fdir_info fdir_info;
4687 static const char *fdir_stats_border = "########################";
4689 if (port_id_is_invalid(port_id, ENABLED_WARN))
4692 memset(&fdir_info, 0, sizeof(fdir_info));
4693 memset(&fdir_stat, 0, sizeof(fdir_stat));
4694 if (get_fdir_info(port_id, &fdir_info, &fdir_stat))
4697 printf("\n %s FDIR infos for port %-2d %s\n",
4698 fdir_stats_border, port_id, fdir_stats_border);
4700 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
4701 printf(" PERFECT\n");
4702 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
4703 printf(" PERFECT-MAC-VLAN\n");
4704 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4705 printf(" PERFECT-TUNNEL\n");
4706 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
4707 printf(" SIGNATURE\n");
4709 printf(" DISABLE\n");
4710 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
4711 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
4712 printf(" SUPPORTED FLOW TYPE: ");
4713 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
4715 printf(" FLEX PAYLOAD INFO:\n");
4716 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
4717 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
4718 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
4719 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
4720 fdir_info.flex_payload_unit,
4721 fdir_info.max_flex_payload_segment_num,
4722 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
4724 print_fdir_mask(&fdir_info.mask);
4725 if (fdir_info.flex_conf.nb_payloads > 0) {
4726 printf(" FLEX PAYLOAD SRC OFFSET:");
4727 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4729 if (fdir_info.flex_conf.nb_flexmasks > 0) {
4730 printf(" FLEX MASK CFG:");
4731 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4733 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
4734 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
4735 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
4736 fdir_info.guarant_spc, fdir_info.best_spc);
4737 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
4738 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
4739 " add: %-10"PRIu64" remove: %"PRIu64"\n"
4740 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
4741 fdir_stat.collision, fdir_stat.free,
4742 fdir_stat.maxhash, fdir_stat.maxlen,
4743 fdir_stat.add, fdir_stat.remove,
4744 fdir_stat.f_add, fdir_stat.f_remove);
4745 printf(" %s############################%s\n",
4746 fdir_stats_border, fdir_stats_border);
4749 #endif /* RTE_NET_I40E || RTE_NET_IXGBE */
4752 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
4754 struct rte_port *port;
4755 struct rte_eth_fdir_flex_conf *flex_conf;
4758 port = &ports[port_id];
4759 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
4760 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
4761 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
4766 if (i >= RTE_ETH_FLOW_MAX) {
4767 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
4768 idx = flex_conf->nb_flexmasks;
4769 flex_conf->nb_flexmasks++;
4771 printf("The flex mask table is full. Can not set flex"
4772 " mask for flow_type(%u).", cfg->flow_type);
4776 rte_memcpy(&flex_conf->flex_mask[idx],
4778 sizeof(struct rte_eth_fdir_flex_mask));
4782 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
4784 struct rte_port *port;
4785 struct rte_eth_fdir_flex_conf *flex_conf;
4788 port = &ports[port_id];
4789 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
4790 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
4791 if (cfg->type == flex_conf->flex_set[i].type) {
4796 if (i >= RTE_ETH_PAYLOAD_MAX) {
4797 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
4798 idx = flex_conf->nb_payloads;
4799 flex_conf->nb_payloads++;
4801 printf("The flex payload table is full. Can not set"
4802 " flex payload for type(%u).", cfg->type);
4806 rte_memcpy(&flex_conf->flex_set[idx],
4808 sizeof(struct rte_eth_flex_payload_cfg));
4813 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
4815 #ifdef RTE_NET_IXGBE
4819 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
4821 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
4825 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
4826 is_rx ? "rx" : "tx", port_id, diag);
4829 printf("VF %s setting not supported for port %d\n",
4830 is_rx ? "Rx" : "Tx", port_id);
4836 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
4839 struct rte_eth_link link;
4842 if (port_id_is_invalid(port_id, ENABLED_WARN))
4844 ret = eth_link_get_nowait_print_err(port_id, &link);
4847 if (link.link_speed != ETH_SPEED_NUM_UNKNOWN &&
4848 rate > link.link_speed) {
4849 printf("Invalid rate value:%u bigger than link speed: %u\n",
4850 rate, link.link_speed);
4853 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
4856 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
4862 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
4864 int diag = -ENOTSUP;
4868 RTE_SET_USED(q_msk);
4870 #ifdef RTE_NET_IXGBE
4871 if (diag == -ENOTSUP)
4872 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
4876 if (diag == -ENOTSUP)
4877 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
4882 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
4888 * Functions to manage the set of filtered Multicast MAC addresses.
4890 * A pool of filtered multicast MAC addresses is associated with each port.
4891 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
4892 * The address of the pool and the number of valid multicast MAC addresses
4893 * recorded in the pool are stored in the fields "mc_addr_pool" and
4894 * "mc_addr_nb" of the "rte_port" data structure.
4896 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
4897 * to be supplied a contiguous array of multicast MAC addresses.
4898 * To comply with this constraint, the set of multicast addresses recorded
4899 * into the pool are systematically compacted at the beginning of the pool.
4900 * Hence, when a multicast address is removed from the pool, all following
4901 * addresses, if any, are copied back to keep the set contiguous.
4903 #define MCAST_POOL_INC 32
4906 mcast_addr_pool_extend(struct rte_port *port)
4908 struct rte_ether_addr *mc_pool;
4909 size_t mc_pool_size;
4912 * If a free entry is available at the end of the pool, just
4913 * increment the number of recorded multicast addresses.
4915 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
4921 * [re]allocate a pool with MCAST_POOL_INC more entries.
4922 * The previous test guarantees that port->mc_addr_nb is a multiple
4923 * of MCAST_POOL_INC.
4925 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
4927 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
4929 if (mc_pool == NULL) {
4930 printf("allocation of pool of %u multicast addresses failed\n",
4931 port->mc_addr_nb + MCAST_POOL_INC);
4935 port->mc_addr_pool = mc_pool;
4942 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
4944 if (mcast_addr_pool_extend(port) != 0)
4946 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
4950 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
4953 if (addr_idx == port->mc_addr_nb) {
4954 /* No need to recompact the set of multicast addressses. */
4955 if (port->mc_addr_nb == 0) {
4956 /* free the pool of multicast addresses. */
4957 free(port->mc_addr_pool);
4958 port->mc_addr_pool = NULL;
4962 memmove(&port->mc_addr_pool[addr_idx],
4963 &port->mc_addr_pool[addr_idx + 1],
4964 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
4968 eth_port_multicast_addr_list_set(portid_t port_id)
4970 struct rte_port *port;
4973 port = &ports[port_id];
4974 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
4977 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
4978 port_id, port->mc_addr_nb, diag);
4984 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
4986 struct rte_port *port;
4989 if (port_id_is_invalid(port_id, ENABLED_WARN))
4992 port = &ports[port_id];
4995 * Check that the added multicast MAC address is not already recorded
4996 * in the pool of multicast addresses.
4998 for (i = 0; i < port->mc_addr_nb; i++) {
4999 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
5000 printf("multicast address already filtered by port\n");
5005 mcast_addr_pool_append(port, mc_addr);
5006 if (eth_port_multicast_addr_list_set(port_id) < 0)
5007 /* Rollback on failure, remove the address from the pool */
5008 mcast_addr_pool_remove(port, i);
5012 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
5014 struct rte_port *port;
5017 if (port_id_is_invalid(port_id, ENABLED_WARN))
5020 port = &ports[port_id];
5023 * Search the pool of multicast MAC addresses for the removed address.
5025 for (i = 0; i < port->mc_addr_nb; i++) {
5026 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
5029 if (i == port->mc_addr_nb) {
5030 printf("multicast address not filtered by port %d\n", port_id);
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 printf("\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 printf("%s: Failed to open %s\n", __func__, file_path);
5100 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
5102 printf("%s: File operations failed\n", __func__);
5106 pkg_size = st_buf.st_size;
5109 printf("%s: File operations failed\n", __func__);
5113 buf = (uint8_t *)malloc(pkg_size);
5116 printf("%s: Failed to malloc memory\n", __func__);
5120 ret = read(fd, buf, pkg_size);
5123 printf("%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 printf("%s: Failed to open %s\n", __func__, file_path);
5146 if (fwrite(buf, 1, size, fh) != size) {
5148 printf("%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 rte_eth_dev_info_get(port_id, &dev_info);
5224 for (i = 0; i < dev_info.max_mac_addrs; i++) {
5225 addr = &dev->data->mac_addrs[i];
5227 /* skip zero address */
5228 if (rte_is_zero_ether_addr(addr))
5234 printf("Number of MAC address added: %d\n", num_macs);
5236 for (i = 0; i < dev_info.max_mac_addrs; i++) {
5237 addr = &dev->data->mac_addrs[i];
5239 /* skip zero address */
5240 if (rte_is_zero_ether_addr(addr))
5243 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5244 printf(" %s\n", buf);
5249 show_mcast_macs(portid_t port_id)
5251 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5252 struct rte_ether_addr *addr;
5253 struct rte_port *port;
5256 port = &ports[port_id];
5258 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
5260 for (i = 0; i < port->mc_addr_nb; i++) {
5261 addr = &port->mc_addr_pool[i];
5263 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5264 printf(" %s\n", buf);