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_BNXT_PMD
75 #include <rte_pmd_bnxt.h>
81 static char *flowtype_to_str(uint16_t flow_type);
84 enum tx_pkt_split split;
88 .split = TX_PKT_SPLIT_OFF,
92 .split = TX_PKT_SPLIT_ON,
96 .split = TX_PKT_SPLIT_RND,
101 struct rss_type_info {
106 static const struct rss_type_info rss_type_table[] = {
107 { "ipv4", ETH_RSS_IPV4 },
108 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
109 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
110 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
111 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
112 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
113 { "ipv6", ETH_RSS_IPV6 },
114 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
115 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
116 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
117 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
118 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
119 { "l2-payload", ETH_RSS_L2_PAYLOAD },
120 { "ipv6-ex", ETH_RSS_IPV6_EX },
121 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
122 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
123 { "port", ETH_RSS_PORT },
124 { "vxlan", ETH_RSS_VXLAN },
125 { "geneve", ETH_RSS_GENEVE },
126 { "nvgre", ETH_RSS_NVGRE },
131 print_ethaddr(const char *name, struct ether_addr *eth_addr)
133 char buf[ETHER_ADDR_FMT_SIZE];
134 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
135 printf("%s%s", name, buf);
139 nic_stats_display(portid_t port_id)
141 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
142 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
143 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
144 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles;
145 uint64_t mpps_rx, mpps_tx;
146 struct rte_eth_stats stats;
147 struct rte_port *port = &ports[port_id];
151 static const char *nic_stats_border = "########################";
153 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
154 printf("Valid port range is [0");
155 RTE_ETH_FOREACH_DEV(pid)
160 rte_eth_stats_get(port_id, &stats);
161 printf("\n %s NIC statistics for port %-2d %s\n",
162 nic_stats_border, port_id, nic_stats_border);
164 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
165 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
167 stats.ipackets, stats.imissed, stats.ibytes);
168 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
169 printf(" RX-nombuf: %-10"PRIu64"\n",
171 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
173 stats.opackets, stats.oerrors, stats.obytes);
176 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
177 " RX-bytes: %10"PRIu64"\n",
178 stats.ipackets, stats.ierrors, stats.ibytes);
179 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
180 printf(" RX-nombuf: %10"PRIu64"\n",
182 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
183 " TX-bytes: %10"PRIu64"\n",
184 stats.opackets, stats.oerrors, stats.obytes);
187 if (port->rx_queue_stats_mapping_enabled) {
189 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
190 printf(" Stats reg %2d RX-packets: %10"PRIu64
191 " RX-errors: %10"PRIu64
192 " RX-bytes: %10"PRIu64"\n",
193 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
196 if (port->tx_queue_stats_mapping_enabled) {
198 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
199 printf(" Stats reg %2d TX-packets: %10"PRIu64
200 " TX-bytes: %10"PRIu64"\n",
201 i, stats.q_opackets[i], stats.q_obytes[i]);
205 diff_cycles = prev_cycles[port_id];
206 prev_cycles[port_id] = rte_rdtsc();
208 diff_cycles = prev_cycles[port_id] - diff_cycles;
210 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
211 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
212 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
213 (stats.opackets - prev_pkts_tx[port_id]) : 0;
214 prev_pkts_rx[port_id] = stats.ipackets;
215 prev_pkts_tx[port_id] = stats.opackets;
216 mpps_rx = diff_cycles > 0 ?
217 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
218 mpps_tx = diff_cycles > 0 ?
219 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
220 printf("\n Throughput (since last show)\n");
221 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
224 printf(" %s############################%s\n",
225 nic_stats_border, nic_stats_border);
229 nic_stats_clear(portid_t port_id)
233 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
234 printf("Valid port range is [0");
235 RTE_ETH_FOREACH_DEV(pid)
240 rte_eth_stats_reset(port_id);
241 printf("\n NIC statistics for port %d cleared\n", port_id);
245 nic_xstats_display(portid_t port_id)
247 struct rte_eth_xstat *xstats;
248 int cnt_xstats, idx_xstat;
249 struct rte_eth_xstat_name *xstats_names;
251 printf("###### NIC extended statistics for port %-2d\n", port_id);
252 if (!rte_eth_dev_is_valid_port(port_id)) {
253 printf("Error: Invalid port number %i\n", port_id);
258 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
259 if (cnt_xstats < 0) {
260 printf("Error: Cannot get count of xstats\n");
264 /* Get id-name lookup table */
265 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
266 if (xstats_names == NULL) {
267 printf("Cannot allocate memory for xstats lookup\n");
270 if (cnt_xstats != rte_eth_xstats_get_names(
271 port_id, xstats_names, cnt_xstats)) {
272 printf("Error: Cannot get xstats lookup\n");
277 /* Get stats themselves */
278 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
279 if (xstats == NULL) {
280 printf("Cannot allocate memory for xstats\n");
284 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
285 printf("Error: Unable to get xstats\n");
292 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
293 printf("%s: %"PRIu64"\n",
294 xstats_names[idx_xstat].name,
295 xstats[idx_xstat].value);
301 nic_xstats_clear(portid_t port_id)
303 rte_eth_xstats_reset(port_id);
307 nic_stats_mapping_display(portid_t port_id)
309 struct rte_port *port = &ports[port_id];
313 static const char *nic_stats_mapping_border = "########################";
315 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
316 printf("Valid port range is [0");
317 RTE_ETH_FOREACH_DEV(pid)
323 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
324 printf("Port id %d - either does not support queue statistic mapping or"
325 " no queue statistic mapping set\n", port_id);
329 printf("\n %s NIC statistics mapping for port %-2d %s\n",
330 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
332 if (port->rx_queue_stats_mapping_enabled) {
333 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
334 if (rx_queue_stats_mappings[i].port_id == port_id) {
335 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
336 rx_queue_stats_mappings[i].queue_id,
337 rx_queue_stats_mappings[i].stats_counter_id);
344 if (port->tx_queue_stats_mapping_enabled) {
345 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
346 if (tx_queue_stats_mappings[i].port_id == port_id) {
347 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
348 tx_queue_stats_mappings[i].queue_id,
349 tx_queue_stats_mappings[i].stats_counter_id);
354 printf(" %s####################################%s\n",
355 nic_stats_mapping_border, nic_stats_mapping_border);
359 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
361 struct rte_eth_rxq_info qinfo;
363 static const char *info_border = "*********************";
365 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
367 printf("Failed to retrieve information for port: %u, "
368 "RX queue: %hu\nerror desc: %s(%d)\n",
369 port_id, queue_id, strerror(-rc), rc);
373 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
374 info_border, port_id, queue_id, info_border);
376 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
377 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
378 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
379 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
380 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
381 printf("\nRX drop packets: %s",
382 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
383 printf("\nRX deferred start: %s",
384 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
385 printf("\nRX scattered packets: %s",
386 (qinfo.scattered_rx != 0) ? "on" : "off");
387 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
392 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
394 struct rte_eth_txq_info qinfo;
396 static const char *info_border = "*********************";
398 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
400 printf("Failed to retrieve information for port: %u, "
401 "TX queue: %hu\nerror desc: %s(%d)\n",
402 port_id, queue_id, strerror(-rc), rc);
406 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
407 info_border, port_id, queue_id, info_border);
409 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
410 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
411 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
412 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
413 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
414 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
415 printf("\nTX deferred start: %s",
416 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
417 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
422 port_infos_display(portid_t port_id)
424 struct rte_port *port;
425 struct ether_addr mac_addr;
426 struct rte_eth_link link;
427 struct rte_eth_dev_info dev_info;
429 struct rte_mempool * mp;
430 static const char *info_border = "*********************";
434 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
435 printf("Valid port range is [0");
436 RTE_ETH_FOREACH_DEV(pid)
441 port = &ports[port_id];
442 rte_eth_link_get_nowait(port_id, &link);
443 memset(&dev_info, 0, sizeof(dev_info));
444 rte_eth_dev_info_get(port_id, &dev_info);
445 printf("\n%s Infos for port %-2d %s\n",
446 info_border, port_id, info_border);
447 rte_eth_macaddr_get(port_id, &mac_addr);
448 print_ethaddr("MAC address: ", &mac_addr);
449 printf("\nDriver name: %s", dev_info.driver_name);
450 printf("\nConnect to socket: %u", port->socket_id);
452 if (port_numa[port_id] != NUMA_NO_CONFIG) {
453 mp = mbuf_pool_find(port_numa[port_id]);
455 printf("\nmemory allocation on the socket: %d",
458 printf("\nmemory allocation on the socket: %u",port->socket_id);
460 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
461 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
462 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
463 ("full-duplex") : ("half-duplex"));
465 if (!rte_eth_dev_get_mtu(port_id, &mtu))
466 printf("MTU: %u\n", mtu);
468 printf("Promiscuous mode: %s\n",
469 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
470 printf("Allmulticast mode: %s\n",
471 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
472 printf("Maximum number of MAC addresses: %u\n",
473 (unsigned int)(port->dev_info.max_mac_addrs));
474 printf("Maximum number of MAC addresses of hash filtering: %u\n",
475 (unsigned int)(port->dev_info.max_hash_mac_addrs));
477 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
478 if (vlan_offload >= 0){
479 printf("VLAN offload: \n");
480 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
481 printf(" strip on \n");
483 printf(" strip off \n");
485 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
486 printf(" filter on \n");
488 printf(" filter off \n");
490 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
491 printf(" qinq(extend) on \n");
493 printf(" qinq(extend) off \n");
496 if (dev_info.hash_key_size > 0)
497 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
498 if (dev_info.reta_size > 0)
499 printf("Redirection table size: %u\n", dev_info.reta_size);
500 if (!dev_info.flow_type_rss_offloads)
501 printf("No flow type is supported.\n");
506 printf("Supported flow types:\n");
507 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
508 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
509 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
511 p = flowtype_to_str(i);
515 printf(" user defined %d\n", i);
519 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
520 printf("Max possible number of RXDs per queue: %hu\n",
521 dev_info.rx_desc_lim.nb_max);
522 printf("Min possible number of RXDs per queue: %hu\n",
523 dev_info.rx_desc_lim.nb_min);
524 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
526 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
527 printf("Max possible number of TXDs per queue: %hu\n",
528 dev_info.tx_desc_lim.nb_max);
529 printf("Min possible number of TXDs per queue: %hu\n",
530 dev_info.tx_desc_lim.nb_min);
531 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
535 port_offload_cap_display(portid_t port_id)
537 struct rte_eth_dev *dev;
538 struct rte_eth_dev_info dev_info;
539 static const char *info_border = "************";
541 if (port_id_is_invalid(port_id, ENABLED_WARN))
544 dev = &rte_eth_devices[port_id];
545 rte_eth_dev_info_get(port_id, &dev_info);
547 printf("\n%s Port %d supported offload features: %s\n",
548 info_border, port_id, info_border);
550 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
551 printf("VLAN stripped: ");
552 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
558 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
559 printf("Double VLANs stripped: ");
560 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
566 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
567 printf("RX IPv4 checksum: ");
568 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
574 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
575 printf("RX UDP checksum: ");
576 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
582 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
583 printf("RX TCP checksum: ");
584 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
590 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
591 printf("RX Outer IPv4 checksum: on");
593 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
594 printf("Large receive offload: ");
595 if (dev->data->dev_conf.rxmode.enable_lro)
601 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
602 printf("VLAN insert: ");
603 if (ports[port_id].tx_ol_flags &
604 TESTPMD_TX_OFFLOAD_INSERT_VLAN)
610 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
611 printf("Double VLANs insert: ");
612 if (ports[port_id].tx_ol_flags &
613 TESTPMD_TX_OFFLOAD_INSERT_QINQ)
619 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
620 printf("TX IPv4 checksum: ");
621 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
627 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
628 printf("TX UDP checksum: ");
629 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
635 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
636 printf("TX TCP checksum: ");
637 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
643 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
644 printf("TX SCTP checksum: ");
645 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
651 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
652 printf("TX Outer IPv4 checksum: ");
653 if (ports[port_id].tx_ol_flags &
654 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
660 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
661 printf("TX TCP segmentation: ");
662 if (ports[port_id].tso_segsz != 0)
668 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
669 printf("TX UDP segmentation: ");
670 if (ports[port_id].tso_segsz != 0)
676 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
677 printf("TSO for VXLAN tunnel packet: ");
678 if (ports[port_id].tunnel_tso_segsz)
684 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
685 printf("TSO for GRE tunnel packet: ");
686 if (ports[port_id].tunnel_tso_segsz)
692 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
693 printf("TSO for IPIP tunnel packet: ");
694 if (ports[port_id].tunnel_tso_segsz)
700 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
701 printf("TSO for GENEVE tunnel packet: ");
702 if (ports[port_id].tunnel_tso_segsz)
711 port_id_is_invalid(portid_t port_id, enum print_warning warning)
713 if (port_id == (portid_t)RTE_PORT_ALL)
716 if (rte_eth_dev_is_valid_port(port_id))
719 if (warning == ENABLED_WARN)
720 printf("Invalid port %d\n", port_id);
726 vlan_id_is_invalid(uint16_t vlan_id)
730 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
735 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
740 printf("Port register offset 0x%X not aligned on a 4-byte "
745 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
746 if (reg_off >= pci_len) {
747 printf("Port %d: register offset %u (0x%X) out of port PCI "
748 "resource (length=%"PRIu64")\n",
749 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
756 reg_bit_pos_is_invalid(uint8_t bit_pos)
760 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
764 #define display_port_and_reg_off(port_id, reg_off) \
765 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
768 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
770 display_port_and_reg_off(port_id, (unsigned)reg_off);
771 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
775 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
780 if (port_id_is_invalid(port_id, ENABLED_WARN))
782 if (port_reg_off_is_invalid(port_id, reg_off))
784 if (reg_bit_pos_is_invalid(bit_x))
786 reg_v = port_id_pci_reg_read(port_id, reg_off);
787 display_port_and_reg_off(port_id, (unsigned)reg_off);
788 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
792 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
793 uint8_t bit1_pos, uint8_t bit2_pos)
799 if (port_id_is_invalid(port_id, ENABLED_WARN))
801 if (port_reg_off_is_invalid(port_id, reg_off))
803 if (reg_bit_pos_is_invalid(bit1_pos))
805 if (reg_bit_pos_is_invalid(bit2_pos))
807 if (bit1_pos > bit2_pos)
808 l_bit = bit2_pos, h_bit = bit1_pos;
810 l_bit = bit1_pos, h_bit = bit2_pos;
812 reg_v = port_id_pci_reg_read(port_id, reg_off);
815 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
816 display_port_and_reg_off(port_id, (unsigned)reg_off);
817 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
818 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
822 port_reg_display(portid_t port_id, uint32_t reg_off)
826 if (port_id_is_invalid(port_id, ENABLED_WARN))
828 if (port_reg_off_is_invalid(port_id, reg_off))
830 reg_v = port_id_pci_reg_read(port_id, reg_off);
831 display_port_reg_value(port_id, reg_off, reg_v);
835 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
840 if (port_id_is_invalid(port_id, ENABLED_WARN))
842 if (port_reg_off_is_invalid(port_id, reg_off))
844 if (reg_bit_pos_is_invalid(bit_pos))
847 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
850 reg_v = port_id_pci_reg_read(port_id, reg_off);
852 reg_v &= ~(1 << bit_pos);
854 reg_v |= (1 << bit_pos);
855 port_id_pci_reg_write(port_id, reg_off, reg_v);
856 display_port_reg_value(port_id, reg_off, reg_v);
860 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
861 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
868 if (port_id_is_invalid(port_id, ENABLED_WARN))
870 if (port_reg_off_is_invalid(port_id, reg_off))
872 if (reg_bit_pos_is_invalid(bit1_pos))
874 if (reg_bit_pos_is_invalid(bit2_pos))
876 if (bit1_pos > bit2_pos)
877 l_bit = bit2_pos, h_bit = bit1_pos;
879 l_bit = bit1_pos, h_bit = bit2_pos;
881 if ((h_bit - l_bit) < 31)
882 max_v = (1 << (h_bit - l_bit + 1)) - 1;
887 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
888 (unsigned)value, (unsigned)value,
889 (unsigned)max_v, (unsigned)max_v);
892 reg_v = port_id_pci_reg_read(port_id, reg_off);
893 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
894 reg_v |= (value << l_bit); /* Set changed bits */
895 port_id_pci_reg_write(port_id, reg_off, reg_v);
896 display_port_reg_value(port_id, reg_off, reg_v);
900 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
902 if (port_id_is_invalid(port_id, ENABLED_WARN))
904 if (port_reg_off_is_invalid(port_id, reg_off))
906 port_id_pci_reg_write(port_id, reg_off, reg_v);
907 display_port_reg_value(port_id, reg_off, reg_v);
911 port_mtu_set(portid_t port_id, uint16_t mtu)
915 if (port_id_is_invalid(port_id, ENABLED_WARN))
917 diag = rte_eth_dev_set_mtu(port_id, mtu);
920 printf("Set MTU failed. diag=%d\n", diag);
923 /* Generic flow management functions. */
925 /** Generate flow_item[] entry. */
926 #define MK_FLOW_ITEM(t, s) \
927 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
932 /** Information about known flow pattern items. */
933 static const struct {
937 MK_FLOW_ITEM(END, 0),
938 MK_FLOW_ITEM(VOID, 0),
939 MK_FLOW_ITEM(INVERT, 0),
940 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
942 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
943 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
944 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
945 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
946 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
947 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
948 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
949 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
950 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
951 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
952 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
953 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
954 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
955 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
956 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
957 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
958 MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
959 MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
960 MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
961 MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
964 /** Compute storage space needed by item specification. */
966 flow_item_spec_size(const struct rte_flow_item *item,
967 size_t *size, size_t *pad)
973 switch (item->type) {
975 const struct rte_flow_item_raw *raw;
978 case RTE_FLOW_ITEM_TYPE_RAW:
979 spec.raw = item->spec;
980 *size = offsetof(struct rte_flow_item_raw, pattern) +
981 spec.raw->length * sizeof(*spec.raw->pattern);
984 *size = flow_item[item->type].size;
988 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
991 /** Generate flow_action[] entry. */
992 #define MK_FLOW_ACTION(t, s) \
993 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
998 /** Information about known flow actions. */
999 static const struct {
1003 MK_FLOW_ACTION(END, 0),
1004 MK_FLOW_ACTION(VOID, 0),
1005 MK_FLOW_ACTION(PASSTHRU, 0),
1006 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1007 MK_FLOW_ACTION(FLAG, 0),
1008 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
1009 MK_FLOW_ACTION(DROP, 0),
1010 MK_FLOW_ACTION(COUNT, 0),
1011 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
1012 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
1013 MK_FLOW_ACTION(PF, 0),
1014 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1017 /** Compute storage space needed by action configuration. */
1019 flow_action_conf_size(const struct rte_flow_action *action,
1020 size_t *size, size_t *pad)
1022 if (!action->conf) {
1026 switch (action->type) {
1028 const struct rte_flow_action_rss *rss;
1031 case RTE_FLOW_ACTION_TYPE_RSS:
1032 conf.rss = action->conf;
1033 *size = offsetof(struct rte_flow_action_rss, queue) +
1034 conf.rss->num * sizeof(*conf.rss->queue);
1037 *size = flow_action[action->type].size;
1041 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1044 /** Generate a port_flow entry from attributes/pattern/actions. */
1045 static struct port_flow *
1046 port_flow_new(const struct rte_flow_attr *attr,
1047 const struct rte_flow_item *pattern,
1048 const struct rte_flow_action *actions)
1050 const struct rte_flow_item *item;
1051 const struct rte_flow_action *action;
1052 struct port_flow *pf = NULL;
1062 pf->pattern = (void *)&pf->data[off1];
1064 struct rte_flow_item *dst = NULL;
1066 if ((unsigned int)item->type >= RTE_DIM(flow_item) ||
1067 !flow_item[item->type].name)
1070 dst = memcpy(pf->data + off1, item, sizeof(*item));
1071 off1 += sizeof(*item);
1072 flow_item_spec_size(item, &tmp, &pad);
1075 dst->spec = memcpy(pf->data + off2,
1081 dst->last = memcpy(pf->data + off2,
1087 dst->mask = memcpy(pf->data + off2,
1091 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1092 } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
1093 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1096 pf->actions = (void *)&pf->data[off1];
1098 struct rte_flow_action *dst = NULL;
1100 if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
1101 !flow_action[action->type].name)
1104 dst = memcpy(pf->data + off1, action, sizeof(*action));
1105 off1 += sizeof(*action);
1106 flow_action_conf_size(action, &tmp, &pad);
1109 dst->conf = memcpy(pf->data + off2,
1113 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1114 } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
1117 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1118 tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double));
1119 pf = calloc(1, tmp + off1 + off2);
1123 *pf = (const struct port_flow){
1124 .size = tmp + off1 + off2,
1127 tmp -= offsetof(struct port_flow, data);
1137 /** Print a message out of a flow error. */
1139 port_flow_complain(struct rte_flow_error *error)
1141 static const char *const errstrlist[] = {
1142 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1143 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1144 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1145 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1146 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1147 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1148 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1149 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1150 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1151 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1152 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1153 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1157 int err = rte_errno;
1159 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1160 !errstrlist[error->type])
1161 errstr = "unknown type";
1163 errstr = errstrlist[error->type];
1164 printf("Caught error type %d (%s): %s%s\n",
1165 error->type, errstr,
1166 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1167 error->cause), buf) : "",
1168 error->message ? error->message : "(no stated reason)");
1172 /** Validate flow rule. */
1174 port_flow_validate(portid_t port_id,
1175 const struct rte_flow_attr *attr,
1176 const struct rte_flow_item *pattern,
1177 const struct rte_flow_action *actions)
1179 struct rte_flow_error error;
1181 /* Poisoning to make sure PMDs update it in case of error. */
1182 memset(&error, 0x11, sizeof(error));
1183 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1184 return port_flow_complain(&error);
1185 printf("Flow rule validated\n");
1189 /** Create flow rule. */
1191 port_flow_create(portid_t port_id,
1192 const struct rte_flow_attr *attr,
1193 const struct rte_flow_item *pattern,
1194 const struct rte_flow_action *actions)
1196 struct rte_flow *flow;
1197 struct rte_port *port;
1198 struct port_flow *pf;
1200 struct rte_flow_error error;
1202 /* Poisoning to make sure PMDs update it in case of error. */
1203 memset(&error, 0x22, sizeof(error));
1204 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1206 return port_flow_complain(&error);
1207 port = &ports[port_id];
1208 if (port->flow_list) {
1209 if (port->flow_list->id == UINT32_MAX) {
1210 printf("Highest rule ID is already assigned, delete"
1212 rte_flow_destroy(port_id, flow, NULL);
1215 id = port->flow_list->id + 1;
1218 pf = port_flow_new(attr, pattern, actions);
1220 int err = rte_errno;
1222 printf("Cannot allocate flow: %s\n", rte_strerror(err));
1223 rte_flow_destroy(port_id, flow, NULL);
1226 pf->next = port->flow_list;
1229 port->flow_list = pf;
1230 printf("Flow rule #%u created\n", pf->id);
1234 /** Destroy a number of flow rules. */
1236 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1238 struct rte_port *port;
1239 struct port_flow **tmp;
1243 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1244 port_id == (portid_t)RTE_PORT_ALL)
1246 port = &ports[port_id];
1247 tmp = &port->flow_list;
1251 for (i = 0; i != n; ++i) {
1252 struct rte_flow_error error;
1253 struct port_flow *pf = *tmp;
1255 if (rule[i] != pf->id)
1258 * Poisoning to make sure PMDs update it in case
1261 memset(&error, 0x33, sizeof(error));
1262 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1263 ret = port_flow_complain(&error);
1266 printf("Flow rule #%u destroyed\n", pf->id);
1272 tmp = &(*tmp)->next;
1278 /** Remove all flow rules. */
1280 port_flow_flush(portid_t port_id)
1282 struct rte_flow_error error;
1283 struct rte_port *port;
1286 /* Poisoning to make sure PMDs update it in case of error. */
1287 memset(&error, 0x44, sizeof(error));
1288 if (rte_flow_flush(port_id, &error)) {
1289 ret = port_flow_complain(&error);
1290 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1291 port_id == (portid_t)RTE_PORT_ALL)
1294 port = &ports[port_id];
1295 while (port->flow_list) {
1296 struct port_flow *pf = port->flow_list->next;
1298 free(port->flow_list);
1299 port->flow_list = pf;
1304 /** Query a flow rule. */
1306 port_flow_query(portid_t port_id, uint32_t rule,
1307 enum rte_flow_action_type action)
1309 struct rte_flow_error error;
1310 struct rte_port *port;
1311 struct port_flow *pf;
1314 struct rte_flow_query_count count;
1317 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1318 port_id == (portid_t)RTE_PORT_ALL)
1320 port = &ports[port_id];
1321 for (pf = port->flow_list; pf; pf = pf->next)
1325 printf("Flow rule #%u not found\n", rule);
1328 if ((unsigned int)action >= RTE_DIM(flow_action) ||
1329 !flow_action[action].name)
1332 name = flow_action[action].name;
1334 case RTE_FLOW_ACTION_TYPE_COUNT:
1337 printf("Cannot query action type %d (%s)\n", action, name);
1340 /* Poisoning to make sure PMDs update it in case of error. */
1341 memset(&error, 0x55, sizeof(error));
1342 memset(&query, 0, sizeof(query));
1343 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1344 return port_flow_complain(&error);
1346 case RTE_FLOW_ACTION_TYPE_COUNT:
1350 " hits: %" PRIu64 "\n"
1351 " bytes: %" PRIu64 "\n",
1353 query.count.hits_set,
1354 query.count.bytes_set,
1359 printf("Cannot display result for action type %d (%s)\n",
1366 /** List flow rules. */
1368 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1370 struct rte_port *port;
1371 struct port_flow *pf;
1372 struct port_flow *list = NULL;
1375 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1376 port_id == (portid_t)RTE_PORT_ALL)
1378 port = &ports[port_id];
1379 if (!port->flow_list)
1381 /* Sort flows by group, priority and ID. */
1382 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1383 struct port_flow **tmp;
1386 /* Filter out unwanted groups. */
1387 for (i = 0; i != n; ++i)
1388 if (pf->attr.group == group[i])
1395 (pf->attr.group > (*tmp)->attr.group ||
1396 (pf->attr.group == (*tmp)->attr.group &&
1397 pf->attr.priority > (*tmp)->attr.priority) ||
1398 (pf->attr.group == (*tmp)->attr.group &&
1399 pf->attr.priority == (*tmp)->attr.priority &&
1400 pf->id > (*tmp)->id)))
1405 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1406 for (pf = list; pf != NULL; pf = pf->tmp) {
1407 const struct rte_flow_item *item = pf->pattern;
1408 const struct rte_flow_action *action = pf->actions;
1410 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t",
1414 pf->attr.ingress ? 'i' : '-',
1415 pf->attr.egress ? 'e' : '-');
1416 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1417 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1418 printf("%s ", flow_item[item->type].name);
1422 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1423 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1424 printf(" %s", flow_action[action->type].name);
1431 /** Restrict ingress traffic to the defined flow rules. */
1433 port_flow_isolate(portid_t port_id, int set)
1435 struct rte_flow_error error;
1437 /* Poisoning to make sure PMDs update it in case of error. */
1438 memset(&error, 0x66, sizeof(error));
1439 if (rte_flow_isolate(port_id, set, &error))
1440 return port_flow_complain(&error);
1441 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1443 set ? "now restricted" : "not restricted anymore");
1448 * RX/TX ring descriptors display functions.
1451 rx_queue_id_is_invalid(queueid_t rxq_id)
1453 if (rxq_id < nb_rxq)
1455 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1460 tx_queue_id_is_invalid(queueid_t txq_id)
1462 if (txq_id < nb_txq)
1464 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1469 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1471 if (rxdesc_id < nb_rxd)
1473 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1479 tx_desc_id_is_invalid(uint16_t txdesc_id)
1481 if (txdesc_id < nb_txd)
1483 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1488 static const struct rte_memzone *
1489 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
1491 char mz_name[RTE_MEMZONE_NAMESIZE];
1492 const struct rte_memzone *mz;
1494 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1495 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1496 mz = rte_memzone_lookup(mz_name);
1498 printf("%s ring memory zoneof (port %d, queue %d) not"
1499 "found (zone name = %s\n",
1500 ring_name, port_id, q_id, mz_name);
1504 union igb_ring_dword {
1507 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1517 struct igb_ring_desc_32_bytes {
1518 union igb_ring_dword lo_dword;
1519 union igb_ring_dword hi_dword;
1520 union igb_ring_dword resv1;
1521 union igb_ring_dword resv2;
1524 struct igb_ring_desc_16_bytes {
1525 union igb_ring_dword lo_dword;
1526 union igb_ring_dword hi_dword;
1530 ring_rxd_display_dword(union igb_ring_dword dword)
1532 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1533 (unsigned)dword.words.hi);
1537 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1538 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1541 __rte_unused uint8_t port_id,
1545 struct igb_ring_desc_16_bytes *ring =
1546 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1547 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1548 struct rte_eth_dev_info dev_info;
1550 memset(&dev_info, 0, sizeof(dev_info));
1551 rte_eth_dev_info_get(port_id, &dev_info);
1552 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1553 /* 32 bytes RX descriptor, i40e only */
1554 struct igb_ring_desc_32_bytes *ring =
1555 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1556 ring[desc_id].lo_dword.dword =
1557 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1558 ring_rxd_display_dword(ring[desc_id].lo_dword);
1559 ring[desc_id].hi_dword.dword =
1560 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1561 ring_rxd_display_dword(ring[desc_id].hi_dword);
1562 ring[desc_id].resv1.dword =
1563 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1564 ring_rxd_display_dword(ring[desc_id].resv1);
1565 ring[desc_id].resv2.dword =
1566 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1567 ring_rxd_display_dword(ring[desc_id].resv2);
1572 /* 16 bytes RX descriptor */
1573 ring[desc_id].lo_dword.dword =
1574 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1575 ring_rxd_display_dword(ring[desc_id].lo_dword);
1576 ring[desc_id].hi_dword.dword =
1577 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1578 ring_rxd_display_dword(ring[desc_id].hi_dword);
1582 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1584 struct igb_ring_desc_16_bytes *ring;
1585 struct igb_ring_desc_16_bytes txd;
1587 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1588 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1589 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1590 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1591 (unsigned)txd.lo_dword.words.lo,
1592 (unsigned)txd.lo_dword.words.hi,
1593 (unsigned)txd.hi_dword.words.lo,
1594 (unsigned)txd.hi_dword.words.hi);
1598 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1600 const struct rte_memzone *rx_mz;
1602 if (port_id_is_invalid(port_id, ENABLED_WARN))
1604 if (rx_queue_id_is_invalid(rxq_id))
1606 if (rx_desc_id_is_invalid(rxd_id))
1608 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1611 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1615 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1617 const struct rte_memzone *tx_mz;
1619 if (port_id_is_invalid(port_id, ENABLED_WARN))
1621 if (tx_queue_id_is_invalid(txq_id))
1623 if (tx_desc_id_is_invalid(txd_id))
1625 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1628 ring_tx_descriptor_display(tx_mz, txd_id);
1632 fwd_lcores_config_display(void)
1636 printf("List of forwarding lcores:");
1637 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1638 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1642 rxtx_config_display(void)
1644 printf(" %s packet forwarding%s - CRC stripping %s - "
1645 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
1646 retry_enabled == 0 ? "" : " with retry",
1647 rx_mode.hw_strip_crc ? "enabled" : "disabled",
1650 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1651 printf(" packet len=%u - nb packet segments=%d\n",
1652 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1654 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
1655 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
1657 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1658 nb_fwd_lcores, nb_fwd_ports);
1659 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1660 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1661 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1662 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
1663 rx_conf->rx_thresh.wthresh);
1664 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1665 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1666 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1667 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
1668 tx_conf->tx_thresh.wthresh);
1669 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
1670 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
1674 port_rss_reta_info(portid_t port_id,
1675 struct rte_eth_rss_reta_entry64 *reta_conf,
1676 uint16_t nb_entries)
1678 uint16_t i, idx, shift;
1681 if (port_id_is_invalid(port_id, ENABLED_WARN))
1684 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1686 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1690 for (i = 0; i < nb_entries; i++) {
1691 idx = i / RTE_RETA_GROUP_SIZE;
1692 shift = i % RTE_RETA_GROUP_SIZE;
1693 if (!(reta_conf[idx].mask & (1ULL << shift)))
1695 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1696 i, reta_conf[idx].reta[shift]);
1701 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1705 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1707 struct rte_eth_rss_conf rss_conf;
1708 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1712 struct rte_eth_dev_info dev_info;
1713 uint8_t hash_key_size;
1715 if (port_id_is_invalid(port_id, ENABLED_WARN))
1718 memset(&dev_info, 0, sizeof(dev_info));
1719 rte_eth_dev_info_get(port_id, &dev_info);
1720 if (dev_info.hash_key_size > 0 &&
1721 dev_info.hash_key_size <= sizeof(rss_key))
1722 hash_key_size = dev_info.hash_key_size;
1724 printf("dev_info did not provide a valid hash key size\n");
1728 rss_conf.rss_hf = 0;
1729 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1730 if (!strcmp(rss_info, rss_type_table[i].str))
1731 rss_conf.rss_hf = rss_type_table[i].rss_type;
1734 /* Get RSS hash key if asked to display it */
1735 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1736 rss_conf.rss_key_len = hash_key_size;
1737 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1741 printf("port index %d invalid\n", port_id);
1744 printf("operation not supported by device\n");
1747 printf("operation failed - diag=%d\n", diag);
1752 rss_hf = rss_conf.rss_hf;
1754 printf("RSS disabled\n");
1757 printf("RSS functions:\n ");
1758 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1759 if (rss_hf & rss_type_table[i].rss_type)
1760 printf("%s ", rss_type_table[i].str);
1765 printf("RSS key:\n");
1766 for (i = 0; i < hash_key_size; i++)
1767 printf("%02X", rss_key[i]);
1772 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1775 struct rte_eth_rss_conf rss_conf;
1779 rss_conf.rss_key = NULL;
1780 rss_conf.rss_key_len = hash_key_len;
1781 rss_conf.rss_hf = 0;
1782 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1783 if (!strcmp(rss_type_table[i].str, rss_type))
1784 rss_conf.rss_hf = rss_type_table[i].rss_type;
1786 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1788 rss_conf.rss_key = hash_key;
1789 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1796 printf("port index %d invalid\n", port_id);
1799 printf("operation not supported by device\n");
1802 printf("operation failed - diag=%d\n", diag);
1808 * Setup forwarding configuration for each logical core.
1811 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1813 streamid_t nb_fs_per_lcore;
1821 nb_fs = cfg->nb_fwd_streams;
1822 nb_fc = cfg->nb_fwd_lcores;
1823 if (nb_fs <= nb_fc) {
1824 nb_fs_per_lcore = 1;
1827 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1828 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1831 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1833 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1834 fwd_lcores[lc_id]->stream_idx = sm_id;
1835 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1836 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1840 * Assign extra remaining streams, if any.
1842 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1843 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1844 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1845 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1846 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1851 simple_fwd_config_setup(void)
1857 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1858 port_topology == PORT_TOPOLOGY_LOOP) {
1860 } else if (nb_fwd_ports % 2) {
1861 printf("\nWarning! Cannot handle an odd number of ports "
1862 "with the current port topology. Configuration "
1863 "must be changed to have an even number of ports, "
1864 "or relaunch application with "
1865 "--port-topology=chained\n\n");
1868 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1869 cur_fwd_config.nb_fwd_streams =
1870 (streamid_t) cur_fwd_config.nb_fwd_ports;
1872 /* reinitialize forwarding streams */
1876 * In the simple forwarding test, the number of forwarding cores
1877 * must be lower or equal to the number of forwarding ports.
1879 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1880 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1881 cur_fwd_config.nb_fwd_lcores =
1882 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1883 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1885 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1886 if (port_topology != PORT_TOPOLOGY_LOOP)
1887 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1890 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1891 fwd_streams[i]->rx_queue = 0;
1892 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1893 fwd_streams[i]->tx_queue = 0;
1894 fwd_streams[i]->peer_addr = j;
1895 fwd_streams[i]->retry_enabled = retry_enabled;
1897 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1898 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1899 fwd_streams[j]->rx_queue = 0;
1900 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1901 fwd_streams[j]->tx_queue = 0;
1902 fwd_streams[j]->peer_addr = i;
1903 fwd_streams[j]->retry_enabled = retry_enabled;
1909 * For the RSS forwarding test all streams distributed over lcores. Each stream
1910 * being composed of a RX queue to poll on a RX port for input messages,
1911 * associated with a TX queue of a TX port where to send forwarded packets.
1912 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1913 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1915 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1919 rss_fwd_config_setup(void)
1930 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1931 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1932 cur_fwd_config.nb_fwd_streams =
1933 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1935 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1936 cur_fwd_config.nb_fwd_lcores =
1937 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1939 /* reinitialize forwarding streams */
1942 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1944 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1945 struct fwd_stream *fs;
1947 fs = fwd_streams[sm_id];
1949 if ((rxp & 0x1) == 0)
1950 txp = (portid_t) (rxp + 1);
1952 txp = (portid_t) (rxp - 1);
1954 * if we are in loopback, simply send stuff out through the
1957 if (port_topology == PORT_TOPOLOGY_LOOP)
1960 fs->rx_port = fwd_ports_ids[rxp];
1962 fs->tx_port = fwd_ports_ids[txp];
1964 fs->peer_addr = fs->tx_port;
1965 fs->retry_enabled = retry_enabled;
1966 rxq = (queueid_t) (rxq + 1);
1971 * Restart from RX queue 0 on next RX port
1974 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1976 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1978 rxp = (portid_t) (rxp + 1);
1983 * For the DCB forwarding test, each core is assigned on each traffic class.
1985 * Each core is assigned a multi-stream, each stream being composed of
1986 * a RX queue to poll on a RX port for input messages, associated with
1987 * a TX queue of a TX port where to send forwarded packets. All RX and
1988 * TX queues are mapping to the same traffic class.
1989 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1993 dcb_fwd_config_setup(void)
1995 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1996 portid_t txp, rxp = 0;
1997 queueid_t txq, rxq = 0;
1999 uint16_t nb_rx_queue, nb_tx_queue;
2000 uint16_t i, j, k, sm_id = 0;
2003 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2004 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2005 cur_fwd_config.nb_fwd_streams =
2006 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2008 /* reinitialize forwarding streams */
2012 /* get the dcb info on the first RX and TX ports */
2013 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2014 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2016 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2017 fwd_lcores[lc_id]->stream_nb = 0;
2018 fwd_lcores[lc_id]->stream_idx = sm_id;
2019 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2020 /* if the nb_queue is zero, means this tc is
2021 * not enabled on the POOL
2023 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2025 k = fwd_lcores[lc_id]->stream_nb +
2026 fwd_lcores[lc_id]->stream_idx;
2027 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2028 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2029 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2030 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2031 for (j = 0; j < nb_rx_queue; j++) {
2032 struct fwd_stream *fs;
2034 fs = fwd_streams[k + j];
2035 fs->rx_port = fwd_ports_ids[rxp];
2036 fs->rx_queue = rxq + j;
2037 fs->tx_port = fwd_ports_ids[txp];
2038 fs->tx_queue = txq + j % nb_tx_queue;
2039 fs->peer_addr = fs->tx_port;
2040 fs->retry_enabled = retry_enabled;
2042 fwd_lcores[lc_id]->stream_nb +=
2043 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2045 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2048 if (tc < rxp_dcb_info.nb_tcs)
2050 /* Restart from TC 0 on next RX port */
2052 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2054 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2057 if (rxp >= nb_fwd_ports)
2059 /* get the dcb information on next RX and TX ports */
2060 if ((rxp & 0x1) == 0)
2061 txp = (portid_t) (rxp + 1);
2063 txp = (portid_t) (rxp - 1);
2064 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2065 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2070 icmp_echo_config_setup(void)
2077 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2078 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2079 (nb_txq * nb_fwd_ports);
2081 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2082 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2083 cur_fwd_config.nb_fwd_streams =
2084 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2085 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2086 cur_fwd_config.nb_fwd_lcores =
2087 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2088 if (verbose_level > 0) {
2089 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2091 cur_fwd_config.nb_fwd_lcores,
2092 cur_fwd_config.nb_fwd_ports,
2093 cur_fwd_config.nb_fwd_streams);
2096 /* reinitialize forwarding streams */
2098 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2100 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2101 if (verbose_level > 0)
2102 printf(" core=%d: \n", lc_id);
2103 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2104 struct fwd_stream *fs;
2105 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2106 fs->rx_port = fwd_ports_ids[rxp];
2108 fs->tx_port = fs->rx_port;
2110 fs->peer_addr = fs->tx_port;
2111 fs->retry_enabled = retry_enabled;
2112 if (verbose_level > 0)
2113 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2114 sm_id, fs->rx_port, fs->rx_queue,
2116 rxq = (queueid_t) (rxq + 1);
2117 if (rxq == nb_rxq) {
2119 rxp = (portid_t) (rxp + 1);
2126 fwd_config_setup(void)
2128 cur_fwd_config.fwd_eng = cur_fwd_eng;
2129 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2130 icmp_echo_config_setup();
2133 if ((nb_rxq > 1) && (nb_txq > 1)){
2135 dcb_fwd_config_setup();
2137 rss_fwd_config_setup();
2140 simple_fwd_config_setup();
2144 pkt_fwd_config_display(struct fwd_config *cfg)
2146 struct fwd_stream *fs;
2150 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2151 "NUMA support %s, MP over anonymous pages %s\n",
2152 cfg->fwd_eng->fwd_mode_name,
2153 retry_enabled == 0 ? "" : " with retry",
2154 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2155 numa_support == 1 ? "enabled" : "disabled",
2156 mp_anon != 0 ? "enabled" : "disabled");
2159 printf("TX retry num: %u, delay between TX retries: %uus\n",
2160 burst_tx_retry_num, burst_tx_delay_time);
2161 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2162 printf("Logical Core %u (socket %u) forwards packets on "
2164 fwd_lcores_cpuids[lc_id],
2165 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2166 fwd_lcores[lc_id]->stream_nb);
2167 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2168 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2169 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2170 "P=%d/Q=%d (socket %u) ",
2171 fs->rx_port, fs->rx_queue,
2172 ports[fs->rx_port].socket_id,
2173 fs->tx_port, fs->tx_queue,
2174 ports[fs->tx_port].socket_id);
2175 print_ethaddr("peer=",
2176 &peer_eth_addrs[fs->peer_addr]);
2184 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2187 unsigned int lcore_cpuid;
2192 for (i = 0; i < nb_lc; i++) {
2193 lcore_cpuid = lcorelist[i];
2194 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2195 printf("lcore %u not enabled\n", lcore_cpuid);
2198 if (lcore_cpuid == rte_get_master_lcore()) {
2199 printf("lcore %u cannot be masked on for running "
2200 "packet forwarding, which is the master lcore "
2201 "and reserved for command line parsing only\n",
2206 fwd_lcores_cpuids[i] = lcore_cpuid;
2208 if (record_now == 0) {
2212 nb_cfg_lcores = (lcoreid_t) nb_lc;
2213 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2214 printf("previous number of forwarding cores %u - changed to "
2215 "number of configured cores %u\n",
2216 (unsigned int) nb_fwd_lcores, nb_lc);
2217 nb_fwd_lcores = (lcoreid_t) nb_lc;
2224 set_fwd_lcores_mask(uint64_t lcoremask)
2226 unsigned int lcorelist[64];
2230 if (lcoremask == 0) {
2231 printf("Invalid NULL mask of cores\n");
2235 for (i = 0; i < 64; i++) {
2236 if (! ((uint64_t)(1ULL << i) & lcoremask))
2238 lcorelist[nb_lc++] = i;
2240 return set_fwd_lcores_list(lcorelist, nb_lc);
2244 set_fwd_lcores_number(uint16_t nb_lc)
2246 if (nb_lc > nb_cfg_lcores) {
2247 printf("nb fwd cores %u > %u (max. number of configured "
2248 "lcores) - ignored\n",
2249 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2252 nb_fwd_lcores = (lcoreid_t) nb_lc;
2253 printf("Number of forwarding cores set to %u\n",
2254 (unsigned int) nb_fwd_lcores);
2258 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2266 for (i = 0; i < nb_pt; i++) {
2267 port_id = (portid_t) portlist[i];
2268 if (port_id_is_invalid(port_id, ENABLED_WARN))
2271 fwd_ports_ids[i] = port_id;
2273 if (record_now == 0) {
2277 nb_cfg_ports = (portid_t) nb_pt;
2278 if (nb_fwd_ports != (portid_t) nb_pt) {
2279 printf("previous number of forwarding ports %u - changed to "
2280 "number of configured ports %u\n",
2281 (unsigned int) nb_fwd_ports, nb_pt);
2282 nb_fwd_ports = (portid_t) nb_pt;
2287 set_fwd_ports_mask(uint64_t portmask)
2289 unsigned int portlist[64];
2293 if (portmask == 0) {
2294 printf("Invalid NULL mask of ports\n");
2298 RTE_ETH_FOREACH_DEV(i) {
2299 if (! ((uint64_t)(1ULL << i) & portmask))
2301 portlist[nb_pt++] = i;
2303 set_fwd_ports_list(portlist, nb_pt);
2307 set_fwd_ports_number(uint16_t nb_pt)
2309 if (nb_pt > nb_cfg_ports) {
2310 printf("nb fwd ports %u > %u (number of configured "
2311 "ports) - ignored\n",
2312 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2315 nb_fwd_ports = (portid_t) nb_pt;
2316 printf("Number of forwarding ports set to %u\n",
2317 (unsigned int) nb_fwd_ports);
2321 port_is_forwarding(portid_t port_id)
2325 if (port_id_is_invalid(port_id, ENABLED_WARN))
2328 for (i = 0; i < nb_fwd_ports; i++) {
2329 if (fwd_ports_ids[i] == port_id)
2337 set_nb_pkt_per_burst(uint16_t nb)
2339 if (nb > MAX_PKT_BURST) {
2340 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2342 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2345 nb_pkt_per_burst = nb;
2346 printf("Number of packets per burst set to %u\n",
2347 (unsigned int) nb_pkt_per_burst);
2351 tx_split_get_name(enum tx_pkt_split split)
2355 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2356 if (tx_split_name[i].split == split)
2357 return tx_split_name[i].name;
2363 set_tx_pkt_split(const char *name)
2367 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2368 if (strcmp(tx_split_name[i].name, name) == 0) {
2369 tx_pkt_split = tx_split_name[i].split;
2373 printf("unknown value: \"%s\"\n", name);
2377 show_tx_pkt_segments(void)
2383 split = tx_split_get_name(tx_pkt_split);
2385 printf("Number of segments: %u\n", n);
2386 printf("Segment sizes: ");
2387 for (i = 0; i != n - 1; i++)
2388 printf("%hu,", tx_pkt_seg_lengths[i]);
2389 printf("%hu\n", tx_pkt_seg_lengths[i]);
2390 printf("Split packet: %s\n", split);
2394 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2396 uint16_t tx_pkt_len;
2399 if (nb_segs >= (unsigned) nb_txd) {
2400 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2401 nb_segs, (unsigned int) nb_txd);
2406 * Check that each segment length is greater or equal than
2407 * the mbuf data sise.
2408 * Check also that the total packet length is greater or equal than the
2409 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2412 for (i = 0; i < nb_segs; i++) {
2413 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2414 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2415 i, seg_lengths[i], (unsigned) mbuf_data_size);
2418 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2420 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2421 printf("total packet length=%u < %d - give up\n",
2422 (unsigned) tx_pkt_len,
2423 (int)(sizeof(struct ether_hdr) + 20 + 8));
2427 for (i = 0; i < nb_segs; i++)
2428 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2430 tx_pkt_length = tx_pkt_len;
2431 tx_pkt_nb_segs = (uint8_t) nb_segs;
2435 setup_gro(const char *onoff, portid_t port_id)
2437 if (!rte_eth_dev_is_valid_port(port_id)) {
2438 printf("invalid port id %u\n", port_id);
2441 if (test_done == 0) {
2442 printf("Before enable/disable GRO,"
2443 " please stop forwarding first\n");
2446 if (strcmp(onoff, "on") == 0) {
2447 if (gro_ports[port_id].enable != 0) {
2448 printf("Port %u has enabled GRO. Please"
2449 " disable GRO first\n", port_id);
2452 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2453 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2454 gro_ports[port_id].param.max_flow_num =
2455 GRO_DEFAULT_FLOW_NUM;
2456 gro_ports[port_id].param.max_item_per_flow =
2457 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2459 gro_ports[port_id].enable = 1;
2461 if (gro_ports[port_id].enable == 0) {
2462 printf("Port %u has disabled GRO\n", port_id);
2465 gro_ports[port_id].enable = 0;
2470 setup_gro_flush_cycles(uint8_t cycles)
2472 if (test_done == 0) {
2473 printf("Before change flush interval for GRO,"
2474 " please stop forwarding first.\n");
2478 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
2479 GRO_DEFAULT_FLUSH_CYCLES) {
2480 printf("The flushing cycle be in the range"
2481 " of 1 to %u. Revert to the default"
2483 GRO_MAX_FLUSH_CYCLES,
2484 GRO_DEFAULT_FLUSH_CYCLES);
2485 cycles = GRO_DEFAULT_FLUSH_CYCLES;
2488 gro_flush_cycles = cycles;
2492 show_gro(portid_t port_id)
2494 struct rte_gro_param *param;
2495 uint32_t max_pkts_num;
2497 param = &gro_ports[port_id].param;
2499 if (!rte_eth_dev_is_valid_port(port_id)) {
2500 printf("Invalid port id %u.\n", port_id);
2503 if (gro_ports[port_id].enable) {
2504 printf("GRO type: TCP/IPv4\n");
2505 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2506 max_pkts_num = param->max_flow_num *
2507 param->max_item_per_flow;
2509 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
2510 printf("Max number of packets to perform GRO: %u\n",
2512 printf("Flushing cycles: %u\n", gro_flush_cycles);
2514 printf("Port %u doesn't enable GRO.\n", port_id);
2518 setup_gso(const char *mode, portid_t port_id)
2520 if (!rte_eth_dev_is_valid_port(port_id)) {
2521 printf("invalid port id %u\n", port_id);
2524 if (strcmp(mode, "on") == 0) {
2525 if (test_done == 0) {
2526 printf("before enabling GSO,"
2527 " please stop forwarding first\n");
2530 gso_ports[port_id].enable = 1;
2531 } else if (strcmp(mode, "off") == 0) {
2532 if (test_done == 0) {
2533 printf("before disabling GSO,"
2534 " please stop forwarding first\n");
2537 gso_ports[port_id].enable = 0;
2542 list_pkt_forwarding_modes(void)
2544 static char fwd_modes[128] = "";
2545 const char *separator = "|";
2546 struct fwd_engine *fwd_eng;
2549 if (strlen (fwd_modes) == 0) {
2550 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2551 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2552 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2553 strncat(fwd_modes, separator,
2554 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2556 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2563 list_pkt_forwarding_retry_modes(void)
2565 static char fwd_modes[128] = "";
2566 const char *separator = "|";
2567 struct fwd_engine *fwd_eng;
2570 if (strlen(fwd_modes) == 0) {
2571 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2572 if (fwd_eng == &rx_only_engine)
2574 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2576 strlen(fwd_modes) - 1);
2577 strncat(fwd_modes, separator,
2579 strlen(fwd_modes) - 1);
2581 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2588 set_pkt_forwarding_mode(const char *fwd_mode_name)
2590 struct fwd_engine *fwd_eng;
2594 while ((fwd_eng = fwd_engines[i]) != NULL) {
2595 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2596 printf("Set %s packet forwarding mode%s\n",
2598 retry_enabled == 0 ? "" : " with retry");
2599 cur_fwd_eng = fwd_eng;
2604 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2608 set_verbose_level(uint16_t vb_level)
2610 printf("Change verbose level from %u to %u\n",
2611 (unsigned int) verbose_level, (unsigned int) vb_level);
2612 verbose_level = vb_level;
2616 vlan_extend_set(portid_t port_id, int on)
2621 if (port_id_is_invalid(port_id, ENABLED_WARN))
2624 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2627 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2629 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2631 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2633 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2634 "diag=%d\n", port_id, on, diag);
2638 rx_vlan_strip_set(portid_t port_id, int on)
2643 if (port_id_is_invalid(port_id, ENABLED_WARN))
2646 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2649 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2651 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2653 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2655 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2656 "diag=%d\n", port_id, on, diag);
2660 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2664 if (port_id_is_invalid(port_id, ENABLED_WARN))
2667 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2669 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2670 "diag=%d\n", port_id, queue_id, on, diag);
2674 rx_vlan_filter_set(portid_t port_id, int on)
2679 if (port_id_is_invalid(port_id, ENABLED_WARN))
2682 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2685 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2687 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2689 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2691 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2692 "diag=%d\n", port_id, on, diag);
2696 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2700 if (port_id_is_invalid(port_id, ENABLED_WARN))
2702 if (vlan_id_is_invalid(vlan_id))
2704 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2707 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2709 port_id, vlan_id, on, diag);
2714 rx_vlan_all_filter_set(portid_t port_id, int on)
2718 if (port_id_is_invalid(port_id, ENABLED_WARN))
2720 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2721 if (rx_vft_set(port_id, vlan_id, on))
2727 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2731 if (port_id_is_invalid(port_id, ENABLED_WARN))
2734 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2738 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2740 port_id, vlan_type, tp_id, diag);
2744 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2747 if (port_id_is_invalid(port_id, ENABLED_WARN))
2749 if (vlan_id_is_invalid(vlan_id))
2752 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2753 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2754 printf("Error, as QinQ has been enabled.\n");
2758 tx_vlan_reset(port_id);
2759 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
2760 ports[port_id].tx_vlan_id = vlan_id;
2764 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2767 if (port_id_is_invalid(port_id, ENABLED_WARN))
2769 if (vlan_id_is_invalid(vlan_id))
2771 if (vlan_id_is_invalid(vlan_id_outer))
2774 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2775 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2776 printf("Error, as QinQ hasn't been enabled.\n");
2780 tx_vlan_reset(port_id);
2781 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
2782 ports[port_id].tx_vlan_id = vlan_id;
2783 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2787 tx_vlan_reset(portid_t port_id)
2789 if (port_id_is_invalid(port_id, ENABLED_WARN))
2791 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
2792 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
2793 ports[port_id].tx_vlan_id = 0;
2794 ports[port_id].tx_vlan_id_outer = 0;
2798 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2800 if (port_id_is_invalid(port_id, ENABLED_WARN))
2803 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2807 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2810 uint8_t existing_mapping_found = 0;
2812 if (port_id_is_invalid(port_id, ENABLED_WARN))
2815 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2818 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2819 printf("map_value not in required range 0..%d\n",
2820 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2824 if (!is_rx) { /*then tx*/
2825 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2826 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2827 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2828 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2829 existing_mapping_found = 1;
2833 if (!existing_mapping_found) { /* A new additional mapping... */
2834 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2835 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2836 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2837 nb_tx_queue_stats_mappings++;
2841 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2842 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2843 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2844 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2845 existing_mapping_found = 1;
2849 if (!existing_mapping_found) { /* A new additional mapping... */
2850 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2851 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2852 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2853 nb_rx_queue_stats_mappings++;
2859 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2861 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2863 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2864 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2865 " tunnel_id: 0x%08x",
2866 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2867 rte_be_to_cpu_32(mask->tunnel_id_mask));
2868 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2869 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2870 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2871 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2873 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2874 rte_be_to_cpu_16(mask->src_port_mask),
2875 rte_be_to_cpu_16(mask->dst_port_mask));
2877 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2878 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2879 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
2880 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
2881 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
2883 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2884 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
2885 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
2886 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
2887 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
2894 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2896 struct rte_eth_flex_payload_cfg *cfg;
2899 for (i = 0; i < flex_conf->nb_payloads; i++) {
2900 cfg = &flex_conf->flex_set[i];
2901 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2903 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2904 printf("\n L2_PAYLOAD: ");
2905 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2906 printf("\n L3_PAYLOAD: ");
2907 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2908 printf("\n L4_PAYLOAD: ");
2910 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2911 for (j = 0; j < num; j++)
2912 printf(" %-5u", cfg->src_offset[j]);
2918 flowtype_to_str(uint16_t flow_type)
2920 struct flow_type_info {
2926 static struct flow_type_info flowtype_str_table[] = {
2927 {"raw", RTE_ETH_FLOW_RAW},
2928 {"ipv4", RTE_ETH_FLOW_IPV4},
2929 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2930 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2931 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2932 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2933 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2934 {"ipv6", RTE_ETH_FLOW_IPV6},
2935 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2936 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2937 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2938 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2939 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2940 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2941 {"port", RTE_ETH_FLOW_PORT},
2942 {"vxlan", RTE_ETH_FLOW_VXLAN},
2943 {"geneve", RTE_ETH_FLOW_GENEVE},
2944 {"nvgre", RTE_ETH_FLOW_NVGRE},
2947 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2948 if (flowtype_str_table[i].ftype == flow_type)
2949 return flowtype_str_table[i].str;
2956 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2958 struct rte_eth_fdir_flex_mask *mask;
2962 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2963 mask = &flex_conf->flex_mask[i];
2964 p = flowtype_to_str(mask->flow_type);
2965 printf("\n %s:\t", p ? p : "unknown");
2966 for (j = 0; j < num; j++)
2967 printf(" %02x", mask->mask[j]);
2973 print_fdir_flow_type(uint32_t flow_types_mask)
2978 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2979 if (!(flow_types_mask & (1 << i)))
2981 p = flowtype_to_str(i);
2991 fdir_get_infos(portid_t port_id)
2993 struct rte_eth_fdir_stats fdir_stat;
2994 struct rte_eth_fdir_info fdir_info;
2997 static const char *fdir_stats_border = "########################";
2999 if (port_id_is_invalid(port_id, ENABLED_WARN))
3001 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3003 printf("\n FDIR is not supported on port %-2d\n",
3008 memset(&fdir_info, 0, sizeof(fdir_info));
3009 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3010 RTE_ETH_FILTER_INFO, &fdir_info);
3011 memset(&fdir_stat, 0, sizeof(fdir_stat));
3012 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3013 RTE_ETH_FILTER_STATS, &fdir_stat);
3014 printf("\n %s FDIR infos for port %-2d %s\n",
3015 fdir_stats_border, port_id, fdir_stats_border);
3017 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3018 printf(" PERFECT\n");
3019 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3020 printf(" PERFECT-MAC-VLAN\n");
3021 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3022 printf(" PERFECT-TUNNEL\n");
3023 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3024 printf(" SIGNATURE\n");
3026 printf(" DISABLE\n");
3027 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3028 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3029 printf(" SUPPORTED FLOW TYPE: ");
3030 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3032 printf(" FLEX PAYLOAD INFO:\n");
3033 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3034 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3035 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3036 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3037 fdir_info.flex_payload_unit,
3038 fdir_info.max_flex_payload_segment_num,
3039 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3041 print_fdir_mask(&fdir_info.mask);
3042 if (fdir_info.flex_conf.nb_payloads > 0) {
3043 printf(" FLEX PAYLOAD SRC OFFSET:");
3044 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3046 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3047 printf(" FLEX MASK CFG:");
3048 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3050 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3051 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3052 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3053 fdir_info.guarant_spc, fdir_info.best_spc);
3054 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3055 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3056 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3057 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3058 fdir_stat.collision, fdir_stat.free,
3059 fdir_stat.maxhash, fdir_stat.maxlen,
3060 fdir_stat.add, fdir_stat.remove,
3061 fdir_stat.f_add, fdir_stat.f_remove);
3062 printf(" %s############################%s\n",
3063 fdir_stats_border, fdir_stats_border);
3067 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3069 struct rte_port *port;
3070 struct rte_eth_fdir_flex_conf *flex_conf;
3073 port = &ports[port_id];
3074 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3075 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3076 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3081 if (i >= RTE_ETH_FLOW_MAX) {
3082 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3083 idx = flex_conf->nb_flexmasks;
3084 flex_conf->nb_flexmasks++;
3086 printf("The flex mask table is full. Can not set flex"
3087 " mask for flow_type(%u).", cfg->flow_type);
3091 rte_memcpy(&flex_conf->flex_mask[idx],
3093 sizeof(struct rte_eth_fdir_flex_mask));
3097 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3099 struct rte_port *port;
3100 struct rte_eth_fdir_flex_conf *flex_conf;
3103 port = &ports[port_id];
3104 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3105 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3106 if (cfg->type == flex_conf->flex_set[i].type) {
3111 if (i >= RTE_ETH_PAYLOAD_MAX) {
3112 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3113 idx = flex_conf->nb_payloads;
3114 flex_conf->nb_payloads++;
3116 printf("The flex payload table is full. Can not set"
3117 " flex payload for type(%u).", cfg->type);
3121 rte_memcpy(&flex_conf->flex_set[idx],
3123 sizeof(struct rte_eth_flex_payload_cfg));
3128 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3130 #ifdef RTE_LIBRTE_IXGBE_PMD
3134 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3136 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3140 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3141 is_rx ? "rx" : "tx", port_id, diag);
3144 printf("VF %s setting not supported for port %d\n",
3145 is_rx ? "Rx" : "Tx", port_id);
3151 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3154 struct rte_eth_link link;
3156 if (port_id_is_invalid(port_id, ENABLED_WARN))
3158 rte_eth_link_get_nowait(port_id, &link);
3159 if (rate > link.link_speed) {
3160 printf("Invalid rate value:%u bigger than link speed: %u\n",
3161 rate, link.link_speed);
3164 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3167 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3173 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3175 int diag = -ENOTSUP;
3177 #ifdef RTE_LIBRTE_IXGBE_PMD
3178 if (diag == -ENOTSUP)
3179 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3182 #ifdef RTE_LIBRTE_BNXT_PMD
3183 if (diag == -ENOTSUP)
3184 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3189 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3195 * Functions to manage the set of filtered Multicast MAC addresses.
3197 * A pool of filtered multicast MAC addresses is associated with each port.
3198 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3199 * The address of the pool and the number of valid multicast MAC addresses
3200 * recorded in the pool are stored in the fields "mc_addr_pool" and
3201 * "mc_addr_nb" of the "rte_port" data structure.
3203 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3204 * to be supplied a contiguous array of multicast MAC addresses.
3205 * To comply with this constraint, the set of multicast addresses recorded
3206 * into the pool are systematically compacted at the beginning of the pool.
3207 * Hence, when a multicast address is removed from the pool, all following
3208 * addresses, if any, are copied back to keep the set contiguous.
3210 #define MCAST_POOL_INC 32
3213 mcast_addr_pool_extend(struct rte_port *port)
3215 struct ether_addr *mc_pool;
3216 size_t mc_pool_size;
3219 * If a free entry is available at the end of the pool, just
3220 * increment the number of recorded multicast addresses.
3222 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3228 * [re]allocate a pool with MCAST_POOL_INC more entries.
3229 * The previous test guarantees that port->mc_addr_nb is a multiple
3230 * of MCAST_POOL_INC.
3232 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3234 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3236 if (mc_pool == NULL) {
3237 printf("allocation of pool of %u multicast addresses failed\n",
3238 port->mc_addr_nb + MCAST_POOL_INC);
3242 port->mc_addr_pool = mc_pool;
3249 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3252 if (addr_idx == port->mc_addr_nb) {
3253 /* No need to recompact the set of multicast addressses. */
3254 if (port->mc_addr_nb == 0) {
3255 /* free the pool of multicast addresses. */
3256 free(port->mc_addr_pool);
3257 port->mc_addr_pool = NULL;
3261 memmove(&port->mc_addr_pool[addr_idx],
3262 &port->mc_addr_pool[addr_idx + 1],
3263 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3267 eth_port_multicast_addr_list_set(uint8_t port_id)
3269 struct rte_port *port;
3272 port = &ports[port_id];
3273 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3277 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3278 port->mc_addr_nb, port_id, -diag);
3282 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
3284 struct rte_port *port;
3287 if (port_id_is_invalid(port_id, ENABLED_WARN))
3290 port = &ports[port_id];
3293 * Check that the added multicast MAC address is not already recorded
3294 * in the pool of multicast addresses.
3296 for (i = 0; i < port->mc_addr_nb; i++) {
3297 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3298 printf("multicast address already filtered by port\n");
3303 if (mcast_addr_pool_extend(port) != 0)
3305 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3306 eth_port_multicast_addr_list_set(port_id);
3310 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
3312 struct rte_port *port;
3315 if (port_id_is_invalid(port_id, ENABLED_WARN))
3318 port = &ports[port_id];
3321 * Search the pool of multicast MAC addresses for the removed address.
3323 for (i = 0; i < port->mc_addr_nb; i++) {
3324 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3327 if (i == port->mc_addr_nb) {
3328 printf("multicast address not filtered by port %d\n", port_id);
3332 mcast_addr_pool_remove(port, i);
3333 eth_port_multicast_addr_list_set(port_id);
3337 port_dcb_info_display(uint8_t port_id)
3339 struct rte_eth_dcb_info dcb_info;
3342 static const char *border = "================";
3344 if (port_id_is_invalid(port_id, ENABLED_WARN))
3347 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3349 printf("\n Failed to get dcb infos on port %-2d\n",
3353 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3354 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3356 for (i = 0; i < dcb_info.nb_tcs; i++)
3358 printf("\n Priority : ");
3359 for (i = 0; i < dcb_info.nb_tcs; i++)
3360 printf("\t%4d", dcb_info.prio_tc[i]);
3361 printf("\n BW percent :");
3362 for (i = 0; i < dcb_info.nb_tcs; i++)
3363 printf("\t%4d%%", dcb_info.tc_bws[i]);
3364 printf("\n RXQ base : ");
3365 for (i = 0; i < dcb_info.nb_tcs; i++)
3366 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3367 printf("\n RXQ number :");
3368 for (i = 0; i < dcb_info.nb_tcs; i++)
3369 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3370 printf("\n TXQ base : ");
3371 for (i = 0; i < dcb_info.nb_tcs; i++)
3372 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3373 printf("\n TXQ number :");
3374 for (i = 0; i < dcb_info.nb_tcs; i++)
3375 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3380 open_ddp_package_file(const char *file_path, uint32_t *size)
3382 int fd = open(file_path, O_RDONLY);
3384 uint8_t *buf = NULL;
3392 printf("%s: Failed to open %s\n", __func__, file_path);
3396 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
3398 printf("%s: File operations failed\n", __func__);
3402 pkg_size = st_buf.st_size;
3405 printf("%s: File operations failed\n", __func__);
3409 buf = (uint8_t *)malloc(pkg_size);
3412 printf("%s: Failed to malloc memory\n", __func__);
3416 ret = read(fd, buf, pkg_size);
3419 printf("%s: File read operation failed\n", __func__);
3420 close_ddp_package_file(buf);
3433 save_ddp_package_file(const char *file_path, uint8_t *buf, uint32_t size)
3435 FILE *fh = fopen(file_path, "wb");
3438 printf("%s: Failed to open %s\n", __func__, file_path);
3442 if (fwrite(buf, 1, size, fh) != size) {
3444 printf("%s: File write operation failed\n", __func__);
3454 close_ddp_package_file(uint8_t *buf)