1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation.
3 * Copyright 2013-2014 6WIND S.A.
13 #include <sys/queue.h>
14 #include <sys/types.h>
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_debug.h>
23 #include <rte_memory.h>
24 #include <rte_memcpy.h>
25 #include <rte_memzone.h>
26 #include <rte_launch.h>
28 #include <rte_per_lcore.h>
29 #include <rte_lcore.h>
30 #include <rte_atomic.h>
31 #include <rte_branch_prediction.h>
32 #include <rte_mempool.h>
34 #include <rte_interrupts.h>
36 #include <rte_ether.h>
37 #include <rte_ethdev.h>
38 #include <rte_string_fns.h>
39 #include <rte_cycles.h>
41 #include <rte_errno.h>
42 #ifdef RTE_LIBRTE_IXGBE_PMD
43 #include <rte_pmd_ixgbe.h>
45 #ifdef RTE_LIBRTE_I40E_PMD
46 #include <rte_pmd_i40e.h>
48 #ifdef RTE_LIBRTE_BNXT_PMD
49 #include <rte_pmd_bnxt.h>
55 #define ETHDEV_FWVERS_LEN 32
57 static char *flowtype_to_str(uint16_t flow_type);
60 enum tx_pkt_split split;
64 .split = TX_PKT_SPLIT_OFF,
68 .split = TX_PKT_SPLIT_ON,
72 .split = TX_PKT_SPLIT_RND,
77 const struct rss_type_info rss_type_table[] = {
78 { "all", ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP | ETH_RSS_TCP |
79 ETH_RSS_UDP | ETH_RSS_SCTP | ETH_RSS_L2_PAYLOAD |
80 ETH_RSS_L2TPV3 | ETH_RSS_ESP | ETH_RSS_AH | ETH_RSS_PFCP},
82 { "eth", ETH_RSS_ETH },
83 { "l2-src-only", ETH_RSS_L2_SRC_ONLY },
84 { "l2-dst-only", ETH_RSS_L2_DST_ONLY },
85 { "vlan", ETH_RSS_VLAN },
86 { "s-vlan", ETH_RSS_S_VLAN },
87 { "c-vlan", ETH_RSS_C_VLAN },
88 { "ipv4", ETH_RSS_IPV4 },
89 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
90 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
91 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
92 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
93 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
94 { "ipv6", ETH_RSS_IPV6 },
95 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
96 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
97 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
98 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
99 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
100 { "l2-payload", ETH_RSS_L2_PAYLOAD },
101 { "ipv6-ex", ETH_RSS_IPV6_EX },
102 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
103 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
104 { "port", ETH_RSS_PORT },
105 { "vxlan", ETH_RSS_VXLAN },
106 { "geneve", ETH_RSS_GENEVE },
107 { "nvgre", ETH_RSS_NVGRE },
108 { "ip", ETH_RSS_IP },
109 { "udp", ETH_RSS_UDP },
110 { "tcp", ETH_RSS_TCP },
111 { "sctp", ETH_RSS_SCTP },
112 { "tunnel", ETH_RSS_TUNNEL },
113 { "l3-src-only", ETH_RSS_L3_SRC_ONLY },
114 { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
115 { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
116 { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
117 { "esp", ETH_RSS_ESP },
118 { "ah", ETH_RSS_AH },
119 { "l2tpv3", ETH_RSS_L2TPV3 },
120 { "pfcp", ETH_RSS_PFCP },
125 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
127 char buf[RTE_ETHER_ADDR_FMT_SIZE];
128 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
129 printf("%s%s", name, buf);
133 nic_stats_display(portid_t port_id)
135 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
136 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
137 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
138 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
139 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
140 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
142 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
143 struct rte_eth_stats stats;
144 struct rte_port *port = &ports[port_id];
147 static const char *nic_stats_border = "########################";
149 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
153 rte_eth_stats_get(port_id, &stats);
154 printf("\n %s NIC statistics for port %-2d %s\n",
155 nic_stats_border, port_id, nic_stats_border);
157 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
158 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
160 stats.ipackets, stats.imissed, stats.ibytes);
161 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
162 printf(" RX-nombuf: %-10"PRIu64"\n",
164 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
166 stats.opackets, stats.oerrors, stats.obytes);
169 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
170 " RX-bytes: %10"PRIu64"\n",
171 stats.ipackets, stats.ierrors, stats.ibytes);
172 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
173 printf(" RX-nombuf: %10"PRIu64"\n",
175 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
176 " TX-bytes: %10"PRIu64"\n",
177 stats.opackets, stats.oerrors, stats.obytes);
180 if (port->rx_queue_stats_mapping_enabled) {
182 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
183 printf(" Stats reg %2d RX-packets: %10"PRIu64
184 " RX-errors: %10"PRIu64
185 " RX-bytes: %10"PRIu64"\n",
186 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
189 if (port->tx_queue_stats_mapping_enabled) {
191 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
192 printf(" Stats reg %2d TX-packets: %10"PRIu64
193 " TX-bytes: %10"PRIu64"\n",
194 i, stats.q_opackets[i], stats.q_obytes[i]);
198 diff_cycles = prev_cycles[port_id];
199 prev_cycles[port_id] = rte_rdtsc();
201 diff_cycles = prev_cycles[port_id] - diff_cycles;
203 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
204 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
205 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
206 (stats.opackets - prev_pkts_tx[port_id]) : 0;
207 prev_pkts_rx[port_id] = stats.ipackets;
208 prev_pkts_tx[port_id] = stats.opackets;
209 mpps_rx = diff_cycles > 0 ?
210 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
211 mpps_tx = diff_cycles > 0 ?
212 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
214 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
215 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
216 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
217 (stats.obytes - prev_bytes_tx[port_id]) : 0;
218 prev_bytes_rx[port_id] = stats.ibytes;
219 prev_bytes_tx[port_id] = stats.obytes;
220 mbps_rx = diff_cycles > 0 ?
221 diff_bytes_rx * rte_get_tsc_hz() / diff_cycles : 0;
222 mbps_tx = diff_cycles > 0 ?
223 diff_bytes_tx * rte_get_tsc_hz() / diff_cycles : 0;
225 printf("\n Throughput (since last show)\n");
226 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
227 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
228 mpps_tx, mbps_tx * 8);
230 printf(" %s############################%s\n",
231 nic_stats_border, nic_stats_border);
235 nic_stats_clear(portid_t port_id)
237 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
241 rte_eth_stats_reset(port_id);
242 printf("\n NIC statistics for port %d cleared\n", port_id);
246 nic_xstats_display(portid_t port_id)
248 struct rte_eth_xstat *xstats;
249 int cnt_xstats, idx_xstat;
250 struct rte_eth_xstat_name *xstats_names;
252 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
256 printf("###### NIC extended statistics for port %-2d\n", port_id);
257 if (!rte_eth_dev_is_valid_port(port_id)) {
258 printf("Error: Invalid port number %i\n", port_id);
263 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
264 if (cnt_xstats < 0) {
265 printf("Error: Cannot get count of xstats\n");
269 /* Get id-name lookup table */
270 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
271 if (xstats_names == NULL) {
272 printf("Cannot allocate memory for xstats lookup\n");
275 if (cnt_xstats != rte_eth_xstats_get_names(
276 port_id, xstats_names, cnt_xstats)) {
277 printf("Error: Cannot get xstats lookup\n");
282 /* Get stats themselves */
283 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
284 if (xstats == NULL) {
285 printf("Cannot allocate memory for xstats\n");
289 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
290 printf("Error: Unable to get xstats\n");
297 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
298 if (xstats_hide_zero && !xstats[idx_xstat].value)
300 printf("%s: %"PRIu64"\n",
301 xstats_names[idx_xstat].name,
302 xstats[idx_xstat].value);
309 nic_xstats_clear(portid_t port_id)
313 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
317 ret = rte_eth_xstats_reset(port_id);
319 printf("%s: Error: failed to reset xstats (port %u): %s",
320 __func__, port_id, strerror(ret));
325 nic_stats_mapping_display(portid_t port_id)
327 struct rte_port *port = &ports[port_id];
330 static const char *nic_stats_mapping_border = "########################";
332 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
337 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
338 printf("Port id %d - either does not support queue statistic mapping or"
339 " no queue statistic mapping set\n", port_id);
343 printf("\n %s NIC statistics mapping for port %-2d %s\n",
344 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
346 if (port->rx_queue_stats_mapping_enabled) {
347 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
348 if (rx_queue_stats_mappings[i].port_id == port_id) {
349 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
350 rx_queue_stats_mappings[i].queue_id,
351 rx_queue_stats_mappings[i].stats_counter_id);
358 if (port->tx_queue_stats_mapping_enabled) {
359 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
360 if (tx_queue_stats_mappings[i].port_id == port_id) {
361 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
362 tx_queue_stats_mappings[i].queue_id,
363 tx_queue_stats_mappings[i].stats_counter_id);
368 printf(" %s####################################%s\n",
369 nic_stats_mapping_border, nic_stats_mapping_border);
373 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
375 struct rte_eth_burst_mode mode;
376 struct rte_eth_rxq_info qinfo;
378 static const char *info_border = "*********************";
380 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
382 printf("Failed to retrieve information for port: %u, "
383 "RX queue: %hu\nerror desc: %s(%d)\n",
384 port_id, queue_id, strerror(-rc), rc);
388 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
389 info_border, port_id, queue_id, info_border);
391 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
392 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
393 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
394 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
395 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
396 printf("\nRX drop packets: %s",
397 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
398 printf("\nRX deferred start: %s",
399 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
400 printf("\nRX scattered packets: %s",
401 (qinfo.scattered_rx != 0) ? "on" : "off");
402 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
404 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
405 printf("\nBurst mode: %s%s",
407 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
408 " (per queue)" : "");
414 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
416 struct rte_eth_burst_mode mode;
417 struct rte_eth_txq_info qinfo;
419 static const char *info_border = "*********************";
421 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
423 printf("Failed to retrieve information for port: %u, "
424 "TX queue: %hu\nerror desc: %s(%d)\n",
425 port_id, queue_id, strerror(-rc), rc);
429 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
430 info_border, port_id, queue_id, info_border);
432 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
433 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
434 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
435 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
436 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
437 printf("\nTX deferred start: %s",
438 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
439 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
441 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
442 printf("\nBurst mode: %s%s",
444 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
445 " (per queue)" : "");
450 static int bus_match_all(const struct rte_bus *bus, const void *data)
458 device_infos_display(const char *identifier)
460 static const char *info_border = "*********************";
461 struct rte_bus *start = NULL, *next;
462 struct rte_dev_iterator dev_iter;
463 char name[RTE_ETH_NAME_MAX_LEN];
464 struct rte_ether_addr mac_addr;
465 struct rte_device *dev;
466 struct rte_devargs da;
470 memset(&da, 0, sizeof(da));
474 if (rte_devargs_parsef(&da, "%s", identifier)) {
475 printf("cannot parse identifier\n");
482 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
485 if (identifier && da.bus != next)
488 /* Skip buses that don't have iterate method */
489 if (!next->dev_iterate)
492 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
493 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
497 /* Check for matching device if identifier is present */
499 strncmp(da.name, dev->name, strlen(dev->name)))
501 printf("\n%s Infos for device %s %s\n",
502 info_border, dev->name, info_border);
503 printf("Bus name: %s", dev->bus->name);
504 printf("\nDriver name: %s", dev->driver->name);
505 printf("\nDevargs: %s",
506 dev->devargs ? dev->devargs->args : "");
507 printf("\nConnect to socket: %d", dev->numa_node);
510 /* List ports with matching device name */
511 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
512 printf("\n\tPort id: %-2d", port_id);
513 if (eth_macaddr_get_print_err(port_id,
515 print_ethaddr("\n\tMAC address: ",
517 rte_eth_dev_get_name_by_port(port_id, name);
518 printf("\n\tDevice name: %s", name);
526 port_infos_display(portid_t port_id)
528 struct rte_port *port;
529 struct rte_ether_addr mac_addr;
530 struct rte_eth_link link;
531 struct rte_eth_dev_info dev_info;
533 struct rte_mempool * mp;
534 static const char *info_border = "*********************";
536 char name[RTE_ETH_NAME_MAX_LEN];
538 char fw_version[ETHDEV_FWVERS_LEN];
540 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
544 port = &ports[port_id];
545 ret = eth_link_get_nowait_print_err(port_id, &link);
549 ret = eth_dev_info_get_print_err(port_id, &dev_info);
553 printf("\n%s Infos for port %-2d %s\n",
554 info_border, port_id, info_border);
555 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
556 print_ethaddr("MAC address: ", &mac_addr);
557 rte_eth_dev_get_name_by_port(port_id, name);
558 printf("\nDevice name: %s", name);
559 printf("\nDriver name: %s", dev_info.driver_name);
561 if (rte_eth_dev_fw_version_get(port_id, fw_version,
562 ETHDEV_FWVERS_LEN) == 0)
563 printf("\nFirmware-version: %s", fw_version);
565 printf("\nFirmware-version: %s", "not available");
567 if (dev_info.device->devargs && dev_info.device->devargs->args)
568 printf("\nDevargs: %s", dev_info.device->devargs->args);
569 printf("\nConnect to socket: %u", port->socket_id);
571 if (port_numa[port_id] != NUMA_NO_CONFIG) {
572 mp = mbuf_pool_find(port_numa[port_id]);
574 printf("\nmemory allocation on the socket: %d",
577 printf("\nmemory allocation on the socket: %u",port->socket_id);
579 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
580 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
581 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
582 ("full-duplex") : ("half-duplex"));
584 if (!rte_eth_dev_get_mtu(port_id, &mtu))
585 printf("MTU: %u\n", mtu);
587 printf("Promiscuous mode: %s\n",
588 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
589 printf("Allmulticast mode: %s\n",
590 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
591 printf("Maximum number of MAC addresses: %u\n",
592 (unsigned int)(port->dev_info.max_mac_addrs));
593 printf("Maximum number of MAC addresses of hash filtering: %u\n",
594 (unsigned int)(port->dev_info.max_hash_mac_addrs));
596 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
597 if (vlan_offload >= 0){
598 printf("VLAN offload: \n");
599 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
600 printf(" strip on, ");
602 printf(" strip off, ");
604 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
605 printf("filter on, ");
607 printf("filter off, ");
609 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
610 printf("extend on, ");
612 printf("extend off, ");
614 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD)
615 printf("qinq strip on\n");
617 printf("qinq strip off\n");
620 if (dev_info.hash_key_size > 0)
621 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
622 if (dev_info.reta_size > 0)
623 printf("Redirection table size: %u\n", dev_info.reta_size);
624 if (!dev_info.flow_type_rss_offloads)
625 printf("No RSS offload flow type is supported.\n");
630 printf("Supported RSS offload flow types:\n");
631 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
632 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
633 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
635 p = flowtype_to_str(i);
639 printf(" user defined %d\n", i);
643 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
644 printf("Maximum configurable length of RX packet: %u\n",
645 dev_info.max_rx_pktlen);
646 printf("Maximum configurable size of LRO aggregated packet: %u\n",
647 dev_info.max_lro_pkt_size);
648 if (dev_info.max_vfs)
649 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
650 if (dev_info.max_vmdq_pools)
651 printf("Maximum number of VMDq pools: %u\n",
652 dev_info.max_vmdq_pools);
654 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
655 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
656 printf("Max possible number of RXDs per queue: %hu\n",
657 dev_info.rx_desc_lim.nb_max);
658 printf("Min possible number of RXDs per queue: %hu\n",
659 dev_info.rx_desc_lim.nb_min);
660 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
662 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
663 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
664 printf("Max possible number of TXDs per queue: %hu\n",
665 dev_info.tx_desc_lim.nb_max);
666 printf("Min possible number of TXDs per queue: %hu\n",
667 dev_info.tx_desc_lim.nb_min);
668 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
669 printf("Max segment number per packet: %hu\n",
670 dev_info.tx_desc_lim.nb_seg_max);
671 printf("Max segment number per MTU/TSO: %hu\n",
672 dev_info.tx_desc_lim.nb_mtu_seg_max);
674 /* Show switch info only if valid switch domain and port id is set */
675 if (dev_info.switch_info.domain_id !=
676 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
677 if (dev_info.switch_info.name)
678 printf("Switch name: %s\n", dev_info.switch_info.name);
680 printf("Switch domain Id: %u\n",
681 dev_info.switch_info.domain_id);
682 printf("Switch Port Id: %u\n",
683 dev_info.switch_info.port_id);
688 port_summary_header_display(void)
690 uint16_t port_number;
692 port_number = rte_eth_dev_count_avail();
693 printf("Number of available ports: %i\n", port_number);
694 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
695 "Driver", "Status", "Link");
699 port_summary_display(portid_t port_id)
701 struct rte_ether_addr mac_addr;
702 struct rte_eth_link link;
703 struct rte_eth_dev_info dev_info;
704 char name[RTE_ETH_NAME_MAX_LEN];
707 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
712 ret = eth_link_get_nowait_print_err(port_id, &link);
716 ret = eth_dev_info_get_print_err(port_id, &dev_info);
720 rte_eth_dev_get_name_by_port(port_id, name);
721 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
725 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n",
726 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
727 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
728 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name,
729 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
730 (unsigned int) link.link_speed);
734 port_offload_cap_display(portid_t port_id)
736 struct rte_eth_dev_info dev_info;
737 static const char *info_border = "************";
740 if (port_id_is_invalid(port_id, ENABLED_WARN))
743 ret = eth_dev_info_get_print_err(port_id, &dev_info);
747 printf("\n%s Port %d supported offload features: %s\n",
748 info_border, port_id, info_border);
750 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
751 printf("VLAN stripped: ");
752 if (ports[port_id].dev_conf.rxmode.offloads &
753 DEV_RX_OFFLOAD_VLAN_STRIP)
759 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
760 printf("Double VLANs stripped: ");
761 if (ports[port_id].dev_conf.rxmode.offloads &
762 DEV_RX_OFFLOAD_QINQ_STRIP)
768 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
769 printf("RX IPv4 checksum: ");
770 if (ports[port_id].dev_conf.rxmode.offloads &
771 DEV_RX_OFFLOAD_IPV4_CKSUM)
777 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
778 printf("RX UDP checksum: ");
779 if (ports[port_id].dev_conf.rxmode.offloads &
780 DEV_RX_OFFLOAD_UDP_CKSUM)
786 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
787 printf("RX TCP checksum: ");
788 if (ports[port_id].dev_conf.rxmode.offloads &
789 DEV_RX_OFFLOAD_TCP_CKSUM)
795 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) {
796 printf("RX SCTP checksum: ");
797 if (ports[port_id].dev_conf.rxmode.offloads &
798 DEV_RX_OFFLOAD_SCTP_CKSUM)
804 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
805 printf("RX Outer IPv4 checksum: ");
806 if (ports[port_id].dev_conf.rxmode.offloads &
807 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
813 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) {
814 printf("RX Outer UDP checksum: ");
815 if (ports[port_id].dev_conf.rxmode.offloads &
816 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM)
822 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
823 printf("Large receive offload: ");
824 if (ports[port_id].dev_conf.rxmode.offloads &
825 DEV_RX_OFFLOAD_TCP_LRO)
831 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
832 printf("HW timestamp: ");
833 if (ports[port_id].dev_conf.rxmode.offloads &
834 DEV_RX_OFFLOAD_TIMESTAMP)
840 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) {
841 printf("Rx Keep CRC: ");
842 if (ports[port_id].dev_conf.rxmode.offloads &
843 DEV_RX_OFFLOAD_KEEP_CRC)
849 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) {
850 printf("RX offload security: ");
851 if (ports[port_id].dev_conf.rxmode.offloads &
852 DEV_RX_OFFLOAD_SECURITY)
858 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
859 printf("VLAN insert: ");
860 if (ports[port_id].dev_conf.txmode.offloads &
861 DEV_TX_OFFLOAD_VLAN_INSERT)
867 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
868 printf("Double VLANs insert: ");
869 if (ports[port_id].dev_conf.txmode.offloads &
870 DEV_TX_OFFLOAD_QINQ_INSERT)
876 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
877 printf("TX IPv4 checksum: ");
878 if (ports[port_id].dev_conf.txmode.offloads &
879 DEV_TX_OFFLOAD_IPV4_CKSUM)
885 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
886 printf("TX UDP checksum: ");
887 if (ports[port_id].dev_conf.txmode.offloads &
888 DEV_TX_OFFLOAD_UDP_CKSUM)
894 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
895 printf("TX TCP checksum: ");
896 if (ports[port_id].dev_conf.txmode.offloads &
897 DEV_TX_OFFLOAD_TCP_CKSUM)
903 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
904 printf("TX SCTP checksum: ");
905 if (ports[port_id].dev_conf.txmode.offloads &
906 DEV_TX_OFFLOAD_SCTP_CKSUM)
912 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
913 printf("TX Outer IPv4 checksum: ");
914 if (ports[port_id].dev_conf.txmode.offloads &
915 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
921 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
922 printf("TX TCP segmentation: ");
923 if (ports[port_id].dev_conf.txmode.offloads &
924 DEV_TX_OFFLOAD_TCP_TSO)
930 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
931 printf("TX UDP segmentation: ");
932 if (ports[port_id].dev_conf.txmode.offloads &
933 DEV_TX_OFFLOAD_UDP_TSO)
939 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
940 printf("TSO for VXLAN tunnel packet: ");
941 if (ports[port_id].dev_conf.txmode.offloads &
942 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
948 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
949 printf("TSO for GRE tunnel packet: ");
950 if (ports[port_id].dev_conf.txmode.offloads &
951 DEV_TX_OFFLOAD_GRE_TNL_TSO)
957 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
958 printf("TSO for IPIP tunnel packet: ");
959 if (ports[port_id].dev_conf.txmode.offloads &
960 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
966 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
967 printf("TSO for GENEVE tunnel packet: ");
968 if (ports[port_id].dev_conf.txmode.offloads &
969 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
975 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) {
976 printf("IP tunnel TSO: ");
977 if (ports[port_id].dev_conf.txmode.offloads &
978 DEV_TX_OFFLOAD_IP_TNL_TSO)
984 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) {
985 printf("UDP tunnel TSO: ");
986 if (ports[port_id].dev_conf.txmode.offloads &
987 DEV_TX_OFFLOAD_UDP_TNL_TSO)
993 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
994 printf("TX Outer UDP checksum: ");
995 if (ports[port_id].dev_conf.txmode.offloads &
996 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
1005 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1009 if (port_id == (portid_t)RTE_PORT_ALL)
1012 RTE_ETH_FOREACH_DEV(pid)
1016 if (warning == ENABLED_WARN)
1017 printf("Invalid port %d\n", port_id);
1022 void print_valid_ports(void)
1026 printf("The valid ports array is [");
1027 RTE_ETH_FOREACH_DEV(pid) {
1034 vlan_id_is_invalid(uint16_t vlan_id)
1038 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1043 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1045 const struct rte_pci_device *pci_dev;
1046 const struct rte_bus *bus;
1049 if (reg_off & 0x3) {
1050 printf("Port register offset 0x%X not aligned on a 4-byte "
1056 if (!ports[port_id].dev_info.device) {
1057 printf("Invalid device\n");
1061 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1062 if (bus && !strcmp(bus->name, "pci")) {
1063 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1065 printf("Not a PCI device\n");
1069 pci_len = pci_dev->mem_resource[0].len;
1070 if (reg_off >= pci_len) {
1071 printf("Port %d: register offset %u (0x%X) out of port PCI "
1072 "resource (length=%"PRIu64")\n",
1073 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
1080 reg_bit_pos_is_invalid(uint8_t bit_pos)
1084 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
1088 #define display_port_and_reg_off(port_id, reg_off) \
1089 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1092 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1094 display_port_and_reg_off(port_id, (unsigned)reg_off);
1095 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1099 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
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(bit_x))
1110 reg_v = port_id_pci_reg_read(port_id, reg_off);
1111 display_port_and_reg_off(port_id, (unsigned)reg_off);
1112 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1116 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1117 uint8_t bit1_pos, uint8_t bit2_pos)
1123 if (port_id_is_invalid(port_id, ENABLED_WARN))
1125 if (port_reg_off_is_invalid(port_id, reg_off))
1127 if (reg_bit_pos_is_invalid(bit1_pos))
1129 if (reg_bit_pos_is_invalid(bit2_pos))
1131 if (bit1_pos > bit2_pos)
1132 l_bit = bit2_pos, h_bit = bit1_pos;
1134 l_bit = bit1_pos, h_bit = bit2_pos;
1136 reg_v = port_id_pci_reg_read(port_id, reg_off);
1139 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1140 display_port_and_reg_off(port_id, (unsigned)reg_off);
1141 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1142 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1146 port_reg_display(portid_t port_id, uint32_t reg_off)
1150 if (port_id_is_invalid(port_id, ENABLED_WARN))
1152 if (port_reg_off_is_invalid(port_id, reg_off))
1154 reg_v = port_id_pci_reg_read(port_id, reg_off);
1155 display_port_reg_value(port_id, reg_off, reg_v);
1159 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1164 if (port_id_is_invalid(port_id, ENABLED_WARN))
1166 if (port_reg_off_is_invalid(port_id, reg_off))
1168 if (reg_bit_pos_is_invalid(bit_pos))
1171 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
1174 reg_v = port_id_pci_reg_read(port_id, reg_off);
1176 reg_v &= ~(1 << bit_pos);
1178 reg_v |= (1 << bit_pos);
1179 port_id_pci_reg_write(port_id, reg_off, reg_v);
1180 display_port_reg_value(port_id, reg_off, reg_v);
1184 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1185 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1192 if (port_id_is_invalid(port_id, ENABLED_WARN))
1194 if (port_reg_off_is_invalid(port_id, reg_off))
1196 if (reg_bit_pos_is_invalid(bit1_pos))
1198 if (reg_bit_pos_is_invalid(bit2_pos))
1200 if (bit1_pos > bit2_pos)
1201 l_bit = bit2_pos, h_bit = bit1_pos;
1203 l_bit = bit1_pos, h_bit = bit2_pos;
1205 if ((h_bit - l_bit) < 31)
1206 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1210 if (value > max_v) {
1211 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
1212 (unsigned)value, (unsigned)value,
1213 (unsigned)max_v, (unsigned)max_v);
1216 reg_v = port_id_pci_reg_read(port_id, reg_off);
1217 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1218 reg_v |= (value << l_bit); /* Set changed bits */
1219 port_id_pci_reg_write(port_id, reg_off, reg_v);
1220 display_port_reg_value(port_id, reg_off, reg_v);
1224 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1226 if (port_id_is_invalid(port_id, ENABLED_WARN))
1228 if (port_reg_off_is_invalid(port_id, reg_off))
1230 port_id_pci_reg_write(port_id, reg_off, reg_v);
1231 display_port_reg_value(port_id, reg_off, reg_v);
1235 port_mtu_set(portid_t port_id, uint16_t mtu)
1238 struct rte_port *rte_port = &ports[port_id];
1239 struct rte_eth_dev_info dev_info;
1240 uint16_t eth_overhead;
1243 if (port_id_is_invalid(port_id, ENABLED_WARN))
1246 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1250 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) {
1251 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n",
1252 mtu, dev_info.min_mtu, dev_info.max_mtu);
1255 diag = rte_eth_dev_set_mtu(port_id, mtu);
1257 dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1259 * Ether overhead in driver is equal to the difference of
1260 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
1261 * device supports jumbo frame.
1263 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
1264 if (mtu > RTE_ETHER_MAX_LEN - eth_overhead) {
1265 rte_port->dev_conf.rxmode.offloads |=
1266 DEV_RX_OFFLOAD_JUMBO_FRAME;
1267 rte_port->dev_conf.rxmode.max_rx_pkt_len =
1270 rte_port->dev_conf.rxmode.offloads &=
1271 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1275 printf("Set MTU failed. diag=%d\n", diag);
1278 /* Generic flow management functions. */
1280 /** Generate a port_flow entry from attributes/pattern/actions. */
1281 static struct port_flow *
1282 port_flow_new(const struct rte_flow_attr *attr,
1283 const struct rte_flow_item *pattern,
1284 const struct rte_flow_action *actions,
1285 struct rte_flow_error *error)
1287 const struct rte_flow_conv_rule rule = {
1289 .pattern_ro = pattern,
1290 .actions_ro = actions,
1292 struct port_flow *pf;
1295 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1298 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1301 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1305 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1312 /** Print a message out of a flow error. */
1314 port_flow_complain(struct rte_flow_error *error)
1316 static const char *const errstrlist[] = {
1317 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1318 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1319 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1320 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1321 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1322 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1323 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1324 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1325 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1326 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1327 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1328 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1329 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1330 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1331 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1332 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1333 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1337 int err = rte_errno;
1339 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1340 !errstrlist[error->type])
1341 errstr = "unknown type";
1343 errstr = errstrlist[error->type];
1344 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
1345 error->type, errstr,
1346 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1347 error->cause), buf) : "",
1348 error->message ? error->message : "(no stated reason)",
1353 /** Validate flow rule. */
1355 port_flow_validate(portid_t port_id,
1356 const struct rte_flow_attr *attr,
1357 const struct rte_flow_item *pattern,
1358 const struct rte_flow_action *actions)
1360 struct rte_flow_error error;
1362 /* Poisoning to make sure PMDs update it in case of error. */
1363 memset(&error, 0x11, sizeof(error));
1364 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1365 return port_flow_complain(&error);
1366 printf("Flow rule validated\n");
1370 /** Create flow rule. */
1372 port_flow_create(portid_t port_id,
1373 const struct rte_flow_attr *attr,
1374 const struct rte_flow_item *pattern,
1375 const struct rte_flow_action *actions)
1377 struct rte_flow *flow;
1378 struct rte_port *port;
1379 struct port_flow *pf;
1381 struct rte_flow_error error;
1383 /* Poisoning to make sure PMDs update it in case of error. */
1384 memset(&error, 0x22, sizeof(error));
1385 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1387 return port_flow_complain(&error);
1388 port = &ports[port_id];
1389 if (port->flow_list) {
1390 if (port->flow_list->id == UINT32_MAX) {
1391 printf("Highest rule ID is already assigned, delete"
1393 rte_flow_destroy(port_id, flow, NULL);
1396 id = port->flow_list->id + 1;
1399 pf = port_flow_new(attr, pattern, actions, &error);
1401 rte_flow_destroy(port_id, flow, NULL);
1402 return port_flow_complain(&error);
1404 pf->next = port->flow_list;
1407 port->flow_list = pf;
1408 printf("Flow rule #%u created\n", pf->id);
1412 /** Destroy a number of flow rules. */
1414 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1416 struct rte_port *port;
1417 struct port_flow **tmp;
1421 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1422 port_id == (portid_t)RTE_PORT_ALL)
1424 port = &ports[port_id];
1425 tmp = &port->flow_list;
1429 for (i = 0; i != n; ++i) {
1430 struct rte_flow_error error;
1431 struct port_flow *pf = *tmp;
1433 if (rule[i] != pf->id)
1436 * Poisoning to make sure PMDs update it in case
1439 memset(&error, 0x33, sizeof(error));
1440 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1441 ret = port_flow_complain(&error);
1444 printf("Flow rule #%u destroyed\n", pf->id);
1450 tmp = &(*tmp)->next;
1456 /** Remove all flow rules. */
1458 port_flow_flush(portid_t port_id)
1460 struct rte_flow_error error;
1461 struct rte_port *port;
1464 /* Poisoning to make sure PMDs update it in case of error. */
1465 memset(&error, 0x44, sizeof(error));
1466 if (rte_flow_flush(port_id, &error)) {
1467 ret = port_flow_complain(&error);
1468 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1469 port_id == (portid_t)RTE_PORT_ALL)
1472 port = &ports[port_id];
1473 while (port->flow_list) {
1474 struct port_flow *pf = port->flow_list->next;
1476 free(port->flow_list);
1477 port->flow_list = pf;
1482 /** Dump all flow rules. */
1484 port_flow_dump(portid_t port_id, const char *file_name)
1487 FILE *file = stdout;
1488 struct rte_flow_error error;
1490 if (file_name && strlen(file_name)) {
1491 file = fopen(file_name, "w");
1493 printf("Failed to create file %s: %s\n", file_name,
1498 ret = rte_flow_dev_dump(port_id, file, &error);
1500 port_flow_complain(&error);
1501 printf("Failed to dump flow: %s\n", strerror(-ret));
1503 printf("Flow dump finished\n");
1504 if (file_name && strlen(file_name))
1509 /** Query a flow rule. */
1511 port_flow_query(portid_t port_id, uint32_t rule,
1512 const struct rte_flow_action *action)
1514 struct rte_flow_error error;
1515 struct rte_port *port;
1516 struct port_flow *pf;
1519 struct rte_flow_query_count count;
1523 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1524 port_id == (portid_t)RTE_PORT_ALL)
1526 port = &ports[port_id];
1527 for (pf = port->flow_list; pf; pf = pf->next)
1531 printf("Flow rule #%u not found\n", rule);
1534 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1535 &name, sizeof(name),
1536 (void *)(uintptr_t)action->type, &error);
1538 return port_flow_complain(&error);
1539 switch (action->type) {
1540 case RTE_FLOW_ACTION_TYPE_COUNT:
1543 printf("Cannot query action type %d (%s)\n",
1544 action->type, name);
1547 /* Poisoning to make sure PMDs update it in case of error. */
1548 memset(&error, 0x55, sizeof(error));
1549 memset(&query, 0, sizeof(query));
1550 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1551 return port_flow_complain(&error);
1552 switch (action->type) {
1553 case RTE_FLOW_ACTION_TYPE_COUNT:
1557 " hits: %" PRIu64 "\n"
1558 " bytes: %" PRIu64 "\n",
1560 query.count.hits_set,
1561 query.count.bytes_set,
1566 printf("Cannot display result for action type %d (%s)\n",
1567 action->type, name);
1573 /** List flow rules. */
1575 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1577 struct rte_port *port;
1578 struct port_flow *pf;
1579 struct port_flow *list = NULL;
1582 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1583 port_id == (portid_t)RTE_PORT_ALL)
1585 port = &ports[port_id];
1586 if (!port->flow_list)
1588 /* Sort flows by group, priority and ID. */
1589 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1590 struct port_flow **tmp;
1591 const struct rte_flow_attr *curr = pf->rule.attr;
1594 /* Filter out unwanted groups. */
1595 for (i = 0; i != n; ++i)
1596 if (curr->group == group[i])
1601 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
1602 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
1604 if (curr->group > comp->group ||
1605 (curr->group == comp->group &&
1606 curr->priority > comp->priority) ||
1607 (curr->group == comp->group &&
1608 curr->priority == comp->priority &&
1609 pf->id > (*tmp)->id))
1616 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1617 for (pf = list; pf != NULL; pf = pf->tmp) {
1618 const struct rte_flow_item *item = pf->rule.pattern;
1619 const struct rte_flow_action *action = pf->rule.actions;
1622 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
1624 pf->rule.attr->group,
1625 pf->rule.attr->priority,
1626 pf->rule.attr->ingress ? 'i' : '-',
1627 pf->rule.attr->egress ? 'e' : '-',
1628 pf->rule.attr->transfer ? 't' : '-');
1629 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1630 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
1631 &name, sizeof(name),
1632 (void *)(uintptr_t)item->type,
1635 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1636 printf("%s ", name);
1640 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1641 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
1642 &name, sizeof(name),
1643 (void *)(uintptr_t)action->type,
1646 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1647 printf(" %s", name);
1654 /** Restrict ingress traffic to the defined flow rules. */
1656 port_flow_isolate(portid_t port_id, int set)
1658 struct rte_flow_error error;
1660 /* Poisoning to make sure PMDs update it in case of error. */
1661 memset(&error, 0x66, sizeof(error));
1662 if (rte_flow_isolate(port_id, set, &error))
1663 return port_flow_complain(&error);
1664 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1666 set ? "now restricted" : "not restricted anymore");
1671 * RX/TX ring descriptors display functions.
1674 rx_queue_id_is_invalid(queueid_t rxq_id)
1676 if (rxq_id < nb_rxq)
1678 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1683 tx_queue_id_is_invalid(queueid_t txq_id)
1685 if (txq_id < nb_txq)
1687 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1692 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1694 if (rxdesc_id < nb_rxd)
1696 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1702 tx_desc_id_is_invalid(uint16_t txdesc_id)
1704 if (txdesc_id < nb_txd)
1706 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1711 static const struct rte_memzone *
1712 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1714 char mz_name[RTE_MEMZONE_NAMESIZE];
1715 const struct rte_memzone *mz;
1717 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
1718 port_id, q_id, ring_name);
1719 mz = rte_memzone_lookup(mz_name);
1721 printf("%s ring memory zoneof (port %d, queue %d) not"
1722 "found (zone name = %s\n",
1723 ring_name, port_id, q_id, mz_name);
1727 union igb_ring_dword {
1730 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1740 struct igb_ring_desc_32_bytes {
1741 union igb_ring_dword lo_dword;
1742 union igb_ring_dword hi_dword;
1743 union igb_ring_dword resv1;
1744 union igb_ring_dword resv2;
1747 struct igb_ring_desc_16_bytes {
1748 union igb_ring_dword lo_dword;
1749 union igb_ring_dword hi_dword;
1753 ring_rxd_display_dword(union igb_ring_dword dword)
1755 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1756 (unsigned)dword.words.hi);
1760 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1761 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1764 __rte_unused portid_t port_id,
1768 struct igb_ring_desc_16_bytes *ring =
1769 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1770 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1772 struct rte_eth_dev_info dev_info;
1774 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1778 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1779 /* 32 bytes RX descriptor, i40e only */
1780 struct igb_ring_desc_32_bytes *ring =
1781 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1782 ring[desc_id].lo_dword.dword =
1783 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1784 ring_rxd_display_dword(ring[desc_id].lo_dword);
1785 ring[desc_id].hi_dword.dword =
1786 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1787 ring_rxd_display_dword(ring[desc_id].hi_dword);
1788 ring[desc_id].resv1.dword =
1789 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1790 ring_rxd_display_dword(ring[desc_id].resv1);
1791 ring[desc_id].resv2.dword =
1792 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1793 ring_rxd_display_dword(ring[desc_id].resv2);
1798 /* 16 bytes RX descriptor */
1799 ring[desc_id].lo_dword.dword =
1800 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1801 ring_rxd_display_dword(ring[desc_id].lo_dword);
1802 ring[desc_id].hi_dword.dword =
1803 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1804 ring_rxd_display_dword(ring[desc_id].hi_dword);
1808 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1810 struct igb_ring_desc_16_bytes *ring;
1811 struct igb_ring_desc_16_bytes txd;
1813 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1814 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1815 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1816 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1817 (unsigned)txd.lo_dword.words.lo,
1818 (unsigned)txd.lo_dword.words.hi,
1819 (unsigned)txd.hi_dword.words.lo,
1820 (unsigned)txd.hi_dword.words.hi);
1824 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1826 const struct rte_memzone *rx_mz;
1828 if (port_id_is_invalid(port_id, ENABLED_WARN))
1830 if (rx_queue_id_is_invalid(rxq_id))
1832 if (rx_desc_id_is_invalid(rxd_id))
1834 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1837 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1841 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1843 const struct rte_memzone *tx_mz;
1845 if (port_id_is_invalid(port_id, ENABLED_WARN))
1847 if (tx_queue_id_is_invalid(txq_id))
1849 if (tx_desc_id_is_invalid(txd_id))
1851 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1854 ring_tx_descriptor_display(tx_mz, txd_id);
1858 fwd_lcores_config_display(void)
1862 printf("List of forwarding lcores:");
1863 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1864 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1868 rxtx_config_display(void)
1873 printf(" %s packet forwarding%s packets/burst=%d\n",
1874 cur_fwd_eng->fwd_mode_name,
1875 retry_enabled == 0 ? "" : " with retry",
1878 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1879 printf(" packet len=%u - nb packet segments=%d\n",
1880 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1882 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1883 nb_fwd_lcores, nb_fwd_ports);
1885 RTE_ETH_FOREACH_DEV(pid) {
1886 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
1887 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
1888 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
1889 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
1890 uint16_t nb_rx_desc_tmp;
1891 uint16_t nb_tx_desc_tmp;
1892 struct rte_eth_rxq_info rx_qinfo;
1893 struct rte_eth_txq_info tx_qinfo;
1896 /* per port config */
1897 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
1898 (unsigned int)pid, nb_rxq, nb_txq);
1900 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
1901 ports[pid].dev_conf.rxmode.offloads,
1902 ports[pid].dev_conf.txmode.offloads);
1904 /* per rx queue config only for first queue to be less verbose */
1905 for (qid = 0; qid < 1; qid++) {
1906 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
1908 nb_rx_desc_tmp = nb_rx_desc[qid];
1910 nb_rx_desc_tmp = rx_qinfo.nb_desc;
1912 printf(" RX queue: %d\n", qid);
1913 printf(" RX desc=%d - RX free threshold=%d\n",
1914 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh);
1915 printf(" RX threshold registers: pthresh=%d hthresh=%d "
1917 rx_conf[qid].rx_thresh.pthresh,
1918 rx_conf[qid].rx_thresh.hthresh,
1919 rx_conf[qid].rx_thresh.wthresh);
1920 printf(" RX Offloads=0x%"PRIx64"\n",
1921 rx_conf[qid].offloads);
1924 /* per tx queue config only for first queue to be less verbose */
1925 for (qid = 0; qid < 1; qid++) {
1926 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
1928 nb_tx_desc_tmp = nb_tx_desc[qid];
1930 nb_tx_desc_tmp = tx_qinfo.nb_desc;
1932 printf(" TX queue: %d\n", qid);
1933 printf(" TX desc=%d - TX free threshold=%d\n",
1934 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh);
1935 printf(" TX threshold registers: pthresh=%d hthresh=%d "
1937 tx_conf[qid].tx_thresh.pthresh,
1938 tx_conf[qid].tx_thresh.hthresh,
1939 tx_conf[qid].tx_thresh.wthresh);
1940 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
1941 tx_conf[qid].offloads, tx_conf->tx_rs_thresh);
1947 port_rss_reta_info(portid_t port_id,
1948 struct rte_eth_rss_reta_entry64 *reta_conf,
1949 uint16_t nb_entries)
1951 uint16_t i, idx, shift;
1954 if (port_id_is_invalid(port_id, ENABLED_WARN))
1957 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1959 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1963 for (i = 0; i < nb_entries; i++) {
1964 idx = i / RTE_RETA_GROUP_SIZE;
1965 shift = i % RTE_RETA_GROUP_SIZE;
1966 if (!(reta_conf[idx].mask & (1ULL << shift)))
1968 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1969 i, reta_conf[idx].reta[shift]);
1974 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1978 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
1980 struct rte_eth_rss_conf rss_conf = {0};
1981 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1985 struct rte_eth_dev_info dev_info;
1986 uint8_t hash_key_size;
1989 if (port_id_is_invalid(port_id, ENABLED_WARN))
1992 ret = eth_dev_info_get_print_err(port_id, &dev_info);
1996 if (dev_info.hash_key_size > 0 &&
1997 dev_info.hash_key_size <= sizeof(rss_key))
1998 hash_key_size = dev_info.hash_key_size;
2000 printf("dev_info did not provide a valid hash key size\n");
2004 /* Get RSS hash key if asked to display it */
2005 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2006 rss_conf.rss_key_len = hash_key_size;
2007 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2011 printf("port index %d invalid\n", port_id);
2014 printf("operation not supported by device\n");
2017 printf("operation failed - diag=%d\n", diag);
2022 rss_hf = rss_conf.rss_hf;
2024 printf("RSS disabled\n");
2027 printf("RSS functions:\n ");
2028 for (i = 0; rss_type_table[i].str; i++) {
2029 if (rss_hf & rss_type_table[i].rss_type)
2030 printf("%s ", rss_type_table[i].str);
2035 printf("RSS key:\n");
2036 for (i = 0; i < hash_key_size; i++)
2037 printf("%02X", rss_key[i]);
2042 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2045 struct rte_eth_rss_conf rss_conf;
2049 rss_conf.rss_key = NULL;
2050 rss_conf.rss_key_len = hash_key_len;
2051 rss_conf.rss_hf = 0;
2052 for (i = 0; rss_type_table[i].str; i++) {
2053 if (!strcmp(rss_type_table[i].str, rss_type))
2054 rss_conf.rss_hf = rss_type_table[i].rss_type;
2056 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2058 rss_conf.rss_key = hash_key;
2059 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2066 printf("port index %d invalid\n", port_id);
2069 printf("operation not supported by device\n");
2072 printf("operation failed - diag=%d\n", diag);
2078 * Setup forwarding configuration for each logical core.
2081 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
2083 streamid_t nb_fs_per_lcore;
2091 nb_fs = cfg->nb_fwd_streams;
2092 nb_fc = cfg->nb_fwd_lcores;
2093 if (nb_fs <= nb_fc) {
2094 nb_fs_per_lcore = 1;
2097 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
2098 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
2101 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
2103 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
2104 fwd_lcores[lc_id]->stream_idx = sm_id;
2105 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
2106 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2110 * Assign extra remaining streams, if any.
2112 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
2113 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
2114 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
2115 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
2116 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
2121 fwd_topology_tx_port_get(portid_t rxp)
2123 static int warning_once = 1;
2125 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
2127 switch (port_topology) {
2129 case PORT_TOPOLOGY_PAIRED:
2130 if ((rxp & 0x1) == 0) {
2131 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
2134 printf("\nWarning! port-topology=paired"
2135 " and odd forward ports number,"
2136 " the last port will pair with"
2143 case PORT_TOPOLOGY_CHAINED:
2144 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
2145 case PORT_TOPOLOGY_LOOP:
2151 simple_fwd_config_setup(void)
2155 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
2156 cur_fwd_config.nb_fwd_streams =
2157 (streamid_t) cur_fwd_config.nb_fwd_ports;
2159 /* reinitialize forwarding streams */
2163 * In the simple forwarding test, the number of forwarding cores
2164 * must be lower or equal to the number of forwarding ports.
2166 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2167 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
2168 cur_fwd_config.nb_fwd_lcores =
2169 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
2170 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2172 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2173 fwd_streams[i]->rx_port = fwd_ports_ids[i];
2174 fwd_streams[i]->rx_queue = 0;
2175 fwd_streams[i]->tx_port =
2176 fwd_ports_ids[fwd_topology_tx_port_get(i)];
2177 fwd_streams[i]->tx_queue = 0;
2178 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2179 fwd_streams[i]->retry_enabled = retry_enabled;
2184 * For the RSS forwarding test all streams distributed over lcores. Each stream
2185 * being composed of a RX queue to poll on a RX port for input messages,
2186 * associated with a TX queue of a TX port where to send forwarded packets.
2189 rss_fwd_config_setup(void)
2200 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2201 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2202 cur_fwd_config.nb_fwd_streams =
2203 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
2205 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2206 cur_fwd_config.nb_fwd_lcores =
2207 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2209 /* reinitialize forwarding streams */
2212 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2214 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2215 struct fwd_stream *fs;
2217 fs = fwd_streams[sm_id];
2218 txp = fwd_topology_tx_port_get(rxp);
2219 fs->rx_port = fwd_ports_ids[rxp];
2221 fs->tx_port = fwd_ports_ids[txp];
2223 fs->peer_addr = fs->tx_port;
2224 fs->retry_enabled = retry_enabled;
2226 if (rxp < nb_fwd_ports)
2234 * For the DCB forwarding test, each core is assigned on each traffic class.
2236 * Each core is assigned a multi-stream, each stream being composed of
2237 * a RX queue to poll on a RX port for input messages, associated with
2238 * a TX queue of a TX port where to send forwarded packets. All RX and
2239 * TX queues are mapping to the same traffic class.
2240 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2244 dcb_fwd_config_setup(void)
2246 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2247 portid_t txp, rxp = 0;
2248 queueid_t txq, rxq = 0;
2250 uint16_t nb_rx_queue, nb_tx_queue;
2251 uint16_t i, j, k, sm_id = 0;
2254 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2255 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2256 cur_fwd_config.nb_fwd_streams =
2257 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2259 /* reinitialize forwarding streams */
2263 /* get the dcb info on the first RX and TX ports */
2264 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2265 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2267 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2268 fwd_lcores[lc_id]->stream_nb = 0;
2269 fwd_lcores[lc_id]->stream_idx = sm_id;
2270 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2271 /* if the nb_queue is zero, means this tc is
2272 * not enabled on the POOL
2274 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2276 k = fwd_lcores[lc_id]->stream_nb +
2277 fwd_lcores[lc_id]->stream_idx;
2278 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2279 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2280 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2281 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2282 for (j = 0; j < nb_rx_queue; j++) {
2283 struct fwd_stream *fs;
2285 fs = fwd_streams[k + j];
2286 fs->rx_port = fwd_ports_ids[rxp];
2287 fs->rx_queue = rxq + j;
2288 fs->tx_port = fwd_ports_ids[txp];
2289 fs->tx_queue = txq + j % nb_tx_queue;
2290 fs->peer_addr = fs->tx_port;
2291 fs->retry_enabled = retry_enabled;
2293 fwd_lcores[lc_id]->stream_nb +=
2294 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2296 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2299 if (tc < rxp_dcb_info.nb_tcs)
2301 /* Restart from TC 0 on next RX port */
2303 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2305 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2308 if (rxp >= nb_fwd_ports)
2310 /* get the dcb information on next RX and TX ports */
2311 if ((rxp & 0x1) == 0)
2312 txp = (portid_t) (rxp + 1);
2314 txp = (portid_t) (rxp - 1);
2315 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2316 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2321 icmp_echo_config_setup(void)
2328 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2329 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2330 (nb_txq * nb_fwd_ports);
2332 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2333 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2334 cur_fwd_config.nb_fwd_streams =
2335 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2336 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2337 cur_fwd_config.nb_fwd_lcores =
2338 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2339 if (verbose_level > 0) {
2340 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2342 cur_fwd_config.nb_fwd_lcores,
2343 cur_fwd_config.nb_fwd_ports,
2344 cur_fwd_config.nb_fwd_streams);
2347 /* reinitialize forwarding streams */
2349 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2351 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2352 if (verbose_level > 0)
2353 printf(" core=%d: \n", lc_id);
2354 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2355 struct fwd_stream *fs;
2356 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2357 fs->rx_port = fwd_ports_ids[rxp];
2359 fs->tx_port = fs->rx_port;
2361 fs->peer_addr = fs->tx_port;
2362 fs->retry_enabled = retry_enabled;
2363 if (verbose_level > 0)
2364 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2365 sm_id, fs->rx_port, fs->rx_queue,
2367 rxq = (queueid_t) (rxq + 1);
2368 if (rxq == nb_rxq) {
2370 rxp = (portid_t) (rxp + 1);
2376 #if defined RTE_LIBRTE_PMD_SOFTNIC
2378 softnic_fwd_config_setup(void)
2380 struct rte_port *port;
2381 portid_t pid, softnic_portid;
2383 uint8_t softnic_enable = 0;
2385 RTE_ETH_FOREACH_DEV(pid) {
2387 const char *driver = port->dev_info.driver_name;
2389 if (strcmp(driver, "net_softnic") == 0) {
2390 softnic_portid = pid;
2396 if (softnic_enable == 0) {
2397 printf("Softnic mode not configured(%s)!\n", __func__);
2401 cur_fwd_config.nb_fwd_ports = 1;
2402 cur_fwd_config.nb_fwd_streams = (streamid_t) nb_rxq;
2404 /* Re-initialize forwarding streams */
2408 * In the softnic forwarding test, the number of forwarding cores
2409 * is set to one and remaining are used for softnic packet processing.
2411 cur_fwd_config.nb_fwd_lcores = 1;
2412 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2414 for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++) {
2415 fwd_streams[i]->rx_port = softnic_portid;
2416 fwd_streams[i]->rx_queue = i;
2417 fwd_streams[i]->tx_port = softnic_portid;
2418 fwd_streams[i]->tx_queue = i;
2419 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
2420 fwd_streams[i]->retry_enabled = retry_enabled;
2426 fwd_config_setup(void)
2428 cur_fwd_config.fwd_eng = cur_fwd_eng;
2429 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2430 icmp_echo_config_setup();
2434 #if defined RTE_LIBRTE_PMD_SOFTNIC
2435 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
2436 softnic_fwd_config_setup();
2441 if ((nb_rxq > 1) && (nb_txq > 1)){
2443 dcb_fwd_config_setup();
2445 rss_fwd_config_setup();
2448 simple_fwd_config_setup();
2452 mp_alloc_to_str(uint8_t mode)
2455 case MP_ALLOC_NATIVE:
2461 case MP_ALLOC_XMEM_HUGE:
2471 pkt_fwd_config_display(struct fwd_config *cfg)
2473 struct fwd_stream *fs;
2477 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2478 "NUMA support %s, MP allocation mode: %s\n",
2479 cfg->fwd_eng->fwd_mode_name,
2480 retry_enabled == 0 ? "" : " with retry",
2481 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2482 numa_support == 1 ? "enabled" : "disabled",
2483 mp_alloc_to_str(mp_alloc_type));
2486 printf("TX retry num: %u, delay between TX retries: %uus\n",
2487 burst_tx_retry_num, burst_tx_delay_time);
2488 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2489 printf("Logical Core %u (socket %u) forwards packets on "
2491 fwd_lcores_cpuids[lc_id],
2492 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2493 fwd_lcores[lc_id]->stream_nb);
2494 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2495 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2496 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2497 "P=%d/Q=%d (socket %u) ",
2498 fs->rx_port, fs->rx_queue,
2499 ports[fs->rx_port].socket_id,
2500 fs->tx_port, fs->tx_queue,
2501 ports[fs->tx_port].socket_id);
2502 print_ethaddr("peer=",
2503 &peer_eth_addrs[fs->peer_addr]);
2511 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2513 struct rte_ether_addr new_peer_addr;
2514 if (!rte_eth_dev_is_valid_port(port_id)) {
2515 printf("Error: Invalid port number %i\n", port_id);
2518 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
2519 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2522 peer_eth_addrs[port_id] = new_peer_addr;
2526 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2529 unsigned int lcore_cpuid;
2534 for (i = 0; i < nb_lc; i++) {
2535 lcore_cpuid = lcorelist[i];
2536 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2537 printf("lcore %u not enabled\n", lcore_cpuid);
2540 if (lcore_cpuid == rte_get_master_lcore()) {
2541 printf("lcore %u cannot be masked on for running "
2542 "packet forwarding, which is the master lcore "
2543 "and reserved for command line parsing only\n",
2548 fwd_lcores_cpuids[i] = lcore_cpuid;
2550 if (record_now == 0) {
2554 nb_cfg_lcores = (lcoreid_t) nb_lc;
2555 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2556 printf("previous number of forwarding cores %u - changed to "
2557 "number of configured cores %u\n",
2558 (unsigned int) nb_fwd_lcores, nb_lc);
2559 nb_fwd_lcores = (lcoreid_t) nb_lc;
2566 set_fwd_lcores_mask(uint64_t lcoremask)
2568 unsigned int lcorelist[64];
2572 if (lcoremask == 0) {
2573 printf("Invalid NULL mask of cores\n");
2577 for (i = 0; i < 64; i++) {
2578 if (! ((uint64_t)(1ULL << i) & lcoremask))
2580 lcorelist[nb_lc++] = i;
2582 return set_fwd_lcores_list(lcorelist, nb_lc);
2586 set_fwd_lcores_number(uint16_t nb_lc)
2588 if (nb_lc > nb_cfg_lcores) {
2589 printf("nb fwd cores %u > %u (max. number of configured "
2590 "lcores) - ignored\n",
2591 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2594 nb_fwd_lcores = (lcoreid_t) nb_lc;
2595 printf("Number of forwarding cores set to %u\n",
2596 (unsigned int) nb_fwd_lcores);
2600 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2608 for (i = 0; i < nb_pt; i++) {
2609 port_id = (portid_t) portlist[i];
2610 if (port_id_is_invalid(port_id, ENABLED_WARN))
2613 fwd_ports_ids[i] = port_id;
2615 if (record_now == 0) {
2619 nb_cfg_ports = (portid_t) nb_pt;
2620 if (nb_fwd_ports != (portid_t) nb_pt) {
2621 printf("previous number of forwarding ports %u - changed to "
2622 "number of configured ports %u\n",
2623 (unsigned int) nb_fwd_ports, nb_pt);
2624 nb_fwd_ports = (portid_t) nb_pt;
2629 * Parse the user input and obtain the list of forwarding ports
2632 * String containing the user input. User can specify
2633 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
2634 * For example, if the user wants to use all the available
2635 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
2636 * If the user wants to use only the ports 1,2 then the input
2638 * valid characters are '-' and ','
2639 * @param[out] values
2640 * This array will be filled with a list of port IDs
2641 * based on the user input
2642 * Note that duplicate entries are discarded and only the first
2643 * count entries in this array are port IDs and all the rest
2644 * will contain default values
2645 * @param[in] maxsize
2646 * This parameter denotes 2 things
2647 * 1) Number of elements in the values array
2648 * 2) Maximum value of each element in the values array
2650 * On success, returns total count of parsed port IDs
2651 * On failure, returns 0
2654 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
2656 unsigned int count = 0;
2660 unsigned int marked[maxsize];
2662 if (list == NULL || values == NULL)
2665 for (i = 0; i < (int)maxsize; i++)
2671 /*Remove the blank spaces if any*/
2672 while (isblank(*list))
2677 value = strtol(list, &end, 10);
2678 if (errno || end == NULL)
2680 if (value < 0 || value >= (int)maxsize)
2682 while (isblank(*end))
2684 if (*end == '-' && min == INT_MAX) {
2686 } else if ((*end == ',') || (*end == '\0')) {
2690 for (i = min; i <= max; i++) {
2691 if (count < maxsize) {
2703 } while (*end != '\0');
2709 parse_fwd_portlist(const char *portlist)
2711 unsigned int portcount;
2712 unsigned int portindex[RTE_MAX_ETHPORTS];
2713 unsigned int i, valid_port_count = 0;
2715 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
2717 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
2720 * Here we verify the validity of the ports
2721 * and thereby calculate the total number of
2724 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
2725 if (rte_eth_dev_is_valid_port(portindex[i])) {
2726 portindex[valid_port_count] = portindex[i];
2731 set_fwd_ports_list(portindex, valid_port_count);
2735 set_fwd_ports_mask(uint64_t portmask)
2737 unsigned int portlist[64];
2741 if (portmask == 0) {
2742 printf("Invalid NULL mask of ports\n");
2746 RTE_ETH_FOREACH_DEV(i) {
2747 if (! ((uint64_t)(1ULL << i) & portmask))
2749 portlist[nb_pt++] = i;
2751 set_fwd_ports_list(portlist, nb_pt);
2755 set_fwd_ports_number(uint16_t nb_pt)
2757 if (nb_pt > nb_cfg_ports) {
2758 printf("nb fwd ports %u > %u (number of configured "
2759 "ports) - ignored\n",
2760 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2763 nb_fwd_ports = (portid_t) nb_pt;
2764 printf("Number of forwarding ports set to %u\n",
2765 (unsigned int) nb_fwd_ports);
2769 port_is_forwarding(portid_t port_id)
2773 if (port_id_is_invalid(port_id, ENABLED_WARN))
2776 for (i = 0; i < nb_fwd_ports; i++) {
2777 if (fwd_ports_ids[i] == port_id)
2785 set_nb_pkt_per_burst(uint16_t nb)
2787 if (nb > MAX_PKT_BURST) {
2788 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2790 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2793 nb_pkt_per_burst = nb;
2794 printf("Number of packets per burst set to %u\n",
2795 (unsigned int) nb_pkt_per_burst);
2799 tx_split_get_name(enum tx_pkt_split split)
2803 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2804 if (tx_split_name[i].split == split)
2805 return tx_split_name[i].name;
2811 set_tx_pkt_split(const char *name)
2815 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2816 if (strcmp(tx_split_name[i].name, name) == 0) {
2817 tx_pkt_split = tx_split_name[i].split;
2821 printf("unknown value: \"%s\"\n", name);
2825 show_tx_pkt_segments(void)
2831 split = tx_split_get_name(tx_pkt_split);
2833 printf("Number of segments: %u\n", n);
2834 printf("Segment sizes: ");
2835 for (i = 0; i != n - 1; i++)
2836 printf("%hu,", tx_pkt_seg_lengths[i]);
2837 printf("%hu\n", tx_pkt_seg_lengths[i]);
2838 printf("Split packet: %s\n", split);
2842 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2844 uint16_t tx_pkt_len;
2847 if (nb_segs >= (unsigned) nb_txd) {
2848 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2849 nb_segs, (unsigned int) nb_txd);
2854 * Check that each segment length is greater or equal than
2855 * the mbuf data sise.
2856 * Check also that the total packet length is greater or equal than the
2857 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
2861 for (i = 0; i < nb_segs; i++) {
2862 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2863 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2864 i, seg_lengths[i], (unsigned) mbuf_data_size);
2867 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2869 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
2870 printf("total packet length=%u < %d - give up\n",
2871 (unsigned) tx_pkt_len,
2872 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
2876 for (i = 0; i < nb_segs; i++)
2877 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2879 tx_pkt_length = tx_pkt_len;
2880 tx_pkt_nb_segs = (uint8_t) nb_segs;
2884 setup_gro(const char *onoff, portid_t port_id)
2886 if (!rte_eth_dev_is_valid_port(port_id)) {
2887 printf("invalid port id %u\n", port_id);
2890 if (test_done == 0) {
2891 printf("Before enable/disable GRO,"
2892 " please stop forwarding first\n");
2895 if (strcmp(onoff, "on") == 0) {
2896 if (gro_ports[port_id].enable != 0) {
2897 printf("Port %u has enabled GRO. Please"
2898 " disable GRO first\n", port_id);
2901 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2902 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2903 gro_ports[port_id].param.max_flow_num =
2904 GRO_DEFAULT_FLOW_NUM;
2905 gro_ports[port_id].param.max_item_per_flow =
2906 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2908 gro_ports[port_id].enable = 1;
2910 if (gro_ports[port_id].enable == 0) {
2911 printf("Port %u has disabled GRO\n", port_id);
2914 gro_ports[port_id].enable = 0;
2919 setup_gro_flush_cycles(uint8_t cycles)
2921 if (test_done == 0) {
2922 printf("Before change flush interval for GRO,"
2923 " please stop forwarding first.\n");
2927 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
2928 GRO_DEFAULT_FLUSH_CYCLES) {
2929 printf("The flushing cycle be in the range"
2930 " of 1 to %u. Revert to the default"
2932 GRO_MAX_FLUSH_CYCLES,
2933 GRO_DEFAULT_FLUSH_CYCLES);
2934 cycles = GRO_DEFAULT_FLUSH_CYCLES;
2937 gro_flush_cycles = cycles;
2941 show_gro(portid_t port_id)
2943 struct rte_gro_param *param;
2944 uint32_t max_pkts_num;
2946 param = &gro_ports[port_id].param;
2948 if (!rte_eth_dev_is_valid_port(port_id)) {
2949 printf("Invalid port id %u.\n", port_id);
2952 if (gro_ports[port_id].enable) {
2953 printf("GRO type: TCP/IPv4\n");
2954 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2955 max_pkts_num = param->max_flow_num *
2956 param->max_item_per_flow;
2958 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
2959 printf("Max number of packets to perform GRO: %u\n",
2961 printf("Flushing cycles: %u\n", gro_flush_cycles);
2963 printf("Port %u doesn't enable GRO.\n", port_id);
2967 setup_gso(const char *mode, portid_t port_id)
2969 if (!rte_eth_dev_is_valid_port(port_id)) {
2970 printf("invalid port id %u\n", port_id);
2973 if (strcmp(mode, "on") == 0) {
2974 if (test_done == 0) {
2975 printf("before enabling GSO,"
2976 " please stop forwarding first\n");
2979 gso_ports[port_id].enable = 1;
2980 } else if (strcmp(mode, "off") == 0) {
2981 if (test_done == 0) {
2982 printf("before disabling GSO,"
2983 " please stop forwarding first\n");
2986 gso_ports[port_id].enable = 0;
2991 list_pkt_forwarding_modes(void)
2993 static char fwd_modes[128] = "";
2994 const char *separator = "|";
2995 struct fwd_engine *fwd_eng;
2998 if (strlen (fwd_modes) == 0) {
2999 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3000 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3001 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3002 strncat(fwd_modes, separator,
3003 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
3005 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3012 list_pkt_forwarding_retry_modes(void)
3014 static char fwd_modes[128] = "";
3015 const char *separator = "|";
3016 struct fwd_engine *fwd_eng;
3019 if (strlen(fwd_modes) == 0) {
3020 while ((fwd_eng = fwd_engines[i++]) != NULL) {
3021 if (fwd_eng == &rx_only_engine)
3023 strncat(fwd_modes, fwd_eng->fwd_mode_name,
3025 strlen(fwd_modes) - 1);
3026 strncat(fwd_modes, separator,
3028 strlen(fwd_modes) - 1);
3030 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
3037 set_pkt_forwarding_mode(const char *fwd_mode_name)
3039 struct fwd_engine *fwd_eng;
3043 while ((fwd_eng = fwd_engines[i]) != NULL) {
3044 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
3045 printf("Set %s packet forwarding mode%s\n",
3047 retry_enabled == 0 ? "" : " with retry");
3048 cur_fwd_eng = fwd_eng;
3053 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
3057 add_rx_dump_callbacks(portid_t portid)
3059 struct rte_eth_dev_info dev_info;
3063 if (port_id_is_invalid(portid, ENABLED_WARN))
3066 ret = eth_dev_info_get_print_err(portid, &dev_info);
3070 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3071 if (!ports[portid].rx_dump_cb[queue])
3072 ports[portid].rx_dump_cb[queue] =
3073 rte_eth_add_rx_callback(portid, queue,
3074 dump_rx_pkts, NULL);
3078 add_tx_dump_callbacks(portid_t portid)
3080 struct rte_eth_dev_info dev_info;
3084 if (port_id_is_invalid(portid, ENABLED_WARN))
3087 ret = eth_dev_info_get_print_err(portid, &dev_info);
3091 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3092 if (!ports[portid].tx_dump_cb[queue])
3093 ports[portid].tx_dump_cb[queue] =
3094 rte_eth_add_tx_callback(portid, queue,
3095 dump_tx_pkts, NULL);
3099 remove_rx_dump_callbacks(portid_t portid)
3101 struct rte_eth_dev_info dev_info;
3105 if (port_id_is_invalid(portid, ENABLED_WARN))
3108 ret = eth_dev_info_get_print_err(portid, &dev_info);
3112 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
3113 if (ports[portid].rx_dump_cb[queue]) {
3114 rte_eth_remove_rx_callback(portid, queue,
3115 ports[portid].rx_dump_cb[queue]);
3116 ports[portid].rx_dump_cb[queue] = NULL;
3121 remove_tx_dump_callbacks(portid_t portid)
3123 struct rte_eth_dev_info dev_info;
3127 if (port_id_is_invalid(portid, ENABLED_WARN))
3130 ret = eth_dev_info_get_print_err(portid, &dev_info);
3134 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
3135 if (ports[portid].tx_dump_cb[queue]) {
3136 rte_eth_remove_tx_callback(portid, queue,
3137 ports[portid].tx_dump_cb[queue]);
3138 ports[portid].tx_dump_cb[queue] = NULL;
3143 configure_rxtx_dump_callbacks(uint16_t verbose)
3147 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3148 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
3152 RTE_ETH_FOREACH_DEV(portid)
3154 if (verbose == 1 || verbose > 2)
3155 add_rx_dump_callbacks(portid);
3157 remove_rx_dump_callbacks(portid);
3159 add_tx_dump_callbacks(portid);
3161 remove_tx_dump_callbacks(portid);
3166 set_verbose_level(uint16_t vb_level)
3168 printf("Change verbose level from %u to %u\n",
3169 (unsigned int) verbose_level, (unsigned int) vb_level);
3170 verbose_level = vb_level;
3171 configure_rxtx_dump_callbacks(verbose_level);
3175 vlan_extend_set(portid_t port_id, int on)
3179 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3181 if (port_id_is_invalid(port_id, ENABLED_WARN))
3184 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3187 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
3188 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
3190 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
3191 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
3194 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3196 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
3197 "diag=%d\n", port_id, on, diag);
3198 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3202 rx_vlan_strip_set(portid_t port_id, int on)
3206 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3208 if (port_id_is_invalid(port_id, ENABLED_WARN))
3211 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3214 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
3215 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
3217 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
3218 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
3221 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3223 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
3224 "diag=%d\n", port_id, on, diag);
3225 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3229 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
3233 if (port_id_is_invalid(port_id, ENABLED_WARN))
3236 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
3238 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
3239 "diag=%d\n", port_id, queue_id, on, diag);
3243 rx_vlan_filter_set(portid_t port_id, int on)
3247 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3249 if (port_id_is_invalid(port_id, ENABLED_WARN))
3252 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3255 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
3256 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3258 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
3259 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
3262 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3264 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
3265 "diag=%d\n", port_id, on, diag);
3266 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3270 rx_vlan_qinq_strip_set(portid_t port_id, int on)
3274 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
3276 if (port_id_is_invalid(port_id, ENABLED_WARN))
3279 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
3282 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD;
3283 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
3285 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD;
3286 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
3289 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
3291 printf("%s(port_pi=%d, on=%d) failed "
3292 "diag=%d\n", __func__, port_id, on, diag);
3293 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
3297 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
3301 if (port_id_is_invalid(port_id, ENABLED_WARN))
3303 if (vlan_id_is_invalid(vlan_id))
3305 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
3308 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
3310 port_id, vlan_id, on, diag);
3315 rx_vlan_all_filter_set(portid_t port_id, int on)
3319 if (port_id_is_invalid(port_id, ENABLED_WARN))
3321 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
3322 if (rx_vft_set(port_id, vlan_id, on))
3328 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
3332 if (port_id_is_invalid(port_id, ENABLED_WARN))
3335 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
3339 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
3341 port_id, vlan_type, tp_id, diag);
3345 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
3347 struct rte_eth_dev_info dev_info;
3350 if (port_id_is_invalid(port_id, ENABLED_WARN))
3352 if (vlan_id_is_invalid(vlan_id))
3355 if (ports[port_id].dev_conf.txmode.offloads &
3356 DEV_TX_OFFLOAD_QINQ_INSERT) {
3357 printf("Error, as QinQ has been enabled.\n");
3361 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3365 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
3366 printf("Error: vlan insert is not supported by port %d\n",
3371 tx_vlan_reset(port_id);
3372 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
3373 ports[port_id].tx_vlan_id = vlan_id;
3377 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
3379 struct rte_eth_dev_info dev_info;
3382 if (port_id_is_invalid(port_id, ENABLED_WARN))
3384 if (vlan_id_is_invalid(vlan_id))
3386 if (vlan_id_is_invalid(vlan_id_outer))
3389 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3393 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
3394 printf("Error: qinq insert not supported by port %d\n",
3399 tx_vlan_reset(port_id);
3400 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT |
3401 DEV_TX_OFFLOAD_QINQ_INSERT);
3402 ports[port_id].tx_vlan_id = vlan_id;
3403 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
3407 tx_vlan_reset(portid_t port_id)
3409 if (port_id_is_invalid(port_id, ENABLED_WARN))
3411 ports[port_id].dev_conf.txmode.offloads &=
3412 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
3413 DEV_TX_OFFLOAD_QINQ_INSERT);
3414 ports[port_id].tx_vlan_id = 0;
3415 ports[port_id].tx_vlan_id_outer = 0;
3419 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
3421 if (port_id_is_invalid(port_id, ENABLED_WARN))
3424 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
3428 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
3431 uint8_t existing_mapping_found = 0;
3433 if (port_id_is_invalid(port_id, ENABLED_WARN))
3436 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
3439 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
3440 printf("map_value not in required range 0..%d\n",
3441 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
3445 if (!is_rx) { /*then tx*/
3446 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3447 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3448 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
3449 tx_queue_stats_mappings[i].stats_counter_id = map_value;
3450 existing_mapping_found = 1;
3454 if (!existing_mapping_found) { /* A new additional mapping... */
3455 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
3456 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
3457 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
3458 nb_tx_queue_stats_mappings++;
3462 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3463 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3464 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
3465 rx_queue_stats_mappings[i].stats_counter_id = map_value;
3466 existing_mapping_found = 1;
3470 if (!existing_mapping_found) { /* A new additional mapping... */
3471 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
3472 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
3473 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
3474 nb_rx_queue_stats_mappings++;
3480 set_xstats_hide_zero(uint8_t on_off)
3482 xstats_hide_zero = on_off;
3486 print_fdir_mask(struct rte_eth_fdir_masks *mask)
3488 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
3490 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3491 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
3492 " tunnel_id: 0x%08x",
3493 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
3494 rte_be_to_cpu_32(mask->tunnel_id_mask));
3495 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3496 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
3497 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
3498 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
3500 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
3501 rte_be_to_cpu_16(mask->src_port_mask),
3502 rte_be_to_cpu_16(mask->dst_port_mask));
3504 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3505 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
3506 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3507 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3508 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3510 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3511 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3512 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3513 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3514 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3521 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3523 struct rte_eth_flex_payload_cfg *cfg;
3526 for (i = 0; i < flex_conf->nb_payloads; i++) {
3527 cfg = &flex_conf->flex_set[i];
3528 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3530 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3531 printf("\n L2_PAYLOAD: ");
3532 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3533 printf("\n L3_PAYLOAD: ");
3534 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3535 printf("\n L4_PAYLOAD: ");
3537 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3538 for (j = 0; j < num; j++)
3539 printf(" %-5u", cfg->src_offset[j]);
3545 flowtype_to_str(uint16_t flow_type)
3547 struct flow_type_info {
3553 static struct flow_type_info flowtype_str_table[] = {
3554 {"raw", RTE_ETH_FLOW_RAW},
3555 {"ipv4", RTE_ETH_FLOW_IPV4},
3556 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3557 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3558 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3559 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3560 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3561 {"ipv6", RTE_ETH_FLOW_IPV6},
3562 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3563 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3564 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3565 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3566 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3567 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3568 {"port", RTE_ETH_FLOW_PORT},
3569 {"vxlan", RTE_ETH_FLOW_VXLAN},
3570 {"geneve", RTE_ETH_FLOW_GENEVE},
3571 {"nvgre", RTE_ETH_FLOW_NVGRE},
3572 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
3575 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3576 if (flowtype_str_table[i].ftype == flow_type)
3577 return flowtype_str_table[i].str;
3584 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3586 struct rte_eth_fdir_flex_mask *mask;
3590 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3591 mask = &flex_conf->flex_mask[i];
3592 p = flowtype_to_str(mask->flow_type);
3593 printf("\n %s:\t", p ? p : "unknown");
3594 for (j = 0; j < num; j++)
3595 printf(" %02x", mask->mask[j]);
3601 print_fdir_flow_type(uint32_t flow_types_mask)
3606 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3607 if (!(flow_types_mask & (1 << i)))
3609 p = flowtype_to_str(i);
3619 fdir_get_infos(portid_t port_id)
3621 struct rte_eth_fdir_stats fdir_stat;
3622 struct rte_eth_fdir_info fdir_info;
3625 static const char *fdir_stats_border = "########################";
3627 if (port_id_is_invalid(port_id, ENABLED_WARN))
3629 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3631 printf("\n FDIR is not supported on port %-2d\n",
3636 memset(&fdir_info, 0, sizeof(fdir_info));
3637 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3638 RTE_ETH_FILTER_INFO, &fdir_info);
3639 memset(&fdir_stat, 0, sizeof(fdir_stat));
3640 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3641 RTE_ETH_FILTER_STATS, &fdir_stat);
3642 printf("\n %s FDIR infos for port %-2d %s\n",
3643 fdir_stats_border, port_id, fdir_stats_border);
3645 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3646 printf(" PERFECT\n");
3647 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3648 printf(" PERFECT-MAC-VLAN\n");
3649 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3650 printf(" PERFECT-TUNNEL\n");
3651 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3652 printf(" SIGNATURE\n");
3654 printf(" DISABLE\n");
3655 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3656 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3657 printf(" SUPPORTED FLOW TYPE: ");
3658 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3660 printf(" FLEX PAYLOAD INFO:\n");
3661 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3662 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3663 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3664 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3665 fdir_info.flex_payload_unit,
3666 fdir_info.max_flex_payload_segment_num,
3667 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3669 print_fdir_mask(&fdir_info.mask);
3670 if (fdir_info.flex_conf.nb_payloads > 0) {
3671 printf(" FLEX PAYLOAD SRC OFFSET:");
3672 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3674 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3675 printf(" FLEX MASK CFG:");
3676 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3678 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3679 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3680 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3681 fdir_info.guarant_spc, fdir_info.best_spc);
3682 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3683 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3684 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3685 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3686 fdir_stat.collision, fdir_stat.free,
3687 fdir_stat.maxhash, fdir_stat.maxlen,
3688 fdir_stat.add, fdir_stat.remove,
3689 fdir_stat.f_add, fdir_stat.f_remove);
3690 printf(" %s############################%s\n",
3691 fdir_stats_border, fdir_stats_border);
3695 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3697 struct rte_port *port;
3698 struct rte_eth_fdir_flex_conf *flex_conf;
3701 port = &ports[port_id];
3702 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3703 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3704 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3709 if (i >= RTE_ETH_FLOW_MAX) {
3710 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3711 idx = flex_conf->nb_flexmasks;
3712 flex_conf->nb_flexmasks++;
3714 printf("The flex mask table is full. Can not set flex"
3715 " mask for flow_type(%u).", cfg->flow_type);
3719 rte_memcpy(&flex_conf->flex_mask[idx],
3721 sizeof(struct rte_eth_fdir_flex_mask));
3725 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3727 struct rte_port *port;
3728 struct rte_eth_fdir_flex_conf *flex_conf;
3731 port = &ports[port_id];
3732 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3733 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3734 if (cfg->type == flex_conf->flex_set[i].type) {
3739 if (i >= RTE_ETH_PAYLOAD_MAX) {
3740 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3741 idx = flex_conf->nb_payloads;
3742 flex_conf->nb_payloads++;
3744 printf("The flex payload table is full. Can not set"
3745 " flex payload for type(%u).", cfg->type);
3749 rte_memcpy(&flex_conf->flex_set[idx],
3751 sizeof(struct rte_eth_flex_payload_cfg));
3756 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3758 #ifdef RTE_LIBRTE_IXGBE_PMD
3762 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3764 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3768 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3769 is_rx ? "rx" : "tx", port_id, diag);
3772 printf("VF %s setting not supported for port %d\n",
3773 is_rx ? "Rx" : "Tx", port_id);
3779 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3782 struct rte_eth_link link;
3785 if (port_id_is_invalid(port_id, ENABLED_WARN))
3787 ret = eth_link_get_nowait_print_err(port_id, &link);
3790 if (rate > link.link_speed) {
3791 printf("Invalid rate value:%u bigger than link speed: %u\n",
3792 rate, link.link_speed);
3795 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3798 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3804 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3806 int diag = -ENOTSUP;
3810 RTE_SET_USED(q_msk);
3812 #ifdef RTE_LIBRTE_IXGBE_PMD
3813 if (diag == -ENOTSUP)
3814 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3817 #ifdef RTE_LIBRTE_BNXT_PMD
3818 if (diag == -ENOTSUP)
3819 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3824 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3830 * Functions to manage the set of filtered Multicast MAC addresses.
3832 * A pool of filtered multicast MAC addresses is associated with each port.
3833 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3834 * The address of the pool and the number of valid multicast MAC addresses
3835 * recorded in the pool are stored in the fields "mc_addr_pool" and
3836 * "mc_addr_nb" of the "rte_port" data structure.
3838 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3839 * to be supplied a contiguous array of multicast MAC addresses.
3840 * To comply with this constraint, the set of multicast addresses recorded
3841 * into the pool are systematically compacted at the beginning of the pool.
3842 * Hence, when a multicast address is removed from the pool, all following
3843 * addresses, if any, are copied back to keep the set contiguous.
3845 #define MCAST_POOL_INC 32
3848 mcast_addr_pool_extend(struct rte_port *port)
3850 struct rte_ether_addr *mc_pool;
3851 size_t mc_pool_size;
3854 * If a free entry is available at the end of the pool, just
3855 * increment the number of recorded multicast addresses.
3857 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3863 * [re]allocate a pool with MCAST_POOL_INC more entries.
3864 * The previous test guarantees that port->mc_addr_nb is a multiple
3865 * of MCAST_POOL_INC.
3867 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
3869 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
3871 if (mc_pool == NULL) {
3872 printf("allocation of pool of %u multicast addresses failed\n",
3873 port->mc_addr_nb + MCAST_POOL_INC);
3877 port->mc_addr_pool = mc_pool;
3884 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
3886 if (mcast_addr_pool_extend(port) != 0)
3888 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
3892 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3895 if (addr_idx == port->mc_addr_nb) {
3896 /* No need to recompact the set of multicast addressses. */
3897 if (port->mc_addr_nb == 0) {
3898 /* free the pool of multicast addresses. */
3899 free(port->mc_addr_pool);
3900 port->mc_addr_pool = NULL;
3904 memmove(&port->mc_addr_pool[addr_idx],
3905 &port->mc_addr_pool[addr_idx + 1],
3906 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
3910 eth_port_multicast_addr_list_set(portid_t port_id)
3912 struct rte_port *port;
3915 port = &ports[port_id];
3916 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3919 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3920 port_id, port->mc_addr_nb, diag);
3926 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
3928 struct rte_port *port;
3931 if (port_id_is_invalid(port_id, ENABLED_WARN))
3934 port = &ports[port_id];
3937 * Check that the added multicast MAC address is not already recorded
3938 * in the pool of multicast addresses.
3940 for (i = 0; i < port->mc_addr_nb; i++) {
3941 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3942 printf("multicast address already filtered by port\n");
3947 mcast_addr_pool_append(port, mc_addr);
3948 if (eth_port_multicast_addr_list_set(port_id) < 0)
3949 /* Rollback on failure, remove the address from the pool */
3950 mcast_addr_pool_remove(port, i);
3954 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
3956 struct rte_port *port;
3959 if (port_id_is_invalid(port_id, ENABLED_WARN))
3962 port = &ports[port_id];
3965 * Search the pool of multicast MAC addresses for the removed address.
3967 for (i = 0; i < port->mc_addr_nb; i++) {
3968 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3971 if (i == port->mc_addr_nb) {
3972 printf("multicast address not filtered by port %d\n", port_id);
3976 mcast_addr_pool_remove(port, i);
3977 if (eth_port_multicast_addr_list_set(port_id) < 0)
3978 /* Rollback on failure, add the address back into the pool */
3979 mcast_addr_pool_append(port, mc_addr);
3983 port_dcb_info_display(portid_t port_id)
3985 struct rte_eth_dcb_info dcb_info;
3988 static const char *border = "================";
3990 if (port_id_is_invalid(port_id, ENABLED_WARN))
3993 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3995 printf("\n Failed to get dcb infos on port %-2d\n",
3999 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
4000 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
4002 for (i = 0; i < dcb_info.nb_tcs; i++)
4004 printf("\n Priority : ");
4005 for (i = 0; i < dcb_info.nb_tcs; i++)
4006 printf("\t%4d", dcb_info.prio_tc[i]);
4007 printf("\n BW percent :");
4008 for (i = 0; i < dcb_info.nb_tcs; i++)
4009 printf("\t%4d%%", dcb_info.tc_bws[i]);
4010 printf("\n RXQ base : ");
4011 for (i = 0; i < dcb_info.nb_tcs; i++)
4012 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
4013 printf("\n RXQ number :");
4014 for (i = 0; i < dcb_info.nb_tcs; i++)
4015 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
4016 printf("\n TXQ base : ");
4017 for (i = 0; i < dcb_info.nb_tcs; i++)
4018 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
4019 printf("\n TXQ number :");
4020 for (i = 0; i < dcb_info.nb_tcs; i++)
4021 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
4026 open_file(const char *file_path, uint32_t *size)
4028 int fd = open(file_path, O_RDONLY);
4030 uint8_t *buf = NULL;
4038 printf("%s: Failed to open %s\n", __func__, file_path);
4042 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
4044 printf("%s: File operations failed\n", __func__);
4048 pkg_size = st_buf.st_size;
4051 printf("%s: File operations failed\n", __func__);
4055 buf = (uint8_t *)malloc(pkg_size);
4058 printf("%s: Failed to malloc memory\n", __func__);
4062 ret = read(fd, buf, pkg_size);
4065 printf("%s: File read operation failed\n", __func__);
4079 save_file(const char *file_path, uint8_t *buf, uint32_t size)
4081 FILE *fh = fopen(file_path, "wb");
4084 printf("%s: Failed to open %s\n", __func__, file_path);
4088 if (fwrite(buf, 1, size, fh) != size) {
4090 printf("%s: File write operation failed\n", __func__);
4100 close_file(uint8_t *buf)
4111 port_queue_region_info_display(portid_t port_id, void *buf)
4113 #ifdef RTE_LIBRTE_I40E_PMD
4115 struct rte_pmd_i40e_queue_regions *info =
4116 (struct rte_pmd_i40e_queue_regions *)buf;
4117 static const char *queue_region_info_stats_border = "-------";
4119 if (!info->queue_region_number)
4120 printf("there is no region has been set before");
4122 printf("\n %s All queue region info for port=%2d %s",
4123 queue_region_info_stats_border, port_id,
4124 queue_region_info_stats_border);
4125 printf("\n queue_region_number: %-14u \n",
4126 info->queue_region_number);
4128 for (i = 0; i < info->queue_region_number; i++) {
4129 printf("\n region_id: %-14u queue_number: %-14u "
4130 "queue_start_index: %-14u \n",
4131 info->region[i].region_id,
4132 info->region[i].queue_num,
4133 info->region[i].queue_start_index);
4135 printf(" user_priority_num is %-14u :",
4136 info->region[i].user_priority_num);
4137 for (j = 0; j < info->region[i].user_priority_num; j++)
4138 printf(" %-14u ", info->region[i].user_priority[j]);
4140 printf("\n flowtype_num is %-14u :",
4141 info->region[i].flowtype_num);
4142 for (j = 0; j < info->region[i].flowtype_num; j++)
4143 printf(" %-14u ", info->region[i].hw_flowtype[j]);
4146 RTE_SET_USED(port_id);
4154 show_macs(portid_t port_id)
4156 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4157 struct rte_eth_dev_info dev_info;
4158 struct rte_ether_addr *addr;
4159 uint32_t i, num_macs = 0;
4160 struct rte_eth_dev *dev;
4162 dev = &rte_eth_devices[port_id];
4164 rte_eth_dev_info_get(port_id, &dev_info);
4166 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4167 addr = &dev->data->mac_addrs[i];
4169 /* skip zero address */
4170 if (rte_is_zero_ether_addr(addr))
4176 printf("Number of MAC address added: %d\n", num_macs);
4178 for (i = 0; i < dev_info.max_mac_addrs; i++) {
4179 addr = &dev->data->mac_addrs[i];
4181 /* skip zero address */
4182 if (rte_is_zero_ether_addr(addr))
4185 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4186 printf(" %s\n", buf);
4191 show_mcast_macs(portid_t port_id)
4193 char buf[RTE_ETHER_ADDR_FMT_SIZE];
4194 struct rte_ether_addr *addr;
4195 struct rte_port *port;
4198 port = &ports[port_id];
4200 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
4202 for (i = 0; i < port->mc_addr_nb; i++) {
4203 addr = &port->mc_addr_pool[i];
4205 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
4206 printf(" %s\n", buf);