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>
52 #include <rte_config.h>
56 static char *flowtype_to_str(uint16_t flow_type);
59 enum tx_pkt_split split;
63 .split = TX_PKT_SPLIT_OFF,
67 .split = TX_PKT_SPLIT_ON,
71 .split = TX_PKT_SPLIT_RND,
76 const struct rss_type_info rss_type_table[] = {
77 { "all", ETH_RSS_IP | ETH_RSS_TCP |
78 ETH_RSS_UDP | ETH_RSS_SCTP |
81 { "ipv4", ETH_RSS_IPV4 },
82 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
83 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
84 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
85 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
86 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
87 { "ipv6", ETH_RSS_IPV6 },
88 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
89 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
90 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
91 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
92 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
93 { "l2-payload", ETH_RSS_L2_PAYLOAD },
94 { "ipv6-ex", ETH_RSS_IPV6_EX },
95 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
96 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
97 { "port", ETH_RSS_PORT },
98 { "vxlan", ETH_RSS_VXLAN },
99 { "geneve", ETH_RSS_GENEVE },
100 { "nvgre", ETH_RSS_NVGRE },
101 { "ip", ETH_RSS_IP },
102 { "udp", ETH_RSS_UDP },
103 { "tcp", ETH_RSS_TCP },
104 { "sctp", ETH_RSS_SCTP },
105 { "tunnel", ETH_RSS_TUNNEL },
106 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
107 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
108 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
109 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
114 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
116 char buf[RTE_ETHER_ADDR_FMT_SIZE];
117 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
118 printf("%s%s", name, buf);
122 nic_stats_display(portid_t port_id)
124 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
125 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
126 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
127 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
128 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
129 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
131 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
132 struct rte_eth_stats stats;
133 struct rte_port *port = &ports[port_id];
136 static const char *nic_stats_border = "########################";
138 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
142 rte_eth_stats_get(port_id, &stats);
143 printf("\n %s NIC statistics for port %-2d %s\n",
144 nic_stats_border, port_id, nic_stats_border);
146 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
147 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
149 stats.ipackets, stats.imissed, stats.ibytes);
150 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
151 printf(" RX-nombuf: %-10"PRIu64"\n",
153 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
155 stats.opackets, stats.oerrors, stats.obytes);
158 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
159 " RX-bytes: %10"PRIu64"\n",
160 stats.ipackets, stats.ierrors, stats.ibytes);
161 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
162 printf(" RX-nombuf: %10"PRIu64"\n",
164 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
165 " TX-bytes: %10"PRIu64"\n",
166 stats.opackets, stats.oerrors, stats.obytes);
169 if (port->rx_queue_stats_mapping_enabled) {
171 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
172 printf(" Stats reg %2d RX-packets: %10"PRIu64
173 " RX-errors: %10"PRIu64
174 " RX-bytes: %10"PRIu64"\n",
175 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
178 if (port->tx_queue_stats_mapping_enabled) {
180 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
181 printf(" Stats reg %2d TX-packets: %10"PRIu64
182 " TX-bytes: %10"PRIu64"\n",
183 i, stats.q_opackets[i], stats.q_obytes[i]);
187 diff_cycles = prev_cycles[port_id];
188 prev_cycles[port_id] = rte_rdtsc();
190 diff_cycles = prev_cycles[port_id] - diff_cycles;
192 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
193 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
194 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
195 (stats.opackets - prev_pkts_tx[port_id]) : 0;
196 prev_pkts_rx[port_id] = stats.ipackets;
197 prev_pkts_tx[port_id] = stats.opackets;
198 mpps_rx = diff_cycles > 0 ?
199 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
200 mpps_tx = diff_cycles > 0 ?
201 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
203 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
204 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
205 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
206 (stats.obytes - prev_bytes_tx[port_id]) : 0;
207 prev_bytes_rx[port_id] = stats.ibytes;
208 prev_bytes_tx[port_id] = stats.obytes;
209 mbps_rx = diff_cycles > 0 ?
210 diff_bytes_rx * rte_get_tsc_hz() / diff_cycles : 0;
211 mbps_tx = diff_cycles > 0 ?
212 diff_bytes_tx * rte_get_tsc_hz() / diff_cycles : 0;
214 printf("\n Throughput (since last show)\n");
215 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
216 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
217 mpps_tx, mbps_tx * 8);
219 printf(" %s############################%s\n",
220 nic_stats_border, nic_stats_border);
224 nic_stats_clear(portid_t port_id)
226 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
230 rte_eth_stats_reset(port_id);
231 printf("\n NIC statistics for port %d cleared\n", port_id);
235 nic_xstats_display(portid_t port_id)
237 struct rte_eth_xstat *xstats;
238 int cnt_xstats, idx_xstat;
239 struct rte_eth_xstat_name *xstats_names;
241 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
245 printf("###### NIC extended statistics for port %-2d\n", port_id);
246 if (!rte_eth_dev_is_valid_port(port_id)) {
247 printf("Error: Invalid port number %i\n", port_id);
252 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
253 if (cnt_xstats < 0) {
254 printf("Error: Cannot get count of xstats\n");
258 /* Get id-name lookup table */
259 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
260 if (xstats_names == NULL) {
261 printf("Cannot allocate memory for xstats lookup\n");
264 if (cnt_xstats != rte_eth_xstats_get_names(
265 port_id, xstats_names, cnt_xstats)) {
266 printf("Error: Cannot get xstats lookup\n");
271 /* Get stats themselves */
272 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
273 if (xstats == NULL) {
274 printf("Cannot allocate memory for xstats\n");
278 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
279 printf("Error: Unable to get xstats\n");
286 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
287 if (xstats_hide_zero && !xstats[idx_xstat].value)
289 printf("%s: %"PRIu64"\n",
290 xstats_names[idx_xstat].name,
291 xstats[idx_xstat].value);
298 nic_xstats_clear(portid_t port_id)
302 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
306 ret = rte_eth_xstats_reset(port_id);
308 printf("%s: Error: failed to reset xstats (port %u): %s",
309 __func__, port_id, strerror(ret));
314 nic_stats_mapping_display(portid_t port_id)
316 struct rte_port *port = &ports[port_id];
319 static const char *nic_stats_mapping_border = "########################";
321 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
326 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
327 printf("Port id %d - either does not support queue statistic mapping or"
328 " no queue statistic mapping set\n", port_id);
332 printf("\n %s NIC statistics mapping for port %-2d %s\n",
333 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
335 if (port->rx_queue_stats_mapping_enabled) {
336 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
337 if (rx_queue_stats_mappings[i].port_id == port_id) {
338 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
339 rx_queue_stats_mappings[i].queue_id,
340 rx_queue_stats_mappings[i].stats_counter_id);
347 if (port->tx_queue_stats_mapping_enabled) {
348 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
349 if (tx_queue_stats_mappings[i].port_id == port_id) {
350 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
351 tx_queue_stats_mappings[i].queue_id,
352 tx_queue_stats_mappings[i].stats_counter_id);
357 printf(" %s####################################%s\n",
358 nic_stats_mapping_border, nic_stats_mapping_border);
362 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
364 struct rte_eth_burst_mode mode;
365 struct rte_eth_rxq_info qinfo;
367 static const char *info_border = "*********************";
369 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
371 printf("Failed to retrieve information for port: %u, "
372 "RX queue: %hu\nerror desc: %s(%d)\n",
373 port_id, queue_id, strerror(-rc), rc);
377 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
378 info_border, port_id, queue_id, info_border);
380 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
381 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
382 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
383 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
384 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
385 printf("\nRX drop packets: %s",
386 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
387 printf("\nRX deferred start: %s",
388 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
389 printf("\nRX scattered packets: %s",
390 (qinfo.scattered_rx != 0) ? "on" : "off");
391 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
393 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
394 printf("\nBurst mode: %s%s",
396 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
397 " (per queue)" : "");
403 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
405 struct rte_eth_burst_mode mode;
406 struct rte_eth_txq_info qinfo;
408 static const char *info_border = "*********************";
410 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
412 printf("Failed to retrieve information for port: %u, "
413 "TX queue: %hu\nerror desc: %s(%d)\n",
414 port_id, queue_id, strerror(-rc), rc);
418 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
419 info_border, port_id, queue_id, info_border);
421 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
422 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
423 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
424 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
425 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
426 printf("\nTX deferred start: %s",
427 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
428 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
430 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
431 printf("\nBurst mode: %s%s",
433 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
434 " (per queue)" : "");
439 static int bus_match_all(const struct rte_bus *bus, const void *data)
447 device_infos_display(const char *identifier)
449 static const char *info_border = "*********************";
450 struct rte_bus *start = NULL, *next;
451 struct rte_dev_iterator dev_iter;
452 char name[RTE_ETH_NAME_MAX_LEN];
453 struct rte_ether_addr mac_addr;
454 struct rte_device *dev;
455 struct rte_devargs da;
459 memset(&da, 0, sizeof(da));
463 if (rte_devargs_parsef(&da, "%s", identifier)) {
464 printf("cannot parse identifier\n");
471 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
474 if (identifier && da.bus != next)
477 /* Skip buses that don't have iterate method */
478 if (!next->dev_iterate)
481 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
482 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
486 /* Check for matching device if identifier is present */
488 strncmp(da.name, dev->name, strlen(dev->name)))
490 printf("\n%s Infos for device %s %s\n",
491 info_border, dev->name, info_border);
492 printf("Bus name: %s", dev->bus->name);
493 printf("\nDriver name: %s", dev->driver->name);
494 printf("\nDevargs: %s",
495 dev->devargs ? dev->devargs->args : "");
496 printf("\nConnect to socket: %d", dev->numa_node);
499 /* List ports with matching device name */
500 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
501 printf("\n\tPort id: %-2d", port_id);
502 if (eth_macaddr_get_print_err(port_id,
504 print_ethaddr("\n\tMAC address: ",
506 rte_eth_dev_get_name_by_port(port_id, name);
507 printf("\n\tDevice name: %s", name);
515 port_infos_display(portid_t port_id)
517 struct rte_port *port;
518 struct rte_ether_addr mac_addr;
519 struct rte_eth_link link;
520 struct rte_eth_dev_info dev_info;
522 struct rte_mempool * mp;
523 static const char *info_border = "*********************";
525 char name[RTE_ETH_NAME_MAX_LEN];
528 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
532 port = &ports[port_id];
533 ret = eth_link_get_nowait_print_err(port_id, &link);
537 ret = eth_dev_info_get_print_err(port_id, &dev_info);
541 printf("\n%s Infos for port %-2d %s\n",
542 info_border, port_id, info_border);
543 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
544 print_ethaddr("MAC address: ", &mac_addr);
545 rte_eth_dev_get_name_by_port(port_id, name);
546 printf("\nDevice name: %s", name);
547 printf("\nDriver name: %s", dev_info.driver_name);
548 if (dev_info.device->devargs && dev_info.device->devargs->args)
549 printf("\nDevargs: %s", dev_info.device->devargs->args);
550 printf("\nConnect to socket: %u", port->socket_id);
552 if (port_numa[port_id] != NUMA_NO_CONFIG) {
553 mp = mbuf_pool_find(port_numa[port_id]);
555 printf("\nmemory allocation on the socket: %d",
558 printf("\nmemory allocation on the socket: %u",port->socket_id);
560 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
561 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
562 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
563 ("full-duplex") : ("half-duplex"));
565 if (!rte_eth_dev_get_mtu(port_id, &mtu))
566 printf("MTU: %u\n", mtu);
568 printf("Promiscuous mode: %s\n",
569 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
570 printf("Allmulticast mode: %s\n",
571 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
572 printf("Maximum number of MAC addresses: %u\n",
573 (unsigned int)(port->dev_info.max_mac_addrs));
574 printf("Maximum number of MAC addresses of hash filtering: %u\n",
575 (unsigned int)(port->dev_info.max_hash_mac_addrs));
577 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
578 if (vlan_offload >= 0){
579 printf("VLAN offload: \n");
580 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
581 printf(" strip on, ");
583 printf(" strip off, ");
585 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
586 printf("filter on, ");
588 printf("filter off, ");
590 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
591 printf("extend on, ");
593 printf("extend off, ");
595 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
596 printf("qinq strip on\n");
598 printf("qinq strip off\n");
601 if (dev_info.hash_key_size > 0)
602 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
603 if (dev_info.reta_size > 0)
604 printf("Redirection table size: %u\n", dev_info.reta_size);
605 if (!dev_info.flow_type_rss_offloads)
606 printf("No RSS offload flow type is supported.\n");
611 printf("Supported RSS offload flow types:\n");
612 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
613 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
614 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
616 p = flowtype_to_str(i);
620 printf(" user defined %d\n", i);
624 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
625 printf("Maximum configurable length of RX packet: %u\n",
626 dev_info.max_rx_pktlen);
627 printf("Maximum configurable size of LRO aggregated packet: %u\n",
628 dev_info.max_lro_pkt_size);
629 if (dev_info.max_vfs)
630 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
631 if (dev_info.max_vmdq_pools)
632 printf("Maximum number of VMDq pools: %u\n",
633 dev_info.max_vmdq_pools);
635 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
636 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
637 printf("Max possible number of RXDs per queue: %hu\n",
638 dev_info.rx_desc_lim.nb_max);
639 printf("Min possible number of RXDs per queue: %hu\n",
640 dev_info.rx_desc_lim.nb_min);
641 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
643 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
644 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
645 printf("Max possible number of TXDs per queue: %hu\n",
646 dev_info.tx_desc_lim.nb_max);
647 printf("Min possible number of TXDs per queue: %hu\n",
648 dev_info.tx_desc_lim.nb_min);
649 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
650 printf("Max segment number per packet: %hu\n",
651 dev_info.tx_desc_lim.nb_seg_max);
652 printf("Max segment number per MTU/TSO: %hu\n",
653 dev_info.tx_desc_lim.nb_mtu_seg_max);
655 /* Show switch info only if valid switch domain and port id is set */
656 if (dev_info.switch_info.domain_id !=
657 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
658 if (dev_info.switch_info.name)
659 printf("Switch name: %s\n", dev_info.switch_info.name);
661 printf("Switch domain Id: %u\n",
662 dev_info.switch_info.domain_id);
663 printf("Switch Port Id: %u\n",
664 dev_info.switch_info.port_id);
669 port_summary_header_display(void)
671 uint16_t port_number;
673 port_number = rte_eth_dev_count_avail();
674 printf("Number of available ports: %i\n", port_number);
675 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
676 "Driver", "Status", "Link");
680 port_summary_display(portid_t port_id)
682 struct rte_ether_addr mac_addr;
683 struct rte_eth_link link;
684 struct rte_eth_dev_info dev_info;
685 char name[RTE_ETH_NAME_MAX_LEN];
688 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
693 ret = eth_link_get_nowait_print_err(port_id, &link);
697 ret = eth_dev_info_get_print_err(port_id, &dev_info);
701 rte_eth_dev_get_name_by_port(port_id, name);
702 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
706 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
707 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
708 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
709 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
710 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
711 (unsigned int) link.link_speed);
715 port_offload_cap_display(portid_t port_id)
717 struct rte_eth_dev_info dev_info;
718 static const char *info_border = "************";
721 if (port_id_is_invalid(port_id, ENABLED_WARN))
724 ret = eth_dev_info_get_print_err(port_id, &dev_info);
728 printf("\n%s Port %d supported offload features: %s\n",
729 info_border, port_id, info_border);
731 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
732 printf("VLAN stripped: ");
733 if (ports[port_id].dev_conf.rxmode.offloads &
734 DEV_RX_OFFLOAD_VLAN_STRIP)
740 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
741 printf("Double VLANs stripped: ");
742 if (ports[port_id].dev_conf.rxmode.offloads &
743 DEV_RX_OFFLOAD_QINQ_STRIP)
749 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
750 printf("RX IPv4 checksum: ");
751 if (ports[port_id].dev_conf.rxmode.offloads &
752 DEV_RX_OFFLOAD_IPV4_CKSUM)
758 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
759 printf("RX UDP checksum: ");
760 if (ports[port_id].dev_conf.rxmode.offloads &
761 DEV_RX_OFFLOAD_UDP_CKSUM)
767 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
768 printf("RX TCP checksum: ");
769 if (ports[port_id].dev_conf.rxmode.offloads &
770 DEV_RX_OFFLOAD_TCP_CKSUM)
776 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) {
777 printf("RX SCTP checksum: ");
778 if (ports[port_id].dev_conf.rxmode.offloads &
779 DEV_RX_OFFLOAD_SCTP_CKSUM)
785 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
786 printf("RX Outer IPv4 checksum: ");
787 if (ports[port_id].dev_conf.rxmode.offloads &
788 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
794 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) {
795 printf("RX Outer UDP checksum: ");
796 if (ports[port_id].dev_conf.rxmode.offloads &
797 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM)
803 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
804 printf("Large receive offload: ");
805 if (ports[port_id].dev_conf.rxmode.offloads &
806 DEV_RX_OFFLOAD_TCP_LRO)
812 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
813 printf("HW timestamp: ");
814 if (ports[port_id].dev_conf.rxmode.offloads &
815 DEV_RX_OFFLOAD_TIMESTAMP)
821 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) {
822 printf("Rx Keep CRC: ");
823 if (ports[port_id].dev_conf.rxmode.offloads &
824 DEV_RX_OFFLOAD_KEEP_CRC)
830 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) {
831 printf("RX offload security: ");
832 if (ports[port_id].dev_conf.rxmode.offloads &
833 DEV_RX_OFFLOAD_SECURITY)
839 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
840 printf("VLAN insert: ");
841 if (ports[port_id].dev_conf.txmode.offloads &
842 DEV_TX_OFFLOAD_VLAN_INSERT)
848 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
849 printf("Double VLANs insert: ");
850 if (ports[port_id].dev_conf.txmode.offloads &
851 DEV_TX_OFFLOAD_QINQ_INSERT)
857 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
858 printf("TX IPv4 checksum: ");
859 if (ports[port_id].dev_conf.txmode.offloads &
860 DEV_TX_OFFLOAD_IPV4_CKSUM)
866 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
867 printf("TX UDP checksum: ");
868 if (ports[port_id].dev_conf.txmode.offloads &
869 DEV_TX_OFFLOAD_UDP_CKSUM)
875 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
876 printf("TX TCP checksum: ");
877 if (ports[port_id].dev_conf.txmode.offloads &
878 DEV_TX_OFFLOAD_TCP_CKSUM)
884 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
885 printf("TX SCTP checksum: ");
886 if (ports[port_id].dev_conf.txmode.offloads &
887 DEV_TX_OFFLOAD_SCTP_CKSUM)
893 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
894 printf("TX Outer IPv4 checksum: ");
895 if (ports[port_id].dev_conf.txmode.offloads &
896 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
902 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
903 printf("TX TCP segmentation: ");
904 if (ports[port_id].dev_conf.txmode.offloads &
905 DEV_TX_OFFLOAD_TCP_TSO)
911 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
912 printf("TX UDP segmentation: ");
913 if (ports[port_id].dev_conf.txmode.offloads &
914 DEV_TX_OFFLOAD_UDP_TSO)
920 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
921 printf("TSO for VXLAN tunnel packet: ");
922 if (ports[port_id].dev_conf.txmode.offloads &
923 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
929 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
930 printf("TSO for GRE tunnel packet: ");
931 if (ports[port_id].dev_conf.txmode.offloads &
932 DEV_TX_OFFLOAD_GRE_TNL_TSO)
938 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
939 printf("TSO for IPIP tunnel packet: ");
940 if (ports[port_id].dev_conf.txmode.offloads &
941 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
947 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
948 printf("TSO for GENEVE tunnel packet: ");
949 if (ports[port_id].dev_conf.txmode.offloads &
950 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
956 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) {
957 printf("IP tunnel TSO: ");
958 if (ports[port_id].dev_conf.txmode.offloads &
959 DEV_TX_OFFLOAD_IP_TNL_TSO)
965 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) {
966 printf("UDP tunnel TSO: ");
967 if (ports[port_id].dev_conf.txmode.offloads &
968 DEV_TX_OFFLOAD_UDP_TNL_TSO)
974 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
975 printf("TX Outer UDP checksum: ");
976 if (ports[port_id].dev_conf.txmode.offloads &
977 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
986 port_id_is_invalid(portid_t port_id, enum print_warning warning)
990 if (port_id == (portid_t)RTE_PORT_ALL)
993 RTE_ETH_FOREACH_DEV(pid)
997 if (warning == ENABLED_WARN)
998 printf("Invalid port %d\n", port_id);
1003 void print_valid_ports(void)
1007 printf("The valid ports array is [");
1008 RTE_ETH_FOREACH_DEV(pid) {
1015 vlan_id_is_invalid(uint16_t vlan_id)
1019 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1024 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1026 const struct rte_pci_device *pci_dev;
1027 const struct rte_bus *bus;
1030 if (reg_off & 0x3) {
1031 printf("Port register offset 0x%X not aligned on a 4-byte "
1037 if (!ports[port_id].dev_info.device) {
1038 printf("Invalid device\n");
1042 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1043 if (bus && !strcmp(bus->name, "pci")) {
1044 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1046 printf("Not a PCI device\n");
1050 pci_len = pci_dev->mem_resource[0].len;
1051 if (reg_off >= pci_len) {
1052 printf("Port %d: register offset %u (0x%X) out of port PCI "
1053 "resource (length=%"PRIu64")\n",
1054 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
1061 reg_bit_pos_is_invalid(uint8_t bit_pos)
1065 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
1069 #define display_port_and_reg_off(port_id, reg_off) \
1070 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1073 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1075 display_port_and_reg_off(port_id, (unsigned)reg_off);
1076 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1080 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1085 if (port_id_is_invalid(port_id, ENABLED_WARN))
1087 if (port_reg_off_is_invalid(port_id, reg_off))
1089 if (reg_bit_pos_is_invalid(bit_x))
1091 reg_v = port_id_pci_reg_read(port_id, reg_off);
1092 display_port_and_reg_off(port_id, (unsigned)reg_off);
1093 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1097 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1098 uint8_t bit1_pos, uint8_t bit2_pos)
1104 if (port_id_is_invalid(port_id, ENABLED_WARN))
1106 if (port_reg_off_is_invalid(port_id, reg_off))
1108 if (reg_bit_pos_is_invalid(bit1_pos))
1110 if (reg_bit_pos_is_invalid(bit2_pos))
1112 if (bit1_pos > bit2_pos)
1113 l_bit = bit2_pos, h_bit = bit1_pos;
1115 l_bit = bit1_pos, h_bit = bit2_pos;
1117 reg_v = port_id_pci_reg_read(port_id, reg_off);
1120 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1121 display_port_and_reg_off(port_id, (unsigned)reg_off);
1122 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1123 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1127 port_reg_display(portid_t port_id, uint32_t reg_off)
1131 if (port_id_is_invalid(port_id, ENABLED_WARN))
1133 if (port_reg_off_is_invalid(port_id, reg_off))
1135 reg_v = port_id_pci_reg_read(port_id, reg_off);
1136 display_port_reg_value(port_id, reg_off, reg_v);
1140 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1145 if (port_id_is_invalid(port_id, ENABLED_WARN))
1147 if (port_reg_off_is_invalid(port_id, reg_off))
1149 if (reg_bit_pos_is_invalid(bit_pos))
1152 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1155 reg_v = port_id_pci_reg_read(port_id, reg_off);
1157 reg_v &= ~(1 << bit_pos);
1159 reg_v |= (1 << bit_pos);
1160 port_id_pci_reg_write(port_id, reg_off, reg_v);
1161 display_port_reg_value(port_id, reg_off, reg_v);
1165 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1166 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1173 if (port_id_is_invalid(port_id, ENABLED_WARN))
1175 if (port_reg_off_is_invalid(port_id, reg_off))
1177 if (reg_bit_pos_is_invalid(bit1_pos))
1179 if (reg_bit_pos_is_invalid(bit2_pos))
1181 if (bit1_pos > bit2_pos)
1182 l_bit = bit2_pos, h_bit = bit1_pos;
1184 l_bit = bit1_pos, h_bit = bit2_pos;
1186 if ((h_bit - l_bit) < 31)
1187 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1191 if (value > max_v) {
1192 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1193 (unsigned)value, (unsigned)value,
1194 (unsigned)max_v, (unsigned)max_v);
1197 reg_v = port_id_pci_reg_read(port_id, reg_off);
1198 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1199 reg_v |= (value << l_bit); /* Set changed bits */
1200 port_id_pci_reg_write(port_id, reg_off, reg_v);
1201 display_port_reg_value(port_id, reg_off, reg_v);
1205 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1207 if (port_id_is_invalid(port_id, ENABLED_WARN))
1209 if (port_reg_off_is_invalid(port_id, reg_off))
1211 port_id_pci_reg_write(port_id, reg_off, reg_v);
1212 display_port_reg_value(port_id, reg_off, reg_v);
1216 port_mtu_set(portid_t port_id, uint16_t mtu)
1219 struct rte_eth_dev_info dev_info;
1222 if (port_id_is_invalid(port_id, ENABLED_WARN))
1225 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1229 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1230 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1231 mtu, dev_info.min_mtu, dev_info.max_mtu);
1234 diag = rte_eth_dev_set_mtu(port_id, mtu);
1237 printf("Set MTU failed. diag=%d\n", diag);
1240 /* Generic flow management functions. */
1242 /** Generate a port_flow entry from attributes/pattern/actions. */
1243 static struct port_flow *
1244 port_flow_new(const struct rte_flow_attr *attr,
1245 const struct rte_flow_item *pattern,
1246 const struct rte_flow_action *actions,
1247 struct rte_flow_error *error)
1249 const struct rte_flow_conv_rule rule = {
1251 .pattern_ro = pattern,
1252 .actions_ro = actions,
1254 struct port_flow *pf;
1257 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1260 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1263 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1267 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1274 /** Print a message out of a flow error. */
1276 port_flow_complain(struct rte_flow_error *error)
1278 static const char *const errstrlist[] = {
1279 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1280 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1281 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1282 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1283 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1284 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1285 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1286 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1287 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1288 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1289 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1290 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1291 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1292 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1293 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1294 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1295 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1299 int err = rte_errno;
1301 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1302 !errstrlist[error->type])
1303 errstr = "unknown type";
1305 errstr = errstrlist[error->type];
1306 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1307 error->type, errstr,
1308 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1309 error->cause), buf) : "",
1310 error->message ? error->message : "(no stated reason)",
1315 /** Validate flow rule. */
1317 port_flow_validate(portid_t port_id,
1318 const struct rte_flow_attr *attr,
1319 const struct rte_flow_item *pattern,
1320 const struct rte_flow_action *actions)
1322 struct rte_flow_error error;
1324 /* Poisoning to make sure PMDs update it in case of error. */
1325 memset(&error, 0x11, sizeof(error));
1326 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1327 return port_flow_complain(&error);
1328 printf("Flow rule validated\n");
1332 /** Create flow rule. */
1334 port_flow_create(portid_t port_id,
1335 const struct rte_flow_attr *attr,
1336 const struct rte_flow_item *pattern,
1337 const struct rte_flow_action *actions)
1339 struct rte_flow *flow;
1340 struct rte_port *port;
1341 struct port_flow *pf;
1343 struct rte_flow_error error;
1345 /* Poisoning to make sure PMDs update it in case of error. */
1346 memset(&error, 0x22, sizeof(error));
1347 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1349 return port_flow_complain(&error);
1350 port = &ports[port_id];
1351 if (port->flow_list) {
1352 if (port->flow_list->id == UINT32_MAX) {
1353 printf("Highest rule ID is already assigned, delete"
1355 rte_flow_destroy(port_id, flow, NULL);
1358 id = port->flow_list->id + 1;
1361 pf = port_flow_new(attr, pattern, actions, &error);
1363 rte_flow_destroy(port_id, flow, NULL);
1364 return port_flow_complain(&error);
1366 pf->next = port->flow_list;
1369 port->flow_list = pf;
1370 printf("Flow rule #%u created\n", pf->id);
1374 /** Destroy a number of flow rules. */
1376 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1378 struct rte_port *port;
1379 struct port_flow **tmp;
1383 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1384 port_id == (portid_t)RTE_PORT_ALL)
1386 port = &ports[port_id];
1387 tmp = &port->flow_list;
1391 for (i = 0; i != n; ++i) {
1392 struct rte_flow_error error;
1393 struct port_flow *pf = *tmp;
1395 if (rule[i] != pf->id)
1398 * Poisoning to make sure PMDs update it in case
1401 memset(&error, 0x33, sizeof(error));
1402 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1403 ret = port_flow_complain(&error);
1406 printf("Flow rule #%u destroyed\n", pf->id);
1412 tmp = &(*tmp)->next;
1418 /** Remove all flow rules. */
1420 port_flow_flush(portid_t port_id)
1422 struct rte_flow_error error;
1423 struct rte_port *port;
1426 /* Poisoning to make sure PMDs update it in case of error. */
1427 memset(&error, 0x44, sizeof(error));
1428 if (rte_flow_flush(port_id, &error)) {
1429 ret = port_flow_complain(&error);
1430 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1431 port_id == (portid_t)RTE_PORT_ALL)
1434 port = &ports[port_id];
1435 while (port->flow_list) {
1436 struct port_flow *pf = port->flow_list->next;
1438 free(port->flow_list);
1439 port->flow_list = pf;
1444 /** Dump all flow rules. */
1446 port_flow_dump(portid_t port_id, const char *file_name)
1449 FILE *file = stdout;
1450 struct rte_flow_error error;
1452 if (file_name && strlen(file_name)) {
1453 file = fopen(file_name, "w");
1455 printf("Failed to create file %s: %s\n", file_name,
1460 ret = rte_flow_dev_dump(port_id, file, &error);
1462 port_flow_complain(&error);
1463 printf("Failed to dump flow: %s\n", strerror(-ret));
1465 printf("Flow dump finished\n");
1466 if (file_name && strlen(file_name))
1471 /** Query a flow rule. */
1473 port_flow_query(portid_t port_id, uint32_t rule,
1474 const struct rte_flow_action *action)
1476 struct rte_flow_error error;
1477 struct rte_port *port;
1478 struct port_flow *pf;
1481 struct rte_flow_query_count count;
1485 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1486 port_id == (portid_t)RTE_PORT_ALL)
1488 port = &ports[port_id];
1489 for (pf = port->flow_list; pf; pf = pf->next)
1493 printf("Flow rule #%u not found\n", rule);
1496 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1497 &name, sizeof(name),
1498 (void *)(uintptr_t)action->type, &error);
1500 return port_flow_complain(&error);
1501 switch (action->type) {
1502 case RTE_FLOW_ACTION_TYPE_COUNT:
1505 printf("Cannot query action type %d (%s)\n",
1506 action->type, name);
1509 /* Poisoning to make sure PMDs update it in case of error. */
1510 memset(&error, 0x55, sizeof(error));
1511 memset(&query, 0, sizeof(query));
1512 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1513 return port_flow_complain(&error);
1514 switch (action->type) {
1515 case RTE_FLOW_ACTION_TYPE_COUNT:
1519 " hits: %" PRIu64 "\n"
1520 " bytes: %" PRIu64 "\n",
1522 query.count.hits_set,
1523 query.count.bytes_set,
1528 printf("Cannot display result for action type %d (%s)\n",
1529 action->type, name);
1535 /** List flow rules. */
1537 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1539 struct rte_port *port;
1540 struct port_flow *pf;
1541 struct port_flow *list = NULL;
1544 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1545 port_id == (portid_t)RTE_PORT_ALL)
1547 port = &ports[port_id];
1548 if (!port->flow_list)
1550 /* Sort flows by group, priority and ID. */
1551 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1552 struct port_flow **tmp;
1553 const struct rte_flow_attr *curr = pf->rule.attr;
1556 /* Filter out unwanted groups. */
1557 for (i = 0; i != n; ++i)
1558 if (curr->group == group[i])
1563 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
1564 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
1566 if (curr->group > comp->group ||
1567 (curr->group == comp->group &&
1568 curr->priority > comp->priority) ||
1569 (curr->group == comp->group &&
1570 curr->priority == comp->priority &&
1571 pf->id > (*tmp)->id))
1578 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1579 for (pf = list; pf != NULL; pf = pf->tmp) {
1580 const struct rte_flow_item *item = pf->rule.pattern;
1581 const struct rte_flow_action *action = pf->rule.actions;
1584 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
1586 pf->rule.attr->group,
1587 pf->rule.attr->priority,
1588 pf->rule.attr->ingress ? 'i' : '-',
1589 pf->rule.attr->egress ? 'e' : '-',
1590 pf->rule.attr->transfer ? 't' : '-');
1591 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1592 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
1593 &name, sizeof(name),
1594 (void *)(uintptr_t)item->type,
1597 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1598 printf("%s ", name);
1602 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1603 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1604 &name, sizeof(name),
1605 (void *)(uintptr_t)action->type,
1608 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1609 printf(" %s", name);
1616 /** Restrict ingress traffic to the defined flow rules. */
1618 port_flow_isolate(portid_t port_id, int set)
1620 struct rte_flow_error error;
1622 /* Poisoning to make sure PMDs update it in case of error. */
1623 memset(&error, 0x66, sizeof(error));
1624 if (rte_flow_isolate(port_id, set, &error))
1625 return port_flow_complain(&error);
1626 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1628 set ? "now restricted" : "not restricted anymore");
1633 * RX/TX ring descriptors display functions.
1636 rx_queue_id_is_invalid(queueid_t rxq_id)
1638 if (rxq_id < nb_rxq)
1640 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1645 tx_queue_id_is_invalid(queueid_t txq_id)
1647 if (txq_id < nb_txq)
1649 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1654 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1656 if (rxdesc_id < nb_rxd)
1658 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1664 tx_desc_id_is_invalid(uint16_t txdesc_id)
1666 if (txdesc_id < nb_txd)
1668 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1673 static const struct rte_memzone *
1674 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1676 char mz_name[RTE_MEMZONE_NAMESIZE];
1677 const struct rte_memzone *mz;
1679 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
1680 port_id, q_id, ring_name);
1681 mz = rte_memzone_lookup(mz_name);
1683 printf("%s ring memory zoneof (port %d, queue %d) not"
1684 "found (zone name = %s\n",
1685 ring_name, port_id, q_id, mz_name);
1689 union igb_ring_dword {
1692 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1702 struct igb_ring_desc_32_bytes {
1703 union igb_ring_dword lo_dword;
1704 union igb_ring_dword hi_dword;
1705 union igb_ring_dword resv1;
1706 union igb_ring_dword resv2;
1709 struct igb_ring_desc_16_bytes {
1710 union igb_ring_dword lo_dword;
1711 union igb_ring_dword hi_dword;
1715 ring_rxd_display_dword(union igb_ring_dword dword)
1717 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1718 (unsigned)dword.words.hi);
1722 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1723 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1726 __rte_unused portid_t port_id,
1730 struct igb_ring_desc_16_bytes *ring =
1731 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1732 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1734 struct rte_eth_dev_info dev_info;
1736 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1740 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1741 /* 32 bytes RX descriptor, i40e only */
1742 struct igb_ring_desc_32_bytes *ring =
1743 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1744 ring[desc_id].lo_dword.dword =
1745 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1746 ring_rxd_display_dword(ring[desc_id].lo_dword);
1747 ring[desc_id].hi_dword.dword =
1748 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1749 ring_rxd_display_dword(ring[desc_id].hi_dword);
1750 ring[desc_id].resv1.dword =
1751 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1752 ring_rxd_display_dword(ring[desc_id].resv1);
1753 ring[desc_id].resv2.dword =
1754 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1755 ring_rxd_display_dword(ring[desc_id].resv2);
1760 /* 16 bytes RX descriptor */
1761 ring[desc_id].lo_dword.dword =
1762 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1763 ring_rxd_display_dword(ring[desc_id].lo_dword);
1764 ring[desc_id].hi_dword.dword =
1765 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1766 ring_rxd_display_dword(ring[desc_id].hi_dword);
1770 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1772 struct igb_ring_desc_16_bytes *ring;
1773 struct igb_ring_desc_16_bytes txd;
1775 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1776 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1777 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1778 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1779 (unsigned)txd.lo_dword.words.lo,
1780 (unsigned)txd.lo_dword.words.hi,
1781 (unsigned)txd.hi_dword.words.lo,
1782 (unsigned)txd.hi_dword.words.hi);
1786 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1788 const struct rte_memzone *rx_mz;
1790 if (port_id_is_invalid(port_id, ENABLED_WARN))
1792 if (rx_queue_id_is_invalid(rxq_id))
1794 if (rx_desc_id_is_invalid(rxd_id))
1796 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1799 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1803 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1805 const struct rte_memzone *tx_mz;
1807 if (port_id_is_invalid(port_id, ENABLED_WARN))
1809 if (tx_queue_id_is_invalid(txq_id))
1811 if (tx_desc_id_is_invalid(txd_id))
1813 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1816 ring_tx_descriptor_display(tx_mz, txd_id);
1820 fwd_lcores_config_display(void)
1824 printf("List of forwarding lcores:");
1825 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1826 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1830 rxtx_config_display(void)
1835 printf(" %s packet forwarding%s packets/burst=%d\n",
1836 cur_fwd_eng->fwd_mode_name,
1837 retry_enabled == 0 ? "" : " with retry",
1840 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1841 printf(" packet len=%u - nb packet segments=%d\n",
1842 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1844 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1845 nb_fwd_lcores, nb_fwd_ports);
1847 RTE_ETH_FOREACH_DEV(pid) {
1848 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
1849 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
1850 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
1851 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
1852 uint16_t nb_rx_desc_tmp;
1853 uint16_t nb_tx_desc_tmp;
1854 struct rte_eth_rxq_info rx_qinfo;
1855 struct rte_eth_txq_info tx_qinfo;
1858 /* per port config */
1859 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
1860 (unsigned int)pid, nb_rxq, nb_txq);
1862 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
1863 ports[pid].dev_conf.rxmode.offloads,
1864 ports[pid].dev_conf.txmode.offloads);
1866 /* per rx queue config only for first queue to be less verbose */
1867 for (qid = 0; qid < 1; qid++) {
1868 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
1870 nb_rx_desc_tmp = nb_rx_desc[qid];
1872 nb_rx_desc_tmp = rx_qinfo.nb_desc;
1874 printf(" RX queue: %d\n", qid);
1875 printf(" RX desc=%d - RX free threshold=%d\n",
1876 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh);
1877 printf(" RX threshold registers: pthresh=%d hthresh=%d "
1879 rx_conf[qid].rx_thresh.pthresh,
1880 rx_conf[qid].rx_thresh.hthresh,
1881 rx_conf[qid].rx_thresh.wthresh);
1882 printf(" RX Offloads=0x%"PRIx64"\n",
1883 rx_conf[qid].offloads);
1886 /* per tx queue config only for first queue to be less verbose */
1887 for (qid = 0; qid < 1; qid++) {
1888 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
1890 nb_tx_desc_tmp = nb_tx_desc[qid];
1892 nb_tx_desc_tmp = tx_qinfo.nb_desc;
1894 printf(" TX queue: %d\n", qid);
1895 printf(" TX desc=%d - TX free threshold=%d\n",
1896 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh);
1897 printf(" TX threshold registers: pthresh=%d hthresh=%d "
1899 tx_conf[qid].tx_thresh.pthresh,
1900 tx_conf[qid].tx_thresh.hthresh,
1901 tx_conf[qid].tx_thresh.wthresh);
1902 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
1903 tx_conf[qid].offloads, tx_conf->tx_rs_thresh);
1909 port_rss_reta_info(portid_t port_id,
1910 struct rte_eth_rss_reta_entry64 *reta_conf,
1911 uint16_t nb_entries)
1913 uint16_t i, idx, shift;
1916 if (port_id_is_invalid(port_id, ENABLED_WARN))
1919 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1921 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1925 for (i = 0; i < nb_entries; i++) {
1926 idx = i / RTE_RETA_GROUP_SIZE;
1927 shift = i % RTE_RETA_GROUP_SIZE;
1928 if (!(reta_conf[idx].mask & (1ULL << shift)))
1930 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1931 i, reta_conf[idx].reta[shift]);
1936 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1940 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
1942 struct rte_eth_rss_conf rss_conf = {0};
1943 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1947 struct rte_eth_dev_info dev_info;
1948 uint8_t hash_key_size;
1951 if (port_id_is_invalid(port_id, ENABLED_WARN))
1954 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1958 if (dev_info.hash_key_size > 0 &&
1959 dev_info.hash_key_size <= sizeof(rss_key))
1960 hash_key_size = dev_info.hash_key_size;
1962 printf("dev_info did not provide a valid hash key size\n");
1966 /* Get RSS hash key if asked to display it */
1967 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1968 rss_conf.rss_key_len = hash_key_size;
1969 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1973 printf("port index %d invalid\n", port_id);
1976 printf("operation not supported by device\n");
1979 printf("operation failed - diag=%d\n", diag);
1984 rss_hf = rss_conf.rss_hf;
1986 printf("RSS disabled\n");
1989 printf("RSS functions:\n ");
1990 for (i = 0; rss_type_table[i].str; i++) {
1991 if (rss_hf & rss_type_table[i].rss_type)
1992 printf("%s ", rss_type_table[i].str);
1997 printf("RSS key:\n");
1998 for (i = 0; i < hash_key_size; i++)
1999 printf("%02X", rss_key[i]);
2004 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2007 struct rte_eth_rss_conf rss_conf;
2011 rss_conf.rss_key = NULL;
2012 rss_conf.rss_key_len = hash_key_len;
2013 rss_conf.rss_hf = 0;
2014 for (i = 0; rss_type_table[i].str; i++) {
2015 if (!strcmp(rss_type_table[i].str, rss_type))
2016 rss_conf.rss_hf = rss_type_table[i].rss_type;
2018 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2020 rss_conf.rss_key = hash_key;
2021 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2028 printf("port index %d invalid\n", port_id);
2031 printf("operation not supported by device\n");
2034 printf("operation failed - diag=%d\n", diag);
2040 * Setup forwarding configuration for each logical core.
2043 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2045 streamid_t nb_fs_per_lcore;
2053 nb_fs = cfg->nb_fwd_streams;
2054 nb_fc = cfg->nb_fwd_lcores;
2055 if (nb_fs <= nb_fc) {
2056 nb_fs_per_lcore = 1;
2059 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2060 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2063 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2065 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2066 fwd_lcores[lc_id]->stream_idx = sm_id;
2067 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2068 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2072 * Assign extra remaining streams, if any.
2074 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2075 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2076 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2077 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2078 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2083 fwd_topology_tx_port_get(portid_t rxp)
2085 static int warning_once = 1;
2087 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2089 switch (port_topology) {
2091 case PORT_TOPOLOGY_PAIRED:
2092 if ((rxp & 0x1) == 0) {
2093 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2096 printf("\nWarning! port-topology=paired"
2097 " and odd forward ports number,"
2098 " the last port will pair with"
2105 case PORT_TOPOLOGY_CHAINED:
2106 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2107 case PORT_TOPOLOGY_LOOP:
2113 simple_fwd_config_setup(void)
2117 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2118 cur_fwd_config.nb_fwd_streams =
2119 (streamid_t) cur_fwd_config.nb_fwd_ports;
2121 /* reinitialize forwarding streams */
2125 * In the simple forwarding test, the number of forwarding cores
2126 * must be lower or equal to the number of forwarding ports.
2128 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2129 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2130 cur_fwd_config.nb_fwd_lcores =
2131 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2132 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2134 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2135 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2136 fwd_streams[i]->rx_queue = 0;
2137 fwd_streams[i]->tx_port =
2138 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2139 fwd_streams[i]->tx_queue = 0;
2140 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2141 fwd_streams[i]->retry_enabled = retry_enabled;
2146 * For the RSS forwarding test all streams distributed over lcores. Each stream
2147 * being composed of a RX queue to poll on a RX port for input messages,
2148 * associated with a TX queue of a TX port where to send forwarded packets.
2151 rss_fwd_config_setup(void)
2162 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2163 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2164 cur_fwd_config.nb_fwd_streams =
2165 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2167 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2168 cur_fwd_config.nb_fwd_lcores =
2169 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2171 /* reinitialize forwarding streams */
2174 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2176 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2177 struct fwd_stream *fs;
2179 fs = fwd_streams[sm_id];
2180 txp = fwd_topology_tx_port_get(rxp);
2181 fs->rx_port = fwd_ports_ids[rxp];
2183 fs->tx_port = fwd_ports_ids[txp];
2185 fs->peer_addr = fs->tx_port;
2186 fs->retry_enabled = retry_enabled;
2188 if (rxp < nb_fwd_ports)
2196 * For the DCB forwarding test, each core is assigned on each traffic class.
2198 * Each core is assigned a multi-stream, each stream being composed of
2199 * a RX queue to poll on a RX port for input messages, associated with
2200 * a TX queue of a TX port where to send forwarded packets. All RX and
2201 * TX queues are mapping to the same traffic class.
2202 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2206 dcb_fwd_config_setup(void)
2208 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2209 portid_t txp, rxp = 0;
2210 queueid_t txq, rxq = 0;
2212 uint16_t nb_rx_queue, nb_tx_queue;
2213 uint16_t i, j, k, sm_id = 0;
2216 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2217 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2218 cur_fwd_config.nb_fwd_streams =
2219 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2221 /* reinitialize forwarding streams */
2225 /* get the dcb info on the first RX and TX ports */
2226 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2227 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2229 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2230 fwd_lcores[lc_id]->stream_nb = 0;
2231 fwd_lcores[lc_id]->stream_idx = sm_id;
2232 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2233 /* if the nb_queue is zero, means this tc is
2234 * not enabled on the POOL
2236 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2238 k = fwd_lcores[lc_id]->stream_nb +
2239 fwd_lcores[lc_id]->stream_idx;
2240 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2241 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2242 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2243 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2244 for (j = 0; j < nb_rx_queue; j++) {
2245 struct fwd_stream *fs;
2247 fs = fwd_streams[k + j];
2248 fs->rx_port = fwd_ports_ids[rxp];
2249 fs->rx_queue = rxq + j;
2250 fs->tx_port = fwd_ports_ids[txp];
2251 fs->tx_queue = txq + j % nb_tx_queue;
2252 fs->peer_addr = fs->tx_port;
2253 fs->retry_enabled = retry_enabled;
2255 fwd_lcores[lc_id]->stream_nb +=
2256 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2258 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2261 if (tc < rxp_dcb_info.nb_tcs)
2263 /* Restart from TC 0 on next RX port */
2265 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2267 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2270 if (rxp >= nb_fwd_ports)
2272 /* get the dcb information on next RX and TX ports */
2273 if ((rxp & 0x1) == 0)
2274 txp = (portid_t) (rxp + 1);
2276 txp = (portid_t) (rxp - 1);
2277 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2278 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2283 icmp_echo_config_setup(void)
2290 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2291 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2292 (nb_txq * nb_fwd_ports);
2294 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2295 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2296 cur_fwd_config.nb_fwd_streams =
2297 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2298 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2299 cur_fwd_config.nb_fwd_lcores =
2300 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2301 if (verbose_level > 0) {
2302 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2304 cur_fwd_config.nb_fwd_lcores,
2305 cur_fwd_config.nb_fwd_ports,
2306 cur_fwd_config.nb_fwd_streams);
2309 /* reinitialize forwarding streams */
2311 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2313 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2314 if (verbose_level > 0)
2315 printf(" core=%d: \n", lc_id);
2316 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2317 struct fwd_stream *fs;
2318 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2319 fs->rx_port = fwd_ports_ids[rxp];
2321 fs->tx_port = fs->rx_port;
2323 fs->peer_addr = fs->tx_port;
2324 fs->retry_enabled = retry_enabled;
2325 if (verbose_level > 0)
2326 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2327 sm_id, fs->rx_port, fs->rx_queue,
2329 rxq = (queueid_t) (rxq + 1);
2330 if (rxq == nb_rxq) {
2332 rxp = (portid_t) (rxp + 1);
2338 #if defined RTE_LIBRTE_PMD_SOFTNIC
2340 softnic_fwd_config_setup(void)
2342 struct rte_port *port;
2343 portid_t pid, softnic_portid;
2345 uint8_t softnic_enable = 0;
2347 RTE_ETH_FOREACH_DEV(pid) {
2349 const char *driver = port->dev_info.driver_name;
2351 if (strcmp(driver, "net_softnic") == 0) {
2352 softnic_portid = pid;
2358 if (softnic_enable == 0) {
2359 printf("Softnic mode not configured(%s)!\n", __func__);
2363 cur_fwd_config.nb_fwd_ports = 1;
2364 cur_fwd_config.nb_fwd_streams = (streamid_t) nb_rxq;
2366 /* Re-initialize forwarding streams */
2370 * In the softnic forwarding test, the number of forwarding cores
2371 * is set to one and remaining are used for softnic packet processing.
2373 cur_fwd_config.nb_fwd_lcores = 1;
2374 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2376 for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++) {
2377 fwd_streams[i]->rx_port = softnic_portid;
2378 fwd_streams[i]->rx_queue = i;
2379 fwd_streams[i]->tx_port = softnic_portid;
2380 fwd_streams[i]->tx_queue = i;
2381 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2382 fwd_streams[i]->retry_enabled = retry_enabled;
2388 fwd_config_setup(void)
2390 cur_fwd_config.fwd_eng = cur_fwd_eng;
2391 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2392 icmp_echo_config_setup();
2396 #if defined RTE_LIBRTE_PMD_SOFTNIC
2397 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
2398 softnic_fwd_config_setup();
2403 if ((nb_rxq > 1) && (nb_txq > 1)){
2405 dcb_fwd_config_setup();
2407 rss_fwd_config_setup();
2410 simple_fwd_config_setup();
2414 mp_alloc_to_str(uint8_t mode)
2417 case MP_ALLOC_NATIVE:
2423 case MP_ALLOC_XMEM_HUGE:
2433 pkt_fwd_config_display(struct fwd_config *cfg)
2435 struct fwd_stream *fs;
2439 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2440 "NUMA support %s, MP allocation mode: %s\n",
2441 cfg->fwd_eng->fwd_mode_name,
2442 retry_enabled == 0 ? "" : " with retry",
2443 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2444 numa_support == 1 ? "enabled" : "disabled",
2445 mp_alloc_to_str(mp_alloc_type));
2448 printf("TX retry num: %u, delay between TX retries: %uus\n",
2449 burst_tx_retry_num, burst_tx_delay_time);
2450 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2451 printf("Logical Core %u (socket %u) forwards packets on "
2453 fwd_lcores_cpuids[lc_id],
2454 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2455 fwd_lcores[lc_id]->stream_nb);
2456 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2457 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2458 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2459 "P=%d/Q=%d (socket %u) ",
2460 fs->rx_port, fs->rx_queue,
2461 ports[fs->rx_port].socket_id,
2462 fs->tx_port, fs->tx_queue,
2463 ports[fs->tx_port].socket_id);
2464 print_ethaddr("peer=",
2465 &peer_eth_addrs[fs->peer_addr]);
2473 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2475 struct rte_ether_addr new_peer_addr;
2476 if (!rte_eth_dev_is_valid_port(port_id)) {
2477 printf("Error: Invalid port number %i\n", port_id);
2480 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
2481 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2484 peer_eth_addrs[port_id] = new_peer_addr;
2488 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2491 unsigned int lcore_cpuid;
2496 for (i = 0; i < nb_lc; i++) {
2497 lcore_cpuid = lcorelist[i];
2498 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2499 printf("lcore %u not enabled\n", lcore_cpuid);
2502 if (lcore_cpuid == rte_get_master_lcore()) {
2503 printf("lcore %u cannot be masked on for running "
2504 "packet forwarding, which is the master lcore "
2505 "and reserved for command line parsing only\n",
2510 fwd_lcores_cpuids[i] = lcore_cpuid;
2512 if (record_now == 0) {
2516 nb_cfg_lcores = (lcoreid_t) nb_lc;
2517 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2518 printf("previous number of forwarding cores %u - changed to "
2519 "number of configured cores %u\n",
2520 (unsigned int) nb_fwd_lcores, nb_lc);
2521 nb_fwd_lcores = (lcoreid_t) nb_lc;
2528 set_fwd_lcores_mask(uint64_t lcoremask)
2530 unsigned int lcorelist[64];
2534 if (lcoremask == 0) {
2535 printf("Invalid NULL mask of cores\n");
2539 for (i = 0; i < 64; i++) {
2540 if (! ((uint64_t)(1ULL << i) & lcoremask))
2542 lcorelist[nb_lc++] = i;
2544 return set_fwd_lcores_list(lcorelist, nb_lc);
2548 set_fwd_lcores_number(uint16_t nb_lc)
2550 if (nb_lc > nb_cfg_lcores) {
2551 printf("nb fwd cores %u > %u (max. number of configured "
2552 "lcores) - ignored\n",
2553 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2556 nb_fwd_lcores = (lcoreid_t) nb_lc;
2557 printf("Number of forwarding cores set to %u\n",
2558 (unsigned int) nb_fwd_lcores);
2562 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2570 for (i = 0; i < nb_pt; i++) {
2571 port_id = (portid_t) portlist[i];
2572 if (port_id_is_invalid(port_id, ENABLED_WARN))
2575 fwd_ports_ids[i] = port_id;
2577 if (record_now == 0) {
2581 nb_cfg_ports = (portid_t) nb_pt;
2582 if (nb_fwd_ports != (portid_t) nb_pt) {
2583 printf("previous number of forwarding ports %u - changed to "
2584 "number of configured ports %u\n",
2585 (unsigned int) nb_fwd_ports, nb_pt);
2586 nb_fwd_ports = (portid_t) nb_pt;
2591 set_fwd_ports_mask(uint64_t portmask)
2593 unsigned int portlist[64];
2597 if (portmask == 0) {
2598 printf("Invalid NULL mask of ports\n");
2602 RTE_ETH_FOREACH_DEV(i) {
2603 if (! ((uint64_t)(1ULL << i) & portmask))
2605 portlist[nb_pt++] = i;
2607 set_fwd_ports_list(portlist, nb_pt);
2611 set_fwd_ports_number(uint16_t nb_pt)
2613 if (nb_pt > nb_cfg_ports) {
2614 printf("nb fwd ports %u > %u (number of configured "
2615 "ports) - ignored\n",
2616 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2619 nb_fwd_ports = (portid_t) nb_pt;
2620 printf("Number of forwarding ports set to %u\n",
2621 (unsigned int) nb_fwd_ports);
2625 port_is_forwarding(portid_t port_id)
2629 if (port_id_is_invalid(port_id, ENABLED_WARN))
2632 for (i = 0; i < nb_fwd_ports; i++) {
2633 if (fwd_ports_ids[i] == port_id)
2641 set_nb_pkt_per_burst(uint16_t nb)
2643 if (nb > MAX_PKT_BURST) {
2644 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2646 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2649 nb_pkt_per_burst = nb;
2650 printf("Number of packets per burst set to %u\n",
2651 (unsigned int) nb_pkt_per_burst);
2655 tx_split_get_name(enum tx_pkt_split split)
2659 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2660 if (tx_split_name[i].split == split)
2661 return tx_split_name[i].name;
2667 set_tx_pkt_split(const char *name)
2671 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2672 if (strcmp(tx_split_name[i].name, name) == 0) {
2673 tx_pkt_split = tx_split_name[i].split;
2677 printf("unknown value: \"%s\"\n", name);
2681 show_tx_pkt_segments(void)
2687 split = tx_split_get_name(tx_pkt_split);
2689 printf("Number of segments: %u\n", n);
2690 printf("Segment sizes: ");
2691 for (i = 0; i != n - 1; i++)
2692 printf("%hu,", tx_pkt_seg_lengths[i]);
2693 printf("%hu\n", tx_pkt_seg_lengths[i]);
2694 printf("Split packet: %s\n", split);
2698 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2700 uint16_t tx_pkt_len;
2703 if (nb_segs >= (unsigned) nb_txd) {
2704 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2705 nb_segs, (unsigned int) nb_txd);
2710 * Check that each segment length is greater or equal than
2711 * the mbuf data sise.
2712 * Check also that the total packet length is greater or equal than the
2713 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
2717 for (i = 0; i < nb_segs; i++) {
2718 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2719 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2720 i, seg_lengths[i], (unsigned) mbuf_data_size);
2723 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2725 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
2726 printf("total packet length=%u < %d - give up\n",
2727 (unsigned) tx_pkt_len,
2728 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
2732 for (i = 0; i < nb_segs; i++)
2733 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2735 tx_pkt_length = tx_pkt_len;
2736 tx_pkt_nb_segs = (uint8_t) nb_segs;
2740 setup_gro(const char *onoff, portid_t port_id)
2742 if (!rte_eth_dev_is_valid_port(port_id)) {
2743 printf("invalid port id %u\n", port_id);
2746 if (test_done == 0) {
2747 printf("Before enable/disable GRO,"
2748 " please stop forwarding first\n");
2751 if (strcmp(onoff, "on") == 0) {
2752 if (gro_ports[port_id].enable != 0) {
2753 printf("Port %u has enabled GRO. Please"
2754 " disable GRO first\n", port_id);
2757 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2758 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2759 gro_ports[port_id].param.max_flow_num =
2760 GRO_DEFAULT_FLOW_NUM;
2761 gro_ports[port_id].param.max_item_per_flow =
2762 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2764 gro_ports[port_id].enable = 1;
2766 if (gro_ports[port_id].enable == 0) {
2767 printf("Port %u has disabled GRO\n", port_id);
2770 gro_ports[port_id].enable = 0;
2775 setup_gro_flush_cycles(uint8_t cycles)
2777 if (test_done == 0) {
2778 printf("Before change flush interval for GRO,"
2779 " please stop forwarding first.\n");
2783 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
2784 GRO_DEFAULT_FLUSH_CYCLES) {
2785 printf("The flushing cycle be in the range"
2786 " of 1 to %u. Revert to the default"
2788 GRO_MAX_FLUSH_CYCLES,
2789 GRO_DEFAULT_FLUSH_CYCLES);
2790 cycles = GRO_DEFAULT_FLUSH_CYCLES;
2793 gro_flush_cycles = cycles;
2797 show_gro(portid_t port_id)
2799 struct rte_gro_param *param;
2800 uint32_t max_pkts_num;
2802 param = &gro_ports[port_id].param;
2804 if (!rte_eth_dev_is_valid_port(port_id)) {
2805 printf("Invalid port id %u.\n", port_id);
2808 if (gro_ports[port_id].enable) {
2809 printf("GRO type: TCP/IPv4\n");
2810 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2811 max_pkts_num = param->max_flow_num *
2812 param->max_item_per_flow;
2814 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
2815 printf("Max number of packets to perform GRO: %u\n",
2817 printf("Flushing cycles: %u\n", gro_flush_cycles);
2819 printf("Port %u doesn't enable GRO.\n", port_id);
2823 setup_gso(const char *mode, portid_t port_id)
2825 if (!rte_eth_dev_is_valid_port(port_id)) {
2826 printf("invalid port id %u\n", port_id);
2829 if (strcmp(mode, "on") == 0) {
2830 if (test_done == 0) {
2831 printf("before enabling GSO,"
2832 " please stop forwarding first\n");
2835 gso_ports[port_id].enable = 1;
2836 } else if (strcmp(mode, "off") == 0) {
2837 if (test_done == 0) {
2838 printf("before disabling GSO,"
2839 " please stop forwarding first\n");
2842 gso_ports[port_id].enable = 0;
2847 list_pkt_forwarding_modes(void)
2849 static char fwd_modes[128] = "";
2850 const char *separator = "|";
2851 struct fwd_engine *fwd_eng;
2854 if (strlen (fwd_modes) == 0) {
2855 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2856 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2857 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2858 strncat(fwd_modes, separator,
2859 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2861 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2868 list_pkt_forwarding_retry_modes(void)
2870 static char fwd_modes[128] = "";
2871 const char *separator = "|";
2872 struct fwd_engine *fwd_eng;
2875 if (strlen(fwd_modes) == 0) {
2876 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2877 if (fwd_eng == &rx_only_engine)
2879 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2881 strlen(fwd_modes) - 1);
2882 strncat(fwd_modes, separator,
2884 strlen(fwd_modes) - 1);
2886 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2893 set_pkt_forwarding_mode(const char *fwd_mode_name)
2895 struct fwd_engine *fwd_eng;
2899 while ((fwd_eng = fwd_engines[i]) != NULL) {
2900 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2901 printf("Set %s packet forwarding mode%s\n",
2903 retry_enabled == 0 ? "" : " with retry");
2904 cur_fwd_eng = fwd_eng;
2909 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2913 add_rx_dump_callbacks(portid_t portid)
2915 struct rte_eth_dev_info dev_info;
2919 if (port_id_is_invalid(portid, ENABLED_WARN))
2922 ret = eth_dev_info_get_print_err(portid, &dev_info);
2926 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
2927 if (!ports[portid].rx_dump_cb[queue])
2928 ports[portid].rx_dump_cb[queue] =
2929 rte_eth_add_rx_callback(portid, queue,
2930 dump_rx_pkts, NULL);
2934 add_tx_dump_callbacks(portid_t portid)
2936 struct rte_eth_dev_info dev_info;
2940 if (port_id_is_invalid(portid, ENABLED_WARN))
2943 ret = eth_dev_info_get_print_err(portid, &dev_info);
2947 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
2948 if (!ports[portid].tx_dump_cb[queue])
2949 ports[portid].tx_dump_cb[queue] =
2950 rte_eth_add_tx_callback(portid, queue,
2951 dump_tx_pkts, NULL);
2955 remove_rx_dump_callbacks(portid_t portid)
2957 struct rte_eth_dev_info dev_info;
2961 if (port_id_is_invalid(portid, ENABLED_WARN))
2964 ret = eth_dev_info_get_print_err(portid, &dev_info);
2968 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
2969 if (ports[portid].rx_dump_cb[queue]) {
2970 rte_eth_remove_rx_callback(portid, queue,
2971 ports[portid].rx_dump_cb[queue]);
2972 ports[portid].rx_dump_cb[queue] = NULL;
2977 remove_tx_dump_callbacks(portid_t portid)
2979 struct rte_eth_dev_info dev_info;
2983 if (port_id_is_invalid(portid, ENABLED_WARN))
2986 ret = eth_dev_info_get_print_err(portid, &dev_info);
2990 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
2991 if (ports[portid].tx_dump_cb[queue]) {
2992 rte_eth_remove_tx_callback(portid, queue,
2993 ports[portid].tx_dump_cb[queue]);
2994 ports[portid].tx_dump_cb[queue] = NULL;
2999 configure_rxtx_dump_callbacks(uint16_t verbose)
3003 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3004 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
3008 RTE_ETH_FOREACH_DEV(portid)
3010 if (verbose == 1 || verbose > 2)
3011 add_rx_dump_callbacks(portid);
3013 remove_rx_dump_callbacks(portid);
3015 add_tx_dump_callbacks(portid);
3017 remove_tx_dump_callbacks(portid);
3022 set_verbose_level(uint16_t vb_level)
3024 printf("Change verbose level from %u to %u\n",
3025 (unsigned int) verbose_level, (unsigned int) vb_level);
3026 verbose_level = vb_level;
3027 configure_rxtx_dump_callbacks(verbose_level);
3031 vlan_extend_set(portid_t port_id, int on)
3035 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3037 if (port_id_is_invalid(port_id, ENABLED_WARN))
3040 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3043 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
3044 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3046 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
3047 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3050 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3052 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
3053 "diag=%d\n", port_id, on, diag);
3054 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3058 rx_vlan_strip_set(portid_t port_id, int on)
3062 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3064 if (port_id_is_invalid(port_id, ENABLED_WARN))
3067 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3070 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
3071 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3073 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
3074 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3077 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3079 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
3080 "diag=%d\n", port_id, on, diag);
3081 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3085 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
3089 if (port_id_is_invalid(port_id, ENABLED_WARN))
3092 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
3094 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
3095 "diag=%d\n", port_id, queue_id, on, diag);
3099 rx_vlan_filter_set(portid_t port_id, int on)
3103 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3105 if (port_id_is_invalid(port_id, ENABLED_WARN))
3108 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3111 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
3112 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3114 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
3115 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3118 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3120 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
3121 "diag=%d\n", port_id, on, diag);
3122 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3126 rx_vlan_qinq_strip_set(portid_t port_id, int on)
3130 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3132 if (port_id_is_invalid(port_id, ENABLED_WARN))
3135 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3138 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
3139 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3141 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
3142 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3145 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3147 printf("%s(port_pi=%d, on=%d) failed "
3148 "diag=%d\n", __func__, port_id, on, diag);
3149 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3153 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
3157 if (port_id_is_invalid(port_id, ENABLED_WARN))
3159 if (vlan_id_is_invalid(vlan_id))
3161 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
3164 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
3166 port_id, vlan_id, on, diag);
3171 rx_vlan_all_filter_set(portid_t port_id, int on)
3175 if (port_id_is_invalid(port_id, ENABLED_WARN))
3177 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
3178 if (rx_vft_set(port_id, vlan_id, on))
3184 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
3188 if (port_id_is_invalid(port_id, ENABLED_WARN))
3191 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
3195 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
3197 port_id, vlan_type, tp_id, diag);
3201 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
3203 struct rte_eth_dev_info dev_info;
3206 if (port_id_is_invalid(port_id, ENABLED_WARN))
3208 if (vlan_id_is_invalid(vlan_id))
3211 if (ports[port_id].dev_conf.txmode.offloads &
3212 DEV_TX_OFFLOAD_QINQ_INSERT) {
3213 printf("Error, as QinQ has been enabled.\n");
3217 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3221 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
3222 printf("Error: vlan insert is not supported by port %d\n",
3227 tx_vlan_reset(port_id);
3228 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
3229 ports[port_id].tx_vlan_id = vlan_id;
3233 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
3235 struct rte_eth_dev_info dev_info;
3238 if (port_id_is_invalid(port_id, ENABLED_WARN))
3240 if (vlan_id_is_invalid(vlan_id))
3242 if (vlan_id_is_invalid(vlan_id_outer))
3245 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3249 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
3250 printf("Error: qinq insert not supported by port %d\n",
3255 tx_vlan_reset(port_id);
3256 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
3257 DEV_TX_OFFLOAD_QINQ_INSERT);
3258 ports[port_id].tx_vlan_id = vlan_id;
3259 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
3263 tx_vlan_reset(portid_t port_id)
3265 if (port_id_is_invalid(port_id, ENABLED_WARN))
3267 ports[port_id].dev_conf.txmode.offloads &=
3268 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
3269 DEV_TX_OFFLOAD_QINQ_INSERT);
3270 ports[port_id].tx_vlan_id = 0;
3271 ports[port_id].tx_vlan_id_outer = 0;
3275 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
3277 if (port_id_is_invalid(port_id, ENABLED_WARN))
3280 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
3284 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
3287 uint8_t existing_mapping_found = 0;
3289 if (port_id_is_invalid(port_id, ENABLED_WARN))
3292 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
3295 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
3296 printf("map_value not in required range 0..%d\n",
3297 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
3301 if (!is_rx) { /*then tx*/
3302 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3303 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3304 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
3305 tx_queue_stats_mappings[i].stats_counter_id = map_value;
3306 existing_mapping_found = 1;
3310 if (!existing_mapping_found) { /* A new additional mapping... */
3311 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
3312 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
3313 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
3314 nb_tx_queue_stats_mappings++;
3318 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3319 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3320 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
3321 rx_queue_stats_mappings[i].stats_counter_id = map_value;
3322 existing_mapping_found = 1;
3326 if (!existing_mapping_found) { /* A new additional mapping... */
3327 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
3328 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
3329 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
3330 nb_rx_queue_stats_mappings++;
3336 set_xstats_hide_zero(uint8_t on_off)
3338 xstats_hide_zero = on_off;
3342 print_fdir_mask(struct rte_eth_fdir_masks *mask)
3344 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
3346 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3347 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
3348 " tunnel_id: 0x%08x",
3349 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
3350 rte_be_to_cpu_32(mask->tunnel_id_mask));
3351 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3352 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
3353 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
3354 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
3356 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
3357 rte_be_to_cpu_16(mask->src_port_mask),
3358 rte_be_to_cpu_16(mask->dst_port_mask));
3360 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3361 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
3362 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3363 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3364 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3366 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3367 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3368 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3369 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3370 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3377 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3379 struct rte_eth_flex_payload_cfg *cfg;
3382 for (i = 0; i < flex_conf->nb_payloads; i++) {
3383 cfg = &flex_conf->flex_set[i];
3384 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3386 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3387 printf("\n L2_PAYLOAD: ");
3388 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3389 printf("\n L3_PAYLOAD: ");
3390 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3391 printf("\n L4_PAYLOAD: ");
3393 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3394 for (j = 0; j < num; j++)
3395 printf(" %-5u", cfg->src_offset[j]);
3401 flowtype_to_str(uint16_t flow_type)
3403 struct flow_type_info {
3409 static struct flow_type_info flowtype_str_table[] = {
3410 {"raw", RTE_ETH_FLOW_RAW},
3411 {"ipv4", RTE_ETH_FLOW_IPV4},
3412 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3413 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3414 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3415 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3416 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3417 {"ipv6", RTE_ETH_FLOW_IPV6},
3418 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3419 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3420 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3421 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3422 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3423 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3424 {"port", RTE_ETH_FLOW_PORT},
3425 {"vxlan", RTE_ETH_FLOW_VXLAN},
3426 {"geneve", RTE_ETH_FLOW_GENEVE},
3427 {"nvgre", RTE_ETH_FLOW_NVGRE},
3428 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
3431 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3432 if (flowtype_str_table[i].ftype == flow_type)
3433 return flowtype_str_table[i].str;
3440 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3442 struct rte_eth_fdir_flex_mask *mask;
3446 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3447 mask = &flex_conf->flex_mask[i];
3448 p = flowtype_to_str(mask->flow_type);
3449 printf("\n %s:\t", p ? p : "unknown");
3450 for (j = 0; j < num; j++)
3451 printf(" %02x", mask->mask[j]);
3457 print_fdir_flow_type(uint32_t flow_types_mask)
3462 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3463 if (!(flow_types_mask & (1 << i)))
3465 p = flowtype_to_str(i);
3475 fdir_get_infos(portid_t port_id)
3477 struct rte_eth_fdir_stats fdir_stat;
3478 struct rte_eth_fdir_info fdir_info;
3481 static const char *fdir_stats_border = "########################";
3483 if (port_id_is_invalid(port_id, ENABLED_WARN))
3485 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3487 printf("\n FDIR is not supported on port %-2d\n",
3492 memset(&fdir_info, 0, sizeof(fdir_info));
3493 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3494 RTE_ETH_FILTER_INFO, &fdir_info);
3495 memset(&fdir_stat, 0, sizeof(fdir_stat));
3496 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3497 RTE_ETH_FILTER_STATS, &fdir_stat);
3498 printf("\n %s FDIR infos for port %-2d %s\n",
3499 fdir_stats_border, port_id, fdir_stats_border);
3501 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3502 printf(" PERFECT\n");
3503 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3504 printf(" PERFECT-MAC-VLAN\n");
3505 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3506 printf(" PERFECT-TUNNEL\n");
3507 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3508 printf(" SIGNATURE\n");
3510 printf(" DISABLE\n");
3511 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3512 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3513 printf(" SUPPORTED FLOW TYPE: ");
3514 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3516 printf(" FLEX PAYLOAD INFO:\n");
3517 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3518 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3519 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3520 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3521 fdir_info.flex_payload_unit,
3522 fdir_info.max_flex_payload_segment_num,
3523 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3525 print_fdir_mask(&fdir_info.mask);
3526 if (fdir_info.flex_conf.nb_payloads > 0) {
3527 printf(" FLEX PAYLOAD SRC OFFSET:");
3528 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3530 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3531 printf(" FLEX MASK CFG:");
3532 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3534 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3535 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3536 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3537 fdir_info.guarant_spc, fdir_info.best_spc);
3538 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3539 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3540 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3541 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3542 fdir_stat.collision, fdir_stat.free,
3543 fdir_stat.maxhash, fdir_stat.maxlen,
3544 fdir_stat.add, fdir_stat.remove,
3545 fdir_stat.f_add, fdir_stat.f_remove);
3546 printf(" %s############################%s\n",
3547 fdir_stats_border, fdir_stats_border);
3551 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3553 struct rte_port *port;
3554 struct rte_eth_fdir_flex_conf *flex_conf;
3557 port = &ports[port_id];
3558 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3559 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3560 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3565 if (i >= RTE_ETH_FLOW_MAX) {
3566 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3567 idx = flex_conf->nb_flexmasks;
3568 flex_conf->nb_flexmasks++;
3570 printf("The flex mask table is full. Can not set flex"
3571 " mask for flow_type(%u).", cfg->flow_type);
3575 rte_memcpy(&flex_conf->flex_mask[idx],
3577 sizeof(struct rte_eth_fdir_flex_mask));
3581 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3583 struct rte_port *port;
3584 struct rte_eth_fdir_flex_conf *flex_conf;
3587 port = &ports[port_id];
3588 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3589 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3590 if (cfg->type == flex_conf->flex_set[i].type) {
3595 if (i >= RTE_ETH_PAYLOAD_MAX) {
3596 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3597 idx = flex_conf->nb_payloads;
3598 flex_conf->nb_payloads++;
3600 printf("The flex payload table is full. Can not set"
3601 " flex payload for type(%u).", cfg->type);
3605 rte_memcpy(&flex_conf->flex_set[idx],
3607 sizeof(struct rte_eth_flex_payload_cfg));
3612 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3614 #ifdef RTE_LIBRTE_IXGBE_PMD
3618 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3620 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3624 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3625 is_rx ? "rx" : "tx", port_id, diag);
3628 printf("VF %s setting not supported for port %d\n",
3629 is_rx ? "Rx" : "Tx", port_id);
3635 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3638 struct rte_eth_link link;
3641 if (port_id_is_invalid(port_id, ENABLED_WARN))
3643 ret = eth_link_get_nowait_print_err(port_id, &link);
3646 if (rate > link.link_speed) {
3647 printf("Invalid rate value:%u bigger than link speed: %u\n",
3648 rate, link.link_speed);
3651 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3654 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3660 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3662 int diag = -ENOTSUP;
3666 RTE_SET_USED(q_msk);
3668 #ifdef RTE_LIBRTE_IXGBE_PMD
3669 if (diag == -ENOTSUP)
3670 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3673 #ifdef RTE_LIBRTE_BNXT_PMD
3674 if (diag == -ENOTSUP)
3675 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3680 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3686 * Functions to manage the set of filtered Multicast MAC addresses.
3688 * A pool of filtered multicast MAC addresses is associated with each port.
3689 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3690 * The address of the pool and the number of valid multicast MAC addresses
3691 * recorded in the pool are stored in the fields "mc_addr_pool" and
3692 * "mc_addr_nb" of the "rte_port" data structure.
3694 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3695 * to be supplied a contiguous array of multicast MAC addresses.
3696 * To comply with this constraint, the set of multicast addresses recorded
3697 * into the pool are systematically compacted at the beginning of the pool.
3698 * Hence, when a multicast address is removed from the pool, all following
3699 * addresses, if any, are copied back to keep the set contiguous.
3701 #define MCAST_POOL_INC 32
3704 mcast_addr_pool_extend(struct rte_port *port)
3706 struct rte_ether_addr *mc_pool;
3707 size_t mc_pool_size;
3710 * If a free entry is available at the end of the pool, just
3711 * increment the number of recorded multicast addresses.
3713 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3719 * [re]allocate a pool with MCAST_POOL_INC more entries.
3720 * The previous test guarantees that port->mc_addr_nb is a multiple
3721 * of MCAST_POOL_INC.
3723 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
3725 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
3727 if (mc_pool == NULL) {
3728 printf("allocation of pool of %u multicast addresses failed\n",
3729 port->mc_addr_nb + MCAST_POOL_INC);
3733 port->mc_addr_pool = mc_pool;
3740 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
3742 if (mcast_addr_pool_extend(port) != 0)
3744 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
3748 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3751 if (addr_idx == port->mc_addr_nb) {
3752 /* No need to recompact the set of multicast addressses. */
3753 if (port->mc_addr_nb == 0) {
3754 /* free the pool of multicast addresses. */
3755 free(port->mc_addr_pool);
3756 port->mc_addr_pool = NULL;
3760 memmove(&port->mc_addr_pool[addr_idx],
3761 &port->mc_addr_pool[addr_idx + 1],
3762 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
3766 eth_port_multicast_addr_list_set(portid_t port_id)
3768 struct rte_port *port;
3771 port = &ports[port_id];
3772 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3775 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3776 port_id, port->mc_addr_nb, diag);
3782 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
3784 struct rte_port *port;
3787 if (port_id_is_invalid(port_id, ENABLED_WARN))
3790 port = &ports[port_id];
3793 * Check that the added multicast MAC address is not already recorded
3794 * in the pool of multicast addresses.
3796 for (i = 0; i < port->mc_addr_nb; i++) {
3797 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3798 printf("multicast address already filtered by port\n");
3803 mcast_addr_pool_append(port, mc_addr);
3804 if (eth_port_multicast_addr_list_set(port_id) < 0)
3805 /* Rollback on failure, remove the address from the pool */
3806 mcast_addr_pool_remove(port, i);
3810 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
3812 struct rte_port *port;
3815 if (port_id_is_invalid(port_id, ENABLED_WARN))
3818 port = &ports[port_id];
3821 * Search the pool of multicast MAC addresses for the removed address.
3823 for (i = 0; i < port->mc_addr_nb; i++) {
3824 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3827 if (i == port->mc_addr_nb) {
3828 printf("multicast address not filtered by port %d\n", port_id);
3832 mcast_addr_pool_remove(port, i);
3833 if (eth_port_multicast_addr_list_set(port_id) < 0)
3834 /* Rollback on failure, add the address back into the pool */
3835 mcast_addr_pool_append(port, mc_addr);
3839 port_dcb_info_display(portid_t port_id)
3841 struct rte_eth_dcb_info dcb_info;
3844 static const char *border = "================";
3846 if (port_id_is_invalid(port_id, ENABLED_WARN))
3849 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3851 printf("\n Failed to get dcb infos on port %-2d\n",
3855 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3856 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3858 for (i = 0; i < dcb_info.nb_tcs; i++)
3860 printf("\n Priority : ");
3861 for (i = 0; i < dcb_info.nb_tcs; i++)
3862 printf("\t%4d", dcb_info.prio_tc[i]);
3863 printf("\n BW percent :");
3864 for (i = 0; i < dcb_info.nb_tcs; i++)
3865 printf("\t%4d%%", dcb_info.tc_bws[i]);
3866 printf("\n RXQ base : ");
3867 for (i = 0; i < dcb_info.nb_tcs; i++)
3868 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3869 printf("\n RXQ number :");
3870 for (i = 0; i < dcb_info.nb_tcs; i++)
3871 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3872 printf("\n TXQ base : ");
3873 for (i = 0; i < dcb_info.nb_tcs; i++)
3874 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3875 printf("\n TXQ number :");
3876 for (i = 0; i < dcb_info.nb_tcs; i++)
3877 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3882 open_file(const char *file_path, uint32_t *size)
3884 int fd = open(file_path, O_RDONLY);
3886 uint8_t *buf = NULL;
3894 printf("%s: Failed to open %s\n", __func__, file_path);
3898 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
3900 printf("%s: File operations failed\n", __func__);
3904 pkg_size = st_buf.st_size;
3907 printf("%s: File operations failed\n", __func__);
3911 buf = (uint8_t *)malloc(pkg_size);
3914 printf("%s: Failed to malloc memory\n", __func__);
3918 ret = read(fd, buf, pkg_size);
3921 printf("%s: File read operation failed\n", __func__);
3935 save_file(const char *file_path, uint8_t *buf, uint32_t size)
3937 FILE *fh = fopen(file_path, "wb");
3940 printf("%s: Failed to open %s\n", __func__, file_path);
3944 if (fwrite(buf, 1, size, fh) != size) {
3946 printf("%s: File write operation failed\n", __func__);
3956 close_file(uint8_t *buf)
3967 port_queue_region_info_display(portid_t port_id, void *buf)
3969 #ifdef RTE_LIBRTE_I40E_PMD
3971 struct rte_pmd_i40e_queue_regions *info =
3972 (struct rte_pmd_i40e_queue_regions *)buf;
3973 static const char *queue_region_info_stats_border = "-------";
3975 if (!info->queue_region_number)
3976 printf("there is no region has been set before");
3978 printf("\n %s All queue region info for port=%2d %s",
3979 queue_region_info_stats_border, port_id,
3980 queue_region_info_stats_border);
3981 printf("\n queue_region_number: %-14u \n",
3982 info->queue_region_number);
3984 for (i = 0; i < info->queue_region_number; i++) {
3985 printf("\n region_id: %-14u queue_number: %-14u "
3986 "queue_start_index: %-14u \n",
3987 info->region[i].region_id,
3988 info->region[i].queue_num,
3989 info->region[i].queue_start_index);
3991 printf(" user_priority_num is %-14u :",
3992 info->region[i].user_priority_num);
3993 for (j = 0; j < info->region[i].user_priority_num; j++)
3994 printf(" %-14u ", info->region[i].user_priority[j]);
3996 printf("\n flowtype_num is %-14u :",
3997 info->region[i].flowtype_num);
3998 for (j = 0; j < info->region[i].flowtype_num; j++)
3999 printf(" %-14u ", info->region[i].hw_flowtype[j]);
4002 RTE_SET_USED(port_id);
4010 show_macs(portid_t port_id)
4012 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4013 struct rte_eth_dev_info dev_info;
4014 struct rte_ether_addr *addr;
4015 uint32_t i, num_macs = 0;
4016 struct rte_eth_dev *dev;
4018 dev = &rte_eth_devices[port_id];
4020 rte_eth_dev_info_get(port_id, &dev_info);
4022 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4023 addr = &dev->data->mac_addrs[i];
4025 /* skip zero address */
4026 if (rte_is_zero_ether_addr(addr))
4032 printf("Number of MAC address added: %d\n", num_macs);
4034 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4035 addr = &dev->data->mac_addrs[i];
4037 /* skip zero address */
4038 if (rte_is_zero_ether_addr(addr))
4041 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4042 printf(" %s\n", buf);
4047 show_mcast_macs(portid_t port_id)
4049 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4050 struct rte_ether_addr *addr;
4051 struct rte_port *port;
4054 port = &ports[port_id];
4056 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
4058 for (i = 0; i < port->mc_addr_nb; i++) {
4059 addr = &port->mc_addr_pool[i];
4061 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4062 printf(" %s\n", buf);