4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * Copyright 2013-2014 6WIND S.A.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name of 6WIND S.A. nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72 #include <sys/queue.h>
74 #include <rte_common.h>
75 #include <rte_byteorder.h>
76 #include <rte_debug.h>
78 #include <rte_memory.h>
79 #include <rte_memcpy.h>
80 #include <rte_memzone.h>
81 #include <rte_launch.h>
83 #include <rte_per_lcore.h>
84 #include <rte_lcore.h>
85 #include <rte_atomic.h>
86 #include <rte_branch_prediction.h>
87 #include <rte_mempool.h>
89 #include <rte_interrupts.h>
91 #include <rte_ether.h>
92 #include <rte_ethdev.h>
93 #include <rte_string_fns.h>
94 #include <rte_cycles.h>
96 #include <rte_errno.h>
97 #ifdef RTE_LIBRTE_IXGBE_PMD
98 #include <rte_pmd_ixgbe.h>
103 static char *flowtype_to_str(uint16_t flow_type);
105 static const struct {
106 enum tx_pkt_split split;
108 } tx_split_name[] = {
110 .split = TX_PKT_SPLIT_OFF,
114 .split = TX_PKT_SPLIT_ON,
118 .split = TX_PKT_SPLIT_RND,
123 struct rss_type_info {
128 static const struct rss_type_info rss_type_table[] = {
129 { "ipv4", ETH_RSS_IPV4 },
130 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
131 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
132 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
133 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
134 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
135 { "ipv6", ETH_RSS_IPV6 },
136 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
137 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
138 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
139 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
140 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
141 { "l2-payload", ETH_RSS_L2_PAYLOAD },
142 { "ipv6-ex", ETH_RSS_IPV6_EX },
143 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
144 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
145 { "port", ETH_RSS_PORT },
146 { "vxlan", ETH_RSS_VXLAN },
147 { "geneve", ETH_RSS_GENEVE },
148 { "nvgre", ETH_RSS_NVGRE },
153 print_ethaddr(const char *name, struct ether_addr *eth_addr)
155 char buf[ETHER_ADDR_FMT_SIZE];
156 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
157 printf("%s%s", name, buf);
161 nic_stats_display(portid_t port_id)
163 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
164 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
165 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
166 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles;
167 uint64_t mpps_rx, mpps_tx;
168 struct rte_eth_stats stats;
169 struct rte_port *port = &ports[port_id];
173 static const char *nic_stats_border = "########################";
175 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
176 printf("Valid port range is [0");
177 RTE_ETH_FOREACH_DEV(pid)
182 rte_eth_stats_get(port_id, &stats);
183 printf("\n %s NIC statistics for port %-2d %s\n",
184 nic_stats_border, port_id, nic_stats_border);
186 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
187 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
189 stats.ipackets, stats.imissed, stats.ibytes);
190 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
191 printf(" RX-nombuf: %-10"PRIu64"\n",
193 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
195 stats.opackets, stats.oerrors, stats.obytes);
198 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
199 " RX-bytes: %10"PRIu64"\n",
200 stats.ipackets, stats.ierrors, stats.ibytes);
201 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
202 printf(" RX-nombuf: %10"PRIu64"\n",
204 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
205 " TX-bytes: %10"PRIu64"\n",
206 stats.opackets, stats.oerrors, stats.obytes);
209 if (port->rx_queue_stats_mapping_enabled) {
211 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
212 printf(" Stats reg %2d RX-packets: %10"PRIu64
213 " RX-errors: %10"PRIu64
214 " RX-bytes: %10"PRIu64"\n",
215 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
218 if (port->tx_queue_stats_mapping_enabled) {
220 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
221 printf(" Stats reg %2d TX-packets: %10"PRIu64
222 " TX-bytes: %10"PRIu64"\n",
223 i, stats.q_opackets[i], stats.q_obytes[i]);
227 diff_cycles = prev_cycles[port_id];
228 prev_cycles[port_id] = rte_rdtsc();
230 diff_cycles = prev_cycles[port_id] - diff_cycles;
232 diff_pkts_rx = stats.ipackets - prev_pkts_rx[port_id];
233 diff_pkts_tx = stats.opackets - prev_pkts_tx[port_id];
234 prev_pkts_rx[port_id] = stats.ipackets;
235 prev_pkts_tx[port_id] = stats.opackets;
236 mpps_rx = diff_cycles > 0 ?
237 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
238 mpps_tx = diff_cycles > 0 ?
239 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
240 printf("\n Throughput (since last show)\n");
241 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
244 printf(" %s############################%s\n",
245 nic_stats_border, nic_stats_border);
249 nic_stats_clear(portid_t port_id)
253 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
254 printf("Valid port range is [0");
255 RTE_ETH_FOREACH_DEV(pid)
260 rte_eth_stats_reset(port_id);
261 printf("\n NIC statistics for port %d cleared\n", port_id);
265 nic_xstats_display(portid_t port_id)
267 struct rte_eth_xstat *xstats;
268 int cnt_xstats, idx_xstat;
269 struct rte_eth_xstat_name *xstats_names;
271 printf("###### NIC extended statistics for port %-2d\n", port_id);
272 if (!rte_eth_dev_is_valid_port(port_id)) {
273 printf("Error: Invalid port number %i\n", port_id);
278 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
279 if (cnt_xstats < 0) {
280 printf("Error: Cannot get count of xstats\n");
284 /* Get id-name lookup table */
285 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
286 if (xstats_names == NULL) {
287 printf("Cannot allocate memory for xstats lookup\n");
290 if (cnt_xstats != rte_eth_xstats_get_names(
291 port_id, xstats_names, cnt_xstats)) {
292 printf("Error: Cannot get xstats lookup\n");
297 /* Get stats themselves */
298 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
299 if (xstats == NULL) {
300 printf("Cannot allocate memory for xstats\n");
304 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
305 printf("Error: Unable to get xstats\n");
312 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
313 printf("%s: %"PRIu64"\n",
314 xstats_names[idx_xstat].name,
315 xstats[idx_xstat].value);
321 nic_xstats_clear(portid_t port_id)
323 rte_eth_xstats_reset(port_id);
327 nic_stats_mapping_display(portid_t port_id)
329 struct rte_port *port = &ports[port_id];
333 static const char *nic_stats_mapping_border = "########################";
335 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
336 printf("Valid port range is [0");
337 RTE_ETH_FOREACH_DEV(pid)
343 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
344 printf("Port id %d - either does not support queue statistic mapping or"
345 " no queue statistic mapping set\n", port_id);
349 printf("\n %s NIC statistics mapping for port %-2d %s\n",
350 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
352 if (port->rx_queue_stats_mapping_enabled) {
353 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
354 if (rx_queue_stats_mappings[i].port_id == port_id) {
355 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
356 rx_queue_stats_mappings[i].queue_id,
357 rx_queue_stats_mappings[i].stats_counter_id);
364 if (port->tx_queue_stats_mapping_enabled) {
365 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
366 if (tx_queue_stats_mappings[i].port_id == port_id) {
367 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
368 tx_queue_stats_mappings[i].queue_id,
369 tx_queue_stats_mappings[i].stats_counter_id);
374 printf(" %s####################################%s\n",
375 nic_stats_mapping_border, nic_stats_mapping_border);
379 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
381 struct rte_eth_rxq_info qinfo;
383 static const char *info_border = "*********************";
385 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
387 printf("Failed to retrieve information for port: %hhu, "
388 "RX queue: %hu\nerror desc: %s(%d)\n",
389 port_id, queue_id, strerror(-rc), rc);
393 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
394 info_border, port_id, queue_id, info_border);
396 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
397 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
398 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
399 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
400 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
401 printf("\nRX drop packets: %s",
402 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
403 printf("\nRX deferred start: %s",
404 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
405 printf("\nRX scattered packets: %s",
406 (qinfo.scattered_rx != 0) ? "on" : "off");
407 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
412 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
414 struct rte_eth_txq_info qinfo;
416 static const char *info_border = "*********************";
418 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
420 printf("Failed to retrieve information for port: %hhu, "
421 "TX queue: %hu\nerror desc: %s(%d)\n",
422 port_id, queue_id, strerror(-rc), rc);
426 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
427 info_border, port_id, queue_id, info_border);
429 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
430 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
431 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
432 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
433 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
434 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
435 printf("\nTX deferred start: %s",
436 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
437 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
442 port_infos_display(portid_t port_id)
444 struct rte_port *port;
445 struct ether_addr mac_addr;
446 struct rte_eth_link link;
447 struct rte_eth_dev_info dev_info;
449 struct rte_mempool * mp;
450 static const char *info_border = "*********************";
454 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
455 printf("Valid port range is [0");
456 RTE_ETH_FOREACH_DEV(pid)
461 port = &ports[port_id];
462 rte_eth_link_get_nowait(port_id, &link);
463 memset(&dev_info, 0, sizeof(dev_info));
464 rte_eth_dev_info_get(port_id, &dev_info);
465 printf("\n%s Infos for port %-2d %s\n",
466 info_border, port_id, info_border);
467 rte_eth_macaddr_get(port_id, &mac_addr);
468 print_ethaddr("MAC address: ", &mac_addr);
469 printf("\nDriver name: %s", dev_info.driver_name);
470 printf("\nConnect to socket: %u", port->socket_id);
472 if (port_numa[port_id] != NUMA_NO_CONFIG) {
473 mp = mbuf_pool_find(port_numa[port_id]);
475 printf("\nmemory allocation on the socket: %d",
478 printf("\nmemory allocation on the socket: %u",port->socket_id);
480 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
481 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
482 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
483 ("full-duplex") : ("half-duplex"));
485 if (!rte_eth_dev_get_mtu(port_id, &mtu))
486 printf("MTU: %u\n", mtu);
488 printf("Promiscuous mode: %s\n",
489 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
490 printf("Allmulticast mode: %s\n",
491 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
492 printf("Maximum number of MAC addresses: %u\n",
493 (unsigned int)(port->dev_info.max_mac_addrs));
494 printf("Maximum number of MAC addresses of hash filtering: %u\n",
495 (unsigned int)(port->dev_info.max_hash_mac_addrs));
497 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
498 if (vlan_offload >= 0){
499 printf("VLAN offload: \n");
500 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
501 printf(" strip on \n");
503 printf(" strip off \n");
505 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
506 printf(" filter on \n");
508 printf(" filter off \n");
510 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
511 printf(" qinq(extend) on \n");
513 printf(" qinq(extend) off \n");
516 if (dev_info.hash_key_size > 0)
517 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
518 if (dev_info.reta_size > 0)
519 printf("Redirection table size: %u\n", dev_info.reta_size);
520 if (!dev_info.flow_type_rss_offloads)
521 printf("No flow type is supported.\n");
526 printf("Supported flow types:\n");
527 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
529 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
531 p = flowtype_to_str(i);
532 printf(" %s\n", (p ? p : "unknown"));
536 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
537 printf("Max possible number of RXDs per queue: %hu\n",
538 dev_info.rx_desc_lim.nb_max);
539 printf("Min possible number of RXDs per queue: %hu\n",
540 dev_info.rx_desc_lim.nb_min);
541 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
543 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
544 printf("Max possible number of TXDs per queue: %hu\n",
545 dev_info.tx_desc_lim.nb_max);
546 printf("Min possible number of TXDs per queue: %hu\n",
547 dev_info.tx_desc_lim.nb_min);
548 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
552 port_offload_cap_display(portid_t port_id)
554 struct rte_eth_dev *dev;
555 struct rte_eth_dev_info dev_info;
556 static const char *info_border = "************";
558 if (port_id_is_invalid(port_id, ENABLED_WARN))
561 dev = &rte_eth_devices[port_id];
562 rte_eth_dev_info_get(port_id, &dev_info);
564 printf("\n%s Port %d supported offload features: %s\n",
565 info_border, port_id, info_border);
567 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
568 printf("VLAN stripped: ");
569 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
575 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
576 printf("Double VLANs stripped: ");
577 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
583 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
584 printf("RX IPv4 checksum: ");
585 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
591 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
592 printf("RX UDP checksum: ");
593 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
599 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
600 printf("RX TCP checksum: ");
601 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
607 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
608 printf("RX Outer IPv4 checksum: on");
610 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
611 printf("Large receive offload: ");
612 if (dev->data->dev_conf.rxmode.enable_lro)
618 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
619 printf("VLAN insert: ");
620 if (ports[port_id].tx_ol_flags &
621 TESTPMD_TX_OFFLOAD_INSERT_VLAN)
627 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
628 printf("Double VLANs insert: ");
629 if (ports[port_id].tx_ol_flags &
630 TESTPMD_TX_OFFLOAD_INSERT_QINQ)
636 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
637 printf("TX IPv4 checksum: ");
638 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
644 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
645 printf("TX UDP checksum: ");
646 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
652 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
653 printf("TX TCP checksum: ");
654 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
660 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
661 printf("TX SCTP checksum: ");
662 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
668 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
669 printf("TX Outer IPv4 checksum: ");
670 if (ports[port_id].tx_ol_flags &
671 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
677 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
678 printf("TX TCP segmentation: ");
679 if (ports[port_id].tso_segsz != 0)
685 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
686 printf("TX UDP segmentation: ");
687 if (ports[port_id].tso_segsz != 0)
693 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
694 printf("TSO for VXLAN tunnel packet: ");
695 if (ports[port_id].tunnel_tso_segsz)
701 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
702 printf("TSO for GRE tunnel packet: ");
703 if (ports[port_id].tunnel_tso_segsz)
709 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
710 printf("TSO for IPIP tunnel packet: ");
711 if (ports[port_id].tunnel_tso_segsz)
717 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
718 printf("TSO for GENEVE tunnel packet: ");
719 if (ports[port_id].tunnel_tso_segsz)
728 port_id_is_invalid(portid_t port_id, enum print_warning warning)
730 if (port_id == (portid_t)RTE_PORT_ALL)
733 if (rte_eth_dev_is_valid_port(port_id))
736 if (warning == ENABLED_WARN)
737 printf("Invalid port %d\n", port_id);
743 vlan_id_is_invalid(uint16_t vlan_id)
747 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
752 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
757 printf("Port register offset 0x%X not aligned on a 4-byte "
762 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
763 if (reg_off >= pci_len) {
764 printf("Port %d: register offset %u (0x%X) out of port PCI "
765 "resource (length=%"PRIu64")\n",
766 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
773 reg_bit_pos_is_invalid(uint8_t bit_pos)
777 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
781 #define display_port_and_reg_off(port_id, reg_off) \
782 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
785 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
787 display_port_and_reg_off(port_id, (unsigned)reg_off);
788 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
792 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
797 if (port_id_is_invalid(port_id, ENABLED_WARN))
799 if (port_reg_off_is_invalid(port_id, reg_off))
801 if (reg_bit_pos_is_invalid(bit_x))
803 reg_v = port_id_pci_reg_read(port_id, reg_off);
804 display_port_and_reg_off(port_id, (unsigned)reg_off);
805 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
809 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
810 uint8_t bit1_pos, uint8_t bit2_pos)
816 if (port_id_is_invalid(port_id, ENABLED_WARN))
818 if (port_reg_off_is_invalid(port_id, reg_off))
820 if (reg_bit_pos_is_invalid(bit1_pos))
822 if (reg_bit_pos_is_invalid(bit2_pos))
824 if (bit1_pos > bit2_pos)
825 l_bit = bit2_pos, h_bit = bit1_pos;
827 l_bit = bit1_pos, h_bit = bit2_pos;
829 reg_v = port_id_pci_reg_read(port_id, reg_off);
832 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
833 display_port_and_reg_off(port_id, (unsigned)reg_off);
834 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
835 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
839 port_reg_display(portid_t port_id, uint32_t reg_off)
843 if (port_id_is_invalid(port_id, ENABLED_WARN))
845 if (port_reg_off_is_invalid(port_id, reg_off))
847 reg_v = port_id_pci_reg_read(port_id, reg_off);
848 display_port_reg_value(port_id, reg_off, reg_v);
852 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
857 if (port_id_is_invalid(port_id, ENABLED_WARN))
859 if (port_reg_off_is_invalid(port_id, reg_off))
861 if (reg_bit_pos_is_invalid(bit_pos))
864 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
867 reg_v = port_id_pci_reg_read(port_id, reg_off);
869 reg_v &= ~(1 << bit_pos);
871 reg_v |= (1 << bit_pos);
872 port_id_pci_reg_write(port_id, reg_off, reg_v);
873 display_port_reg_value(port_id, reg_off, reg_v);
877 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
878 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
885 if (port_id_is_invalid(port_id, ENABLED_WARN))
887 if (port_reg_off_is_invalid(port_id, reg_off))
889 if (reg_bit_pos_is_invalid(bit1_pos))
891 if (reg_bit_pos_is_invalid(bit2_pos))
893 if (bit1_pos > bit2_pos)
894 l_bit = bit2_pos, h_bit = bit1_pos;
896 l_bit = bit1_pos, h_bit = bit2_pos;
898 if ((h_bit - l_bit) < 31)
899 max_v = (1 << (h_bit - l_bit + 1)) - 1;
904 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
905 (unsigned)value, (unsigned)value,
906 (unsigned)max_v, (unsigned)max_v);
909 reg_v = port_id_pci_reg_read(port_id, reg_off);
910 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
911 reg_v |= (value << l_bit); /* Set changed bits */
912 port_id_pci_reg_write(port_id, reg_off, reg_v);
913 display_port_reg_value(port_id, reg_off, reg_v);
917 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
919 if (port_id_is_invalid(port_id, ENABLED_WARN))
921 if (port_reg_off_is_invalid(port_id, reg_off))
923 port_id_pci_reg_write(port_id, reg_off, reg_v);
924 display_port_reg_value(port_id, reg_off, reg_v);
928 port_mtu_set(portid_t port_id, uint16_t mtu)
932 if (port_id_is_invalid(port_id, ENABLED_WARN))
934 diag = rte_eth_dev_set_mtu(port_id, mtu);
937 printf("Set MTU failed. diag=%d\n", diag);
940 /* Generic flow management functions. */
942 /** Generate flow_item[] entry. */
943 #define MK_FLOW_ITEM(t, s) \
944 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
949 /** Information about known flow pattern items. */
950 static const struct {
954 MK_FLOW_ITEM(END, 0),
955 MK_FLOW_ITEM(VOID, 0),
956 MK_FLOW_ITEM(INVERT, 0),
957 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
959 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
960 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
961 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
962 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
963 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
964 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
965 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
966 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
967 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
968 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
969 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
970 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
971 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
972 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
973 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
974 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
977 /** Compute storage space needed by item specification. */
979 flow_item_spec_size(const struct rte_flow_item *item,
980 size_t *size, size_t *pad)
984 switch (item->type) {
986 const struct rte_flow_item_raw *raw;
989 case RTE_FLOW_ITEM_TYPE_RAW:
990 spec.raw = item->spec;
991 *size = offsetof(struct rte_flow_item_raw, pattern) +
992 spec.raw->length * sizeof(*spec.raw->pattern);
999 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1002 /** Generate flow_action[] entry. */
1003 #define MK_FLOW_ACTION(t, s) \
1004 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
1009 /** Information about known flow actions. */
1010 static const struct {
1014 MK_FLOW_ACTION(END, 0),
1015 MK_FLOW_ACTION(VOID, 0),
1016 MK_FLOW_ACTION(PASSTHRU, 0),
1017 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1018 MK_FLOW_ACTION(FLAG, 0),
1019 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
1020 MK_FLOW_ACTION(DROP, 0),
1021 MK_FLOW_ACTION(COUNT, 0),
1022 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
1023 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
1024 MK_FLOW_ACTION(PF, 0),
1025 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
1028 /** Compute storage space needed by action configuration. */
1030 flow_action_conf_size(const struct rte_flow_action *action,
1031 size_t *size, size_t *pad)
1035 switch (action->type) {
1037 const struct rte_flow_action_rss *rss;
1040 case RTE_FLOW_ACTION_TYPE_RSS:
1041 conf.rss = action->conf;
1042 *size = offsetof(struct rte_flow_action_rss, queue) +
1043 conf.rss->num * sizeof(*conf.rss->queue);
1050 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
1053 /** Generate a port_flow entry from attributes/pattern/actions. */
1054 static struct port_flow *
1055 port_flow_new(const struct rte_flow_attr *attr,
1056 const struct rte_flow_item *pattern,
1057 const struct rte_flow_action *actions)
1059 const struct rte_flow_item *item;
1060 const struct rte_flow_action *action;
1061 struct port_flow *pf = NULL;
1071 pf->pattern = (void *)&pf->data[off1];
1073 struct rte_flow_item *dst = NULL;
1075 if ((unsigned int)item->type >= RTE_DIM(flow_item) ||
1076 !flow_item[item->type].name)
1079 dst = memcpy(pf->data + off1, item, sizeof(*item));
1080 off1 += sizeof(*item);
1081 flow_item_spec_size(item, &tmp, &pad);
1084 dst->spec = memcpy(pf->data + off2,
1090 dst->last = memcpy(pf->data + off2,
1096 dst->mask = memcpy(pf->data + off2,
1100 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1101 } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
1102 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1105 pf->actions = (void *)&pf->data[off1];
1107 struct rte_flow_action *dst = NULL;
1109 if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
1110 !flow_action[action->type].name)
1113 dst = memcpy(pf->data + off1, action, sizeof(*action));
1114 off1 += sizeof(*action);
1115 flow_action_conf_size(action, &tmp, &pad);
1118 dst->conf = memcpy(pf->data + off2,
1122 off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
1123 } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
1126 off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
1127 tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double));
1128 pf = calloc(1, tmp + off1 + off2);
1132 *pf = (const struct port_flow){
1133 .size = tmp + off1 + off2,
1136 tmp -= offsetof(struct port_flow, data);
1146 /** Print a message out of a flow error. */
1148 port_flow_complain(struct rte_flow_error *error)
1150 static const char *const errstrlist[] = {
1151 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1152 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1153 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1154 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1155 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1156 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1157 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1158 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1159 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1160 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1161 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1162 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1166 int err = rte_errno;
1168 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1169 !errstrlist[error->type])
1170 errstr = "unknown type";
1172 errstr = errstrlist[error->type];
1173 printf("Caught error type %d (%s): %s%s\n",
1174 error->type, errstr,
1175 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1176 error->cause), buf) : "",
1177 error->message ? error->message : "(no stated reason)");
1181 /** Validate flow rule. */
1183 port_flow_validate(portid_t port_id,
1184 const struct rte_flow_attr *attr,
1185 const struct rte_flow_item *pattern,
1186 const struct rte_flow_action *actions)
1188 struct rte_flow_error error;
1190 /* Poisoning to make sure PMDs update it in case of error. */
1191 memset(&error, 0x11, sizeof(error));
1192 if (rte_flow_validate(port_id, attr, pattern, actions, &error))
1193 return port_flow_complain(&error);
1194 printf("Flow rule validated\n");
1198 /** Create flow rule. */
1200 port_flow_create(portid_t port_id,
1201 const struct rte_flow_attr *attr,
1202 const struct rte_flow_item *pattern,
1203 const struct rte_flow_action *actions)
1205 struct rte_flow *flow;
1206 struct rte_port *port;
1207 struct port_flow *pf;
1209 struct rte_flow_error error;
1211 /* Poisoning to make sure PMDs update it in case of error. */
1212 memset(&error, 0x22, sizeof(error));
1213 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
1215 return port_flow_complain(&error);
1216 port = &ports[port_id];
1217 if (port->flow_list) {
1218 if (port->flow_list->id == UINT32_MAX) {
1219 printf("Highest rule ID is already assigned, delete"
1221 rte_flow_destroy(port_id, flow, NULL);
1224 id = port->flow_list->id + 1;
1227 pf = port_flow_new(attr, pattern, actions);
1229 int err = rte_errno;
1231 printf("Cannot allocate flow: %s\n", rte_strerror(err));
1232 rte_flow_destroy(port_id, flow, NULL);
1235 pf->next = port->flow_list;
1238 port->flow_list = pf;
1239 printf("Flow rule #%u created\n", pf->id);
1243 /** Destroy a number of flow rules. */
1245 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
1247 struct rte_port *port;
1248 struct port_flow **tmp;
1252 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1253 port_id == (portid_t)RTE_PORT_ALL)
1255 port = &ports[port_id];
1256 tmp = &port->flow_list;
1260 for (i = 0; i != n; ++i) {
1261 struct rte_flow_error error;
1262 struct port_flow *pf = *tmp;
1264 if (rule[i] != pf->id)
1267 * Poisoning to make sure PMDs update it in case
1270 memset(&error, 0x33, sizeof(error));
1271 if (rte_flow_destroy(port_id, pf->flow, &error)) {
1272 ret = port_flow_complain(&error);
1275 printf("Flow rule #%u destroyed\n", pf->id);
1281 tmp = &(*tmp)->next;
1287 /** Remove all flow rules. */
1289 port_flow_flush(portid_t port_id)
1291 struct rte_flow_error error;
1292 struct rte_port *port;
1295 /* Poisoning to make sure PMDs update it in case of error. */
1296 memset(&error, 0x44, sizeof(error));
1297 if (rte_flow_flush(port_id, &error)) {
1298 ret = port_flow_complain(&error);
1299 if (port_id_is_invalid(port_id, DISABLED_WARN) ||
1300 port_id == (portid_t)RTE_PORT_ALL)
1303 port = &ports[port_id];
1304 while (port->flow_list) {
1305 struct port_flow *pf = port->flow_list->next;
1307 free(port->flow_list);
1308 port->flow_list = pf;
1313 /** Query a flow rule. */
1315 port_flow_query(portid_t port_id, uint32_t rule,
1316 enum rte_flow_action_type action)
1318 struct rte_flow_error error;
1319 struct rte_port *port;
1320 struct port_flow *pf;
1323 struct rte_flow_query_count count;
1326 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1327 port_id == (portid_t)RTE_PORT_ALL)
1329 port = &ports[port_id];
1330 for (pf = port->flow_list; pf; pf = pf->next)
1334 printf("Flow rule #%u not found\n", rule);
1337 if ((unsigned int)action >= RTE_DIM(flow_action) ||
1338 !flow_action[action].name)
1341 name = flow_action[action].name;
1343 case RTE_FLOW_ACTION_TYPE_COUNT:
1346 printf("Cannot query action type %d (%s)\n", action, name);
1349 /* Poisoning to make sure PMDs update it in case of error. */
1350 memset(&error, 0x55, sizeof(error));
1351 memset(&query, 0, sizeof(query));
1352 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
1353 return port_flow_complain(&error);
1355 case RTE_FLOW_ACTION_TYPE_COUNT:
1359 " hits: %" PRIu64 "\n"
1360 " bytes: %" PRIu64 "\n",
1362 query.count.hits_set,
1363 query.count.bytes_set,
1368 printf("Cannot display result for action type %d (%s)\n",
1375 /** List flow rules. */
1377 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
1379 struct rte_port *port;
1380 struct port_flow *pf;
1381 struct port_flow *list = NULL;
1384 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1385 port_id == (portid_t)RTE_PORT_ALL)
1387 port = &ports[port_id];
1388 if (!port->flow_list)
1390 /* Sort flows by group, priority and ID. */
1391 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
1392 struct port_flow **tmp;
1395 /* Filter out unwanted groups. */
1396 for (i = 0; i != n; ++i)
1397 if (pf->attr.group == group[i])
1404 (pf->attr.group > (*tmp)->attr.group ||
1405 (pf->attr.group == (*tmp)->attr.group &&
1406 pf->attr.priority > (*tmp)->attr.priority) ||
1407 (pf->attr.group == (*tmp)->attr.group &&
1408 pf->attr.priority == (*tmp)->attr.priority &&
1409 pf->id > (*tmp)->id)))
1414 printf("ID\tGroup\tPrio\tAttr\tRule\n");
1415 for (pf = list; pf != NULL; pf = pf->tmp) {
1416 const struct rte_flow_item *item = pf->pattern;
1417 const struct rte_flow_action *action = pf->actions;
1419 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t",
1423 pf->attr.ingress ? 'i' : '-',
1424 pf->attr.egress ? 'e' : '-');
1425 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1426 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
1427 printf("%s ", flow_item[item->type].name);
1431 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
1432 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
1433 printf(" %s", flow_action[action->type].name);
1441 * RX/TX ring descriptors display functions.
1444 rx_queue_id_is_invalid(queueid_t rxq_id)
1446 if (rxq_id < nb_rxq)
1448 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
1453 tx_queue_id_is_invalid(queueid_t txq_id)
1455 if (txq_id < nb_txq)
1457 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
1462 rx_desc_id_is_invalid(uint16_t rxdesc_id)
1464 if (rxdesc_id < nb_rxd)
1466 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
1472 tx_desc_id_is_invalid(uint16_t txdesc_id)
1474 if (txdesc_id < nb_txd)
1476 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
1481 static const struct rte_memzone *
1482 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
1484 char mz_name[RTE_MEMZONE_NAMESIZE];
1485 const struct rte_memzone *mz;
1487 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
1488 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
1489 mz = rte_memzone_lookup(mz_name);
1491 printf("%s ring memory zoneof (port %d, queue %d) not"
1492 "found (zone name = %s\n",
1493 ring_name, port_id, q_id, mz_name);
1497 union igb_ring_dword {
1500 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1510 struct igb_ring_desc_32_bytes {
1511 union igb_ring_dword lo_dword;
1512 union igb_ring_dword hi_dword;
1513 union igb_ring_dword resv1;
1514 union igb_ring_dword resv2;
1517 struct igb_ring_desc_16_bytes {
1518 union igb_ring_dword lo_dword;
1519 union igb_ring_dword hi_dword;
1523 ring_rxd_display_dword(union igb_ring_dword dword)
1525 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
1526 (unsigned)dword.words.hi);
1530 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
1531 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1534 __rte_unused uint8_t port_id,
1538 struct igb_ring_desc_16_bytes *ring =
1539 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1540 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
1541 struct rte_eth_dev_info dev_info;
1543 memset(&dev_info, 0, sizeof(dev_info));
1544 rte_eth_dev_info_get(port_id, &dev_info);
1545 if (strstr(dev_info.driver_name, "i40e") != NULL) {
1546 /* 32 bytes RX descriptor, i40e only */
1547 struct igb_ring_desc_32_bytes *ring =
1548 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
1549 ring[desc_id].lo_dword.dword =
1550 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1551 ring_rxd_display_dword(ring[desc_id].lo_dword);
1552 ring[desc_id].hi_dword.dword =
1553 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1554 ring_rxd_display_dword(ring[desc_id].hi_dword);
1555 ring[desc_id].resv1.dword =
1556 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
1557 ring_rxd_display_dword(ring[desc_id].resv1);
1558 ring[desc_id].resv2.dword =
1559 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
1560 ring_rxd_display_dword(ring[desc_id].resv2);
1565 /* 16 bytes RX descriptor */
1566 ring[desc_id].lo_dword.dword =
1567 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1568 ring_rxd_display_dword(ring[desc_id].lo_dword);
1569 ring[desc_id].hi_dword.dword =
1570 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1571 ring_rxd_display_dword(ring[desc_id].hi_dword);
1575 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
1577 struct igb_ring_desc_16_bytes *ring;
1578 struct igb_ring_desc_16_bytes txd;
1580 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
1581 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
1582 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
1583 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
1584 (unsigned)txd.lo_dword.words.lo,
1585 (unsigned)txd.lo_dword.words.hi,
1586 (unsigned)txd.hi_dword.words.lo,
1587 (unsigned)txd.hi_dword.words.hi);
1591 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
1593 const struct rte_memzone *rx_mz;
1595 if (port_id_is_invalid(port_id, ENABLED_WARN))
1597 if (rx_queue_id_is_invalid(rxq_id))
1599 if (rx_desc_id_is_invalid(rxd_id))
1601 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
1604 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
1608 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
1610 const struct rte_memzone *tx_mz;
1612 if (port_id_is_invalid(port_id, ENABLED_WARN))
1614 if (tx_queue_id_is_invalid(txq_id))
1616 if (tx_desc_id_is_invalid(txd_id))
1618 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
1621 ring_tx_descriptor_display(tx_mz, txd_id);
1625 fwd_lcores_config_display(void)
1629 printf("List of forwarding lcores:");
1630 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
1631 printf(" %2u", fwd_lcores_cpuids[lc_id]);
1635 rxtx_config_display(void)
1637 printf(" %s packet forwarding%s - CRC stripping %s - "
1638 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
1639 retry_enabled == 0 ? "" : " with retry",
1640 rx_mode.hw_strip_crc ? "enabled" : "disabled",
1643 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
1644 printf(" packet len=%u - nb packet segments=%d\n",
1645 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
1647 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
1648 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
1650 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
1651 nb_fwd_lcores, nb_fwd_ports);
1652 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
1653 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
1654 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1655 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
1656 rx_conf->rx_thresh.wthresh);
1657 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
1658 nb_txq, nb_txd, tx_conf->tx_free_thresh);
1659 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
1660 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
1661 tx_conf->tx_thresh.wthresh);
1662 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
1663 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
1667 port_rss_reta_info(portid_t port_id,
1668 struct rte_eth_rss_reta_entry64 *reta_conf,
1669 uint16_t nb_entries)
1671 uint16_t i, idx, shift;
1674 if (port_id_is_invalid(port_id, ENABLED_WARN))
1677 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
1679 printf("Failed to get RSS RETA info, return code = %d\n", ret);
1683 for (i = 0; i < nb_entries; i++) {
1684 idx = i / RTE_RETA_GROUP_SIZE;
1685 shift = i % RTE_RETA_GROUP_SIZE;
1686 if (!(reta_conf[idx].mask & (1ULL << shift)))
1688 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
1689 i, reta_conf[idx].reta[shift]);
1694 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
1698 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
1700 struct rte_eth_rss_conf rss_conf;
1701 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
1705 struct rte_eth_dev_info dev_info;
1706 uint8_t hash_key_size;
1708 if (port_id_is_invalid(port_id, ENABLED_WARN))
1711 memset(&dev_info, 0, sizeof(dev_info));
1712 rte_eth_dev_info_get(port_id, &dev_info);
1713 if (dev_info.hash_key_size > 0 &&
1714 dev_info.hash_key_size <= sizeof(rss_key))
1715 hash_key_size = dev_info.hash_key_size;
1717 printf("dev_info did not provide a valid hash key size\n");
1721 rss_conf.rss_hf = 0;
1722 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1723 if (!strcmp(rss_info, rss_type_table[i].str))
1724 rss_conf.rss_hf = rss_type_table[i].rss_type;
1727 /* Get RSS hash key if asked to display it */
1728 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
1729 rss_conf.rss_key_len = hash_key_size;
1730 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1734 printf("port index %d invalid\n", port_id);
1737 printf("operation not supported by device\n");
1740 printf("operation failed - diag=%d\n", diag);
1745 rss_hf = rss_conf.rss_hf;
1747 printf("RSS disabled\n");
1750 printf("RSS functions:\n ");
1751 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1752 if (rss_hf & rss_type_table[i].rss_type)
1753 printf("%s ", rss_type_table[i].str);
1758 printf("RSS key:\n");
1759 for (i = 0; i < hash_key_size; i++)
1760 printf("%02X", rss_key[i]);
1765 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1768 struct rte_eth_rss_conf rss_conf;
1772 rss_conf.rss_key = NULL;
1773 rss_conf.rss_key_len = hash_key_len;
1774 rss_conf.rss_hf = 0;
1775 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1776 if (!strcmp(rss_type_table[i].str, rss_type))
1777 rss_conf.rss_hf = rss_type_table[i].rss_type;
1779 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1781 rss_conf.rss_key = hash_key;
1782 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1789 printf("port index %d invalid\n", port_id);
1792 printf("operation not supported by device\n");
1795 printf("operation failed - diag=%d\n", diag);
1801 * Setup forwarding configuration for each logical core.
1804 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1806 streamid_t nb_fs_per_lcore;
1814 nb_fs = cfg->nb_fwd_streams;
1815 nb_fc = cfg->nb_fwd_lcores;
1816 if (nb_fs <= nb_fc) {
1817 nb_fs_per_lcore = 1;
1820 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1821 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1824 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1826 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1827 fwd_lcores[lc_id]->stream_idx = sm_id;
1828 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1829 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1833 * Assign extra remaining streams, if any.
1835 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1836 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1837 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1838 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1839 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1844 simple_fwd_config_setup(void)
1850 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1851 port_topology == PORT_TOPOLOGY_LOOP) {
1853 } else if (nb_fwd_ports % 2) {
1854 printf("\nWarning! Cannot handle an odd number of ports "
1855 "with the current port topology. Configuration "
1856 "must be changed to have an even number of ports, "
1857 "or relaunch application with "
1858 "--port-topology=chained\n\n");
1861 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1862 cur_fwd_config.nb_fwd_streams =
1863 (streamid_t) cur_fwd_config.nb_fwd_ports;
1865 /* reinitialize forwarding streams */
1869 * In the simple forwarding test, the number of forwarding cores
1870 * must be lower or equal to the number of forwarding ports.
1872 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1873 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1874 cur_fwd_config.nb_fwd_lcores =
1875 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1876 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1878 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1879 if (port_topology != PORT_TOPOLOGY_LOOP)
1880 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1883 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1884 fwd_streams[i]->rx_queue = 0;
1885 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1886 fwd_streams[i]->tx_queue = 0;
1887 fwd_streams[i]->peer_addr = j;
1888 fwd_streams[i]->retry_enabled = retry_enabled;
1890 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1891 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1892 fwd_streams[j]->rx_queue = 0;
1893 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1894 fwd_streams[j]->tx_queue = 0;
1895 fwd_streams[j]->peer_addr = i;
1896 fwd_streams[j]->retry_enabled = retry_enabled;
1902 * For the RSS forwarding test all streams distributed over lcores. Each stream
1903 * being composed of a RX queue to poll on a RX port for input messages,
1904 * associated with a TX queue of a TX port where to send forwarded packets.
1905 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1906 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1908 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1912 rss_fwd_config_setup(void)
1923 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1924 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1925 cur_fwd_config.nb_fwd_streams =
1926 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1928 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1929 cur_fwd_config.nb_fwd_lcores =
1930 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1932 /* reinitialize forwarding streams */
1935 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1937 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1938 struct fwd_stream *fs;
1940 fs = fwd_streams[sm_id];
1942 if ((rxp & 0x1) == 0)
1943 txp = (portid_t) (rxp + 1);
1945 txp = (portid_t) (rxp - 1);
1947 * if we are in loopback, simply send stuff out through the
1950 if (port_topology == PORT_TOPOLOGY_LOOP)
1953 fs->rx_port = fwd_ports_ids[rxp];
1955 fs->tx_port = fwd_ports_ids[txp];
1957 fs->peer_addr = fs->tx_port;
1958 fs->retry_enabled = retry_enabled;
1959 rxq = (queueid_t) (rxq + 1);
1964 * Restart from RX queue 0 on next RX port
1967 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1969 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1971 rxp = (portid_t) (rxp + 1);
1976 * For the DCB forwarding test, each core is assigned on each traffic class.
1978 * Each core is assigned a multi-stream, each stream being composed of
1979 * a RX queue to poll on a RX port for input messages, associated with
1980 * a TX queue of a TX port where to send forwarded packets. All RX and
1981 * TX queues are mapping to the same traffic class.
1982 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1986 dcb_fwd_config_setup(void)
1988 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1989 portid_t txp, rxp = 0;
1990 queueid_t txq, rxq = 0;
1992 uint16_t nb_rx_queue, nb_tx_queue;
1993 uint16_t i, j, k, sm_id = 0;
1996 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1997 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1998 cur_fwd_config.nb_fwd_streams =
1999 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2001 /* reinitialize forwarding streams */
2005 /* get the dcb info on the first RX and TX ports */
2006 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2007 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2009 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2010 fwd_lcores[lc_id]->stream_nb = 0;
2011 fwd_lcores[lc_id]->stream_idx = sm_id;
2012 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
2013 /* if the nb_queue is zero, means this tc is
2014 * not enabled on the POOL
2016 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
2018 k = fwd_lcores[lc_id]->stream_nb +
2019 fwd_lcores[lc_id]->stream_idx;
2020 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
2021 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
2022 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2023 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
2024 for (j = 0; j < nb_rx_queue; j++) {
2025 struct fwd_stream *fs;
2027 fs = fwd_streams[k + j];
2028 fs->rx_port = fwd_ports_ids[rxp];
2029 fs->rx_queue = rxq + j;
2030 fs->tx_port = fwd_ports_ids[txp];
2031 fs->tx_queue = txq + j % nb_tx_queue;
2032 fs->peer_addr = fs->tx_port;
2033 fs->retry_enabled = retry_enabled;
2035 fwd_lcores[lc_id]->stream_nb +=
2036 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
2038 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
2041 if (tc < rxp_dcb_info.nb_tcs)
2043 /* Restart from TC 0 on next RX port */
2045 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
2047 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
2050 if (rxp >= nb_fwd_ports)
2052 /* get the dcb information on next RX and TX ports */
2053 if ((rxp & 0x1) == 0)
2054 txp = (portid_t) (rxp + 1);
2056 txp = (portid_t) (rxp - 1);
2057 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
2058 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
2063 icmp_echo_config_setup(void)
2070 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
2071 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
2072 (nb_txq * nb_fwd_ports);
2074 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
2075 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
2076 cur_fwd_config.nb_fwd_streams =
2077 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
2078 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
2079 cur_fwd_config.nb_fwd_lcores =
2080 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
2081 if (verbose_level > 0) {
2082 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
2084 cur_fwd_config.nb_fwd_lcores,
2085 cur_fwd_config.nb_fwd_ports,
2086 cur_fwd_config.nb_fwd_streams);
2089 /* reinitialize forwarding streams */
2091 setup_fwd_config_of_each_lcore(&cur_fwd_config);
2093 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
2094 if (verbose_level > 0)
2095 printf(" core=%d: \n", lc_id);
2096 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2097 struct fwd_stream *fs;
2098 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2099 fs->rx_port = fwd_ports_ids[rxp];
2101 fs->tx_port = fs->rx_port;
2103 fs->peer_addr = fs->tx_port;
2104 fs->retry_enabled = retry_enabled;
2105 if (verbose_level > 0)
2106 printf(" stream=%d port=%d rxq=%d txq=%d\n",
2107 sm_id, fs->rx_port, fs->rx_queue,
2109 rxq = (queueid_t) (rxq + 1);
2110 if (rxq == nb_rxq) {
2112 rxp = (portid_t) (rxp + 1);
2119 fwd_config_setup(void)
2121 cur_fwd_config.fwd_eng = cur_fwd_eng;
2122 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
2123 icmp_echo_config_setup();
2126 if ((nb_rxq > 1) && (nb_txq > 1)){
2128 dcb_fwd_config_setup();
2130 rss_fwd_config_setup();
2133 simple_fwd_config_setup();
2137 pkt_fwd_config_display(struct fwd_config *cfg)
2139 struct fwd_stream *fs;
2143 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
2144 "NUMA support %s, MP over anonymous pages %s\n",
2145 cfg->fwd_eng->fwd_mode_name,
2146 retry_enabled == 0 ? "" : " with retry",
2147 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
2148 numa_support == 1 ? "enabled" : "disabled",
2149 mp_anon != 0 ? "enabled" : "disabled");
2152 printf("TX retry num: %u, delay between TX retries: %uus\n",
2153 burst_tx_retry_num, burst_tx_delay_time);
2154 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
2155 printf("Logical Core %u (socket %u) forwards packets on "
2157 fwd_lcores_cpuids[lc_id],
2158 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
2159 fwd_lcores[lc_id]->stream_nb);
2160 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
2161 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
2162 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
2163 "P=%d/Q=%d (socket %u) ",
2164 fs->rx_port, fs->rx_queue,
2165 ports[fs->rx_port].socket_id,
2166 fs->tx_port, fs->tx_queue,
2167 ports[fs->tx_port].socket_id);
2168 print_ethaddr("peer=",
2169 &peer_eth_addrs[fs->peer_addr]);
2177 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
2180 unsigned int lcore_cpuid;
2185 for (i = 0; i < nb_lc; i++) {
2186 lcore_cpuid = lcorelist[i];
2187 if (! rte_lcore_is_enabled(lcore_cpuid)) {
2188 printf("lcore %u not enabled\n", lcore_cpuid);
2191 if (lcore_cpuid == rte_get_master_lcore()) {
2192 printf("lcore %u cannot be masked on for running "
2193 "packet forwarding, which is the master lcore "
2194 "and reserved for command line parsing only\n",
2199 fwd_lcores_cpuids[i] = lcore_cpuid;
2201 if (record_now == 0) {
2205 nb_cfg_lcores = (lcoreid_t) nb_lc;
2206 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
2207 printf("previous number of forwarding cores %u - changed to "
2208 "number of configured cores %u\n",
2209 (unsigned int) nb_fwd_lcores, nb_lc);
2210 nb_fwd_lcores = (lcoreid_t) nb_lc;
2217 set_fwd_lcores_mask(uint64_t lcoremask)
2219 unsigned int lcorelist[64];
2223 if (lcoremask == 0) {
2224 printf("Invalid NULL mask of cores\n");
2228 for (i = 0; i < 64; i++) {
2229 if (! ((uint64_t)(1ULL << i) & lcoremask))
2231 lcorelist[nb_lc++] = i;
2233 return set_fwd_lcores_list(lcorelist, nb_lc);
2237 set_fwd_lcores_number(uint16_t nb_lc)
2239 if (nb_lc > nb_cfg_lcores) {
2240 printf("nb fwd cores %u > %u (max. number of configured "
2241 "lcores) - ignored\n",
2242 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
2245 nb_fwd_lcores = (lcoreid_t) nb_lc;
2246 printf("Number of forwarding cores set to %u\n",
2247 (unsigned int) nb_fwd_lcores);
2251 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
2259 for (i = 0; i < nb_pt; i++) {
2260 port_id = (portid_t) portlist[i];
2261 if (port_id_is_invalid(port_id, ENABLED_WARN))
2264 fwd_ports_ids[i] = port_id;
2266 if (record_now == 0) {
2270 nb_cfg_ports = (portid_t) nb_pt;
2271 if (nb_fwd_ports != (portid_t) nb_pt) {
2272 printf("previous number of forwarding ports %u - changed to "
2273 "number of configured ports %u\n",
2274 (unsigned int) nb_fwd_ports, nb_pt);
2275 nb_fwd_ports = (portid_t) nb_pt;
2280 set_fwd_ports_mask(uint64_t portmask)
2282 unsigned int portlist[64];
2286 if (portmask == 0) {
2287 printf("Invalid NULL mask of ports\n");
2291 RTE_ETH_FOREACH_DEV(i) {
2292 if (! ((uint64_t)(1ULL << i) & portmask))
2294 portlist[nb_pt++] = i;
2296 set_fwd_ports_list(portlist, nb_pt);
2300 set_fwd_ports_number(uint16_t nb_pt)
2302 if (nb_pt > nb_cfg_ports) {
2303 printf("nb fwd ports %u > %u (number of configured "
2304 "ports) - ignored\n",
2305 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
2308 nb_fwd_ports = (portid_t) nb_pt;
2309 printf("Number of forwarding ports set to %u\n",
2310 (unsigned int) nb_fwd_ports);
2314 port_is_forwarding(portid_t port_id)
2318 if (port_id_is_invalid(port_id, ENABLED_WARN))
2321 for (i = 0; i < nb_fwd_ports; i++) {
2322 if (fwd_ports_ids[i] == port_id)
2330 set_nb_pkt_per_burst(uint16_t nb)
2332 if (nb > MAX_PKT_BURST) {
2333 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
2335 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
2338 nb_pkt_per_burst = nb;
2339 printf("Number of packets per burst set to %u\n",
2340 (unsigned int) nb_pkt_per_burst);
2344 tx_split_get_name(enum tx_pkt_split split)
2348 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2349 if (tx_split_name[i].split == split)
2350 return tx_split_name[i].name;
2356 set_tx_pkt_split(const char *name)
2360 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
2361 if (strcmp(tx_split_name[i].name, name) == 0) {
2362 tx_pkt_split = tx_split_name[i].split;
2366 printf("unknown value: \"%s\"\n", name);
2370 show_tx_pkt_segments(void)
2376 split = tx_split_get_name(tx_pkt_split);
2378 printf("Number of segments: %u\n", n);
2379 printf("Segment sizes: ");
2380 for (i = 0; i != n - 1; i++)
2381 printf("%hu,", tx_pkt_seg_lengths[i]);
2382 printf("%hu\n", tx_pkt_seg_lengths[i]);
2383 printf("Split packet: %s\n", split);
2387 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
2389 uint16_t tx_pkt_len;
2392 if (nb_segs >= (unsigned) nb_txd) {
2393 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
2394 nb_segs, (unsigned int) nb_txd);
2399 * Check that each segment length is greater or equal than
2400 * the mbuf data sise.
2401 * Check also that the total packet length is greater or equal than the
2402 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
2405 for (i = 0; i < nb_segs; i++) {
2406 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
2407 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
2408 i, seg_lengths[i], (unsigned) mbuf_data_size);
2411 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
2413 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
2414 printf("total packet length=%u < %d - give up\n",
2415 (unsigned) tx_pkt_len,
2416 (int)(sizeof(struct ether_hdr) + 20 + 8));
2420 for (i = 0; i < nb_segs; i++)
2421 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
2423 tx_pkt_length = tx_pkt_len;
2424 tx_pkt_nb_segs = (uint8_t) nb_segs;
2428 list_pkt_forwarding_modes(void)
2430 static char fwd_modes[128] = "";
2431 const char *separator = "|";
2432 struct fwd_engine *fwd_eng;
2435 if (strlen (fwd_modes) == 0) {
2436 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2437 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2438 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2439 strncat(fwd_modes, separator,
2440 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
2442 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2449 list_pkt_forwarding_retry_modes(void)
2451 static char fwd_modes[128] = "";
2452 const char *separator = "|";
2453 struct fwd_engine *fwd_eng;
2456 if (strlen(fwd_modes) == 0) {
2457 while ((fwd_eng = fwd_engines[i++]) != NULL) {
2458 if (fwd_eng == &rx_only_engine)
2460 strncat(fwd_modes, fwd_eng->fwd_mode_name,
2462 strlen(fwd_modes) - 1);
2463 strncat(fwd_modes, separator,
2465 strlen(fwd_modes) - 1);
2467 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
2474 set_pkt_forwarding_mode(const char *fwd_mode_name)
2476 struct fwd_engine *fwd_eng;
2480 while ((fwd_eng = fwd_engines[i]) != NULL) {
2481 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
2482 printf("Set %s packet forwarding mode%s\n",
2484 retry_enabled == 0 ? "" : " with retry");
2485 cur_fwd_eng = fwd_eng;
2490 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
2494 set_verbose_level(uint16_t vb_level)
2496 printf("Change verbose level from %u to %u\n",
2497 (unsigned int) verbose_level, (unsigned int) vb_level);
2498 verbose_level = vb_level;
2502 vlan_extend_set(portid_t port_id, int on)
2507 if (port_id_is_invalid(port_id, ENABLED_WARN))
2510 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2513 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
2515 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
2517 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2519 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
2520 "diag=%d\n", port_id, on, diag);
2524 rx_vlan_strip_set(portid_t port_id, int on)
2529 if (port_id_is_invalid(port_id, ENABLED_WARN))
2532 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2535 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
2537 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
2539 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2541 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
2542 "diag=%d\n", port_id, on, diag);
2546 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
2550 if (port_id_is_invalid(port_id, ENABLED_WARN))
2553 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
2555 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
2556 "diag=%d\n", port_id, queue_id, on, diag);
2560 rx_vlan_filter_set(portid_t port_id, int on)
2565 if (port_id_is_invalid(port_id, ENABLED_WARN))
2568 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2571 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
2573 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
2575 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
2577 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
2578 "diag=%d\n", port_id, on, diag);
2582 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
2586 if (port_id_is_invalid(port_id, ENABLED_WARN))
2588 if (vlan_id_is_invalid(vlan_id))
2590 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
2593 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
2595 port_id, vlan_id, on, diag);
2600 rx_vlan_all_filter_set(portid_t port_id, int on)
2604 if (port_id_is_invalid(port_id, ENABLED_WARN))
2606 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
2607 if (rx_vft_set(port_id, vlan_id, on))
2613 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
2617 if (port_id_is_invalid(port_id, ENABLED_WARN))
2620 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
2624 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
2626 port_id, vlan_type, tp_id, diag);
2630 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
2633 if (port_id_is_invalid(port_id, ENABLED_WARN))
2635 if (vlan_id_is_invalid(vlan_id))
2638 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2639 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2640 printf("Error, as QinQ has been enabled.\n");
2644 tx_vlan_reset(port_id);
2645 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
2646 ports[port_id].tx_vlan_id = vlan_id;
2650 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
2653 if (port_id_is_invalid(port_id, ENABLED_WARN))
2655 if (vlan_id_is_invalid(vlan_id))
2657 if (vlan_id_is_invalid(vlan_id_outer))
2660 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
2661 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2662 printf("Error, as QinQ hasn't been enabled.\n");
2666 tx_vlan_reset(port_id);
2667 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
2668 ports[port_id].tx_vlan_id = vlan_id;
2669 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
2673 tx_vlan_reset(portid_t port_id)
2675 if (port_id_is_invalid(port_id, ENABLED_WARN))
2677 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
2678 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
2679 ports[port_id].tx_vlan_id = 0;
2680 ports[port_id].tx_vlan_id_outer = 0;
2684 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
2686 if (port_id_is_invalid(port_id, ENABLED_WARN))
2689 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
2693 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
2696 uint8_t existing_mapping_found = 0;
2698 if (port_id_is_invalid(port_id, ENABLED_WARN))
2701 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
2704 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2705 printf("map_value not in required range 0..%d\n",
2706 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
2710 if (!is_rx) { /*then tx*/
2711 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2712 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2713 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
2714 tx_queue_stats_mappings[i].stats_counter_id = map_value;
2715 existing_mapping_found = 1;
2719 if (!existing_mapping_found) { /* A new additional mapping... */
2720 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
2721 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
2722 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2723 nb_tx_queue_stats_mappings++;
2727 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2728 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2729 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2730 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2731 existing_mapping_found = 1;
2735 if (!existing_mapping_found) { /* A new additional mapping... */
2736 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2737 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2738 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2739 nb_rx_queue_stats_mappings++;
2745 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2747 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
2749 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2750 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
2751 " tunnel_id: 0x%08x",
2752 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2753 rte_be_to_cpu_32(mask->tunnel_id_mask));
2754 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2755 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
2756 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
2757 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
2759 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
2760 rte_be_to_cpu_16(mask->src_port_mask),
2761 rte_be_to_cpu_16(mask->dst_port_mask));
2763 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2764 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
2765 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
2766 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
2767 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
2769 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2770 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
2771 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
2772 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
2773 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
2780 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2782 struct rte_eth_flex_payload_cfg *cfg;
2785 for (i = 0; i < flex_conf->nb_payloads; i++) {
2786 cfg = &flex_conf->flex_set[i];
2787 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2789 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2790 printf("\n L2_PAYLOAD: ");
2791 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2792 printf("\n L3_PAYLOAD: ");
2793 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2794 printf("\n L4_PAYLOAD: ");
2796 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2797 for (j = 0; j < num; j++)
2798 printf(" %-5u", cfg->src_offset[j]);
2804 flowtype_to_str(uint16_t flow_type)
2806 struct flow_type_info {
2812 static struct flow_type_info flowtype_str_table[] = {
2813 {"raw", RTE_ETH_FLOW_RAW},
2814 {"ipv4", RTE_ETH_FLOW_IPV4},
2815 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2816 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2817 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2818 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2819 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2820 {"ipv6", RTE_ETH_FLOW_IPV6},
2821 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2822 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2823 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2824 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2825 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2826 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2827 {"port", RTE_ETH_FLOW_PORT},
2828 {"vxlan", RTE_ETH_FLOW_VXLAN},
2829 {"geneve", RTE_ETH_FLOW_GENEVE},
2830 {"nvgre", RTE_ETH_FLOW_NVGRE},
2833 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2834 if (flowtype_str_table[i].ftype == flow_type)
2835 return flowtype_str_table[i].str;
2842 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2844 struct rte_eth_fdir_flex_mask *mask;
2848 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2849 mask = &flex_conf->flex_mask[i];
2850 p = flowtype_to_str(mask->flow_type);
2851 printf("\n %s:\t", p ? p : "unknown");
2852 for (j = 0; j < num; j++)
2853 printf(" %02x", mask->mask[j]);
2859 print_fdir_flow_type(uint32_t flow_types_mask)
2864 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2865 if (!(flow_types_mask & (1 << i)))
2867 p = flowtype_to_str(i);
2877 fdir_get_infos(portid_t port_id)
2879 struct rte_eth_fdir_stats fdir_stat;
2880 struct rte_eth_fdir_info fdir_info;
2883 static const char *fdir_stats_border = "########################";
2885 if (port_id_is_invalid(port_id, ENABLED_WARN))
2887 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
2889 printf("\n FDIR is not supported on port %-2d\n",
2894 memset(&fdir_info, 0, sizeof(fdir_info));
2895 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2896 RTE_ETH_FILTER_INFO, &fdir_info);
2897 memset(&fdir_stat, 0, sizeof(fdir_stat));
2898 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2899 RTE_ETH_FILTER_STATS, &fdir_stat);
2900 printf("\n %s FDIR infos for port %-2d %s\n",
2901 fdir_stats_border, port_id, fdir_stats_border);
2903 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
2904 printf(" PERFECT\n");
2905 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2906 printf(" PERFECT-MAC-VLAN\n");
2907 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2908 printf(" PERFECT-TUNNEL\n");
2909 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
2910 printf(" SIGNATURE\n");
2912 printf(" DISABLE\n");
2913 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
2914 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
2915 printf(" SUPPORTED FLOW TYPE: ");
2916 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
2918 printf(" FLEX PAYLOAD INFO:\n");
2919 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
2920 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
2921 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
2922 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
2923 fdir_info.flex_payload_unit,
2924 fdir_info.max_flex_payload_segment_num,
2925 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
2927 print_fdir_mask(&fdir_info.mask);
2928 if (fdir_info.flex_conf.nb_payloads > 0) {
2929 printf(" FLEX PAYLOAD SRC OFFSET:");
2930 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2932 if (fdir_info.flex_conf.nb_flexmasks > 0) {
2933 printf(" FLEX MASK CFG:");
2934 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2936 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2937 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2938 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2939 fdir_info.guarant_spc, fdir_info.best_spc);
2940 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2941 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2942 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2943 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2944 fdir_stat.collision, fdir_stat.free,
2945 fdir_stat.maxhash, fdir_stat.maxlen,
2946 fdir_stat.add, fdir_stat.remove,
2947 fdir_stat.f_add, fdir_stat.f_remove);
2948 printf(" %s############################%s\n",
2949 fdir_stats_border, fdir_stats_border);
2953 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2955 struct rte_port *port;
2956 struct rte_eth_fdir_flex_conf *flex_conf;
2959 port = &ports[port_id];
2960 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2961 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2962 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2967 if (i >= RTE_ETH_FLOW_MAX) {
2968 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2969 idx = flex_conf->nb_flexmasks;
2970 flex_conf->nb_flexmasks++;
2972 printf("The flex mask table is full. Can not set flex"
2973 " mask for flow_type(%u).", cfg->flow_type);
2977 (void)rte_memcpy(&flex_conf->flex_mask[idx],
2979 sizeof(struct rte_eth_fdir_flex_mask));
2983 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2985 struct rte_port *port;
2986 struct rte_eth_fdir_flex_conf *flex_conf;
2989 port = &ports[port_id];
2990 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2991 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2992 if (cfg->type == flex_conf->flex_set[i].type) {
2997 if (i >= RTE_ETH_PAYLOAD_MAX) {
2998 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2999 idx = flex_conf->nb_payloads;
3000 flex_conf->nb_payloads++;
3002 printf("The flex payload table is full. Can not set"
3003 " flex payload for type(%u).", cfg->type);
3007 (void)rte_memcpy(&flex_conf->flex_set[idx],
3009 sizeof(struct rte_eth_flex_payload_cfg));
3013 #ifdef RTE_LIBRTE_IXGBE_PMD
3015 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
3020 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
3022 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
3027 printf("rte_pmd_ixgbe_set_vf_rx for port_id=%d failed "
3028 "diag=%d\n", port_id, diag);
3030 printf("rte_pmd_ixgbe_set_vf_tx for port_id=%d failed "
3031 "diag=%d\n", port_id, diag);
3037 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
3040 struct rte_eth_link link;
3042 if (port_id_is_invalid(port_id, ENABLED_WARN))
3044 rte_eth_link_get_nowait(port_id, &link);
3045 if (rate > link.link_speed) {
3046 printf("Invalid rate value:%u bigger than link speed: %u\n",
3047 rate, link.link_speed);
3050 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
3053 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
3058 #ifdef RTE_LIBRTE_IXGBE_PMD
3060 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
3064 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate, q_msk);
3067 printf("rte_pmd_ixgbe_set_vf_rate_limit for port_id=%d failed diag=%d\n",
3074 * Functions to manage the set of filtered Multicast MAC addresses.
3076 * A pool of filtered multicast MAC addresses is associated with each port.
3077 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
3078 * The address of the pool and the number of valid multicast MAC addresses
3079 * recorded in the pool are stored in the fields "mc_addr_pool" and
3080 * "mc_addr_nb" of the "rte_port" data structure.
3082 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
3083 * to be supplied a contiguous array of multicast MAC addresses.
3084 * To comply with this constraint, the set of multicast addresses recorded
3085 * into the pool are systematically compacted at the beginning of the pool.
3086 * Hence, when a multicast address is removed from the pool, all following
3087 * addresses, if any, are copied back to keep the set contiguous.
3089 #define MCAST_POOL_INC 32
3092 mcast_addr_pool_extend(struct rte_port *port)
3094 struct ether_addr *mc_pool;
3095 size_t mc_pool_size;
3098 * If a free entry is available at the end of the pool, just
3099 * increment the number of recorded multicast addresses.
3101 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
3107 * [re]allocate a pool with MCAST_POOL_INC more entries.
3108 * The previous test guarantees that port->mc_addr_nb is a multiple
3109 * of MCAST_POOL_INC.
3111 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
3113 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
3115 if (mc_pool == NULL) {
3116 printf("allocation of pool of %u multicast addresses failed\n",
3117 port->mc_addr_nb + MCAST_POOL_INC);
3121 port->mc_addr_pool = mc_pool;
3128 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
3131 if (addr_idx == port->mc_addr_nb) {
3132 /* No need to recompact the set of multicast addressses. */
3133 if (port->mc_addr_nb == 0) {
3134 /* free the pool of multicast addresses. */
3135 free(port->mc_addr_pool);
3136 port->mc_addr_pool = NULL;
3140 memmove(&port->mc_addr_pool[addr_idx],
3141 &port->mc_addr_pool[addr_idx + 1],
3142 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
3146 eth_port_multicast_addr_list_set(uint8_t port_id)
3148 struct rte_port *port;
3151 port = &ports[port_id];
3152 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
3156 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
3157 port->mc_addr_nb, port_id, -diag);
3161 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
3163 struct rte_port *port;
3166 if (port_id_is_invalid(port_id, ENABLED_WARN))
3169 port = &ports[port_id];
3172 * Check that the added multicast MAC address is not already recorded
3173 * in the pool of multicast addresses.
3175 for (i = 0; i < port->mc_addr_nb; i++) {
3176 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
3177 printf("multicast address already filtered by port\n");
3182 if (mcast_addr_pool_extend(port) != 0)
3184 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
3185 eth_port_multicast_addr_list_set(port_id);
3189 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
3191 struct rte_port *port;
3194 if (port_id_is_invalid(port_id, ENABLED_WARN))
3197 port = &ports[port_id];
3200 * Search the pool of multicast MAC addresses for the removed address.
3202 for (i = 0; i < port->mc_addr_nb; i++) {
3203 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
3206 if (i == port->mc_addr_nb) {
3207 printf("multicast address not filtered by port %d\n", port_id);
3211 mcast_addr_pool_remove(port, i);
3212 eth_port_multicast_addr_list_set(port_id);
3216 port_dcb_info_display(uint8_t port_id)
3218 struct rte_eth_dcb_info dcb_info;
3221 static const char *border = "================";
3223 if (port_id_is_invalid(port_id, ENABLED_WARN))
3226 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3228 printf("\n Failed to get dcb infos on port %-2d\n",
3232 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
3233 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
3235 for (i = 0; i < dcb_info.nb_tcs; i++)
3237 printf("\n Priority : ");
3238 for (i = 0; i < dcb_info.nb_tcs; i++)
3239 printf("\t%4d", dcb_info.prio_tc[i]);
3240 printf("\n BW percent :");
3241 for (i = 0; i < dcb_info.nb_tcs; i++)
3242 printf("\t%4d%%", dcb_info.tc_bws[i]);
3243 printf("\n RXQ base : ");
3244 for (i = 0; i < dcb_info.nb_tcs; i++)
3245 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
3246 printf("\n RXQ number :");
3247 for (i = 0; i < dcb_info.nb_tcs; i++)
3248 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
3249 printf("\n TXQ base : ");
3250 for (i = 0; i < dcb_info.nb_tcs; i++)
3251 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
3252 printf("\n TXQ number :");
3253 for (i = 0; i < dcb_info.nb_tcs; i++)
3254 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
3259 open_ddp_package_file(const char *file_path, uint32_t *size)
3261 FILE *fh = fopen(file_path, "rb");
3263 uint8_t *buf = NULL;
3270 printf("%s: Failed to open %s\n", __func__, file_path);
3274 ret = fseek(fh, 0, SEEK_END);
3277 printf("%s: File operations failed\n", __func__);
3281 pkg_size = ftell(fh);
3283 buf = (uint8_t *)malloc(pkg_size);
3286 printf("%s: Failed to malloc memory\n", __func__);
3290 ret = fseek(fh, 0, SEEK_SET);
3293 printf("%s: File seek operation failed\n", __func__);
3294 close_ddp_package_file(buf);
3298 ret = fread(buf, 1, pkg_size, fh);
3301 printf("%s: File read operation failed\n", __func__);
3302 close_ddp_package_file(buf);
3315 close_ddp_package_file(uint8_t *buf)