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_IP | ETH_RSS_TCP |
79 ETH_RSS_UDP | ETH_RSS_SCTP |
82 { "ipv4", ETH_RSS_IPV4 },
83 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
84 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
85 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
86 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
87 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
88 { "ipv6", ETH_RSS_IPV6 },
89 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
90 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
91 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
92 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
93 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
94 { "l2-payload", ETH_RSS_L2_PAYLOAD },
95 { "ipv6-ex", ETH_RSS_IPV6_EX },
96 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
97 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
98 { "port", ETH_RSS_PORT },
99 { "vxlan", ETH_RSS_VXLAN },
100 { "geneve", ETH_RSS_GENEVE },
101 { "nvgre", ETH_RSS_NVGRE },
102 { "ip", ETH_RSS_IP },
103 { "udp", ETH_RSS_UDP },
104 { "tcp", ETH_RSS_TCP },
105 { "sctp", ETH_RSS_SCTP },
106 { "tunnel", ETH_RSS_TUNNEL },
107 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
108 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
109 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
110 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
115 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
117 char buf[RTE_ETHER_ADDR_FMT_SIZE];
118 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
119 printf("%s%s", name, buf);
123 nic_stats_display(portid_t port_id)
125 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
126 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
127 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
128 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
129 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
130 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
132 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
133 struct rte_eth_stats stats;
134 struct rte_port *port = &ports[port_id];
137 static const char *nic_stats_border = "########################";
139 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
143 rte_eth_stats_get(port_id, &stats);
144 printf("\n %s NIC statistics for port %-2d %s\n",
145 nic_stats_border, port_id, nic_stats_border);
147 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
148 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
150 stats.ipackets, stats.imissed, stats.ibytes);
151 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
152 printf(" RX-nombuf: %-10"PRIu64"\n",
154 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
156 stats.opackets, stats.oerrors, stats.obytes);
159 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
160 " RX-bytes: %10"PRIu64"\n",
161 stats.ipackets, stats.ierrors, stats.ibytes);
162 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
163 printf(" RX-nombuf: %10"PRIu64"\n",
165 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
166 " TX-bytes: %10"PRIu64"\n",
167 stats.opackets, stats.oerrors, stats.obytes);
170 if (port->rx_queue_stats_mapping_enabled) {
172 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
173 printf(" Stats reg %2d RX-packets: %10"PRIu64
174 " RX-errors: %10"PRIu64
175 " RX-bytes: %10"PRIu64"\n",
176 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
179 if (port->tx_queue_stats_mapping_enabled) {
181 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
182 printf(" Stats reg %2d TX-packets: %10"PRIu64
183 " TX-bytes: %10"PRIu64"\n",
184 i, stats.q_opackets[i], stats.q_obytes[i]);
188 diff_cycles = prev_cycles[port_id];
189 prev_cycles[port_id] = rte_rdtsc();
191 diff_cycles = prev_cycles[port_id] - diff_cycles;
193 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
194 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
195 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
196 (stats.opackets - prev_pkts_tx[port_id]) : 0;
197 prev_pkts_rx[port_id] = stats.ipackets;
198 prev_pkts_tx[port_id] = stats.opackets;
199 mpps_rx = diff_cycles > 0 ?
200 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
201 mpps_tx = diff_cycles > 0 ?
202 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
204 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
205 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
206 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
207 (stats.obytes - prev_bytes_tx[port_id]) : 0;
208 prev_bytes_rx[port_id] = stats.ibytes;
209 prev_bytes_tx[port_id] = stats.obytes;
210 mbps_rx = diff_cycles > 0 ?
211 diff_bytes_rx * rte_get_tsc_hz() / diff_cycles : 0;
212 mbps_tx = diff_cycles > 0 ?
213 diff_bytes_tx * rte_get_tsc_hz() / diff_cycles : 0;
215 printf("\n Throughput (since last show)\n");
216 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
217 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
218 mpps_tx, mbps_tx * 8);
220 printf(" %s############################%s\n",
221 nic_stats_border, nic_stats_border);
225 nic_stats_clear(portid_t port_id)
227 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
231 rte_eth_stats_reset(port_id);
232 printf("\n NIC statistics for port %d cleared\n", port_id);
236 nic_xstats_display(portid_t port_id)
238 struct rte_eth_xstat *xstats;
239 int cnt_xstats, idx_xstat;
240 struct rte_eth_xstat_name *xstats_names;
242 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
246 printf("###### NIC extended statistics for port %-2d\n", port_id);
247 if (!rte_eth_dev_is_valid_port(port_id)) {
248 printf("Error: Invalid port number %i\n", port_id);
253 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
254 if (cnt_xstats < 0) {
255 printf("Error: Cannot get count of xstats\n");
259 /* Get id-name lookup table */
260 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
261 if (xstats_names == NULL) {
262 printf("Cannot allocate memory for xstats lookup\n");
265 if (cnt_xstats != rte_eth_xstats_get_names(
266 port_id, xstats_names, cnt_xstats)) {
267 printf("Error: Cannot get xstats lookup\n");
272 /* Get stats themselves */
273 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
274 if (xstats == NULL) {
275 printf("Cannot allocate memory for xstats\n");
279 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
280 printf("Error: Unable to get xstats\n");
287 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
288 if (xstats_hide_zero && !xstats[idx_xstat].value)
290 printf("%s: %"PRIu64"\n",
291 xstats_names[idx_xstat].name,
292 xstats[idx_xstat].value);
299 nic_xstats_clear(portid_t port_id)
303 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
307 ret = rte_eth_xstats_reset(port_id);
309 printf("%s: Error: failed to reset xstats (port %u): %s",
310 __func__, port_id, strerror(ret));
315 nic_stats_mapping_display(portid_t port_id)
317 struct rte_port *port = &ports[port_id];
320 static const char *nic_stats_mapping_border = "########################";
322 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
327 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
328 printf("Port id %d - either does not support queue statistic mapping or"
329 " no queue statistic mapping set\n", port_id);
333 printf("\n %s NIC statistics mapping for port %-2d %s\n",
334 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
336 if (port->rx_queue_stats_mapping_enabled) {
337 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
338 if (rx_queue_stats_mappings[i].port_id == port_id) {
339 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
340 rx_queue_stats_mappings[i].queue_id,
341 rx_queue_stats_mappings[i].stats_counter_id);
348 if (port->tx_queue_stats_mapping_enabled) {
349 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
350 if (tx_queue_stats_mappings[i].port_id == port_id) {
351 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
352 tx_queue_stats_mappings[i].queue_id,
353 tx_queue_stats_mappings[i].stats_counter_id);
358 printf(" %s####################################%s\n",
359 nic_stats_mapping_border, nic_stats_mapping_border);
363 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
365 struct rte_eth_burst_mode mode;
366 struct rte_eth_rxq_info qinfo;
368 static const char *info_border = "*********************";
370 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
372 printf("Failed to retrieve information for port: %u, "
373 "RX queue: %hu\nerror desc: %s(%d)\n",
374 port_id, queue_id, strerror(-rc), rc);
378 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
379 info_border, port_id, queue_id, info_border);
381 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
382 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
383 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
384 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
385 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
386 printf("\nRX drop packets: %s",
387 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
388 printf("\nRX deferred start: %s",
389 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
390 printf("\nRX scattered packets: %s",
391 (qinfo.scattered_rx != 0) ? "on" : "off");
392 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
394 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
395 printf("\nBurst mode: %s%s",
397 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
398 " (per queue)" : "");
404 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
406 struct rte_eth_burst_mode mode;
407 struct rte_eth_txq_info qinfo;
409 static const char *info_border = "*********************";
411 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
413 printf("Failed to retrieve information for port: %u, "
414 "TX queue: %hu\nerror desc: %s(%d)\n",
415 port_id, queue_id, strerror(-rc), rc);
419 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
420 info_border, port_id, queue_id, info_border);
422 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
423 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
424 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
425 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
426 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
427 printf("\nTX deferred start: %s",
428 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
429 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
431 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
432 printf("\nBurst mode: %s%s",
434 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
435 " (per queue)" : "");
440 static int bus_match_all(const struct rte_bus *bus, const void *data)
448 device_infos_display(const char *identifier)
450 static const char *info_border = "*********************";
451 struct rte_bus *start = NULL, *next;
452 struct rte_dev_iterator dev_iter;
453 char name[RTE_ETH_NAME_MAX_LEN];
454 struct rte_ether_addr mac_addr;
455 struct rte_device *dev;
456 struct rte_devargs da;
460 memset(&da, 0, sizeof(da));
464 if (rte_devargs_parsef(&da, "%s", identifier)) {
465 printf("cannot parse identifier\n");
472 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
475 if (identifier && da.bus != next)
478 /* Skip buses that don't have iterate method */
479 if (!next->dev_iterate)
482 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
483 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
487 /* Check for matching device if identifier is present */
489 strncmp(da.name, dev->name, strlen(dev->name)))
491 printf("\n%s Infos for device %s %s\n",
492 info_border, dev->name, info_border);
493 printf("Bus name: %s", dev->bus->name);
494 printf("\nDriver name: %s", dev->driver->name);
495 printf("\nDevargs: %s",
496 dev->devargs ? dev->devargs->args : "");
497 printf("\nConnect to socket: %d", dev->numa_node);
500 /* List ports with matching device name */
501 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
502 printf("\n\tPort id: %-2d", port_id);
503 if (eth_macaddr_get_print_err(port_id,
505 print_ethaddr("\n\tMAC address: ",
507 rte_eth_dev_get_name_by_port(port_id, name);
508 printf("\n\tDevice name: %s", name);
516 port_infos_display(portid_t port_id)
518 struct rte_port *port;
519 struct rte_ether_addr mac_addr;
520 struct rte_eth_link link;
521 struct rte_eth_dev_info dev_info;
523 struct rte_mempool * mp;
524 static const char *info_border = "*********************";
526 char name[RTE_ETH_NAME_MAX_LEN];
528 char fw_version[ETHDEV_FWVERS_LEN];
530 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
534 port = &ports[port_id];
535 ret = eth_link_get_nowait_print_err(port_id, &link);
539 ret = eth_dev_info_get_print_err(port_id, &dev_info);
543 printf("\n%s Infos for port %-2d %s\n",
544 info_border, port_id, info_border);
545 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
546 print_ethaddr("MAC address: ", &mac_addr);
547 rte_eth_dev_get_name_by_port(port_id, name);
548 printf("\nDevice name: %s", name);
549 printf("\nDriver name: %s", dev_info.driver_name);
551 if (rte_eth_dev_fw_version_get(port_id, fw_version,
552 ETHDEV_FWVERS_LEN) == 0)
553 printf("\nFirmware-version: %s", fw_version);
555 printf("\nFirmware-version: %s", "not available");
557 if (dev_info.device->devargs && dev_info.device->devargs->args)
558 printf("\nDevargs: %s", dev_info.device->devargs->args);
559 printf("\nConnect to socket: %u", port->socket_id);
561 if (port_numa[port_id] != NUMA_NO_CONFIG) {
562 mp = mbuf_pool_find(port_numa[port_id]);
564 printf("\nmemory allocation on the socket: %d",
567 printf("\nmemory allocation on the socket: %u",port->socket_id);
569 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
570 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
571 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
572 ("full-duplex") : ("half-duplex"));
574 if (!rte_eth_dev_get_mtu(port_id, &mtu))
575 printf("MTU: %u\n", mtu);
577 printf("Promiscuous mode: %s\n",
578 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
579 printf("Allmulticast mode: %s\n",
580 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
581 printf("Maximum number of MAC addresses: %u\n",
582 (unsigned int)(port->dev_info.max_mac_addrs));
583 printf("Maximum number of MAC addresses of hash filtering: %u\n",
584 (unsigned int)(port->dev_info.max_hash_mac_addrs));
586 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
587 if (vlan_offload >= 0){
588 printf("VLAN offload: \n");
589 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
590 printf(" strip on, ");
592 printf(" strip off, ");
594 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
595 printf("filter on, ");
597 printf("filter off, ");
599 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
600 printf("extend on, ");
602 printf("extend off, ");
604 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
605 printf("qinq strip on\n");
607 printf("qinq strip off\n");
610 if (dev_info.hash_key_size > 0)
611 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
612 if (dev_info.reta_size > 0)
613 printf("Redirection table size: %u\n", dev_info.reta_size);
614 if (!dev_info.flow_type_rss_offloads)
615 printf("No RSS offload flow type is supported.\n");
620 printf("Supported RSS offload flow types:\n");
621 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
622 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
623 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
625 p = flowtype_to_str(i);
629 printf(" user defined %d\n", i);
633 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
634 printf("Maximum configurable length of RX packet: %u\n",
635 dev_info.max_rx_pktlen);
636 printf("Maximum configurable size of LRO aggregated packet: %u\n",
637 dev_info.max_lro_pkt_size);
638 if (dev_info.max_vfs)
639 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
640 if (dev_info.max_vmdq_pools)
641 printf("Maximum number of VMDq pools: %u\n",
642 dev_info.max_vmdq_pools);
644 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
645 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
646 printf("Max possible number of RXDs per queue: %hu\n",
647 dev_info.rx_desc_lim.nb_max);
648 printf("Min possible number of RXDs per queue: %hu\n",
649 dev_info.rx_desc_lim.nb_min);
650 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
652 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
653 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
654 printf("Max possible number of TXDs per queue: %hu\n",
655 dev_info.tx_desc_lim.nb_max);
656 printf("Min possible number of TXDs per queue: %hu\n",
657 dev_info.tx_desc_lim.nb_min);
658 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
659 printf("Max segment number per packet: %hu\n",
660 dev_info.tx_desc_lim.nb_seg_max);
661 printf("Max segment number per MTU/TSO: %hu\n",
662 dev_info.tx_desc_lim.nb_mtu_seg_max);
664 /* Show switch info only if valid switch domain and port id is set */
665 if (dev_info.switch_info.domain_id !=
666 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
667 if (dev_info.switch_info.name)
668 printf("Switch name: %s\n", dev_info.switch_info.name);
670 printf("Switch domain Id: %u\n",
671 dev_info.switch_info.domain_id);
672 printf("Switch Port Id: %u\n",
673 dev_info.switch_info.port_id);
678 port_summary_header_display(void)
680 uint16_t port_number;
682 port_number = rte_eth_dev_count_avail();
683 printf("Number of available ports: %i\n", port_number);
684 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
685 "Driver", "Status", "Link");
689 port_summary_display(portid_t port_id)
691 struct rte_ether_addr mac_addr;
692 struct rte_eth_link link;
693 struct rte_eth_dev_info dev_info;
694 char name[RTE_ETH_NAME_MAX_LEN];
697 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
702 ret = eth_link_get_nowait_print_err(port_id, &link);
706 ret = eth_dev_info_get_print_err(port_id, &dev_info);
710 rte_eth_dev_get_name_by_port(port_id, name);
711 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
715 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
716 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
717 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
718 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
719 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
720 (unsigned int) link.link_speed);
724 port_offload_cap_display(portid_t port_id)
726 struct rte_eth_dev_info dev_info;
727 static const char *info_border = "************";
730 if (port_id_is_invalid(port_id, ENABLED_WARN))
733 ret = eth_dev_info_get_print_err(port_id, &dev_info);
737 printf("\n%s Port %d supported offload features: %s\n",
738 info_border, port_id, info_border);
740 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
741 printf("VLAN stripped: ");
742 if (ports[port_id].dev_conf.rxmode.offloads &
743 DEV_RX_OFFLOAD_VLAN_STRIP)
749 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
750 printf("Double VLANs stripped: ");
751 if (ports[port_id].dev_conf.rxmode.offloads &
752 DEV_RX_OFFLOAD_QINQ_STRIP)
758 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
759 printf("RX IPv4 checksum: ");
760 if (ports[port_id].dev_conf.rxmode.offloads &
761 DEV_RX_OFFLOAD_IPV4_CKSUM)
767 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
768 printf("RX UDP checksum: ");
769 if (ports[port_id].dev_conf.rxmode.offloads &
770 DEV_RX_OFFLOAD_UDP_CKSUM)
776 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
777 printf("RX TCP checksum: ");
778 if (ports[port_id].dev_conf.rxmode.offloads &
779 DEV_RX_OFFLOAD_TCP_CKSUM)
785 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) {
786 printf("RX SCTP checksum: ");
787 if (ports[port_id].dev_conf.rxmode.offloads &
788 DEV_RX_OFFLOAD_SCTP_CKSUM)
794 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
795 printf("RX Outer IPv4 checksum: ");
796 if (ports[port_id].dev_conf.rxmode.offloads &
797 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
803 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) {
804 printf("RX Outer UDP checksum: ");
805 if (ports[port_id].dev_conf.rxmode.offloads &
806 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM)
812 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
813 printf("Large receive offload: ");
814 if (ports[port_id].dev_conf.rxmode.offloads &
815 DEV_RX_OFFLOAD_TCP_LRO)
821 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
822 printf("HW timestamp: ");
823 if (ports[port_id].dev_conf.rxmode.offloads &
824 DEV_RX_OFFLOAD_TIMESTAMP)
830 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) {
831 printf("Rx Keep CRC: ");
832 if (ports[port_id].dev_conf.rxmode.offloads &
833 DEV_RX_OFFLOAD_KEEP_CRC)
839 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) {
840 printf("RX offload security: ");
841 if (ports[port_id].dev_conf.rxmode.offloads &
842 DEV_RX_OFFLOAD_SECURITY)
848 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
849 printf("VLAN insert: ");
850 if (ports[port_id].dev_conf.txmode.offloads &
851 DEV_TX_OFFLOAD_VLAN_INSERT)
857 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
858 printf("Double VLANs insert: ");
859 if (ports[port_id].dev_conf.txmode.offloads &
860 DEV_TX_OFFLOAD_QINQ_INSERT)
866 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
867 printf("TX IPv4 checksum: ");
868 if (ports[port_id].dev_conf.txmode.offloads &
869 DEV_TX_OFFLOAD_IPV4_CKSUM)
875 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
876 printf("TX UDP checksum: ");
877 if (ports[port_id].dev_conf.txmode.offloads &
878 DEV_TX_OFFLOAD_UDP_CKSUM)
884 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
885 printf("TX TCP checksum: ");
886 if (ports[port_id].dev_conf.txmode.offloads &
887 DEV_TX_OFFLOAD_TCP_CKSUM)
893 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
894 printf("TX SCTP checksum: ");
895 if (ports[port_id].dev_conf.txmode.offloads &
896 DEV_TX_OFFLOAD_SCTP_CKSUM)
902 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
903 printf("TX Outer IPv4 checksum: ");
904 if (ports[port_id].dev_conf.txmode.offloads &
905 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
911 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
912 printf("TX TCP segmentation: ");
913 if (ports[port_id].dev_conf.txmode.offloads &
914 DEV_TX_OFFLOAD_TCP_TSO)
920 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
921 printf("TX UDP segmentation: ");
922 if (ports[port_id].dev_conf.txmode.offloads &
923 DEV_TX_OFFLOAD_UDP_TSO)
929 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
930 printf("TSO for VXLAN tunnel packet: ");
931 if (ports[port_id].dev_conf.txmode.offloads &
932 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
938 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
939 printf("TSO for GRE tunnel packet: ");
940 if (ports[port_id].dev_conf.txmode.offloads &
941 DEV_TX_OFFLOAD_GRE_TNL_TSO)
947 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
948 printf("TSO for IPIP tunnel packet: ");
949 if (ports[port_id].dev_conf.txmode.offloads &
950 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
956 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
957 printf("TSO for GENEVE tunnel packet: ");
958 if (ports[port_id].dev_conf.txmode.offloads &
959 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
965 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) {
966 printf("IP tunnel TSO: ");
967 if (ports[port_id].dev_conf.txmode.offloads &
968 DEV_TX_OFFLOAD_IP_TNL_TSO)
974 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) {
975 printf("UDP tunnel TSO: ");
976 if (ports[port_id].dev_conf.txmode.offloads &
977 DEV_TX_OFFLOAD_UDP_TNL_TSO)
983 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
984 printf("TX Outer UDP checksum: ");
985 if (ports[port_id].dev_conf.txmode.offloads &
986 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
995 port_id_is_invalid(portid_t port_id, enum print_warning warning)
999 if (port_id == (portid_t)RTE_PORT_ALL)
1002 RTE_ETH_FOREACH_DEV(pid)
1006 if (warning == ENABLED_WARN)
1007 printf("Invalid port %d\n", port_id);
1012 void print_valid_ports(void)
1016 printf("The valid ports array is [");
1017 RTE_ETH_FOREACH_DEV(pid) {
1024 vlan_id_is_invalid(uint16_t vlan_id)
1028 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1033 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1035 const struct rte_pci_device *pci_dev;
1036 const struct rte_bus *bus;
1039 if (reg_off & 0x3) {
1040 printf("Port register offset 0x%X not aligned on a 4-byte "
1046 if (!ports[port_id].dev_info.device) {
1047 printf("Invalid device\n");
1051 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1052 if (bus && !strcmp(bus->name, "pci")) {
1053 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1055 printf("Not a PCI device\n");
1059 pci_len = pci_dev->mem_resource[0].len;
1060 if (reg_off >= pci_len) {
1061 printf("Port %d: register offset %u (0x%X) out of port PCI "
1062 "resource (length=%"PRIu64")\n",
1063 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
1070 reg_bit_pos_is_invalid(uint8_t bit_pos)
1074 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
1078 #define display_port_and_reg_off(port_id, reg_off) \
1079 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1082 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1084 display_port_and_reg_off(port_id, (unsigned)reg_off);
1085 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1089 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1094 if (port_id_is_invalid(port_id, ENABLED_WARN))
1096 if (port_reg_off_is_invalid(port_id, reg_off))
1098 if (reg_bit_pos_is_invalid(bit_x))
1100 reg_v = port_id_pci_reg_read(port_id, reg_off);
1101 display_port_and_reg_off(port_id, (unsigned)reg_off);
1102 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1106 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1107 uint8_t bit1_pos, uint8_t bit2_pos)
1113 if (port_id_is_invalid(port_id, ENABLED_WARN))
1115 if (port_reg_off_is_invalid(port_id, reg_off))
1117 if (reg_bit_pos_is_invalid(bit1_pos))
1119 if (reg_bit_pos_is_invalid(bit2_pos))
1121 if (bit1_pos > bit2_pos)
1122 l_bit = bit2_pos, h_bit = bit1_pos;
1124 l_bit = bit1_pos, h_bit = bit2_pos;
1126 reg_v = port_id_pci_reg_read(port_id, reg_off);
1129 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1130 display_port_and_reg_off(port_id, (unsigned)reg_off);
1131 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1132 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1136 port_reg_display(portid_t port_id, uint32_t reg_off)
1140 if (port_id_is_invalid(port_id, ENABLED_WARN))
1142 if (port_reg_off_is_invalid(port_id, reg_off))
1144 reg_v = port_id_pci_reg_read(port_id, reg_off);
1145 display_port_reg_value(port_id, reg_off, reg_v);
1149 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1154 if (port_id_is_invalid(port_id, ENABLED_WARN))
1156 if (port_reg_off_is_invalid(port_id, reg_off))
1158 if (reg_bit_pos_is_invalid(bit_pos))
1161 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1164 reg_v = port_id_pci_reg_read(port_id, reg_off);
1166 reg_v &= ~(1 << bit_pos);
1168 reg_v |= (1 << bit_pos);
1169 port_id_pci_reg_write(port_id, reg_off, reg_v);
1170 display_port_reg_value(port_id, reg_off, reg_v);
1174 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1175 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1182 if (port_id_is_invalid(port_id, ENABLED_WARN))
1184 if (port_reg_off_is_invalid(port_id, reg_off))
1186 if (reg_bit_pos_is_invalid(bit1_pos))
1188 if (reg_bit_pos_is_invalid(bit2_pos))
1190 if (bit1_pos > bit2_pos)
1191 l_bit = bit2_pos, h_bit = bit1_pos;
1193 l_bit = bit1_pos, h_bit = bit2_pos;
1195 if ((h_bit - l_bit) < 31)
1196 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1200 if (value > max_v) {
1201 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1202 (unsigned)value, (unsigned)value,
1203 (unsigned)max_v, (unsigned)max_v);
1206 reg_v = port_id_pci_reg_read(port_id, reg_off);
1207 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1208 reg_v |= (value << l_bit); /* Set changed bits */
1209 port_id_pci_reg_write(port_id, reg_off, reg_v);
1210 display_port_reg_value(port_id, reg_off, reg_v);
1214 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1216 if (port_id_is_invalid(port_id, ENABLED_WARN))
1218 if (port_reg_off_is_invalid(port_id, reg_off))
1220 port_id_pci_reg_write(port_id, reg_off, reg_v);
1221 display_port_reg_value(port_id, reg_off, reg_v);
1225 port_mtu_set(portid_t port_id, uint16_t mtu)
1228 struct rte_port *rte_port = &ports[port_id];
1229 struct rte_eth_dev_info dev_info;
1230 uint16_t eth_overhead;
1233 if (port_id_is_invalid(port_id, ENABLED_WARN))
1236 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1240 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1241 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1242 mtu, dev_info.min_mtu, dev_info.max_mtu);
1245 diag = rte_eth_dev_set_mtu(port_id, mtu);
1247 dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1249 * Ether overhead in driver is equal to the difference of
1250 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1251 * device supports jumbo frame.
1253 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1254 if (mtu > RTE_ETHER_MAX_LEN - eth_overhead) {
1255 rte_port->dev_conf.rxmode.offloads |=
1256 DEV_RX_OFFLOAD_JUMBO_FRAME;
1257 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1260 rte_port->dev_conf.rxmode.offloads &=
1261 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1265 printf("Set MTU failed. diag=%d\n", diag);
1268 /* Generic flow management functions. */
1270 /** Generate a port_flow entry from attributes/pattern/actions. */
1271 static struct port_flow *
1272 port_flow_new(const struct rte_flow_attr *attr,
1273 const struct rte_flow_item *pattern,
1274 const struct rte_flow_action *actions,
1275 struct rte_flow_error *error)
1277 const struct rte_flow_conv_rule rule = {
1279 .pattern_ro = pattern,
1280 .actions_ro = actions,
1282 struct port_flow *pf;
1285 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1288 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1291 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1295 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1302 /** Print a message out of a flow error. */
1304 port_flow_complain(struct rte_flow_error *error)
1306 static const char *const errstrlist[] = {
1307 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1308 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1309 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1310 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1311 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1312 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1313 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1314 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1315 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1316 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1317 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1318 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1319 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1320 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1321 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1322 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1323 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1327 int err = rte_errno;
1329 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1330 !errstrlist[error->type])
1331 errstr = "unknown type";
1333 errstr = errstrlist[error->type];
1334 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1335 error->type, errstr,
1336 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1337 error->cause), buf) : "",
1338 error->message ? error->message : "(no stated reason)",
1343 /** Validate flow rule. */
1345 port_flow_validate(portid_t port_id,
1346 const struct rte_flow_attr *attr,
1347 const struct rte_flow_item *pattern,
1348 const struct rte_flow_action *actions)
1350 struct rte_flow_error error;
1352 /* Poisoning to make sure PMDs update it in case of error. */
1353 memset(&error, 0x11, sizeof(error));
1354 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1355 return port_flow_complain(&error);
1356 printf("Flow rule validated\n");
1360 /** Create flow rule. */
1362 port_flow_create(portid_t port_id,
1363 const struct rte_flow_attr *attr,
1364 const struct rte_flow_item *pattern,
1365 const struct rte_flow_action *actions)
1367 struct rte_flow *flow;
1368 struct rte_port *port;
1369 struct port_flow *pf;
1371 struct rte_flow_error error;
1373 /* Poisoning to make sure PMDs update it in case of error. */
1374 memset(&error, 0x22, sizeof(error));
1375 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1377 return port_flow_complain(&error);
1378 port = &ports[port_id];
1379 if (port->flow_list) {
1380 if (port->flow_list->id == UINT32_MAX) {
1381 printf("Highest rule ID is already assigned, delete"
1383 rte_flow_destroy(port_id, flow, NULL);
1386 id = port->flow_list->id + 1;
1389 pf = port_flow_new(attr, pattern, actions, &error);
1391 rte_flow_destroy(port_id, flow, NULL);
1392 return port_flow_complain(&error);
1394 pf->next = port->flow_list;
1397 port->flow_list = pf;
1398 printf("Flow rule #%u created\n", pf->id);
1402 /** Destroy a number of flow rules. */
1404 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1406 struct rte_port *port;
1407 struct port_flow **tmp;
1411 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1412 port_id == (portid_t)RTE_PORT_ALL)
1414 port = &ports[port_id];
1415 tmp = &port->flow_list;
1419 for (i = 0; i != n; ++i) {
1420 struct rte_flow_error error;
1421 struct port_flow *pf = *tmp;
1423 if (rule[i] != pf->id)
1426 * Poisoning to make sure PMDs update it in case
1429 memset(&error, 0x33, sizeof(error));
1430 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1431 ret = port_flow_complain(&error);
1434 printf("Flow rule #%u destroyed\n", pf->id);
1440 tmp = &(*tmp)->next;
1446 /** Remove all flow rules. */
1448 port_flow_flush(portid_t port_id)
1450 struct rte_flow_error error;
1451 struct rte_port *port;
1454 /* Poisoning to make sure PMDs update it in case of error. */
1455 memset(&error, 0x44, sizeof(error));
1456 if (rte_flow_flush(port_id, &error)) {
1457 ret = port_flow_complain(&error);
1458 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1459 port_id == (portid_t)RTE_PORT_ALL)
1462 port = &ports[port_id];
1463 while (port->flow_list) {
1464 struct port_flow *pf = port->flow_list->next;
1466 free(port->flow_list);
1467 port->flow_list = pf;
1472 /** Dump all flow rules. */
1474 port_flow_dump(portid_t port_id, const char *file_name)
1477 FILE *file = stdout;
1478 struct rte_flow_error error;
1480 if (file_name && strlen(file_name)) {
1481 file = fopen(file_name, "w");
1483 printf("Failed to create file %s: %s\n", file_name,
1488 ret = rte_flow_dev_dump(port_id, file, &error);
1490 port_flow_complain(&error);
1491 printf("Failed to dump flow: %s\n", strerror(-ret));
1493 printf("Flow dump finished\n");
1494 if (file_name && strlen(file_name))
1499 /** Query a flow rule. */
1501 port_flow_query(portid_t port_id, uint32_t rule,
1502 const struct rte_flow_action *action)
1504 struct rte_flow_error error;
1505 struct rte_port *port;
1506 struct port_flow *pf;
1509 struct rte_flow_query_count count;
1513 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1514 port_id == (portid_t)RTE_PORT_ALL)
1516 port = &ports[port_id];
1517 for (pf = port->flow_list; pf; pf = pf->next)
1521 printf("Flow rule #%u not found\n", rule);
1524 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1525 &name, sizeof(name),
1526 (void *)(uintptr_t)action->type, &error);
1528 return port_flow_complain(&error);
1529 switch (action->type) {
1530 case RTE_FLOW_ACTION_TYPE_COUNT:
1533 printf("Cannot query action type %d (%s)\n",
1534 action->type, name);
1537 /* Poisoning to make sure PMDs update it in case of error. */
1538 memset(&error, 0x55, sizeof(error));
1539 memset(&query, 0, sizeof(query));
1540 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1541 return port_flow_complain(&error);
1542 switch (action->type) {
1543 case RTE_FLOW_ACTION_TYPE_COUNT:
1547 " hits: %" PRIu64 "\n"
1548 " bytes: %" PRIu64 "\n",
1550 query.count.hits_set,
1551 query.count.bytes_set,
1556 printf("Cannot display result for action type %d (%s)\n",
1557 action->type, name);
1563 /** List flow rules. */
1565 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1567 struct rte_port *port;
1568 struct port_flow *pf;
1569 struct port_flow *list = NULL;
1572 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1573 port_id == (portid_t)RTE_PORT_ALL)
1575 port = &ports[port_id];
1576 if (!port->flow_list)
1578 /* Sort flows by group, priority and ID. */
1579 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1580 struct port_flow **tmp;
1581 const struct rte_flow_attr *curr = pf->rule.attr;
1584 /* Filter out unwanted groups. */
1585 for (i = 0; i != n; ++i)
1586 if (curr->group == group[i])
1591 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
1592 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
1594 if (curr->group > comp->group ||
1595 (curr->group == comp->group &&
1596 curr->priority > comp->priority) ||
1597 (curr->group == comp->group &&
1598 curr->priority == comp->priority &&
1599 pf->id > (*tmp)->id))
1606 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1607 for (pf = list; pf != NULL; pf = pf->tmp) {
1608 const struct rte_flow_item *item = pf->rule.pattern;
1609 const struct rte_flow_action *action = pf->rule.actions;
1612 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
1614 pf->rule.attr->group,
1615 pf->rule.attr->priority,
1616 pf->rule.attr->ingress ? 'i' : '-',
1617 pf->rule.attr->egress ? 'e' : '-',
1618 pf->rule.attr->transfer ? 't' : '-');
1619 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1620 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
1621 &name, sizeof(name),
1622 (void *)(uintptr_t)item->type,
1625 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1626 printf("%s ", name);
1630 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1631 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1632 &name, sizeof(name),
1633 (void *)(uintptr_t)action->type,
1636 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1637 printf(" %s", name);
1644 /** Restrict ingress traffic to the defined flow rules. */
1646 port_flow_isolate(portid_t port_id, int set)
1648 struct rte_flow_error error;
1650 /* Poisoning to make sure PMDs update it in case of error. */
1651 memset(&error, 0x66, sizeof(error));
1652 if (rte_flow_isolate(port_id, set, &error))
1653 return port_flow_complain(&error);
1654 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1656 set ? "now restricted" : "not restricted anymore");
1661 * RX/TX ring descriptors display functions.
1664 rx_queue_id_is_invalid(queueid_t rxq_id)
1666 if (rxq_id < nb_rxq)
1668 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1673 tx_queue_id_is_invalid(queueid_t txq_id)
1675 if (txq_id < nb_txq)
1677 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1682 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1684 if (rxdesc_id < nb_rxd)
1686 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1692 tx_desc_id_is_invalid(uint16_t txdesc_id)
1694 if (txdesc_id < nb_txd)
1696 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1701 static const struct rte_memzone *
1702 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1704 char mz_name[RTE_MEMZONE_NAMESIZE];
1705 const struct rte_memzone *mz;
1707 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
1708 port_id, q_id, ring_name);
1709 mz = rte_memzone_lookup(mz_name);
1711 printf("%s ring memory zoneof (port %d, queue %d) not"
1712 "found (zone name = %s\n",
1713 ring_name, port_id, q_id, mz_name);
1717 union igb_ring_dword {
1720 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1730 struct igb_ring_desc_32_bytes {
1731 union igb_ring_dword lo_dword;
1732 union igb_ring_dword hi_dword;
1733 union igb_ring_dword resv1;
1734 union igb_ring_dword resv2;
1737 struct igb_ring_desc_16_bytes {
1738 union igb_ring_dword lo_dword;
1739 union igb_ring_dword hi_dword;
1743 ring_rxd_display_dword(union igb_ring_dword dword)
1745 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1746 (unsigned)dword.words.hi);
1750 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1751 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1754 __rte_unused portid_t port_id,
1758 struct igb_ring_desc_16_bytes *ring =
1759 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1760 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1762 struct rte_eth_dev_info dev_info;
1764 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1768 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1769 /* 32 bytes RX descriptor, i40e only */
1770 struct igb_ring_desc_32_bytes *ring =
1771 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1772 ring[desc_id].lo_dword.dword =
1773 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1774 ring_rxd_display_dword(ring[desc_id].lo_dword);
1775 ring[desc_id].hi_dword.dword =
1776 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1777 ring_rxd_display_dword(ring[desc_id].hi_dword);
1778 ring[desc_id].resv1.dword =
1779 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1780 ring_rxd_display_dword(ring[desc_id].resv1);
1781 ring[desc_id].resv2.dword =
1782 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1783 ring_rxd_display_dword(ring[desc_id].resv2);
1788 /* 16 bytes RX descriptor */
1789 ring[desc_id].lo_dword.dword =
1790 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1791 ring_rxd_display_dword(ring[desc_id].lo_dword);
1792 ring[desc_id].hi_dword.dword =
1793 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1794 ring_rxd_display_dword(ring[desc_id].hi_dword);
1798 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1800 struct igb_ring_desc_16_bytes *ring;
1801 struct igb_ring_desc_16_bytes txd;
1803 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1804 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1805 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1806 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1807 (unsigned)txd.lo_dword.words.lo,
1808 (unsigned)txd.lo_dword.words.hi,
1809 (unsigned)txd.hi_dword.words.lo,
1810 (unsigned)txd.hi_dword.words.hi);
1814 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1816 const struct rte_memzone *rx_mz;
1818 if (port_id_is_invalid(port_id, ENABLED_WARN))
1820 if (rx_queue_id_is_invalid(rxq_id))
1822 if (rx_desc_id_is_invalid(rxd_id))
1824 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1827 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1831 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1833 const struct rte_memzone *tx_mz;
1835 if (port_id_is_invalid(port_id, ENABLED_WARN))
1837 if (tx_queue_id_is_invalid(txq_id))
1839 if (tx_desc_id_is_invalid(txd_id))
1841 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1844 ring_tx_descriptor_display(tx_mz, txd_id);
1848 fwd_lcores_config_display(void)
1852 printf("List of forwarding lcores:");
1853 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1854 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1858 rxtx_config_display(void)
1863 printf(" %s packet forwarding%s packets/burst=%d\n",
1864 cur_fwd_eng->fwd_mode_name,
1865 retry_enabled == 0 ? "" : " with retry",
1868 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1869 printf(" packet len=%u - nb packet segments=%d\n",
1870 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1872 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1873 nb_fwd_lcores, nb_fwd_ports);
1875 RTE_ETH_FOREACH_DEV(pid) {
1876 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
1877 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
1878 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
1879 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
1880 uint16_t nb_rx_desc_tmp;
1881 uint16_t nb_tx_desc_tmp;
1882 struct rte_eth_rxq_info rx_qinfo;
1883 struct rte_eth_txq_info tx_qinfo;
1886 /* per port config */
1887 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
1888 (unsigned int)pid, nb_rxq, nb_txq);
1890 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
1891 ports[pid].dev_conf.rxmode.offloads,
1892 ports[pid].dev_conf.txmode.offloads);
1894 /* per rx queue config only for first queue to be less verbose */
1895 for (qid = 0; qid < 1; qid++) {
1896 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
1898 nb_rx_desc_tmp = nb_rx_desc[qid];
1900 nb_rx_desc_tmp = rx_qinfo.nb_desc;
1902 printf(" RX queue: %d\n", qid);
1903 printf(" RX desc=%d - RX free threshold=%d\n",
1904 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh);
1905 printf(" RX threshold registers: pthresh=%d hthresh=%d "
1907 rx_conf[qid].rx_thresh.pthresh,
1908 rx_conf[qid].rx_thresh.hthresh,
1909 rx_conf[qid].rx_thresh.wthresh);
1910 printf(" RX Offloads=0x%"PRIx64"\n",
1911 rx_conf[qid].offloads);
1914 /* per tx queue config only for first queue to be less verbose */
1915 for (qid = 0; qid < 1; qid++) {
1916 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
1918 nb_tx_desc_tmp = nb_tx_desc[qid];
1920 nb_tx_desc_tmp = tx_qinfo.nb_desc;
1922 printf(" TX queue: %d\n", qid);
1923 printf(" TX desc=%d - TX free threshold=%d\n",
1924 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh);
1925 printf(" TX threshold registers: pthresh=%d hthresh=%d "
1927 tx_conf[qid].tx_thresh.pthresh,
1928 tx_conf[qid].tx_thresh.hthresh,
1929 tx_conf[qid].tx_thresh.wthresh);
1930 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
1931 tx_conf[qid].offloads, tx_conf->tx_rs_thresh);
1937 port_rss_reta_info(portid_t port_id,
1938 struct rte_eth_rss_reta_entry64 *reta_conf,
1939 uint16_t nb_entries)
1941 uint16_t i, idx, shift;
1944 if (port_id_is_invalid(port_id, ENABLED_WARN))
1947 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1949 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1953 for (i = 0; i < nb_entries; i++) {
1954 idx = i / RTE_RETA_GROUP_SIZE;
1955 shift = i % RTE_RETA_GROUP_SIZE;
1956 if (!(reta_conf[idx].mask & (1ULL << shift)))
1958 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1959 i, reta_conf[idx].reta[shift]);
1964 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1968 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
1970 struct rte_eth_rss_conf rss_conf = {0};
1971 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1975 struct rte_eth_dev_info dev_info;
1976 uint8_t hash_key_size;
1979 if (port_id_is_invalid(port_id, ENABLED_WARN))
1982 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1986 if (dev_info.hash_key_size > 0 &&
1987 dev_info.hash_key_size <= sizeof(rss_key))
1988 hash_key_size = dev_info.hash_key_size;
1990 printf("dev_info did not provide a valid hash key size\n");
1994 /* Get RSS hash key if asked to display it */
1995 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1996 rss_conf.rss_key_len = hash_key_size;
1997 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2001 printf("port index %d invalid\n", port_id);
2004 printf("operation not supported by device\n");
2007 printf("operation failed - diag=%d\n", diag);
2012 rss_hf = rss_conf.rss_hf;
2014 printf("RSS disabled\n");
2017 printf("RSS functions:\n ");
2018 for (i = 0; rss_type_table[i].str; i++) {
2019 if (rss_hf & rss_type_table[i].rss_type)
2020 printf("%s ", rss_type_table[i].str);
2025 printf("RSS key:\n");
2026 for (i = 0; i < hash_key_size; i++)
2027 printf("%02X", rss_key[i]);
2032 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2035 struct rte_eth_rss_conf rss_conf;
2039 rss_conf.rss_key = NULL;
2040 rss_conf.rss_key_len = hash_key_len;
2041 rss_conf.rss_hf = 0;
2042 for (i = 0; rss_type_table[i].str; i++) {
2043 if (!strcmp(rss_type_table[i].str, rss_type))
2044 rss_conf.rss_hf = rss_type_table[i].rss_type;
2046 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2048 rss_conf.rss_key = hash_key;
2049 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2056 printf("port index %d invalid\n", port_id);
2059 printf("operation not supported by device\n");
2062 printf("operation failed - diag=%d\n", diag);
2068 * Setup forwarding configuration for each logical core.
2071 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2073 streamid_t nb_fs_per_lcore;
2081 nb_fs = cfg->nb_fwd_streams;
2082 nb_fc = cfg->nb_fwd_lcores;
2083 if (nb_fs <= nb_fc) {
2084 nb_fs_per_lcore = 1;
2087 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2088 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2091 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2093 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2094 fwd_lcores[lc_id]->stream_idx = sm_id;
2095 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2096 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2100 * Assign extra remaining streams, if any.
2102 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2103 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2104 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2105 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2106 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2111 fwd_topology_tx_port_get(portid_t rxp)
2113 static int warning_once = 1;
2115 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2117 switch (port_topology) {
2119 case PORT_TOPOLOGY_PAIRED:
2120 if ((rxp & 0x1) == 0) {
2121 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2124 printf("\nWarning! port-topology=paired"
2125 " and odd forward ports number,"
2126 " the last port will pair with"
2133 case PORT_TOPOLOGY_CHAINED:
2134 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2135 case PORT_TOPOLOGY_LOOP:
2141 simple_fwd_config_setup(void)
2145 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2146 cur_fwd_config.nb_fwd_streams =
2147 (streamid_t) cur_fwd_config.nb_fwd_ports;
2149 /* reinitialize forwarding streams */
2153 * In the simple forwarding test, the number of forwarding cores
2154 * must be lower or equal to the number of forwarding ports.
2156 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2157 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2158 cur_fwd_config.nb_fwd_lcores =
2159 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2160 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2162 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2163 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2164 fwd_streams[i]->rx_queue = 0;
2165 fwd_streams[i]->tx_port =
2166 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2167 fwd_streams[i]->tx_queue = 0;
2168 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2169 fwd_streams[i]->retry_enabled = retry_enabled;
2174 * For the RSS forwarding test all streams distributed over lcores. Each stream
2175 * being composed of a RX queue to poll on a RX port for input messages,
2176 * associated with a TX queue of a TX port where to send forwarded packets.
2179 rss_fwd_config_setup(void)
2190 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2191 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2192 cur_fwd_config.nb_fwd_streams =
2193 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2195 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2196 cur_fwd_config.nb_fwd_lcores =
2197 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2199 /* reinitialize forwarding streams */
2202 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2204 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2205 struct fwd_stream *fs;
2207 fs = fwd_streams[sm_id];
2208 txp = fwd_topology_tx_port_get(rxp);
2209 fs->rx_port = fwd_ports_ids[rxp];
2211 fs->tx_port = fwd_ports_ids[txp];
2213 fs->peer_addr = fs->tx_port;
2214 fs->retry_enabled = retry_enabled;
2216 if (rxp < nb_fwd_ports)
2224 * For the DCB forwarding test, each core is assigned on each traffic class.
2226 * Each core is assigned a multi-stream, each stream being composed of
2227 * a RX queue to poll on a RX port for input messages, associated with
2228 * a TX queue of a TX port where to send forwarded packets. All RX and
2229 * TX queues are mapping to the same traffic class.
2230 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2234 dcb_fwd_config_setup(void)
2236 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2237 portid_t txp, rxp = 0;
2238 queueid_t txq, rxq = 0;
2240 uint16_t nb_rx_queue, nb_tx_queue;
2241 uint16_t i, j, k, sm_id = 0;
2244 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2245 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2246 cur_fwd_config.nb_fwd_streams =
2247 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2249 /* reinitialize forwarding streams */
2253 /* get the dcb info on the first RX and TX ports */
2254 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2255 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2257 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2258 fwd_lcores[lc_id]->stream_nb = 0;
2259 fwd_lcores[lc_id]->stream_idx = sm_id;
2260 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2261 /* if the nb_queue is zero, means this tc is
2262 * not enabled on the POOL
2264 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2266 k = fwd_lcores[lc_id]->stream_nb +
2267 fwd_lcores[lc_id]->stream_idx;
2268 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2269 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2270 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2271 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2272 for (j = 0; j < nb_rx_queue; j++) {
2273 struct fwd_stream *fs;
2275 fs = fwd_streams[k + j];
2276 fs->rx_port = fwd_ports_ids[rxp];
2277 fs->rx_queue = rxq + j;
2278 fs->tx_port = fwd_ports_ids[txp];
2279 fs->tx_queue = txq + j % nb_tx_queue;
2280 fs->peer_addr = fs->tx_port;
2281 fs->retry_enabled = retry_enabled;
2283 fwd_lcores[lc_id]->stream_nb +=
2284 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2286 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2289 if (tc < rxp_dcb_info.nb_tcs)
2291 /* Restart from TC 0 on next RX port */
2293 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2295 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2298 if (rxp >= nb_fwd_ports)
2300 /* get the dcb information on next RX and TX ports */
2301 if ((rxp & 0x1) == 0)
2302 txp = (portid_t) (rxp + 1);
2304 txp = (portid_t) (rxp - 1);
2305 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2306 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2311 icmp_echo_config_setup(void)
2318 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2319 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2320 (nb_txq * nb_fwd_ports);
2322 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2323 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2324 cur_fwd_config.nb_fwd_streams =
2325 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2326 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2327 cur_fwd_config.nb_fwd_lcores =
2328 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2329 if (verbose_level > 0) {
2330 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2332 cur_fwd_config.nb_fwd_lcores,
2333 cur_fwd_config.nb_fwd_ports,
2334 cur_fwd_config.nb_fwd_streams);
2337 /* reinitialize forwarding streams */
2339 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2341 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2342 if (verbose_level > 0)
2343 printf(" core=%d: \n", lc_id);
2344 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2345 struct fwd_stream *fs;
2346 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2347 fs->rx_port = fwd_ports_ids[rxp];
2349 fs->tx_port = fs->rx_port;
2351 fs->peer_addr = fs->tx_port;
2352 fs->retry_enabled = retry_enabled;
2353 if (verbose_level > 0)
2354 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2355 sm_id, fs->rx_port, fs->rx_queue,
2357 rxq = (queueid_t) (rxq + 1);
2358 if (rxq == nb_rxq) {
2360 rxp = (portid_t) (rxp + 1);
2366 #if defined RTE_LIBRTE_PMD_SOFTNIC
2368 softnic_fwd_config_setup(void)
2370 struct rte_port *port;
2371 portid_t pid, softnic_portid;
2373 uint8_t softnic_enable = 0;
2375 RTE_ETH_FOREACH_DEV(pid) {
2377 const char *driver = port->dev_info.driver_name;
2379 if (strcmp(driver, "net_softnic") == 0) {
2380 softnic_portid = pid;
2386 if (softnic_enable == 0) {
2387 printf("Softnic mode not configured(%s)!\n", __func__);
2391 cur_fwd_config.nb_fwd_ports = 1;
2392 cur_fwd_config.nb_fwd_streams = (streamid_t) nb_rxq;
2394 /* Re-initialize forwarding streams */
2398 * In the softnic forwarding test, the number of forwarding cores
2399 * is set to one and remaining are used for softnic packet processing.
2401 cur_fwd_config.nb_fwd_lcores = 1;
2402 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2404 for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++) {
2405 fwd_streams[i]->rx_port = softnic_portid;
2406 fwd_streams[i]->rx_queue = i;
2407 fwd_streams[i]->tx_port = softnic_portid;
2408 fwd_streams[i]->tx_queue = i;
2409 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2410 fwd_streams[i]->retry_enabled = retry_enabled;
2416 fwd_config_setup(void)
2418 cur_fwd_config.fwd_eng = cur_fwd_eng;
2419 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2420 icmp_echo_config_setup();
2424 #if defined RTE_LIBRTE_PMD_SOFTNIC
2425 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
2426 softnic_fwd_config_setup();
2431 if ((nb_rxq > 1) && (nb_txq > 1)){
2433 dcb_fwd_config_setup();
2435 rss_fwd_config_setup();
2438 simple_fwd_config_setup();
2442 mp_alloc_to_str(uint8_t mode)
2445 case MP_ALLOC_NATIVE:
2451 case MP_ALLOC_XMEM_HUGE:
2461 pkt_fwd_config_display(struct fwd_config *cfg)
2463 struct fwd_stream *fs;
2467 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2468 "NUMA support %s, MP allocation mode: %s\n",
2469 cfg->fwd_eng->fwd_mode_name,
2470 retry_enabled == 0 ? "" : " with retry",
2471 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2472 numa_support == 1 ? "enabled" : "disabled",
2473 mp_alloc_to_str(mp_alloc_type));
2476 printf("TX retry num: %u, delay between TX retries: %uus\n",
2477 burst_tx_retry_num, burst_tx_delay_time);
2478 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2479 printf("Logical Core %u (socket %u) forwards packets on "
2481 fwd_lcores_cpuids[lc_id],
2482 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2483 fwd_lcores[lc_id]->stream_nb);
2484 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2485 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2486 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2487 "P=%d/Q=%d (socket %u) ",
2488 fs->rx_port, fs->rx_queue,
2489 ports[fs->rx_port].socket_id,
2490 fs->tx_port, fs->tx_queue,
2491 ports[fs->tx_port].socket_id);
2492 print_ethaddr("peer=",
2493 &peer_eth_addrs[fs->peer_addr]);
2501 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2503 struct rte_ether_addr new_peer_addr;
2504 if (!rte_eth_dev_is_valid_port(port_id)) {
2505 printf("Error: Invalid port number %i\n", port_id);
2508 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
2509 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2512 peer_eth_addrs[port_id] = new_peer_addr;
2516 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2519 unsigned int lcore_cpuid;
2524 for (i = 0; i < nb_lc; i++) {
2525 lcore_cpuid = lcorelist[i];
2526 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2527 printf("lcore %u not enabled\n", lcore_cpuid);
2530 if (lcore_cpuid == rte_get_master_lcore()) {
2531 printf("lcore %u cannot be masked on for running "
2532 "packet forwarding, which is the master lcore "
2533 "and reserved for command line parsing only\n",
2538 fwd_lcores_cpuids[i] = lcore_cpuid;
2540 if (record_now == 0) {
2544 nb_cfg_lcores = (lcoreid_t) nb_lc;
2545 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2546 printf("previous number of forwarding cores %u - changed to "
2547 "number of configured cores %u\n",
2548 (unsigned int) nb_fwd_lcores, nb_lc);
2549 nb_fwd_lcores = (lcoreid_t) nb_lc;
2556 set_fwd_lcores_mask(uint64_t lcoremask)
2558 unsigned int lcorelist[64];
2562 if (lcoremask == 0) {
2563 printf("Invalid NULL mask of cores\n");
2567 for (i = 0; i < 64; i++) {
2568 if (! ((uint64_t)(1ULL << i) & lcoremask))
2570 lcorelist[nb_lc++] = i;
2572 return set_fwd_lcores_list(lcorelist, nb_lc);
2576 set_fwd_lcores_number(uint16_t nb_lc)
2578 if (nb_lc > nb_cfg_lcores) {
2579 printf("nb fwd cores %u > %u (max. number of configured "
2580 "lcores) - ignored\n",
2581 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2584 nb_fwd_lcores = (lcoreid_t) nb_lc;
2585 printf("Number of forwarding cores set to %u\n",
2586 (unsigned int) nb_fwd_lcores);
2590 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2598 for (i = 0; i < nb_pt; i++) {
2599 port_id = (portid_t) portlist[i];
2600 if (port_id_is_invalid(port_id, ENABLED_WARN))
2603 fwd_ports_ids[i] = port_id;
2605 if (record_now == 0) {
2609 nb_cfg_ports = (portid_t) nb_pt;
2610 if (nb_fwd_ports != (portid_t) nb_pt) {
2611 printf("previous number of forwarding ports %u - changed to "
2612 "number of configured ports %u\n",
2613 (unsigned int) nb_fwd_ports, nb_pt);
2614 nb_fwd_ports = (portid_t) nb_pt;
2619 * Parse the user input and obtain the list of forwarding ports
2622 * String containing the user input. User can specify
2623 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
2624 * For example, if the user wants to use all the available
2625 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
2626 * If the user wants to use only the ports 1,2 then the input
2628 * valid characters are '-' and ','
2629 * @param[out] values
2630 * This array will be filled with a list of port IDs
2631 * based on the user input
2632 * Note that duplicate entries are discarded and only the first
2633 * count entries in this array are port IDs and all the rest
2634 * will contain default values
2635 * @param[in] maxsize
2636 * This parameter denotes 2 things
2637 * 1) Number of elements in the values array
2638 * 2) Maximum value of each element in the values array
2640 * On success, returns total count of parsed port IDs
2641 * On failure, returns 0
2644 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
2646 unsigned int count = 0;
2650 unsigned int marked[maxsize];
2652 if (list == NULL || values == NULL)
2655 for (i = 0; i < (int)maxsize; i++)
2661 /*Remove the blank spaces if any*/
2662 while (isblank(*list))
2667 value = strtol(list, &end, 10);
2668 if (errno || end == NULL)
2670 if (value < 0 || value >= (int)maxsize)
2672 while (isblank(*end))
2674 if (*end == '-' && min == INT_MAX) {
2676 } else if ((*end == ',') || (*end == '\0')) {
2680 for (i = min; i <= max; i++) {
2681 if (count < maxsize) {
2693 } while (*end != '\0');
2699 parse_fwd_portlist(const char *portlist)
2701 unsigned int portcount;
2702 unsigned int portindex[RTE_MAX_ETHPORTS];
2703 unsigned int i, valid_port_count = 0;
2705 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
2707 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
2710 * Here we verify the validity of the ports
2711 * and thereby calculate the total number of
2714 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
2715 if (rte_eth_dev_is_valid_port(portindex[i])) {
2716 portindex[valid_port_count] = portindex[i];
2721 set_fwd_ports_list(portindex, valid_port_count);
2725 set_fwd_ports_mask(uint64_t portmask)
2727 unsigned int portlist[64];
2731 if (portmask == 0) {
2732 printf("Invalid NULL mask of ports\n");
2736 RTE_ETH_FOREACH_DEV(i) {
2737 if (! ((uint64_t)(1ULL << i) & portmask))
2739 portlist[nb_pt++] = i;
2741 set_fwd_ports_list(portlist, nb_pt);
2745 set_fwd_ports_number(uint16_t nb_pt)
2747 if (nb_pt > nb_cfg_ports) {
2748 printf("nb fwd ports %u > %u (number of configured "
2749 "ports) - ignored\n",
2750 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2753 nb_fwd_ports = (portid_t) nb_pt;
2754 printf("Number of forwarding ports set to %u\n",
2755 (unsigned int) nb_fwd_ports);
2759 port_is_forwarding(portid_t port_id)
2763 if (port_id_is_invalid(port_id, ENABLED_WARN))
2766 for (i = 0; i < nb_fwd_ports; i++) {
2767 if (fwd_ports_ids[i] == port_id)
2775 set_nb_pkt_per_burst(uint16_t nb)
2777 if (nb > MAX_PKT_BURST) {
2778 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2780 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2783 nb_pkt_per_burst = nb;
2784 printf("Number of packets per burst set to %u\n",
2785 (unsigned int) nb_pkt_per_burst);
2789 tx_split_get_name(enum tx_pkt_split split)
2793 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2794 if (tx_split_name[i].split == split)
2795 return tx_split_name[i].name;
2801 set_tx_pkt_split(const char *name)
2805 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2806 if (strcmp(tx_split_name[i].name, name) == 0) {
2807 tx_pkt_split = tx_split_name[i].split;
2811 printf("unknown value: \"%s\"\n", name);
2815 show_tx_pkt_segments(void)
2821 split = tx_split_get_name(tx_pkt_split);
2823 printf("Number of segments: %u\n", n);
2824 printf("Segment sizes: ");
2825 for (i = 0; i != n - 1; i++)
2826 printf("%hu,", tx_pkt_seg_lengths[i]);
2827 printf("%hu\n", tx_pkt_seg_lengths[i]);
2828 printf("Split packet: %s\n", split);
2832 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2834 uint16_t tx_pkt_len;
2837 if (nb_segs >= (unsigned) nb_txd) {
2838 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2839 nb_segs, (unsigned int) nb_txd);
2844 * Check that each segment length is greater or equal than
2845 * the mbuf data sise.
2846 * Check also that the total packet length is greater or equal than the
2847 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
2851 for (i = 0; i < nb_segs; i++) {
2852 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2853 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2854 i, seg_lengths[i], (unsigned) mbuf_data_size);
2857 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2859 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
2860 printf("total packet length=%u < %d - give up\n",
2861 (unsigned) tx_pkt_len,
2862 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
2866 for (i = 0; i < nb_segs; i++)
2867 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2869 tx_pkt_length = tx_pkt_len;
2870 tx_pkt_nb_segs = (uint8_t) nb_segs;
2874 setup_gro(const char *onoff, portid_t port_id)
2876 if (!rte_eth_dev_is_valid_port(port_id)) {
2877 printf("invalid port id %u\n", port_id);
2880 if (test_done == 0) {
2881 printf("Before enable/disable GRO,"
2882 " please stop forwarding first\n");
2885 if (strcmp(onoff, "on") == 0) {
2886 if (gro_ports[port_id].enable != 0) {
2887 printf("Port %u has enabled GRO. Please"
2888 " disable GRO first\n", port_id);
2891 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2892 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2893 gro_ports[port_id].param.max_flow_num =
2894 GRO_DEFAULT_FLOW_NUM;
2895 gro_ports[port_id].param.max_item_per_flow =
2896 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2898 gro_ports[port_id].enable = 1;
2900 if (gro_ports[port_id].enable == 0) {
2901 printf("Port %u has disabled GRO\n", port_id);
2904 gro_ports[port_id].enable = 0;
2909 setup_gro_flush_cycles(uint8_t cycles)
2911 if (test_done == 0) {
2912 printf("Before change flush interval for GRO,"
2913 " please stop forwarding first.\n");
2917 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
2918 GRO_DEFAULT_FLUSH_CYCLES) {
2919 printf("The flushing cycle be in the range"
2920 " of 1 to %u. Revert to the default"
2922 GRO_MAX_FLUSH_CYCLES,
2923 GRO_DEFAULT_FLUSH_CYCLES);
2924 cycles = GRO_DEFAULT_FLUSH_CYCLES;
2927 gro_flush_cycles = cycles;
2931 show_gro(portid_t port_id)
2933 struct rte_gro_param *param;
2934 uint32_t max_pkts_num;
2936 param = &gro_ports[port_id].param;
2938 if (!rte_eth_dev_is_valid_port(port_id)) {
2939 printf("Invalid port id %u.\n", port_id);
2942 if (gro_ports[port_id].enable) {
2943 printf("GRO type: TCP/IPv4\n");
2944 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2945 max_pkts_num = param->max_flow_num *
2946 param->max_item_per_flow;
2948 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
2949 printf("Max number of packets to perform GRO: %u\n",
2951 printf("Flushing cycles: %u\n", gro_flush_cycles);
2953 printf("Port %u doesn't enable GRO.\n", port_id);
2957 setup_gso(const char *mode, portid_t port_id)
2959 if (!rte_eth_dev_is_valid_port(port_id)) {
2960 printf("invalid port id %u\n", port_id);
2963 if (strcmp(mode, "on") == 0) {
2964 if (test_done == 0) {
2965 printf("before enabling GSO,"
2966 " please stop forwarding first\n");
2969 gso_ports[port_id].enable = 1;
2970 } else if (strcmp(mode, "off") == 0) {
2971 if (test_done == 0) {
2972 printf("before disabling GSO,"
2973 " please stop forwarding first\n");
2976 gso_ports[port_id].enable = 0;
2981 list_pkt_forwarding_modes(void)
2983 static char fwd_modes[128] = "";
2984 const char *separator = "|";
2985 struct fwd_engine *fwd_eng;
2988 if (strlen (fwd_modes) == 0) {
2989 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2990 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2991 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2992 strncat(fwd_modes, separator,
2993 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2995 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3002 list_pkt_forwarding_retry_modes(void)
3004 static char fwd_modes[128] = "";
3005 const char *separator = "|";
3006 struct fwd_engine *fwd_eng;
3009 if (strlen(fwd_modes) == 0) {
3010 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3011 if (fwd_eng == &rx_only_engine)
3013 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3015 strlen(fwd_modes) - 1);
3016 strncat(fwd_modes, separator,
3018 strlen(fwd_modes) - 1);
3020 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3027 set_pkt_forwarding_mode(const char *fwd_mode_name)
3029 struct fwd_engine *fwd_eng;
3033 while ((fwd_eng = fwd_engines[i]) != NULL) {
3034 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
3035 printf("Set %s packet forwarding mode%s\n",
3037 retry_enabled == 0 ? "" : " with retry");
3038 cur_fwd_eng = fwd_eng;
3043 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
3047 add_rx_dump_callbacks(portid_t portid)
3049 struct rte_eth_dev_info dev_info;
3053 if (port_id_is_invalid(portid, ENABLED_WARN))
3056 ret = eth_dev_info_get_print_err(portid, &dev_info);
3060 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3061 if (!ports[portid].rx_dump_cb[queue])
3062 ports[portid].rx_dump_cb[queue] =
3063 rte_eth_add_rx_callback(portid, queue,
3064 dump_rx_pkts, NULL);
3068 add_tx_dump_callbacks(portid_t portid)
3070 struct rte_eth_dev_info dev_info;
3074 if (port_id_is_invalid(portid, ENABLED_WARN))
3077 ret = eth_dev_info_get_print_err(portid, &dev_info);
3081 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3082 if (!ports[portid].tx_dump_cb[queue])
3083 ports[portid].tx_dump_cb[queue] =
3084 rte_eth_add_tx_callback(portid, queue,
3085 dump_tx_pkts, NULL);
3089 remove_rx_dump_callbacks(portid_t portid)
3091 struct rte_eth_dev_info dev_info;
3095 if (port_id_is_invalid(portid, ENABLED_WARN))
3098 ret = eth_dev_info_get_print_err(portid, &dev_info);
3102 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3103 if (ports[portid].rx_dump_cb[queue]) {
3104 rte_eth_remove_rx_callback(portid, queue,
3105 ports[portid].rx_dump_cb[queue]);
3106 ports[portid].rx_dump_cb[queue] = NULL;
3111 remove_tx_dump_callbacks(portid_t portid)
3113 struct rte_eth_dev_info dev_info;
3117 if (port_id_is_invalid(portid, ENABLED_WARN))
3120 ret = eth_dev_info_get_print_err(portid, &dev_info);
3124 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3125 if (ports[portid].tx_dump_cb[queue]) {
3126 rte_eth_remove_tx_callback(portid, queue,
3127 ports[portid].tx_dump_cb[queue]);
3128 ports[portid].tx_dump_cb[queue] = NULL;
3133 configure_rxtx_dump_callbacks(uint16_t verbose)
3137 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3138 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
3142 RTE_ETH_FOREACH_DEV(portid)
3144 if (verbose == 1 || verbose > 2)
3145 add_rx_dump_callbacks(portid);
3147 remove_rx_dump_callbacks(portid);
3149 add_tx_dump_callbacks(portid);
3151 remove_tx_dump_callbacks(portid);
3156 set_verbose_level(uint16_t vb_level)
3158 printf("Change verbose level from %u to %u\n",
3159 (unsigned int) verbose_level, (unsigned int) vb_level);
3160 verbose_level = vb_level;
3161 configure_rxtx_dump_callbacks(verbose_level);
3165 vlan_extend_set(portid_t port_id, int on)
3169 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3171 if (port_id_is_invalid(port_id, ENABLED_WARN))
3174 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3177 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
3178 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3180 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
3181 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3184 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3186 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
3187 "diag=%d\n", port_id, on, diag);
3188 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3192 rx_vlan_strip_set(portid_t port_id, int on)
3196 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3198 if (port_id_is_invalid(port_id, ENABLED_WARN))
3201 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3204 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
3205 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3207 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
3208 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3211 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3213 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
3214 "diag=%d\n", port_id, on, diag);
3215 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3219 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
3223 if (port_id_is_invalid(port_id, ENABLED_WARN))
3226 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
3228 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
3229 "diag=%d\n", port_id, queue_id, on, diag);
3233 rx_vlan_filter_set(portid_t port_id, int on)
3237 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3239 if (port_id_is_invalid(port_id, ENABLED_WARN))
3242 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3245 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
3246 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3248 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
3249 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3252 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3254 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
3255 "diag=%d\n", port_id, on, diag);
3256 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3260 rx_vlan_qinq_strip_set(portid_t port_id, int on)
3264 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3266 if (port_id_is_invalid(port_id, ENABLED_WARN))
3269 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3272 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
3273 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3275 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
3276 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3279 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3281 printf("%s(port_pi=%d, on=%d) failed "
3282 "diag=%d\n", __func__, port_id, on, diag);
3283 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3287 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
3291 if (port_id_is_invalid(port_id, ENABLED_WARN))
3293 if (vlan_id_is_invalid(vlan_id))
3295 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
3298 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
3300 port_id, vlan_id, on, diag);
3305 rx_vlan_all_filter_set(portid_t port_id, int on)
3309 if (port_id_is_invalid(port_id, ENABLED_WARN))
3311 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
3312 if (rx_vft_set(port_id, vlan_id, on))
3318 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
3322 if (port_id_is_invalid(port_id, ENABLED_WARN))
3325 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
3329 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
3331 port_id, vlan_type, tp_id, diag);
3335 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
3337 struct rte_eth_dev_info dev_info;
3340 if (port_id_is_invalid(port_id, ENABLED_WARN))
3342 if (vlan_id_is_invalid(vlan_id))
3345 if (ports[port_id].dev_conf.txmode.offloads &
3346 DEV_TX_OFFLOAD_QINQ_INSERT) {
3347 printf("Error, as QinQ has been enabled.\n");
3351 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3355 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
3356 printf("Error: vlan insert is not supported by port %d\n",
3361 tx_vlan_reset(port_id);
3362 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
3363 ports[port_id].tx_vlan_id = vlan_id;
3367 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
3369 struct rte_eth_dev_info dev_info;
3372 if (port_id_is_invalid(port_id, ENABLED_WARN))
3374 if (vlan_id_is_invalid(vlan_id))
3376 if (vlan_id_is_invalid(vlan_id_outer))
3379 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3383 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
3384 printf("Error: qinq insert not supported by port %d\n",
3389 tx_vlan_reset(port_id);
3390 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
3391 DEV_TX_OFFLOAD_QINQ_INSERT);
3392 ports[port_id].tx_vlan_id = vlan_id;
3393 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
3397 tx_vlan_reset(portid_t port_id)
3399 if (port_id_is_invalid(port_id, ENABLED_WARN))
3401 ports[port_id].dev_conf.txmode.offloads &=
3402 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
3403 DEV_TX_OFFLOAD_QINQ_INSERT);
3404 ports[port_id].tx_vlan_id = 0;
3405 ports[port_id].tx_vlan_id_outer = 0;
3409 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
3411 if (port_id_is_invalid(port_id, ENABLED_WARN))
3414 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
3418 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
3421 uint8_t existing_mapping_found = 0;
3423 if (port_id_is_invalid(port_id, ENABLED_WARN))
3426 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
3429 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
3430 printf("map_value not in required range 0..%d\n",
3431 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
3435 if (!is_rx) { /*then tx*/
3436 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3437 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3438 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
3439 tx_queue_stats_mappings[i].stats_counter_id = map_value;
3440 existing_mapping_found = 1;
3444 if (!existing_mapping_found) { /* A new additional mapping... */
3445 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
3446 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
3447 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
3448 nb_tx_queue_stats_mappings++;
3452 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3453 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3454 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
3455 rx_queue_stats_mappings[i].stats_counter_id = map_value;
3456 existing_mapping_found = 1;
3460 if (!existing_mapping_found) { /* A new additional mapping... */
3461 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
3462 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
3463 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
3464 nb_rx_queue_stats_mappings++;
3470 set_xstats_hide_zero(uint8_t on_off)
3472 xstats_hide_zero = on_off;
3476 print_fdir_mask(struct rte_eth_fdir_masks *mask)
3478 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
3480 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3481 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
3482 " tunnel_id: 0x%08x",
3483 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
3484 rte_be_to_cpu_32(mask->tunnel_id_mask));
3485 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3486 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
3487 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
3488 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
3490 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
3491 rte_be_to_cpu_16(mask->src_port_mask),
3492 rte_be_to_cpu_16(mask->dst_port_mask));
3494 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3495 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
3496 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3497 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3498 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3500 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3501 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3502 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3503 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3504 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3511 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3513 struct rte_eth_flex_payload_cfg *cfg;
3516 for (i = 0; i < flex_conf->nb_payloads; i++) {
3517 cfg = &flex_conf->flex_set[i];
3518 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3520 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3521 printf("\n L2_PAYLOAD: ");
3522 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3523 printf("\n L3_PAYLOAD: ");
3524 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3525 printf("\n L4_PAYLOAD: ");
3527 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3528 for (j = 0; j < num; j++)
3529 printf(" %-5u", cfg->src_offset[j]);
3535 flowtype_to_str(uint16_t flow_type)
3537 struct flow_type_info {
3543 static struct flow_type_info flowtype_str_table[] = {
3544 {"raw", RTE_ETH_FLOW_RAW},
3545 {"ipv4", RTE_ETH_FLOW_IPV4},
3546 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3547 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3548 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3549 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3550 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3551 {"ipv6", RTE_ETH_FLOW_IPV6},
3552 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3553 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3554 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3555 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3556 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3557 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3558 {"port", RTE_ETH_FLOW_PORT},
3559 {"vxlan", RTE_ETH_FLOW_VXLAN},
3560 {"geneve", RTE_ETH_FLOW_GENEVE},
3561 {"nvgre", RTE_ETH_FLOW_NVGRE},
3562 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
3565 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3566 if (flowtype_str_table[i].ftype == flow_type)
3567 return flowtype_str_table[i].str;
3574 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3576 struct rte_eth_fdir_flex_mask *mask;
3580 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3581 mask = &flex_conf->flex_mask[i];
3582 p = flowtype_to_str(mask->flow_type);
3583 printf("\n %s:\t", p ? p : "unknown");
3584 for (j = 0; j < num; j++)
3585 printf(" %02x", mask->mask[j]);
3591 print_fdir_flow_type(uint32_t flow_types_mask)
3596 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3597 if (!(flow_types_mask & (1 << i)))
3599 p = flowtype_to_str(i);
3609 fdir_get_infos(portid_t port_id)
3611 struct rte_eth_fdir_stats fdir_stat;
3612 struct rte_eth_fdir_info fdir_info;
3615 static const char *fdir_stats_border = "########################";
3617 if (port_id_is_invalid(port_id, ENABLED_WARN))
3619 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3621 printf("\n FDIR is not supported on port %-2d\n",
3626 memset(&fdir_info, 0, sizeof(fdir_info));
3627 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3628 RTE_ETH_FILTER_INFO, &fdir_info);
3629 memset(&fdir_stat, 0, sizeof(fdir_stat));
3630 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3631 RTE_ETH_FILTER_STATS, &fdir_stat);
3632 printf("\n %s FDIR infos for port %-2d %s\n",
3633 fdir_stats_border, port_id, fdir_stats_border);
3635 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3636 printf(" PERFECT\n");
3637 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3638 printf(" PERFECT-MAC-VLAN\n");
3639 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3640 printf(" PERFECT-TUNNEL\n");
3641 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3642 printf(" SIGNATURE\n");
3644 printf(" DISABLE\n");
3645 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3646 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3647 printf(" SUPPORTED FLOW TYPE: ");
3648 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3650 printf(" FLEX PAYLOAD INFO:\n");
3651 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3652 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3653 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3654 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3655 fdir_info.flex_payload_unit,
3656 fdir_info.max_flex_payload_segment_num,
3657 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3659 print_fdir_mask(&fdir_info.mask);
3660 if (fdir_info.flex_conf.nb_payloads > 0) {
3661 printf(" FLEX PAYLOAD SRC OFFSET:");
3662 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3664 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3665 printf(" FLEX MASK CFG:");
3666 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3668 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3669 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3670 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3671 fdir_info.guarant_spc, fdir_info.best_spc);
3672 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3673 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3674 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3675 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3676 fdir_stat.collision, fdir_stat.free,
3677 fdir_stat.maxhash, fdir_stat.maxlen,
3678 fdir_stat.add, fdir_stat.remove,
3679 fdir_stat.f_add, fdir_stat.f_remove);
3680 printf(" %s############################%s\n",
3681 fdir_stats_border, fdir_stats_border);
3685 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3687 struct rte_port *port;
3688 struct rte_eth_fdir_flex_conf *flex_conf;
3691 port = &ports[port_id];
3692 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3693 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3694 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3699 if (i >= RTE_ETH_FLOW_MAX) {
3700 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3701 idx = flex_conf->nb_flexmasks;
3702 flex_conf->nb_flexmasks++;
3704 printf("The flex mask table is full. Can not set flex"
3705 " mask for flow_type(%u).", cfg->flow_type);
3709 rte_memcpy(&flex_conf->flex_mask[idx],
3711 sizeof(struct rte_eth_fdir_flex_mask));
3715 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3717 struct rte_port *port;
3718 struct rte_eth_fdir_flex_conf *flex_conf;
3721 port = &ports[port_id];
3722 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3723 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3724 if (cfg->type == flex_conf->flex_set[i].type) {
3729 if (i >= RTE_ETH_PAYLOAD_MAX) {
3730 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3731 idx = flex_conf->nb_payloads;
3732 flex_conf->nb_payloads++;
3734 printf("The flex payload table is full. Can not set"
3735 " flex payload for type(%u).", cfg->type);
3739 rte_memcpy(&flex_conf->flex_set[idx],
3741 sizeof(struct rte_eth_flex_payload_cfg));
3746 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3748 #ifdef RTE_LIBRTE_IXGBE_PMD
3752 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3754 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3758 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3759 is_rx ? "rx" : "tx", port_id, diag);
3762 printf("VF %s setting not supported for port %d\n",
3763 is_rx ? "Rx" : "Tx", port_id);
3769 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3772 struct rte_eth_link link;
3775 if (port_id_is_invalid(port_id, ENABLED_WARN))
3777 ret = eth_link_get_nowait_print_err(port_id, &link);
3780 if (rate > link.link_speed) {
3781 printf("Invalid rate value:%u bigger than link speed: %u\n",
3782 rate, link.link_speed);
3785 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3788 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3794 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3796 int diag = -ENOTSUP;
3800 RTE_SET_USED(q_msk);
3802 #ifdef RTE_LIBRTE_IXGBE_PMD
3803 if (diag == -ENOTSUP)
3804 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3807 #ifdef RTE_LIBRTE_BNXT_PMD
3808 if (diag == -ENOTSUP)
3809 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3814 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3820 * Functions to manage the set of filtered Multicast MAC addresses.
3822 * A pool of filtered multicast MAC addresses is associated with each port.
3823 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3824 * The address of the pool and the number of valid multicast MAC addresses
3825 * recorded in the pool are stored in the fields "mc_addr_pool" and
3826 * "mc_addr_nb" of the "rte_port" data structure.
3828 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3829 * to be supplied a contiguous array of multicast MAC addresses.
3830 * To comply with this constraint, the set of multicast addresses recorded
3831 * into the pool are systematically compacted at the beginning of the pool.
3832 * Hence, when a multicast address is removed from the pool, all following
3833 * addresses, if any, are copied back to keep the set contiguous.
3835 #define MCAST_POOL_INC 32
3838 mcast_addr_pool_extend(struct rte_port *port)
3840 struct rte_ether_addr *mc_pool;
3841 size_t mc_pool_size;
3844 * If a free entry is available at the end of the pool, just
3845 * increment the number of recorded multicast addresses.
3847 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3853 * [re]allocate a pool with MCAST_POOL_INC more entries.
3854 * The previous test guarantees that port->mc_addr_nb is a multiple
3855 * of MCAST_POOL_INC.
3857 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
3859 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
3861 if (mc_pool == NULL) {
3862 printf("allocation of pool of %u multicast addresses failed\n",
3863 port->mc_addr_nb + MCAST_POOL_INC);
3867 port->mc_addr_pool = mc_pool;
3874 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
3876 if (mcast_addr_pool_extend(port) != 0)
3878 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
3882 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3885 if (addr_idx == port->mc_addr_nb) {
3886 /* No need to recompact the set of multicast addressses. */
3887 if (port->mc_addr_nb == 0) {
3888 /* free the pool of multicast addresses. */
3889 free(port->mc_addr_pool);
3890 port->mc_addr_pool = NULL;
3894 memmove(&port->mc_addr_pool[addr_idx],
3895 &port->mc_addr_pool[addr_idx + 1],
3896 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
3900 eth_port_multicast_addr_list_set(portid_t port_id)
3902 struct rte_port *port;
3905 port = &ports[port_id];
3906 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3909 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3910 port_id, port->mc_addr_nb, diag);
3916 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
3918 struct rte_port *port;
3921 if (port_id_is_invalid(port_id, ENABLED_WARN))
3924 port = &ports[port_id];
3927 * Check that the added multicast MAC address is not already recorded
3928 * in the pool of multicast addresses.
3930 for (i = 0; i < port->mc_addr_nb; i++) {
3931 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3932 printf("multicast address already filtered by port\n");
3937 mcast_addr_pool_append(port, mc_addr);
3938 if (eth_port_multicast_addr_list_set(port_id) < 0)
3939 /* Rollback on failure, remove the address from the pool */
3940 mcast_addr_pool_remove(port, i);
3944 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
3946 struct rte_port *port;
3949 if (port_id_is_invalid(port_id, ENABLED_WARN))
3952 port = &ports[port_id];
3955 * Search the pool of multicast MAC addresses for the removed address.
3957 for (i = 0; i < port->mc_addr_nb; i++) {
3958 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3961 if (i == port->mc_addr_nb) {
3962 printf("multicast address not filtered by port %d\n", port_id);
3966 mcast_addr_pool_remove(port, i);
3967 if (eth_port_multicast_addr_list_set(port_id) < 0)
3968 /* Rollback on failure, add the address back into the pool */
3969 mcast_addr_pool_append(port, mc_addr);
3973 port_dcb_info_display(portid_t port_id)
3975 struct rte_eth_dcb_info dcb_info;
3978 static const char *border = "================";
3980 if (port_id_is_invalid(port_id, ENABLED_WARN))
3983 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3985 printf("\n Failed to get dcb infos on port %-2d\n",
3989 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3990 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3992 for (i = 0; i < dcb_info.nb_tcs; i++)
3994 printf("\n Priority : ");
3995 for (i = 0; i < dcb_info.nb_tcs; i++)
3996 printf("\t%4d", dcb_info.prio_tc[i]);
3997 printf("\n BW percent :");
3998 for (i = 0; i < dcb_info.nb_tcs; i++)
3999 printf("\t%4d%%", dcb_info.tc_bws[i]);
4000 printf("\n RXQ base : ");
4001 for (i = 0; i < dcb_info.nb_tcs; i++)
4002 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
4003 printf("\n RXQ number :");
4004 for (i = 0; i < dcb_info.nb_tcs; i++)
4005 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
4006 printf("\n TXQ base : ");
4007 for (i = 0; i < dcb_info.nb_tcs; i++)
4008 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
4009 printf("\n TXQ number :");
4010 for (i = 0; i < dcb_info.nb_tcs; i++)
4011 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
4016 open_file(const char *file_path, uint32_t *size)
4018 int fd = open(file_path, O_RDONLY);
4020 uint8_t *buf = NULL;
4028 printf("%s: Failed to open %s\n", __func__, file_path);
4032 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
4034 printf("%s: File operations failed\n", __func__);
4038 pkg_size = st_buf.st_size;
4041 printf("%s: File operations failed\n", __func__);
4045 buf = (uint8_t *)malloc(pkg_size);
4048 printf("%s: Failed to malloc memory\n", __func__);
4052 ret = read(fd, buf, pkg_size);
4055 printf("%s: File read operation failed\n", __func__);
4069 save_file(const char *file_path, uint8_t *buf, uint32_t size)
4071 FILE *fh = fopen(file_path, "wb");
4074 printf("%s: Failed to open %s\n", __func__, file_path);
4078 if (fwrite(buf, 1, size, fh) != size) {
4080 printf("%s: File write operation failed\n", __func__);
4090 close_file(uint8_t *buf)
4101 port_queue_region_info_display(portid_t port_id, void *buf)
4103 #ifdef RTE_LIBRTE_I40E_PMD
4105 struct rte_pmd_i40e_queue_regions *info =
4106 (struct rte_pmd_i40e_queue_regions *)buf;
4107 static const char *queue_region_info_stats_border = "-------";
4109 if (!info->queue_region_number)
4110 printf("there is no region has been set before");
4112 printf("\n %s All queue region info for port=%2d %s",
4113 queue_region_info_stats_border, port_id,
4114 queue_region_info_stats_border);
4115 printf("\n queue_region_number: %-14u \n",
4116 info->queue_region_number);
4118 for (i = 0; i < info->queue_region_number; i++) {
4119 printf("\n region_id: %-14u queue_number: %-14u "
4120 "queue_start_index: %-14u \n",
4121 info->region[i].region_id,
4122 info->region[i].queue_num,
4123 info->region[i].queue_start_index);
4125 printf(" user_priority_num is %-14u :",
4126 info->region[i].user_priority_num);
4127 for (j = 0; j < info->region[i].user_priority_num; j++)
4128 printf(" %-14u ", info->region[i].user_priority[j]);
4130 printf("\n flowtype_num is %-14u :",
4131 info->region[i].flowtype_num);
4132 for (j = 0; j < info->region[i].flowtype_num; j++)
4133 printf(" %-14u ", info->region[i].hw_flowtype[j]);
4136 RTE_SET_USED(port_id);
4144 show_macs(portid_t port_id)
4146 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4147 struct rte_eth_dev_info dev_info;
4148 struct rte_ether_addr *addr;
4149 uint32_t i, num_macs = 0;
4150 struct rte_eth_dev *dev;
4152 dev = &rte_eth_devices[port_id];
4154 rte_eth_dev_info_get(port_id, &dev_info);
4156 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4157 addr = &dev->data->mac_addrs[i];
4159 /* skip zero address */
4160 if (rte_is_zero_ether_addr(addr))
4166 printf("Number of MAC address added: %d\n", num_macs);
4168 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4169 addr = &dev->data->mac_addrs[i];
4171 /* skip zero address */
4172 if (rte_is_zero_ether_addr(addr))
4175 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4176 printf(" %s\n", buf);
4181 show_mcast_macs(portid_t port_id)
4183 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4184 struct rte_ether_addr *addr;
4185 struct rte_port *port;
4188 port = &ports[port_id];
4190 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
4192 for (i = 0; i < port->mc_addr_nb; i++) {
4193 addr = &port->mc_addr_pool[i];
4195 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4196 printf(" %s\n", buf);