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>
84 static char *flowtype_to_str(uint16_t flow_type);
87 enum tx_pkt_split split;
91 .split = TX_PKT_SPLIT_OFF,
95 .split = TX_PKT_SPLIT_ON,
99 .split = TX_PKT_SPLIT_RND,
104 struct rss_type_info {
109 static const struct rss_type_info rss_type_table[] = {
110 { "ipv4", ETH_RSS_IPV4 },
111 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
112 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
113 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
114 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
115 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
116 { "ipv6", ETH_RSS_IPV6 },
117 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
118 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
119 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
120 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
121 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
122 { "l2-payload", ETH_RSS_L2_PAYLOAD },
123 { "ipv6-ex", ETH_RSS_IPV6_EX },
124 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
125 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
126 { "port", ETH_RSS_PORT },
127 { "vxlan", ETH_RSS_VXLAN },
128 { "geneve", ETH_RSS_GENEVE },
129 { "nvgre", ETH_RSS_NVGRE },
134 print_ethaddr(const char *name, struct ether_addr *eth_addr)
136 char buf[ETHER_ADDR_FMT_SIZE];
137 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
138 printf("%s%s", name, buf);
142 nic_stats_display(portid_t port_id)
144 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
145 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
146 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
147 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles;
148 uint64_t mpps_rx, mpps_tx;
149 struct rte_eth_stats stats;
150 struct rte_port *port = &ports[port_id];
154 static const char *nic_stats_border = "########################";
156 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
157 printf("Valid port range is [0");
158 RTE_ETH_FOREACH_DEV(pid)
163 rte_eth_stats_get(port_id, &stats);
164 printf("\n %s NIC statistics for port %-2d %s\n",
165 nic_stats_border, port_id, nic_stats_border);
167 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
168 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
170 stats.ipackets, stats.imissed, stats.ibytes);
171 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
172 printf(" RX-nombuf: %-10"PRIu64"\n",
174 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
176 stats.opackets, stats.oerrors, stats.obytes);
179 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
180 " RX-bytes: %10"PRIu64"\n",
181 stats.ipackets, stats.ierrors, stats.ibytes);
182 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
183 printf(" RX-nombuf: %10"PRIu64"\n",
185 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
186 " TX-bytes: %10"PRIu64"\n",
187 stats.opackets, stats.oerrors, stats.obytes);
190 if (port->rx_queue_stats_mapping_enabled) {
192 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
193 printf(" Stats reg %2d RX-packets: %10"PRIu64
194 " RX-errors: %10"PRIu64
195 " RX-bytes: %10"PRIu64"\n",
196 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
199 if (port->tx_queue_stats_mapping_enabled) {
201 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
202 printf(" Stats reg %2d TX-packets: %10"PRIu64
203 " TX-bytes: %10"PRIu64"\n",
204 i, stats.q_opackets[i], stats.q_obytes[i]);
208 diff_cycles = prev_cycles[port_id];
209 prev_cycles[port_id] = rte_rdtsc();
211 diff_cycles = prev_cycles[port_id] - diff_cycles;
213 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
214 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
215 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
216 (stats.opackets - prev_pkts_tx[port_id]) : 0;
217 prev_pkts_rx[port_id] = stats.ipackets;
218 prev_pkts_tx[port_id] = stats.opackets;
219 mpps_rx = diff_cycles > 0 ?
220 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
221 mpps_tx = diff_cycles > 0 ?
222 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
223 printf("\n Throughput (since last show)\n");
224 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
227 printf(" %s############################%s\n",
228 nic_stats_border, nic_stats_border);
232 nic_stats_clear(portid_t port_id)
236 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
237 printf("Valid port range is [0");
238 RTE_ETH_FOREACH_DEV(pid)
243 rte_eth_stats_reset(port_id);
244 printf("\n NIC statistics for port %d cleared\n", port_id);
248 nic_xstats_display(portid_t port_id)
250 struct rte_eth_xstat *xstats;
251 int cnt_xstats, idx_xstat;
252 struct rte_eth_xstat_name *xstats_names;
254 printf("###### NIC extended statistics for port %-2d\n", port_id);
255 if (!rte_eth_dev_is_valid_port(port_id)) {
256 printf("Error: Invalid port number %i\n", port_id);
261 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
262 if (cnt_xstats < 0) {
263 printf("Error: Cannot get count of xstats\n");
267 /* Get id-name lookup table */
268 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
269 if (xstats_names == NULL) {
270 printf("Cannot allocate memory for xstats lookup\n");
273 if (cnt_xstats != rte_eth_xstats_get_names(
274 port_id, xstats_names, cnt_xstats)) {
275 printf("Error: Cannot get xstats lookup\n");
280 /* Get stats themselves */
281 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
282 if (xstats == NULL) {
283 printf("Cannot allocate memory for xstats\n");
287 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
288 printf("Error: Unable to get xstats\n");
295 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
296 if (xstats_hide_zero && !xstats[idx_xstat].value)
298 printf("%s: %"PRIu64"\n",
299 xstats_names[idx_xstat].name,
300 xstats[idx_xstat].value);
307 nic_xstats_clear(portid_t port_id)
309 rte_eth_xstats_reset(port_id);
313 nic_stats_mapping_display(portid_t port_id)
315 struct rte_port *port = &ports[port_id];
319 static const char *nic_stats_mapping_border = "########################";
321 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
322 printf("Valid port range is [0");
323 RTE_ETH_FOREACH_DEV(pid)
329 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
330 printf("Port id %d - either does not support queue statistic mapping or"
331 " no queue statistic mapping set\n", port_id);
335 printf("\n %s NIC statistics mapping for port %-2d %s\n",
336 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
338 if (port->rx_queue_stats_mapping_enabled) {
339 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
340 if (rx_queue_stats_mappings[i].port_id == port_id) {
341 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
342 rx_queue_stats_mappings[i].queue_id,
343 rx_queue_stats_mappings[i].stats_counter_id);
350 if (port->tx_queue_stats_mapping_enabled) {
351 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
352 if (tx_queue_stats_mappings[i].port_id == port_id) {
353 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
354 tx_queue_stats_mappings[i].queue_id,
355 tx_queue_stats_mappings[i].stats_counter_id);
360 printf(" %s####################################%s\n",
361 nic_stats_mapping_border, nic_stats_mapping_border);
365 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
367 struct rte_eth_rxq_info qinfo;
369 static const char *info_border = "*********************";
371 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
373 printf("Failed to retrieve information for port: %u, "
374 "RX queue: %hu\nerror desc: %s(%d)\n",
375 port_id, queue_id, strerror(-rc), rc);
379 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
380 info_border, port_id, queue_id, info_border);
382 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
383 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
384 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
385 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
386 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
387 printf("\nRX drop packets: %s",
388 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
389 printf("\nRX deferred start: %s",
390 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
391 printf("\nRX scattered packets: %s",
392 (qinfo.scattered_rx != 0) ? "on" : "off");
393 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
398 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
400 struct rte_eth_txq_info qinfo;
402 static const char *info_border = "*********************";
404 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
406 printf("Failed to retrieve information for port: %u, "
407 "TX queue: %hu\nerror desc: %s(%d)\n",
408 port_id, queue_id, strerror(-rc), rc);
412 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
413 info_border, port_id, queue_id, info_border);
415 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
416 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
417 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
418 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
419 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
420 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
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);
550 printf("Global RX offload capabilities: %"PRIx64"\n",
551 dev_info.rx_offload_capa);
552 printf("Queue RX offload capabilities: %"PRIx64"\n",
553 dev_info.rx_queue_offload_capa);
554 printf("Global TX offload capabilities: %"PRIx64"\n",
555 dev_info.tx_offload_capa);
556 printf("Queue TX offload capabilities: %"PRIx64"\n",
557 dev_info.tx_queue_offload_capa);
561 port_offload_cap_display(portid_t port_id)
563 struct rte_eth_dev *dev;
564 struct rte_eth_dev_info dev_info;
565 static const char *info_border = "************";
567 if (port_id_is_invalid(port_id, ENABLED_WARN))
570 dev = &rte_eth_devices[port_id];
571 rte_eth_dev_info_get(port_id, &dev_info);
573 printf("\n%s Port %d supported offload features: %s\n",
574 info_border, port_id, info_border);
576 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
577 printf("VLAN stripped: ");
578 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
584 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
585 printf("Double VLANs stripped: ");
586 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
592 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
593 printf("RX IPv4 checksum: ");
594 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
600 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
601 printf("RX UDP checksum: ");
602 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
608 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
609 printf("RX TCP checksum: ");
610 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
616 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
617 printf("RX Outer IPv4 checksum: on");
619 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
620 printf("Large receive offload: ");
621 if (dev->data->dev_conf.rxmode.enable_lro)
627 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
628 printf("VLAN insert: ");
629 if (ports[port_id].tx_ol_flags &
630 TESTPMD_TX_OFFLOAD_INSERT_VLAN)
636 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
637 printf("HW timestamp: ");
638 if (dev->data->dev_conf.rxmode.hw_timestamp)
644 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
645 printf("Double VLANs insert: ");
646 if (ports[port_id].tx_ol_flags &
647 TESTPMD_TX_OFFLOAD_INSERT_QINQ)
653 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
654 printf("TX IPv4 checksum: ");
655 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
661 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
662 printf("TX UDP checksum: ");
663 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
669 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
670 printf("TX TCP checksum: ");
671 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
677 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
678 printf("TX SCTP checksum: ");
679 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
685 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
686 printf("TX Outer IPv4 checksum: ");
687 if (ports[port_id].tx_ol_flags &
688 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
694 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
695 printf("TX TCP segmentation: ");
696 if (ports[port_id].tso_segsz != 0)
702 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
703 printf("TX UDP segmentation: ");
704 if (ports[port_id].tso_segsz != 0)
710 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
711 printf("TSO for VXLAN tunnel packet: ");
712 if (ports[port_id].tunnel_tso_segsz)
718 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
719 printf("TSO for GRE tunnel packet: ");
720 if (ports[port_id].tunnel_tso_segsz)
726 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
727 printf("TSO for IPIP tunnel packet: ");
728 if (ports[port_id].tunnel_tso_segsz)
734 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
735 printf("TSO for GENEVE tunnel packet: ");
736 if (ports[port_id].tunnel_tso_segsz)
745 port_id_is_invalid(portid_t port_id, enum print_warning warning)
747 if (port_id == (portid_t)RTE_PORT_ALL)
750 if (rte_eth_dev_is_valid_port(port_id))
753 if (warning == ENABLED_WARN)
754 printf("Invalid port %d\n", port_id);
760 vlan_id_is_invalid(uint16_t vlan_id)
764 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
769 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
774 printf("Port register offset 0x%X not aligned on a 4-byte "
779 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
780 if (reg_off >= pci_len) {
781 printf("Port %d: register offset %u (0x%X) out of port PCI "
782 "resource (length=%"PRIu64")\n",
783 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
790 reg_bit_pos_is_invalid(uint8_t bit_pos)
794 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
798 #define display_port_and_reg_off(port_id, reg_off) \
799 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
802 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
804 display_port_and_reg_off(port_id, (unsigned)reg_off);
805 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
809 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
814 if (port_id_is_invalid(port_id, ENABLED_WARN))
816 if (port_reg_off_is_invalid(port_id, reg_off))
818 if (reg_bit_pos_is_invalid(bit_x))
820 reg_v = port_id_pci_reg_read(port_id, reg_off);
821 display_port_and_reg_off(port_id, (unsigned)reg_off);
822 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
826 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
827 uint8_t bit1_pos, uint8_t bit2_pos)
833 if (port_id_is_invalid(port_id, ENABLED_WARN))
835 if (port_reg_off_is_invalid(port_id, reg_off))
837 if (reg_bit_pos_is_invalid(bit1_pos))
839 if (reg_bit_pos_is_invalid(bit2_pos))
841 if (bit1_pos > bit2_pos)
842 l_bit = bit2_pos, h_bit = bit1_pos;
844 l_bit = bit1_pos, h_bit = bit2_pos;
846 reg_v = port_id_pci_reg_read(port_id, reg_off);
849 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
850 display_port_and_reg_off(port_id, (unsigned)reg_off);
851 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
852 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
856 port_reg_display(portid_t port_id, uint32_t reg_off)
860 if (port_id_is_invalid(port_id, ENABLED_WARN))
862 if (port_reg_off_is_invalid(port_id, reg_off))
864 reg_v = port_id_pci_reg_read(port_id, reg_off);
865 display_port_reg_value(port_id, reg_off, reg_v);
869 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
874 if (port_id_is_invalid(port_id, ENABLED_WARN))
876 if (port_reg_off_is_invalid(port_id, reg_off))
878 if (reg_bit_pos_is_invalid(bit_pos))
881 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
884 reg_v = port_id_pci_reg_read(port_id, reg_off);
886 reg_v &= ~(1 << bit_pos);
888 reg_v |= (1 << bit_pos);
889 port_id_pci_reg_write(port_id, reg_off, reg_v);
890 display_port_reg_value(port_id, reg_off, reg_v);
894 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
895 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
902 if (port_id_is_invalid(port_id, ENABLED_WARN))
904 if (port_reg_off_is_invalid(port_id, reg_off))
906 if (reg_bit_pos_is_invalid(bit1_pos))
908 if (reg_bit_pos_is_invalid(bit2_pos))
910 if (bit1_pos > bit2_pos)
911 l_bit = bit2_pos, h_bit = bit1_pos;
913 l_bit = bit1_pos, h_bit = bit2_pos;
915 if ((h_bit - l_bit) < 31)
916 max_v = (1 << (h_bit - l_bit + 1)) - 1;
921 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
922 (unsigned)value, (unsigned)value,
923 (unsigned)max_v, (unsigned)max_v);
926 reg_v = port_id_pci_reg_read(port_id, reg_off);
927 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
928 reg_v |= (value << l_bit); /* Set changed bits */
929 port_id_pci_reg_write(port_id, reg_off, reg_v);
930 display_port_reg_value(port_id, reg_off, reg_v);
934 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
936 if (port_id_is_invalid(port_id, ENABLED_WARN))
938 if (port_reg_off_is_invalid(port_id, reg_off))
940 port_id_pci_reg_write(port_id, reg_off, reg_v);
941 display_port_reg_value(port_id, reg_off, reg_v);
945 port_mtu_set(portid_t port_id, uint16_t mtu)
949 if (port_id_is_invalid(port_id, ENABLED_WARN))
951 diag = rte_eth_dev_set_mtu(port_id, mtu);
954 printf("Set MTU failed. diag=%d\n", diag);
957 /* Generic flow management functions. */
959 /** Generate flow_item[] entry. */
960 #define MK_FLOW_ITEM(t, s) \
961 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
966 /** Information about known flow pattern items. */
967 static const struct {
971 MK_FLOW_ITEM(END, 0),
972 MK_FLOW_ITEM(VOID, 0),
973 MK_FLOW_ITEM(INVERT, 0),
974 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
976 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
977 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
978 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
979 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
980 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
981 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
982 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
983 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
984 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
985 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
986 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
987 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
988 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
989 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
990 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
991 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
992 MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
993 MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
994 MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
995 MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
998 /** Compute storage space needed by item specification. */
1000 flow_item_spec_size(const struct rte_flow_item *item,
1001 size_t *size, size_t *pad)
1007 switch (item->type) {
1009 const struct rte_flow_item_raw *raw;
1012 case RTE_FLOW_ITEM_TYPE_RAW:
1013 spec.raw = item->spec;
1014 *size = offsetof(struct rte_flow_item_raw, pattern) +
1015 spec.raw->length * sizeof(*spec.raw->pattern);
1018 *size = flow_item[item->type].size;
1022 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1025 /** Generate flow_action[] entry. */
1026 #define MK_FLOW_ACTION(t, s) \
1027 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
1032 /** Information about known flow actions. */
1033 static const struct {
1037 MK_FLOW_ACTION(END, 0),
1038 MK_FLOW_ACTION(VOID, 0),
1039 MK_FLOW_ACTION(PASSTHRU, 0),
1040 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1041 MK_FLOW_ACTION(FLAG, 0),
1042 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
1043 MK_FLOW_ACTION(DROP, 0),
1044 MK_FLOW_ACTION(COUNT, 0),
1045 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
1046 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
1047 MK_FLOW_ACTION(PF, 0),
1048 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1051 /** Compute storage space needed by action configuration. */
1053 flow_action_conf_size(const struct rte_flow_action *action,
1054 size_t *size, size_t *pad)
1056 if (!action->conf) {
1060 switch (action->type) {
1062 const struct rte_flow_action_rss *rss;
1065 case RTE_FLOW_ACTION_TYPE_RSS:
1066 conf.rss = action->conf;
1067 *size = offsetof(struct rte_flow_action_rss, queue) +
1068 conf.rss->num * sizeof(*conf.rss->queue);
1071 *size = flow_action[action->type].size;
1075 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1078 /** Generate a port_flow entry from attributes/pattern/actions. */
1079 static struct port_flow *
1080 port_flow_new(const struct rte_flow_attr *attr,
1081 const struct rte_flow_item *pattern,
1082 const struct rte_flow_action *actions)
1084 const struct rte_flow_item *item;
1085 const struct rte_flow_action *action;
1086 struct port_flow *pf = NULL;
1096 pf->pattern = (void *)&pf->data[off1];
1098 struct rte_flow_item *dst = NULL;
1100 if ((unsigned int)item->type >= RTE_DIM(flow_item) ||
1101 !flow_item[item->type].name)
1104 dst = memcpy(pf->data + off1, item, sizeof(*item));
1105 off1 += sizeof(*item);
1106 flow_item_spec_size(item, &tmp, &pad);
1109 dst->spec = memcpy(pf->data + off2,
1115 dst->last = memcpy(pf->data + off2,
1121 dst->mask = memcpy(pf->data + off2,
1125 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1126 } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
1127 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1130 pf->actions = (void *)&pf->data[off1];
1132 struct rte_flow_action *dst = NULL;
1134 if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
1135 !flow_action[action->type].name)
1138 dst = memcpy(pf->data + off1, action, sizeof(*action));
1139 off1 += sizeof(*action);
1140 flow_action_conf_size(action, &tmp, &pad);
1143 dst->conf = memcpy(pf->data + off2,
1147 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1148 } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
1151 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1152 tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double));
1153 pf = calloc(1, tmp + off1 + off2);
1157 *pf = (const struct port_flow){
1158 .size = tmp + off1 + off2,
1161 tmp -= offsetof(struct port_flow, data);
1171 /** Print a message out of a flow error. */
1173 port_flow_complain(struct rte_flow_error *error)
1175 static const char *const errstrlist[] = {
1176 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1177 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1178 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1179 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1180 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1181 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1182 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1183 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1184 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1185 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1186 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1187 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1191 int err = rte_errno;
1193 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1194 !errstrlist[error->type])
1195 errstr = "unknown type";
1197 errstr = errstrlist[error->type];
1198 printf("Caught error type %d (%s): %s%s\n",
1199 error->type, errstr,
1200 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1201 error->cause), buf) : "",
1202 error->message ? error->message : "(no stated reason)");
1206 /** Validate flow rule. */
1208 port_flow_validate(portid_t port_id,
1209 const struct rte_flow_attr *attr,
1210 const struct rte_flow_item *pattern,
1211 const struct rte_flow_action *actions)
1213 struct rte_flow_error error;
1215 /* Poisoning to make sure PMDs update it in case of error. */
1216 memset(&error, 0x11, sizeof(error));
1217 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1218 return port_flow_complain(&error);
1219 printf("Flow rule validated\n");
1223 /** Create flow rule. */
1225 port_flow_create(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 *flow;
1231 struct rte_port *port;
1232 struct port_flow *pf;
1234 struct rte_flow_error error;
1236 /* Poisoning to make sure PMDs update it in case of error. */
1237 memset(&error, 0x22, sizeof(error));
1238 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1240 return port_flow_complain(&error);
1241 port = &ports[port_id];
1242 if (port->flow_list) {
1243 if (port->flow_list->id == UINT32_MAX) {
1244 printf("Highest rule ID is already assigned, delete"
1246 rte_flow_destroy(port_id, flow, NULL);
1249 id = port->flow_list->id + 1;
1252 pf = port_flow_new(attr, pattern, actions);
1254 int err = rte_errno;
1256 printf("Cannot allocate flow: %s\n", rte_strerror(err));
1257 rte_flow_destroy(port_id, flow, NULL);
1260 pf->next = port->flow_list;
1263 port->flow_list = pf;
1264 printf("Flow rule #%u created\n", pf->id);
1268 /** Destroy a number of flow rules. */
1270 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1272 struct rte_port *port;
1273 struct port_flow **tmp;
1277 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1278 port_id == (portid_t)RTE_PORT_ALL)
1280 port = &ports[port_id];
1281 tmp = &port->flow_list;
1285 for (i = 0; i != n; ++i) {
1286 struct rte_flow_error error;
1287 struct port_flow *pf = *tmp;
1289 if (rule[i] != pf->id)
1292 * Poisoning to make sure PMDs update it in case
1295 memset(&error, 0x33, sizeof(error));
1296 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1297 ret = port_flow_complain(&error);
1300 printf("Flow rule #%u destroyed\n", pf->id);
1306 tmp = &(*tmp)->next;
1312 /** Remove all flow rules. */
1314 port_flow_flush(portid_t port_id)
1316 struct rte_flow_error error;
1317 struct rte_port *port;
1320 /* Poisoning to make sure PMDs update it in case of error. */
1321 memset(&error, 0x44, sizeof(error));
1322 if (rte_flow_flush(port_id, &error)) {
1323 ret = port_flow_complain(&error);
1324 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1325 port_id == (portid_t)RTE_PORT_ALL)
1328 port = &ports[port_id];
1329 while (port->flow_list) {
1330 struct port_flow *pf = port->flow_list->next;
1332 free(port->flow_list);
1333 port->flow_list = pf;
1338 /** Query a flow rule. */
1340 port_flow_query(portid_t port_id, uint32_t rule,
1341 enum rte_flow_action_type action)
1343 struct rte_flow_error error;
1344 struct rte_port *port;
1345 struct port_flow *pf;
1348 struct rte_flow_query_count count;
1351 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1352 port_id == (portid_t)RTE_PORT_ALL)
1354 port = &ports[port_id];
1355 for (pf = port->flow_list; pf; pf = pf->next)
1359 printf("Flow rule #%u not found\n", rule);
1362 if ((unsigned int)action >= RTE_DIM(flow_action) ||
1363 !flow_action[action].name)
1366 name = flow_action[action].name;
1368 case RTE_FLOW_ACTION_TYPE_COUNT:
1371 printf("Cannot query action type %d (%s)\n", action, name);
1374 /* Poisoning to make sure PMDs update it in case of error. */
1375 memset(&error, 0x55, sizeof(error));
1376 memset(&query, 0, sizeof(query));
1377 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1378 return port_flow_complain(&error);
1380 case RTE_FLOW_ACTION_TYPE_COUNT:
1384 " hits: %" PRIu64 "\n"
1385 " bytes: %" PRIu64 "\n",
1387 query.count.hits_set,
1388 query.count.bytes_set,
1393 printf("Cannot display result for action type %d (%s)\n",
1400 /** List flow rules. */
1402 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1404 struct rte_port *port;
1405 struct port_flow *pf;
1406 struct port_flow *list = NULL;
1409 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1410 port_id == (portid_t)RTE_PORT_ALL)
1412 port = &ports[port_id];
1413 if (!port->flow_list)
1415 /* Sort flows by group, priority and ID. */
1416 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1417 struct port_flow **tmp;
1420 /* Filter out unwanted groups. */
1421 for (i = 0; i != n; ++i)
1422 if (pf->attr.group == group[i])
1429 (pf->attr.group > (*tmp)->attr.group ||
1430 (pf->attr.group == (*tmp)->attr.group &&
1431 pf->attr.priority > (*tmp)->attr.priority) ||
1432 (pf->attr.group == (*tmp)->attr.group &&
1433 pf->attr.priority == (*tmp)->attr.priority &&
1434 pf->id > (*tmp)->id)))
1439 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1440 for (pf = list; pf != NULL; pf = pf->tmp) {
1441 const struct rte_flow_item *item = pf->pattern;
1442 const struct rte_flow_action *action = pf->actions;
1444 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t",
1448 pf->attr.ingress ? 'i' : '-',
1449 pf->attr.egress ? 'e' : '-');
1450 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1451 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1452 printf("%s ", flow_item[item->type].name);
1456 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1457 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1458 printf(" %s", flow_action[action->type].name);
1465 /** Restrict ingress traffic to the defined flow rules. */
1467 port_flow_isolate(portid_t port_id, int set)
1469 struct rte_flow_error error;
1471 /* Poisoning to make sure PMDs update it in case of error. */
1472 memset(&error, 0x66, sizeof(error));
1473 if (rte_flow_isolate(port_id, set, &error))
1474 return port_flow_complain(&error);
1475 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1477 set ? "now restricted" : "not restricted anymore");
1482 * RX/TX ring descriptors display functions.
1485 rx_queue_id_is_invalid(queueid_t rxq_id)
1487 if (rxq_id < nb_rxq)
1489 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1494 tx_queue_id_is_invalid(queueid_t txq_id)
1496 if (txq_id < nb_txq)
1498 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1503 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1505 if (rxdesc_id < nb_rxd)
1507 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1513 tx_desc_id_is_invalid(uint16_t txdesc_id)
1515 if (txdesc_id < nb_txd)
1517 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1522 static const struct rte_memzone *
1523 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
1525 char mz_name[RTE_MEMZONE_NAMESIZE];
1526 const struct rte_memzone *mz;
1528 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1529 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1530 mz = rte_memzone_lookup(mz_name);
1532 printf("%s ring memory zoneof (port %d, queue %d) not"
1533 "found (zone name = %s\n",
1534 ring_name, port_id, q_id, mz_name);
1538 union igb_ring_dword {
1541 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1551 struct igb_ring_desc_32_bytes {
1552 union igb_ring_dword lo_dword;
1553 union igb_ring_dword hi_dword;
1554 union igb_ring_dword resv1;
1555 union igb_ring_dword resv2;
1558 struct igb_ring_desc_16_bytes {
1559 union igb_ring_dword lo_dword;
1560 union igb_ring_dword hi_dword;
1564 ring_rxd_display_dword(union igb_ring_dword dword)
1566 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1567 (unsigned)dword.words.hi);
1571 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1572 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1575 __rte_unused portid_t port_id,
1579 struct igb_ring_desc_16_bytes *ring =
1580 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1581 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1582 struct rte_eth_dev_info dev_info;
1584 memset(&dev_info, 0, sizeof(dev_info));
1585 rte_eth_dev_info_get(port_id, &dev_info);
1586 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1587 /* 32 bytes RX descriptor, i40e only */
1588 struct igb_ring_desc_32_bytes *ring =
1589 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1590 ring[desc_id].lo_dword.dword =
1591 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1592 ring_rxd_display_dword(ring[desc_id].lo_dword);
1593 ring[desc_id].hi_dword.dword =
1594 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1595 ring_rxd_display_dword(ring[desc_id].hi_dword);
1596 ring[desc_id].resv1.dword =
1597 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1598 ring_rxd_display_dword(ring[desc_id].resv1);
1599 ring[desc_id].resv2.dword =
1600 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1601 ring_rxd_display_dword(ring[desc_id].resv2);
1606 /* 16 bytes RX descriptor */
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);
1616 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1618 struct igb_ring_desc_16_bytes *ring;
1619 struct igb_ring_desc_16_bytes txd;
1621 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1622 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1623 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1624 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1625 (unsigned)txd.lo_dword.words.lo,
1626 (unsigned)txd.lo_dword.words.hi,
1627 (unsigned)txd.hi_dword.words.lo,
1628 (unsigned)txd.hi_dword.words.hi);
1632 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1634 const struct rte_memzone *rx_mz;
1636 if (port_id_is_invalid(port_id, ENABLED_WARN))
1638 if (rx_queue_id_is_invalid(rxq_id))
1640 if (rx_desc_id_is_invalid(rxd_id))
1642 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1645 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1649 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1651 const struct rte_memzone *tx_mz;
1653 if (port_id_is_invalid(port_id, ENABLED_WARN))
1655 if (tx_queue_id_is_invalid(txq_id))
1657 if (tx_desc_id_is_invalid(txd_id))
1659 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1662 ring_tx_descriptor_display(tx_mz, txd_id);
1666 fwd_lcores_config_display(void)
1670 printf("List of forwarding lcores:");
1671 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1672 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1676 rxtx_config_display(void)
1678 printf(" %s packet forwarding%s - CRC stripping %s - "
1679 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
1680 retry_enabled == 0 ? "" : " with retry",
1681 rx_mode.hw_strip_crc ? "enabled" : "disabled",
1684 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1685 printf(" packet len=%u - nb packet segments=%d\n",
1686 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1688 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
1689 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
1691 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1692 nb_fwd_lcores, nb_fwd_ports);
1693 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1694 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1695 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1696 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
1697 rx_conf->rx_thresh.wthresh);
1698 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1699 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1700 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1701 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
1702 tx_conf->tx_thresh.wthresh);
1703 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
1704 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
1708 port_rss_reta_info(portid_t port_id,
1709 struct rte_eth_rss_reta_entry64 *reta_conf,
1710 uint16_t nb_entries)
1712 uint16_t i, idx, shift;
1715 if (port_id_is_invalid(port_id, ENABLED_WARN))
1718 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1720 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1724 for (i = 0; i < nb_entries; i++) {
1725 idx = i / RTE_RETA_GROUP_SIZE;
1726 shift = i % RTE_RETA_GROUP_SIZE;
1727 if (!(reta_conf[idx].mask & (1ULL << shift)))
1729 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1730 i, reta_conf[idx].reta[shift]);
1735 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1739 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1741 struct rte_eth_rss_conf rss_conf;
1742 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1746 struct rte_eth_dev_info dev_info;
1747 uint8_t hash_key_size;
1749 if (port_id_is_invalid(port_id, ENABLED_WARN))
1752 memset(&dev_info, 0, sizeof(dev_info));
1753 rte_eth_dev_info_get(port_id, &dev_info);
1754 if (dev_info.hash_key_size > 0 &&
1755 dev_info.hash_key_size <= sizeof(rss_key))
1756 hash_key_size = dev_info.hash_key_size;
1758 printf("dev_info did not provide a valid hash key size\n");
1762 rss_conf.rss_hf = 0;
1763 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1764 if (!strcmp(rss_info, rss_type_table[i].str))
1765 rss_conf.rss_hf = rss_type_table[i].rss_type;
1768 /* Get RSS hash key if asked to display it */
1769 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1770 rss_conf.rss_key_len = hash_key_size;
1771 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1775 printf("port index %d invalid\n", port_id);
1778 printf("operation not supported by device\n");
1781 printf("operation failed - diag=%d\n", diag);
1786 rss_hf = rss_conf.rss_hf;
1788 printf("RSS disabled\n");
1791 printf("RSS functions:\n ");
1792 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1793 if (rss_hf & rss_type_table[i].rss_type)
1794 printf("%s ", rss_type_table[i].str);
1799 printf("RSS key:\n");
1800 for (i = 0; i < hash_key_size; i++)
1801 printf("%02X", rss_key[i]);
1806 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1809 struct rte_eth_rss_conf rss_conf;
1813 rss_conf.rss_key = NULL;
1814 rss_conf.rss_key_len = hash_key_len;
1815 rss_conf.rss_hf = 0;
1816 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1817 if (!strcmp(rss_type_table[i].str, rss_type))
1818 rss_conf.rss_hf = rss_type_table[i].rss_type;
1820 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1822 rss_conf.rss_key = hash_key;
1823 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1830 printf("port index %d invalid\n", port_id);
1833 printf("operation not supported by device\n");
1836 printf("operation failed - diag=%d\n", diag);
1842 * Setup forwarding configuration for each logical core.
1845 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1847 streamid_t nb_fs_per_lcore;
1855 nb_fs = cfg->nb_fwd_streams;
1856 nb_fc = cfg->nb_fwd_lcores;
1857 if (nb_fs <= nb_fc) {
1858 nb_fs_per_lcore = 1;
1861 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1862 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1865 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1867 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1868 fwd_lcores[lc_id]->stream_idx = sm_id;
1869 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1870 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1874 * Assign extra remaining streams, if any.
1876 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1877 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1878 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1879 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1880 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1885 simple_fwd_config_setup(void)
1891 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1892 port_topology == PORT_TOPOLOGY_LOOP) {
1894 } else if (nb_fwd_ports % 2) {
1895 printf("\nWarning! Cannot handle an odd number of ports "
1896 "with the current port topology. Configuration "
1897 "must be changed to have an even number of ports, "
1898 "or relaunch application with "
1899 "--port-topology=chained\n\n");
1902 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1903 cur_fwd_config.nb_fwd_streams =
1904 (streamid_t) cur_fwd_config.nb_fwd_ports;
1906 /* reinitialize forwarding streams */
1910 * In the simple forwarding test, the number of forwarding cores
1911 * must be lower or equal to the number of forwarding ports.
1913 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1914 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1915 cur_fwd_config.nb_fwd_lcores =
1916 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1917 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1919 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1920 if (port_topology != PORT_TOPOLOGY_LOOP)
1921 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1924 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1925 fwd_streams[i]->rx_queue = 0;
1926 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1927 fwd_streams[i]->tx_queue = 0;
1928 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
1929 fwd_streams[i]->retry_enabled = retry_enabled;
1931 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1932 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1933 fwd_streams[j]->rx_queue = 0;
1934 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1935 fwd_streams[j]->tx_queue = 0;
1936 fwd_streams[j]->peer_addr = fwd_streams[j]->tx_port;
1937 fwd_streams[j]->retry_enabled = retry_enabled;
1943 * For the RSS forwarding test all streams distributed over lcores. Each stream
1944 * being composed of a RX queue to poll on a RX port for input messages,
1945 * associated with a TX queue of a TX port where to send forwarded packets.
1946 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1947 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1949 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1953 rss_fwd_config_setup(void)
1964 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1965 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1966 cur_fwd_config.nb_fwd_streams =
1967 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1969 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1970 cur_fwd_config.nb_fwd_lcores =
1971 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1973 /* reinitialize forwarding streams */
1976 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1978 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1979 struct fwd_stream *fs;
1981 fs = fwd_streams[sm_id];
1983 if ((rxp & 0x1) == 0)
1984 txp = (portid_t) (rxp + 1);
1986 txp = (portid_t) (rxp - 1);
1988 * if we are in loopback, simply send stuff out through the
1991 if (port_topology == PORT_TOPOLOGY_LOOP)
1994 fs->rx_port = fwd_ports_ids[rxp];
1996 fs->tx_port = fwd_ports_ids[txp];
1998 fs->peer_addr = fs->tx_port;
1999 fs->retry_enabled = retry_enabled;
2000 rxq = (queueid_t) (rxq + 1);
2005 * Restart from RX queue 0 on next RX port
2008 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2010 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2012 rxp = (portid_t) (rxp + 1);
2017 * For the DCB forwarding test, each core is assigned on each traffic class.
2019 * Each core is assigned a multi-stream, each stream being composed of
2020 * a RX queue to poll on a RX port for input messages, associated with
2021 * a TX queue of a TX port where to send forwarded packets. All RX and
2022 * TX queues are mapping to the same traffic class.
2023 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2027 dcb_fwd_config_setup(void)
2029 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2030 portid_t txp, rxp = 0;
2031 queueid_t txq, rxq = 0;
2033 uint16_t nb_rx_queue, nb_tx_queue;
2034 uint16_t i, j, k, sm_id = 0;
2037 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2038 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2039 cur_fwd_config.nb_fwd_streams =
2040 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2042 /* reinitialize forwarding streams */
2046 /* get the dcb info on the first RX and TX ports */
2047 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2048 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2050 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2051 fwd_lcores[lc_id]->stream_nb = 0;
2052 fwd_lcores[lc_id]->stream_idx = sm_id;
2053 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2054 /* if the nb_queue is zero, means this tc is
2055 * not enabled on the POOL
2057 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2059 k = fwd_lcores[lc_id]->stream_nb +
2060 fwd_lcores[lc_id]->stream_idx;
2061 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2062 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2063 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2064 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2065 for (j = 0; j < nb_rx_queue; j++) {
2066 struct fwd_stream *fs;
2068 fs = fwd_streams[k + j];
2069 fs->rx_port = fwd_ports_ids[rxp];
2070 fs->rx_queue = rxq + j;
2071 fs->tx_port = fwd_ports_ids[txp];
2072 fs->tx_queue = txq + j % nb_tx_queue;
2073 fs->peer_addr = fs->tx_port;
2074 fs->retry_enabled = retry_enabled;
2076 fwd_lcores[lc_id]->stream_nb +=
2077 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2079 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2082 if (tc < rxp_dcb_info.nb_tcs)
2084 /* Restart from TC 0 on next RX port */
2086 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2088 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2091 if (rxp >= nb_fwd_ports)
2093 /* get the dcb information on next RX and TX ports */
2094 if ((rxp & 0x1) == 0)
2095 txp = (portid_t) (rxp + 1);
2097 txp = (portid_t) (rxp - 1);
2098 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2099 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2104 icmp_echo_config_setup(void)
2111 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2112 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2113 (nb_txq * nb_fwd_ports);
2115 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2116 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2117 cur_fwd_config.nb_fwd_streams =
2118 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2119 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2120 cur_fwd_config.nb_fwd_lcores =
2121 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2122 if (verbose_level > 0) {
2123 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2125 cur_fwd_config.nb_fwd_lcores,
2126 cur_fwd_config.nb_fwd_ports,
2127 cur_fwd_config.nb_fwd_streams);
2130 /* reinitialize forwarding streams */
2132 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2134 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2135 if (verbose_level > 0)
2136 printf(" core=%d: \n", lc_id);
2137 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2138 struct fwd_stream *fs;
2139 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2140 fs->rx_port = fwd_ports_ids[rxp];
2142 fs->tx_port = fs->rx_port;
2144 fs->peer_addr = fs->tx_port;
2145 fs->retry_enabled = retry_enabled;
2146 if (verbose_level > 0)
2147 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2148 sm_id, fs->rx_port, fs->rx_queue,
2150 rxq = (queueid_t) (rxq + 1);
2151 if (rxq == nb_rxq) {
2153 rxp = (portid_t) (rxp + 1);
2160 fwd_config_setup(void)
2162 cur_fwd_config.fwd_eng = cur_fwd_eng;
2163 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2164 icmp_echo_config_setup();
2167 if ((nb_rxq > 1) && (nb_txq > 1)){
2169 dcb_fwd_config_setup();
2171 rss_fwd_config_setup();
2174 simple_fwd_config_setup();
2178 pkt_fwd_config_display(struct fwd_config *cfg)
2180 struct fwd_stream *fs;
2184 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2185 "NUMA support %s, MP over anonymous pages %s\n",
2186 cfg->fwd_eng->fwd_mode_name,
2187 retry_enabled == 0 ? "" : " with retry",
2188 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2189 numa_support == 1 ? "enabled" : "disabled",
2190 mp_anon != 0 ? "enabled" : "disabled");
2193 printf("TX retry num: %u, delay between TX retries: %uus\n",
2194 burst_tx_retry_num, burst_tx_delay_time);
2195 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2196 printf("Logical Core %u (socket %u) forwards packets on "
2198 fwd_lcores_cpuids[lc_id],
2199 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2200 fwd_lcores[lc_id]->stream_nb);
2201 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2202 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2203 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2204 "P=%d/Q=%d (socket %u) ",
2205 fs->rx_port, fs->rx_queue,
2206 ports[fs->rx_port].socket_id,
2207 fs->tx_port, fs->tx_queue,
2208 ports[fs->tx_port].socket_id);
2209 print_ethaddr("peer=",
2210 &peer_eth_addrs[fs->peer_addr]);
2218 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2221 unsigned int lcore_cpuid;
2226 for (i = 0; i < nb_lc; i++) {
2227 lcore_cpuid = lcorelist[i];
2228 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2229 printf("lcore %u not enabled\n", lcore_cpuid);
2232 if (lcore_cpuid == rte_get_master_lcore()) {
2233 printf("lcore %u cannot be masked on for running "
2234 "packet forwarding, which is the master lcore "
2235 "and reserved for command line parsing only\n",
2240 fwd_lcores_cpuids[i] = lcore_cpuid;
2242 if (record_now == 0) {
2246 nb_cfg_lcores = (lcoreid_t) nb_lc;
2247 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2248 printf("previous number of forwarding cores %u - changed to "
2249 "number of configured cores %u\n",
2250 (unsigned int) nb_fwd_lcores, nb_lc);
2251 nb_fwd_lcores = (lcoreid_t) nb_lc;
2258 set_fwd_lcores_mask(uint64_t lcoremask)
2260 unsigned int lcorelist[64];
2264 if (lcoremask == 0) {
2265 printf("Invalid NULL mask of cores\n");
2269 for (i = 0; i < 64; i++) {
2270 if (! ((uint64_t)(1ULL << i) & lcoremask))
2272 lcorelist[nb_lc++] = i;
2274 return set_fwd_lcores_list(lcorelist, nb_lc);
2278 set_fwd_lcores_number(uint16_t nb_lc)
2280 if (nb_lc > nb_cfg_lcores) {
2281 printf("nb fwd cores %u > %u (max. number of configured "
2282 "lcores) - ignored\n",
2283 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2286 nb_fwd_lcores = (lcoreid_t) nb_lc;
2287 printf("Number of forwarding cores set to %u\n",
2288 (unsigned int) nb_fwd_lcores);
2292 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2300 for (i = 0; i < nb_pt; i++) {
2301 port_id = (portid_t) portlist[i];
2302 if (port_id_is_invalid(port_id, ENABLED_WARN))
2305 fwd_ports_ids[i] = port_id;
2307 if (record_now == 0) {
2311 nb_cfg_ports = (portid_t) nb_pt;
2312 if (nb_fwd_ports != (portid_t) nb_pt) {
2313 printf("previous number of forwarding ports %u - changed to "
2314 "number of configured ports %u\n",
2315 (unsigned int) nb_fwd_ports, nb_pt);
2316 nb_fwd_ports = (portid_t) nb_pt;
2321 set_fwd_ports_mask(uint64_t portmask)
2323 unsigned int portlist[64];
2327 if (portmask == 0) {
2328 printf("Invalid NULL mask of ports\n");
2332 RTE_ETH_FOREACH_DEV(i) {
2333 if (! ((uint64_t)(1ULL << i) & portmask))
2335 portlist[nb_pt++] = i;
2337 set_fwd_ports_list(portlist, nb_pt);
2341 set_fwd_ports_number(uint16_t nb_pt)
2343 if (nb_pt > nb_cfg_ports) {
2344 printf("nb fwd ports %u > %u (number of configured "
2345 "ports) - ignored\n",
2346 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2349 nb_fwd_ports = (portid_t) nb_pt;
2350 printf("Number of forwarding ports set to %u\n",
2351 (unsigned int) nb_fwd_ports);
2355 port_is_forwarding(portid_t port_id)
2359 if (port_id_is_invalid(port_id, ENABLED_WARN))
2362 for (i = 0; i < nb_fwd_ports; i++) {
2363 if (fwd_ports_ids[i] == port_id)
2371 set_nb_pkt_per_burst(uint16_t nb)
2373 if (nb > MAX_PKT_BURST) {
2374 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2376 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2379 nb_pkt_per_burst = nb;
2380 printf("Number of packets per burst set to %u\n",
2381 (unsigned int) nb_pkt_per_burst);
2385 tx_split_get_name(enum tx_pkt_split split)
2389 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2390 if (tx_split_name[i].split == split)
2391 return tx_split_name[i].name;
2397 set_tx_pkt_split(const char *name)
2401 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2402 if (strcmp(tx_split_name[i].name, name) == 0) {
2403 tx_pkt_split = tx_split_name[i].split;
2407 printf("unknown value: \"%s\"\n", name);
2411 show_tx_pkt_segments(void)
2417 split = tx_split_get_name(tx_pkt_split);
2419 printf("Number of segments: %u\n", n);
2420 printf("Segment sizes: ");
2421 for (i = 0; i != n - 1; i++)
2422 printf("%hu,", tx_pkt_seg_lengths[i]);
2423 printf("%hu\n", tx_pkt_seg_lengths[i]);
2424 printf("Split packet: %s\n", split);
2428 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2430 uint16_t tx_pkt_len;
2433 if (nb_segs >= (unsigned) nb_txd) {
2434 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2435 nb_segs, (unsigned int) nb_txd);
2440 * Check that each segment length is greater or equal than
2441 * the mbuf data sise.
2442 * Check also that the total packet length is greater or equal than the
2443 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2446 for (i = 0; i < nb_segs; i++) {
2447 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2448 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2449 i, seg_lengths[i], (unsigned) mbuf_data_size);
2452 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2454 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2455 printf("total packet length=%u < %d - give up\n",
2456 (unsigned) tx_pkt_len,
2457 (int)(sizeof(struct ether_hdr) + 20 + 8));
2461 for (i = 0; i < nb_segs; i++)
2462 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2464 tx_pkt_length = tx_pkt_len;
2465 tx_pkt_nb_segs = (uint8_t) nb_segs;
2469 setup_gro(const char *onoff, portid_t port_id)
2471 if (!rte_eth_dev_is_valid_port(port_id)) {
2472 printf("invalid port id %u\n", port_id);
2475 if (test_done == 0) {
2476 printf("Before enable/disable GRO,"
2477 " please stop forwarding first\n");
2480 if (strcmp(onoff, "on") == 0) {
2481 if (gro_ports[port_id].enable != 0) {
2482 printf("Port %u has enabled GRO. Please"
2483 " disable GRO first\n", port_id);
2486 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2487 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2488 gro_ports[port_id].param.max_flow_num =
2489 GRO_DEFAULT_FLOW_NUM;
2490 gro_ports[port_id].param.max_item_per_flow =
2491 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2493 gro_ports[port_id].enable = 1;
2495 if (gro_ports[port_id].enable == 0) {
2496 printf("Port %u has disabled GRO\n", port_id);
2499 gro_ports[port_id].enable = 0;
2504 setup_gro_flush_cycles(uint8_t cycles)
2506 if (test_done == 0) {
2507 printf("Before change flush interval for GRO,"
2508 " please stop forwarding first.\n");
2512 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
2513 GRO_DEFAULT_FLUSH_CYCLES) {
2514 printf("The flushing cycle be in the range"
2515 " of 1 to %u. Revert to the default"
2517 GRO_MAX_FLUSH_CYCLES,
2518 GRO_DEFAULT_FLUSH_CYCLES);
2519 cycles = GRO_DEFAULT_FLUSH_CYCLES;
2522 gro_flush_cycles = cycles;
2526 show_gro(portid_t port_id)
2528 struct rte_gro_param *param;
2529 uint32_t max_pkts_num;
2531 param = &gro_ports[port_id].param;
2533 if (!rte_eth_dev_is_valid_port(port_id)) {
2534 printf("Invalid port id %u.\n", port_id);
2537 if (gro_ports[port_id].enable) {
2538 printf("GRO type: TCP/IPv4\n");
2539 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2540 max_pkts_num = param->max_flow_num *
2541 param->max_item_per_flow;
2543 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
2544 printf("Max number of packets to perform GRO: %u\n",
2546 printf("Flushing cycles: %u\n", gro_flush_cycles);
2548 printf("Port %u doesn't enable GRO.\n", port_id);
2552 setup_gso(const char *mode, portid_t port_id)
2554 if (!rte_eth_dev_is_valid_port(port_id)) {
2555 printf("invalid port id %u\n", port_id);
2558 if (strcmp(mode, "on") == 0) {
2559 if (test_done == 0) {
2560 printf("before enabling GSO,"
2561 " please stop forwarding first\n");
2564 gso_ports[port_id].enable = 1;
2565 } else if (strcmp(mode, "off") == 0) {
2566 if (test_done == 0) {
2567 printf("before disabling GSO,"
2568 " please stop forwarding first\n");
2571 gso_ports[port_id].enable = 0;
2576 list_pkt_forwarding_modes(void)
2578 static char fwd_modes[128] = "";
2579 const char *separator = "|";
2580 struct fwd_engine *fwd_eng;
2583 if (strlen (fwd_modes) == 0) {
2584 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2585 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2586 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2587 strncat(fwd_modes, separator,
2588 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2590 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2597 list_pkt_forwarding_retry_modes(void)
2599 static char fwd_modes[128] = "";
2600 const char *separator = "|";
2601 struct fwd_engine *fwd_eng;
2604 if (strlen(fwd_modes) == 0) {
2605 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2606 if (fwd_eng == &rx_only_engine)
2608 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2610 strlen(fwd_modes) - 1);
2611 strncat(fwd_modes, separator,
2613 strlen(fwd_modes) - 1);
2615 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2622 set_pkt_forwarding_mode(const char *fwd_mode_name)
2624 struct fwd_engine *fwd_eng;
2628 while ((fwd_eng = fwd_engines[i]) != NULL) {
2629 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2630 printf("Set %s packet forwarding mode%s\n",
2632 retry_enabled == 0 ? "" : " with retry");
2633 cur_fwd_eng = fwd_eng;
2638 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2642 set_verbose_level(uint16_t vb_level)
2644 printf("Change verbose level from %u to %u\n",
2645 (unsigned int) verbose_level, (unsigned int) vb_level);
2646 verbose_level = vb_level;
2650 vlan_extend_set(portid_t port_id, int on)
2655 if (port_id_is_invalid(port_id, ENABLED_WARN))
2658 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2661 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2663 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2665 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2667 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2668 "diag=%d\n", port_id, on, diag);
2672 rx_vlan_strip_set(portid_t port_id, int on)
2677 if (port_id_is_invalid(port_id, ENABLED_WARN))
2680 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2683 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2685 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2687 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2689 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2690 "diag=%d\n", port_id, on, diag);
2694 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2698 if (port_id_is_invalid(port_id, ENABLED_WARN))
2701 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2703 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2704 "diag=%d\n", port_id, queue_id, on, diag);
2708 rx_vlan_filter_set(portid_t port_id, int on)
2713 if (port_id_is_invalid(port_id, ENABLED_WARN))
2716 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2719 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2721 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2723 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2725 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2726 "diag=%d\n", port_id, on, diag);
2730 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2734 if (port_id_is_invalid(port_id, ENABLED_WARN))
2736 if (vlan_id_is_invalid(vlan_id))
2738 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2741 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2743 port_id, vlan_id, on, diag);
2748 rx_vlan_all_filter_set(portid_t port_id, int on)
2752 if (port_id_is_invalid(port_id, ENABLED_WARN))
2754 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2755 if (rx_vft_set(port_id, vlan_id, on))
2761 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2765 if (port_id_is_invalid(port_id, ENABLED_WARN))
2768 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2772 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2774 port_id, vlan_type, tp_id, diag);
2778 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2781 if (port_id_is_invalid(port_id, ENABLED_WARN))
2783 if (vlan_id_is_invalid(vlan_id))
2786 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2787 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2788 printf("Error, as QinQ has been enabled.\n");
2792 tx_vlan_reset(port_id);
2793 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
2794 ports[port_id].tx_vlan_id = vlan_id;
2798 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2801 if (port_id_is_invalid(port_id, ENABLED_WARN))
2803 if (vlan_id_is_invalid(vlan_id))
2805 if (vlan_id_is_invalid(vlan_id_outer))
2808 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2809 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2810 printf("Error, as QinQ hasn't been enabled.\n");
2814 tx_vlan_reset(port_id);
2815 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
2816 ports[port_id].tx_vlan_id = vlan_id;
2817 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2821 tx_vlan_reset(portid_t port_id)
2823 if (port_id_is_invalid(port_id, ENABLED_WARN))
2825 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
2826 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
2827 ports[port_id].tx_vlan_id = 0;
2828 ports[port_id].tx_vlan_id_outer = 0;
2832 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2834 if (port_id_is_invalid(port_id, ENABLED_WARN))
2837 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2841 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2844 uint8_t existing_mapping_found = 0;
2846 if (port_id_is_invalid(port_id, ENABLED_WARN))
2849 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2852 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2853 printf("map_value not in required range 0..%d\n",
2854 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2858 if (!is_rx) { /*then tx*/
2859 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2860 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2861 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2862 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2863 existing_mapping_found = 1;
2867 if (!existing_mapping_found) { /* A new additional mapping... */
2868 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2869 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2870 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2871 nb_tx_queue_stats_mappings++;
2875 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2876 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2877 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2878 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2879 existing_mapping_found = 1;
2883 if (!existing_mapping_found) { /* A new additional mapping... */
2884 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2885 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2886 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2887 nb_rx_queue_stats_mappings++;
2893 set_xstats_hide_zero(uint8_t on_off)
2895 xstats_hide_zero = on_off;
2899 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2901 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2903 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2904 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2905 " tunnel_id: 0x%08x",
2906 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2907 rte_be_to_cpu_32(mask->tunnel_id_mask));
2908 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2909 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2910 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2911 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2913 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2914 rte_be_to_cpu_16(mask->src_port_mask),
2915 rte_be_to_cpu_16(mask->dst_port_mask));
2917 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2918 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2919 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
2920 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
2921 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
2923 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2924 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
2925 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
2926 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
2927 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
2934 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2936 struct rte_eth_flex_payload_cfg *cfg;
2939 for (i = 0; i < flex_conf->nb_payloads; i++) {
2940 cfg = &flex_conf->flex_set[i];
2941 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2943 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2944 printf("\n L2_PAYLOAD: ");
2945 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2946 printf("\n L3_PAYLOAD: ");
2947 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2948 printf("\n L4_PAYLOAD: ");
2950 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2951 for (j = 0; j < num; j++)
2952 printf(" %-5u", cfg->src_offset[j]);
2958 flowtype_to_str(uint16_t flow_type)
2960 struct flow_type_info {
2966 static struct flow_type_info flowtype_str_table[] = {
2967 {"raw", RTE_ETH_FLOW_RAW},
2968 {"ipv4", RTE_ETH_FLOW_IPV4},
2969 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2970 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2971 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2972 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2973 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2974 {"ipv6", RTE_ETH_FLOW_IPV6},
2975 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2976 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2977 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2978 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2979 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2980 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2981 {"port", RTE_ETH_FLOW_PORT},
2982 {"vxlan", RTE_ETH_FLOW_VXLAN},
2983 {"geneve", RTE_ETH_FLOW_GENEVE},
2984 {"nvgre", RTE_ETH_FLOW_NVGRE},
2987 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2988 if (flowtype_str_table[i].ftype == flow_type)
2989 return flowtype_str_table[i].str;
2996 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2998 struct rte_eth_fdir_flex_mask *mask;
3002 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
3003 mask = &flex_conf->flex_mask[i];
3004 p = flowtype_to_str(mask->flow_type);
3005 printf("\n %s:\t", p ? p : "unknown");
3006 for (j = 0; j < num; j++)
3007 printf(" %02x", mask->mask[j]);
3013 print_fdir_flow_type(uint32_t flow_types_mask)
3018 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
3019 if (!(flow_types_mask & (1 << i)))
3021 p = flowtype_to_str(i);
3031 fdir_get_infos(portid_t port_id)
3033 struct rte_eth_fdir_stats fdir_stat;
3034 struct rte_eth_fdir_info fdir_info;
3037 static const char *fdir_stats_border = "########################";
3039 if (port_id_is_invalid(port_id, ENABLED_WARN))
3041 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3043 printf("\n FDIR is not supported on port %-2d\n",
3048 memset(&fdir_info, 0, sizeof(fdir_info));
3049 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3050 RTE_ETH_FILTER_INFO, &fdir_info);
3051 memset(&fdir_stat, 0, sizeof(fdir_stat));
3052 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3053 RTE_ETH_FILTER_STATS, &fdir_stat);
3054 printf("\n %s FDIR infos for port %-2d %s\n",
3055 fdir_stats_border, port_id, fdir_stats_border);
3057 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3058 printf(" PERFECT\n");
3059 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3060 printf(" PERFECT-MAC-VLAN\n");
3061 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3062 printf(" PERFECT-TUNNEL\n");
3063 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3064 printf(" SIGNATURE\n");
3066 printf(" DISABLE\n");
3067 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3068 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3069 printf(" SUPPORTED FLOW TYPE: ");
3070 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3072 printf(" FLEX PAYLOAD INFO:\n");
3073 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3074 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3075 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3076 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3077 fdir_info.flex_payload_unit,
3078 fdir_info.max_flex_payload_segment_num,
3079 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3081 print_fdir_mask(&fdir_info.mask);
3082 if (fdir_info.flex_conf.nb_payloads > 0) {
3083 printf(" FLEX PAYLOAD SRC OFFSET:");
3084 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3086 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3087 printf(" FLEX MASK CFG:");
3088 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3090 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3091 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3092 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3093 fdir_info.guarant_spc, fdir_info.best_spc);
3094 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3095 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3096 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3097 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3098 fdir_stat.collision, fdir_stat.free,
3099 fdir_stat.maxhash, fdir_stat.maxlen,
3100 fdir_stat.add, fdir_stat.remove,
3101 fdir_stat.f_add, fdir_stat.f_remove);
3102 printf(" %s############################%s\n",
3103 fdir_stats_border, fdir_stats_border);
3107 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3109 struct rte_port *port;
3110 struct rte_eth_fdir_flex_conf *flex_conf;
3113 port = &ports[port_id];
3114 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3115 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3116 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3121 if (i >= RTE_ETH_FLOW_MAX) {
3122 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3123 idx = flex_conf->nb_flexmasks;
3124 flex_conf->nb_flexmasks++;
3126 printf("The flex mask table is full. Can not set flex"
3127 " mask for flow_type(%u).", cfg->flow_type);
3131 rte_memcpy(&flex_conf->flex_mask[idx],
3133 sizeof(struct rte_eth_fdir_flex_mask));
3137 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3139 struct rte_port *port;
3140 struct rte_eth_fdir_flex_conf *flex_conf;
3143 port = &ports[port_id];
3144 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3145 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3146 if (cfg->type == flex_conf->flex_set[i].type) {
3151 if (i >= RTE_ETH_PAYLOAD_MAX) {
3152 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3153 idx = flex_conf->nb_payloads;
3154 flex_conf->nb_payloads++;
3156 printf("The flex payload table is full. Can not set"
3157 " flex payload for type(%u).", cfg->type);
3161 rte_memcpy(&flex_conf->flex_set[idx],
3163 sizeof(struct rte_eth_flex_payload_cfg));
3168 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3170 #ifdef RTE_LIBRTE_IXGBE_PMD
3174 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3176 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3180 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3181 is_rx ? "rx" : "tx", port_id, diag);
3184 printf("VF %s setting not supported for port %d\n",
3185 is_rx ? "Rx" : "Tx", port_id);
3191 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3194 struct rte_eth_link link;
3196 if (port_id_is_invalid(port_id, ENABLED_WARN))
3198 rte_eth_link_get_nowait(port_id, &link);
3199 if (rate > link.link_speed) {
3200 printf("Invalid rate value:%u bigger than link speed: %u\n",
3201 rate, link.link_speed);
3204 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3207 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3213 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3215 int diag = -ENOTSUP;
3219 RTE_SET_USED(q_msk);
3221 #ifdef RTE_LIBRTE_IXGBE_PMD
3222 if (diag == -ENOTSUP)
3223 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3226 #ifdef RTE_LIBRTE_BNXT_PMD
3227 if (diag == -ENOTSUP)
3228 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3233 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3239 * Functions to manage the set of filtered Multicast MAC addresses.
3241 * A pool of filtered multicast MAC addresses is associated with each port.
3242 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3243 * The address of the pool and the number of valid multicast MAC addresses
3244 * recorded in the pool are stored in the fields "mc_addr_pool" and
3245 * "mc_addr_nb" of the "rte_port" data structure.
3247 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3248 * to be supplied a contiguous array of multicast MAC addresses.
3249 * To comply with this constraint, the set of multicast addresses recorded
3250 * into the pool are systematically compacted at the beginning of the pool.
3251 * Hence, when a multicast address is removed from the pool, all following
3252 * addresses, if any, are copied back to keep the set contiguous.
3254 #define MCAST_POOL_INC 32
3257 mcast_addr_pool_extend(struct rte_port *port)
3259 struct ether_addr *mc_pool;
3260 size_t mc_pool_size;
3263 * If a free entry is available at the end of the pool, just
3264 * increment the number of recorded multicast addresses.
3266 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3272 * [re]allocate a pool with MCAST_POOL_INC more entries.
3273 * The previous test guarantees that port->mc_addr_nb is a multiple
3274 * of MCAST_POOL_INC.
3276 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3278 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3280 if (mc_pool == NULL) {
3281 printf("allocation of pool of %u multicast addresses failed\n",
3282 port->mc_addr_nb + MCAST_POOL_INC);
3286 port->mc_addr_pool = mc_pool;
3293 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3296 if (addr_idx == port->mc_addr_nb) {
3297 /* No need to recompact the set of multicast addressses. */
3298 if (port->mc_addr_nb == 0) {
3299 /* free the pool of multicast addresses. */
3300 free(port->mc_addr_pool);
3301 port->mc_addr_pool = NULL;
3305 memmove(&port->mc_addr_pool[addr_idx],
3306 &port->mc_addr_pool[addr_idx + 1],
3307 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3311 eth_port_multicast_addr_list_set(portid_t port_id)
3313 struct rte_port *port;
3316 port = &ports[port_id];
3317 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3321 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3322 port->mc_addr_nb, port_id, -diag);
3326 mcast_addr_add(portid_t port_id, struct ether_addr *mc_addr)
3328 struct rte_port *port;
3331 if (port_id_is_invalid(port_id, ENABLED_WARN))
3334 port = &ports[port_id];
3337 * Check that the added multicast MAC address is not already recorded
3338 * in the pool of multicast addresses.
3340 for (i = 0; i < port->mc_addr_nb; i++) {
3341 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3342 printf("multicast address already filtered by port\n");
3347 if (mcast_addr_pool_extend(port) != 0)
3349 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3350 eth_port_multicast_addr_list_set(port_id);
3354 mcast_addr_remove(portid_t port_id, struct ether_addr *mc_addr)
3356 struct rte_port *port;
3359 if (port_id_is_invalid(port_id, ENABLED_WARN))
3362 port = &ports[port_id];
3365 * Search the pool of multicast MAC addresses for the removed address.
3367 for (i = 0; i < port->mc_addr_nb; i++) {
3368 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3371 if (i == port->mc_addr_nb) {
3372 printf("multicast address not filtered by port %d\n", port_id);
3376 mcast_addr_pool_remove(port, i);
3377 eth_port_multicast_addr_list_set(port_id);
3381 port_dcb_info_display(portid_t port_id)
3383 struct rte_eth_dcb_info dcb_info;
3386 static const char *border = "================";
3388 if (port_id_is_invalid(port_id, ENABLED_WARN))
3391 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3393 printf("\n Failed to get dcb infos on port %-2d\n",
3397 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3398 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3400 for (i = 0; i < dcb_info.nb_tcs; i++)
3402 printf("\n Priority : ");
3403 for (i = 0; i < dcb_info.nb_tcs; i++)
3404 printf("\t%4d", dcb_info.prio_tc[i]);
3405 printf("\n BW percent :");
3406 for (i = 0; i < dcb_info.nb_tcs; i++)
3407 printf("\t%4d%%", dcb_info.tc_bws[i]);
3408 printf("\n RXQ base : ");
3409 for (i = 0; i < dcb_info.nb_tcs; i++)
3410 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3411 printf("\n RXQ number :");
3412 for (i = 0; i < dcb_info.nb_tcs; i++)
3413 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3414 printf("\n TXQ base : ");
3415 for (i = 0; i < dcb_info.nb_tcs; i++)
3416 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3417 printf("\n TXQ number :");
3418 for (i = 0; i < dcb_info.nb_tcs; i++)
3419 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3424 open_ddp_package_file(const char *file_path, uint32_t *size)
3426 int fd = open(file_path, O_RDONLY);
3428 uint8_t *buf = NULL;
3436 printf("%s: Failed to open %s\n", __func__, file_path);
3440 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
3442 printf("%s: File operations failed\n", __func__);
3446 pkg_size = st_buf.st_size;
3449 printf("%s: File operations failed\n", __func__);
3453 buf = (uint8_t *)malloc(pkg_size);
3456 printf("%s: Failed to malloc memory\n", __func__);
3460 ret = read(fd, buf, pkg_size);
3463 printf("%s: File read operation failed\n", __func__);
3464 close_ddp_package_file(buf);
3477 save_ddp_package_file(const char *file_path, uint8_t *buf, uint32_t size)
3479 FILE *fh = fopen(file_path, "wb");
3482 printf("%s: Failed to open %s\n", __func__, file_path);
3486 if (fwrite(buf, 1, size, fh) != size) {
3488 printf("%s: File write operation failed\n", __func__);
3498 close_ddp_package_file(uint8_t *buf)
3509 port_queue_region_info_display(portid_t port_id, void *buf)
3511 #ifdef RTE_LIBRTE_I40E_PMD
3513 struct rte_pmd_i40e_queue_regions *info =
3514 (struct rte_pmd_i40e_queue_regions *)buf;
3515 static const char *queue_region_info_stats_border = "-------";
3517 if (!info->queue_region_number)
3518 printf("there is no region has been set before");
3520 printf("\n %s All queue region info for port=%2d %s",
3521 queue_region_info_stats_border, port_id,
3522 queue_region_info_stats_border);
3523 printf("\n queue_region_number: %-14u \n",
3524 info->queue_region_number);
3526 for (i = 0; i < info->queue_region_number; i++) {
3527 printf("\n region_id: %-14u queue_number: %-14u "
3528 "queue_start_index: %-14u \n",
3529 info->region[i].region_id,
3530 info->region[i].queue_num,
3531 info->region[i].queue_start_index);
3533 printf(" user_priority_num is %-14u :",
3534 info->region[i].user_priority_num);
3535 for (j = 0; j < info->region[i].user_priority_num; j++)
3536 printf(" %-14u ", info->region[i].user_priority[j]);
3538 printf("\n flowtype_num is %-14u :",
3539 info->region[i].flowtype_num);
3540 for (j = 0; j < info->region[i].flowtype_num; j++)
3541 printf(" %-14u ", info->region[i].hw_flowtype[j]);
3544 RTE_SET_USED(port_id);