4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * Copyright 2013-2014 6WIND S.A.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name of 6WIND S.A. nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72 #include <sys/queue.h>
74 #include <rte_common.h>
75 #include <rte_byteorder.h>
76 #include <rte_debug.h>
78 #include <rte_memory.h>
79 #include <rte_memcpy.h>
80 #include <rte_memzone.h>
81 #include <rte_launch.h>
83 #include <rte_per_lcore.h>
84 #include <rte_lcore.h>
85 #include <rte_atomic.h>
86 #include <rte_branch_prediction.h>
87 #include <rte_mempool.h>
89 #include <rte_interrupts.h>
91 #include <rte_ether.h>
92 #include <rte_ethdev.h>
93 #include <rte_string_fns.h>
94 #include <rte_cycles.h>
96 #include <rte_errno.h>
97 #ifdef RTE_LIBRTE_IXGBE_PMD
98 #include <rte_pmd_ixgbe.h>
103 static char *flowtype_to_str(uint16_t flow_type);
105 static const struct {
106 enum tx_pkt_split split;
108 } tx_split_name[] = {
110 .split = TX_PKT_SPLIT_OFF,
114 .split = TX_PKT_SPLIT_ON,
118 .split = TX_PKT_SPLIT_RND,
123 struct rss_type_info {
128 static const struct rss_type_info rss_type_table[] = {
129 { "ipv4", ETH_RSS_IPV4 },
130 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
131 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
132 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
133 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
134 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
135 { "ipv6", ETH_RSS_IPV6 },
136 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
137 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
138 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
139 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
140 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
141 { "l2-payload", ETH_RSS_L2_PAYLOAD },
142 { "ipv6-ex", ETH_RSS_IPV6_EX },
143 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
144 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
145 { "port", ETH_RSS_PORT },
146 { "vxlan", ETH_RSS_VXLAN },
147 { "geneve", ETH_RSS_GENEVE },
148 { "nvgre", ETH_RSS_NVGRE },
153 print_ethaddr(const char *name, struct ether_addr *eth_addr)
155 char buf[ETHER_ADDR_FMT_SIZE];
156 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
157 printf("%s%s", name, buf);
161 nic_stats_display(portid_t port_id)
163 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
164 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
165 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
166 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles;
167 uint64_t mpps_rx, mpps_tx;
168 struct rte_eth_stats stats;
169 struct rte_port *port = &ports[port_id];
173 static const char *nic_stats_border = "########################";
175 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
176 printf("Valid port range is [0");
177 FOREACH_PORT(pid, ports)
182 rte_eth_stats_get(port_id, &stats);
183 printf("\n %s NIC statistics for port %-2d %s\n",
184 nic_stats_border, port_id, nic_stats_border);
186 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
187 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
189 stats.ipackets, stats.imissed, stats.ibytes);
190 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
191 printf(" RX-nombuf: %-10"PRIu64"\n",
193 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
195 stats.opackets, stats.oerrors, stats.obytes);
198 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
199 " RX-bytes: %10"PRIu64"\n",
200 stats.ipackets, stats.ierrors, stats.ibytes);
201 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
202 printf(" RX-nombuf: %10"PRIu64"\n",
204 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
205 " TX-bytes: %10"PRIu64"\n",
206 stats.opackets, stats.oerrors, stats.obytes);
209 if (port->rx_queue_stats_mapping_enabled) {
211 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
212 printf(" Stats reg %2d RX-packets: %10"PRIu64
213 " RX-errors: %10"PRIu64
214 " RX-bytes: %10"PRIu64"\n",
215 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
218 if (port->tx_queue_stats_mapping_enabled) {
220 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
221 printf(" Stats reg %2d TX-packets: %10"PRIu64
222 " TX-bytes: %10"PRIu64"\n",
223 i, stats.q_opackets[i], stats.q_obytes[i]);
227 diff_cycles = prev_cycles[port_id];
228 prev_cycles[port_id] = rte_rdtsc();
230 diff_cycles = prev_cycles[port_id] - diff_cycles;
232 diff_pkts_rx = stats.ipackets - prev_pkts_rx[port_id];
233 diff_pkts_tx = stats.opackets - prev_pkts_tx[port_id];
234 prev_pkts_rx[port_id] = stats.ipackets;
235 prev_pkts_tx[port_id] = stats.opackets;
236 mpps_rx = diff_cycles > 0 ?
237 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
238 mpps_tx = diff_cycles > 0 ?
239 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
240 printf("\n Throughput (since last show)\n");
241 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
244 printf(" %s############################%s\n",
245 nic_stats_border, nic_stats_border);
249 nic_stats_clear(portid_t port_id)
253 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
254 printf("Valid port range is [0");
255 FOREACH_PORT(pid, ports)
260 rte_eth_stats_reset(port_id);
261 printf("\n NIC statistics for port %d cleared\n", port_id);
265 nic_xstats_display(portid_t port_id)
267 struct rte_eth_xstat *xstats;
268 int cnt_xstats, idx_xstat;
269 struct rte_eth_xstat_name *xstats_names;
271 printf("###### NIC extended statistics for port %-2d\n", port_id);
272 if (!rte_eth_dev_is_valid_port(port_id)) {
273 printf("Error: Invalid port number %i\n", port_id);
278 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
279 if (cnt_xstats < 0) {
280 printf("Error: Cannot get count of xstats\n");
284 /* Get id-name lookup table */
285 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
286 if (xstats_names == NULL) {
287 printf("Cannot allocate memory for xstats lookup\n");
290 if (cnt_xstats != rte_eth_xstats_get_names(
291 port_id, xstats_names, cnt_xstats)) {
292 printf("Error: Cannot get xstats lookup\n");
297 /* Get stats themselves */
298 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
299 if (xstats == NULL) {
300 printf("Cannot allocate memory for xstats\n");
304 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
305 printf("Error: Unable to get xstats\n");
312 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
313 printf("%s: %"PRIu64"\n",
314 xstats_names[idx_xstat].name,
315 xstats[idx_xstat].value);
321 nic_xstats_clear(portid_t port_id)
323 rte_eth_xstats_reset(port_id);
327 nic_stats_mapping_display(portid_t port_id)
329 struct rte_port *port = &ports[port_id];
333 static const char *nic_stats_mapping_border = "########################";
335 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
336 printf("Valid port range is [0");
337 FOREACH_PORT(pid, ports)
343 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
344 printf("Port id %d - either does not support queue statistic mapping or"
345 " no queue statistic mapping set\n", port_id);
349 printf("\n %s NIC statistics mapping for port %-2d %s\n",
350 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
352 if (port->rx_queue_stats_mapping_enabled) {
353 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
354 if (rx_queue_stats_mappings[i].port_id == port_id) {
355 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
356 rx_queue_stats_mappings[i].queue_id,
357 rx_queue_stats_mappings[i].stats_counter_id);
364 if (port->tx_queue_stats_mapping_enabled) {
365 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
366 if (tx_queue_stats_mappings[i].port_id == port_id) {
367 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
368 tx_queue_stats_mappings[i].queue_id,
369 tx_queue_stats_mappings[i].stats_counter_id);
374 printf(" %s####################################%s\n",
375 nic_stats_mapping_border, nic_stats_mapping_border);
379 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
381 struct rte_eth_rxq_info qinfo;
383 static const char *info_border = "*********************";
385 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
387 printf("Failed to retrieve information for port: %hhu, "
388 "RX queue: %hu\nerror desc: %s(%d)\n",
389 port_id, queue_id, strerror(-rc), rc);
393 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
394 info_border, port_id, queue_id, info_border);
396 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
397 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
398 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
399 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
400 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
401 printf("\nRX drop packets: %s",
402 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
403 printf("\nRX deferred start: %s",
404 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
405 printf("\nRX scattered packets: %s",
406 (qinfo.scattered_rx != 0) ? "on" : "off");
407 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
412 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
414 struct rte_eth_txq_info qinfo;
416 static const char *info_border = "*********************";
418 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
420 printf("Failed to retrieve information for port: %hhu, "
421 "TX queue: %hu\nerror desc: %s(%d)\n",
422 port_id, queue_id, strerror(-rc), rc);
426 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
427 info_border, port_id, queue_id, info_border);
429 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
430 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
431 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
432 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
433 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
434 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
435 printf("\nTX deferred start: %s",
436 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
437 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
442 port_infos_display(portid_t port_id)
444 struct rte_port *port;
445 struct ether_addr mac_addr;
446 struct rte_eth_link link;
447 struct rte_eth_dev_info dev_info;
449 struct rte_mempool * mp;
450 static const char *info_border = "*********************";
453 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
454 printf("Valid port range is [0");
455 FOREACH_PORT(pid, ports)
460 port = &ports[port_id];
461 rte_eth_link_get_nowait(port_id, &link);
462 memset(&dev_info, 0, sizeof(dev_info));
463 rte_eth_dev_info_get(port_id, &dev_info);
464 printf("\n%s Infos for port %-2d %s\n",
465 info_border, port_id, info_border);
466 rte_eth_macaddr_get(port_id, &mac_addr);
467 print_ethaddr("MAC address: ", &mac_addr);
468 printf("\nDriver name: %s", dev_info.driver_name);
469 printf("\nConnect to socket: %u", port->socket_id);
471 if (port_numa[port_id] != NUMA_NO_CONFIG) {
472 mp = mbuf_pool_find(port_numa[port_id]);
474 printf("\nmemory allocation on the socket: %d",
477 printf("\nmemory allocation on the socket: %u",port->socket_id);
479 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
480 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
481 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
482 ("full-duplex") : ("half-duplex"));
483 printf("Promiscuous mode: %s\n",
484 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
485 printf("Allmulticast mode: %s\n",
486 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
487 printf("Maximum number of MAC addresses: %u\n",
488 (unsigned int)(port->dev_info.max_mac_addrs));
489 printf("Maximum number of MAC addresses of hash filtering: %u\n",
490 (unsigned int)(port->dev_info.max_hash_mac_addrs));
492 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
493 if (vlan_offload >= 0){
494 printf("VLAN offload: \n");
495 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
496 printf(" strip on \n");
498 printf(" strip off \n");
500 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
501 printf(" filter on \n");
503 printf(" filter off \n");
505 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
506 printf(" qinq(extend) on \n");
508 printf(" qinq(extend) off \n");
511 if (dev_info.hash_key_size > 0)
512 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
513 if (dev_info.reta_size > 0)
514 printf("Redirection table size: %u\n", dev_info.reta_size);
515 if (!dev_info.flow_type_rss_offloads)
516 printf("No flow type is supported.\n");
521 printf("Supported flow types:\n");
522 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
524 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
526 p = flowtype_to_str(i);
527 printf(" %s\n", (p ? p : "unknown"));
531 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
532 printf("Max possible number of RXDs per queue: %hu\n",
533 dev_info.rx_desc_lim.nb_max);
534 printf("Min possible number of RXDs per queue: %hu\n",
535 dev_info.rx_desc_lim.nb_min);
536 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
538 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
539 printf("Max possible number of TXDs per queue: %hu\n",
540 dev_info.tx_desc_lim.nb_max);
541 printf("Min possible number of TXDs per queue: %hu\n",
542 dev_info.tx_desc_lim.nb_min);
543 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
547 port_offload_cap_display(portid_t port_id)
549 struct rte_eth_dev *dev;
550 struct rte_eth_dev_info dev_info;
551 static const char *info_border = "************";
553 if (port_id_is_invalid(port_id, ENABLED_WARN))
556 dev = &rte_eth_devices[port_id];
557 rte_eth_dev_info_get(port_id, &dev_info);
559 printf("\n%s Port %d supported offload features: %s\n",
560 info_border, port_id, info_border);
562 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
563 printf("VLAN stripped: ");
564 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
570 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
571 printf("Double VLANs stripped: ");
572 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
578 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
579 printf("RX IPv4 checksum: ");
580 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
586 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
587 printf("RX UDP checksum: ");
588 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
594 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
595 printf("RX TCP checksum: ");
596 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
602 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
603 printf("RX Outer IPv4 checksum: on");
605 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
606 printf("Large receive offload: ");
607 if (dev->data->dev_conf.rxmode.enable_lro)
613 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
614 printf("VLAN insert: ");
615 if (ports[port_id].tx_ol_flags &
616 TESTPMD_TX_OFFLOAD_INSERT_VLAN)
622 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
623 printf("Double VLANs insert: ");
624 if (ports[port_id].tx_ol_flags &
625 TESTPMD_TX_OFFLOAD_INSERT_QINQ)
631 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
632 printf("TX IPv4 checksum: ");
633 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
639 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
640 printf("TX UDP checksum: ");
641 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
647 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
648 printf("TX TCP checksum: ");
649 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
655 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
656 printf("TX SCTP checksum: ");
657 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
663 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
664 printf("TX Outer IPv4 checksum: ");
665 if (ports[port_id].tx_ol_flags &
666 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
672 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
673 printf("TX TCP segmentation: ");
674 if (ports[port_id].tso_segsz != 0)
680 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
681 printf("TX UDP segmentation: ");
682 if (ports[port_id].tso_segsz != 0)
688 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
689 printf("TSO for VXLAN tunnel packet: ");
690 if (ports[port_id].tunnel_tso_segsz)
696 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
697 printf("TSO for GRE tunnel packet: ");
698 if (ports[port_id].tunnel_tso_segsz)
704 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
705 printf("TSO for IPIP tunnel packet: ");
706 if (ports[port_id].tunnel_tso_segsz)
712 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
713 printf("TSO for GENEVE tunnel packet: ");
714 if (ports[port_id].tunnel_tso_segsz)
723 port_id_is_invalid(portid_t port_id, enum print_warning warning)
725 if (port_id == (portid_t)RTE_PORT_ALL)
728 if (port_id < RTE_MAX_ETHPORTS && ports[port_id].enabled)
731 if (warning == ENABLED_WARN)
732 printf("Invalid port %d\n", port_id);
738 vlan_id_is_invalid(uint16_t vlan_id)
742 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
747 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
752 printf("Port register offset 0x%X not aligned on a 4-byte "
757 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
758 if (reg_off >= pci_len) {
759 printf("Port %d: register offset %u (0x%X) out of port PCI "
760 "resource (length=%"PRIu64")\n",
761 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
768 reg_bit_pos_is_invalid(uint8_t bit_pos)
772 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
776 #define display_port_and_reg_off(port_id, reg_off) \
777 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
780 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
782 display_port_and_reg_off(port_id, (unsigned)reg_off);
783 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
787 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
792 if (port_id_is_invalid(port_id, ENABLED_WARN))
794 if (port_reg_off_is_invalid(port_id, reg_off))
796 if (reg_bit_pos_is_invalid(bit_x))
798 reg_v = port_id_pci_reg_read(port_id, reg_off);
799 display_port_and_reg_off(port_id, (unsigned)reg_off);
800 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
804 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
805 uint8_t bit1_pos, uint8_t bit2_pos)
811 if (port_id_is_invalid(port_id, ENABLED_WARN))
813 if (port_reg_off_is_invalid(port_id, reg_off))
815 if (reg_bit_pos_is_invalid(bit1_pos))
817 if (reg_bit_pos_is_invalid(bit2_pos))
819 if (bit1_pos > bit2_pos)
820 l_bit = bit2_pos, h_bit = bit1_pos;
822 l_bit = bit1_pos, h_bit = bit2_pos;
824 reg_v = port_id_pci_reg_read(port_id, reg_off);
827 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
828 display_port_and_reg_off(port_id, (unsigned)reg_off);
829 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
830 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
834 port_reg_display(portid_t port_id, uint32_t reg_off)
838 if (port_id_is_invalid(port_id, ENABLED_WARN))
840 if (port_reg_off_is_invalid(port_id, reg_off))
842 reg_v = port_id_pci_reg_read(port_id, reg_off);
843 display_port_reg_value(port_id, reg_off, reg_v);
847 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
852 if (port_id_is_invalid(port_id, ENABLED_WARN))
854 if (port_reg_off_is_invalid(port_id, reg_off))
856 if (reg_bit_pos_is_invalid(bit_pos))
859 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
862 reg_v = port_id_pci_reg_read(port_id, reg_off);
864 reg_v &= ~(1 << bit_pos);
866 reg_v |= (1 << bit_pos);
867 port_id_pci_reg_write(port_id, reg_off, reg_v);
868 display_port_reg_value(port_id, reg_off, reg_v);
872 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
873 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
880 if (port_id_is_invalid(port_id, ENABLED_WARN))
882 if (port_reg_off_is_invalid(port_id, reg_off))
884 if (reg_bit_pos_is_invalid(bit1_pos))
886 if (reg_bit_pos_is_invalid(bit2_pos))
888 if (bit1_pos > bit2_pos)
889 l_bit = bit2_pos, h_bit = bit1_pos;
891 l_bit = bit1_pos, h_bit = bit2_pos;
893 if ((h_bit - l_bit) < 31)
894 max_v = (1 << (h_bit - l_bit + 1)) - 1;
899 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
900 (unsigned)value, (unsigned)value,
901 (unsigned)max_v, (unsigned)max_v);
904 reg_v = port_id_pci_reg_read(port_id, reg_off);
905 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
906 reg_v |= (value << l_bit); /* Set changed bits */
907 port_id_pci_reg_write(port_id, reg_off, reg_v);
908 display_port_reg_value(port_id, reg_off, reg_v);
912 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
914 if (port_id_is_invalid(port_id, ENABLED_WARN))
916 if (port_reg_off_is_invalid(port_id, reg_off))
918 port_id_pci_reg_write(port_id, reg_off, reg_v);
919 display_port_reg_value(port_id, reg_off, reg_v);
923 port_mtu_set(portid_t port_id, uint16_t mtu)
927 if (port_id_is_invalid(port_id, ENABLED_WARN))
929 diag = rte_eth_dev_set_mtu(port_id, mtu);
932 printf("Set MTU failed. diag=%d\n", diag);
935 /* Generic flow management functions. */
937 /** Generate flow_item[] entry. */
938 #define MK_FLOW_ITEM(t, s) \
939 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
944 /** Information about known flow pattern items. */
945 static const struct {
949 MK_FLOW_ITEM(END, 0),
950 MK_FLOW_ITEM(VOID, 0),
951 MK_FLOW_ITEM(INVERT, 0),
952 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
954 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
955 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
956 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
957 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
958 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
959 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
960 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
961 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
962 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
963 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
964 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
965 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
968 /** Compute storage space needed by item specification. */
970 flow_item_spec_size(const struct rte_flow_item *item,
971 size_t *size, size_t *pad)
975 switch (item->type) {
977 const struct rte_flow_item_raw *raw;
980 case RTE_FLOW_ITEM_TYPE_RAW:
981 spec.raw = item->spec;
982 *size = offsetof(struct rte_flow_item_raw, pattern) +
983 spec.raw->length * sizeof(*spec.raw->pattern);
990 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
993 /** Generate flow_action[] entry. */
994 #define MK_FLOW_ACTION(t, s) \
995 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
1000 /** Information about known flow actions. */
1001 static const struct {
1005 MK_FLOW_ACTION(END, 0),
1006 MK_FLOW_ACTION(VOID, 0),
1007 MK_FLOW_ACTION(PASSTHRU, 0),
1008 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1009 MK_FLOW_ACTION(FLAG, 0),
1010 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
1011 MK_FLOW_ACTION(DROP, 0),
1012 MK_FLOW_ACTION(COUNT, 0),
1013 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
1014 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
1015 MK_FLOW_ACTION(PF, 0),
1016 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1019 /** Compute storage space needed by action configuration. */
1021 flow_action_conf_size(const struct rte_flow_action *action,
1022 size_t *size, size_t *pad)
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);
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);
1432 * RX/TX ring descriptors display functions.
1435 rx_queue_id_is_invalid(queueid_t rxq_id)
1437 if (rxq_id < nb_rxq)
1439 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1444 tx_queue_id_is_invalid(queueid_t txq_id)
1446 if (txq_id < nb_txq)
1448 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1453 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1455 if (rxdesc_id < nb_rxd)
1457 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1463 tx_desc_id_is_invalid(uint16_t txdesc_id)
1465 if (txdesc_id < nb_txd)
1467 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1472 static const struct rte_memzone *
1473 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
1475 char mz_name[RTE_MEMZONE_NAMESIZE];
1476 const struct rte_memzone *mz;
1478 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1479 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1480 mz = rte_memzone_lookup(mz_name);
1482 printf("%s ring memory zoneof (port %d, queue %d) not"
1483 "found (zone name = %s\n",
1484 ring_name, port_id, q_id, mz_name);
1488 union igb_ring_dword {
1491 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1501 struct igb_ring_desc_32_bytes {
1502 union igb_ring_dword lo_dword;
1503 union igb_ring_dword hi_dword;
1504 union igb_ring_dword resv1;
1505 union igb_ring_dword resv2;
1508 struct igb_ring_desc_16_bytes {
1509 union igb_ring_dword lo_dword;
1510 union igb_ring_dword hi_dword;
1514 ring_rxd_display_dword(union igb_ring_dword dword)
1516 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1517 (unsigned)dword.words.hi);
1521 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1522 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1525 __rte_unused uint8_t port_id,
1529 struct igb_ring_desc_16_bytes *ring =
1530 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1531 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1532 struct rte_eth_dev_info dev_info;
1534 memset(&dev_info, 0, sizeof(dev_info));
1535 rte_eth_dev_info_get(port_id, &dev_info);
1536 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1537 /* 32 bytes RX descriptor, i40e only */
1538 struct igb_ring_desc_32_bytes *ring =
1539 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1540 ring[desc_id].lo_dword.dword =
1541 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1542 ring_rxd_display_dword(ring[desc_id].lo_dword);
1543 ring[desc_id].hi_dword.dword =
1544 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1545 ring_rxd_display_dword(ring[desc_id].hi_dword);
1546 ring[desc_id].resv1.dword =
1547 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1548 ring_rxd_display_dword(ring[desc_id].resv1);
1549 ring[desc_id].resv2.dword =
1550 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1551 ring_rxd_display_dword(ring[desc_id].resv2);
1556 /* 16 bytes RX descriptor */
1557 ring[desc_id].lo_dword.dword =
1558 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1559 ring_rxd_display_dword(ring[desc_id].lo_dword);
1560 ring[desc_id].hi_dword.dword =
1561 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1562 ring_rxd_display_dword(ring[desc_id].hi_dword);
1566 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1568 struct igb_ring_desc_16_bytes *ring;
1569 struct igb_ring_desc_16_bytes txd;
1571 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1572 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1573 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1574 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1575 (unsigned)txd.lo_dword.words.lo,
1576 (unsigned)txd.lo_dword.words.hi,
1577 (unsigned)txd.hi_dword.words.lo,
1578 (unsigned)txd.hi_dword.words.hi);
1582 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1584 const struct rte_memzone *rx_mz;
1586 if (port_id_is_invalid(port_id, ENABLED_WARN))
1588 if (rx_queue_id_is_invalid(rxq_id))
1590 if (rx_desc_id_is_invalid(rxd_id))
1592 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1595 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1599 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1601 const struct rte_memzone *tx_mz;
1603 if (port_id_is_invalid(port_id, ENABLED_WARN))
1605 if (tx_queue_id_is_invalid(txq_id))
1607 if (tx_desc_id_is_invalid(txd_id))
1609 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1612 ring_tx_descriptor_display(tx_mz, txd_id);
1616 fwd_lcores_config_display(void)
1620 printf("List of forwarding lcores:");
1621 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1622 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1626 rxtx_config_display(void)
1628 printf(" %s packet forwarding%s - CRC stripping %s - "
1629 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
1630 retry_enabled == 0 ? "" : " with retry",
1631 rx_mode.hw_strip_crc ? "enabled" : "disabled",
1634 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1635 printf(" packet len=%u - nb packet segments=%d\n",
1636 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1638 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
1639 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
1641 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1642 nb_fwd_lcores, nb_fwd_ports);
1643 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1644 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1645 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1646 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
1647 rx_conf->rx_thresh.wthresh);
1648 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1649 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1650 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1651 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
1652 tx_conf->tx_thresh.wthresh);
1653 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
1654 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
1658 port_rss_reta_info(portid_t port_id,
1659 struct rte_eth_rss_reta_entry64 *reta_conf,
1660 uint16_t nb_entries)
1662 uint16_t i, idx, shift;
1665 if (port_id_is_invalid(port_id, ENABLED_WARN))
1668 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1670 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1674 for (i = 0; i < nb_entries; i++) {
1675 idx = i / RTE_RETA_GROUP_SIZE;
1676 shift = i % RTE_RETA_GROUP_SIZE;
1677 if (!(reta_conf[idx].mask & (1ULL << shift)))
1679 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1680 i, reta_conf[idx].reta[shift]);
1685 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1689 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1691 struct rte_eth_rss_conf rss_conf;
1692 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1696 struct rte_eth_dev_info dev_info;
1697 uint8_t hash_key_size;
1699 if (port_id_is_invalid(port_id, ENABLED_WARN))
1702 memset(&dev_info, 0, sizeof(dev_info));
1703 rte_eth_dev_info_get(port_id, &dev_info);
1704 if (dev_info.hash_key_size > 0 &&
1705 dev_info.hash_key_size <= sizeof(rss_key))
1706 hash_key_size = dev_info.hash_key_size;
1708 printf("dev_info did not provide a valid hash key size\n");
1712 rss_conf.rss_hf = 0;
1713 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1714 if (!strcmp(rss_info, rss_type_table[i].str))
1715 rss_conf.rss_hf = rss_type_table[i].rss_type;
1718 /* Get RSS hash key if asked to display it */
1719 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1720 rss_conf.rss_key_len = hash_key_size;
1721 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1725 printf("port index %d invalid\n", port_id);
1728 printf("operation not supported by device\n");
1731 printf("operation failed - diag=%d\n", diag);
1736 rss_hf = rss_conf.rss_hf;
1738 printf("RSS disabled\n");
1741 printf("RSS functions:\n ");
1742 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1743 if (rss_hf & rss_type_table[i].rss_type)
1744 printf("%s ", rss_type_table[i].str);
1749 printf("RSS key:\n");
1750 for (i = 0; i < hash_key_size; i++)
1751 printf("%02X", rss_key[i]);
1756 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1759 struct rte_eth_rss_conf rss_conf;
1763 rss_conf.rss_key = NULL;
1764 rss_conf.rss_key_len = hash_key_len;
1765 rss_conf.rss_hf = 0;
1766 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1767 if (!strcmp(rss_type_table[i].str, rss_type))
1768 rss_conf.rss_hf = rss_type_table[i].rss_type;
1770 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1772 rss_conf.rss_key = hash_key;
1773 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1780 printf("port index %d invalid\n", port_id);
1783 printf("operation not supported by device\n");
1786 printf("operation failed - diag=%d\n", diag);
1792 * Setup forwarding configuration for each logical core.
1795 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1797 streamid_t nb_fs_per_lcore;
1805 nb_fs = cfg->nb_fwd_streams;
1806 nb_fc = cfg->nb_fwd_lcores;
1807 if (nb_fs <= nb_fc) {
1808 nb_fs_per_lcore = 1;
1811 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1812 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1815 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1817 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1818 fwd_lcores[lc_id]->stream_idx = sm_id;
1819 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1820 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1824 * Assign extra remaining streams, if any.
1826 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1827 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1828 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1829 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1830 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1835 simple_fwd_config_setup(void)
1841 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1842 port_topology == PORT_TOPOLOGY_LOOP) {
1844 } else if (nb_fwd_ports % 2) {
1845 printf("\nWarning! Cannot handle an odd number of ports "
1846 "with the current port topology. Configuration "
1847 "must be changed to have an even number of ports, "
1848 "or relaunch application with "
1849 "--port-topology=chained\n\n");
1852 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1853 cur_fwd_config.nb_fwd_streams =
1854 (streamid_t) cur_fwd_config.nb_fwd_ports;
1856 /* reinitialize forwarding streams */
1860 * In the simple forwarding test, the number of forwarding cores
1861 * must be lower or equal to the number of forwarding ports.
1863 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1864 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1865 cur_fwd_config.nb_fwd_lcores =
1866 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1867 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1869 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1870 if (port_topology != PORT_TOPOLOGY_LOOP)
1871 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1874 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1875 fwd_streams[i]->rx_queue = 0;
1876 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1877 fwd_streams[i]->tx_queue = 0;
1878 fwd_streams[i]->peer_addr = j;
1879 fwd_streams[i]->retry_enabled = retry_enabled;
1881 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1882 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1883 fwd_streams[j]->rx_queue = 0;
1884 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1885 fwd_streams[j]->tx_queue = 0;
1886 fwd_streams[j]->peer_addr = i;
1887 fwd_streams[j]->retry_enabled = retry_enabled;
1893 * For the RSS forwarding test all streams distributed over lcores. Each stream
1894 * being composed of a RX queue to poll on a RX port for input messages,
1895 * associated with a TX queue of a TX port where to send forwarded packets.
1896 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1897 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1899 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1903 rss_fwd_config_setup(void)
1914 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1915 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1916 cur_fwd_config.nb_fwd_streams =
1917 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1919 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1920 cur_fwd_config.nb_fwd_lcores =
1921 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1923 /* reinitialize forwarding streams */
1926 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1928 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1929 struct fwd_stream *fs;
1931 fs = fwd_streams[sm_id];
1933 if ((rxp & 0x1) == 0)
1934 txp = (portid_t) (rxp + 1);
1936 txp = (portid_t) (rxp - 1);
1938 * if we are in loopback, simply send stuff out through the
1941 if (port_topology == PORT_TOPOLOGY_LOOP)
1944 fs->rx_port = fwd_ports_ids[rxp];
1946 fs->tx_port = fwd_ports_ids[txp];
1948 fs->peer_addr = fs->tx_port;
1949 fs->retry_enabled = retry_enabled;
1950 rxq = (queueid_t) (rxq + 1);
1955 * Restart from RX queue 0 on next RX port
1958 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1960 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1962 rxp = (portid_t) (rxp + 1);
1967 * For the DCB forwarding test, each core is assigned on each traffic class.
1969 * Each core is assigned a multi-stream, each stream being composed of
1970 * a RX queue to poll on a RX port for input messages, associated with
1971 * a TX queue of a TX port where to send forwarded packets. All RX and
1972 * TX queues are mapping to the same traffic class.
1973 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1977 dcb_fwd_config_setup(void)
1979 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1980 portid_t txp, rxp = 0;
1981 queueid_t txq, rxq = 0;
1983 uint16_t nb_rx_queue, nb_tx_queue;
1984 uint16_t i, j, k, sm_id = 0;
1987 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1988 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1989 cur_fwd_config.nb_fwd_streams =
1990 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1992 /* reinitialize forwarding streams */
1996 /* get the dcb info on the first RX and TX ports */
1997 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1998 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2000 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2001 fwd_lcores[lc_id]->stream_nb = 0;
2002 fwd_lcores[lc_id]->stream_idx = sm_id;
2003 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2004 /* if the nb_queue is zero, means this tc is
2005 * not enabled on the POOL
2007 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2009 k = fwd_lcores[lc_id]->stream_nb +
2010 fwd_lcores[lc_id]->stream_idx;
2011 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2012 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2013 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2014 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2015 for (j = 0; j < nb_rx_queue; j++) {
2016 struct fwd_stream *fs;
2018 fs = fwd_streams[k + j];
2019 fs->rx_port = fwd_ports_ids[rxp];
2020 fs->rx_queue = rxq + j;
2021 fs->tx_port = fwd_ports_ids[txp];
2022 fs->tx_queue = txq + j % nb_tx_queue;
2023 fs->peer_addr = fs->tx_port;
2024 fs->retry_enabled = retry_enabled;
2026 fwd_lcores[lc_id]->stream_nb +=
2027 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2029 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2032 if (tc < rxp_dcb_info.nb_tcs)
2034 /* Restart from TC 0 on next RX port */
2036 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2038 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2041 if (rxp >= nb_fwd_ports)
2043 /* get the dcb information on next RX and TX ports */
2044 if ((rxp & 0x1) == 0)
2045 txp = (portid_t) (rxp + 1);
2047 txp = (portid_t) (rxp - 1);
2048 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2049 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2054 icmp_echo_config_setup(void)
2061 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2062 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2063 (nb_txq * nb_fwd_ports);
2065 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2066 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2067 cur_fwd_config.nb_fwd_streams =
2068 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2069 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2070 cur_fwd_config.nb_fwd_lcores =
2071 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2072 if (verbose_level > 0) {
2073 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2075 cur_fwd_config.nb_fwd_lcores,
2076 cur_fwd_config.nb_fwd_ports,
2077 cur_fwd_config.nb_fwd_streams);
2080 /* reinitialize forwarding streams */
2082 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2084 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2085 if (verbose_level > 0)
2086 printf(" core=%d: \n", lc_id);
2087 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2088 struct fwd_stream *fs;
2089 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2090 fs->rx_port = fwd_ports_ids[rxp];
2092 fs->tx_port = fs->rx_port;
2094 fs->peer_addr = fs->tx_port;
2095 fs->retry_enabled = retry_enabled;
2096 if (verbose_level > 0)
2097 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2098 sm_id, fs->rx_port, fs->rx_queue,
2100 rxq = (queueid_t) (rxq + 1);
2101 if (rxq == nb_rxq) {
2103 rxp = (portid_t) (rxp + 1);
2110 fwd_config_setup(void)
2112 cur_fwd_config.fwd_eng = cur_fwd_eng;
2113 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2114 icmp_echo_config_setup();
2117 if ((nb_rxq > 1) && (nb_txq > 1)){
2119 dcb_fwd_config_setup();
2121 rss_fwd_config_setup();
2124 simple_fwd_config_setup();
2128 pkt_fwd_config_display(struct fwd_config *cfg)
2130 struct fwd_stream *fs;
2134 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2135 "NUMA support %s, MP over anonymous pages %s\n",
2136 cfg->fwd_eng->fwd_mode_name,
2137 retry_enabled == 0 ? "" : " with retry",
2138 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2139 numa_support == 1 ? "enabled" : "disabled",
2140 mp_anon != 0 ? "enabled" : "disabled");
2143 printf("TX retry num: %u, delay between TX retries: %uus\n",
2144 burst_tx_retry_num, burst_tx_delay_time);
2145 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2146 printf("Logical Core %u (socket %u) forwards packets on "
2148 fwd_lcores_cpuids[lc_id],
2149 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2150 fwd_lcores[lc_id]->stream_nb);
2151 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2152 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2153 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2154 "P=%d/Q=%d (socket %u) ",
2155 fs->rx_port, fs->rx_queue,
2156 ports[fs->rx_port].socket_id,
2157 fs->tx_port, fs->tx_queue,
2158 ports[fs->tx_port].socket_id);
2159 print_ethaddr("peer=",
2160 &peer_eth_addrs[fs->peer_addr]);
2168 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2171 unsigned int lcore_cpuid;
2176 for (i = 0; i < nb_lc; i++) {
2177 lcore_cpuid = lcorelist[i];
2178 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2179 printf("lcore %u not enabled\n", lcore_cpuid);
2182 if (lcore_cpuid == rte_get_master_lcore()) {
2183 printf("lcore %u cannot be masked on for running "
2184 "packet forwarding, which is the master lcore "
2185 "and reserved for command line parsing only\n",
2190 fwd_lcores_cpuids[i] = lcore_cpuid;
2192 if (record_now == 0) {
2196 nb_cfg_lcores = (lcoreid_t) nb_lc;
2197 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2198 printf("previous number of forwarding cores %u - changed to "
2199 "number of configured cores %u\n",
2200 (unsigned int) nb_fwd_lcores, nb_lc);
2201 nb_fwd_lcores = (lcoreid_t) nb_lc;
2208 set_fwd_lcores_mask(uint64_t lcoremask)
2210 unsigned int lcorelist[64];
2214 if (lcoremask == 0) {
2215 printf("Invalid NULL mask of cores\n");
2219 for (i = 0; i < 64; i++) {
2220 if (! ((uint64_t)(1ULL << i) & lcoremask))
2222 lcorelist[nb_lc++] = i;
2224 return set_fwd_lcores_list(lcorelist, nb_lc);
2228 set_fwd_lcores_number(uint16_t nb_lc)
2230 if (nb_lc > nb_cfg_lcores) {
2231 printf("nb fwd cores %u > %u (max. number of configured "
2232 "lcores) - ignored\n",
2233 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2236 nb_fwd_lcores = (lcoreid_t) nb_lc;
2237 printf("Number of forwarding cores set to %u\n",
2238 (unsigned int) nb_fwd_lcores);
2242 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2250 for (i = 0; i < nb_pt; i++) {
2251 port_id = (portid_t) portlist[i];
2252 if (port_id_is_invalid(port_id, ENABLED_WARN))
2255 fwd_ports_ids[i] = port_id;
2257 if (record_now == 0) {
2261 nb_cfg_ports = (portid_t) nb_pt;
2262 if (nb_fwd_ports != (portid_t) nb_pt) {
2263 printf("previous number of forwarding ports %u - changed to "
2264 "number of configured ports %u\n",
2265 (unsigned int) nb_fwd_ports, nb_pt);
2266 nb_fwd_ports = (portid_t) nb_pt;
2271 set_fwd_ports_mask(uint64_t portmask)
2273 unsigned int portlist[64];
2277 if (portmask == 0) {
2278 printf("Invalid NULL mask of ports\n");
2282 for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
2283 if (! ((uint64_t)(1ULL << i) & portmask))
2285 portlist[nb_pt++] = i;
2287 set_fwd_ports_list(portlist, nb_pt);
2291 set_fwd_ports_number(uint16_t nb_pt)
2293 if (nb_pt > nb_cfg_ports) {
2294 printf("nb fwd ports %u > %u (number of configured "
2295 "ports) - ignored\n",
2296 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2299 nb_fwd_ports = (portid_t) nb_pt;
2300 printf("Number of forwarding ports set to %u\n",
2301 (unsigned int) nb_fwd_ports);
2305 port_is_forwarding(portid_t port_id)
2309 if (port_id_is_invalid(port_id, ENABLED_WARN))
2312 for (i = 0; i < nb_fwd_ports; i++) {
2313 if (fwd_ports_ids[i] == port_id)
2321 set_nb_pkt_per_burst(uint16_t nb)
2323 if (nb > MAX_PKT_BURST) {
2324 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2326 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2329 nb_pkt_per_burst = nb;
2330 printf("Number of packets per burst set to %u\n",
2331 (unsigned int) nb_pkt_per_burst);
2335 tx_split_get_name(enum tx_pkt_split split)
2339 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2340 if (tx_split_name[i].split == split)
2341 return tx_split_name[i].name;
2347 set_tx_pkt_split(const char *name)
2351 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2352 if (strcmp(tx_split_name[i].name, name) == 0) {
2353 tx_pkt_split = tx_split_name[i].split;
2357 printf("unknown value: \"%s\"\n", name);
2361 show_tx_pkt_segments(void)
2367 split = tx_split_get_name(tx_pkt_split);
2369 printf("Number of segments: %u\n", n);
2370 printf("Segment sizes: ");
2371 for (i = 0; i != n - 1; i++)
2372 printf("%hu,", tx_pkt_seg_lengths[i]);
2373 printf("%hu\n", tx_pkt_seg_lengths[i]);
2374 printf("Split packet: %s\n", split);
2378 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2380 uint16_t tx_pkt_len;
2383 if (nb_segs >= (unsigned) nb_txd) {
2384 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2385 nb_segs, (unsigned int) nb_txd);
2390 * Check that each segment length is greater or equal than
2391 * the mbuf data sise.
2392 * Check also that the total packet length is greater or equal than the
2393 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2396 for (i = 0; i < nb_segs; i++) {
2397 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2398 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2399 i, seg_lengths[i], (unsigned) mbuf_data_size);
2402 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2404 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2405 printf("total packet length=%u < %d - give up\n",
2406 (unsigned) tx_pkt_len,
2407 (int)(sizeof(struct ether_hdr) + 20 + 8));
2411 for (i = 0; i < nb_segs; i++)
2412 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2414 tx_pkt_length = tx_pkt_len;
2415 tx_pkt_nb_segs = (uint8_t) nb_segs;
2419 list_pkt_forwarding_modes(void)
2421 static char fwd_modes[128] = "";
2422 const char *separator = "|";
2423 struct fwd_engine *fwd_eng;
2426 if (strlen (fwd_modes) == 0) {
2427 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2428 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2429 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2430 strncat(fwd_modes, separator,
2431 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2433 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2440 list_pkt_forwarding_retry_modes(void)
2442 static char fwd_modes[128] = "";
2443 const char *separator = "|";
2444 struct fwd_engine *fwd_eng;
2447 if (strlen(fwd_modes) == 0) {
2448 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2449 if (fwd_eng == &rx_only_engine)
2451 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2453 strlen(fwd_modes) - 1);
2454 strncat(fwd_modes, separator,
2456 strlen(fwd_modes) - 1);
2458 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2465 set_pkt_forwarding_mode(const char *fwd_mode_name)
2467 struct fwd_engine *fwd_eng;
2471 while ((fwd_eng = fwd_engines[i]) != NULL) {
2472 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2473 printf("Set %s packet forwarding mode%s\n",
2475 retry_enabled == 0 ? "" : " with retry");
2476 cur_fwd_eng = fwd_eng;
2481 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2485 set_verbose_level(uint16_t vb_level)
2487 printf("Change verbose level from %u to %u\n",
2488 (unsigned int) verbose_level, (unsigned int) vb_level);
2489 verbose_level = vb_level;
2493 vlan_extend_set(portid_t port_id, int on)
2498 if (port_id_is_invalid(port_id, ENABLED_WARN))
2501 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2504 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2506 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2508 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2510 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2511 "diag=%d\n", port_id, on, diag);
2515 rx_vlan_strip_set(portid_t port_id, int on)
2520 if (port_id_is_invalid(port_id, ENABLED_WARN))
2523 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2526 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2528 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2530 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2532 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2533 "diag=%d\n", port_id, on, diag);
2537 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2541 if (port_id_is_invalid(port_id, ENABLED_WARN))
2544 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2546 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2547 "diag=%d\n", port_id, queue_id, on, diag);
2551 rx_vlan_filter_set(portid_t port_id, int on)
2556 if (port_id_is_invalid(port_id, ENABLED_WARN))
2559 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2562 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2564 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2566 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2568 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2569 "diag=%d\n", port_id, on, diag);
2573 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2577 if (port_id_is_invalid(port_id, ENABLED_WARN))
2579 if (vlan_id_is_invalid(vlan_id))
2581 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2584 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2586 port_id, vlan_id, on, diag);
2591 rx_vlan_all_filter_set(portid_t port_id, int on)
2595 if (port_id_is_invalid(port_id, ENABLED_WARN))
2597 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2598 if (rx_vft_set(port_id, vlan_id, on))
2604 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2608 if (port_id_is_invalid(port_id, ENABLED_WARN))
2611 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2615 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2617 port_id, vlan_type, tp_id, diag);
2621 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2624 if (port_id_is_invalid(port_id, ENABLED_WARN))
2626 if (vlan_id_is_invalid(vlan_id))
2629 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2630 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2631 printf("Error, as QinQ has been enabled.\n");
2635 tx_vlan_reset(port_id);
2636 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
2637 ports[port_id].tx_vlan_id = vlan_id;
2641 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2644 if (port_id_is_invalid(port_id, ENABLED_WARN))
2646 if (vlan_id_is_invalid(vlan_id))
2648 if (vlan_id_is_invalid(vlan_id_outer))
2651 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2652 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2653 printf("Error, as QinQ hasn't been enabled.\n");
2657 tx_vlan_reset(port_id);
2658 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
2659 ports[port_id].tx_vlan_id = vlan_id;
2660 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2664 tx_vlan_reset(portid_t port_id)
2666 if (port_id_is_invalid(port_id, ENABLED_WARN))
2668 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
2669 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
2670 ports[port_id].tx_vlan_id = 0;
2671 ports[port_id].tx_vlan_id_outer = 0;
2675 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2677 if (port_id_is_invalid(port_id, ENABLED_WARN))
2680 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2684 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2687 uint8_t existing_mapping_found = 0;
2689 if (port_id_is_invalid(port_id, ENABLED_WARN))
2692 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2695 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2696 printf("map_value not in required range 0..%d\n",
2697 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2701 if (!is_rx) { /*then tx*/
2702 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2703 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2704 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2705 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2706 existing_mapping_found = 1;
2710 if (!existing_mapping_found) { /* A new additional mapping... */
2711 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2712 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2713 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2714 nb_tx_queue_stats_mappings++;
2718 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2719 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2720 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2721 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2722 existing_mapping_found = 1;
2726 if (!existing_mapping_found) { /* A new additional mapping... */
2727 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2728 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2729 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2730 nb_rx_queue_stats_mappings++;
2736 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2738 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2740 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2741 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2742 " tunnel_id: 0x%08x",
2743 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2744 rte_be_to_cpu_32(mask->tunnel_id_mask));
2745 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2746 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2747 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2748 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2750 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2751 rte_be_to_cpu_16(mask->src_port_mask),
2752 rte_be_to_cpu_16(mask->dst_port_mask));
2754 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2755 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2756 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
2757 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
2758 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
2760 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2761 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
2762 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
2763 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
2764 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
2771 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2773 struct rte_eth_flex_payload_cfg *cfg;
2776 for (i = 0; i < flex_conf->nb_payloads; i++) {
2777 cfg = &flex_conf->flex_set[i];
2778 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2780 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2781 printf("\n L2_PAYLOAD: ");
2782 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2783 printf("\n L3_PAYLOAD: ");
2784 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2785 printf("\n L4_PAYLOAD: ");
2787 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2788 for (j = 0; j < num; j++)
2789 printf(" %-5u", cfg->src_offset[j]);
2795 flowtype_to_str(uint16_t flow_type)
2797 struct flow_type_info {
2803 static struct flow_type_info flowtype_str_table[] = {
2804 {"raw", RTE_ETH_FLOW_RAW},
2805 {"ipv4", RTE_ETH_FLOW_IPV4},
2806 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2807 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2808 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2809 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2810 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2811 {"ipv6", RTE_ETH_FLOW_IPV6},
2812 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2813 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2814 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2815 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2816 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2817 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2818 {"port", RTE_ETH_FLOW_PORT},
2819 {"vxlan", RTE_ETH_FLOW_VXLAN},
2820 {"geneve", RTE_ETH_FLOW_GENEVE},
2821 {"nvgre", RTE_ETH_FLOW_NVGRE},
2824 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2825 if (flowtype_str_table[i].ftype == flow_type)
2826 return flowtype_str_table[i].str;
2833 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2835 struct rte_eth_fdir_flex_mask *mask;
2839 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2840 mask = &flex_conf->flex_mask[i];
2841 p = flowtype_to_str(mask->flow_type);
2842 printf("\n %s:\t", p ? p : "unknown");
2843 for (j = 0; j < num; j++)
2844 printf(" %02x", mask->mask[j]);
2850 print_fdir_flow_type(uint32_t flow_types_mask)
2855 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2856 if (!(flow_types_mask & (1 << i)))
2858 p = flowtype_to_str(i);
2868 fdir_get_infos(portid_t port_id)
2870 struct rte_eth_fdir_stats fdir_stat;
2871 struct rte_eth_fdir_info fdir_info;
2874 static const char *fdir_stats_border = "########################";
2876 if (port_id_is_invalid(port_id, ENABLED_WARN))
2878 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
2880 printf("\n FDIR is not supported on port %-2d\n",
2885 memset(&fdir_info, 0, sizeof(fdir_info));
2886 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2887 RTE_ETH_FILTER_INFO, &fdir_info);
2888 memset(&fdir_stat, 0, sizeof(fdir_stat));
2889 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2890 RTE_ETH_FILTER_STATS, &fdir_stat);
2891 printf("\n %s FDIR infos for port %-2d %s\n",
2892 fdir_stats_border, port_id, fdir_stats_border);
2894 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
2895 printf(" PERFECT\n");
2896 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2897 printf(" PERFECT-MAC-VLAN\n");
2898 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2899 printf(" PERFECT-TUNNEL\n");
2900 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
2901 printf(" SIGNATURE\n");
2903 printf(" DISABLE\n");
2904 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
2905 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
2906 printf(" SUPPORTED FLOW TYPE: ");
2907 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
2909 printf(" FLEX PAYLOAD INFO:\n");
2910 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
2911 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
2912 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
2913 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
2914 fdir_info.flex_payload_unit,
2915 fdir_info.max_flex_payload_segment_num,
2916 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
2918 print_fdir_mask(&fdir_info.mask);
2919 if (fdir_info.flex_conf.nb_payloads > 0) {
2920 printf(" FLEX PAYLOAD SRC OFFSET:");
2921 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2923 if (fdir_info.flex_conf.nb_flexmasks > 0) {
2924 printf(" FLEX MASK CFG:");
2925 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2927 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2928 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2929 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2930 fdir_info.guarant_spc, fdir_info.best_spc);
2931 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2932 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2933 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2934 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2935 fdir_stat.collision, fdir_stat.free,
2936 fdir_stat.maxhash, fdir_stat.maxlen,
2937 fdir_stat.add, fdir_stat.remove,
2938 fdir_stat.f_add, fdir_stat.f_remove);
2939 printf(" %s############################%s\n",
2940 fdir_stats_border, fdir_stats_border);
2944 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2946 struct rte_port *port;
2947 struct rte_eth_fdir_flex_conf *flex_conf;
2950 port = &ports[port_id];
2951 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2952 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2953 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2958 if (i >= RTE_ETH_FLOW_MAX) {
2959 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2960 idx = flex_conf->nb_flexmasks;
2961 flex_conf->nb_flexmasks++;
2963 printf("The flex mask table is full. Can not set flex"
2964 " mask for flow_type(%u).", cfg->flow_type);
2968 (void)rte_memcpy(&flex_conf->flex_mask[idx],
2970 sizeof(struct rte_eth_fdir_flex_mask));
2974 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2976 struct rte_port *port;
2977 struct rte_eth_fdir_flex_conf *flex_conf;
2980 port = &ports[port_id];
2981 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2982 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2983 if (cfg->type == flex_conf->flex_set[i].type) {
2988 if (i >= RTE_ETH_PAYLOAD_MAX) {
2989 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2990 idx = flex_conf->nb_payloads;
2991 flex_conf->nb_payloads++;
2993 printf("The flex payload table is full. Can not set"
2994 " flex payload for type(%u).", cfg->type);
2998 (void)rte_memcpy(&flex_conf->flex_set[idx],
3000 sizeof(struct rte_eth_flex_payload_cfg));
3004 #ifdef RTE_LIBRTE_IXGBE_PMD
3006 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3011 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3013 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3018 printf("rte_pmd_ixgbe_set_vf_rx for port_id=%d failed "
3019 "diag=%d\n", port_id, diag);
3021 printf("rte_pmd_ixgbe_set_vf_tx for port_id=%d failed "
3022 "diag=%d\n", port_id, diag);
3028 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3031 struct rte_eth_link link;
3033 if (port_id_is_invalid(port_id, ENABLED_WARN))
3035 rte_eth_link_get_nowait(port_id, &link);
3036 if (rate > link.link_speed) {
3037 printf("Invalid rate value:%u bigger than link speed: %u\n",
3038 rate, link.link_speed);
3041 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3044 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3049 #ifdef RTE_LIBRTE_IXGBE_PMD
3051 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3055 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate, q_msk);
3058 printf("rte_pmd_ixgbe_set_vf_rate_limit for port_id=%d failed diag=%d\n",
3065 * Functions to manage the set of filtered Multicast MAC addresses.
3067 * A pool of filtered multicast MAC addresses is associated with each port.
3068 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3069 * The address of the pool and the number of valid multicast MAC addresses
3070 * recorded in the pool are stored in the fields "mc_addr_pool" and
3071 * "mc_addr_nb" of the "rte_port" data structure.
3073 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3074 * to be supplied a contiguous array of multicast MAC addresses.
3075 * To comply with this constraint, the set of multicast addresses recorded
3076 * into the pool are systematically compacted at the beginning of the pool.
3077 * Hence, when a multicast address is removed from the pool, all following
3078 * addresses, if any, are copied back to keep the set contiguous.
3080 #define MCAST_POOL_INC 32
3083 mcast_addr_pool_extend(struct rte_port *port)
3085 struct ether_addr *mc_pool;
3086 size_t mc_pool_size;
3089 * If a free entry is available at the end of the pool, just
3090 * increment the number of recorded multicast addresses.
3092 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3098 * [re]allocate a pool with MCAST_POOL_INC more entries.
3099 * The previous test guarantees that port->mc_addr_nb is a multiple
3100 * of MCAST_POOL_INC.
3102 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3104 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3106 if (mc_pool == NULL) {
3107 printf("allocation of pool of %u multicast addresses failed\n",
3108 port->mc_addr_nb + MCAST_POOL_INC);
3112 port->mc_addr_pool = mc_pool;
3119 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3122 if (addr_idx == port->mc_addr_nb) {
3123 /* No need to recompact the set of multicast addressses. */
3124 if (port->mc_addr_nb == 0) {
3125 /* free the pool of multicast addresses. */
3126 free(port->mc_addr_pool);
3127 port->mc_addr_pool = NULL;
3131 memmove(&port->mc_addr_pool[addr_idx],
3132 &port->mc_addr_pool[addr_idx + 1],
3133 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3137 eth_port_multicast_addr_list_set(uint8_t port_id)
3139 struct rte_port *port;
3142 port = &ports[port_id];
3143 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3147 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3148 port->mc_addr_nb, port_id, -diag);
3152 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
3154 struct rte_port *port;
3157 if (port_id_is_invalid(port_id, ENABLED_WARN))
3160 port = &ports[port_id];
3163 * Check that the added multicast MAC address is not already recorded
3164 * in the pool of multicast addresses.
3166 for (i = 0; i < port->mc_addr_nb; i++) {
3167 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3168 printf("multicast address already filtered by port\n");
3173 if (mcast_addr_pool_extend(port) != 0)
3175 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3176 eth_port_multicast_addr_list_set(port_id);
3180 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
3182 struct rte_port *port;
3185 if (port_id_is_invalid(port_id, ENABLED_WARN))
3188 port = &ports[port_id];
3191 * Search the pool of multicast MAC addresses for the removed address.
3193 for (i = 0; i < port->mc_addr_nb; i++) {
3194 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3197 if (i == port->mc_addr_nb) {
3198 printf("multicast address not filtered by port %d\n", port_id);
3202 mcast_addr_pool_remove(port, i);
3203 eth_port_multicast_addr_list_set(port_id);
3207 port_dcb_info_display(uint8_t port_id)
3209 struct rte_eth_dcb_info dcb_info;
3212 static const char *border = "================";
3214 if (port_id_is_invalid(port_id, ENABLED_WARN))
3217 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3219 printf("\n Failed to get dcb infos on port %-2d\n",
3223 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3224 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3226 for (i = 0; i < dcb_info.nb_tcs; i++)
3228 printf("\n Priority : ");
3229 for (i = 0; i < dcb_info.nb_tcs; i++)
3230 printf("\t%4d", dcb_info.prio_tc[i]);
3231 printf("\n BW percent :");
3232 for (i = 0; i < dcb_info.nb_tcs; i++)
3233 printf("\t%4d%%", dcb_info.tc_bws[i]);
3234 printf("\n RXQ base : ");
3235 for (i = 0; i < dcb_info.nb_tcs; i++)
3236 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3237 printf("\n RXQ number :");
3238 for (i = 0; i < dcb_info.nb_tcs; i++)
3239 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3240 printf("\n TXQ base : ");
3241 for (i = 0; i < dcb_info.nb_tcs; i++)
3242 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3243 printf("\n TXQ number :");
3244 for (i = 0; i < dcb_info.nb_tcs; i++)
3245 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);