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>
44 #include <rte_common.h>
45 #include <rte_byteorder.h>
46 #include <rte_debug.h>
48 #include <rte_memory.h>
49 #include <rte_memcpy.h>
50 #include <rte_memzone.h>
51 #include <rte_launch.h>
53 #include <rte_per_lcore.h>
54 #include <rte_lcore.h>
55 #include <rte_atomic.h>
56 #include <rte_branch_prediction.h>
57 #include <rte_mempool.h>
59 #include <rte_interrupts.h>
61 #include <rte_ether.h>
62 #include <rte_ethdev.h>
63 #include <rte_string_fns.h>
64 #include <rte_cycles.h>
66 #include <rte_errno.h>
67 #ifdef RTE_LIBRTE_IXGBE_PMD
68 #include <rte_pmd_ixgbe.h>
70 #ifdef RTE_LIBRTE_BNXT_PMD
71 #include <rte_pmd_bnxt.h>
77 static char *flowtype_to_str(uint16_t flow_type);
80 enum tx_pkt_split split;
84 .split = TX_PKT_SPLIT_OFF,
88 .split = TX_PKT_SPLIT_ON,
92 .split = TX_PKT_SPLIT_RND,
97 struct rss_type_info {
102 static const struct rss_type_info rss_type_table[] = {
103 { "ipv4", ETH_RSS_IPV4 },
104 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
105 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
106 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
107 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
108 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
109 { "ipv6", ETH_RSS_IPV6 },
110 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
111 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
112 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
113 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
114 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
115 { "l2-payload", ETH_RSS_L2_PAYLOAD },
116 { "ipv6-ex", ETH_RSS_IPV6_EX },
117 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
118 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
119 { "port", ETH_RSS_PORT },
120 { "vxlan", ETH_RSS_VXLAN },
121 { "geneve", ETH_RSS_GENEVE },
122 { "nvgre", ETH_RSS_NVGRE },
127 print_ethaddr(const char *name, struct ether_addr *eth_addr)
129 char buf[ETHER_ADDR_FMT_SIZE];
130 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
131 printf("%s%s", name, buf);
135 nic_stats_display(portid_t port_id)
137 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
138 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
139 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
140 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles;
141 uint64_t mpps_rx, mpps_tx;
142 struct rte_eth_stats stats;
143 struct rte_port *port = &ports[port_id];
147 static const char *nic_stats_border = "########################";
149 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
150 printf("Valid port range is [0");
151 RTE_ETH_FOREACH_DEV(pid)
156 rte_eth_stats_get(port_id, &stats);
157 printf("\n %s NIC statistics for port %-2d %s\n",
158 nic_stats_border, port_id, nic_stats_border);
160 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
161 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
163 stats.ipackets, stats.imissed, stats.ibytes);
164 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
165 printf(" RX-nombuf: %-10"PRIu64"\n",
167 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
169 stats.opackets, stats.oerrors, stats.obytes);
172 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
173 " RX-bytes: %10"PRIu64"\n",
174 stats.ipackets, stats.ierrors, stats.ibytes);
175 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
176 printf(" RX-nombuf: %10"PRIu64"\n",
178 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
179 " TX-bytes: %10"PRIu64"\n",
180 stats.opackets, stats.oerrors, stats.obytes);
183 if (port->rx_queue_stats_mapping_enabled) {
185 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
186 printf(" Stats reg %2d RX-packets: %10"PRIu64
187 " RX-errors: %10"PRIu64
188 " RX-bytes: %10"PRIu64"\n",
189 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
192 if (port->tx_queue_stats_mapping_enabled) {
194 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
195 printf(" Stats reg %2d TX-packets: %10"PRIu64
196 " TX-bytes: %10"PRIu64"\n",
197 i, stats.q_opackets[i], stats.q_obytes[i]);
201 diff_cycles = prev_cycles[port_id];
202 prev_cycles[port_id] = rte_rdtsc();
204 diff_cycles = prev_cycles[port_id] - diff_cycles;
206 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
207 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
208 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
209 (stats.opackets - prev_pkts_tx[port_id]) : 0;
210 prev_pkts_rx[port_id] = stats.ipackets;
211 prev_pkts_tx[port_id] = stats.opackets;
212 mpps_rx = diff_cycles > 0 ?
213 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
214 mpps_tx = diff_cycles > 0 ?
215 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
216 printf("\n Throughput (since last show)\n");
217 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
220 printf(" %s############################%s\n",
221 nic_stats_border, nic_stats_border);
225 nic_stats_clear(portid_t port_id)
229 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
230 printf("Valid port range is [0");
231 RTE_ETH_FOREACH_DEV(pid)
236 rte_eth_stats_reset(port_id);
237 printf("\n NIC statistics for port %d cleared\n", port_id);
241 nic_xstats_display(portid_t port_id)
243 struct rte_eth_xstat *xstats;
244 int cnt_xstats, idx_xstat;
245 struct rte_eth_xstat_name *xstats_names;
247 printf("###### NIC extended statistics for port %-2d\n", port_id);
248 if (!rte_eth_dev_is_valid_port(port_id)) {
249 printf("Error: Invalid port number %i\n", port_id);
254 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
255 if (cnt_xstats < 0) {
256 printf("Error: Cannot get count of xstats\n");
260 /* Get id-name lookup table */
261 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
262 if (xstats_names == NULL) {
263 printf("Cannot allocate memory for xstats lookup\n");
266 if (cnt_xstats != rte_eth_xstats_get_names(
267 port_id, xstats_names, cnt_xstats)) {
268 printf("Error: Cannot get xstats lookup\n");
273 /* Get stats themselves */
274 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
275 if (xstats == NULL) {
276 printf("Cannot allocate memory for xstats\n");
280 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
281 printf("Error: Unable to get xstats\n");
288 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
289 printf("%s: %"PRIu64"\n",
290 xstats_names[idx_xstat].name,
291 xstats[idx_xstat].value);
297 nic_xstats_clear(portid_t port_id)
299 rte_eth_xstats_reset(port_id);
303 nic_stats_mapping_display(portid_t port_id)
305 struct rte_port *port = &ports[port_id];
309 static const char *nic_stats_mapping_border = "########################";
311 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
312 printf("Valid port range is [0");
313 RTE_ETH_FOREACH_DEV(pid)
319 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
320 printf("Port id %d - either does not support queue statistic mapping or"
321 " no queue statistic mapping set\n", port_id);
325 printf("\n %s NIC statistics mapping for port %-2d %s\n",
326 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
328 if (port->rx_queue_stats_mapping_enabled) {
329 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
330 if (rx_queue_stats_mappings[i].port_id == port_id) {
331 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
332 rx_queue_stats_mappings[i].queue_id,
333 rx_queue_stats_mappings[i].stats_counter_id);
340 if (port->tx_queue_stats_mapping_enabled) {
341 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
342 if (tx_queue_stats_mappings[i].port_id == port_id) {
343 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
344 tx_queue_stats_mappings[i].queue_id,
345 tx_queue_stats_mappings[i].stats_counter_id);
350 printf(" %s####################################%s\n",
351 nic_stats_mapping_border, nic_stats_mapping_border);
355 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
357 struct rte_eth_rxq_info qinfo;
359 static const char *info_border = "*********************";
361 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
363 printf("Failed to retrieve information for port: %hhu, "
364 "RX queue: %hu\nerror desc: %s(%d)\n",
365 port_id, queue_id, strerror(-rc), rc);
369 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
370 info_border, port_id, queue_id, info_border);
372 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
373 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
374 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
375 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
376 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
377 printf("\nRX drop packets: %s",
378 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
379 printf("\nRX deferred start: %s",
380 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
381 printf("\nRX scattered packets: %s",
382 (qinfo.scattered_rx != 0) ? "on" : "off");
383 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
388 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
390 struct rte_eth_txq_info qinfo;
392 static const char *info_border = "*********************";
394 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
396 printf("Failed to retrieve information for port: %hhu, "
397 "TX queue: %hu\nerror desc: %s(%d)\n",
398 port_id, queue_id, strerror(-rc), rc);
402 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
403 info_border, port_id, queue_id, info_border);
405 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
406 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
407 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
408 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
409 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
410 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
411 printf("\nTX deferred start: %s",
412 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
413 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
418 port_infos_display(portid_t port_id)
420 struct rte_port *port;
421 struct ether_addr mac_addr;
422 struct rte_eth_link link;
423 struct rte_eth_dev_info dev_info;
425 struct rte_mempool * mp;
426 static const char *info_border = "*********************";
430 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
431 printf("Valid port range is [0");
432 RTE_ETH_FOREACH_DEV(pid)
437 port = &ports[port_id];
438 rte_eth_link_get_nowait(port_id, &link);
439 memset(&dev_info, 0, sizeof(dev_info));
440 rte_eth_dev_info_get(port_id, &dev_info);
441 printf("\n%s Infos for port %-2d %s\n",
442 info_border, port_id, info_border);
443 rte_eth_macaddr_get(port_id, &mac_addr);
444 print_ethaddr("MAC address: ", &mac_addr);
445 printf("\nDriver name: %s", dev_info.driver_name);
446 printf("\nConnect to socket: %u", port->socket_id);
448 if (port_numa[port_id] != NUMA_NO_CONFIG) {
449 mp = mbuf_pool_find(port_numa[port_id]);
451 printf("\nmemory allocation on the socket: %d",
454 printf("\nmemory allocation on the socket: %u",port->socket_id);
456 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
457 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
458 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
459 ("full-duplex") : ("half-duplex"));
461 if (!rte_eth_dev_get_mtu(port_id, &mtu))
462 printf("MTU: %u\n", mtu);
464 printf("Promiscuous mode: %s\n",
465 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
466 printf("Allmulticast mode: %s\n",
467 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
468 printf("Maximum number of MAC addresses: %u\n",
469 (unsigned int)(port->dev_info.max_mac_addrs));
470 printf("Maximum number of MAC addresses of hash filtering: %u\n",
471 (unsigned int)(port->dev_info.max_hash_mac_addrs));
473 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
474 if (vlan_offload >= 0){
475 printf("VLAN offload: \n");
476 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
477 printf(" strip on \n");
479 printf(" strip off \n");
481 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
482 printf(" filter on \n");
484 printf(" filter off \n");
486 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
487 printf(" qinq(extend) on \n");
489 printf(" qinq(extend) off \n");
492 if (dev_info.hash_key_size > 0)
493 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
494 if (dev_info.reta_size > 0)
495 printf("Redirection table size: %u\n", dev_info.reta_size);
496 if (!dev_info.flow_type_rss_offloads)
497 printf("No flow type is supported.\n");
502 printf("Supported flow types:\n");
503 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
505 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
507 p = flowtype_to_str(i);
508 printf(" %s\n", (p ? p : "unknown"));
512 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
513 printf("Max possible number of RXDs per queue: %hu\n",
514 dev_info.rx_desc_lim.nb_max);
515 printf("Min possible number of RXDs per queue: %hu\n",
516 dev_info.rx_desc_lim.nb_min);
517 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
519 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
520 printf("Max possible number of TXDs per queue: %hu\n",
521 dev_info.tx_desc_lim.nb_max);
522 printf("Min possible number of TXDs per queue: %hu\n",
523 dev_info.tx_desc_lim.nb_min);
524 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
528 port_offload_cap_display(portid_t port_id)
530 struct rte_eth_dev *dev;
531 struct rte_eth_dev_info dev_info;
532 static const char *info_border = "************";
534 if (port_id_is_invalid(port_id, ENABLED_WARN))
537 dev = &rte_eth_devices[port_id];
538 rte_eth_dev_info_get(port_id, &dev_info);
540 printf("\n%s Port %d supported offload features: %s\n",
541 info_border, port_id, info_border);
543 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
544 printf("VLAN stripped: ");
545 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
551 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
552 printf("Double VLANs stripped: ");
553 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
559 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
560 printf("RX IPv4 checksum: ");
561 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
567 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
568 printf("RX UDP checksum: ");
569 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
575 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
576 printf("RX TCP checksum: ");
577 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
583 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
584 printf("RX Outer IPv4 checksum: on");
586 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
587 printf("Large receive offload: ");
588 if (dev->data->dev_conf.rxmode.enable_lro)
594 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
595 printf("VLAN insert: ");
596 if (ports[port_id].tx_ol_flags &
597 TESTPMD_TX_OFFLOAD_INSERT_VLAN)
603 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
604 printf("Double VLANs insert: ");
605 if (ports[port_id].tx_ol_flags &
606 TESTPMD_TX_OFFLOAD_INSERT_QINQ)
612 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
613 printf("TX IPv4 checksum: ");
614 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
620 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
621 printf("TX UDP checksum: ");
622 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
628 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
629 printf("TX TCP checksum: ");
630 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
636 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
637 printf("TX SCTP checksum: ");
638 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
644 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
645 printf("TX Outer IPv4 checksum: ");
646 if (ports[port_id].tx_ol_flags &
647 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
653 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
654 printf("TX TCP segmentation: ");
655 if (ports[port_id].tso_segsz != 0)
661 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
662 printf("TX UDP segmentation: ");
663 if (ports[port_id].tso_segsz != 0)
669 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
670 printf("TSO for VXLAN tunnel packet: ");
671 if (ports[port_id].tunnel_tso_segsz)
677 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
678 printf("TSO for GRE tunnel packet: ");
679 if (ports[port_id].tunnel_tso_segsz)
685 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
686 printf("TSO for IPIP tunnel packet: ");
687 if (ports[port_id].tunnel_tso_segsz)
693 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
694 printf("TSO for GENEVE tunnel packet: ");
695 if (ports[port_id].tunnel_tso_segsz)
704 port_id_is_invalid(portid_t port_id, enum print_warning warning)
706 if (port_id == (portid_t)RTE_PORT_ALL)
709 if (rte_eth_dev_is_valid_port(port_id))
712 if (warning == ENABLED_WARN)
713 printf("Invalid port %d\n", port_id);
719 vlan_id_is_invalid(uint16_t vlan_id)
723 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
728 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
733 printf("Port register offset 0x%X not aligned on a 4-byte "
738 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
739 if (reg_off >= pci_len) {
740 printf("Port %d: register offset %u (0x%X) out of port PCI "
741 "resource (length=%"PRIu64")\n",
742 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
749 reg_bit_pos_is_invalid(uint8_t bit_pos)
753 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
757 #define display_port_and_reg_off(port_id, reg_off) \
758 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
761 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
763 display_port_and_reg_off(port_id, (unsigned)reg_off);
764 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
768 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
773 if (port_id_is_invalid(port_id, ENABLED_WARN))
775 if (port_reg_off_is_invalid(port_id, reg_off))
777 if (reg_bit_pos_is_invalid(bit_x))
779 reg_v = port_id_pci_reg_read(port_id, reg_off);
780 display_port_and_reg_off(port_id, (unsigned)reg_off);
781 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
785 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
786 uint8_t bit1_pos, uint8_t bit2_pos)
792 if (port_id_is_invalid(port_id, ENABLED_WARN))
794 if (port_reg_off_is_invalid(port_id, reg_off))
796 if (reg_bit_pos_is_invalid(bit1_pos))
798 if (reg_bit_pos_is_invalid(bit2_pos))
800 if (bit1_pos > bit2_pos)
801 l_bit = bit2_pos, h_bit = bit1_pos;
803 l_bit = bit1_pos, h_bit = bit2_pos;
805 reg_v = port_id_pci_reg_read(port_id, reg_off);
808 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
809 display_port_and_reg_off(port_id, (unsigned)reg_off);
810 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
811 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
815 port_reg_display(portid_t port_id, uint32_t reg_off)
819 if (port_id_is_invalid(port_id, ENABLED_WARN))
821 if (port_reg_off_is_invalid(port_id, reg_off))
823 reg_v = port_id_pci_reg_read(port_id, reg_off);
824 display_port_reg_value(port_id, reg_off, reg_v);
828 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
833 if (port_id_is_invalid(port_id, ENABLED_WARN))
835 if (port_reg_off_is_invalid(port_id, reg_off))
837 if (reg_bit_pos_is_invalid(bit_pos))
840 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
843 reg_v = port_id_pci_reg_read(port_id, reg_off);
845 reg_v &= ~(1 << bit_pos);
847 reg_v |= (1 << bit_pos);
848 port_id_pci_reg_write(port_id, reg_off, reg_v);
849 display_port_reg_value(port_id, reg_off, reg_v);
853 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
854 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
861 if (port_id_is_invalid(port_id, ENABLED_WARN))
863 if (port_reg_off_is_invalid(port_id, reg_off))
865 if (reg_bit_pos_is_invalid(bit1_pos))
867 if (reg_bit_pos_is_invalid(bit2_pos))
869 if (bit1_pos > bit2_pos)
870 l_bit = bit2_pos, h_bit = bit1_pos;
872 l_bit = bit1_pos, h_bit = bit2_pos;
874 if ((h_bit - l_bit) < 31)
875 max_v = (1 << (h_bit - l_bit + 1)) - 1;
880 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
881 (unsigned)value, (unsigned)value,
882 (unsigned)max_v, (unsigned)max_v);
885 reg_v = port_id_pci_reg_read(port_id, reg_off);
886 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
887 reg_v |= (value << l_bit); /* Set changed bits */
888 port_id_pci_reg_write(port_id, reg_off, reg_v);
889 display_port_reg_value(port_id, reg_off, reg_v);
893 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
895 if (port_id_is_invalid(port_id, ENABLED_WARN))
897 if (port_reg_off_is_invalid(port_id, reg_off))
899 port_id_pci_reg_write(port_id, reg_off, reg_v);
900 display_port_reg_value(port_id, reg_off, reg_v);
904 port_mtu_set(portid_t port_id, uint16_t mtu)
908 if (port_id_is_invalid(port_id, ENABLED_WARN))
910 diag = rte_eth_dev_set_mtu(port_id, mtu);
913 printf("Set MTU failed. diag=%d\n", diag);
916 /* Generic flow management functions. */
918 /** Generate flow_item[] entry. */
919 #define MK_FLOW_ITEM(t, s) \
920 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
925 /** Information about known flow pattern items. */
926 static const struct {
930 MK_FLOW_ITEM(END, 0),
931 MK_FLOW_ITEM(VOID, 0),
932 MK_FLOW_ITEM(INVERT, 0),
933 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
935 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
936 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
937 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
938 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
939 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
940 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
941 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
942 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
943 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
944 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
945 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
946 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
947 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
948 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
949 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
950 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
951 MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
954 /** Compute storage space needed by item specification. */
956 flow_item_spec_size(const struct rte_flow_item *item,
957 size_t *size, size_t *pad)
963 switch (item->type) {
965 const struct rte_flow_item_raw *raw;
968 case RTE_FLOW_ITEM_TYPE_RAW:
969 spec.raw = item->spec;
970 *size = offsetof(struct rte_flow_item_raw, pattern) +
971 spec.raw->length * sizeof(*spec.raw->pattern);
974 *size = flow_item[item->type].size;
978 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
981 /** Generate flow_action[] entry. */
982 #define MK_FLOW_ACTION(t, s) \
983 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
988 /** Information about known flow actions. */
989 static const struct {
993 MK_FLOW_ACTION(END, 0),
994 MK_FLOW_ACTION(VOID, 0),
995 MK_FLOW_ACTION(PASSTHRU, 0),
996 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
997 MK_FLOW_ACTION(FLAG, 0),
998 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
999 MK_FLOW_ACTION(DROP, 0),
1000 MK_FLOW_ACTION(COUNT, 0),
1001 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
1002 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
1003 MK_FLOW_ACTION(PF, 0),
1004 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1007 /** Compute storage space needed by action configuration. */
1009 flow_action_conf_size(const struct rte_flow_action *action,
1010 size_t *size, size_t *pad)
1012 if (!action->conf) {
1016 switch (action->type) {
1018 const struct rte_flow_action_rss *rss;
1021 case RTE_FLOW_ACTION_TYPE_RSS:
1022 conf.rss = action->conf;
1023 *size = offsetof(struct rte_flow_action_rss, queue) +
1024 conf.rss->num * sizeof(*conf.rss->queue);
1027 *size = flow_action[action->type].size;
1031 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1034 /** Generate a port_flow entry from attributes/pattern/actions. */
1035 static struct port_flow *
1036 port_flow_new(const struct rte_flow_attr *attr,
1037 const struct rte_flow_item *pattern,
1038 const struct rte_flow_action *actions)
1040 const struct rte_flow_item *item;
1041 const struct rte_flow_action *action;
1042 struct port_flow *pf = NULL;
1052 pf->pattern = (void *)&pf->data[off1];
1054 struct rte_flow_item *dst = NULL;
1056 if ((unsigned int)item->type >= RTE_DIM(flow_item) ||
1057 !flow_item[item->type].name)
1060 dst = memcpy(pf->data + off1, item, sizeof(*item));
1061 off1 += sizeof(*item);
1062 flow_item_spec_size(item, &tmp, &pad);
1065 dst->spec = memcpy(pf->data + off2,
1071 dst->last = memcpy(pf->data + off2,
1077 dst->mask = memcpy(pf->data + off2,
1081 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1082 } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
1083 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1086 pf->actions = (void *)&pf->data[off1];
1088 struct rte_flow_action *dst = NULL;
1090 if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
1091 !flow_action[action->type].name)
1094 dst = memcpy(pf->data + off1, action, sizeof(*action));
1095 off1 += sizeof(*action);
1096 flow_action_conf_size(action, &tmp, &pad);
1099 dst->conf = memcpy(pf->data + off2,
1103 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1104 } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
1107 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1108 tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double));
1109 pf = calloc(1, tmp + off1 + off2);
1113 *pf = (const struct port_flow){
1114 .size = tmp + off1 + off2,
1117 tmp -= offsetof(struct port_flow, data);
1127 /** Print a message out of a flow error. */
1129 port_flow_complain(struct rte_flow_error *error)
1131 static const char *const errstrlist[] = {
1132 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1133 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1134 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1135 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1136 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1137 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1138 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1139 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1140 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1141 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1142 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1143 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1147 int err = rte_errno;
1149 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1150 !errstrlist[error->type])
1151 errstr = "unknown type";
1153 errstr = errstrlist[error->type];
1154 printf("Caught error type %d (%s): %s%s\n",
1155 error->type, errstr,
1156 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1157 error->cause), buf) : "",
1158 error->message ? error->message : "(no stated reason)");
1162 /** Validate flow rule. */
1164 port_flow_validate(portid_t port_id,
1165 const struct rte_flow_attr *attr,
1166 const struct rte_flow_item *pattern,
1167 const struct rte_flow_action *actions)
1169 struct rte_flow_error error;
1171 /* Poisoning to make sure PMDs update it in case of error. */
1172 memset(&error, 0x11, sizeof(error));
1173 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1174 return port_flow_complain(&error);
1175 printf("Flow rule validated\n");
1179 /** Create flow rule. */
1181 port_flow_create(portid_t port_id,
1182 const struct rte_flow_attr *attr,
1183 const struct rte_flow_item *pattern,
1184 const struct rte_flow_action *actions)
1186 struct rte_flow *flow;
1187 struct rte_port *port;
1188 struct port_flow *pf;
1190 struct rte_flow_error error;
1192 /* Poisoning to make sure PMDs update it in case of error. */
1193 memset(&error, 0x22, sizeof(error));
1194 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1196 return port_flow_complain(&error);
1197 port = &ports[port_id];
1198 if (port->flow_list) {
1199 if (port->flow_list->id == UINT32_MAX) {
1200 printf("Highest rule ID is already assigned, delete"
1202 rte_flow_destroy(port_id, flow, NULL);
1205 id = port->flow_list->id + 1;
1208 pf = port_flow_new(attr, pattern, actions);
1210 int err = rte_errno;
1212 printf("Cannot allocate flow: %s\n", rte_strerror(err));
1213 rte_flow_destroy(port_id, flow, NULL);
1216 pf->next = port->flow_list;
1219 port->flow_list = pf;
1220 printf("Flow rule #%u created\n", pf->id);
1224 /** Destroy a number of flow rules. */
1226 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1228 struct rte_port *port;
1229 struct port_flow **tmp;
1233 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1234 port_id == (portid_t)RTE_PORT_ALL)
1236 port = &ports[port_id];
1237 tmp = &port->flow_list;
1241 for (i = 0; i != n; ++i) {
1242 struct rte_flow_error error;
1243 struct port_flow *pf = *tmp;
1245 if (rule[i] != pf->id)
1248 * Poisoning to make sure PMDs update it in case
1251 memset(&error, 0x33, sizeof(error));
1252 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1253 ret = port_flow_complain(&error);
1256 printf("Flow rule #%u destroyed\n", pf->id);
1262 tmp = &(*tmp)->next;
1268 /** Remove all flow rules. */
1270 port_flow_flush(portid_t port_id)
1272 struct rte_flow_error error;
1273 struct rte_port *port;
1276 /* Poisoning to make sure PMDs update it in case of error. */
1277 memset(&error, 0x44, sizeof(error));
1278 if (rte_flow_flush(port_id, &error)) {
1279 ret = port_flow_complain(&error);
1280 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1281 port_id == (portid_t)RTE_PORT_ALL)
1284 port = &ports[port_id];
1285 while (port->flow_list) {
1286 struct port_flow *pf = port->flow_list->next;
1288 free(port->flow_list);
1289 port->flow_list = pf;
1294 /** Query a flow rule. */
1296 port_flow_query(portid_t port_id, uint32_t rule,
1297 enum rte_flow_action_type action)
1299 struct rte_flow_error error;
1300 struct rte_port *port;
1301 struct port_flow *pf;
1304 struct rte_flow_query_count count;
1307 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1308 port_id == (portid_t)RTE_PORT_ALL)
1310 port = &ports[port_id];
1311 for (pf = port->flow_list; pf; pf = pf->next)
1315 printf("Flow rule #%u not found\n", rule);
1318 if ((unsigned int)action >= RTE_DIM(flow_action) ||
1319 !flow_action[action].name)
1322 name = flow_action[action].name;
1324 case RTE_FLOW_ACTION_TYPE_COUNT:
1327 printf("Cannot query action type %d (%s)\n", action, name);
1330 /* Poisoning to make sure PMDs update it in case of error. */
1331 memset(&error, 0x55, sizeof(error));
1332 memset(&query, 0, sizeof(query));
1333 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1334 return port_flow_complain(&error);
1336 case RTE_FLOW_ACTION_TYPE_COUNT:
1340 " hits: %" PRIu64 "\n"
1341 " bytes: %" PRIu64 "\n",
1343 query.count.hits_set,
1344 query.count.bytes_set,
1349 printf("Cannot display result for action type %d (%s)\n",
1356 /** List flow rules. */
1358 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1360 struct rte_port *port;
1361 struct port_flow *pf;
1362 struct port_flow *list = NULL;
1365 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1366 port_id == (portid_t)RTE_PORT_ALL)
1368 port = &ports[port_id];
1369 if (!port->flow_list)
1371 /* Sort flows by group, priority and ID. */
1372 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1373 struct port_flow **tmp;
1376 /* Filter out unwanted groups. */
1377 for (i = 0; i != n; ++i)
1378 if (pf->attr.group == group[i])
1385 (pf->attr.group > (*tmp)->attr.group ||
1386 (pf->attr.group == (*tmp)->attr.group &&
1387 pf->attr.priority > (*tmp)->attr.priority) ||
1388 (pf->attr.group == (*tmp)->attr.group &&
1389 pf->attr.priority == (*tmp)->attr.priority &&
1390 pf->id > (*tmp)->id)))
1395 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1396 for (pf = list; pf != NULL; pf = pf->tmp) {
1397 const struct rte_flow_item *item = pf->pattern;
1398 const struct rte_flow_action *action = pf->actions;
1400 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t",
1404 pf->attr.ingress ? 'i' : '-',
1405 pf->attr.egress ? 'e' : '-');
1406 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1407 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1408 printf("%s ", flow_item[item->type].name);
1412 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1413 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1414 printf(" %s", flow_action[action->type].name);
1421 /** Restrict ingress traffic to the defined flow rules. */
1423 port_flow_isolate(portid_t port_id, int set)
1425 struct rte_flow_error error;
1427 /* Poisoning to make sure PMDs update it in case of error. */
1428 memset(&error, 0x66, sizeof(error));
1429 if (rte_flow_isolate(port_id, set, &error))
1430 return port_flow_complain(&error);
1431 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1433 set ? "now restricted" : "not restricted anymore");
1438 * RX/TX ring descriptors display functions.
1441 rx_queue_id_is_invalid(queueid_t rxq_id)
1443 if (rxq_id < nb_rxq)
1445 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1450 tx_queue_id_is_invalid(queueid_t txq_id)
1452 if (txq_id < nb_txq)
1454 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1459 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1461 if (rxdesc_id < nb_rxd)
1463 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1469 tx_desc_id_is_invalid(uint16_t txdesc_id)
1471 if (txdesc_id < nb_txd)
1473 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1478 static const struct rte_memzone *
1479 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
1481 char mz_name[RTE_MEMZONE_NAMESIZE];
1482 const struct rte_memzone *mz;
1484 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1485 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1486 mz = rte_memzone_lookup(mz_name);
1488 printf("%s ring memory zoneof (port %d, queue %d) not"
1489 "found (zone name = %s\n",
1490 ring_name, port_id, q_id, mz_name);
1494 union igb_ring_dword {
1497 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1507 struct igb_ring_desc_32_bytes {
1508 union igb_ring_dword lo_dword;
1509 union igb_ring_dword hi_dword;
1510 union igb_ring_dword resv1;
1511 union igb_ring_dword resv2;
1514 struct igb_ring_desc_16_bytes {
1515 union igb_ring_dword lo_dword;
1516 union igb_ring_dword hi_dword;
1520 ring_rxd_display_dword(union igb_ring_dword dword)
1522 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1523 (unsigned)dword.words.hi);
1527 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1528 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1531 __rte_unused uint8_t port_id,
1535 struct igb_ring_desc_16_bytes *ring =
1536 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1537 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1538 struct rte_eth_dev_info dev_info;
1540 memset(&dev_info, 0, sizeof(dev_info));
1541 rte_eth_dev_info_get(port_id, &dev_info);
1542 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1543 /* 32 bytes RX descriptor, i40e only */
1544 struct igb_ring_desc_32_bytes *ring =
1545 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1546 ring[desc_id].lo_dword.dword =
1547 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1548 ring_rxd_display_dword(ring[desc_id].lo_dword);
1549 ring[desc_id].hi_dword.dword =
1550 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1551 ring_rxd_display_dword(ring[desc_id].hi_dword);
1552 ring[desc_id].resv1.dword =
1553 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1554 ring_rxd_display_dword(ring[desc_id].resv1);
1555 ring[desc_id].resv2.dword =
1556 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1557 ring_rxd_display_dword(ring[desc_id].resv2);
1562 /* 16 bytes RX descriptor */
1563 ring[desc_id].lo_dword.dword =
1564 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1565 ring_rxd_display_dword(ring[desc_id].lo_dword);
1566 ring[desc_id].hi_dword.dword =
1567 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1568 ring_rxd_display_dword(ring[desc_id].hi_dword);
1572 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1574 struct igb_ring_desc_16_bytes *ring;
1575 struct igb_ring_desc_16_bytes txd;
1577 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1578 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1579 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1580 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1581 (unsigned)txd.lo_dword.words.lo,
1582 (unsigned)txd.lo_dword.words.hi,
1583 (unsigned)txd.hi_dword.words.lo,
1584 (unsigned)txd.hi_dword.words.hi);
1588 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1590 const struct rte_memzone *rx_mz;
1592 if (port_id_is_invalid(port_id, ENABLED_WARN))
1594 if (rx_queue_id_is_invalid(rxq_id))
1596 if (rx_desc_id_is_invalid(rxd_id))
1598 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1601 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1605 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1607 const struct rte_memzone *tx_mz;
1609 if (port_id_is_invalid(port_id, ENABLED_WARN))
1611 if (tx_queue_id_is_invalid(txq_id))
1613 if (tx_desc_id_is_invalid(txd_id))
1615 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1618 ring_tx_descriptor_display(tx_mz, txd_id);
1622 fwd_lcores_config_display(void)
1626 printf("List of forwarding lcores:");
1627 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1628 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1632 rxtx_config_display(void)
1634 printf(" %s packet forwarding%s - CRC stripping %s - "
1635 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
1636 retry_enabled == 0 ? "" : " with retry",
1637 rx_mode.hw_strip_crc ? "enabled" : "disabled",
1640 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1641 printf(" packet len=%u - nb packet segments=%d\n",
1642 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1644 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
1645 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
1647 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1648 nb_fwd_lcores, nb_fwd_ports);
1649 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1650 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1651 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1652 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
1653 rx_conf->rx_thresh.wthresh);
1654 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1655 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1656 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1657 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
1658 tx_conf->tx_thresh.wthresh);
1659 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
1660 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
1664 port_rss_reta_info(portid_t port_id,
1665 struct rte_eth_rss_reta_entry64 *reta_conf,
1666 uint16_t nb_entries)
1668 uint16_t i, idx, shift;
1671 if (port_id_is_invalid(port_id, ENABLED_WARN))
1674 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1676 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1680 for (i = 0; i < nb_entries; i++) {
1681 idx = i / RTE_RETA_GROUP_SIZE;
1682 shift = i % RTE_RETA_GROUP_SIZE;
1683 if (!(reta_conf[idx].mask & (1ULL << shift)))
1685 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1686 i, reta_conf[idx].reta[shift]);
1691 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1695 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1697 struct rte_eth_rss_conf rss_conf;
1698 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1702 struct rte_eth_dev_info dev_info;
1703 uint8_t hash_key_size;
1705 if (port_id_is_invalid(port_id, ENABLED_WARN))
1708 memset(&dev_info, 0, sizeof(dev_info));
1709 rte_eth_dev_info_get(port_id, &dev_info);
1710 if (dev_info.hash_key_size > 0 &&
1711 dev_info.hash_key_size <= sizeof(rss_key))
1712 hash_key_size = dev_info.hash_key_size;
1714 printf("dev_info did not provide a valid hash key size\n");
1718 rss_conf.rss_hf = 0;
1719 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1720 if (!strcmp(rss_info, rss_type_table[i].str))
1721 rss_conf.rss_hf = rss_type_table[i].rss_type;
1724 /* Get RSS hash key if asked to display it */
1725 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1726 rss_conf.rss_key_len = hash_key_size;
1727 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1731 printf("port index %d invalid\n", port_id);
1734 printf("operation not supported by device\n");
1737 printf("operation failed - diag=%d\n", diag);
1742 rss_hf = rss_conf.rss_hf;
1744 printf("RSS disabled\n");
1747 printf("RSS functions:\n ");
1748 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1749 if (rss_hf & rss_type_table[i].rss_type)
1750 printf("%s ", rss_type_table[i].str);
1755 printf("RSS key:\n");
1756 for (i = 0; i < hash_key_size; i++)
1757 printf("%02X", rss_key[i]);
1762 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1765 struct rte_eth_rss_conf rss_conf;
1769 rss_conf.rss_key = NULL;
1770 rss_conf.rss_key_len = hash_key_len;
1771 rss_conf.rss_hf = 0;
1772 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1773 if (!strcmp(rss_type_table[i].str, rss_type))
1774 rss_conf.rss_hf = rss_type_table[i].rss_type;
1776 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1778 rss_conf.rss_key = hash_key;
1779 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1786 printf("port index %d invalid\n", port_id);
1789 printf("operation not supported by device\n");
1792 printf("operation failed - diag=%d\n", diag);
1798 * Setup forwarding configuration for each logical core.
1801 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1803 streamid_t nb_fs_per_lcore;
1811 nb_fs = cfg->nb_fwd_streams;
1812 nb_fc = cfg->nb_fwd_lcores;
1813 if (nb_fs <= nb_fc) {
1814 nb_fs_per_lcore = 1;
1817 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1818 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1821 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1823 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1824 fwd_lcores[lc_id]->stream_idx = sm_id;
1825 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1826 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1830 * Assign extra remaining streams, if any.
1832 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1833 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1834 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1835 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1836 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1841 simple_fwd_config_setup(void)
1847 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1848 port_topology == PORT_TOPOLOGY_LOOP) {
1850 } else if (nb_fwd_ports % 2) {
1851 printf("\nWarning! Cannot handle an odd number of ports "
1852 "with the current port topology. Configuration "
1853 "must be changed to have an even number of ports, "
1854 "or relaunch application with "
1855 "--port-topology=chained\n\n");
1858 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1859 cur_fwd_config.nb_fwd_streams =
1860 (streamid_t) cur_fwd_config.nb_fwd_ports;
1862 /* reinitialize forwarding streams */
1866 * In the simple forwarding test, the number of forwarding cores
1867 * must be lower or equal to the number of forwarding ports.
1869 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1870 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1871 cur_fwd_config.nb_fwd_lcores =
1872 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1873 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1875 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1876 if (port_topology != PORT_TOPOLOGY_LOOP)
1877 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1880 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1881 fwd_streams[i]->rx_queue = 0;
1882 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1883 fwd_streams[i]->tx_queue = 0;
1884 fwd_streams[i]->peer_addr = j;
1885 fwd_streams[i]->retry_enabled = retry_enabled;
1887 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1888 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1889 fwd_streams[j]->rx_queue = 0;
1890 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1891 fwd_streams[j]->tx_queue = 0;
1892 fwd_streams[j]->peer_addr = i;
1893 fwd_streams[j]->retry_enabled = retry_enabled;
1899 * For the RSS forwarding test all streams distributed over lcores. Each stream
1900 * being composed of a RX queue to poll on a RX port for input messages,
1901 * associated with a TX queue of a TX port where to send forwarded packets.
1902 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1903 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1905 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1909 rss_fwd_config_setup(void)
1920 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1921 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1922 cur_fwd_config.nb_fwd_streams =
1923 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1925 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1926 cur_fwd_config.nb_fwd_lcores =
1927 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1929 /* reinitialize forwarding streams */
1932 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1934 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1935 struct fwd_stream *fs;
1937 fs = fwd_streams[sm_id];
1939 if ((rxp & 0x1) == 0)
1940 txp = (portid_t) (rxp + 1);
1942 txp = (portid_t) (rxp - 1);
1944 * if we are in loopback, simply send stuff out through the
1947 if (port_topology == PORT_TOPOLOGY_LOOP)
1950 fs->rx_port = fwd_ports_ids[rxp];
1952 fs->tx_port = fwd_ports_ids[txp];
1954 fs->peer_addr = fs->tx_port;
1955 fs->retry_enabled = retry_enabled;
1956 rxq = (queueid_t) (rxq + 1);
1961 * Restart from RX queue 0 on next RX port
1964 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1966 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1968 rxp = (portid_t) (rxp + 1);
1973 * For the DCB forwarding test, each core is assigned on each traffic class.
1975 * Each core is assigned a multi-stream, each stream being composed of
1976 * a RX queue to poll on a RX port for input messages, associated with
1977 * a TX queue of a TX port where to send forwarded packets. All RX and
1978 * TX queues are mapping to the same traffic class.
1979 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1983 dcb_fwd_config_setup(void)
1985 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1986 portid_t txp, rxp = 0;
1987 queueid_t txq, rxq = 0;
1989 uint16_t nb_rx_queue, nb_tx_queue;
1990 uint16_t i, j, k, sm_id = 0;
1993 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1994 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1995 cur_fwd_config.nb_fwd_streams =
1996 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1998 /* reinitialize forwarding streams */
2002 /* get the dcb info on the first RX and TX ports */
2003 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2004 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2006 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2007 fwd_lcores[lc_id]->stream_nb = 0;
2008 fwd_lcores[lc_id]->stream_idx = sm_id;
2009 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2010 /* if the nb_queue is zero, means this tc is
2011 * not enabled on the POOL
2013 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2015 k = fwd_lcores[lc_id]->stream_nb +
2016 fwd_lcores[lc_id]->stream_idx;
2017 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2018 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2019 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2020 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2021 for (j = 0; j < nb_rx_queue; j++) {
2022 struct fwd_stream *fs;
2024 fs = fwd_streams[k + j];
2025 fs->rx_port = fwd_ports_ids[rxp];
2026 fs->rx_queue = rxq + j;
2027 fs->tx_port = fwd_ports_ids[txp];
2028 fs->tx_queue = txq + j % nb_tx_queue;
2029 fs->peer_addr = fs->tx_port;
2030 fs->retry_enabled = retry_enabled;
2032 fwd_lcores[lc_id]->stream_nb +=
2033 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2035 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2038 if (tc < rxp_dcb_info.nb_tcs)
2040 /* Restart from TC 0 on next RX port */
2042 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2044 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2047 if (rxp >= nb_fwd_ports)
2049 /* get the dcb information on next RX and TX ports */
2050 if ((rxp & 0x1) == 0)
2051 txp = (portid_t) (rxp + 1);
2053 txp = (portid_t) (rxp - 1);
2054 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2055 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2060 icmp_echo_config_setup(void)
2067 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2068 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2069 (nb_txq * nb_fwd_ports);
2071 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2072 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2073 cur_fwd_config.nb_fwd_streams =
2074 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2075 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2076 cur_fwd_config.nb_fwd_lcores =
2077 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2078 if (verbose_level > 0) {
2079 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2081 cur_fwd_config.nb_fwd_lcores,
2082 cur_fwd_config.nb_fwd_ports,
2083 cur_fwd_config.nb_fwd_streams);
2086 /* reinitialize forwarding streams */
2088 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2090 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2091 if (verbose_level > 0)
2092 printf(" core=%d: \n", lc_id);
2093 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2094 struct fwd_stream *fs;
2095 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2096 fs->rx_port = fwd_ports_ids[rxp];
2098 fs->tx_port = fs->rx_port;
2100 fs->peer_addr = fs->tx_port;
2101 fs->retry_enabled = retry_enabled;
2102 if (verbose_level > 0)
2103 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2104 sm_id, fs->rx_port, fs->rx_queue,
2106 rxq = (queueid_t) (rxq + 1);
2107 if (rxq == nb_rxq) {
2109 rxp = (portid_t) (rxp + 1);
2116 fwd_config_setup(void)
2118 cur_fwd_config.fwd_eng = cur_fwd_eng;
2119 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2120 icmp_echo_config_setup();
2123 if ((nb_rxq > 1) && (nb_txq > 1)){
2125 dcb_fwd_config_setup();
2127 rss_fwd_config_setup();
2130 simple_fwd_config_setup();
2134 pkt_fwd_config_display(struct fwd_config *cfg)
2136 struct fwd_stream *fs;
2140 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2141 "NUMA support %s, MP over anonymous pages %s\n",
2142 cfg->fwd_eng->fwd_mode_name,
2143 retry_enabled == 0 ? "" : " with retry",
2144 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2145 numa_support == 1 ? "enabled" : "disabled",
2146 mp_anon != 0 ? "enabled" : "disabled");
2149 printf("TX retry num: %u, delay between TX retries: %uus\n",
2150 burst_tx_retry_num, burst_tx_delay_time);
2151 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2152 printf("Logical Core %u (socket %u) forwards packets on "
2154 fwd_lcores_cpuids[lc_id],
2155 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2156 fwd_lcores[lc_id]->stream_nb);
2157 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2158 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2159 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2160 "P=%d/Q=%d (socket %u) ",
2161 fs->rx_port, fs->rx_queue,
2162 ports[fs->rx_port].socket_id,
2163 fs->tx_port, fs->tx_queue,
2164 ports[fs->tx_port].socket_id);
2165 print_ethaddr("peer=",
2166 &peer_eth_addrs[fs->peer_addr]);
2174 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2177 unsigned int lcore_cpuid;
2182 for (i = 0; i < nb_lc; i++) {
2183 lcore_cpuid = lcorelist[i];
2184 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2185 printf("lcore %u not enabled\n", lcore_cpuid);
2188 if (lcore_cpuid == rte_get_master_lcore()) {
2189 printf("lcore %u cannot be masked on for running "
2190 "packet forwarding, which is the master lcore "
2191 "and reserved for command line parsing only\n",
2196 fwd_lcores_cpuids[i] = lcore_cpuid;
2198 if (record_now == 0) {
2202 nb_cfg_lcores = (lcoreid_t) nb_lc;
2203 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2204 printf("previous number of forwarding cores %u - changed to "
2205 "number of configured cores %u\n",
2206 (unsigned int) nb_fwd_lcores, nb_lc);
2207 nb_fwd_lcores = (lcoreid_t) nb_lc;
2214 set_fwd_lcores_mask(uint64_t lcoremask)
2216 unsigned int lcorelist[64];
2220 if (lcoremask == 0) {
2221 printf("Invalid NULL mask of cores\n");
2225 for (i = 0; i < 64; i++) {
2226 if (! ((uint64_t)(1ULL << i) & lcoremask))
2228 lcorelist[nb_lc++] = i;
2230 return set_fwd_lcores_list(lcorelist, nb_lc);
2234 set_fwd_lcores_number(uint16_t nb_lc)
2236 if (nb_lc > nb_cfg_lcores) {
2237 printf("nb fwd cores %u > %u (max. number of configured "
2238 "lcores) - ignored\n",
2239 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2242 nb_fwd_lcores = (lcoreid_t) nb_lc;
2243 printf("Number of forwarding cores set to %u\n",
2244 (unsigned int) nb_fwd_lcores);
2248 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2256 for (i = 0; i < nb_pt; i++) {
2257 port_id = (portid_t) portlist[i];
2258 if (port_id_is_invalid(port_id, ENABLED_WARN))
2261 fwd_ports_ids[i] = port_id;
2263 if (record_now == 0) {
2267 nb_cfg_ports = (portid_t) nb_pt;
2268 if (nb_fwd_ports != (portid_t) nb_pt) {
2269 printf("previous number of forwarding ports %u - changed to "
2270 "number of configured ports %u\n",
2271 (unsigned int) nb_fwd_ports, nb_pt);
2272 nb_fwd_ports = (portid_t) nb_pt;
2277 set_fwd_ports_mask(uint64_t portmask)
2279 unsigned int portlist[64];
2283 if (portmask == 0) {
2284 printf("Invalid NULL mask of ports\n");
2288 RTE_ETH_FOREACH_DEV(i) {
2289 if (! ((uint64_t)(1ULL << i) & portmask))
2291 portlist[nb_pt++] = i;
2293 set_fwd_ports_list(portlist, nb_pt);
2297 set_fwd_ports_number(uint16_t nb_pt)
2299 if (nb_pt > nb_cfg_ports) {
2300 printf("nb fwd ports %u > %u (number of configured "
2301 "ports) - ignored\n",
2302 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2305 nb_fwd_ports = (portid_t) nb_pt;
2306 printf("Number of forwarding ports set to %u\n",
2307 (unsigned int) nb_fwd_ports);
2311 port_is_forwarding(portid_t port_id)
2315 if (port_id_is_invalid(port_id, ENABLED_WARN))
2318 for (i = 0; i < nb_fwd_ports; i++) {
2319 if (fwd_ports_ids[i] == port_id)
2327 set_nb_pkt_per_burst(uint16_t nb)
2329 if (nb > MAX_PKT_BURST) {
2330 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2332 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2335 nb_pkt_per_burst = nb;
2336 printf("Number of packets per burst set to %u\n",
2337 (unsigned int) nb_pkt_per_burst);
2341 tx_split_get_name(enum tx_pkt_split split)
2345 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2346 if (tx_split_name[i].split == split)
2347 return tx_split_name[i].name;
2353 set_tx_pkt_split(const char *name)
2357 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2358 if (strcmp(tx_split_name[i].name, name) == 0) {
2359 tx_pkt_split = tx_split_name[i].split;
2363 printf("unknown value: \"%s\"\n", name);
2367 show_tx_pkt_segments(void)
2373 split = tx_split_get_name(tx_pkt_split);
2375 printf("Number of segments: %u\n", n);
2376 printf("Segment sizes: ");
2377 for (i = 0; i != n - 1; i++)
2378 printf("%hu,", tx_pkt_seg_lengths[i]);
2379 printf("%hu\n", tx_pkt_seg_lengths[i]);
2380 printf("Split packet: %s\n", split);
2384 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2386 uint16_t tx_pkt_len;
2389 if (nb_segs >= (unsigned) nb_txd) {
2390 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2391 nb_segs, (unsigned int) nb_txd);
2396 * Check that each segment length is greater or equal than
2397 * the mbuf data sise.
2398 * Check also that the total packet length is greater or equal than the
2399 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2402 for (i = 0; i < nb_segs; i++) {
2403 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2404 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2405 i, seg_lengths[i], (unsigned) mbuf_data_size);
2408 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2410 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2411 printf("total packet length=%u < %d - give up\n",
2412 (unsigned) tx_pkt_len,
2413 (int)(sizeof(struct ether_hdr) + 20 + 8));
2417 for (i = 0; i < nb_segs; i++)
2418 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2420 tx_pkt_length = tx_pkt_len;
2421 tx_pkt_nb_segs = (uint8_t) nb_segs;
2425 setup_gro(const char *mode, uint8_t port_id)
2427 if (!rte_eth_dev_is_valid_port(port_id)) {
2428 printf("invalid port id %u\n", port_id);
2431 if (test_done == 0) {
2432 printf("Before enable/disable GRO,"
2433 " please stop forwarding first\n");
2436 if (strcmp(mode, "on") == 0) {
2437 if (gro_ports[port_id].enable) {
2438 printf("port %u has enabled GRO\n", port_id);
2441 gro_ports[port_id].enable = 1;
2442 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2444 if (gro_ports[port_id].param.max_flow_num == 0)
2445 gro_ports[port_id].param.max_flow_num =
2446 GRO_DEFAULT_FLOW_NUM;
2447 if (gro_ports[port_id].param.max_item_per_flow == 0)
2448 gro_ports[port_id].param.max_item_per_flow =
2449 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2451 if (gro_ports[port_id].enable == 0) {
2452 printf("port %u has disabled GRO\n", port_id);
2455 gro_ports[port_id].enable = 0;
2460 list_pkt_forwarding_modes(void)
2462 static char fwd_modes[128] = "";
2463 const char *separator = "|";
2464 struct fwd_engine *fwd_eng;
2467 if (strlen (fwd_modes) == 0) {
2468 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2469 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2470 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2471 strncat(fwd_modes, separator,
2472 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2474 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2481 list_pkt_forwarding_retry_modes(void)
2483 static char fwd_modes[128] = "";
2484 const char *separator = "|";
2485 struct fwd_engine *fwd_eng;
2488 if (strlen(fwd_modes) == 0) {
2489 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2490 if (fwd_eng == &rx_only_engine)
2492 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2494 strlen(fwd_modes) - 1);
2495 strncat(fwd_modes, separator,
2497 strlen(fwd_modes) - 1);
2499 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2506 set_pkt_forwarding_mode(const char *fwd_mode_name)
2508 struct fwd_engine *fwd_eng;
2512 while ((fwd_eng = fwd_engines[i]) != NULL) {
2513 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2514 printf("Set %s packet forwarding mode%s\n",
2516 retry_enabled == 0 ? "" : " with retry");
2517 cur_fwd_eng = fwd_eng;
2522 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2526 set_verbose_level(uint16_t vb_level)
2528 printf("Change verbose level from %u to %u\n",
2529 (unsigned int) verbose_level, (unsigned int) vb_level);
2530 verbose_level = vb_level;
2534 vlan_extend_set(portid_t port_id, int on)
2539 if (port_id_is_invalid(port_id, ENABLED_WARN))
2542 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2545 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2547 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2549 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2551 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2552 "diag=%d\n", port_id, on, diag);
2556 rx_vlan_strip_set(portid_t port_id, int on)
2561 if (port_id_is_invalid(port_id, ENABLED_WARN))
2564 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2567 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2569 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2571 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2573 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2574 "diag=%d\n", port_id, on, diag);
2578 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2582 if (port_id_is_invalid(port_id, ENABLED_WARN))
2585 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2587 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2588 "diag=%d\n", port_id, queue_id, on, diag);
2592 rx_vlan_filter_set(portid_t port_id, int on)
2597 if (port_id_is_invalid(port_id, ENABLED_WARN))
2600 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2603 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2605 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2607 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2609 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2610 "diag=%d\n", port_id, on, diag);
2614 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2618 if (port_id_is_invalid(port_id, ENABLED_WARN))
2620 if (vlan_id_is_invalid(vlan_id))
2622 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2625 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2627 port_id, vlan_id, on, diag);
2632 rx_vlan_all_filter_set(portid_t port_id, int on)
2636 if (port_id_is_invalid(port_id, ENABLED_WARN))
2638 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2639 if (rx_vft_set(port_id, vlan_id, on))
2645 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2649 if (port_id_is_invalid(port_id, ENABLED_WARN))
2652 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2656 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2658 port_id, vlan_type, tp_id, diag);
2662 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2665 if (port_id_is_invalid(port_id, ENABLED_WARN))
2667 if (vlan_id_is_invalid(vlan_id))
2670 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2671 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2672 printf("Error, as QinQ has been enabled.\n");
2676 tx_vlan_reset(port_id);
2677 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
2678 ports[port_id].tx_vlan_id = vlan_id;
2682 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2685 if (port_id_is_invalid(port_id, ENABLED_WARN))
2687 if (vlan_id_is_invalid(vlan_id))
2689 if (vlan_id_is_invalid(vlan_id_outer))
2692 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2693 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2694 printf("Error, as QinQ hasn't been enabled.\n");
2698 tx_vlan_reset(port_id);
2699 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
2700 ports[port_id].tx_vlan_id = vlan_id;
2701 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2705 tx_vlan_reset(portid_t port_id)
2707 if (port_id_is_invalid(port_id, ENABLED_WARN))
2709 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
2710 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
2711 ports[port_id].tx_vlan_id = 0;
2712 ports[port_id].tx_vlan_id_outer = 0;
2716 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2718 if (port_id_is_invalid(port_id, ENABLED_WARN))
2721 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2725 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2728 uint8_t existing_mapping_found = 0;
2730 if (port_id_is_invalid(port_id, ENABLED_WARN))
2733 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2736 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2737 printf("map_value not in required range 0..%d\n",
2738 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2742 if (!is_rx) { /*then tx*/
2743 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2744 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2745 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2746 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2747 existing_mapping_found = 1;
2751 if (!existing_mapping_found) { /* A new additional mapping... */
2752 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2753 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2754 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2755 nb_tx_queue_stats_mappings++;
2759 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2760 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2761 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2762 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2763 existing_mapping_found = 1;
2767 if (!existing_mapping_found) { /* A new additional mapping... */
2768 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2769 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2770 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2771 nb_rx_queue_stats_mappings++;
2777 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2779 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2781 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2782 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2783 " tunnel_id: 0x%08x",
2784 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2785 rte_be_to_cpu_32(mask->tunnel_id_mask));
2786 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2787 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2788 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2789 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2791 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2792 rte_be_to_cpu_16(mask->src_port_mask),
2793 rte_be_to_cpu_16(mask->dst_port_mask));
2795 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2796 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2797 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
2798 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
2799 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
2801 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2802 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
2803 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
2804 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
2805 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
2812 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2814 struct rte_eth_flex_payload_cfg *cfg;
2817 for (i = 0; i < flex_conf->nb_payloads; i++) {
2818 cfg = &flex_conf->flex_set[i];
2819 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2821 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2822 printf("\n L2_PAYLOAD: ");
2823 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2824 printf("\n L3_PAYLOAD: ");
2825 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2826 printf("\n L4_PAYLOAD: ");
2828 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2829 for (j = 0; j < num; j++)
2830 printf(" %-5u", cfg->src_offset[j]);
2836 flowtype_to_str(uint16_t flow_type)
2838 struct flow_type_info {
2844 static struct flow_type_info flowtype_str_table[] = {
2845 {"raw", RTE_ETH_FLOW_RAW},
2846 {"ipv4", RTE_ETH_FLOW_IPV4},
2847 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2848 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2849 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2850 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2851 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2852 {"ipv6", RTE_ETH_FLOW_IPV6},
2853 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2854 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2855 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2856 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2857 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2858 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2859 {"port", RTE_ETH_FLOW_PORT},
2860 {"vxlan", RTE_ETH_FLOW_VXLAN},
2861 {"geneve", RTE_ETH_FLOW_GENEVE},
2862 {"nvgre", RTE_ETH_FLOW_NVGRE},
2865 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2866 if (flowtype_str_table[i].ftype == flow_type)
2867 return flowtype_str_table[i].str;
2874 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2876 struct rte_eth_fdir_flex_mask *mask;
2880 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2881 mask = &flex_conf->flex_mask[i];
2882 p = flowtype_to_str(mask->flow_type);
2883 printf("\n %s:\t", p ? p : "unknown");
2884 for (j = 0; j < num; j++)
2885 printf(" %02x", mask->mask[j]);
2891 print_fdir_flow_type(uint32_t flow_types_mask)
2896 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2897 if (!(flow_types_mask & (1 << i)))
2899 p = flowtype_to_str(i);
2909 fdir_get_infos(portid_t port_id)
2911 struct rte_eth_fdir_stats fdir_stat;
2912 struct rte_eth_fdir_info fdir_info;
2915 static const char *fdir_stats_border = "########################";
2917 if (port_id_is_invalid(port_id, ENABLED_WARN))
2919 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
2921 printf("\n FDIR is not supported on port %-2d\n",
2926 memset(&fdir_info, 0, sizeof(fdir_info));
2927 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2928 RTE_ETH_FILTER_INFO, &fdir_info);
2929 memset(&fdir_stat, 0, sizeof(fdir_stat));
2930 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2931 RTE_ETH_FILTER_STATS, &fdir_stat);
2932 printf("\n %s FDIR infos for port %-2d %s\n",
2933 fdir_stats_border, port_id, fdir_stats_border);
2935 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
2936 printf(" PERFECT\n");
2937 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2938 printf(" PERFECT-MAC-VLAN\n");
2939 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2940 printf(" PERFECT-TUNNEL\n");
2941 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
2942 printf(" SIGNATURE\n");
2944 printf(" DISABLE\n");
2945 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
2946 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
2947 printf(" SUPPORTED FLOW TYPE: ");
2948 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
2950 printf(" FLEX PAYLOAD INFO:\n");
2951 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
2952 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
2953 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
2954 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
2955 fdir_info.flex_payload_unit,
2956 fdir_info.max_flex_payload_segment_num,
2957 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
2959 print_fdir_mask(&fdir_info.mask);
2960 if (fdir_info.flex_conf.nb_payloads > 0) {
2961 printf(" FLEX PAYLOAD SRC OFFSET:");
2962 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2964 if (fdir_info.flex_conf.nb_flexmasks > 0) {
2965 printf(" FLEX MASK CFG:");
2966 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2968 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2969 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2970 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2971 fdir_info.guarant_spc, fdir_info.best_spc);
2972 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2973 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2974 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2975 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2976 fdir_stat.collision, fdir_stat.free,
2977 fdir_stat.maxhash, fdir_stat.maxlen,
2978 fdir_stat.add, fdir_stat.remove,
2979 fdir_stat.f_add, fdir_stat.f_remove);
2980 printf(" %s############################%s\n",
2981 fdir_stats_border, fdir_stats_border);
2985 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2987 struct rte_port *port;
2988 struct rte_eth_fdir_flex_conf *flex_conf;
2991 port = &ports[port_id];
2992 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2993 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2994 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2999 if (i >= RTE_ETH_FLOW_MAX) {
3000 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
3001 idx = flex_conf->nb_flexmasks;
3002 flex_conf->nb_flexmasks++;
3004 printf("The flex mask table is full. Can not set flex"
3005 " mask for flow_type(%u).", cfg->flow_type);
3009 rte_memcpy(&flex_conf->flex_mask[idx],
3011 sizeof(struct rte_eth_fdir_flex_mask));
3015 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3017 struct rte_port *port;
3018 struct rte_eth_fdir_flex_conf *flex_conf;
3021 port = &ports[port_id];
3022 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3023 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3024 if (cfg->type == flex_conf->flex_set[i].type) {
3029 if (i >= RTE_ETH_PAYLOAD_MAX) {
3030 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3031 idx = flex_conf->nb_payloads;
3032 flex_conf->nb_payloads++;
3034 printf("The flex payload table is full. Can not set"
3035 " flex payload for type(%u).", cfg->type);
3039 rte_memcpy(&flex_conf->flex_set[idx],
3041 sizeof(struct rte_eth_flex_payload_cfg));
3046 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3048 #ifdef RTE_LIBRTE_IXGBE_PMD
3052 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3054 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3058 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3059 is_rx ? "rx" : "tx", port_id, diag);
3062 printf("VF %s setting not supported for port %d\n",
3063 is_rx ? "Rx" : "Tx", port_id);
3069 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3072 struct rte_eth_link link;
3074 if (port_id_is_invalid(port_id, ENABLED_WARN))
3076 rte_eth_link_get_nowait(port_id, &link);
3077 if (rate > link.link_speed) {
3078 printf("Invalid rate value:%u bigger than link speed: %u\n",
3079 rate, link.link_speed);
3082 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3085 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3091 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3093 int diag = -ENOTSUP;
3095 #ifdef RTE_LIBRTE_IXGBE_PMD
3096 if (diag == -ENOTSUP)
3097 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3100 #ifdef RTE_LIBRTE_BNXT_PMD
3101 if (diag == -ENOTSUP)
3102 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3107 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3113 * Functions to manage the set of filtered Multicast MAC addresses.
3115 * A pool of filtered multicast MAC addresses is associated with each port.
3116 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3117 * The address of the pool and the number of valid multicast MAC addresses
3118 * recorded in the pool are stored in the fields "mc_addr_pool" and
3119 * "mc_addr_nb" of the "rte_port" data structure.
3121 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3122 * to be supplied a contiguous array of multicast MAC addresses.
3123 * To comply with this constraint, the set of multicast addresses recorded
3124 * into the pool are systematically compacted at the beginning of the pool.
3125 * Hence, when a multicast address is removed from the pool, all following
3126 * addresses, if any, are copied back to keep the set contiguous.
3128 #define MCAST_POOL_INC 32
3131 mcast_addr_pool_extend(struct rte_port *port)
3133 struct ether_addr *mc_pool;
3134 size_t mc_pool_size;
3137 * If a free entry is available at the end of the pool, just
3138 * increment the number of recorded multicast addresses.
3140 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3146 * [re]allocate a pool with MCAST_POOL_INC more entries.
3147 * The previous test guarantees that port->mc_addr_nb is a multiple
3148 * of MCAST_POOL_INC.
3150 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3152 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3154 if (mc_pool == NULL) {
3155 printf("allocation of pool of %u multicast addresses failed\n",
3156 port->mc_addr_nb + MCAST_POOL_INC);
3160 port->mc_addr_pool = mc_pool;
3167 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3170 if (addr_idx == port->mc_addr_nb) {
3171 /* No need to recompact the set of multicast addressses. */
3172 if (port->mc_addr_nb == 0) {
3173 /* free the pool of multicast addresses. */
3174 free(port->mc_addr_pool);
3175 port->mc_addr_pool = NULL;
3179 memmove(&port->mc_addr_pool[addr_idx],
3180 &port->mc_addr_pool[addr_idx + 1],
3181 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3185 eth_port_multicast_addr_list_set(uint8_t port_id)
3187 struct rte_port *port;
3190 port = &ports[port_id];
3191 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3195 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3196 port->mc_addr_nb, port_id, -diag);
3200 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
3202 struct rte_port *port;
3205 if (port_id_is_invalid(port_id, ENABLED_WARN))
3208 port = &ports[port_id];
3211 * Check that the added multicast MAC address is not already recorded
3212 * in the pool of multicast addresses.
3214 for (i = 0; i < port->mc_addr_nb; i++) {
3215 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3216 printf("multicast address already filtered by port\n");
3221 if (mcast_addr_pool_extend(port) != 0)
3223 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3224 eth_port_multicast_addr_list_set(port_id);
3228 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
3230 struct rte_port *port;
3233 if (port_id_is_invalid(port_id, ENABLED_WARN))
3236 port = &ports[port_id];
3239 * Search the pool of multicast MAC addresses for the removed address.
3241 for (i = 0; i < port->mc_addr_nb; i++) {
3242 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3245 if (i == port->mc_addr_nb) {
3246 printf("multicast address not filtered by port %d\n", port_id);
3250 mcast_addr_pool_remove(port, i);
3251 eth_port_multicast_addr_list_set(port_id);
3255 port_dcb_info_display(uint8_t port_id)
3257 struct rte_eth_dcb_info dcb_info;
3260 static const char *border = "================";
3262 if (port_id_is_invalid(port_id, ENABLED_WARN))
3265 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3267 printf("\n Failed to get dcb infos on port %-2d\n",
3271 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3272 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3274 for (i = 0; i < dcb_info.nb_tcs; i++)
3276 printf("\n Priority : ");
3277 for (i = 0; i < dcb_info.nb_tcs; i++)
3278 printf("\t%4d", dcb_info.prio_tc[i]);
3279 printf("\n BW percent :");
3280 for (i = 0; i < dcb_info.nb_tcs; i++)
3281 printf("\t%4d%%", dcb_info.tc_bws[i]);
3282 printf("\n RXQ base : ");
3283 for (i = 0; i < dcb_info.nb_tcs; i++)
3284 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3285 printf("\n RXQ number :");
3286 for (i = 0; i < dcb_info.nb_tcs; i++)
3287 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3288 printf("\n TXQ base : ");
3289 for (i = 0; i < dcb_info.nb_tcs; i++)
3290 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3291 printf("\n TXQ number :");
3292 for (i = 0; i < dcb_info.nb_tcs; i++)
3293 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3298 open_ddp_package_file(const char *file_path, uint32_t *size)
3300 FILE *fh = fopen(file_path, "rb");
3302 uint8_t *buf = NULL;
3309 printf("%s: Failed to open %s\n", __func__, file_path);
3313 ret = fseek(fh, 0, SEEK_END);
3316 printf("%s: File operations failed\n", __func__);
3320 pkg_size = ftell(fh);
3322 buf = (uint8_t *)malloc(pkg_size);
3325 printf("%s: Failed to malloc memory\n", __func__);
3329 ret = fseek(fh, 0, SEEK_SET);
3332 printf("%s: File seek operation failed\n", __func__);
3333 close_ddp_package_file(buf);
3337 ret = fread(buf, 1, pkg_size, fh);
3340 printf("%s: File read operation failed\n", __func__);
3341 close_ddp_package_file(buf);
3354 save_ddp_package_file(const char *file_path, uint8_t *buf, uint32_t size)
3356 FILE *fh = fopen(file_path, "wb");
3359 printf("%s: Failed to open %s\n", __func__, file_path);
3363 if (fwrite(buf, 1, size, fh) != size) {
3365 printf("%s: File write operation failed\n", __func__);
3375 close_ddp_package_file(uint8_t *buf)