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>
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 diff_pkts_tx = stats.opackets - prev_pkts_tx[port_id];
208 prev_pkts_rx[port_id] = stats.ipackets;
209 prev_pkts_tx[port_id] = stats.opackets;
210 mpps_rx = diff_cycles > 0 ?
211 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
212 mpps_tx = diff_cycles > 0 ?
213 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
214 printf("\n Throughput (since last show)\n");
215 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
218 printf(" %s############################%s\n",
219 nic_stats_border, nic_stats_border);
223 nic_stats_clear(portid_t port_id)
227 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
228 printf("Valid port range is [0");
229 RTE_ETH_FOREACH_DEV(pid)
234 rte_eth_stats_reset(port_id);
235 printf("\n NIC statistics for port %d cleared\n", port_id);
239 nic_xstats_display(portid_t port_id)
241 struct rte_eth_xstat *xstats;
242 int cnt_xstats, idx_xstat;
243 struct rte_eth_xstat_name *xstats_names;
245 printf("###### NIC extended statistics for port %-2d\n", port_id);
246 if (!rte_eth_dev_is_valid_port(port_id)) {
247 printf("Error: Invalid port number %i\n", port_id);
252 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
253 if (cnt_xstats < 0) {
254 printf("Error: Cannot get count of xstats\n");
258 /* Get id-name lookup table */
259 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
260 if (xstats_names == NULL) {
261 printf("Cannot allocate memory for xstats lookup\n");
264 if (cnt_xstats != rte_eth_xstats_get_names(
265 port_id, xstats_names, cnt_xstats)) {
266 printf("Error: Cannot get xstats lookup\n");
271 /* Get stats themselves */
272 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
273 if (xstats == NULL) {
274 printf("Cannot allocate memory for xstats\n");
278 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
279 printf("Error: Unable to get xstats\n");
286 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
287 printf("%s: %"PRIu64"\n",
288 xstats_names[idx_xstat].name,
289 xstats[idx_xstat].value);
295 nic_xstats_clear(portid_t port_id)
297 rte_eth_xstats_reset(port_id);
301 nic_stats_mapping_display(portid_t port_id)
303 struct rte_port *port = &ports[port_id];
307 static const char *nic_stats_mapping_border = "########################";
309 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
310 printf("Valid port range is [0");
311 RTE_ETH_FOREACH_DEV(pid)
317 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
318 printf("Port id %d - either does not support queue statistic mapping or"
319 " no queue statistic mapping set\n", port_id);
323 printf("\n %s NIC statistics mapping for port %-2d %s\n",
324 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
326 if (port->rx_queue_stats_mapping_enabled) {
327 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
328 if (rx_queue_stats_mappings[i].port_id == port_id) {
329 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
330 rx_queue_stats_mappings[i].queue_id,
331 rx_queue_stats_mappings[i].stats_counter_id);
338 if (port->tx_queue_stats_mapping_enabled) {
339 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
340 if (tx_queue_stats_mappings[i].port_id == port_id) {
341 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
342 tx_queue_stats_mappings[i].queue_id,
343 tx_queue_stats_mappings[i].stats_counter_id);
348 printf(" %s####################################%s\n",
349 nic_stats_mapping_border, nic_stats_mapping_border);
353 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
355 struct rte_eth_rxq_info qinfo;
357 static const char *info_border = "*********************";
359 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
361 printf("Failed to retrieve information for port: %hhu, "
362 "RX queue: %hu\nerror desc: %s(%d)\n",
363 port_id, queue_id, strerror(-rc), rc);
367 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
368 info_border, port_id, queue_id, info_border);
370 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
371 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
372 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
373 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
374 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
375 printf("\nRX drop packets: %s",
376 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
377 printf("\nRX deferred start: %s",
378 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
379 printf("\nRX scattered packets: %s",
380 (qinfo.scattered_rx != 0) ? "on" : "off");
381 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
386 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
388 struct rte_eth_txq_info qinfo;
390 static const char *info_border = "*********************";
392 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
394 printf("Failed to retrieve information for port: %hhu, "
395 "TX queue: %hu\nerror desc: %s(%d)\n",
396 port_id, queue_id, strerror(-rc), rc);
400 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
401 info_border, port_id, queue_id, info_border);
403 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
404 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
405 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
406 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
407 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
408 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
409 printf("\nTX deferred start: %s",
410 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
411 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
416 port_infos_display(portid_t port_id)
418 struct rte_port *port;
419 struct ether_addr mac_addr;
420 struct rte_eth_link link;
421 struct rte_eth_dev_info dev_info;
423 struct rte_mempool * mp;
424 static const char *info_border = "*********************";
428 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
429 printf("Valid port range is [0");
430 RTE_ETH_FOREACH_DEV(pid)
435 port = &ports[port_id];
436 rte_eth_link_get_nowait(port_id, &link);
437 memset(&dev_info, 0, sizeof(dev_info));
438 rte_eth_dev_info_get(port_id, &dev_info);
439 printf("\n%s Infos for port %-2d %s\n",
440 info_border, port_id, info_border);
441 rte_eth_macaddr_get(port_id, &mac_addr);
442 print_ethaddr("MAC address: ", &mac_addr);
443 printf("\nDriver name: %s", dev_info.driver_name);
444 printf("\nConnect to socket: %u", port->socket_id);
446 if (port_numa[port_id] != NUMA_NO_CONFIG) {
447 mp = mbuf_pool_find(port_numa[port_id]);
449 printf("\nmemory allocation on the socket: %d",
452 printf("\nmemory allocation on the socket: %u",port->socket_id);
454 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
455 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
456 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
457 ("full-duplex") : ("half-duplex"));
459 if (!rte_eth_dev_get_mtu(port_id, &mtu))
460 printf("MTU: %u\n", mtu);
462 printf("Promiscuous mode: %s\n",
463 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
464 printf("Allmulticast mode: %s\n",
465 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
466 printf("Maximum number of MAC addresses: %u\n",
467 (unsigned int)(port->dev_info.max_mac_addrs));
468 printf("Maximum number of MAC addresses of hash filtering: %u\n",
469 (unsigned int)(port->dev_info.max_hash_mac_addrs));
471 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
472 if (vlan_offload >= 0){
473 printf("VLAN offload: \n");
474 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
475 printf(" strip on \n");
477 printf(" strip off \n");
479 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
480 printf(" filter on \n");
482 printf(" filter off \n");
484 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
485 printf(" qinq(extend) on \n");
487 printf(" qinq(extend) off \n");
490 if (dev_info.hash_key_size > 0)
491 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
492 if (dev_info.reta_size > 0)
493 printf("Redirection table size: %u\n", dev_info.reta_size);
494 if (!dev_info.flow_type_rss_offloads)
495 printf("No flow type is supported.\n");
500 printf("Supported flow types:\n");
501 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
503 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
505 p = flowtype_to_str(i);
506 printf(" %s\n", (p ? p : "unknown"));
510 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
511 printf("Max possible number of RXDs per queue: %hu\n",
512 dev_info.rx_desc_lim.nb_max);
513 printf("Min possible number of RXDs per queue: %hu\n",
514 dev_info.rx_desc_lim.nb_min);
515 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
517 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
518 printf("Max possible number of TXDs per queue: %hu\n",
519 dev_info.tx_desc_lim.nb_max);
520 printf("Min possible number of TXDs per queue: %hu\n",
521 dev_info.tx_desc_lim.nb_min);
522 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
526 port_offload_cap_display(portid_t port_id)
528 struct rte_eth_dev *dev;
529 struct rte_eth_dev_info dev_info;
530 static const char *info_border = "************";
532 if (port_id_is_invalid(port_id, ENABLED_WARN))
535 dev = &rte_eth_devices[port_id];
536 rte_eth_dev_info_get(port_id, &dev_info);
538 printf("\n%s Port %d supported offload features: %s\n",
539 info_border, port_id, info_border);
541 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
542 printf("VLAN stripped: ");
543 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
549 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
550 printf("Double VLANs stripped: ");
551 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
557 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
558 printf("RX IPv4 checksum: ");
559 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
565 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
566 printf("RX UDP checksum: ");
567 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
573 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
574 printf("RX TCP checksum: ");
575 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
581 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
582 printf("RX Outer IPv4 checksum: on");
584 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
585 printf("Large receive offload: ");
586 if (dev->data->dev_conf.rxmode.enable_lro)
592 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
593 printf("VLAN insert: ");
594 if (ports[port_id].tx_ol_flags &
595 TESTPMD_TX_OFFLOAD_INSERT_VLAN)
601 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
602 printf("Double VLANs insert: ");
603 if (ports[port_id].tx_ol_flags &
604 TESTPMD_TX_OFFLOAD_INSERT_QINQ)
610 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
611 printf("TX IPv4 checksum: ");
612 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
618 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
619 printf("TX UDP checksum: ");
620 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
626 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
627 printf("TX TCP checksum: ");
628 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
634 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
635 printf("TX SCTP checksum: ");
636 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
642 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
643 printf("TX Outer IPv4 checksum: ");
644 if (ports[port_id].tx_ol_flags &
645 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
651 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
652 printf("TX TCP segmentation: ");
653 if (ports[port_id].tso_segsz != 0)
659 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
660 printf("TX UDP segmentation: ");
661 if (ports[port_id].tso_segsz != 0)
667 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
668 printf("TSO for VXLAN tunnel packet: ");
669 if (ports[port_id].tunnel_tso_segsz)
675 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
676 printf("TSO for GRE tunnel packet: ");
677 if (ports[port_id].tunnel_tso_segsz)
683 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
684 printf("TSO for IPIP tunnel packet: ");
685 if (ports[port_id].tunnel_tso_segsz)
691 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
692 printf("TSO for GENEVE tunnel packet: ");
693 if (ports[port_id].tunnel_tso_segsz)
702 port_id_is_invalid(portid_t port_id, enum print_warning warning)
704 if (port_id == (portid_t)RTE_PORT_ALL)
707 if (rte_eth_dev_is_valid_port(port_id))
710 if (warning == ENABLED_WARN)
711 printf("Invalid port %d\n", port_id);
717 vlan_id_is_invalid(uint16_t vlan_id)
721 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
726 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
731 printf("Port register offset 0x%X not aligned on a 4-byte "
736 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
737 if (reg_off >= pci_len) {
738 printf("Port %d: register offset %u (0x%X) out of port PCI "
739 "resource (length=%"PRIu64")\n",
740 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
747 reg_bit_pos_is_invalid(uint8_t bit_pos)
751 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
755 #define display_port_and_reg_off(port_id, reg_off) \
756 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
759 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
761 display_port_and_reg_off(port_id, (unsigned)reg_off);
762 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
766 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
771 if (port_id_is_invalid(port_id, ENABLED_WARN))
773 if (port_reg_off_is_invalid(port_id, reg_off))
775 if (reg_bit_pos_is_invalid(bit_x))
777 reg_v = port_id_pci_reg_read(port_id, reg_off);
778 display_port_and_reg_off(port_id, (unsigned)reg_off);
779 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
783 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
784 uint8_t bit1_pos, uint8_t bit2_pos)
790 if (port_id_is_invalid(port_id, ENABLED_WARN))
792 if (port_reg_off_is_invalid(port_id, reg_off))
794 if (reg_bit_pos_is_invalid(bit1_pos))
796 if (reg_bit_pos_is_invalid(bit2_pos))
798 if (bit1_pos > bit2_pos)
799 l_bit = bit2_pos, h_bit = bit1_pos;
801 l_bit = bit1_pos, h_bit = bit2_pos;
803 reg_v = port_id_pci_reg_read(port_id, reg_off);
806 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
807 display_port_and_reg_off(port_id, (unsigned)reg_off);
808 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
809 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
813 port_reg_display(portid_t port_id, uint32_t reg_off)
817 if (port_id_is_invalid(port_id, ENABLED_WARN))
819 if (port_reg_off_is_invalid(port_id, reg_off))
821 reg_v = port_id_pci_reg_read(port_id, reg_off);
822 display_port_reg_value(port_id, reg_off, reg_v);
826 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
831 if (port_id_is_invalid(port_id, ENABLED_WARN))
833 if (port_reg_off_is_invalid(port_id, reg_off))
835 if (reg_bit_pos_is_invalid(bit_pos))
838 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
841 reg_v = port_id_pci_reg_read(port_id, reg_off);
843 reg_v &= ~(1 << bit_pos);
845 reg_v |= (1 << bit_pos);
846 port_id_pci_reg_write(port_id, reg_off, reg_v);
847 display_port_reg_value(port_id, reg_off, reg_v);
851 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
852 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
859 if (port_id_is_invalid(port_id, ENABLED_WARN))
861 if (port_reg_off_is_invalid(port_id, reg_off))
863 if (reg_bit_pos_is_invalid(bit1_pos))
865 if (reg_bit_pos_is_invalid(bit2_pos))
867 if (bit1_pos > bit2_pos)
868 l_bit = bit2_pos, h_bit = bit1_pos;
870 l_bit = bit1_pos, h_bit = bit2_pos;
872 if ((h_bit - l_bit) < 31)
873 max_v = (1 << (h_bit - l_bit + 1)) - 1;
878 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
879 (unsigned)value, (unsigned)value,
880 (unsigned)max_v, (unsigned)max_v);
883 reg_v = port_id_pci_reg_read(port_id, reg_off);
884 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
885 reg_v |= (value << l_bit); /* Set changed bits */
886 port_id_pci_reg_write(port_id, reg_off, reg_v);
887 display_port_reg_value(port_id, reg_off, reg_v);
891 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
893 if (port_id_is_invalid(port_id, ENABLED_WARN))
895 if (port_reg_off_is_invalid(port_id, reg_off))
897 port_id_pci_reg_write(port_id, reg_off, reg_v);
898 display_port_reg_value(port_id, reg_off, reg_v);
902 port_mtu_set(portid_t port_id, uint16_t mtu)
906 if (port_id_is_invalid(port_id, ENABLED_WARN))
908 diag = rte_eth_dev_set_mtu(port_id, mtu);
911 printf("Set MTU failed. diag=%d\n", diag);
914 /* Generic flow management functions. */
916 /** Generate flow_item[] entry. */
917 #define MK_FLOW_ITEM(t, s) \
918 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
923 /** Information about known flow pattern items. */
924 static const struct {
928 MK_FLOW_ITEM(END, 0),
929 MK_FLOW_ITEM(VOID, 0),
930 MK_FLOW_ITEM(INVERT, 0),
931 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
933 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
934 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
935 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
936 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
937 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
938 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
939 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
940 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
941 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
942 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
943 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
944 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
945 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
946 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
947 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
948 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
951 /** Compute storage space needed by item specification. */
953 flow_item_spec_size(const struct rte_flow_item *item,
954 size_t *size, size_t *pad)
958 switch (item->type) {
960 const struct rte_flow_item_raw *raw;
963 case RTE_FLOW_ITEM_TYPE_RAW:
964 spec.raw = item->spec;
965 *size = offsetof(struct rte_flow_item_raw, pattern) +
966 spec.raw->length * sizeof(*spec.raw->pattern);
973 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
976 /** Generate flow_action[] entry. */
977 #define MK_FLOW_ACTION(t, s) \
978 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
983 /** Information about known flow actions. */
984 static const struct {
988 MK_FLOW_ACTION(END, 0),
989 MK_FLOW_ACTION(VOID, 0),
990 MK_FLOW_ACTION(PASSTHRU, 0),
991 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
992 MK_FLOW_ACTION(FLAG, 0),
993 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
994 MK_FLOW_ACTION(DROP, 0),
995 MK_FLOW_ACTION(COUNT, 0),
996 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
997 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
998 MK_FLOW_ACTION(PF, 0),
999 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1002 /** Compute storage space needed by action configuration. */
1004 flow_action_conf_size(const struct rte_flow_action *action,
1005 size_t *size, size_t *pad)
1009 switch (action->type) {
1011 const struct rte_flow_action_rss *rss;
1014 case RTE_FLOW_ACTION_TYPE_RSS:
1015 conf.rss = action->conf;
1016 *size = offsetof(struct rte_flow_action_rss, queue) +
1017 conf.rss->num * sizeof(*conf.rss->queue);
1024 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1027 /** Generate a port_flow entry from attributes/pattern/actions. */
1028 static struct port_flow *
1029 port_flow_new(const struct rte_flow_attr *attr,
1030 const struct rte_flow_item *pattern,
1031 const struct rte_flow_action *actions)
1033 const struct rte_flow_item *item;
1034 const struct rte_flow_action *action;
1035 struct port_flow *pf = NULL;
1045 pf->pattern = (void *)&pf->data[off1];
1047 struct rte_flow_item *dst = NULL;
1049 if ((unsigned int)item->type >= RTE_DIM(flow_item) ||
1050 !flow_item[item->type].name)
1053 dst = memcpy(pf->data + off1, item, sizeof(*item));
1054 off1 += sizeof(*item);
1055 flow_item_spec_size(item, &tmp, &pad);
1058 dst->spec = memcpy(pf->data + off2,
1064 dst->last = memcpy(pf->data + off2,
1070 dst->mask = memcpy(pf->data + off2,
1074 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1075 } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
1076 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1079 pf->actions = (void *)&pf->data[off1];
1081 struct rte_flow_action *dst = NULL;
1083 if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
1084 !flow_action[action->type].name)
1087 dst = memcpy(pf->data + off1, action, sizeof(*action));
1088 off1 += sizeof(*action);
1089 flow_action_conf_size(action, &tmp, &pad);
1092 dst->conf = memcpy(pf->data + off2,
1096 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1097 } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
1100 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1101 tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double));
1102 pf = calloc(1, tmp + off1 + off2);
1106 *pf = (const struct port_flow){
1107 .size = tmp + off1 + off2,
1110 tmp -= offsetof(struct port_flow, data);
1120 /** Print a message out of a flow error. */
1122 port_flow_complain(struct rte_flow_error *error)
1124 static const char *const errstrlist[] = {
1125 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1126 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1127 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1128 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1129 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1130 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1131 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1132 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1133 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1134 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1135 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1136 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1140 int err = rte_errno;
1142 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1143 !errstrlist[error->type])
1144 errstr = "unknown type";
1146 errstr = errstrlist[error->type];
1147 printf("Caught error type %d (%s): %s%s\n",
1148 error->type, errstr,
1149 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1150 error->cause), buf) : "",
1151 error->message ? error->message : "(no stated reason)");
1155 /** Validate flow rule. */
1157 port_flow_validate(portid_t port_id,
1158 const struct rte_flow_attr *attr,
1159 const struct rte_flow_item *pattern,
1160 const struct rte_flow_action *actions)
1162 struct rte_flow_error error;
1164 /* Poisoning to make sure PMDs update it in case of error. */
1165 memset(&error, 0x11, sizeof(error));
1166 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1167 return port_flow_complain(&error);
1168 printf("Flow rule validated\n");
1172 /** Create flow rule. */
1174 port_flow_create(portid_t port_id,
1175 const struct rte_flow_attr *attr,
1176 const struct rte_flow_item *pattern,
1177 const struct rte_flow_action *actions)
1179 struct rte_flow *flow;
1180 struct rte_port *port;
1181 struct port_flow *pf;
1183 struct rte_flow_error error;
1185 /* Poisoning to make sure PMDs update it in case of error. */
1186 memset(&error, 0x22, sizeof(error));
1187 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1189 return port_flow_complain(&error);
1190 port = &ports[port_id];
1191 if (port->flow_list) {
1192 if (port->flow_list->id == UINT32_MAX) {
1193 printf("Highest rule ID is already assigned, delete"
1195 rte_flow_destroy(port_id, flow, NULL);
1198 id = port->flow_list->id + 1;
1201 pf = port_flow_new(attr, pattern, actions);
1203 int err = rte_errno;
1205 printf("Cannot allocate flow: %s\n", rte_strerror(err));
1206 rte_flow_destroy(port_id, flow, NULL);
1209 pf->next = port->flow_list;
1212 port->flow_list = pf;
1213 printf("Flow rule #%u created\n", pf->id);
1217 /** Destroy a number of flow rules. */
1219 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1221 struct rte_port *port;
1222 struct port_flow **tmp;
1226 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1227 port_id == (portid_t)RTE_PORT_ALL)
1229 port = &ports[port_id];
1230 tmp = &port->flow_list;
1234 for (i = 0; i != n; ++i) {
1235 struct rte_flow_error error;
1236 struct port_flow *pf = *tmp;
1238 if (rule[i] != pf->id)
1241 * Poisoning to make sure PMDs update it in case
1244 memset(&error, 0x33, sizeof(error));
1245 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1246 ret = port_flow_complain(&error);
1249 printf("Flow rule #%u destroyed\n", pf->id);
1255 tmp = &(*tmp)->next;
1261 /** Remove all flow rules. */
1263 port_flow_flush(portid_t port_id)
1265 struct rte_flow_error error;
1266 struct rte_port *port;
1269 /* Poisoning to make sure PMDs update it in case of error. */
1270 memset(&error, 0x44, sizeof(error));
1271 if (rte_flow_flush(port_id, &error)) {
1272 ret = port_flow_complain(&error);
1273 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1274 port_id == (portid_t)RTE_PORT_ALL)
1277 port = &ports[port_id];
1278 while (port->flow_list) {
1279 struct port_flow *pf = port->flow_list->next;
1281 free(port->flow_list);
1282 port->flow_list = pf;
1287 /** Query a flow rule. */
1289 port_flow_query(portid_t port_id, uint32_t rule,
1290 enum rte_flow_action_type action)
1292 struct rte_flow_error error;
1293 struct rte_port *port;
1294 struct port_flow *pf;
1297 struct rte_flow_query_count count;
1300 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1301 port_id == (portid_t)RTE_PORT_ALL)
1303 port = &ports[port_id];
1304 for (pf = port->flow_list; pf; pf = pf->next)
1308 printf("Flow rule #%u not found\n", rule);
1311 if ((unsigned int)action >= RTE_DIM(flow_action) ||
1312 !flow_action[action].name)
1315 name = flow_action[action].name;
1317 case RTE_FLOW_ACTION_TYPE_COUNT:
1320 printf("Cannot query action type %d (%s)\n", action, name);
1323 /* Poisoning to make sure PMDs update it in case of error. */
1324 memset(&error, 0x55, sizeof(error));
1325 memset(&query, 0, sizeof(query));
1326 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1327 return port_flow_complain(&error);
1329 case RTE_FLOW_ACTION_TYPE_COUNT:
1333 " hits: %" PRIu64 "\n"
1334 " bytes: %" PRIu64 "\n",
1336 query.count.hits_set,
1337 query.count.bytes_set,
1342 printf("Cannot display result for action type %d (%s)\n",
1349 /** List flow rules. */
1351 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1353 struct rte_port *port;
1354 struct port_flow *pf;
1355 struct port_flow *list = NULL;
1358 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1359 port_id == (portid_t)RTE_PORT_ALL)
1361 port = &ports[port_id];
1362 if (!port->flow_list)
1364 /* Sort flows by group, priority and ID. */
1365 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1366 struct port_flow **tmp;
1369 /* Filter out unwanted groups. */
1370 for (i = 0; i != n; ++i)
1371 if (pf->attr.group == group[i])
1378 (pf->attr.group > (*tmp)->attr.group ||
1379 (pf->attr.group == (*tmp)->attr.group &&
1380 pf->attr.priority > (*tmp)->attr.priority) ||
1381 (pf->attr.group == (*tmp)->attr.group &&
1382 pf->attr.priority == (*tmp)->attr.priority &&
1383 pf->id > (*tmp)->id)))
1388 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1389 for (pf = list; pf != NULL; pf = pf->tmp) {
1390 const struct rte_flow_item *item = pf->pattern;
1391 const struct rte_flow_action *action = pf->actions;
1393 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t",
1397 pf->attr.ingress ? 'i' : '-',
1398 pf->attr.egress ? 'e' : '-');
1399 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1400 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1401 printf("%s ", flow_item[item->type].name);
1405 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1406 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1407 printf(" %s", flow_action[action->type].name);
1414 /** Restrict ingress traffic to the defined flow rules. */
1416 port_flow_isolate(portid_t port_id, int set)
1418 struct rte_flow_error error;
1420 /* Poisoning to make sure PMDs update it in case of error. */
1421 memset(&error, 0x66, sizeof(error));
1422 if (rte_flow_isolate(port_id, set, &error))
1423 return port_flow_complain(&error);
1424 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
1426 set ? "now restricted" : "not restricted anymore");
1431 * RX/TX ring descriptors display functions.
1434 rx_queue_id_is_invalid(queueid_t rxq_id)
1436 if (rxq_id < nb_rxq)
1438 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1443 tx_queue_id_is_invalid(queueid_t txq_id)
1445 if (txq_id < nb_txq)
1447 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1452 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1454 if (rxdesc_id < nb_rxd)
1456 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1462 tx_desc_id_is_invalid(uint16_t txdesc_id)
1464 if (txdesc_id < nb_txd)
1466 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1471 static const struct rte_memzone *
1472 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
1474 char mz_name[RTE_MEMZONE_NAMESIZE];
1475 const struct rte_memzone *mz;
1477 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1478 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1479 mz = rte_memzone_lookup(mz_name);
1481 printf("%s ring memory zoneof (port %d, queue %d) not"
1482 "found (zone name = %s\n",
1483 ring_name, port_id, q_id, mz_name);
1487 union igb_ring_dword {
1490 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1500 struct igb_ring_desc_32_bytes {
1501 union igb_ring_dword lo_dword;
1502 union igb_ring_dword hi_dword;
1503 union igb_ring_dword resv1;
1504 union igb_ring_dword resv2;
1507 struct igb_ring_desc_16_bytes {
1508 union igb_ring_dword lo_dword;
1509 union igb_ring_dword hi_dword;
1513 ring_rxd_display_dword(union igb_ring_dword dword)
1515 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1516 (unsigned)dword.words.hi);
1520 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1521 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1524 __rte_unused uint8_t port_id,
1528 struct igb_ring_desc_16_bytes *ring =
1529 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1530 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1531 struct rte_eth_dev_info dev_info;
1533 memset(&dev_info, 0, sizeof(dev_info));
1534 rte_eth_dev_info_get(port_id, &dev_info);
1535 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1536 /* 32 bytes RX descriptor, i40e only */
1537 struct igb_ring_desc_32_bytes *ring =
1538 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1539 ring[desc_id].lo_dword.dword =
1540 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1541 ring_rxd_display_dword(ring[desc_id].lo_dword);
1542 ring[desc_id].hi_dword.dword =
1543 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1544 ring_rxd_display_dword(ring[desc_id].hi_dword);
1545 ring[desc_id].resv1.dword =
1546 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1547 ring_rxd_display_dword(ring[desc_id].resv1);
1548 ring[desc_id].resv2.dword =
1549 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1550 ring_rxd_display_dword(ring[desc_id].resv2);
1555 /* 16 bytes RX descriptor */
1556 ring[desc_id].lo_dword.dword =
1557 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1558 ring_rxd_display_dword(ring[desc_id].lo_dword);
1559 ring[desc_id].hi_dword.dword =
1560 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1561 ring_rxd_display_dword(ring[desc_id].hi_dword);
1565 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1567 struct igb_ring_desc_16_bytes *ring;
1568 struct igb_ring_desc_16_bytes txd;
1570 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1571 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1572 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1573 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1574 (unsigned)txd.lo_dword.words.lo,
1575 (unsigned)txd.lo_dword.words.hi,
1576 (unsigned)txd.hi_dword.words.lo,
1577 (unsigned)txd.hi_dword.words.hi);
1581 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1583 const struct rte_memzone *rx_mz;
1585 if (port_id_is_invalid(port_id, ENABLED_WARN))
1587 if (rx_queue_id_is_invalid(rxq_id))
1589 if (rx_desc_id_is_invalid(rxd_id))
1591 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1594 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1598 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1600 const struct rte_memzone *tx_mz;
1602 if (port_id_is_invalid(port_id, ENABLED_WARN))
1604 if (tx_queue_id_is_invalid(txq_id))
1606 if (tx_desc_id_is_invalid(txd_id))
1608 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1611 ring_tx_descriptor_display(tx_mz, txd_id);
1615 fwd_lcores_config_display(void)
1619 printf("List of forwarding lcores:");
1620 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1621 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1625 rxtx_config_display(void)
1627 printf(" %s packet forwarding%s - CRC stripping %s - "
1628 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
1629 retry_enabled == 0 ? "" : " with retry",
1630 rx_mode.hw_strip_crc ? "enabled" : "disabled",
1633 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1634 printf(" packet len=%u - nb packet segments=%d\n",
1635 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1637 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
1638 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
1640 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1641 nb_fwd_lcores, nb_fwd_ports);
1642 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1643 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1644 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1645 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
1646 rx_conf->rx_thresh.wthresh);
1647 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1648 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1649 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1650 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
1651 tx_conf->tx_thresh.wthresh);
1652 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
1653 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
1657 port_rss_reta_info(portid_t port_id,
1658 struct rte_eth_rss_reta_entry64 *reta_conf,
1659 uint16_t nb_entries)
1661 uint16_t i, idx, shift;
1664 if (port_id_is_invalid(port_id, ENABLED_WARN))
1667 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1669 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1673 for (i = 0; i < nb_entries; i++) {
1674 idx = i / RTE_RETA_GROUP_SIZE;
1675 shift = i % RTE_RETA_GROUP_SIZE;
1676 if (!(reta_conf[idx].mask & (1ULL << shift)))
1678 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1679 i, reta_conf[idx].reta[shift]);
1684 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1688 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1690 struct rte_eth_rss_conf rss_conf;
1691 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1695 struct rte_eth_dev_info dev_info;
1696 uint8_t hash_key_size;
1698 if (port_id_is_invalid(port_id, ENABLED_WARN))
1701 memset(&dev_info, 0, sizeof(dev_info));
1702 rte_eth_dev_info_get(port_id, &dev_info);
1703 if (dev_info.hash_key_size > 0 &&
1704 dev_info.hash_key_size <= sizeof(rss_key))
1705 hash_key_size = dev_info.hash_key_size;
1707 printf("dev_info did not provide a valid hash key size\n");
1711 rss_conf.rss_hf = 0;
1712 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1713 if (!strcmp(rss_info, rss_type_table[i].str))
1714 rss_conf.rss_hf = rss_type_table[i].rss_type;
1717 /* Get RSS hash key if asked to display it */
1718 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1719 rss_conf.rss_key_len = hash_key_size;
1720 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1724 printf("port index %d invalid\n", port_id);
1727 printf("operation not supported by device\n");
1730 printf("operation failed - diag=%d\n", diag);
1735 rss_hf = rss_conf.rss_hf;
1737 printf("RSS disabled\n");
1740 printf("RSS functions:\n ");
1741 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1742 if (rss_hf & rss_type_table[i].rss_type)
1743 printf("%s ", rss_type_table[i].str);
1748 printf("RSS key:\n");
1749 for (i = 0; i < hash_key_size; i++)
1750 printf("%02X", rss_key[i]);
1755 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1758 struct rte_eth_rss_conf rss_conf;
1762 rss_conf.rss_key = NULL;
1763 rss_conf.rss_key_len = hash_key_len;
1764 rss_conf.rss_hf = 0;
1765 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1766 if (!strcmp(rss_type_table[i].str, rss_type))
1767 rss_conf.rss_hf = rss_type_table[i].rss_type;
1769 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1771 rss_conf.rss_key = hash_key;
1772 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1779 printf("port index %d invalid\n", port_id);
1782 printf("operation not supported by device\n");
1785 printf("operation failed - diag=%d\n", diag);
1791 * Setup forwarding configuration for each logical core.
1794 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1796 streamid_t nb_fs_per_lcore;
1804 nb_fs = cfg->nb_fwd_streams;
1805 nb_fc = cfg->nb_fwd_lcores;
1806 if (nb_fs <= nb_fc) {
1807 nb_fs_per_lcore = 1;
1810 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1811 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1814 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1816 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1817 fwd_lcores[lc_id]->stream_idx = sm_id;
1818 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1819 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1823 * Assign extra remaining streams, if any.
1825 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1826 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1827 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1828 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1829 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1834 simple_fwd_config_setup(void)
1840 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1841 port_topology == PORT_TOPOLOGY_LOOP) {
1843 } else if (nb_fwd_ports % 2) {
1844 printf("\nWarning! Cannot handle an odd number of ports "
1845 "with the current port topology. Configuration "
1846 "must be changed to have an even number of ports, "
1847 "or relaunch application with "
1848 "--port-topology=chained\n\n");
1851 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1852 cur_fwd_config.nb_fwd_streams =
1853 (streamid_t) cur_fwd_config.nb_fwd_ports;
1855 /* reinitialize forwarding streams */
1859 * In the simple forwarding test, the number of forwarding cores
1860 * must be lower or equal to the number of forwarding ports.
1862 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1863 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1864 cur_fwd_config.nb_fwd_lcores =
1865 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1866 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1868 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1869 if (port_topology != PORT_TOPOLOGY_LOOP)
1870 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1873 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1874 fwd_streams[i]->rx_queue = 0;
1875 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1876 fwd_streams[i]->tx_queue = 0;
1877 fwd_streams[i]->peer_addr = j;
1878 fwd_streams[i]->retry_enabled = retry_enabled;
1880 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1881 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1882 fwd_streams[j]->rx_queue = 0;
1883 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1884 fwd_streams[j]->tx_queue = 0;
1885 fwd_streams[j]->peer_addr = i;
1886 fwd_streams[j]->retry_enabled = retry_enabled;
1892 * For the RSS forwarding test all streams distributed over lcores. Each stream
1893 * being composed of a RX queue to poll on a RX port for input messages,
1894 * associated with a TX queue of a TX port where to send forwarded packets.
1895 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1896 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1898 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1902 rss_fwd_config_setup(void)
1913 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1914 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1915 cur_fwd_config.nb_fwd_streams =
1916 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1918 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1919 cur_fwd_config.nb_fwd_lcores =
1920 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1922 /* reinitialize forwarding streams */
1925 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1927 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1928 struct fwd_stream *fs;
1930 fs = fwd_streams[sm_id];
1932 if ((rxp & 0x1) == 0)
1933 txp = (portid_t) (rxp + 1);
1935 txp = (portid_t) (rxp - 1);
1937 * if we are in loopback, simply send stuff out through the
1940 if (port_topology == PORT_TOPOLOGY_LOOP)
1943 fs->rx_port = fwd_ports_ids[rxp];
1945 fs->tx_port = fwd_ports_ids[txp];
1947 fs->peer_addr = fs->tx_port;
1948 fs->retry_enabled = retry_enabled;
1949 rxq = (queueid_t) (rxq + 1);
1954 * Restart from RX queue 0 on next RX port
1957 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1959 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1961 rxp = (portid_t) (rxp + 1);
1966 * For the DCB forwarding test, each core is assigned on each traffic class.
1968 * Each core is assigned a multi-stream, each stream being composed of
1969 * a RX queue to poll on a RX port for input messages, associated with
1970 * a TX queue of a TX port where to send forwarded packets. All RX and
1971 * TX queues are mapping to the same traffic class.
1972 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1976 dcb_fwd_config_setup(void)
1978 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1979 portid_t txp, rxp = 0;
1980 queueid_t txq, rxq = 0;
1982 uint16_t nb_rx_queue, nb_tx_queue;
1983 uint16_t i, j, k, sm_id = 0;
1986 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1987 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1988 cur_fwd_config.nb_fwd_streams =
1989 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1991 /* reinitialize forwarding streams */
1995 /* get the dcb info on the first RX and TX ports */
1996 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1997 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
1999 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2000 fwd_lcores[lc_id]->stream_nb = 0;
2001 fwd_lcores[lc_id]->stream_idx = sm_id;
2002 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2003 /* if the nb_queue is zero, means this tc is
2004 * not enabled on the POOL
2006 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2008 k = fwd_lcores[lc_id]->stream_nb +
2009 fwd_lcores[lc_id]->stream_idx;
2010 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2011 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2012 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2013 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2014 for (j = 0; j < nb_rx_queue; j++) {
2015 struct fwd_stream *fs;
2017 fs = fwd_streams[k + j];
2018 fs->rx_port = fwd_ports_ids[rxp];
2019 fs->rx_queue = rxq + j;
2020 fs->tx_port = fwd_ports_ids[txp];
2021 fs->tx_queue = txq + j % nb_tx_queue;
2022 fs->peer_addr = fs->tx_port;
2023 fs->retry_enabled = retry_enabled;
2025 fwd_lcores[lc_id]->stream_nb +=
2026 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2028 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2031 if (tc < rxp_dcb_info.nb_tcs)
2033 /* Restart from TC 0 on next RX port */
2035 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2037 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2040 if (rxp >= nb_fwd_ports)
2042 /* get the dcb information on next RX and TX ports */
2043 if ((rxp & 0x1) == 0)
2044 txp = (portid_t) (rxp + 1);
2046 txp = (portid_t) (rxp - 1);
2047 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2048 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2053 icmp_echo_config_setup(void)
2060 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2061 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2062 (nb_txq * nb_fwd_ports);
2064 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2065 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2066 cur_fwd_config.nb_fwd_streams =
2067 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2068 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2069 cur_fwd_config.nb_fwd_lcores =
2070 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2071 if (verbose_level > 0) {
2072 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2074 cur_fwd_config.nb_fwd_lcores,
2075 cur_fwd_config.nb_fwd_ports,
2076 cur_fwd_config.nb_fwd_streams);
2079 /* reinitialize forwarding streams */
2081 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2083 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2084 if (verbose_level > 0)
2085 printf(" core=%d: \n", lc_id);
2086 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2087 struct fwd_stream *fs;
2088 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2089 fs->rx_port = fwd_ports_ids[rxp];
2091 fs->tx_port = fs->rx_port;
2093 fs->peer_addr = fs->tx_port;
2094 fs->retry_enabled = retry_enabled;
2095 if (verbose_level > 0)
2096 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2097 sm_id, fs->rx_port, fs->rx_queue,
2099 rxq = (queueid_t) (rxq + 1);
2100 if (rxq == nb_rxq) {
2102 rxp = (portid_t) (rxp + 1);
2109 fwd_config_setup(void)
2111 cur_fwd_config.fwd_eng = cur_fwd_eng;
2112 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2113 icmp_echo_config_setup();
2116 if ((nb_rxq > 1) && (nb_txq > 1)){
2118 dcb_fwd_config_setup();
2120 rss_fwd_config_setup();
2123 simple_fwd_config_setup();
2127 pkt_fwd_config_display(struct fwd_config *cfg)
2129 struct fwd_stream *fs;
2133 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2134 "NUMA support %s, MP over anonymous pages %s\n",
2135 cfg->fwd_eng->fwd_mode_name,
2136 retry_enabled == 0 ? "" : " with retry",
2137 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2138 numa_support == 1 ? "enabled" : "disabled",
2139 mp_anon != 0 ? "enabled" : "disabled");
2142 printf("TX retry num: %u, delay between TX retries: %uus\n",
2143 burst_tx_retry_num, burst_tx_delay_time);
2144 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2145 printf("Logical Core %u (socket %u) forwards packets on "
2147 fwd_lcores_cpuids[lc_id],
2148 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2149 fwd_lcores[lc_id]->stream_nb);
2150 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2151 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2152 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2153 "P=%d/Q=%d (socket %u) ",
2154 fs->rx_port, fs->rx_queue,
2155 ports[fs->rx_port].socket_id,
2156 fs->tx_port, fs->tx_queue,
2157 ports[fs->tx_port].socket_id);
2158 print_ethaddr("peer=",
2159 &peer_eth_addrs[fs->peer_addr]);
2167 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2170 unsigned int lcore_cpuid;
2175 for (i = 0; i < nb_lc; i++) {
2176 lcore_cpuid = lcorelist[i];
2177 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2178 printf("lcore %u not enabled\n", lcore_cpuid);
2181 if (lcore_cpuid == rte_get_master_lcore()) {
2182 printf("lcore %u cannot be masked on for running "
2183 "packet forwarding, which is the master lcore "
2184 "and reserved for command line parsing only\n",
2189 fwd_lcores_cpuids[i] = lcore_cpuid;
2191 if (record_now == 0) {
2195 nb_cfg_lcores = (lcoreid_t) nb_lc;
2196 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2197 printf("previous number of forwarding cores %u - changed to "
2198 "number of configured cores %u\n",
2199 (unsigned int) nb_fwd_lcores, nb_lc);
2200 nb_fwd_lcores = (lcoreid_t) nb_lc;
2207 set_fwd_lcores_mask(uint64_t lcoremask)
2209 unsigned int lcorelist[64];
2213 if (lcoremask == 0) {
2214 printf("Invalid NULL mask of cores\n");
2218 for (i = 0; i < 64; i++) {
2219 if (! ((uint64_t)(1ULL << i) & lcoremask))
2221 lcorelist[nb_lc++] = i;
2223 return set_fwd_lcores_list(lcorelist, nb_lc);
2227 set_fwd_lcores_number(uint16_t nb_lc)
2229 if (nb_lc > nb_cfg_lcores) {
2230 printf("nb fwd cores %u > %u (max. number of configured "
2231 "lcores) - ignored\n",
2232 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2235 nb_fwd_lcores = (lcoreid_t) nb_lc;
2236 printf("Number of forwarding cores set to %u\n",
2237 (unsigned int) nb_fwd_lcores);
2241 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2249 for (i = 0; i < nb_pt; i++) {
2250 port_id = (portid_t) portlist[i];
2251 if (port_id_is_invalid(port_id, ENABLED_WARN))
2254 fwd_ports_ids[i] = port_id;
2256 if (record_now == 0) {
2260 nb_cfg_ports = (portid_t) nb_pt;
2261 if (nb_fwd_ports != (portid_t) nb_pt) {
2262 printf("previous number of forwarding ports %u - changed to "
2263 "number of configured ports %u\n",
2264 (unsigned int) nb_fwd_ports, nb_pt);
2265 nb_fwd_ports = (portid_t) nb_pt;
2270 set_fwd_ports_mask(uint64_t portmask)
2272 unsigned int portlist[64];
2276 if (portmask == 0) {
2277 printf("Invalid NULL mask of ports\n");
2281 RTE_ETH_FOREACH_DEV(i) {
2282 if (! ((uint64_t)(1ULL << i) & portmask))
2284 portlist[nb_pt++] = i;
2286 set_fwd_ports_list(portlist, nb_pt);
2290 set_fwd_ports_number(uint16_t nb_pt)
2292 if (nb_pt > nb_cfg_ports) {
2293 printf("nb fwd ports %u > %u (number of configured "
2294 "ports) - ignored\n",
2295 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2298 nb_fwd_ports = (portid_t) nb_pt;
2299 printf("Number of forwarding ports set to %u\n",
2300 (unsigned int) nb_fwd_ports);
2304 port_is_forwarding(portid_t port_id)
2308 if (port_id_is_invalid(port_id, ENABLED_WARN))
2311 for (i = 0; i < nb_fwd_ports; i++) {
2312 if (fwd_ports_ids[i] == port_id)
2320 set_nb_pkt_per_burst(uint16_t nb)
2322 if (nb > MAX_PKT_BURST) {
2323 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2325 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2328 nb_pkt_per_burst = nb;
2329 printf("Number of packets per burst set to %u\n",
2330 (unsigned int) nb_pkt_per_burst);
2334 tx_split_get_name(enum tx_pkt_split split)
2338 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2339 if (tx_split_name[i].split == split)
2340 return tx_split_name[i].name;
2346 set_tx_pkt_split(const char *name)
2350 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2351 if (strcmp(tx_split_name[i].name, name) == 0) {
2352 tx_pkt_split = tx_split_name[i].split;
2356 printf("unknown value: \"%s\"\n", name);
2360 show_tx_pkt_segments(void)
2366 split = tx_split_get_name(tx_pkt_split);
2368 printf("Number of segments: %u\n", n);
2369 printf("Segment sizes: ");
2370 for (i = 0; i != n - 1; i++)
2371 printf("%hu,", tx_pkt_seg_lengths[i]);
2372 printf("%hu\n", tx_pkt_seg_lengths[i]);
2373 printf("Split packet: %s\n", split);
2377 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2379 uint16_t tx_pkt_len;
2382 if (nb_segs >= (unsigned) nb_txd) {
2383 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2384 nb_segs, (unsigned int) nb_txd);
2389 * Check that each segment length is greater or equal than
2390 * the mbuf data sise.
2391 * Check also that the total packet length is greater or equal than the
2392 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2395 for (i = 0; i < nb_segs; i++) {
2396 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2397 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2398 i, seg_lengths[i], (unsigned) mbuf_data_size);
2401 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2403 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2404 printf("total packet length=%u < %d - give up\n",
2405 (unsigned) tx_pkt_len,
2406 (int)(sizeof(struct ether_hdr) + 20 + 8));
2410 for (i = 0; i < nb_segs; i++)
2411 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2413 tx_pkt_length = tx_pkt_len;
2414 tx_pkt_nb_segs = (uint8_t) nb_segs;
2418 list_pkt_forwarding_modes(void)
2420 static char fwd_modes[128] = "";
2421 const char *separator = "|";
2422 struct fwd_engine *fwd_eng;
2425 if (strlen (fwd_modes) == 0) {
2426 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2427 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2428 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2429 strncat(fwd_modes, separator,
2430 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2432 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2439 list_pkt_forwarding_retry_modes(void)
2441 static char fwd_modes[128] = "";
2442 const char *separator = "|";
2443 struct fwd_engine *fwd_eng;
2446 if (strlen(fwd_modes) == 0) {
2447 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2448 if (fwd_eng == &rx_only_engine)
2450 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2452 strlen(fwd_modes) - 1);
2453 strncat(fwd_modes, separator,
2455 strlen(fwd_modes) - 1);
2457 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2464 set_pkt_forwarding_mode(const char *fwd_mode_name)
2466 struct fwd_engine *fwd_eng;
2470 while ((fwd_eng = fwd_engines[i]) != NULL) {
2471 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2472 printf("Set %s packet forwarding mode%s\n",
2474 retry_enabled == 0 ? "" : " with retry");
2475 cur_fwd_eng = fwd_eng;
2480 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2484 set_verbose_level(uint16_t vb_level)
2486 printf("Change verbose level from %u to %u\n",
2487 (unsigned int) verbose_level, (unsigned int) vb_level);
2488 verbose_level = vb_level;
2492 vlan_extend_set(portid_t port_id, int on)
2497 if (port_id_is_invalid(port_id, ENABLED_WARN))
2500 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2503 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2505 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2507 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2509 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2510 "diag=%d\n", port_id, on, diag);
2514 rx_vlan_strip_set(portid_t port_id, int on)
2519 if (port_id_is_invalid(port_id, ENABLED_WARN))
2522 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2525 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2527 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2529 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2531 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2532 "diag=%d\n", port_id, on, diag);
2536 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2540 if (port_id_is_invalid(port_id, ENABLED_WARN))
2543 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2545 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2546 "diag=%d\n", port_id, queue_id, on, diag);
2550 rx_vlan_filter_set(portid_t port_id, int on)
2555 if (port_id_is_invalid(port_id, ENABLED_WARN))
2558 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2561 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2563 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2565 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2567 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2568 "diag=%d\n", port_id, on, diag);
2572 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2576 if (port_id_is_invalid(port_id, ENABLED_WARN))
2578 if (vlan_id_is_invalid(vlan_id))
2580 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2583 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2585 port_id, vlan_id, on, diag);
2590 rx_vlan_all_filter_set(portid_t port_id, int on)
2594 if (port_id_is_invalid(port_id, ENABLED_WARN))
2596 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2597 if (rx_vft_set(port_id, vlan_id, on))
2603 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2607 if (port_id_is_invalid(port_id, ENABLED_WARN))
2610 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2614 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2616 port_id, vlan_type, tp_id, diag);
2620 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2623 if (port_id_is_invalid(port_id, ENABLED_WARN))
2625 if (vlan_id_is_invalid(vlan_id))
2628 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2629 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2630 printf("Error, as QinQ has been enabled.\n");
2634 tx_vlan_reset(port_id);
2635 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
2636 ports[port_id].tx_vlan_id = vlan_id;
2640 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2643 if (port_id_is_invalid(port_id, ENABLED_WARN))
2645 if (vlan_id_is_invalid(vlan_id))
2647 if (vlan_id_is_invalid(vlan_id_outer))
2650 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2651 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2652 printf("Error, as QinQ hasn't been enabled.\n");
2656 tx_vlan_reset(port_id);
2657 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
2658 ports[port_id].tx_vlan_id = vlan_id;
2659 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2663 tx_vlan_reset(portid_t port_id)
2665 if (port_id_is_invalid(port_id, ENABLED_WARN))
2667 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
2668 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
2669 ports[port_id].tx_vlan_id = 0;
2670 ports[port_id].tx_vlan_id_outer = 0;
2674 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2676 if (port_id_is_invalid(port_id, ENABLED_WARN))
2679 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2683 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2686 uint8_t existing_mapping_found = 0;
2688 if (port_id_is_invalid(port_id, ENABLED_WARN))
2691 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2694 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2695 printf("map_value not in required range 0..%d\n",
2696 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2700 if (!is_rx) { /*then tx*/
2701 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2702 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2703 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2704 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2705 existing_mapping_found = 1;
2709 if (!existing_mapping_found) { /* A new additional mapping... */
2710 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2711 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2712 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2713 nb_tx_queue_stats_mappings++;
2717 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2718 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2719 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2720 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2721 existing_mapping_found = 1;
2725 if (!existing_mapping_found) { /* A new additional mapping... */
2726 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2727 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2728 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2729 nb_rx_queue_stats_mappings++;
2735 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2737 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2739 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2740 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2741 " tunnel_id: 0x%08x",
2742 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2743 rte_be_to_cpu_32(mask->tunnel_id_mask));
2744 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2745 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2746 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2747 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2749 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2750 rte_be_to_cpu_16(mask->src_port_mask),
2751 rte_be_to_cpu_16(mask->dst_port_mask));
2753 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2754 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2755 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
2756 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
2757 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
2759 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2760 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
2761 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
2762 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
2763 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
2770 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2772 struct rte_eth_flex_payload_cfg *cfg;
2775 for (i = 0; i < flex_conf->nb_payloads; i++) {
2776 cfg = &flex_conf->flex_set[i];
2777 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2779 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2780 printf("\n L2_PAYLOAD: ");
2781 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2782 printf("\n L3_PAYLOAD: ");
2783 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2784 printf("\n L4_PAYLOAD: ");
2786 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2787 for (j = 0; j < num; j++)
2788 printf(" %-5u", cfg->src_offset[j]);
2794 flowtype_to_str(uint16_t flow_type)
2796 struct flow_type_info {
2802 static struct flow_type_info flowtype_str_table[] = {
2803 {"raw", RTE_ETH_FLOW_RAW},
2804 {"ipv4", RTE_ETH_FLOW_IPV4},
2805 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2806 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2807 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2808 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2809 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2810 {"ipv6", RTE_ETH_FLOW_IPV6},
2811 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2812 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2813 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2814 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2815 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2816 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2817 {"port", RTE_ETH_FLOW_PORT},
2818 {"vxlan", RTE_ETH_FLOW_VXLAN},
2819 {"geneve", RTE_ETH_FLOW_GENEVE},
2820 {"nvgre", RTE_ETH_FLOW_NVGRE},
2823 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2824 if (flowtype_str_table[i].ftype == flow_type)
2825 return flowtype_str_table[i].str;
2832 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2834 struct rte_eth_fdir_flex_mask *mask;
2838 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2839 mask = &flex_conf->flex_mask[i];
2840 p = flowtype_to_str(mask->flow_type);
2841 printf("\n %s:\t", p ? p : "unknown");
2842 for (j = 0; j < num; j++)
2843 printf(" %02x", mask->mask[j]);
2849 print_fdir_flow_type(uint32_t flow_types_mask)
2854 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2855 if (!(flow_types_mask & (1 << i)))
2857 p = flowtype_to_str(i);
2867 fdir_get_infos(portid_t port_id)
2869 struct rte_eth_fdir_stats fdir_stat;
2870 struct rte_eth_fdir_info fdir_info;
2873 static const char *fdir_stats_border = "########################";
2875 if (port_id_is_invalid(port_id, ENABLED_WARN))
2877 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
2879 printf("\n FDIR is not supported on port %-2d\n",
2884 memset(&fdir_info, 0, sizeof(fdir_info));
2885 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2886 RTE_ETH_FILTER_INFO, &fdir_info);
2887 memset(&fdir_stat, 0, sizeof(fdir_stat));
2888 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2889 RTE_ETH_FILTER_STATS, &fdir_stat);
2890 printf("\n %s FDIR infos for port %-2d %s\n",
2891 fdir_stats_border, port_id, fdir_stats_border);
2893 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
2894 printf(" PERFECT\n");
2895 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2896 printf(" PERFECT-MAC-VLAN\n");
2897 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2898 printf(" PERFECT-TUNNEL\n");
2899 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
2900 printf(" SIGNATURE\n");
2902 printf(" DISABLE\n");
2903 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
2904 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
2905 printf(" SUPPORTED FLOW TYPE: ");
2906 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
2908 printf(" FLEX PAYLOAD INFO:\n");
2909 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
2910 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
2911 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
2912 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
2913 fdir_info.flex_payload_unit,
2914 fdir_info.max_flex_payload_segment_num,
2915 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
2917 print_fdir_mask(&fdir_info.mask);
2918 if (fdir_info.flex_conf.nb_payloads > 0) {
2919 printf(" FLEX PAYLOAD SRC OFFSET:");
2920 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2922 if (fdir_info.flex_conf.nb_flexmasks > 0) {
2923 printf(" FLEX MASK CFG:");
2924 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2926 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2927 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2928 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2929 fdir_info.guarant_spc, fdir_info.best_spc);
2930 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2931 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2932 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2933 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2934 fdir_stat.collision, fdir_stat.free,
2935 fdir_stat.maxhash, fdir_stat.maxlen,
2936 fdir_stat.add, fdir_stat.remove,
2937 fdir_stat.f_add, fdir_stat.f_remove);
2938 printf(" %s############################%s\n",
2939 fdir_stats_border, fdir_stats_border);
2943 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2945 struct rte_port *port;
2946 struct rte_eth_fdir_flex_conf *flex_conf;
2949 port = &ports[port_id];
2950 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2951 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2952 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2957 if (i >= RTE_ETH_FLOW_MAX) {
2958 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2959 idx = flex_conf->nb_flexmasks;
2960 flex_conf->nb_flexmasks++;
2962 printf("The flex mask table is full. Can not set flex"
2963 " mask for flow_type(%u).", cfg->flow_type);
2967 (void)rte_memcpy(&flex_conf->flex_mask[idx],
2969 sizeof(struct rte_eth_fdir_flex_mask));
2973 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2975 struct rte_port *port;
2976 struct rte_eth_fdir_flex_conf *flex_conf;
2979 port = &ports[port_id];
2980 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2981 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2982 if (cfg->type == flex_conf->flex_set[i].type) {
2987 if (i >= RTE_ETH_PAYLOAD_MAX) {
2988 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2989 idx = flex_conf->nb_payloads;
2990 flex_conf->nb_payloads++;
2992 printf("The flex payload table is full. Can not set"
2993 " flex payload for type(%u).", cfg->type);
2997 (void)rte_memcpy(&flex_conf->flex_set[idx],
2999 sizeof(struct rte_eth_flex_payload_cfg));
3004 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3006 #ifdef RTE_LIBRTE_IXGBE_PMD
3010 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3012 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3016 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
3017 is_rx ? "rx" : "tx", port_id, diag);
3020 printf("VF %s setting not supported for port %d\n",
3021 is_rx ? "Rx" : "Tx", port_id);
3027 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3030 struct rte_eth_link link;
3032 if (port_id_is_invalid(port_id, ENABLED_WARN))
3034 rte_eth_link_get_nowait(port_id, &link);
3035 if (rate > link.link_speed) {
3036 printf("Invalid rate value:%u bigger than link speed: %u\n",
3037 rate, link.link_speed);
3040 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3043 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3049 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3051 int diag = -ENOTSUP;
3053 #ifdef RTE_LIBRTE_IXGBE_PMD
3054 if (diag == -ENOTSUP)
3055 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
3058 #ifdef RTE_LIBRTE_BNXT_PMD
3059 if (diag == -ENOTSUP)
3060 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
3065 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n",
3071 * Functions to manage the set of filtered Multicast MAC addresses.
3073 * A pool of filtered multicast MAC addresses is associated with each port.
3074 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3075 * The address of the pool and the number of valid multicast MAC addresses
3076 * recorded in the pool are stored in the fields "mc_addr_pool" and
3077 * "mc_addr_nb" of the "rte_port" data structure.
3079 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3080 * to be supplied a contiguous array of multicast MAC addresses.
3081 * To comply with this constraint, the set of multicast addresses recorded
3082 * into the pool are systematically compacted at the beginning of the pool.
3083 * Hence, when a multicast address is removed from the pool, all following
3084 * addresses, if any, are copied back to keep the set contiguous.
3086 #define MCAST_POOL_INC 32
3089 mcast_addr_pool_extend(struct rte_port *port)
3091 struct ether_addr *mc_pool;
3092 size_t mc_pool_size;
3095 * If a free entry is available at the end of the pool, just
3096 * increment the number of recorded multicast addresses.
3098 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3104 * [re]allocate a pool with MCAST_POOL_INC more entries.
3105 * The previous test guarantees that port->mc_addr_nb is a multiple
3106 * of MCAST_POOL_INC.
3108 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3110 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3112 if (mc_pool == NULL) {
3113 printf("allocation of pool of %u multicast addresses failed\n",
3114 port->mc_addr_nb + MCAST_POOL_INC);
3118 port->mc_addr_pool = mc_pool;
3125 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3128 if (addr_idx == port->mc_addr_nb) {
3129 /* No need to recompact the set of multicast addressses. */
3130 if (port->mc_addr_nb == 0) {
3131 /* free the pool of multicast addresses. */
3132 free(port->mc_addr_pool);
3133 port->mc_addr_pool = NULL;
3137 memmove(&port->mc_addr_pool[addr_idx],
3138 &port->mc_addr_pool[addr_idx + 1],
3139 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3143 eth_port_multicast_addr_list_set(uint8_t port_id)
3145 struct rte_port *port;
3148 port = &ports[port_id];
3149 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3153 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3154 port->mc_addr_nb, port_id, -diag);
3158 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
3160 struct rte_port *port;
3163 if (port_id_is_invalid(port_id, ENABLED_WARN))
3166 port = &ports[port_id];
3169 * Check that the added multicast MAC address is not already recorded
3170 * in the pool of multicast addresses.
3172 for (i = 0; i < port->mc_addr_nb; i++) {
3173 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3174 printf("multicast address already filtered by port\n");
3179 if (mcast_addr_pool_extend(port) != 0)
3181 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3182 eth_port_multicast_addr_list_set(port_id);
3186 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
3188 struct rte_port *port;
3191 if (port_id_is_invalid(port_id, ENABLED_WARN))
3194 port = &ports[port_id];
3197 * Search the pool of multicast MAC addresses for the removed address.
3199 for (i = 0; i < port->mc_addr_nb; i++) {
3200 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3203 if (i == port->mc_addr_nb) {
3204 printf("multicast address not filtered by port %d\n", port_id);
3208 mcast_addr_pool_remove(port, i);
3209 eth_port_multicast_addr_list_set(port_id);
3213 port_dcb_info_display(uint8_t port_id)
3215 struct rte_eth_dcb_info dcb_info;
3218 static const char *border = "================";
3220 if (port_id_is_invalid(port_id, ENABLED_WARN))
3223 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3225 printf("\n Failed to get dcb infos on port %-2d\n",
3229 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3230 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3232 for (i = 0; i < dcb_info.nb_tcs; i++)
3234 printf("\n Priority : ");
3235 for (i = 0; i < dcb_info.nb_tcs; i++)
3236 printf("\t%4d", dcb_info.prio_tc[i]);
3237 printf("\n BW percent :");
3238 for (i = 0; i < dcb_info.nb_tcs; i++)
3239 printf("\t%4d%%", dcb_info.tc_bws[i]);
3240 printf("\n RXQ base : ");
3241 for (i = 0; i < dcb_info.nb_tcs; i++)
3242 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3243 printf("\n RXQ number :");
3244 for (i = 0; i < dcb_info.nb_tcs; i++)
3245 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3246 printf("\n TXQ base : ");
3247 for (i = 0; i < dcb_info.nb_tcs; i++)
3248 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3249 printf("\n TXQ number :");
3250 for (i = 0; i < dcb_info.nb_tcs; i++)
3251 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3256 open_ddp_package_file(const char *file_path, uint32_t *size)
3258 FILE *fh = fopen(file_path, "rb");
3260 uint8_t *buf = NULL;
3267 printf("%s: Failed to open %s\n", __func__, file_path);
3271 ret = fseek(fh, 0, SEEK_END);
3274 printf("%s: File operations failed\n", __func__);
3278 pkg_size = ftell(fh);
3280 buf = (uint8_t *)malloc(pkg_size);
3283 printf("%s: Failed to malloc memory\n", __func__);
3287 ret = fseek(fh, 0, SEEK_SET);
3290 printf("%s: File seek operation failed\n", __func__);
3291 close_ddp_package_file(buf);
3295 ret = fread(buf, 1, pkg_size, fh);
3298 printf("%s: File read operation failed\n", __func__);
3299 close_ddp_package_file(buf);
3312 close_ddp_package_file(uint8_t *buf)