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.
43 #include <sys/queue.h>
45 #include <rte_common.h>
46 #include <rte_byteorder.h>
47 #include <rte_debug.h>
49 #include <rte_memory.h>
50 #include <rte_memcpy.h>
51 #include <rte_memzone.h>
52 #include <rte_launch.h>
54 #include <rte_per_lcore.h>
55 #include <rte_lcore.h>
56 #include <rte_atomic.h>
57 #include <rte_branch_prediction.h>
58 #include <rte_mempool.h>
60 #include <rte_interrupts.h>
62 #include <rte_ether.h>
63 #include <rte_ethdev.h>
64 #include <rte_string_fns.h>
65 #include <rte_cycles.h>
67 #include <rte_errno.h>
68 #ifdef RTE_LIBRTE_IXGBE_PMD
69 #include <rte_pmd_ixgbe.h>
71 #ifdef RTE_LIBRTE_BNXT_PMD
72 #include <rte_pmd_bnxt.h>
78 static char *flowtype_to_str(uint16_t flow_type);
81 enum tx_pkt_split split;
85 .split = TX_PKT_SPLIT_OFF,
89 .split = TX_PKT_SPLIT_ON,
93 .split = TX_PKT_SPLIT_RND,
98 struct rss_type_info {
103 static const struct rss_type_info rss_type_table[] = {
104 { "ipv4", ETH_RSS_IPV4 },
105 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
106 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
107 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
108 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
109 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
110 { "ipv6", ETH_RSS_IPV6 },
111 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
112 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
113 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
114 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
115 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
116 { "l2-payload", ETH_RSS_L2_PAYLOAD },
117 { "ipv6-ex", ETH_RSS_IPV6_EX },
118 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
119 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
120 { "port", ETH_RSS_PORT },
121 { "vxlan", ETH_RSS_VXLAN },
122 { "geneve", ETH_RSS_GENEVE },
123 { "nvgre", ETH_RSS_NVGRE },
128 print_ethaddr(const char *name, struct ether_addr *eth_addr)
130 char buf[ETHER_ADDR_FMT_SIZE];
131 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
132 printf("%s%s", name, buf);
136 nic_stats_display(portid_t port_id)
138 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
139 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
140 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
141 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles;
142 uint64_t mpps_rx, mpps_tx;
143 struct rte_eth_stats stats;
144 struct rte_port *port = &ports[port_id];
148 static const char *nic_stats_border = "########################";
150 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
151 printf("Valid port range is [0");
152 RTE_ETH_FOREACH_DEV(pid)
157 rte_eth_stats_get(port_id, &stats);
158 printf("\n %s NIC statistics for port %-2d %s\n",
159 nic_stats_border, port_id, nic_stats_border);
161 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
162 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
164 stats.ipackets, stats.imissed, stats.ibytes);
165 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
166 printf(" RX-nombuf: %-10"PRIu64"\n",
168 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
170 stats.opackets, stats.oerrors, stats.obytes);
173 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
174 " RX-bytes: %10"PRIu64"\n",
175 stats.ipackets, stats.ierrors, stats.ibytes);
176 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
177 printf(" RX-nombuf: %10"PRIu64"\n",
179 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
180 " TX-bytes: %10"PRIu64"\n",
181 stats.opackets, stats.oerrors, stats.obytes);
184 if (port->rx_queue_stats_mapping_enabled) {
186 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
187 printf(" Stats reg %2d RX-packets: %10"PRIu64
188 " RX-errors: %10"PRIu64
189 " RX-bytes: %10"PRIu64"\n",
190 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
193 if (port->tx_queue_stats_mapping_enabled) {
195 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
196 printf(" Stats reg %2d TX-packets: %10"PRIu64
197 " TX-bytes: %10"PRIu64"\n",
198 i, stats.q_opackets[i], stats.q_obytes[i]);
202 diff_cycles = prev_cycles[port_id];
203 prev_cycles[port_id] = rte_rdtsc();
205 diff_cycles = prev_cycles[port_id] - diff_cycles;
207 diff_pkts_rx = stats.ipackets - prev_pkts_rx[port_id];
208 diff_pkts_tx = stats.opackets - prev_pkts_tx[port_id];
209 prev_pkts_rx[port_id] = stats.ipackets;
210 prev_pkts_tx[port_id] = stats.opackets;
211 mpps_rx = diff_cycles > 0 ?
212 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
213 mpps_tx = diff_cycles > 0 ?
214 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
215 printf("\n Throughput (since last show)\n");
216 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
219 printf(" %s############################%s\n",
220 nic_stats_border, nic_stats_border);
224 nic_stats_clear(portid_t port_id)
228 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
229 printf("Valid port range is [0");
230 RTE_ETH_FOREACH_DEV(pid)
235 rte_eth_stats_reset(port_id);
236 printf("\n NIC statistics for port %d cleared\n", port_id);
240 nic_xstats_display(portid_t port_id)
242 struct rte_eth_xstat *xstats;
243 int cnt_xstats, idx_xstat;
244 struct rte_eth_xstat_name *xstats_names;
246 printf("###### NIC extended statistics for port %-2d\n", port_id);
247 if (!rte_eth_dev_is_valid_port(port_id)) {
248 printf("Error: Invalid port number %i\n", port_id);
253 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
254 if (cnt_xstats < 0) {
255 printf("Error: Cannot get count of xstats\n");
259 /* Get id-name lookup table */
260 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
261 if (xstats_names == NULL) {
262 printf("Cannot allocate memory for xstats lookup\n");
265 if (cnt_xstats != rte_eth_xstats_get_names(
266 port_id, xstats_names, cnt_xstats)) {
267 printf("Error: Cannot get xstats lookup\n");
272 /* Get stats themselves */
273 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
274 if (xstats == NULL) {
275 printf("Cannot allocate memory for xstats\n");
279 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
280 printf("Error: Unable to get xstats\n");
287 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
288 printf("%s: %"PRIu64"\n",
289 xstats_names[idx_xstat].name,
290 xstats[idx_xstat].value);
296 nic_xstats_clear(portid_t port_id)
298 rte_eth_xstats_reset(port_id);
302 nic_stats_mapping_display(portid_t port_id)
304 struct rte_port *port = &ports[port_id];
308 static const char *nic_stats_mapping_border = "########################";
310 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
311 printf("Valid port range is [0");
312 RTE_ETH_FOREACH_DEV(pid)
318 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
319 printf("Port id %d - either does not support queue statistic mapping or"
320 " no queue statistic mapping set\n", port_id);
324 printf("\n %s NIC statistics mapping for port %-2d %s\n",
325 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
327 if (port->rx_queue_stats_mapping_enabled) {
328 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
329 if (rx_queue_stats_mappings[i].port_id == port_id) {
330 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
331 rx_queue_stats_mappings[i].queue_id,
332 rx_queue_stats_mappings[i].stats_counter_id);
339 if (port->tx_queue_stats_mapping_enabled) {
340 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
341 if (tx_queue_stats_mappings[i].port_id == port_id) {
342 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
343 tx_queue_stats_mappings[i].queue_id,
344 tx_queue_stats_mappings[i].stats_counter_id);
349 printf(" %s####################################%s\n",
350 nic_stats_mapping_border, nic_stats_mapping_border);
354 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
356 struct rte_eth_rxq_info qinfo;
358 static const char *info_border = "*********************";
360 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
362 printf("Failed to retrieve information for port: %hhu, "
363 "RX queue: %hu\nerror desc: %s(%d)\n",
364 port_id, queue_id, strerror(-rc), rc);
368 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
369 info_border, port_id, queue_id, info_border);
371 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
372 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
373 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
374 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
375 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
376 printf("\nRX drop packets: %s",
377 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
378 printf("\nRX deferred start: %s",
379 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
380 printf("\nRX scattered packets: %s",
381 (qinfo.scattered_rx != 0) ? "on" : "off");
382 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
387 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
389 struct rte_eth_txq_info qinfo;
391 static const char *info_border = "*********************";
393 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
395 printf("Failed to retrieve information for port: %hhu, "
396 "TX queue: %hu\nerror desc: %s(%d)\n",
397 port_id, queue_id, strerror(-rc), rc);
401 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
402 info_border, port_id, queue_id, info_border);
404 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
405 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
406 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
407 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
408 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
409 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
410 printf("\nTX deferred start: %s",
411 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
412 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
417 port_infos_display(portid_t port_id)
419 struct rte_port *port;
420 struct ether_addr mac_addr;
421 struct rte_eth_link link;
422 struct rte_eth_dev_info dev_info;
424 struct rte_mempool * mp;
425 static const char *info_border = "*********************";
429 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
430 printf("Valid port range is [0");
431 RTE_ETH_FOREACH_DEV(pid)
436 port = &ports[port_id];
437 rte_eth_link_get_nowait(port_id, &link);
438 memset(&dev_info, 0, sizeof(dev_info));
439 rte_eth_dev_info_get(port_id, &dev_info);
440 printf("\n%s Infos for port %-2d %s\n",
441 info_border, port_id, info_border);
442 rte_eth_macaddr_get(port_id, &mac_addr);
443 print_ethaddr("MAC address: ", &mac_addr);
444 printf("\nDriver name: %s", dev_info.driver_name);
445 printf("\nConnect to socket: %u", port->socket_id);
447 if (port_numa[port_id] != NUMA_NO_CONFIG) {
448 mp = mbuf_pool_find(port_numa[port_id]);
450 printf("\nmemory allocation on the socket: %d",
453 printf("\nmemory allocation on the socket: %u",port->socket_id);
455 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
456 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
457 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
458 ("full-duplex") : ("half-duplex"));
460 if (!rte_eth_dev_get_mtu(port_id, &mtu))
461 printf("MTU: %u\n", mtu);
463 printf("Promiscuous mode: %s\n",
464 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
465 printf("Allmulticast mode: %s\n",
466 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
467 printf("Maximum number of MAC addresses: %u\n",
468 (unsigned int)(port->dev_info.max_mac_addrs));
469 printf("Maximum number of MAC addresses of hash filtering: %u\n",
470 (unsigned int)(port->dev_info.max_hash_mac_addrs));
472 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
473 if (vlan_offload >= 0){
474 printf("VLAN offload: \n");
475 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
476 printf(" strip on \n");
478 printf(" strip off \n");
480 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
481 printf(" filter on \n");
483 printf(" filter off \n");
485 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
486 printf(" qinq(extend) on \n");
488 printf(" qinq(extend) off \n");
491 if (dev_info.hash_key_size > 0)
492 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
493 if (dev_info.reta_size > 0)
494 printf("Redirection table size: %u\n", dev_info.reta_size);
495 if (!dev_info.flow_type_rss_offloads)
496 printf("No flow type is supported.\n");
501 printf("Supported flow types:\n");
502 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
504 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
506 p = flowtype_to_str(i);
507 printf(" %s\n", (p ? p : "unknown"));
511 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
512 printf("Max possible number of RXDs per queue: %hu\n",
513 dev_info.rx_desc_lim.nb_max);
514 printf("Min possible number of RXDs per queue: %hu\n",
515 dev_info.rx_desc_lim.nb_min);
516 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
518 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
519 printf("Max possible number of TXDs per queue: %hu\n",
520 dev_info.tx_desc_lim.nb_max);
521 printf("Min possible number of TXDs per queue: %hu\n",
522 dev_info.tx_desc_lim.nb_min);
523 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
527 port_offload_cap_display(portid_t port_id)
529 struct rte_eth_dev *dev;
530 struct rte_eth_dev_info dev_info;
531 static const char *info_border = "************";
533 if (port_id_is_invalid(port_id, ENABLED_WARN))
536 dev = &rte_eth_devices[port_id];
537 rte_eth_dev_info_get(port_id, &dev_info);
539 printf("\n%s Port %d supported offload features: %s\n",
540 info_border, port_id, info_border);
542 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
543 printf("VLAN stripped: ");
544 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
550 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
551 printf("Double VLANs stripped: ");
552 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
558 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
559 printf("RX IPv4 checksum: ");
560 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
566 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
567 printf("RX UDP checksum: ");
568 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
574 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
575 printf("RX TCP checksum: ");
576 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
582 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
583 printf("RX Outer IPv4 checksum: on");
585 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
586 printf("Large receive offload: ");
587 if (dev->data->dev_conf.rxmode.enable_lro)
593 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
594 printf("VLAN insert: ");
595 if (ports[port_id].tx_ol_flags &
596 TESTPMD_TX_OFFLOAD_INSERT_VLAN)
602 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
603 printf("Double VLANs insert: ");
604 if (ports[port_id].tx_ol_flags &
605 TESTPMD_TX_OFFLOAD_INSERT_QINQ)
611 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
612 printf("TX IPv4 checksum: ");
613 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
619 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
620 printf("TX UDP checksum: ");
621 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
627 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
628 printf("TX TCP checksum: ");
629 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
635 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
636 printf("TX SCTP checksum: ");
637 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
643 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
644 printf("TX Outer IPv4 checksum: ");
645 if (ports[port_id].tx_ol_flags &
646 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
652 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
653 printf("TX TCP segmentation: ");
654 if (ports[port_id].tso_segsz != 0)
660 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
661 printf("TX UDP segmentation: ");
662 if (ports[port_id].tso_segsz != 0)
668 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
669 printf("TSO for VXLAN tunnel packet: ");
670 if (ports[port_id].tunnel_tso_segsz)
676 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
677 printf("TSO for GRE tunnel packet: ");
678 if (ports[port_id].tunnel_tso_segsz)
684 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
685 printf("TSO for IPIP tunnel packet: ");
686 if (ports[port_id].tunnel_tso_segsz)
692 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
693 printf("TSO for GENEVE tunnel packet: ");
694 if (ports[port_id].tunnel_tso_segsz)
703 port_id_is_invalid(portid_t port_id, enum print_warning warning)
705 if (port_id == (portid_t)RTE_PORT_ALL)
708 if (rte_eth_dev_is_valid_port(port_id))
711 if (warning == ENABLED_WARN)
712 printf("Invalid port %d\n", port_id);
718 vlan_id_is_invalid(uint16_t vlan_id)
722 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
727 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
732 printf("Port register offset 0x%X not aligned on a 4-byte "
737 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
738 if (reg_off >= pci_len) {
739 printf("Port %d: register offset %u (0x%X) out of port PCI "
740 "resource (length=%"PRIu64")\n",
741 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
748 reg_bit_pos_is_invalid(uint8_t bit_pos)
752 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
756 #define display_port_and_reg_off(port_id, reg_off) \
757 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
760 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
762 display_port_and_reg_off(port_id, (unsigned)reg_off);
763 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
767 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
772 if (port_id_is_invalid(port_id, ENABLED_WARN))
774 if (port_reg_off_is_invalid(port_id, reg_off))
776 if (reg_bit_pos_is_invalid(bit_x))
778 reg_v = port_id_pci_reg_read(port_id, reg_off);
779 display_port_and_reg_off(port_id, (unsigned)reg_off);
780 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
784 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
785 uint8_t bit1_pos, uint8_t bit2_pos)
791 if (port_id_is_invalid(port_id, ENABLED_WARN))
793 if (port_reg_off_is_invalid(port_id, reg_off))
795 if (reg_bit_pos_is_invalid(bit1_pos))
797 if (reg_bit_pos_is_invalid(bit2_pos))
799 if (bit1_pos > bit2_pos)
800 l_bit = bit2_pos, h_bit = bit1_pos;
802 l_bit = bit1_pos, h_bit = bit2_pos;
804 reg_v = port_id_pci_reg_read(port_id, reg_off);
807 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
808 display_port_and_reg_off(port_id, (unsigned)reg_off);
809 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
810 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
814 port_reg_display(portid_t port_id, uint32_t reg_off)
818 if (port_id_is_invalid(port_id, ENABLED_WARN))
820 if (port_reg_off_is_invalid(port_id, reg_off))
822 reg_v = port_id_pci_reg_read(port_id, reg_off);
823 display_port_reg_value(port_id, reg_off, reg_v);
827 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
832 if (port_id_is_invalid(port_id, ENABLED_WARN))
834 if (port_reg_off_is_invalid(port_id, reg_off))
836 if (reg_bit_pos_is_invalid(bit_pos))
839 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
842 reg_v = port_id_pci_reg_read(port_id, reg_off);
844 reg_v &= ~(1 << bit_pos);
846 reg_v |= (1 << bit_pos);
847 port_id_pci_reg_write(port_id, reg_off, reg_v);
848 display_port_reg_value(port_id, reg_off, reg_v);
852 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
853 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
860 if (port_id_is_invalid(port_id, ENABLED_WARN))
862 if (port_reg_off_is_invalid(port_id, reg_off))
864 if (reg_bit_pos_is_invalid(bit1_pos))
866 if (reg_bit_pos_is_invalid(bit2_pos))
868 if (bit1_pos > bit2_pos)
869 l_bit = bit2_pos, h_bit = bit1_pos;
871 l_bit = bit1_pos, h_bit = bit2_pos;
873 if ((h_bit - l_bit) < 31)
874 max_v = (1 << (h_bit - l_bit + 1)) - 1;
879 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
880 (unsigned)value, (unsigned)value,
881 (unsigned)max_v, (unsigned)max_v);
884 reg_v = port_id_pci_reg_read(port_id, reg_off);
885 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
886 reg_v |= (value << l_bit); /* Set changed bits */
887 port_id_pci_reg_write(port_id, reg_off, reg_v);
888 display_port_reg_value(port_id, reg_off, reg_v);
892 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
894 if (port_id_is_invalid(port_id, ENABLED_WARN))
896 if (port_reg_off_is_invalid(port_id, reg_off))
898 port_id_pci_reg_write(port_id, reg_off, reg_v);
899 display_port_reg_value(port_id, reg_off, reg_v);
903 port_mtu_set(portid_t port_id, uint16_t mtu)
907 if (port_id_is_invalid(port_id, ENABLED_WARN))
909 diag = rte_eth_dev_set_mtu(port_id, mtu);
912 printf("Set MTU failed. diag=%d\n", diag);
915 /* Generic flow management functions. */
917 /** Generate flow_item[] entry. */
918 #define MK_FLOW_ITEM(t, s) \
919 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
924 /** Information about known flow pattern items. */
925 static const struct {
929 MK_FLOW_ITEM(END, 0),
930 MK_FLOW_ITEM(VOID, 0),
931 MK_FLOW_ITEM(INVERT, 0),
932 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
934 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
935 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
936 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
937 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
938 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
939 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
940 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
941 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
942 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
943 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
944 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
945 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
946 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
947 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
948 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
949 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
950 MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
953 /** Compute storage space needed by item specification. */
955 flow_item_spec_size(const struct rte_flow_item *item,
956 size_t *size, size_t *pad)
960 switch (item->type) {
962 const struct rte_flow_item_raw *raw;
965 case RTE_FLOW_ITEM_TYPE_RAW:
966 spec.raw = item->spec;
967 *size = offsetof(struct rte_flow_item_raw, pattern) +
968 spec.raw->length * sizeof(*spec.raw->pattern);
975 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
978 /** Generate flow_action[] entry. */
979 #define MK_FLOW_ACTION(t, s) \
980 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
985 /** Information about known flow actions. */
986 static const struct {
990 MK_FLOW_ACTION(END, 0),
991 MK_FLOW_ACTION(VOID, 0),
992 MK_FLOW_ACTION(PASSTHRU, 0),
993 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
994 MK_FLOW_ACTION(FLAG, 0),
995 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
996 MK_FLOW_ACTION(DROP, 0),
997 MK_FLOW_ACTION(COUNT, 0),
998 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
999 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
1000 MK_FLOW_ACTION(PF, 0),
1001 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1004 /** Compute storage space needed by action configuration. */
1006 flow_action_conf_size(const struct rte_flow_action *action,
1007 size_t *size, size_t *pad)
1011 switch (action->type) {
1013 const struct rte_flow_action_rss *rss;
1016 case RTE_FLOW_ACTION_TYPE_RSS:
1017 conf.rss = action->conf;
1018 *size = offsetof(struct rte_flow_action_rss, queue) +
1019 conf.rss->num * sizeof(*conf.rss->queue);
1026 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1029 /** Generate a port_flow entry from attributes/pattern/actions. */
1030 static struct port_flow *
1031 port_flow_new(const struct rte_flow_attr *attr,
1032 const struct rte_flow_item *pattern,
1033 const struct rte_flow_action *actions)
1035 const struct rte_flow_item *item;
1036 const struct rte_flow_action *action;
1037 struct port_flow *pf = NULL;
1047 pf->pattern = (void *)&pf->data[off1];
1049 struct rte_flow_item *dst = NULL;
1051 if ((unsigned int)item->type >= RTE_DIM(flow_item) ||
1052 !flow_item[item->type].name)
1055 dst = memcpy(pf->data + off1, item, sizeof(*item));
1056 off1 += sizeof(*item);
1057 flow_item_spec_size(item, &tmp, &pad);
1060 dst->spec = memcpy(pf->data + off2,
1066 dst->last = memcpy(pf->data + off2,
1072 dst->mask = memcpy(pf->data + off2,
1076 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1077 } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
1078 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1081 pf->actions = (void *)&pf->data[off1];
1083 struct rte_flow_action *dst = NULL;
1085 if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
1086 !flow_action[action->type].name)
1089 dst = memcpy(pf->data + off1, action, sizeof(*action));
1090 off1 += sizeof(*action);
1091 flow_action_conf_size(action, &tmp, &pad);
1094 dst->conf = memcpy(pf->data + off2,
1098 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1099 } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
1102 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1103 tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double));
1104 pf = calloc(1, tmp + off1 + off2);
1108 *pf = (const struct port_flow){
1109 .size = tmp + off1 + off2,
1112 tmp -= offsetof(struct port_flow, data);
1122 /** Print a message out of a flow error. */
1124 port_flow_complain(struct rte_flow_error *error)
1126 static const char *const errstrlist[] = {
1127 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1128 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1129 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1130 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1131 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1132 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1133 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1134 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1135 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1136 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1137 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1138 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1142 int err = rte_errno;
1144 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1145 !errstrlist[error->type])
1146 errstr = "unknown type";
1148 errstr = errstrlist[error->type];
1149 printf("Caught error type %d (%s): %s%s\n",
1150 error->type, errstr,
1151 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1152 error->cause), buf) : "",
1153 error->message ? error->message : "(no stated reason)");
1157 /** Validate flow rule. */
1159 port_flow_validate(portid_t port_id,
1160 const struct rte_flow_attr *attr,
1161 const struct rte_flow_item *pattern,
1162 const struct rte_flow_action *actions)
1164 struct rte_flow_error error;
1166 /* Poisoning to make sure PMDs update it in case of error. */
1167 memset(&error, 0x11, sizeof(error));
1168 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1169 return port_flow_complain(&error);
1170 printf("Flow rule validated\n");
1174 /** Create flow rule. */
1176 port_flow_create(portid_t port_id,
1177 const struct rte_flow_attr *attr,
1178 const struct rte_flow_item *pattern,
1179 const struct rte_flow_action *actions)
1181 struct rte_flow *flow;
1182 struct rte_port *port;
1183 struct port_flow *pf;
1185 struct rte_flow_error error;
1187 /* Poisoning to make sure PMDs update it in case of error. */
1188 memset(&error, 0x22, sizeof(error));
1189 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1191 return port_flow_complain(&error);
1192 port = &ports[port_id];
1193 if (port->flow_list) {
1194 if (port->flow_list->id == UINT32_MAX) {
1195 printf("Highest rule ID is already assigned, delete"
1197 rte_flow_destroy(port_id, flow, NULL);
1200 id = port->flow_list->id + 1;
1203 pf = port_flow_new(attr, pattern, actions);
1205 int err = rte_errno;
1207 printf("Cannot allocate flow: %s\n", rte_strerror(err));
1208 rte_flow_destroy(port_id, flow, NULL);
1211 pf->next = port->flow_list;
1214 port->flow_list = pf;
1215 printf("Flow rule #%u created\n", pf->id);
1219 /** Destroy a number of flow rules. */
1221 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1223 struct rte_port *port;
1224 struct port_flow **tmp;
1228 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1229 port_id == (portid_t)RTE_PORT_ALL)
1231 port = &ports[port_id];
1232 tmp = &port->flow_list;
1236 for (i = 0; i != n; ++i) {
1237 struct rte_flow_error error;
1238 struct port_flow *pf = *tmp;
1240 if (rule[i] != pf->id)
1243 * Poisoning to make sure PMDs update it in case
1246 memset(&error, 0x33, sizeof(error));
1247 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1248 ret = port_flow_complain(&error);
1251 printf("Flow rule #%u destroyed\n", pf->id);
1257 tmp = &(*tmp)->next;
1263 /** Remove all flow rules. */
1265 port_flow_flush(portid_t port_id)
1267 struct rte_flow_error error;
1268 struct rte_port *port;
1271 /* Poisoning to make sure PMDs update it in case of error. */
1272 memset(&error, 0x44, sizeof(error));
1273 if (rte_flow_flush(port_id, &error)) {
1274 ret = port_flow_complain(&error);
1275 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1276 port_id == (portid_t)RTE_PORT_ALL)
1279 port = &ports[port_id];
1280 while (port->flow_list) {
1281 struct port_flow *pf = port->flow_list->next;
1283 free(port->flow_list);
1284 port->flow_list = pf;
1289 /** Query a flow rule. */
1291 port_flow_query(portid_t port_id, uint32_t rule,
1292 enum rte_flow_action_type action)
1294 struct rte_flow_error error;
1295 struct rte_port *port;
1296 struct port_flow *pf;
1299 struct rte_flow_query_count count;
1302 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1303 port_id == (portid_t)RTE_PORT_ALL)
1305 port = &ports[port_id];
1306 for (pf = port->flow_list; pf; pf = pf->next)
1310 printf("Flow rule #%u not found\n", rule);
1313 if ((unsigned int)action >= RTE_DIM(flow_action) ||
1314 !flow_action[action].name)
1317 name = flow_action[action].name;
1319 case RTE_FLOW_ACTION_TYPE_COUNT:
1322 printf("Cannot query action type %d (%s)\n", action, name);
1325 /* Poisoning to make sure PMDs update it in case of error. */
1326 memset(&error, 0x55, sizeof(error));
1327 memset(&query, 0, sizeof(query));
1328 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1329 return port_flow_complain(&error);
1331 case RTE_FLOW_ACTION_TYPE_COUNT:
1335 " hits: %" PRIu64 "\n"
1336 " bytes: %" PRIu64 "\n",
1338 query.count.hits_set,
1339 query.count.bytes_set,
1344 printf("Cannot display result for action type %d (%s)\n",
1351 /** List flow rules. */
1353 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1355 struct rte_port *port;
1356 struct port_flow *pf;
1357 struct port_flow *list = NULL;
1360 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1361 port_id == (portid_t)RTE_PORT_ALL)
1363 port = &ports[port_id];
1364 if (!port->flow_list)
1366 /* Sort flows by group, priority and ID. */
1367 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1368 struct port_flow **tmp;
1371 /* Filter out unwanted groups. */
1372 for (i = 0; i != n; ++i)
1373 if (pf->attr.group == group[i])
1380 (pf->attr.group > (*tmp)->attr.group ||
1381 (pf->attr.group == (*tmp)->attr.group &&
1382 pf->attr.priority > (*tmp)->attr.priority) ||
1383 (pf->attr.group == (*tmp)->attr.group &&
1384 pf->attr.priority == (*tmp)->attr.priority &&
1385 pf->id > (*tmp)->id)))
1390 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1391 for (pf = list; pf != NULL; pf = pf->tmp) {
1392 const struct rte_flow_item *item = pf->pattern;
1393 const struct rte_flow_action *action = pf->actions;
1395 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t",
1399 pf->attr.ingress ? 'i' : '-',
1400 pf->attr.egress ? 'e' : '-');
1401 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1402 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1403 printf("%s ", flow_item[item->type].name);
1407 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1408 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1409 printf(" %s", flow_action[action->type].name);
1416 /** Restrict ingress traffic to the defined flow rules. */
1418 port_flow_isolate(portid_t port_id, int set)
1420 struct rte_flow_error error;
1422 /* Poisoning to make sure PMDs update it in case of error. */
1423 memset(&error, 0x66, sizeof(error));
1424 if (rte_flow_isolate(port_id, set, &error))
1425 return port_flow_complain(&error);
1426 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1428 set ? "now restricted" : "not restricted anymore");
1433 * RX/TX ring descriptors display functions.
1436 rx_queue_id_is_invalid(queueid_t rxq_id)
1438 if (rxq_id < nb_rxq)
1440 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1445 tx_queue_id_is_invalid(queueid_t txq_id)
1447 if (txq_id < nb_txq)
1449 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1454 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1456 if (rxdesc_id < nb_rxd)
1458 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1464 tx_desc_id_is_invalid(uint16_t txdesc_id)
1466 if (txdesc_id < nb_txd)
1468 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1473 static const struct rte_memzone *
1474 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
1476 char mz_name[RTE_MEMZONE_NAMESIZE];
1477 const struct rte_memzone *mz;
1479 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1480 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1481 mz = rte_memzone_lookup(mz_name);
1483 printf("%s ring memory zoneof (port %d, queue %d) not"
1484 "found (zone name = %s\n",
1485 ring_name, port_id, q_id, mz_name);
1489 union igb_ring_dword {
1492 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1502 struct igb_ring_desc_32_bytes {
1503 union igb_ring_dword lo_dword;
1504 union igb_ring_dword hi_dword;
1505 union igb_ring_dword resv1;
1506 union igb_ring_dword resv2;
1509 struct igb_ring_desc_16_bytes {
1510 union igb_ring_dword lo_dword;
1511 union igb_ring_dword hi_dword;
1515 ring_rxd_display_dword(union igb_ring_dword dword)
1517 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1518 (unsigned)dword.words.hi);
1522 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1523 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1526 __rte_unused uint8_t port_id,
1530 struct igb_ring_desc_16_bytes *ring =
1531 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1532 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1533 struct rte_eth_dev_info dev_info;
1535 memset(&dev_info, 0, sizeof(dev_info));
1536 rte_eth_dev_info_get(port_id, &dev_info);
1537 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1538 /* 32 bytes RX descriptor, i40e only */
1539 struct igb_ring_desc_32_bytes *ring =
1540 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1541 ring[desc_id].lo_dword.dword =
1542 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1543 ring_rxd_display_dword(ring[desc_id].lo_dword);
1544 ring[desc_id].hi_dword.dword =
1545 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1546 ring_rxd_display_dword(ring[desc_id].hi_dword);
1547 ring[desc_id].resv1.dword =
1548 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1549 ring_rxd_display_dword(ring[desc_id].resv1);
1550 ring[desc_id].resv2.dword =
1551 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1552 ring_rxd_display_dword(ring[desc_id].resv2);
1557 /* 16 bytes RX descriptor */
1558 ring[desc_id].lo_dword.dword =
1559 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1560 ring_rxd_display_dword(ring[desc_id].lo_dword);
1561 ring[desc_id].hi_dword.dword =
1562 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1563 ring_rxd_display_dword(ring[desc_id].hi_dword);
1567 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1569 struct igb_ring_desc_16_bytes *ring;
1570 struct igb_ring_desc_16_bytes txd;
1572 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1573 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1574 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1575 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1576 (unsigned)txd.lo_dword.words.lo,
1577 (unsigned)txd.lo_dword.words.hi,
1578 (unsigned)txd.hi_dword.words.lo,
1579 (unsigned)txd.hi_dword.words.hi);
1583 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1585 const struct rte_memzone *rx_mz;
1587 if (port_id_is_invalid(port_id, ENABLED_WARN))
1589 if (rx_queue_id_is_invalid(rxq_id))
1591 if (rx_desc_id_is_invalid(rxd_id))
1593 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1596 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1600 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1602 const struct rte_memzone *tx_mz;
1604 if (port_id_is_invalid(port_id, ENABLED_WARN))
1606 if (tx_queue_id_is_invalid(txq_id))
1608 if (tx_desc_id_is_invalid(txd_id))
1610 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1613 ring_tx_descriptor_display(tx_mz, txd_id);
1617 fwd_lcores_config_display(void)
1621 printf("List of forwarding lcores:");
1622 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1623 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1627 rxtx_config_display(void)
1629 printf(" %s packet forwarding%s - CRC stripping %s - "
1630 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
1631 retry_enabled == 0 ? "" : " with retry",
1632 rx_mode.hw_strip_crc ? "enabled" : "disabled",
1635 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1636 printf(" packet len=%u - nb packet segments=%d\n",
1637 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1639 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
1640 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
1642 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1643 nb_fwd_lcores, nb_fwd_ports);
1644 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1645 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1646 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1647 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
1648 rx_conf->rx_thresh.wthresh);
1649 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1650 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1651 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1652 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
1653 tx_conf->tx_thresh.wthresh);
1654 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
1655 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
1659 port_rss_reta_info(portid_t port_id,
1660 struct rte_eth_rss_reta_entry64 *reta_conf,
1661 uint16_t nb_entries)
1663 uint16_t i, idx, shift;
1666 if (port_id_is_invalid(port_id, ENABLED_WARN))
1669 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1671 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1675 for (i = 0; i < nb_entries; i++) {
1676 idx = i / RTE_RETA_GROUP_SIZE;
1677 shift = i % RTE_RETA_GROUP_SIZE;
1678 if (!(reta_conf[idx].mask & (1ULL << shift)))
1680 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1681 i, reta_conf[idx].reta[shift]);
1686 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1690 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1692 struct rte_eth_rss_conf rss_conf;
1693 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1697 struct rte_eth_dev_info dev_info;
1698 uint8_t hash_key_size;
1700 if (port_id_is_invalid(port_id, ENABLED_WARN))
1703 memset(&dev_info, 0, sizeof(dev_info));
1704 rte_eth_dev_info_get(port_id, &dev_info);
1705 if (dev_info.hash_key_size > 0 &&
1706 dev_info.hash_key_size <= sizeof(rss_key))
1707 hash_key_size = dev_info.hash_key_size;
1709 printf("dev_info did not provide a valid hash key size\n");
1713 rss_conf.rss_hf = 0;
1714 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1715 if (!strcmp(rss_info, rss_type_table[i].str))
1716 rss_conf.rss_hf = rss_type_table[i].rss_type;
1719 /* Get RSS hash key if asked to display it */
1720 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1721 rss_conf.rss_key_len = hash_key_size;
1722 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1726 printf("port index %d invalid\n", port_id);
1729 printf("operation not supported by device\n");
1732 printf("operation failed - diag=%d\n", diag);
1737 rss_hf = rss_conf.rss_hf;
1739 printf("RSS disabled\n");
1742 printf("RSS functions:\n ");
1743 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1744 if (rss_hf & rss_type_table[i].rss_type)
1745 printf("%s ", rss_type_table[i].str);
1750 printf("RSS key:\n");
1751 for (i = 0; i < hash_key_size; i++)
1752 printf("%02X", rss_key[i]);
1757 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1760 struct rte_eth_rss_conf rss_conf;
1764 rss_conf.rss_key = NULL;
1765 rss_conf.rss_key_len = hash_key_len;
1766 rss_conf.rss_hf = 0;
1767 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1768 if (!strcmp(rss_type_table[i].str, rss_type))
1769 rss_conf.rss_hf = rss_type_table[i].rss_type;
1771 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1773 rss_conf.rss_key = hash_key;
1774 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1781 printf("port index %d invalid\n", port_id);
1784 printf("operation not supported by device\n");
1787 printf("operation failed - diag=%d\n", diag);
1793 * Setup forwarding configuration for each logical core.
1796 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1798 streamid_t nb_fs_per_lcore;
1806 nb_fs = cfg->nb_fwd_streams;
1807 nb_fc = cfg->nb_fwd_lcores;
1808 if (nb_fs <= nb_fc) {
1809 nb_fs_per_lcore = 1;
1812 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1813 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1816 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1818 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1819 fwd_lcores[lc_id]->stream_idx = sm_id;
1820 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1821 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1825 * Assign extra remaining streams, if any.
1827 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1828 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1829 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1830 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1831 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1836 simple_fwd_config_setup(void)
1842 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1843 port_topology == PORT_TOPOLOGY_LOOP) {
1845 } else if (nb_fwd_ports % 2) {
1846 printf("\nWarning! Cannot handle an odd number of ports "
1847 "with the current port topology. Configuration "
1848 "must be changed to have an even number of ports, "
1849 "or relaunch application with "
1850 "--port-topology=chained\n\n");
1853 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1854 cur_fwd_config.nb_fwd_streams =
1855 (streamid_t) cur_fwd_config.nb_fwd_ports;
1857 /* reinitialize forwarding streams */
1861 * In the simple forwarding test, the number of forwarding cores
1862 * must be lower or equal to the number of forwarding ports.
1864 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1865 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1866 cur_fwd_config.nb_fwd_lcores =
1867 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1868 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1870 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1871 if (port_topology != PORT_TOPOLOGY_LOOP)
1872 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1875 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1876 fwd_streams[i]->rx_queue = 0;
1877 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1878 fwd_streams[i]->tx_queue = 0;
1879 fwd_streams[i]->peer_addr = j;
1880 fwd_streams[i]->retry_enabled = retry_enabled;
1882 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1883 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1884 fwd_streams[j]->rx_queue = 0;
1885 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1886 fwd_streams[j]->tx_queue = 0;
1887 fwd_streams[j]->peer_addr = i;
1888 fwd_streams[j]->retry_enabled = retry_enabled;
1894 * For the RSS forwarding test all streams distributed over lcores. Each stream
1895 * being composed of a RX queue to poll on a RX port for input messages,
1896 * associated with a TX queue of a TX port where to send forwarded packets.
1897 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1898 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1900 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1904 rss_fwd_config_setup(void)
1915 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1916 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1917 cur_fwd_config.nb_fwd_streams =
1918 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1920 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1921 cur_fwd_config.nb_fwd_lcores =
1922 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1924 /* reinitialize forwarding streams */
1927 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1929 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1930 struct fwd_stream *fs;
1932 fs = fwd_streams[sm_id];
1934 if ((rxp & 0x1) == 0)
1935 txp = (portid_t) (rxp + 1);
1937 txp = (portid_t) (rxp - 1);
1939 * if we are in loopback, simply send stuff out through the
1942 if (port_topology == PORT_TOPOLOGY_LOOP)
1945 fs->rx_port = fwd_ports_ids[rxp];
1947 fs->tx_port = fwd_ports_ids[txp];
1949 fs->peer_addr = fs->tx_port;
1950 fs->retry_enabled = retry_enabled;
1951 rxq = (queueid_t) (rxq + 1);
1956 * Restart from RX queue 0 on next RX port
1959 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1961 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1963 rxp = (portid_t) (rxp + 1);
1968 * For the DCB forwarding test, each core is assigned on each traffic class.
1970 * Each core is assigned a multi-stream, each stream being composed of
1971 * a RX queue to poll on a RX port for input messages, associated with
1972 * a TX queue of a TX port where to send forwarded packets. All RX and
1973 * TX queues are mapping to the same traffic class.
1974 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1978 dcb_fwd_config_setup(void)
1980 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1981 portid_t txp, rxp = 0;
1982 queueid_t txq, rxq = 0;
1984 uint16_t nb_rx_queue, nb_tx_queue;
1985 uint16_t i, j, k, sm_id = 0;
1988 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1989 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1990 cur_fwd_config.nb_fwd_streams =
1991 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1993 /* reinitialize forwarding streams */
1997 /* get the dcb info on the first RX and TX ports */
1998 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1999 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2001 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2002 fwd_lcores[lc_id]->stream_nb = 0;
2003 fwd_lcores[lc_id]->stream_idx = sm_id;
2004 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2005 /* if the nb_queue is zero, means this tc is
2006 * not enabled on the POOL
2008 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2010 k = fwd_lcores[lc_id]->stream_nb +
2011 fwd_lcores[lc_id]->stream_idx;
2012 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2013 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2014 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2015 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2016 for (j = 0; j < nb_rx_queue; j++) {
2017 struct fwd_stream *fs;
2019 fs = fwd_streams[k + j];
2020 fs->rx_port = fwd_ports_ids[rxp];
2021 fs->rx_queue = rxq + j;
2022 fs->tx_port = fwd_ports_ids[txp];
2023 fs->tx_queue = txq + j % nb_tx_queue;
2024 fs->peer_addr = fs->tx_port;
2025 fs->retry_enabled = retry_enabled;
2027 fwd_lcores[lc_id]->stream_nb +=
2028 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2030 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2033 if (tc < rxp_dcb_info.nb_tcs)
2035 /* Restart from TC 0 on next RX port */
2037 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2039 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2042 if (rxp >= nb_fwd_ports)
2044 /* get the dcb information on next RX and TX ports */
2045 if ((rxp & 0x1) == 0)
2046 txp = (portid_t) (rxp + 1);
2048 txp = (portid_t) (rxp - 1);
2049 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2050 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2055 icmp_echo_config_setup(void)
2062 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2063 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2064 (nb_txq * nb_fwd_ports);
2066 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2067 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2068 cur_fwd_config.nb_fwd_streams =
2069 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2070 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2071 cur_fwd_config.nb_fwd_lcores =
2072 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2073 if (verbose_level > 0) {
2074 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2076 cur_fwd_config.nb_fwd_lcores,
2077 cur_fwd_config.nb_fwd_ports,
2078 cur_fwd_config.nb_fwd_streams);
2081 /* reinitialize forwarding streams */
2083 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2085 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2086 if (verbose_level > 0)
2087 printf(" core=%d: \n", lc_id);
2088 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2089 struct fwd_stream *fs;
2090 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2091 fs->rx_port = fwd_ports_ids[rxp];
2093 fs->tx_port = fs->rx_port;
2095 fs->peer_addr = fs->tx_port;
2096 fs->retry_enabled = retry_enabled;
2097 if (verbose_level > 0)
2098 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2099 sm_id, fs->rx_port, fs->rx_queue,
2101 rxq = (queueid_t) (rxq + 1);
2102 if (rxq == nb_rxq) {
2104 rxp = (portid_t) (rxp + 1);
2111 fwd_config_setup(void)
2113 cur_fwd_config.fwd_eng = cur_fwd_eng;
2114 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2115 icmp_echo_config_setup();
2118 if ((nb_rxq > 1) && (nb_txq > 1)){
2120 dcb_fwd_config_setup();
2122 rss_fwd_config_setup();
2125 simple_fwd_config_setup();
2129 pkt_fwd_config_display(struct fwd_config *cfg)
2131 struct fwd_stream *fs;
2135 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2136 "NUMA support %s, MP over anonymous pages %s\n",
2137 cfg->fwd_eng->fwd_mode_name,
2138 retry_enabled == 0 ? "" : " with retry",
2139 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2140 numa_support == 1 ? "enabled" : "disabled",
2141 mp_anon != 0 ? "enabled" : "disabled");
2144 printf("TX retry num: %u, delay between TX retries: %uus\n",
2145 burst_tx_retry_num, burst_tx_delay_time);
2146 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2147 printf("Logical Core %u (socket %u) forwards packets on "
2149 fwd_lcores_cpuids[lc_id],
2150 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2151 fwd_lcores[lc_id]->stream_nb);
2152 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2153 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2154 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2155 "P=%d/Q=%d (socket %u) ",
2156 fs->rx_port, fs->rx_queue,
2157 ports[fs->rx_port].socket_id,
2158 fs->tx_port, fs->tx_queue,
2159 ports[fs->tx_port].socket_id);
2160 print_ethaddr("peer=",
2161 &peer_eth_addrs[fs->peer_addr]);
2169 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2172 unsigned int lcore_cpuid;
2177 for (i = 0; i < nb_lc; i++) {
2178 lcore_cpuid = lcorelist[i];
2179 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2180 printf("lcore %u not enabled\n", lcore_cpuid);
2183 if (lcore_cpuid == rte_get_master_lcore()) {
2184 printf("lcore %u cannot be masked on for running "
2185 "packet forwarding, which is the master lcore "
2186 "and reserved for command line parsing only\n",
2191 fwd_lcores_cpuids[i] = lcore_cpuid;
2193 if (record_now == 0) {
2197 nb_cfg_lcores = (lcoreid_t) nb_lc;
2198 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2199 printf("previous number of forwarding cores %u - changed to "
2200 "number of configured cores %u\n",
2201 (unsigned int) nb_fwd_lcores, nb_lc);
2202 nb_fwd_lcores = (lcoreid_t) nb_lc;
2209 set_fwd_lcores_mask(uint64_t lcoremask)
2211 unsigned int lcorelist[64];
2215 if (lcoremask == 0) {
2216 printf("Invalid NULL mask of cores\n");
2220 for (i = 0; i < 64; i++) {
2221 if (! ((uint64_t)(1ULL << i) & lcoremask))
2223 lcorelist[nb_lc++] = i;
2225 return set_fwd_lcores_list(lcorelist, nb_lc);
2229 set_fwd_lcores_number(uint16_t nb_lc)
2231 if (nb_lc > nb_cfg_lcores) {
2232 printf("nb fwd cores %u > %u (max. number of configured "
2233 "lcores) - ignored\n",
2234 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2237 nb_fwd_lcores = (lcoreid_t) nb_lc;
2238 printf("Number of forwarding cores set to %u\n",
2239 (unsigned int) nb_fwd_lcores);
2243 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2251 for (i = 0; i < nb_pt; i++) {
2252 port_id = (portid_t) portlist[i];
2253 if (port_id_is_invalid(port_id, ENABLED_WARN))
2256 fwd_ports_ids[i] = port_id;
2258 if (record_now == 0) {
2262 nb_cfg_ports = (portid_t) nb_pt;
2263 if (nb_fwd_ports != (portid_t) nb_pt) {
2264 printf("previous number of forwarding ports %u - changed to "
2265 "number of configured ports %u\n",
2266 (unsigned int) nb_fwd_ports, nb_pt);
2267 nb_fwd_ports = (portid_t) nb_pt;
2272 set_fwd_ports_mask(uint64_t portmask)
2274 unsigned int portlist[64];
2278 if (portmask == 0) {
2279 printf("Invalid NULL mask of ports\n");
2283 RTE_ETH_FOREACH_DEV(i) {
2284 if (! ((uint64_t)(1ULL << i) & portmask))
2286 portlist[nb_pt++] = i;
2288 set_fwd_ports_list(portlist, nb_pt);
2292 set_fwd_ports_number(uint16_t nb_pt)
2294 if (nb_pt > nb_cfg_ports) {
2295 printf("nb fwd ports %u > %u (number of configured "
2296 "ports) - ignored\n",
2297 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2300 nb_fwd_ports = (portid_t) nb_pt;
2301 printf("Number of forwarding ports set to %u\n",
2302 (unsigned int) nb_fwd_ports);
2306 port_is_forwarding(portid_t port_id)
2310 if (port_id_is_invalid(port_id, ENABLED_WARN))
2313 for (i = 0; i < nb_fwd_ports; i++) {
2314 if (fwd_ports_ids[i] == port_id)
2322 set_nb_pkt_per_burst(uint16_t nb)
2324 if (nb > MAX_PKT_BURST) {
2325 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2327 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2330 nb_pkt_per_burst = nb;
2331 printf("Number of packets per burst set to %u\n",
2332 (unsigned int) nb_pkt_per_burst);
2336 tx_split_get_name(enum tx_pkt_split split)
2340 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2341 if (tx_split_name[i].split == split)
2342 return tx_split_name[i].name;
2348 set_tx_pkt_split(const char *name)
2352 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2353 if (strcmp(tx_split_name[i].name, name) == 0) {
2354 tx_pkt_split = tx_split_name[i].split;
2358 printf("unknown value: \"%s\"\n", name);
2362 show_tx_pkt_segments(void)
2368 split = tx_split_get_name(tx_pkt_split);
2370 printf("Number of segments: %u\n", n);
2371 printf("Segment sizes: ");
2372 for (i = 0; i != n - 1; i++)
2373 printf("%hu,", tx_pkt_seg_lengths[i]);
2374 printf("%hu\n", tx_pkt_seg_lengths[i]);
2375 printf("Split packet: %s\n", split);
2379 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2381 uint16_t tx_pkt_len;
2384 if (nb_segs >= (unsigned) nb_txd) {
2385 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2386 nb_segs, (unsigned int) nb_txd);
2391 * Check that each segment length is greater or equal than
2392 * the mbuf data sise.
2393 * Check also that the total packet length is greater or equal than the
2394 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2397 for (i = 0; i < nb_segs; i++) {
2398 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2399 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2400 i, seg_lengths[i], (unsigned) mbuf_data_size);
2403 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2405 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2406 printf("total packet length=%u < %d - give up\n",
2407 (unsigned) tx_pkt_len,
2408 (int)(sizeof(struct ether_hdr) + 20 + 8));
2412 for (i = 0; i < nb_segs; i++)
2413 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2415 tx_pkt_length = tx_pkt_len;
2416 tx_pkt_nb_segs = (uint8_t) nb_segs;
2420 setup_gro(const char *mode, uint8_t port_id)
2422 if (!rte_eth_dev_is_valid_port(port_id)) {
2423 printf("invalid port id %u\n", port_id);
2426 if (test_done == 0) {
2427 printf("Before enable/disable GRO,"
2428 " please stop forwarding first\n");
2431 if (strcmp(mode, "on") == 0) {
2432 if (gro_ports[port_id].enable) {
2433 printf("port %u has enabled GRO\n", port_id);
2436 gro_ports[port_id].enable = 1;
2437 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
2439 if (gro_ports[port_id].param.max_flow_num == 0)
2440 gro_ports[port_id].param.max_flow_num =
2441 GRO_DEFAULT_FLOW_NUM;
2442 if (gro_ports[port_id].param.max_item_per_flow == 0)
2443 gro_ports[port_id].param.max_item_per_flow =
2444 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
2446 if (gro_ports[port_id].enable == 0) {
2447 printf("port %u has disabled GRO\n", port_id);
2450 gro_ports[port_id].enable = 0;
2455 list_pkt_forwarding_modes(void)
2457 static char fwd_modes[128] = "";
2458 const char *separator = "|";
2459 struct fwd_engine *fwd_eng;
2462 if (strlen (fwd_modes) == 0) {
2463 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2464 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2465 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2466 strncat(fwd_modes, separator,
2467 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2469 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2476 list_pkt_forwarding_retry_modes(void)
2478 static char fwd_modes[128] = "";
2479 const char *separator = "|";
2480 struct fwd_engine *fwd_eng;
2483 if (strlen(fwd_modes) == 0) {
2484 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2485 if (fwd_eng == &rx_only_engine)
2487 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2489 strlen(fwd_modes) - 1);
2490 strncat(fwd_modes, separator,
2492 strlen(fwd_modes) - 1);
2494 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2501 set_pkt_forwarding_mode(const char *fwd_mode_name)
2503 struct fwd_engine *fwd_eng;
2507 while ((fwd_eng = fwd_engines[i]) != NULL) {
2508 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2509 printf("Set %s packet forwarding mode%s\n",
2511 retry_enabled == 0 ? "" : " with retry");
2512 cur_fwd_eng = fwd_eng;
2517 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2521 set_verbose_level(uint16_t vb_level)
2523 printf("Change verbose level from %u to %u\n",
2524 (unsigned int) verbose_level, (unsigned int) vb_level);
2525 verbose_level = vb_level;
2529 vlan_extend_set(portid_t port_id, int on)
2534 if (port_id_is_invalid(port_id, ENABLED_WARN))
2537 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2540 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2542 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2544 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2546 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2547 "diag=%d\n", port_id, on, diag);
2551 rx_vlan_strip_set(portid_t port_id, int on)
2556 if (port_id_is_invalid(port_id, ENABLED_WARN))
2559 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2562 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2564 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2566 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2568 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2569 "diag=%d\n", port_id, on, diag);
2573 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2577 if (port_id_is_invalid(port_id, ENABLED_WARN))
2580 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2582 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2583 "diag=%d\n", port_id, queue_id, on, diag);
2587 rx_vlan_filter_set(portid_t port_id, int on)
2592 if (port_id_is_invalid(port_id, ENABLED_WARN))
2595 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2598 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2600 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2602 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2604 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2605 "diag=%d\n", port_id, on, diag);
2609 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2613 if (port_id_is_invalid(port_id, ENABLED_WARN))
2615 if (vlan_id_is_invalid(vlan_id))
2617 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2620 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2622 port_id, vlan_id, on, diag);
2627 rx_vlan_all_filter_set(portid_t port_id, int on)
2631 if (port_id_is_invalid(port_id, ENABLED_WARN))
2633 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2634 if (rx_vft_set(port_id, vlan_id, on))
2640 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2644 if (port_id_is_invalid(port_id, ENABLED_WARN))
2647 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2651 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2653 port_id, vlan_type, tp_id, diag);
2657 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2660 if (port_id_is_invalid(port_id, ENABLED_WARN))
2662 if (vlan_id_is_invalid(vlan_id))
2665 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2666 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2667 printf("Error, as QinQ has been enabled.\n");
2671 tx_vlan_reset(port_id);
2672 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
2673 ports[port_id].tx_vlan_id = vlan_id;
2677 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2680 if (port_id_is_invalid(port_id, ENABLED_WARN))
2682 if (vlan_id_is_invalid(vlan_id))
2684 if (vlan_id_is_invalid(vlan_id_outer))
2687 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2688 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2689 printf("Error, as QinQ hasn't been enabled.\n");
2693 tx_vlan_reset(port_id);
2694 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
2695 ports[port_id].tx_vlan_id = vlan_id;
2696 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2700 tx_vlan_reset(portid_t port_id)
2702 if (port_id_is_invalid(port_id, ENABLED_WARN))
2704 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
2705 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
2706 ports[port_id].tx_vlan_id = 0;
2707 ports[port_id].tx_vlan_id_outer = 0;
2711 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2713 if (port_id_is_invalid(port_id, ENABLED_WARN))
2716 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2720 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2723 uint8_t existing_mapping_found = 0;
2725 if (port_id_is_invalid(port_id, ENABLED_WARN))
2728 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2731 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2732 printf("map_value not in required range 0..%d\n",
2733 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2737 if (!is_rx) { /*then tx*/
2738 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2739 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2740 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2741 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2742 existing_mapping_found = 1;
2746 if (!existing_mapping_found) { /* A new additional mapping... */
2747 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2748 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2749 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2750 nb_tx_queue_stats_mappings++;
2754 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2755 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2756 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2757 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2758 existing_mapping_found = 1;
2762 if (!existing_mapping_found) { /* A new additional mapping... */
2763 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2764 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2765 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2766 nb_rx_queue_stats_mappings++;
2772 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2774 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2776 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2777 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2778 " tunnel_id: 0x%08x",
2779 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2780 rte_be_to_cpu_32(mask->tunnel_id_mask));
2781 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2782 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2783 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2784 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2786 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2787 rte_be_to_cpu_16(mask->src_port_mask),
2788 rte_be_to_cpu_16(mask->dst_port_mask));
2790 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2791 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2792 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
2793 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
2794 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
2796 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2797 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
2798 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
2799 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
2800 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
2807 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2809 struct rte_eth_flex_payload_cfg *cfg;
2812 for (i = 0; i < flex_conf->nb_payloads; i++) {
2813 cfg = &flex_conf->flex_set[i];
2814 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2816 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2817 printf("\n L2_PAYLOAD: ");
2818 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2819 printf("\n L3_PAYLOAD: ");
2820 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2821 printf("\n L4_PAYLOAD: ");
2823 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2824 for (j = 0; j < num; j++)
2825 printf(" %-5u", cfg->src_offset[j]);
2831 flowtype_to_str(uint16_t flow_type)
2833 struct flow_type_info {
2839 static struct flow_type_info flowtype_str_table[] = {
2840 {"raw", RTE_ETH_FLOW_RAW},
2841 {"ipv4", RTE_ETH_FLOW_IPV4},
2842 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2843 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2844 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2845 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2846 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2847 {"ipv6", RTE_ETH_FLOW_IPV6},
2848 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2849 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2850 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2851 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2852 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2853 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2854 {"port", RTE_ETH_FLOW_PORT},
2855 {"vxlan", RTE_ETH_FLOW_VXLAN},
2856 {"geneve", RTE_ETH_FLOW_GENEVE},
2857 {"nvgre", RTE_ETH_FLOW_NVGRE},
2860 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2861 if (flowtype_str_table[i].ftype == flow_type)
2862 return flowtype_str_table[i].str;
2869 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2871 struct rte_eth_fdir_flex_mask *mask;
2875 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2876 mask = &flex_conf->flex_mask[i];
2877 p = flowtype_to_str(mask->flow_type);
2878 printf("\n %s:\t", p ? p : "unknown");
2879 for (j = 0; j < num; j++)
2880 printf(" %02x", mask->mask[j]);
2886 print_fdir_flow_type(uint32_t flow_types_mask)
2891 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2892 if (!(flow_types_mask & (1 << i)))
2894 p = flowtype_to_str(i);
2904 fdir_get_infos(portid_t port_id)
2906 struct rte_eth_fdir_stats fdir_stat;
2907 struct rte_eth_fdir_info fdir_info;
2910 static const char *fdir_stats_border = "########################";
2912 if (port_id_is_invalid(port_id, ENABLED_WARN))
2914 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
2916 printf("\n FDIR is not supported on port %-2d\n",
2921 memset(&fdir_info, 0, sizeof(fdir_info));
2922 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2923 RTE_ETH_FILTER_INFO, &fdir_info);
2924 memset(&fdir_stat, 0, sizeof(fdir_stat));
2925 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2926 RTE_ETH_FILTER_STATS, &fdir_stat);
2927 printf("\n %s FDIR infos for port %-2d %s\n",
2928 fdir_stats_border, port_id, fdir_stats_border);
2930 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
2931 printf(" PERFECT\n");
2932 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2933 printf(" PERFECT-MAC-VLAN\n");
2934 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2935 printf(" PERFECT-TUNNEL\n");
2936 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
2937 printf(" SIGNATURE\n");
2939 printf(" DISABLE\n");
2940 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
2941 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
2942 printf(" SUPPORTED FLOW TYPE: ");
2943 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
2945 printf(" FLEX PAYLOAD INFO:\n");
2946 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
2947 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
2948 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
2949 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
2950 fdir_info.flex_payload_unit,
2951 fdir_info.max_flex_payload_segment_num,
2952 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
2954 print_fdir_mask(&fdir_info.mask);
2955 if (fdir_info.flex_conf.nb_payloads > 0) {
2956 printf(" FLEX PAYLOAD SRC OFFSET:");
2957 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2959 if (fdir_info.flex_conf.nb_flexmasks > 0) {
2960 printf(" FLEX MASK CFG:");
2961 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2963 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2964 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2965 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2966 fdir_info.guarant_spc, fdir_info.best_spc);
2967 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2968 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2969 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2970 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2971 fdir_stat.collision, fdir_stat.free,
2972 fdir_stat.maxhash, fdir_stat.maxlen,
2973 fdir_stat.add, fdir_stat.remove,
2974 fdir_stat.f_add, fdir_stat.f_remove);
2975 printf(" %s############################%s\n",
2976 fdir_stats_border, fdir_stats_border);
2980 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2982 struct rte_port *port;
2983 struct rte_eth_fdir_flex_conf *flex_conf;
2986 port = &ports[port_id];
2987 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2988 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2989 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2994 if (i >= RTE_ETH_FLOW_MAX) {
2995 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2996 idx = flex_conf->nb_flexmasks;
2997 flex_conf->nb_flexmasks++;
2999 printf("The flex mask table is full. Can not set flex"
3000 " mask for flow_type(%u).", cfg->flow_type);
3004 (void)rte_memcpy(&flex_conf->flex_mask[idx],
3006 sizeof(struct rte_eth_fdir_flex_mask));
3010 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
3012 struct rte_port *port;
3013 struct rte_eth_fdir_flex_conf *flex_conf;
3016 port = &ports[port_id];
3017 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
3018 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
3019 if (cfg->type == flex_conf->flex_set[i].type) {
3024 if (i >= RTE_ETH_PAYLOAD_MAX) {
3025 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
3026 idx = flex_conf->nb_payloads;
3027 flex_conf->nb_payloads++;
3029 printf("The flex payload table is full. Can not set"
3030 " flex payload for type(%u).", cfg->type);
3034 (void)rte_memcpy(&flex_conf->flex_set[idx],
3036 sizeof(struct rte_eth_flex_payload_cfg));
3041 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3043 #ifdef RTE_LIBRTE_IXGBE_PMD
3047 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3049 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3053 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3054 is_rx ? "rx" : "tx", port_id, diag);
3057 printf("VF %s setting not supported for port %d\n",
3058 is_rx ? "Rx" : "Tx", port_id);
3064 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3067 struct rte_eth_link link;
3069 if (port_id_is_invalid(port_id, ENABLED_WARN))
3071 rte_eth_link_get_nowait(port_id, &link);
3072 if (rate > link.link_speed) {
3073 printf("Invalid rate value:%u bigger than link speed: %u\n",
3074 rate, link.link_speed);
3077 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3080 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3086 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3088 int diag = -ENOTSUP;
3090 #ifdef RTE_LIBRTE_IXGBE_PMD
3091 if (diag == -ENOTSUP)
3092 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3095 #ifdef RTE_LIBRTE_BNXT_PMD
3096 if (diag == -ENOTSUP)
3097 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3102 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3108 * Functions to manage the set of filtered Multicast MAC addresses.
3110 * A pool of filtered multicast MAC addresses is associated with each port.
3111 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3112 * The address of the pool and the number of valid multicast MAC addresses
3113 * recorded in the pool are stored in the fields "mc_addr_pool" and
3114 * "mc_addr_nb" of the "rte_port" data structure.
3116 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3117 * to be supplied a contiguous array of multicast MAC addresses.
3118 * To comply with this constraint, the set of multicast addresses recorded
3119 * into the pool are systematically compacted at the beginning of the pool.
3120 * Hence, when a multicast address is removed from the pool, all following
3121 * addresses, if any, are copied back to keep the set contiguous.
3123 #define MCAST_POOL_INC 32
3126 mcast_addr_pool_extend(struct rte_port *port)
3128 struct ether_addr *mc_pool;
3129 size_t mc_pool_size;
3132 * If a free entry is available at the end of the pool, just
3133 * increment the number of recorded multicast addresses.
3135 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3141 * [re]allocate a pool with MCAST_POOL_INC more entries.
3142 * The previous test guarantees that port->mc_addr_nb is a multiple
3143 * of MCAST_POOL_INC.
3145 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3147 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3149 if (mc_pool == NULL) {
3150 printf("allocation of pool of %u multicast addresses failed\n",
3151 port->mc_addr_nb + MCAST_POOL_INC);
3155 port->mc_addr_pool = mc_pool;
3162 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3165 if (addr_idx == port->mc_addr_nb) {
3166 /* No need to recompact the set of multicast addressses. */
3167 if (port->mc_addr_nb == 0) {
3168 /* free the pool of multicast addresses. */
3169 free(port->mc_addr_pool);
3170 port->mc_addr_pool = NULL;
3174 memmove(&port->mc_addr_pool[addr_idx],
3175 &port->mc_addr_pool[addr_idx + 1],
3176 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3180 eth_port_multicast_addr_list_set(uint8_t port_id)
3182 struct rte_port *port;
3185 port = &ports[port_id];
3186 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3190 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3191 port->mc_addr_nb, port_id, -diag);
3195 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
3197 struct rte_port *port;
3200 if (port_id_is_invalid(port_id, ENABLED_WARN))
3203 port = &ports[port_id];
3206 * Check that the added multicast MAC address is not already recorded
3207 * in the pool of multicast addresses.
3209 for (i = 0; i < port->mc_addr_nb; i++) {
3210 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3211 printf("multicast address already filtered by port\n");
3216 if (mcast_addr_pool_extend(port) != 0)
3218 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3219 eth_port_multicast_addr_list_set(port_id);
3223 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
3225 struct rte_port *port;
3228 if (port_id_is_invalid(port_id, ENABLED_WARN))
3231 port = &ports[port_id];
3234 * Search the pool of multicast MAC addresses for the removed address.
3236 for (i = 0; i < port->mc_addr_nb; i++) {
3237 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3240 if (i == port->mc_addr_nb) {
3241 printf("multicast address not filtered by port %d\n", port_id);
3245 mcast_addr_pool_remove(port, i);
3246 eth_port_multicast_addr_list_set(port_id);
3250 port_dcb_info_display(uint8_t port_id)
3252 struct rte_eth_dcb_info dcb_info;
3255 static const char *border = "================";
3257 if (port_id_is_invalid(port_id, ENABLED_WARN))
3260 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3262 printf("\n Failed to get dcb infos on port %-2d\n",
3266 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3267 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3269 for (i = 0; i < dcb_info.nb_tcs; i++)
3271 printf("\n Priority : ");
3272 for (i = 0; i < dcb_info.nb_tcs; i++)
3273 printf("\t%4d", dcb_info.prio_tc[i]);
3274 printf("\n BW percent :");
3275 for (i = 0; i < dcb_info.nb_tcs; i++)
3276 printf("\t%4d%%", dcb_info.tc_bws[i]);
3277 printf("\n RXQ base : ");
3278 for (i = 0; i < dcb_info.nb_tcs; i++)
3279 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3280 printf("\n RXQ number :");
3281 for (i = 0; i < dcb_info.nb_tcs; i++)
3282 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3283 printf("\n TXQ base : ");
3284 for (i = 0; i < dcb_info.nb_tcs; i++)
3285 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3286 printf("\n TXQ number :");
3287 for (i = 0; i < dcb_info.nb_tcs; i++)
3288 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3293 open_ddp_package_file(const char *file_path, uint32_t *size)
3295 FILE *fh = fopen(file_path, "rb");
3297 uint8_t *buf = NULL;
3304 printf("%s: Failed to open %s\n", __func__, file_path);
3308 ret = fseek(fh, 0, SEEK_END);
3311 printf("%s: File operations failed\n", __func__);
3315 pkg_size = ftell(fh);
3317 buf = (uint8_t *)malloc(pkg_size);
3320 printf("%s: Failed to malloc memory\n", __func__);
3324 ret = fseek(fh, 0, SEEK_SET);
3327 printf("%s: File seek operation failed\n", __func__);
3328 close_ddp_package_file(buf);
3332 ret = fread(buf, 1, pkg_size, fh);
3335 printf("%s: File read operation failed\n", __func__);
3336 close_ddp_package_file(buf);
3349 save_ddp_package_file(const char *file_path, uint8_t *buf, uint32_t size)
3351 FILE *fh = fopen(file_path, "wb");
3354 printf("%s: Failed to open %s\n", __func__, file_path);
3358 if (fwrite(buf, 1, size, fh) != size) {
3360 printf("%s: File write operation failed\n", __func__);
3370 close_ddp_package_file(uint8_t *buf)