4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5 * Copyright 2013-2014 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/queue.h>
43 #include <sys/types.h>
48 #include <rte_common.h>
49 #include <rte_byteorder.h>
50 #include <rte_debug.h>
52 #include <rte_memory.h>
53 #include <rte_memcpy.h>
54 #include <rte_memzone.h>
55 #include <rte_launch.h>
57 #include <rte_per_lcore.h>
58 #include <rte_lcore.h>
59 #include <rte_atomic.h>
60 #include <rte_branch_prediction.h>
61 #include <rte_mempool.h>
63 #include <rte_interrupts.h>
65 #include <rte_ether.h>
66 #include <rte_ethdev.h>
67 #include <rte_string_fns.h>
68 #include <rte_cycles.h>
70 #include <rte_errno.h>
71 #ifdef RTE_LIBRTE_IXGBE_PMD
72 #include <rte_pmd_ixgbe.h>
74 #ifdef RTE_LIBRTE_BNXT_PMD
75 #include <rte_pmd_bnxt.h>
81 static char *flowtype_to_str(uint16_t flow_type);
84 enum tx_pkt_split split;
88 .split = TX_PKT_SPLIT_OFF,
92 .split = TX_PKT_SPLIT_ON,
96 .split = TX_PKT_SPLIT_RND,
101 struct rss_type_info {
106 static const struct rss_type_info rss_type_table[] = {
107 { "ipv4", ETH_RSS_IPV4 },
108 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
109 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
110 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
111 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
112 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
113 { "ipv6", ETH_RSS_IPV6 },
114 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
115 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
116 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
117 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
118 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
119 { "l2-payload", ETH_RSS_L2_PAYLOAD },
120 { "ipv6-ex", ETH_RSS_IPV6_EX },
121 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
122 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
123 { "port", ETH_RSS_PORT },
124 { "vxlan", ETH_RSS_VXLAN },
125 { "geneve", ETH_RSS_GENEVE },
126 { "nvgre", ETH_RSS_NVGRE },
131 print_ethaddr(const char *name, struct ether_addr *eth_addr)
133 char buf[ETHER_ADDR_FMT_SIZE];
134 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
135 printf("%s%s", name, buf);
139 nic_stats_display(portid_t port_id)
141 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
142 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
143 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
144 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles;
145 uint64_t mpps_rx, mpps_tx;
146 struct rte_eth_stats stats;
147 struct rte_port *port = &ports[port_id];
151 static const char *nic_stats_border = "########################";
153 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
154 printf("Valid port range is [0");
155 RTE_ETH_FOREACH_DEV(pid)
160 rte_eth_stats_get(port_id, &stats);
161 printf("\n %s NIC statistics for port %-2d %s\n",
162 nic_stats_border, port_id, nic_stats_border);
164 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
165 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
167 stats.ipackets, stats.imissed, stats.ibytes);
168 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
169 printf(" RX-nombuf: %-10"PRIu64"\n",
171 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
173 stats.opackets, stats.oerrors, stats.obytes);
176 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
177 " RX-bytes: %10"PRIu64"\n",
178 stats.ipackets, stats.ierrors, stats.ibytes);
179 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
180 printf(" RX-nombuf: %10"PRIu64"\n",
182 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
183 " TX-bytes: %10"PRIu64"\n",
184 stats.opackets, stats.oerrors, stats.obytes);
187 if (port->rx_queue_stats_mapping_enabled) {
189 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
190 printf(" Stats reg %2d RX-packets: %10"PRIu64
191 " RX-errors: %10"PRIu64
192 " RX-bytes: %10"PRIu64"\n",
193 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
196 if (port->tx_queue_stats_mapping_enabled) {
198 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
199 printf(" Stats reg %2d TX-packets: %10"PRIu64
200 " TX-bytes: %10"PRIu64"\n",
201 i, stats.q_opackets[i], stats.q_obytes[i]);
205 diff_cycles = prev_cycles[port_id];
206 prev_cycles[port_id] = rte_rdtsc();
208 diff_cycles = prev_cycles[port_id] - diff_cycles;
210 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
211 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
212 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
213 (stats.opackets - prev_pkts_tx[port_id]) : 0;
214 prev_pkts_rx[port_id] = stats.ipackets;
215 prev_pkts_tx[port_id] = stats.opackets;
216 mpps_rx = diff_cycles > 0 ?
217 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
218 mpps_tx = diff_cycles > 0 ?
219 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
220 printf("\n Throughput (since last show)\n");
221 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
224 printf(" %s############################%s\n",
225 nic_stats_border, nic_stats_border);
229 nic_stats_clear(portid_t port_id)
233 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
234 printf("Valid port range is [0");
235 RTE_ETH_FOREACH_DEV(pid)
240 rte_eth_stats_reset(port_id);
241 printf("\n NIC statistics for port %d cleared\n", port_id);
245 nic_xstats_display(portid_t port_id)
247 struct rte_eth_xstat *xstats;
248 int cnt_xstats, idx_xstat;
249 struct rte_eth_xstat_name *xstats_names;
251 printf("###### NIC extended statistics for port %-2d\n", port_id);
252 if (!rte_eth_dev_is_valid_port(port_id)) {
253 printf("Error: Invalid port number %i\n", port_id);
258 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
259 if (cnt_xstats < 0) {
260 printf("Error: Cannot get count of xstats\n");
264 /* Get id-name lookup table */
265 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
266 if (xstats_names == NULL) {
267 printf("Cannot allocate memory for xstats lookup\n");
270 if (cnt_xstats != rte_eth_xstats_get_names(
271 port_id, xstats_names, cnt_xstats)) {
272 printf("Error: Cannot get xstats lookup\n");
277 /* Get stats themselves */
278 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
279 if (xstats == NULL) {
280 printf("Cannot allocate memory for xstats\n");
284 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
285 printf("Error: Unable to get xstats\n");
292 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
293 printf("%s: %"PRIu64"\n",
294 xstats_names[idx_xstat].name,
295 xstats[idx_xstat].value);
301 nic_xstats_clear(portid_t port_id)
303 rte_eth_xstats_reset(port_id);
307 nic_stats_mapping_display(portid_t port_id)
309 struct rte_port *port = &ports[port_id];
313 static const char *nic_stats_mapping_border = "########################";
315 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
316 printf("Valid port range is [0");
317 RTE_ETH_FOREACH_DEV(pid)
323 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
324 printf("Port id %d - either does not support queue statistic mapping or"
325 " no queue statistic mapping set\n", port_id);
329 printf("\n %s NIC statistics mapping for port %-2d %s\n",
330 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
332 if (port->rx_queue_stats_mapping_enabled) {
333 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
334 if (rx_queue_stats_mappings[i].port_id == port_id) {
335 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
336 rx_queue_stats_mappings[i].queue_id,
337 rx_queue_stats_mappings[i].stats_counter_id);
344 if (port->tx_queue_stats_mapping_enabled) {
345 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
346 if (tx_queue_stats_mappings[i].port_id == port_id) {
347 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
348 tx_queue_stats_mappings[i].queue_id,
349 tx_queue_stats_mappings[i].stats_counter_id);
354 printf(" %s####################################%s\n",
355 nic_stats_mapping_border, nic_stats_mapping_border);
359 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
361 struct rte_eth_rxq_info qinfo;
363 static const char *info_border = "*********************";
365 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
367 printf("Failed to retrieve information for port: %u, "
368 "RX queue: %hu\nerror desc: %s(%d)\n",
369 port_id, queue_id, strerror(-rc), rc);
373 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
374 info_border, port_id, queue_id, info_border);
376 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
377 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
378 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
379 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
380 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
381 printf("\nRX drop packets: %s",
382 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
383 printf("\nRX deferred start: %s",
384 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
385 printf("\nRX scattered packets: %s",
386 (qinfo.scattered_rx != 0) ? "on" : "off");
387 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
392 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
394 struct rte_eth_txq_info qinfo;
396 static const char *info_border = "*********************";
398 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
400 printf("Failed to retrieve information for port: %u, "
401 "TX queue: %hu\nerror desc: %s(%d)\n",
402 port_id, queue_id, strerror(-rc), rc);
406 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
407 info_border, port_id, queue_id, info_border);
409 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
410 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
411 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
412 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
413 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
414 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
415 printf("\nTX deferred start: %s",
416 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
417 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
422 port_infos_display(portid_t port_id)
424 struct rte_port *port;
425 struct ether_addr mac_addr;
426 struct rte_eth_link link;
427 struct rte_eth_dev_info dev_info;
429 struct rte_mempool * mp;
430 static const char *info_border = "*********************";
434 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
435 printf("Valid port range is [0");
436 RTE_ETH_FOREACH_DEV(pid)
441 port = &ports[port_id];
442 rte_eth_link_get_nowait(port_id, &link);
443 memset(&dev_info, 0, sizeof(dev_info));
444 rte_eth_dev_info_get(port_id, &dev_info);
445 printf("\n%s Infos for port %-2d %s\n",
446 info_border, port_id, info_border);
447 rte_eth_macaddr_get(port_id, &mac_addr);
448 print_ethaddr("MAC address: ", &mac_addr);
449 printf("\nDriver name: %s", dev_info.driver_name);
450 printf("\nConnect to socket: %u", port->socket_id);
452 if (port_numa[port_id] != NUMA_NO_CONFIG) {
453 mp = mbuf_pool_find(port_numa[port_id]);
455 printf("\nmemory allocation on the socket: %d",
458 printf("\nmemory allocation on the socket: %u",port->socket_id);
460 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
461 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
462 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
463 ("full-duplex") : ("half-duplex"));
465 if (!rte_eth_dev_get_mtu(port_id, &mtu))
466 printf("MTU: %u\n", mtu);
468 printf("Promiscuous mode: %s\n",
469 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
470 printf("Allmulticast mode: %s\n",
471 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
472 printf("Maximum number of MAC addresses: %u\n",
473 (unsigned int)(port->dev_info.max_mac_addrs));
474 printf("Maximum number of MAC addresses of hash filtering: %u\n",
475 (unsigned int)(port->dev_info.max_hash_mac_addrs));
477 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
478 if (vlan_offload >= 0){
479 printf("VLAN offload: \n");
480 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
481 printf(" strip on \n");
483 printf(" strip off \n");
485 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
486 printf(" filter on \n");
488 printf(" filter off \n");
490 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
491 printf(" qinq(extend) on \n");
493 printf(" qinq(extend) off \n");
496 if (dev_info.hash_key_size > 0)
497 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
498 if (dev_info.reta_size > 0)
499 printf("Redirection table size: %u\n", dev_info.reta_size);
500 if (!dev_info.flow_type_rss_offloads)
501 printf("No flow type is supported.\n");
506 printf("Supported flow types:\n");
507 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
508 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
509 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
511 p = flowtype_to_str(i);
515 printf(" user defined %d\n", i);
519 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
520 printf("Max possible number of RXDs per queue: %hu\n",
521 dev_info.rx_desc_lim.nb_max);
522 printf("Min possible number of RXDs per queue: %hu\n",
523 dev_info.rx_desc_lim.nb_min);
524 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
526 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
527 printf("Max possible number of TXDs per queue: %hu\n",
528 dev_info.tx_desc_lim.nb_max);
529 printf("Min possible number of TXDs per queue: %hu\n",
530 dev_info.tx_desc_lim.nb_min);
531 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
535 port_offload_cap_display(portid_t port_id)
537 struct rte_eth_dev *dev;
538 struct rte_eth_dev_info dev_info;
539 static const char *info_border = "************";
541 if (port_id_is_invalid(port_id, ENABLED_WARN))
544 dev = &rte_eth_devices[port_id];
545 rte_eth_dev_info_get(port_id, &dev_info);
547 printf("\n%s Port %d supported offload features: %s\n",
548 info_border, port_id, info_border);
550 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
551 printf("VLAN stripped: ");
552 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
558 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
559 printf("Double VLANs stripped: ");
560 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
566 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
567 printf("RX IPv4 checksum: ");
568 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
574 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
575 printf("RX UDP checksum: ");
576 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
582 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
583 printf("RX TCP checksum: ");
584 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
590 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
591 printf("RX Outer IPv4 checksum: on");
593 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
594 printf("Large receive offload: ");
595 if (dev->data->dev_conf.rxmode.enable_lro)
601 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
602 printf("VLAN insert: ");
603 if (ports[port_id].tx_ol_flags &
604 TESTPMD_TX_OFFLOAD_INSERT_VLAN)
610 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) {
611 printf("HW timestamp: ");
612 if (dev->data->dev_conf.rxmode.hw_timestamp)
618 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
619 printf("Double VLANs insert: ");
620 if (ports[port_id].tx_ol_flags &
621 TESTPMD_TX_OFFLOAD_INSERT_QINQ)
627 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
628 printf("TX IPv4 checksum: ");
629 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
635 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
636 printf("TX UDP checksum: ");
637 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
643 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
644 printf("TX TCP checksum: ");
645 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
651 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
652 printf("TX SCTP checksum: ");
653 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
659 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
660 printf("TX Outer IPv4 checksum: ");
661 if (ports[port_id].tx_ol_flags &
662 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
668 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
669 printf("TX TCP segmentation: ");
670 if (ports[port_id].tso_segsz != 0)
676 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
677 printf("TX UDP segmentation: ");
678 if (ports[port_id].tso_segsz != 0)
684 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
685 printf("TSO for VXLAN tunnel packet: ");
686 if (ports[port_id].tunnel_tso_segsz)
692 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
693 printf("TSO for GRE tunnel packet: ");
694 if (ports[port_id].tunnel_tso_segsz)
700 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
701 printf("TSO for IPIP tunnel packet: ");
702 if (ports[port_id].tunnel_tso_segsz)
708 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
709 printf("TSO for GENEVE tunnel packet: ");
710 if (ports[port_id].tunnel_tso_segsz)
719 port_id_is_invalid(portid_t port_id, enum print_warning warning)
721 if (port_id == (portid_t)RTE_PORT_ALL)
724 if (rte_eth_dev_is_valid_port(port_id))
727 if (warning == ENABLED_WARN)
728 printf("Invalid port %d\n", port_id);
734 vlan_id_is_invalid(uint16_t vlan_id)
738 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
743 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
748 printf("Port register offset 0x%X not aligned on a 4-byte "
753 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
754 if (reg_off >= pci_len) {
755 printf("Port %d: register offset %u (0x%X) out of port PCI "
756 "resource (length=%"PRIu64")\n",
757 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
764 reg_bit_pos_is_invalid(uint8_t bit_pos)
768 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
772 #define display_port_and_reg_off(port_id, reg_off) \
773 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
776 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
778 display_port_and_reg_off(port_id, (unsigned)reg_off);
779 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
783 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
788 if (port_id_is_invalid(port_id, ENABLED_WARN))
790 if (port_reg_off_is_invalid(port_id, reg_off))
792 if (reg_bit_pos_is_invalid(bit_x))
794 reg_v = port_id_pci_reg_read(port_id, reg_off);
795 display_port_and_reg_off(port_id, (unsigned)reg_off);
796 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
800 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
801 uint8_t bit1_pos, uint8_t bit2_pos)
807 if (port_id_is_invalid(port_id, ENABLED_WARN))
809 if (port_reg_off_is_invalid(port_id, reg_off))
811 if (reg_bit_pos_is_invalid(bit1_pos))
813 if (reg_bit_pos_is_invalid(bit2_pos))
815 if (bit1_pos > bit2_pos)
816 l_bit = bit2_pos, h_bit = bit1_pos;
818 l_bit = bit1_pos, h_bit = bit2_pos;
820 reg_v = port_id_pci_reg_read(port_id, reg_off);
823 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
824 display_port_and_reg_off(port_id, (unsigned)reg_off);
825 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
826 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
830 port_reg_display(portid_t port_id, uint32_t reg_off)
834 if (port_id_is_invalid(port_id, ENABLED_WARN))
836 if (port_reg_off_is_invalid(port_id, reg_off))
838 reg_v = port_id_pci_reg_read(port_id, reg_off);
839 display_port_reg_value(port_id, reg_off, reg_v);
843 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
848 if (port_id_is_invalid(port_id, ENABLED_WARN))
850 if (port_reg_off_is_invalid(port_id, reg_off))
852 if (reg_bit_pos_is_invalid(bit_pos))
855 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
858 reg_v = port_id_pci_reg_read(port_id, reg_off);
860 reg_v &= ~(1 << bit_pos);
862 reg_v |= (1 << bit_pos);
863 port_id_pci_reg_write(port_id, reg_off, reg_v);
864 display_port_reg_value(port_id, reg_off, reg_v);
868 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
869 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
876 if (port_id_is_invalid(port_id, ENABLED_WARN))
878 if (port_reg_off_is_invalid(port_id, reg_off))
880 if (reg_bit_pos_is_invalid(bit1_pos))
882 if (reg_bit_pos_is_invalid(bit2_pos))
884 if (bit1_pos > bit2_pos)
885 l_bit = bit2_pos, h_bit = bit1_pos;
887 l_bit = bit1_pos, h_bit = bit2_pos;
889 if ((h_bit - l_bit) < 31)
890 max_v = (1 << (h_bit - l_bit + 1)) - 1;
895 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
896 (unsigned)value, (unsigned)value,
897 (unsigned)max_v, (unsigned)max_v);
900 reg_v = port_id_pci_reg_read(port_id, reg_off);
901 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
902 reg_v |= (value << l_bit); /* Set changed bits */
903 port_id_pci_reg_write(port_id, reg_off, reg_v);
904 display_port_reg_value(port_id, reg_off, reg_v);
908 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
910 if (port_id_is_invalid(port_id, ENABLED_WARN))
912 if (port_reg_off_is_invalid(port_id, reg_off))
914 port_id_pci_reg_write(port_id, reg_off, reg_v);
915 display_port_reg_value(port_id, reg_off, reg_v);
919 port_mtu_set(portid_t port_id, uint16_t mtu)
923 if (port_id_is_invalid(port_id, ENABLED_WARN))
925 diag = rte_eth_dev_set_mtu(port_id, mtu);
928 printf("Set MTU failed. diag=%d\n", diag);
931 /* Generic flow management functions. */
933 /** Generate flow_item[] entry. */
934 #define MK_FLOW_ITEM(t, s) \
935 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
940 /** Information about known flow pattern items. */
941 static const struct {
945 MK_FLOW_ITEM(END, 0),
946 MK_FLOW_ITEM(VOID, 0),
947 MK_FLOW_ITEM(INVERT, 0),
948 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
950 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
951 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
952 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
953 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
954 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
955 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
956 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
957 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
958 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
959 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
960 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
961 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
962 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
963 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
964 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
965 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
966 MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
967 MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
968 MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
969 MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
972 /** Compute storage space needed by item specification. */
974 flow_item_spec_size(const struct rte_flow_item *item,
975 size_t *size, size_t *pad)
981 switch (item->type) {
983 const struct rte_flow_item_raw *raw;
986 case RTE_FLOW_ITEM_TYPE_RAW:
987 spec.raw = item->spec;
988 *size = offsetof(struct rte_flow_item_raw, pattern) +
989 spec.raw->length * sizeof(*spec.raw->pattern);
992 *size = flow_item[item->type].size;
996 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
999 /** Generate flow_action[] entry. */
1000 #define MK_FLOW_ACTION(t, s) \
1001 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
1006 /** Information about known flow actions. */
1007 static const struct {
1011 MK_FLOW_ACTION(END, 0),
1012 MK_FLOW_ACTION(VOID, 0),
1013 MK_FLOW_ACTION(PASSTHRU, 0),
1014 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1015 MK_FLOW_ACTION(FLAG, 0),
1016 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
1017 MK_FLOW_ACTION(DROP, 0),
1018 MK_FLOW_ACTION(COUNT, 0),
1019 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
1020 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
1021 MK_FLOW_ACTION(PF, 0),
1022 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1025 /** Compute storage space needed by action configuration. */
1027 flow_action_conf_size(const struct rte_flow_action *action,
1028 size_t *size, size_t *pad)
1030 if (!action->conf) {
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);
1045 *size = flow_action[action->type].size;
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);
1439 /** Restrict ingress traffic to the defined flow rules. */
1441 port_flow_isolate(portid_t port_id, int set)
1443 struct rte_flow_error error;
1445 /* Poisoning to make sure PMDs update it in case of error. */
1446 memset(&error, 0x66, sizeof(error));
1447 if (rte_flow_isolate(port_id, set, &error))
1448 return port_flow_complain(&error);
1449 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1451 set ? "now restricted" : "not restricted anymore");
1456 * RX/TX ring descriptors display functions.
1459 rx_queue_id_is_invalid(queueid_t rxq_id)
1461 if (rxq_id < nb_rxq)
1463 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1468 tx_queue_id_is_invalid(queueid_t txq_id)
1470 if (txq_id < nb_txq)
1472 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1477 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1479 if (rxdesc_id < nb_rxd)
1481 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1487 tx_desc_id_is_invalid(uint16_t txdesc_id)
1489 if (txdesc_id < nb_txd)
1491 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1496 static const struct rte_memzone *
1497 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
1499 char mz_name[RTE_MEMZONE_NAMESIZE];
1500 const struct rte_memzone *mz;
1502 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1503 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1504 mz = rte_memzone_lookup(mz_name);
1506 printf("%s ring memory zoneof (port %d, queue %d) not"
1507 "found (zone name = %s\n",
1508 ring_name, port_id, q_id, mz_name);
1512 union igb_ring_dword {
1515 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1525 struct igb_ring_desc_32_bytes {
1526 union igb_ring_dword lo_dword;
1527 union igb_ring_dword hi_dword;
1528 union igb_ring_dword resv1;
1529 union igb_ring_dword resv2;
1532 struct igb_ring_desc_16_bytes {
1533 union igb_ring_dword lo_dword;
1534 union igb_ring_dword hi_dword;
1538 ring_rxd_display_dword(union igb_ring_dword dword)
1540 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1541 (unsigned)dword.words.hi);
1545 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1546 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1549 __rte_unused uint8_t port_id,
1553 struct igb_ring_desc_16_bytes *ring =
1554 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1555 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1556 struct rte_eth_dev_info dev_info;
1558 memset(&dev_info, 0, sizeof(dev_info));
1559 rte_eth_dev_info_get(port_id, &dev_info);
1560 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1561 /* 32 bytes RX descriptor, i40e only */
1562 struct igb_ring_desc_32_bytes *ring =
1563 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1564 ring[desc_id].lo_dword.dword =
1565 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1566 ring_rxd_display_dword(ring[desc_id].lo_dword);
1567 ring[desc_id].hi_dword.dword =
1568 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1569 ring_rxd_display_dword(ring[desc_id].hi_dword);
1570 ring[desc_id].resv1.dword =
1571 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1572 ring_rxd_display_dword(ring[desc_id].resv1);
1573 ring[desc_id].resv2.dword =
1574 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1575 ring_rxd_display_dword(ring[desc_id].resv2);
1580 /* 16 bytes RX descriptor */
1581 ring[desc_id].lo_dword.dword =
1582 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1583 ring_rxd_display_dword(ring[desc_id].lo_dword);
1584 ring[desc_id].hi_dword.dword =
1585 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1586 ring_rxd_display_dword(ring[desc_id].hi_dword);
1590 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1592 struct igb_ring_desc_16_bytes *ring;
1593 struct igb_ring_desc_16_bytes txd;
1595 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1596 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1597 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1598 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1599 (unsigned)txd.lo_dword.words.lo,
1600 (unsigned)txd.lo_dword.words.hi,
1601 (unsigned)txd.hi_dword.words.lo,
1602 (unsigned)txd.hi_dword.words.hi);
1606 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1608 const struct rte_memzone *rx_mz;
1610 if (port_id_is_invalid(port_id, ENABLED_WARN))
1612 if (rx_queue_id_is_invalid(rxq_id))
1614 if (rx_desc_id_is_invalid(rxd_id))
1616 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1619 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1623 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1625 const struct rte_memzone *tx_mz;
1627 if (port_id_is_invalid(port_id, ENABLED_WARN))
1629 if (tx_queue_id_is_invalid(txq_id))
1631 if (tx_desc_id_is_invalid(txd_id))
1633 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1636 ring_tx_descriptor_display(tx_mz, txd_id);
1640 fwd_lcores_config_display(void)
1644 printf("List of forwarding lcores:");
1645 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1646 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1650 rxtx_config_display(void)
1652 printf(" %s packet forwarding%s - CRC stripping %s - "
1653 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
1654 retry_enabled == 0 ? "" : " with retry",
1655 rx_mode.hw_strip_crc ? "enabled" : "disabled",
1658 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1659 printf(" packet len=%u - nb packet segments=%d\n",
1660 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1662 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
1663 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
1665 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1666 nb_fwd_lcores, nb_fwd_ports);
1667 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1668 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1669 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1670 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
1671 rx_conf->rx_thresh.wthresh);
1672 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1673 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1674 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1675 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
1676 tx_conf->tx_thresh.wthresh);
1677 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
1678 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
1682 port_rss_reta_info(portid_t port_id,
1683 struct rte_eth_rss_reta_entry64 *reta_conf,
1684 uint16_t nb_entries)
1686 uint16_t i, idx, shift;
1689 if (port_id_is_invalid(port_id, ENABLED_WARN))
1692 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1694 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1698 for (i = 0; i < nb_entries; i++) {
1699 idx = i / RTE_RETA_GROUP_SIZE;
1700 shift = i % RTE_RETA_GROUP_SIZE;
1701 if (!(reta_conf[idx].mask & (1ULL << shift)))
1703 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1704 i, reta_conf[idx].reta[shift]);
1709 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1713 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1715 struct rte_eth_rss_conf rss_conf;
1716 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1720 struct rte_eth_dev_info dev_info;
1721 uint8_t hash_key_size;
1723 if (port_id_is_invalid(port_id, ENABLED_WARN))
1726 memset(&dev_info, 0, sizeof(dev_info));
1727 rte_eth_dev_info_get(port_id, &dev_info);
1728 if (dev_info.hash_key_size > 0 &&
1729 dev_info.hash_key_size <= sizeof(rss_key))
1730 hash_key_size = dev_info.hash_key_size;
1732 printf("dev_info did not provide a valid hash key size\n");
1736 rss_conf.rss_hf = 0;
1737 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1738 if (!strcmp(rss_info, rss_type_table[i].str))
1739 rss_conf.rss_hf = rss_type_table[i].rss_type;
1742 /* Get RSS hash key if asked to display it */
1743 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1744 rss_conf.rss_key_len = hash_key_size;
1745 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1749 printf("port index %d invalid\n", port_id);
1752 printf("operation not supported by device\n");
1755 printf("operation failed - diag=%d\n", diag);
1760 rss_hf = rss_conf.rss_hf;
1762 printf("RSS disabled\n");
1765 printf("RSS functions:\n ");
1766 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1767 if (rss_hf & rss_type_table[i].rss_type)
1768 printf("%s ", rss_type_table[i].str);
1773 printf("RSS key:\n");
1774 for (i = 0; i < hash_key_size; i++)
1775 printf("%02X", rss_key[i]);
1780 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1783 struct rte_eth_rss_conf rss_conf;
1787 rss_conf.rss_key = NULL;
1788 rss_conf.rss_key_len = hash_key_len;
1789 rss_conf.rss_hf = 0;
1790 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1791 if (!strcmp(rss_type_table[i].str, rss_type))
1792 rss_conf.rss_hf = rss_type_table[i].rss_type;
1794 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1796 rss_conf.rss_key = hash_key;
1797 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1804 printf("port index %d invalid\n", port_id);
1807 printf("operation not supported by device\n");
1810 printf("operation failed - diag=%d\n", diag);
1816 * Setup forwarding configuration for each logical core.
1819 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1821 streamid_t nb_fs_per_lcore;
1829 nb_fs = cfg->nb_fwd_streams;
1830 nb_fc = cfg->nb_fwd_lcores;
1831 if (nb_fs <= nb_fc) {
1832 nb_fs_per_lcore = 1;
1835 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1836 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1839 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1841 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1842 fwd_lcores[lc_id]->stream_idx = sm_id;
1843 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1844 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1848 * Assign extra remaining streams, if any.
1850 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1851 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1852 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1853 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1854 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1859 simple_fwd_config_setup(void)
1865 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1866 port_topology == PORT_TOPOLOGY_LOOP) {
1868 } else if (nb_fwd_ports % 2) {
1869 printf("\nWarning! Cannot handle an odd number of ports "
1870 "with the current port topology. Configuration "
1871 "must be changed to have an even number of ports, "
1872 "or relaunch application with "
1873 "--port-topology=chained\n\n");
1876 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1877 cur_fwd_config.nb_fwd_streams =
1878 (streamid_t) cur_fwd_config.nb_fwd_ports;
1880 /* reinitialize forwarding streams */
1884 * In the simple forwarding test, the number of forwarding cores
1885 * must be lower or equal to the number of forwarding ports.
1887 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1888 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1889 cur_fwd_config.nb_fwd_lcores =
1890 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1891 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1893 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1894 if (port_topology != PORT_TOPOLOGY_LOOP)
1895 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1898 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1899 fwd_streams[i]->rx_queue = 0;
1900 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1901 fwd_streams[i]->tx_queue = 0;
1902 fwd_streams[i]->peer_addr = j;
1903 fwd_streams[i]->retry_enabled = retry_enabled;
1905 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1906 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1907 fwd_streams[j]->rx_queue = 0;
1908 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1909 fwd_streams[j]->tx_queue = 0;
1910 fwd_streams[j]->peer_addr = i;
1911 fwd_streams[j]->retry_enabled = retry_enabled;
1917 * For the RSS forwarding test all streams distributed over lcores. Each stream
1918 * being composed of a RX queue to poll on a RX port for input messages,
1919 * associated with a TX queue of a TX port where to send forwarded packets.
1920 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1921 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1923 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1927 rss_fwd_config_setup(void)
1938 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1939 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1940 cur_fwd_config.nb_fwd_streams =
1941 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1943 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1944 cur_fwd_config.nb_fwd_lcores =
1945 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1947 /* reinitialize forwarding streams */
1950 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1952 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1953 struct fwd_stream *fs;
1955 fs = fwd_streams[sm_id];
1957 if ((rxp & 0x1) == 0)
1958 txp = (portid_t) (rxp + 1);
1960 txp = (portid_t) (rxp - 1);
1962 * if we are in loopback, simply send stuff out through the
1965 if (port_topology == PORT_TOPOLOGY_LOOP)
1968 fs->rx_port = fwd_ports_ids[rxp];
1970 fs->tx_port = fwd_ports_ids[txp];
1972 fs->peer_addr = fs->tx_port;
1973 fs->retry_enabled = retry_enabled;
1974 rxq = (queueid_t) (rxq + 1);
1979 * Restart from RX queue 0 on next RX port
1982 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1984 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1986 rxp = (portid_t) (rxp + 1);
1991 * For the DCB forwarding test, each core is assigned on each traffic class.
1993 * Each core is assigned a multi-stream, each stream being composed of
1994 * a RX queue to poll on a RX port for input messages, associated with
1995 * a TX queue of a TX port where to send forwarded packets. All RX and
1996 * TX queues are mapping to the same traffic class.
1997 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
2001 dcb_fwd_config_setup(void)
2003 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
2004 portid_t txp, rxp = 0;
2005 queueid_t txq, rxq = 0;
2007 uint16_t nb_rx_queue, nb_tx_queue;
2008 uint16_t i, j, k, sm_id = 0;
2011 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2012 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2013 cur_fwd_config.nb_fwd_streams =
2014 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2016 /* reinitialize forwarding streams */
2020 /* get the dcb info on the first RX and TX ports */
2021 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2022 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2024 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2025 fwd_lcores[lc_id]->stream_nb = 0;
2026 fwd_lcores[lc_id]->stream_idx = sm_id;
2027 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2028 /* if the nb_queue is zero, means this tc is
2029 * not enabled on the POOL
2031 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2033 k = fwd_lcores[lc_id]->stream_nb +
2034 fwd_lcores[lc_id]->stream_idx;
2035 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2036 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2037 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2038 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2039 for (j = 0; j < nb_rx_queue; j++) {
2040 struct fwd_stream *fs;
2042 fs = fwd_streams[k + j];
2043 fs->rx_port = fwd_ports_ids[rxp];
2044 fs->rx_queue = rxq + j;
2045 fs->tx_port = fwd_ports_ids[txp];
2046 fs->tx_queue = txq + j % nb_tx_queue;
2047 fs->peer_addr = fs->tx_port;
2048 fs->retry_enabled = retry_enabled;
2050 fwd_lcores[lc_id]->stream_nb +=
2051 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2053 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2056 if (tc < rxp_dcb_info.nb_tcs)
2058 /* Restart from TC 0 on next RX port */
2060 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2062 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2065 if (rxp >= nb_fwd_ports)
2067 /* get the dcb information on next RX and TX ports */
2068 if ((rxp & 0x1) == 0)
2069 txp = (portid_t) (rxp + 1);
2071 txp = (portid_t) (rxp - 1);
2072 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2073 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2078 icmp_echo_config_setup(void)
2085 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2086 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2087 (nb_txq * nb_fwd_ports);
2089 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2090 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2091 cur_fwd_config.nb_fwd_streams =
2092 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2093 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2094 cur_fwd_config.nb_fwd_lcores =
2095 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2096 if (verbose_level > 0) {
2097 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2099 cur_fwd_config.nb_fwd_lcores,
2100 cur_fwd_config.nb_fwd_ports,
2101 cur_fwd_config.nb_fwd_streams);
2104 /* reinitialize forwarding streams */
2106 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2108 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2109 if (verbose_level > 0)
2110 printf(" core=%d: \n", lc_id);
2111 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2112 struct fwd_stream *fs;
2113 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2114 fs->rx_port = fwd_ports_ids[rxp];
2116 fs->tx_port = fs->rx_port;
2118 fs->peer_addr = fs->tx_port;
2119 fs->retry_enabled = retry_enabled;
2120 if (verbose_level > 0)
2121 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2122 sm_id, fs->rx_port, fs->rx_queue,
2124 rxq = (queueid_t) (rxq + 1);
2125 if (rxq == nb_rxq) {
2127 rxp = (portid_t) (rxp + 1);
2134 fwd_config_setup(void)
2136 cur_fwd_config.fwd_eng = cur_fwd_eng;
2137 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2138 icmp_echo_config_setup();
2141 if ((nb_rxq > 1) && (nb_txq > 1)){
2143 dcb_fwd_config_setup();
2145 rss_fwd_config_setup();
2148 simple_fwd_config_setup();
2152 pkt_fwd_config_display(struct fwd_config *cfg)
2154 struct fwd_stream *fs;
2158 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2159 "NUMA support %s, MP over anonymous pages %s\n",
2160 cfg->fwd_eng->fwd_mode_name,
2161 retry_enabled == 0 ? "" : " with retry",
2162 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2163 numa_support == 1 ? "enabled" : "disabled",
2164 mp_anon != 0 ? "enabled" : "disabled");
2167 printf("TX retry num: %u, delay between TX retries: %uus\n",
2168 burst_tx_retry_num, burst_tx_delay_time);
2169 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2170 printf("Logical Core %u (socket %u) forwards packets on "
2172 fwd_lcores_cpuids[lc_id],
2173 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2174 fwd_lcores[lc_id]->stream_nb);
2175 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2176 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2177 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2178 "P=%d/Q=%d (socket %u) ",
2179 fs->rx_port, fs->rx_queue,
2180 ports[fs->rx_port].socket_id,
2181 fs->tx_port, fs->tx_queue,
2182 ports[fs->tx_port].socket_id);
2183 print_ethaddr("peer=",
2184 &peer_eth_addrs[fs->peer_addr]);
2192 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2195 unsigned int lcore_cpuid;
2200 for (i = 0; i < nb_lc; i++) {
2201 lcore_cpuid = lcorelist[i];
2202 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2203 printf("lcore %u not enabled\n", lcore_cpuid);
2206 if (lcore_cpuid == rte_get_master_lcore()) {
2207 printf("lcore %u cannot be masked on for running "
2208 "packet forwarding, which is the master lcore "
2209 "and reserved for command line parsing only\n",
2214 fwd_lcores_cpuids[i] = lcore_cpuid;
2216 if (record_now == 0) {
2220 nb_cfg_lcores = (lcoreid_t) nb_lc;
2221 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2222 printf("previous number of forwarding cores %u - changed to "
2223 "number of configured cores %u\n",
2224 (unsigned int) nb_fwd_lcores, nb_lc);
2225 nb_fwd_lcores = (lcoreid_t) nb_lc;
2232 set_fwd_lcores_mask(uint64_t lcoremask)
2234 unsigned int lcorelist[64];
2238 if (lcoremask == 0) {
2239 printf("Invalid NULL mask of cores\n");
2243 for (i = 0; i < 64; i++) {
2244 if (! ((uint64_t)(1ULL << i) & lcoremask))
2246 lcorelist[nb_lc++] = i;
2248 return set_fwd_lcores_list(lcorelist, nb_lc);
2252 set_fwd_lcores_number(uint16_t nb_lc)
2254 if (nb_lc > nb_cfg_lcores) {
2255 printf("nb fwd cores %u > %u (max. number of configured "
2256 "lcores) - ignored\n",
2257 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2260 nb_fwd_lcores = (lcoreid_t) nb_lc;
2261 printf("Number of forwarding cores set to %u\n",
2262 (unsigned int) nb_fwd_lcores);
2266 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2274 for (i = 0; i < nb_pt; i++) {
2275 port_id = (portid_t) portlist[i];
2276 if (port_id_is_invalid(port_id, ENABLED_WARN))
2279 fwd_ports_ids[i] = port_id;
2281 if (record_now == 0) {
2285 nb_cfg_ports = (portid_t) nb_pt;
2286 if (nb_fwd_ports != (portid_t) nb_pt) {
2287 printf("previous number of forwarding ports %u - changed to "
2288 "number of configured ports %u\n",
2289 (unsigned int) nb_fwd_ports, nb_pt);
2290 nb_fwd_ports = (portid_t) nb_pt;
2295 set_fwd_ports_mask(uint64_t portmask)
2297 unsigned int portlist[64];
2301 if (portmask == 0) {
2302 printf("Invalid NULL mask of ports\n");
2306 RTE_ETH_FOREACH_DEV(i) {
2307 if (! ((uint64_t)(1ULL << i) & portmask))
2309 portlist[nb_pt++] = i;
2311 set_fwd_ports_list(portlist, nb_pt);
2315 set_fwd_ports_number(uint16_t nb_pt)
2317 if (nb_pt > nb_cfg_ports) {
2318 printf("nb fwd ports %u > %u (number of configured "
2319 "ports) - ignored\n",
2320 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2323 nb_fwd_ports = (portid_t) nb_pt;
2324 printf("Number of forwarding ports set to %u\n",
2325 (unsigned int) nb_fwd_ports);
2329 port_is_forwarding(portid_t port_id)
2333 if (port_id_is_invalid(port_id, ENABLED_WARN))
2336 for (i = 0; i < nb_fwd_ports; i++) {
2337 if (fwd_ports_ids[i] == port_id)
2345 set_nb_pkt_per_burst(uint16_t nb)
2347 if (nb > MAX_PKT_BURST) {
2348 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2350 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2353 nb_pkt_per_burst = nb;
2354 printf("Number of packets per burst set to %u\n",
2355 (unsigned int) nb_pkt_per_burst);
2359 tx_split_get_name(enum tx_pkt_split split)
2363 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2364 if (tx_split_name[i].split == split)
2365 return tx_split_name[i].name;
2371 set_tx_pkt_split(const char *name)
2375 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2376 if (strcmp(tx_split_name[i].name, name) == 0) {
2377 tx_pkt_split = tx_split_name[i].split;
2381 printf("unknown value: \"%s\"\n", name);
2385 show_tx_pkt_segments(void)
2391 split = tx_split_get_name(tx_pkt_split);
2393 printf("Number of segments: %u\n", n);
2394 printf("Segment sizes: ");
2395 for (i = 0; i != n - 1; i++)
2396 printf("%hu,", tx_pkt_seg_lengths[i]);
2397 printf("%hu\n", tx_pkt_seg_lengths[i]);
2398 printf("Split packet: %s\n", split);
2402 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2404 uint16_t tx_pkt_len;
2407 if (nb_segs >= (unsigned) nb_txd) {
2408 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2409 nb_segs, (unsigned int) nb_txd);
2414 * Check that each segment length is greater or equal than
2415 * the mbuf data sise.
2416 * Check also that the total packet length is greater or equal than the
2417 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2420 for (i = 0; i < nb_segs; i++) {
2421 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2422 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2423 i, seg_lengths[i], (unsigned) mbuf_data_size);
2426 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2428 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2429 printf("total packet length=%u < %d - give up\n",
2430 (unsigned) tx_pkt_len,
2431 (int)(sizeof(struct ether_hdr) + 20 + 8));
2435 for (i = 0; i < nb_segs; i++)
2436 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2438 tx_pkt_length = tx_pkt_len;
2439 tx_pkt_nb_segs = (uint8_t) nb_segs;
2443 setup_gro(const char *onoff, portid_t port_id)
2445 if (!rte_eth_dev_is_valid_port(port_id)) {
2446 printf("invalid port id %u\n", port_id);
2449 if (test_done == 0) {
2450 printf("Before enable/disable GRO,"
2451 " please stop forwarding first\n");
2454 if (strcmp(onoff, "on") == 0) {
2455 if (gro_ports[port_id].enable != 0) {
2456 printf("Port %u has enabled GRO. Please"
2457 " disable GRO first\n", port_id);
2460 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2461 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2462 gro_ports[port_id].param.max_flow_num =
2463 GRO_DEFAULT_FLOW_NUM;
2464 gro_ports[port_id].param.max_item_per_flow =
2465 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2467 gro_ports[port_id].enable = 1;
2469 if (gro_ports[port_id].enable == 0) {
2470 printf("Port %u has disabled GRO\n", port_id);
2473 gro_ports[port_id].enable = 0;
2478 setup_gro_flush_cycles(uint8_t cycles)
2480 if (test_done == 0) {
2481 printf("Before change flush interval for GRO,"
2482 " please stop forwarding first.\n");
2486 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
2487 GRO_DEFAULT_FLUSH_CYCLES) {
2488 printf("The flushing cycle be in the range"
2489 " of 1 to %u. Revert to the default"
2491 GRO_MAX_FLUSH_CYCLES,
2492 GRO_DEFAULT_FLUSH_CYCLES);
2493 cycles = GRO_DEFAULT_FLUSH_CYCLES;
2496 gro_flush_cycles = cycles;
2500 show_gro(portid_t port_id)
2502 struct rte_gro_param *param;
2503 uint32_t max_pkts_num;
2505 param = &gro_ports[port_id].param;
2507 if (!rte_eth_dev_is_valid_port(port_id)) {
2508 printf("Invalid port id %u.\n", port_id);
2511 if (gro_ports[port_id].enable) {
2512 printf("GRO type: TCP/IPv4\n");
2513 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
2514 max_pkts_num = param->max_flow_num *
2515 param->max_item_per_flow;
2517 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
2518 printf("Max number of packets to perform GRO: %u\n",
2520 printf("Flushing cycles: %u\n", gro_flush_cycles);
2522 printf("Port %u doesn't enable GRO.\n", port_id);
2526 setup_gso(const char *mode, portid_t port_id)
2528 if (!rte_eth_dev_is_valid_port(port_id)) {
2529 printf("invalid port id %u\n", port_id);
2532 if (strcmp(mode, "on") == 0) {
2533 if (test_done == 0) {
2534 printf("before enabling GSO,"
2535 " please stop forwarding first\n");
2538 gso_ports[port_id].enable = 1;
2539 } else if (strcmp(mode, "off") == 0) {
2540 if (test_done == 0) {
2541 printf("before disabling GSO,"
2542 " please stop forwarding first\n");
2545 gso_ports[port_id].enable = 0;
2550 list_pkt_forwarding_modes(void)
2552 static char fwd_modes[128] = "";
2553 const char *separator = "|";
2554 struct fwd_engine *fwd_eng;
2557 if (strlen (fwd_modes) == 0) {
2558 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2559 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2560 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2561 strncat(fwd_modes, separator,
2562 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2564 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2571 list_pkt_forwarding_retry_modes(void)
2573 static char fwd_modes[128] = "";
2574 const char *separator = "|";
2575 struct fwd_engine *fwd_eng;
2578 if (strlen(fwd_modes) == 0) {
2579 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2580 if (fwd_eng == &rx_only_engine)
2582 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2584 strlen(fwd_modes) - 1);
2585 strncat(fwd_modes, separator,
2587 strlen(fwd_modes) - 1);
2589 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2596 set_pkt_forwarding_mode(const char *fwd_mode_name)
2598 struct fwd_engine *fwd_eng;
2602 while ((fwd_eng = fwd_engines[i]) != NULL) {
2603 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2604 printf("Set %s packet forwarding mode%s\n",
2606 retry_enabled == 0 ? "" : " with retry");
2607 cur_fwd_eng = fwd_eng;
2612 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2616 set_verbose_level(uint16_t vb_level)
2618 printf("Change verbose level from %u to %u\n",
2619 (unsigned int) verbose_level, (unsigned int) vb_level);
2620 verbose_level = vb_level;
2624 vlan_extend_set(portid_t port_id, int on)
2629 if (port_id_is_invalid(port_id, ENABLED_WARN))
2632 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2635 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2637 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2639 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2641 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2642 "diag=%d\n", port_id, on, diag);
2646 rx_vlan_strip_set(portid_t port_id, int on)
2651 if (port_id_is_invalid(port_id, ENABLED_WARN))
2654 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2657 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2659 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2661 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2663 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2664 "diag=%d\n", port_id, on, diag);
2668 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2672 if (port_id_is_invalid(port_id, ENABLED_WARN))
2675 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2677 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2678 "diag=%d\n", port_id, queue_id, on, diag);
2682 rx_vlan_filter_set(portid_t port_id, int on)
2687 if (port_id_is_invalid(port_id, ENABLED_WARN))
2690 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2693 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2695 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2697 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2699 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2700 "diag=%d\n", port_id, on, diag);
2704 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2708 if (port_id_is_invalid(port_id, ENABLED_WARN))
2710 if (vlan_id_is_invalid(vlan_id))
2712 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2715 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2717 port_id, vlan_id, on, diag);
2722 rx_vlan_all_filter_set(portid_t port_id, int on)
2726 if (port_id_is_invalid(port_id, ENABLED_WARN))
2728 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2729 if (rx_vft_set(port_id, vlan_id, on))
2735 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2739 if (port_id_is_invalid(port_id, ENABLED_WARN))
2742 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2746 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2748 port_id, vlan_type, tp_id, diag);
2752 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2755 if (port_id_is_invalid(port_id, ENABLED_WARN))
2757 if (vlan_id_is_invalid(vlan_id))
2760 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2761 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2762 printf("Error, as QinQ has been enabled.\n");
2766 tx_vlan_reset(port_id);
2767 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
2768 ports[port_id].tx_vlan_id = vlan_id;
2772 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2775 if (port_id_is_invalid(port_id, ENABLED_WARN))
2777 if (vlan_id_is_invalid(vlan_id))
2779 if (vlan_id_is_invalid(vlan_id_outer))
2782 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2783 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2784 printf("Error, as QinQ hasn't been enabled.\n");
2788 tx_vlan_reset(port_id);
2789 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
2790 ports[port_id].tx_vlan_id = vlan_id;
2791 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2795 tx_vlan_reset(portid_t port_id)
2797 if (port_id_is_invalid(port_id, ENABLED_WARN))
2799 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
2800 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
2801 ports[port_id].tx_vlan_id = 0;
2802 ports[port_id].tx_vlan_id_outer = 0;
2806 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2808 if (port_id_is_invalid(port_id, ENABLED_WARN))
2811 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2815 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2818 uint8_t existing_mapping_found = 0;
2820 if (port_id_is_invalid(port_id, ENABLED_WARN))
2823 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2826 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2827 printf("map_value not in required range 0..%d\n",
2828 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2832 if (!is_rx) { /*then tx*/
2833 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2834 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2835 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2836 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2837 existing_mapping_found = 1;
2841 if (!existing_mapping_found) { /* A new additional mapping... */
2842 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2843 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2844 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2845 nb_tx_queue_stats_mappings++;
2849 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2850 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2851 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2852 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2853 existing_mapping_found = 1;
2857 if (!existing_mapping_found) { /* A new additional mapping... */
2858 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2859 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2860 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2861 nb_rx_queue_stats_mappings++;
2867 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2869 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2871 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2872 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2873 " tunnel_id: 0x%08x",
2874 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2875 rte_be_to_cpu_32(mask->tunnel_id_mask));
2876 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2877 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2878 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2879 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2881 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2882 rte_be_to_cpu_16(mask->src_port_mask),
2883 rte_be_to_cpu_16(mask->dst_port_mask));
2885 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2886 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2887 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
2888 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
2889 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
2891 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2892 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
2893 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
2894 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
2895 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
2902 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2904 struct rte_eth_flex_payload_cfg *cfg;
2907 for (i = 0; i < flex_conf->nb_payloads; i++) {
2908 cfg = &flex_conf->flex_set[i];
2909 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2911 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2912 printf("\n L2_PAYLOAD: ");
2913 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2914 printf("\n L3_PAYLOAD: ");
2915 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2916 printf("\n L4_PAYLOAD: ");
2918 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2919 for (j = 0; j < num; j++)
2920 printf(" %-5u", cfg->src_offset[j]);
2926 flowtype_to_str(uint16_t flow_type)
2928 struct flow_type_info {
2934 static struct flow_type_info flowtype_str_table[] = {
2935 {"raw", RTE_ETH_FLOW_RAW},
2936 {"ipv4", RTE_ETH_FLOW_IPV4},
2937 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2938 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2939 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2940 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2941 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2942 {"ipv6", RTE_ETH_FLOW_IPV6},
2943 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2944 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2945 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2946 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2947 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2948 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2949 {"port", RTE_ETH_FLOW_PORT},
2950 {"vxlan", RTE_ETH_FLOW_VXLAN},
2951 {"geneve", RTE_ETH_FLOW_GENEVE},
2952 {"nvgre", RTE_ETH_FLOW_NVGRE},
2955 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2956 if (flowtype_str_table[i].ftype == flow_type)
2957 return flowtype_str_table[i].str;
2964 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2966 struct rte_eth_fdir_flex_mask *mask;
2970 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2971 mask = &flex_conf->flex_mask[i];
2972 p = flowtype_to_str(mask->flow_type);
2973 printf("\n %s:\t", p ? p : "unknown");
2974 for (j = 0; j < num; j++)
2975 printf(" %02x", mask->mask[j]);
2981 print_fdir_flow_type(uint32_t flow_types_mask)
2986 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2987 if (!(flow_types_mask & (1 << i)))
2989 p = flowtype_to_str(i);
2999 fdir_get_infos(portid_t port_id)
3001 struct rte_eth_fdir_stats fdir_stat;
3002 struct rte_eth_fdir_info fdir_info;
3005 static const char *fdir_stats_border = "########################";
3007 if (port_id_is_invalid(port_id, ENABLED_WARN))
3009 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
3011 printf("\n FDIR is not supported on port %-2d\n",
3016 memset(&fdir_info, 0, sizeof(fdir_info));
3017 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3018 RTE_ETH_FILTER_INFO, &fdir_info);
3019 memset(&fdir_stat, 0, sizeof(fdir_stat));
3020 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
3021 RTE_ETH_FILTER_STATS, &fdir_stat);
3022 printf("\n %s FDIR infos for port %-2d %s\n",
3023 fdir_stats_border, port_id, fdir_stats_border);
3025 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
3026 printf(" PERFECT\n");
3027 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
3028 printf(" PERFECT-MAC-VLAN\n");
3029 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3030 printf(" PERFECT-TUNNEL\n");
3031 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
3032 printf(" SIGNATURE\n");
3034 printf(" DISABLE\n");
3035 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
3036 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
3037 printf(" SUPPORTED FLOW TYPE: ");
3038 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
3040 printf(" FLEX PAYLOAD INFO:\n");
3041 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
3042 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
3043 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
3044 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
3045 fdir_info.flex_payload_unit,
3046 fdir_info.max_flex_payload_segment_num,
3047 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
3049 print_fdir_mask(&fdir_info.mask);
3050 if (fdir_info.flex_conf.nb_payloads > 0) {
3051 printf(" FLEX PAYLOAD SRC OFFSET:");
3052 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3054 if (fdir_info.flex_conf.nb_flexmasks > 0) {
3055 printf(" FLEX MASK CFG:");
3056 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
3058 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
3059 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
3060 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
3061 fdir_info.guarant_spc, fdir_info.best_spc);
3062 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
3063 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
3064 " add: %-10"PRIu64" remove: %"PRIu64"\n"
3065 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
3066 fdir_stat.collision, fdir_stat.free,
3067 fdir_stat.maxhash, fdir_stat.maxlen,
3068 fdir_stat.add, fdir_stat.remove,
3069 fdir_stat.f_add, fdir_stat.f_remove);
3070 printf(" %s############################%s\n",
3071 fdir_stats_border, fdir_stats_border);
3075 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
3077 struct rte_port *port;
3078 struct rte_eth_fdir_flex_conf *flex_conf;
3081 port = &ports[port_id];
3082 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3083 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
3084 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
3089 if (i >= RTE_ETH_FLOW_MAX) {
3090 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3091 idx = flex_conf->nb_flexmasks;
3092 flex_conf->nb_flexmasks++;
3094 printf("The flex mask table is full. Can not set flex"
3095 " mask for flow_type(%u).", cfg->flow_type);
3099 rte_memcpy(&flex_conf->flex_mask[idx],
3101 sizeof(struct rte_eth_fdir_flex_mask));
3105 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3107 struct rte_port *port;
3108 struct rte_eth_fdir_flex_conf *flex_conf;
3111 port = &ports[port_id];
3112 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3113 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3114 if (cfg->type == flex_conf->flex_set[i].type) {
3119 if (i >= RTE_ETH_PAYLOAD_MAX) {
3120 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3121 idx = flex_conf->nb_payloads;
3122 flex_conf->nb_payloads++;
3124 printf("The flex payload table is full. Can not set"
3125 " flex payload for type(%u).", cfg->type);
3129 rte_memcpy(&flex_conf->flex_set[idx],
3131 sizeof(struct rte_eth_flex_payload_cfg));
3136 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3138 #ifdef RTE_LIBRTE_IXGBE_PMD
3142 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3144 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3148 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3149 is_rx ? "rx" : "tx", port_id, diag);
3152 printf("VF %s setting not supported for port %d\n",
3153 is_rx ? "Rx" : "Tx", port_id);
3159 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3162 struct rte_eth_link link;
3164 if (port_id_is_invalid(port_id, ENABLED_WARN))
3166 rte_eth_link_get_nowait(port_id, &link);
3167 if (rate > link.link_speed) {
3168 printf("Invalid rate value:%u bigger than link speed: %u\n",
3169 rate, link.link_speed);
3172 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3175 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3181 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3183 int diag = -ENOTSUP;
3185 #ifdef RTE_LIBRTE_IXGBE_PMD
3186 if (diag == -ENOTSUP)
3187 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3190 #ifdef RTE_LIBRTE_BNXT_PMD
3191 if (diag == -ENOTSUP)
3192 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3197 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3203 * Functions to manage the set of filtered Multicast MAC addresses.
3205 * A pool of filtered multicast MAC addresses is associated with each port.
3206 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3207 * The address of the pool and the number of valid multicast MAC addresses
3208 * recorded in the pool are stored in the fields "mc_addr_pool" and
3209 * "mc_addr_nb" of the "rte_port" data structure.
3211 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3212 * to be supplied a contiguous array of multicast MAC addresses.
3213 * To comply with this constraint, the set of multicast addresses recorded
3214 * into the pool are systematically compacted at the beginning of the pool.
3215 * Hence, when a multicast address is removed from the pool, all following
3216 * addresses, if any, are copied back to keep the set contiguous.
3218 #define MCAST_POOL_INC 32
3221 mcast_addr_pool_extend(struct rte_port *port)
3223 struct ether_addr *mc_pool;
3224 size_t mc_pool_size;
3227 * If a free entry is available at the end of the pool, just
3228 * increment the number of recorded multicast addresses.
3230 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3236 * [re]allocate a pool with MCAST_POOL_INC more entries.
3237 * The previous test guarantees that port->mc_addr_nb is a multiple
3238 * of MCAST_POOL_INC.
3240 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3242 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3244 if (mc_pool == NULL) {
3245 printf("allocation of pool of %u multicast addresses failed\n",
3246 port->mc_addr_nb + MCAST_POOL_INC);
3250 port->mc_addr_pool = mc_pool;
3257 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3260 if (addr_idx == port->mc_addr_nb) {
3261 /* No need to recompact the set of multicast addressses. */
3262 if (port->mc_addr_nb == 0) {
3263 /* free the pool of multicast addresses. */
3264 free(port->mc_addr_pool);
3265 port->mc_addr_pool = NULL;
3269 memmove(&port->mc_addr_pool[addr_idx],
3270 &port->mc_addr_pool[addr_idx + 1],
3271 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3275 eth_port_multicast_addr_list_set(uint8_t port_id)
3277 struct rte_port *port;
3280 port = &ports[port_id];
3281 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3285 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3286 port->mc_addr_nb, port_id, -diag);
3290 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
3292 struct rte_port *port;
3295 if (port_id_is_invalid(port_id, ENABLED_WARN))
3298 port = &ports[port_id];
3301 * Check that the added multicast MAC address is not already recorded
3302 * in the pool of multicast addresses.
3304 for (i = 0; i < port->mc_addr_nb; i++) {
3305 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3306 printf("multicast address already filtered by port\n");
3311 if (mcast_addr_pool_extend(port) != 0)
3313 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3314 eth_port_multicast_addr_list_set(port_id);
3318 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
3320 struct rte_port *port;
3323 if (port_id_is_invalid(port_id, ENABLED_WARN))
3326 port = &ports[port_id];
3329 * Search the pool of multicast MAC addresses for the removed address.
3331 for (i = 0; i < port->mc_addr_nb; i++) {
3332 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3335 if (i == port->mc_addr_nb) {
3336 printf("multicast address not filtered by port %d\n", port_id);
3340 mcast_addr_pool_remove(port, i);
3341 eth_port_multicast_addr_list_set(port_id);
3345 port_dcb_info_display(uint8_t port_id)
3347 struct rte_eth_dcb_info dcb_info;
3350 static const char *border = "================";
3352 if (port_id_is_invalid(port_id, ENABLED_WARN))
3355 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3357 printf("\n Failed to get dcb infos on port %-2d\n",
3361 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3362 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3364 for (i = 0; i < dcb_info.nb_tcs; i++)
3366 printf("\n Priority : ");
3367 for (i = 0; i < dcb_info.nb_tcs; i++)
3368 printf("\t%4d", dcb_info.prio_tc[i]);
3369 printf("\n BW percent :");
3370 for (i = 0; i < dcb_info.nb_tcs; i++)
3371 printf("\t%4d%%", dcb_info.tc_bws[i]);
3372 printf("\n RXQ base : ");
3373 for (i = 0; i < dcb_info.nb_tcs; i++)
3374 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3375 printf("\n RXQ number :");
3376 for (i = 0; i < dcb_info.nb_tcs; i++)
3377 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3378 printf("\n TXQ base : ");
3379 for (i = 0; i < dcb_info.nb_tcs; i++)
3380 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3381 printf("\n TXQ number :");
3382 for (i = 0; i < dcb_info.nb_tcs; i++)
3383 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3388 open_ddp_package_file(const char *file_path, uint32_t *size)
3390 int fd = open(file_path, O_RDONLY);
3392 uint8_t *buf = NULL;
3400 printf("%s: Failed to open %s\n", __func__, file_path);
3404 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
3406 printf("%s: File operations failed\n", __func__);
3410 pkg_size = st_buf.st_size;
3413 printf("%s: File operations failed\n", __func__);
3417 buf = (uint8_t *)malloc(pkg_size);
3420 printf("%s: Failed to malloc memory\n", __func__);
3424 ret = read(fd, buf, pkg_size);
3427 printf("%s: File read operation failed\n", __func__);
3428 close_ddp_package_file(buf);
3441 save_ddp_package_file(const char *file_path, uint8_t *buf, uint32_t size)
3443 FILE *fh = fopen(file_path, "wb");
3446 printf("%s: Failed to open %s\n", __func__, file_path);
3450 if (fwrite(buf, 1, size, fh) != size) {
3452 printf("%s: File write operation failed\n", __func__);
3462 close_ddp_package_file(uint8_t *buf)