4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5 * Copyright 2013-2014 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/queue.h>
43 #include <sys/types.h>
48 #include <rte_common.h>
49 #include <rte_byteorder.h>
50 #include <rte_debug.h>
52 #include <rte_memory.h>
53 #include <rte_memcpy.h>
54 #include <rte_memzone.h>
55 #include <rte_launch.h>
57 #include <rte_per_lcore.h>
58 #include <rte_lcore.h>
59 #include <rte_atomic.h>
60 #include <rte_branch_prediction.h>
61 #include <rte_mempool.h>
63 #include <rte_interrupts.h>
65 #include <rte_ether.h>
66 #include <rte_ethdev.h>
67 #include <rte_string_fns.h>
68 #include <rte_cycles.h>
70 #include <rte_errno.h>
71 #ifdef RTE_LIBRTE_IXGBE_PMD
72 #include <rte_pmd_ixgbe.h>
74 #ifdef RTE_LIBRTE_I40E_PMD
75 #include <rte_pmd_i40e.h>
77 #ifdef RTE_LIBRTE_BNXT_PMD
78 #include <rte_pmd_bnxt.h>
81 #include <cmdline_parse_etheraddr.h>
85 static char *flowtype_to_str(uint16_t flow_type);
88 enum tx_pkt_split split;
92 .split = TX_PKT_SPLIT_OFF,
96 .split = TX_PKT_SPLIT_ON,
100 .split = TX_PKT_SPLIT_RND,
105 struct rss_type_info {
110 static const struct rss_type_info rss_type_table[] = {
111 { "ipv4", ETH_RSS_IPV4 },
112 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
113 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
114 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
115 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
116 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
117 { "ipv6", ETH_RSS_IPV6 },
118 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
119 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
120 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
121 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
122 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
123 { "l2-payload", ETH_RSS_L2_PAYLOAD },
124 { "ipv6-ex", ETH_RSS_IPV6_EX },
125 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
126 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
127 { "port", ETH_RSS_PORT },
128 { "vxlan", ETH_RSS_VXLAN },
129 { "geneve", ETH_RSS_GENEVE },
130 { "nvgre", ETH_RSS_NVGRE },
135 print_ethaddr(const char *name, struct ether_addr *eth_addr)
137 char buf[ETHER_ADDR_FMT_SIZE];
138 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
139 printf("%s%s", name, buf);
143 nic_stats_display(portid_t port_id)
145 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
146 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
147 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
148 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles;
149 uint64_t mpps_rx, mpps_tx;
150 struct rte_eth_stats stats;
151 struct rte_port *port = &ports[port_id];
155 static const char *nic_stats_border = "########################";
157 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
158 printf("Valid port range is [0");
159 RTE_ETH_FOREACH_DEV(pid)
164 rte_eth_stats_get(port_id, &stats);
165 printf("\n %s NIC statistics for port %-2d %s\n",
166 nic_stats_border, port_id, nic_stats_border);
168 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
169 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
171 stats.ipackets, stats.imissed, stats.ibytes);
172 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
173 printf(" RX-nombuf: %-10"PRIu64"\n",
175 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
177 stats.opackets, stats.oerrors, stats.obytes);
180 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
181 " RX-bytes: %10"PRIu64"\n",
182 stats.ipackets, stats.ierrors, stats.ibytes);
183 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
184 printf(" RX-nombuf: %10"PRIu64"\n",
186 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
187 " TX-bytes: %10"PRIu64"\n",
188 stats.opackets, stats.oerrors, stats.obytes);
191 if (port->rx_queue_stats_mapping_enabled) {
193 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
194 printf(" Stats reg %2d RX-packets: %10"PRIu64
195 " RX-errors: %10"PRIu64
196 " RX-bytes: %10"PRIu64"\n",
197 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
200 if (port->tx_queue_stats_mapping_enabled) {
202 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
203 printf(" Stats reg %2d TX-packets: %10"PRIu64
204 " TX-bytes: %10"PRIu64"\n",
205 i, stats.q_opackets[i], stats.q_obytes[i]);
209 diff_cycles = prev_cycles[port_id];
210 prev_cycles[port_id] = rte_rdtsc();
212 diff_cycles = prev_cycles[port_id] - diff_cycles;
214 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
215 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
216 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
217 (stats.opackets - prev_pkts_tx[port_id]) : 0;
218 prev_pkts_rx[port_id] = stats.ipackets;
219 prev_pkts_tx[port_id] = stats.opackets;
220 mpps_rx = diff_cycles > 0 ?
221 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
222 mpps_tx = diff_cycles > 0 ?
223 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
224 printf("\n Throughput (since last show)\n");
225 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
228 printf(" %s############################%s\n",
229 nic_stats_border, nic_stats_border);
233 nic_stats_clear(portid_t port_id)
237 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
238 printf("Valid port range is [0");
239 RTE_ETH_FOREACH_DEV(pid)
244 rte_eth_stats_reset(port_id);
245 printf("\n NIC statistics for port %d cleared\n", port_id);
249 nic_xstats_display(portid_t port_id)
251 struct rte_eth_xstat *xstats;
252 int cnt_xstats, idx_xstat;
253 struct rte_eth_xstat_name *xstats_names;
255 printf("###### NIC extended statistics for port %-2d\n", port_id);
256 if (!rte_eth_dev_is_valid_port(port_id)) {
257 printf("Error: Invalid port number %i\n", port_id);
262 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
263 if (cnt_xstats < 0) {
264 printf("Error: Cannot get count of xstats\n");
268 /* Get id-name lookup table */
269 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
270 if (xstats_names == NULL) {
271 printf("Cannot allocate memory for xstats lookup\n");
274 if (cnt_xstats != rte_eth_xstats_get_names(
275 port_id, xstats_names, cnt_xstats)) {
276 printf("Error: Cannot get xstats lookup\n");
281 /* Get stats themselves */
282 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
283 if (xstats == NULL) {
284 printf("Cannot allocate memory for xstats\n");
288 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
289 printf("Error: Unable to get xstats\n");
296 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
297 if (xstats_hide_zero && !xstats[idx_xstat].value)
299 printf("%s: %"PRIu64"\n",
300 xstats_names[idx_xstat].name,
301 xstats[idx_xstat].value);
308 nic_xstats_clear(portid_t port_id)
310 rte_eth_xstats_reset(port_id);
314 nic_stats_mapping_display(portid_t port_id)
316 struct rte_port *port = &ports[port_id];
320 static const char *nic_stats_mapping_border = "########################";
322 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
323 printf("Valid port range is [0");
324 RTE_ETH_FOREACH_DEV(pid)
330 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
331 printf("Port id %d - either does not support queue statistic mapping or"
332 " no queue statistic mapping set\n", port_id);
336 printf("\n %s NIC statistics mapping for port %-2d %s\n",
337 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
339 if (port->rx_queue_stats_mapping_enabled) {
340 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
341 if (rx_queue_stats_mappings[i].port_id == port_id) {
342 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
343 rx_queue_stats_mappings[i].queue_id,
344 rx_queue_stats_mappings[i].stats_counter_id);
351 if (port->tx_queue_stats_mapping_enabled) {
352 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
353 if (tx_queue_stats_mappings[i].port_id == port_id) {
354 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
355 tx_queue_stats_mappings[i].queue_id,
356 tx_queue_stats_mappings[i].stats_counter_id);
361 printf(" %s####################################%s\n",
362 nic_stats_mapping_border, nic_stats_mapping_border);
366 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
368 struct rte_eth_rxq_info qinfo;
370 static const char *info_border = "*********************";
372 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
374 printf("Failed to retrieve information for port: %u, "
375 "RX queue: %hu\nerror desc: %s(%d)\n",
376 port_id, queue_id, strerror(-rc), rc);
380 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
381 info_border, port_id, queue_id, info_border);
383 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
384 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
385 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
386 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
387 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
388 printf("\nRX drop packets: %s",
389 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
390 printf("\nRX deferred start: %s",
391 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
392 printf("\nRX scattered packets: %s",
393 (qinfo.scattered_rx != 0) ? "on" : "off");
394 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
399 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
401 struct rte_eth_txq_info qinfo;
403 static const char *info_border = "*********************";
405 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
407 printf("Failed to retrieve information for port: %u, "
408 "TX queue: %hu\nerror desc: %s(%d)\n",
409 port_id, queue_id, strerror(-rc), rc);
413 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
414 info_border, port_id, queue_id, info_border);
416 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
417 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
418 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
419 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
420 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
421 printf("\nTX deferred start: %s",
422 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
423 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
428 port_infos_display(portid_t port_id)
430 struct rte_port *port;
431 struct ether_addr mac_addr;
432 struct rte_eth_link link;
433 struct rte_eth_dev_info dev_info;
435 struct rte_mempool * mp;
436 static const char *info_border = "*********************";
440 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
441 printf("Valid port range is [0");
442 RTE_ETH_FOREACH_DEV(pid)
447 port = &ports[port_id];
448 rte_eth_link_get_nowait(port_id, &link);
449 memset(&dev_info, 0, sizeof(dev_info));
450 rte_eth_dev_info_get(port_id, &dev_info);
451 printf("\n%s Infos for port %-2d %s\n",
452 info_border, port_id, info_border);
453 rte_eth_macaddr_get(port_id, &mac_addr);
454 print_ethaddr("MAC address: ", &mac_addr);
455 printf("\nDriver name: %s", dev_info.driver_name);
456 printf("\nConnect to socket: %u", port->socket_id);
458 if (port_numa[port_id] != NUMA_NO_CONFIG) {
459 mp = mbuf_pool_find(port_numa[port_id]);
461 printf("\nmemory allocation on the socket: %d",
464 printf("\nmemory allocation on the socket: %u",port->socket_id);
466 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
467 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
468 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
469 ("full-duplex") : ("half-duplex"));
471 if (!rte_eth_dev_get_mtu(port_id, &mtu))
472 printf("MTU: %u\n", mtu);
474 printf("Promiscuous mode: %s\n",
475 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
476 printf("Allmulticast mode: %s\n",
477 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
478 printf("Maximum number of MAC addresses: %u\n",
479 (unsigned int)(port->dev_info.max_mac_addrs));
480 printf("Maximum number of MAC addresses of hash filtering: %u\n",
481 (unsigned int)(port->dev_info.max_hash_mac_addrs));
483 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
484 if (vlan_offload >= 0){
485 printf("VLAN offload: \n");
486 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
487 printf(" strip on \n");
489 printf(" strip off \n");
491 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
492 printf(" filter on \n");
494 printf(" filter off \n");
496 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
497 printf(" qinq(extend) on \n");
499 printf(" qinq(extend) off \n");
502 if (dev_info.hash_key_size > 0)
503 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
504 if (dev_info.reta_size > 0)
505 printf("Redirection table size: %u\n", dev_info.reta_size);
506 if (!dev_info.flow_type_rss_offloads)
507 printf("No flow type is supported.\n");
512 printf("Supported flow types:\n");
513 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
514 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
515 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
517 p = flowtype_to_str(i);
521 printf(" user defined %d\n", i);
525 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
526 printf("Maximum configurable length of RX packet: %u\n",
527 dev_info.max_rx_pktlen);
528 if (dev_info.max_vfs)
529 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
530 if (dev_info.max_vmdq_pools)
531 printf("Maximum number of VMDq pools: %u\n",
532 dev_info.max_vmdq_pools);
534 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
535 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
536 printf("Max possible number of RXDs per queue: %hu\n",
537 dev_info.rx_desc_lim.nb_max);
538 printf("Min possible number of RXDs per queue: %hu\n",
539 dev_info.rx_desc_lim.nb_min);
540 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
542 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
543 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
544 printf("Max possible number of TXDs per queue: %hu\n",
545 dev_info.tx_desc_lim.nb_max);
546 printf("Min possible number of TXDs per queue: %hu\n",
547 dev_info.tx_desc_lim.nb_min);
548 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
552 port_offload_cap_display(portid_t port_id)
554 struct rte_eth_dev_info dev_info;
555 static const char *info_border = "************";
557 if (port_id_is_invalid(port_id, ENABLED_WARN))
560 rte_eth_dev_info_get(port_id, &dev_info);
562 printf("\n%s Port %d supported offload features: %s\n",
563 info_border, port_id, info_border);
565 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
566 printf("VLAN stripped: ");
567 if (ports[port_id].dev_conf.rxmode.offloads &
568 DEV_RX_OFFLOAD_VLAN_STRIP)
574 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
575 printf("Double VLANs stripped: ");
576 if (ports[port_id].dev_conf.rxmode.offloads &
577 DEV_RX_OFFLOAD_VLAN_EXTEND)
583 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
584 printf("RX IPv4 checksum: ");
585 if (ports[port_id].dev_conf.rxmode.offloads &
586 DEV_RX_OFFLOAD_IPV4_CKSUM)
592 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
593 printf("RX UDP checksum: ");
594 if (ports[port_id].dev_conf.rxmode.offloads &
595 DEV_RX_OFFLOAD_UDP_CKSUM)
601 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
602 printf("RX TCP checksum: ");
603 if (ports[port_id].dev_conf.rxmode.offloads &
604 DEV_RX_OFFLOAD_TCP_CKSUM)
610 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) {
611 printf("RX Outer IPv4 checksum: ");
612 if (ports[port_id].dev_conf.rxmode.offloads &
613 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
619 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
620 printf("Large receive offload: ");
621 if (ports[port_id].dev_conf.rxmode.offloads &
622 DEV_RX_OFFLOAD_TCP_LRO)
628 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
629 printf("VLAN insert: ");
630 if (ports[port_id].dev_conf.txmode.offloads &
631 DEV_TX_OFFLOAD_VLAN_INSERT)
637 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
638 printf("HW timestamp: ");
639 if (ports[port_id].dev_conf.rxmode.offloads &
640 DEV_RX_OFFLOAD_TIMESTAMP)
646 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
647 printf("Double VLANs insert: ");
648 if (ports[port_id].dev_conf.txmode.offloads &
649 DEV_TX_OFFLOAD_QINQ_INSERT)
655 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
656 printf("TX IPv4 checksum: ");
657 if (ports[port_id].dev_conf.txmode.offloads &
658 DEV_TX_OFFLOAD_IPV4_CKSUM)
664 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
665 printf("TX UDP checksum: ");
666 if (ports[port_id].dev_conf.txmode.offloads &
667 DEV_TX_OFFLOAD_UDP_CKSUM)
673 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
674 printf("TX TCP checksum: ");
675 if (ports[port_id].dev_conf.txmode.offloads &
676 DEV_TX_OFFLOAD_TCP_CKSUM)
682 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
683 printf("TX SCTP checksum: ");
684 if (ports[port_id].dev_conf.txmode.offloads &
685 DEV_TX_OFFLOAD_SCTP_CKSUM)
691 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
692 printf("TX Outer IPv4 checksum: ");
693 if (ports[port_id].dev_conf.txmode.offloads &
694 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
700 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
701 printf("TX TCP segmentation: ");
702 if (ports[port_id].dev_conf.txmode.offloads &
703 DEV_TX_OFFLOAD_TCP_TSO)
709 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
710 printf("TX UDP segmentation: ");
711 if (ports[port_id].dev_conf.txmode.offloads &
712 DEV_TX_OFFLOAD_UDP_TSO)
718 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
719 printf("TSO for VXLAN tunnel packet: ");
720 if (ports[port_id].dev_conf.txmode.offloads &
721 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)
727 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
728 printf("TSO for GRE tunnel packet: ");
729 if (ports[port_id].dev_conf.txmode.offloads &
730 DEV_TX_OFFLOAD_GRE_TNL_TSO)
736 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
737 printf("TSO for IPIP tunnel packet: ");
738 if (ports[port_id].dev_conf.txmode.offloads &
739 DEV_TX_OFFLOAD_IPIP_TNL_TSO)
745 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
746 printf("TSO for GENEVE tunnel packet: ");
747 if (ports[port_id].dev_conf.txmode.offloads &
748 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)
757 port_id_is_invalid(portid_t port_id, enum print_warning warning)
761 if (port_id == (portid_t)RTE_PORT_ALL)
764 RTE_ETH_FOREACH_DEV(pid)
768 if (warning == ENABLED_WARN)
769 printf("Invalid port %d\n", port_id);
775 vlan_id_is_invalid(uint16_t vlan_id)
779 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
784 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
789 printf("Port register offset 0x%X not aligned on a 4-byte "
794 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
795 if (reg_off >= pci_len) {
796 printf("Port %d: register offset %u (0x%X) out of port PCI "
797 "resource (length=%"PRIu64")\n",
798 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
805 reg_bit_pos_is_invalid(uint8_t bit_pos)
809 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
813 #define display_port_and_reg_off(port_id, reg_off) \
814 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
817 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
819 display_port_and_reg_off(port_id, (unsigned)reg_off);
820 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
824 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
829 if (port_id_is_invalid(port_id, ENABLED_WARN))
831 if (port_reg_off_is_invalid(port_id, reg_off))
833 if (reg_bit_pos_is_invalid(bit_x))
835 reg_v = port_id_pci_reg_read(port_id, reg_off);
836 display_port_and_reg_off(port_id, (unsigned)reg_off);
837 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
841 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
842 uint8_t bit1_pos, uint8_t bit2_pos)
848 if (port_id_is_invalid(port_id, ENABLED_WARN))
850 if (port_reg_off_is_invalid(port_id, reg_off))
852 if (reg_bit_pos_is_invalid(bit1_pos))
854 if (reg_bit_pos_is_invalid(bit2_pos))
856 if (bit1_pos > bit2_pos)
857 l_bit = bit2_pos, h_bit = bit1_pos;
859 l_bit = bit1_pos, h_bit = bit2_pos;
861 reg_v = port_id_pci_reg_read(port_id, reg_off);
864 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
865 display_port_and_reg_off(port_id, (unsigned)reg_off);
866 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
867 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
871 port_reg_display(portid_t port_id, uint32_t reg_off)
875 if (port_id_is_invalid(port_id, ENABLED_WARN))
877 if (port_reg_off_is_invalid(port_id, reg_off))
879 reg_v = port_id_pci_reg_read(port_id, reg_off);
880 display_port_reg_value(port_id, reg_off, reg_v);
884 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
889 if (port_id_is_invalid(port_id, ENABLED_WARN))
891 if (port_reg_off_is_invalid(port_id, reg_off))
893 if (reg_bit_pos_is_invalid(bit_pos))
896 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
899 reg_v = port_id_pci_reg_read(port_id, reg_off);
901 reg_v &= ~(1 << bit_pos);
903 reg_v |= (1 << bit_pos);
904 port_id_pci_reg_write(port_id, reg_off, reg_v);
905 display_port_reg_value(port_id, reg_off, reg_v);
909 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
910 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
917 if (port_id_is_invalid(port_id, ENABLED_WARN))
919 if (port_reg_off_is_invalid(port_id, reg_off))
921 if (reg_bit_pos_is_invalid(bit1_pos))
923 if (reg_bit_pos_is_invalid(bit2_pos))
925 if (bit1_pos > bit2_pos)
926 l_bit = bit2_pos, h_bit = bit1_pos;
928 l_bit = bit1_pos, h_bit = bit2_pos;
930 if ((h_bit - l_bit) < 31)
931 max_v = (1 << (h_bit - l_bit + 1)) - 1;
936 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
937 (unsigned)value, (unsigned)value,
938 (unsigned)max_v, (unsigned)max_v);
941 reg_v = port_id_pci_reg_read(port_id, reg_off);
942 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
943 reg_v |= (value << l_bit); /* Set changed bits */
944 port_id_pci_reg_write(port_id, reg_off, reg_v);
945 display_port_reg_value(port_id, reg_off, reg_v);
949 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
951 if (port_id_is_invalid(port_id, ENABLED_WARN))
953 if (port_reg_off_is_invalid(port_id, reg_off))
955 port_id_pci_reg_write(port_id, reg_off, reg_v);
956 display_port_reg_value(port_id, reg_off, reg_v);
960 port_mtu_set(portid_t port_id, uint16_t mtu)
964 if (port_id_is_invalid(port_id, ENABLED_WARN))
966 diag = rte_eth_dev_set_mtu(port_id, mtu);
969 printf("Set MTU failed. diag=%d\n", diag);
972 /* Generic flow management functions. */
974 /** Generate flow_item[] entry. */
975 #define MK_FLOW_ITEM(t, s) \
976 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
981 /** Information about known flow pattern items. */
982 static const struct {
986 MK_FLOW_ITEM(END, 0),
987 MK_FLOW_ITEM(VOID, 0),
988 MK_FLOW_ITEM(INVERT, 0),
989 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
991 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
992 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
993 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
994 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
995 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
996 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
997 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
998 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
999 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
1000 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
1001 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
1002 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
1003 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
1004 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
1005 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
1006 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
1007 MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
1008 MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
1009 MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
1010 MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
1011 MK_FLOW_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
1014 /** Compute storage space needed by item specification. */
1016 flow_item_spec_size(const struct rte_flow_item *item,
1017 size_t *size, size_t *pad)
1023 switch (item->type) {
1025 const struct rte_flow_item_raw *raw;
1028 case RTE_FLOW_ITEM_TYPE_RAW:
1029 spec.raw = item->spec;
1030 *size = offsetof(struct rte_flow_item_raw, pattern) +
1031 spec.raw->length * sizeof(*spec.raw->pattern);
1034 *size = flow_item[item->type].size;
1038 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1041 /** Generate flow_action[] entry. */
1042 #define MK_FLOW_ACTION(t, s) \
1043 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
1048 /** Information about known flow actions. */
1049 static const struct {
1053 MK_FLOW_ACTION(END, 0),
1054 MK_FLOW_ACTION(VOID, 0),
1055 MK_FLOW_ACTION(PASSTHRU, 0),
1056 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1057 MK_FLOW_ACTION(FLAG, 0),
1058 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
1059 MK_FLOW_ACTION(DROP, 0),
1060 MK_FLOW_ACTION(COUNT, 0),
1061 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
1062 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
1063 MK_FLOW_ACTION(PF, 0),
1064 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1065 MK_FLOW_ACTION(METER, sizeof(struct rte_flow_action_meter)),
1068 /** Compute storage space needed by action configuration. */
1070 flow_action_conf_size(const struct rte_flow_action *action,
1071 size_t *size, size_t *pad)
1073 if (!action->conf) {
1077 switch (action->type) {
1079 const struct rte_flow_action_rss *rss;
1082 case RTE_FLOW_ACTION_TYPE_RSS:
1083 conf.rss = action->conf;
1084 *size = offsetof(struct rte_flow_action_rss, queue) +
1085 conf.rss->num * sizeof(*conf.rss->queue);
1088 *size = flow_action[action->type].size;
1092 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1095 /** Generate a port_flow entry from attributes/pattern/actions. */
1096 static struct port_flow *
1097 port_flow_new(const struct rte_flow_attr *attr,
1098 const struct rte_flow_item *pattern,
1099 const struct rte_flow_action *actions)
1101 const struct rte_flow_item *item;
1102 const struct rte_flow_action *action;
1103 struct port_flow *pf = NULL;
1113 pf->pattern = (void *)&pf->data[off1];
1115 struct rte_flow_item *dst = NULL;
1117 if ((unsigned int)item->type >= RTE_DIM(flow_item) ||
1118 !flow_item[item->type].name)
1121 dst = memcpy(pf->data + off1, item, sizeof(*item));
1122 off1 += sizeof(*item);
1123 flow_item_spec_size(item, &tmp, &pad);
1126 dst->spec = memcpy(pf->data + off2,
1132 dst->last = memcpy(pf->data + off2,
1138 dst->mask = memcpy(pf->data + off2,
1142 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1143 } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
1144 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1147 pf->actions = (void *)&pf->data[off1];
1149 struct rte_flow_action *dst = NULL;
1151 if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
1152 !flow_action[action->type].name)
1155 dst = memcpy(pf->data + off1, action, sizeof(*action));
1156 off1 += sizeof(*action);
1157 flow_action_conf_size(action, &tmp, &pad);
1160 dst->conf = memcpy(pf->data + off2,
1164 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1165 } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
1168 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1169 tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double));
1170 pf = calloc(1, tmp + off1 + off2);
1174 *pf = (const struct port_flow){
1175 .size = tmp + off1 + off2,
1178 tmp -= offsetof(struct port_flow, data);
1188 /** Print a message out of a flow error. */
1190 port_flow_complain(struct rte_flow_error *error)
1192 static const char *const errstrlist[] = {
1193 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1194 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1195 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1196 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1197 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1198 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1199 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1200 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1201 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1202 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1203 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1204 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1208 int err = rte_errno;
1210 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1211 !errstrlist[error->type])
1212 errstr = "unknown type";
1214 errstr = errstrlist[error->type];
1215 printf("Caught error type %d (%s): %s%s\n",
1216 error->type, errstr,
1217 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1218 error->cause), buf) : "",
1219 error->message ? error->message : "(no stated reason)");
1223 /** Validate flow rule. */
1225 port_flow_validate(portid_t port_id,
1226 const struct rte_flow_attr *attr,
1227 const struct rte_flow_item *pattern,
1228 const struct rte_flow_action *actions)
1230 struct rte_flow_error error;
1232 /* Poisoning to make sure PMDs update it in case of error. */
1233 memset(&error, 0x11, sizeof(error));
1234 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1235 return port_flow_complain(&error);
1236 printf("Flow rule validated\n");
1240 /** Create flow rule. */
1242 port_flow_create(portid_t port_id,
1243 const struct rte_flow_attr *attr,
1244 const struct rte_flow_item *pattern,
1245 const struct rte_flow_action *actions)
1247 struct rte_flow *flow;
1248 struct rte_port *port;
1249 struct port_flow *pf;
1251 struct rte_flow_error error;
1253 /* Poisoning to make sure PMDs update it in case of error. */
1254 memset(&error, 0x22, sizeof(error));
1255 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1257 return port_flow_complain(&error);
1258 port = &ports[port_id];
1259 if (port->flow_list) {
1260 if (port->flow_list->id == UINT32_MAX) {
1261 printf("Highest rule ID is already assigned, delete"
1263 rte_flow_destroy(port_id, flow, NULL);
1266 id = port->flow_list->id + 1;
1269 pf = port_flow_new(attr, pattern, actions);
1271 int err = rte_errno;
1273 printf("Cannot allocate flow: %s\n", rte_strerror(err));
1274 rte_flow_destroy(port_id, flow, NULL);
1277 pf->next = port->flow_list;
1280 port->flow_list = pf;
1281 printf("Flow rule #%u created\n", pf->id);
1285 /** Destroy a number of flow rules. */
1287 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1289 struct rte_port *port;
1290 struct port_flow **tmp;
1294 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1295 port_id == (portid_t)RTE_PORT_ALL)
1297 port = &ports[port_id];
1298 tmp = &port->flow_list;
1302 for (i = 0; i != n; ++i) {
1303 struct rte_flow_error error;
1304 struct port_flow *pf = *tmp;
1306 if (rule[i] != pf->id)
1309 * Poisoning to make sure PMDs update it in case
1312 memset(&error, 0x33, sizeof(error));
1313 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1314 ret = port_flow_complain(&error);
1317 printf("Flow rule #%u destroyed\n", pf->id);
1323 tmp = &(*tmp)->next;
1329 /** Remove all flow rules. */
1331 port_flow_flush(portid_t port_id)
1333 struct rte_flow_error error;
1334 struct rte_port *port;
1337 /* Poisoning to make sure PMDs update it in case of error. */
1338 memset(&error, 0x44, sizeof(error));
1339 if (rte_flow_flush(port_id, &error)) {
1340 ret = port_flow_complain(&error);
1341 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1342 port_id == (portid_t)RTE_PORT_ALL)
1345 port = &ports[port_id];
1346 while (port->flow_list) {
1347 struct port_flow *pf = port->flow_list->next;
1349 free(port->flow_list);
1350 port->flow_list = pf;
1355 /** Query a flow rule. */
1357 port_flow_query(portid_t port_id, uint32_t rule,
1358 enum rte_flow_action_type action)
1360 struct rte_flow_error error;
1361 struct rte_port *port;
1362 struct port_flow *pf;
1365 struct rte_flow_query_count count;
1368 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1369 port_id == (portid_t)RTE_PORT_ALL)
1371 port = &ports[port_id];
1372 for (pf = port->flow_list; pf; pf = pf->next)
1376 printf("Flow rule #%u not found\n", rule);
1379 if ((unsigned int)action >= RTE_DIM(flow_action) ||
1380 !flow_action[action].name)
1383 name = flow_action[action].name;
1385 case RTE_FLOW_ACTION_TYPE_COUNT:
1388 printf("Cannot query action type %d (%s)\n", action, name);
1391 /* Poisoning to make sure PMDs update it in case of error. */
1392 memset(&error, 0x55, sizeof(error));
1393 memset(&query, 0, sizeof(query));
1394 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1395 return port_flow_complain(&error);
1397 case RTE_FLOW_ACTION_TYPE_COUNT:
1401 " hits: %" PRIu64 "\n"
1402 " bytes: %" PRIu64 "\n",
1404 query.count.hits_set,
1405 query.count.bytes_set,
1410 printf("Cannot display result for action type %d (%s)\n",
1417 /** List flow rules. */
1419 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1421 struct rte_port *port;
1422 struct port_flow *pf;
1423 struct port_flow *list = NULL;
1426 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1427 port_id == (portid_t)RTE_PORT_ALL)
1429 port = &ports[port_id];
1430 if (!port->flow_list)
1432 /* Sort flows by group, priority and ID. */
1433 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1434 struct port_flow **tmp;
1437 /* Filter out unwanted groups. */
1438 for (i = 0; i != n; ++i)
1439 if (pf->attr.group == group[i])
1446 (pf->attr.group > (*tmp)->attr.group ||
1447 (pf->attr.group == (*tmp)->attr.group &&
1448 pf->attr.priority > (*tmp)->attr.priority) ||
1449 (pf->attr.group == (*tmp)->attr.group &&
1450 pf->attr.priority == (*tmp)->attr.priority &&
1451 pf->id > (*tmp)->id)))
1456 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1457 for (pf = list; pf != NULL; pf = pf->tmp) {
1458 const struct rte_flow_item *item = pf->pattern;
1459 const struct rte_flow_action *action = pf->actions;
1461 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t",
1465 pf->attr.ingress ? 'i' : '-',
1466 pf->attr.egress ? 'e' : '-');
1467 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1468 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1469 printf("%s ", flow_item[item->type].name);
1473 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1474 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1475 printf(" %s", flow_action[action->type].name);
1482 /** Restrict ingress traffic to the defined flow rules. */
1484 port_flow_isolate(portid_t port_id, int set)
1486 struct rte_flow_error error;
1488 /* Poisoning to make sure PMDs update it in case of error. */
1489 memset(&error, 0x66, sizeof(error));
1490 if (rte_flow_isolate(port_id, set, &error))
1491 return port_flow_complain(&error);
1492 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1494 set ? "now restricted" : "not restricted anymore");
1499 * RX/TX ring descriptors display functions.
1502 rx_queue_id_is_invalid(queueid_t rxq_id)
1504 if (rxq_id < nb_rxq)
1506 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1511 tx_queue_id_is_invalid(queueid_t txq_id)
1513 if (txq_id < nb_txq)
1515 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1520 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1522 if (rxdesc_id < nb_rxd)
1524 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1530 tx_desc_id_is_invalid(uint16_t txdesc_id)
1532 if (txdesc_id < nb_txd)
1534 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1539 static const struct rte_memzone *
1540 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1542 char mz_name[RTE_MEMZONE_NAMESIZE];
1543 const struct rte_memzone *mz;
1545 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1546 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1547 mz = rte_memzone_lookup(mz_name);
1549 printf("%s ring memory zoneof (port %d, queue %d) not"
1550 "found (zone name = %s\n",
1551 ring_name, port_id, q_id, mz_name);
1555 union igb_ring_dword {
1558 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1568 struct igb_ring_desc_32_bytes {
1569 union igb_ring_dword lo_dword;
1570 union igb_ring_dword hi_dword;
1571 union igb_ring_dword resv1;
1572 union igb_ring_dword resv2;
1575 struct igb_ring_desc_16_bytes {
1576 union igb_ring_dword lo_dword;
1577 union igb_ring_dword hi_dword;
1581 ring_rxd_display_dword(union igb_ring_dword dword)
1583 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1584 (unsigned)dword.words.hi);
1588 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1589 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1592 __rte_unused portid_t port_id,
1596 struct igb_ring_desc_16_bytes *ring =
1597 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1598 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1599 struct rte_eth_dev_info dev_info;
1601 memset(&dev_info, 0, sizeof(dev_info));
1602 rte_eth_dev_info_get(port_id, &dev_info);
1603 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1604 /* 32 bytes RX descriptor, i40e only */
1605 struct igb_ring_desc_32_bytes *ring =
1606 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1607 ring[desc_id].lo_dword.dword =
1608 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1609 ring_rxd_display_dword(ring[desc_id].lo_dword);
1610 ring[desc_id].hi_dword.dword =
1611 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1612 ring_rxd_display_dword(ring[desc_id].hi_dword);
1613 ring[desc_id].resv1.dword =
1614 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1615 ring_rxd_display_dword(ring[desc_id].resv1);
1616 ring[desc_id].resv2.dword =
1617 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1618 ring_rxd_display_dword(ring[desc_id].resv2);
1623 /* 16 bytes RX descriptor */
1624 ring[desc_id].lo_dword.dword =
1625 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1626 ring_rxd_display_dword(ring[desc_id].lo_dword);
1627 ring[desc_id].hi_dword.dword =
1628 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1629 ring_rxd_display_dword(ring[desc_id].hi_dword);
1633 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1635 struct igb_ring_desc_16_bytes *ring;
1636 struct igb_ring_desc_16_bytes txd;
1638 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1639 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1640 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1641 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1642 (unsigned)txd.lo_dword.words.lo,
1643 (unsigned)txd.lo_dword.words.hi,
1644 (unsigned)txd.hi_dword.words.lo,
1645 (unsigned)txd.hi_dword.words.hi);
1649 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1651 const struct rte_memzone *rx_mz;
1653 if (port_id_is_invalid(port_id, ENABLED_WARN))
1655 if (rx_queue_id_is_invalid(rxq_id))
1657 if (rx_desc_id_is_invalid(rxd_id))
1659 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1662 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1666 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1668 const struct rte_memzone *tx_mz;
1670 if (port_id_is_invalid(port_id, ENABLED_WARN))
1672 if (tx_queue_id_is_invalid(txq_id))
1674 if (tx_desc_id_is_invalid(txd_id))
1676 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1679 ring_tx_descriptor_display(tx_mz, txd_id);
1683 fwd_lcores_config_display(void)
1687 printf("List of forwarding lcores:");
1688 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1689 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1693 rxtx_config_display(void)
1697 printf(" %s packet forwarding%s packets/burst=%d\n",
1698 cur_fwd_eng->fwd_mode_name,
1699 retry_enabled == 0 ? "" : " with retry",
1702 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1703 printf(" packet len=%u - nb packet segments=%d\n",
1704 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1706 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1707 nb_fwd_lcores, nb_fwd_ports);
1709 RTE_ETH_FOREACH_DEV(pid) {
1710 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf;
1711 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf;
1713 printf(" port %d:\n", (unsigned int)pid);
1714 printf(" CRC stripping %s\n",
1715 (ports[pid].dev_conf.rxmode.offloads &
1716 DEV_RX_OFFLOAD_CRC_STRIP) ?
1717 "enabled" : "disabled");
1718 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1719 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1720 printf(" RX threshold registers: pthresh=%d hthresh=%d "
1722 rx_conf->rx_thresh.pthresh,
1723 rx_conf->rx_thresh.hthresh,
1724 rx_conf->rx_thresh.wthresh);
1725 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1726 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1727 printf(" TX threshold registers: pthresh=%d hthresh=%d "
1729 tx_conf->tx_thresh.pthresh,
1730 tx_conf->tx_thresh.hthresh,
1731 tx_conf->tx_thresh.wthresh);
1732 printf(" TX RS bit threshold=%d - TXQ offloads=0x%"PRIx64"\n",
1733 tx_conf->tx_rs_thresh, tx_conf->offloads);
1738 port_rss_reta_info(portid_t port_id,
1739 struct rte_eth_rss_reta_entry64 *reta_conf,
1740 uint16_t nb_entries)
1742 uint16_t i, idx, shift;
1745 if (port_id_is_invalid(port_id, ENABLED_WARN))
1748 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1750 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1754 for (i = 0; i < nb_entries; i++) {
1755 idx = i / RTE_RETA_GROUP_SIZE;
1756 shift = i % RTE_RETA_GROUP_SIZE;
1757 if (!(reta_conf[idx].mask & (1ULL << shift)))
1759 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1760 i, reta_conf[idx].reta[shift]);
1765 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1769 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1771 struct rte_eth_rss_conf rss_conf;
1772 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1776 struct rte_eth_dev_info dev_info;
1777 uint8_t hash_key_size;
1779 if (port_id_is_invalid(port_id, ENABLED_WARN))
1782 memset(&dev_info, 0, sizeof(dev_info));
1783 rte_eth_dev_info_get(port_id, &dev_info);
1784 if (dev_info.hash_key_size > 0 &&
1785 dev_info.hash_key_size <= sizeof(rss_key))
1786 hash_key_size = dev_info.hash_key_size;
1788 printf("dev_info did not provide a valid hash key size\n");
1792 rss_conf.rss_hf = 0;
1793 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1794 if (!strcmp(rss_info, rss_type_table[i].str))
1795 rss_conf.rss_hf = rss_type_table[i].rss_type;
1798 /* Get RSS hash key if asked to display it */
1799 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1800 rss_conf.rss_key_len = hash_key_size;
1801 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1805 printf("port index %d invalid\n", port_id);
1808 printf("operation not supported by device\n");
1811 printf("operation failed - diag=%d\n", diag);
1816 rss_hf = rss_conf.rss_hf;
1818 printf("RSS disabled\n");
1821 printf("RSS functions:\n ");
1822 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1823 if (rss_hf & rss_type_table[i].rss_type)
1824 printf("%s ", rss_type_table[i].str);
1829 printf("RSS key:\n");
1830 for (i = 0; i < hash_key_size; i++)
1831 printf("%02X", rss_key[i]);
1836 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1839 struct rte_eth_rss_conf rss_conf;
1843 rss_conf.rss_key = NULL;
1844 rss_conf.rss_key_len = hash_key_len;
1845 rss_conf.rss_hf = 0;
1846 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1847 if (!strcmp(rss_type_table[i].str, rss_type))
1848 rss_conf.rss_hf = rss_type_table[i].rss_type;
1850 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1852 rss_conf.rss_key = hash_key;
1853 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1860 printf("port index %d invalid\n", port_id);
1863 printf("operation not supported by device\n");
1866 printf("operation failed - diag=%d\n", diag);
1872 * Setup forwarding configuration for each logical core.
1875 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1877 streamid_t nb_fs_per_lcore;
1885 nb_fs = cfg->nb_fwd_streams;
1886 nb_fc = cfg->nb_fwd_lcores;
1887 if (nb_fs <= nb_fc) {
1888 nb_fs_per_lcore = 1;
1891 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1892 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1895 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1897 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1898 fwd_lcores[lc_id]->stream_idx = sm_id;
1899 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1900 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1904 * Assign extra remaining streams, if any.
1906 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1907 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1908 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1909 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1910 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1915 simple_fwd_config_setup(void)
1921 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1922 port_topology == PORT_TOPOLOGY_LOOP) {
1924 } else if (nb_fwd_ports % 2) {
1925 printf("\nWarning! Cannot handle an odd number of ports "
1926 "with the current port topology. Configuration "
1927 "must be changed to have an even number of ports, "
1928 "or relaunch application with "
1929 "--port-topology=chained\n\n");
1932 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1933 cur_fwd_config.nb_fwd_streams =
1934 (streamid_t) cur_fwd_config.nb_fwd_ports;
1936 /* reinitialize forwarding streams */
1940 * In the simple forwarding test, the number of forwarding cores
1941 * must be lower or equal to the number of forwarding ports.
1943 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1944 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1945 cur_fwd_config.nb_fwd_lcores =
1946 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1947 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1949 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1950 if (port_topology != PORT_TOPOLOGY_LOOP)
1951 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1954 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1955 fwd_streams[i]->rx_queue = 0;
1956 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1957 fwd_streams[i]->tx_queue = 0;
1958 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
1959 fwd_streams[i]->retry_enabled = retry_enabled;
1961 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1962 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1963 fwd_streams[j]->rx_queue = 0;
1964 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1965 fwd_streams[j]->tx_queue = 0;
1966 fwd_streams[j]->peer_addr = fwd_streams[j]->tx_port;
1967 fwd_streams[j]->retry_enabled = retry_enabled;
1973 * For the RSS forwarding test all streams distributed over lcores. Each stream
1974 * being composed of a RX queue to poll on a RX port for input messages,
1975 * associated with a TX queue of a TX port where to send forwarded packets.
1976 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1977 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1979 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1983 rss_fwd_config_setup(void)
1994 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1995 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1996 cur_fwd_config.nb_fwd_streams =
1997 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1999 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2000 cur_fwd_config.nb_fwd_lcores =
2001 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2003 /* reinitialize forwarding streams */
2006 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2008 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2009 struct fwd_stream *fs;
2011 fs = fwd_streams[sm_id];
2013 if ((rxp & 0x1) == 0)
2014 txp = (portid_t) (rxp + 1);
2016 txp = (portid_t) (rxp - 1);
2018 * if we are in loopback, simply send stuff out through the
2021 if (port_topology == PORT_TOPOLOGY_LOOP)
2024 fs->rx_port = fwd_ports_ids[rxp];
2026 fs->tx_port = fwd_ports_ids[txp];
2028 fs->peer_addr = fs->tx_port;
2029 fs->retry_enabled = retry_enabled;
2030 rxq = (queueid_t) (rxq + 1);
2035 * Restart from RX queue 0 on next RX port
2038 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2040 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2042 rxp = (portid_t) (rxp + 1);
2047 * For the DCB forwarding test, each core is assigned on each traffic class.
2049 * Each core is assigned a multi-stream, each stream being composed of
2050 * a RX queue to poll on a RX port for input messages, associated with
2051 * a TX queue of a TX port where to send forwarded packets. All RX and
2052 * TX queues are mapping to the same traffic class.
2053 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2057 dcb_fwd_config_setup(void)
2059 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2060 portid_t txp, rxp = 0;
2061 queueid_t txq, rxq = 0;
2063 uint16_t nb_rx_queue, nb_tx_queue;
2064 uint16_t i, j, k, sm_id = 0;
2067 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2068 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2069 cur_fwd_config.nb_fwd_streams =
2070 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2072 /* reinitialize forwarding streams */
2076 /* get the dcb info on the first RX and TX ports */
2077 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2078 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2080 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2081 fwd_lcores[lc_id]->stream_nb = 0;
2082 fwd_lcores[lc_id]->stream_idx = sm_id;
2083 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2084 /* if the nb_queue is zero, means this tc is
2085 * not enabled on the POOL
2087 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2089 k = fwd_lcores[lc_id]->stream_nb +
2090 fwd_lcores[lc_id]->stream_idx;
2091 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2092 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2093 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2094 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2095 for (j = 0; j < nb_rx_queue; j++) {
2096 struct fwd_stream *fs;
2098 fs = fwd_streams[k + j];
2099 fs->rx_port = fwd_ports_ids[rxp];
2100 fs->rx_queue = rxq + j;
2101 fs->tx_port = fwd_ports_ids[txp];
2102 fs->tx_queue = txq + j % nb_tx_queue;
2103 fs->peer_addr = fs->tx_port;
2104 fs->retry_enabled = retry_enabled;
2106 fwd_lcores[lc_id]->stream_nb +=
2107 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2109 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2112 if (tc < rxp_dcb_info.nb_tcs)
2114 /* Restart from TC 0 on next RX port */
2116 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2118 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2121 if (rxp >= nb_fwd_ports)
2123 /* get the dcb information on next RX and TX ports */
2124 if ((rxp & 0x1) == 0)
2125 txp = (portid_t) (rxp + 1);
2127 txp = (portid_t) (rxp - 1);
2128 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2129 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2134 icmp_echo_config_setup(void)
2141 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2142 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2143 (nb_txq * nb_fwd_ports);
2145 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2146 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2147 cur_fwd_config.nb_fwd_streams =
2148 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2149 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2150 cur_fwd_config.nb_fwd_lcores =
2151 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2152 if (verbose_level > 0) {
2153 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2155 cur_fwd_config.nb_fwd_lcores,
2156 cur_fwd_config.nb_fwd_ports,
2157 cur_fwd_config.nb_fwd_streams);
2160 /* reinitialize forwarding streams */
2162 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2164 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2165 if (verbose_level > 0)
2166 printf(" core=%d: \n", lc_id);
2167 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2168 struct fwd_stream *fs;
2169 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2170 fs->rx_port = fwd_ports_ids[rxp];
2172 fs->tx_port = fs->rx_port;
2174 fs->peer_addr = fs->tx_port;
2175 fs->retry_enabled = retry_enabled;
2176 if (verbose_level > 0)
2177 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2178 sm_id, fs->rx_port, fs->rx_queue,
2180 rxq = (queueid_t) (rxq + 1);
2181 if (rxq == nb_rxq) {
2183 rxp = (portid_t) (rxp + 1);
2190 fwd_config_setup(void)
2192 cur_fwd_config.fwd_eng = cur_fwd_eng;
2193 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2194 icmp_echo_config_setup();
2197 if ((nb_rxq > 1) && (nb_txq > 1)){
2199 dcb_fwd_config_setup();
2201 rss_fwd_config_setup();
2204 simple_fwd_config_setup();
2208 pkt_fwd_config_display(struct fwd_config *cfg)
2210 struct fwd_stream *fs;
2214 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2215 "NUMA support %s, MP over anonymous pages %s\n",
2216 cfg->fwd_eng->fwd_mode_name,
2217 retry_enabled == 0 ? "" : " with retry",
2218 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2219 numa_support == 1 ? "enabled" : "disabled",
2220 mp_anon != 0 ? "enabled" : "disabled");
2223 printf("TX retry num: %u, delay between TX retries: %uus\n",
2224 burst_tx_retry_num, burst_tx_delay_time);
2225 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2226 printf("Logical Core %u (socket %u) forwards packets on "
2228 fwd_lcores_cpuids[lc_id],
2229 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2230 fwd_lcores[lc_id]->stream_nb);
2231 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2232 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2233 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2234 "P=%d/Q=%d (socket %u) ",
2235 fs->rx_port, fs->rx_queue,
2236 ports[fs->rx_port].socket_id,
2237 fs->tx_port, fs->tx_queue,
2238 ports[fs->tx_port].socket_id);
2239 print_ethaddr("peer=",
2240 &peer_eth_addrs[fs->peer_addr]);
2248 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
2250 uint8_t c, new_peer_addr[6];
2251 if (!rte_eth_dev_is_valid_port(port_id)) {
2252 printf("Error: Invalid port number %i\n", port_id);
2255 if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
2256 sizeof(new_peer_addr)) < 0) {
2257 printf("Error: Invalid ethernet address: %s\n", peer_addr);
2260 for (c = 0; c < 6; c++)
2261 peer_eth_addrs[port_id].addr_bytes[c] =
2266 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2269 unsigned int lcore_cpuid;
2274 for (i = 0; i < nb_lc; i++) {
2275 lcore_cpuid = lcorelist[i];
2276 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2277 printf("lcore %u not enabled\n", lcore_cpuid);
2280 if (lcore_cpuid == rte_get_master_lcore()) {
2281 printf("lcore %u cannot be masked on for running "
2282 "packet forwarding, which is the master lcore "
2283 "and reserved for command line parsing only\n",
2288 fwd_lcores_cpuids[i] = lcore_cpuid;
2290 if (record_now == 0) {
2294 nb_cfg_lcores = (lcoreid_t) nb_lc;
2295 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2296 printf("previous number of forwarding cores %u - changed to "
2297 "number of configured cores %u\n",
2298 (unsigned int) nb_fwd_lcores, nb_lc);
2299 nb_fwd_lcores = (lcoreid_t) nb_lc;
2306 set_fwd_lcores_mask(uint64_t lcoremask)
2308 unsigned int lcorelist[64];
2312 if (lcoremask == 0) {
2313 printf("Invalid NULL mask of cores\n");
2317 for (i = 0; i < 64; i++) {
2318 if (! ((uint64_t)(1ULL << i) & lcoremask))
2320 lcorelist[nb_lc++] = i;
2322 return set_fwd_lcores_list(lcorelist, nb_lc);
2326 set_fwd_lcores_number(uint16_t nb_lc)
2328 if (nb_lc > nb_cfg_lcores) {
2329 printf("nb fwd cores %u > %u (max. number of configured "
2330 "lcores) - ignored\n",
2331 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2334 nb_fwd_lcores = (lcoreid_t) nb_lc;
2335 printf("Number of forwarding cores set to %u\n",
2336 (unsigned int) nb_fwd_lcores);
2340 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2348 for (i = 0; i < nb_pt; i++) {
2349 port_id = (portid_t) portlist[i];
2350 if (port_id_is_invalid(port_id, ENABLED_WARN))
2353 fwd_ports_ids[i] = port_id;
2355 if (record_now == 0) {
2359 nb_cfg_ports = (portid_t) nb_pt;
2360 if (nb_fwd_ports != (portid_t) nb_pt) {
2361 printf("previous number of forwarding ports %u - changed to "
2362 "number of configured ports %u\n",
2363 (unsigned int) nb_fwd_ports, nb_pt);
2364 nb_fwd_ports = (portid_t) nb_pt;
2369 set_fwd_ports_mask(uint64_t portmask)
2371 unsigned int portlist[64];
2375 if (portmask == 0) {
2376 printf("Invalid NULL mask of ports\n");
2380 RTE_ETH_FOREACH_DEV(i) {
2381 if (! ((uint64_t)(1ULL << i) & portmask))
2383 portlist[nb_pt++] = i;
2385 set_fwd_ports_list(portlist, nb_pt);
2389 set_fwd_ports_number(uint16_t nb_pt)
2391 if (nb_pt > nb_cfg_ports) {
2392 printf("nb fwd ports %u > %u (number of configured "
2393 "ports) - ignored\n",
2394 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2397 nb_fwd_ports = (portid_t) nb_pt;
2398 printf("Number of forwarding ports set to %u\n",
2399 (unsigned int) nb_fwd_ports);
2403 port_is_forwarding(portid_t port_id)
2407 if (port_id_is_invalid(port_id, ENABLED_WARN))
2410 for (i = 0; i < nb_fwd_ports; i++) {
2411 if (fwd_ports_ids[i] == port_id)
2419 set_nb_pkt_per_burst(uint16_t nb)
2421 if (nb > MAX_PKT_BURST) {
2422 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2424 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2427 nb_pkt_per_burst = nb;
2428 printf("Number of packets per burst set to %u\n",
2429 (unsigned int) nb_pkt_per_burst);
2433 tx_split_get_name(enum tx_pkt_split split)
2437 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2438 if (tx_split_name[i].split == split)
2439 return tx_split_name[i].name;
2445 set_tx_pkt_split(const char *name)
2449 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2450 if (strcmp(tx_split_name[i].name, name) == 0) {
2451 tx_pkt_split = tx_split_name[i].split;
2455 printf("unknown value: \"%s\"\n", name);
2459 show_tx_pkt_segments(void)
2465 split = tx_split_get_name(tx_pkt_split);
2467 printf("Number of segments: %u\n", n);
2468 printf("Segment sizes: ");
2469 for (i = 0; i != n - 1; i++)
2470 printf("%hu,", tx_pkt_seg_lengths[i]);
2471 printf("%hu\n", tx_pkt_seg_lengths[i]);
2472 printf("Split packet: %s\n", split);
2476 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2478 uint16_t tx_pkt_len;
2481 if (nb_segs >= (unsigned) nb_txd) {
2482 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2483 nb_segs, (unsigned int) nb_txd);
2488 * Check that each segment length is greater or equal than
2489 * the mbuf data sise.
2490 * Check also that the total packet length is greater or equal than the
2491 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2494 for (i = 0; i < nb_segs; i++) {
2495 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2496 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2497 i, seg_lengths[i], (unsigned) mbuf_data_size);
2500 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2502 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2503 printf("total packet length=%u < %d - give up\n",
2504 (unsigned) tx_pkt_len,
2505 (int)(sizeof(struct ether_hdr) + 20 + 8));
2509 for (i = 0; i < nb_segs; i++)
2510 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2512 tx_pkt_length = tx_pkt_len;
2513 tx_pkt_nb_segs = (uint8_t) nb_segs;
2517 setup_gro(const char *onoff, portid_t port_id)
2519 if (!rte_eth_dev_is_valid_port(port_id)) {
2520 printf("invalid port id %u\n", port_id);
2523 if (test_done == 0) {
2524 printf("Before enable/disable GRO,"
2525 " please stop forwarding first\n");
2528 if (strcmp(onoff, "on") == 0) {
2529 if (gro_ports[port_id].enable != 0) {
2530 printf("Port %u has enabled GRO. Please"
2531 " disable GRO first\n", port_id);
2534 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2535 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2536 gro_ports[port_id].param.max_flow_num =
2537 GRO_DEFAULT_FLOW_NUM;
2538 gro_ports[port_id].param.max_item_per_flow =
2539 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2541 gro_ports[port_id].enable = 1;
2543 if (gro_ports[port_id].enable == 0) {
2544 printf("Port %u has disabled GRO\n", port_id);
2547 gro_ports[port_id].enable = 0;
2552 setup_gro_flush_cycles(uint8_t cycles)
2554 if (test_done == 0) {
2555 printf("Before change flush interval for GRO,"
2556 " please stop forwarding first.\n");
2560 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
2561 GRO_DEFAULT_FLUSH_CYCLES) {
2562 printf("The flushing cycle be in the range"
2563 " of 1 to %u. Revert to the default"
2565 GRO_MAX_FLUSH_CYCLES,
2566 GRO_DEFAULT_FLUSH_CYCLES);
2567 cycles = GRO_DEFAULT_FLUSH_CYCLES;
2570 gro_flush_cycles = cycles;
2574 show_gro(portid_t port_id)
2576 struct rte_gro_param *param;
2577 uint32_t max_pkts_num;
2579 param = &gro_ports[port_id].param;
2581 if (!rte_eth_dev_is_valid_port(port_id)) {
2582 printf("Invalid port id %u.\n", port_id);
2585 if (gro_ports[port_id].enable) {
2586 printf("GRO type: TCP/IPv4\n");
2587 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2588 max_pkts_num = param->max_flow_num *
2589 param->max_item_per_flow;
2591 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
2592 printf("Max number of packets to perform GRO: %u\n",
2594 printf("Flushing cycles: %u\n", gro_flush_cycles);
2596 printf("Port %u doesn't enable GRO.\n", port_id);
2600 setup_gso(const char *mode, portid_t port_id)
2602 if (!rte_eth_dev_is_valid_port(port_id)) {
2603 printf("invalid port id %u\n", port_id);
2606 if (strcmp(mode, "on") == 0) {
2607 if (test_done == 0) {
2608 printf("before enabling GSO,"
2609 " please stop forwarding first\n");
2612 gso_ports[port_id].enable = 1;
2613 } else if (strcmp(mode, "off") == 0) {
2614 if (test_done == 0) {
2615 printf("before disabling GSO,"
2616 " please stop forwarding first\n");
2619 gso_ports[port_id].enable = 0;
2624 list_pkt_forwarding_modes(void)
2626 static char fwd_modes[128] = "";
2627 const char *separator = "|";
2628 struct fwd_engine *fwd_eng;
2631 if (strlen (fwd_modes) == 0) {
2632 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2633 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2634 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2635 strncat(fwd_modes, separator,
2636 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2638 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2645 list_pkt_forwarding_retry_modes(void)
2647 static char fwd_modes[128] = "";
2648 const char *separator = "|";
2649 struct fwd_engine *fwd_eng;
2652 if (strlen(fwd_modes) == 0) {
2653 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2654 if (fwd_eng == &rx_only_engine)
2656 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2658 strlen(fwd_modes) - 1);
2659 strncat(fwd_modes, separator,
2661 strlen(fwd_modes) - 1);
2663 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2670 set_pkt_forwarding_mode(const char *fwd_mode_name)
2672 struct fwd_engine *fwd_eng;
2676 while ((fwd_eng = fwd_engines[i]) != NULL) {
2677 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2678 printf("Set %s packet forwarding mode%s\n",
2680 retry_enabled == 0 ? "" : " with retry");
2681 cur_fwd_eng = fwd_eng;
2686 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2690 set_verbose_level(uint16_t vb_level)
2692 printf("Change verbose level from %u to %u\n",
2693 (unsigned int) verbose_level, (unsigned int) vb_level);
2694 verbose_level = vb_level;
2698 vlan_extend_set(portid_t port_id, int on)
2702 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
2704 if (port_id_is_invalid(port_id, ENABLED_WARN))
2707 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2710 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2711 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2713 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2714 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2717 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2719 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2720 "diag=%d\n", port_id, on, diag);
2721 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
2725 rx_vlan_strip_set(portid_t port_id, int on)
2729 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
2731 if (port_id_is_invalid(port_id, ENABLED_WARN))
2734 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2737 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2738 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2740 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2741 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2744 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2746 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2747 "diag=%d\n", port_id, on, diag);
2748 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
2752 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2756 if (port_id_is_invalid(port_id, ENABLED_WARN))
2759 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2761 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2762 "diag=%d\n", port_id, queue_id, on, diag);
2766 rx_vlan_filter_set(portid_t port_id, int on)
2770 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
2772 if (port_id_is_invalid(port_id, ENABLED_WARN))
2775 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2778 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2779 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2781 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2782 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2785 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2787 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2788 "diag=%d\n", port_id, on, diag);
2789 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
2793 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2797 if (port_id_is_invalid(port_id, ENABLED_WARN))
2799 if (vlan_id_is_invalid(vlan_id))
2801 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2804 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2806 port_id, vlan_id, on, diag);
2811 rx_vlan_all_filter_set(portid_t port_id, int on)
2815 if (port_id_is_invalid(port_id, ENABLED_WARN))
2817 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2818 if (rx_vft_set(port_id, vlan_id, on))
2824 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2828 if (port_id_is_invalid(port_id, ENABLED_WARN))
2831 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2835 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2837 port_id, vlan_type, tp_id, diag);
2841 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2844 struct rte_eth_dev_info dev_info;
2846 if (port_id_is_invalid(port_id, ENABLED_WARN))
2848 if (vlan_id_is_invalid(vlan_id))
2851 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2852 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2853 printf("Error, as QinQ has been enabled.\n");
2856 rte_eth_dev_info_get(port_id, &dev_info);
2857 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
2858 printf("Error: vlan insert is not supported by port %d\n",
2863 tx_vlan_reset(port_id);
2864 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
2865 ports[port_id].tx_vlan_id = vlan_id;
2869 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2872 struct rte_eth_dev_info dev_info;
2874 if (port_id_is_invalid(port_id, ENABLED_WARN))
2876 if (vlan_id_is_invalid(vlan_id))
2878 if (vlan_id_is_invalid(vlan_id_outer))
2881 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2882 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2883 printf("Error, as QinQ hasn't been enabled.\n");
2886 rte_eth_dev_info_get(port_id, &dev_info);
2887 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
2888 printf("Error: qinq insert not supported by port %d\n",
2893 tx_vlan_reset(port_id);
2894 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_QINQ_INSERT;
2895 ports[port_id].tx_vlan_id = vlan_id;
2896 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2900 tx_vlan_reset(portid_t port_id)
2902 if (port_id_is_invalid(port_id, ENABLED_WARN))
2904 ports[port_id].dev_conf.txmode.offloads &=
2905 ~(DEV_TX_OFFLOAD_VLAN_INSERT |
2906 DEV_TX_OFFLOAD_QINQ_INSERT);
2907 ports[port_id].tx_vlan_id = 0;
2908 ports[port_id].tx_vlan_id_outer = 0;
2912 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2914 if (port_id_is_invalid(port_id, ENABLED_WARN))
2917 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2921 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2924 uint8_t existing_mapping_found = 0;
2926 if (port_id_is_invalid(port_id, ENABLED_WARN))
2929 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2932 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2933 printf("map_value not in required range 0..%d\n",
2934 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2938 if (!is_rx) { /*then tx*/
2939 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2940 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2941 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2942 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2943 existing_mapping_found = 1;
2947 if (!existing_mapping_found) { /* A new additional mapping... */
2948 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2949 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2950 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2951 nb_tx_queue_stats_mappings++;
2955 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2956 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2957 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2958 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2959 existing_mapping_found = 1;
2963 if (!existing_mapping_found) { /* A new additional mapping... */
2964 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2965 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2966 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2967 nb_rx_queue_stats_mappings++;
2973 set_xstats_hide_zero(uint8_t on_off)
2975 xstats_hide_zero = on_off;
2979 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2981 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2983 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2984 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2985 " tunnel_id: 0x%08x",
2986 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2987 rte_be_to_cpu_32(mask->tunnel_id_mask));
2988 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2989 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2990 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2991 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2993 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2994 rte_be_to_cpu_16(mask->src_port_mask),
2995 rte_be_to_cpu_16(mask->dst_port_mask));
2997 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2998 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2999 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
3000 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
3001 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
3003 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
3004 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
3005 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
3006 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
3007 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
3014 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3016 struct rte_eth_flex_payload_cfg *cfg;
3019 for (i = 0; i < flex_conf->nb_payloads; i++) {
3020 cfg = &flex_conf->flex_set[i];
3021 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
3023 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
3024 printf("\n L2_PAYLOAD: ");
3025 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
3026 printf("\n L3_PAYLOAD: ");
3027 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
3028 printf("\n L4_PAYLOAD: ");
3030 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
3031 for (j = 0; j < num; j++)
3032 printf(" %-5u", cfg->src_offset[j]);
3038 flowtype_to_str(uint16_t flow_type)
3040 struct flow_type_info {
3046 static struct flow_type_info flowtype_str_table[] = {
3047 {"raw", RTE_ETH_FLOW_RAW},
3048 {"ipv4", RTE_ETH_FLOW_IPV4},
3049 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
3050 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
3051 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
3052 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
3053 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
3054 {"ipv6", RTE_ETH_FLOW_IPV6},
3055 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
3056 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
3057 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
3058 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
3059 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
3060 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
3061 {"port", RTE_ETH_FLOW_PORT},
3062 {"vxlan", RTE_ETH_FLOW_VXLAN},
3063 {"geneve", RTE_ETH_FLOW_GENEVE},
3064 {"nvgre", RTE_ETH_FLOW_NVGRE},
3067 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
3068 if (flowtype_str_table[i].ftype == flow_type)
3069 return flowtype_str_table[i].str;
3076 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
3078 struct rte_eth_fdir_flex_mask *mask;
3082 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3083 mask = &flex_conf->flex_mask[i];
3084 p = flowtype_to_str(mask->flow_type);
3085 printf("\n %s:\t", p ? p : "unknown");
3086 for (j = 0; j < num; j++)
3087 printf(" %02x", mask->mask[j]);
3093 print_fdir_flow_type(uint32_t flow_types_mask)
3098 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3099 if (!(flow_types_mask & (1 << i)))
3101 p = flowtype_to_str(i);
3111 fdir_get_infos(portid_t port_id)
3113 struct rte_eth_fdir_stats fdir_stat;
3114 struct rte_eth_fdir_info fdir_info;
3117 static const char *fdir_stats_border = "########################";
3119 if (port_id_is_invalid(port_id, ENABLED_WARN))
3121 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3123 printf("\n FDIR is not supported on port %-2d\n",
3128 memset(&fdir_info, 0, sizeof(fdir_info));
3129 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3130 RTE_ETH_FILTER_INFO, &fdir_info);
3131 memset(&fdir_stat, 0, sizeof(fdir_stat));
3132 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3133 RTE_ETH_FILTER_STATS, &fdir_stat);
3134 printf("\n %s FDIR infos for port %-2d %s\n",
3135 fdir_stats_border, port_id, fdir_stats_border);
3137 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3138 printf(" PERFECT\n");
3139 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3140 printf(" PERFECT-MAC-VLAN\n");
3141 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3142 printf(" PERFECT-TUNNEL\n");
3143 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3144 printf(" SIGNATURE\n");
3146 printf(" DISABLE\n");
3147 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3148 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3149 printf(" SUPPORTED FLOW TYPE: ");
3150 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3152 printf(" FLEX PAYLOAD INFO:\n");
3153 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3154 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3155 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3156 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3157 fdir_info.flex_payload_unit,
3158 fdir_info.max_flex_payload_segment_num,
3159 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3161 print_fdir_mask(&fdir_info.mask);
3162 if (fdir_info.flex_conf.nb_payloads > 0) {
3163 printf(" FLEX PAYLOAD SRC OFFSET:");
3164 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3166 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3167 printf(" FLEX MASK CFG:");
3168 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3170 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3171 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3172 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3173 fdir_info.guarant_spc, fdir_info.best_spc);
3174 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3175 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3176 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3177 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3178 fdir_stat.collision, fdir_stat.free,
3179 fdir_stat.maxhash, fdir_stat.maxlen,
3180 fdir_stat.add, fdir_stat.remove,
3181 fdir_stat.f_add, fdir_stat.f_remove);
3182 printf(" %s############################%s\n",
3183 fdir_stats_border, fdir_stats_border);
3187 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3189 struct rte_port *port;
3190 struct rte_eth_fdir_flex_conf *flex_conf;
3193 port = &ports[port_id];
3194 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3195 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3196 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3201 if (i >= RTE_ETH_FLOW_MAX) {
3202 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3203 idx = flex_conf->nb_flexmasks;
3204 flex_conf->nb_flexmasks++;
3206 printf("The flex mask table is full. Can not set flex"
3207 " mask for flow_type(%u).", cfg->flow_type);
3211 rte_memcpy(&flex_conf->flex_mask[idx],
3213 sizeof(struct rte_eth_fdir_flex_mask));
3217 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3219 struct rte_port *port;
3220 struct rte_eth_fdir_flex_conf *flex_conf;
3223 port = &ports[port_id];
3224 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3225 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3226 if (cfg->type == flex_conf->flex_set[i].type) {
3231 if (i >= RTE_ETH_PAYLOAD_MAX) {
3232 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3233 idx = flex_conf->nb_payloads;
3234 flex_conf->nb_payloads++;
3236 printf("The flex payload table is full. Can not set"
3237 " flex payload for type(%u).", cfg->type);
3241 rte_memcpy(&flex_conf->flex_set[idx],
3243 sizeof(struct rte_eth_flex_payload_cfg));
3248 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3250 #ifdef RTE_LIBRTE_IXGBE_PMD
3254 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3256 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3260 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3261 is_rx ? "rx" : "tx", port_id, diag);
3264 printf("VF %s setting not supported for port %d\n",
3265 is_rx ? "Rx" : "Tx", port_id);
3271 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3274 struct rte_eth_link link;
3276 if (port_id_is_invalid(port_id, ENABLED_WARN))
3278 rte_eth_link_get_nowait(port_id, &link);
3279 if (rate > link.link_speed) {
3280 printf("Invalid rate value:%u bigger than link speed: %u\n",
3281 rate, link.link_speed);
3284 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3287 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3293 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3295 int diag = -ENOTSUP;
3299 RTE_SET_USED(q_msk);
3301 #ifdef RTE_LIBRTE_IXGBE_PMD
3302 if (diag == -ENOTSUP)
3303 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3306 #ifdef RTE_LIBRTE_BNXT_PMD
3307 if (diag == -ENOTSUP)
3308 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3313 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3319 * Functions to manage the set of filtered Multicast MAC addresses.
3321 * A pool of filtered multicast MAC addresses is associated with each port.
3322 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3323 * The address of the pool and the number of valid multicast MAC addresses
3324 * recorded in the pool are stored in the fields "mc_addr_pool" and
3325 * "mc_addr_nb" of the "rte_port" data structure.
3327 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3328 * to be supplied a contiguous array of multicast MAC addresses.
3329 * To comply with this constraint, the set of multicast addresses recorded
3330 * into the pool are systematically compacted at the beginning of the pool.
3331 * Hence, when a multicast address is removed from the pool, all following
3332 * addresses, if any, are copied back to keep the set contiguous.
3334 #define MCAST_POOL_INC 32
3337 mcast_addr_pool_extend(struct rte_port *port)
3339 struct ether_addr *mc_pool;
3340 size_t mc_pool_size;
3343 * If a free entry is available at the end of the pool, just
3344 * increment the number of recorded multicast addresses.
3346 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3352 * [re]allocate a pool with MCAST_POOL_INC more entries.
3353 * The previous test guarantees that port->mc_addr_nb is a multiple
3354 * of MCAST_POOL_INC.
3356 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3358 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3360 if (mc_pool == NULL) {
3361 printf("allocation of pool of %u multicast addresses failed\n",
3362 port->mc_addr_nb + MCAST_POOL_INC);
3366 port->mc_addr_pool = mc_pool;
3373 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3376 if (addr_idx == port->mc_addr_nb) {
3377 /* No need to recompact the set of multicast addressses. */
3378 if (port->mc_addr_nb == 0) {
3379 /* free the pool of multicast addresses. */
3380 free(port->mc_addr_pool);
3381 port->mc_addr_pool = NULL;
3385 memmove(&port->mc_addr_pool[addr_idx],
3386 &port->mc_addr_pool[addr_idx + 1],
3387 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3391 eth_port_multicast_addr_list_set(portid_t port_id)
3393 struct rte_port *port;
3396 port = &ports[port_id];
3397 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3401 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3402 port->mc_addr_nb, port_id, -diag);
3406 mcast_addr_add(portid_t port_id, struct ether_addr *mc_addr)
3408 struct rte_port *port;
3411 if (port_id_is_invalid(port_id, ENABLED_WARN))
3414 port = &ports[port_id];
3417 * Check that the added multicast MAC address is not already recorded
3418 * in the pool of multicast addresses.
3420 for (i = 0; i < port->mc_addr_nb; i++) {
3421 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3422 printf("multicast address already filtered by port\n");
3427 if (mcast_addr_pool_extend(port) != 0)
3429 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3430 eth_port_multicast_addr_list_set(port_id);
3434 mcast_addr_remove(portid_t port_id, struct ether_addr *mc_addr)
3436 struct rte_port *port;
3439 if (port_id_is_invalid(port_id, ENABLED_WARN))
3442 port = &ports[port_id];
3445 * Search the pool of multicast MAC addresses for the removed address.
3447 for (i = 0; i < port->mc_addr_nb; i++) {
3448 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3451 if (i == port->mc_addr_nb) {
3452 printf("multicast address not filtered by port %d\n", port_id);
3456 mcast_addr_pool_remove(port, i);
3457 eth_port_multicast_addr_list_set(port_id);
3461 port_dcb_info_display(portid_t port_id)
3463 struct rte_eth_dcb_info dcb_info;
3466 static const char *border = "================";
3468 if (port_id_is_invalid(port_id, ENABLED_WARN))
3471 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3473 printf("\n Failed to get dcb infos on port %-2d\n",
3477 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3478 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3480 for (i = 0; i < dcb_info.nb_tcs; i++)
3482 printf("\n Priority : ");
3483 for (i = 0; i < dcb_info.nb_tcs; i++)
3484 printf("\t%4d", dcb_info.prio_tc[i]);
3485 printf("\n BW percent :");
3486 for (i = 0; i < dcb_info.nb_tcs; i++)
3487 printf("\t%4d%%", dcb_info.tc_bws[i]);
3488 printf("\n RXQ base : ");
3489 for (i = 0; i < dcb_info.nb_tcs; i++)
3490 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3491 printf("\n RXQ number :");
3492 for (i = 0; i < dcb_info.nb_tcs; i++)
3493 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3494 printf("\n TXQ base : ");
3495 for (i = 0; i < dcb_info.nb_tcs; i++)
3496 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3497 printf("\n TXQ number :");
3498 for (i = 0; i < dcb_info.nb_tcs; i++)
3499 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3504 open_file(const char *file_path, uint32_t *size)
3506 int fd = open(file_path, O_RDONLY);
3508 uint8_t *buf = NULL;
3516 printf("%s: Failed to open %s\n", __func__, file_path);
3520 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
3522 printf("%s: File operations failed\n", __func__);
3526 pkg_size = st_buf.st_size;
3529 printf("%s: File operations failed\n", __func__);
3533 buf = (uint8_t *)malloc(pkg_size);
3536 printf("%s: Failed to malloc memory\n", __func__);
3540 ret = read(fd, buf, pkg_size);
3543 printf("%s: File read operation failed\n", __func__);
3557 save_file(const char *file_path, uint8_t *buf, uint32_t size)
3559 FILE *fh = fopen(file_path, "wb");
3562 printf("%s: Failed to open %s\n", __func__, file_path);
3566 if (fwrite(buf, 1, size, fh) != size) {
3568 printf("%s: File write operation failed\n", __func__);
3578 close_file(uint8_t *buf)
3589 port_queue_region_info_display(portid_t port_id, void *buf)
3591 #ifdef RTE_LIBRTE_I40E_PMD
3593 struct rte_pmd_i40e_queue_regions *info =
3594 (struct rte_pmd_i40e_queue_regions *)buf;
3595 static const char *queue_region_info_stats_border = "-------";
3597 if (!info->queue_region_number)
3598 printf("there is no region has been set before");
3600 printf("\n %s All queue region info for port=%2d %s",
3601 queue_region_info_stats_border, port_id,
3602 queue_region_info_stats_border);
3603 printf("\n queue_region_number: %-14u \n",
3604 info->queue_region_number);
3606 for (i = 0; i < info->queue_region_number; i++) {
3607 printf("\n region_id: %-14u queue_number: %-14u "
3608 "queue_start_index: %-14u \n",
3609 info->region[i].region_id,
3610 info->region[i].queue_num,
3611 info->region[i].queue_start_index);
3613 printf(" user_priority_num is %-14u :",
3614 info->region[i].user_priority_num);
3615 for (j = 0; j < info->region[i].user_priority_num; j++)
3616 printf(" %-14u ", info->region[i].user_priority[j]);
3618 printf("\n flowtype_num is %-14u :",
3619 info->region[i].flowtype_num);
3620 for (j = 0; j < info->region[i].flowtype_num; j++)
3621 printf(" %-14u ", info->region[i].hw_flowtype[j]);
3624 RTE_SET_USED(port_id);