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 },
121 { "pppoe", ETH_RSS_PPPOE },
126 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
128 char buf[RTE_ETHER_ADDR_FMT_SIZE];
129 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
130 printf("%s%s", name, buf);
134 nic_stats_display(portid_t port_id)
136 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
137 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
138 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
139 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
140 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
141 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
143 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
144 struct rte_eth_stats stats;
145 struct rte_port *port = &ports[port_id];
148 static const char *nic_stats_border = "########################";
150 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
154 rte_eth_stats_get(port_id, &stats);
155 printf("\n %s NIC statistics for port %-2d %s\n",
156 nic_stats_border, port_id, nic_stats_border);
158 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
159 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
161 stats.ipackets, stats.imissed, stats.ibytes);
162 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
163 printf(" RX-nombuf: %-10"PRIu64"\n",
165 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
167 stats.opackets, stats.oerrors, stats.obytes);
170 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
171 " RX-bytes: %10"PRIu64"\n",
172 stats.ipackets, stats.ierrors, stats.ibytes);
173 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
174 printf(" RX-nombuf: %10"PRIu64"\n",
176 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
177 " TX-bytes: %10"PRIu64"\n",
178 stats.opackets, stats.oerrors, stats.obytes);
181 if (port->rx_queue_stats_mapping_enabled) {
183 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
184 printf(" Stats reg %2d RX-packets: %10"PRIu64
185 " RX-errors: %10"PRIu64
186 " RX-bytes: %10"PRIu64"\n",
187 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
190 if (port->tx_queue_stats_mapping_enabled) {
192 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
193 printf(" Stats reg %2d TX-packets: %10"PRIu64
194 " TX-bytes: %10"PRIu64"\n",
195 i, stats.q_opackets[i], stats.q_obytes[i]);
199 diff_cycles = prev_cycles[port_id];
200 prev_cycles[port_id] = rte_rdtsc();
202 diff_cycles = prev_cycles[port_id] - diff_cycles;
204 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
205 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
206 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
207 (stats.opackets - prev_pkts_tx[port_id]) : 0;
208 prev_pkts_rx[port_id] = stats.ipackets;
209 prev_pkts_tx[port_id] = stats.opackets;
210 mpps_rx = diff_cycles > 0 ?
211 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
212 mpps_tx = diff_cycles > 0 ?
213 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
215 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
216 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
217 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
218 (stats.obytes - prev_bytes_tx[port_id]) : 0;
219 prev_bytes_rx[port_id] = stats.ibytes;
220 prev_bytes_tx[port_id] = stats.obytes;
221 mbps_rx = diff_cycles > 0 ?
222 diff_bytes_rx * rte_get_tsc_hz() / diff_cycles : 0;
223 mbps_tx = diff_cycles > 0 ?
224 diff_bytes_tx * rte_get_tsc_hz() / diff_cycles : 0;
226 printf("\n Throughput (since last show)\n");
227 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
228 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
229 mpps_tx, mbps_tx * 8);
231 printf(" %s############################%s\n",
232 nic_stats_border, nic_stats_border);
236 nic_stats_clear(portid_t port_id)
240 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
245 ret = rte_eth_stats_reset(port_id);
247 printf("%s: Error: failed to reset stats (port %u): %s",
248 __func__, port_id, strerror(-ret));
252 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
256 printf("%s: Error: failed to get stats (port %u): %s",
257 __func__, port_id, strerror(ret));
260 printf("\n NIC statistics for port %d cleared\n", port_id);
264 nic_xstats_display(portid_t port_id)
266 struct rte_eth_xstat *xstats;
267 int cnt_xstats, idx_xstat;
268 struct rte_eth_xstat_name *xstats_names;
270 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
274 printf("###### NIC extended statistics for port %-2d\n", port_id);
275 if (!rte_eth_dev_is_valid_port(port_id)) {
276 printf("Error: Invalid port number %i\n", port_id);
281 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
282 if (cnt_xstats < 0) {
283 printf("Error: Cannot get count of xstats\n");
287 /* Get id-name lookup table */
288 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
289 if (xstats_names == NULL) {
290 printf("Cannot allocate memory for xstats lookup\n");
293 if (cnt_xstats != rte_eth_xstats_get_names(
294 port_id, xstats_names, cnt_xstats)) {
295 printf("Error: Cannot get xstats lookup\n");
300 /* Get stats themselves */
301 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
302 if (xstats == NULL) {
303 printf("Cannot allocate memory for xstats\n");
307 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
308 printf("Error: Unable to get xstats\n");
315 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
316 if (xstats_hide_zero && !xstats[idx_xstat].value)
318 printf("%s: %"PRIu64"\n",
319 xstats_names[idx_xstat].name,
320 xstats[idx_xstat].value);
327 nic_xstats_clear(portid_t port_id)
331 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
336 ret = rte_eth_xstats_reset(port_id);
338 printf("%s: Error: failed to reset xstats (port %u): %s",
339 __func__, port_id, strerror(-ret));
343 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
347 printf("%s: Error: failed to get stats (port %u): %s",
348 __func__, port_id, strerror(ret));
354 nic_stats_mapping_display(portid_t port_id)
356 struct rte_port *port = &ports[port_id];
359 static const char *nic_stats_mapping_border = "########################";
361 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
366 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
367 printf("Port id %d - either does not support queue statistic mapping or"
368 " no queue statistic mapping set\n", port_id);
372 printf("\n %s NIC statistics mapping for port %-2d %s\n",
373 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
375 if (port->rx_queue_stats_mapping_enabled) {
376 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
377 if (rx_queue_stats_mappings[i].port_id == port_id) {
378 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
379 rx_queue_stats_mappings[i].queue_id,
380 rx_queue_stats_mappings[i].stats_counter_id);
387 if (port->tx_queue_stats_mapping_enabled) {
388 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
389 if (tx_queue_stats_mappings[i].port_id == port_id) {
390 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
391 tx_queue_stats_mappings[i].queue_id,
392 tx_queue_stats_mappings[i].stats_counter_id);
397 printf(" %s####################################%s\n",
398 nic_stats_mapping_border, nic_stats_mapping_border);
402 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
404 struct rte_eth_burst_mode mode;
405 struct rte_eth_rxq_info qinfo;
407 static const char *info_border = "*********************";
409 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
411 printf("Failed to retrieve information for port: %u, "
412 "RX queue: %hu\nerror desc: %s(%d)\n",
413 port_id, queue_id, strerror(-rc), rc);
417 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
418 info_border, port_id, queue_id, info_border);
420 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
421 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
422 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
423 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
424 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
425 printf("\nRX drop packets: %s",
426 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
427 printf("\nRX deferred start: %s",
428 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
429 printf("\nRX scattered packets: %s",
430 (qinfo.scattered_rx != 0) ? "on" : "off");
431 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
433 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
434 printf("\nBurst mode: %s%s",
436 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
437 " (per queue)" : "");
443 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
445 struct rte_eth_burst_mode mode;
446 struct rte_eth_txq_info qinfo;
448 static const char *info_border = "*********************";
450 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
452 printf("Failed to retrieve information for port: %u, "
453 "TX queue: %hu\nerror desc: %s(%d)\n",
454 port_id, queue_id, strerror(-rc), rc);
458 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
459 info_border, port_id, queue_id, info_border);
461 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
462 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
463 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
464 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
465 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
466 printf("\nTX deferred start: %s",
467 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
468 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
470 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
471 printf("\nBurst mode: %s%s",
473 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
474 " (per queue)" : "");
479 static int bus_match_all(const struct rte_bus *bus, const void *data)
487 device_infos_display(const char *identifier)
489 static const char *info_border = "*********************";
490 struct rte_bus *start = NULL, *next;
491 struct rte_dev_iterator dev_iter;
492 char name[RTE_ETH_NAME_MAX_LEN];
493 struct rte_ether_addr mac_addr;
494 struct rte_device *dev;
495 struct rte_devargs da;
499 memset(&da, 0, sizeof(da));
503 if (rte_devargs_parsef(&da, "%s", identifier)) {
504 printf("cannot parse identifier\n");
511 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
514 if (identifier && da.bus != next)
517 /* Skip buses that don't have iterate method */
518 if (!next->dev_iterate)
521 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
522 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
526 /* Check for matching device if identifier is present */
528 strncmp(da.name, dev->name, strlen(dev->name)))
530 printf("\n%s Infos for device %s %s\n",
531 info_border, dev->name, info_border);
532 printf("Bus name: %s", dev->bus->name);
533 printf("\nDriver name: %s", dev->driver->name);
534 printf("\nDevargs: %s",
535 dev->devargs ? dev->devargs->args : "");
536 printf("\nConnect to socket: %d", dev->numa_node);
539 /* List ports with matching device name */
540 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
541 printf("\n\tPort id: %-2d", port_id);
542 if (eth_macaddr_get_print_err(port_id,
544 print_ethaddr("\n\tMAC address: ",
546 rte_eth_dev_get_name_by_port(port_id, name);
547 printf("\n\tDevice name: %s", name);
555 port_infos_display(portid_t port_id)
557 struct rte_port *port;
558 struct rte_ether_addr mac_addr;
559 struct rte_eth_link link;
560 struct rte_eth_dev_info dev_info;
562 struct rte_mempool * mp;
563 static const char *info_border = "*********************";
565 char name[RTE_ETH_NAME_MAX_LEN];
567 char fw_version[ETHDEV_FWVERS_LEN];
569 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
573 port = &ports[port_id];
574 ret = eth_link_get_nowait_print_err(port_id, &link);
578 ret = eth_dev_info_get_print_err(port_id, &dev_info);
582 printf("\n%s Infos for port %-2d %s\n",
583 info_border, port_id, info_border);
584 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
585 print_ethaddr("MAC address: ", &mac_addr);
586 rte_eth_dev_get_name_by_port(port_id, name);
587 printf("\nDevice name: %s", name);
588 printf("\nDriver name: %s", dev_info.driver_name);
590 if (rte_eth_dev_fw_version_get(port_id, fw_version,
591 ETHDEV_FWVERS_LEN) == 0)
592 printf("\nFirmware-version: %s", fw_version);
594 printf("\nFirmware-version: %s", "not available");
596 if (dev_info.device->devargs && dev_info.device->devargs->args)
597 printf("\nDevargs: %s", dev_info.device->devargs->args);
598 printf("\nConnect to socket: %u", port->socket_id);
600 if (port_numa[port_id] != NUMA_NO_CONFIG) {
601 mp = mbuf_pool_find(port_numa[port_id]);
603 printf("\nmemory allocation on the socket: %d",
606 printf("\nmemory allocation on the socket: %u",port->socket_id);
608 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
609 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
610 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
611 ("full-duplex") : ("half-duplex"));
613 if (!rte_eth_dev_get_mtu(port_id, &mtu))
614 printf("MTU: %u\n", mtu);
616 printf("Promiscuous mode: %s\n",
617 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
618 printf("Allmulticast mode: %s\n",
619 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
620 printf("Maximum number of MAC addresses: %u\n",
621 (unsigned int)(port->dev_info.max_mac_addrs));
622 printf("Maximum number of MAC addresses of hash filtering: %u\n",
623 (unsigned int)(port->dev_info.max_hash_mac_addrs));
625 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
626 if (vlan_offload >= 0){
627 printf("VLAN offload: \n");
628 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
629 printf(" strip on, ");
631 printf(" strip off, ");
633 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
634 printf("filter on, ");
636 printf("filter off, ");
638 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
639 printf("extend on, ");
641 printf("extend off, ");
643 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
644 printf("qinq strip on\n");
646 printf("qinq strip off\n");
649 if (dev_info.hash_key_size > 0)
650 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
651 if (dev_info.reta_size > 0)
652 printf("Redirection table size: %u\n", dev_info.reta_size);
653 if (!dev_info.flow_type_rss_offloads)
654 printf("No RSS offload flow type is supported.\n");
659 printf("Supported RSS offload flow types:\n");
660 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
661 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
662 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
664 p = flowtype_to_str(i);
668 printf(" user defined %d\n", i);
672 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
673 printf("Maximum configurable length of RX packet: %u\n",
674 dev_info.max_rx_pktlen);
675 printf("Maximum configurable size of LRO aggregated packet: %u\n",
676 dev_info.max_lro_pkt_size);
677 if (dev_info.max_vfs)
678 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
679 if (dev_info.max_vmdq_pools)
680 printf("Maximum number of VMDq pools: %u\n",
681 dev_info.max_vmdq_pools);
683 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
684 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
685 printf("Max possible number of RXDs per queue: %hu\n",
686 dev_info.rx_desc_lim.nb_max);
687 printf("Min possible number of RXDs per queue: %hu\n",
688 dev_info.rx_desc_lim.nb_min);
689 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
691 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
692 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
693 printf("Max possible number of TXDs per queue: %hu\n",
694 dev_info.tx_desc_lim.nb_max);
695 printf("Min possible number of TXDs per queue: %hu\n",
696 dev_info.tx_desc_lim.nb_min);
697 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
698 printf("Max segment number per packet: %hu\n",
699 dev_info.tx_desc_lim.nb_seg_max);
700 printf("Max segment number per MTU/TSO: %hu\n",
701 dev_info.tx_desc_lim.nb_mtu_seg_max);
703 /* Show switch info only if valid switch domain and port id is set */
704 if (dev_info.switch_info.domain_id !=
705 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
706 if (dev_info.switch_info.name)
707 printf("Switch name: %s\n", dev_info.switch_info.name);
709 printf("Switch domain Id: %u\n",
710 dev_info.switch_info.domain_id);
711 printf("Switch Port Id: %u\n",
712 dev_info.switch_info.port_id);
717 port_summary_header_display(void)
719 uint16_t port_number;
721 port_number = rte_eth_dev_count_avail();
722 printf("Number of available ports: %i\n", port_number);
723 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
724 "Driver", "Status", "Link");
728 port_summary_display(portid_t port_id)
730 struct rte_ether_addr mac_addr;
731 struct rte_eth_link link;
732 struct rte_eth_dev_info dev_info;
733 char name[RTE_ETH_NAME_MAX_LEN];
736 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
741 ret = eth_link_get_nowait_print_err(port_id, &link);
745 ret = eth_dev_info_get_print_err(port_id, &dev_info);
749 rte_eth_dev_get_name_by_port(port_id, name);
750 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
754 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
755 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
756 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
757 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
758 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
759 (unsigned int) link.link_speed);
763 port_offload_cap_display(portid_t port_id)
765 struct rte_eth_dev_info dev_info;
766 static const char *info_border = "************";
769 if (port_id_is_invalid(port_id, ENABLED_WARN))
772 ret = eth_dev_info_get_print_err(port_id, &dev_info);
776 printf("\n%s Port %d supported offload features: %s\n",
777 info_border, port_id, info_border);
779 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
780 printf("VLAN stripped: ");
781 if (ports[port_id].dev_conf.rxmode.offloads &
782 DEV_RX_OFFLOAD_VLAN_STRIP)
788 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
789 printf("Double VLANs stripped: ");
790 if (ports[port_id].dev_conf.rxmode.offloads &
791 DEV_RX_OFFLOAD_QINQ_STRIP)
797 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
798 printf("RX IPv4 checksum: ");
799 if (ports[port_id].dev_conf.rxmode.offloads &
800 DEV_RX_OFFLOAD_IPV4_CKSUM)
806 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
807 printf("RX UDP checksum: ");
808 if (ports[port_id].dev_conf.rxmode.offloads &
809 DEV_RX_OFFLOAD_UDP_CKSUM)
815 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
816 printf("RX TCP checksum: ");
817 if (ports[port_id].dev_conf.rxmode.offloads &
818 DEV_RX_OFFLOAD_TCP_CKSUM)
824 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) {
825 printf("RX SCTP checksum: ");
826 if (ports[port_id].dev_conf.rxmode.offloads &
827 DEV_RX_OFFLOAD_SCTP_CKSUM)
833 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
834 printf("RX Outer IPv4 checksum: ");
835 if (ports[port_id].dev_conf.rxmode.offloads &
836 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
842 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) {
843 printf("RX Outer UDP checksum: ");
844 if (ports[port_id].dev_conf.rxmode.offloads &
845 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM)
851 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
852 printf("Large receive offload: ");
853 if (ports[port_id].dev_conf.rxmode.offloads &
854 DEV_RX_OFFLOAD_TCP_LRO)
860 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
861 printf("HW timestamp: ");
862 if (ports[port_id].dev_conf.rxmode.offloads &
863 DEV_RX_OFFLOAD_TIMESTAMP)
869 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) {
870 printf("Rx Keep CRC: ");
871 if (ports[port_id].dev_conf.rxmode.offloads &
872 DEV_RX_OFFLOAD_KEEP_CRC)
878 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) {
879 printf("RX offload security: ");
880 if (ports[port_id].dev_conf.rxmode.offloads &
881 DEV_RX_OFFLOAD_SECURITY)
887 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
888 printf("VLAN insert: ");
889 if (ports[port_id].dev_conf.txmode.offloads &
890 DEV_TX_OFFLOAD_VLAN_INSERT)
896 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
897 printf("Double VLANs insert: ");
898 if (ports[port_id].dev_conf.txmode.offloads &
899 DEV_TX_OFFLOAD_QINQ_INSERT)
905 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
906 printf("TX IPv4 checksum: ");
907 if (ports[port_id].dev_conf.txmode.offloads &
908 DEV_TX_OFFLOAD_IPV4_CKSUM)
914 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
915 printf("TX UDP checksum: ");
916 if (ports[port_id].dev_conf.txmode.offloads &
917 DEV_TX_OFFLOAD_UDP_CKSUM)
923 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
924 printf("TX TCP checksum: ");
925 if (ports[port_id].dev_conf.txmode.offloads &
926 DEV_TX_OFFLOAD_TCP_CKSUM)
932 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
933 printf("TX SCTP checksum: ");
934 if (ports[port_id].dev_conf.txmode.offloads &
935 DEV_TX_OFFLOAD_SCTP_CKSUM)
941 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
942 printf("TX Outer IPv4 checksum: ");
943 if (ports[port_id].dev_conf.txmode.offloads &
944 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
950 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
951 printf("TX TCP segmentation: ");
952 if (ports[port_id].dev_conf.txmode.offloads &
953 DEV_TX_OFFLOAD_TCP_TSO)
959 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
960 printf("TX UDP segmentation: ");
961 if (ports[port_id].dev_conf.txmode.offloads &
962 DEV_TX_OFFLOAD_UDP_TSO)
968 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
969 printf("TSO for VXLAN tunnel packet: ");
970 if (ports[port_id].dev_conf.txmode.offloads &
971 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
977 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
978 printf("TSO for GRE tunnel packet: ");
979 if (ports[port_id].dev_conf.txmode.offloads &
980 DEV_TX_OFFLOAD_GRE_TNL_TSO)
986 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
987 printf("TSO for IPIP tunnel packet: ");
988 if (ports[port_id].dev_conf.txmode.offloads &
989 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
995 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
996 printf("TSO for GENEVE tunnel packet: ");
997 if (ports[port_id].dev_conf.txmode.offloads &
998 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
1004 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) {
1005 printf("IP tunnel TSO: ");
1006 if (ports[port_id].dev_conf.txmode.offloads &
1007 DEV_TX_OFFLOAD_IP_TNL_TSO)
1013 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) {
1014 printf("UDP tunnel TSO: ");
1015 if (ports[port_id].dev_conf.txmode.offloads &
1016 DEV_TX_OFFLOAD_UDP_TNL_TSO)
1022 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
1023 printf("TX Outer UDP checksum: ");
1024 if (ports[port_id].dev_conf.txmode.offloads &
1025 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
1034 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1038 if (port_id == (portid_t)RTE_PORT_ALL)
1041 RTE_ETH_FOREACH_DEV(pid)
1045 if (warning == ENABLED_WARN)
1046 printf("Invalid port %d\n", port_id);
1051 void print_valid_ports(void)
1055 printf("The valid ports array is [");
1056 RTE_ETH_FOREACH_DEV(pid) {
1063 vlan_id_is_invalid(uint16_t vlan_id)
1067 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1072 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1074 const struct rte_pci_device *pci_dev;
1075 const struct rte_bus *bus;
1078 if (reg_off & 0x3) {
1079 printf("Port register offset 0x%X not aligned on a 4-byte "
1085 if (!ports[port_id].dev_info.device) {
1086 printf("Invalid device\n");
1090 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1091 if (bus && !strcmp(bus->name, "pci")) {
1092 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1094 printf("Not a PCI device\n");
1098 pci_len = pci_dev->mem_resource[0].len;
1099 if (reg_off >= pci_len) {
1100 printf("Port %d: register offset %u (0x%X) out of port PCI "
1101 "resource (length=%"PRIu64")\n",
1102 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
1109 reg_bit_pos_is_invalid(uint8_t bit_pos)
1113 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
1117 #define display_port_and_reg_off(port_id, reg_off) \
1118 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1121 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1123 display_port_and_reg_off(port_id, (unsigned)reg_off);
1124 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1128 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1133 if (port_id_is_invalid(port_id, ENABLED_WARN))
1135 if (port_reg_off_is_invalid(port_id, reg_off))
1137 if (reg_bit_pos_is_invalid(bit_x))
1139 reg_v = port_id_pci_reg_read(port_id, reg_off);
1140 display_port_and_reg_off(port_id, (unsigned)reg_off);
1141 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1145 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1146 uint8_t bit1_pos, uint8_t bit2_pos)
1152 if (port_id_is_invalid(port_id, ENABLED_WARN))
1154 if (port_reg_off_is_invalid(port_id, reg_off))
1156 if (reg_bit_pos_is_invalid(bit1_pos))
1158 if (reg_bit_pos_is_invalid(bit2_pos))
1160 if (bit1_pos > bit2_pos)
1161 l_bit = bit2_pos, h_bit = bit1_pos;
1163 l_bit = bit1_pos, h_bit = bit2_pos;
1165 reg_v = port_id_pci_reg_read(port_id, reg_off);
1168 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1169 display_port_and_reg_off(port_id, (unsigned)reg_off);
1170 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1171 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1175 port_reg_display(portid_t port_id, uint32_t reg_off)
1179 if (port_id_is_invalid(port_id, ENABLED_WARN))
1181 if (port_reg_off_is_invalid(port_id, reg_off))
1183 reg_v = port_id_pci_reg_read(port_id, reg_off);
1184 display_port_reg_value(port_id, reg_off, reg_v);
1188 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1193 if (port_id_is_invalid(port_id, ENABLED_WARN))
1195 if (port_reg_off_is_invalid(port_id, reg_off))
1197 if (reg_bit_pos_is_invalid(bit_pos))
1200 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1203 reg_v = port_id_pci_reg_read(port_id, reg_off);
1205 reg_v &= ~(1 << bit_pos);
1207 reg_v |= (1 << bit_pos);
1208 port_id_pci_reg_write(port_id, reg_off, reg_v);
1209 display_port_reg_value(port_id, reg_off, reg_v);
1213 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1214 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1221 if (port_id_is_invalid(port_id, ENABLED_WARN))
1223 if (port_reg_off_is_invalid(port_id, reg_off))
1225 if (reg_bit_pos_is_invalid(bit1_pos))
1227 if (reg_bit_pos_is_invalid(bit2_pos))
1229 if (bit1_pos > bit2_pos)
1230 l_bit = bit2_pos, h_bit = bit1_pos;
1232 l_bit = bit1_pos, h_bit = bit2_pos;
1234 if ((h_bit - l_bit) < 31)
1235 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1239 if (value > max_v) {
1240 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1241 (unsigned)value, (unsigned)value,
1242 (unsigned)max_v, (unsigned)max_v);
1245 reg_v = port_id_pci_reg_read(port_id, reg_off);
1246 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1247 reg_v |= (value << l_bit); /* Set changed bits */
1248 port_id_pci_reg_write(port_id, reg_off, reg_v);
1249 display_port_reg_value(port_id, reg_off, reg_v);
1253 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1255 if (port_id_is_invalid(port_id, ENABLED_WARN))
1257 if (port_reg_off_is_invalid(port_id, reg_off))
1259 port_id_pci_reg_write(port_id, reg_off, reg_v);
1260 display_port_reg_value(port_id, reg_off, reg_v);
1264 port_mtu_set(portid_t port_id, uint16_t mtu)
1267 struct rte_port *rte_port = &ports[port_id];
1268 struct rte_eth_dev_info dev_info;
1269 uint16_t eth_overhead;
1272 if (port_id_is_invalid(port_id, ENABLED_WARN))
1275 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1279 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1280 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1281 mtu, dev_info.min_mtu, dev_info.max_mtu);
1284 diag = rte_eth_dev_set_mtu(port_id, mtu);
1286 printf("Set MTU failed. diag=%d\n", diag);
1287 else if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1289 * Ether overhead in driver is equal to the difference of
1290 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1291 * device supports jumbo frame.
1293 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1294 if (mtu > RTE_ETHER_MAX_LEN - eth_overhead) {
1295 rte_port->dev_conf.rxmode.offloads |=
1296 DEV_RX_OFFLOAD_JUMBO_FRAME;
1297 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1300 rte_port->dev_conf.rxmode.offloads &=
1301 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1305 /* Generic flow management functions. */
1307 /** Generate a port_flow entry from attributes/pattern/actions. */
1308 static struct port_flow *
1309 port_flow_new(const struct rte_flow_attr *attr,
1310 const struct rte_flow_item *pattern,
1311 const struct rte_flow_action *actions,
1312 struct rte_flow_error *error)
1314 const struct rte_flow_conv_rule rule = {
1316 .pattern_ro = pattern,
1317 .actions_ro = actions,
1319 struct port_flow *pf;
1322 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1325 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1328 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1332 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1339 /** Print a message out of a flow error. */
1341 port_flow_complain(struct rte_flow_error *error)
1343 static const char *const errstrlist[] = {
1344 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1345 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1346 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1347 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1348 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1349 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1350 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1351 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1352 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1353 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1354 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1355 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1356 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1357 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1358 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1359 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1360 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1364 int err = rte_errno;
1366 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1367 !errstrlist[error->type])
1368 errstr = "unknown type";
1370 errstr = errstrlist[error->type];
1371 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1372 error->type, errstr,
1373 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1374 error->cause), buf) : "",
1375 error->message ? error->message : "(no stated reason)",
1380 /** Validate flow rule. */
1382 port_flow_validate(portid_t port_id,
1383 const struct rte_flow_attr *attr,
1384 const struct rte_flow_item *pattern,
1385 const struct rte_flow_action *actions)
1387 struct rte_flow_error error;
1389 /* Poisoning to make sure PMDs update it in case of error. */
1390 memset(&error, 0x11, sizeof(error));
1391 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1392 return port_flow_complain(&error);
1393 printf("Flow rule validated\n");
1397 /** Update age action context by port_flow pointer. */
1399 update_age_action_context(const struct rte_flow_action *actions,
1400 struct port_flow *pf)
1402 struct rte_flow_action_age *age = NULL;
1404 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1405 switch (actions->type) {
1406 case RTE_FLOW_ACTION_TYPE_AGE:
1407 age = (struct rte_flow_action_age *)
1408 (uintptr_t)actions->conf;
1417 /** Create flow rule. */
1419 port_flow_create(portid_t port_id,
1420 const struct rte_flow_attr *attr,
1421 const struct rte_flow_item *pattern,
1422 const struct rte_flow_action *actions)
1424 struct rte_flow *flow;
1425 struct rte_port *port;
1426 struct port_flow *pf;
1428 struct rte_flow_error error;
1430 port = &ports[port_id];
1431 if (port->flow_list) {
1432 if (port->flow_list->id == UINT32_MAX) {
1433 printf("Highest rule ID is already assigned, delete"
1437 id = port->flow_list->id + 1;
1439 pf = port_flow_new(attr, pattern, actions, &error);
1441 return port_flow_complain(&error);
1442 update_age_action_context(actions, pf);
1443 /* Poisoning to make sure PMDs update it in case of error. */
1444 memset(&error, 0x22, sizeof(error));
1445 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1448 return port_flow_complain(&error);
1450 pf->next = port->flow_list;
1453 port->flow_list = pf;
1454 printf("Flow rule #%u created\n", pf->id);
1458 /** Destroy a number of flow rules. */
1460 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1462 struct rte_port *port;
1463 struct port_flow **tmp;
1467 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1468 port_id == (portid_t)RTE_PORT_ALL)
1470 port = &ports[port_id];
1471 tmp = &port->flow_list;
1475 for (i = 0; i != n; ++i) {
1476 struct rte_flow_error error;
1477 struct port_flow *pf = *tmp;
1479 if (rule[i] != pf->id)
1482 * Poisoning to make sure PMDs update it in case
1485 memset(&error, 0x33, sizeof(error));
1486 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1487 ret = port_flow_complain(&error);
1490 printf("Flow rule #%u destroyed\n", pf->id);
1496 tmp = &(*tmp)->next;
1502 /** Remove all flow rules. */
1504 port_flow_flush(portid_t port_id)
1506 struct rte_flow_error error;
1507 struct rte_port *port;
1510 /* Poisoning to make sure PMDs update it in case of error. */
1511 memset(&error, 0x44, sizeof(error));
1512 if (rte_flow_flush(port_id, &error)) {
1513 ret = port_flow_complain(&error);
1514 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1515 port_id == (portid_t)RTE_PORT_ALL)
1518 port = &ports[port_id];
1519 while (port->flow_list) {
1520 struct port_flow *pf = port->flow_list->next;
1522 free(port->flow_list);
1523 port->flow_list = pf;
1528 /** Dump all flow rules. */
1530 port_flow_dump(portid_t port_id, const char *file_name)
1533 FILE *file = stdout;
1534 struct rte_flow_error error;
1536 if (file_name && strlen(file_name)) {
1537 file = fopen(file_name, "w");
1539 printf("Failed to create file %s: %s\n", file_name,
1544 ret = rte_flow_dev_dump(port_id, file, &error);
1546 port_flow_complain(&error);
1547 printf("Failed to dump flow: %s\n", strerror(-ret));
1549 printf("Flow dump finished\n");
1550 if (file_name && strlen(file_name))
1555 /** Query a flow rule. */
1557 port_flow_query(portid_t port_id, uint32_t rule,
1558 const struct rte_flow_action *action)
1560 struct rte_flow_error error;
1561 struct rte_port *port;
1562 struct port_flow *pf;
1565 struct rte_flow_query_count count;
1569 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1570 port_id == (portid_t)RTE_PORT_ALL)
1572 port = &ports[port_id];
1573 for (pf = port->flow_list; pf; pf = pf->next)
1577 printf("Flow rule #%u not found\n", rule);
1580 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1581 &name, sizeof(name),
1582 (void *)(uintptr_t)action->type, &error);
1584 return port_flow_complain(&error);
1585 switch (action->type) {
1586 case RTE_FLOW_ACTION_TYPE_COUNT:
1589 printf("Cannot query action type %d (%s)\n",
1590 action->type, name);
1593 /* Poisoning to make sure PMDs update it in case of error. */
1594 memset(&error, 0x55, sizeof(error));
1595 memset(&query, 0, sizeof(query));
1596 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1597 return port_flow_complain(&error);
1598 switch (action->type) {
1599 case RTE_FLOW_ACTION_TYPE_COUNT:
1603 " hits: %" PRIu64 "\n"
1604 " bytes: %" PRIu64 "\n",
1606 query.count.hits_set,
1607 query.count.bytes_set,
1612 printf("Cannot display result for action type %d (%s)\n",
1613 action->type, name);
1619 /** List simply and destroy all aged flows. */
1621 port_flow_aged(portid_t port_id, uint8_t destroy)
1624 int nb_context, total = 0, idx;
1625 struct rte_flow_error error;
1626 struct port_flow *pf;
1628 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1629 port_id == (portid_t)RTE_PORT_ALL)
1631 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
1632 printf("Port %u total aged flows: %d\n", port_id, total);
1634 port_flow_complain(&error);
1639 contexts = malloc(sizeof(void *) * total);
1640 if (contexts == NULL) {
1641 printf("Cannot allocate contexts for aged flow\n");
1644 printf("ID\tGroup\tPrio\tAttr\n");
1645 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
1646 if (nb_context != total) {
1647 printf("Port:%d get aged flows count(%d) != total(%d)\n",
1648 port_id, nb_context, total);
1652 for (idx = 0; idx < nb_context; idx++) {
1653 pf = (struct port_flow *)contexts[idx];
1655 printf("Error: get Null context in port %u\n", port_id);
1658 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
1660 pf->rule.attr->group,
1661 pf->rule.attr->priority,
1662 pf->rule.attr->ingress ? 'i' : '-',
1663 pf->rule.attr->egress ? 'e' : '-',
1664 pf->rule.attr->transfer ? 't' : '-');
1672 for (idx = 0; idx < nb_context; idx++) {
1673 pf = (struct port_flow *)contexts[idx];
1677 ret = port_flow_destroy(port_id, 1, &flow_id);
1681 printf("%d flows be destroyed\n", total);
1686 /** List flow rules. */
1688 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1690 struct rte_port *port;
1691 struct port_flow *pf;
1692 struct port_flow *list = NULL;
1695 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1696 port_id == (portid_t)RTE_PORT_ALL)
1698 port = &ports[port_id];
1699 if (!port->flow_list)
1701 /* Sort flows by group, priority and ID. */
1702 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1703 struct port_flow **tmp;
1704 const struct rte_flow_attr *curr = pf->rule.attr;
1707 /* Filter out unwanted groups. */
1708 for (i = 0; i != n; ++i)
1709 if (curr->group == group[i])
1714 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
1715 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
1717 if (curr->group > comp->group ||
1718 (curr->group == comp->group &&
1719 curr->priority > comp->priority) ||
1720 (curr->group == comp->group &&
1721 curr->priority == comp->priority &&
1722 pf->id > (*tmp)->id))
1729 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1730 for (pf = list; pf != NULL; pf = pf->tmp) {
1731 const struct rte_flow_item *item = pf->rule.pattern;
1732 const struct rte_flow_action *action = pf->rule.actions;
1735 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
1737 pf->rule.attr->group,
1738 pf->rule.attr->priority,
1739 pf->rule.attr->ingress ? 'i' : '-',
1740 pf->rule.attr->egress ? 'e' : '-',
1741 pf->rule.attr->transfer ? 't' : '-');
1742 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1743 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
1744 &name, sizeof(name),
1745 (void *)(uintptr_t)item->type,
1748 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1749 printf("%s ", name);
1753 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1754 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1755 &name, sizeof(name),
1756 (void *)(uintptr_t)action->type,
1759 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1760 printf(" %s", name);
1767 /** Restrict ingress traffic to the defined flow rules. */
1769 port_flow_isolate(portid_t port_id, int set)
1771 struct rte_flow_error error;
1773 /* Poisoning to make sure PMDs update it in case of error. */
1774 memset(&error, 0x66, sizeof(error));
1775 if (rte_flow_isolate(port_id, set, &error))
1776 return port_flow_complain(&error);
1777 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1779 set ? "now restricted" : "not restricted anymore");
1784 * RX/TX ring descriptors display functions.
1787 rx_queue_id_is_invalid(queueid_t rxq_id)
1789 if (rxq_id < nb_rxq)
1791 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1796 tx_queue_id_is_invalid(queueid_t txq_id)
1798 if (txq_id < nb_txq)
1800 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1805 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1807 if (rxdesc_id < nb_rxd)
1809 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1815 tx_desc_id_is_invalid(uint16_t txdesc_id)
1817 if (txdesc_id < nb_txd)
1819 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1824 static const struct rte_memzone *
1825 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1827 char mz_name[RTE_MEMZONE_NAMESIZE];
1828 const struct rte_memzone *mz;
1830 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
1831 port_id, q_id, ring_name);
1832 mz = rte_memzone_lookup(mz_name);
1834 printf("%s ring memory zoneof (port %d, queue %d) not"
1835 "found (zone name = %s\n",
1836 ring_name, port_id, q_id, mz_name);
1840 union igb_ring_dword {
1843 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1853 struct igb_ring_desc_32_bytes {
1854 union igb_ring_dword lo_dword;
1855 union igb_ring_dword hi_dword;
1856 union igb_ring_dword resv1;
1857 union igb_ring_dword resv2;
1860 struct igb_ring_desc_16_bytes {
1861 union igb_ring_dword lo_dword;
1862 union igb_ring_dword hi_dword;
1866 ring_rxd_display_dword(union igb_ring_dword dword)
1868 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1869 (unsigned)dword.words.hi);
1873 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1874 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1877 __rte_unused portid_t port_id,
1881 struct igb_ring_desc_16_bytes *ring =
1882 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1883 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1885 struct rte_eth_dev_info dev_info;
1887 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1891 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1892 /* 32 bytes RX descriptor, i40e only */
1893 struct igb_ring_desc_32_bytes *ring =
1894 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1895 ring[desc_id].lo_dword.dword =
1896 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1897 ring_rxd_display_dword(ring[desc_id].lo_dword);
1898 ring[desc_id].hi_dword.dword =
1899 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1900 ring_rxd_display_dword(ring[desc_id].hi_dword);
1901 ring[desc_id].resv1.dword =
1902 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1903 ring_rxd_display_dword(ring[desc_id].resv1);
1904 ring[desc_id].resv2.dword =
1905 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1906 ring_rxd_display_dword(ring[desc_id].resv2);
1911 /* 16 bytes RX descriptor */
1912 ring[desc_id].lo_dword.dword =
1913 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1914 ring_rxd_display_dword(ring[desc_id].lo_dword);
1915 ring[desc_id].hi_dword.dword =
1916 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1917 ring_rxd_display_dword(ring[desc_id].hi_dword);
1921 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1923 struct igb_ring_desc_16_bytes *ring;
1924 struct igb_ring_desc_16_bytes txd;
1926 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1927 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1928 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1929 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1930 (unsigned)txd.lo_dword.words.lo,
1931 (unsigned)txd.lo_dword.words.hi,
1932 (unsigned)txd.hi_dword.words.lo,
1933 (unsigned)txd.hi_dword.words.hi);
1937 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1939 const struct rte_memzone *rx_mz;
1941 if (port_id_is_invalid(port_id, ENABLED_WARN))
1943 if (rx_queue_id_is_invalid(rxq_id))
1945 if (rx_desc_id_is_invalid(rxd_id))
1947 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1950 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1954 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1956 const struct rte_memzone *tx_mz;
1958 if (port_id_is_invalid(port_id, ENABLED_WARN))
1960 if (tx_queue_id_is_invalid(txq_id))
1962 if (tx_desc_id_is_invalid(txd_id))
1964 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1967 ring_tx_descriptor_display(tx_mz, txd_id);
1971 fwd_lcores_config_display(void)
1975 printf("List of forwarding lcores:");
1976 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1977 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1981 rxtx_config_display(void)
1986 printf(" %s packet forwarding%s packets/burst=%d\n",
1987 cur_fwd_eng->fwd_mode_name,
1988 retry_enabled == 0 ? "" : " with retry",
1991 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1992 printf(" packet len=%u - nb packet segments=%d\n",
1993 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1995 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1996 nb_fwd_lcores, nb_fwd_ports);
1998 RTE_ETH_FOREACH_DEV(pid) {
1999 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
2000 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
2001 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
2002 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
2003 uint16_t nb_rx_desc_tmp;
2004 uint16_t nb_tx_desc_tmp;
2005 struct rte_eth_rxq_info rx_qinfo;
2006 struct rte_eth_txq_info tx_qinfo;
2009 /* per port config */
2010 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
2011 (unsigned int)pid, nb_rxq, nb_txq);
2013 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
2014 ports[pid].dev_conf.rxmode.offloads,
2015 ports[pid].dev_conf.txmode.offloads);
2017 /* per rx queue config only for first queue to be less verbose */
2018 for (qid = 0; qid < 1; qid++) {
2019 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
2021 nb_rx_desc_tmp = nb_rx_desc[qid];
2023 nb_rx_desc_tmp = rx_qinfo.nb_desc;
2025 printf(" RX queue: %d\n", qid);
2026 printf(" RX desc=%d - RX free threshold=%d\n",
2027 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh);
2028 printf(" RX threshold registers: pthresh=%d hthresh=%d "
2030 rx_conf[qid].rx_thresh.pthresh,
2031 rx_conf[qid].rx_thresh.hthresh,
2032 rx_conf[qid].rx_thresh.wthresh);
2033 printf(" RX Offloads=0x%"PRIx64"\n",
2034 rx_conf[qid].offloads);
2037 /* per tx queue config only for first queue to be less verbose */
2038 for (qid = 0; qid < 1; qid++) {
2039 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
2041 nb_tx_desc_tmp = nb_tx_desc[qid];
2043 nb_tx_desc_tmp = tx_qinfo.nb_desc;
2045 printf(" TX queue: %d\n", qid);
2046 printf(" TX desc=%d - TX free threshold=%d\n",
2047 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh);
2048 printf(" TX threshold registers: pthresh=%d hthresh=%d "
2050 tx_conf[qid].tx_thresh.pthresh,
2051 tx_conf[qid].tx_thresh.hthresh,
2052 tx_conf[qid].tx_thresh.wthresh);
2053 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
2054 tx_conf[qid].offloads, tx_conf->tx_rs_thresh);
2060 port_rss_reta_info(portid_t port_id,
2061 struct rte_eth_rss_reta_entry64 *reta_conf,
2062 uint16_t nb_entries)
2064 uint16_t i, idx, shift;
2067 if (port_id_is_invalid(port_id, ENABLED_WARN))
2070 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
2072 printf("Failed to get RSS RETA info, return code = %d\n", ret);
2076 for (i = 0; i < nb_entries; i++) {
2077 idx = i / RTE_RETA_GROUP_SIZE;
2078 shift = i % RTE_RETA_GROUP_SIZE;
2079 if (!(reta_conf[idx].mask & (1ULL << shift)))
2081 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
2082 i, reta_conf[idx].reta[shift]);
2087 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
2091 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
2093 struct rte_eth_rss_conf rss_conf = {0};
2094 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
2098 struct rte_eth_dev_info dev_info;
2099 uint8_t hash_key_size;
2102 if (port_id_is_invalid(port_id, ENABLED_WARN))
2105 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2109 if (dev_info.hash_key_size > 0 &&
2110 dev_info.hash_key_size <= sizeof(rss_key))
2111 hash_key_size = dev_info.hash_key_size;
2113 printf("dev_info did not provide a valid hash key size\n");
2117 /* Get RSS hash key if asked to display it */
2118 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2119 rss_conf.rss_key_len = hash_key_size;
2120 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2124 printf("port index %d invalid\n", port_id);
2127 printf("operation not supported by device\n");
2130 printf("operation failed - diag=%d\n", diag);
2135 rss_hf = rss_conf.rss_hf;
2137 printf("RSS disabled\n");
2140 printf("RSS functions:\n ");
2141 for (i = 0; rss_type_table[i].str; i++) {
2142 if (rss_hf & rss_type_table[i].rss_type)
2143 printf("%s ", rss_type_table[i].str);
2148 printf("RSS key:\n");
2149 for (i = 0; i < hash_key_size; i++)
2150 printf("%02X", rss_key[i]);
2155 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2158 struct rte_eth_rss_conf rss_conf;
2162 rss_conf.rss_key = NULL;
2163 rss_conf.rss_key_len = hash_key_len;
2164 rss_conf.rss_hf = 0;
2165 for (i = 0; rss_type_table[i].str; i++) {
2166 if (!strcmp(rss_type_table[i].str, rss_type))
2167 rss_conf.rss_hf = rss_type_table[i].rss_type;
2169 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2171 rss_conf.rss_key = hash_key;
2172 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2179 printf("port index %d invalid\n", port_id);
2182 printf("operation not supported by device\n");
2185 printf("operation failed - diag=%d\n", diag);
2191 * Setup forwarding configuration for each logical core.
2194 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2196 streamid_t nb_fs_per_lcore;
2204 nb_fs = cfg->nb_fwd_streams;
2205 nb_fc = cfg->nb_fwd_lcores;
2206 if (nb_fs <= nb_fc) {
2207 nb_fs_per_lcore = 1;
2210 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2211 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2214 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2216 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2217 fwd_lcores[lc_id]->stream_idx = sm_id;
2218 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2219 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2223 * Assign extra remaining streams, if any.
2225 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2226 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2227 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2228 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2229 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2234 fwd_topology_tx_port_get(portid_t rxp)
2236 static int warning_once = 1;
2238 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2240 switch (port_topology) {
2242 case PORT_TOPOLOGY_PAIRED:
2243 if ((rxp & 0x1) == 0) {
2244 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2247 printf("\nWarning! port-topology=paired"
2248 " and odd forward ports number,"
2249 " the last port will pair with"
2256 case PORT_TOPOLOGY_CHAINED:
2257 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2258 case PORT_TOPOLOGY_LOOP:
2264 simple_fwd_config_setup(void)
2268 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2269 cur_fwd_config.nb_fwd_streams =
2270 (streamid_t) cur_fwd_config.nb_fwd_ports;
2272 /* reinitialize forwarding streams */
2276 * In the simple forwarding test, the number of forwarding cores
2277 * must be lower or equal to the number of forwarding ports.
2279 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2280 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2281 cur_fwd_config.nb_fwd_lcores =
2282 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2283 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2285 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2286 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2287 fwd_streams[i]->rx_queue = 0;
2288 fwd_streams[i]->tx_port =
2289 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2290 fwd_streams[i]->tx_queue = 0;
2291 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2292 fwd_streams[i]->retry_enabled = retry_enabled;
2297 * For the RSS forwarding test all streams distributed over lcores. Each stream
2298 * being composed of a RX queue to poll on a RX port for input messages,
2299 * associated with a TX queue of a TX port where to send forwarded packets.
2302 rss_fwd_config_setup(void)
2313 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2314 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2315 cur_fwd_config.nb_fwd_streams =
2316 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2318 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2319 cur_fwd_config.nb_fwd_lcores =
2320 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2322 /* reinitialize forwarding streams */
2325 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2327 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2328 struct fwd_stream *fs;
2330 fs = fwd_streams[sm_id];
2331 txp = fwd_topology_tx_port_get(rxp);
2332 fs->rx_port = fwd_ports_ids[rxp];
2334 fs->tx_port = fwd_ports_ids[txp];
2336 fs->peer_addr = fs->tx_port;
2337 fs->retry_enabled = retry_enabled;
2339 if (rxp < nb_fwd_ports)
2347 * For the DCB forwarding test, each core is assigned on each traffic class.
2349 * Each core is assigned a multi-stream, each stream being composed of
2350 * a RX queue to poll on a RX port for input messages, associated with
2351 * a TX queue of a TX port where to send forwarded packets. All RX and
2352 * TX queues are mapping to the same traffic class.
2353 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2357 dcb_fwd_config_setup(void)
2359 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2360 portid_t txp, rxp = 0;
2361 queueid_t txq, rxq = 0;
2363 uint16_t nb_rx_queue, nb_tx_queue;
2364 uint16_t i, j, k, sm_id = 0;
2367 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2368 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2369 cur_fwd_config.nb_fwd_streams =
2370 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2372 /* reinitialize forwarding streams */
2376 /* get the dcb info on the first RX and TX ports */
2377 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2378 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2380 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2381 fwd_lcores[lc_id]->stream_nb = 0;
2382 fwd_lcores[lc_id]->stream_idx = sm_id;
2383 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2384 /* if the nb_queue is zero, means this tc is
2385 * not enabled on the POOL
2387 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2389 k = fwd_lcores[lc_id]->stream_nb +
2390 fwd_lcores[lc_id]->stream_idx;
2391 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2392 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2393 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2394 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2395 for (j = 0; j < nb_rx_queue; j++) {
2396 struct fwd_stream *fs;
2398 fs = fwd_streams[k + j];
2399 fs->rx_port = fwd_ports_ids[rxp];
2400 fs->rx_queue = rxq + j;
2401 fs->tx_port = fwd_ports_ids[txp];
2402 fs->tx_queue = txq + j % nb_tx_queue;
2403 fs->peer_addr = fs->tx_port;
2404 fs->retry_enabled = retry_enabled;
2406 fwd_lcores[lc_id]->stream_nb +=
2407 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2409 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2412 if (tc < rxp_dcb_info.nb_tcs)
2414 /* Restart from TC 0 on next RX port */
2416 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2418 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2421 if (rxp >= nb_fwd_ports)
2423 /* get the dcb information on next RX and TX ports */
2424 if ((rxp & 0x1) == 0)
2425 txp = (portid_t) (rxp + 1);
2427 txp = (portid_t) (rxp - 1);
2428 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2429 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2434 icmp_echo_config_setup(void)
2441 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2442 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2443 (nb_txq * nb_fwd_ports);
2445 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2446 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2447 cur_fwd_config.nb_fwd_streams =
2448 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2449 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2450 cur_fwd_config.nb_fwd_lcores =
2451 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2452 if (verbose_level > 0) {
2453 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2455 cur_fwd_config.nb_fwd_lcores,
2456 cur_fwd_config.nb_fwd_ports,
2457 cur_fwd_config.nb_fwd_streams);
2460 /* reinitialize forwarding streams */
2462 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2464 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2465 if (verbose_level > 0)
2466 printf(" core=%d: \n", lc_id);
2467 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2468 struct fwd_stream *fs;
2469 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2470 fs->rx_port = fwd_ports_ids[rxp];
2472 fs->tx_port = fs->rx_port;
2474 fs->peer_addr = fs->tx_port;
2475 fs->retry_enabled = retry_enabled;
2476 if (verbose_level > 0)
2477 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2478 sm_id, fs->rx_port, fs->rx_queue,
2480 rxq = (queueid_t) (rxq + 1);
2481 if (rxq == nb_rxq) {
2483 rxp = (portid_t) (rxp + 1);
2489 #if defined RTE_LIBRTE_PMD_SOFTNIC
2491 softnic_fwd_config_setup(void)
2493 struct rte_port *port;
2494 portid_t pid, softnic_portid;
2496 uint8_t softnic_enable = 0;
2498 RTE_ETH_FOREACH_DEV(pid) {
2500 const char *driver = port->dev_info.driver_name;
2502 if (strcmp(driver, "net_softnic") == 0) {
2503 softnic_portid = pid;
2509 if (softnic_enable == 0) {
2510 printf("Softnic mode not configured(%s)!\n", __func__);
2514 cur_fwd_config.nb_fwd_ports = 1;
2515 cur_fwd_config.nb_fwd_streams = (streamid_t) nb_rxq;
2517 /* Re-initialize forwarding streams */
2521 * In the softnic forwarding test, the number of forwarding cores
2522 * is set to one and remaining are used for softnic packet processing.
2524 cur_fwd_config.nb_fwd_lcores = 1;
2525 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2527 for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++) {
2528 fwd_streams[i]->rx_port = softnic_portid;
2529 fwd_streams[i]->rx_queue = i;
2530 fwd_streams[i]->tx_port = softnic_portid;
2531 fwd_streams[i]->tx_queue = i;
2532 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2533 fwd_streams[i]->retry_enabled = retry_enabled;
2539 fwd_config_setup(void)
2541 cur_fwd_config.fwd_eng = cur_fwd_eng;
2542 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2543 icmp_echo_config_setup();
2547 #if defined RTE_LIBRTE_PMD_SOFTNIC
2548 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
2549 softnic_fwd_config_setup();
2554 if ((nb_rxq > 1) && (nb_txq > 1)){
2556 dcb_fwd_config_setup();
2558 rss_fwd_config_setup();
2561 simple_fwd_config_setup();
2565 mp_alloc_to_str(uint8_t mode)
2568 case MP_ALLOC_NATIVE:
2574 case MP_ALLOC_XMEM_HUGE:
2584 pkt_fwd_config_display(struct fwd_config *cfg)
2586 struct fwd_stream *fs;
2590 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2591 "NUMA support %s, MP allocation mode: %s\n",
2592 cfg->fwd_eng->fwd_mode_name,
2593 retry_enabled == 0 ? "" : " with retry",
2594 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2595 numa_support == 1 ? "enabled" : "disabled",
2596 mp_alloc_to_str(mp_alloc_type));
2599 printf("TX retry num: %u, delay between TX retries: %uus\n",
2600 burst_tx_retry_num, burst_tx_delay_time);
2601 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2602 printf("Logical Core %u (socket %u) forwards packets on "
2604 fwd_lcores_cpuids[lc_id],
2605 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2606 fwd_lcores[lc_id]->stream_nb);
2607 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2608 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2609 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2610 "P=%d/Q=%d (socket %u) ",
2611 fs->rx_port, fs->rx_queue,
2612 ports[fs->rx_port].socket_id,
2613 fs->tx_port, fs->tx_queue,
2614 ports[fs->tx_port].socket_id);
2615 print_ethaddr("peer=",
2616 &peer_eth_addrs[fs->peer_addr]);
2624 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2626 struct rte_ether_addr new_peer_addr;
2627 if (!rte_eth_dev_is_valid_port(port_id)) {
2628 printf("Error: Invalid port number %i\n", port_id);
2631 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
2632 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2635 peer_eth_addrs[port_id] = new_peer_addr;
2639 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2642 unsigned int lcore_cpuid;
2647 for (i = 0; i < nb_lc; i++) {
2648 lcore_cpuid = lcorelist[i];
2649 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2650 printf("lcore %u not enabled\n", lcore_cpuid);
2653 if (lcore_cpuid == rte_get_master_lcore()) {
2654 printf("lcore %u cannot be masked on for running "
2655 "packet forwarding, which is the master lcore "
2656 "and reserved for command line parsing only\n",
2661 fwd_lcores_cpuids[i] = lcore_cpuid;
2663 if (record_now == 0) {
2667 nb_cfg_lcores = (lcoreid_t) nb_lc;
2668 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2669 printf("previous number of forwarding cores %u - changed to "
2670 "number of configured cores %u\n",
2671 (unsigned int) nb_fwd_lcores, nb_lc);
2672 nb_fwd_lcores = (lcoreid_t) nb_lc;
2679 set_fwd_lcores_mask(uint64_t lcoremask)
2681 unsigned int lcorelist[64];
2685 if (lcoremask == 0) {
2686 printf("Invalid NULL mask of cores\n");
2690 for (i = 0; i < 64; i++) {
2691 if (! ((uint64_t)(1ULL << i) & lcoremask))
2693 lcorelist[nb_lc++] = i;
2695 return set_fwd_lcores_list(lcorelist, nb_lc);
2699 set_fwd_lcores_number(uint16_t nb_lc)
2701 if (nb_lc > nb_cfg_lcores) {
2702 printf("nb fwd cores %u > %u (max. number of configured "
2703 "lcores) - ignored\n",
2704 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2707 nb_fwd_lcores = (lcoreid_t) nb_lc;
2708 printf("Number of forwarding cores set to %u\n",
2709 (unsigned int) nb_fwd_lcores);
2713 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2721 for (i = 0; i < nb_pt; i++) {
2722 port_id = (portid_t) portlist[i];
2723 if (port_id_is_invalid(port_id, ENABLED_WARN))
2726 fwd_ports_ids[i] = port_id;
2728 if (record_now == 0) {
2732 nb_cfg_ports = (portid_t) nb_pt;
2733 if (nb_fwd_ports != (portid_t) nb_pt) {
2734 printf("previous number of forwarding ports %u - changed to "
2735 "number of configured ports %u\n",
2736 (unsigned int) nb_fwd_ports, nb_pt);
2737 nb_fwd_ports = (portid_t) nb_pt;
2742 * Parse the user input and obtain the list of forwarding ports
2745 * String containing the user input. User can specify
2746 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
2747 * For example, if the user wants to use all the available
2748 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
2749 * If the user wants to use only the ports 1,2 then the input
2751 * valid characters are '-' and ','
2752 * @param[out] values
2753 * This array will be filled with a list of port IDs
2754 * based on the user input
2755 * Note that duplicate entries are discarded and only the first
2756 * count entries in this array are port IDs and all the rest
2757 * will contain default values
2758 * @param[in] maxsize
2759 * This parameter denotes 2 things
2760 * 1) Number of elements in the values array
2761 * 2) Maximum value of each element in the values array
2763 * On success, returns total count of parsed port IDs
2764 * On failure, returns 0
2767 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
2769 unsigned int count = 0;
2773 unsigned int marked[maxsize];
2775 if (list == NULL || values == NULL)
2778 for (i = 0; i < (int)maxsize; i++)
2784 /*Remove the blank spaces if any*/
2785 while (isblank(*list))
2790 value = strtol(list, &end, 10);
2791 if (errno || end == NULL)
2793 if (value < 0 || value >= (int)maxsize)
2795 while (isblank(*end))
2797 if (*end == '-' && min == INT_MAX) {
2799 } else if ((*end == ',') || (*end == '\0')) {
2803 for (i = min; i <= max; i++) {
2804 if (count < maxsize) {
2816 } while (*end != '\0');
2822 parse_fwd_portlist(const char *portlist)
2824 unsigned int portcount;
2825 unsigned int portindex[RTE_MAX_ETHPORTS];
2826 unsigned int i, valid_port_count = 0;
2828 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
2830 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
2833 * Here we verify the validity of the ports
2834 * and thereby calculate the total number of
2837 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
2838 if (rte_eth_dev_is_valid_port(portindex[i])) {
2839 portindex[valid_port_count] = portindex[i];
2844 set_fwd_ports_list(portindex, valid_port_count);
2848 set_fwd_ports_mask(uint64_t portmask)
2850 unsigned int portlist[64];
2854 if (portmask == 0) {
2855 printf("Invalid NULL mask of ports\n");
2859 RTE_ETH_FOREACH_DEV(i) {
2860 if (! ((uint64_t)(1ULL << i) & portmask))
2862 portlist[nb_pt++] = i;
2864 set_fwd_ports_list(portlist, nb_pt);
2868 set_fwd_ports_number(uint16_t nb_pt)
2870 if (nb_pt > nb_cfg_ports) {
2871 printf("nb fwd ports %u > %u (number of configured "
2872 "ports) - ignored\n",
2873 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2876 nb_fwd_ports = (portid_t) nb_pt;
2877 printf("Number of forwarding ports set to %u\n",
2878 (unsigned int) nb_fwd_ports);
2882 port_is_forwarding(portid_t port_id)
2886 if (port_id_is_invalid(port_id, ENABLED_WARN))
2889 for (i = 0; i < nb_fwd_ports; i++) {
2890 if (fwd_ports_ids[i] == port_id)
2898 set_nb_pkt_per_burst(uint16_t nb)
2900 if (nb > MAX_PKT_BURST) {
2901 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2903 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2906 nb_pkt_per_burst = nb;
2907 printf("Number of packets per burst set to %u\n",
2908 (unsigned int) nb_pkt_per_burst);
2912 tx_split_get_name(enum tx_pkt_split split)
2916 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2917 if (tx_split_name[i].split == split)
2918 return tx_split_name[i].name;
2924 set_tx_pkt_split(const char *name)
2928 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2929 if (strcmp(tx_split_name[i].name, name) == 0) {
2930 tx_pkt_split = tx_split_name[i].split;
2934 printf("unknown value: \"%s\"\n", name);
2938 show_tx_pkt_segments(void)
2944 split = tx_split_get_name(tx_pkt_split);
2946 printf("Number of segments: %u\n", n);
2947 printf("Segment sizes: ");
2948 for (i = 0; i != n - 1; i++)
2949 printf("%hu,", tx_pkt_seg_lengths[i]);
2950 printf("%hu\n", tx_pkt_seg_lengths[i]);
2951 printf("Split packet: %s\n", split);
2955 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2957 uint16_t tx_pkt_len;
2960 if (nb_segs >= (unsigned) nb_txd) {
2961 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2962 nb_segs, (unsigned int) nb_txd);
2967 * Check that each segment length is greater or equal than
2968 * the mbuf data sise.
2969 * Check also that the total packet length is greater or equal than the
2970 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
2974 for (i = 0; i < nb_segs; i++) {
2975 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2976 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2977 i, seg_lengths[i], (unsigned) mbuf_data_size);
2980 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2982 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
2983 printf("total packet length=%u < %d - give up\n",
2984 (unsigned) tx_pkt_len,
2985 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
2989 for (i = 0; i < nb_segs; i++)
2990 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2992 tx_pkt_length = tx_pkt_len;
2993 tx_pkt_nb_segs = (uint8_t) nb_segs;
2997 setup_gro(const char *onoff, portid_t port_id)
2999 if (!rte_eth_dev_is_valid_port(port_id)) {
3000 printf("invalid port id %u\n", port_id);
3003 if (test_done == 0) {
3004 printf("Before enable/disable GRO,"
3005 " please stop forwarding first\n");
3008 if (strcmp(onoff, "on") == 0) {
3009 if (gro_ports[port_id].enable != 0) {
3010 printf("Port %u has enabled GRO. Please"
3011 " disable GRO first\n", port_id);
3014 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3015 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
3016 gro_ports[port_id].param.max_flow_num =
3017 GRO_DEFAULT_FLOW_NUM;
3018 gro_ports[port_id].param.max_item_per_flow =
3019 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
3021 gro_ports[port_id].enable = 1;
3023 if (gro_ports[port_id].enable == 0) {
3024 printf("Port %u has disabled GRO\n", port_id);
3027 gro_ports[port_id].enable = 0;
3032 setup_gro_flush_cycles(uint8_t cycles)
3034 if (test_done == 0) {
3035 printf("Before change flush interval for GRO,"
3036 " please stop forwarding first.\n");
3040 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
3041 GRO_DEFAULT_FLUSH_CYCLES) {
3042 printf("The flushing cycle be in the range"
3043 " of 1 to %u. Revert to the default"
3045 GRO_MAX_FLUSH_CYCLES,
3046 GRO_DEFAULT_FLUSH_CYCLES);
3047 cycles = GRO_DEFAULT_FLUSH_CYCLES;
3050 gro_flush_cycles = cycles;
3054 show_gro(portid_t port_id)
3056 struct rte_gro_param *param;
3057 uint32_t max_pkts_num;
3059 param = &gro_ports[port_id].param;
3061 if (!rte_eth_dev_is_valid_port(port_id)) {
3062 printf("Invalid port id %u.\n", port_id);
3065 if (gro_ports[port_id].enable) {
3066 printf("GRO type: TCP/IPv4\n");
3067 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
3068 max_pkts_num = param->max_flow_num *
3069 param->max_item_per_flow;
3071 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
3072 printf("Max number of packets to perform GRO: %u\n",
3074 printf("Flushing cycles: %u\n", gro_flush_cycles);
3076 printf("Port %u doesn't enable GRO.\n", port_id);
3080 setup_gso(const char *mode, portid_t port_id)
3082 if (!rte_eth_dev_is_valid_port(port_id)) {
3083 printf("invalid port id %u\n", port_id);
3086 if (strcmp(mode, "on") == 0) {
3087 if (test_done == 0) {
3088 printf("before enabling GSO,"
3089 " please stop forwarding first\n");
3092 gso_ports[port_id].enable = 1;
3093 } else if (strcmp(mode, "off") == 0) {
3094 if (test_done == 0) {
3095 printf("before disabling GSO,"
3096 " please stop forwarding first\n");
3099 gso_ports[port_id].enable = 0;
3104 list_pkt_forwarding_modes(void)
3106 static char fwd_modes[128] = "";
3107 const char *separator = "|";
3108 struct fwd_engine *fwd_eng;
3111 if (strlen (fwd_modes) == 0) {
3112 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3113 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3114 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3115 strncat(fwd_modes, separator,
3116 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3118 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3125 list_pkt_forwarding_retry_modes(void)
3127 static char fwd_modes[128] = "";
3128 const char *separator = "|";
3129 struct fwd_engine *fwd_eng;
3132 if (strlen(fwd_modes) == 0) {
3133 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3134 if (fwd_eng == &rx_only_engine)
3136 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3138 strlen(fwd_modes) - 1);
3139 strncat(fwd_modes, separator,
3141 strlen(fwd_modes) - 1);
3143 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3150 set_pkt_forwarding_mode(const char *fwd_mode_name)
3152 struct fwd_engine *fwd_eng;
3156 while ((fwd_eng = fwd_engines[i]) != NULL) {
3157 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
3158 printf("Set %s packet forwarding mode%s\n",
3160 retry_enabled == 0 ? "" : " with retry");
3161 cur_fwd_eng = fwd_eng;
3166 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
3170 add_rx_dump_callbacks(portid_t portid)
3172 struct rte_eth_dev_info dev_info;
3176 if (port_id_is_invalid(portid, ENABLED_WARN))
3179 ret = eth_dev_info_get_print_err(portid, &dev_info);
3183 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3184 if (!ports[portid].rx_dump_cb[queue])
3185 ports[portid].rx_dump_cb[queue] =
3186 rte_eth_add_rx_callback(portid, queue,
3187 dump_rx_pkts, NULL);
3191 add_tx_dump_callbacks(portid_t portid)
3193 struct rte_eth_dev_info dev_info;
3197 if (port_id_is_invalid(portid, ENABLED_WARN))
3200 ret = eth_dev_info_get_print_err(portid, &dev_info);
3204 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3205 if (!ports[portid].tx_dump_cb[queue])
3206 ports[portid].tx_dump_cb[queue] =
3207 rte_eth_add_tx_callback(portid, queue,
3208 dump_tx_pkts, NULL);
3212 remove_rx_dump_callbacks(portid_t portid)
3214 struct rte_eth_dev_info dev_info;
3218 if (port_id_is_invalid(portid, ENABLED_WARN))
3221 ret = eth_dev_info_get_print_err(portid, &dev_info);
3225 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3226 if (ports[portid].rx_dump_cb[queue]) {
3227 rte_eth_remove_rx_callback(portid, queue,
3228 ports[portid].rx_dump_cb[queue]);
3229 ports[portid].rx_dump_cb[queue] = NULL;
3234 remove_tx_dump_callbacks(portid_t portid)
3236 struct rte_eth_dev_info dev_info;
3240 if (port_id_is_invalid(portid, ENABLED_WARN))
3243 ret = eth_dev_info_get_print_err(portid, &dev_info);
3247 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3248 if (ports[portid].tx_dump_cb[queue]) {
3249 rte_eth_remove_tx_callback(portid, queue,
3250 ports[portid].tx_dump_cb[queue]);
3251 ports[portid].tx_dump_cb[queue] = NULL;
3256 configure_rxtx_dump_callbacks(uint16_t verbose)
3260 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3261 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
3265 RTE_ETH_FOREACH_DEV(portid)
3267 if (verbose == 1 || verbose > 2)
3268 add_rx_dump_callbacks(portid);
3270 remove_rx_dump_callbacks(portid);
3272 add_tx_dump_callbacks(portid);
3274 remove_tx_dump_callbacks(portid);
3279 set_verbose_level(uint16_t vb_level)
3281 printf("Change verbose level from %u to %u\n",
3282 (unsigned int) verbose_level, (unsigned int) vb_level);
3283 verbose_level = vb_level;
3284 configure_rxtx_dump_callbacks(verbose_level);
3288 vlan_extend_set(portid_t port_id, int on)
3292 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3294 if (port_id_is_invalid(port_id, ENABLED_WARN))
3297 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3300 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
3301 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3303 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
3304 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3307 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3309 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
3310 "diag=%d\n", port_id, on, diag);
3311 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3315 rx_vlan_strip_set(portid_t port_id, int on)
3319 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3321 if (port_id_is_invalid(port_id, ENABLED_WARN))
3324 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3327 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
3328 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3330 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
3331 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3334 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3336 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
3337 "diag=%d\n", port_id, on, diag);
3338 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3342 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
3346 if (port_id_is_invalid(port_id, ENABLED_WARN))
3349 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
3351 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
3352 "diag=%d\n", port_id, queue_id, on, diag);
3356 rx_vlan_filter_set(portid_t port_id, int on)
3360 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3362 if (port_id_is_invalid(port_id, ENABLED_WARN))
3365 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3368 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
3369 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3371 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
3372 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3375 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3377 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
3378 "diag=%d\n", port_id, on, diag);
3379 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3383 rx_vlan_qinq_strip_set(portid_t port_id, int on)
3387 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3389 if (port_id_is_invalid(port_id, ENABLED_WARN))
3392 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3395 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
3396 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3398 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
3399 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3402 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3404 printf("%s(port_pi=%d, on=%d) failed "
3405 "diag=%d\n", __func__, port_id, on, diag);
3406 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3410 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
3414 if (port_id_is_invalid(port_id, ENABLED_WARN))
3416 if (vlan_id_is_invalid(vlan_id))
3418 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
3421 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
3423 port_id, vlan_id, on, diag);
3428 rx_vlan_all_filter_set(portid_t port_id, int on)
3432 if (port_id_is_invalid(port_id, ENABLED_WARN))
3434 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
3435 if (rx_vft_set(port_id, vlan_id, on))
3441 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
3445 if (port_id_is_invalid(port_id, ENABLED_WARN))
3448 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
3452 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
3454 port_id, vlan_type, tp_id, diag);
3458 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
3460 struct rte_eth_dev_info dev_info;
3463 if (port_id_is_invalid(port_id, ENABLED_WARN))
3465 if (vlan_id_is_invalid(vlan_id))
3468 if (ports[port_id].dev_conf.txmode.offloads &
3469 DEV_TX_OFFLOAD_QINQ_INSERT) {
3470 printf("Error, as QinQ has been enabled.\n");
3474 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3478 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
3479 printf("Error: vlan insert is not supported by port %d\n",
3484 tx_vlan_reset(port_id);
3485 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
3486 ports[port_id].tx_vlan_id = vlan_id;
3490 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
3492 struct rte_eth_dev_info dev_info;
3495 if (port_id_is_invalid(port_id, ENABLED_WARN))
3497 if (vlan_id_is_invalid(vlan_id))
3499 if (vlan_id_is_invalid(vlan_id_outer))
3502 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3506 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
3507 printf("Error: qinq insert not supported by port %d\n",
3512 tx_vlan_reset(port_id);
3513 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
3514 DEV_TX_OFFLOAD_QINQ_INSERT);
3515 ports[port_id].tx_vlan_id = vlan_id;
3516 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
3520 tx_vlan_reset(portid_t port_id)
3522 if (port_id_is_invalid(port_id, ENABLED_WARN))
3524 ports[port_id].dev_conf.txmode.offloads &=
3525 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
3526 DEV_TX_OFFLOAD_QINQ_INSERT);
3527 ports[port_id].tx_vlan_id = 0;
3528 ports[port_id].tx_vlan_id_outer = 0;
3532 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
3534 if (port_id_is_invalid(port_id, ENABLED_WARN))
3537 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
3541 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
3544 uint8_t existing_mapping_found = 0;
3546 if (port_id_is_invalid(port_id, ENABLED_WARN))
3549 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
3552 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
3553 printf("map_value not in required range 0..%d\n",
3554 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
3558 if (!is_rx) { /*then tx*/
3559 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3560 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3561 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
3562 tx_queue_stats_mappings[i].stats_counter_id = map_value;
3563 existing_mapping_found = 1;
3567 if (!existing_mapping_found) { /* A new additional mapping... */
3568 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
3569 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
3570 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
3571 nb_tx_queue_stats_mappings++;
3575 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3576 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3577 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
3578 rx_queue_stats_mappings[i].stats_counter_id = map_value;
3579 existing_mapping_found = 1;
3583 if (!existing_mapping_found) { /* A new additional mapping... */
3584 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
3585 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
3586 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
3587 nb_rx_queue_stats_mappings++;
3593 set_xstats_hide_zero(uint8_t on_off)
3595 xstats_hide_zero = on_off;
3599 print_fdir_mask(struct rte_eth_fdir_masks *mask)
3601 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
3603 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3604 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
3605 " tunnel_id: 0x%08x",
3606 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
3607 rte_be_to_cpu_32(mask->tunnel_id_mask));
3608 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3609 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
3610 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
3611 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
3613 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
3614 rte_be_to_cpu_16(mask->src_port_mask),
3615 rte_be_to_cpu_16(mask->dst_port_mask));
3617 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3618 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
3619 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3620 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3621 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3623 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3624 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3625 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3626 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3627 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3634 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3636 struct rte_eth_flex_payload_cfg *cfg;
3639 for (i = 0; i < flex_conf->nb_payloads; i++) {
3640 cfg = &flex_conf->flex_set[i];
3641 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3643 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3644 printf("\n L2_PAYLOAD: ");
3645 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3646 printf("\n L3_PAYLOAD: ");
3647 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3648 printf("\n L4_PAYLOAD: ");
3650 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3651 for (j = 0; j < num; j++)
3652 printf(" %-5u", cfg->src_offset[j]);
3658 flowtype_to_str(uint16_t flow_type)
3660 struct flow_type_info {
3666 static struct flow_type_info flowtype_str_table[] = {
3667 {"raw", RTE_ETH_FLOW_RAW},
3668 {"ipv4", RTE_ETH_FLOW_IPV4},
3669 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3670 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3671 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3672 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3673 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3674 {"ipv6", RTE_ETH_FLOW_IPV6},
3675 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3676 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3677 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3678 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3679 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3680 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3681 {"port", RTE_ETH_FLOW_PORT},
3682 {"vxlan", RTE_ETH_FLOW_VXLAN},
3683 {"geneve", RTE_ETH_FLOW_GENEVE},
3684 {"nvgre", RTE_ETH_FLOW_NVGRE},
3685 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
3688 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3689 if (flowtype_str_table[i].ftype == flow_type)
3690 return flowtype_str_table[i].str;
3697 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3699 struct rte_eth_fdir_flex_mask *mask;
3703 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3704 mask = &flex_conf->flex_mask[i];
3705 p = flowtype_to_str(mask->flow_type);
3706 printf("\n %s:\t", p ? p : "unknown");
3707 for (j = 0; j < num; j++)
3708 printf(" %02x", mask->mask[j]);
3714 print_fdir_flow_type(uint32_t flow_types_mask)
3719 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3720 if (!(flow_types_mask & (1 << i)))
3722 p = flowtype_to_str(i);
3732 fdir_get_infos(portid_t port_id)
3734 struct rte_eth_fdir_stats fdir_stat;
3735 struct rte_eth_fdir_info fdir_info;
3738 static const char *fdir_stats_border = "########################";
3740 if (port_id_is_invalid(port_id, ENABLED_WARN))
3742 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3744 printf("\n FDIR is not supported on port %-2d\n",
3749 memset(&fdir_info, 0, sizeof(fdir_info));
3750 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3751 RTE_ETH_FILTER_INFO, &fdir_info);
3752 memset(&fdir_stat, 0, sizeof(fdir_stat));
3753 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3754 RTE_ETH_FILTER_STATS, &fdir_stat);
3755 printf("\n %s FDIR infos for port %-2d %s\n",
3756 fdir_stats_border, port_id, fdir_stats_border);
3758 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3759 printf(" PERFECT\n");
3760 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3761 printf(" PERFECT-MAC-VLAN\n");
3762 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3763 printf(" PERFECT-TUNNEL\n");
3764 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3765 printf(" SIGNATURE\n");
3767 printf(" DISABLE\n");
3768 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3769 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3770 printf(" SUPPORTED FLOW TYPE: ");
3771 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3773 printf(" FLEX PAYLOAD INFO:\n");
3774 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3775 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3776 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3777 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3778 fdir_info.flex_payload_unit,
3779 fdir_info.max_flex_payload_segment_num,
3780 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3782 print_fdir_mask(&fdir_info.mask);
3783 if (fdir_info.flex_conf.nb_payloads > 0) {
3784 printf(" FLEX PAYLOAD SRC OFFSET:");
3785 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3787 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3788 printf(" FLEX MASK CFG:");
3789 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3791 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3792 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3793 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3794 fdir_info.guarant_spc, fdir_info.best_spc);
3795 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3796 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3797 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3798 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3799 fdir_stat.collision, fdir_stat.free,
3800 fdir_stat.maxhash, fdir_stat.maxlen,
3801 fdir_stat.add, fdir_stat.remove,
3802 fdir_stat.f_add, fdir_stat.f_remove);
3803 printf(" %s############################%s\n",
3804 fdir_stats_border, fdir_stats_border);
3808 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3810 struct rte_port *port;
3811 struct rte_eth_fdir_flex_conf *flex_conf;
3814 port = &ports[port_id];
3815 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3816 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3817 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3822 if (i >= RTE_ETH_FLOW_MAX) {
3823 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3824 idx = flex_conf->nb_flexmasks;
3825 flex_conf->nb_flexmasks++;
3827 printf("The flex mask table is full. Can not set flex"
3828 " mask for flow_type(%u).", cfg->flow_type);
3832 rte_memcpy(&flex_conf->flex_mask[idx],
3834 sizeof(struct rte_eth_fdir_flex_mask));
3838 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3840 struct rte_port *port;
3841 struct rte_eth_fdir_flex_conf *flex_conf;
3844 port = &ports[port_id];
3845 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3846 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3847 if (cfg->type == flex_conf->flex_set[i].type) {
3852 if (i >= RTE_ETH_PAYLOAD_MAX) {
3853 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3854 idx = flex_conf->nb_payloads;
3855 flex_conf->nb_payloads++;
3857 printf("The flex payload table is full. Can not set"
3858 " flex payload for type(%u).", cfg->type);
3862 rte_memcpy(&flex_conf->flex_set[idx],
3864 sizeof(struct rte_eth_flex_payload_cfg));
3869 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3871 #ifdef RTE_LIBRTE_IXGBE_PMD
3875 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3877 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3881 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3882 is_rx ? "rx" : "tx", port_id, diag);
3885 printf("VF %s setting not supported for port %d\n",
3886 is_rx ? "Rx" : "Tx", port_id);
3892 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3895 struct rte_eth_link link;
3898 if (port_id_is_invalid(port_id, ENABLED_WARN))
3900 ret = eth_link_get_nowait_print_err(port_id, &link);
3903 if (rate > link.link_speed) {
3904 printf("Invalid rate value:%u bigger than link speed: %u\n",
3905 rate, link.link_speed);
3908 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3911 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3917 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3919 int diag = -ENOTSUP;
3923 RTE_SET_USED(q_msk);
3925 #ifdef RTE_LIBRTE_IXGBE_PMD
3926 if (diag == -ENOTSUP)
3927 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3930 #ifdef RTE_LIBRTE_BNXT_PMD
3931 if (diag == -ENOTSUP)
3932 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3937 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3943 * Functions to manage the set of filtered Multicast MAC addresses.
3945 * A pool of filtered multicast MAC addresses is associated with each port.
3946 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3947 * The address of the pool and the number of valid multicast MAC addresses
3948 * recorded in the pool are stored in the fields "mc_addr_pool" and
3949 * "mc_addr_nb" of the "rte_port" data structure.
3951 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3952 * to be supplied a contiguous array of multicast MAC addresses.
3953 * To comply with this constraint, the set of multicast addresses recorded
3954 * into the pool are systematically compacted at the beginning of the pool.
3955 * Hence, when a multicast address is removed from the pool, all following
3956 * addresses, if any, are copied back to keep the set contiguous.
3958 #define MCAST_POOL_INC 32
3961 mcast_addr_pool_extend(struct rte_port *port)
3963 struct rte_ether_addr *mc_pool;
3964 size_t mc_pool_size;
3967 * If a free entry is available at the end of the pool, just
3968 * increment the number of recorded multicast addresses.
3970 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3976 * [re]allocate a pool with MCAST_POOL_INC more entries.
3977 * The previous test guarantees that port->mc_addr_nb is a multiple
3978 * of MCAST_POOL_INC.
3980 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
3982 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
3984 if (mc_pool == NULL) {
3985 printf("allocation of pool of %u multicast addresses failed\n",
3986 port->mc_addr_nb + MCAST_POOL_INC);
3990 port->mc_addr_pool = mc_pool;
3997 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
3999 if (mcast_addr_pool_extend(port) != 0)
4001 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
4005 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
4008 if (addr_idx == port->mc_addr_nb) {
4009 /* No need to recompact the set of multicast addressses. */
4010 if (port->mc_addr_nb == 0) {
4011 /* free the pool of multicast addresses. */
4012 free(port->mc_addr_pool);
4013 port->mc_addr_pool = NULL;
4017 memmove(&port->mc_addr_pool[addr_idx],
4018 &port->mc_addr_pool[addr_idx + 1],
4019 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
4023 eth_port_multicast_addr_list_set(portid_t port_id)
4025 struct rte_port *port;
4028 port = &ports[port_id];
4029 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
4032 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
4033 port_id, port->mc_addr_nb, diag);
4039 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
4041 struct rte_port *port;
4044 if (port_id_is_invalid(port_id, ENABLED_WARN))
4047 port = &ports[port_id];
4050 * Check that the added multicast MAC address is not already recorded
4051 * in the pool of multicast addresses.
4053 for (i = 0; i < port->mc_addr_nb; i++) {
4054 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
4055 printf("multicast address already filtered by port\n");
4060 mcast_addr_pool_append(port, mc_addr);
4061 if (eth_port_multicast_addr_list_set(port_id) < 0)
4062 /* Rollback on failure, remove the address from the pool */
4063 mcast_addr_pool_remove(port, i);
4067 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
4069 struct rte_port *port;
4072 if (port_id_is_invalid(port_id, ENABLED_WARN))
4075 port = &ports[port_id];
4078 * Search the pool of multicast MAC addresses for the removed address.
4080 for (i = 0; i < port->mc_addr_nb; i++) {
4081 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
4084 if (i == port->mc_addr_nb) {
4085 printf("multicast address not filtered by port %d\n", port_id);
4089 mcast_addr_pool_remove(port, i);
4090 if (eth_port_multicast_addr_list_set(port_id) < 0)
4091 /* Rollback on failure, add the address back into the pool */
4092 mcast_addr_pool_append(port, mc_addr);
4096 port_dcb_info_display(portid_t port_id)
4098 struct rte_eth_dcb_info dcb_info;
4101 static const char *border = "================";
4103 if (port_id_is_invalid(port_id, ENABLED_WARN))
4106 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
4108 printf("\n Failed to get dcb infos on port %-2d\n",
4112 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
4113 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
4115 for (i = 0; i < dcb_info.nb_tcs; i++)
4117 printf("\n Priority : ");
4118 for (i = 0; i < dcb_info.nb_tcs; i++)
4119 printf("\t%4d", dcb_info.prio_tc[i]);
4120 printf("\n BW percent :");
4121 for (i = 0; i < dcb_info.nb_tcs; i++)
4122 printf("\t%4d%%", dcb_info.tc_bws[i]);
4123 printf("\n RXQ base : ");
4124 for (i = 0; i < dcb_info.nb_tcs; i++)
4125 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
4126 printf("\n RXQ number :");
4127 for (i = 0; i < dcb_info.nb_tcs; i++)
4128 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
4129 printf("\n TXQ base : ");
4130 for (i = 0; i < dcb_info.nb_tcs; i++)
4131 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
4132 printf("\n TXQ number :");
4133 for (i = 0; i < dcb_info.nb_tcs; i++)
4134 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
4139 open_file(const char *file_path, uint32_t *size)
4141 int fd = open(file_path, O_RDONLY);
4143 uint8_t *buf = NULL;
4151 printf("%s: Failed to open %s\n", __func__, file_path);
4155 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
4157 printf("%s: File operations failed\n", __func__);
4161 pkg_size = st_buf.st_size;
4164 printf("%s: File operations failed\n", __func__);
4168 buf = (uint8_t *)malloc(pkg_size);
4171 printf("%s: Failed to malloc memory\n", __func__);
4175 ret = read(fd, buf, pkg_size);
4178 printf("%s: File read operation failed\n", __func__);
4192 save_file(const char *file_path, uint8_t *buf, uint32_t size)
4194 FILE *fh = fopen(file_path, "wb");
4197 printf("%s: Failed to open %s\n", __func__, file_path);
4201 if (fwrite(buf, 1, size, fh) != size) {
4203 printf("%s: File write operation failed\n", __func__);
4213 close_file(uint8_t *buf)
4224 port_queue_region_info_display(portid_t port_id, void *buf)
4226 #ifdef RTE_LIBRTE_I40E_PMD
4228 struct rte_pmd_i40e_queue_regions *info =
4229 (struct rte_pmd_i40e_queue_regions *)buf;
4230 static const char *queue_region_info_stats_border = "-------";
4232 if (!info->queue_region_number)
4233 printf("there is no region has been set before");
4235 printf("\n %s All queue region info for port=%2d %s",
4236 queue_region_info_stats_border, port_id,
4237 queue_region_info_stats_border);
4238 printf("\n queue_region_number: %-14u \n",
4239 info->queue_region_number);
4241 for (i = 0; i < info->queue_region_number; i++) {
4242 printf("\n region_id: %-14u queue_number: %-14u "
4243 "queue_start_index: %-14u \n",
4244 info->region[i].region_id,
4245 info->region[i].queue_num,
4246 info->region[i].queue_start_index);
4248 printf(" user_priority_num is %-14u :",
4249 info->region[i].user_priority_num);
4250 for (j = 0; j < info->region[i].user_priority_num; j++)
4251 printf(" %-14u ", info->region[i].user_priority[j]);
4253 printf("\n flowtype_num is %-14u :",
4254 info->region[i].flowtype_num);
4255 for (j = 0; j < info->region[i].flowtype_num; j++)
4256 printf(" %-14u ", info->region[i].hw_flowtype[j]);
4259 RTE_SET_USED(port_id);
4267 show_macs(portid_t port_id)
4269 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4270 struct rte_eth_dev_info dev_info;
4271 struct rte_ether_addr *addr;
4272 uint32_t i, num_macs = 0;
4273 struct rte_eth_dev *dev;
4275 dev = &rte_eth_devices[port_id];
4277 rte_eth_dev_info_get(port_id, &dev_info);
4279 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4280 addr = &dev->data->mac_addrs[i];
4282 /* skip zero address */
4283 if (rte_is_zero_ether_addr(addr))
4289 printf("Number of MAC address added: %d\n", num_macs);
4291 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4292 addr = &dev->data->mac_addrs[i];
4294 /* skip zero address */
4295 if (rte_is_zero_ether_addr(addr))
4298 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4299 printf(" %s\n", buf);
4304 show_mcast_macs(portid_t port_id)
4306 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4307 struct rte_ether_addr *addr;
4308 struct rte_port *port;
4311 port = &ports[port_id];
4313 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
4315 for (i = 0; i < port->mc_addr_nb; i++) {
4316 addr = &port->mc_addr_pool[i];
4318 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4319 printf(" %s\n", buf);