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("Caught error type %d (%s): %s%s: %s\n",
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 /** Query a flow rule. */
1446 port_flow_query(portid_t port_id, uint32_t rule,
1447 const struct rte_flow_action *action)
1449 struct rte_flow_error error;
1450 struct rte_port *port;
1451 struct port_flow *pf;
1454 struct rte_flow_query_count count;
1458 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1459 port_id == (portid_t)RTE_PORT_ALL)
1461 port = &ports[port_id];
1462 for (pf = port->flow_list; pf; pf = pf->next)
1466 printf("Flow rule #%u not found\n", rule);
1469 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1470 &name, sizeof(name),
1471 (void *)(uintptr_t)action->type, &error);
1473 return port_flow_complain(&error);
1474 switch (action->type) {
1475 case RTE_FLOW_ACTION_TYPE_COUNT:
1478 printf("Cannot query action type %d (%s)\n",
1479 action->type, name);
1482 /* Poisoning to make sure PMDs update it in case of error. */
1483 memset(&error, 0x55, sizeof(error));
1484 memset(&query, 0, sizeof(query));
1485 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1486 return port_flow_complain(&error);
1487 switch (action->type) {
1488 case RTE_FLOW_ACTION_TYPE_COUNT:
1492 " hits: %" PRIu64 "\n"
1493 " bytes: %" PRIu64 "\n",
1495 query.count.hits_set,
1496 query.count.bytes_set,
1501 printf("Cannot display result for action type %d (%s)\n",
1502 action->type, name);
1508 /** List flow rules. */
1510 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1512 struct rte_port *port;
1513 struct port_flow *pf;
1514 struct port_flow *list = NULL;
1517 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1518 port_id == (portid_t)RTE_PORT_ALL)
1520 port = &ports[port_id];
1521 if (!port->flow_list)
1523 /* Sort flows by group, priority and ID. */
1524 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1525 struct port_flow **tmp;
1526 const struct rte_flow_attr *curr = pf->rule.attr;
1529 /* Filter out unwanted groups. */
1530 for (i = 0; i != n; ++i)
1531 if (curr->group == group[i])
1536 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
1537 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
1539 if (curr->group > comp->group ||
1540 (curr->group == comp->group &&
1541 curr->priority > comp->priority) ||
1542 (curr->group == comp->group &&
1543 curr->priority == comp->priority &&
1544 pf->id > (*tmp)->id))
1551 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1552 for (pf = list; pf != NULL; pf = pf->tmp) {
1553 const struct rte_flow_item *item = pf->rule.pattern;
1554 const struct rte_flow_action *action = pf->rule.actions;
1557 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
1559 pf->rule.attr->group,
1560 pf->rule.attr->priority,
1561 pf->rule.attr->ingress ? 'i' : '-',
1562 pf->rule.attr->egress ? 'e' : '-',
1563 pf->rule.attr->transfer ? 't' : '-');
1564 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1565 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
1566 &name, sizeof(name),
1567 (void *)(uintptr_t)item->type,
1570 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1571 printf("%s ", name);
1575 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1576 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1577 &name, sizeof(name),
1578 (void *)(uintptr_t)action->type,
1581 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1582 printf(" %s", name);
1589 /** Restrict ingress traffic to the defined flow rules. */
1591 port_flow_isolate(portid_t port_id, int set)
1593 struct rte_flow_error error;
1595 /* Poisoning to make sure PMDs update it in case of error. */
1596 memset(&error, 0x66, sizeof(error));
1597 if (rte_flow_isolate(port_id, set, &error))
1598 return port_flow_complain(&error);
1599 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1601 set ? "now restricted" : "not restricted anymore");
1606 * RX/TX ring descriptors display functions.
1609 rx_queue_id_is_invalid(queueid_t rxq_id)
1611 if (rxq_id < nb_rxq)
1613 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1618 tx_queue_id_is_invalid(queueid_t txq_id)
1620 if (txq_id < nb_txq)
1622 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1627 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1629 if (rxdesc_id < nb_rxd)
1631 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1637 tx_desc_id_is_invalid(uint16_t txdesc_id)
1639 if (txdesc_id < nb_txd)
1641 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1646 static const struct rte_memzone *
1647 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1649 char mz_name[RTE_MEMZONE_NAMESIZE];
1650 const struct rte_memzone *mz;
1652 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
1653 port_id, q_id, ring_name);
1654 mz = rte_memzone_lookup(mz_name);
1656 printf("%s ring memory zoneof (port %d, queue %d) not"
1657 "found (zone name = %s\n",
1658 ring_name, port_id, q_id, mz_name);
1662 union igb_ring_dword {
1665 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1675 struct igb_ring_desc_32_bytes {
1676 union igb_ring_dword lo_dword;
1677 union igb_ring_dword hi_dword;
1678 union igb_ring_dword resv1;
1679 union igb_ring_dword resv2;
1682 struct igb_ring_desc_16_bytes {
1683 union igb_ring_dword lo_dword;
1684 union igb_ring_dword hi_dword;
1688 ring_rxd_display_dword(union igb_ring_dword dword)
1690 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1691 (unsigned)dword.words.hi);
1695 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1696 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1699 __rte_unused portid_t port_id,
1703 struct igb_ring_desc_16_bytes *ring =
1704 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1705 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1707 struct rte_eth_dev_info dev_info;
1709 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1713 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1714 /* 32 bytes RX descriptor, i40e only */
1715 struct igb_ring_desc_32_bytes *ring =
1716 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1717 ring[desc_id].lo_dword.dword =
1718 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1719 ring_rxd_display_dword(ring[desc_id].lo_dword);
1720 ring[desc_id].hi_dword.dword =
1721 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1722 ring_rxd_display_dword(ring[desc_id].hi_dword);
1723 ring[desc_id].resv1.dword =
1724 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1725 ring_rxd_display_dword(ring[desc_id].resv1);
1726 ring[desc_id].resv2.dword =
1727 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1728 ring_rxd_display_dword(ring[desc_id].resv2);
1733 /* 16 bytes RX descriptor */
1734 ring[desc_id].lo_dword.dword =
1735 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1736 ring_rxd_display_dword(ring[desc_id].lo_dword);
1737 ring[desc_id].hi_dword.dword =
1738 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1739 ring_rxd_display_dword(ring[desc_id].hi_dword);
1743 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1745 struct igb_ring_desc_16_bytes *ring;
1746 struct igb_ring_desc_16_bytes txd;
1748 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1749 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1750 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1751 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1752 (unsigned)txd.lo_dword.words.lo,
1753 (unsigned)txd.lo_dword.words.hi,
1754 (unsigned)txd.hi_dword.words.lo,
1755 (unsigned)txd.hi_dword.words.hi);
1759 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1761 const struct rte_memzone *rx_mz;
1763 if (port_id_is_invalid(port_id, ENABLED_WARN))
1765 if (rx_queue_id_is_invalid(rxq_id))
1767 if (rx_desc_id_is_invalid(rxd_id))
1769 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1772 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1776 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1778 const struct rte_memzone *tx_mz;
1780 if (port_id_is_invalid(port_id, ENABLED_WARN))
1782 if (tx_queue_id_is_invalid(txq_id))
1784 if (tx_desc_id_is_invalid(txd_id))
1786 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1789 ring_tx_descriptor_display(tx_mz, txd_id);
1793 fwd_lcores_config_display(void)
1797 printf("List of forwarding lcores:");
1798 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1799 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1803 rxtx_config_display(void)
1808 printf(" %s packet forwarding%s packets/burst=%d\n",
1809 cur_fwd_eng->fwd_mode_name,
1810 retry_enabled == 0 ? "" : " with retry",
1813 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1814 printf(" packet len=%u - nb packet segments=%d\n",
1815 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1817 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1818 nb_fwd_lcores, nb_fwd_ports);
1820 RTE_ETH_FOREACH_DEV(pid) {
1821 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
1822 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
1823 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
1824 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
1825 uint16_t nb_rx_desc_tmp;
1826 uint16_t nb_tx_desc_tmp;
1827 struct rte_eth_rxq_info rx_qinfo;
1828 struct rte_eth_txq_info tx_qinfo;
1831 /* per port config */
1832 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
1833 (unsigned int)pid, nb_rxq, nb_txq);
1835 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
1836 ports[pid].dev_conf.rxmode.offloads,
1837 ports[pid].dev_conf.txmode.offloads);
1839 /* per rx queue config only for first queue to be less verbose */
1840 for (qid = 0; qid < 1; qid++) {
1841 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
1843 nb_rx_desc_tmp = nb_rx_desc[qid];
1845 nb_rx_desc_tmp = rx_qinfo.nb_desc;
1847 printf(" RX queue: %d\n", qid);
1848 printf(" RX desc=%d - RX free threshold=%d\n",
1849 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh);
1850 printf(" RX threshold registers: pthresh=%d hthresh=%d "
1852 rx_conf[qid].rx_thresh.pthresh,
1853 rx_conf[qid].rx_thresh.hthresh,
1854 rx_conf[qid].rx_thresh.wthresh);
1855 printf(" RX Offloads=0x%"PRIx64"\n",
1856 rx_conf[qid].offloads);
1859 /* per tx queue config only for first queue to be less verbose */
1860 for (qid = 0; qid < 1; qid++) {
1861 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
1863 nb_tx_desc_tmp = nb_tx_desc[qid];
1865 nb_tx_desc_tmp = tx_qinfo.nb_desc;
1867 printf(" TX queue: %d\n", qid);
1868 printf(" TX desc=%d - TX free threshold=%d\n",
1869 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh);
1870 printf(" TX threshold registers: pthresh=%d hthresh=%d "
1872 tx_conf[qid].tx_thresh.pthresh,
1873 tx_conf[qid].tx_thresh.hthresh,
1874 tx_conf[qid].tx_thresh.wthresh);
1875 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
1876 tx_conf[qid].offloads, tx_conf->tx_rs_thresh);
1882 port_rss_reta_info(portid_t port_id,
1883 struct rte_eth_rss_reta_entry64 *reta_conf,
1884 uint16_t nb_entries)
1886 uint16_t i, idx, shift;
1889 if (port_id_is_invalid(port_id, ENABLED_WARN))
1892 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1894 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1898 for (i = 0; i < nb_entries; i++) {
1899 idx = i / RTE_RETA_GROUP_SIZE;
1900 shift = i % RTE_RETA_GROUP_SIZE;
1901 if (!(reta_conf[idx].mask & (1ULL << shift)))
1903 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1904 i, reta_conf[idx].reta[shift]);
1909 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1913 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
1915 struct rte_eth_rss_conf rss_conf = {0};
1916 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1920 struct rte_eth_dev_info dev_info;
1921 uint8_t hash_key_size;
1924 if (port_id_is_invalid(port_id, ENABLED_WARN))
1927 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1931 if (dev_info.hash_key_size > 0 &&
1932 dev_info.hash_key_size <= sizeof(rss_key))
1933 hash_key_size = dev_info.hash_key_size;
1935 printf("dev_info did not provide a valid hash key size\n");
1939 /* Get RSS hash key if asked to display it */
1940 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1941 rss_conf.rss_key_len = hash_key_size;
1942 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1946 printf("port index %d invalid\n", port_id);
1949 printf("operation not supported by device\n");
1952 printf("operation failed - diag=%d\n", diag);
1957 rss_hf = rss_conf.rss_hf;
1959 printf("RSS disabled\n");
1962 printf("RSS functions:\n ");
1963 for (i = 0; rss_type_table[i].str; i++) {
1964 if (rss_hf & rss_type_table[i].rss_type)
1965 printf("%s ", rss_type_table[i].str);
1970 printf("RSS key:\n");
1971 for (i = 0; i < hash_key_size; i++)
1972 printf("%02X", rss_key[i]);
1977 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1980 struct rte_eth_rss_conf rss_conf;
1984 rss_conf.rss_key = NULL;
1985 rss_conf.rss_key_len = hash_key_len;
1986 rss_conf.rss_hf = 0;
1987 for (i = 0; rss_type_table[i].str; i++) {
1988 if (!strcmp(rss_type_table[i].str, rss_type))
1989 rss_conf.rss_hf = rss_type_table[i].rss_type;
1991 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1993 rss_conf.rss_key = hash_key;
1994 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2001 printf("port index %d invalid\n", port_id);
2004 printf("operation not supported by device\n");
2007 printf("operation failed - diag=%d\n", diag);
2013 * Setup forwarding configuration for each logical core.
2016 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2018 streamid_t nb_fs_per_lcore;
2026 nb_fs = cfg->nb_fwd_streams;
2027 nb_fc = cfg->nb_fwd_lcores;
2028 if (nb_fs <= nb_fc) {
2029 nb_fs_per_lcore = 1;
2032 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2033 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2036 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2038 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2039 fwd_lcores[lc_id]->stream_idx = sm_id;
2040 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2041 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2045 * Assign extra remaining streams, if any.
2047 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2048 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2049 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2050 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2051 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2056 fwd_topology_tx_port_get(portid_t rxp)
2058 static int warning_once = 1;
2060 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2062 switch (port_topology) {
2064 case PORT_TOPOLOGY_PAIRED:
2065 if ((rxp & 0x1) == 0) {
2066 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2069 printf("\nWarning! port-topology=paired"
2070 " and odd forward ports number,"
2071 " the last port will pair with"
2078 case PORT_TOPOLOGY_CHAINED:
2079 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2080 case PORT_TOPOLOGY_LOOP:
2086 simple_fwd_config_setup(void)
2090 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2091 cur_fwd_config.nb_fwd_streams =
2092 (streamid_t) cur_fwd_config.nb_fwd_ports;
2094 /* reinitialize forwarding streams */
2098 * In the simple forwarding test, the number of forwarding cores
2099 * must be lower or equal to the number of forwarding ports.
2101 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2102 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2103 cur_fwd_config.nb_fwd_lcores =
2104 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2105 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2107 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2108 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2109 fwd_streams[i]->rx_queue = 0;
2110 fwd_streams[i]->tx_port =
2111 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2112 fwd_streams[i]->tx_queue = 0;
2113 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2114 fwd_streams[i]->retry_enabled = retry_enabled;
2119 * For the RSS forwarding test all streams distributed over lcores. Each stream
2120 * being composed of a RX queue to poll on a RX port for input messages,
2121 * associated with a TX queue of a TX port where to send forwarded packets.
2124 rss_fwd_config_setup(void)
2135 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2136 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2137 cur_fwd_config.nb_fwd_streams =
2138 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2140 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2141 cur_fwd_config.nb_fwd_lcores =
2142 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2144 /* reinitialize forwarding streams */
2147 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2149 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2150 struct fwd_stream *fs;
2152 fs = fwd_streams[sm_id];
2153 txp = fwd_topology_tx_port_get(rxp);
2154 fs->rx_port = fwd_ports_ids[rxp];
2156 fs->tx_port = fwd_ports_ids[txp];
2158 fs->peer_addr = fs->tx_port;
2159 fs->retry_enabled = retry_enabled;
2161 if (rxp < nb_fwd_ports)
2169 * For the DCB forwarding test, each core is assigned on each traffic class.
2171 * Each core is assigned a multi-stream, each stream being composed of
2172 * a RX queue to poll on a RX port for input messages, associated with
2173 * a TX queue of a TX port where to send forwarded packets. All RX and
2174 * TX queues are mapping to the same traffic class.
2175 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2179 dcb_fwd_config_setup(void)
2181 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2182 portid_t txp, rxp = 0;
2183 queueid_t txq, rxq = 0;
2185 uint16_t nb_rx_queue, nb_tx_queue;
2186 uint16_t i, j, k, sm_id = 0;
2189 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2190 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2191 cur_fwd_config.nb_fwd_streams =
2192 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2194 /* reinitialize forwarding streams */
2198 /* get the dcb info on the first RX and TX ports */
2199 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2200 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2202 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2203 fwd_lcores[lc_id]->stream_nb = 0;
2204 fwd_lcores[lc_id]->stream_idx = sm_id;
2205 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2206 /* if the nb_queue is zero, means this tc is
2207 * not enabled on the POOL
2209 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2211 k = fwd_lcores[lc_id]->stream_nb +
2212 fwd_lcores[lc_id]->stream_idx;
2213 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2214 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2215 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2216 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2217 for (j = 0; j < nb_rx_queue; j++) {
2218 struct fwd_stream *fs;
2220 fs = fwd_streams[k + j];
2221 fs->rx_port = fwd_ports_ids[rxp];
2222 fs->rx_queue = rxq + j;
2223 fs->tx_port = fwd_ports_ids[txp];
2224 fs->tx_queue = txq + j % nb_tx_queue;
2225 fs->peer_addr = fs->tx_port;
2226 fs->retry_enabled = retry_enabled;
2228 fwd_lcores[lc_id]->stream_nb +=
2229 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2231 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2234 if (tc < rxp_dcb_info.nb_tcs)
2236 /* Restart from TC 0 on next RX port */
2238 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2240 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2243 if (rxp >= nb_fwd_ports)
2245 /* get the dcb information on next RX and TX ports */
2246 if ((rxp & 0x1) == 0)
2247 txp = (portid_t) (rxp + 1);
2249 txp = (portid_t) (rxp - 1);
2250 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2251 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2256 icmp_echo_config_setup(void)
2263 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2264 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2265 (nb_txq * nb_fwd_ports);
2267 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2268 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2269 cur_fwd_config.nb_fwd_streams =
2270 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2271 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2272 cur_fwd_config.nb_fwd_lcores =
2273 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2274 if (verbose_level > 0) {
2275 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2277 cur_fwd_config.nb_fwd_lcores,
2278 cur_fwd_config.nb_fwd_ports,
2279 cur_fwd_config.nb_fwd_streams);
2282 /* reinitialize forwarding streams */
2284 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2286 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2287 if (verbose_level > 0)
2288 printf(" core=%d: \n", lc_id);
2289 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2290 struct fwd_stream *fs;
2291 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2292 fs->rx_port = fwd_ports_ids[rxp];
2294 fs->tx_port = fs->rx_port;
2296 fs->peer_addr = fs->tx_port;
2297 fs->retry_enabled = retry_enabled;
2298 if (verbose_level > 0)
2299 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2300 sm_id, fs->rx_port, fs->rx_queue,
2302 rxq = (queueid_t) (rxq + 1);
2303 if (rxq == nb_rxq) {
2305 rxp = (portid_t) (rxp + 1);
2311 #if defined RTE_LIBRTE_PMD_SOFTNIC
2313 softnic_fwd_config_setup(void)
2315 struct rte_port *port;
2316 portid_t pid, softnic_portid;
2318 uint8_t softnic_enable = 0;
2320 RTE_ETH_FOREACH_DEV(pid) {
2322 const char *driver = port->dev_info.driver_name;
2324 if (strcmp(driver, "net_softnic") == 0) {
2325 softnic_portid = pid;
2331 if (softnic_enable == 0) {
2332 printf("Softnic mode not configured(%s)!\n", __func__);
2336 cur_fwd_config.nb_fwd_ports = 1;
2337 cur_fwd_config.nb_fwd_streams = (streamid_t) nb_rxq;
2339 /* Re-initialize forwarding streams */
2343 * In the softnic forwarding test, the number of forwarding cores
2344 * is set to one and remaining are used for softnic packet processing.
2346 cur_fwd_config.nb_fwd_lcores = 1;
2347 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2349 for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++) {
2350 fwd_streams[i]->rx_port = softnic_portid;
2351 fwd_streams[i]->rx_queue = i;
2352 fwd_streams[i]->tx_port = softnic_portid;
2353 fwd_streams[i]->tx_queue = i;
2354 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2355 fwd_streams[i]->retry_enabled = retry_enabled;
2361 fwd_config_setup(void)
2363 cur_fwd_config.fwd_eng = cur_fwd_eng;
2364 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2365 icmp_echo_config_setup();
2369 #if defined RTE_LIBRTE_PMD_SOFTNIC
2370 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
2371 softnic_fwd_config_setup();
2376 if ((nb_rxq > 1) && (nb_txq > 1)){
2378 dcb_fwd_config_setup();
2380 rss_fwd_config_setup();
2383 simple_fwd_config_setup();
2387 mp_alloc_to_str(uint8_t mode)
2390 case MP_ALLOC_NATIVE:
2396 case MP_ALLOC_XMEM_HUGE:
2404 pkt_fwd_config_display(struct fwd_config *cfg)
2406 struct fwd_stream *fs;
2410 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2411 "NUMA support %s, MP allocation mode: %s\n",
2412 cfg->fwd_eng->fwd_mode_name,
2413 retry_enabled == 0 ? "" : " with retry",
2414 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2415 numa_support == 1 ? "enabled" : "disabled",
2416 mp_alloc_to_str(mp_alloc_type));
2419 printf("TX retry num: %u, delay between TX retries: %uus\n",
2420 burst_tx_retry_num, burst_tx_delay_time);
2421 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2422 printf("Logical Core %u (socket %u) forwards packets on "
2424 fwd_lcores_cpuids[lc_id],
2425 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2426 fwd_lcores[lc_id]->stream_nb);
2427 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2428 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2429 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2430 "P=%d/Q=%d (socket %u) ",
2431 fs->rx_port, fs->rx_queue,
2432 ports[fs->rx_port].socket_id,
2433 fs->tx_port, fs->tx_queue,
2434 ports[fs->tx_port].socket_id);
2435 print_ethaddr("peer=",
2436 &peer_eth_addrs[fs->peer_addr]);
2444 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2446 struct rte_ether_addr new_peer_addr;
2447 if (!rte_eth_dev_is_valid_port(port_id)) {
2448 printf("Error: Invalid port number %i\n", port_id);
2451 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
2452 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2455 peer_eth_addrs[port_id] = new_peer_addr;
2459 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2462 unsigned int lcore_cpuid;
2467 for (i = 0; i < nb_lc; i++) {
2468 lcore_cpuid = lcorelist[i];
2469 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2470 printf("lcore %u not enabled\n", lcore_cpuid);
2473 if (lcore_cpuid == rte_get_master_lcore()) {
2474 printf("lcore %u cannot be masked on for running "
2475 "packet forwarding, which is the master lcore "
2476 "and reserved for command line parsing only\n",
2481 fwd_lcores_cpuids[i] = lcore_cpuid;
2483 if (record_now == 0) {
2487 nb_cfg_lcores = (lcoreid_t) nb_lc;
2488 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2489 printf("previous number of forwarding cores %u - changed to "
2490 "number of configured cores %u\n",
2491 (unsigned int) nb_fwd_lcores, nb_lc);
2492 nb_fwd_lcores = (lcoreid_t) nb_lc;
2499 set_fwd_lcores_mask(uint64_t lcoremask)
2501 unsigned int lcorelist[64];
2505 if (lcoremask == 0) {
2506 printf("Invalid NULL mask of cores\n");
2510 for (i = 0; i < 64; i++) {
2511 if (! ((uint64_t)(1ULL << i) & lcoremask))
2513 lcorelist[nb_lc++] = i;
2515 return set_fwd_lcores_list(lcorelist, nb_lc);
2519 set_fwd_lcores_number(uint16_t nb_lc)
2521 if (nb_lc > nb_cfg_lcores) {
2522 printf("nb fwd cores %u > %u (max. number of configured "
2523 "lcores) - ignored\n",
2524 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2527 nb_fwd_lcores = (lcoreid_t) nb_lc;
2528 printf("Number of forwarding cores set to %u\n",
2529 (unsigned int) nb_fwd_lcores);
2533 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2541 for (i = 0; i < nb_pt; i++) {
2542 port_id = (portid_t) portlist[i];
2543 if (port_id_is_invalid(port_id, ENABLED_WARN))
2546 fwd_ports_ids[i] = port_id;
2548 if (record_now == 0) {
2552 nb_cfg_ports = (portid_t) nb_pt;
2553 if (nb_fwd_ports != (portid_t) nb_pt) {
2554 printf("previous number of forwarding ports %u - changed to "
2555 "number of configured ports %u\n",
2556 (unsigned int) nb_fwd_ports, nb_pt);
2557 nb_fwd_ports = (portid_t) nb_pt;
2562 set_fwd_ports_mask(uint64_t portmask)
2564 unsigned int portlist[64];
2568 if (portmask == 0) {
2569 printf("Invalid NULL mask of ports\n");
2573 RTE_ETH_FOREACH_DEV(i) {
2574 if (! ((uint64_t)(1ULL << i) & portmask))
2576 portlist[nb_pt++] = i;
2578 set_fwd_ports_list(portlist, nb_pt);
2582 set_fwd_ports_number(uint16_t nb_pt)
2584 if (nb_pt > nb_cfg_ports) {
2585 printf("nb fwd ports %u > %u (number of configured "
2586 "ports) - ignored\n",
2587 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2590 nb_fwd_ports = (portid_t) nb_pt;
2591 printf("Number of forwarding ports set to %u\n",
2592 (unsigned int) nb_fwd_ports);
2596 port_is_forwarding(portid_t port_id)
2600 if (port_id_is_invalid(port_id, ENABLED_WARN))
2603 for (i = 0; i < nb_fwd_ports; i++) {
2604 if (fwd_ports_ids[i] == port_id)
2612 set_nb_pkt_per_burst(uint16_t nb)
2614 if (nb > MAX_PKT_BURST) {
2615 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2617 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2620 nb_pkt_per_burst = nb;
2621 printf("Number of packets per burst set to %u\n",
2622 (unsigned int) nb_pkt_per_burst);
2626 tx_split_get_name(enum tx_pkt_split split)
2630 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2631 if (tx_split_name[i].split == split)
2632 return tx_split_name[i].name;
2638 set_tx_pkt_split(const char *name)
2642 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2643 if (strcmp(tx_split_name[i].name, name) == 0) {
2644 tx_pkt_split = tx_split_name[i].split;
2648 printf("unknown value: \"%s\"\n", name);
2652 show_tx_pkt_segments(void)
2658 split = tx_split_get_name(tx_pkt_split);
2660 printf("Number of segments: %u\n", n);
2661 printf("Segment sizes: ");
2662 for (i = 0; i != n - 1; i++)
2663 printf("%hu,", tx_pkt_seg_lengths[i]);
2664 printf("%hu\n", tx_pkt_seg_lengths[i]);
2665 printf("Split packet: %s\n", split);
2669 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2671 uint16_t tx_pkt_len;
2674 if (nb_segs >= (unsigned) nb_txd) {
2675 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2676 nb_segs, (unsigned int) nb_txd);
2681 * Check that each segment length is greater or equal than
2682 * the mbuf data sise.
2683 * Check also that the total packet length is greater or equal than the
2684 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
2688 for (i = 0; i < nb_segs; i++) {
2689 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2690 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2691 i, seg_lengths[i], (unsigned) mbuf_data_size);
2694 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2696 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
2697 printf("total packet length=%u < %d - give up\n",
2698 (unsigned) tx_pkt_len,
2699 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
2703 for (i = 0; i < nb_segs; i++)
2704 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2706 tx_pkt_length = tx_pkt_len;
2707 tx_pkt_nb_segs = (uint8_t) nb_segs;
2711 setup_gro(const char *onoff, portid_t port_id)
2713 if (!rte_eth_dev_is_valid_port(port_id)) {
2714 printf("invalid port id %u\n", port_id);
2717 if (test_done == 0) {
2718 printf("Before enable/disable GRO,"
2719 " please stop forwarding first\n");
2722 if (strcmp(onoff, "on") == 0) {
2723 if (gro_ports[port_id].enable != 0) {
2724 printf("Port %u has enabled GRO. Please"
2725 " disable GRO first\n", port_id);
2728 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2729 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2730 gro_ports[port_id].param.max_flow_num =
2731 GRO_DEFAULT_FLOW_NUM;
2732 gro_ports[port_id].param.max_item_per_flow =
2733 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2735 gro_ports[port_id].enable = 1;
2737 if (gro_ports[port_id].enable == 0) {
2738 printf("Port %u has disabled GRO\n", port_id);
2741 gro_ports[port_id].enable = 0;
2746 setup_gro_flush_cycles(uint8_t cycles)
2748 if (test_done == 0) {
2749 printf("Before change flush interval for GRO,"
2750 " please stop forwarding first.\n");
2754 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
2755 GRO_DEFAULT_FLUSH_CYCLES) {
2756 printf("The flushing cycle be in the range"
2757 " of 1 to %u. Revert to the default"
2759 GRO_MAX_FLUSH_CYCLES,
2760 GRO_DEFAULT_FLUSH_CYCLES);
2761 cycles = GRO_DEFAULT_FLUSH_CYCLES;
2764 gro_flush_cycles = cycles;
2768 show_gro(portid_t port_id)
2770 struct rte_gro_param *param;
2771 uint32_t max_pkts_num;
2773 param = &gro_ports[port_id].param;
2775 if (!rte_eth_dev_is_valid_port(port_id)) {
2776 printf("Invalid port id %u.\n", port_id);
2779 if (gro_ports[port_id].enable) {
2780 printf("GRO type: TCP/IPv4\n");
2781 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2782 max_pkts_num = param->max_flow_num *
2783 param->max_item_per_flow;
2785 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
2786 printf("Max number of packets to perform GRO: %u\n",
2788 printf("Flushing cycles: %u\n", gro_flush_cycles);
2790 printf("Port %u doesn't enable GRO.\n", port_id);
2794 setup_gso(const char *mode, portid_t port_id)
2796 if (!rte_eth_dev_is_valid_port(port_id)) {
2797 printf("invalid port id %u\n", port_id);
2800 if (strcmp(mode, "on") == 0) {
2801 if (test_done == 0) {
2802 printf("before enabling GSO,"
2803 " please stop forwarding first\n");
2806 gso_ports[port_id].enable = 1;
2807 } else if (strcmp(mode, "off") == 0) {
2808 if (test_done == 0) {
2809 printf("before disabling GSO,"
2810 " please stop forwarding first\n");
2813 gso_ports[port_id].enable = 0;
2818 list_pkt_forwarding_modes(void)
2820 static char fwd_modes[128] = "";
2821 const char *separator = "|";
2822 struct fwd_engine *fwd_eng;
2825 if (strlen (fwd_modes) == 0) {
2826 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2827 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2828 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2829 strncat(fwd_modes, separator,
2830 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2832 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2839 list_pkt_forwarding_retry_modes(void)
2841 static char fwd_modes[128] = "";
2842 const char *separator = "|";
2843 struct fwd_engine *fwd_eng;
2846 if (strlen(fwd_modes) == 0) {
2847 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2848 if (fwd_eng == &rx_only_engine)
2850 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2852 strlen(fwd_modes) - 1);
2853 strncat(fwd_modes, separator,
2855 strlen(fwd_modes) - 1);
2857 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2864 set_pkt_forwarding_mode(const char *fwd_mode_name)
2866 struct fwd_engine *fwd_eng;
2870 while ((fwd_eng = fwd_engines[i]) != NULL) {
2871 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2872 printf("Set %s packet forwarding mode%s\n",
2874 retry_enabled == 0 ? "" : " with retry");
2875 cur_fwd_eng = fwd_eng;
2880 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2884 add_rx_dump_callbacks(portid_t portid)
2886 struct rte_eth_dev_info dev_info;
2890 if (port_id_is_invalid(portid, ENABLED_WARN))
2893 ret = eth_dev_info_get_print_err(portid, &dev_info);
2897 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
2898 if (!ports[portid].rx_dump_cb[queue])
2899 ports[portid].rx_dump_cb[queue] =
2900 rte_eth_add_rx_callback(portid, queue,
2901 dump_rx_pkts, NULL);
2905 add_tx_dump_callbacks(portid_t portid)
2907 struct rte_eth_dev_info dev_info;
2911 if (port_id_is_invalid(portid, ENABLED_WARN))
2914 ret = eth_dev_info_get_print_err(portid, &dev_info);
2918 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
2919 if (!ports[portid].tx_dump_cb[queue])
2920 ports[portid].tx_dump_cb[queue] =
2921 rte_eth_add_tx_callback(portid, queue,
2922 dump_tx_pkts, NULL);
2926 remove_rx_dump_callbacks(portid_t portid)
2928 struct rte_eth_dev_info dev_info;
2932 if (port_id_is_invalid(portid, ENABLED_WARN))
2935 ret = eth_dev_info_get_print_err(portid, &dev_info);
2939 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
2940 if (ports[portid].rx_dump_cb[queue]) {
2941 rte_eth_remove_rx_callback(portid, queue,
2942 ports[portid].rx_dump_cb[queue]);
2943 ports[portid].rx_dump_cb[queue] = NULL;
2948 remove_tx_dump_callbacks(portid_t portid)
2950 struct rte_eth_dev_info dev_info;
2954 if (port_id_is_invalid(portid, ENABLED_WARN))
2957 ret = eth_dev_info_get_print_err(portid, &dev_info);
2961 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
2962 if (ports[portid].tx_dump_cb[queue]) {
2963 rte_eth_remove_tx_callback(portid, queue,
2964 ports[portid].tx_dump_cb[queue]);
2965 ports[portid].tx_dump_cb[queue] = NULL;
2970 configure_rxtx_dump_callbacks(uint16_t verbose)
2974 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2975 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
2979 RTE_ETH_FOREACH_DEV(portid)
2981 if (verbose == 1 || verbose > 2)
2982 add_rx_dump_callbacks(portid);
2984 remove_rx_dump_callbacks(portid);
2986 add_tx_dump_callbacks(portid);
2988 remove_tx_dump_callbacks(portid);
2993 set_verbose_level(uint16_t vb_level)
2995 printf("Change verbose level from %u to %u\n",
2996 (unsigned int) verbose_level, (unsigned int) vb_level);
2997 verbose_level = vb_level;
2998 configure_rxtx_dump_callbacks(verbose_level);
3002 vlan_extend_set(portid_t port_id, int on)
3006 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3008 if (port_id_is_invalid(port_id, ENABLED_WARN))
3011 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3014 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
3015 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3017 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
3018 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3021 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3023 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
3024 "diag=%d\n", port_id, on, diag);
3025 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3029 rx_vlan_strip_set(portid_t port_id, int on)
3033 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3035 if (port_id_is_invalid(port_id, ENABLED_WARN))
3038 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3041 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
3042 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3044 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
3045 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3048 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3050 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
3051 "diag=%d\n", port_id, on, diag);
3052 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3056 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
3060 if (port_id_is_invalid(port_id, ENABLED_WARN))
3063 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
3065 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
3066 "diag=%d\n", port_id, queue_id, on, diag);
3070 rx_vlan_filter_set(portid_t port_id, int on)
3074 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3076 if (port_id_is_invalid(port_id, ENABLED_WARN))
3079 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3082 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
3083 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3085 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
3086 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3089 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3091 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
3092 "diag=%d\n", port_id, on, diag);
3093 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3097 rx_vlan_qinq_strip_set(portid_t port_id, int on)
3101 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3103 if (port_id_is_invalid(port_id, ENABLED_WARN))
3106 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3109 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
3110 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3112 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
3113 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3116 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3118 printf("%s(port_pi=%d, on=%d) failed "
3119 "diag=%d\n", __func__, port_id, on, diag);
3120 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3124 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
3128 if (port_id_is_invalid(port_id, ENABLED_WARN))
3130 if (vlan_id_is_invalid(vlan_id))
3132 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
3135 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
3137 port_id, vlan_id, on, diag);
3142 rx_vlan_all_filter_set(portid_t port_id, int on)
3146 if (port_id_is_invalid(port_id, ENABLED_WARN))
3148 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
3149 if (rx_vft_set(port_id, vlan_id, on))
3155 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
3159 if (port_id_is_invalid(port_id, ENABLED_WARN))
3162 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
3166 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
3168 port_id, vlan_type, tp_id, diag);
3172 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
3174 struct rte_eth_dev_info dev_info;
3177 if (port_id_is_invalid(port_id, ENABLED_WARN))
3179 if (vlan_id_is_invalid(vlan_id))
3182 if (ports[port_id].dev_conf.txmode.offloads &
3183 DEV_TX_OFFLOAD_QINQ_INSERT) {
3184 printf("Error, as QinQ has been enabled.\n");
3188 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3192 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
3193 printf("Error: vlan insert is not supported by port %d\n",
3198 tx_vlan_reset(port_id);
3199 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
3200 ports[port_id].tx_vlan_id = vlan_id;
3204 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
3206 struct rte_eth_dev_info dev_info;
3209 if (port_id_is_invalid(port_id, ENABLED_WARN))
3211 if (vlan_id_is_invalid(vlan_id))
3213 if (vlan_id_is_invalid(vlan_id_outer))
3216 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3220 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
3221 printf("Error: qinq insert not supported by port %d\n",
3226 tx_vlan_reset(port_id);
3227 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
3228 DEV_TX_OFFLOAD_QINQ_INSERT);
3229 ports[port_id].tx_vlan_id = vlan_id;
3230 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
3234 tx_vlan_reset(portid_t port_id)
3236 if (port_id_is_invalid(port_id, ENABLED_WARN))
3238 ports[port_id].dev_conf.txmode.offloads &=
3239 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
3240 DEV_TX_OFFLOAD_QINQ_INSERT);
3241 ports[port_id].tx_vlan_id = 0;
3242 ports[port_id].tx_vlan_id_outer = 0;
3246 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
3248 if (port_id_is_invalid(port_id, ENABLED_WARN))
3251 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
3255 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
3258 uint8_t existing_mapping_found = 0;
3260 if (port_id_is_invalid(port_id, ENABLED_WARN))
3263 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
3266 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
3267 printf("map_value not in required range 0..%d\n",
3268 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
3272 if (!is_rx) { /*then tx*/
3273 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3274 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3275 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
3276 tx_queue_stats_mappings[i].stats_counter_id = map_value;
3277 existing_mapping_found = 1;
3281 if (!existing_mapping_found) { /* A new additional mapping... */
3282 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
3283 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
3284 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
3285 nb_tx_queue_stats_mappings++;
3289 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3290 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3291 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
3292 rx_queue_stats_mappings[i].stats_counter_id = map_value;
3293 existing_mapping_found = 1;
3297 if (!existing_mapping_found) { /* A new additional mapping... */
3298 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
3299 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
3300 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
3301 nb_rx_queue_stats_mappings++;
3307 set_xstats_hide_zero(uint8_t on_off)
3309 xstats_hide_zero = on_off;
3313 print_fdir_mask(struct rte_eth_fdir_masks *mask)
3315 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
3317 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3318 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
3319 " tunnel_id: 0x%08x",
3320 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
3321 rte_be_to_cpu_32(mask->tunnel_id_mask));
3322 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3323 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
3324 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
3325 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
3327 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
3328 rte_be_to_cpu_16(mask->src_port_mask),
3329 rte_be_to_cpu_16(mask->dst_port_mask));
3331 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3332 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
3333 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3334 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3335 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3337 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3338 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3339 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3340 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3341 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3348 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3350 struct rte_eth_flex_payload_cfg *cfg;
3353 for (i = 0; i < flex_conf->nb_payloads; i++) {
3354 cfg = &flex_conf->flex_set[i];
3355 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3357 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3358 printf("\n L2_PAYLOAD: ");
3359 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3360 printf("\n L3_PAYLOAD: ");
3361 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3362 printf("\n L4_PAYLOAD: ");
3364 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3365 for (j = 0; j < num; j++)
3366 printf(" %-5u", cfg->src_offset[j]);
3372 flowtype_to_str(uint16_t flow_type)
3374 struct flow_type_info {
3380 static struct flow_type_info flowtype_str_table[] = {
3381 {"raw", RTE_ETH_FLOW_RAW},
3382 {"ipv4", RTE_ETH_FLOW_IPV4},
3383 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3384 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3385 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3386 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3387 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3388 {"ipv6", RTE_ETH_FLOW_IPV6},
3389 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3390 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3391 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3392 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3393 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3394 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3395 {"port", RTE_ETH_FLOW_PORT},
3396 {"vxlan", RTE_ETH_FLOW_VXLAN},
3397 {"geneve", RTE_ETH_FLOW_GENEVE},
3398 {"nvgre", RTE_ETH_FLOW_NVGRE},
3399 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
3402 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3403 if (flowtype_str_table[i].ftype == flow_type)
3404 return flowtype_str_table[i].str;
3411 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3413 struct rte_eth_fdir_flex_mask *mask;
3417 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3418 mask = &flex_conf->flex_mask[i];
3419 p = flowtype_to_str(mask->flow_type);
3420 printf("\n %s:\t", p ? p : "unknown");
3421 for (j = 0; j < num; j++)
3422 printf(" %02x", mask->mask[j]);
3428 print_fdir_flow_type(uint32_t flow_types_mask)
3433 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3434 if (!(flow_types_mask & (1 << i)))
3436 p = flowtype_to_str(i);
3446 fdir_get_infos(portid_t port_id)
3448 struct rte_eth_fdir_stats fdir_stat;
3449 struct rte_eth_fdir_info fdir_info;
3452 static const char *fdir_stats_border = "########################";
3454 if (port_id_is_invalid(port_id, ENABLED_WARN))
3456 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3458 printf("\n FDIR is not supported on port %-2d\n",
3463 memset(&fdir_info, 0, sizeof(fdir_info));
3464 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3465 RTE_ETH_FILTER_INFO, &fdir_info);
3466 memset(&fdir_stat, 0, sizeof(fdir_stat));
3467 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3468 RTE_ETH_FILTER_STATS, &fdir_stat);
3469 printf("\n %s FDIR infos for port %-2d %s\n",
3470 fdir_stats_border, port_id, fdir_stats_border);
3472 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3473 printf(" PERFECT\n");
3474 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3475 printf(" PERFECT-MAC-VLAN\n");
3476 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3477 printf(" PERFECT-TUNNEL\n");
3478 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3479 printf(" SIGNATURE\n");
3481 printf(" DISABLE\n");
3482 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3483 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3484 printf(" SUPPORTED FLOW TYPE: ");
3485 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3487 printf(" FLEX PAYLOAD INFO:\n");
3488 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3489 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3490 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3491 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3492 fdir_info.flex_payload_unit,
3493 fdir_info.max_flex_payload_segment_num,
3494 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3496 print_fdir_mask(&fdir_info.mask);
3497 if (fdir_info.flex_conf.nb_payloads > 0) {
3498 printf(" FLEX PAYLOAD SRC OFFSET:");
3499 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3501 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3502 printf(" FLEX MASK CFG:");
3503 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3505 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3506 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3507 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3508 fdir_info.guarant_spc, fdir_info.best_spc);
3509 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3510 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3511 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3512 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3513 fdir_stat.collision, fdir_stat.free,
3514 fdir_stat.maxhash, fdir_stat.maxlen,
3515 fdir_stat.add, fdir_stat.remove,
3516 fdir_stat.f_add, fdir_stat.f_remove);
3517 printf(" %s############################%s\n",
3518 fdir_stats_border, fdir_stats_border);
3522 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3524 struct rte_port *port;
3525 struct rte_eth_fdir_flex_conf *flex_conf;
3528 port = &ports[port_id];
3529 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3530 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3531 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3536 if (i >= RTE_ETH_FLOW_MAX) {
3537 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3538 idx = flex_conf->nb_flexmasks;
3539 flex_conf->nb_flexmasks++;
3541 printf("The flex mask table is full. Can not set flex"
3542 " mask for flow_type(%u).", cfg->flow_type);
3546 rte_memcpy(&flex_conf->flex_mask[idx],
3548 sizeof(struct rte_eth_fdir_flex_mask));
3552 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3554 struct rte_port *port;
3555 struct rte_eth_fdir_flex_conf *flex_conf;
3558 port = &ports[port_id];
3559 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3560 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3561 if (cfg->type == flex_conf->flex_set[i].type) {
3566 if (i >= RTE_ETH_PAYLOAD_MAX) {
3567 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3568 idx = flex_conf->nb_payloads;
3569 flex_conf->nb_payloads++;
3571 printf("The flex payload table is full. Can not set"
3572 " flex payload for type(%u).", cfg->type);
3576 rte_memcpy(&flex_conf->flex_set[idx],
3578 sizeof(struct rte_eth_flex_payload_cfg));
3583 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3585 #ifdef RTE_LIBRTE_IXGBE_PMD
3589 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3591 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3595 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3596 is_rx ? "rx" : "tx", port_id, diag);
3599 printf("VF %s setting not supported for port %d\n",
3600 is_rx ? "Rx" : "Tx", port_id);
3606 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3609 struct rte_eth_link link;
3612 if (port_id_is_invalid(port_id, ENABLED_WARN))
3614 ret = eth_link_get_nowait_print_err(port_id, &link);
3617 if (rate > link.link_speed) {
3618 printf("Invalid rate value:%u bigger than link speed: %u\n",
3619 rate, link.link_speed);
3622 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3625 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3631 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3633 int diag = -ENOTSUP;
3637 RTE_SET_USED(q_msk);
3639 #ifdef RTE_LIBRTE_IXGBE_PMD
3640 if (diag == -ENOTSUP)
3641 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3644 #ifdef RTE_LIBRTE_BNXT_PMD
3645 if (diag == -ENOTSUP)
3646 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3651 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3657 * Functions to manage the set of filtered Multicast MAC addresses.
3659 * A pool of filtered multicast MAC addresses is associated with each port.
3660 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3661 * The address of the pool and the number of valid multicast MAC addresses
3662 * recorded in the pool are stored in the fields "mc_addr_pool" and
3663 * "mc_addr_nb" of the "rte_port" data structure.
3665 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3666 * to be supplied a contiguous array of multicast MAC addresses.
3667 * To comply with this constraint, the set of multicast addresses recorded
3668 * into the pool are systematically compacted at the beginning of the pool.
3669 * Hence, when a multicast address is removed from the pool, all following
3670 * addresses, if any, are copied back to keep the set contiguous.
3672 #define MCAST_POOL_INC 32
3675 mcast_addr_pool_extend(struct rte_port *port)
3677 struct rte_ether_addr *mc_pool;
3678 size_t mc_pool_size;
3681 * If a free entry is available at the end of the pool, just
3682 * increment the number of recorded multicast addresses.
3684 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3690 * [re]allocate a pool with MCAST_POOL_INC more entries.
3691 * The previous test guarantees that port->mc_addr_nb is a multiple
3692 * of MCAST_POOL_INC.
3694 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
3696 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
3698 if (mc_pool == NULL) {
3699 printf("allocation of pool of %u multicast addresses failed\n",
3700 port->mc_addr_nb + MCAST_POOL_INC);
3704 port->mc_addr_pool = mc_pool;
3711 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
3713 if (mcast_addr_pool_extend(port) != 0)
3715 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
3719 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3722 if (addr_idx == port->mc_addr_nb) {
3723 /* No need to recompact the set of multicast addressses. */
3724 if (port->mc_addr_nb == 0) {
3725 /* free the pool of multicast addresses. */
3726 free(port->mc_addr_pool);
3727 port->mc_addr_pool = NULL;
3731 memmove(&port->mc_addr_pool[addr_idx],
3732 &port->mc_addr_pool[addr_idx + 1],
3733 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
3737 eth_port_multicast_addr_list_set(portid_t port_id)
3739 struct rte_port *port;
3742 port = &ports[port_id];
3743 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3746 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3747 port_id, port->mc_addr_nb, diag);
3753 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
3755 struct rte_port *port;
3758 if (port_id_is_invalid(port_id, ENABLED_WARN))
3761 port = &ports[port_id];
3764 * Check that the added multicast MAC address is not already recorded
3765 * in the pool of multicast addresses.
3767 for (i = 0; i < port->mc_addr_nb; i++) {
3768 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3769 printf("multicast address already filtered by port\n");
3774 mcast_addr_pool_append(port, mc_addr);
3775 if (eth_port_multicast_addr_list_set(port_id) < 0)
3776 /* Rollback on failure, remove the address from the pool */
3777 mcast_addr_pool_remove(port, i);
3781 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
3783 struct rte_port *port;
3786 if (port_id_is_invalid(port_id, ENABLED_WARN))
3789 port = &ports[port_id];
3792 * Search the pool of multicast MAC addresses for the removed address.
3794 for (i = 0; i < port->mc_addr_nb; i++) {
3795 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3798 if (i == port->mc_addr_nb) {
3799 printf("multicast address not filtered by port %d\n", port_id);
3803 mcast_addr_pool_remove(port, i);
3804 if (eth_port_multicast_addr_list_set(port_id) < 0)
3805 /* Rollback on failure, add the address back into the pool */
3806 mcast_addr_pool_append(port, mc_addr);
3810 port_dcb_info_display(portid_t port_id)
3812 struct rte_eth_dcb_info dcb_info;
3815 static const char *border = "================";
3817 if (port_id_is_invalid(port_id, ENABLED_WARN))
3820 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3822 printf("\n Failed to get dcb infos on port %-2d\n",
3826 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3827 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3829 for (i = 0; i < dcb_info.nb_tcs; i++)
3831 printf("\n Priority : ");
3832 for (i = 0; i < dcb_info.nb_tcs; i++)
3833 printf("\t%4d", dcb_info.prio_tc[i]);
3834 printf("\n BW percent :");
3835 for (i = 0; i < dcb_info.nb_tcs; i++)
3836 printf("\t%4d%%", dcb_info.tc_bws[i]);
3837 printf("\n RXQ base : ");
3838 for (i = 0; i < dcb_info.nb_tcs; i++)
3839 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3840 printf("\n RXQ number :");
3841 for (i = 0; i < dcb_info.nb_tcs; i++)
3842 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3843 printf("\n TXQ base : ");
3844 for (i = 0; i < dcb_info.nb_tcs; i++)
3845 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3846 printf("\n TXQ number :");
3847 for (i = 0; i < dcb_info.nb_tcs; i++)
3848 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3853 open_file(const char *file_path, uint32_t *size)
3855 int fd = open(file_path, O_RDONLY);
3857 uint8_t *buf = NULL;
3865 printf("%s: Failed to open %s\n", __func__, file_path);
3869 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
3871 printf("%s: File operations failed\n", __func__);
3875 pkg_size = st_buf.st_size;
3878 printf("%s: File operations failed\n", __func__);
3882 buf = (uint8_t *)malloc(pkg_size);
3885 printf("%s: Failed to malloc memory\n", __func__);
3889 ret = read(fd, buf, pkg_size);
3892 printf("%s: File read operation failed\n", __func__);
3906 save_file(const char *file_path, uint8_t *buf, uint32_t size)
3908 FILE *fh = fopen(file_path, "wb");
3911 printf("%s: Failed to open %s\n", __func__, file_path);
3915 if (fwrite(buf, 1, size, fh) != size) {
3917 printf("%s: File write operation failed\n", __func__);
3927 close_file(uint8_t *buf)
3938 port_queue_region_info_display(portid_t port_id, void *buf)
3940 #ifdef RTE_LIBRTE_I40E_PMD
3942 struct rte_pmd_i40e_queue_regions *info =
3943 (struct rte_pmd_i40e_queue_regions *)buf;
3944 static const char *queue_region_info_stats_border = "-------";
3946 if (!info->queue_region_number)
3947 printf("there is no region has been set before");
3949 printf("\n %s All queue region info for port=%2d %s",
3950 queue_region_info_stats_border, port_id,
3951 queue_region_info_stats_border);
3952 printf("\n queue_region_number: %-14u \n",
3953 info->queue_region_number);
3955 for (i = 0; i < info->queue_region_number; i++) {
3956 printf("\n region_id: %-14u queue_number: %-14u "
3957 "queue_start_index: %-14u \n",
3958 info->region[i].region_id,
3959 info->region[i].queue_num,
3960 info->region[i].queue_start_index);
3962 printf(" user_priority_num is %-14u :",
3963 info->region[i].user_priority_num);
3964 for (j = 0; j < info->region[i].user_priority_num; j++)
3965 printf(" %-14u ", info->region[i].user_priority[j]);
3967 printf("\n flowtype_num is %-14u :",
3968 info->region[i].flowtype_num);
3969 for (j = 0; j < info->region[i].flowtype_num; j++)
3970 printf(" %-14u ", info->region[i].hw_flowtype[j]);
3973 RTE_SET_USED(port_id);
3981 show_macs(portid_t port_id)
3983 char buf[RTE_ETHER_ADDR_FMT_SIZE];
3984 struct rte_eth_dev_info dev_info;
3985 struct rte_ether_addr *addr;
3986 uint32_t i, num_macs = 0;
3987 struct rte_eth_dev *dev;
3989 dev = &rte_eth_devices[port_id];
3991 rte_eth_dev_info_get(port_id, &dev_info);
3993 for (i = 0; i < dev_info.max_mac_addrs; i++) {
3994 addr = &dev->data->mac_addrs[i];
3996 /* skip zero address */
3997 if (rte_is_zero_ether_addr(addr))
4003 printf("Number of MAC address added: %d\n", num_macs);
4005 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4006 addr = &dev->data->mac_addrs[i];
4008 /* skip zero address */
4009 if (rte_is_zero_ether_addr(addr))
4012 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4013 printf(" %s\n", buf);
4018 show_mcast_macs(portid_t port_id)
4020 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4021 struct rte_ether_addr *addr;
4022 struct rte_port *port;
4025 port = &ports[port_id];
4027 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
4029 for (i = 0; i < port->mc_addr_nb; i++) {
4030 addr = &port->mc_addr_pool[i];
4032 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4033 printf(" %s\n", buf);