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 static char *flowtype_to_str(uint16_t flow_type);
58 enum tx_pkt_split split;
62 .split = TX_PKT_SPLIT_OFF,
66 .split = TX_PKT_SPLIT_ON,
70 .split = TX_PKT_SPLIT_RND,
75 const struct rss_type_info rss_type_table[] = {
76 { "all", ETH_RSS_IP | ETH_RSS_TCP |
77 ETH_RSS_UDP | ETH_RSS_SCTP |
80 { "ipv4", ETH_RSS_IPV4 },
81 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
82 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
83 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
84 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
85 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
86 { "ipv6", ETH_RSS_IPV6 },
87 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
88 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
89 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
90 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
91 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
92 { "l2-payload", ETH_RSS_L2_PAYLOAD },
93 { "ipv6-ex", ETH_RSS_IPV6_EX },
94 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
95 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
96 { "port", ETH_RSS_PORT },
97 { "vxlan", ETH_RSS_VXLAN },
98 { "geneve", ETH_RSS_GENEVE },
99 { "nvgre", ETH_RSS_NVGRE },
100 { "ip", ETH_RSS_IP },
101 { "udp", ETH_RSS_UDP },
102 { "tcp", ETH_RSS_TCP },
103 { "sctp", ETH_RSS_SCTP },
104 { "tunnel", ETH_RSS_TUNNEL },
105 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
106 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
107 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
108 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
113 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
115 char buf[RTE_ETHER_ADDR_FMT_SIZE];
116 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
117 printf("%s%s", name, buf);
121 nic_stats_display(portid_t port_id)
123 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
124 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
125 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
126 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
127 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
128 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
130 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
131 struct rte_eth_stats stats;
132 struct rte_port *port = &ports[port_id];
135 static const char *nic_stats_border = "########################";
137 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
141 rte_eth_stats_get(port_id, &stats);
142 printf("\n %s NIC statistics for port %-2d %s\n",
143 nic_stats_border, port_id, nic_stats_border);
145 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
146 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
148 stats.ipackets, stats.imissed, stats.ibytes);
149 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
150 printf(" RX-nombuf: %-10"PRIu64"\n",
152 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
154 stats.opackets, stats.oerrors, stats.obytes);
157 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
158 " RX-bytes: %10"PRIu64"\n",
159 stats.ipackets, stats.ierrors, stats.ibytes);
160 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
161 printf(" RX-nombuf: %10"PRIu64"\n",
163 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
164 " TX-bytes: %10"PRIu64"\n",
165 stats.opackets, stats.oerrors, stats.obytes);
168 if (port->rx_queue_stats_mapping_enabled) {
170 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
171 printf(" Stats reg %2d RX-packets: %10"PRIu64
172 " RX-errors: %10"PRIu64
173 " RX-bytes: %10"PRIu64"\n",
174 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
177 if (port->tx_queue_stats_mapping_enabled) {
179 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
180 printf(" Stats reg %2d TX-packets: %10"PRIu64
181 " TX-bytes: %10"PRIu64"\n",
182 i, stats.q_opackets[i], stats.q_obytes[i]);
186 diff_cycles = prev_cycles[port_id];
187 prev_cycles[port_id] = rte_rdtsc();
189 diff_cycles = prev_cycles[port_id] - diff_cycles;
191 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
192 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
193 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
194 (stats.opackets - prev_pkts_tx[port_id]) : 0;
195 prev_pkts_rx[port_id] = stats.ipackets;
196 prev_pkts_tx[port_id] = stats.opackets;
197 mpps_rx = diff_cycles > 0 ?
198 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
199 mpps_tx = diff_cycles > 0 ?
200 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
202 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
203 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
204 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
205 (stats.obytes - prev_bytes_tx[port_id]) : 0;
206 prev_bytes_rx[port_id] = stats.ibytes;
207 prev_bytes_tx[port_id] = stats.obytes;
208 mbps_rx = diff_cycles > 0 ?
209 diff_bytes_rx * rte_get_tsc_hz() / diff_cycles : 0;
210 mbps_tx = diff_cycles > 0 ?
211 diff_bytes_tx * rte_get_tsc_hz() / diff_cycles : 0;
213 printf("\n Throughput (since last show)\n");
214 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
215 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
216 mpps_tx, mbps_tx * 8);
218 printf(" %s############################%s\n",
219 nic_stats_border, nic_stats_border);
223 nic_stats_clear(portid_t port_id)
225 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
229 rte_eth_stats_reset(port_id);
230 printf("\n NIC statistics for port %d cleared\n", port_id);
234 nic_xstats_display(portid_t port_id)
236 struct rte_eth_xstat *xstats;
237 int cnt_xstats, idx_xstat;
238 struct rte_eth_xstat_name *xstats_names;
240 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
244 printf("###### NIC extended statistics for port %-2d\n", port_id);
245 if (!rte_eth_dev_is_valid_port(port_id)) {
246 printf("Error: Invalid port number %i\n", port_id);
251 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
252 if (cnt_xstats < 0) {
253 printf("Error: Cannot get count of xstats\n");
257 /* Get id-name lookup table */
258 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
259 if (xstats_names == NULL) {
260 printf("Cannot allocate memory for xstats lookup\n");
263 if (cnt_xstats != rte_eth_xstats_get_names(
264 port_id, xstats_names, cnt_xstats)) {
265 printf("Error: Cannot get xstats lookup\n");
270 /* Get stats themselves */
271 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
272 if (xstats == NULL) {
273 printf("Cannot allocate memory for xstats\n");
277 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
278 printf("Error: Unable to get xstats\n");
285 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
286 if (xstats_hide_zero && !xstats[idx_xstat].value)
288 printf("%s: %"PRIu64"\n",
289 xstats_names[idx_xstat].name,
290 xstats[idx_xstat].value);
297 nic_xstats_clear(portid_t port_id)
301 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
305 ret = rte_eth_xstats_reset(port_id);
307 printf("%s: Error: failed to reset xstats (port %u): %s",
308 __func__, port_id, strerror(ret));
313 nic_stats_mapping_display(portid_t port_id)
315 struct rte_port *port = &ports[port_id];
318 static const char *nic_stats_mapping_border = "########################";
320 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
325 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
326 printf("Port id %d - either does not support queue statistic mapping or"
327 " no queue statistic mapping set\n", port_id);
331 printf("\n %s NIC statistics mapping for port %-2d %s\n",
332 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
334 if (port->rx_queue_stats_mapping_enabled) {
335 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
336 if (rx_queue_stats_mappings[i].port_id == port_id) {
337 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
338 rx_queue_stats_mappings[i].queue_id,
339 rx_queue_stats_mappings[i].stats_counter_id);
346 if (port->tx_queue_stats_mapping_enabled) {
347 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
348 if (tx_queue_stats_mappings[i].port_id == port_id) {
349 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
350 tx_queue_stats_mappings[i].queue_id,
351 tx_queue_stats_mappings[i].stats_counter_id);
356 printf(" %s####################################%s\n",
357 nic_stats_mapping_border, nic_stats_mapping_border);
361 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
363 struct rte_eth_burst_mode mode;
364 struct rte_eth_rxq_info qinfo;
366 static const char *info_border = "*********************";
368 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
370 printf("Failed to retrieve information for port: %u, "
371 "RX queue: %hu\nerror desc: %s(%d)\n",
372 port_id, queue_id, strerror(-rc), rc);
376 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
377 info_border, port_id, queue_id, info_border);
379 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
380 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
381 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
382 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
383 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
384 printf("\nRX drop packets: %s",
385 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
386 printf("\nRX deferred start: %s",
387 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
388 printf("\nRX scattered packets: %s",
389 (qinfo.scattered_rx != 0) ? "on" : "off");
390 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
392 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
393 printf("\nBurst mode: %s%s",
395 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
396 " (per queue)" : "");
402 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
404 struct rte_eth_burst_mode mode;
405 struct rte_eth_txq_info qinfo;
407 static const char *info_border = "*********************";
409 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
411 printf("Failed to retrieve information for port: %u, "
412 "TX queue: %hu\nerror desc: %s(%d)\n",
413 port_id, queue_id, strerror(-rc), rc);
417 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
418 info_border, port_id, queue_id, info_border);
420 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
421 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
422 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
423 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
424 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
425 printf("\nTX deferred start: %s",
426 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
427 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
429 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
430 printf("\nBurst mode: %s%s",
432 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
433 " (per queue)" : "");
438 static int bus_match_all(const struct rte_bus *bus, const void *data)
446 device_infos_display(const char *identifier)
448 static const char *info_border = "*********************";
449 struct rte_bus *start = NULL, *next;
450 struct rte_dev_iterator dev_iter;
451 char name[RTE_ETH_NAME_MAX_LEN];
452 struct rte_ether_addr mac_addr;
453 struct rte_device *dev;
454 struct rte_devargs da;
458 memset(&da, 0, sizeof(da));
462 if (rte_devargs_parsef(&da, "%s", identifier)) {
463 printf("cannot parse identifier\n");
470 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
473 if (identifier && da.bus != next)
476 /* Skip buses that don't have iterate method */
477 if (!next->dev_iterate)
480 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
481 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
485 /* Check for matching device if identifier is present */
487 strncmp(da.name, dev->name, strlen(dev->name)))
489 printf("\n%s Infos for device %s %s\n",
490 info_border, dev->name, info_border);
491 printf("Bus name: %s", dev->bus->name);
492 printf("\nDriver name: %s", dev->driver->name);
493 printf("\nDevargs: %s",
494 dev->devargs ? dev->devargs->args : "");
495 printf("\nConnect to socket: %d", dev->numa_node);
498 /* List ports with matching device name */
499 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
500 printf("\n\tPort id: %-2d", port_id);
501 if (eth_macaddr_get_print_err(port_id,
503 print_ethaddr("\n\tMAC address: ",
505 rte_eth_dev_get_name_by_port(port_id, name);
506 printf("\n\tDevice name: %s", name);
514 port_infos_display(portid_t port_id)
516 struct rte_port *port;
517 struct rte_ether_addr mac_addr;
518 struct rte_eth_link link;
519 struct rte_eth_dev_info dev_info;
521 struct rte_mempool * mp;
522 static const char *info_border = "*********************";
524 char name[RTE_ETH_NAME_MAX_LEN];
527 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
531 port = &ports[port_id];
532 ret = eth_link_get_nowait_print_err(port_id, &link);
536 ret = eth_dev_info_get_print_err(port_id, &dev_info);
540 printf("\n%s Infos for port %-2d %s\n",
541 info_border, port_id, info_border);
542 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
543 print_ethaddr("MAC address: ", &mac_addr);
544 rte_eth_dev_get_name_by_port(port_id, name);
545 printf("\nDevice name: %s", name);
546 printf("\nDriver name: %s", dev_info.driver_name);
547 if (dev_info.device->devargs && dev_info.device->devargs->args)
548 printf("\nDevargs: %s", dev_info.device->devargs->args);
549 printf("\nConnect to socket: %u", port->socket_id);
551 if (port_numa[port_id] != NUMA_NO_CONFIG) {
552 mp = mbuf_pool_find(port_numa[port_id]);
554 printf("\nmemory allocation on the socket: %d",
557 printf("\nmemory allocation on the socket: %u",port->socket_id);
559 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
560 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
561 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
562 ("full-duplex") : ("half-duplex"));
564 if (!rte_eth_dev_get_mtu(port_id, &mtu))
565 printf("MTU: %u\n", mtu);
567 printf("Promiscuous mode: %s\n",
568 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
569 printf("Allmulticast mode: %s\n",
570 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
571 printf("Maximum number of MAC addresses: %u\n",
572 (unsigned int)(port->dev_info.max_mac_addrs));
573 printf("Maximum number of MAC addresses of hash filtering: %u\n",
574 (unsigned int)(port->dev_info.max_hash_mac_addrs));
576 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
577 if (vlan_offload >= 0){
578 printf("VLAN offload: \n");
579 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
580 printf(" strip on, ");
582 printf(" strip off, ");
584 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
585 printf("filter on, ");
587 printf("filter off, ");
589 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
590 printf("extend on, ");
592 printf("extend off, ");
594 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
595 printf("qinq strip on\n");
597 printf("qinq strip off\n");
600 if (dev_info.hash_key_size > 0)
601 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
602 if (dev_info.reta_size > 0)
603 printf("Redirection table size: %u\n", dev_info.reta_size);
604 if (!dev_info.flow_type_rss_offloads)
605 printf("No RSS offload flow type is supported.\n");
610 printf("Supported RSS offload flow types:\n");
611 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
612 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
613 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
615 p = flowtype_to_str(i);
619 printf(" user defined %d\n", i);
623 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
624 printf("Maximum configurable length of RX packet: %u\n",
625 dev_info.max_rx_pktlen);
626 printf("Maximum configurable size of LRO aggregated packet: %u\n",
627 dev_info.max_lro_pkt_size);
628 if (dev_info.max_vfs)
629 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
630 if (dev_info.max_vmdq_pools)
631 printf("Maximum number of VMDq pools: %u\n",
632 dev_info.max_vmdq_pools);
634 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
635 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
636 printf("Max possible number of RXDs per queue: %hu\n",
637 dev_info.rx_desc_lim.nb_max);
638 printf("Min possible number of RXDs per queue: %hu\n",
639 dev_info.rx_desc_lim.nb_min);
640 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
642 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
643 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
644 printf("Max possible number of TXDs per queue: %hu\n",
645 dev_info.tx_desc_lim.nb_max);
646 printf("Min possible number of TXDs per queue: %hu\n",
647 dev_info.tx_desc_lim.nb_min);
648 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
649 printf("Max segment number per packet: %hu\n",
650 dev_info.tx_desc_lim.nb_seg_max);
651 printf("Max segment number per MTU/TSO: %hu\n",
652 dev_info.tx_desc_lim.nb_mtu_seg_max);
654 /* Show switch info only if valid switch domain and port id is set */
655 if (dev_info.switch_info.domain_id !=
656 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
657 if (dev_info.switch_info.name)
658 printf("Switch name: %s\n", dev_info.switch_info.name);
660 printf("Switch domain Id: %u\n",
661 dev_info.switch_info.domain_id);
662 printf("Switch Port Id: %u\n",
663 dev_info.switch_info.port_id);
668 port_summary_header_display(void)
670 uint16_t port_number;
672 port_number = rte_eth_dev_count_avail();
673 printf("Number of available ports: %i\n", port_number);
674 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
675 "Driver", "Status", "Link");
679 port_summary_display(portid_t port_id)
681 struct rte_ether_addr mac_addr;
682 struct rte_eth_link link;
683 struct rte_eth_dev_info dev_info;
684 char name[RTE_ETH_NAME_MAX_LEN];
687 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
692 ret = eth_link_get_nowait_print_err(port_id, &link);
696 ret = eth_dev_info_get_print_err(port_id, &dev_info);
700 rte_eth_dev_get_name_by_port(port_id, name);
701 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
705 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
706 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
707 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
708 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
709 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
710 (unsigned int) link.link_speed);
714 port_offload_cap_display(portid_t port_id)
716 struct rte_eth_dev_info dev_info;
717 static const char *info_border = "************";
720 if (port_id_is_invalid(port_id, ENABLED_WARN))
723 ret = eth_dev_info_get_print_err(port_id, &dev_info);
727 printf("\n%s Port %d supported offload features: %s\n",
728 info_border, port_id, info_border);
730 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
731 printf("VLAN stripped: ");
732 if (ports[port_id].dev_conf.rxmode.offloads &
733 DEV_RX_OFFLOAD_VLAN_STRIP)
739 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
740 printf("Double VLANs stripped: ");
741 if (ports[port_id].dev_conf.rxmode.offloads &
742 DEV_RX_OFFLOAD_QINQ_STRIP)
748 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
749 printf("RX IPv4 checksum: ");
750 if (ports[port_id].dev_conf.rxmode.offloads &
751 DEV_RX_OFFLOAD_IPV4_CKSUM)
757 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
758 printf("RX UDP checksum: ");
759 if (ports[port_id].dev_conf.rxmode.offloads &
760 DEV_RX_OFFLOAD_UDP_CKSUM)
766 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
767 printf("RX TCP checksum: ");
768 if (ports[port_id].dev_conf.rxmode.offloads &
769 DEV_RX_OFFLOAD_TCP_CKSUM)
775 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) {
776 printf("RX SCTP checksum: ");
777 if (ports[port_id].dev_conf.rxmode.offloads &
778 DEV_RX_OFFLOAD_SCTP_CKSUM)
784 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
785 printf("RX Outer IPv4 checksum: ");
786 if (ports[port_id].dev_conf.rxmode.offloads &
787 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
793 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) {
794 printf("RX Outer UDP checksum: ");
795 if (ports[port_id].dev_conf.rxmode.offloads &
796 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM)
802 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
803 printf("Large receive offload: ");
804 if (ports[port_id].dev_conf.rxmode.offloads &
805 DEV_RX_OFFLOAD_TCP_LRO)
811 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
812 printf("HW timestamp: ");
813 if (ports[port_id].dev_conf.rxmode.offloads &
814 DEV_RX_OFFLOAD_TIMESTAMP)
820 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) {
821 printf("Rx Keep CRC: ");
822 if (ports[port_id].dev_conf.rxmode.offloads &
823 DEV_RX_OFFLOAD_KEEP_CRC)
829 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) {
830 printf("RX offload security: ");
831 if (ports[port_id].dev_conf.rxmode.offloads &
832 DEV_RX_OFFLOAD_SECURITY)
838 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
839 printf("VLAN insert: ");
840 if (ports[port_id].dev_conf.txmode.offloads &
841 DEV_TX_OFFLOAD_VLAN_INSERT)
847 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
848 printf("Double VLANs insert: ");
849 if (ports[port_id].dev_conf.txmode.offloads &
850 DEV_TX_OFFLOAD_QINQ_INSERT)
856 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
857 printf("TX IPv4 checksum: ");
858 if (ports[port_id].dev_conf.txmode.offloads &
859 DEV_TX_OFFLOAD_IPV4_CKSUM)
865 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
866 printf("TX UDP checksum: ");
867 if (ports[port_id].dev_conf.txmode.offloads &
868 DEV_TX_OFFLOAD_UDP_CKSUM)
874 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
875 printf("TX TCP checksum: ");
876 if (ports[port_id].dev_conf.txmode.offloads &
877 DEV_TX_OFFLOAD_TCP_CKSUM)
883 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
884 printf("TX SCTP checksum: ");
885 if (ports[port_id].dev_conf.txmode.offloads &
886 DEV_TX_OFFLOAD_SCTP_CKSUM)
892 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
893 printf("TX Outer IPv4 checksum: ");
894 if (ports[port_id].dev_conf.txmode.offloads &
895 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
901 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
902 printf("TX TCP segmentation: ");
903 if (ports[port_id].dev_conf.txmode.offloads &
904 DEV_TX_OFFLOAD_TCP_TSO)
910 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
911 printf("TX UDP segmentation: ");
912 if (ports[port_id].dev_conf.txmode.offloads &
913 DEV_TX_OFFLOAD_UDP_TSO)
919 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
920 printf("TSO for VXLAN tunnel packet: ");
921 if (ports[port_id].dev_conf.txmode.offloads &
922 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
928 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
929 printf("TSO for GRE tunnel packet: ");
930 if (ports[port_id].dev_conf.txmode.offloads &
931 DEV_TX_OFFLOAD_GRE_TNL_TSO)
937 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
938 printf("TSO for IPIP tunnel packet: ");
939 if (ports[port_id].dev_conf.txmode.offloads &
940 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
946 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
947 printf("TSO for GENEVE tunnel packet: ");
948 if (ports[port_id].dev_conf.txmode.offloads &
949 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
955 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) {
956 printf("IP tunnel TSO: ");
957 if (ports[port_id].dev_conf.txmode.offloads &
958 DEV_TX_OFFLOAD_IP_TNL_TSO)
964 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) {
965 printf("UDP tunnel TSO: ");
966 if (ports[port_id].dev_conf.txmode.offloads &
967 DEV_TX_OFFLOAD_UDP_TNL_TSO)
973 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
974 printf("TX Outer UDP checksum: ");
975 if (ports[port_id].dev_conf.txmode.offloads &
976 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
985 port_id_is_invalid(portid_t port_id, enum print_warning warning)
989 if (port_id == (portid_t)RTE_PORT_ALL)
992 RTE_ETH_FOREACH_DEV(pid)
996 if (warning == ENABLED_WARN)
997 printf("Invalid port %d\n", port_id);
1002 void print_valid_ports(void)
1006 printf("The valid ports array is [");
1007 RTE_ETH_FOREACH_DEV(pid) {
1014 vlan_id_is_invalid(uint16_t vlan_id)
1018 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1023 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1025 const struct rte_pci_device *pci_dev;
1026 const struct rte_bus *bus;
1029 if (reg_off & 0x3) {
1030 printf("Port register offset 0x%X not aligned on a 4-byte "
1036 if (!ports[port_id].dev_info.device) {
1037 printf("Invalid device\n");
1041 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1042 if (bus && !strcmp(bus->name, "pci")) {
1043 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1045 printf("Not a PCI device\n");
1049 pci_len = pci_dev->mem_resource[0].len;
1050 if (reg_off >= pci_len) {
1051 printf("Port %d: register offset %u (0x%X) out of port PCI "
1052 "resource (length=%"PRIu64")\n",
1053 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
1060 reg_bit_pos_is_invalid(uint8_t bit_pos)
1064 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
1068 #define display_port_and_reg_off(port_id, reg_off) \
1069 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1072 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1074 display_port_and_reg_off(port_id, (unsigned)reg_off);
1075 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1079 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1084 if (port_id_is_invalid(port_id, ENABLED_WARN))
1086 if (port_reg_off_is_invalid(port_id, reg_off))
1088 if (reg_bit_pos_is_invalid(bit_x))
1090 reg_v = port_id_pci_reg_read(port_id, reg_off);
1091 display_port_and_reg_off(port_id, (unsigned)reg_off);
1092 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1096 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1097 uint8_t bit1_pos, uint8_t bit2_pos)
1103 if (port_id_is_invalid(port_id, ENABLED_WARN))
1105 if (port_reg_off_is_invalid(port_id, reg_off))
1107 if (reg_bit_pos_is_invalid(bit1_pos))
1109 if (reg_bit_pos_is_invalid(bit2_pos))
1111 if (bit1_pos > bit2_pos)
1112 l_bit = bit2_pos, h_bit = bit1_pos;
1114 l_bit = bit1_pos, h_bit = bit2_pos;
1116 reg_v = port_id_pci_reg_read(port_id, reg_off);
1119 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1120 display_port_and_reg_off(port_id, (unsigned)reg_off);
1121 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1122 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1126 port_reg_display(portid_t port_id, uint32_t reg_off)
1130 if (port_id_is_invalid(port_id, ENABLED_WARN))
1132 if (port_reg_off_is_invalid(port_id, reg_off))
1134 reg_v = port_id_pci_reg_read(port_id, reg_off);
1135 display_port_reg_value(port_id, reg_off, reg_v);
1139 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1144 if (port_id_is_invalid(port_id, ENABLED_WARN))
1146 if (port_reg_off_is_invalid(port_id, reg_off))
1148 if (reg_bit_pos_is_invalid(bit_pos))
1151 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1154 reg_v = port_id_pci_reg_read(port_id, reg_off);
1156 reg_v &= ~(1 << bit_pos);
1158 reg_v |= (1 << bit_pos);
1159 port_id_pci_reg_write(port_id, reg_off, reg_v);
1160 display_port_reg_value(port_id, reg_off, reg_v);
1164 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1165 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1172 if (port_id_is_invalid(port_id, ENABLED_WARN))
1174 if (port_reg_off_is_invalid(port_id, reg_off))
1176 if (reg_bit_pos_is_invalid(bit1_pos))
1178 if (reg_bit_pos_is_invalid(bit2_pos))
1180 if (bit1_pos > bit2_pos)
1181 l_bit = bit2_pos, h_bit = bit1_pos;
1183 l_bit = bit1_pos, h_bit = bit2_pos;
1185 if ((h_bit - l_bit) < 31)
1186 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1190 if (value > max_v) {
1191 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1192 (unsigned)value, (unsigned)value,
1193 (unsigned)max_v, (unsigned)max_v);
1196 reg_v = port_id_pci_reg_read(port_id, reg_off);
1197 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1198 reg_v |= (value << l_bit); /* Set changed bits */
1199 port_id_pci_reg_write(port_id, reg_off, reg_v);
1200 display_port_reg_value(port_id, reg_off, reg_v);
1204 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1206 if (port_id_is_invalid(port_id, ENABLED_WARN))
1208 if (port_reg_off_is_invalid(port_id, reg_off))
1210 port_id_pci_reg_write(port_id, reg_off, reg_v);
1211 display_port_reg_value(port_id, reg_off, reg_v);
1215 port_mtu_set(portid_t port_id, uint16_t mtu)
1218 struct rte_eth_dev_info dev_info;
1221 if (port_id_is_invalid(port_id, ENABLED_WARN))
1224 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1228 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1229 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1230 mtu, dev_info.min_mtu, dev_info.max_mtu);
1233 diag = rte_eth_dev_set_mtu(port_id, mtu);
1236 printf("Set MTU failed. diag=%d\n", diag);
1239 /* Generic flow management functions. */
1241 /** Generate a port_flow entry from attributes/pattern/actions. */
1242 static struct port_flow *
1243 port_flow_new(const struct rte_flow_attr *attr,
1244 const struct rte_flow_item *pattern,
1245 const struct rte_flow_action *actions,
1246 struct rte_flow_error *error)
1248 const struct rte_flow_conv_rule rule = {
1250 .pattern_ro = pattern,
1251 .actions_ro = actions,
1253 struct port_flow *pf;
1256 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1259 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1262 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1266 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1273 /** Print a message out of a flow error. */
1275 port_flow_complain(struct rte_flow_error *error)
1277 static const char *const errstrlist[] = {
1278 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1279 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1280 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1281 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1282 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1283 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1284 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1285 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1286 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1287 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1288 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1289 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1290 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1291 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1292 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1293 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1294 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1298 int err = rte_errno;
1300 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1301 !errstrlist[error->type])
1302 errstr = "unknown type";
1304 errstr = errstrlist[error->type];
1305 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1306 error->type, errstr,
1307 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1308 error->cause), buf) : "",
1309 error->message ? error->message : "(no stated reason)",
1314 /** Validate flow rule. */
1316 port_flow_validate(portid_t port_id,
1317 const struct rte_flow_attr *attr,
1318 const struct rte_flow_item *pattern,
1319 const struct rte_flow_action *actions)
1321 struct rte_flow_error error;
1323 /* Poisoning to make sure PMDs update it in case of error. */
1324 memset(&error, 0x11, sizeof(error));
1325 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1326 return port_flow_complain(&error);
1327 printf("Flow rule validated\n");
1331 /** Create flow rule. */
1333 port_flow_create(portid_t port_id,
1334 const struct rte_flow_attr *attr,
1335 const struct rte_flow_item *pattern,
1336 const struct rte_flow_action *actions)
1338 struct rte_flow *flow;
1339 struct rte_port *port;
1340 struct port_flow *pf;
1342 struct rte_flow_error error;
1344 /* Poisoning to make sure PMDs update it in case of error. */
1345 memset(&error, 0x22, sizeof(error));
1346 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1348 return port_flow_complain(&error);
1349 port = &ports[port_id];
1350 if (port->flow_list) {
1351 if (port->flow_list->id == UINT32_MAX) {
1352 printf("Highest rule ID is already assigned, delete"
1354 rte_flow_destroy(port_id, flow, NULL);
1357 id = port->flow_list->id + 1;
1360 pf = port_flow_new(attr, pattern, actions, &error);
1362 rte_flow_destroy(port_id, flow, NULL);
1363 return port_flow_complain(&error);
1365 pf->next = port->flow_list;
1368 port->flow_list = pf;
1369 printf("Flow rule #%u created\n", pf->id);
1373 /** Destroy a number of flow rules. */
1375 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1377 struct rte_port *port;
1378 struct port_flow **tmp;
1382 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1383 port_id == (portid_t)RTE_PORT_ALL)
1385 port = &ports[port_id];
1386 tmp = &port->flow_list;
1390 for (i = 0; i != n; ++i) {
1391 struct rte_flow_error error;
1392 struct port_flow *pf = *tmp;
1394 if (rule[i] != pf->id)
1397 * Poisoning to make sure PMDs update it in case
1400 memset(&error, 0x33, sizeof(error));
1401 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1402 ret = port_flow_complain(&error);
1405 printf("Flow rule #%u destroyed\n", pf->id);
1411 tmp = &(*tmp)->next;
1417 /** Remove all flow rules. */
1419 port_flow_flush(portid_t port_id)
1421 struct rte_flow_error error;
1422 struct rte_port *port;
1425 /* Poisoning to make sure PMDs update it in case of error. */
1426 memset(&error, 0x44, sizeof(error));
1427 if (rte_flow_flush(port_id, &error)) {
1428 ret = port_flow_complain(&error);
1429 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1430 port_id == (portid_t)RTE_PORT_ALL)
1433 port = &ports[port_id];
1434 while (port->flow_list) {
1435 struct port_flow *pf = port->flow_list->next;
1437 free(port->flow_list);
1438 port->flow_list = pf;
1443 /** Dump all flow rules. */
1445 port_flow_dump(portid_t port_id, const char *file_name)
1448 FILE *file = stdout;
1449 struct rte_flow_error error;
1451 if (file_name && strlen(file_name)) {
1452 file = fopen(file_name, "w");
1454 printf("Failed to create file %s: %s\n", file_name,
1459 ret = rte_flow_dev_dump(port_id, file, &error);
1461 port_flow_complain(&error);
1462 printf("Failed to dump flow: %s\n", strerror(-ret));
1464 printf("Flow dump finished\n");
1465 if (file_name && strlen(file_name))
1470 /** Query a flow rule. */
1472 port_flow_query(portid_t port_id, uint32_t rule,
1473 const struct rte_flow_action *action)
1475 struct rte_flow_error error;
1476 struct rte_port *port;
1477 struct port_flow *pf;
1480 struct rte_flow_query_count count;
1484 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1485 port_id == (portid_t)RTE_PORT_ALL)
1487 port = &ports[port_id];
1488 for (pf = port->flow_list; pf; pf = pf->next)
1492 printf("Flow rule #%u not found\n", rule);
1495 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1496 &name, sizeof(name),
1497 (void *)(uintptr_t)action->type, &error);
1499 return port_flow_complain(&error);
1500 switch (action->type) {
1501 case RTE_FLOW_ACTION_TYPE_COUNT:
1504 printf("Cannot query action type %d (%s)\n",
1505 action->type, name);
1508 /* Poisoning to make sure PMDs update it in case of error. */
1509 memset(&error, 0x55, sizeof(error));
1510 memset(&query, 0, sizeof(query));
1511 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1512 return port_flow_complain(&error);
1513 switch (action->type) {
1514 case RTE_FLOW_ACTION_TYPE_COUNT:
1518 " hits: %" PRIu64 "\n"
1519 " bytes: %" PRIu64 "\n",
1521 query.count.hits_set,
1522 query.count.bytes_set,
1527 printf("Cannot display result for action type %d (%s)\n",
1528 action->type, name);
1534 /** List flow rules. */
1536 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1538 struct rte_port *port;
1539 struct port_flow *pf;
1540 struct port_flow *list = NULL;
1543 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1544 port_id == (portid_t)RTE_PORT_ALL)
1546 port = &ports[port_id];
1547 if (!port->flow_list)
1549 /* Sort flows by group, priority and ID. */
1550 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1551 struct port_flow **tmp;
1552 const struct rte_flow_attr *curr = pf->rule.attr;
1555 /* Filter out unwanted groups. */
1556 for (i = 0; i != n; ++i)
1557 if (curr->group == group[i])
1562 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
1563 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
1565 if (curr->group > comp->group ||
1566 (curr->group == comp->group &&
1567 curr->priority > comp->priority) ||
1568 (curr->group == comp->group &&
1569 curr->priority == comp->priority &&
1570 pf->id > (*tmp)->id))
1577 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1578 for (pf = list; pf != NULL; pf = pf->tmp) {
1579 const struct rte_flow_item *item = pf->rule.pattern;
1580 const struct rte_flow_action *action = pf->rule.actions;
1583 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
1585 pf->rule.attr->group,
1586 pf->rule.attr->priority,
1587 pf->rule.attr->ingress ? 'i' : '-',
1588 pf->rule.attr->egress ? 'e' : '-',
1589 pf->rule.attr->transfer ? 't' : '-');
1590 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1591 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
1592 &name, sizeof(name),
1593 (void *)(uintptr_t)item->type,
1596 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1597 printf("%s ", name);
1601 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1602 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1603 &name, sizeof(name),
1604 (void *)(uintptr_t)action->type,
1607 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1608 printf(" %s", name);
1615 /** Restrict ingress traffic to the defined flow rules. */
1617 port_flow_isolate(portid_t port_id, int set)
1619 struct rte_flow_error error;
1621 /* Poisoning to make sure PMDs update it in case of error. */
1622 memset(&error, 0x66, sizeof(error));
1623 if (rte_flow_isolate(port_id, set, &error))
1624 return port_flow_complain(&error);
1625 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1627 set ? "now restricted" : "not restricted anymore");
1632 * RX/TX ring descriptors display functions.
1635 rx_queue_id_is_invalid(queueid_t rxq_id)
1637 if (rxq_id < nb_rxq)
1639 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1644 tx_queue_id_is_invalid(queueid_t txq_id)
1646 if (txq_id < nb_txq)
1648 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1653 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1655 if (rxdesc_id < nb_rxd)
1657 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1663 tx_desc_id_is_invalid(uint16_t txdesc_id)
1665 if (txdesc_id < nb_txd)
1667 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1672 static const struct rte_memzone *
1673 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1675 char mz_name[RTE_MEMZONE_NAMESIZE];
1676 const struct rte_memzone *mz;
1678 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
1679 port_id, q_id, ring_name);
1680 mz = rte_memzone_lookup(mz_name);
1682 printf("%s ring memory zoneof (port %d, queue %d) not"
1683 "found (zone name = %s\n",
1684 ring_name, port_id, q_id, mz_name);
1688 union igb_ring_dword {
1691 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1701 struct igb_ring_desc_32_bytes {
1702 union igb_ring_dword lo_dword;
1703 union igb_ring_dword hi_dword;
1704 union igb_ring_dword resv1;
1705 union igb_ring_dword resv2;
1708 struct igb_ring_desc_16_bytes {
1709 union igb_ring_dword lo_dword;
1710 union igb_ring_dword hi_dword;
1714 ring_rxd_display_dword(union igb_ring_dword dword)
1716 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1717 (unsigned)dword.words.hi);
1721 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1722 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1725 __rte_unused portid_t port_id,
1729 struct igb_ring_desc_16_bytes *ring =
1730 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1731 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1733 struct rte_eth_dev_info dev_info;
1735 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1739 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1740 /* 32 bytes RX descriptor, i40e only */
1741 struct igb_ring_desc_32_bytes *ring =
1742 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1743 ring[desc_id].lo_dword.dword =
1744 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1745 ring_rxd_display_dword(ring[desc_id].lo_dword);
1746 ring[desc_id].hi_dword.dword =
1747 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1748 ring_rxd_display_dword(ring[desc_id].hi_dword);
1749 ring[desc_id].resv1.dword =
1750 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1751 ring_rxd_display_dword(ring[desc_id].resv1);
1752 ring[desc_id].resv2.dword =
1753 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1754 ring_rxd_display_dword(ring[desc_id].resv2);
1759 /* 16 bytes RX descriptor */
1760 ring[desc_id].lo_dword.dword =
1761 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1762 ring_rxd_display_dword(ring[desc_id].lo_dword);
1763 ring[desc_id].hi_dword.dword =
1764 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1765 ring_rxd_display_dword(ring[desc_id].hi_dword);
1769 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1771 struct igb_ring_desc_16_bytes *ring;
1772 struct igb_ring_desc_16_bytes txd;
1774 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1775 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1776 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1777 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1778 (unsigned)txd.lo_dword.words.lo,
1779 (unsigned)txd.lo_dword.words.hi,
1780 (unsigned)txd.hi_dword.words.lo,
1781 (unsigned)txd.hi_dword.words.hi);
1785 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1787 const struct rte_memzone *rx_mz;
1789 if (port_id_is_invalid(port_id, ENABLED_WARN))
1791 if (rx_queue_id_is_invalid(rxq_id))
1793 if (rx_desc_id_is_invalid(rxd_id))
1795 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1798 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1802 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1804 const struct rte_memzone *tx_mz;
1806 if (port_id_is_invalid(port_id, ENABLED_WARN))
1808 if (tx_queue_id_is_invalid(txq_id))
1810 if (tx_desc_id_is_invalid(txd_id))
1812 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1815 ring_tx_descriptor_display(tx_mz, txd_id);
1819 fwd_lcores_config_display(void)
1823 printf("List of forwarding lcores:");
1824 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1825 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1829 rxtx_config_display(void)
1834 printf(" %s packet forwarding%s packets/burst=%d\n",
1835 cur_fwd_eng->fwd_mode_name,
1836 retry_enabled == 0 ? "" : " with retry",
1839 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1840 printf(" packet len=%u - nb packet segments=%d\n",
1841 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1843 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1844 nb_fwd_lcores, nb_fwd_ports);
1846 RTE_ETH_FOREACH_DEV(pid) {
1847 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
1848 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
1849 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
1850 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
1851 uint16_t nb_rx_desc_tmp;
1852 uint16_t nb_tx_desc_tmp;
1853 struct rte_eth_rxq_info rx_qinfo;
1854 struct rte_eth_txq_info tx_qinfo;
1857 /* per port config */
1858 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
1859 (unsigned int)pid, nb_rxq, nb_txq);
1861 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
1862 ports[pid].dev_conf.rxmode.offloads,
1863 ports[pid].dev_conf.txmode.offloads);
1865 /* per rx queue config only for first queue to be less verbose */
1866 for (qid = 0; qid < 1; qid++) {
1867 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
1869 nb_rx_desc_tmp = nb_rx_desc[qid];
1871 nb_rx_desc_tmp = rx_qinfo.nb_desc;
1873 printf(" RX queue: %d\n", qid);
1874 printf(" RX desc=%d - RX free threshold=%d\n",
1875 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh);
1876 printf(" RX threshold registers: pthresh=%d hthresh=%d "
1878 rx_conf[qid].rx_thresh.pthresh,
1879 rx_conf[qid].rx_thresh.hthresh,
1880 rx_conf[qid].rx_thresh.wthresh);
1881 printf(" RX Offloads=0x%"PRIx64"\n",
1882 rx_conf[qid].offloads);
1885 /* per tx queue config only for first queue to be less verbose */
1886 for (qid = 0; qid < 1; qid++) {
1887 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
1889 nb_tx_desc_tmp = nb_tx_desc[qid];
1891 nb_tx_desc_tmp = tx_qinfo.nb_desc;
1893 printf(" TX queue: %d\n", qid);
1894 printf(" TX desc=%d - TX free threshold=%d\n",
1895 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh);
1896 printf(" TX threshold registers: pthresh=%d hthresh=%d "
1898 tx_conf[qid].tx_thresh.pthresh,
1899 tx_conf[qid].tx_thresh.hthresh,
1900 tx_conf[qid].tx_thresh.wthresh);
1901 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
1902 tx_conf[qid].offloads, tx_conf->tx_rs_thresh);
1908 port_rss_reta_info(portid_t port_id,
1909 struct rte_eth_rss_reta_entry64 *reta_conf,
1910 uint16_t nb_entries)
1912 uint16_t i, idx, shift;
1915 if (port_id_is_invalid(port_id, ENABLED_WARN))
1918 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1920 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1924 for (i = 0; i < nb_entries; i++) {
1925 idx = i / RTE_RETA_GROUP_SIZE;
1926 shift = i % RTE_RETA_GROUP_SIZE;
1927 if (!(reta_conf[idx].mask & (1ULL << shift)))
1929 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1930 i, reta_conf[idx].reta[shift]);
1935 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1939 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
1941 struct rte_eth_rss_conf rss_conf = {0};
1942 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1946 struct rte_eth_dev_info dev_info;
1947 uint8_t hash_key_size;
1950 if (port_id_is_invalid(port_id, ENABLED_WARN))
1953 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1957 if (dev_info.hash_key_size > 0 &&
1958 dev_info.hash_key_size <= sizeof(rss_key))
1959 hash_key_size = dev_info.hash_key_size;
1961 printf("dev_info did not provide a valid hash key size\n");
1965 /* Get RSS hash key if asked to display it */
1966 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1967 rss_conf.rss_key_len = hash_key_size;
1968 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1972 printf("port index %d invalid\n", port_id);
1975 printf("operation not supported by device\n");
1978 printf("operation failed - diag=%d\n", diag);
1983 rss_hf = rss_conf.rss_hf;
1985 printf("RSS disabled\n");
1988 printf("RSS functions:\n ");
1989 for (i = 0; rss_type_table[i].str; i++) {
1990 if (rss_hf & rss_type_table[i].rss_type)
1991 printf("%s ", rss_type_table[i].str);
1996 printf("RSS key:\n");
1997 for (i = 0; i < hash_key_size; i++)
1998 printf("%02X", rss_key[i]);
2003 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2006 struct rte_eth_rss_conf rss_conf;
2010 rss_conf.rss_key = NULL;
2011 rss_conf.rss_key_len = hash_key_len;
2012 rss_conf.rss_hf = 0;
2013 for (i = 0; rss_type_table[i].str; i++) {
2014 if (!strcmp(rss_type_table[i].str, rss_type))
2015 rss_conf.rss_hf = rss_type_table[i].rss_type;
2017 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2019 rss_conf.rss_key = hash_key;
2020 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2027 printf("port index %d invalid\n", port_id);
2030 printf("operation not supported by device\n");
2033 printf("operation failed - diag=%d\n", diag);
2039 * Setup forwarding configuration for each logical core.
2042 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2044 streamid_t nb_fs_per_lcore;
2052 nb_fs = cfg->nb_fwd_streams;
2053 nb_fc = cfg->nb_fwd_lcores;
2054 if (nb_fs <= nb_fc) {
2055 nb_fs_per_lcore = 1;
2058 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2059 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2062 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2064 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2065 fwd_lcores[lc_id]->stream_idx = sm_id;
2066 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2067 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2071 * Assign extra remaining streams, if any.
2073 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2074 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2075 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2076 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2077 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2082 fwd_topology_tx_port_get(portid_t rxp)
2084 static int warning_once = 1;
2086 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2088 switch (port_topology) {
2090 case PORT_TOPOLOGY_PAIRED:
2091 if ((rxp & 0x1) == 0) {
2092 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2095 printf("\nWarning! port-topology=paired"
2096 " and odd forward ports number,"
2097 " the last port will pair with"
2104 case PORT_TOPOLOGY_CHAINED:
2105 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2106 case PORT_TOPOLOGY_LOOP:
2112 simple_fwd_config_setup(void)
2116 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2117 cur_fwd_config.nb_fwd_streams =
2118 (streamid_t) cur_fwd_config.nb_fwd_ports;
2120 /* reinitialize forwarding streams */
2124 * In the simple forwarding test, the number of forwarding cores
2125 * must be lower or equal to the number of forwarding ports.
2127 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2128 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2129 cur_fwd_config.nb_fwd_lcores =
2130 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2131 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2133 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2134 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2135 fwd_streams[i]->rx_queue = 0;
2136 fwd_streams[i]->tx_port =
2137 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2138 fwd_streams[i]->tx_queue = 0;
2139 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2140 fwd_streams[i]->retry_enabled = retry_enabled;
2145 * For the RSS forwarding test all streams distributed over lcores. Each stream
2146 * being composed of a RX queue to poll on a RX port for input messages,
2147 * associated with a TX queue of a TX port where to send forwarded packets.
2150 rss_fwd_config_setup(void)
2161 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2162 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2163 cur_fwd_config.nb_fwd_streams =
2164 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2166 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2167 cur_fwd_config.nb_fwd_lcores =
2168 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2170 /* reinitialize forwarding streams */
2173 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2175 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2176 struct fwd_stream *fs;
2178 fs = fwd_streams[sm_id];
2179 txp = fwd_topology_tx_port_get(rxp);
2180 fs->rx_port = fwd_ports_ids[rxp];
2182 fs->tx_port = fwd_ports_ids[txp];
2184 fs->peer_addr = fs->tx_port;
2185 fs->retry_enabled = retry_enabled;
2187 if (rxp < nb_fwd_ports)
2195 * For the DCB forwarding test, each core is assigned on each traffic class.
2197 * Each core is assigned a multi-stream, each stream being composed of
2198 * a RX queue to poll on a RX port for input messages, associated with
2199 * a TX queue of a TX port where to send forwarded packets. All RX and
2200 * TX queues are mapping to the same traffic class.
2201 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2205 dcb_fwd_config_setup(void)
2207 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2208 portid_t txp, rxp = 0;
2209 queueid_t txq, rxq = 0;
2211 uint16_t nb_rx_queue, nb_tx_queue;
2212 uint16_t i, j, k, sm_id = 0;
2215 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2216 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2217 cur_fwd_config.nb_fwd_streams =
2218 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2220 /* reinitialize forwarding streams */
2224 /* get the dcb info on the first RX and TX ports */
2225 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2226 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2228 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2229 fwd_lcores[lc_id]->stream_nb = 0;
2230 fwd_lcores[lc_id]->stream_idx = sm_id;
2231 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2232 /* if the nb_queue is zero, means this tc is
2233 * not enabled on the POOL
2235 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2237 k = fwd_lcores[lc_id]->stream_nb +
2238 fwd_lcores[lc_id]->stream_idx;
2239 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2240 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2241 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2242 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2243 for (j = 0; j < nb_rx_queue; j++) {
2244 struct fwd_stream *fs;
2246 fs = fwd_streams[k + j];
2247 fs->rx_port = fwd_ports_ids[rxp];
2248 fs->rx_queue = rxq + j;
2249 fs->tx_port = fwd_ports_ids[txp];
2250 fs->tx_queue = txq + j % nb_tx_queue;
2251 fs->peer_addr = fs->tx_port;
2252 fs->retry_enabled = retry_enabled;
2254 fwd_lcores[lc_id]->stream_nb +=
2255 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2257 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2260 if (tc < rxp_dcb_info.nb_tcs)
2262 /* Restart from TC 0 on next RX port */
2264 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2266 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2269 if (rxp >= nb_fwd_ports)
2271 /* get the dcb information on next RX and TX ports */
2272 if ((rxp & 0x1) == 0)
2273 txp = (portid_t) (rxp + 1);
2275 txp = (portid_t) (rxp - 1);
2276 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2277 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2282 icmp_echo_config_setup(void)
2289 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2290 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2291 (nb_txq * nb_fwd_ports);
2293 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2294 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2295 cur_fwd_config.nb_fwd_streams =
2296 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2297 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2298 cur_fwd_config.nb_fwd_lcores =
2299 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2300 if (verbose_level > 0) {
2301 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2303 cur_fwd_config.nb_fwd_lcores,
2304 cur_fwd_config.nb_fwd_ports,
2305 cur_fwd_config.nb_fwd_streams);
2308 /* reinitialize forwarding streams */
2310 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2312 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2313 if (verbose_level > 0)
2314 printf(" core=%d: \n", lc_id);
2315 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2316 struct fwd_stream *fs;
2317 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2318 fs->rx_port = fwd_ports_ids[rxp];
2320 fs->tx_port = fs->rx_port;
2322 fs->peer_addr = fs->tx_port;
2323 fs->retry_enabled = retry_enabled;
2324 if (verbose_level > 0)
2325 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2326 sm_id, fs->rx_port, fs->rx_queue,
2328 rxq = (queueid_t) (rxq + 1);
2329 if (rxq == nb_rxq) {
2331 rxp = (portid_t) (rxp + 1);
2337 #if defined RTE_LIBRTE_PMD_SOFTNIC
2339 softnic_fwd_config_setup(void)
2341 struct rte_port *port;
2342 portid_t pid, softnic_portid;
2344 uint8_t softnic_enable = 0;
2346 RTE_ETH_FOREACH_DEV(pid) {
2348 const char *driver = port->dev_info.driver_name;
2350 if (strcmp(driver, "net_softnic") == 0) {
2351 softnic_portid = pid;
2357 if (softnic_enable == 0) {
2358 printf("Softnic mode not configured(%s)!\n", __func__);
2362 cur_fwd_config.nb_fwd_ports = 1;
2363 cur_fwd_config.nb_fwd_streams = (streamid_t) nb_rxq;
2365 /* Re-initialize forwarding streams */
2369 * In the softnic forwarding test, the number of forwarding cores
2370 * is set to one and remaining are used for softnic packet processing.
2372 cur_fwd_config.nb_fwd_lcores = 1;
2373 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2375 for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++) {
2376 fwd_streams[i]->rx_port = softnic_portid;
2377 fwd_streams[i]->rx_queue = i;
2378 fwd_streams[i]->tx_port = softnic_portid;
2379 fwd_streams[i]->tx_queue = i;
2380 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2381 fwd_streams[i]->retry_enabled = retry_enabled;
2387 fwd_config_setup(void)
2389 cur_fwd_config.fwd_eng = cur_fwd_eng;
2390 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2391 icmp_echo_config_setup();
2395 #if defined RTE_LIBRTE_PMD_SOFTNIC
2396 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
2397 softnic_fwd_config_setup();
2402 if ((nb_rxq > 1) && (nb_txq > 1)){
2404 dcb_fwd_config_setup();
2406 rss_fwd_config_setup();
2409 simple_fwd_config_setup();
2413 mp_alloc_to_str(uint8_t mode)
2416 case MP_ALLOC_NATIVE:
2422 case MP_ALLOC_XMEM_HUGE:
2432 pkt_fwd_config_display(struct fwd_config *cfg)
2434 struct fwd_stream *fs;
2438 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2439 "NUMA support %s, MP allocation mode: %s\n",
2440 cfg->fwd_eng->fwd_mode_name,
2441 retry_enabled == 0 ? "" : " with retry",
2442 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2443 numa_support == 1 ? "enabled" : "disabled",
2444 mp_alloc_to_str(mp_alloc_type));
2447 printf("TX retry num: %u, delay between TX retries: %uus\n",
2448 burst_tx_retry_num, burst_tx_delay_time);
2449 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2450 printf("Logical Core %u (socket %u) forwards packets on "
2452 fwd_lcores_cpuids[lc_id],
2453 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2454 fwd_lcores[lc_id]->stream_nb);
2455 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2456 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2457 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2458 "P=%d/Q=%d (socket %u) ",
2459 fs->rx_port, fs->rx_queue,
2460 ports[fs->rx_port].socket_id,
2461 fs->tx_port, fs->tx_queue,
2462 ports[fs->tx_port].socket_id);
2463 print_ethaddr("peer=",
2464 &peer_eth_addrs[fs->peer_addr]);
2472 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2474 struct rte_ether_addr new_peer_addr;
2475 if (!rte_eth_dev_is_valid_port(port_id)) {
2476 printf("Error: Invalid port number %i\n", port_id);
2479 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
2480 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2483 peer_eth_addrs[port_id] = new_peer_addr;
2487 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2490 unsigned int lcore_cpuid;
2495 for (i = 0; i < nb_lc; i++) {
2496 lcore_cpuid = lcorelist[i];
2497 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2498 printf("lcore %u not enabled\n", lcore_cpuid);
2501 if (lcore_cpuid == rte_get_master_lcore()) {
2502 printf("lcore %u cannot be masked on for running "
2503 "packet forwarding, which is the master lcore "
2504 "and reserved for command line parsing only\n",
2509 fwd_lcores_cpuids[i] = lcore_cpuid;
2511 if (record_now == 0) {
2515 nb_cfg_lcores = (lcoreid_t) nb_lc;
2516 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2517 printf("previous number of forwarding cores %u - changed to "
2518 "number of configured cores %u\n",
2519 (unsigned int) nb_fwd_lcores, nb_lc);
2520 nb_fwd_lcores = (lcoreid_t) nb_lc;
2527 set_fwd_lcores_mask(uint64_t lcoremask)
2529 unsigned int lcorelist[64];
2533 if (lcoremask == 0) {
2534 printf("Invalid NULL mask of cores\n");
2538 for (i = 0; i < 64; i++) {
2539 if (! ((uint64_t)(1ULL << i) & lcoremask))
2541 lcorelist[nb_lc++] = i;
2543 return set_fwd_lcores_list(lcorelist, nb_lc);
2547 set_fwd_lcores_number(uint16_t nb_lc)
2549 if (nb_lc > nb_cfg_lcores) {
2550 printf("nb fwd cores %u > %u (max. number of configured "
2551 "lcores) - ignored\n",
2552 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2555 nb_fwd_lcores = (lcoreid_t) nb_lc;
2556 printf("Number of forwarding cores set to %u\n",
2557 (unsigned int) nb_fwd_lcores);
2561 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2569 for (i = 0; i < nb_pt; i++) {
2570 port_id = (portid_t) portlist[i];
2571 if (port_id_is_invalid(port_id, ENABLED_WARN))
2574 fwd_ports_ids[i] = port_id;
2576 if (record_now == 0) {
2580 nb_cfg_ports = (portid_t) nb_pt;
2581 if (nb_fwd_ports != (portid_t) nb_pt) {
2582 printf("previous number of forwarding ports %u - changed to "
2583 "number of configured ports %u\n",
2584 (unsigned int) nb_fwd_ports, nb_pt);
2585 nb_fwd_ports = (portid_t) nb_pt;
2590 * Parse the user input and obtain the list of forwarding ports
2593 * String containing the user input. User can specify
2594 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
2595 * For example, if the user wants to use all the available
2596 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
2597 * If the user wants to use only the ports 1,2 then the input
2599 * valid characters are '-' and ','
2600 * invalid chars like '.' or '#' will result in
2601 * EAL: Error - exiting with code: 1
2602 * Cause: Invalid fwd port list
2603 * @param[out] values
2604 * This array will be filled with a list of port IDs
2605 * based on the user input
2606 * Note that duplicate entries are discarded and only the first
2607 * count entries in this array are port IDs and all the rest
2608 * will contain default values
2609 * @param[in] maxsize
2610 * This parameter denotes 2 things
2611 * 1) Number of elements in the values array
2612 * 2) Maximum value of each element in the values array
2614 * -returns total count of parsed port IDs
2617 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
2619 unsigned int count = 0;
2623 unsigned int marked[maxsize];
2625 if (list == NULL || values == NULL)
2628 for (i = 0; i < (int)maxsize; i++)
2634 /*Remove the blank spaces if any*/
2635 while (isblank(*list))
2640 value = strtol(list, &end, 10);
2641 if (errno || end == NULL)
2643 if (value < 0 || value >= (int)maxsize)
2645 while (isblank(*end))
2647 if (*end == '-' && min == INT_MAX) {
2649 } else if ((*end == ',') || (*end == '\0')) {
2653 for (i = min; i <= max; i++) {
2654 if (count < maxsize) {
2666 } while (*end != '\0');
2672 parse_fwd_portlist(const char *portlist)
2674 unsigned int portcount;
2675 unsigned int portindex[RTE_MAX_ETHPORTS];
2676 unsigned int i, valid_port_count = 0;
2678 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
2680 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
2683 * Here we verify the validity of the ports
2684 * and thereby calculate the total number of
2687 for (i = 0; i < portcount && valid_port_count < portcount; i++) {
2688 if (rte_eth_dev_is_valid_port(portindex[i])) {
2689 portindex[valid_port_count] = portindex[i];
2694 set_fwd_ports_list(portindex, valid_port_count);
2698 set_fwd_ports_mask(uint64_t portmask)
2700 unsigned int portlist[64];
2704 if (portmask == 0) {
2705 printf("Invalid NULL mask of ports\n");
2709 RTE_ETH_FOREACH_DEV(i) {
2710 if (! ((uint64_t)(1ULL << i) & portmask))
2712 portlist[nb_pt++] = i;
2714 set_fwd_ports_list(portlist, nb_pt);
2718 set_fwd_ports_number(uint16_t nb_pt)
2720 if (nb_pt > nb_cfg_ports) {
2721 printf("nb fwd ports %u > %u (number of configured "
2722 "ports) - ignored\n",
2723 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2726 nb_fwd_ports = (portid_t) nb_pt;
2727 printf("Number of forwarding ports set to %u\n",
2728 (unsigned int) nb_fwd_ports);
2732 port_is_forwarding(portid_t port_id)
2736 if (port_id_is_invalid(port_id, ENABLED_WARN))
2739 for (i = 0; i < nb_fwd_ports; i++) {
2740 if (fwd_ports_ids[i] == port_id)
2748 set_nb_pkt_per_burst(uint16_t nb)
2750 if (nb > MAX_PKT_BURST) {
2751 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2753 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2756 nb_pkt_per_burst = nb;
2757 printf("Number of packets per burst set to %u\n",
2758 (unsigned int) nb_pkt_per_burst);
2762 tx_split_get_name(enum tx_pkt_split split)
2766 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2767 if (tx_split_name[i].split == split)
2768 return tx_split_name[i].name;
2774 set_tx_pkt_split(const char *name)
2778 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2779 if (strcmp(tx_split_name[i].name, name) == 0) {
2780 tx_pkt_split = tx_split_name[i].split;
2784 printf("unknown value: \"%s\"\n", name);
2788 show_tx_pkt_segments(void)
2794 split = tx_split_get_name(tx_pkt_split);
2796 printf("Number of segments: %u\n", n);
2797 printf("Segment sizes: ");
2798 for (i = 0; i != n - 1; i++)
2799 printf("%hu,", tx_pkt_seg_lengths[i]);
2800 printf("%hu\n", tx_pkt_seg_lengths[i]);
2801 printf("Split packet: %s\n", split);
2805 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2807 uint16_t tx_pkt_len;
2810 if (nb_segs >= (unsigned) nb_txd) {
2811 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2812 nb_segs, (unsigned int) nb_txd);
2817 * Check that each segment length is greater or equal than
2818 * the mbuf data sise.
2819 * Check also that the total packet length is greater or equal than the
2820 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
2824 for (i = 0; i < nb_segs; i++) {
2825 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2826 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2827 i, seg_lengths[i], (unsigned) mbuf_data_size);
2830 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2832 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
2833 printf("total packet length=%u < %d - give up\n",
2834 (unsigned) tx_pkt_len,
2835 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
2839 for (i = 0; i < nb_segs; i++)
2840 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2842 tx_pkt_length = tx_pkt_len;
2843 tx_pkt_nb_segs = (uint8_t) nb_segs;
2847 setup_gro(const char *onoff, portid_t port_id)
2849 if (!rte_eth_dev_is_valid_port(port_id)) {
2850 printf("invalid port id %u\n", port_id);
2853 if (test_done == 0) {
2854 printf("Before enable/disable GRO,"
2855 " please stop forwarding first\n");
2858 if (strcmp(onoff, "on") == 0) {
2859 if (gro_ports[port_id].enable != 0) {
2860 printf("Port %u has enabled GRO. Please"
2861 " disable GRO first\n", port_id);
2864 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2865 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2866 gro_ports[port_id].param.max_flow_num =
2867 GRO_DEFAULT_FLOW_NUM;
2868 gro_ports[port_id].param.max_item_per_flow =
2869 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2871 gro_ports[port_id].enable = 1;
2873 if (gro_ports[port_id].enable == 0) {
2874 printf("Port %u has disabled GRO\n", port_id);
2877 gro_ports[port_id].enable = 0;
2882 setup_gro_flush_cycles(uint8_t cycles)
2884 if (test_done == 0) {
2885 printf("Before change flush interval for GRO,"
2886 " please stop forwarding first.\n");
2890 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
2891 GRO_DEFAULT_FLUSH_CYCLES) {
2892 printf("The flushing cycle be in the range"
2893 " of 1 to %u. Revert to the default"
2895 GRO_MAX_FLUSH_CYCLES,
2896 GRO_DEFAULT_FLUSH_CYCLES);
2897 cycles = GRO_DEFAULT_FLUSH_CYCLES;
2900 gro_flush_cycles = cycles;
2904 show_gro(portid_t port_id)
2906 struct rte_gro_param *param;
2907 uint32_t max_pkts_num;
2909 param = &gro_ports[port_id].param;
2911 if (!rte_eth_dev_is_valid_port(port_id)) {
2912 printf("Invalid port id %u.\n", port_id);
2915 if (gro_ports[port_id].enable) {
2916 printf("GRO type: TCP/IPv4\n");
2917 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2918 max_pkts_num = param->max_flow_num *
2919 param->max_item_per_flow;
2921 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
2922 printf("Max number of packets to perform GRO: %u\n",
2924 printf("Flushing cycles: %u\n", gro_flush_cycles);
2926 printf("Port %u doesn't enable GRO.\n", port_id);
2930 setup_gso(const char *mode, portid_t port_id)
2932 if (!rte_eth_dev_is_valid_port(port_id)) {
2933 printf("invalid port id %u\n", port_id);
2936 if (strcmp(mode, "on") == 0) {
2937 if (test_done == 0) {
2938 printf("before enabling GSO,"
2939 " please stop forwarding first\n");
2942 gso_ports[port_id].enable = 1;
2943 } else if (strcmp(mode, "off") == 0) {
2944 if (test_done == 0) {
2945 printf("before disabling GSO,"
2946 " please stop forwarding first\n");
2949 gso_ports[port_id].enable = 0;
2954 list_pkt_forwarding_modes(void)
2956 static char fwd_modes[128] = "";
2957 const char *separator = "|";
2958 struct fwd_engine *fwd_eng;
2961 if (strlen (fwd_modes) == 0) {
2962 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2963 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2964 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2965 strncat(fwd_modes, separator,
2966 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2968 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2975 list_pkt_forwarding_retry_modes(void)
2977 static char fwd_modes[128] = "";
2978 const char *separator = "|";
2979 struct fwd_engine *fwd_eng;
2982 if (strlen(fwd_modes) == 0) {
2983 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2984 if (fwd_eng == &rx_only_engine)
2986 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2988 strlen(fwd_modes) - 1);
2989 strncat(fwd_modes, separator,
2991 strlen(fwd_modes) - 1);
2993 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3000 set_pkt_forwarding_mode(const char *fwd_mode_name)
3002 struct fwd_engine *fwd_eng;
3006 while ((fwd_eng = fwd_engines[i]) != NULL) {
3007 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
3008 printf("Set %s packet forwarding mode%s\n",
3010 retry_enabled == 0 ? "" : " with retry");
3011 cur_fwd_eng = fwd_eng;
3016 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
3020 add_rx_dump_callbacks(portid_t portid)
3022 struct rte_eth_dev_info dev_info;
3026 if (port_id_is_invalid(portid, ENABLED_WARN))
3029 ret = eth_dev_info_get_print_err(portid, &dev_info);
3033 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3034 if (!ports[portid].rx_dump_cb[queue])
3035 ports[portid].rx_dump_cb[queue] =
3036 rte_eth_add_rx_callback(portid, queue,
3037 dump_rx_pkts, NULL);
3041 add_tx_dump_callbacks(portid_t portid)
3043 struct rte_eth_dev_info dev_info;
3047 if (port_id_is_invalid(portid, ENABLED_WARN))
3050 ret = eth_dev_info_get_print_err(portid, &dev_info);
3054 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3055 if (!ports[portid].tx_dump_cb[queue])
3056 ports[portid].tx_dump_cb[queue] =
3057 rte_eth_add_tx_callback(portid, queue,
3058 dump_tx_pkts, NULL);
3062 remove_rx_dump_callbacks(portid_t portid)
3064 struct rte_eth_dev_info dev_info;
3068 if (port_id_is_invalid(portid, ENABLED_WARN))
3071 ret = eth_dev_info_get_print_err(portid, &dev_info);
3075 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3076 if (ports[portid].rx_dump_cb[queue]) {
3077 rte_eth_remove_rx_callback(portid, queue,
3078 ports[portid].rx_dump_cb[queue]);
3079 ports[portid].rx_dump_cb[queue] = NULL;
3084 remove_tx_dump_callbacks(portid_t portid)
3086 struct rte_eth_dev_info dev_info;
3090 if (port_id_is_invalid(portid, ENABLED_WARN))
3093 ret = eth_dev_info_get_print_err(portid, &dev_info);
3097 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3098 if (ports[portid].tx_dump_cb[queue]) {
3099 rte_eth_remove_tx_callback(portid, queue,
3100 ports[portid].tx_dump_cb[queue]);
3101 ports[portid].tx_dump_cb[queue] = NULL;
3106 configure_rxtx_dump_callbacks(uint16_t verbose)
3110 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3111 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
3115 RTE_ETH_FOREACH_DEV(portid)
3117 if (verbose == 1 || verbose > 2)
3118 add_rx_dump_callbacks(portid);
3120 remove_rx_dump_callbacks(portid);
3122 add_tx_dump_callbacks(portid);
3124 remove_tx_dump_callbacks(portid);
3129 set_verbose_level(uint16_t vb_level)
3131 printf("Change verbose level from %u to %u\n",
3132 (unsigned int) verbose_level, (unsigned int) vb_level);
3133 verbose_level = vb_level;
3134 configure_rxtx_dump_callbacks(verbose_level);
3138 vlan_extend_set(portid_t port_id, int on)
3142 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3144 if (port_id_is_invalid(port_id, ENABLED_WARN))
3147 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3150 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
3151 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3153 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
3154 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3157 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3159 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
3160 "diag=%d\n", port_id, on, diag);
3161 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3165 rx_vlan_strip_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_STRIP_OFFLOAD;
3178 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3180 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
3181 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3184 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3186 printf("rx_vlan_strip_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_on_queue(portid_t port_id, uint16_t queue_id, int on)
3196 if (port_id_is_invalid(port_id, ENABLED_WARN))
3199 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
3201 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
3202 "diag=%d\n", port_id, queue_id, on, diag);
3206 rx_vlan_filter_set(portid_t port_id, int on)
3210 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3212 if (port_id_is_invalid(port_id, ENABLED_WARN))
3215 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3218 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
3219 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3221 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
3222 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3225 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3227 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
3228 "diag=%d\n", port_id, on, diag);
3229 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3233 rx_vlan_qinq_strip_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_QINQ_STRIP_OFFLOAD;
3246 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3248 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
3249 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3252 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3254 printf("%s(port_pi=%d, on=%d) failed "
3255 "diag=%d\n", __func__, port_id, on, diag);
3256 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3260 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
3264 if (port_id_is_invalid(port_id, ENABLED_WARN))
3266 if (vlan_id_is_invalid(vlan_id))
3268 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
3271 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
3273 port_id, vlan_id, on, diag);
3278 rx_vlan_all_filter_set(portid_t port_id, int on)
3282 if (port_id_is_invalid(port_id, ENABLED_WARN))
3284 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
3285 if (rx_vft_set(port_id, vlan_id, on))
3291 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
3295 if (port_id_is_invalid(port_id, ENABLED_WARN))
3298 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
3302 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
3304 port_id, vlan_type, tp_id, diag);
3308 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
3310 struct rte_eth_dev_info dev_info;
3313 if (port_id_is_invalid(port_id, ENABLED_WARN))
3315 if (vlan_id_is_invalid(vlan_id))
3318 if (ports[port_id].dev_conf.txmode.offloads &
3319 DEV_TX_OFFLOAD_QINQ_INSERT) {
3320 printf("Error, as QinQ has been enabled.\n");
3324 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3328 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
3329 printf("Error: vlan insert is not supported by port %d\n",
3334 tx_vlan_reset(port_id);
3335 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
3336 ports[port_id].tx_vlan_id = vlan_id;
3340 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
3342 struct rte_eth_dev_info dev_info;
3345 if (port_id_is_invalid(port_id, ENABLED_WARN))
3347 if (vlan_id_is_invalid(vlan_id))
3349 if (vlan_id_is_invalid(vlan_id_outer))
3352 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3356 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
3357 printf("Error: qinq insert not supported by port %d\n",
3362 tx_vlan_reset(port_id);
3363 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
3364 DEV_TX_OFFLOAD_QINQ_INSERT);
3365 ports[port_id].tx_vlan_id = vlan_id;
3366 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
3370 tx_vlan_reset(portid_t port_id)
3372 if (port_id_is_invalid(port_id, ENABLED_WARN))
3374 ports[port_id].dev_conf.txmode.offloads &=
3375 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
3376 DEV_TX_OFFLOAD_QINQ_INSERT);
3377 ports[port_id].tx_vlan_id = 0;
3378 ports[port_id].tx_vlan_id_outer = 0;
3382 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
3384 if (port_id_is_invalid(port_id, ENABLED_WARN))
3387 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
3391 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
3394 uint8_t existing_mapping_found = 0;
3396 if (port_id_is_invalid(port_id, ENABLED_WARN))
3399 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
3402 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
3403 printf("map_value not in required range 0..%d\n",
3404 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
3408 if (!is_rx) { /*then tx*/
3409 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3410 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3411 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
3412 tx_queue_stats_mappings[i].stats_counter_id = map_value;
3413 existing_mapping_found = 1;
3417 if (!existing_mapping_found) { /* A new additional mapping... */
3418 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
3419 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
3420 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
3421 nb_tx_queue_stats_mappings++;
3425 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3426 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3427 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
3428 rx_queue_stats_mappings[i].stats_counter_id = map_value;
3429 existing_mapping_found = 1;
3433 if (!existing_mapping_found) { /* A new additional mapping... */
3434 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
3435 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
3436 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
3437 nb_rx_queue_stats_mappings++;
3443 set_xstats_hide_zero(uint8_t on_off)
3445 xstats_hide_zero = on_off;
3449 print_fdir_mask(struct rte_eth_fdir_masks *mask)
3451 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
3453 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3454 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
3455 " tunnel_id: 0x%08x",
3456 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
3457 rte_be_to_cpu_32(mask->tunnel_id_mask));
3458 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3459 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
3460 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
3461 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
3463 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
3464 rte_be_to_cpu_16(mask->src_port_mask),
3465 rte_be_to_cpu_16(mask->dst_port_mask));
3467 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3468 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
3469 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3470 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3471 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3473 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3474 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3475 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3476 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3477 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3484 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3486 struct rte_eth_flex_payload_cfg *cfg;
3489 for (i = 0; i < flex_conf->nb_payloads; i++) {
3490 cfg = &flex_conf->flex_set[i];
3491 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3493 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3494 printf("\n L2_PAYLOAD: ");
3495 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3496 printf("\n L3_PAYLOAD: ");
3497 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3498 printf("\n L4_PAYLOAD: ");
3500 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3501 for (j = 0; j < num; j++)
3502 printf(" %-5u", cfg->src_offset[j]);
3508 flowtype_to_str(uint16_t flow_type)
3510 struct flow_type_info {
3516 static struct flow_type_info flowtype_str_table[] = {
3517 {"raw", RTE_ETH_FLOW_RAW},
3518 {"ipv4", RTE_ETH_FLOW_IPV4},
3519 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3520 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3521 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3522 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3523 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3524 {"ipv6", RTE_ETH_FLOW_IPV6},
3525 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3526 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3527 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3528 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3529 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3530 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3531 {"port", RTE_ETH_FLOW_PORT},
3532 {"vxlan", RTE_ETH_FLOW_VXLAN},
3533 {"geneve", RTE_ETH_FLOW_GENEVE},
3534 {"nvgre", RTE_ETH_FLOW_NVGRE},
3535 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
3538 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3539 if (flowtype_str_table[i].ftype == flow_type)
3540 return flowtype_str_table[i].str;
3547 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3549 struct rte_eth_fdir_flex_mask *mask;
3553 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3554 mask = &flex_conf->flex_mask[i];
3555 p = flowtype_to_str(mask->flow_type);
3556 printf("\n %s:\t", p ? p : "unknown");
3557 for (j = 0; j < num; j++)
3558 printf(" %02x", mask->mask[j]);
3564 print_fdir_flow_type(uint32_t flow_types_mask)
3569 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3570 if (!(flow_types_mask & (1 << i)))
3572 p = flowtype_to_str(i);
3582 fdir_get_infos(portid_t port_id)
3584 struct rte_eth_fdir_stats fdir_stat;
3585 struct rte_eth_fdir_info fdir_info;
3588 static const char *fdir_stats_border = "########################";
3590 if (port_id_is_invalid(port_id, ENABLED_WARN))
3592 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3594 printf("\n FDIR is not supported on port %-2d\n",
3599 memset(&fdir_info, 0, sizeof(fdir_info));
3600 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3601 RTE_ETH_FILTER_INFO, &fdir_info);
3602 memset(&fdir_stat, 0, sizeof(fdir_stat));
3603 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3604 RTE_ETH_FILTER_STATS, &fdir_stat);
3605 printf("\n %s FDIR infos for port %-2d %s\n",
3606 fdir_stats_border, port_id, fdir_stats_border);
3608 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3609 printf(" PERFECT\n");
3610 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3611 printf(" PERFECT-MAC-VLAN\n");
3612 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3613 printf(" PERFECT-TUNNEL\n");
3614 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3615 printf(" SIGNATURE\n");
3617 printf(" DISABLE\n");
3618 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3619 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3620 printf(" SUPPORTED FLOW TYPE: ");
3621 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3623 printf(" FLEX PAYLOAD INFO:\n");
3624 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3625 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3626 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3627 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3628 fdir_info.flex_payload_unit,
3629 fdir_info.max_flex_payload_segment_num,
3630 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3632 print_fdir_mask(&fdir_info.mask);
3633 if (fdir_info.flex_conf.nb_payloads > 0) {
3634 printf(" FLEX PAYLOAD SRC OFFSET:");
3635 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3637 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3638 printf(" FLEX MASK CFG:");
3639 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3641 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3642 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3643 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3644 fdir_info.guarant_spc, fdir_info.best_spc);
3645 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3646 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3647 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3648 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3649 fdir_stat.collision, fdir_stat.free,
3650 fdir_stat.maxhash, fdir_stat.maxlen,
3651 fdir_stat.add, fdir_stat.remove,
3652 fdir_stat.f_add, fdir_stat.f_remove);
3653 printf(" %s############################%s\n",
3654 fdir_stats_border, fdir_stats_border);
3658 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3660 struct rte_port *port;
3661 struct rte_eth_fdir_flex_conf *flex_conf;
3664 port = &ports[port_id];
3665 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3666 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3667 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3672 if (i >= RTE_ETH_FLOW_MAX) {
3673 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3674 idx = flex_conf->nb_flexmasks;
3675 flex_conf->nb_flexmasks++;
3677 printf("The flex mask table is full. Can not set flex"
3678 " mask for flow_type(%u).", cfg->flow_type);
3682 rte_memcpy(&flex_conf->flex_mask[idx],
3684 sizeof(struct rte_eth_fdir_flex_mask));
3688 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3690 struct rte_port *port;
3691 struct rte_eth_fdir_flex_conf *flex_conf;
3694 port = &ports[port_id];
3695 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3696 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3697 if (cfg->type == flex_conf->flex_set[i].type) {
3702 if (i >= RTE_ETH_PAYLOAD_MAX) {
3703 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3704 idx = flex_conf->nb_payloads;
3705 flex_conf->nb_payloads++;
3707 printf("The flex payload table is full. Can not set"
3708 " flex payload for type(%u).", cfg->type);
3712 rte_memcpy(&flex_conf->flex_set[idx],
3714 sizeof(struct rte_eth_flex_payload_cfg));
3719 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3721 #ifdef RTE_LIBRTE_IXGBE_PMD
3725 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3727 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3731 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3732 is_rx ? "rx" : "tx", port_id, diag);
3735 printf("VF %s setting not supported for port %d\n",
3736 is_rx ? "Rx" : "Tx", port_id);
3742 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3745 struct rte_eth_link link;
3748 if (port_id_is_invalid(port_id, ENABLED_WARN))
3750 ret = eth_link_get_nowait_print_err(port_id, &link);
3753 if (rate > link.link_speed) {
3754 printf("Invalid rate value:%u bigger than link speed: %u\n",
3755 rate, link.link_speed);
3758 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3761 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3767 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3769 int diag = -ENOTSUP;
3773 RTE_SET_USED(q_msk);
3775 #ifdef RTE_LIBRTE_IXGBE_PMD
3776 if (diag == -ENOTSUP)
3777 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3780 #ifdef RTE_LIBRTE_BNXT_PMD
3781 if (diag == -ENOTSUP)
3782 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3787 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3793 * Functions to manage the set of filtered Multicast MAC addresses.
3795 * A pool of filtered multicast MAC addresses is associated with each port.
3796 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3797 * The address of the pool and the number of valid multicast MAC addresses
3798 * recorded in the pool are stored in the fields "mc_addr_pool" and
3799 * "mc_addr_nb" of the "rte_port" data structure.
3801 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3802 * to be supplied a contiguous array of multicast MAC addresses.
3803 * To comply with this constraint, the set of multicast addresses recorded
3804 * into the pool are systematically compacted at the beginning of the pool.
3805 * Hence, when a multicast address is removed from the pool, all following
3806 * addresses, if any, are copied back to keep the set contiguous.
3808 #define MCAST_POOL_INC 32
3811 mcast_addr_pool_extend(struct rte_port *port)
3813 struct rte_ether_addr *mc_pool;
3814 size_t mc_pool_size;
3817 * If a free entry is available at the end of the pool, just
3818 * increment the number of recorded multicast addresses.
3820 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3826 * [re]allocate a pool with MCAST_POOL_INC more entries.
3827 * The previous test guarantees that port->mc_addr_nb is a multiple
3828 * of MCAST_POOL_INC.
3830 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
3832 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
3834 if (mc_pool == NULL) {
3835 printf("allocation of pool of %u multicast addresses failed\n",
3836 port->mc_addr_nb + MCAST_POOL_INC);
3840 port->mc_addr_pool = mc_pool;
3847 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
3849 if (mcast_addr_pool_extend(port) != 0)
3851 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
3855 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3858 if (addr_idx == port->mc_addr_nb) {
3859 /* No need to recompact the set of multicast addressses. */
3860 if (port->mc_addr_nb == 0) {
3861 /* free the pool of multicast addresses. */
3862 free(port->mc_addr_pool);
3863 port->mc_addr_pool = NULL;
3867 memmove(&port->mc_addr_pool[addr_idx],
3868 &port->mc_addr_pool[addr_idx + 1],
3869 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
3873 eth_port_multicast_addr_list_set(portid_t port_id)
3875 struct rte_port *port;
3878 port = &ports[port_id];
3879 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3882 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3883 port_id, port->mc_addr_nb, diag);
3889 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
3891 struct rte_port *port;
3894 if (port_id_is_invalid(port_id, ENABLED_WARN))
3897 port = &ports[port_id];
3900 * Check that the added multicast MAC address is not already recorded
3901 * in the pool of multicast addresses.
3903 for (i = 0; i < port->mc_addr_nb; i++) {
3904 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3905 printf("multicast address already filtered by port\n");
3910 mcast_addr_pool_append(port, mc_addr);
3911 if (eth_port_multicast_addr_list_set(port_id) < 0)
3912 /* Rollback on failure, remove the address from the pool */
3913 mcast_addr_pool_remove(port, i);
3917 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
3919 struct rte_port *port;
3922 if (port_id_is_invalid(port_id, ENABLED_WARN))
3925 port = &ports[port_id];
3928 * Search the pool of multicast MAC addresses for the removed address.
3930 for (i = 0; i < port->mc_addr_nb; i++) {
3931 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3934 if (i == port->mc_addr_nb) {
3935 printf("multicast address not filtered by port %d\n", port_id);
3939 mcast_addr_pool_remove(port, i);
3940 if (eth_port_multicast_addr_list_set(port_id) < 0)
3941 /* Rollback on failure, add the address back into the pool */
3942 mcast_addr_pool_append(port, mc_addr);
3946 port_dcb_info_display(portid_t port_id)
3948 struct rte_eth_dcb_info dcb_info;
3951 static const char *border = "================";
3953 if (port_id_is_invalid(port_id, ENABLED_WARN))
3956 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3958 printf("\n Failed to get dcb infos on port %-2d\n",
3962 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3963 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3965 for (i = 0; i < dcb_info.nb_tcs; i++)
3967 printf("\n Priority : ");
3968 for (i = 0; i < dcb_info.nb_tcs; i++)
3969 printf("\t%4d", dcb_info.prio_tc[i]);
3970 printf("\n BW percent :");
3971 for (i = 0; i < dcb_info.nb_tcs; i++)
3972 printf("\t%4d%%", dcb_info.tc_bws[i]);
3973 printf("\n RXQ base : ");
3974 for (i = 0; i < dcb_info.nb_tcs; i++)
3975 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3976 printf("\n RXQ number :");
3977 for (i = 0; i < dcb_info.nb_tcs; i++)
3978 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3979 printf("\n TXQ base : ");
3980 for (i = 0; i < dcb_info.nb_tcs; i++)
3981 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3982 printf("\n TXQ number :");
3983 for (i = 0; i < dcb_info.nb_tcs; i++)
3984 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3989 open_file(const char *file_path, uint32_t *size)
3991 int fd = open(file_path, O_RDONLY);
3993 uint8_t *buf = NULL;
4001 printf("%s: Failed to open %s\n", __func__, file_path);
4005 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
4007 printf("%s: File operations failed\n", __func__);
4011 pkg_size = st_buf.st_size;
4014 printf("%s: File operations failed\n", __func__);
4018 buf = (uint8_t *)malloc(pkg_size);
4021 printf("%s: Failed to malloc memory\n", __func__);
4025 ret = read(fd, buf, pkg_size);
4028 printf("%s: File read operation failed\n", __func__);
4042 save_file(const char *file_path, uint8_t *buf, uint32_t size)
4044 FILE *fh = fopen(file_path, "wb");
4047 printf("%s: Failed to open %s\n", __func__, file_path);
4051 if (fwrite(buf, 1, size, fh) != size) {
4053 printf("%s: File write operation failed\n", __func__);
4063 close_file(uint8_t *buf)
4074 port_queue_region_info_display(portid_t port_id, void *buf)
4076 #ifdef RTE_LIBRTE_I40E_PMD
4078 struct rte_pmd_i40e_queue_regions *info =
4079 (struct rte_pmd_i40e_queue_regions *)buf;
4080 static const char *queue_region_info_stats_border = "-------";
4082 if (!info->queue_region_number)
4083 printf("there is no region has been set before");
4085 printf("\n %s All queue region info for port=%2d %s",
4086 queue_region_info_stats_border, port_id,
4087 queue_region_info_stats_border);
4088 printf("\n queue_region_number: %-14u \n",
4089 info->queue_region_number);
4091 for (i = 0; i < info->queue_region_number; i++) {
4092 printf("\n region_id: %-14u queue_number: %-14u "
4093 "queue_start_index: %-14u \n",
4094 info->region[i].region_id,
4095 info->region[i].queue_num,
4096 info->region[i].queue_start_index);
4098 printf(" user_priority_num is %-14u :",
4099 info->region[i].user_priority_num);
4100 for (j = 0; j < info->region[i].user_priority_num; j++)
4101 printf(" %-14u ", info->region[i].user_priority[j]);
4103 printf("\n flowtype_num is %-14u :",
4104 info->region[i].flowtype_num);
4105 for (j = 0; j < info->region[i].flowtype_num; j++)
4106 printf(" %-14u ", info->region[i].hw_flowtype[j]);
4109 RTE_SET_USED(port_id);
4117 show_macs(portid_t port_id)
4119 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4120 struct rte_eth_dev_info dev_info;
4121 struct rte_ether_addr *addr;
4122 uint32_t i, num_macs = 0;
4123 struct rte_eth_dev *dev;
4125 dev = &rte_eth_devices[port_id];
4127 rte_eth_dev_info_get(port_id, &dev_info);
4129 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4130 addr = &dev->data->mac_addrs[i];
4132 /* skip zero address */
4133 if (rte_is_zero_ether_addr(addr))
4139 printf("Number of MAC address added: %d\n", num_macs);
4141 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4142 addr = &dev->data->mac_addrs[i];
4144 /* skip zero address */
4145 if (rte_is_zero_ether_addr(addr))
4148 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4149 printf(" %s\n", buf);
4154 show_mcast_macs(portid_t port_id)
4156 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4157 struct rte_ether_addr *addr;
4158 struct rte_port *port;
4161 port = &ports[port_id];
4163 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
4165 for (i = 0; i < port->mc_addr_nb; i++) {
4166 addr = &port->mc_addr_pool[i];
4168 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4169 printf(" %s\n", buf);