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>
42 #ifdef RTE_LIBRTE_IXGBE_PMD
43 #include <rte_pmd_ixgbe.h>
45 #ifdef RTE_LIBRTE_I40E_PMD
46 #include <rte_pmd_i40e.h>
48 #ifdef RTE_LIBRTE_BNXT_PMD
49 #include <rte_pmd_bnxt.h>
55 #define ETHDEV_FWVERS_LEN 32
57 static char *flowtype_to_str(uint16_t flow_type);
60 enum tx_pkt_split split;
64 .split = TX_PKT_SPLIT_OFF,
68 .split = TX_PKT_SPLIT_ON,
72 .split = TX_PKT_SPLIT_RND,
77 const struct rss_type_info rss_type_table[] = {
78 { "all", ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP | ETH_RSS_TCP |
79 ETH_RSS_UDP | ETH_RSS_SCTP | ETH_RSS_L2_PAYLOAD |
80 ETH_RSS_L2TPV3 | ETH_RSS_ESP | ETH_RSS_AH | ETH_RSS_PFCP},
82 { "eth", ETH_RSS_ETH },
83 { "l2-src-only", ETH_RSS_L2_SRC_ONLY },
84 { "l2-dst-only", ETH_RSS_L2_DST_ONLY },
85 { "vlan", ETH_RSS_VLAN },
86 { "s-vlan", ETH_RSS_S_VLAN },
87 { "c-vlan", ETH_RSS_C_VLAN },
88 { "ipv4", ETH_RSS_IPV4 },
89 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
90 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
91 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
92 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
93 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
94 { "ipv6", ETH_RSS_IPV6 },
95 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
96 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
97 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
98 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
99 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
100 { "l2-payload", ETH_RSS_L2_PAYLOAD },
101 { "ipv6-ex", ETH_RSS_IPV6_EX },
102 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
103 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
104 { "port", ETH_RSS_PORT },
105 { "vxlan", ETH_RSS_VXLAN },
106 { "geneve", ETH_RSS_GENEVE },
107 { "nvgre", ETH_RSS_NVGRE },
108 { "ip", ETH_RSS_IP },
109 { "udp", ETH_RSS_UDP },
110 { "tcp", ETH_RSS_TCP },
111 { "sctp", ETH_RSS_SCTP },
112 { "tunnel", ETH_RSS_TUNNEL },
113 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
114 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
115 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
116 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
117 { "esp", ETH_RSS_ESP },
118 { "ah", ETH_RSS_AH },
119 { "l2tpv3", ETH_RSS_L2TPV3 },
120 { "pfcp", ETH_RSS_PFCP },
125 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
127 char buf[RTE_ETHER_ADDR_FMT_SIZE];
128 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
129 printf("%s%s", name, buf);
133 nic_stats_display(portid_t port_id)
135 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
136 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
137 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
138 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
139 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
140 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
142 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
143 struct rte_eth_stats stats;
144 struct rte_port *port = &ports[port_id];
147 static const char *nic_stats_border = "########################";
149 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
153 rte_eth_stats_get(port_id, &stats);
154 printf("\n %s NIC statistics for port %-2d %s\n",
155 nic_stats_border, port_id, nic_stats_border);
157 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
158 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
160 stats.ipackets, stats.imissed, stats.ibytes);
161 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
162 printf(" RX-nombuf: %-10"PRIu64"\n",
164 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
166 stats.opackets, stats.oerrors, stats.obytes);
169 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
170 " RX-bytes: %10"PRIu64"\n",
171 stats.ipackets, stats.ierrors, stats.ibytes);
172 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
173 printf(" RX-nombuf: %10"PRIu64"\n",
175 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
176 " TX-bytes: %10"PRIu64"\n",
177 stats.opackets, stats.oerrors, stats.obytes);
180 if (port->rx_queue_stats_mapping_enabled) {
182 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
183 printf(" Stats reg %2d RX-packets: %10"PRIu64
184 " RX-errors: %10"PRIu64
185 " RX-bytes: %10"PRIu64"\n",
186 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
189 if (port->tx_queue_stats_mapping_enabled) {
191 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
192 printf(" Stats reg %2d TX-packets: %10"PRIu64
193 " TX-bytes: %10"PRIu64"\n",
194 i, stats.q_opackets[i], stats.q_obytes[i]);
198 diff_cycles = prev_cycles[port_id];
199 prev_cycles[port_id] = rte_rdtsc();
201 diff_cycles = prev_cycles[port_id] - diff_cycles;
203 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
204 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
205 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
206 (stats.opackets - prev_pkts_tx[port_id]) : 0;
207 prev_pkts_rx[port_id] = stats.ipackets;
208 prev_pkts_tx[port_id] = stats.opackets;
209 mpps_rx = diff_cycles > 0 ?
210 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
211 mpps_tx = diff_cycles > 0 ?
212 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
214 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
215 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
216 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
217 (stats.obytes - prev_bytes_tx[port_id]) : 0;
218 prev_bytes_rx[port_id] = stats.ibytes;
219 prev_bytes_tx[port_id] = stats.obytes;
220 mbps_rx = diff_cycles > 0 ?
221 diff_bytes_rx * rte_get_tsc_hz() / diff_cycles : 0;
222 mbps_tx = diff_cycles > 0 ?
223 diff_bytes_tx * rte_get_tsc_hz() / diff_cycles : 0;
225 printf("\n Throughput (since last show)\n");
226 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
227 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
228 mpps_tx, mbps_tx * 8);
230 printf(" %s############################%s\n",
231 nic_stats_border, nic_stats_border);
235 nic_stats_clear(portid_t port_id)
237 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
241 rte_eth_stats_reset(port_id);
242 printf("\n NIC statistics for port %d cleared\n", port_id);
246 nic_xstats_display(portid_t port_id)
248 struct rte_eth_xstat *xstats;
249 int cnt_xstats, idx_xstat;
250 struct rte_eth_xstat_name *xstats_names;
252 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
256 printf("###### NIC extended statistics for port %-2d\n", port_id);
257 if (!rte_eth_dev_is_valid_port(port_id)) {
258 printf("Error: Invalid port number %i\n", port_id);
263 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
264 if (cnt_xstats < 0) {
265 printf("Error: Cannot get count of xstats\n");
269 /* Get id-name lookup table */
270 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
271 if (xstats_names == NULL) {
272 printf("Cannot allocate memory for xstats lookup\n");
275 if (cnt_xstats != rte_eth_xstats_get_names(
276 port_id, xstats_names, cnt_xstats)) {
277 printf("Error: Cannot get xstats lookup\n");
282 /* Get stats themselves */
283 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
284 if (xstats == NULL) {
285 printf("Cannot allocate memory for xstats\n");
289 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
290 printf("Error: Unable to get xstats\n");
297 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
298 if (xstats_hide_zero && !xstats[idx_xstat].value)
300 printf("%s: %"PRIu64"\n",
301 xstats_names[idx_xstat].name,
302 xstats[idx_xstat].value);
309 nic_xstats_clear(portid_t port_id)
313 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
317 ret = rte_eth_xstats_reset(port_id);
319 printf("%s: Error: failed to reset xstats (port %u): %s",
320 __func__, port_id, strerror(ret));
325 nic_stats_mapping_display(portid_t port_id)
327 struct rte_port *port = &ports[port_id];
330 static const char *nic_stats_mapping_border = "########################";
332 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
337 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
338 printf("Port id %d - either does not support queue statistic mapping or"
339 " no queue statistic mapping set\n", port_id);
343 printf("\n %s NIC statistics mapping for port %-2d %s\n",
344 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
346 if (port->rx_queue_stats_mapping_enabled) {
347 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
348 if (rx_queue_stats_mappings[i].port_id == port_id) {
349 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
350 rx_queue_stats_mappings[i].queue_id,
351 rx_queue_stats_mappings[i].stats_counter_id);
358 if (port->tx_queue_stats_mapping_enabled) {
359 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
360 if (tx_queue_stats_mappings[i].port_id == port_id) {
361 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
362 tx_queue_stats_mappings[i].queue_id,
363 tx_queue_stats_mappings[i].stats_counter_id);
368 printf(" %s####################################%s\n",
369 nic_stats_mapping_border, nic_stats_mapping_border);
373 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
375 struct rte_eth_burst_mode mode;
376 struct rte_eth_rxq_info qinfo;
378 static const char *info_border = "*********************";
380 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
382 printf("Failed to retrieve information for port: %u, "
383 "RX queue: %hu\nerror desc: %s(%d)\n",
384 port_id, queue_id, strerror(-rc), rc);
388 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
389 info_border, port_id, queue_id, info_border);
391 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
392 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
393 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
394 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
395 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
396 printf("\nRX drop packets: %s",
397 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
398 printf("\nRX deferred start: %s",
399 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
400 printf("\nRX scattered packets: %s",
401 (qinfo.scattered_rx != 0) ? "on" : "off");
402 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
404 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
405 printf("\nBurst mode: %s%s",
407 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
408 " (per queue)" : "");
414 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
416 struct rte_eth_burst_mode mode;
417 struct rte_eth_txq_info qinfo;
419 static const char *info_border = "*********************";
421 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
423 printf("Failed to retrieve information for port: %u, "
424 "TX queue: %hu\nerror desc: %s(%d)\n",
425 port_id, queue_id, strerror(-rc), rc);
429 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
430 info_border, port_id, queue_id, info_border);
432 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
433 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
434 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
435 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
436 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
437 printf("\nTX deferred start: %s",
438 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
439 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
441 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
442 printf("\nBurst mode: %s%s",
444 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
445 " (per queue)" : "");
450 static int bus_match_all(const struct rte_bus *bus, const void *data)
458 device_infos_display(const char *identifier)
460 static const char *info_border = "*********************";
461 struct rte_bus *start = NULL, *next;
462 struct rte_dev_iterator dev_iter;
463 char name[RTE_ETH_NAME_MAX_LEN];
464 struct rte_ether_addr mac_addr;
465 struct rte_device *dev;
466 struct rte_devargs da;
470 memset(&da, 0, sizeof(da));
474 if (rte_devargs_parsef(&da, "%s", identifier)) {
475 printf("cannot parse identifier\n");
482 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
485 if (identifier && da.bus != next)
488 /* Skip buses that don't have iterate method */
489 if (!next->dev_iterate)
492 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
493 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
497 /* Check for matching device if identifier is present */
499 strncmp(da.name, dev->name, strlen(dev->name)))
501 printf("\n%s Infos for device %s %s\n",
502 info_border, dev->name, info_border);
503 printf("Bus name: %s", dev->bus->name);
504 printf("\nDriver name: %s", dev->driver->name);
505 printf("\nDevargs: %s",
506 dev->devargs ? dev->devargs->args : "");
507 printf("\nConnect to socket: %d", dev->numa_node);
510 /* List ports with matching device name */
511 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
512 printf("\n\tPort id: %-2d", port_id);
513 if (eth_macaddr_get_print_err(port_id,
515 print_ethaddr("\n\tMAC address: ",
517 rte_eth_dev_get_name_by_port(port_id, name);
518 printf("\n\tDevice name: %s", name);
526 port_infos_display(portid_t port_id)
528 struct rte_port *port;
529 struct rte_ether_addr mac_addr;
530 struct rte_eth_link link;
531 struct rte_eth_dev_info dev_info;
533 struct rte_mempool * mp;
534 static const char *info_border = "*********************";
536 char name[RTE_ETH_NAME_MAX_LEN];
538 char fw_version[ETHDEV_FWVERS_LEN];
540 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
544 port = &ports[port_id];
545 ret = eth_link_get_nowait_print_err(port_id, &link);
549 ret = eth_dev_info_get_print_err(port_id, &dev_info);
553 printf("\n%s Infos for port %-2d %s\n",
554 info_border, port_id, info_border);
555 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
556 print_ethaddr("MAC address: ", &mac_addr);
557 rte_eth_dev_get_name_by_port(port_id, name);
558 printf("\nDevice name: %s", name);
559 printf("\nDriver name: %s", dev_info.driver_name);
561 if (rte_eth_dev_fw_version_get(port_id, fw_version,
562 ETHDEV_FWVERS_LEN) == 0)
563 printf("\nFirmware-version: %s", fw_version);
565 printf("\nFirmware-version: %s", "not available");
567 if (dev_info.device->devargs && dev_info.device->devargs->args)
568 printf("\nDevargs: %s", dev_info.device->devargs->args);
569 printf("\nConnect to socket: %u", port->socket_id);
571 if (port_numa[port_id] != NUMA_NO_CONFIG) {
572 mp = mbuf_pool_find(port_numa[port_id]);
574 printf("\nmemory allocation on the socket: %d",
577 printf("\nmemory allocation on the socket: %u",port->socket_id);
579 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
580 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
581 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
582 ("full-duplex") : ("half-duplex"));
584 if (!rte_eth_dev_get_mtu(port_id, &mtu))
585 printf("MTU: %u\n", mtu);
587 printf("Promiscuous mode: %s\n",
588 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
589 printf("Allmulticast mode: %s\n",
590 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
591 printf("Maximum number of MAC addresses: %u\n",
592 (unsigned int)(port->dev_info.max_mac_addrs));
593 printf("Maximum number of MAC addresses of hash filtering: %u\n",
594 (unsigned int)(port->dev_info.max_hash_mac_addrs));
596 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
597 if (vlan_offload >= 0){
598 printf("VLAN offload: \n");
599 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
600 printf(" strip on, ");
602 printf(" strip off, ");
604 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
605 printf("filter on, ");
607 printf("filter off, ");
609 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
610 printf("extend on, ");
612 printf("extend off, ");
614 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
615 printf("qinq strip on\n");
617 printf("qinq strip off\n");
620 if (dev_info.hash_key_size > 0)
621 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
622 if (dev_info.reta_size > 0)
623 printf("Redirection table size: %u\n", dev_info.reta_size);
624 if (!dev_info.flow_type_rss_offloads)
625 printf("No RSS offload flow type is supported.\n");
630 printf("Supported RSS offload flow types:\n");
631 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
632 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
633 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
635 p = flowtype_to_str(i);
639 printf(" user defined %d\n", i);
643 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
644 printf("Maximum configurable length of RX packet: %u\n",
645 dev_info.max_rx_pktlen);
646 printf("Maximum configurable size of LRO aggregated packet: %u\n",
647 dev_info.max_lro_pkt_size);
648 if (dev_info.max_vfs)
649 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
650 if (dev_info.max_vmdq_pools)
651 printf("Maximum number of VMDq pools: %u\n",
652 dev_info.max_vmdq_pools);
654 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
655 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
656 printf("Max possible number of RXDs per queue: %hu\n",
657 dev_info.rx_desc_lim.nb_max);
658 printf("Min possible number of RXDs per queue: %hu\n",
659 dev_info.rx_desc_lim.nb_min);
660 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
662 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
663 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
664 printf("Max possible number of TXDs per queue: %hu\n",
665 dev_info.tx_desc_lim.nb_max);
666 printf("Min possible number of TXDs per queue: %hu\n",
667 dev_info.tx_desc_lim.nb_min);
668 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
669 printf("Max segment number per packet: %hu\n",
670 dev_info.tx_desc_lim.nb_seg_max);
671 printf("Max segment number per MTU/TSO: %hu\n",
672 dev_info.tx_desc_lim.nb_mtu_seg_max);
674 /* Show switch info only if valid switch domain and port id is set */
675 if (dev_info.switch_info.domain_id !=
676 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
677 if (dev_info.switch_info.name)
678 printf("Switch name: %s\n", dev_info.switch_info.name);
680 printf("Switch domain Id: %u\n",
681 dev_info.switch_info.domain_id);
682 printf("Switch Port Id: %u\n",
683 dev_info.switch_info.port_id);
688 port_summary_header_display(void)
690 uint16_t port_number;
692 port_number = rte_eth_dev_count_avail();
693 printf("Number of available ports: %i\n", port_number);
694 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
695 "Driver", "Status", "Link");
699 port_summary_display(portid_t port_id)
701 struct rte_ether_addr mac_addr;
702 struct rte_eth_link link;
703 struct rte_eth_dev_info dev_info;
704 char name[RTE_ETH_NAME_MAX_LEN];
707 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
712 ret = eth_link_get_nowait_print_err(port_id, &link);
716 ret = eth_dev_info_get_print_err(port_id, &dev_info);
720 rte_eth_dev_get_name_by_port(port_id, name);
721 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
725 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
726 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
727 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
728 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
729 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
730 (unsigned int) link.link_speed);
734 port_offload_cap_display(portid_t port_id)
736 struct rte_eth_dev_info dev_info;
737 static const char *info_border = "************";
740 if (port_id_is_invalid(port_id, ENABLED_WARN))
743 ret = eth_dev_info_get_print_err(port_id, &dev_info);
747 printf("\n%s Port %d supported offload features: %s\n",
748 info_border, port_id, info_border);
750 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
751 printf("VLAN stripped: ");
752 if (ports[port_id].dev_conf.rxmode.offloads &
753 DEV_RX_OFFLOAD_VLAN_STRIP)
759 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
760 printf("Double VLANs stripped: ");
761 if (ports[port_id].dev_conf.rxmode.offloads &
762 DEV_RX_OFFLOAD_QINQ_STRIP)
768 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
769 printf("RX IPv4 checksum: ");
770 if (ports[port_id].dev_conf.rxmode.offloads &
771 DEV_RX_OFFLOAD_IPV4_CKSUM)
777 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
778 printf("RX UDP checksum: ");
779 if (ports[port_id].dev_conf.rxmode.offloads &
780 DEV_RX_OFFLOAD_UDP_CKSUM)
786 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
787 printf("RX TCP checksum: ");
788 if (ports[port_id].dev_conf.rxmode.offloads &
789 DEV_RX_OFFLOAD_TCP_CKSUM)
795 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) {
796 printf("RX SCTP checksum: ");
797 if (ports[port_id].dev_conf.rxmode.offloads &
798 DEV_RX_OFFLOAD_SCTP_CKSUM)
804 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
805 printf("RX Outer IPv4 checksum: ");
806 if (ports[port_id].dev_conf.rxmode.offloads &
807 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
813 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) {
814 printf("RX Outer UDP checksum: ");
815 if (ports[port_id].dev_conf.rxmode.offloads &
816 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM)
822 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
823 printf("Large receive offload: ");
824 if (ports[port_id].dev_conf.rxmode.offloads &
825 DEV_RX_OFFLOAD_TCP_LRO)
831 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
832 printf("HW timestamp: ");
833 if (ports[port_id].dev_conf.rxmode.offloads &
834 DEV_RX_OFFLOAD_TIMESTAMP)
840 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) {
841 printf("Rx Keep CRC: ");
842 if (ports[port_id].dev_conf.rxmode.offloads &
843 DEV_RX_OFFLOAD_KEEP_CRC)
849 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) {
850 printf("RX offload security: ");
851 if (ports[port_id].dev_conf.rxmode.offloads &
852 DEV_RX_OFFLOAD_SECURITY)
858 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
859 printf("VLAN insert: ");
860 if (ports[port_id].dev_conf.txmode.offloads &
861 DEV_TX_OFFLOAD_VLAN_INSERT)
867 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
868 printf("Double VLANs insert: ");
869 if (ports[port_id].dev_conf.txmode.offloads &
870 DEV_TX_OFFLOAD_QINQ_INSERT)
876 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
877 printf("TX IPv4 checksum: ");
878 if (ports[port_id].dev_conf.txmode.offloads &
879 DEV_TX_OFFLOAD_IPV4_CKSUM)
885 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
886 printf("TX UDP checksum: ");
887 if (ports[port_id].dev_conf.txmode.offloads &
888 DEV_TX_OFFLOAD_UDP_CKSUM)
894 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
895 printf("TX TCP checksum: ");
896 if (ports[port_id].dev_conf.txmode.offloads &
897 DEV_TX_OFFLOAD_TCP_CKSUM)
903 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
904 printf("TX SCTP checksum: ");
905 if (ports[port_id].dev_conf.txmode.offloads &
906 DEV_TX_OFFLOAD_SCTP_CKSUM)
912 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
913 printf("TX Outer IPv4 checksum: ");
914 if (ports[port_id].dev_conf.txmode.offloads &
915 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
921 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
922 printf("TX TCP segmentation: ");
923 if (ports[port_id].dev_conf.txmode.offloads &
924 DEV_TX_OFFLOAD_TCP_TSO)
930 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
931 printf("TX UDP segmentation: ");
932 if (ports[port_id].dev_conf.txmode.offloads &
933 DEV_TX_OFFLOAD_UDP_TSO)
939 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
940 printf("TSO for VXLAN tunnel packet: ");
941 if (ports[port_id].dev_conf.txmode.offloads &
942 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
948 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
949 printf("TSO for GRE tunnel packet: ");
950 if (ports[port_id].dev_conf.txmode.offloads &
951 DEV_TX_OFFLOAD_GRE_TNL_TSO)
957 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
958 printf("TSO for IPIP tunnel packet: ");
959 if (ports[port_id].dev_conf.txmode.offloads &
960 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
966 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
967 printf("TSO for GENEVE tunnel packet: ");
968 if (ports[port_id].dev_conf.txmode.offloads &
969 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
975 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) {
976 printf("IP tunnel TSO: ");
977 if (ports[port_id].dev_conf.txmode.offloads &
978 DEV_TX_OFFLOAD_IP_TNL_TSO)
984 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) {
985 printf("UDP tunnel TSO: ");
986 if (ports[port_id].dev_conf.txmode.offloads &
987 DEV_TX_OFFLOAD_UDP_TNL_TSO)
993 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
994 printf("TX Outer UDP checksum: ");
995 if (ports[port_id].dev_conf.txmode.offloads &
996 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
1005 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1009 if (port_id == (portid_t)RTE_PORT_ALL)
1012 RTE_ETH_FOREACH_DEV(pid)
1016 if (warning == ENABLED_WARN)
1017 printf("Invalid port %d\n", port_id);
1022 void print_valid_ports(void)
1026 printf("The valid ports array is [");
1027 RTE_ETH_FOREACH_DEV(pid) {
1034 vlan_id_is_invalid(uint16_t vlan_id)
1038 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1043 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1045 const struct rte_pci_device *pci_dev;
1046 const struct rte_bus *bus;
1049 if (reg_off & 0x3) {
1050 printf("Port register offset 0x%X not aligned on a 4-byte "
1056 if (!ports[port_id].dev_info.device) {
1057 printf("Invalid device\n");
1061 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1062 if (bus && !strcmp(bus->name, "pci")) {
1063 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1065 printf("Not a PCI device\n");
1069 pci_len = pci_dev->mem_resource[0].len;
1070 if (reg_off >= pci_len) {
1071 printf("Port %d: register offset %u (0x%X) out of port PCI "
1072 "resource (length=%"PRIu64")\n",
1073 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
1080 reg_bit_pos_is_invalid(uint8_t bit_pos)
1084 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
1088 #define display_port_and_reg_off(port_id, reg_off) \
1089 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1092 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1094 display_port_and_reg_off(port_id, (unsigned)reg_off);
1095 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1099 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1104 if (port_id_is_invalid(port_id, ENABLED_WARN))
1106 if (port_reg_off_is_invalid(port_id, reg_off))
1108 if (reg_bit_pos_is_invalid(bit_x))
1110 reg_v = port_id_pci_reg_read(port_id, reg_off);
1111 display_port_and_reg_off(port_id, (unsigned)reg_off);
1112 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1116 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1117 uint8_t bit1_pos, uint8_t bit2_pos)
1123 if (port_id_is_invalid(port_id, ENABLED_WARN))
1125 if (port_reg_off_is_invalid(port_id, reg_off))
1127 if (reg_bit_pos_is_invalid(bit1_pos))
1129 if (reg_bit_pos_is_invalid(bit2_pos))
1131 if (bit1_pos > bit2_pos)
1132 l_bit = bit2_pos, h_bit = bit1_pos;
1134 l_bit = bit1_pos, h_bit = bit2_pos;
1136 reg_v = port_id_pci_reg_read(port_id, reg_off);
1139 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1140 display_port_and_reg_off(port_id, (unsigned)reg_off);
1141 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1142 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1146 port_reg_display(portid_t port_id, uint32_t reg_off)
1150 if (port_id_is_invalid(port_id, ENABLED_WARN))
1152 if (port_reg_off_is_invalid(port_id, reg_off))
1154 reg_v = port_id_pci_reg_read(port_id, reg_off);
1155 display_port_reg_value(port_id, reg_off, reg_v);
1159 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1164 if (port_id_is_invalid(port_id, ENABLED_WARN))
1166 if (port_reg_off_is_invalid(port_id, reg_off))
1168 if (reg_bit_pos_is_invalid(bit_pos))
1171 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1174 reg_v = port_id_pci_reg_read(port_id, reg_off);
1176 reg_v &= ~(1 << bit_pos);
1178 reg_v |= (1 << bit_pos);
1179 port_id_pci_reg_write(port_id, reg_off, reg_v);
1180 display_port_reg_value(port_id, reg_off, reg_v);
1184 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1185 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1192 if (port_id_is_invalid(port_id, ENABLED_WARN))
1194 if (port_reg_off_is_invalid(port_id, reg_off))
1196 if (reg_bit_pos_is_invalid(bit1_pos))
1198 if (reg_bit_pos_is_invalid(bit2_pos))
1200 if (bit1_pos > bit2_pos)
1201 l_bit = bit2_pos, h_bit = bit1_pos;
1203 l_bit = bit1_pos, h_bit = bit2_pos;
1205 if ((h_bit - l_bit) < 31)
1206 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1210 if (value > max_v) {
1211 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1212 (unsigned)value, (unsigned)value,
1213 (unsigned)max_v, (unsigned)max_v);
1216 reg_v = port_id_pci_reg_read(port_id, reg_off);
1217 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1218 reg_v |= (value << l_bit); /* Set changed bits */
1219 port_id_pci_reg_write(port_id, reg_off, reg_v);
1220 display_port_reg_value(port_id, reg_off, reg_v);
1224 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1226 if (port_id_is_invalid(port_id, ENABLED_WARN))
1228 if (port_reg_off_is_invalid(port_id, reg_off))
1230 port_id_pci_reg_write(port_id, reg_off, reg_v);
1231 display_port_reg_value(port_id, reg_off, reg_v);
1235 port_mtu_set(portid_t port_id, uint16_t mtu)
1238 struct rte_port *rte_port = &ports[port_id];
1239 struct rte_eth_dev_info dev_info;
1240 uint16_t eth_overhead;
1243 if (port_id_is_invalid(port_id, ENABLED_WARN))
1246 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1250 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1251 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1252 mtu, dev_info.min_mtu, dev_info.max_mtu);
1255 diag = rte_eth_dev_set_mtu(port_id, mtu);
1257 dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1259 * Ether overhead in driver is equal to the difference of
1260 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1261 * device supports jumbo frame.
1263 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1264 if (mtu > RTE_ETHER_MAX_LEN - eth_overhead) {
1265 rte_port->dev_conf.rxmode.offloads |=
1266 DEV_RX_OFFLOAD_JUMBO_FRAME;
1267 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1270 rte_port->dev_conf.rxmode.offloads &=
1271 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1275 printf("Set MTU failed. diag=%d\n", diag);
1278 /* Generic flow management functions. */
1280 /** Generate a port_flow entry from attributes/pattern/actions. */
1281 static struct port_flow *
1282 port_flow_new(const struct rte_flow_attr *attr,
1283 const struct rte_flow_item *pattern,
1284 const struct rte_flow_action *actions,
1285 struct rte_flow_error *error)
1287 const struct rte_flow_conv_rule rule = {
1289 .pattern_ro = pattern,
1290 .actions_ro = actions,
1292 struct port_flow *pf;
1295 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1298 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1301 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1305 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1312 /** Print a message out of a flow error. */
1314 port_flow_complain(struct rte_flow_error *error)
1316 static const char *const errstrlist[] = {
1317 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1318 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1319 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1320 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1321 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1322 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1323 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1324 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1325 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1326 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1327 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1328 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1329 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1330 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1331 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1332 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1333 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1337 int err = rte_errno;
1339 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1340 !errstrlist[error->type])
1341 errstr = "unknown type";
1343 errstr = errstrlist[error->type];
1344 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1345 error->type, errstr,
1346 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1347 error->cause), buf) : "",
1348 error->message ? error->message : "(no stated reason)",
1353 /** Validate flow rule. */
1355 port_flow_validate(portid_t port_id,
1356 const struct rte_flow_attr *attr,
1357 const struct rte_flow_item *pattern,
1358 const struct rte_flow_action *actions)
1360 struct rte_flow_error error;
1362 /* Poisoning to make sure PMDs update it in case of error. */
1363 memset(&error, 0x11, sizeof(error));
1364 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1365 return port_flow_complain(&error);
1366 printf("Flow rule validated\n");
1370 /** Update age action context by port_flow pointer. */
1372 update_age_action_context(const struct rte_flow_action *actions,
1373 struct port_flow *pf)
1375 struct rte_flow_action_age *age = NULL;
1377 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1378 switch (actions->type) {
1379 case RTE_FLOW_ACTION_TYPE_AGE:
1380 age = (struct rte_flow_action_age *)
1381 (uintptr_t)actions->conf;
1390 /** Create flow rule. */
1392 port_flow_create(portid_t port_id,
1393 const struct rte_flow_attr *attr,
1394 const struct rte_flow_item *pattern,
1395 const struct rte_flow_action *actions)
1397 struct rte_flow *flow;
1398 struct rte_port *port;
1399 struct port_flow *pf;
1401 struct rte_flow_error error;
1403 port = &ports[port_id];
1404 if (port->flow_list) {
1405 if (port->flow_list->id == UINT32_MAX) {
1406 printf("Highest rule ID is already assigned, delete"
1410 id = port->flow_list->id + 1;
1412 pf = port_flow_new(attr, pattern, actions, &error);
1414 return port_flow_complain(&error);
1415 update_age_action_context(actions, pf);
1416 /* Poisoning to make sure PMDs update it in case of error. */
1417 memset(&error, 0x22, sizeof(error));
1418 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1421 return port_flow_complain(&error);
1423 pf->next = port->flow_list;
1426 port->flow_list = pf;
1427 printf("Flow rule #%u created\n", pf->id);
1431 /** Destroy a number of flow rules. */
1433 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1435 struct rte_port *port;
1436 struct port_flow **tmp;
1440 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1441 port_id == (portid_t)RTE_PORT_ALL)
1443 port = &ports[port_id];
1444 tmp = &port->flow_list;
1448 for (i = 0; i != n; ++i) {
1449 struct rte_flow_error error;
1450 struct port_flow *pf = *tmp;
1452 if (rule[i] != pf->id)
1455 * Poisoning to make sure PMDs update it in case
1458 memset(&error, 0x33, sizeof(error));
1459 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1460 ret = port_flow_complain(&error);
1463 printf("Flow rule #%u destroyed\n", pf->id);
1469 tmp = &(*tmp)->next;
1475 /** Remove all flow rules. */
1477 port_flow_flush(portid_t port_id)
1479 struct rte_flow_error error;
1480 struct rte_port *port;
1483 /* Poisoning to make sure PMDs update it in case of error. */
1484 memset(&error, 0x44, sizeof(error));
1485 if (rte_flow_flush(port_id, &error)) {
1486 ret = port_flow_complain(&error);
1487 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1488 port_id == (portid_t)RTE_PORT_ALL)
1491 port = &ports[port_id];
1492 while (port->flow_list) {
1493 struct port_flow *pf = port->flow_list->next;
1495 free(port->flow_list);
1496 port->flow_list = pf;
1501 /** Dump all flow rules. */
1503 port_flow_dump(portid_t port_id, const char *file_name)
1506 FILE *file = stdout;
1507 struct rte_flow_error error;
1509 if (file_name && strlen(file_name)) {
1510 file = fopen(file_name, "w");
1512 printf("Failed to create file %s: %s\n", file_name,
1517 ret = rte_flow_dev_dump(port_id, file, &error);
1519 port_flow_complain(&error);
1520 printf("Failed to dump flow: %s\n", strerror(-ret));
1522 printf("Flow dump finished\n");
1523 if (file_name && strlen(file_name))
1528 /** Query a flow rule. */
1530 port_flow_query(portid_t port_id, uint32_t rule,
1531 const struct rte_flow_action *action)
1533 struct rte_flow_error error;
1534 struct rte_port *port;
1535 struct port_flow *pf;
1538 struct rte_flow_query_count count;
1542 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1543 port_id == (portid_t)RTE_PORT_ALL)
1545 port = &ports[port_id];
1546 for (pf = port->flow_list; pf; pf = pf->next)
1550 printf("Flow rule #%u not found\n", rule);
1553 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1554 &name, sizeof(name),
1555 (void *)(uintptr_t)action->type, &error);
1557 return port_flow_complain(&error);
1558 switch (action->type) {
1559 case RTE_FLOW_ACTION_TYPE_COUNT:
1562 printf("Cannot query action type %d (%s)\n",
1563 action->type, name);
1566 /* Poisoning to make sure PMDs update it in case of error. */
1567 memset(&error, 0x55, sizeof(error));
1568 memset(&query, 0, sizeof(query));
1569 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1570 return port_flow_complain(&error);
1571 switch (action->type) {
1572 case RTE_FLOW_ACTION_TYPE_COUNT:
1576 " hits: %" PRIu64 "\n"
1577 " bytes: %" PRIu64 "\n",
1579 query.count.hits_set,
1580 query.count.bytes_set,
1585 printf("Cannot display result for action type %d (%s)\n",
1586 action->type, name);
1592 /** List simply and destroy all aged flows. */
1594 port_flow_aged(portid_t port_id, uint8_t destroy)
1597 int nb_context, total = 0, idx;
1598 struct rte_flow_error error;
1599 struct port_flow *pf;
1601 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1602 port_id == (portid_t)RTE_PORT_ALL)
1604 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
1605 printf("Port %u total aged flows: %d\n", port_id, total);
1607 port_flow_complain(&error);
1612 contexts = malloc(sizeof(void *) * total);
1613 if (contexts == NULL) {
1614 printf("Cannot allocate contexts for aged flow\n");
1617 printf("ID\tGroup\tPrio\tAttr\n");
1618 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
1619 if (nb_context != total) {
1620 printf("Port:%d get aged flows count(%d) != total(%d)\n",
1621 port_id, nb_context, total);
1625 for (idx = 0; idx < nb_context; idx++) {
1626 pf = (struct port_flow *)contexts[idx];
1628 printf("Error: get Null context in port %u\n", port_id);
1631 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
1633 pf->rule.attr->group,
1634 pf->rule.attr->priority,
1635 pf->rule.attr->ingress ? 'i' : '-',
1636 pf->rule.attr->egress ? 'e' : '-',
1637 pf->rule.attr->transfer ? 't' : '-');
1645 for (idx = 0; idx < nb_context; idx++) {
1646 pf = (struct port_flow *)contexts[idx];
1650 ret = port_flow_destroy(port_id, 1, &flow_id);
1654 printf("%d flows be destroyed\n", total);
1659 /** List flow rules. */
1661 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1663 struct rte_port *port;
1664 struct port_flow *pf;
1665 struct port_flow *list = NULL;
1668 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1669 port_id == (portid_t)RTE_PORT_ALL)
1671 port = &ports[port_id];
1672 if (!port->flow_list)
1674 /* Sort flows by group, priority and ID. */
1675 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1676 struct port_flow **tmp;
1677 const struct rte_flow_attr *curr = pf->rule.attr;
1680 /* Filter out unwanted groups. */
1681 for (i = 0; i != n; ++i)
1682 if (curr->group == group[i])
1687 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
1688 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
1690 if (curr->group > comp->group ||
1691 (curr->group == comp->group &&
1692 curr->priority > comp->priority) ||
1693 (curr->group == comp->group &&
1694 curr->priority == comp->priority &&
1695 pf->id > (*tmp)->id))
1702 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1703 for (pf = list; pf != NULL; pf = pf->tmp) {
1704 const struct rte_flow_item *item = pf->rule.pattern;
1705 const struct rte_flow_action *action = pf->rule.actions;
1708 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
1710 pf->rule.attr->group,
1711 pf->rule.attr->priority,
1712 pf->rule.attr->ingress ? 'i' : '-',
1713 pf->rule.attr->egress ? 'e' : '-',
1714 pf->rule.attr->transfer ? 't' : '-');
1715 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1716 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
1717 &name, sizeof(name),
1718 (void *)(uintptr_t)item->type,
1721 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1722 printf("%s ", name);
1726 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1727 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1728 &name, sizeof(name),
1729 (void *)(uintptr_t)action->type,
1732 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1733 printf(" %s", name);
1740 /** Restrict ingress traffic to the defined flow rules. */
1742 port_flow_isolate(portid_t port_id, int set)
1744 struct rte_flow_error error;
1746 /* Poisoning to make sure PMDs update it in case of error. */
1747 memset(&error, 0x66, sizeof(error));
1748 if (rte_flow_isolate(port_id, set, &error))
1749 return port_flow_complain(&error);
1750 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1752 set ? "now restricted" : "not restricted anymore");
1757 * RX/TX ring descriptors display functions.
1760 rx_queue_id_is_invalid(queueid_t rxq_id)
1762 if (rxq_id < nb_rxq)
1764 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1769 tx_queue_id_is_invalid(queueid_t txq_id)
1771 if (txq_id < nb_txq)
1773 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1778 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1780 if (rxdesc_id < nb_rxd)
1782 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1788 tx_desc_id_is_invalid(uint16_t txdesc_id)
1790 if (txdesc_id < nb_txd)
1792 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1797 static const struct rte_memzone *
1798 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1800 char mz_name[RTE_MEMZONE_NAMESIZE];
1801 const struct rte_memzone *mz;
1803 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
1804 port_id, q_id, ring_name);
1805 mz = rte_memzone_lookup(mz_name);
1807 printf("%s ring memory zoneof (port %d, queue %d) not"
1808 "found (zone name = %s\n",
1809 ring_name, port_id, q_id, mz_name);
1813 union igb_ring_dword {
1816 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1826 struct igb_ring_desc_32_bytes {
1827 union igb_ring_dword lo_dword;
1828 union igb_ring_dword hi_dword;
1829 union igb_ring_dword resv1;
1830 union igb_ring_dword resv2;
1833 struct igb_ring_desc_16_bytes {
1834 union igb_ring_dword lo_dword;
1835 union igb_ring_dword hi_dword;
1839 ring_rxd_display_dword(union igb_ring_dword dword)
1841 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1842 (unsigned)dword.words.hi);
1846 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1847 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1850 __rte_unused portid_t port_id,
1854 struct igb_ring_desc_16_bytes *ring =
1855 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1856 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1858 struct rte_eth_dev_info dev_info;
1860 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1864 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1865 /* 32 bytes RX descriptor, i40e only */
1866 struct igb_ring_desc_32_bytes *ring =
1867 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1868 ring[desc_id].lo_dword.dword =
1869 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1870 ring_rxd_display_dword(ring[desc_id].lo_dword);
1871 ring[desc_id].hi_dword.dword =
1872 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1873 ring_rxd_display_dword(ring[desc_id].hi_dword);
1874 ring[desc_id].resv1.dword =
1875 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1876 ring_rxd_display_dword(ring[desc_id].resv1);
1877 ring[desc_id].resv2.dword =
1878 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1879 ring_rxd_display_dword(ring[desc_id].resv2);
1884 /* 16 bytes RX descriptor */
1885 ring[desc_id].lo_dword.dword =
1886 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1887 ring_rxd_display_dword(ring[desc_id].lo_dword);
1888 ring[desc_id].hi_dword.dword =
1889 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1890 ring_rxd_display_dword(ring[desc_id].hi_dword);
1894 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1896 struct igb_ring_desc_16_bytes *ring;
1897 struct igb_ring_desc_16_bytes txd;
1899 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1900 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1901 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1902 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1903 (unsigned)txd.lo_dword.words.lo,
1904 (unsigned)txd.lo_dword.words.hi,
1905 (unsigned)txd.hi_dword.words.lo,
1906 (unsigned)txd.hi_dword.words.hi);
1910 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1912 const struct rte_memzone *rx_mz;
1914 if (port_id_is_invalid(port_id, ENABLED_WARN))
1916 if (rx_queue_id_is_invalid(rxq_id))
1918 if (rx_desc_id_is_invalid(rxd_id))
1920 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1923 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1927 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1929 const struct rte_memzone *tx_mz;
1931 if (port_id_is_invalid(port_id, ENABLED_WARN))
1933 if (tx_queue_id_is_invalid(txq_id))
1935 if (tx_desc_id_is_invalid(txd_id))
1937 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1940 ring_tx_descriptor_display(tx_mz, txd_id);
1944 fwd_lcores_config_display(void)
1948 printf("List of forwarding lcores:");
1949 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1950 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1954 rxtx_config_display(void)
1959 printf(" %s packet forwarding%s packets/burst=%d\n",
1960 cur_fwd_eng->fwd_mode_name,
1961 retry_enabled == 0 ? "" : " with retry",
1964 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1965 printf(" packet len=%u - nb packet segments=%d\n",
1966 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1968 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1969 nb_fwd_lcores, nb_fwd_ports);
1971 RTE_ETH_FOREACH_DEV(pid) {
1972 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
1973 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
1974 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
1975 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
1976 uint16_t nb_rx_desc_tmp;
1977 uint16_t nb_tx_desc_tmp;
1978 struct rte_eth_rxq_info rx_qinfo;
1979 struct rte_eth_txq_info tx_qinfo;
1982 /* per port config */
1983 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
1984 (unsigned int)pid, nb_rxq, nb_txq);
1986 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
1987 ports[pid].dev_conf.rxmode.offloads,
1988 ports[pid].dev_conf.txmode.offloads);
1990 /* per rx queue config only for first queue to be less verbose */
1991 for (qid = 0; qid < 1; qid++) {
1992 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
1994 nb_rx_desc_tmp = nb_rx_desc[qid];
1996 nb_rx_desc_tmp = rx_qinfo.nb_desc;
1998 printf(" RX queue: %d\n", qid);
1999 printf(" RX desc=%d - RX free threshold=%d\n",
2000 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh);
2001 printf(" RX threshold registers: pthresh=%d hthresh=%d "
2003 rx_conf[qid].rx_thresh.pthresh,
2004 rx_conf[qid].rx_thresh.hthresh,
2005 rx_conf[qid].rx_thresh.wthresh);
2006 printf(" RX Offloads=0x%"PRIx64"\n",
2007 rx_conf[qid].offloads);
2010 /* per tx queue config only for first queue to be less verbose */
2011 for (qid = 0; qid < 1; qid++) {
2012 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
2014 nb_tx_desc_tmp = nb_tx_desc[qid];
2016 nb_tx_desc_tmp = tx_qinfo.nb_desc;
2018 printf(" TX queue: %d\n", qid);
2019 printf(" TX desc=%d - TX free threshold=%d\n",
2020 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh);
2021 printf(" TX threshold registers: pthresh=%d hthresh=%d "
2023 tx_conf[qid].tx_thresh.pthresh,
2024 tx_conf[qid].tx_thresh.hthresh,
2025 tx_conf[qid].tx_thresh.wthresh);
2026 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
2027 tx_conf[qid].offloads, tx_conf->tx_rs_thresh);
2033 port_rss_reta_info(portid_t port_id,
2034 struct rte_eth_rss_reta_entry64 *reta_conf,
2035 uint16_t nb_entries)
2037 uint16_t i, idx, shift;
2040 if (port_id_is_invalid(port_id, ENABLED_WARN))
2043 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
2045 printf("Failed to get RSS RETA info, return code = %d\n", ret);
2049 for (i = 0; i < nb_entries; i++) {
2050 idx = i / RTE_RETA_GROUP_SIZE;
2051 shift = i % RTE_RETA_GROUP_SIZE;
2052 if (!(reta_conf[idx].mask & (1ULL << shift)))
2054 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
2055 i, reta_conf[idx].reta[shift]);
2060 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
2064 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
2066 struct rte_eth_rss_conf rss_conf = {0};
2067 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
2071 struct rte_eth_dev_info dev_info;
2072 uint8_t hash_key_size;
2075 if (port_id_is_invalid(port_id, ENABLED_WARN))
2078 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2082 if (dev_info.hash_key_size > 0 &&
2083 dev_info.hash_key_size <= sizeof(rss_key))
2084 hash_key_size = dev_info.hash_key_size;
2086 printf("dev_info did not provide a valid hash key size\n");
2090 /* Get RSS hash key if asked to display it */
2091 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2092 rss_conf.rss_key_len = hash_key_size;
2093 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2097 printf("port index %d invalid\n", port_id);
2100 printf("operation not supported by device\n");
2103 printf("operation failed - diag=%d\n", diag);
2108 rss_hf = rss_conf.rss_hf;
2110 printf("RSS disabled\n");
2113 printf("RSS functions:\n ");
2114 for (i = 0; rss_type_table[i].str; i++) {
2115 if (rss_hf & rss_type_table[i].rss_type)
2116 printf("%s ", rss_type_table[i].str);
2121 printf("RSS key:\n");
2122 for (i = 0; i < hash_key_size; i++)
2123 printf("%02X", rss_key[i]);
2128 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2131 struct rte_eth_rss_conf rss_conf;
2135 rss_conf.rss_key = NULL;
2136 rss_conf.rss_key_len = hash_key_len;
2137 rss_conf.rss_hf = 0;
2138 for (i = 0; rss_type_table[i].str; i++) {
2139 if (!strcmp(rss_type_table[i].str, rss_type))
2140 rss_conf.rss_hf = rss_type_table[i].rss_type;
2142 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2144 rss_conf.rss_key = hash_key;
2145 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2152 printf("port index %d invalid\n", port_id);
2155 printf("operation not supported by device\n");
2158 printf("operation failed - diag=%d\n", diag);
2164 * Setup forwarding configuration for each logical core.
2167 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2169 streamid_t nb_fs_per_lcore;
2177 nb_fs = cfg->nb_fwd_streams;
2178 nb_fc = cfg->nb_fwd_lcores;
2179 if (nb_fs <= nb_fc) {
2180 nb_fs_per_lcore = 1;
2183 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2184 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2187 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2189 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2190 fwd_lcores[lc_id]->stream_idx = sm_id;
2191 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2192 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2196 * Assign extra remaining streams, if any.
2198 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2199 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2200 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2201 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2202 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2207 fwd_topology_tx_port_get(portid_t rxp)
2209 static int warning_once = 1;
2211 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2213 switch (port_topology) {
2215 case PORT_TOPOLOGY_PAIRED:
2216 if ((rxp & 0x1) == 0) {
2217 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2220 printf("\nWarning! port-topology=paired"
2221 " and odd forward ports number,"
2222 " the last port will pair with"
2229 case PORT_TOPOLOGY_CHAINED:
2230 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2231 case PORT_TOPOLOGY_LOOP:
2237 simple_fwd_config_setup(void)
2241 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2242 cur_fwd_config.nb_fwd_streams =
2243 (streamid_t) cur_fwd_config.nb_fwd_ports;
2245 /* reinitialize forwarding streams */
2249 * In the simple forwarding test, the number of forwarding cores
2250 * must be lower or equal to the number of forwarding ports.
2252 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2253 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2254 cur_fwd_config.nb_fwd_lcores =
2255 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2256 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2258 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2259 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2260 fwd_streams[i]->rx_queue = 0;
2261 fwd_streams[i]->tx_port =
2262 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2263 fwd_streams[i]->tx_queue = 0;
2264 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2265 fwd_streams[i]->retry_enabled = retry_enabled;
2270 * For the RSS forwarding test all streams distributed over lcores. Each stream
2271 * being composed of a RX queue to poll on a RX port for input messages,
2272 * associated with a TX queue of a TX port where to send forwarded packets.
2275 rss_fwd_config_setup(void)
2286 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2287 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2288 cur_fwd_config.nb_fwd_streams =
2289 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2291 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2292 cur_fwd_config.nb_fwd_lcores =
2293 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2295 /* reinitialize forwarding streams */
2298 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2300 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2301 struct fwd_stream *fs;
2303 fs = fwd_streams[sm_id];
2304 txp = fwd_topology_tx_port_get(rxp);
2305 fs->rx_port = fwd_ports_ids[rxp];
2307 fs->tx_port = fwd_ports_ids[txp];
2309 fs->peer_addr = fs->tx_port;
2310 fs->retry_enabled = retry_enabled;
2312 if (rxp < nb_fwd_ports)
2320 * For the DCB forwarding test, each core is assigned on each traffic class.
2322 * Each core is assigned a multi-stream, each stream being composed of
2323 * a RX queue to poll on a RX port for input messages, associated with
2324 * a TX queue of a TX port where to send forwarded packets. All RX and
2325 * TX queues are mapping to the same traffic class.
2326 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2330 dcb_fwd_config_setup(void)
2332 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2333 portid_t txp, rxp = 0;
2334 queueid_t txq, rxq = 0;
2336 uint16_t nb_rx_queue, nb_tx_queue;
2337 uint16_t i, j, k, sm_id = 0;
2340 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2341 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2342 cur_fwd_config.nb_fwd_streams =
2343 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2345 /* reinitialize forwarding streams */
2349 /* get the dcb info on the first RX and TX ports */
2350 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2351 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2353 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2354 fwd_lcores[lc_id]->stream_nb = 0;
2355 fwd_lcores[lc_id]->stream_idx = sm_id;
2356 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2357 /* if the nb_queue is zero, means this tc is
2358 * not enabled on the POOL
2360 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2362 k = fwd_lcores[lc_id]->stream_nb +
2363 fwd_lcores[lc_id]->stream_idx;
2364 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2365 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2366 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2367 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2368 for (j = 0; j < nb_rx_queue; j++) {
2369 struct fwd_stream *fs;
2371 fs = fwd_streams[k + j];
2372 fs->rx_port = fwd_ports_ids[rxp];
2373 fs->rx_queue = rxq + j;
2374 fs->tx_port = fwd_ports_ids[txp];
2375 fs->tx_queue = txq + j % nb_tx_queue;
2376 fs->peer_addr = fs->tx_port;
2377 fs->retry_enabled = retry_enabled;
2379 fwd_lcores[lc_id]->stream_nb +=
2380 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2382 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2385 if (tc < rxp_dcb_info.nb_tcs)
2387 /* Restart from TC 0 on next RX port */
2389 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2391 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2394 if (rxp >= nb_fwd_ports)
2396 /* get the dcb information on next RX and TX ports */
2397 if ((rxp & 0x1) == 0)
2398 txp = (portid_t) (rxp + 1);
2400 txp = (portid_t) (rxp - 1);
2401 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2402 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2407 icmp_echo_config_setup(void)
2414 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2415 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2416 (nb_txq * nb_fwd_ports);
2418 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2419 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2420 cur_fwd_config.nb_fwd_streams =
2421 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2422 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2423 cur_fwd_config.nb_fwd_lcores =
2424 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2425 if (verbose_level > 0) {
2426 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2428 cur_fwd_config.nb_fwd_lcores,
2429 cur_fwd_config.nb_fwd_ports,
2430 cur_fwd_config.nb_fwd_streams);
2433 /* reinitialize forwarding streams */
2435 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2437 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2438 if (verbose_level > 0)
2439 printf(" core=%d: \n", lc_id);
2440 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2441 struct fwd_stream *fs;
2442 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2443 fs->rx_port = fwd_ports_ids[rxp];
2445 fs->tx_port = fs->rx_port;
2447 fs->peer_addr = fs->tx_port;
2448 fs->retry_enabled = retry_enabled;
2449 if (verbose_level > 0)
2450 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2451 sm_id, fs->rx_port, fs->rx_queue,
2453 rxq = (queueid_t) (rxq + 1);
2454 if (rxq == nb_rxq) {
2456 rxp = (portid_t) (rxp + 1);
2462 #if defined RTE_LIBRTE_PMD_SOFTNIC
2464 softnic_fwd_config_setup(void)
2466 struct rte_port *port;
2467 portid_t pid, softnic_portid;
2469 uint8_t softnic_enable = 0;
2471 RTE_ETH_FOREACH_DEV(pid) {
2473 const char *driver = port->dev_info.driver_name;
2475 if (strcmp(driver, "net_softnic") == 0) {
2476 softnic_portid = pid;
2482 if (softnic_enable == 0) {
2483 printf("Softnic mode not configured(%s)!\n", __func__);
2487 cur_fwd_config.nb_fwd_ports = 1;
2488 cur_fwd_config.nb_fwd_streams = (streamid_t) nb_rxq;
2490 /* Re-initialize forwarding streams */
2494 * In the softnic forwarding test, the number of forwarding cores
2495 * is set to one and remaining are used for softnic packet processing.
2497 cur_fwd_config.nb_fwd_lcores = 1;
2498 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2500 for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++) {
2501 fwd_streams[i]->rx_port = softnic_portid;
2502 fwd_streams[i]->rx_queue = i;
2503 fwd_streams[i]->tx_port = softnic_portid;
2504 fwd_streams[i]->tx_queue = i;
2505 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2506 fwd_streams[i]->retry_enabled = retry_enabled;
2512 fwd_config_setup(void)
2514 cur_fwd_config.fwd_eng = cur_fwd_eng;
2515 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2516 icmp_echo_config_setup();
2520 #if defined RTE_LIBRTE_PMD_SOFTNIC
2521 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
2522 softnic_fwd_config_setup();
2527 if ((nb_rxq > 1) && (nb_txq > 1)){
2529 dcb_fwd_config_setup();
2531 rss_fwd_config_setup();
2534 simple_fwd_config_setup();
2538 mp_alloc_to_str(uint8_t mode)
2541 case MP_ALLOC_NATIVE:
2547 case MP_ALLOC_XMEM_HUGE:
2557 pkt_fwd_config_display(struct fwd_config *cfg)
2559 struct fwd_stream *fs;
2563 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2564 "NUMA support %s, MP allocation mode: %s\n",
2565 cfg->fwd_eng->fwd_mode_name,
2566 retry_enabled == 0 ? "" : " with retry",
2567 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2568 numa_support == 1 ? "enabled" : "disabled",
2569 mp_alloc_to_str(mp_alloc_type));
2572 printf("TX retry num: %u, delay between TX retries: %uus\n",
2573 burst_tx_retry_num, burst_tx_delay_time);
2574 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2575 printf("Logical Core %u (socket %u) forwards packets on "
2577 fwd_lcores_cpuids[lc_id],
2578 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2579 fwd_lcores[lc_id]->stream_nb);
2580 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2581 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2582 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2583 "P=%d/Q=%d (socket %u) ",
2584 fs->rx_port, fs->rx_queue,
2585 ports[fs->rx_port].socket_id,
2586 fs->tx_port, fs->tx_queue,
2587 ports[fs->tx_port].socket_id);
2588 print_ethaddr("peer=",
2589 &peer_eth_addrs[fs->peer_addr]);
2597 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2599 struct rte_ether_addr new_peer_addr;
2600 if (!rte_eth_dev_is_valid_port(port_id)) {
2601 printf("Error: Invalid port number %i\n", port_id);
2604 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
2605 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2608 peer_eth_addrs[port_id] = new_peer_addr;
2612 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2615 unsigned int lcore_cpuid;
2620 for (i = 0; i < nb_lc; i++) {
2621 lcore_cpuid = lcorelist[i];
2622 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2623 printf("lcore %u not enabled\n", lcore_cpuid);
2626 if (lcore_cpuid == rte_get_master_lcore()) {
2627 printf("lcore %u cannot be masked on for running "
2628 "packet forwarding, which is the master lcore "
2629 "and reserved for command line parsing only\n",
2634 fwd_lcores_cpuids[i] = lcore_cpuid;
2636 if (record_now == 0) {
2640 nb_cfg_lcores = (lcoreid_t) nb_lc;
2641 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2642 printf("previous number of forwarding cores %u - changed to "
2643 "number of configured cores %u\n",
2644 (unsigned int) nb_fwd_lcores, nb_lc);
2645 nb_fwd_lcores = (lcoreid_t) nb_lc;
2652 set_fwd_lcores_mask(uint64_t lcoremask)
2654 unsigned int lcorelist[64];
2658 if (lcoremask == 0) {
2659 printf("Invalid NULL mask of cores\n");
2663 for (i = 0; i < 64; i++) {
2664 if (! ((uint64_t)(1ULL << i) & lcoremask))
2666 lcorelist[nb_lc++] = i;
2668 return set_fwd_lcores_list(lcorelist, nb_lc);
2672 set_fwd_lcores_number(uint16_t nb_lc)
2674 if (nb_lc > nb_cfg_lcores) {
2675 printf("nb fwd cores %u > %u (max. number of configured "
2676 "lcores) - ignored\n",
2677 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2680 nb_fwd_lcores = (lcoreid_t) nb_lc;
2681 printf("Number of forwarding cores set to %u\n",
2682 (unsigned int) nb_fwd_lcores);
2686 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2694 for (i = 0; i < nb_pt; i++) {
2695 port_id = (portid_t) portlist[i];
2696 if (port_id_is_invalid(port_id, ENABLED_WARN))
2699 fwd_ports_ids[i] = port_id;
2701 if (record_now == 0) {
2705 nb_cfg_ports = (portid_t) nb_pt;
2706 if (nb_fwd_ports != (portid_t) nb_pt) {
2707 printf("previous number of forwarding ports %u - changed to "
2708 "number of configured ports %u\n",
2709 (unsigned int) nb_fwd_ports, nb_pt);
2710 nb_fwd_ports = (portid_t) nb_pt;
2715 * Parse the user input and obtain the list of forwarding ports
2718 * String containing the user input. User can specify
2719 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
2720 * For example, if the user wants to use all the available
2721 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
2722 * If the user wants to use only the ports 1,2 then the input
2724 * valid characters are '-' and ','
2725 * @param[out] values
2726 * This array will be filled with a list of port IDs
2727 * based on the user input
2728 * Note that duplicate entries are discarded and only the first
2729 * count entries in this array are port IDs and all the rest
2730 * will contain default values
2731 * @param[in] maxsize
2732 * This parameter denotes 2 things
2733 * 1) Number of elements in the values array
2734 * 2) Maximum value of each element in the values array
2736 * On success, returns total count of parsed port IDs
2737 * On failure, returns 0
2740 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
2742 unsigned int count = 0;
2746 unsigned int marked[maxsize];
2748 if (list == NULL || values == NULL)
2751 for (i = 0; i < (int)maxsize; i++)
2757 /*Remove the blank spaces if any*/
2758 while (isblank(*list))
2763 value = strtol(list, &end, 10);
2764 if (errno || end == NULL)
2766 if (value < 0 || value >= (int)maxsize)
2768 while (isblank(*end))
2770 if (*end == '-' && min == INT_MAX) {
2772 } else if ((*end == ',') || (*end == '\0')) {
2776 for (i = min; i <= max; i++) {
2777 if (count < maxsize) {
2789 } while (*end != '\0');
2795 parse_fwd_portlist(const char *portlist)
2797 unsigned int portcount;
2798 unsigned int portindex[RTE_MAX_ETHPORTS];
2799 unsigned int i, valid_port_count = 0;
2801 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
2803 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
2806 * Here we verify the validity of the ports
2807 * and thereby calculate the total number of
2810 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
2811 if (rte_eth_dev_is_valid_port(portindex[i])) {
2812 portindex[valid_port_count] = portindex[i];
2817 set_fwd_ports_list(portindex, valid_port_count);
2821 set_fwd_ports_mask(uint64_t portmask)
2823 unsigned int portlist[64];
2827 if (portmask == 0) {
2828 printf("Invalid NULL mask of ports\n");
2832 RTE_ETH_FOREACH_DEV(i) {
2833 if (! ((uint64_t)(1ULL << i) & portmask))
2835 portlist[nb_pt++] = i;
2837 set_fwd_ports_list(portlist, nb_pt);
2841 set_fwd_ports_number(uint16_t nb_pt)
2843 if (nb_pt > nb_cfg_ports) {
2844 printf("nb fwd ports %u > %u (number of configured "
2845 "ports) - ignored\n",
2846 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2849 nb_fwd_ports = (portid_t) nb_pt;
2850 printf("Number of forwarding ports set to %u\n",
2851 (unsigned int) nb_fwd_ports);
2855 port_is_forwarding(portid_t port_id)
2859 if (port_id_is_invalid(port_id, ENABLED_WARN))
2862 for (i = 0; i < nb_fwd_ports; i++) {
2863 if (fwd_ports_ids[i] == port_id)
2871 set_nb_pkt_per_burst(uint16_t nb)
2873 if (nb > MAX_PKT_BURST) {
2874 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2876 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2879 nb_pkt_per_burst = nb;
2880 printf("Number of packets per burst set to %u\n",
2881 (unsigned int) nb_pkt_per_burst);
2885 tx_split_get_name(enum tx_pkt_split split)
2889 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2890 if (tx_split_name[i].split == split)
2891 return tx_split_name[i].name;
2897 set_tx_pkt_split(const char *name)
2901 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2902 if (strcmp(tx_split_name[i].name, name) == 0) {
2903 tx_pkt_split = tx_split_name[i].split;
2907 printf("unknown value: \"%s\"\n", name);
2911 show_tx_pkt_segments(void)
2917 split = tx_split_get_name(tx_pkt_split);
2919 printf("Number of segments: %u\n", n);
2920 printf("Segment sizes: ");
2921 for (i = 0; i != n - 1; i++)
2922 printf("%hu,", tx_pkt_seg_lengths[i]);
2923 printf("%hu\n", tx_pkt_seg_lengths[i]);
2924 printf("Split packet: %s\n", split);
2928 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2930 uint16_t tx_pkt_len;
2933 if (nb_segs >= (unsigned) nb_txd) {
2934 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2935 nb_segs, (unsigned int) nb_txd);
2940 * Check that each segment length is greater or equal than
2941 * the mbuf data sise.
2942 * Check also that the total packet length is greater or equal than the
2943 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
2947 for (i = 0; i < nb_segs; i++) {
2948 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2949 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2950 i, seg_lengths[i], (unsigned) mbuf_data_size);
2953 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2955 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
2956 printf("total packet length=%u < %d - give up\n",
2957 (unsigned) tx_pkt_len,
2958 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
2962 for (i = 0; i < nb_segs; i++)
2963 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2965 tx_pkt_length = tx_pkt_len;
2966 tx_pkt_nb_segs = (uint8_t) nb_segs;
2970 setup_gro(const char *onoff, portid_t port_id)
2972 if (!rte_eth_dev_is_valid_port(port_id)) {
2973 printf("invalid port id %u\n", port_id);
2976 if (test_done == 0) {
2977 printf("Before enable/disable GRO,"
2978 " please stop forwarding first\n");
2981 if (strcmp(onoff, "on") == 0) {
2982 if (gro_ports[port_id].enable != 0) {
2983 printf("Port %u has enabled GRO. Please"
2984 " disable GRO first\n", port_id);
2987 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2988 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2989 gro_ports[port_id].param.max_flow_num =
2990 GRO_DEFAULT_FLOW_NUM;
2991 gro_ports[port_id].param.max_item_per_flow =
2992 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2994 gro_ports[port_id].enable = 1;
2996 if (gro_ports[port_id].enable == 0) {
2997 printf("Port %u has disabled GRO\n", port_id);
3000 gro_ports[port_id].enable = 0;
3005 setup_gro_flush_cycles(uint8_t cycles)
3007 if (test_done == 0) {
3008 printf("Before change flush interval for GRO,"
3009 " please stop forwarding first.\n");
3013 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
3014 GRO_DEFAULT_FLUSH_CYCLES) {
3015 printf("The flushing cycle be in the range"
3016 " of 1 to %u. Revert to the default"
3018 GRO_MAX_FLUSH_CYCLES,
3019 GRO_DEFAULT_FLUSH_CYCLES);
3020 cycles = GRO_DEFAULT_FLUSH_CYCLES;
3023 gro_flush_cycles = cycles;
3027 show_gro(portid_t port_id)
3029 struct rte_gro_param *param;
3030 uint32_t max_pkts_num;
3032 param = &gro_ports[port_id].param;
3034 if (!rte_eth_dev_is_valid_port(port_id)) {
3035 printf("Invalid port id %u.\n", port_id);
3038 if (gro_ports[port_id].enable) {
3039 printf("GRO type: TCP/IPv4\n");
3040 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3041 max_pkts_num = param->max_flow_num *
3042 param->max_item_per_flow;
3044 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
3045 printf("Max number of packets to perform GRO: %u\n",
3047 printf("Flushing cycles: %u\n", gro_flush_cycles);
3049 printf("Port %u doesn't enable GRO.\n", port_id);
3053 setup_gso(const char *mode, portid_t port_id)
3055 if (!rte_eth_dev_is_valid_port(port_id)) {
3056 printf("invalid port id %u\n", port_id);
3059 if (strcmp(mode, "on") == 0) {
3060 if (test_done == 0) {
3061 printf("before enabling GSO,"
3062 " please stop forwarding first\n");
3065 gso_ports[port_id].enable = 1;
3066 } else if (strcmp(mode, "off") == 0) {
3067 if (test_done == 0) {
3068 printf("before disabling GSO,"
3069 " please stop forwarding first\n");
3072 gso_ports[port_id].enable = 0;
3077 list_pkt_forwarding_modes(void)
3079 static char fwd_modes[128] = "";
3080 const char *separator = "|";
3081 struct fwd_engine *fwd_eng;
3084 if (strlen (fwd_modes) == 0) {
3085 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3086 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3087 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3088 strncat(fwd_modes, separator,
3089 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3091 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3098 list_pkt_forwarding_retry_modes(void)
3100 static char fwd_modes[128] = "";
3101 const char *separator = "|";
3102 struct fwd_engine *fwd_eng;
3105 if (strlen(fwd_modes) == 0) {
3106 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3107 if (fwd_eng == &rx_only_engine)
3109 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3111 strlen(fwd_modes) - 1);
3112 strncat(fwd_modes, separator,
3114 strlen(fwd_modes) - 1);
3116 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3123 set_pkt_forwarding_mode(const char *fwd_mode_name)
3125 struct fwd_engine *fwd_eng;
3129 while ((fwd_eng = fwd_engines[i]) != NULL) {
3130 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
3131 printf("Set %s packet forwarding mode%s\n",
3133 retry_enabled == 0 ? "" : " with retry");
3134 cur_fwd_eng = fwd_eng;
3139 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
3143 add_rx_dump_callbacks(portid_t portid)
3145 struct rte_eth_dev_info dev_info;
3149 if (port_id_is_invalid(portid, ENABLED_WARN))
3152 ret = eth_dev_info_get_print_err(portid, &dev_info);
3156 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3157 if (!ports[portid].rx_dump_cb[queue])
3158 ports[portid].rx_dump_cb[queue] =
3159 rte_eth_add_rx_callback(portid, queue,
3160 dump_rx_pkts, NULL);
3164 add_tx_dump_callbacks(portid_t portid)
3166 struct rte_eth_dev_info dev_info;
3170 if (port_id_is_invalid(portid, ENABLED_WARN))
3173 ret = eth_dev_info_get_print_err(portid, &dev_info);
3177 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3178 if (!ports[portid].tx_dump_cb[queue])
3179 ports[portid].tx_dump_cb[queue] =
3180 rte_eth_add_tx_callback(portid, queue,
3181 dump_tx_pkts, NULL);
3185 remove_rx_dump_callbacks(portid_t portid)
3187 struct rte_eth_dev_info dev_info;
3191 if (port_id_is_invalid(portid, ENABLED_WARN))
3194 ret = eth_dev_info_get_print_err(portid, &dev_info);
3198 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3199 if (ports[portid].rx_dump_cb[queue]) {
3200 rte_eth_remove_rx_callback(portid, queue,
3201 ports[portid].rx_dump_cb[queue]);
3202 ports[portid].rx_dump_cb[queue] = NULL;
3207 remove_tx_dump_callbacks(portid_t portid)
3209 struct rte_eth_dev_info dev_info;
3213 if (port_id_is_invalid(portid, ENABLED_WARN))
3216 ret = eth_dev_info_get_print_err(portid, &dev_info);
3220 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3221 if (ports[portid].tx_dump_cb[queue]) {
3222 rte_eth_remove_tx_callback(portid, queue,
3223 ports[portid].tx_dump_cb[queue]);
3224 ports[portid].tx_dump_cb[queue] = NULL;
3229 configure_rxtx_dump_callbacks(uint16_t verbose)
3233 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3234 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
3238 RTE_ETH_FOREACH_DEV(portid)
3240 if (verbose == 1 || verbose > 2)
3241 add_rx_dump_callbacks(portid);
3243 remove_rx_dump_callbacks(portid);
3245 add_tx_dump_callbacks(portid);
3247 remove_tx_dump_callbacks(portid);
3252 set_verbose_level(uint16_t vb_level)
3254 printf("Change verbose level from %u to %u\n",
3255 (unsigned int) verbose_level, (unsigned int) vb_level);
3256 verbose_level = vb_level;
3257 configure_rxtx_dump_callbacks(verbose_level);
3261 vlan_extend_set(portid_t port_id, int on)
3265 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3267 if (port_id_is_invalid(port_id, ENABLED_WARN))
3270 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3273 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
3274 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3276 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
3277 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3280 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3282 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
3283 "diag=%d\n", port_id, on, diag);
3284 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3288 rx_vlan_strip_set(portid_t port_id, int on)
3292 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3294 if (port_id_is_invalid(port_id, ENABLED_WARN))
3297 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3300 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
3301 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3303 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
3304 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3307 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3309 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
3310 "diag=%d\n", port_id, on, diag);
3311 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3315 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
3319 if (port_id_is_invalid(port_id, ENABLED_WARN))
3322 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
3324 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
3325 "diag=%d\n", port_id, queue_id, on, diag);
3329 rx_vlan_filter_set(portid_t port_id, int on)
3333 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3335 if (port_id_is_invalid(port_id, ENABLED_WARN))
3338 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3341 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
3342 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3344 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
3345 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3348 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3350 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
3351 "diag=%d\n", port_id, on, diag);
3352 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3356 rx_vlan_qinq_strip_set(portid_t port_id, int on)
3360 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3362 if (port_id_is_invalid(port_id, ENABLED_WARN))
3365 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3368 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
3369 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3371 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
3372 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3375 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3377 printf("%s(port_pi=%d, on=%d) failed "
3378 "diag=%d\n", __func__, port_id, on, diag);
3379 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3383 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
3387 if (port_id_is_invalid(port_id, ENABLED_WARN))
3389 if (vlan_id_is_invalid(vlan_id))
3391 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
3394 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
3396 port_id, vlan_id, on, diag);
3401 rx_vlan_all_filter_set(portid_t port_id, int on)
3405 if (port_id_is_invalid(port_id, ENABLED_WARN))
3407 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
3408 if (rx_vft_set(port_id, vlan_id, on))
3414 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
3418 if (port_id_is_invalid(port_id, ENABLED_WARN))
3421 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
3425 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
3427 port_id, vlan_type, tp_id, diag);
3431 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
3433 struct rte_eth_dev_info dev_info;
3436 if (port_id_is_invalid(port_id, ENABLED_WARN))
3438 if (vlan_id_is_invalid(vlan_id))
3441 if (ports[port_id].dev_conf.txmode.offloads &
3442 DEV_TX_OFFLOAD_QINQ_INSERT) {
3443 printf("Error, as QinQ has been enabled.\n");
3447 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3451 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
3452 printf("Error: vlan insert is not supported by port %d\n",
3457 tx_vlan_reset(port_id);
3458 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
3459 ports[port_id].tx_vlan_id = vlan_id;
3463 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
3465 struct rte_eth_dev_info dev_info;
3468 if (port_id_is_invalid(port_id, ENABLED_WARN))
3470 if (vlan_id_is_invalid(vlan_id))
3472 if (vlan_id_is_invalid(vlan_id_outer))
3475 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3479 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
3480 printf("Error: qinq insert not supported by port %d\n",
3485 tx_vlan_reset(port_id);
3486 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
3487 DEV_TX_OFFLOAD_QINQ_INSERT);
3488 ports[port_id].tx_vlan_id = vlan_id;
3489 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
3493 tx_vlan_reset(portid_t port_id)
3495 if (port_id_is_invalid(port_id, ENABLED_WARN))
3497 ports[port_id].dev_conf.txmode.offloads &=
3498 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
3499 DEV_TX_OFFLOAD_QINQ_INSERT);
3500 ports[port_id].tx_vlan_id = 0;
3501 ports[port_id].tx_vlan_id_outer = 0;
3505 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
3507 if (port_id_is_invalid(port_id, ENABLED_WARN))
3510 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
3514 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
3517 uint8_t existing_mapping_found = 0;
3519 if (port_id_is_invalid(port_id, ENABLED_WARN))
3522 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
3525 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
3526 printf("map_value not in required range 0..%d\n",
3527 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
3531 if (!is_rx) { /*then tx*/
3532 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3533 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3534 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
3535 tx_queue_stats_mappings[i].stats_counter_id = map_value;
3536 existing_mapping_found = 1;
3540 if (!existing_mapping_found) { /* A new additional mapping... */
3541 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
3542 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
3543 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
3544 nb_tx_queue_stats_mappings++;
3548 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3549 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3550 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
3551 rx_queue_stats_mappings[i].stats_counter_id = map_value;
3552 existing_mapping_found = 1;
3556 if (!existing_mapping_found) { /* A new additional mapping... */
3557 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
3558 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
3559 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
3560 nb_rx_queue_stats_mappings++;
3566 set_xstats_hide_zero(uint8_t on_off)
3568 xstats_hide_zero = on_off;
3572 print_fdir_mask(struct rte_eth_fdir_masks *mask)
3574 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
3576 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3577 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
3578 " tunnel_id: 0x%08x",
3579 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
3580 rte_be_to_cpu_32(mask->tunnel_id_mask));
3581 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3582 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
3583 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
3584 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
3586 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
3587 rte_be_to_cpu_16(mask->src_port_mask),
3588 rte_be_to_cpu_16(mask->dst_port_mask));
3590 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3591 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
3592 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3593 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3594 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3596 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3597 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3598 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3599 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3600 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3607 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3609 struct rte_eth_flex_payload_cfg *cfg;
3612 for (i = 0; i < flex_conf->nb_payloads; i++) {
3613 cfg = &flex_conf->flex_set[i];
3614 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3616 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3617 printf("\n L2_PAYLOAD: ");
3618 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3619 printf("\n L3_PAYLOAD: ");
3620 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3621 printf("\n L4_PAYLOAD: ");
3623 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3624 for (j = 0; j < num; j++)
3625 printf(" %-5u", cfg->src_offset[j]);
3631 flowtype_to_str(uint16_t flow_type)
3633 struct flow_type_info {
3639 static struct flow_type_info flowtype_str_table[] = {
3640 {"raw", RTE_ETH_FLOW_RAW},
3641 {"ipv4", RTE_ETH_FLOW_IPV4},
3642 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3643 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3644 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3645 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3646 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3647 {"ipv6", RTE_ETH_FLOW_IPV6},
3648 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3649 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3650 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3651 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3652 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3653 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3654 {"port", RTE_ETH_FLOW_PORT},
3655 {"vxlan", RTE_ETH_FLOW_VXLAN},
3656 {"geneve", RTE_ETH_FLOW_GENEVE},
3657 {"nvgre", RTE_ETH_FLOW_NVGRE},
3658 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
3661 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3662 if (flowtype_str_table[i].ftype == flow_type)
3663 return flowtype_str_table[i].str;
3670 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3672 struct rte_eth_fdir_flex_mask *mask;
3676 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3677 mask = &flex_conf->flex_mask[i];
3678 p = flowtype_to_str(mask->flow_type);
3679 printf("\n %s:\t", p ? p : "unknown");
3680 for (j = 0; j < num; j++)
3681 printf(" %02x", mask->mask[j]);
3687 print_fdir_flow_type(uint32_t flow_types_mask)
3692 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3693 if (!(flow_types_mask & (1 << i)))
3695 p = flowtype_to_str(i);
3705 fdir_get_infos(portid_t port_id)
3707 struct rte_eth_fdir_stats fdir_stat;
3708 struct rte_eth_fdir_info fdir_info;
3711 static const char *fdir_stats_border = "########################";
3713 if (port_id_is_invalid(port_id, ENABLED_WARN))
3715 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3717 printf("\n FDIR is not supported on port %-2d\n",
3722 memset(&fdir_info, 0, sizeof(fdir_info));
3723 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3724 RTE_ETH_FILTER_INFO, &fdir_info);
3725 memset(&fdir_stat, 0, sizeof(fdir_stat));
3726 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3727 RTE_ETH_FILTER_STATS, &fdir_stat);
3728 printf("\n %s FDIR infos for port %-2d %s\n",
3729 fdir_stats_border, port_id, fdir_stats_border);
3731 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3732 printf(" PERFECT\n");
3733 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3734 printf(" PERFECT-MAC-VLAN\n");
3735 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3736 printf(" PERFECT-TUNNEL\n");
3737 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3738 printf(" SIGNATURE\n");
3740 printf(" DISABLE\n");
3741 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3742 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3743 printf(" SUPPORTED FLOW TYPE: ");
3744 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3746 printf(" FLEX PAYLOAD INFO:\n");
3747 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3748 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3749 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3750 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3751 fdir_info.flex_payload_unit,
3752 fdir_info.max_flex_payload_segment_num,
3753 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3755 print_fdir_mask(&fdir_info.mask);
3756 if (fdir_info.flex_conf.nb_payloads > 0) {
3757 printf(" FLEX PAYLOAD SRC OFFSET:");
3758 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3760 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3761 printf(" FLEX MASK CFG:");
3762 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3764 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3765 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3766 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3767 fdir_info.guarant_spc, fdir_info.best_spc);
3768 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3769 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3770 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3771 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3772 fdir_stat.collision, fdir_stat.free,
3773 fdir_stat.maxhash, fdir_stat.maxlen,
3774 fdir_stat.add, fdir_stat.remove,
3775 fdir_stat.f_add, fdir_stat.f_remove);
3776 printf(" %s############################%s\n",
3777 fdir_stats_border, fdir_stats_border);
3781 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3783 struct rte_port *port;
3784 struct rte_eth_fdir_flex_conf *flex_conf;
3787 port = &ports[port_id];
3788 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3789 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3790 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3795 if (i >= RTE_ETH_FLOW_MAX) {
3796 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3797 idx = flex_conf->nb_flexmasks;
3798 flex_conf->nb_flexmasks++;
3800 printf("The flex mask table is full. Can not set flex"
3801 " mask for flow_type(%u).", cfg->flow_type);
3805 rte_memcpy(&flex_conf->flex_mask[idx],
3807 sizeof(struct rte_eth_fdir_flex_mask));
3811 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3813 struct rte_port *port;
3814 struct rte_eth_fdir_flex_conf *flex_conf;
3817 port = &ports[port_id];
3818 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3819 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3820 if (cfg->type == flex_conf->flex_set[i].type) {
3825 if (i >= RTE_ETH_PAYLOAD_MAX) {
3826 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3827 idx = flex_conf->nb_payloads;
3828 flex_conf->nb_payloads++;
3830 printf("The flex payload table is full. Can not set"
3831 " flex payload for type(%u).", cfg->type);
3835 rte_memcpy(&flex_conf->flex_set[idx],
3837 sizeof(struct rte_eth_flex_payload_cfg));
3842 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3844 #ifdef RTE_LIBRTE_IXGBE_PMD
3848 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3850 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3854 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3855 is_rx ? "rx" : "tx", port_id, diag);
3858 printf("VF %s setting not supported for port %d\n",
3859 is_rx ? "Rx" : "Tx", port_id);
3865 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3868 struct rte_eth_link link;
3871 if (port_id_is_invalid(port_id, ENABLED_WARN))
3873 ret = eth_link_get_nowait_print_err(port_id, &link);
3876 if (rate > link.link_speed) {
3877 printf("Invalid rate value:%u bigger than link speed: %u\n",
3878 rate, link.link_speed);
3881 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3884 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3890 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3892 int diag = -ENOTSUP;
3896 RTE_SET_USED(q_msk);
3898 #ifdef RTE_LIBRTE_IXGBE_PMD
3899 if (diag == -ENOTSUP)
3900 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3903 #ifdef RTE_LIBRTE_BNXT_PMD
3904 if (diag == -ENOTSUP)
3905 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3910 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3916 * Functions to manage the set of filtered Multicast MAC addresses.
3918 * A pool of filtered multicast MAC addresses is associated with each port.
3919 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3920 * The address of the pool and the number of valid multicast MAC addresses
3921 * recorded in the pool are stored in the fields "mc_addr_pool" and
3922 * "mc_addr_nb" of the "rte_port" data structure.
3924 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3925 * to be supplied a contiguous array of multicast MAC addresses.
3926 * To comply with this constraint, the set of multicast addresses recorded
3927 * into the pool are systematically compacted at the beginning of the pool.
3928 * Hence, when a multicast address is removed from the pool, all following
3929 * addresses, if any, are copied back to keep the set contiguous.
3931 #define MCAST_POOL_INC 32
3934 mcast_addr_pool_extend(struct rte_port *port)
3936 struct rte_ether_addr *mc_pool;
3937 size_t mc_pool_size;
3940 * If a free entry is available at the end of the pool, just
3941 * increment the number of recorded multicast addresses.
3943 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3949 * [re]allocate a pool with MCAST_POOL_INC more entries.
3950 * The previous test guarantees that port->mc_addr_nb is a multiple
3951 * of MCAST_POOL_INC.
3953 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
3955 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
3957 if (mc_pool == NULL) {
3958 printf("allocation of pool of %u multicast addresses failed\n",
3959 port->mc_addr_nb + MCAST_POOL_INC);
3963 port->mc_addr_pool = mc_pool;
3970 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
3972 if (mcast_addr_pool_extend(port) != 0)
3974 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
3978 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3981 if (addr_idx == port->mc_addr_nb) {
3982 /* No need to recompact the set of multicast addressses. */
3983 if (port->mc_addr_nb == 0) {
3984 /* free the pool of multicast addresses. */
3985 free(port->mc_addr_pool);
3986 port->mc_addr_pool = NULL;
3990 memmove(&port->mc_addr_pool[addr_idx],
3991 &port->mc_addr_pool[addr_idx + 1],
3992 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
3996 eth_port_multicast_addr_list_set(portid_t port_id)
3998 struct rte_port *port;
4001 port = &ports[port_id];
4002 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
4005 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
4006 port_id, port->mc_addr_nb, diag);
4012 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
4014 struct rte_port *port;
4017 if (port_id_is_invalid(port_id, ENABLED_WARN))
4020 port = &ports[port_id];
4023 * Check that the added multicast MAC address is not already recorded
4024 * in the pool of multicast addresses.
4026 for (i = 0; i < port->mc_addr_nb; i++) {
4027 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
4028 printf("multicast address already filtered by port\n");
4033 mcast_addr_pool_append(port, mc_addr);
4034 if (eth_port_multicast_addr_list_set(port_id) < 0)
4035 /* Rollback on failure, remove the address from the pool */
4036 mcast_addr_pool_remove(port, i);
4040 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
4042 struct rte_port *port;
4045 if (port_id_is_invalid(port_id, ENABLED_WARN))
4048 port = &ports[port_id];
4051 * Search the pool of multicast MAC addresses for the removed address.
4053 for (i = 0; i < port->mc_addr_nb; i++) {
4054 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
4057 if (i == port->mc_addr_nb) {
4058 printf("multicast address not filtered by port %d\n", port_id);
4062 mcast_addr_pool_remove(port, i);
4063 if (eth_port_multicast_addr_list_set(port_id) < 0)
4064 /* Rollback on failure, add the address back into the pool */
4065 mcast_addr_pool_append(port, mc_addr);
4069 port_dcb_info_display(portid_t port_id)
4071 struct rte_eth_dcb_info dcb_info;
4074 static const char *border = "================";
4076 if (port_id_is_invalid(port_id, ENABLED_WARN))
4079 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
4081 printf("\n Failed to get dcb infos on port %-2d\n",
4085 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
4086 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
4088 for (i = 0; i < dcb_info.nb_tcs; i++)
4090 printf("\n Priority : ");
4091 for (i = 0; i < dcb_info.nb_tcs; i++)
4092 printf("\t%4d", dcb_info.prio_tc[i]);
4093 printf("\n BW percent :");
4094 for (i = 0; i < dcb_info.nb_tcs; i++)
4095 printf("\t%4d%%", dcb_info.tc_bws[i]);
4096 printf("\n RXQ base : ");
4097 for (i = 0; i < dcb_info.nb_tcs; i++)
4098 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
4099 printf("\n RXQ number :");
4100 for (i = 0; i < dcb_info.nb_tcs; i++)
4101 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
4102 printf("\n TXQ base : ");
4103 for (i = 0; i < dcb_info.nb_tcs; i++)
4104 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
4105 printf("\n TXQ number :");
4106 for (i = 0; i < dcb_info.nb_tcs; i++)
4107 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
4112 open_file(const char *file_path, uint32_t *size)
4114 int fd = open(file_path, O_RDONLY);
4116 uint8_t *buf = NULL;
4124 printf("%s: Failed to open %s\n", __func__, file_path);
4128 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
4130 printf("%s: File operations failed\n", __func__);
4134 pkg_size = st_buf.st_size;
4137 printf("%s: File operations failed\n", __func__);
4141 buf = (uint8_t *)malloc(pkg_size);
4144 printf("%s: Failed to malloc memory\n", __func__);
4148 ret = read(fd, buf, pkg_size);
4151 printf("%s: File read operation failed\n", __func__);
4165 save_file(const char *file_path, uint8_t *buf, uint32_t size)
4167 FILE *fh = fopen(file_path, "wb");
4170 printf("%s: Failed to open %s\n", __func__, file_path);
4174 if (fwrite(buf, 1, size, fh) != size) {
4176 printf("%s: File write operation failed\n", __func__);
4186 close_file(uint8_t *buf)
4197 port_queue_region_info_display(portid_t port_id, void *buf)
4199 #ifdef RTE_LIBRTE_I40E_PMD
4201 struct rte_pmd_i40e_queue_regions *info =
4202 (struct rte_pmd_i40e_queue_regions *)buf;
4203 static const char *queue_region_info_stats_border = "-------";
4205 if (!info->queue_region_number)
4206 printf("there is no region has been set before");
4208 printf("\n %s All queue region info for port=%2d %s",
4209 queue_region_info_stats_border, port_id,
4210 queue_region_info_stats_border);
4211 printf("\n queue_region_number: %-14u \n",
4212 info->queue_region_number);
4214 for (i = 0; i < info->queue_region_number; i++) {
4215 printf("\n region_id: %-14u queue_number: %-14u "
4216 "queue_start_index: %-14u \n",
4217 info->region[i].region_id,
4218 info->region[i].queue_num,
4219 info->region[i].queue_start_index);
4221 printf(" user_priority_num is %-14u :",
4222 info->region[i].user_priority_num);
4223 for (j = 0; j < info->region[i].user_priority_num; j++)
4224 printf(" %-14u ", info->region[i].user_priority[j]);
4226 printf("\n flowtype_num is %-14u :",
4227 info->region[i].flowtype_num);
4228 for (j = 0; j < info->region[i].flowtype_num; j++)
4229 printf(" %-14u ", info->region[i].hw_flowtype[j]);
4232 RTE_SET_USED(port_id);
4240 show_macs(portid_t port_id)
4242 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4243 struct rte_eth_dev_info dev_info;
4244 struct rte_ether_addr *addr;
4245 uint32_t i, num_macs = 0;
4246 struct rte_eth_dev *dev;
4248 dev = &rte_eth_devices[port_id];
4250 rte_eth_dev_info_get(port_id, &dev_info);
4252 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4253 addr = &dev->data->mac_addrs[i];
4255 /* skip zero address */
4256 if (rte_is_zero_ether_addr(addr))
4262 printf("Number of MAC address added: %d\n", num_macs);
4264 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4265 addr = &dev->data->mac_addrs[i];
4267 /* skip zero address */
4268 if (rte_is_zero_ether_addr(addr))
4271 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4272 printf(" %s\n", buf);
4277 show_mcast_macs(portid_t port_id)
4279 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4280 struct rte_ether_addr *addr;
4281 struct rte_port *port;
4284 port = &ports[port_id];
4286 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
4288 for (i = 0; i < port->mc_addr_nb; i++) {
4289 addr = &port->mc_addr_pool[i];
4291 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4292 printf(" %s\n", buf);