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 RTE_ETH_FOREACH_DEV(pid)
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 RTE_ETH_FOREACH_DEV(pid)
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 int cnt_xstats, idx_xstat;
268 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, NULL);
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, NULL)) {
292 printf("Error: Cannot get xstats lookup\n");
297 /* Get stats themselves */
298 values = malloc(sizeof(values) * cnt_xstats);
299 if (values == NULL) {
300 printf("Cannot allocate memory for xstats\n");
304 if (cnt_xstats != rte_eth_xstats_get(port_id, NULL, values,
306 printf("Error: Unable to get xstats\n");
313 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
314 printf("%s: %"PRIu64"\n",
315 xstats_names[idx_xstat].name,
322 nic_xstats_clear(portid_t port_id)
324 rte_eth_xstats_reset(port_id);
328 nic_stats_mapping_display(portid_t port_id)
330 struct rte_port *port = &ports[port_id];
334 static const char *nic_stats_mapping_border = "########################";
336 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
337 printf("Valid port range is [0");
338 RTE_ETH_FOREACH_DEV(pid)
344 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
345 printf("Port id %d - either does not support queue statistic mapping or"
346 " no queue statistic mapping set\n", port_id);
350 printf("\n %s NIC statistics mapping for port %-2d %s\n",
351 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
353 if (port->rx_queue_stats_mapping_enabled) {
354 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
355 if (rx_queue_stats_mappings[i].port_id == port_id) {
356 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
357 rx_queue_stats_mappings[i].queue_id,
358 rx_queue_stats_mappings[i].stats_counter_id);
365 if (port->tx_queue_stats_mapping_enabled) {
366 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
367 if (tx_queue_stats_mappings[i].port_id == port_id) {
368 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
369 tx_queue_stats_mappings[i].queue_id,
370 tx_queue_stats_mappings[i].stats_counter_id);
375 printf(" %s####################################%s\n",
376 nic_stats_mapping_border, nic_stats_mapping_border);
380 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
382 struct rte_eth_rxq_info qinfo;
384 static const char *info_border = "*********************";
386 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
388 printf("Failed to retrieve information for port: %hhu, "
389 "RX queue: %hu\nerror desc: %s(%d)\n",
390 port_id, queue_id, strerror(-rc), rc);
394 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
395 info_border, port_id, queue_id, info_border);
397 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
398 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
399 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
400 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
401 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
402 printf("\nRX drop packets: %s",
403 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
404 printf("\nRX deferred start: %s",
405 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
406 printf("\nRX scattered packets: %s",
407 (qinfo.scattered_rx != 0) ? "on" : "off");
408 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
413 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
415 struct rte_eth_txq_info qinfo;
417 static const char *info_border = "*********************";
419 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
421 printf("Failed to retrieve information for port: %hhu, "
422 "TX queue: %hu\nerror desc: %s(%d)\n",
423 port_id, queue_id, strerror(-rc), rc);
427 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
428 info_border, port_id, queue_id, info_border);
430 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
431 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
432 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
433 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
434 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
435 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
436 printf("\nTX deferred start: %s",
437 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
438 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
443 port_infos_display(portid_t port_id)
445 struct rte_port *port;
446 struct ether_addr mac_addr;
447 struct rte_eth_link link;
448 struct rte_eth_dev_info dev_info;
450 struct rte_mempool * mp;
451 static const char *info_border = "*********************";
455 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
456 printf("Valid port range is [0");
457 RTE_ETH_FOREACH_DEV(pid)
462 port = &ports[port_id];
463 rte_eth_link_get_nowait(port_id, &link);
464 memset(&dev_info, 0, sizeof(dev_info));
465 rte_eth_dev_info_get(port_id, &dev_info);
466 printf("\n%s Infos for port %-2d %s\n",
467 info_border, port_id, info_border);
468 rte_eth_macaddr_get(port_id, &mac_addr);
469 print_ethaddr("MAC address: ", &mac_addr);
470 printf("\nDriver name: %s", dev_info.driver_name);
471 printf("\nConnect to socket: %u", port->socket_id);
473 if (port_numa[port_id] != NUMA_NO_CONFIG) {
474 mp = mbuf_pool_find(port_numa[port_id]);
476 printf("\nmemory allocation on the socket: %d",
479 printf("\nmemory allocation on the socket: %u",port->socket_id);
481 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
482 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
483 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
484 ("full-duplex") : ("half-duplex"));
486 if (!rte_eth_dev_get_mtu(port_id, &mtu))
487 printf("MTU: %u\n", mtu);
489 printf("Promiscuous mode: %s\n",
490 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
491 printf("Allmulticast mode: %s\n",
492 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
493 printf("Maximum number of MAC addresses: %u\n",
494 (unsigned int)(port->dev_info.max_mac_addrs));
495 printf("Maximum number of MAC addresses of hash filtering: %u\n",
496 (unsigned int)(port->dev_info.max_hash_mac_addrs));
498 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
499 if (vlan_offload >= 0){
500 printf("VLAN offload: \n");
501 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
502 printf(" strip on \n");
504 printf(" strip off \n");
506 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
507 printf(" filter on \n");
509 printf(" filter off \n");
511 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
512 printf(" qinq(extend) on \n");
514 printf(" qinq(extend) off \n");
517 if (dev_info.hash_key_size > 0)
518 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
519 if (dev_info.reta_size > 0)
520 printf("Redirection table size: %u\n", dev_info.reta_size);
521 if (!dev_info.flow_type_rss_offloads)
522 printf("No flow type is supported.\n");
527 printf("Supported flow types:\n");
528 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
530 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
532 p = flowtype_to_str(i);
533 printf(" %s\n", (p ? p : "unknown"));
537 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
538 printf("Max possible number of RXDs per queue: %hu\n",
539 dev_info.rx_desc_lim.nb_max);
540 printf("Min possible number of RXDs per queue: %hu\n",
541 dev_info.rx_desc_lim.nb_min);
542 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
544 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
545 printf("Max possible number of TXDs per queue: %hu\n",
546 dev_info.tx_desc_lim.nb_max);
547 printf("Min possible number of TXDs per queue: %hu\n",
548 dev_info.tx_desc_lim.nb_min);
549 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
553 port_offload_cap_display(portid_t port_id)
555 struct rte_eth_dev *dev;
556 struct rte_eth_dev_info dev_info;
557 static const char *info_border = "************";
559 if (port_id_is_invalid(port_id, ENABLED_WARN))
562 dev = &rte_eth_devices[port_id];
563 rte_eth_dev_info_get(port_id, &dev_info);
565 printf("\n%s Port %d supported offload features: %s\n",
566 info_border, port_id, info_border);
568 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
569 printf("VLAN stripped: ");
570 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
576 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
577 printf("Double VLANs stripped: ");
578 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
584 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
585 printf("RX IPv4 checksum: ");
586 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
592 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
593 printf("RX UDP checksum: ");
594 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
600 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
601 printf("RX TCP checksum: ");
602 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
608 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
609 printf("RX Outer IPv4 checksum: on");
611 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
612 printf("Large receive offload: ");
613 if (dev->data->dev_conf.rxmode.enable_lro)
619 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
620 printf("VLAN insert: ");
621 if (ports[port_id].tx_ol_flags &
622 TESTPMD_TX_OFFLOAD_INSERT_VLAN)
628 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
629 printf("Double VLANs insert: ");
630 if (ports[port_id].tx_ol_flags &
631 TESTPMD_TX_OFFLOAD_INSERT_QINQ)
637 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
638 printf("TX IPv4 checksum: ");
639 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
645 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
646 printf("TX UDP checksum: ");
647 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
653 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
654 printf("TX TCP checksum: ");
655 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
661 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
662 printf("TX SCTP checksum: ");
663 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
669 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
670 printf("TX Outer IPv4 checksum: ");
671 if (ports[port_id].tx_ol_flags &
672 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
678 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
679 printf("TX TCP segmentation: ");
680 if (ports[port_id].tso_segsz != 0)
686 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
687 printf("TX UDP segmentation: ");
688 if (ports[port_id].tso_segsz != 0)
694 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
695 printf("TSO for VXLAN tunnel packet: ");
696 if (ports[port_id].tunnel_tso_segsz)
702 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
703 printf("TSO for GRE tunnel packet: ");
704 if (ports[port_id].tunnel_tso_segsz)
710 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
711 printf("TSO for IPIP tunnel packet: ");
712 if (ports[port_id].tunnel_tso_segsz)
718 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
719 printf("TSO for GENEVE tunnel packet: ");
720 if (ports[port_id].tunnel_tso_segsz)
729 port_id_is_invalid(portid_t port_id, enum print_warning warning)
731 if (port_id == (portid_t)RTE_PORT_ALL)
734 if (rte_eth_dev_is_valid_port(port_id))
737 if (warning == ENABLED_WARN)
738 printf("Invalid port %d\n", port_id);
744 vlan_id_is_invalid(uint16_t vlan_id)
748 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
753 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
758 printf("Port register offset 0x%X not aligned on a 4-byte "
763 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
764 if (reg_off >= pci_len) {
765 printf("Port %d: register offset %u (0x%X) out of port PCI "
766 "resource (length=%"PRIu64")\n",
767 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
774 reg_bit_pos_is_invalid(uint8_t bit_pos)
778 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
782 #define display_port_and_reg_off(port_id, reg_off) \
783 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
786 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
788 display_port_and_reg_off(port_id, (unsigned)reg_off);
789 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
793 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
798 if (port_id_is_invalid(port_id, ENABLED_WARN))
800 if (port_reg_off_is_invalid(port_id, reg_off))
802 if (reg_bit_pos_is_invalid(bit_x))
804 reg_v = port_id_pci_reg_read(port_id, reg_off);
805 display_port_and_reg_off(port_id, (unsigned)reg_off);
806 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
810 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
811 uint8_t bit1_pos, uint8_t bit2_pos)
817 if (port_id_is_invalid(port_id, ENABLED_WARN))
819 if (port_reg_off_is_invalid(port_id, reg_off))
821 if (reg_bit_pos_is_invalid(bit1_pos))
823 if (reg_bit_pos_is_invalid(bit2_pos))
825 if (bit1_pos > bit2_pos)
826 l_bit = bit2_pos, h_bit = bit1_pos;
828 l_bit = bit1_pos, h_bit = bit2_pos;
830 reg_v = port_id_pci_reg_read(port_id, reg_off);
833 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
834 display_port_and_reg_off(port_id, (unsigned)reg_off);
835 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
836 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
840 port_reg_display(portid_t port_id, uint32_t reg_off)
844 if (port_id_is_invalid(port_id, ENABLED_WARN))
846 if (port_reg_off_is_invalid(port_id, reg_off))
848 reg_v = port_id_pci_reg_read(port_id, reg_off);
849 display_port_reg_value(port_id, reg_off, reg_v);
853 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
858 if (port_id_is_invalid(port_id, ENABLED_WARN))
860 if (port_reg_off_is_invalid(port_id, reg_off))
862 if (reg_bit_pos_is_invalid(bit_pos))
865 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
868 reg_v = port_id_pci_reg_read(port_id, reg_off);
870 reg_v &= ~(1 << bit_pos);
872 reg_v |= (1 << bit_pos);
873 port_id_pci_reg_write(port_id, reg_off, reg_v);
874 display_port_reg_value(port_id, reg_off, reg_v);
878 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
879 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
886 if (port_id_is_invalid(port_id, ENABLED_WARN))
888 if (port_reg_off_is_invalid(port_id, reg_off))
890 if (reg_bit_pos_is_invalid(bit1_pos))
892 if (reg_bit_pos_is_invalid(bit2_pos))
894 if (bit1_pos > bit2_pos)
895 l_bit = bit2_pos, h_bit = bit1_pos;
897 l_bit = bit1_pos, h_bit = bit2_pos;
899 if ((h_bit - l_bit) < 31)
900 max_v = (1 << (h_bit - l_bit + 1)) - 1;
905 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
906 (unsigned)value, (unsigned)value,
907 (unsigned)max_v, (unsigned)max_v);
910 reg_v = port_id_pci_reg_read(port_id, reg_off);
911 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
912 reg_v |= (value << l_bit); /* Set changed bits */
913 port_id_pci_reg_write(port_id, reg_off, reg_v);
914 display_port_reg_value(port_id, reg_off, reg_v);
918 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
920 if (port_id_is_invalid(port_id, ENABLED_WARN))
922 if (port_reg_off_is_invalid(port_id, reg_off))
924 port_id_pci_reg_write(port_id, reg_off, reg_v);
925 display_port_reg_value(port_id, reg_off, reg_v);
929 port_mtu_set(portid_t port_id, uint16_t mtu)
933 if (port_id_is_invalid(port_id, ENABLED_WARN))
935 diag = rte_eth_dev_set_mtu(port_id, mtu);
938 printf("Set MTU failed. diag=%d\n", diag);
941 /* Generic flow management functions. */
943 /** Generate flow_item[] entry. */
944 #define MK_FLOW_ITEM(t, s) \
945 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
950 /** Information about known flow pattern items. */
951 static const struct {
955 MK_FLOW_ITEM(END, 0),
956 MK_FLOW_ITEM(VOID, 0),
957 MK_FLOW_ITEM(INVERT, 0),
958 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
960 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
961 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
962 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
963 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
964 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
965 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
966 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
967 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
968 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
969 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
970 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
971 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
972 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
973 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
976 /** Compute storage space needed by item specification. */
978 flow_item_spec_size(const struct rte_flow_item *item,
979 size_t *size, size_t *pad)
983 switch (item->type) {
985 const struct rte_flow_item_raw *raw;
988 case RTE_FLOW_ITEM_TYPE_RAW:
989 spec.raw = item->spec;
990 *size = offsetof(struct rte_flow_item_raw, pattern) +
991 spec.raw->length * sizeof(*spec.raw->pattern);
998 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1001 /** Generate flow_action[] entry. */
1002 #define MK_FLOW_ACTION(t, s) \
1003 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
1008 /** Information about known flow actions. */
1009 static const struct {
1013 MK_FLOW_ACTION(END, 0),
1014 MK_FLOW_ACTION(VOID, 0),
1015 MK_FLOW_ACTION(PASSTHRU, 0),
1016 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1017 MK_FLOW_ACTION(FLAG, 0),
1018 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
1019 MK_FLOW_ACTION(DROP, 0),
1020 MK_FLOW_ACTION(COUNT, 0),
1021 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
1022 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
1023 MK_FLOW_ACTION(PF, 0),
1024 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1027 /** Compute storage space needed by action configuration. */
1029 flow_action_conf_size(const struct rte_flow_action *action,
1030 size_t *size, size_t *pad)
1034 switch (action->type) {
1036 const struct rte_flow_action_rss *rss;
1039 case RTE_FLOW_ACTION_TYPE_RSS:
1040 conf.rss = action->conf;
1041 *size = offsetof(struct rte_flow_action_rss, queue) +
1042 conf.rss->num * sizeof(*conf.rss->queue);
1049 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1052 /** Generate a port_flow entry from attributes/pattern/actions. */
1053 static struct port_flow *
1054 port_flow_new(const struct rte_flow_attr *attr,
1055 const struct rte_flow_item *pattern,
1056 const struct rte_flow_action *actions)
1058 const struct rte_flow_item *item;
1059 const struct rte_flow_action *action;
1060 struct port_flow *pf = NULL;
1070 pf->pattern = (void *)&pf->data[off1];
1072 struct rte_flow_item *dst = NULL;
1074 if ((unsigned int)item->type >= RTE_DIM(flow_item) ||
1075 !flow_item[item->type].name)
1078 dst = memcpy(pf->data + off1, item, sizeof(*item));
1079 off1 += sizeof(*item);
1080 flow_item_spec_size(item, &tmp, &pad);
1083 dst->spec = memcpy(pf->data + off2,
1089 dst->last = memcpy(pf->data + off2,
1095 dst->mask = memcpy(pf->data + off2,
1099 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1100 } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
1101 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1104 pf->actions = (void *)&pf->data[off1];
1106 struct rte_flow_action *dst = NULL;
1108 if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
1109 !flow_action[action->type].name)
1112 dst = memcpy(pf->data + off1, action, sizeof(*action));
1113 off1 += sizeof(*action);
1114 flow_action_conf_size(action, &tmp, &pad);
1117 dst->conf = memcpy(pf->data + off2,
1121 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1122 } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
1125 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1126 tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double));
1127 pf = calloc(1, tmp + off1 + off2);
1131 *pf = (const struct port_flow){
1132 .size = tmp + off1 + off2,
1135 tmp -= offsetof(struct port_flow, data);
1145 /** Print a message out of a flow error. */
1147 port_flow_complain(struct rte_flow_error *error)
1149 static const char *const errstrlist[] = {
1150 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1151 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1152 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1153 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1154 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1155 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1156 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1157 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1158 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1159 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1160 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1161 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1165 int err = rte_errno;
1167 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1168 !errstrlist[error->type])
1169 errstr = "unknown type";
1171 errstr = errstrlist[error->type];
1172 printf("Caught error type %d (%s): %s%s\n",
1173 error->type, errstr,
1174 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1175 error->cause), buf) : "",
1176 error->message ? error->message : "(no stated reason)");
1180 /** Validate flow rule. */
1182 port_flow_validate(portid_t port_id,
1183 const struct rte_flow_attr *attr,
1184 const struct rte_flow_item *pattern,
1185 const struct rte_flow_action *actions)
1187 struct rte_flow_error error;
1189 /* Poisoning to make sure PMDs update it in case of error. */
1190 memset(&error, 0x11, sizeof(error));
1191 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1192 return port_flow_complain(&error);
1193 printf("Flow rule validated\n");
1197 /** Create flow rule. */
1199 port_flow_create(portid_t port_id,
1200 const struct rte_flow_attr *attr,
1201 const struct rte_flow_item *pattern,
1202 const struct rte_flow_action *actions)
1204 struct rte_flow *flow;
1205 struct rte_port *port;
1206 struct port_flow *pf;
1208 struct rte_flow_error error;
1210 /* Poisoning to make sure PMDs update it in case of error. */
1211 memset(&error, 0x22, sizeof(error));
1212 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1214 return port_flow_complain(&error);
1215 port = &ports[port_id];
1216 if (port->flow_list) {
1217 if (port->flow_list->id == UINT32_MAX) {
1218 printf("Highest rule ID is already assigned, delete"
1220 rte_flow_destroy(port_id, flow, NULL);
1223 id = port->flow_list->id + 1;
1226 pf = port_flow_new(attr, pattern, actions);
1228 int err = rte_errno;
1230 printf("Cannot allocate flow: %s\n", rte_strerror(err));
1231 rte_flow_destroy(port_id, flow, NULL);
1234 pf->next = port->flow_list;
1237 port->flow_list = pf;
1238 printf("Flow rule #%u created\n", pf->id);
1242 /** Destroy a number of flow rules. */
1244 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1246 struct rte_port *port;
1247 struct port_flow **tmp;
1251 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1252 port_id == (portid_t)RTE_PORT_ALL)
1254 port = &ports[port_id];
1255 tmp = &port->flow_list;
1259 for (i = 0; i != n; ++i) {
1260 struct rte_flow_error error;
1261 struct port_flow *pf = *tmp;
1263 if (rule[i] != pf->id)
1266 * Poisoning to make sure PMDs update it in case
1269 memset(&error, 0x33, sizeof(error));
1270 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1271 ret = port_flow_complain(&error);
1274 printf("Flow rule #%u destroyed\n", pf->id);
1280 tmp = &(*tmp)->next;
1286 /** Remove all flow rules. */
1288 port_flow_flush(portid_t port_id)
1290 struct rte_flow_error error;
1291 struct rte_port *port;
1294 /* Poisoning to make sure PMDs update it in case of error. */
1295 memset(&error, 0x44, sizeof(error));
1296 if (rte_flow_flush(port_id, &error)) {
1297 ret = port_flow_complain(&error);
1298 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1299 port_id == (portid_t)RTE_PORT_ALL)
1302 port = &ports[port_id];
1303 while (port->flow_list) {
1304 struct port_flow *pf = port->flow_list->next;
1306 free(port->flow_list);
1307 port->flow_list = pf;
1312 /** Query a flow rule. */
1314 port_flow_query(portid_t port_id, uint32_t rule,
1315 enum rte_flow_action_type action)
1317 struct rte_flow_error error;
1318 struct rte_port *port;
1319 struct port_flow *pf;
1322 struct rte_flow_query_count count;
1325 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1326 port_id == (portid_t)RTE_PORT_ALL)
1328 port = &ports[port_id];
1329 for (pf = port->flow_list; pf; pf = pf->next)
1333 printf("Flow rule #%u not found\n", rule);
1336 if ((unsigned int)action >= RTE_DIM(flow_action) ||
1337 !flow_action[action].name)
1340 name = flow_action[action].name;
1342 case RTE_FLOW_ACTION_TYPE_COUNT:
1345 printf("Cannot query action type %d (%s)\n", action, name);
1348 /* Poisoning to make sure PMDs update it in case of error. */
1349 memset(&error, 0x55, sizeof(error));
1350 memset(&query, 0, sizeof(query));
1351 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1352 return port_flow_complain(&error);
1354 case RTE_FLOW_ACTION_TYPE_COUNT:
1358 " hits: %" PRIu64 "\n"
1359 " bytes: %" PRIu64 "\n",
1361 query.count.hits_set,
1362 query.count.bytes_set,
1367 printf("Cannot display result for action type %d (%s)\n",
1374 /** List flow rules. */
1376 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1378 struct rte_port *port;
1379 struct port_flow *pf;
1380 struct port_flow *list = NULL;
1383 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1384 port_id == (portid_t)RTE_PORT_ALL)
1386 port = &ports[port_id];
1387 if (!port->flow_list)
1389 /* Sort flows by group, priority and ID. */
1390 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1391 struct port_flow **tmp;
1394 /* Filter out unwanted groups. */
1395 for (i = 0; i != n; ++i)
1396 if (pf->attr.group == group[i])
1403 (pf->attr.group > (*tmp)->attr.group ||
1404 (pf->attr.group == (*tmp)->attr.group &&
1405 pf->attr.priority > (*tmp)->attr.priority) ||
1406 (pf->attr.group == (*tmp)->attr.group &&
1407 pf->attr.priority == (*tmp)->attr.priority &&
1408 pf->id > (*tmp)->id)))
1413 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1414 for (pf = list; pf != NULL; pf = pf->tmp) {
1415 const struct rte_flow_item *item = pf->pattern;
1416 const struct rte_flow_action *action = pf->actions;
1418 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t",
1422 pf->attr.ingress ? 'i' : '-',
1423 pf->attr.egress ? 'e' : '-');
1424 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1425 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1426 printf("%s ", flow_item[item->type].name);
1430 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1431 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1432 printf(" %s", flow_action[action->type].name);
1440 * RX/TX ring descriptors display functions.
1443 rx_queue_id_is_invalid(queueid_t rxq_id)
1445 if (rxq_id < nb_rxq)
1447 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1452 tx_queue_id_is_invalid(queueid_t txq_id)
1454 if (txq_id < nb_txq)
1456 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1461 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1463 if (rxdesc_id < nb_rxd)
1465 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1471 tx_desc_id_is_invalid(uint16_t txdesc_id)
1473 if (txdesc_id < nb_txd)
1475 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1480 static const struct rte_memzone *
1481 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
1483 char mz_name[RTE_MEMZONE_NAMESIZE];
1484 const struct rte_memzone *mz;
1486 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1487 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1488 mz = rte_memzone_lookup(mz_name);
1490 printf("%s ring memory zoneof (port %d, queue %d) not"
1491 "found (zone name = %s\n",
1492 ring_name, port_id, q_id, mz_name);
1496 union igb_ring_dword {
1499 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1509 struct igb_ring_desc_32_bytes {
1510 union igb_ring_dword lo_dword;
1511 union igb_ring_dword hi_dword;
1512 union igb_ring_dword resv1;
1513 union igb_ring_dword resv2;
1516 struct igb_ring_desc_16_bytes {
1517 union igb_ring_dword lo_dword;
1518 union igb_ring_dword hi_dword;
1522 ring_rxd_display_dword(union igb_ring_dword dword)
1524 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1525 (unsigned)dword.words.hi);
1529 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1530 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1533 __rte_unused uint8_t port_id,
1537 struct igb_ring_desc_16_bytes *ring =
1538 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1539 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1540 struct rte_eth_dev_info dev_info;
1542 memset(&dev_info, 0, sizeof(dev_info));
1543 rte_eth_dev_info_get(port_id, &dev_info);
1544 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1545 /* 32 bytes RX descriptor, i40e only */
1546 struct igb_ring_desc_32_bytes *ring =
1547 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1548 ring[desc_id].lo_dword.dword =
1549 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1550 ring_rxd_display_dword(ring[desc_id].lo_dword);
1551 ring[desc_id].hi_dword.dword =
1552 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1553 ring_rxd_display_dword(ring[desc_id].hi_dword);
1554 ring[desc_id].resv1.dword =
1555 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1556 ring_rxd_display_dword(ring[desc_id].resv1);
1557 ring[desc_id].resv2.dword =
1558 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1559 ring_rxd_display_dword(ring[desc_id].resv2);
1564 /* 16 bytes RX descriptor */
1565 ring[desc_id].lo_dword.dword =
1566 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1567 ring_rxd_display_dword(ring[desc_id].lo_dword);
1568 ring[desc_id].hi_dword.dword =
1569 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1570 ring_rxd_display_dword(ring[desc_id].hi_dword);
1574 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1576 struct igb_ring_desc_16_bytes *ring;
1577 struct igb_ring_desc_16_bytes txd;
1579 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1580 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1581 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1582 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1583 (unsigned)txd.lo_dword.words.lo,
1584 (unsigned)txd.lo_dword.words.hi,
1585 (unsigned)txd.hi_dword.words.lo,
1586 (unsigned)txd.hi_dword.words.hi);
1590 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1592 const struct rte_memzone *rx_mz;
1594 if (port_id_is_invalid(port_id, ENABLED_WARN))
1596 if (rx_queue_id_is_invalid(rxq_id))
1598 if (rx_desc_id_is_invalid(rxd_id))
1600 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1603 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1607 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1609 const struct rte_memzone *tx_mz;
1611 if (port_id_is_invalid(port_id, ENABLED_WARN))
1613 if (tx_queue_id_is_invalid(txq_id))
1615 if (tx_desc_id_is_invalid(txd_id))
1617 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1620 ring_tx_descriptor_display(tx_mz, txd_id);
1624 fwd_lcores_config_display(void)
1628 printf("List of forwarding lcores:");
1629 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1630 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1634 rxtx_config_display(void)
1636 printf(" %s packet forwarding%s - CRC stripping %s - "
1637 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
1638 retry_enabled == 0 ? "" : " with retry",
1639 rx_mode.hw_strip_crc ? "enabled" : "disabled",
1642 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1643 printf(" packet len=%u - nb packet segments=%d\n",
1644 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1646 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
1647 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
1649 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1650 nb_fwd_lcores, nb_fwd_ports);
1651 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1652 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1653 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1654 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
1655 rx_conf->rx_thresh.wthresh);
1656 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1657 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1658 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1659 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
1660 tx_conf->tx_thresh.wthresh);
1661 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
1662 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
1666 port_rss_reta_info(portid_t port_id,
1667 struct rte_eth_rss_reta_entry64 *reta_conf,
1668 uint16_t nb_entries)
1670 uint16_t i, idx, shift;
1673 if (port_id_is_invalid(port_id, ENABLED_WARN))
1676 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1678 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1682 for (i = 0; i < nb_entries; i++) {
1683 idx = i / RTE_RETA_GROUP_SIZE;
1684 shift = i % RTE_RETA_GROUP_SIZE;
1685 if (!(reta_conf[idx].mask & (1ULL << shift)))
1687 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1688 i, reta_conf[idx].reta[shift]);
1693 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1697 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1699 struct rte_eth_rss_conf rss_conf;
1700 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1704 struct rte_eth_dev_info dev_info;
1705 uint8_t hash_key_size;
1707 if (port_id_is_invalid(port_id, ENABLED_WARN))
1710 memset(&dev_info, 0, sizeof(dev_info));
1711 rte_eth_dev_info_get(port_id, &dev_info);
1712 if (dev_info.hash_key_size > 0 &&
1713 dev_info.hash_key_size <= sizeof(rss_key))
1714 hash_key_size = dev_info.hash_key_size;
1716 printf("dev_info did not provide a valid hash key size\n");
1720 rss_conf.rss_hf = 0;
1721 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1722 if (!strcmp(rss_info, rss_type_table[i].str))
1723 rss_conf.rss_hf = rss_type_table[i].rss_type;
1726 /* Get RSS hash key if asked to display it */
1727 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1728 rss_conf.rss_key_len = hash_key_size;
1729 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1733 printf("port index %d invalid\n", port_id);
1736 printf("operation not supported by device\n");
1739 printf("operation failed - diag=%d\n", diag);
1744 rss_hf = rss_conf.rss_hf;
1746 printf("RSS disabled\n");
1749 printf("RSS functions:\n ");
1750 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1751 if (rss_hf & rss_type_table[i].rss_type)
1752 printf("%s ", rss_type_table[i].str);
1757 printf("RSS key:\n");
1758 for (i = 0; i < hash_key_size; i++)
1759 printf("%02X", rss_key[i]);
1764 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1767 struct rte_eth_rss_conf rss_conf;
1771 rss_conf.rss_key = NULL;
1772 rss_conf.rss_key_len = hash_key_len;
1773 rss_conf.rss_hf = 0;
1774 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1775 if (!strcmp(rss_type_table[i].str, rss_type))
1776 rss_conf.rss_hf = rss_type_table[i].rss_type;
1778 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1780 rss_conf.rss_key = hash_key;
1781 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1788 printf("port index %d invalid\n", port_id);
1791 printf("operation not supported by device\n");
1794 printf("operation failed - diag=%d\n", diag);
1800 * Setup forwarding configuration for each logical core.
1803 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1805 streamid_t nb_fs_per_lcore;
1813 nb_fs = cfg->nb_fwd_streams;
1814 nb_fc = cfg->nb_fwd_lcores;
1815 if (nb_fs <= nb_fc) {
1816 nb_fs_per_lcore = 1;
1819 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1820 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1823 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1825 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1826 fwd_lcores[lc_id]->stream_idx = sm_id;
1827 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1828 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1832 * Assign extra remaining streams, if any.
1834 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1835 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1836 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1837 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1838 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1843 simple_fwd_config_setup(void)
1849 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1850 port_topology == PORT_TOPOLOGY_LOOP) {
1852 } else if (nb_fwd_ports % 2) {
1853 printf("\nWarning! Cannot handle an odd number of ports "
1854 "with the current port topology. Configuration "
1855 "must be changed to have an even number of ports, "
1856 "or relaunch application with "
1857 "--port-topology=chained\n\n");
1860 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1861 cur_fwd_config.nb_fwd_streams =
1862 (streamid_t) cur_fwd_config.nb_fwd_ports;
1864 /* reinitialize forwarding streams */
1868 * In the simple forwarding test, the number of forwarding cores
1869 * must be lower or equal to the number of forwarding ports.
1871 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1872 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1873 cur_fwd_config.nb_fwd_lcores =
1874 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1875 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1877 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1878 if (port_topology != PORT_TOPOLOGY_LOOP)
1879 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1882 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1883 fwd_streams[i]->rx_queue = 0;
1884 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1885 fwd_streams[i]->tx_queue = 0;
1886 fwd_streams[i]->peer_addr = j;
1887 fwd_streams[i]->retry_enabled = retry_enabled;
1889 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1890 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1891 fwd_streams[j]->rx_queue = 0;
1892 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1893 fwd_streams[j]->tx_queue = 0;
1894 fwd_streams[j]->peer_addr = i;
1895 fwd_streams[j]->retry_enabled = retry_enabled;
1901 * For the RSS forwarding test all streams distributed over lcores. Each stream
1902 * being composed of a RX queue to poll on a RX port for input messages,
1903 * associated with a TX queue of a TX port where to send forwarded packets.
1904 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1905 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1907 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1911 rss_fwd_config_setup(void)
1922 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1923 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1924 cur_fwd_config.nb_fwd_streams =
1925 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1927 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1928 cur_fwd_config.nb_fwd_lcores =
1929 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1931 /* reinitialize forwarding streams */
1934 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1936 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1937 struct fwd_stream *fs;
1939 fs = fwd_streams[sm_id];
1941 if ((rxp & 0x1) == 0)
1942 txp = (portid_t) (rxp + 1);
1944 txp = (portid_t) (rxp - 1);
1946 * if we are in loopback, simply send stuff out through the
1949 if (port_topology == PORT_TOPOLOGY_LOOP)
1952 fs->rx_port = fwd_ports_ids[rxp];
1954 fs->tx_port = fwd_ports_ids[txp];
1956 fs->peer_addr = fs->tx_port;
1957 fs->retry_enabled = retry_enabled;
1958 rxq = (queueid_t) (rxq + 1);
1963 * Restart from RX queue 0 on next RX port
1966 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1968 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1970 rxp = (portid_t) (rxp + 1);
1975 * For the DCB forwarding test, each core is assigned on each traffic class.
1977 * Each core is assigned a multi-stream, each stream being composed of
1978 * a RX queue to poll on a RX port for input messages, associated with
1979 * a TX queue of a TX port where to send forwarded packets. All RX and
1980 * TX queues are mapping to the same traffic class.
1981 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1985 dcb_fwd_config_setup(void)
1987 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1988 portid_t txp, rxp = 0;
1989 queueid_t txq, rxq = 0;
1991 uint16_t nb_rx_queue, nb_tx_queue;
1992 uint16_t i, j, k, sm_id = 0;
1995 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1996 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1997 cur_fwd_config.nb_fwd_streams =
1998 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2000 /* reinitialize forwarding streams */
2004 /* get the dcb info on the first RX and TX ports */
2005 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2006 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2008 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2009 fwd_lcores[lc_id]->stream_nb = 0;
2010 fwd_lcores[lc_id]->stream_idx = sm_id;
2011 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2012 /* if the nb_queue is zero, means this tc is
2013 * not enabled on the POOL
2015 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2017 k = fwd_lcores[lc_id]->stream_nb +
2018 fwd_lcores[lc_id]->stream_idx;
2019 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2020 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2021 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2022 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2023 for (j = 0; j < nb_rx_queue; j++) {
2024 struct fwd_stream *fs;
2026 fs = fwd_streams[k + j];
2027 fs->rx_port = fwd_ports_ids[rxp];
2028 fs->rx_queue = rxq + j;
2029 fs->tx_port = fwd_ports_ids[txp];
2030 fs->tx_queue = txq + j % nb_tx_queue;
2031 fs->peer_addr = fs->tx_port;
2032 fs->retry_enabled = retry_enabled;
2034 fwd_lcores[lc_id]->stream_nb +=
2035 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2037 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2040 if (tc < rxp_dcb_info.nb_tcs)
2042 /* Restart from TC 0 on next RX port */
2044 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2046 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2049 if (rxp >= nb_fwd_ports)
2051 /* get the dcb information on next RX and TX ports */
2052 if ((rxp & 0x1) == 0)
2053 txp = (portid_t) (rxp + 1);
2055 txp = (portid_t) (rxp - 1);
2056 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2057 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2062 icmp_echo_config_setup(void)
2069 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2070 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2071 (nb_txq * nb_fwd_ports);
2073 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2074 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2075 cur_fwd_config.nb_fwd_streams =
2076 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2077 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2078 cur_fwd_config.nb_fwd_lcores =
2079 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2080 if (verbose_level > 0) {
2081 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2083 cur_fwd_config.nb_fwd_lcores,
2084 cur_fwd_config.nb_fwd_ports,
2085 cur_fwd_config.nb_fwd_streams);
2088 /* reinitialize forwarding streams */
2090 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2092 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2093 if (verbose_level > 0)
2094 printf(" core=%d: \n", lc_id);
2095 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2096 struct fwd_stream *fs;
2097 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2098 fs->rx_port = fwd_ports_ids[rxp];
2100 fs->tx_port = fs->rx_port;
2102 fs->peer_addr = fs->tx_port;
2103 fs->retry_enabled = retry_enabled;
2104 if (verbose_level > 0)
2105 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2106 sm_id, fs->rx_port, fs->rx_queue,
2108 rxq = (queueid_t) (rxq + 1);
2109 if (rxq == nb_rxq) {
2111 rxp = (portid_t) (rxp + 1);
2118 fwd_config_setup(void)
2120 cur_fwd_config.fwd_eng = cur_fwd_eng;
2121 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2122 icmp_echo_config_setup();
2125 if ((nb_rxq > 1) && (nb_txq > 1)){
2127 dcb_fwd_config_setup();
2129 rss_fwd_config_setup();
2132 simple_fwd_config_setup();
2136 pkt_fwd_config_display(struct fwd_config *cfg)
2138 struct fwd_stream *fs;
2142 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2143 "NUMA support %s, MP over anonymous pages %s\n",
2144 cfg->fwd_eng->fwd_mode_name,
2145 retry_enabled == 0 ? "" : " with retry",
2146 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2147 numa_support == 1 ? "enabled" : "disabled",
2148 mp_anon != 0 ? "enabled" : "disabled");
2151 printf("TX retry num: %u, delay between TX retries: %uus\n",
2152 burst_tx_retry_num, burst_tx_delay_time);
2153 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2154 printf("Logical Core %u (socket %u) forwards packets on "
2156 fwd_lcores_cpuids[lc_id],
2157 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2158 fwd_lcores[lc_id]->stream_nb);
2159 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2160 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2161 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2162 "P=%d/Q=%d (socket %u) ",
2163 fs->rx_port, fs->rx_queue,
2164 ports[fs->rx_port].socket_id,
2165 fs->tx_port, fs->tx_queue,
2166 ports[fs->tx_port].socket_id);
2167 print_ethaddr("peer=",
2168 &peer_eth_addrs[fs->peer_addr]);
2176 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2179 unsigned int lcore_cpuid;
2184 for (i = 0; i < nb_lc; i++) {
2185 lcore_cpuid = lcorelist[i];
2186 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2187 printf("lcore %u not enabled\n", lcore_cpuid);
2190 if (lcore_cpuid == rte_get_master_lcore()) {
2191 printf("lcore %u cannot be masked on for running "
2192 "packet forwarding, which is the master lcore "
2193 "and reserved for command line parsing only\n",
2198 fwd_lcores_cpuids[i] = lcore_cpuid;
2200 if (record_now == 0) {
2204 nb_cfg_lcores = (lcoreid_t) nb_lc;
2205 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2206 printf("previous number of forwarding cores %u - changed to "
2207 "number of configured cores %u\n",
2208 (unsigned int) nb_fwd_lcores, nb_lc);
2209 nb_fwd_lcores = (lcoreid_t) nb_lc;
2216 set_fwd_lcores_mask(uint64_t lcoremask)
2218 unsigned int lcorelist[64];
2222 if (lcoremask == 0) {
2223 printf("Invalid NULL mask of cores\n");
2227 for (i = 0; i < 64; i++) {
2228 if (! ((uint64_t)(1ULL << i) & lcoremask))
2230 lcorelist[nb_lc++] = i;
2232 return set_fwd_lcores_list(lcorelist, nb_lc);
2236 set_fwd_lcores_number(uint16_t nb_lc)
2238 if (nb_lc > nb_cfg_lcores) {
2239 printf("nb fwd cores %u > %u (max. number of configured "
2240 "lcores) - ignored\n",
2241 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2244 nb_fwd_lcores = (lcoreid_t) nb_lc;
2245 printf("Number of forwarding cores set to %u\n",
2246 (unsigned int) nb_fwd_lcores);
2250 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2258 for (i = 0; i < nb_pt; i++) {
2259 port_id = (portid_t) portlist[i];
2260 if (port_id_is_invalid(port_id, ENABLED_WARN))
2263 fwd_ports_ids[i] = port_id;
2265 if (record_now == 0) {
2269 nb_cfg_ports = (portid_t) nb_pt;
2270 if (nb_fwd_ports != (portid_t) nb_pt) {
2271 printf("previous number of forwarding ports %u - changed to "
2272 "number of configured ports %u\n",
2273 (unsigned int) nb_fwd_ports, nb_pt);
2274 nb_fwd_ports = (portid_t) nb_pt;
2279 set_fwd_ports_mask(uint64_t portmask)
2281 unsigned int portlist[64];
2285 if (portmask == 0) {
2286 printf("Invalid NULL mask of ports\n");
2290 RTE_ETH_FOREACH_DEV(i) {
2291 if (! ((uint64_t)(1ULL << i) & portmask))
2293 portlist[nb_pt++] = i;
2295 set_fwd_ports_list(portlist, nb_pt);
2299 set_fwd_ports_number(uint16_t nb_pt)
2301 if (nb_pt > nb_cfg_ports) {
2302 printf("nb fwd ports %u > %u (number of configured "
2303 "ports) - ignored\n",
2304 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2307 nb_fwd_ports = (portid_t) nb_pt;
2308 printf("Number of forwarding ports set to %u\n",
2309 (unsigned int) nb_fwd_ports);
2313 port_is_forwarding(portid_t port_id)
2317 if (port_id_is_invalid(port_id, ENABLED_WARN))
2320 for (i = 0; i < nb_fwd_ports; i++) {
2321 if (fwd_ports_ids[i] == port_id)
2329 set_nb_pkt_per_burst(uint16_t nb)
2331 if (nb > MAX_PKT_BURST) {
2332 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2334 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2337 nb_pkt_per_burst = nb;
2338 printf("Number of packets per burst set to %u\n",
2339 (unsigned int) nb_pkt_per_burst);
2343 tx_split_get_name(enum tx_pkt_split split)
2347 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2348 if (tx_split_name[i].split == split)
2349 return tx_split_name[i].name;
2355 set_tx_pkt_split(const char *name)
2359 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2360 if (strcmp(tx_split_name[i].name, name) == 0) {
2361 tx_pkt_split = tx_split_name[i].split;
2365 printf("unknown value: \"%s\"\n", name);
2369 show_tx_pkt_segments(void)
2375 split = tx_split_get_name(tx_pkt_split);
2377 printf("Number of segments: %u\n", n);
2378 printf("Segment sizes: ");
2379 for (i = 0; i != n - 1; i++)
2380 printf("%hu,", tx_pkt_seg_lengths[i]);
2381 printf("%hu\n", tx_pkt_seg_lengths[i]);
2382 printf("Split packet: %s\n", split);
2386 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2388 uint16_t tx_pkt_len;
2391 if (nb_segs >= (unsigned) nb_txd) {
2392 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2393 nb_segs, (unsigned int) nb_txd);
2398 * Check that each segment length is greater or equal than
2399 * the mbuf data sise.
2400 * Check also that the total packet length is greater or equal than the
2401 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2404 for (i = 0; i < nb_segs; i++) {
2405 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2406 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2407 i, seg_lengths[i], (unsigned) mbuf_data_size);
2410 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2412 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2413 printf("total packet length=%u < %d - give up\n",
2414 (unsigned) tx_pkt_len,
2415 (int)(sizeof(struct ether_hdr) + 20 + 8));
2419 for (i = 0; i < nb_segs; i++)
2420 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2422 tx_pkt_length = tx_pkt_len;
2423 tx_pkt_nb_segs = (uint8_t) nb_segs;
2427 list_pkt_forwarding_modes(void)
2429 static char fwd_modes[128] = "";
2430 const char *separator = "|";
2431 struct fwd_engine *fwd_eng;
2434 if (strlen (fwd_modes) == 0) {
2435 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2436 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2437 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2438 strncat(fwd_modes, separator,
2439 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2441 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2448 list_pkt_forwarding_retry_modes(void)
2450 static char fwd_modes[128] = "";
2451 const char *separator = "|";
2452 struct fwd_engine *fwd_eng;
2455 if (strlen(fwd_modes) == 0) {
2456 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2457 if (fwd_eng == &rx_only_engine)
2459 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2461 strlen(fwd_modes) - 1);
2462 strncat(fwd_modes, separator,
2464 strlen(fwd_modes) - 1);
2466 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2473 set_pkt_forwarding_mode(const char *fwd_mode_name)
2475 struct fwd_engine *fwd_eng;
2479 while ((fwd_eng = fwd_engines[i]) != NULL) {
2480 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2481 printf("Set %s packet forwarding mode%s\n",
2483 retry_enabled == 0 ? "" : " with retry");
2484 cur_fwd_eng = fwd_eng;
2489 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2493 set_verbose_level(uint16_t vb_level)
2495 printf("Change verbose level from %u to %u\n",
2496 (unsigned int) verbose_level, (unsigned int) vb_level);
2497 verbose_level = vb_level;
2501 vlan_extend_set(portid_t port_id, int on)
2506 if (port_id_is_invalid(port_id, ENABLED_WARN))
2509 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2512 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2514 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2516 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2518 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2519 "diag=%d\n", port_id, on, diag);
2523 rx_vlan_strip_set(portid_t port_id, int on)
2528 if (port_id_is_invalid(port_id, ENABLED_WARN))
2531 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2534 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2536 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2538 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2540 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2541 "diag=%d\n", port_id, on, diag);
2545 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2549 if (port_id_is_invalid(port_id, ENABLED_WARN))
2552 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2554 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2555 "diag=%d\n", port_id, queue_id, on, diag);
2559 rx_vlan_filter_set(portid_t port_id, int on)
2564 if (port_id_is_invalid(port_id, ENABLED_WARN))
2567 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2570 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2572 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2574 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2576 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2577 "diag=%d\n", port_id, on, diag);
2581 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2585 if (port_id_is_invalid(port_id, ENABLED_WARN))
2587 if (vlan_id_is_invalid(vlan_id))
2589 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2592 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2594 port_id, vlan_id, on, diag);
2599 rx_vlan_all_filter_set(portid_t port_id, int on)
2603 if (port_id_is_invalid(port_id, ENABLED_WARN))
2605 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2606 if (rx_vft_set(port_id, vlan_id, on))
2612 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2616 if (port_id_is_invalid(port_id, ENABLED_WARN))
2619 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2623 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2625 port_id, vlan_type, tp_id, diag);
2629 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2632 if (port_id_is_invalid(port_id, ENABLED_WARN))
2634 if (vlan_id_is_invalid(vlan_id))
2637 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2638 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2639 printf("Error, as QinQ has been enabled.\n");
2643 tx_vlan_reset(port_id);
2644 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
2645 ports[port_id].tx_vlan_id = vlan_id;
2649 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2652 if (port_id_is_invalid(port_id, ENABLED_WARN))
2654 if (vlan_id_is_invalid(vlan_id))
2656 if (vlan_id_is_invalid(vlan_id_outer))
2659 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2660 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2661 printf("Error, as QinQ hasn't been enabled.\n");
2665 tx_vlan_reset(port_id);
2666 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
2667 ports[port_id].tx_vlan_id = vlan_id;
2668 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2672 tx_vlan_reset(portid_t port_id)
2674 if (port_id_is_invalid(port_id, ENABLED_WARN))
2676 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
2677 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
2678 ports[port_id].tx_vlan_id = 0;
2679 ports[port_id].tx_vlan_id_outer = 0;
2683 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2685 if (port_id_is_invalid(port_id, ENABLED_WARN))
2688 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2692 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2695 uint8_t existing_mapping_found = 0;
2697 if (port_id_is_invalid(port_id, ENABLED_WARN))
2700 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2703 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2704 printf("map_value not in required range 0..%d\n",
2705 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2709 if (!is_rx) { /*then tx*/
2710 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2711 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2712 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2713 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2714 existing_mapping_found = 1;
2718 if (!existing_mapping_found) { /* A new additional mapping... */
2719 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2720 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2721 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2722 nb_tx_queue_stats_mappings++;
2726 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2727 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2728 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2729 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2730 existing_mapping_found = 1;
2734 if (!existing_mapping_found) { /* A new additional mapping... */
2735 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2736 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2737 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2738 nb_rx_queue_stats_mappings++;
2744 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2746 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2748 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2749 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2750 " tunnel_id: 0x%08x",
2751 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2752 rte_be_to_cpu_32(mask->tunnel_id_mask));
2753 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2754 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2755 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2756 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2758 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2759 rte_be_to_cpu_16(mask->src_port_mask),
2760 rte_be_to_cpu_16(mask->dst_port_mask));
2762 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2763 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2764 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
2765 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
2766 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
2768 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2769 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
2770 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
2771 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
2772 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
2779 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2781 struct rte_eth_flex_payload_cfg *cfg;
2784 for (i = 0; i < flex_conf->nb_payloads; i++) {
2785 cfg = &flex_conf->flex_set[i];
2786 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2788 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2789 printf("\n L2_PAYLOAD: ");
2790 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2791 printf("\n L3_PAYLOAD: ");
2792 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2793 printf("\n L4_PAYLOAD: ");
2795 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2796 for (j = 0; j < num; j++)
2797 printf(" %-5u", cfg->src_offset[j]);
2803 flowtype_to_str(uint16_t flow_type)
2805 struct flow_type_info {
2811 static struct flow_type_info flowtype_str_table[] = {
2812 {"raw", RTE_ETH_FLOW_RAW},
2813 {"ipv4", RTE_ETH_FLOW_IPV4},
2814 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2815 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2816 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2817 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2818 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2819 {"ipv6", RTE_ETH_FLOW_IPV6},
2820 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2821 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2822 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2823 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2824 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2825 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2826 {"port", RTE_ETH_FLOW_PORT},
2827 {"vxlan", RTE_ETH_FLOW_VXLAN},
2828 {"geneve", RTE_ETH_FLOW_GENEVE},
2829 {"nvgre", RTE_ETH_FLOW_NVGRE},
2832 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2833 if (flowtype_str_table[i].ftype == flow_type)
2834 return flowtype_str_table[i].str;
2841 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2843 struct rte_eth_fdir_flex_mask *mask;
2847 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2848 mask = &flex_conf->flex_mask[i];
2849 p = flowtype_to_str(mask->flow_type);
2850 printf("\n %s:\t", p ? p : "unknown");
2851 for (j = 0; j < num; j++)
2852 printf(" %02x", mask->mask[j]);
2858 print_fdir_flow_type(uint32_t flow_types_mask)
2863 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2864 if (!(flow_types_mask & (1 << i)))
2866 p = flowtype_to_str(i);
2876 fdir_get_infos(portid_t port_id)
2878 struct rte_eth_fdir_stats fdir_stat;
2879 struct rte_eth_fdir_info fdir_info;
2882 static const char *fdir_stats_border = "########################";
2884 if (port_id_is_invalid(port_id, ENABLED_WARN))
2886 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
2888 printf("\n FDIR is not supported on port %-2d\n",
2893 memset(&fdir_info, 0, sizeof(fdir_info));
2894 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2895 RTE_ETH_FILTER_INFO, &fdir_info);
2896 memset(&fdir_stat, 0, sizeof(fdir_stat));
2897 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2898 RTE_ETH_FILTER_STATS, &fdir_stat);
2899 printf("\n %s FDIR infos for port %-2d %s\n",
2900 fdir_stats_border, port_id, fdir_stats_border);
2902 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
2903 printf(" PERFECT\n");
2904 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2905 printf(" PERFECT-MAC-VLAN\n");
2906 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2907 printf(" PERFECT-TUNNEL\n");
2908 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
2909 printf(" SIGNATURE\n");
2911 printf(" DISABLE\n");
2912 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
2913 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
2914 printf(" SUPPORTED FLOW TYPE: ");
2915 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
2917 printf(" FLEX PAYLOAD INFO:\n");
2918 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
2919 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
2920 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
2921 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
2922 fdir_info.flex_payload_unit,
2923 fdir_info.max_flex_payload_segment_num,
2924 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
2926 print_fdir_mask(&fdir_info.mask);
2927 if (fdir_info.flex_conf.nb_payloads > 0) {
2928 printf(" FLEX PAYLOAD SRC OFFSET:");
2929 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2931 if (fdir_info.flex_conf.nb_flexmasks > 0) {
2932 printf(" FLEX MASK CFG:");
2933 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2935 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2936 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2937 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2938 fdir_info.guarant_spc, fdir_info.best_spc);
2939 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2940 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2941 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2942 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2943 fdir_stat.collision, fdir_stat.free,
2944 fdir_stat.maxhash, fdir_stat.maxlen,
2945 fdir_stat.add, fdir_stat.remove,
2946 fdir_stat.f_add, fdir_stat.f_remove);
2947 printf(" %s############################%s\n",
2948 fdir_stats_border, fdir_stats_border);
2952 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2954 struct rte_port *port;
2955 struct rte_eth_fdir_flex_conf *flex_conf;
2958 port = &ports[port_id];
2959 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2960 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2961 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2966 if (i >= RTE_ETH_FLOW_MAX) {
2967 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2968 idx = flex_conf->nb_flexmasks;
2969 flex_conf->nb_flexmasks++;
2971 printf("The flex mask table is full. Can not set flex"
2972 " mask for flow_type(%u).", cfg->flow_type);
2976 (void)rte_memcpy(&flex_conf->flex_mask[idx],
2978 sizeof(struct rte_eth_fdir_flex_mask));
2982 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2984 struct rte_port *port;
2985 struct rte_eth_fdir_flex_conf *flex_conf;
2988 port = &ports[port_id];
2989 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2990 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2991 if (cfg->type == flex_conf->flex_set[i].type) {
2996 if (i >= RTE_ETH_PAYLOAD_MAX) {
2997 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2998 idx = flex_conf->nb_payloads;
2999 flex_conf->nb_payloads++;
3001 printf("The flex payload table is full. Can not set"
3002 " flex payload for type(%u).", cfg->type);
3006 (void)rte_memcpy(&flex_conf->flex_set[idx],
3008 sizeof(struct rte_eth_flex_payload_cfg));
3012 #ifdef RTE_LIBRTE_IXGBE_PMD
3014 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3019 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3021 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3026 printf("rte_pmd_ixgbe_set_vf_rx for port_id=%d failed "
3027 "diag=%d\n", port_id, diag);
3029 printf("rte_pmd_ixgbe_set_vf_tx for port_id=%d failed "
3030 "diag=%d\n", port_id, diag);
3036 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3039 struct rte_eth_link link;
3041 if (port_id_is_invalid(port_id, ENABLED_WARN))
3043 rte_eth_link_get_nowait(port_id, &link);
3044 if (rate > link.link_speed) {
3045 printf("Invalid rate value:%u bigger than link speed: %u\n",
3046 rate, link.link_speed);
3049 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3052 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3057 #ifdef RTE_LIBRTE_IXGBE_PMD
3059 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3063 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate, q_msk);
3066 printf("rte_pmd_ixgbe_set_vf_rate_limit for port_id=%d failed diag=%d\n",
3073 * Functions to manage the set of filtered Multicast MAC addresses.
3075 * A pool of filtered multicast MAC addresses is associated with each port.
3076 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3077 * The address of the pool and the number of valid multicast MAC addresses
3078 * recorded in the pool are stored in the fields "mc_addr_pool" and
3079 * "mc_addr_nb" of the "rte_port" data structure.
3081 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3082 * to be supplied a contiguous array of multicast MAC addresses.
3083 * To comply with this constraint, the set of multicast addresses recorded
3084 * into the pool are systematically compacted at the beginning of the pool.
3085 * Hence, when a multicast address is removed from the pool, all following
3086 * addresses, if any, are copied back to keep the set contiguous.
3088 #define MCAST_POOL_INC 32
3091 mcast_addr_pool_extend(struct rte_port *port)
3093 struct ether_addr *mc_pool;
3094 size_t mc_pool_size;
3097 * If a free entry is available at the end of the pool, just
3098 * increment the number of recorded multicast addresses.
3100 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3106 * [re]allocate a pool with MCAST_POOL_INC more entries.
3107 * The previous test guarantees that port->mc_addr_nb is a multiple
3108 * of MCAST_POOL_INC.
3110 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3112 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3114 if (mc_pool == NULL) {
3115 printf("allocation of pool of %u multicast addresses failed\n",
3116 port->mc_addr_nb + MCAST_POOL_INC);
3120 port->mc_addr_pool = mc_pool;
3127 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3130 if (addr_idx == port->mc_addr_nb) {
3131 /* No need to recompact the set of multicast addressses. */
3132 if (port->mc_addr_nb == 0) {
3133 /* free the pool of multicast addresses. */
3134 free(port->mc_addr_pool);
3135 port->mc_addr_pool = NULL;
3139 memmove(&port->mc_addr_pool[addr_idx],
3140 &port->mc_addr_pool[addr_idx + 1],
3141 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3145 eth_port_multicast_addr_list_set(uint8_t port_id)
3147 struct rte_port *port;
3150 port = &ports[port_id];
3151 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3155 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3156 port->mc_addr_nb, port_id, -diag);
3160 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
3162 struct rte_port *port;
3165 if (port_id_is_invalid(port_id, ENABLED_WARN))
3168 port = &ports[port_id];
3171 * Check that the added multicast MAC address is not already recorded
3172 * in the pool of multicast addresses.
3174 for (i = 0; i < port->mc_addr_nb; i++) {
3175 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3176 printf("multicast address already filtered by port\n");
3181 if (mcast_addr_pool_extend(port) != 0)
3183 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3184 eth_port_multicast_addr_list_set(port_id);
3188 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
3190 struct rte_port *port;
3193 if (port_id_is_invalid(port_id, ENABLED_WARN))
3196 port = &ports[port_id];
3199 * Search the pool of multicast MAC addresses for the removed address.
3201 for (i = 0; i < port->mc_addr_nb; i++) {
3202 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3205 if (i == port->mc_addr_nb) {
3206 printf("multicast address not filtered by port %d\n", port_id);
3210 mcast_addr_pool_remove(port, i);
3211 eth_port_multicast_addr_list_set(port_id);
3215 port_dcb_info_display(uint8_t port_id)
3217 struct rte_eth_dcb_info dcb_info;
3220 static const char *border = "================";
3222 if (port_id_is_invalid(port_id, ENABLED_WARN))
3225 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3227 printf("\n Failed to get dcb infos on port %-2d\n",
3231 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3232 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3234 for (i = 0; i < dcb_info.nb_tcs; i++)
3236 printf("\n Priority : ");
3237 for (i = 0; i < dcb_info.nb_tcs; i++)
3238 printf("\t%4d", dcb_info.prio_tc[i]);
3239 printf("\n BW percent :");
3240 for (i = 0; i < dcb_info.nb_tcs; i++)
3241 printf("\t%4d%%", dcb_info.tc_bws[i]);
3242 printf("\n RXQ base : ");
3243 for (i = 0; i < dcb_info.nb_tcs; i++)
3244 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3245 printf("\n RXQ number :");
3246 for (i = 0; i < dcb_info.nb_tcs; i++)
3247 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3248 printf("\n TXQ base : ");
3249 for (i = 0; i < dcb_info.nb_tcs; i++)
3250 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3251 printf("\n TXQ number :");
3252 for (i = 0; i < dcb_info.nb_tcs; i++)
3253 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3258 open_ddp_package_file(const char *file_path, uint32_t *size)
3260 FILE *fh = fopen(file_path, "rb");
3262 uint8_t *buf = NULL;
3269 printf("%s: Failed to open %s\n", __func__, file_path);
3273 ret = fseek(fh, 0, SEEK_END);
3276 printf("%s: File operations failed\n", __func__);
3280 pkg_size = ftell(fh);
3282 buf = (uint8_t *)malloc(pkg_size);
3285 printf("%s: Failed to malloc memory\n", __func__);
3289 ret = fseek(fh, 0, SEEK_SET);
3292 printf("%s: File seek operation failed\n", __func__);
3293 close_ddp_package_file(buf);
3297 ret = fread(buf, 1, pkg_size, fh);
3300 printf("%s: File read operation failed\n", __func__);
3301 close_ddp_package_file(buf);
3314 close_ddp_package_file(uint8_t *buf)