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 #ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
58 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
60 #define CLOCK_TYPE_ID CLOCK_MONOTONIC
63 #define NS_PER_SEC 1E9
65 static char *flowtype_to_str(uint16_t flow_type);
68 enum tx_pkt_split split;
72 .split = TX_PKT_SPLIT_OFF,
76 .split = TX_PKT_SPLIT_ON,
80 .split = TX_PKT_SPLIT_RND,
85 const struct rss_type_info rss_type_table[] = {
86 { "all", ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP | ETH_RSS_TCP |
87 ETH_RSS_UDP | ETH_RSS_SCTP | ETH_RSS_L2_PAYLOAD |
88 ETH_RSS_L2TPV3 | ETH_RSS_ESP | ETH_RSS_AH | ETH_RSS_PFCP |
91 { "eth", ETH_RSS_ETH },
92 { "l2-src-only", ETH_RSS_L2_SRC_ONLY },
93 { "l2-dst-only", ETH_RSS_L2_DST_ONLY },
94 { "vlan", ETH_RSS_VLAN },
95 { "s-vlan", ETH_RSS_S_VLAN },
96 { "c-vlan", ETH_RSS_C_VLAN },
97 { "ipv4", ETH_RSS_IPV4 },
98 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
99 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
100 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
101 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
102 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
103 { "ipv6", ETH_RSS_IPV6 },
104 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
105 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
106 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
107 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
108 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
109 { "l2-payload", ETH_RSS_L2_PAYLOAD },
110 { "ipv6-ex", ETH_RSS_IPV6_EX },
111 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
112 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
113 { "port", ETH_RSS_PORT },
114 { "vxlan", ETH_RSS_VXLAN },
115 { "geneve", ETH_RSS_GENEVE },
116 { "nvgre", ETH_RSS_NVGRE },
117 { "ip", ETH_RSS_IP },
118 { "udp", ETH_RSS_UDP },
119 { "tcp", ETH_RSS_TCP },
120 { "sctp", ETH_RSS_SCTP },
121 { "tunnel", ETH_RSS_TUNNEL },
122 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
123 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
124 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
125 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
126 { "esp", ETH_RSS_ESP },
127 { "ah", ETH_RSS_AH },
128 { "l2tpv3", ETH_RSS_L2TPV3 },
129 { "pfcp", ETH_RSS_PFCP },
130 { "pppoe", ETH_RSS_PPPOE },
131 { "gtpu", ETH_RSS_GTPU },
136 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
138 char buf[RTE_ETHER_ADDR_FMT_SIZE];
139 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
140 printf("%s%s", name, buf);
144 nic_stats_display(portid_t port_id)
146 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
147 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
148 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
149 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
150 static uint64_t prev_ns[RTE_MAX_ETHPORTS];
151 struct timespec cur_time;
152 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
154 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
155 struct rte_eth_stats stats;
156 struct rte_port *port = &ports[port_id];
159 static const char *nic_stats_border = "########################";
161 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
165 rte_eth_stats_get(port_id, &stats);
166 printf("\n %s NIC statistics for port %-2d %s\n",
167 nic_stats_border, port_id, nic_stats_border);
169 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
170 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
172 stats.ipackets, stats.imissed, stats.ibytes);
173 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
174 printf(" RX-nombuf: %-10"PRIu64"\n",
176 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
178 stats.opackets, stats.oerrors, stats.obytes);
181 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
182 " RX-bytes: %10"PRIu64"\n",
183 stats.ipackets, stats.ierrors, stats.ibytes);
184 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
185 printf(" RX-nombuf: %10"PRIu64"\n",
187 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
188 " TX-bytes: %10"PRIu64"\n",
189 stats.opackets, stats.oerrors, stats.obytes);
192 if (port->rx_queue_stats_mapping_enabled) {
194 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
195 printf(" Stats reg %2d RX-packets: %10"PRIu64
196 " RX-errors: %10"PRIu64
197 " RX-bytes: %10"PRIu64"\n",
198 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
201 if (port->tx_queue_stats_mapping_enabled) {
203 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
204 printf(" Stats reg %2d TX-packets: %10"PRIu64
205 " TX-bytes: %10"PRIu64"\n",
206 i, stats.q_opackets[i], stats.q_obytes[i]);
211 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
214 ns = cur_time.tv_sec * NS_PER_SEC;
215 ns += cur_time.tv_nsec;
217 if (prev_ns[port_id] != 0)
218 diff_ns = ns - prev_ns[port_id];
219 prev_ns[port_id] = ns;
222 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
223 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
224 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
225 (stats.opackets - prev_pkts_tx[port_id]) : 0;
226 prev_pkts_rx[port_id] = stats.ipackets;
227 prev_pkts_tx[port_id] = stats.opackets;
228 mpps_rx = diff_ns > 0 ?
229 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
230 mpps_tx = diff_ns > 0 ?
231 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
233 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
234 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
235 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
236 (stats.obytes - prev_bytes_tx[port_id]) : 0;
237 prev_bytes_rx[port_id] = stats.ibytes;
238 prev_bytes_tx[port_id] = stats.obytes;
239 mbps_rx = diff_ns > 0 ?
240 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
241 mbps_tx = diff_ns > 0 ?
242 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
244 printf("\n Throughput (since last show)\n");
245 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
246 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
247 mpps_tx, mbps_tx * 8);
249 printf(" %s############################%s\n",
250 nic_stats_border, nic_stats_border);
254 nic_stats_clear(portid_t port_id)
258 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
263 ret = rte_eth_stats_reset(port_id);
265 printf("%s: Error: failed to reset stats (port %u): %s",
266 __func__, port_id, strerror(-ret));
270 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
274 printf("%s: Error: failed to get stats (port %u): %s",
275 __func__, port_id, strerror(ret));
278 printf("\n NIC statistics for port %d cleared\n", port_id);
282 nic_xstats_display(portid_t port_id)
284 struct rte_eth_xstat *xstats;
285 int cnt_xstats, idx_xstat;
286 struct rte_eth_xstat_name *xstats_names;
288 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
292 printf("###### NIC extended statistics for port %-2d\n", port_id);
293 if (!rte_eth_dev_is_valid_port(port_id)) {
294 printf("Error: Invalid port number %i\n", port_id);
299 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
300 if (cnt_xstats < 0) {
301 printf("Error: Cannot get count of xstats\n");
305 /* Get id-name lookup table */
306 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
307 if (xstats_names == NULL) {
308 printf("Cannot allocate memory for xstats lookup\n");
311 if (cnt_xstats != rte_eth_xstats_get_names(
312 port_id, xstats_names, cnt_xstats)) {
313 printf("Error: Cannot get xstats lookup\n");
318 /* Get stats themselves */
319 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
320 if (xstats == NULL) {
321 printf("Cannot allocate memory for xstats\n");
325 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
326 printf("Error: Unable to get xstats\n");
333 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
334 if (xstats_hide_zero && !xstats[idx_xstat].value)
336 printf("%s: %"PRIu64"\n",
337 xstats_names[idx_xstat].name,
338 xstats[idx_xstat].value);
345 nic_xstats_clear(portid_t port_id)
349 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
354 ret = rte_eth_xstats_reset(port_id);
356 printf("%s: Error: failed to reset xstats (port %u): %s",
357 __func__, port_id, strerror(-ret));
361 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
365 printf("%s: Error: failed to get stats (port %u): %s",
366 __func__, port_id, strerror(ret));
372 nic_stats_mapping_display(portid_t port_id)
374 struct rte_port *port = &ports[port_id];
377 static const char *nic_stats_mapping_border = "########################";
379 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
384 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
385 printf("Port id %d - either does not support queue statistic mapping or"
386 " no queue statistic mapping set\n", port_id);
390 printf("\n %s NIC statistics mapping for port %-2d %s\n",
391 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
393 if (port->rx_queue_stats_mapping_enabled) {
394 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
395 if (rx_queue_stats_mappings[i].port_id == port_id) {
396 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
397 rx_queue_stats_mappings[i].queue_id,
398 rx_queue_stats_mappings[i].stats_counter_id);
405 if (port->tx_queue_stats_mapping_enabled) {
406 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
407 if (tx_queue_stats_mappings[i].port_id == port_id) {
408 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
409 tx_queue_stats_mappings[i].queue_id,
410 tx_queue_stats_mappings[i].stats_counter_id);
415 printf(" %s####################################%s\n",
416 nic_stats_mapping_border, nic_stats_mapping_border);
420 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
422 struct rte_eth_burst_mode mode;
423 struct rte_eth_rxq_info qinfo;
425 static const char *info_border = "*********************";
427 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
429 printf("Failed to retrieve information for port: %u, "
430 "RX queue: %hu\nerror desc: %s(%d)\n",
431 port_id, queue_id, strerror(-rc), rc);
435 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
436 info_border, port_id, queue_id, info_border);
438 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
439 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
440 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
441 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
442 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
443 printf("\nRX drop packets: %s",
444 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
445 printf("\nRX deferred start: %s",
446 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
447 printf("\nRX scattered packets: %s",
448 (qinfo.scattered_rx != 0) ? "on" : "off");
449 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
451 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
452 printf("\nBurst mode: %s%s",
454 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
455 " (per queue)" : "");
461 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
463 struct rte_eth_burst_mode mode;
464 struct rte_eth_txq_info qinfo;
466 static const char *info_border = "*********************";
468 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
470 printf("Failed to retrieve information for port: %u, "
471 "TX queue: %hu\nerror desc: %s(%d)\n",
472 port_id, queue_id, strerror(-rc), rc);
476 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
477 info_border, port_id, queue_id, info_border);
479 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
480 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
481 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
482 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
483 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
484 printf("\nTX deferred start: %s",
485 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
486 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
488 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
489 printf("\nBurst mode: %s%s",
491 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
492 " (per queue)" : "");
497 static int bus_match_all(const struct rte_bus *bus, const void *data)
505 device_infos_display(const char *identifier)
507 static const char *info_border = "*********************";
508 struct rte_bus *start = NULL, *next;
509 struct rte_dev_iterator dev_iter;
510 char name[RTE_ETH_NAME_MAX_LEN];
511 struct rte_ether_addr mac_addr;
512 struct rte_device *dev;
513 struct rte_devargs da;
517 memset(&da, 0, sizeof(da));
521 if (rte_devargs_parsef(&da, "%s", identifier)) {
522 printf("cannot parse identifier\n");
529 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
532 if (identifier && da.bus != next)
535 /* Skip buses that don't have iterate method */
536 if (!next->dev_iterate)
539 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
540 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
544 /* Check for matching device if identifier is present */
546 strncmp(da.name, dev->name, strlen(dev->name)))
548 printf("\n%s Infos for device %s %s\n",
549 info_border, dev->name, info_border);
550 printf("Bus name: %s", dev->bus->name);
551 printf("\nDriver name: %s", dev->driver->name);
552 printf("\nDevargs: %s",
553 dev->devargs ? dev->devargs->args : "");
554 printf("\nConnect to socket: %d", dev->numa_node);
557 /* List ports with matching device name */
558 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
559 printf("\n\tPort id: %-2d", port_id);
560 if (eth_macaddr_get_print_err(port_id,
562 print_ethaddr("\n\tMAC address: ",
564 rte_eth_dev_get_name_by_port(port_id, name);
565 printf("\n\tDevice name: %s", name);
573 port_infos_display(portid_t port_id)
575 struct rte_port *port;
576 struct rte_ether_addr mac_addr;
577 struct rte_eth_link link;
578 struct rte_eth_dev_info dev_info;
580 struct rte_mempool * mp;
581 static const char *info_border = "*********************";
583 char name[RTE_ETH_NAME_MAX_LEN];
585 char fw_version[ETHDEV_FWVERS_LEN];
587 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
591 port = &ports[port_id];
592 ret = eth_link_get_nowait_print_err(port_id, &link);
596 ret = eth_dev_info_get_print_err(port_id, &dev_info);
600 printf("\n%s Infos for port %-2d %s\n",
601 info_border, port_id, info_border);
602 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
603 print_ethaddr("MAC address: ", &mac_addr);
604 rte_eth_dev_get_name_by_port(port_id, name);
605 printf("\nDevice name: %s", name);
606 printf("\nDriver name: %s", dev_info.driver_name);
608 if (rte_eth_dev_fw_version_get(port_id, fw_version,
609 ETHDEV_FWVERS_LEN) == 0)
610 printf("\nFirmware-version: %s", fw_version);
612 printf("\nFirmware-version: %s", "not available");
614 if (dev_info.device->devargs && dev_info.device->devargs->args)
615 printf("\nDevargs: %s", dev_info.device->devargs->args);
616 printf("\nConnect to socket: %u", port->socket_id);
618 if (port_numa[port_id] != NUMA_NO_CONFIG) {
619 mp = mbuf_pool_find(port_numa[port_id]);
621 printf("\nmemory allocation on the socket: %d",
624 printf("\nmemory allocation on the socket: %u",port->socket_id);
626 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
627 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
628 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
629 ("full-duplex") : ("half-duplex"));
631 if (!rte_eth_dev_get_mtu(port_id, &mtu))
632 printf("MTU: %u\n", mtu);
634 printf("Promiscuous mode: %s\n",
635 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
636 printf("Allmulticast mode: %s\n",
637 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
638 printf("Maximum number of MAC addresses: %u\n",
639 (unsigned int)(port->dev_info.max_mac_addrs));
640 printf("Maximum number of MAC addresses of hash filtering: %u\n",
641 (unsigned int)(port->dev_info.max_hash_mac_addrs));
643 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
644 if (vlan_offload >= 0){
645 printf("VLAN offload: \n");
646 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
647 printf(" strip on, ");
649 printf(" strip off, ");
651 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
652 printf("filter on, ");
654 printf("filter off, ");
656 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
657 printf("extend on, ");
659 printf("extend off, ");
661 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
662 printf("qinq strip on\n");
664 printf("qinq strip off\n");
667 if (dev_info.hash_key_size > 0)
668 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
669 if (dev_info.reta_size > 0)
670 printf("Redirection table size: %u\n", dev_info.reta_size);
671 if (!dev_info.flow_type_rss_offloads)
672 printf("No RSS offload flow type is supported.\n");
677 printf("Supported RSS offload flow types:\n");
678 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
679 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
680 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
682 p = flowtype_to_str(i);
686 printf(" user defined %d\n", i);
690 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
691 printf("Maximum configurable length of RX packet: %u\n",
692 dev_info.max_rx_pktlen);
693 printf("Maximum configurable size of LRO aggregated packet: %u\n",
694 dev_info.max_lro_pkt_size);
695 if (dev_info.max_vfs)
696 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
697 if (dev_info.max_vmdq_pools)
698 printf("Maximum number of VMDq pools: %u\n",
699 dev_info.max_vmdq_pools);
701 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
702 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
703 printf("Max possible number of RXDs per queue: %hu\n",
704 dev_info.rx_desc_lim.nb_max);
705 printf("Min possible number of RXDs per queue: %hu\n",
706 dev_info.rx_desc_lim.nb_min);
707 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
709 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
710 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
711 printf("Max possible number of TXDs per queue: %hu\n",
712 dev_info.tx_desc_lim.nb_max);
713 printf("Min possible number of TXDs per queue: %hu\n",
714 dev_info.tx_desc_lim.nb_min);
715 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
716 printf("Max segment number per packet: %hu\n",
717 dev_info.tx_desc_lim.nb_seg_max);
718 printf("Max segment number per MTU/TSO: %hu\n",
719 dev_info.tx_desc_lim.nb_mtu_seg_max);
721 /* Show switch info only if valid switch domain and port id is set */
722 if (dev_info.switch_info.domain_id !=
723 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
724 if (dev_info.switch_info.name)
725 printf("Switch name: %s\n", dev_info.switch_info.name);
727 printf("Switch domain Id: %u\n",
728 dev_info.switch_info.domain_id);
729 printf("Switch Port Id: %u\n",
730 dev_info.switch_info.port_id);
735 port_summary_header_display(void)
737 uint16_t port_number;
739 port_number = rte_eth_dev_count_avail();
740 printf("Number of available ports: %i\n", port_number);
741 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
742 "Driver", "Status", "Link");
746 port_summary_display(portid_t port_id)
748 struct rte_ether_addr mac_addr;
749 struct rte_eth_link link;
750 struct rte_eth_dev_info dev_info;
751 char name[RTE_ETH_NAME_MAX_LEN];
754 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
759 ret = eth_link_get_nowait_print_err(port_id, &link);
763 ret = eth_dev_info_get_print_err(port_id, &dev_info);
767 rte_eth_dev_get_name_by_port(port_id, name);
768 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
772 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
773 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
774 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
775 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
776 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
777 (unsigned int) link.link_speed);
781 port_offload_cap_display(portid_t port_id)
783 struct rte_eth_dev_info dev_info;
784 static const char *info_border = "************";
787 if (port_id_is_invalid(port_id, ENABLED_WARN))
790 ret = eth_dev_info_get_print_err(port_id, &dev_info);
794 printf("\n%s Port %d supported offload features: %s\n",
795 info_border, port_id, info_border);
797 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
798 printf("VLAN stripped: ");
799 if (ports[port_id].dev_conf.rxmode.offloads &
800 DEV_RX_OFFLOAD_VLAN_STRIP)
806 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
807 printf("Double VLANs stripped: ");
808 if (ports[port_id].dev_conf.rxmode.offloads &
809 DEV_RX_OFFLOAD_QINQ_STRIP)
815 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
816 printf("RX IPv4 checksum: ");
817 if (ports[port_id].dev_conf.rxmode.offloads &
818 DEV_RX_OFFLOAD_IPV4_CKSUM)
824 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
825 printf("RX UDP checksum: ");
826 if (ports[port_id].dev_conf.rxmode.offloads &
827 DEV_RX_OFFLOAD_UDP_CKSUM)
833 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
834 printf("RX TCP checksum: ");
835 if (ports[port_id].dev_conf.rxmode.offloads &
836 DEV_RX_OFFLOAD_TCP_CKSUM)
842 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) {
843 printf("RX SCTP checksum: ");
844 if (ports[port_id].dev_conf.rxmode.offloads &
845 DEV_RX_OFFLOAD_SCTP_CKSUM)
851 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
852 printf("RX Outer IPv4 checksum: ");
853 if (ports[port_id].dev_conf.rxmode.offloads &
854 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
860 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) {
861 printf("RX Outer UDP checksum: ");
862 if (ports[port_id].dev_conf.rxmode.offloads &
863 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM)
869 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
870 printf("Large receive offload: ");
871 if (ports[port_id].dev_conf.rxmode.offloads &
872 DEV_RX_OFFLOAD_TCP_LRO)
878 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
879 printf("HW timestamp: ");
880 if (ports[port_id].dev_conf.rxmode.offloads &
881 DEV_RX_OFFLOAD_TIMESTAMP)
887 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) {
888 printf("Rx Keep CRC: ");
889 if (ports[port_id].dev_conf.rxmode.offloads &
890 DEV_RX_OFFLOAD_KEEP_CRC)
896 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) {
897 printf("RX offload security: ");
898 if (ports[port_id].dev_conf.rxmode.offloads &
899 DEV_RX_OFFLOAD_SECURITY)
905 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
906 printf("VLAN insert: ");
907 if (ports[port_id].dev_conf.txmode.offloads &
908 DEV_TX_OFFLOAD_VLAN_INSERT)
914 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
915 printf("Double VLANs insert: ");
916 if (ports[port_id].dev_conf.txmode.offloads &
917 DEV_TX_OFFLOAD_QINQ_INSERT)
923 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
924 printf("TX IPv4 checksum: ");
925 if (ports[port_id].dev_conf.txmode.offloads &
926 DEV_TX_OFFLOAD_IPV4_CKSUM)
932 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
933 printf("TX UDP checksum: ");
934 if (ports[port_id].dev_conf.txmode.offloads &
935 DEV_TX_OFFLOAD_UDP_CKSUM)
941 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
942 printf("TX TCP checksum: ");
943 if (ports[port_id].dev_conf.txmode.offloads &
944 DEV_TX_OFFLOAD_TCP_CKSUM)
950 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
951 printf("TX SCTP checksum: ");
952 if (ports[port_id].dev_conf.txmode.offloads &
953 DEV_TX_OFFLOAD_SCTP_CKSUM)
959 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
960 printf("TX Outer IPv4 checksum: ");
961 if (ports[port_id].dev_conf.txmode.offloads &
962 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
968 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
969 printf("TX TCP segmentation: ");
970 if (ports[port_id].dev_conf.txmode.offloads &
971 DEV_TX_OFFLOAD_TCP_TSO)
977 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
978 printf("TX UDP segmentation: ");
979 if (ports[port_id].dev_conf.txmode.offloads &
980 DEV_TX_OFFLOAD_UDP_TSO)
986 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
987 printf("TSO for VXLAN tunnel packet: ");
988 if (ports[port_id].dev_conf.txmode.offloads &
989 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
995 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
996 printf("TSO for GRE tunnel packet: ");
997 if (ports[port_id].dev_conf.txmode.offloads &
998 DEV_TX_OFFLOAD_GRE_TNL_TSO)
1004 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
1005 printf("TSO for IPIP tunnel packet: ");
1006 if (ports[port_id].dev_conf.txmode.offloads &
1007 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
1013 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
1014 printf("TSO for GENEVE tunnel packet: ");
1015 if (ports[port_id].dev_conf.txmode.offloads &
1016 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
1022 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) {
1023 printf("IP tunnel TSO: ");
1024 if (ports[port_id].dev_conf.txmode.offloads &
1025 DEV_TX_OFFLOAD_IP_TNL_TSO)
1031 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) {
1032 printf("UDP tunnel TSO: ");
1033 if (ports[port_id].dev_conf.txmode.offloads &
1034 DEV_TX_OFFLOAD_UDP_TNL_TSO)
1040 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
1041 printf("TX Outer UDP checksum: ");
1042 if (ports[port_id].dev_conf.txmode.offloads &
1043 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
1052 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1056 if (port_id == (portid_t)RTE_PORT_ALL)
1059 RTE_ETH_FOREACH_DEV(pid)
1063 if (warning == ENABLED_WARN)
1064 printf("Invalid port %d\n", port_id);
1069 void print_valid_ports(void)
1073 printf("The valid ports array is [");
1074 RTE_ETH_FOREACH_DEV(pid) {
1081 vlan_id_is_invalid(uint16_t vlan_id)
1085 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1090 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1092 const struct rte_pci_device *pci_dev;
1093 const struct rte_bus *bus;
1096 if (reg_off & 0x3) {
1097 printf("Port register offset 0x%X not aligned on a 4-byte "
1103 if (!ports[port_id].dev_info.device) {
1104 printf("Invalid device\n");
1108 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1109 if (bus && !strcmp(bus->name, "pci")) {
1110 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1112 printf("Not a PCI device\n");
1116 pci_len = pci_dev->mem_resource[0].len;
1117 if (reg_off >= pci_len) {
1118 printf("Port %d: register offset %u (0x%X) out of port PCI "
1119 "resource (length=%"PRIu64")\n",
1120 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
1127 reg_bit_pos_is_invalid(uint8_t bit_pos)
1131 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
1135 #define display_port_and_reg_off(port_id, reg_off) \
1136 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1139 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1141 display_port_and_reg_off(port_id, (unsigned)reg_off);
1142 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1146 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1151 if (port_id_is_invalid(port_id, ENABLED_WARN))
1153 if (port_reg_off_is_invalid(port_id, reg_off))
1155 if (reg_bit_pos_is_invalid(bit_x))
1157 reg_v = port_id_pci_reg_read(port_id, reg_off);
1158 display_port_and_reg_off(port_id, (unsigned)reg_off);
1159 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1163 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1164 uint8_t bit1_pos, uint8_t bit2_pos)
1170 if (port_id_is_invalid(port_id, ENABLED_WARN))
1172 if (port_reg_off_is_invalid(port_id, reg_off))
1174 if (reg_bit_pos_is_invalid(bit1_pos))
1176 if (reg_bit_pos_is_invalid(bit2_pos))
1178 if (bit1_pos > bit2_pos)
1179 l_bit = bit2_pos, h_bit = bit1_pos;
1181 l_bit = bit1_pos, h_bit = bit2_pos;
1183 reg_v = port_id_pci_reg_read(port_id, reg_off);
1186 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1187 display_port_and_reg_off(port_id, (unsigned)reg_off);
1188 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1189 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1193 port_reg_display(portid_t port_id, uint32_t reg_off)
1197 if (port_id_is_invalid(port_id, ENABLED_WARN))
1199 if (port_reg_off_is_invalid(port_id, reg_off))
1201 reg_v = port_id_pci_reg_read(port_id, reg_off);
1202 display_port_reg_value(port_id, reg_off, reg_v);
1206 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1211 if (port_id_is_invalid(port_id, ENABLED_WARN))
1213 if (port_reg_off_is_invalid(port_id, reg_off))
1215 if (reg_bit_pos_is_invalid(bit_pos))
1218 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1221 reg_v = port_id_pci_reg_read(port_id, reg_off);
1223 reg_v &= ~(1 << bit_pos);
1225 reg_v |= (1 << bit_pos);
1226 port_id_pci_reg_write(port_id, reg_off, reg_v);
1227 display_port_reg_value(port_id, reg_off, reg_v);
1231 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1232 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1239 if (port_id_is_invalid(port_id, ENABLED_WARN))
1241 if (port_reg_off_is_invalid(port_id, reg_off))
1243 if (reg_bit_pos_is_invalid(bit1_pos))
1245 if (reg_bit_pos_is_invalid(bit2_pos))
1247 if (bit1_pos > bit2_pos)
1248 l_bit = bit2_pos, h_bit = bit1_pos;
1250 l_bit = bit1_pos, h_bit = bit2_pos;
1252 if ((h_bit - l_bit) < 31)
1253 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1257 if (value > max_v) {
1258 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1259 (unsigned)value, (unsigned)value,
1260 (unsigned)max_v, (unsigned)max_v);
1263 reg_v = port_id_pci_reg_read(port_id, reg_off);
1264 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1265 reg_v |= (value << l_bit); /* Set changed bits */
1266 port_id_pci_reg_write(port_id, reg_off, reg_v);
1267 display_port_reg_value(port_id, reg_off, reg_v);
1271 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1273 if (port_id_is_invalid(port_id, ENABLED_WARN))
1275 if (port_reg_off_is_invalid(port_id, reg_off))
1277 port_id_pci_reg_write(port_id, reg_off, reg_v);
1278 display_port_reg_value(port_id, reg_off, reg_v);
1282 port_mtu_set(portid_t port_id, uint16_t mtu)
1285 struct rte_port *rte_port = &ports[port_id];
1286 struct rte_eth_dev_info dev_info;
1287 uint16_t eth_overhead;
1290 if (port_id_is_invalid(port_id, ENABLED_WARN))
1293 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1297 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1298 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1299 mtu, dev_info.min_mtu, dev_info.max_mtu);
1302 diag = rte_eth_dev_set_mtu(port_id, mtu);
1304 printf("Set MTU failed. diag=%d\n", diag);
1305 else if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1307 * Ether overhead in driver is equal to the difference of
1308 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1309 * device supports jumbo frame.
1311 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1312 if (mtu > RTE_ETHER_MAX_LEN - eth_overhead) {
1313 rte_port->dev_conf.rxmode.offloads |=
1314 DEV_RX_OFFLOAD_JUMBO_FRAME;
1315 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1318 rte_port->dev_conf.rxmode.offloads &=
1319 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1323 /* Generic flow management functions. */
1325 /** Generate a port_flow entry from attributes/pattern/actions. */
1326 static struct port_flow *
1327 port_flow_new(const struct rte_flow_attr *attr,
1328 const struct rte_flow_item *pattern,
1329 const struct rte_flow_action *actions,
1330 struct rte_flow_error *error)
1332 const struct rte_flow_conv_rule rule = {
1334 .pattern_ro = pattern,
1335 .actions_ro = actions,
1337 struct port_flow *pf;
1340 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1343 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1346 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1350 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1357 /** Print a message out of a flow error. */
1359 port_flow_complain(struct rte_flow_error *error)
1361 static const char *const errstrlist[] = {
1362 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1363 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1364 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1365 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1366 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1367 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1368 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1369 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1370 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1371 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1372 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1373 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1374 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1375 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1376 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1377 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1378 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1382 int err = rte_errno;
1384 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1385 !errstrlist[error->type])
1386 errstr = "unknown type";
1388 errstr = errstrlist[error->type];
1389 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1390 error->type, errstr,
1391 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1392 error->cause), buf) : "",
1393 error->message ? error->message : "(no stated reason)",
1398 /** Validate flow rule. */
1400 port_flow_validate(portid_t port_id,
1401 const struct rte_flow_attr *attr,
1402 const struct rte_flow_item *pattern,
1403 const struct rte_flow_action *actions)
1405 struct rte_flow_error error;
1407 /* Poisoning to make sure PMDs update it in case of error. */
1408 memset(&error, 0x11, sizeof(error));
1409 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1410 return port_flow_complain(&error);
1411 printf("Flow rule validated\n");
1415 /** Update age action context by port_flow pointer. */
1417 update_age_action_context(const struct rte_flow_action *actions,
1418 struct port_flow *pf)
1420 struct rte_flow_action_age *age = NULL;
1422 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1423 switch (actions->type) {
1424 case RTE_FLOW_ACTION_TYPE_AGE:
1425 age = (struct rte_flow_action_age *)
1426 (uintptr_t)actions->conf;
1435 /** Create flow rule. */
1437 port_flow_create(portid_t port_id,
1438 const struct rte_flow_attr *attr,
1439 const struct rte_flow_item *pattern,
1440 const struct rte_flow_action *actions)
1442 struct rte_flow *flow;
1443 struct rte_port *port;
1444 struct port_flow *pf;
1446 struct rte_flow_error error;
1448 port = &ports[port_id];
1449 if (port->flow_list) {
1450 if (port->flow_list->id == UINT32_MAX) {
1451 printf("Highest rule ID is already assigned, delete"
1455 id = port->flow_list->id + 1;
1457 pf = port_flow_new(attr, pattern, actions, &error);
1459 return port_flow_complain(&error);
1460 update_age_action_context(actions, pf);
1461 /* Poisoning to make sure PMDs update it in case of error. */
1462 memset(&error, 0x22, sizeof(error));
1463 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1466 return port_flow_complain(&error);
1468 pf->next = port->flow_list;
1471 port->flow_list = pf;
1472 printf("Flow rule #%u created\n", pf->id);
1476 /** Destroy a number of flow rules. */
1478 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1480 struct rte_port *port;
1481 struct port_flow **tmp;
1485 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1486 port_id == (portid_t)RTE_PORT_ALL)
1488 port = &ports[port_id];
1489 tmp = &port->flow_list;
1493 for (i = 0; i != n; ++i) {
1494 struct rte_flow_error error;
1495 struct port_flow *pf = *tmp;
1497 if (rule[i] != pf->id)
1500 * Poisoning to make sure PMDs update it in case
1503 memset(&error, 0x33, sizeof(error));
1504 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1505 ret = port_flow_complain(&error);
1508 printf("Flow rule #%u destroyed\n", pf->id);
1514 tmp = &(*tmp)->next;
1520 /** Remove all flow rules. */
1522 port_flow_flush(portid_t port_id)
1524 struct rte_flow_error error;
1525 struct rte_port *port;
1528 /* Poisoning to make sure PMDs update it in case of error. */
1529 memset(&error, 0x44, sizeof(error));
1530 if (rte_flow_flush(port_id, &error)) {
1531 ret = port_flow_complain(&error);
1532 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1533 port_id == (portid_t)RTE_PORT_ALL)
1536 port = &ports[port_id];
1537 while (port->flow_list) {
1538 struct port_flow *pf = port->flow_list->next;
1540 free(port->flow_list);
1541 port->flow_list = pf;
1546 /** Dump all flow rules. */
1548 port_flow_dump(portid_t port_id, const char *file_name)
1551 FILE *file = stdout;
1552 struct rte_flow_error error;
1554 if (file_name && strlen(file_name)) {
1555 file = fopen(file_name, "w");
1557 printf("Failed to create file %s: %s\n", file_name,
1562 ret = rte_flow_dev_dump(port_id, file, &error);
1564 port_flow_complain(&error);
1565 printf("Failed to dump flow: %s\n", strerror(-ret));
1567 printf("Flow dump finished\n");
1568 if (file_name && strlen(file_name))
1573 /** Query a flow rule. */
1575 port_flow_query(portid_t port_id, uint32_t rule,
1576 const struct rte_flow_action *action)
1578 struct rte_flow_error error;
1579 struct rte_port *port;
1580 struct port_flow *pf;
1583 struct rte_flow_query_count count;
1587 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1588 port_id == (portid_t)RTE_PORT_ALL)
1590 port = &ports[port_id];
1591 for (pf = port->flow_list; pf; pf = pf->next)
1595 printf("Flow rule #%u not found\n", rule);
1598 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1599 &name, sizeof(name),
1600 (void *)(uintptr_t)action->type, &error);
1602 return port_flow_complain(&error);
1603 switch (action->type) {
1604 case RTE_FLOW_ACTION_TYPE_COUNT:
1607 printf("Cannot query action type %d (%s)\n",
1608 action->type, name);
1611 /* Poisoning to make sure PMDs update it in case of error. */
1612 memset(&error, 0x55, sizeof(error));
1613 memset(&query, 0, sizeof(query));
1614 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1615 return port_flow_complain(&error);
1616 switch (action->type) {
1617 case RTE_FLOW_ACTION_TYPE_COUNT:
1621 " hits: %" PRIu64 "\n"
1622 " bytes: %" PRIu64 "\n",
1624 query.count.hits_set,
1625 query.count.bytes_set,
1630 printf("Cannot display result for action type %d (%s)\n",
1631 action->type, name);
1637 /** List simply and destroy all aged flows. */
1639 port_flow_aged(portid_t port_id, uint8_t destroy)
1642 int nb_context, total = 0, idx;
1643 struct rte_flow_error error;
1644 struct port_flow *pf;
1646 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1647 port_id == (portid_t)RTE_PORT_ALL)
1649 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
1650 printf("Port %u total aged flows: %d\n", port_id, total);
1652 port_flow_complain(&error);
1657 contexts = malloc(sizeof(void *) * total);
1658 if (contexts == NULL) {
1659 printf("Cannot allocate contexts for aged flow\n");
1662 printf("ID\tGroup\tPrio\tAttr\n");
1663 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
1664 if (nb_context != total) {
1665 printf("Port:%d get aged flows count(%d) != total(%d)\n",
1666 port_id, nb_context, total);
1670 for (idx = 0; idx < nb_context; idx++) {
1671 pf = (struct port_flow *)contexts[idx];
1673 printf("Error: get Null context in port %u\n", port_id);
1676 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
1678 pf->rule.attr->group,
1679 pf->rule.attr->priority,
1680 pf->rule.attr->ingress ? 'i' : '-',
1681 pf->rule.attr->egress ? 'e' : '-',
1682 pf->rule.attr->transfer ? 't' : '-');
1690 for (idx = 0; idx < nb_context; idx++) {
1691 pf = (struct port_flow *)contexts[idx];
1695 ret = port_flow_destroy(port_id, 1, &flow_id);
1699 printf("%d flows be destroyed\n", total);
1704 /** List flow rules. */
1706 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1708 struct rte_port *port;
1709 struct port_flow *pf;
1710 struct port_flow *list = NULL;
1713 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1714 port_id == (portid_t)RTE_PORT_ALL)
1716 port = &ports[port_id];
1717 if (!port->flow_list)
1719 /* Sort flows by group, priority and ID. */
1720 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1721 struct port_flow **tmp;
1722 const struct rte_flow_attr *curr = pf->rule.attr;
1725 /* Filter out unwanted groups. */
1726 for (i = 0; i != n; ++i)
1727 if (curr->group == group[i])
1732 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
1733 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
1735 if (curr->group > comp->group ||
1736 (curr->group == comp->group &&
1737 curr->priority > comp->priority) ||
1738 (curr->group == comp->group &&
1739 curr->priority == comp->priority &&
1740 pf->id > (*tmp)->id))
1747 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1748 for (pf = list; pf != NULL; pf = pf->tmp) {
1749 const struct rte_flow_item *item = pf->rule.pattern;
1750 const struct rte_flow_action *action = pf->rule.actions;
1753 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
1755 pf->rule.attr->group,
1756 pf->rule.attr->priority,
1757 pf->rule.attr->ingress ? 'i' : '-',
1758 pf->rule.attr->egress ? 'e' : '-',
1759 pf->rule.attr->transfer ? 't' : '-');
1760 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1761 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
1762 &name, sizeof(name),
1763 (void *)(uintptr_t)item->type,
1766 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1767 printf("%s ", name);
1771 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1772 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1773 &name, sizeof(name),
1774 (void *)(uintptr_t)action->type,
1777 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1778 printf(" %s", name);
1785 /** Restrict ingress traffic to the defined flow rules. */
1787 port_flow_isolate(portid_t port_id, int set)
1789 struct rte_flow_error error;
1791 /* Poisoning to make sure PMDs update it in case of error. */
1792 memset(&error, 0x66, sizeof(error));
1793 if (rte_flow_isolate(port_id, set, &error))
1794 return port_flow_complain(&error);
1795 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1797 set ? "now restricted" : "not restricted anymore");
1802 * RX/TX ring descriptors display functions.
1805 rx_queue_id_is_invalid(queueid_t rxq_id)
1807 if (rxq_id < nb_rxq)
1809 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1814 tx_queue_id_is_invalid(queueid_t txq_id)
1816 if (txq_id < nb_txq)
1818 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1823 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1825 if (rxdesc_id < nb_rxd)
1827 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1833 tx_desc_id_is_invalid(uint16_t txdesc_id)
1835 if (txdesc_id < nb_txd)
1837 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1842 static const struct rte_memzone *
1843 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1845 char mz_name[RTE_MEMZONE_NAMESIZE];
1846 const struct rte_memzone *mz;
1848 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
1849 port_id, q_id, ring_name);
1850 mz = rte_memzone_lookup(mz_name);
1852 printf("%s ring memory zoneof (port %d, queue %d) not"
1853 "found (zone name = %s\n",
1854 ring_name, port_id, q_id, mz_name);
1858 union igb_ring_dword {
1861 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1871 struct igb_ring_desc_32_bytes {
1872 union igb_ring_dword lo_dword;
1873 union igb_ring_dword hi_dword;
1874 union igb_ring_dword resv1;
1875 union igb_ring_dword resv2;
1878 struct igb_ring_desc_16_bytes {
1879 union igb_ring_dword lo_dword;
1880 union igb_ring_dword hi_dword;
1884 ring_rxd_display_dword(union igb_ring_dword dword)
1886 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1887 (unsigned)dword.words.hi);
1891 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1892 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1895 __rte_unused portid_t port_id,
1899 struct igb_ring_desc_16_bytes *ring =
1900 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1901 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1903 struct rte_eth_dev_info dev_info;
1905 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1909 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1910 /* 32 bytes RX descriptor, i40e only */
1911 struct igb_ring_desc_32_bytes *ring =
1912 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1913 ring[desc_id].lo_dword.dword =
1914 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1915 ring_rxd_display_dword(ring[desc_id].lo_dword);
1916 ring[desc_id].hi_dword.dword =
1917 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1918 ring_rxd_display_dword(ring[desc_id].hi_dword);
1919 ring[desc_id].resv1.dword =
1920 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1921 ring_rxd_display_dword(ring[desc_id].resv1);
1922 ring[desc_id].resv2.dword =
1923 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1924 ring_rxd_display_dword(ring[desc_id].resv2);
1929 /* 16 bytes RX descriptor */
1930 ring[desc_id].lo_dword.dword =
1931 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1932 ring_rxd_display_dword(ring[desc_id].lo_dword);
1933 ring[desc_id].hi_dword.dword =
1934 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1935 ring_rxd_display_dword(ring[desc_id].hi_dword);
1939 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1941 struct igb_ring_desc_16_bytes *ring;
1942 struct igb_ring_desc_16_bytes txd;
1944 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1945 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1946 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1947 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1948 (unsigned)txd.lo_dword.words.lo,
1949 (unsigned)txd.lo_dword.words.hi,
1950 (unsigned)txd.hi_dword.words.lo,
1951 (unsigned)txd.hi_dword.words.hi);
1955 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1957 const struct rte_memzone *rx_mz;
1959 if (port_id_is_invalid(port_id, ENABLED_WARN))
1961 if (rx_queue_id_is_invalid(rxq_id))
1963 if (rx_desc_id_is_invalid(rxd_id))
1965 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1968 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1972 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1974 const struct rte_memzone *tx_mz;
1976 if (port_id_is_invalid(port_id, ENABLED_WARN))
1978 if (tx_queue_id_is_invalid(txq_id))
1980 if (tx_desc_id_is_invalid(txd_id))
1982 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1985 ring_tx_descriptor_display(tx_mz, txd_id);
1989 fwd_lcores_config_display(void)
1993 printf("List of forwarding lcores:");
1994 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1995 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1999 rxtx_config_display(void)
2004 printf(" %s packet forwarding%s packets/burst=%d\n",
2005 cur_fwd_eng->fwd_mode_name,
2006 retry_enabled == 0 ? "" : " with retry",
2009 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
2010 printf(" packet len=%u - nb packet segments=%d\n",
2011 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
2013 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
2014 nb_fwd_lcores, nb_fwd_ports);
2016 RTE_ETH_FOREACH_DEV(pid) {
2017 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
2018 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
2019 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
2020 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
2021 uint16_t nb_rx_desc_tmp;
2022 uint16_t nb_tx_desc_tmp;
2023 struct rte_eth_rxq_info rx_qinfo;
2024 struct rte_eth_txq_info tx_qinfo;
2027 /* per port config */
2028 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
2029 (unsigned int)pid, nb_rxq, nb_txq);
2031 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
2032 ports[pid].dev_conf.rxmode.offloads,
2033 ports[pid].dev_conf.txmode.offloads);
2035 /* per rx queue config only for first queue to be less verbose */
2036 for (qid = 0; qid < 1; qid++) {
2037 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
2039 nb_rx_desc_tmp = nb_rx_desc[qid];
2041 nb_rx_desc_tmp = rx_qinfo.nb_desc;
2043 printf(" RX queue: %d\n", qid);
2044 printf(" RX desc=%d - RX free threshold=%d\n",
2045 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh);
2046 printf(" RX threshold registers: pthresh=%d hthresh=%d "
2048 rx_conf[qid].rx_thresh.pthresh,
2049 rx_conf[qid].rx_thresh.hthresh,
2050 rx_conf[qid].rx_thresh.wthresh);
2051 printf(" RX Offloads=0x%"PRIx64"\n",
2052 rx_conf[qid].offloads);
2055 /* per tx queue config only for first queue to be less verbose */
2056 for (qid = 0; qid < 1; qid++) {
2057 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
2059 nb_tx_desc_tmp = nb_tx_desc[qid];
2061 nb_tx_desc_tmp = tx_qinfo.nb_desc;
2063 printf(" TX queue: %d\n", qid);
2064 printf(" TX desc=%d - TX free threshold=%d\n",
2065 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh);
2066 printf(" TX threshold registers: pthresh=%d hthresh=%d "
2068 tx_conf[qid].tx_thresh.pthresh,
2069 tx_conf[qid].tx_thresh.hthresh,
2070 tx_conf[qid].tx_thresh.wthresh);
2071 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
2072 tx_conf[qid].offloads, tx_conf->tx_rs_thresh);
2078 port_rss_reta_info(portid_t port_id,
2079 struct rte_eth_rss_reta_entry64 *reta_conf,
2080 uint16_t nb_entries)
2082 uint16_t i, idx, shift;
2085 if (port_id_is_invalid(port_id, ENABLED_WARN))
2088 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
2090 printf("Failed to get RSS RETA info, return code = %d\n", ret);
2094 for (i = 0; i < nb_entries; i++) {
2095 idx = i / RTE_RETA_GROUP_SIZE;
2096 shift = i % RTE_RETA_GROUP_SIZE;
2097 if (!(reta_conf[idx].mask & (1ULL << shift)))
2099 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
2100 i, reta_conf[idx].reta[shift]);
2105 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
2109 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
2111 struct rte_eth_rss_conf rss_conf = {0};
2112 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
2116 struct rte_eth_dev_info dev_info;
2117 uint8_t hash_key_size;
2120 if (port_id_is_invalid(port_id, ENABLED_WARN))
2123 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2127 if (dev_info.hash_key_size > 0 &&
2128 dev_info.hash_key_size <= sizeof(rss_key))
2129 hash_key_size = dev_info.hash_key_size;
2131 printf("dev_info did not provide a valid hash key size\n");
2135 /* Get RSS hash key if asked to display it */
2136 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2137 rss_conf.rss_key_len = hash_key_size;
2138 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2142 printf("port index %d invalid\n", port_id);
2145 printf("operation not supported by device\n");
2148 printf("operation failed - diag=%d\n", diag);
2153 rss_hf = rss_conf.rss_hf;
2155 printf("RSS disabled\n");
2158 printf("RSS functions:\n ");
2159 for (i = 0; rss_type_table[i].str; i++) {
2160 if (rss_hf & rss_type_table[i].rss_type)
2161 printf("%s ", rss_type_table[i].str);
2166 printf("RSS key:\n");
2167 for (i = 0; i < hash_key_size; i++)
2168 printf("%02X", rss_key[i]);
2173 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2176 struct rte_eth_rss_conf rss_conf;
2180 rss_conf.rss_key = NULL;
2181 rss_conf.rss_key_len = hash_key_len;
2182 rss_conf.rss_hf = 0;
2183 for (i = 0; rss_type_table[i].str; i++) {
2184 if (!strcmp(rss_type_table[i].str, rss_type))
2185 rss_conf.rss_hf = rss_type_table[i].rss_type;
2187 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2189 rss_conf.rss_key = hash_key;
2190 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2197 printf("port index %d invalid\n", port_id);
2200 printf("operation not supported by device\n");
2203 printf("operation failed - diag=%d\n", diag);
2209 * Setup forwarding configuration for each logical core.
2212 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2214 streamid_t nb_fs_per_lcore;
2222 nb_fs = cfg->nb_fwd_streams;
2223 nb_fc = cfg->nb_fwd_lcores;
2224 if (nb_fs <= nb_fc) {
2225 nb_fs_per_lcore = 1;
2228 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2229 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2232 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2234 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2235 fwd_lcores[lc_id]->stream_idx = sm_id;
2236 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2237 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2241 * Assign extra remaining streams, if any.
2243 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2244 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2245 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2246 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2247 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2252 fwd_topology_tx_port_get(portid_t rxp)
2254 static int warning_once = 1;
2256 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2258 switch (port_topology) {
2260 case PORT_TOPOLOGY_PAIRED:
2261 if ((rxp & 0x1) == 0) {
2262 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2265 printf("\nWarning! port-topology=paired"
2266 " and odd forward ports number,"
2267 " the last port will pair with"
2274 case PORT_TOPOLOGY_CHAINED:
2275 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2276 case PORT_TOPOLOGY_LOOP:
2282 simple_fwd_config_setup(void)
2286 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2287 cur_fwd_config.nb_fwd_streams =
2288 (streamid_t) cur_fwd_config.nb_fwd_ports;
2290 /* reinitialize forwarding streams */
2294 * In the simple forwarding test, the number of forwarding cores
2295 * must be lower or equal to the number of forwarding ports.
2297 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2298 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2299 cur_fwd_config.nb_fwd_lcores =
2300 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2301 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2303 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2304 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2305 fwd_streams[i]->rx_queue = 0;
2306 fwd_streams[i]->tx_port =
2307 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2308 fwd_streams[i]->tx_queue = 0;
2309 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2310 fwd_streams[i]->retry_enabled = retry_enabled;
2315 * For the RSS forwarding test all streams distributed over lcores. Each stream
2316 * being composed of a RX queue to poll on a RX port for input messages,
2317 * associated with a TX queue of a TX port where to send forwarded packets.
2320 rss_fwd_config_setup(void)
2331 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2332 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2333 cur_fwd_config.nb_fwd_streams =
2334 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2336 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2337 cur_fwd_config.nb_fwd_lcores =
2338 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2340 /* reinitialize forwarding streams */
2343 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2345 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2346 struct fwd_stream *fs;
2348 fs = fwd_streams[sm_id];
2349 txp = fwd_topology_tx_port_get(rxp);
2350 fs->rx_port = fwd_ports_ids[rxp];
2352 fs->tx_port = fwd_ports_ids[txp];
2354 fs->peer_addr = fs->tx_port;
2355 fs->retry_enabled = retry_enabled;
2357 if (rxp < nb_fwd_ports)
2365 * For the DCB forwarding test, each core is assigned on each traffic class.
2367 * Each core is assigned a multi-stream, each stream being composed of
2368 * a RX queue to poll on a RX port for input messages, associated with
2369 * a TX queue of a TX port where to send forwarded packets. All RX and
2370 * TX queues are mapping to the same traffic class.
2371 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2375 dcb_fwd_config_setup(void)
2377 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2378 portid_t txp, rxp = 0;
2379 queueid_t txq, rxq = 0;
2381 uint16_t nb_rx_queue, nb_tx_queue;
2382 uint16_t i, j, k, sm_id = 0;
2385 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2386 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2387 cur_fwd_config.nb_fwd_streams =
2388 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2390 /* reinitialize forwarding streams */
2394 /* get the dcb info on the first RX and TX ports */
2395 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2396 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2398 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2399 fwd_lcores[lc_id]->stream_nb = 0;
2400 fwd_lcores[lc_id]->stream_idx = sm_id;
2401 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2402 /* if the nb_queue is zero, means this tc is
2403 * not enabled on the POOL
2405 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2407 k = fwd_lcores[lc_id]->stream_nb +
2408 fwd_lcores[lc_id]->stream_idx;
2409 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2410 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2411 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2412 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2413 for (j = 0; j < nb_rx_queue; j++) {
2414 struct fwd_stream *fs;
2416 fs = fwd_streams[k + j];
2417 fs->rx_port = fwd_ports_ids[rxp];
2418 fs->rx_queue = rxq + j;
2419 fs->tx_port = fwd_ports_ids[txp];
2420 fs->tx_queue = txq + j % nb_tx_queue;
2421 fs->peer_addr = fs->tx_port;
2422 fs->retry_enabled = retry_enabled;
2424 fwd_lcores[lc_id]->stream_nb +=
2425 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2427 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2430 if (tc < rxp_dcb_info.nb_tcs)
2432 /* Restart from TC 0 on next RX port */
2434 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2436 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2439 if (rxp >= nb_fwd_ports)
2441 /* get the dcb information on next RX and TX ports */
2442 if ((rxp & 0x1) == 0)
2443 txp = (portid_t) (rxp + 1);
2445 txp = (portid_t) (rxp - 1);
2446 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2447 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2452 icmp_echo_config_setup(void)
2459 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2460 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2461 (nb_txq * nb_fwd_ports);
2463 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2464 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2465 cur_fwd_config.nb_fwd_streams =
2466 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2467 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2468 cur_fwd_config.nb_fwd_lcores =
2469 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2470 if (verbose_level > 0) {
2471 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2473 cur_fwd_config.nb_fwd_lcores,
2474 cur_fwd_config.nb_fwd_ports,
2475 cur_fwd_config.nb_fwd_streams);
2478 /* reinitialize forwarding streams */
2480 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2482 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2483 if (verbose_level > 0)
2484 printf(" core=%d: \n", lc_id);
2485 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2486 struct fwd_stream *fs;
2487 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2488 fs->rx_port = fwd_ports_ids[rxp];
2490 fs->tx_port = fs->rx_port;
2492 fs->peer_addr = fs->tx_port;
2493 fs->retry_enabled = retry_enabled;
2494 if (verbose_level > 0)
2495 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2496 sm_id, fs->rx_port, fs->rx_queue,
2498 rxq = (queueid_t) (rxq + 1);
2499 if (rxq == nb_rxq) {
2501 rxp = (portid_t) (rxp + 1);
2507 #if defined RTE_LIBRTE_PMD_SOFTNIC
2509 softnic_fwd_config_setup(void)
2511 struct rte_port *port;
2512 portid_t pid, softnic_portid;
2514 uint8_t softnic_enable = 0;
2516 RTE_ETH_FOREACH_DEV(pid) {
2518 const char *driver = port->dev_info.driver_name;
2520 if (strcmp(driver, "net_softnic") == 0) {
2521 softnic_portid = pid;
2527 if (softnic_enable == 0) {
2528 printf("Softnic mode not configured(%s)!\n", __func__);
2532 cur_fwd_config.nb_fwd_ports = 1;
2533 cur_fwd_config.nb_fwd_streams = (streamid_t) nb_rxq;
2535 /* Re-initialize forwarding streams */
2539 * In the softnic forwarding test, the number of forwarding cores
2540 * is set to one and remaining are used for softnic packet processing.
2542 cur_fwd_config.nb_fwd_lcores = 1;
2543 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2545 for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++) {
2546 fwd_streams[i]->rx_port = softnic_portid;
2547 fwd_streams[i]->rx_queue = i;
2548 fwd_streams[i]->tx_port = softnic_portid;
2549 fwd_streams[i]->tx_queue = i;
2550 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2551 fwd_streams[i]->retry_enabled = retry_enabled;
2557 fwd_config_setup(void)
2559 cur_fwd_config.fwd_eng = cur_fwd_eng;
2560 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2561 icmp_echo_config_setup();
2565 #if defined RTE_LIBRTE_PMD_SOFTNIC
2566 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
2567 softnic_fwd_config_setup();
2572 if ((nb_rxq > 1) && (nb_txq > 1)){
2574 dcb_fwd_config_setup();
2576 rss_fwd_config_setup();
2579 simple_fwd_config_setup();
2583 mp_alloc_to_str(uint8_t mode)
2586 case MP_ALLOC_NATIVE:
2592 case MP_ALLOC_XMEM_HUGE:
2602 pkt_fwd_config_display(struct fwd_config *cfg)
2604 struct fwd_stream *fs;
2608 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2609 "NUMA support %s, MP allocation mode: %s\n",
2610 cfg->fwd_eng->fwd_mode_name,
2611 retry_enabled == 0 ? "" : " with retry",
2612 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2613 numa_support == 1 ? "enabled" : "disabled",
2614 mp_alloc_to_str(mp_alloc_type));
2617 printf("TX retry num: %u, delay between TX retries: %uus\n",
2618 burst_tx_retry_num, burst_tx_delay_time);
2619 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2620 printf("Logical Core %u (socket %u) forwards packets on "
2622 fwd_lcores_cpuids[lc_id],
2623 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2624 fwd_lcores[lc_id]->stream_nb);
2625 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2626 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2627 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2628 "P=%d/Q=%d (socket %u) ",
2629 fs->rx_port, fs->rx_queue,
2630 ports[fs->rx_port].socket_id,
2631 fs->tx_port, fs->tx_queue,
2632 ports[fs->tx_port].socket_id);
2633 print_ethaddr("peer=",
2634 &peer_eth_addrs[fs->peer_addr]);
2642 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2644 struct rte_ether_addr new_peer_addr;
2645 if (!rte_eth_dev_is_valid_port(port_id)) {
2646 printf("Error: Invalid port number %i\n", port_id);
2649 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
2650 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2653 peer_eth_addrs[port_id] = new_peer_addr;
2657 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2660 unsigned int lcore_cpuid;
2665 for (i = 0; i < nb_lc; i++) {
2666 lcore_cpuid = lcorelist[i];
2667 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2668 printf("lcore %u not enabled\n", lcore_cpuid);
2671 if (lcore_cpuid == rte_get_master_lcore()) {
2672 printf("lcore %u cannot be masked on for running "
2673 "packet forwarding, which is the master lcore "
2674 "and reserved for command line parsing only\n",
2679 fwd_lcores_cpuids[i] = lcore_cpuid;
2681 if (record_now == 0) {
2685 nb_cfg_lcores = (lcoreid_t) nb_lc;
2686 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2687 printf("previous number of forwarding cores %u - changed to "
2688 "number of configured cores %u\n",
2689 (unsigned int) nb_fwd_lcores, nb_lc);
2690 nb_fwd_lcores = (lcoreid_t) nb_lc;
2697 set_fwd_lcores_mask(uint64_t lcoremask)
2699 unsigned int lcorelist[64];
2703 if (lcoremask == 0) {
2704 printf("Invalid NULL mask of cores\n");
2708 for (i = 0; i < 64; i++) {
2709 if (! ((uint64_t)(1ULL << i) & lcoremask))
2711 lcorelist[nb_lc++] = i;
2713 return set_fwd_lcores_list(lcorelist, nb_lc);
2717 set_fwd_lcores_number(uint16_t nb_lc)
2719 if (nb_lc > nb_cfg_lcores) {
2720 printf("nb fwd cores %u > %u (max. number of configured "
2721 "lcores) - ignored\n",
2722 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2725 nb_fwd_lcores = (lcoreid_t) nb_lc;
2726 printf("Number of forwarding cores set to %u\n",
2727 (unsigned int) nb_fwd_lcores);
2731 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2739 for (i = 0; i < nb_pt; i++) {
2740 port_id = (portid_t) portlist[i];
2741 if (port_id_is_invalid(port_id, ENABLED_WARN))
2744 fwd_ports_ids[i] = port_id;
2746 if (record_now == 0) {
2750 nb_cfg_ports = (portid_t) nb_pt;
2751 if (nb_fwd_ports != (portid_t) nb_pt) {
2752 printf("previous number of forwarding ports %u - changed to "
2753 "number of configured ports %u\n",
2754 (unsigned int) nb_fwd_ports, nb_pt);
2755 nb_fwd_ports = (portid_t) nb_pt;
2760 * Parse the user input and obtain the list of forwarding ports
2763 * String containing the user input. User can specify
2764 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
2765 * For example, if the user wants to use all the available
2766 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
2767 * If the user wants to use only the ports 1,2 then the input
2769 * valid characters are '-' and ','
2770 * @param[out] values
2771 * This array will be filled with a list of port IDs
2772 * based on the user input
2773 * Note that duplicate entries are discarded and only the first
2774 * count entries in this array are port IDs and all the rest
2775 * will contain default values
2776 * @param[in] maxsize
2777 * This parameter denotes 2 things
2778 * 1) Number of elements in the values array
2779 * 2) Maximum value of each element in the values array
2781 * On success, returns total count of parsed port IDs
2782 * On failure, returns 0
2785 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
2787 unsigned int count = 0;
2791 unsigned int marked[maxsize];
2793 if (list == NULL || values == NULL)
2796 for (i = 0; i < (int)maxsize; i++)
2802 /*Remove the blank spaces if any*/
2803 while (isblank(*list))
2808 value = strtol(list, &end, 10);
2809 if (errno || end == NULL)
2811 if (value < 0 || value >= (int)maxsize)
2813 while (isblank(*end))
2815 if (*end == '-' && min == INT_MAX) {
2817 } else if ((*end == ',') || (*end == '\0')) {
2821 for (i = min; i <= max; i++) {
2822 if (count < maxsize) {
2834 } while (*end != '\0');
2840 parse_fwd_portlist(const char *portlist)
2842 unsigned int portcount;
2843 unsigned int portindex[RTE_MAX_ETHPORTS];
2844 unsigned int i, valid_port_count = 0;
2846 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
2848 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
2851 * Here we verify the validity of the ports
2852 * and thereby calculate the total number of
2855 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
2856 if (rte_eth_dev_is_valid_port(portindex[i])) {
2857 portindex[valid_port_count] = portindex[i];
2862 set_fwd_ports_list(portindex, valid_port_count);
2866 set_fwd_ports_mask(uint64_t portmask)
2868 unsigned int portlist[64];
2872 if (portmask == 0) {
2873 printf("Invalid NULL mask of ports\n");
2877 RTE_ETH_FOREACH_DEV(i) {
2878 if (! ((uint64_t)(1ULL << i) & portmask))
2880 portlist[nb_pt++] = i;
2882 set_fwd_ports_list(portlist, nb_pt);
2886 set_fwd_ports_number(uint16_t nb_pt)
2888 if (nb_pt > nb_cfg_ports) {
2889 printf("nb fwd ports %u > %u (number of configured "
2890 "ports) - ignored\n",
2891 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2894 nb_fwd_ports = (portid_t) nb_pt;
2895 printf("Number of forwarding ports set to %u\n",
2896 (unsigned int) nb_fwd_ports);
2900 port_is_forwarding(portid_t port_id)
2904 if (port_id_is_invalid(port_id, ENABLED_WARN))
2907 for (i = 0; i < nb_fwd_ports; i++) {
2908 if (fwd_ports_ids[i] == port_id)
2916 set_nb_pkt_per_burst(uint16_t nb)
2918 if (nb > MAX_PKT_BURST) {
2919 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2921 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2924 nb_pkt_per_burst = nb;
2925 printf("Number of packets per burst set to %u\n",
2926 (unsigned int) nb_pkt_per_burst);
2930 tx_split_get_name(enum tx_pkt_split split)
2934 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2935 if (tx_split_name[i].split == split)
2936 return tx_split_name[i].name;
2942 set_tx_pkt_split(const char *name)
2946 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2947 if (strcmp(tx_split_name[i].name, name) == 0) {
2948 tx_pkt_split = tx_split_name[i].split;
2952 printf("unknown value: \"%s\"\n", name);
2956 show_tx_pkt_segments(void)
2962 split = tx_split_get_name(tx_pkt_split);
2964 printf("Number of segments: %u\n", n);
2965 printf("Segment sizes: ");
2966 for (i = 0; i != n - 1; i++)
2967 printf("%hu,", tx_pkt_seg_lengths[i]);
2968 printf("%hu\n", tx_pkt_seg_lengths[i]);
2969 printf("Split packet: %s\n", split);
2973 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2975 uint16_t tx_pkt_len;
2978 if (nb_segs >= (unsigned) nb_txd) {
2979 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2980 nb_segs, (unsigned int) nb_txd);
2985 * Check that each segment length is greater or equal than
2986 * the mbuf data sise.
2987 * Check also that the total packet length is greater or equal than the
2988 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
2992 for (i = 0; i < nb_segs; i++) {
2993 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2994 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2995 i, seg_lengths[i], (unsigned) mbuf_data_size);
2998 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
3000 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
3001 printf("total packet length=%u < %d - give up\n",
3002 (unsigned) tx_pkt_len,
3003 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
3007 for (i = 0; i < nb_segs; i++)
3008 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3010 tx_pkt_length = tx_pkt_len;
3011 tx_pkt_nb_segs = (uint8_t) nb_segs;
3015 setup_gro(const char *onoff, portid_t port_id)
3017 if (!rte_eth_dev_is_valid_port(port_id)) {
3018 printf("invalid port id %u\n", port_id);
3021 if (test_done == 0) {
3022 printf("Before enable/disable GRO,"
3023 " please stop forwarding first\n");
3026 if (strcmp(onoff, "on") == 0) {
3027 if (gro_ports[port_id].enable != 0) {
3028 printf("Port %u has enabled GRO. Please"
3029 " disable GRO first\n", port_id);
3032 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3033 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
3034 gro_ports[port_id].param.max_flow_num =
3035 GRO_DEFAULT_FLOW_NUM;
3036 gro_ports[port_id].param.max_item_per_flow =
3037 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
3039 gro_ports[port_id].enable = 1;
3041 if (gro_ports[port_id].enable == 0) {
3042 printf("Port %u has disabled GRO\n", port_id);
3045 gro_ports[port_id].enable = 0;
3050 setup_gro_flush_cycles(uint8_t cycles)
3052 if (test_done == 0) {
3053 printf("Before change flush interval for GRO,"
3054 " please stop forwarding first.\n");
3058 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
3059 GRO_DEFAULT_FLUSH_CYCLES) {
3060 printf("The flushing cycle be in the range"
3061 " of 1 to %u. Revert to the default"
3063 GRO_MAX_FLUSH_CYCLES,
3064 GRO_DEFAULT_FLUSH_CYCLES);
3065 cycles = GRO_DEFAULT_FLUSH_CYCLES;
3068 gro_flush_cycles = cycles;
3072 show_gro(portid_t port_id)
3074 struct rte_gro_param *param;
3075 uint32_t max_pkts_num;
3077 param = &gro_ports[port_id].param;
3079 if (!rte_eth_dev_is_valid_port(port_id)) {
3080 printf("Invalid port id %u.\n", port_id);
3083 if (gro_ports[port_id].enable) {
3084 printf("GRO type: TCP/IPv4\n");
3085 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3086 max_pkts_num = param->max_flow_num *
3087 param->max_item_per_flow;
3089 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
3090 printf("Max number of packets to perform GRO: %u\n",
3092 printf("Flushing cycles: %u\n", gro_flush_cycles);
3094 printf("Port %u doesn't enable GRO.\n", port_id);
3098 setup_gso(const char *mode, portid_t port_id)
3100 if (!rte_eth_dev_is_valid_port(port_id)) {
3101 printf("invalid port id %u\n", port_id);
3104 if (strcmp(mode, "on") == 0) {
3105 if (test_done == 0) {
3106 printf("before enabling GSO,"
3107 " please stop forwarding first\n");
3110 gso_ports[port_id].enable = 1;
3111 } else if (strcmp(mode, "off") == 0) {
3112 if (test_done == 0) {
3113 printf("before disabling GSO,"
3114 " please stop forwarding first\n");
3117 gso_ports[port_id].enable = 0;
3122 list_pkt_forwarding_modes(void)
3124 static char fwd_modes[128] = "";
3125 const char *separator = "|";
3126 struct fwd_engine *fwd_eng;
3129 if (strlen (fwd_modes) == 0) {
3130 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3131 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3132 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3133 strncat(fwd_modes, separator,
3134 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3136 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3143 list_pkt_forwarding_retry_modes(void)
3145 static char fwd_modes[128] = "";
3146 const char *separator = "|";
3147 struct fwd_engine *fwd_eng;
3150 if (strlen(fwd_modes) == 0) {
3151 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3152 if (fwd_eng == &rx_only_engine)
3154 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3156 strlen(fwd_modes) - 1);
3157 strncat(fwd_modes, separator,
3159 strlen(fwd_modes) - 1);
3161 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3168 set_pkt_forwarding_mode(const char *fwd_mode_name)
3170 struct fwd_engine *fwd_eng;
3174 while ((fwd_eng = fwd_engines[i]) != NULL) {
3175 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
3176 printf("Set %s packet forwarding mode%s\n",
3178 retry_enabled == 0 ? "" : " with retry");
3179 cur_fwd_eng = fwd_eng;
3184 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
3188 add_rx_dump_callbacks(portid_t portid)
3190 struct rte_eth_dev_info dev_info;
3194 if (port_id_is_invalid(portid, ENABLED_WARN))
3197 ret = eth_dev_info_get_print_err(portid, &dev_info);
3201 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3202 if (!ports[portid].rx_dump_cb[queue])
3203 ports[portid].rx_dump_cb[queue] =
3204 rte_eth_add_rx_callback(portid, queue,
3205 dump_rx_pkts, NULL);
3209 add_tx_dump_callbacks(portid_t portid)
3211 struct rte_eth_dev_info dev_info;
3215 if (port_id_is_invalid(portid, ENABLED_WARN))
3218 ret = eth_dev_info_get_print_err(portid, &dev_info);
3222 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3223 if (!ports[portid].tx_dump_cb[queue])
3224 ports[portid].tx_dump_cb[queue] =
3225 rte_eth_add_tx_callback(portid, queue,
3226 dump_tx_pkts, NULL);
3230 remove_rx_dump_callbacks(portid_t portid)
3232 struct rte_eth_dev_info dev_info;
3236 if (port_id_is_invalid(portid, ENABLED_WARN))
3239 ret = eth_dev_info_get_print_err(portid, &dev_info);
3243 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3244 if (ports[portid].rx_dump_cb[queue]) {
3245 rte_eth_remove_rx_callback(portid, queue,
3246 ports[portid].rx_dump_cb[queue]);
3247 ports[portid].rx_dump_cb[queue] = NULL;
3252 remove_tx_dump_callbacks(portid_t portid)
3254 struct rte_eth_dev_info dev_info;
3258 if (port_id_is_invalid(portid, ENABLED_WARN))
3261 ret = eth_dev_info_get_print_err(portid, &dev_info);
3265 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3266 if (ports[portid].tx_dump_cb[queue]) {
3267 rte_eth_remove_tx_callback(portid, queue,
3268 ports[portid].tx_dump_cb[queue]);
3269 ports[portid].tx_dump_cb[queue] = NULL;
3274 configure_rxtx_dump_callbacks(uint16_t verbose)
3278 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3279 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
3283 RTE_ETH_FOREACH_DEV(portid)
3285 if (verbose == 1 || verbose > 2)
3286 add_rx_dump_callbacks(portid);
3288 remove_rx_dump_callbacks(portid);
3290 add_tx_dump_callbacks(portid);
3292 remove_tx_dump_callbacks(portid);
3297 set_verbose_level(uint16_t vb_level)
3299 printf("Change verbose level from %u to %u\n",
3300 (unsigned int) verbose_level, (unsigned int) vb_level);
3301 verbose_level = vb_level;
3302 configure_rxtx_dump_callbacks(verbose_level);
3306 vlan_extend_set(portid_t port_id, int on)
3310 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3312 if (port_id_is_invalid(port_id, ENABLED_WARN))
3315 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3318 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
3319 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3321 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
3322 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3325 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3327 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
3328 "diag=%d\n", port_id, on, diag);
3329 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3333 rx_vlan_strip_set(portid_t port_id, int on)
3337 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3339 if (port_id_is_invalid(port_id, ENABLED_WARN))
3342 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3345 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
3346 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3348 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
3349 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3352 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3354 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
3355 "diag=%d\n", port_id, on, diag);
3356 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3360 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
3364 if (port_id_is_invalid(port_id, ENABLED_WARN))
3367 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
3369 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
3370 "diag=%d\n", port_id, queue_id, on, diag);
3374 rx_vlan_filter_set(portid_t port_id, int on)
3378 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3380 if (port_id_is_invalid(port_id, ENABLED_WARN))
3383 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3386 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
3387 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3389 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
3390 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3393 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3395 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
3396 "diag=%d\n", port_id, on, diag);
3397 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3401 rx_vlan_qinq_strip_set(portid_t port_id, int on)
3405 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3407 if (port_id_is_invalid(port_id, ENABLED_WARN))
3410 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3413 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
3414 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3416 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
3417 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3420 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3422 printf("%s(port_pi=%d, on=%d) failed "
3423 "diag=%d\n", __func__, port_id, on, diag);
3424 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3428 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
3432 if (port_id_is_invalid(port_id, ENABLED_WARN))
3434 if (vlan_id_is_invalid(vlan_id))
3436 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
3439 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
3441 port_id, vlan_id, on, diag);
3446 rx_vlan_all_filter_set(portid_t port_id, int on)
3450 if (port_id_is_invalid(port_id, ENABLED_WARN))
3452 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
3453 if (rx_vft_set(port_id, vlan_id, on))
3459 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
3463 if (port_id_is_invalid(port_id, ENABLED_WARN))
3466 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
3470 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
3472 port_id, vlan_type, tp_id, diag);
3476 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
3478 struct rte_eth_dev_info dev_info;
3481 if (port_id_is_invalid(port_id, ENABLED_WARN))
3483 if (vlan_id_is_invalid(vlan_id))
3486 if (ports[port_id].dev_conf.txmode.offloads &
3487 DEV_TX_OFFLOAD_QINQ_INSERT) {
3488 printf("Error, as QinQ has been enabled.\n");
3492 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3496 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
3497 printf("Error: vlan insert is not supported by port %d\n",
3502 tx_vlan_reset(port_id);
3503 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
3504 ports[port_id].tx_vlan_id = vlan_id;
3508 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
3510 struct rte_eth_dev_info dev_info;
3513 if (port_id_is_invalid(port_id, ENABLED_WARN))
3515 if (vlan_id_is_invalid(vlan_id))
3517 if (vlan_id_is_invalid(vlan_id_outer))
3520 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3524 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
3525 printf("Error: qinq insert not supported by port %d\n",
3530 tx_vlan_reset(port_id);
3531 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
3532 DEV_TX_OFFLOAD_QINQ_INSERT);
3533 ports[port_id].tx_vlan_id = vlan_id;
3534 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
3538 tx_vlan_reset(portid_t port_id)
3540 if (port_id_is_invalid(port_id, ENABLED_WARN))
3542 ports[port_id].dev_conf.txmode.offloads &=
3543 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
3544 DEV_TX_OFFLOAD_QINQ_INSERT);
3545 ports[port_id].tx_vlan_id = 0;
3546 ports[port_id].tx_vlan_id_outer = 0;
3550 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
3552 if (port_id_is_invalid(port_id, ENABLED_WARN))
3555 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
3559 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
3562 uint8_t existing_mapping_found = 0;
3564 if (port_id_is_invalid(port_id, ENABLED_WARN))
3567 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
3570 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
3571 printf("map_value not in required range 0..%d\n",
3572 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
3576 if (!is_rx) { /*then tx*/
3577 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3578 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3579 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
3580 tx_queue_stats_mappings[i].stats_counter_id = map_value;
3581 existing_mapping_found = 1;
3585 if (!existing_mapping_found) { /* A new additional mapping... */
3586 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
3587 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
3588 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
3589 nb_tx_queue_stats_mappings++;
3593 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3594 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3595 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
3596 rx_queue_stats_mappings[i].stats_counter_id = map_value;
3597 existing_mapping_found = 1;
3601 if (!existing_mapping_found) { /* A new additional mapping... */
3602 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
3603 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
3604 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
3605 nb_rx_queue_stats_mappings++;
3611 set_xstats_hide_zero(uint8_t on_off)
3613 xstats_hide_zero = on_off;
3617 print_fdir_mask(struct rte_eth_fdir_masks *mask)
3619 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
3621 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3622 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
3623 " tunnel_id: 0x%08x",
3624 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
3625 rte_be_to_cpu_32(mask->tunnel_id_mask));
3626 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3627 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
3628 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
3629 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
3631 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
3632 rte_be_to_cpu_16(mask->src_port_mask),
3633 rte_be_to_cpu_16(mask->dst_port_mask));
3635 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3636 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
3637 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3638 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3639 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3641 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3642 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3643 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3644 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3645 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3652 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3654 struct rte_eth_flex_payload_cfg *cfg;
3657 for (i = 0; i < flex_conf->nb_payloads; i++) {
3658 cfg = &flex_conf->flex_set[i];
3659 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3661 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3662 printf("\n L2_PAYLOAD: ");
3663 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3664 printf("\n L3_PAYLOAD: ");
3665 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3666 printf("\n L4_PAYLOAD: ");
3668 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3669 for (j = 0; j < num; j++)
3670 printf(" %-5u", cfg->src_offset[j]);
3676 flowtype_to_str(uint16_t flow_type)
3678 struct flow_type_info {
3684 static struct flow_type_info flowtype_str_table[] = {
3685 {"raw", RTE_ETH_FLOW_RAW},
3686 {"ipv4", RTE_ETH_FLOW_IPV4},
3687 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3688 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3689 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3690 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3691 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3692 {"ipv6", RTE_ETH_FLOW_IPV6},
3693 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3694 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3695 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3696 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3697 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3698 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3699 {"port", RTE_ETH_FLOW_PORT},
3700 {"vxlan", RTE_ETH_FLOW_VXLAN},
3701 {"geneve", RTE_ETH_FLOW_GENEVE},
3702 {"nvgre", RTE_ETH_FLOW_NVGRE},
3703 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
3706 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3707 if (flowtype_str_table[i].ftype == flow_type)
3708 return flowtype_str_table[i].str;
3715 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3717 struct rte_eth_fdir_flex_mask *mask;
3721 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3722 mask = &flex_conf->flex_mask[i];
3723 p = flowtype_to_str(mask->flow_type);
3724 printf("\n %s:\t", p ? p : "unknown");
3725 for (j = 0; j < num; j++)
3726 printf(" %02x", mask->mask[j]);
3732 print_fdir_flow_type(uint32_t flow_types_mask)
3737 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3738 if (!(flow_types_mask & (1 << i)))
3740 p = flowtype_to_str(i);
3750 fdir_get_infos(portid_t port_id)
3752 struct rte_eth_fdir_stats fdir_stat;
3753 struct rte_eth_fdir_info fdir_info;
3756 static const char *fdir_stats_border = "########################";
3758 if (port_id_is_invalid(port_id, ENABLED_WARN))
3760 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3762 printf("\n FDIR is not supported on port %-2d\n",
3767 memset(&fdir_info, 0, sizeof(fdir_info));
3768 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3769 RTE_ETH_FILTER_INFO, &fdir_info);
3770 memset(&fdir_stat, 0, sizeof(fdir_stat));
3771 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3772 RTE_ETH_FILTER_STATS, &fdir_stat);
3773 printf("\n %s FDIR infos for port %-2d %s\n",
3774 fdir_stats_border, port_id, fdir_stats_border);
3776 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3777 printf(" PERFECT\n");
3778 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3779 printf(" PERFECT-MAC-VLAN\n");
3780 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3781 printf(" PERFECT-TUNNEL\n");
3782 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3783 printf(" SIGNATURE\n");
3785 printf(" DISABLE\n");
3786 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3787 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3788 printf(" SUPPORTED FLOW TYPE: ");
3789 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3791 printf(" FLEX PAYLOAD INFO:\n");
3792 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3793 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3794 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3795 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3796 fdir_info.flex_payload_unit,
3797 fdir_info.max_flex_payload_segment_num,
3798 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3800 print_fdir_mask(&fdir_info.mask);
3801 if (fdir_info.flex_conf.nb_payloads > 0) {
3802 printf(" FLEX PAYLOAD SRC OFFSET:");
3803 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3805 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3806 printf(" FLEX MASK CFG:");
3807 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3809 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3810 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3811 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3812 fdir_info.guarant_spc, fdir_info.best_spc);
3813 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3814 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3815 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3816 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3817 fdir_stat.collision, fdir_stat.free,
3818 fdir_stat.maxhash, fdir_stat.maxlen,
3819 fdir_stat.add, fdir_stat.remove,
3820 fdir_stat.f_add, fdir_stat.f_remove);
3821 printf(" %s############################%s\n",
3822 fdir_stats_border, fdir_stats_border);
3826 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3828 struct rte_port *port;
3829 struct rte_eth_fdir_flex_conf *flex_conf;
3832 port = &ports[port_id];
3833 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3834 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3835 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3840 if (i >= RTE_ETH_FLOW_MAX) {
3841 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3842 idx = flex_conf->nb_flexmasks;
3843 flex_conf->nb_flexmasks++;
3845 printf("The flex mask table is full. Can not set flex"
3846 " mask for flow_type(%u).", cfg->flow_type);
3850 rte_memcpy(&flex_conf->flex_mask[idx],
3852 sizeof(struct rte_eth_fdir_flex_mask));
3856 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3858 struct rte_port *port;
3859 struct rte_eth_fdir_flex_conf *flex_conf;
3862 port = &ports[port_id];
3863 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3864 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3865 if (cfg->type == flex_conf->flex_set[i].type) {
3870 if (i >= RTE_ETH_PAYLOAD_MAX) {
3871 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3872 idx = flex_conf->nb_payloads;
3873 flex_conf->nb_payloads++;
3875 printf("The flex payload table is full. Can not set"
3876 " flex payload for type(%u).", cfg->type);
3880 rte_memcpy(&flex_conf->flex_set[idx],
3882 sizeof(struct rte_eth_flex_payload_cfg));
3887 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3889 #ifdef RTE_LIBRTE_IXGBE_PMD
3893 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3895 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3899 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3900 is_rx ? "rx" : "tx", port_id, diag);
3903 printf("VF %s setting not supported for port %d\n",
3904 is_rx ? "Rx" : "Tx", port_id);
3910 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3913 struct rte_eth_link link;
3916 if (port_id_is_invalid(port_id, ENABLED_WARN))
3918 ret = eth_link_get_nowait_print_err(port_id, &link);
3921 if (rate > link.link_speed) {
3922 printf("Invalid rate value:%u bigger than link speed: %u\n",
3923 rate, link.link_speed);
3926 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3929 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3935 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3937 int diag = -ENOTSUP;
3941 RTE_SET_USED(q_msk);
3943 #ifdef RTE_LIBRTE_IXGBE_PMD
3944 if (diag == -ENOTSUP)
3945 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3948 #ifdef RTE_LIBRTE_BNXT_PMD
3949 if (diag == -ENOTSUP)
3950 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3955 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3961 * Functions to manage the set of filtered Multicast MAC addresses.
3963 * A pool of filtered multicast MAC addresses is associated with each port.
3964 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3965 * The address of the pool and the number of valid multicast MAC addresses
3966 * recorded in the pool are stored in the fields "mc_addr_pool" and
3967 * "mc_addr_nb" of the "rte_port" data structure.
3969 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3970 * to be supplied a contiguous array of multicast MAC addresses.
3971 * To comply with this constraint, the set of multicast addresses recorded
3972 * into the pool are systematically compacted at the beginning of the pool.
3973 * Hence, when a multicast address is removed from the pool, all following
3974 * addresses, if any, are copied back to keep the set contiguous.
3976 #define MCAST_POOL_INC 32
3979 mcast_addr_pool_extend(struct rte_port *port)
3981 struct rte_ether_addr *mc_pool;
3982 size_t mc_pool_size;
3985 * If a free entry is available at the end of the pool, just
3986 * increment the number of recorded multicast addresses.
3988 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3994 * [re]allocate a pool with MCAST_POOL_INC more entries.
3995 * The previous test guarantees that port->mc_addr_nb is a multiple
3996 * of MCAST_POOL_INC.
3998 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
4000 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
4002 if (mc_pool == NULL) {
4003 printf("allocation of pool of %u multicast addresses failed\n",
4004 port->mc_addr_nb + MCAST_POOL_INC);
4008 port->mc_addr_pool = mc_pool;
4015 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
4017 if (mcast_addr_pool_extend(port) != 0)
4019 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
4023 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
4026 if (addr_idx == port->mc_addr_nb) {
4027 /* No need to recompact the set of multicast addressses. */
4028 if (port->mc_addr_nb == 0) {
4029 /* free the pool of multicast addresses. */
4030 free(port->mc_addr_pool);
4031 port->mc_addr_pool = NULL;
4035 memmove(&port->mc_addr_pool[addr_idx],
4036 &port->mc_addr_pool[addr_idx + 1],
4037 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
4041 eth_port_multicast_addr_list_set(portid_t port_id)
4043 struct rte_port *port;
4046 port = &ports[port_id];
4047 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
4050 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
4051 port_id, port->mc_addr_nb, diag);
4057 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
4059 struct rte_port *port;
4062 if (port_id_is_invalid(port_id, ENABLED_WARN))
4065 port = &ports[port_id];
4068 * Check that the added multicast MAC address is not already recorded
4069 * in the pool of multicast addresses.
4071 for (i = 0; i < port->mc_addr_nb; i++) {
4072 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
4073 printf("multicast address already filtered by port\n");
4078 mcast_addr_pool_append(port, mc_addr);
4079 if (eth_port_multicast_addr_list_set(port_id) < 0)
4080 /* Rollback on failure, remove the address from the pool */
4081 mcast_addr_pool_remove(port, i);
4085 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
4087 struct rte_port *port;
4090 if (port_id_is_invalid(port_id, ENABLED_WARN))
4093 port = &ports[port_id];
4096 * Search the pool of multicast MAC addresses for the removed address.
4098 for (i = 0; i < port->mc_addr_nb; i++) {
4099 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
4102 if (i == port->mc_addr_nb) {
4103 printf("multicast address not filtered by port %d\n", port_id);
4107 mcast_addr_pool_remove(port, i);
4108 if (eth_port_multicast_addr_list_set(port_id) < 0)
4109 /* Rollback on failure, add the address back into the pool */
4110 mcast_addr_pool_append(port, mc_addr);
4114 port_dcb_info_display(portid_t port_id)
4116 struct rte_eth_dcb_info dcb_info;
4119 static const char *border = "================";
4121 if (port_id_is_invalid(port_id, ENABLED_WARN))
4124 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
4126 printf("\n Failed to get dcb infos on port %-2d\n",
4130 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
4131 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
4133 for (i = 0; i < dcb_info.nb_tcs; i++)
4135 printf("\n Priority : ");
4136 for (i = 0; i < dcb_info.nb_tcs; i++)
4137 printf("\t%4d", dcb_info.prio_tc[i]);
4138 printf("\n BW percent :");
4139 for (i = 0; i < dcb_info.nb_tcs; i++)
4140 printf("\t%4d%%", dcb_info.tc_bws[i]);
4141 printf("\n RXQ base : ");
4142 for (i = 0; i < dcb_info.nb_tcs; i++)
4143 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
4144 printf("\n RXQ number :");
4145 for (i = 0; i < dcb_info.nb_tcs; i++)
4146 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
4147 printf("\n TXQ base : ");
4148 for (i = 0; i < dcb_info.nb_tcs; i++)
4149 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
4150 printf("\n TXQ number :");
4151 for (i = 0; i < dcb_info.nb_tcs; i++)
4152 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
4157 open_file(const char *file_path, uint32_t *size)
4159 int fd = open(file_path, O_RDONLY);
4161 uint8_t *buf = NULL;
4169 printf("%s: Failed to open %s\n", __func__, file_path);
4173 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
4175 printf("%s: File operations failed\n", __func__);
4179 pkg_size = st_buf.st_size;
4182 printf("%s: File operations failed\n", __func__);
4186 buf = (uint8_t *)malloc(pkg_size);
4189 printf("%s: Failed to malloc memory\n", __func__);
4193 ret = read(fd, buf, pkg_size);
4196 printf("%s: File read operation failed\n", __func__);
4210 save_file(const char *file_path, uint8_t *buf, uint32_t size)
4212 FILE *fh = fopen(file_path, "wb");
4215 printf("%s: Failed to open %s\n", __func__, file_path);
4219 if (fwrite(buf, 1, size, fh) != size) {
4221 printf("%s: File write operation failed\n", __func__);
4231 close_file(uint8_t *buf)
4242 port_queue_region_info_display(portid_t port_id, void *buf)
4244 #ifdef RTE_LIBRTE_I40E_PMD
4246 struct rte_pmd_i40e_queue_regions *info =
4247 (struct rte_pmd_i40e_queue_regions *)buf;
4248 static const char *queue_region_info_stats_border = "-------";
4250 if (!info->queue_region_number)
4251 printf("there is no region has been set before");
4253 printf("\n %s All queue region info for port=%2d %s",
4254 queue_region_info_stats_border, port_id,
4255 queue_region_info_stats_border);
4256 printf("\n queue_region_number: %-14u \n",
4257 info->queue_region_number);
4259 for (i = 0; i < info->queue_region_number; i++) {
4260 printf("\n region_id: %-14u queue_number: %-14u "
4261 "queue_start_index: %-14u \n",
4262 info->region[i].region_id,
4263 info->region[i].queue_num,
4264 info->region[i].queue_start_index);
4266 printf(" user_priority_num is %-14u :",
4267 info->region[i].user_priority_num);
4268 for (j = 0; j < info->region[i].user_priority_num; j++)
4269 printf(" %-14u ", info->region[i].user_priority[j]);
4271 printf("\n flowtype_num is %-14u :",
4272 info->region[i].flowtype_num);
4273 for (j = 0; j < info->region[i].flowtype_num; j++)
4274 printf(" %-14u ", info->region[i].hw_flowtype[j]);
4277 RTE_SET_USED(port_id);
4285 show_macs(portid_t port_id)
4287 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4288 struct rte_eth_dev_info dev_info;
4289 struct rte_ether_addr *addr;
4290 uint32_t i, num_macs = 0;
4291 struct rte_eth_dev *dev;
4293 dev = &rte_eth_devices[port_id];
4295 rte_eth_dev_info_get(port_id, &dev_info);
4297 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4298 addr = &dev->data->mac_addrs[i];
4300 /* skip zero address */
4301 if (rte_is_zero_ether_addr(addr))
4307 printf("Number of MAC address added: %d\n", num_macs);
4309 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4310 addr = &dev->data->mac_addrs[i];
4312 /* skip zero address */
4313 if (rte_is_zero_ether_addr(addr))
4316 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4317 printf(" %s\n", buf);
4322 show_mcast_macs(portid_t port_id)
4324 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4325 struct rte_ether_addr *addr;
4326 struct rte_port *port;
4329 port = &ports[port_id];
4331 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
4333 for (i = 0; i < port->mc_addr_nb; i++) {
4334 addr = &port->mc_addr_pool[i];
4336 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4337 printf(" %s\n", buf);