1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation.
3 * Copyright 2013-2014 6WIND S.A.
13 #include <sys/queue.h>
14 #include <sys/types.h>
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_debug.h>
23 #include <rte_memory.h>
24 #include <rte_memcpy.h>
25 #include <rte_memzone.h>
26 #include <rte_launch.h>
28 #include <rte_per_lcore.h>
29 #include <rte_lcore.h>
30 #include <rte_atomic.h>
31 #include <rte_branch_prediction.h>
32 #include <rte_mempool.h>
34 #include <rte_interrupts.h>
36 #include <rte_ether.h>
37 #include <rte_ethdev.h>
38 #include <rte_string_fns.h>
39 #include <rte_cycles.h>
41 #include <rte_errno.h>
42 #ifdef RTE_LIBRTE_IXGBE_PMD
43 #include <rte_pmd_ixgbe.h>
45 #ifdef RTE_LIBRTE_I40E_PMD
46 #include <rte_pmd_i40e.h>
48 #ifdef RTE_LIBRTE_BNXT_PMD
49 #include <rte_pmd_bnxt.h>
55 #define ETHDEV_FWVERS_LEN 32
57 static char *flowtype_to_str(uint16_t flow_type);
60 enum tx_pkt_split split;
64 .split = TX_PKT_SPLIT_OFF,
68 .split = TX_PKT_SPLIT_ON,
72 .split = TX_PKT_SPLIT_RND,
77 const struct rss_type_info rss_type_table[] = {
78 { "all", ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP | ETH_RSS_TCP |
79 ETH_RSS_UDP | ETH_RSS_SCTP | ETH_RSS_L2_PAYLOAD |
80 ETH_RSS_L2TPV3 | ETH_RSS_ESP | ETH_RSS_AH | ETH_RSS_PFCP},
82 { "eth", ETH_RSS_ETH },
83 { "l2-src-only", ETH_RSS_L2_SRC_ONLY },
84 { "l2-dst-only", ETH_RSS_L2_DST_ONLY },
85 { "vlan", ETH_RSS_VLAN },
86 { "s-vlan", ETH_RSS_S_VLAN },
87 { "c-vlan", ETH_RSS_C_VLAN },
88 { "ipv4", ETH_RSS_IPV4 },
89 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
90 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
91 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
92 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
93 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
94 { "ipv6", ETH_RSS_IPV6 },
95 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
96 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
97 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
98 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
99 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
100 { "l2-payload", ETH_RSS_L2_PAYLOAD },
101 { "ipv6-ex", ETH_RSS_IPV6_EX },
102 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
103 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
104 { "port", ETH_RSS_PORT },
105 { "vxlan", ETH_RSS_VXLAN },
106 { "geneve", ETH_RSS_GENEVE },
107 { "nvgre", ETH_RSS_NVGRE },
108 { "ip", ETH_RSS_IP },
109 { "udp", ETH_RSS_UDP },
110 { "tcp", ETH_RSS_TCP },
111 { "sctp", ETH_RSS_SCTP },
112 { "tunnel", ETH_RSS_TUNNEL },
113 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
114 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
115 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
116 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
117 { "esp", ETH_RSS_ESP },
118 { "ah", ETH_RSS_AH },
119 { "l2tpv3", ETH_RSS_L2TPV3 },
120 { "pfcp", ETH_RSS_PFCP },
125 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
127 char buf[RTE_ETHER_ADDR_FMT_SIZE];
128 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
129 printf("%s%s", name, buf);
133 nic_stats_display(portid_t port_id)
135 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
136 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
137 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
138 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
139 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
140 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
142 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
143 struct rte_eth_stats stats;
144 struct rte_port *port = &ports[port_id];
147 static const char *nic_stats_border = "########################";
149 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
153 rte_eth_stats_get(port_id, &stats);
154 printf("\n %s NIC statistics for port %-2d %s\n",
155 nic_stats_border, port_id, nic_stats_border);
157 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
158 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
160 stats.ipackets, stats.imissed, stats.ibytes);
161 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
162 printf(" RX-nombuf: %-10"PRIu64"\n",
164 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
166 stats.opackets, stats.oerrors, stats.obytes);
169 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
170 " RX-bytes: %10"PRIu64"\n",
171 stats.ipackets, stats.ierrors, stats.ibytes);
172 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
173 printf(" RX-nombuf: %10"PRIu64"\n",
175 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
176 " TX-bytes: %10"PRIu64"\n",
177 stats.opackets, stats.oerrors, stats.obytes);
180 if (port->rx_queue_stats_mapping_enabled) {
182 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
183 printf(" Stats reg %2d RX-packets: %10"PRIu64
184 " RX-errors: %10"PRIu64
185 " RX-bytes: %10"PRIu64"\n",
186 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
189 if (port->tx_queue_stats_mapping_enabled) {
191 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
192 printf(" Stats reg %2d TX-packets: %10"PRIu64
193 " TX-bytes: %10"PRIu64"\n",
194 i, stats.q_opackets[i], stats.q_obytes[i]);
198 diff_cycles = prev_cycles[port_id];
199 prev_cycles[port_id] = rte_rdtsc();
201 diff_cycles = prev_cycles[port_id] - diff_cycles;
203 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
204 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
205 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
206 (stats.opackets - prev_pkts_tx[port_id]) : 0;
207 prev_pkts_rx[port_id] = stats.ipackets;
208 prev_pkts_tx[port_id] = stats.opackets;
209 mpps_rx = diff_cycles > 0 ?
210 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
211 mpps_tx = diff_cycles > 0 ?
212 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
214 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
215 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
216 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
217 (stats.obytes - prev_bytes_tx[port_id]) : 0;
218 prev_bytes_rx[port_id] = stats.ibytes;
219 prev_bytes_tx[port_id] = stats.obytes;
220 mbps_rx = diff_cycles > 0 ?
221 diff_bytes_rx * rte_get_tsc_hz() / diff_cycles : 0;
222 mbps_tx = diff_cycles > 0 ?
223 diff_bytes_tx * rte_get_tsc_hz() / diff_cycles : 0;
225 printf("\n Throughput (since last show)\n");
226 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
227 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
228 mpps_tx, mbps_tx * 8);
230 printf(" %s############################%s\n",
231 nic_stats_border, nic_stats_border);
235 nic_stats_clear(portid_t port_id)
239 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
244 ret = rte_eth_stats_reset(port_id);
246 printf("%s: Error: failed to reset stats (port %u): %s",
247 __func__, port_id, strerror(-ret));
251 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
255 printf("%s: Error: failed to get stats (port %u): %s",
256 __func__, port_id, strerror(ret));
259 printf("\n NIC statistics for port %d cleared\n", port_id);
263 nic_xstats_display(portid_t port_id)
265 struct rte_eth_xstat *xstats;
266 int cnt_xstats, idx_xstat;
267 struct rte_eth_xstat_name *xstats_names;
269 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
273 printf("###### NIC extended statistics for port %-2d\n", port_id);
274 if (!rte_eth_dev_is_valid_port(port_id)) {
275 printf("Error: Invalid port number %i\n", port_id);
280 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
281 if (cnt_xstats < 0) {
282 printf("Error: Cannot get count of xstats\n");
286 /* Get id-name lookup table */
287 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
288 if (xstats_names == NULL) {
289 printf("Cannot allocate memory for xstats lookup\n");
292 if (cnt_xstats != rte_eth_xstats_get_names(
293 port_id, xstats_names, cnt_xstats)) {
294 printf("Error: Cannot get xstats lookup\n");
299 /* Get stats themselves */
300 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
301 if (xstats == NULL) {
302 printf("Cannot allocate memory for xstats\n");
306 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
307 printf("Error: Unable to get xstats\n");
314 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
315 if (xstats_hide_zero && !xstats[idx_xstat].value)
317 printf("%s: %"PRIu64"\n",
318 xstats_names[idx_xstat].name,
319 xstats[idx_xstat].value);
326 nic_xstats_clear(portid_t port_id)
330 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
335 ret = rte_eth_xstats_reset(port_id);
337 printf("%s: Error: failed to reset xstats (port %u): %s",
338 __func__, port_id, strerror(-ret));
342 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
346 printf("%s: Error: failed to get stats (port %u): %s",
347 __func__, port_id, strerror(ret));
353 nic_stats_mapping_display(portid_t port_id)
355 struct rte_port *port = &ports[port_id];
358 static const char *nic_stats_mapping_border = "########################";
360 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
365 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
366 printf("Port id %d - either does not support queue statistic mapping or"
367 " no queue statistic mapping set\n", port_id);
371 printf("\n %s NIC statistics mapping for port %-2d %s\n",
372 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
374 if (port->rx_queue_stats_mapping_enabled) {
375 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
376 if (rx_queue_stats_mappings[i].port_id == port_id) {
377 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
378 rx_queue_stats_mappings[i].queue_id,
379 rx_queue_stats_mappings[i].stats_counter_id);
386 if (port->tx_queue_stats_mapping_enabled) {
387 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
388 if (tx_queue_stats_mappings[i].port_id == port_id) {
389 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
390 tx_queue_stats_mappings[i].queue_id,
391 tx_queue_stats_mappings[i].stats_counter_id);
396 printf(" %s####################################%s\n",
397 nic_stats_mapping_border, nic_stats_mapping_border);
401 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
403 struct rte_eth_burst_mode mode;
404 struct rte_eth_rxq_info qinfo;
406 static const char *info_border = "*********************";
408 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
410 printf("Failed to retrieve information for port: %u, "
411 "RX queue: %hu\nerror desc: %s(%d)\n",
412 port_id, queue_id, strerror(-rc), rc);
416 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
417 info_border, port_id, queue_id, info_border);
419 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
420 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
421 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
422 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
423 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
424 printf("\nRX drop packets: %s",
425 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
426 printf("\nRX deferred start: %s",
427 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
428 printf("\nRX scattered packets: %s",
429 (qinfo.scattered_rx != 0) ? "on" : "off");
430 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
432 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
433 printf("\nBurst mode: %s%s",
435 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
436 " (per queue)" : "");
442 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
444 struct rte_eth_burst_mode mode;
445 struct rte_eth_txq_info qinfo;
447 static const char *info_border = "*********************";
449 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
451 printf("Failed to retrieve information for port: %u, "
452 "TX queue: %hu\nerror desc: %s(%d)\n",
453 port_id, queue_id, strerror(-rc), rc);
457 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
458 info_border, port_id, queue_id, info_border);
460 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
461 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
462 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
463 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
464 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
465 printf("\nTX deferred start: %s",
466 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
467 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
469 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
470 printf("\nBurst mode: %s%s",
472 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
473 " (per queue)" : "");
478 static int bus_match_all(const struct rte_bus *bus, const void *data)
486 device_infos_display(const char *identifier)
488 static const char *info_border = "*********************";
489 struct rte_bus *start = NULL, *next;
490 struct rte_dev_iterator dev_iter;
491 char name[RTE_ETH_NAME_MAX_LEN];
492 struct rte_ether_addr mac_addr;
493 struct rte_device *dev;
494 struct rte_devargs da;
498 memset(&da, 0, sizeof(da));
502 if (rte_devargs_parsef(&da, "%s", identifier)) {
503 printf("cannot parse identifier\n");
510 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
513 if (identifier && da.bus != next)
516 /* Skip buses that don't have iterate method */
517 if (!next->dev_iterate)
520 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
521 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
525 /* Check for matching device if identifier is present */
527 strncmp(da.name, dev->name, strlen(dev->name)))
529 printf("\n%s Infos for device %s %s\n",
530 info_border, dev->name, info_border);
531 printf("Bus name: %s", dev->bus->name);
532 printf("\nDriver name: %s", dev->driver->name);
533 printf("\nDevargs: %s",
534 dev->devargs ? dev->devargs->args : "");
535 printf("\nConnect to socket: %d", dev->numa_node);
538 /* List ports with matching device name */
539 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
540 printf("\n\tPort id: %-2d", port_id);
541 if (eth_macaddr_get_print_err(port_id,
543 print_ethaddr("\n\tMAC address: ",
545 rte_eth_dev_get_name_by_port(port_id, name);
546 printf("\n\tDevice name: %s", name);
554 port_infos_display(portid_t port_id)
556 struct rte_port *port;
557 struct rte_ether_addr mac_addr;
558 struct rte_eth_link link;
559 struct rte_eth_dev_info dev_info;
561 struct rte_mempool * mp;
562 static const char *info_border = "*********************";
564 char name[RTE_ETH_NAME_MAX_LEN];
566 char fw_version[ETHDEV_FWVERS_LEN];
568 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
572 port = &ports[port_id];
573 ret = eth_link_get_nowait_print_err(port_id, &link);
577 ret = eth_dev_info_get_print_err(port_id, &dev_info);
581 printf("\n%s Infos for port %-2d %s\n",
582 info_border, port_id, info_border);
583 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
584 print_ethaddr("MAC address: ", &mac_addr);
585 rte_eth_dev_get_name_by_port(port_id, name);
586 printf("\nDevice name: %s", name);
587 printf("\nDriver name: %s", dev_info.driver_name);
589 if (rte_eth_dev_fw_version_get(port_id, fw_version,
590 ETHDEV_FWVERS_LEN) == 0)
591 printf("\nFirmware-version: %s", fw_version);
593 printf("\nFirmware-version: %s", "not available");
595 if (dev_info.device->devargs && dev_info.device->devargs->args)
596 printf("\nDevargs: %s", dev_info.device->devargs->args);
597 printf("\nConnect to socket: %u", port->socket_id);
599 if (port_numa[port_id] != NUMA_NO_CONFIG) {
600 mp = mbuf_pool_find(port_numa[port_id]);
602 printf("\nmemory allocation on the socket: %d",
605 printf("\nmemory allocation on the socket: %u",port->socket_id);
607 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
608 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
609 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
610 ("full-duplex") : ("half-duplex"));
612 if (!rte_eth_dev_get_mtu(port_id, &mtu))
613 printf("MTU: %u\n", mtu);
615 printf("Promiscuous mode: %s\n",
616 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
617 printf("Allmulticast mode: %s\n",
618 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
619 printf("Maximum number of MAC addresses: %u\n",
620 (unsigned int)(port->dev_info.max_mac_addrs));
621 printf("Maximum number of MAC addresses of hash filtering: %u\n",
622 (unsigned int)(port->dev_info.max_hash_mac_addrs));
624 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
625 if (vlan_offload >= 0){
626 printf("VLAN offload: \n");
627 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
628 printf(" strip on, ");
630 printf(" strip off, ");
632 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
633 printf("filter on, ");
635 printf("filter off, ");
637 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
638 printf("extend on, ");
640 printf("extend off, ");
642 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
643 printf("qinq strip on\n");
645 printf("qinq strip off\n");
648 if (dev_info.hash_key_size > 0)
649 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
650 if (dev_info.reta_size > 0)
651 printf("Redirection table size: %u\n", dev_info.reta_size);
652 if (!dev_info.flow_type_rss_offloads)
653 printf("No RSS offload flow type is supported.\n");
658 printf("Supported RSS offload flow types:\n");
659 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
660 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
661 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
663 p = flowtype_to_str(i);
667 printf(" user defined %d\n", i);
671 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
672 printf("Maximum configurable length of RX packet: %u\n",
673 dev_info.max_rx_pktlen);
674 printf("Maximum configurable size of LRO aggregated packet: %u\n",
675 dev_info.max_lro_pkt_size);
676 if (dev_info.max_vfs)
677 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
678 if (dev_info.max_vmdq_pools)
679 printf("Maximum number of VMDq pools: %u\n",
680 dev_info.max_vmdq_pools);
682 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
683 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
684 printf("Max possible number of RXDs per queue: %hu\n",
685 dev_info.rx_desc_lim.nb_max);
686 printf("Min possible number of RXDs per queue: %hu\n",
687 dev_info.rx_desc_lim.nb_min);
688 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
690 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
691 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
692 printf("Max possible number of TXDs per queue: %hu\n",
693 dev_info.tx_desc_lim.nb_max);
694 printf("Min possible number of TXDs per queue: %hu\n",
695 dev_info.tx_desc_lim.nb_min);
696 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
697 printf("Max segment number per packet: %hu\n",
698 dev_info.tx_desc_lim.nb_seg_max);
699 printf("Max segment number per MTU/TSO: %hu\n",
700 dev_info.tx_desc_lim.nb_mtu_seg_max);
702 /* Show switch info only if valid switch domain and port id is set */
703 if (dev_info.switch_info.domain_id !=
704 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
705 if (dev_info.switch_info.name)
706 printf("Switch name: %s\n", dev_info.switch_info.name);
708 printf("Switch domain Id: %u\n",
709 dev_info.switch_info.domain_id);
710 printf("Switch Port Id: %u\n",
711 dev_info.switch_info.port_id);
716 port_summary_header_display(void)
718 uint16_t port_number;
720 port_number = rte_eth_dev_count_avail();
721 printf("Number of available ports: %i\n", port_number);
722 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
723 "Driver", "Status", "Link");
727 port_summary_display(portid_t port_id)
729 struct rte_ether_addr mac_addr;
730 struct rte_eth_link link;
731 struct rte_eth_dev_info dev_info;
732 char name[RTE_ETH_NAME_MAX_LEN];
735 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
740 ret = eth_link_get_nowait_print_err(port_id, &link);
744 ret = eth_dev_info_get_print_err(port_id, &dev_info);
748 rte_eth_dev_get_name_by_port(port_id, name);
749 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
753 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
754 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
755 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
756 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
757 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
758 (unsigned int) link.link_speed);
762 port_offload_cap_display(portid_t port_id)
764 struct rte_eth_dev_info dev_info;
765 static const char *info_border = "************";
768 if (port_id_is_invalid(port_id, ENABLED_WARN))
771 ret = eth_dev_info_get_print_err(port_id, &dev_info);
775 printf("\n%s Port %d supported offload features: %s\n",
776 info_border, port_id, info_border);
778 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
779 printf("VLAN stripped: ");
780 if (ports[port_id].dev_conf.rxmode.offloads &
781 DEV_RX_OFFLOAD_VLAN_STRIP)
787 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
788 printf("Double VLANs stripped: ");
789 if (ports[port_id].dev_conf.rxmode.offloads &
790 DEV_RX_OFFLOAD_QINQ_STRIP)
796 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
797 printf("RX IPv4 checksum: ");
798 if (ports[port_id].dev_conf.rxmode.offloads &
799 DEV_RX_OFFLOAD_IPV4_CKSUM)
805 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
806 printf("RX UDP checksum: ");
807 if (ports[port_id].dev_conf.rxmode.offloads &
808 DEV_RX_OFFLOAD_UDP_CKSUM)
814 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
815 printf("RX TCP checksum: ");
816 if (ports[port_id].dev_conf.rxmode.offloads &
817 DEV_RX_OFFLOAD_TCP_CKSUM)
823 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) {
824 printf("RX SCTP checksum: ");
825 if (ports[port_id].dev_conf.rxmode.offloads &
826 DEV_RX_OFFLOAD_SCTP_CKSUM)
832 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
833 printf("RX Outer IPv4 checksum: ");
834 if (ports[port_id].dev_conf.rxmode.offloads &
835 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
841 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) {
842 printf("RX Outer UDP checksum: ");
843 if (ports[port_id].dev_conf.rxmode.offloads &
844 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM)
850 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
851 printf("Large receive offload: ");
852 if (ports[port_id].dev_conf.rxmode.offloads &
853 DEV_RX_OFFLOAD_TCP_LRO)
859 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
860 printf("HW timestamp: ");
861 if (ports[port_id].dev_conf.rxmode.offloads &
862 DEV_RX_OFFLOAD_TIMESTAMP)
868 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) {
869 printf("Rx Keep CRC: ");
870 if (ports[port_id].dev_conf.rxmode.offloads &
871 DEV_RX_OFFLOAD_KEEP_CRC)
877 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) {
878 printf("RX offload security: ");
879 if (ports[port_id].dev_conf.rxmode.offloads &
880 DEV_RX_OFFLOAD_SECURITY)
886 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
887 printf("VLAN insert: ");
888 if (ports[port_id].dev_conf.txmode.offloads &
889 DEV_TX_OFFLOAD_VLAN_INSERT)
895 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
896 printf("Double VLANs insert: ");
897 if (ports[port_id].dev_conf.txmode.offloads &
898 DEV_TX_OFFLOAD_QINQ_INSERT)
904 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
905 printf("TX IPv4 checksum: ");
906 if (ports[port_id].dev_conf.txmode.offloads &
907 DEV_TX_OFFLOAD_IPV4_CKSUM)
913 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
914 printf("TX UDP checksum: ");
915 if (ports[port_id].dev_conf.txmode.offloads &
916 DEV_TX_OFFLOAD_UDP_CKSUM)
922 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
923 printf("TX TCP checksum: ");
924 if (ports[port_id].dev_conf.txmode.offloads &
925 DEV_TX_OFFLOAD_TCP_CKSUM)
931 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
932 printf("TX SCTP checksum: ");
933 if (ports[port_id].dev_conf.txmode.offloads &
934 DEV_TX_OFFLOAD_SCTP_CKSUM)
940 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
941 printf("TX Outer IPv4 checksum: ");
942 if (ports[port_id].dev_conf.txmode.offloads &
943 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
949 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
950 printf("TX TCP segmentation: ");
951 if (ports[port_id].dev_conf.txmode.offloads &
952 DEV_TX_OFFLOAD_TCP_TSO)
958 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
959 printf("TX UDP segmentation: ");
960 if (ports[port_id].dev_conf.txmode.offloads &
961 DEV_TX_OFFLOAD_UDP_TSO)
967 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
968 printf("TSO for VXLAN tunnel packet: ");
969 if (ports[port_id].dev_conf.txmode.offloads &
970 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
976 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
977 printf("TSO for GRE tunnel packet: ");
978 if (ports[port_id].dev_conf.txmode.offloads &
979 DEV_TX_OFFLOAD_GRE_TNL_TSO)
985 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
986 printf("TSO for IPIP tunnel packet: ");
987 if (ports[port_id].dev_conf.txmode.offloads &
988 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
994 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
995 printf("TSO for GENEVE tunnel packet: ");
996 if (ports[port_id].dev_conf.txmode.offloads &
997 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
1003 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) {
1004 printf("IP tunnel TSO: ");
1005 if (ports[port_id].dev_conf.txmode.offloads &
1006 DEV_TX_OFFLOAD_IP_TNL_TSO)
1012 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) {
1013 printf("UDP tunnel TSO: ");
1014 if (ports[port_id].dev_conf.txmode.offloads &
1015 DEV_TX_OFFLOAD_UDP_TNL_TSO)
1021 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
1022 printf("TX Outer UDP checksum: ");
1023 if (ports[port_id].dev_conf.txmode.offloads &
1024 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
1033 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1037 if (port_id == (portid_t)RTE_PORT_ALL)
1040 RTE_ETH_FOREACH_DEV(pid)
1044 if (warning == ENABLED_WARN)
1045 printf("Invalid port %d\n", port_id);
1050 void print_valid_ports(void)
1054 printf("The valid ports array is [");
1055 RTE_ETH_FOREACH_DEV(pid) {
1062 vlan_id_is_invalid(uint16_t vlan_id)
1066 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1071 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1073 const struct rte_pci_device *pci_dev;
1074 const struct rte_bus *bus;
1077 if (reg_off & 0x3) {
1078 printf("Port register offset 0x%X not aligned on a 4-byte "
1084 if (!ports[port_id].dev_info.device) {
1085 printf("Invalid device\n");
1089 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1090 if (bus && !strcmp(bus->name, "pci")) {
1091 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1093 printf("Not a PCI device\n");
1097 pci_len = pci_dev->mem_resource[0].len;
1098 if (reg_off >= pci_len) {
1099 printf("Port %d: register offset %u (0x%X) out of port PCI "
1100 "resource (length=%"PRIu64")\n",
1101 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
1108 reg_bit_pos_is_invalid(uint8_t bit_pos)
1112 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
1116 #define display_port_and_reg_off(port_id, reg_off) \
1117 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1120 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1122 display_port_and_reg_off(port_id, (unsigned)reg_off);
1123 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1127 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1132 if (port_id_is_invalid(port_id, ENABLED_WARN))
1134 if (port_reg_off_is_invalid(port_id, reg_off))
1136 if (reg_bit_pos_is_invalid(bit_x))
1138 reg_v = port_id_pci_reg_read(port_id, reg_off);
1139 display_port_and_reg_off(port_id, (unsigned)reg_off);
1140 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1144 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1145 uint8_t bit1_pos, uint8_t bit2_pos)
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(bit1_pos))
1157 if (reg_bit_pos_is_invalid(bit2_pos))
1159 if (bit1_pos > bit2_pos)
1160 l_bit = bit2_pos, h_bit = bit1_pos;
1162 l_bit = bit1_pos, h_bit = bit2_pos;
1164 reg_v = port_id_pci_reg_read(port_id, reg_off);
1167 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1168 display_port_and_reg_off(port_id, (unsigned)reg_off);
1169 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1170 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1174 port_reg_display(portid_t port_id, uint32_t reg_off)
1178 if (port_id_is_invalid(port_id, ENABLED_WARN))
1180 if (port_reg_off_is_invalid(port_id, reg_off))
1182 reg_v = port_id_pci_reg_read(port_id, reg_off);
1183 display_port_reg_value(port_id, reg_off, reg_v);
1187 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1192 if (port_id_is_invalid(port_id, ENABLED_WARN))
1194 if (port_reg_off_is_invalid(port_id, reg_off))
1196 if (reg_bit_pos_is_invalid(bit_pos))
1199 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1202 reg_v = port_id_pci_reg_read(port_id, reg_off);
1204 reg_v &= ~(1 << bit_pos);
1206 reg_v |= (1 << bit_pos);
1207 port_id_pci_reg_write(port_id, reg_off, reg_v);
1208 display_port_reg_value(port_id, reg_off, reg_v);
1212 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1213 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1220 if (port_id_is_invalid(port_id, ENABLED_WARN))
1222 if (port_reg_off_is_invalid(port_id, reg_off))
1224 if (reg_bit_pos_is_invalid(bit1_pos))
1226 if (reg_bit_pos_is_invalid(bit2_pos))
1228 if (bit1_pos > bit2_pos)
1229 l_bit = bit2_pos, h_bit = bit1_pos;
1231 l_bit = bit1_pos, h_bit = bit2_pos;
1233 if ((h_bit - l_bit) < 31)
1234 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1238 if (value > max_v) {
1239 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1240 (unsigned)value, (unsigned)value,
1241 (unsigned)max_v, (unsigned)max_v);
1244 reg_v = port_id_pci_reg_read(port_id, reg_off);
1245 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1246 reg_v |= (value << l_bit); /* Set changed bits */
1247 port_id_pci_reg_write(port_id, reg_off, reg_v);
1248 display_port_reg_value(port_id, reg_off, reg_v);
1252 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1254 if (port_id_is_invalid(port_id, ENABLED_WARN))
1256 if (port_reg_off_is_invalid(port_id, reg_off))
1258 port_id_pci_reg_write(port_id, reg_off, reg_v);
1259 display_port_reg_value(port_id, reg_off, reg_v);
1263 port_mtu_set(portid_t port_id, uint16_t mtu)
1266 struct rte_port *rte_port = &ports[port_id];
1267 struct rte_eth_dev_info dev_info;
1268 uint16_t eth_overhead;
1271 if (port_id_is_invalid(port_id, ENABLED_WARN))
1274 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1278 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1279 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1280 mtu, dev_info.min_mtu, dev_info.max_mtu);
1283 diag = rte_eth_dev_set_mtu(port_id, mtu);
1285 dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1287 * Ether overhead in driver is equal to the difference of
1288 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1289 * device supports jumbo frame.
1291 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1292 if (mtu > RTE_ETHER_MAX_LEN - eth_overhead) {
1293 rte_port->dev_conf.rxmode.offloads |=
1294 DEV_RX_OFFLOAD_JUMBO_FRAME;
1295 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1298 rte_port->dev_conf.rxmode.offloads &=
1299 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1303 printf("Set MTU failed. diag=%d\n", diag);
1306 /* Generic flow management functions. */
1308 /** Generate a port_flow entry from attributes/pattern/actions. */
1309 static struct port_flow *
1310 port_flow_new(const struct rte_flow_attr *attr,
1311 const struct rte_flow_item *pattern,
1312 const struct rte_flow_action *actions,
1313 struct rte_flow_error *error)
1315 const struct rte_flow_conv_rule rule = {
1317 .pattern_ro = pattern,
1318 .actions_ro = actions,
1320 struct port_flow *pf;
1323 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1326 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1329 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1333 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1340 /** Print a message out of a flow error. */
1342 port_flow_complain(struct rte_flow_error *error)
1344 static const char *const errstrlist[] = {
1345 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1346 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1347 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1348 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1349 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1350 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1351 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1352 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1353 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1354 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1355 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1356 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1357 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1358 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1359 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1360 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1361 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1365 int err = rte_errno;
1367 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1368 !errstrlist[error->type])
1369 errstr = "unknown type";
1371 errstr = errstrlist[error->type];
1372 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1373 error->type, errstr,
1374 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1375 error->cause), buf) : "",
1376 error->message ? error->message : "(no stated reason)",
1381 /** Validate flow rule. */
1383 port_flow_validate(portid_t port_id,
1384 const struct rte_flow_attr *attr,
1385 const struct rte_flow_item *pattern,
1386 const struct rte_flow_action *actions)
1388 struct rte_flow_error error;
1390 /* Poisoning to make sure PMDs update it in case of error. */
1391 memset(&error, 0x11, sizeof(error));
1392 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1393 return port_flow_complain(&error);
1394 printf("Flow rule validated\n");
1398 /** Update age action context by port_flow pointer. */
1400 update_age_action_context(const struct rte_flow_action *actions,
1401 struct port_flow *pf)
1403 struct rte_flow_action_age *age = NULL;
1405 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1406 switch (actions->type) {
1407 case RTE_FLOW_ACTION_TYPE_AGE:
1408 age = (struct rte_flow_action_age *)
1409 (uintptr_t)actions->conf;
1418 /** Create flow rule. */
1420 port_flow_create(portid_t port_id,
1421 const struct rte_flow_attr *attr,
1422 const struct rte_flow_item *pattern,
1423 const struct rte_flow_action *actions)
1425 struct rte_flow *flow;
1426 struct rte_port *port;
1427 struct port_flow *pf;
1429 struct rte_flow_error error;
1431 port = &ports[port_id];
1432 if (port->flow_list) {
1433 if (port->flow_list->id == UINT32_MAX) {
1434 printf("Highest rule ID is already assigned, delete"
1438 id = port->flow_list->id + 1;
1440 pf = port_flow_new(attr, pattern, actions, &error);
1442 return port_flow_complain(&error);
1443 update_age_action_context(actions, pf);
1444 /* Poisoning to make sure PMDs update it in case of error. */
1445 memset(&error, 0x22, sizeof(error));
1446 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1449 return port_flow_complain(&error);
1451 pf->next = port->flow_list;
1454 port->flow_list = pf;
1455 printf("Flow rule #%u created\n", pf->id);
1459 /** Destroy a number of flow rules. */
1461 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1463 struct rte_port *port;
1464 struct port_flow **tmp;
1468 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1469 port_id == (portid_t)RTE_PORT_ALL)
1471 port = &ports[port_id];
1472 tmp = &port->flow_list;
1476 for (i = 0; i != n; ++i) {
1477 struct rte_flow_error error;
1478 struct port_flow *pf = *tmp;
1480 if (rule[i] != pf->id)
1483 * Poisoning to make sure PMDs update it in case
1486 memset(&error, 0x33, sizeof(error));
1487 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1488 ret = port_flow_complain(&error);
1491 printf("Flow rule #%u destroyed\n", pf->id);
1497 tmp = &(*tmp)->next;
1503 /** Remove all flow rules. */
1505 port_flow_flush(portid_t port_id)
1507 struct rte_flow_error error;
1508 struct rte_port *port;
1511 /* Poisoning to make sure PMDs update it in case of error. */
1512 memset(&error, 0x44, sizeof(error));
1513 if (rte_flow_flush(port_id, &error)) {
1514 ret = port_flow_complain(&error);
1515 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1516 port_id == (portid_t)RTE_PORT_ALL)
1519 port = &ports[port_id];
1520 while (port->flow_list) {
1521 struct port_flow *pf = port->flow_list->next;
1523 free(port->flow_list);
1524 port->flow_list = pf;
1529 /** Dump all flow rules. */
1531 port_flow_dump(portid_t port_id, const char *file_name)
1534 FILE *file = stdout;
1535 struct rte_flow_error error;
1537 if (file_name && strlen(file_name)) {
1538 file = fopen(file_name, "w");
1540 printf("Failed to create file %s: %s\n", file_name,
1545 ret = rte_flow_dev_dump(port_id, file, &error);
1547 port_flow_complain(&error);
1548 printf("Failed to dump flow: %s\n", strerror(-ret));
1550 printf("Flow dump finished\n");
1551 if (file_name && strlen(file_name))
1556 /** Query a flow rule. */
1558 port_flow_query(portid_t port_id, uint32_t rule,
1559 const struct rte_flow_action *action)
1561 struct rte_flow_error error;
1562 struct rte_port *port;
1563 struct port_flow *pf;
1566 struct rte_flow_query_count count;
1570 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1571 port_id == (portid_t)RTE_PORT_ALL)
1573 port = &ports[port_id];
1574 for (pf = port->flow_list; pf; pf = pf->next)
1578 printf("Flow rule #%u not found\n", rule);
1581 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1582 &name, sizeof(name),
1583 (void *)(uintptr_t)action->type, &error);
1585 return port_flow_complain(&error);
1586 switch (action->type) {
1587 case RTE_FLOW_ACTION_TYPE_COUNT:
1590 printf("Cannot query action type %d (%s)\n",
1591 action->type, name);
1594 /* Poisoning to make sure PMDs update it in case of error. */
1595 memset(&error, 0x55, sizeof(error));
1596 memset(&query, 0, sizeof(query));
1597 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1598 return port_flow_complain(&error);
1599 switch (action->type) {
1600 case RTE_FLOW_ACTION_TYPE_COUNT:
1604 " hits: %" PRIu64 "\n"
1605 " bytes: %" PRIu64 "\n",
1607 query.count.hits_set,
1608 query.count.bytes_set,
1613 printf("Cannot display result for action type %d (%s)\n",
1614 action->type, name);
1620 /** List simply and destroy all aged flows. */
1622 port_flow_aged(portid_t port_id, uint8_t destroy)
1625 int nb_context, total = 0, idx;
1626 struct rte_flow_error error;
1627 struct port_flow *pf;
1629 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1630 port_id == (portid_t)RTE_PORT_ALL)
1632 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
1633 printf("Port %u total aged flows: %d\n", port_id, total);
1635 port_flow_complain(&error);
1640 contexts = malloc(sizeof(void *) * total);
1641 if (contexts == NULL) {
1642 printf("Cannot allocate contexts for aged flow\n");
1645 printf("ID\tGroup\tPrio\tAttr\n");
1646 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
1647 if (nb_context != total) {
1648 printf("Port:%d get aged flows count(%d) != total(%d)\n",
1649 port_id, nb_context, total);
1653 for (idx = 0; idx < nb_context; idx++) {
1654 pf = (struct port_flow *)contexts[idx];
1656 printf("Error: get Null context in port %u\n", port_id);
1659 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
1661 pf->rule.attr->group,
1662 pf->rule.attr->priority,
1663 pf->rule.attr->ingress ? 'i' : '-',
1664 pf->rule.attr->egress ? 'e' : '-',
1665 pf->rule.attr->transfer ? 't' : '-');
1673 for (idx = 0; idx < nb_context; idx++) {
1674 pf = (struct port_flow *)contexts[idx];
1678 ret = port_flow_destroy(port_id, 1, &flow_id);
1682 printf("%d flows be destroyed\n", total);
1687 /** List flow rules. */
1689 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1691 struct rte_port *port;
1692 struct port_flow *pf;
1693 struct port_flow *list = NULL;
1696 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1697 port_id == (portid_t)RTE_PORT_ALL)
1699 port = &ports[port_id];
1700 if (!port->flow_list)
1702 /* Sort flows by group, priority and ID. */
1703 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1704 struct port_flow **tmp;
1705 const struct rte_flow_attr *curr = pf->rule.attr;
1708 /* Filter out unwanted groups. */
1709 for (i = 0; i != n; ++i)
1710 if (curr->group == group[i])
1715 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
1716 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
1718 if (curr->group > comp->group ||
1719 (curr->group == comp->group &&
1720 curr->priority > comp->priority) ||
1721 (curr->group == comp->group &&
1722 curr->priority == comp->priority &&
1723 pf->id > (*tmp)->id))
1730 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1731 for (pf = list; pf != NULL; pf = pf->tmp) {
1732 const struct rte_flow_item *item = pf->rule.pattern;
1733 const struct rte_flow_action *action = pf->rule.actions;
1736 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
1738 pf->rule.attr->group,
1739 pf->rule.attr->priority,
1740 pf->rule.attr->ingress ? 'i' : '-',
1741 pf->rule.attr->egress ? 'e' : '-',
1742 pf->rule.attr->transfer ? 't' : '-');
1743 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1744 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
1745 &name, sizeof(name),
1746 (void *)(uintptr_t)item->type,
1749 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1750 printf("%s ", name);
1754 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1755 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1756 &name, sizeof(name),
1757 (void *)(uintptr_t)action->type,
1760 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1761 printf(" %s", name);
1768 /** Restrict ingress traffic to the defined flow rules. */
1770 port_flow_isolate(portid_t port_id, int set)
1772 struct rte_flow_error error;
1774 /* Poisoning to make sure PMDs update it in case of error. */
1775 memset(&error, 0x66, sizeof(error));
1776 if (rte_flow_isolate(port_id, set, &error))
1777 return port_flow_complain(&error);
1778 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1780 set ? "now restricted" : "not restricted anymore");
1785 * RX/TX ring descriptors display functions.
1788 rx_queue_id_is_invalid(queueid_t rxq_id)
1790 if (rxq_id < nb_rxq)
1792 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1797 tx_queue_id_is_invalid(queueid_t txq_id)
1799 if (txq_id < nb_txq)
1801 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1806 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1808 if (rxdesc_id < nb_rxd)
1810 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1816 tx_desc_id_is_invalid(uint16_t txdesc_id)
1818 if (txdesc_id < nb_txd)
1820 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1825 static const struct rte_memzone *
1826 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1828 char mz_name[RTE_MEMZONE_NAMESIZE];
1829 const struct rte_memzone *mz;
1831 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
1832 port_id, q_id, ring_name);
1833 mz = rte_memzone_lookup(mz_name);
1835 printf("%s ring memory zoneof (port %d, queue %d) not"
1836 "found (zone name = %s\n",
1837 ring_name, port_id, q_id, mz_name);
1841 union igb_ring_dword {
1844 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1854 struct igb_ring_desc_32_bytes {
1855 union igb_ring_dword lo_dword;
1856 union igb_ring_dword hi_dword;
1857 union igb_ring_dword resv1;
1858 union igb_ring_dword resv2;
1861 struct igb_ring_desc_16_bytes {
1862 union igb_ring_dword lo_dword;
1863 union igb_ring_dword hi_dword;
1867 ring_rxd_display_dword(union igb_ring_dword dword)
1869 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1870 (unsigned)dword.words.hi);
1874 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1875 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1878 __rte_unused portid_t port_id,
1882 struct igb_ring_desc_16_bytes *ring =
1883 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1884 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1886 struct rte_eth_dev_info dev_info;
1888 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1892 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1893 /* 32 bytes RX descriptor, i40e only */
1894 struct igb_ring_desc_32_bytes *ring =
1895 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1896 ring[desc_id].lo_dword.dword =
1897 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1898 ring_rxd_display_dword(ring[desc_id].lo_dword);
1899 ring[desc_id].hi_dword.dword =
1900 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1901 ring_rxd_display_dword(ring[desc_id].hi_dword);
1902 ring[desc_id].resv1.dword =
1903 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1904 ring_rxd_display_dword(ring[desc_id].resv1);
1905 ring[desc_id].resv2.dword =
1906 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1907 ring_rxd_display_dword(ring[desc_id].resv2);
1912 /* 16 bytes RX descriptor */
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);
1922 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1924 struct igb_ring_desc_16_bytes *ring;
1925 struct igb_ring_desc_16_bytes txd;
1927 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1928 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1929 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1930 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1931 (unsigned)txd.lo_dword.words.lo,
1932 (unsigned)txd.lo_dword.words.hi,
1933 (unsigned)txd.hi_dword.words.lo,
1934 (unsigned)txd.hi_dword.words.hi);
1938 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1940 const struct rte_memzone *rx_mz;
1942 if (port_id_is_invalid(port_id, ENABLED_WARN))
1944 if (rx_queue_id_is_invalid(rxq_id))
1946 if (rx_desc_id_is_invalid(rxd_id))
1948 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1951 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1955 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1957 const struct rte_memzone *tx_mz;
1959 if (port_id_is_invalid(port_id, ENABLED_WARN))
1961 if (tx_queue_id_is_invalid(txq_id))
1963 if (tx_desc_id_is_invalid(txd_id))
1965 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1968 ring_tx_descriptor_display(tx_mz, txd_id);
1972 fwd_lcores_config_display(void)
1976 printf("List of forwarding lcores:");
1977 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1978 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1982 rxtx_config_display(void)
1987 printf(" %s packet forwarding%s packets/burst=%d\n",
1988 cur_fwd_eng->fwd_mode_name,
1989 retry_enabled == 0 ? "" : " with retry",
1992 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1993 printf(" packet len=%u - nb packet segments=%d\n",
1994 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1996 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1997 nb_fwd_lcores, nb_fwd_ports);
1999 RTE_ETH_FOREACH_DEV(pid) {
2000 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
2001 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
2002 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
2003 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
2004 uint16_t nb_rx_desc_tmp;
2005 uint16_t nb_tx_desc_tmp;
2006 struct rte_eth_rxq_info rx_qinfo;
2007 struct rte_eth_txq_info tx_qinfo;
2010 /* per port config */
2011 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
2012 (unsigned int)pid, nb_rxq, nb_txq);
2014 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
2015 ports[pid].dev_conf.rxmode.offloads,
2016 ports[pid].dev_conf.txmode.offloads);
2018 /* per rx queue config only for first queue to be less verbose */
2019 for (qid = 0; qid < 1; qid++) {
2020 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
2022 nb_rx_desc_tmp = nb_rx_desc[qid];
2024 nb_rx_desc_tmp = rx_qinfo.nb_desc;
2026 printf(" RX queue: %d\n", qid);
2027 printf(" RX desc=%d - RX free threshold=%d\n",
2028 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh);
2029 printf(" RX threshold registers: pthresh=%d hthresh=%d "
2031 rx_conf[qid].rx_thresh.pthresh,
2032 rx_conf[qid].rx_thresh.hthresh,
2033 rx_conf[qid].rx_thresh.wthresh);
2034 printf(" RX Offloads=0x%"PRIx64"\n",
2035 rx_conf[qid].offloads);
2038 /* per tx queue config only for first queue to be less verbose */
2039 for (qid = 0; qid < 1; qid++) {
2040 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
2042 nb_tx_desc_tmp = nb_tx_desc[qid];
2044 nb_tx_desc_tmp = tx_qinfo.nb_desc;
2046 printf(" TX queue: %d\n", qid);
2047 printf(" TX desc=%d - TX free threshold=%d\n",
2048 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh);
2049 printf(" TX threshold registers: pthresh=%d hthresh=%d "
2051 tx_conf[qid].tx_thresh.pthresh,
2052 tx_conf[qid].tx_thresh.hthresh,
2053 tx_conf[qid].tx_thresh.wthresh);
2054 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
2055 tx_conf[qid].offloads, tx_conf->tx_rs_thresh);
2061 port_rss_reta_info(portid_t port_id,
2062 struct rte_eth_rss_reta_entry64 *reta_conf,
2063 uint16_t nb_entries)
2065 uint16_t i, idx, shift;
2068 if (port_id_is_invalid(port_id, ENABLED_WARN))
2071 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
2073 printf("Failed to get RSS RETA info, return code = %d\n", ret);
2077 for (i = 0; i < nb_entries; i++) {
2078 idx = i / RTE_RETA_GROUP_SIZE;
2079 shift = i % RTE_RETA_GROUP_SIZE;
2080 if (!(reta_conf[idx].mask & (1ULL << shift)))
2082 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
2083 i, reta_conf[idx].reta[shift]);
2088 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
2092 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
2094 struct rte_eth_rss_conf rss_conf = {0};
2095 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
2099 struct rte_eth_dev_info dev_info;
2100 uint8_t hash_key_size;
2103 if (port_id_is_invalid(port_id, ENABLED_WARN))
2106 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2110 if (dev_info.hash_key_size > 0 &&
2111 dev_info.hash_key_size <= sizeof(rss_key))
2112 hash_key_size = dev_info.hash_key_size;
2114 printf("dev_info did not provide a valid hash key size\n");
2118 /* Get RSS hash key if asked to display it */
2119 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2120 rss_conf.rss_key_len = hash_key_size;
2121 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2125 printf("port index %d invalid\n", port_id);
2128 printf("operation not supported by device\n");
2131 printf("operation failed - diag=%d\n", diag);
2136 rss_hf = rss_conf.rss_hf;
2138 printf("RSS disabled\n");
2141 printf("RSS functions:\n ");
2142 for (i = 0; rss_type_table[i].str; i++) {
2143 if (rss_hf & rss_type_table[i].rss_type)
2144 printf("%s ", rss_type_table[i].str);
2149 printf("RSS key:\n");
2150 for (i = 0; i < hash_key_size; i++)
2151 printf("%02X", rss_key[i]);
2156 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2159 struct rte_eth_rss_conf rss_conf;
2163 rss_conf.rss_key = NULL;
2164 rss_conf.rss_key_len = hash_key_len;
2165 rss_conf.rss_hf = 0;
2166 for (i = 0; rss_type_table[i].str; i++) {
2167 if (!strcmp(rss_type_table[i].str, rss_type))
2168 rss_conf.rss_hf = rss_type_table[i].rss_type;
2170 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2172 rss_conf.rss_key = hash_key;
2173 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2180 printf("port index %d invalid\n", port_id);
2183 printf("operation not supported by device\n");
2186 printf("operation failed - diag=%d\n", diag);
2192 * Setup forwarding configuration for each logical core.
2195 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2197 streamid_t nb_fs_per_lcore;
2205 nb_fs = cfg->nb_fwd_streams;
2206 nb_fc = cfg->nb_fwd_lcores;
2207 if (nb_fs <= nb_fc) {
2208 nb_fs_per_lcore = 1;
2211 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2212 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2215 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2217 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2218 fwd_lcores[lc_id]->stream_idx = sm_id;
2219 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2220 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2224 * Assign extra remaining streams, if any.
2226 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2227 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2228 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2229 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2230 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2235 fwd_topology_tx_port_get(portid_t rxp)
2237 static int warning_once = 1;
2239 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2241 switch (port_topology) {
2243 case PORT_TOPOLOGY_PAIRED:
2244 if ((rxp & 0x1) == 0) {
2245 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2248 printf("\nWarning! port-topology=paired"
2249 " and odd forward ports number,"
2250 " the last port will pair with"
2257 case PORT_TOPOLOGY_CHAINED:
2258 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2259 case PORT_TOPOLOGY_LOOP:
2265 simple_fwd_config_setup(void)
2269 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2270 cur_fwd_config.nb_fwd_streams =
2271 (streamid_t) cur_fwd_config.nb_fwd_ports;
2273 /* reinitialize forwarding streams */
2277 * In the simple forwarding test, the number of forwarding cores
2278 * must be lower or equal to the number of forwarding ports.
2280 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2281 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2282 cur_fwd_config.nb_fwd_lcores =
2283 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2284 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2286 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2287 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2288 fwd_streams[i]->rx_queue = 0;
2289 fwd_streams[i]->tx_port =
2290 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2291 fwd_streams[i]->tx_queue = 0;
2292 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2293 fwd_streams[i]->retry_enabled = retry_enabled;
2298 * For the RSS forwarding test all streams distributed over lcores. Each stream
2299 * being composed of a RX queue to poll on a RX port for input messages,
2300 * associated with a TX queue of a TX port where to send forwarded packets.
2303 rss_fwd_config_setup(void)
2314 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2315 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2316 cur_fwd_config.nb_fwd_streams =
2317 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2319 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2320 cur_fwd_config.nb_fwd_lcores =
2321 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2323 /* reinitialize forwarding streams */
2326 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2328 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2329 struct fwd_stream *fs;
2331 fs = fwd_streams[sm_id];
2332 txp = fwd_topology_tx_port_get(rxp);
2333 fs->rx_port = fwd_ports_ids[rxp];
2335 fs->tx_port = fwd_ports_ids[txp];
2337 fs->peer_addr = fs->tx_port;
2338 fs->retry_enabled = retry_enabled;
2340 if (rxp < nb_fwd_ports)
2348 * For the DCB forwarding test, each core is assigned on each traffic class.
2350 * Each core is assigned a multi-stream, each stream being composed of
2351 * a RX queue to poll on a RX port for input messages, associated with
2352 * a TX queue of a TX port where to send forwarded packets. All RX and
2353 * TX queues are mapping to the same traffic class.
2354 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2358 dcb_fwd_config_setup(void)
2360 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2361 portid_t txp, rxp = 0;
2362 queueid_t txq, rxq = 0;
2364 uint16_t nb_rx_queue, nb_tx_queue;
2365 uint16_t i, j, k, sm_id = 0;
2368 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2369 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2370 cur_fwd_config.nb_fwd_streams =
2371 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2373 /* reinitialize forwarding streams */
2377 /* get the dcb info on the first RX and TX ports */
2378 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2379 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2381 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2382 fwd_lcores[lc_id]->stream_nb = 0;
2383 fwd_lcores[lc_id]->stream_idx = sm_id;
2384 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2385 /* if the nb_queue is zero, means this tc is
2386 * not enabled on the POOL
2388 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2390 k = fwd_lcores[lc_id]->stream_nb +
2391 fwd_lcores[lc_id]->stream_idx;
2392 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2393 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2394 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2395 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2396 for (j = 0; j < nb_rx_queue; j++) {
2397 struct fwd_stream *fs;
2399 fs = fwd_streams[k + j];
2400 fs->rx_port = fwd_ports_ids[rxp];
2401 fs->rx_queue = rxq + j;
2402 fs->tx_port = fwd_ports_ids[txp];
2403 fs->tx_queue = txq + j % nb_tx_queue;
2404 fs->peer_addr = fs->tx_port;
2405 fs->retry_enabled = retry_enabled;
2407 fwd_lcores[lc_id]->stream_nb +=
2408 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2410 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2413 if (tc < rxp_dcb_info.nb_tcs)
2415 /* Restart from TC 0 on next RX port */
2417 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2419 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2422 if (rxp >= nb_fwd_ports)
2424 /* get the dcb information on next RX and TX ports */
2425 if ((rxp & 0x1) == 0)
2426 txp = (portid_t) (rxp + 1);
2428 txp = (portid_t) (rxp - 1);
2429 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2430 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2435 icmp_echo_config_setup(void)
2442 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2443 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2444 (nb_txq * nb_fwd_ports);
2446 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2447 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2448 cur_fwd_config.nb_fwd_streams =
2449 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2450 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2451 cur_fwd_config.nb_fwd_lcores =
2452 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2453 if (verbose_level > 0) {
2454 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2456 cur_fwd_config.nb_fwd_lcores,
2457 cur_fwd_config.nb_fwd_ports,
2458 cur_fwd_config.nb_fwd_streams);
2461 /* reinitialize forwarding streams */
2463 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2465 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2466 if (verbose_level > 0)
2467 printf(" core=%d: \n", lc_id);
2468 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2469 struct fwd_stream *fs;
2470 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2471 fs->rx_port = fwd_ports_ids[rxp];
2473 fs->tx_port = fs->rx_port;
2475 fs->peer_addr = fs->tx_port;
2476 fs->retry_enabled = retry_enabled;
2477 if (verbose_level > 0)
2478 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2479 sm_id, fs->rx_port, fs->rx_queue,
2481 rxq = (queueid_t) (rxq + 1);
2482 if (rxq == nb_rxq) {
2484 rxp = (portid_t) (rxp + 1);
2490 #if defined RTE_LIBRTE_PMD_SOFTNIC
2492 softnic_fwd_config_setup(void)
2494 struct rte_port *port;
2495 portid_t pid, softnic_portid;
2497 uint8_t softnic_enable = 0;
2499 RTE_ETH_FOREACH_DEV(pid) {
2501 const char *driver = port->dev_info.driver_name;
2503 if (strcmp(driver, "net_softnic") == 0) {
2504 softnic_portid = pid;
2510 if (softnic_enable == 0) {
2511 printf("Softnic mode not configured(%s)!\n", __func__);
2515 cur_fwd_config.nb_fwd_ports = 1;
2516 cur_fwd_config.nb_fwd_streams = (streamid_t) nb_rxq;
2518 /* Re-initialize forwarding streams */
2522 * In the softnic forwarding test, the number of forwarding cores
2523 * is set to one and remaining are used for softnic packet processing.
2525 cur_fwd_config.nb_fwd_lcores = 1;
2526 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2528 for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++) {
2529 fwd_streams[i]->rx_port = softnic_portid;
2530 fwd_streams[i]->rx_queue = i;
2531 fwd_streams[i]->tx_port = softnic_portid;
2532 fwd_streams[i]->tx_queue = i;
2533 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2534 fwd_streams[i]->retry_enabled = retry_enabled;
2540 fwd_config_setup(void)
2542 cur_fwd_config.fwd_eng = cur_fwd_eng;
2543 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2544 icmp_echo_config_setup();
2548 #if defined RTE_LIBRTE_PMD_SOFTNIC
2549 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
2550 softnic_fwd_config_setup();
2555 if ((nb_rxq > 1) && (nb_txq > 1)){
2557 dcb_fwd_config_setup();
2559 rss_fwd_config_setup();
2562 simple_fwd_config_setup();
2566 mp_alloc_to_str(uint8_t mode)
2569 case MP_ALLOC_NATIVE:
2575 case MP_ALLOC_XMEM_HUGE:
2585 pkt_fwd_config_display(struct fwd_config *cfg)
2587 struct fwd_stream *fs;
2591 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2592 "NUMA support %s, MP allocation mode: %s\n",
2593 cfg->fwd_eng->fwd_mode_name,
2594 retry_enabled == 0 ? "" : " with retry",
2595 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2596 numa_support == 1 ? "enabled" : "disabled",
2597 mp_alloc_to_str(mp_alloc_type));
2600 printf("TX retry num: %u, delay between TX retries: %uus\n",
2601 burst_tx_retry_num, burst_tx_delay_time);
2602 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2603 printf("Logical Core %u (socket %u) forwards packets on "
2605 fwd_lcores_cpuids[lc_id],
2606 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2607 fwd_lcores[lc_id]->stream_nb);
2608 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2609 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2610 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2611 "P=%d/Q=%d (socket %u) ",
2612 fs->rx_port, fs->rx_queue,
2613 ports[fs->rx_port].socket_id,
2614 fs->tx_port, fs->tx_queue,
2615 ports[fs->tx_port].socket_id);
2616 print_ethaddr("peer=",
2617 &peer_eth_addrs[fs->peer_addr]);
2625 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2627 struct rte_ether_addr new_peer_addr;
2628 if (!rte_eth_dev_is_valid_port(port_id)) {
2629 printf("Error: Invalid port number %i\n", port_id);
2632 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
2633 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2636 peer_eth_addrs[port_id] = new_peer_addr;
2640 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2643 unsigned int lcore_cpuid;
2648 for (i = 0; i < nb_lc; i++) {
2649 lcore_cpuid = lcorelist[i];
2650 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2651 printf("lcore %u not enabled\n", lcore_cpuid);
2654 if (lcore_cpuid == rte_get_master_lcore()) {
2655 printf("lcore %u cannot be masked on for running "
2656 "packet forwarding, which is the master lcore "
2657 "and reserved for command line parsing only\n",
2662 fwd_lcores_cpuids[i] = lcore_cpuid;
2664 if (record_now == 0) {
2668 nb_cfg_lcores = (lcoreid_t) nb_lc;
2669 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2670 printf("previous number of forwarding cores %u - changed to "
2671 "number of configured cores %u\n",
2672 (unsigned int) nb_fwd_lcores, nb_lc);
2673 nb_fwd_lcores = (lcoreid_t) nb_lc;
2680 set_fwd_lcores_mask(uint64_t lcoremask)
2682 unsigned int lcorelist[64];
2686 if (lcoremask == 0) {
2687 printf("Invalid NULL mask of cores\n");
2691 for (i = 0; i < 64; i++) {
2692 if (! ((uint64_t)(1ULL << i) & lcoremask))
2694 lcorelist[nb_lc++] = i;
2696 return set_fwd_lcores_list(lcorelist, nb_lc);
2700 set_fwd_lcores_number(uint16_t nb_lc)
2702 if (nb_lc > nb_cfg_lcores) {
2703 printf("nb fwd cores %u > %u (max. number of configured "
2704 "lcores) - ignored\n",
2705 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2708 nb_fwd_lcores = (lcoreid_t) nb_lc;
2709 printf("Number of forwarding cores set to %u\n",
2710 (unsigned int) nb_fwd_lcores);
2714 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2722 for (i = 0; i < nb_pt; i++) {
2723 port_id = (portid_t) portlist[i];
2724 if (port_id_is_invalid(port_id, ENABLED_WARN))
2727 fwd_ports_ids[i] = port_id;
2729 if (record_now == 0) {
2733 nb_cfg_ports = (portid_t) nb_pt;
2734 if (nb_fwd_ports != (portid_t) nb_pt) {
2735 printf("previous number of forwarding ports %u - changed to "
2736 "number of configured ports %u\n",
2737 (unsigned int) nb_fwd_ports, nb_pt);
2738 nb_fwd_ports = (portid_t) nb_pt;
2743 * Parse the user input and obtain the list of forwarding ports
2746 * String containing the user input. User can specify
2747 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
2748 * For example, if the user wants to use all the available
2749 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
2750 * If the user wants to use only the ports 1,2 then the input
2752 * valid characters are '-' and ','
2753 * @param[out] values
2754 * This array will be filled with a list of port IDs
2755 * based on the user input
2756 * Note that duplicate entries are discarded and only the first
2757 * count entries in this array are port IDs and all the rest
2758 * will contain default values
2759 * @param[in] maxsize
2760 * This parameter denotes 2 things
2761 * 1) Number of elements in the values array
2762 * 2) Maximum value of each element in the values array
2764 * On success, returns total count of parsed port IDs
2765 * On failure, returns 0
2768 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
2770 unsigned int count = 0;
2774 unsigned int marked[maxsize];
2776 if (list == NULL || values == NULL)
2779 for (i = 0; i < (int)maxsize; i++)
2785 /*Remove the blank spaces if any*/
2786 while (isblank(*list))
2791 value = strtol(list, &end, 10);
2792 if (errno || end == NULL)
2794 if (value < 0 || value >= (int)maxsize)
2796 while (isblank(*end))
2798 if (*end == '-' && min == INT_MAX) {
2800 } else if ((*end == ',') || (*end == '\0')) {
2804 for (i = min; i <= max; i++) {
2805 if (count < maxsize) {
2817 } while (*end != '\0');
2823 parse_fwd_portlist(const char *portlist)
2825 unsigned int portcount;
2826 unsigned int portindex[RTE_MAX_ETHPORTS];
2827 unsigned int i, valid_port_count = 0;
2829 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
2831 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
2834 * Here we verify the validity of the ports
2835 * and thereby calculate the total number of
2838 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
2839 if (rte_eth_dev_is_valid_port(portindex[i])) {
2840 portindex[valid_port_count] = portindex[i];
2845 set_fwd_ports_list(portindex, valid_port_count);
2849 set_fwd_ports_mask(uint64_t portmask)
2851 unsigned int portlist[64];
2855 if (portmask == 0) {
2856 printf("Invalid NULL mask of ports\n");
2860 RTE_ETH_FOREACH_DEV(i) {
2861 if (! ((uint64_t)(1ULL << i) & portmask))
2863 portlist[nb_pt++] = i;
2865 set_fwd_ports_list(portlist, nb_pt);
2869 set_fwd_ports_number(uint16_t nb_pt)
2871 if (nb_pt > nb_cfg_ports) {
2872 printf("nb fwd ports %u > %u (number of configured "
2873 "ports) - ignored\n",
2874 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2877 nb_fwd_ports = (portid_t) nb_pt;
2878 printf("Number of forwarding ports set to %u\n",
2879 (unsigned int) nb_fwd_ports);
2883 port_is_forwarding(portid_t port_id)
2887 if (port_id_is_invalid(port_id, ENABLED_WARN))
2890 for (i = 0; i < nb_fwd_ports; i++) {
2891 if (fwd_ports_ids[i] == port_id)
2899 set_nb_pkt_per_burst(uint16_t nb)
2901 if (nb > MAX_PKT_BURST) {
2902 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2904 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2907 nb_pkt_per_burst = nb;
2908 printf("Number of packets per burst set to %u\n",
2909 (unsigned int) nb_pkt_per_burst);
2913 tx_split_get_name(enum tx_pkt_split split)
2917 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2918 if (tx_split_name[i].split == split)
2919 return tx_split_name[i].name;
2925 set_tx_pkt_split(const char *name)
2929 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2930 if (strcmp(tx_split_name[i].name, name) == 0) {
2931 tx_pkt_split = tx_split_name[i].split;
2935 printf("unknown value: \"%s\"\n", name);
2939 show_tx_pkt_segments(void)
2945 split = tx_split_get_name(tx_pkt_split);
2947 printf("Number of segments: %u\n", n);
2948 printf("Segment sizes: ");
2949 for (i = 0; i != n - 1; i++)
2950 printf("%hu,", tx_pkt_seg_lengths[i]);
2951 printf("%hu\n", tx_pkt_seg_lengths[i]);
2952 printf("Split packet: %s\n", split);
2956 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2958 uint16_t tx_pkt_len;
2961 if (nb_segs >= (unsigned) nb_txd) {
2962 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2963 nb_segs, (unsigned int) nb_txd);
2968 * Check that each segment length is greater or equal than
2969 * the mbuf data sise.
2970 * Check also that the total packet length is greater or equal than the
2971 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
2975 for (i = 0; i < nb_segs; i++) {
2976 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2977 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2978 i, seg_lengths[i], (unsigned) mbuf_data_size);
2981 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2983 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
2984 printf("total packet length=%u < %d - give up\n",
2985 (unsigned) tx_pkt_len,
2986 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
2990 for (i = 0; i < nb_segs; i++)
2991 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2993 tx_pkt_length = tx_pkt_len;
2994 tx_pkt_nb_segs = (uint8_t) nb_segs;
2998 setup_gro(const char *onoff, portid_t port_id)
3000 if (!rte_eth_dev_is_valid_port(port_id)) {
3001 printf("invalid port id %u\n", port_id);
3004 if (test_done == 0) {
3005 printf("Before enable/disable GRO,"
3006 " please stop forwarding first\n");
3009 if (strcmp(onoff, "on") == 0) {
3010 if (gro_ports[port_id].enable != 0) {
3011 printf("Port %u has enabled GRO. Please"
3012 " disable GRO first\n", port_id);
3015 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3016 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
3017 gro_ports[port_id].param.max_flow_num =
3018 GRO_DEFAULT_FLOW_NUM;
3019 gro_ports[port_id].param.max_item_per_flow =
3020 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
3022 gro_ports[port_id].enable = 1;
3024 if (gro_ports[port_id].enable == 0) {
3025 printf("Port %u has disabled GRO\n", port_id);
3028 gro_ports[port_id].enable = 0;
3033 setup_gro_flush_cycles(uint8_t cycles)
3035 if (test_done == 0) {
3036 printf("Before change flush interval for GRO,"
3037 " please stop forwarding first.\n");
3041 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
3042 GRO_DEFAULT_FLUSH_CYCLES) {
3043 printf("The flushing cycle be in the range"
3044 " of 1 to %u. Revert to the default"
3046 GRO_MAX_FLUSH_CYCLES,
3047 GRO_DEFAULT_FLUSH_CYCLES);
3048 cycles = GRO_DEFAULT_FLUSH_CYCLES;
3051 gro_flush_cycles = cycles;
3055 show_gro(portid_t port_id)
3057 struct rte_gro_param *param;
3058 uint32_t max_pkts_num;
3060 param = &gro_ports[port_id].param;
3062 if (!rte_eth_dev_is_valid_port(port_id)) {
3063 printf("Invalid port id %u.\n", port_id);
3066 if (gro_ports[port_id].enable) {
3067 printf("GRO type: TCP/IPv4\n");
3068 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3069 max_pkts_num = param->max_flow_num *
3070 param->max_item_per_flow;
3072 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
3073 printf("Max number of packets to perform GRO: %u\n",
3075 printf("Flushing cycles: %u\n", gro_flush_cycles);
3077 printf("Port %u doesn't enable GRO.\n", port_id);
3081 setup_gso(const char *mode, portid_t port_id)
3083 if (!rte_eth_dev_is_valid_port(port_id)) {
3084 printf("invalid port id %u\n", port_id);
3087 if (strcmp(mode, "on") == 0) {
3088 if (test_done == 0) {
3089 printf("before enabling GSO,"
3090 " please stop forwarding first\n");
3093 gso_ports[port_id].enable = 1;
3094 } else if (strcmp(mode, "off") == 0) {
3095 if (test_done == 0) {
3096 printf("before disabling GSO,"
3097 " please stop forwarding first\n");
3100 gso_ports[port_id].enable = 0;
3105 list_pkt_forwarding_modes(void)
3107 static char fwd_modes[128] = "";
3108 const char *separator = "|";
3109 struct fwd_engine *fwd_eng;
3112 if (strlen (fwd_modes) == 0) {
3113 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3114 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3115 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3116 strncat(fwd_modes, separator,
3117 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3119 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3126 list_pkt_forwarding_retry_modes(void)
3128 static char fwd_modes[128] = "";
3129 const char *separator = "|";
3130 struct fwd_engine *fwd_eng;
3133 if (strlen(fwd_modes) == 0) {
3134 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3135 if (fwd_eng == &rx_only_engine)
3137 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3139 strlen(fwd_modes) - 1);
3140 strncat(fwd_modes, separator,
3142 strlen(fwd_modes) - 1);
3144 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3151 set_pkt_forwarding_mode(const char *fwd_mode_name)
3153 struct fwd_engine *fwd_eng;
3157 while ((fwd_eng = fwd_engines[i]) != NULL) {
3158 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
3159 printf("Set %s packet forwarding mode%s\n",
3161 retry_enabled == 0 ? "" : " with retry");
3162 cur_fwd_eng = fwd_eng;
3167 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
3171 add_rx_dump_callbacks(portid_t portid)
3173 struct rte_eth_dev_info dev_info;
3177 if (port_id_is_invalid(portid, ENABLED_WARN))
3180 ret = eth_dev_info_get_print_err(portid, &dev_info);
3184 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3185 if (!ports[portid].rx_dump_cb[queue])
3186 ports[portid].rx_dump_cb[queue] =
3187 rte_eth_add_rx_callback(portid, queue,
3188 dump_rx_pkts, NULL);
3192 add_tx_dump_callbacks(portid_t portid)
3194 struct rte_eth_dev_info dev_info;
3198 if (port_id_is_invalid(portid, ENABLED_WARN))
3201 ret = eth_dev_info_get_print_err(portid, &dev_info);
3205 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3206 if (!ports[portid].tx_dump_cb[queue])
3207 ports[portid].tx_dump_cb[queue] =
3208 rte_eth_add_tx_callback(portid, queue,
3209 dump_tx_pkts, NULL);
3213 remove_rx_dump_callbacks(portid_t portid)
3215 struct rte_eth_dev_info dev_info;
3219 if (port_id_is_invalid(portid, ENABLED_WARN))
3222 ret = eth_dev_info_get_print_err(portid, &dev_info);
3226 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3227 if (ports[portid].rx_dump_cb[queue]) {
3228 rte_eth_remove_rx_callback(portid, queue,
3229 ports[portid].rx_dump_cb[queue]);
3230 ports[portid].rx_dump_cb[queue] = NULL;
3235 remove_tx_dump_callbacks(portid_t portid)
3237 struct rte_eth_dev_info dev_info;
3241 if (port_id_is_invalid(portid, ENABLED_WARN))
3244 ret = eth_dev_info_get_print_err(portid, &dev_info);
3248 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3249 if (ports[portid].tx_dump_cb[queue]) {
3250 rte_eth_remove_tx_callback(portid, queue,
3251 ports[portid].tx_dump_cb[queue]);
3252 ports[portid].tx_dump_cb[queue] = NULL;
3257 configure_rxtx_dump_callbacks(uint16_t verbose)
3261 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3262 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
3266 RTE_ETH_FOREACH_DEV(portid)
3268 if (verbose == 1 || verbose > 2)
3269 add_rx_dump_callbacks(portid);
3271 remove_rx_dump_callbacks(portid);
3273 add_tx_dump_callbacks(portid);
3275 remove_tx_dump_callbacks(portid);
3280 set_verbose_level(uint16_t vb_level)
3282 printf("Change verbose level from %u to %u\n",
3283 (unsigned int) verbose_level, (unsigned int) vb_level);
3284 verbose_level = vb_level;
3285 configure_rxtx_dump_callbacks(verbose_level);
3289 vlan_extend_set(portid_t port_id, int on)
3293 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3295 if (port_id_is_invalid(port_id, ENABLED_WARN))
3298 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3301 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
3302 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3304 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
3305 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3308 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3310 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
3311 "diag=%d\n", port_id, on, diag);
3312 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3316 rx_vlan_strip_set(portid_t port_id, int on)
3320 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3322 if (port_id_is_invalid(port_id, ENABLED_WARN))
3325 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3328 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
3329 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3331 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
3332 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3335 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3337 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
3338 "diag=%d\n", port_id, on, diag);
3339 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3343 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
3347 if (port_id_is_invalid(port_id, ENABLED_WARN))
3350 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
3352 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
3353 "diag=%d\n", port_id, queue_id, on, diag);
3357 rx_vlan_filter_set(portid_t port_id, int on)
3361 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3363 if (port_id_is_invalid(port_id, ENABLED_WARN))
3366 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3369 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
3370 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3372 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
3373 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3376 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3378 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
3379 "diag=%d\n", port_id, on, diag);
3380 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3384 rx_vlan_qinq_strip_set(portid_t port_id, int on)
3388 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3390 if (port_id_is_invalid(port_id, ENABLED_WARN))
3393 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3396 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
3397 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3399 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
3400 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3403 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3405 printf("%s(port_pi=%d, on=%d) failed "
3406 "diag=%d\n", __func__, port_id, on, diag);
3407 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3411 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
3415 if (port_id_is_invalid(port_id, ENABLED_WARN))
3417 if (vlan_id_is_invalid(vlan_id))
3419 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
3422 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
3424 port_id, vlan_id, on, diag);
3429 rx_vlan_all_filter_set(portid_t port_id, int on)
3433 if (port_id_is_invalid(port_id, ENABLED_WARN))
3435 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
3436 if (rx_vft_set(port_id, vlan_id, on))
3442 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
3446 if (port_id_is_invalid(port_id, ENABLED_WARN))
3449 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
3453 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
3455 port_id, vlan_type, tp_id, diag);
3459 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
3461 struct rte_eth_dev_info dev_info;
3464 if (port_id_is_invalid(port_id, ENABLED_WARN))
3466 if (vlan_id_is_invalid(vlan_id))
3469 if (ports[port_id].dev_conf.txmode.offloads &
3470 DEV_TX_OFFLOAD_QINQ_INSERT) {
3471 printf("Error, as QinQ has been enabled.\n");
3475 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3479 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
3480 printf("Error: vlan insert is not supported by port %d\n",
3485 tx_vlan_reset(port_id);
3486 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
3487 ports[port_id].tx_vlan_id = vlan_id;
3491 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
3493 struct rte_eth_dev_info dev_info;
3496 if (port_id_is_invalid(port_id, ENABLED_WARN))
3498 if (vlan_id_is_invalid(vlan_id))
3500 if (vlan_id_is_invalid(vlan_id_outer))
3503 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3507 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
3508 printf("Error: qinq insert not supported by port %d\n",
3513 tx_vlan_reset(port_id);
3514 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
3515 DEV_TX_OFFLOAD_QINQ_INSERT);
3516 ports[port_id].tx_vlan_id = vlan_id;
3517 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
3521 tx_vlan_reset(portid_t port_id)
3523 if (port_id_is_invalid(port_id, ENABLED_WARN))
3525 ports[port_id].dev_conf.txmode.offloads &=
3526 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
3527 DEV_TX_OFFLOAD_QINQ_INSERT);
3528 ports[port_id].tx_vlan_id = 0;
3529 ports[port_id].tx_vlan_id_outer = 0;
3533 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
3535 if (port_id_is_invalid(port_id, ENABLED_WARN))
3538 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
3542 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
3545 uint8_t existing_mapping_found = 0;
3547 if (port_id_is_invalid(port_id, ENABLED_WARN))
3550 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
3553 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
3554 printf("map_value not in required range 0..%d\n",
3555 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
3559 if (!is_rx) { /*then tx*/
3560 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3561 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3562 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
3563 tx_queue_stats_mappings[i].stats_counter_id = map_value;
3564 existing_mapping_found = 1;
3568 if (!existing_mapping_found) { /* A new additional mapping... */
3569 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
3570 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
3571 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
3572 nb_tx_queue_stats_mappings++;
3576 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3577 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3578 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
3579 rx_queue_stats_mappings[i].stats_counter_id = map_value;
3580 existing_mapping_found = 1;
3584 if (!existing_mapping_found) { /* A new additional mapping... */
3585 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
3586 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
3587 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
3588 nb_rx_queue_stats_mappings++;
3594 set_xstats_hide_zero(uint8_t on_off)
3596 xstats_hide_zero = on_off;
3600 print_fdir_mask(struct rte_eth_fdir_masks *mask)
3602 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
3604 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3605 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
3606 " tunnel_id: 0x%08x",
3607 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
3608 rte_be_to_cpu_32(mask->tunnel_id_mask));
3609 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3610 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
3611 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
3612 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
3614 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
3615 rte_be_to_cpu_16(mask->src_port_mask),
3616 rte_be_to_cpu_16(mask->dst_port_mask));
3618 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3619 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
3620 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3621 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3622 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3624 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3625 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3626 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3627 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3628 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3635 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3637 struct rte_eth_flex_payload_cfg *cfg;
3640 for (i = 0; i < flex_conf->nb_payloads; i++) {
3641 cfg = &flex_conf->flex_set[i];
3642 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3644 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3645 printf("\n L2_PAYLOAD: ");
3646 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3647 printf("\n L3_PAYLOAD: ");
3648 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3649 printf("\n L4_PAYLOAD: ");
3651 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3652 for (j = 0; j < num; j++)
3653 printf(" %-5u", cfg->src_offset[j]);
3659 flowtype_to_str(uint16_t flow_type)
3661 struct flow_type_info {
3667 static struct flow_type_info flowtype_str_table[] = {
3668 {"raw", RTE_ETH_FLOW_RAW},
3669 {"ipv4", RTE_ETH_FLOW_IPV4},
3670 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3671 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3672 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3673 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3674 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3675 {"ipv6", RTE_ETH_FLOW_IPV6},
3676 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3677 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3678 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3679 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3680 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3681 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3682 {"port", RTE_ETH_FLOW_PORT},
3683 {"vxlan", RTE_ETH_FLOW_VXLAN},
3684 {"geneve", RTE_ETH_FLOW_GENEVE},
3685 {"nvgre", RTE_ETH_FLOW_NVGRE},
3686 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
3689 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3690 if (flowtype_str_table[i].ftype == flow_type)
3691 return flowtype_str_table[i].str;
3698 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3700 struct rte_eth_fdir_flex_mask *mask;
3704 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3705 mask = &flex_conf->flex_mask[i];
3706 p = flowtype_to_str(mask->flow_type);
3707 printf("\n %s:\t", p ? p : "unknown");
3708 for (j = 0; j < num; j++)
3709 printf(" %02x", mask->mask[j]);
3715 print_fdir_flow_type(uint32_t flow_types_mask)
3720 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3721 if (!(flow_types_mask & (1 << i)))
3723 p = flowtype_to_str(i);
3733 fdir_get_infos(portid_t port_id)
3735 struct rte_eth_fdir_stats fdir_stat;
3736 struct rte_eth_fdir_info fdir_info;
3739 static const char *fdir_stats_border = "########################";
3741 if (port_id_is_invalid(port_id, ENABLED_WARN))
3743 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3745 printf("\n FDIR is not supported on port %-2d\n",
3750 memset(&fdir_info, 0, sizeof(fdir_info));
3751 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3752 RTE_ETH_FILTER_INFO, &fdir_info);
3753 memset(&fdir_stat, 0, sizeof(fdir_stat));
3754 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3755 RTE_ETH_FILTER_STATS, &fdir_stat);
3756 printf("\n %s FDIR infos for port %-2d %s\n",
3757 fdir_stats_border, port_id, fdir_stats_border);
3759 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3760 printf(" PERFECT\n");
3761 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3762 printf(" PERFECT-MAC-VLAN\n");
3763 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3764 printf(" PERFECT-TUNNEL\n");
3765 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3766 printf(" SIGNATURE\n");
3768 printf(" DISABLE\n");
3769 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3770 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3771 printf(" SUPPORTED FLOW TYPE: ");
3772 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3774 printf(" FLEX PAYLOAD INFO:\n");
3775 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3776 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3777 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3778 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3779 fdir_info.flex_payload_unit,
3780 fdir_info.max_flex_payload_segment_num,
3781 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3783 print_fdir_mask(&fdir_info.mask);
3784 if (fdir_info.flex_conf.nb_payloads > 0) {
3785 printf(" FLEX PAYLOAD SRC OFFSET:");
3786 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3788 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3789 printf(" FLEX MASK CFG:");
3790 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3792 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3793 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3794 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3795 fdir_info.guarant_spc, fdir_info.best_spc);
3796 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3797 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3798 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3799 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3800 fdir_stat.collision, fdir_stat.free,
3801 fdir_stat.maxhash, fdir_stat.maxlen,
3802 fdir_stat.add, fdir_stat.remove,
3803 fdir_stat.f_add, fdir_stat.f_remove);
3804 printf(" %s############################%s\n",
3805 fdir_stats_border, fdir_stats_border);
3809 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3811 struct rte_port *port;
3812 struct rte_eth_fdir_flex_conf *flex_conf;
3815 port = &ports[port_id];
3816 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3817 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3818 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3823 if (i >= RTE_ETH_FLOW_MAX) {
3824 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3825 idx = flex_conf->nb_flexmasks;
3826 flex_conf->nb_flexmasks++;
3828 printf("The flex mask table is full. Can not set flex"
3829 " mask for flow_type(%u).", cfg->flow_type);
3833 rte_memcpy(&flex_conf->flex_mask[idx],
3835 sizeof(struct rte_eth_fdir_flex_mask));
3839 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3841 struct rte_port *port;
3842 struct rte_eth_fdir_flex_conf *flex_conf;
3845 port = &ports[port_id];
3846 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3847 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3848 if (cfg->type == flex_conf->flex_set[i].type) {
3853 if (i >= RTE_ETH_PAYLOAD_MAX) {
3854 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3855 idx = flex_conf->nb_payloads;
3856 flex_conf->nb_payloads++;
3858 printf("The flex payload table is full. Can not set"
3859 " flex payload for type(%u).", cfg->type);
3863 rte_memcpy(&flex_conf->flex_set[idx],
3865 sizeof(struct rte_eth_flex_payload_cfg));
3870 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3872 #ifdef RTE_LIBRTE_IXGBE_PMD
3876 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3878 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3882 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3883 is_rx ? "rx" : "tx", port_id, diag);
3886 printf("VF %s setting not supported for port %d\n",
3887 is_rx ? "Rx" : "Tx", port_id);
3893 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3896 struct rte_eth_link link;
3899 if (port_id_is_invalid(port_id, ENABLED_WARN))
3901 ret = eth_link_get_nowait_print_err(port_id, &link);
3904 if (rate > link.link_speed) {
3905 printf("Invalid rate value:%u bigger than link speed: %u\n",
3906 rate, link.link_speed);
3909 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3912 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3918 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3920 int diag = -ENOTSUP;
3924 RTE_SET_USED(q_msk);
3926 #ifdef RTE_LIBRTE_IXGBE_PMD
3927 if (diag == -ENOTSUP)
3928 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3931 #ifdef RTE_LIBRTE_BNXT_PMD
3932 if (diag == -ENOTSUP)
3933 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3938 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3944 * Functions to manage the set of filtered Multicast MAC addresses.
3946 * A pool of filtered multicast MAC addresses is associated with each port.
3947 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3948 * The address of the pool and the number of valid multicast MAC addresses
3949 * recorded in the pool are stored in the fields "mc_addr_pool" and
3950 * "mc_addr_nb" of the "rte_port" data structure.
3952 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3953 * to be supplied a contiguous array of multicast MAC addresses.
3954 * To comply with this constraint, the set of multicast addresses recorded
3955 * into the pool are systematically compacted at the beginning of the pool.
3956 * Hence, when a multicast address is removed from the pool, all following
3957 * addresses, if any, are copied back to keep the set contiguous.
3959 #define MCAST_POOL_INC 32
3962 mcast_addr_pool_extend(struct rte_port *port)
3964 struct rte_ether_addr *mc_pool;
3965 size_t mc_pool_size;
3968 * If a free entry is available at the end of the pool, just
3969 * increment the number of recorded multicast addresses.
3971 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3977 * [re]allocate a pool with MCAST_POOL_INC more entries.
3978 * The previous test guarantees that port->mc_addr_nb is a multiple
3979 * of MCAST_POOL_INC.
3981 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
3983 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
3985 if (mc_pool == NULL) {
3986 printf("allocation of pool of %u multicast addresses failed\n",
3987 port->mc_addr_nb + MCAST_POOL_INC);
3991 port->mc_addr_pool = mc_pool;
3998 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
4000 if (mcast_addr_pool_extend(port) != 0)
4002 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
4006 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
4009 if (addr_idx == port->mc_addr_nb) {
4010 /* No need to recompact the set of multicast addressses. */
4011 if (port->mc_addr_nb == 0) {
4012 /* free the pool of multicast addresses. */
4013 free(port->mc_addr_pool);
4014 port->mc_addr_pool = NULL;
4018 memmove(&port->mc_addr_pool[addr_idx],
4019 &port->mc_addr_pool[addr_idx + 1],
4020 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
4024 eth_port_multicast_addr_list_set(portid_t port_id)
4026 struct rte_port *port;
4029 port = &ports[port_id];
4030 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
4033 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
4034 port_id, port->mc_addr_nb, diag);
4040 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
4042 struct rte_port *port;
4045 if (port_id_is_invalid(port_id, ENABLED_WARN))
4048 port = &ports[port_id];
4051 * Check that the added multicast MAC address is not already recorded
4052 * in the pool of multicast addresses.
4054 for (i = 0; i < port->mc_addr_nb; i++) {
4055 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
4056 printf("multicast address already filtered by port\n");
4061 mcast_addr_pool_append(port, mc_addr);
4062 if (eth_port_multicast_addr_list_set(port_id) < 0)
4063 /* Rollback on failure, remove the address from the pool */
4064 mcast_addr_pool_remove(port, i);
4068 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
4070 struct rte_port *port;
4073 if (port_id_is_invalid(port_id, ENABLED_WARN))
4076 port = &ports[port_id];
4079 * Search the pool of multicast MAC addresses for the removed address.
4081 for (i = 0; i < port->mc_addr_nb; i++) {
4082 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
4085 if (i == port->mc_addr_nb) {
4086 printf("multicast address not filtered by port %d\n", port_id);
4090 mcast_addr_pool_remove(port, i);
4091 if (eth_port_multicast_addr_list_set(port_id) < 0)
4092 /* Rollback on failure, add the address back into the pool */
4093 mcast_addr_pool_append(port, mc_addr);
4097 port_dcb_info_display(portid_t port_id)
4099 struct rte_eth_dcb_info dcb_info;
4102 static const char *border = "================";
4104 if (port_id_is_invalid(port_id, ENABLED_WARN))
4107 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
4109 printf("\n Failed to get dcb infos on port %-2d\n",
4113 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
4114 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
4116 for (i = 0; i < dcb_info.nb_tcs; i++)
4118 printf("\n Priority : ");
4119 for (i = 0; i < dcb_info.nb_tcs; i++)
4120 printf("\t%4d", dcb_info.prio_tc[i]);
4121 printf("\n BW percent :");
4122 for (i = 0; i < dcb_info.nb_tcs; i++)
4123 printf("\t%4d%%", dcb_info.tc_bws[i]);
4124 printf("\n RXQ base : ");
4125 for (i = 0; i < dcb_info.nb_tcs; i++)
4126 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
4127 printf("\n RXQ number :");
4128 for (i = 0; i < dcb_info.nb_tcs; i++)
4129 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
4130 printf("\n TXQ base : ");
4131 for (i = 0; i < dcb_info.nb_tcs; i++)
4132 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
4133 printf("\n TXQ number :");
4134 for (i = 0; i < dcb_info.nb_tcs; i++)
4135 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
4140 open_file(const char *file_path, uint32_t *size)
4142 int fd = open(file_path, O_RDONLY);
4144 uint8_t *buf = NULL;
4152 printf("%s: Failed to open %s\n", __func__, file_path);
4156 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
4158 printf("%s: File operations failed\n", __func__);
4162 pkg_size = st_buf.st_size;
4165 printf("%s: File operations failed\n", __func__);
4169 buf = (uint8_t *)malloc(pkg_size);
4172 printf("%s: Failed to malloc memory\n", __func__);
4176 ret = read(fd, buf, pkg_size);
4179 printf("%s: File read operation failed\n", __func__);
4193 save_file(const char *file_path, uint8_t *buf, uint32_t size)
4195 FILE *fh = fopen(file_path, "wb");
4198 printf("%s: Failed to open %s\n", __func__, file_path);
4202 if (fwrite(buf, 1, size, fh) != size) {
4204 printf("%s: File write operation failed\n", __func__);
4214 close_file(uint8_t *buf)
4225 port_queue_region_info_display(portid_t port_id, void *buf)
4227 #ifdef RTE_LIBRTE_I40E_PMD
4229 struct rte_pmd_i40e_queue_regions *info =
4230 (struct rte_pmd_i40e_queue_regions *)buf;
4231 static const char *queue_region_info_stats_border = "-------";
4233 if (!info->queue_region_number)
4234 printf("there is no region has been set before");
4236 printf("\n %s All queue region info for port=%2d %s",
4237 queue_region_info_stats_border, port_id,
4238 queue_region_info_stats_border);
4239 printf("\n queue_region_number: %-14u \n",
4240 info->queue_region_number);
4242 for (i = 0; i < info->queue_region_number; i++) {
4243 printf("\n region_id: %-14u queue_number: %-14u "
4244 "queue_start_index: %-14u \n",
4245 info->region[i].region_id,
4246 info->region[i].queue_num,
4247 info->region[i].queue_start_index);
4249 printf(" user_priority_num is %-14u :",
4250 info->region[i].user_priority_num);
4251 for (j = 0; j < info->region[i].user_priority_num; j++)
4252 printf(" %-14u ", info->region[i].user_priority[j]);
4254 printf("\n flowtype_num is %-14u :",
4255 info->region[i].flowtype_num);
4256 for (j = 0; j < info->region[i].flowtype_num; j++)
4257 printf(" %-14u ", info->region[i].hw_flowtype[j]);
4260 RTE_SET_USED(port_id);
4268 show_macs(portid_t port_id)
4270 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4271 struct rte_eth_dev_info dev_info;
4272 struct rte_ether_addr *addr;
4273 uint32_t i, num_macs = 0;
4274 struct rte_eth_dev *dev;
4276 dev = &rte_eth_devices[port_id];
4278 rte_eth_dev_info_get(port_id, &dev_info);
4280 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4281 addr = &dev->data->mac_addrs[i];
4283 /* skip zero address */
4284 if (rte_is_zero_ether_addr(addr))
4290 printf("Number of MAC address added: %d\n", num_macs);
4292 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4293 addr = &dev->data->mac_addrs[i];
4295 /* skip zero address */
4296 if (rte_is_zero_ether_addr(addr))
4299 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4300 printf(" %s\n", buf);
4305 show_mcast_macs(portid_t port_id)
4307 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4308 struct rte_ether_addr *addr;
4309 struct rte_port *port;
4312 port = &ports[port_id];
4314 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
4316 for (i = 0; i < port->mc_addr_nb; i++) {
4317 addr = &port->mc_addr_pool[i];
4319 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4320 printf(" %s\n", buf);