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>
88 #include <rte_mempool.h>
90 #include <rte_interrupts.h>
92 #include <rte_ether.h>
93 #include <rte_ethdev.h>
94 #include <rte_string_fns.h>
95 #include <rte_cycles.h>
99 static char *flowtype_to_str(uint16_t flow_type);
101 static const struct {
102 enum tx_pkt_split split;
104 } tx_split_name[] = {
106 .split = TX_PKT_SPLIT_OFF,
110 .split = TX_PKT_SPLIT_ON,
114 .split = TX_PKT_SPLIT_RND,
119 struct rss_type_info {
124 static const struct rss_type_info rss_type_table[] = {
125 { "ipv4", ETH_RSS_IPV4 },
126 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
127 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
128 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
129 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
130 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
131 { "ipv6", ETH_RSS_IPV6 },
132 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
133 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
134 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
135 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
136 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
137 { "l2-payload", ETH_RSS_L2_PAYLOAD },
138 { "ipv6-ex", ETH_RSS_IPV6_EX },
139 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
140 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
144 print_ethaddr(const char *name, struct ether_addr *eth_addr)
146 char buf[ETHER_ADDR_FMT_SIZE];
147 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
148 printf("%s%s", name, buf);
152 nic_stats_display(portid_t port_id)
154 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
155 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
156 static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
157 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles;
158 uint64_t mpps_rx, mpps_tx;
159 struct rte_eth_stats stats;
160 struct rte_port *port = &ports[port_id];
164 static const char *nic_stats_border = "########################";
166 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
167 printf("Valid port range is [0");
168 FOREACH_PORT(pid, ports)
173 rte_eth_stats_get(port_id, &stats);
174 printf("\n %s NIC statistics for port %-2d %s\n",
175 nic_stats_border, port_id, nic_stats_border);
177 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
178 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
180 stats.ipackets, stats.imissed, stats.ibytes);
181 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
182 printf(" RX-nombuf: %-10"PRIu64"\n",
184 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
186 stats.opackets, stats.oerrors, stats.obytes);
189 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
190 " RX-bytes: %10"PRIu64"\n",
191 stats.ipackets, stats.ierrors, stats.ibytes);
192 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
193 printf(" RX-nombuf: %10"PRIu64"\n",
195 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
196 " TX-bytes: %10"PRIu64"\n",
197 stats.opackets, stats.oerrors, stats.obytes);
200 if (port->rx_queue_stats_mapping_enabled) {
202 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
203 printf(" Stats reg %2d RX-packets: %10"PRIu64
204 " RX-errors: %10"PRIu64
205 " RX-bytes: %10"PRIu64"\n",
206 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
209 if (port->tx_queue_stats_mapping_enabled) {
211 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
212 printf(" Stats reg %2d TX-packets: %10"PRIu64
213 " TX-bytes: %10"PRIu64"\n",
214 i, stats.q_opackets[i], stats.q_obytes[i]);
218 diff_cycles = prev_cycles[port_id];
219 prev_cycles[port_id] = rte_rdtsc();
221 diff_cycles = prev_cycles[port_id] - diff_cycles;
223 diff_pkts_rx = stats.ipackets - prev_pkts_rx[port_id];
224 diff_pkts_tx = stats.opackets - prev_pkts_tx[port_id];
225 prev_pkts_rx[port_id] = stats.ipackets;
226 prev_pkts_tx[port_id] = stats.opackets;
227 mpps_rx = diff_cycles > 0 ?
228 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0;
229 mpps_tx = diff_cycles > 0 ?
230 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0;
231 printf("\n Throughput (since last show)\n");
232 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n",
235 printf(" %s############################%s\n",
236 nic_stats_border, nic_stats_border);
240 nic_stats_clear(portid_t port_id)
244 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
245 printf("Valid port range is [0");
246 FOREACH_PORT(pid, ports)
251 rte_eth_stats_reset(port_id);
252 printf("\n NIC statistics for port %d cleared\n", port_id);
256 nic_xstats_display(portid_t port_id)
258 struct rte_eth_xstats *xstats;
261 printf("###### NIC extended statistics for port %-2d\n", port_id);
263 len = rte_eth_xstats_get(port_id, NULL, 0);
265 printf("Cannot get xstats count\n");
268 xstats = malloc(sizeof(xstats[0]) * len);
269 if (xstats == NULL) {
270 printf("Cannot allocate memory for xstats\n");
273 ret = rte_eth_xstats_get(port_id, xstats, len);
274 if (ret < 0 || ret > len) {
275 printf("Cannot get xstats\n");
279 for (i = 0; i < len; i++)
280 printf("%s: %"PRIu64"\n", xstats[i].name, xstats[i].value);
285 nic_xstats_clear(portid_t port_id)
287 rte_eth_xstats_reset(port_id);
291 nic_stats_mapping_display(portid_t port_id)
293 struct rte_port *port = &ports[port_id];
297 static const char *nic_stats_mapping_border = "########################";
299 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
300 printf("Valid port range is [0");
301 FOREACH_PORT(pid, ports)
307 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
308 printf("Port id %d - either does not support queue statistic mapping or"
309 " no queue statistic mapping set\n", port_id);
313 printf("\n %s NIC statistics mapping for port %-2d %s\n",
314 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
316 if (port->rx_queue_stats_mapping_enabled) {
317 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
318 if (rx_queue_stats_mappings[i].port_id == port_id) {
319 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
320 rx_queue_stats_mappings[i].queue_id,
321 rx_queue_stats_mappings[i].stats_counter_id);
328 if (port->tx_queue_stats_mapping_enabled) {
329 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
330 if (tx_queue_stats_mappings[i].port_id == port_id) {
331 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
332 tx_queue_stats_mappings[i].queue_id,
333 tx_queue_stats_mappings[i].stats_counter_id);
338 printf(" %s####################################%s\n",
339 nic_stats_mapping_border, nic_stats_mapping_border);
343 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
345 struct rte_eth_rxq_info qinfo;
347 static const char *info_border = "*********************";
349 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
351 printf("Failed to retrieve information for port: %hhu, "
352 "RX queue: %hu\nerror desc: %s(%d)\n",
353 port_id, queue_id, strerror(-rc), rc);
357 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
358 info_border, port_id, queue_id, info_border);
360 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
361 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
362 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
363 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
364 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
365 printf("\nRX drop packets: %s",
366 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
367 printf("\nRX deferred start: %s",
368 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
369 printf("\nRX scattered packets: %s",
370 (qinfo.scattered_rx != 0) ? "on" : "off");
371 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
376 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
378 struct rte_eth_txq_info qinfo;
380 static const char *info_border = "*********************";
382 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
384 printf("Failed to retrieve information for port: %hhu, "
385 "TX queue: %hu\nerror desc: %s(%d)\n",
386 port_id, queue_id, strerror(-rc), rc);
390 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
391 info_border, port_id, queue_id, info_border);
393 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
394 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
395 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
396 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
397 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
398 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
399 printf("\nTX deferred start: %s",
400 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
401 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
406 port_infos_display(portid_t port_id)
408 struct rte_port *port;
409 struct ether_addr mac_addr;
410 struct rte_eth_link link;
411 struct rte_eth_dev_info dev_info;
413 struct rte_mempool * mp;
414 static const char *info_border = "*********************";
417 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
418 printf("Valid port range is [0");
419 FOREACH_PORT(pid, ports)
424 port = &ports[port_id];
425 rte_eth_link_get_nowait(port_id, &link);
426 printf("\n%s Infos for port %-2d %s\n",
427 info_border, port_id, info_border);
428 rte_eth_macaddr_get(port_id, &mac_addr);
429 print_ethaddr("MAC address: ", &mac_addr);
430 printf("\nConnect to socket: %u", port->socket_id);
432 if (port_numa[port_id] != NUMA_NO_CONFIG) {
433 mp = mbuf_pool_find(port_numa[port_id]);
435 printf("\nmemory allocation on the socket: %d",
438 printf("\nmemory allocation on the socket: %u",port->socket_id);
440 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
441 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
442 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
443 ("full-duplex") : ("half-duplex"));
444 printf("Promiscuous mode: %s\n",
445 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
446 printf("Allmulticast mode: %s\n",
447 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
448 printf("Maximum number of MAC addresses: %u\n",
449 (unsigned int)(port->dev_info.max_mac_addrs));
450 printf("Maximum number of MAC addresses of hash filtering: %u\n",
451 (unsigned int)(port->dev_info.max_hash_mac_addrs));
453 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
454 if (vlan_offload >= 0){
455 printf("VLAN offload: \n");
456 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
457 printf(" strip on \n");
459 printf(" strip off \n");
461 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
462 printf(" filter on \n");
464 printf(" filter off \n");
466 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
467 printf(" qinq(extend) on \n");
469 printf(" qinq(extend) off \n");
472 memset(&dev_info, 0, sizeof(dev_info));
473 rte_eth_dev_info_get(port_id, &dev_info);
474 if (dev_info.hash_key_size > 0)
475 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
476 if (dev_info.reta_size > 0)
477 printf("Redirection table size: %u\n", dev_info.reta_size);
478 if (!dev_info.flow_type_rss_offloads)
479 printf("No flow type is supported.\n");
484 printf("Supported flow types:\n");
485 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
487 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
489 p = flowtype_to_str(i);
490 printf(" %s\n", (p ? p : "unknown"));
494 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
495 printf("Max possible number of RXDs per queue: %hu\n",
496 dev_info.rx_desc_lim.nb_max);
497 printf("Min possible number of RXDs per queue: %hu\n",
498 dev_info.rx_desc_lim.nb_min);
499 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
501 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
502 printf("Max possible number of TXDs per queue: %hu\n",
503 dev_info.tx_desc_lim.nb_max);
504 printf("Min possible number of TXDs per queue: %hu\n",
505 dev_info.tx_desc_lim.nb_min);
506 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
510 port_id_is_invalid(portid_t port_id, enum print_warning warning)
512 if (port_id == (portid_t)RTE_PORT_ALL)
515 if (port_id < RTE_MAX_ETHPORTS && ports[port_id].enabled)
518 if (warning == ENABLED_WARN)
519 printf("Invalid port %d\n", port_id);
525 vlan_id_is_invalid(uint16_t vlan_id)
529 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
534 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
539 printf("Port register offset 0x%X not aligned on a 4-byte "
544 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
545 if (reg_off >= pci_len) {
546 printf("Port %d: register offset %u (0x%X) out of port PCI "
547 "resource (length=%"PRIu64")\n",
548 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
555 reg_bit_pos_is_invalid(uint8_t bit_pos)
559 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
563 #define display_port_and_reg_off(port_id, reg_off) \
564 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
567 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
569 display_port_and_reg_off(port_id, (unsigned)reg_off);
570 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
574 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
579 if (port_id_is_invalid(port_id, ENABLED_WARN))
581 if (port_reg_off_is_invalid(port_id, reg_off))
583 if (reg_bit_pos_is_invalid(bit_x))
585 reg_v = port_id_pci_reg_read(port_id, reg_off);
586 display_port_and_reg_off(port_id, (unsigned)reg_off);
587 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
591 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
592 uint8_t bit1_pos, uint8_t bit2_pos)
598 if (port_id_is_invalid(port_id, ENABLED_WARN))
600 if (port_reg_off_is_invalid(port_id, reg_off))
602 if (reg_bit_pos_is_invalid(bit1_pos))
604 if (reg_bit_pos_is_invalid(bit2_pos))
606 if (bit1_pos > bit2_pos)
607 l_bit = bit2_pos, h_bit = bit1_pos;
609 l_bit = bit1_pos, h_bit = bit2_pos;
611 reg_v = port_id_pci_reg_read(port_id, reg_off);
614 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
615 display_port_and_reg_off(port_id, (unsigned)reg_off);
616 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
617 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
621 port_reg_display(portid_t port_id, uint32_t reg_off)
625 if (port_id_is_invalid(port_id, ENABLED_WARN))
627 if (port_reg_off_is_invalid(port_id, reg_off))
629 reg_v = port_id_pci_reg_read(port_id, reg_off);
630 display_port_reg_value(port_id, reg_off, reg_v);
634 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
639 if (port_id_is_invalid(port_id, ENABLED_WARN))
641 if (port_reg_off_is_invalid(port_id, reg_off))
643 if (reg_bit_pos_is_invalid(bit_pos))
646 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
649 reg_v = port_id_pci_reg_read(port_id, reg_off);
651 reg_v &= ~(1 << bit_pos);
653 reg_v |= (1 << bit_pos);
654 port_id_pci_reg_write(port_id, reg_off, reg_v);
655 display_port_reg_value(port_id, reg_off, reg_v);
659 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
660 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
667 if (port_id_is_invalid(port_id, ENABLED_WARN))
669 if (port_reg_off_is_invalid(port_id, reg_off))
671 if (reg_bit_pos_is_invalid(bit1_pos))
673 if (reg_bit_pos_is_invalid(bit2_pos))
675 if (bit1_pos > bit2_pos)
676 l_bit = bit2_pos, h_bit = bit1_pos;
678 l_bit = bit1_pos, h_bit = bit2_pos;
680 if ((h_bit - l_bit) < 31)
681 max_v = (1 << (h_bit - l_bit + 1)) - 1;
686 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
687 (unsigned)value, (unsigned)value,
688 (unsigned)max_v, (unsigned)max_v);
691 reg_v = port_id_pci_reg_read(port_id, reg_off);
692 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
693 reg_v |= (value << l_bit); /* Set changed bits */
694 port_id_pci_reg_write(port_id, reg_off, reg_v);
695 display_port_reg_value(port_id, reg_off, reg_v);
699 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
701 if (port_id_is_invalid(port_id, ENABLED_WARN))
703 if (port_reg_off_is_invalid(port_id, reg_off))
705 port_id_pci_reg_write(port_id, reg_off, reg_v);
706 display_port_reg_value(port_id, reg_off, reg_v);
710 port_mtu_set(portid_t port_id, uint16_t mtu)
714 if (port_id_is_invalid(port_id, ENABLED_WARN))
716 diag = rte_eth_dev_set_mtu(port_id, mtu);
719 printf("Set MTU failed. diag=%d\n", diag);
723 * RX/TX ring descriptors display functions.
726 rx_queue_id_is_invalid(queueid_t rxq_id)
730 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
735 tx_queue_id_is_invalid(queueid_t txq_id)
739 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
744 rx_desc_id_is_invalid(uint16_t rxdesc_id)
746 if (rxdesc_id < nb_rxd)
748 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
754 tx_desc_id_is_invalid(uint16_t txdesc_id)
756 if (txdesc_id < nb_txd)
758 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
763 static const struct rte_memzone *
764 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
766 char mz_name[RTE_MEMZONE_NAMESIZE];
767 const struct rte_memzone *mz;
769 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
770 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
771 mz = rte_memzone_lookup(mz_name);
773 printf("%s ring memory zoneof (port %d, queue %d) not"
774 "found (zone name = %s\n",
775 ring_name, port_id, q_id, mz_name);
779 union igb_ring_dword {
782 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
792 struct igb_ring_desc_32_bytes {
793 union igb_ring_dword lo_dword;
794 union igb_ring_dword hi_dword;
795 union igb_ring_dword resv1;
796 union igb_ring_dword resv2;
799 struct igb_ring_desc_16_bytes {
800 union igb_ring_dword lo_dword;
801 union igb_ring_dword hi_dword;
805 ring_rxd_display_dword(union igb_ring_dword dword)
807 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
808 (unsigned)dword.words.hi);
812 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
813 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
816 __rte_unused uint8_t port_id,
820 struct igb_ring_desc_16_bytes *ring =
821 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
822 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
823 struct rte_eth_dev_info dev_info;
825 memset(&dev_info, 0, sizeof(dev_info));
826 rte_eth_dev_info_get(port_id, &dev_info);
827 if (strstr(dev_info.driver_name, "i40e") != NULL) {
828 /* 32 bytes RX descriptor, i40e only */
829 struct igb_ring_desc_32_bytes *ring =
830 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
831 ring[desc_id].lo_dword.dword =
832 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
833 ring_rxd_display_dword(ring[desc_id].lo_dword);
834 ring[desc_id].hi_dword.dword =
835 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
836 ring_rxd_display_dword(ring[desc_id].hi_dword);
837 ring[desc_id].resv1.dword =
838 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
839 ring_rxd_display_dword(ring[desc_id].resv1);
840 ring[desc_id].resv2.dword =
841 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
842 ring_rxd_display_dword(ring[desc_id].resv2);
847 /* 16 bytes RX descriptor */
848 ring[desc_id].lo_dword.dword =
849 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
850 ring_rxd_display_dword(ring[desc_id].lo_dword);
851 ring[desc_id].hi_dword.dword =
852 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
853 ring_rxd_display_dword(ring[desc_id].hi_dword);
857 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
859 struct igb_ring_desc_16_bytes *ring;
860 struct igb_ring_desc_16_bytes txd;
862 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
863 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
864 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
865 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
866 (unsigned)txd.lo_dword.words.lo,
867 (unsigned)txd.lo_dword.words.hi,
868 (unsigned)txd.hi_dword.words.lo,
869 (unsigned)txd.hi_dword.words.hi);
873 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
875 const struct rte_memzone *rx_mz;
877 if (port_id_is_invalid(port_id, ENABLED_WARN))
879 if (rx_queue_id_is_invalid(rxq_id))
881 if (rx_desc_id_is_invalid(rxd_id))
883 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
886 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
890 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
892 const struct rte_memzone *tx_mz;
894 if (port_id_is_invalid(port_id, ENABLED_WARN))
896 if (tx_queue_id_is_invalid(txq_id))
898 if (tx_desc_id_is_invalid(txd_id))
900 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
903 ring_tx_descriptor_display(tx_mz, txd_id);
907 fwd_lcores_config_display(void)
911 printf("List of forwarding lcores:");
912 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
913 printf(" %2u", fwd_lcores_cpuids[lc_id]);
917 rxtx_config_display(void)
919 printf(" %s packet forwarding%s - CRC stripping %s - "
920 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
921 retry_enabled == 0 ? "" : " with retry",
922 rx_mode.hw_strip_crc ? "enabled" : "disabled",
925 if (cur_fwd_eng == &tx_only_engine)
926 printf(" packet len=%u - nb packet segments=%d\n",
927 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
929 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
930 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
932 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
933 nb_fwd_lcores, nb_fwd_ports);
934 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
935 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
936 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
937 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
938 rx_conf->rx_thresh.wthresh);
939 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
940 nb_txq, nb_txd, tx_conf->tx_free_thresh);
941 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
942 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
943 tx_conf->tx_thresh.wthresh);
944 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
945 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
949 port_rss_reta_info(portid_t port_id,
950 struct rte_eth_rss_reta_entry64 *reta_conf,
953 uint16_t i, idx, shift;
956 if (port_id_is_invalid(port_id, ENABLED_WARN))
959 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
961 printf("Failed to get RSS RETA info, return code = %d\n", ret);
965 for (i = 0; i < nb_entries; i++) {
966 idx = i / RTE_RETA_GROUP_SIZE;
967 shift = i % RTE_RETA_GROUP_SIZE;
968 if (!(reta_conf[idx].mask & (1ULL << shift)))
970 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
971 i, reta_conf[idx].reta[shift]);
976 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
980 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
982 struct rte_eth_rss_conf rss_conf;
983 uint8_t rss_key[10 * 4] = "";
988 if (port_id_is_invalid(port_id, ENABLED_WARN))
992 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
993 if (!strcmp(rss_info, rss_type_table[i].str))
994 rss_conf.rss_hf = rss_type_table[i].rss_type;
997 /* Get RSS hash key if asked to display it */
998 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
999 rss_conf.rss_key_len = sizeof(rss_key);
1000 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1004 printf("port index %d invalid\n", port_id);
1007 printf("operation not supported by device\n");
1010 printf("operation failed - diag=%d\n", diag);
1015 rss_hf = rss_conf.rss_hf;
1017 printf("RSS disabled\n");
1020 printf("RSS functions:\n ");
1021 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1022 if (rss_hf & rss_type_table[i].rss_type)
1023 printf("%s ", rss_type_table[i].str);
1028 printf("RSS key:\n");
1029 for (i = 0; i < sizeof(rss_key); i++)
1030 printf("%02X", rss_key[i]);
1035 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1038 struct rte_eth_rss_conf rss_conf;
1042 rss_conf.rss_key = NULL;
1043 rss_conf.rss_key_len = hash_key_len;
1044 rss_conf.rss_hf = 0;
1045 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1046 if (!strcmp(rss_type_table[i].str, rss_type))
1047 rss_conf.rss_hf = rss_type_table[i].rss_type;
1049 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1051 rss_conf.rss_key = hash_key;
1052 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1059 printf("port index %d invalid\n", port_id);
1062 printf("operation not supported by device\n");
1065 printf("operation failed - diag=%d\n", diag);
1071 * Setup forwarding configuration for each logical core.
1074 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1076 streamid_t nb_fs_per_lcore;
1084 nb_fs = cfg->nb_fwd_streams;
1085 nb_fc = cfg->nb_fwd_lcores;
1086 if (nb_fs <= nb_fc) {
1087 nb_fs_per_lcore = 1;
1090 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1091 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1094 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1096 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1097 fwd_lcores[lc_id]->stream_idx = sm_id;
1098 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1099 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1103 * Assign extra remaining streams, if any.
1105 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1106 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1107 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1108 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1109 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1114 simple_fwd_config_setup(void)
1120 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1121 port_topology == PORT_TOPOLOGY_LOOP) {
1123 } else if (nb_fwd_ports % 2) {
1124 printf("\nWarning! Cannot handle an odd number of ports "
1125 "with the current port topology. Configuration "
1126 "must be changed to have an even number of ports, "
1127 "or relaunch application with "
1128 "--port-topology=chained\n\n");
1131 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1132 cur_fwd_config.nb_fwd_streams =
1133 (streamid_t) cur_fwd_config.nb_fwd_ports;
1135 /* reinitialize forwarding streams */
1139 * In the simple forwarding test, the number of forwarding cores
1140 * must be lower or equal to the number of forwarding ports.
1142 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1143 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1144 cur_fwd_config.nb_fwd_lcores =
1145 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1146 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1148 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1149 if (port_topology != PORT_TOPOLOGY_LOOP)
1150 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1153 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1154 fwd_streams[i]->rx_queue = 0;
1155 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1156 fwd_streams[i]->tx_queue = 0;
1157 fwd_streams[i]->peer_addr = j;
1158 fwd_streams[i]->retry_enabled = retry_enabled;
1160 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1161 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1162 fwd_streams[j]->rx_queue = 0;
1163 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1164 fwd_streams[j]->tx_queue = 0;
1165 fwd_streams[j]->peer_addr = i;
1166 fwd_streams[j]->retry_enabled = retry_enabled;
1172 * For the RSS forwarding test, each core is assigned on every port a transmit
1173 * queue whose index is the index of the core itself. This approach limits the
1174 * maximumm number of processing cores of the RSS test to the maximum number of
1175 * TX queues supported by the devices.
1177 * Each core is assigned a single stream, each stream being composed of
1178 * a RX queue to poll on a RX port for input messages, associated with
1179 * a TX queue of a TX port where to send forwarded packets.
1180 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1181 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1183 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1187 rss_fwd_config_setup(void)
1198 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1199 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1200 cur_fwd_config.nb_fwd_streams =
1201 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1203 /* reinitialize forwarding streams */
1206 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1208 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_streams; lc_id++) {
1209 struct fwd_stream *fs;
1211 fs = fwd_streams[lc_id];
1213 if ((rxp & 0x1) == 0)
1214 txp = (portid_t) (rxp + 1);
1216 txp = (portid_t) (rxp - 1);
1218 * if we are in loopback, simply send stuff out through the
1221 if (port_topology == PORT_TOPOLOGY_LOOP)
1224 fs->rx_port = fwd_ports_ids[rxp];
1226 fs->tx_port = fwd_ports_ids[txp];
1228 fs->peer_addr = fs->tx_port;
1229 fs->retry_enabled = retry_enabled;
1230 rxq = (queueid_t) (rxq + 1);
1235 * Restart from RX queue 0 on next RX port
1238 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1240 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1242 rxp = (portid_t) (rxp + 1);
1247 * For the DCB forwarding test, each core is assigned on each traffic class.
1249 * Each core is assigned a multi-stream, each stream being composed of
1250 * a RX queue to poll on a RX port for input messages, associated with
1251 * a TX queue of a TX port where to send forwarded packets. All RX and
1252 * TX queues are mapping to the same traffic class.
1253 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1257 dcb_fwd_config_setup(void)
1259 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1260 portid_t txp, rxp = 0;
1261 queueid_t txq, rxq = 0;
1263 uint16_t nb_rx_queue, nb_tx_queue;
1264 uint16_t i, j, k, sm_id = 0;
1267 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1268 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1269 cur_fwd_config.nb_fwd_streams =
1270 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1272 /* reinitialize forwarding streams */
1276 /* get the dcb info on the first RX and TX ports */
1277 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1278 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
1280 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1281 fwd_lcores[lc_id]->stream_nb = 0;
1282 fwd_lcores[lc_id]->stream_idx = sm_id;
1283 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
1284 /* if the nb_queue is zero, means this tc is
1285 * not enabled on the POOL
1287 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
1289 k = fwd_lcores[lc_id]->stream_nb +
1290 fwd_lcores[lc_id]->stream_idx;
1291 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
1292 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
1293 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
1294 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
1295 for (j = 0; j < nb_rx_queue; j++) {
1296 struct fwd_stream *fs;
1298 fs = fwd_streams[k + j];
1299 fs->rx_port = fwd_ports_ids[rxp];
1300 fs->rx_queue = rxq + j;
1301 fs->tx_port = fwd_ports_ids[txp];
1302 fs->tx_queue = txq + j % nb_tx_queue;
1303 fs->peer_addr = fs->tx_port;
1304 fs->retry_enabled = retry_enabled;
1306 fwd_lcores[lc_id]->stream_nb +=
1307 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
1309 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
1312 if (tc < rxp_dcb_info.nb_tcs)
1314 /* Restart from TC 0 on next RX port */
1316 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1318 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1321 if (rxp >= nb_fwd_ports)
1323 /* get the dcb information on next RX and TX ports */
1324 if ((rxp & 0x1) == 0)
1325 txp = (portid_t) (rxp + 1);
1327 txp = (portid_t) (rxp - 1);
1328 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1329 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
1334 icmp_echo_config_setup(void)
1341 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1342 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1343 (nb_txq * nb_fwd_ports);
1345 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1346 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1347 cur_fwd_config.nb_fwd_streams =
1348 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1349 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1350 cur_fwd_config.nb_fwd_lcores =
1351 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1352 if (verbose_level > 0) {
1353 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1355 cur_fwd_config.nb_fwd_lcores,
1356 cur_fwd_config.nb_fwd_ports,
1357 cur_fwd_config.nb_fwd_streams);
1360 /* reinitialize forwarding streams */
1362 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1364 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1365 if (verbose_level > 0)
1366 printf(" core=%d: \n", lc_id);
1367 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1368 struct fwd_stream *fs;
1369 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1370 fs->rx_port = fwd_ports_ids[rxp];
1372 fs->tx_port = fs->rx_port;
1374 fs->peer_addr = fs->tx_port;
1375 fs->retry_enabled = retry_enabled;
1376 if (verbose_level > 0)
1377 printf(" stream=%d port=%d rxq=%d txq=%d\n",
1378 sm_id, fs->rx_port, fs->rx_queue,
1380 rxq = (queueid_t) (rxq + 1);
1381 if (rxq == nb_rxq) {
1383 rxp = (portid_t) (rxp + 1);
1390 fwd_config_setup(void)
1392 cur_fwd_config.fwd_eng = cur_fwd_eng;
1393 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1394 icmp_echo_config_setup();
1397 if ((nb_rxq > 1) && (nb_txq > 1)){
1399 dcb_fwd_config_setup();
1401 rss_fwd_config_setup();
1404 simple_fwd_config_setup();
1408 pkt_fwd_config_display(struct fwd_config *cfg)
1410 struct fwd_stream *fs;
1414 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
1415 "NUMA support %s, MP over anonymous pages %s\n",
1416 cfg->fwd_eng->fwd_mode_name,
1417 retry_enabled == 0 ? "" : " with retry",
1418 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1419 numa_support == 1 ? "enabled" : "disabled",
1420 mp_anon != 0 ? "enabled" : "disabled");
1423 printf("TX retry num: %u, delay between TX retries: %uus\n",
1424 burst_tx_retry_num, burst_tx_delay_time);
1425 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1426 printf("Logical Core %u (socket %u) forwards packets on "
1428 fwd_lcores_cpuids[lc_id],
1429 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1430 fwd_lcores[lc_id]->stream_nb);
1431 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1432 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1433 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
1434 "P=%d/Q=%d (socket %u) ",
1435 fs->rx_port, fs->rx_queue,
1436 ports[fs->rx_port].socket_id,
1437 fs->tx_port, fs->tx_queue,
1438 ports[fs->tx_port].socket_id);
1439 print_ethaddr("peer=",
1440 &peer_eth_addrs[fs->peer_addr]);
1448 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1451 unsigned int lcore_cpuid;
1456 for (i = 0; i < nb_lc; i++) {
1457 lcore_cpuid = lcorelist[i];
1458 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1459 printf("lcore %u not enabled\n", lcore_cpuid);
1462 if (lcore_cpuid == rte_get_master_lcore()) {
1463 printf("lcore %u cannot be masked on for running "
1464 "packet forwarding, which is the master lcore "
1465 "and reserved for command line parsing only\n",
1470 fwd_lcores_cpuids[i] = lcore_cpuid;
1472 if (record_now == 0) {
1476 nb_cfg_lcores = (lcoreid_t) nb_lc;
1477 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1478 printf("previous number of forwarding cores %u - changed to "
1479 "number of configured cores %u\n",
1480 (unsigned int) nb_fwd_lcores, nb_lc);
1481 nb_fwd_lcores = (lcoreid_t) nb_lc;
1488 set_fwd_lcores_mask(uint64_t lcoremask)
1490 unsigned int lcorelist[64];
1494 if (lcoremask == 0) {
1495 printf("Invalid NULL mask of cores\n");
1499 for (i = 0; i < 64; i++) {
1500 if (! ((uint64_t)(1ULL << i) & lcoremask))
1502 lcorelist[nb_lc++] = i;
1504 return set_fwd_lcores_list(lcorelist, nb_lc);
1508 set_fwd_lcores_number(uint16_t nb_lc)
1510 if (nb_lc > nb_cfg_lcores) {
1511 printf("nb fwd cores %u > %u (max. number of configured "
1512 "lcores) - ignored\n",
1513 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1516 nb_fwd_lcores = (lcoreid_t) nb_lc;
1517 printf("Number of forwarding cores set to %u\n",
1518 (unsigned int) nb_fwd_lcores);
1522 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1530 for (i = 0; i < nb_pt; i++) {
1531 port_id = (portid_t) portlist[i];
1532 if (port_id_is_invalid(port_id, ENABLED_WARN))
1535 fwd_ports_ids[i] = port_id;
1537 if (record_now == 0) {
1541 nb_cfg_ports = (portid_t) nb_pt;
1542 if (nb_fwd_ports != (portid_t) nb_pt) {
1543 printf("previous number of forwarding ports %u - changed to "
1544 "number of configured ports %u\n",
1545 (unsigned int) nb_fwd_ports, nb_pt);
1546 nb_fwd_ports = (portid_t) nb_pt;
1551 set_fwd_ports_mask(uint64_t portmask)
1553 unsigned int portlist[64];
1557 if (portmask == 0) {
1558 printf("Invalid NULL mask of ports\n");
1562 for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
1563 if (! ((uint64_t)(1ULL << i) & portmask))
1565 portlist[nb_pt++] = i;
1567 set_fwd_ports_list(portlist, nb_pt);
1571 set_fwd_ports_number(uint16_t nb_pt)
1573 if (nb_pt > nb_cfg_ports) {
1574 printf("nb fwd ports %u > %u (number of configured "
1575 "ports) - ignored\n",
1576 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1579 nb_fwd_ports = (portid_t) nb_pt;
1580 printf("Number of forwarding ports set to %u\n",
1581 (unsigned int) nb_fwd_ports);
1585 port_is_forwarding(portid_t port_id)
1589 if (port_id_is_invalid(port_id, ENABLED_WARN))
1592 for (i = 0; i < nb_fwd_ports; i++) {
1593 if (fwd_ports_ids[i] == port_id)
1601 set_nb_pkt_per_burst(uint16_t nb)
1603 if (nb > MAX_PKT_BURST) {
1604 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1606 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1609 nb_pkt_per_burst = nb;
1610 printf("Number of packets per burst set to %u\n",
1611 (unsigned int) nb_pkt_per_burst);
1615 tx_split_get_name(enum tx_pkt_split split)
1619 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
1620 if (tx_split_name[i].split == split)
1621 return tx_split_name[i].name;
1627 set_tx_pkt_split(const char *name)
1631 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
1632 if (strcmp(tx_split_name[i].name, name) == 0) {
1633 tx_pkt_split = tx_split_name[i].split;
1637 printf("unknown value: \"%s\"\n", name);
1641 show_tx_pkt_segments(void)
1647 split = tx_split_get_name(tx_pkt_split);
1649 printf("Number of segments: %u\n", n);
1650 printf("Segment sizes: ");
1651 for (i = 0; i != n - 1; i++)
1652 printf("%hu,", tx_pkt_seg_lengths[i]);
1653 printf("%hu\n", tx_pkt_seg_lengths[i]);
1654 printf("Split packet: %s\n", split);
1658 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1660 uint16_t tx_pkt_len;
1663 if (nb_segs >= (unsigned) nb_txd) {
1664 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1665 nb_segs, (unsigned int) nb_txd);
1670 * Check that each segment length is greater or equal than
1671 * the mbuf data sise.
1672 * Check also that the total packet length is greater or equal than the
1673 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1676 for (i = 0; i < nb_segs; i++) {
1677 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1678 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1679 i, seg_lengths[i], (unsigned) mbuf_data_size);
1682 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1684 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1685 printf("total packet length=%u < %d - give up\n",
1686 (unsigned) tx_pkt_len,
1687 (int)(sizeof(struct ether_hdr) + 20 + 8));
1691 for (i = 0; i < nb_segs; i++)
1692 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1694 tx_pkt_length = tx_pkt_len;
1695 tx_pkt_nb_segs = (uint8_t) nb_segs;
1699 list_pkt_forwarding_modes(void)
1701 static char fwd_modes[128] = "";
1702 const char *separator = "|";
1703 struct fwd_engine *fwd_eng;
1706 if (strlen (fwd_modes) == 0) {
1707 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1708 strncat(fwd_modes, fwd_eng->fwd_mode_name,
1709 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
1710 strncat(fwd_modes, separator,
1711 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
1713 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1720 list_pkt_forwarding_retry_modes(void)
1722 static char fwd_modes[128] = "";
1723 const char *separator = "|";
1724 struct fwd_engine *fwd_eng;
1727 if (strlen(fwd_modes) == 0) {
1728 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1729 if (fwd_eng == &rx_only_engine)
1731 strncat(fwd_modes, fwd_eng->fwd_mode_name,
1733 strlen(fwd_modes) - 1);
1734 strncat(fwd_modes, separator,
1736 strlen(fwd_modes) - 1);
1738 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1745 set_pkt_forwarding_mode(const char *fwd_mode_name)
1747 struct fwd_engine *fwd_eng;
1751 while ((fwd_eng = fwd_engines[i]) != NULL) {
1752 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1753 printf("Set %s packet forwarding mode%s\n",
1755 retry_enabled == 0 ? "" : " with retry");
1756 cur_fwd_eng = fwd_eng;
1761 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1765 set_verbose_level(uint16_t vb_level)
1767 printf("Change verbose level from %u to %u\n",
1768 (unsigned int) verbose_level, (unsigned int) vb_level);
1769 verbose_level = vb_level;
1773 vlan_extend_set(portid_t port_id, int on)
1778 if (port_id_is_invalid(port_id, ENABLED_WARN))
1781 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1784 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1786 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1788 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1790 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1791 "diag=%d\n", port_id, on, diag);
1795 rx_vlan_strip_set(portid_t port_id, int on)
1800 if (port_id_is_invalid(port_id, ENABLED_WARN))
1803 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1806 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1808 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1810 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1812 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1813 "diag=%d\n", port_id, on, diag);
1817 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1821 if (port_id_is_invalid(port_id, ENABLED_WARN))
1824 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1826 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1827 "diag=%d\n", port_id, queue_id, on, diag);
1831 rx_vlan_filter_set(portid_t port_id, int on)
1836 if (port_id_is_invalid(port_id, ENABLED_WARN))
1839 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1842 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1844 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1846 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1848 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1849 "diag=%d\n", port_id, on, diag);
1853 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1857 if (port_id_is_invalid(port_id, ENABLED_WARN))
1859 if (vlan_id_is_invalid(vlan_id))
1861 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1864 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1866 port_id, vlan_id, on, diag);
1871 rx_vlan_all_filter_set(portid_t port_id, int on)
1875 if (port_id_is_invalid(port_id, ENABLED_WARN))
1877 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
1878 if (rx_vft_set(port_id, vlan_id, on))
1884 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
1888 if (port_id_is_invalid(port_id, ENABLED_WARN))
1891 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
1895 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
1897 port_id, vlan_type, tp_id, diag);
1901 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1904 if (port_id_is_invalid(port_id, ENABLED_WARN))
1906 if (vlan_id_is_invalid(vlan_id))
1909 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1910 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
1911 printf("Error, as QinQ has been enabled.\n");
1915 tx_vlan_reset(port_id);
1916 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1917 ports[port_id].tx_vlan_id = vlan_id;
1921 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
1924 if (port_id_is_invalid(port_id, ENABLED_WARN))
1926 if (vlan_id_is_invalid(vlan_id))
1928 if (vlan_id_is_invalid(vlan_id_outer))
1931 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1932 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
1933 printf("Error, as QinQ hasn't been enabled.\n");
1937 tx_vlan_reset(port_id);
1938 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
1939 ports[port_id].tx_vlan_id = vlan_id;
1940 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
1944 tx_vlan_reset(portid_t port_id)
1946 if (port_id_is_invalid(port_id, ENABLED_WARN))
1948 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
1949 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
1950 ports[port_id].tx_vlan_id = 0;
1951 ports[port_id].tx_vlan_id_outer = 0;
1955 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
1957 if (port_id_is_invalid(port_id, ENABLED_WARN))
1960 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
1964 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1967 uint8_t existing_mapping_found = 0;
1969 if (port_id_is_invalid(port_id, ENABLED_WARN))
1972 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1975 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1976 printf("map_value not in required range 0..%d\n",
1977 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1981 if (!is_rx) { /*then tx*/
1982 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1983 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1984 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1985 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1986 existing_mapping_found = 1;
1990 if (!existing_mapping_found) { /* A new additional mapping... */
1991 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1992 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1993 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1994 nb_tx_queue_stats_mappings++;
1998 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1999 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2000 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2001 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2002 existing_mapping_found = 1;
2006 if (!existing_mapping_found) { /* A new additional mapping... */
2007 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2008 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2009 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2010 nb_rx_queue_stats_mappings++;
2016 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2018 printf("\n vlan_tci: 0x%04x, ", mask->vlan_tci_mask);
2020 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2021 printf("mac_addr: 0x%02x", mask->mac_addr_byte_mask);
2022 else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2023 printf("mac_addr: 0x%02x, tunnel_type: 0x%01x, tunnel_id: 0x%08x",
2024 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2025 mask->tunnel_id_mask);
2027 printf("src_ipv4: 0x%08x, dst_ipv4: 0x%08x,"
2028 " src_port: 0x%04x, dst_port: 0x%04x",
2029 mask->ipv4_mask.src_ip, mask->ipv4_mask.dst_ip,
2030 mask->src_port_mask, mask->dst_port_mask);
2032 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x,"
2033 " dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2034 mask->ipv6_mask.src_ip[0], mask->ipv6_mask.src_ip[1],
2035 mask->ipv6_mask.src_ip[2], mask->ipv6_mask.src_ip[3],
2036 mask->ipv6_mask.dst_ip[0], mask->ipv6_mask.dst_ip[1],
2037 mask->ipv6_mask.dst_ip[2], mask->ipv6_mask.dst_ip[3]);
2044 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2046 struct rte_eth_flex_payload_cfg *cfg;
2049 for (i = 0; i < flex_conf->nb_payloads; i++) {
2050 cfg = &flex_conf->flex_set[i];
2051 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2053 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2054 printf("\n L2_PAYLOAD: ");
2055 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2056 printf("\n L3_PAYLOAD: ");
2057 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2058 printf("\n L4_PAYLOAD: ");
2060 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2061 for (j = 0; j < num; j++)
2062 printf(" %-5u", cfg->src_offset[j]);
2068 flowtype_to_str(uint16_t flow_type)
2070 struct flow_type_info {
2076 static struct flow_type_info flowtype_str_table[] = {
2077 {"raw", RTE_ETH_FLOW_RAW},
2078 {"ipv4", RTE_ETH_FLOW_IPV4},
2079 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2080 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2081 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2082 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2083 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2084 {"ipv6", RTE_ETH_FLOW_IPV6},
2085 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2086 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2087 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2088 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2089 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2090 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2093 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2094 if (flowtype_str_table[i].ftype == flow_type)
2095 return flowtype_str_table[i].str;
2102 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2104 struct rte_eth_fdir_flex_mask *mask;
2108 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2109 mask = &flex_conf->flex_mask[i];
2110 p = flowtype_to_str(mask->flow_type);
2111 printf("\n %s:\t", p ? p : "unknown");
2112 for (j = 0; j < num; j++)
2113 printf(" %02x", mask->mask[j]);
2119 print_fdir_flow_type(uint32_t flow_types_mask)
2124 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2125 if (!(flow_types_mask & (1 << i)))
2127 p = flowtype_to_str(i);
2137 fdir_get_infos(portid_t port_id)
2139 struct rte_eth_fdir_stats fdir_stat;
2140 struct rte_eth_fdir_info fdir_info;
2143 static const char *fdir_stats_border = "########################";
2145 if (port_id_is_invalid(port_id, ENABLED_WARN))
2147 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
2149 printf("\n FDIR is not supported on port %-2d\n",
2154 memset(&fdir_info, 0, sizeof(fdir_info));
2155 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2156 RTE_ETH_FILTER_INFO, &fdir_info);
2157 memset(&fdir_stat, 0, sizeof(fdir_stat));
2158 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2159 RTE_ETH_FILTER_STATS, &fdir_stat);
2160 printf("\n %s FDIR infos for port %-2d %s\n",
2161 fdir_stats_border, port_id, fdir_stats_border);
2163 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
2164 printf(" PERFECT\n");
2165 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2166 printf(" PERFECT-MAC-VLAN\n");
2167 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2168 printf(" PERFECT-TUNNEL\n");
2169 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
2170 printf(" SIGNATURE\n");
2172 printf(" DISABLE\n");
2173 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
2174 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
2175 printf(" SUPPORTED FLOW TYPE: ");
2176 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
2178 printf(" FLEX PAYLOAD INFO:\n");
2179 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
2180 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
2181 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
2182 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
2183 fdir_info.flex_payload_unit,
2184 fdir_info.max_flex_payload_segment_num,
2185 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
2187 print_fdir_mask(&fdir_info.mask);
2188 if (fdir_info.flex_conf.nb_payloads > 0) {
2189 printf(" FLEX PAYLOAD SRC OFFSET:");
2190 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2192 if (fdir_info.flex_conf.nb_flexmasks > 0) {
2193 printf(" FLEX MASK CFG:");
2194 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2196 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2197 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2198 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2199 fdir_info.guarant_spc, fdir_info.best_spc);
2200 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2201 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2202 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2203 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2204 fdir_stat.collision, fdir_stat.free,
2205 fdir_stat.maxhash, fdir_stat.maxlen,
2206 fdir_stat.add, fdir_stat.remove,
2207 fdir_stat.f_add, fdir_stat.f_remove);
2208 printf(" %s############################%s\n",
2209 fdir_stats_border, fdir_stats_border);
2213 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2215 struct rte_port *port;
2216 struct rte_eth_fdir_flex_conf *flex_conf;
2219 port = &ports[port_id];
2220 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2221 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2222 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2227 if (i >= RTE_ETH_FLOW_MAX) {
2228 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2229 idx = flex_conf->nb_flexmasks;
2230 flex_conf->nb_flexmasks++;
2232 printf("The flex mask table is full. Can not set flex"
2233 " mask for flow_type(%u).", cfg->flow_type);
2237 (void)rte_memcpy(&flex_conf->flex_mask[idx],
2239 sizeof(struct rte_eth_fdir_flex_mask));
2243 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2245 struct rte_port *port;
2246 struct rte_eth_fdir_flex_conf *flex_conf;
2249 port = &ports[port_id];
2250 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2251 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2252 if (cfg->type == flex_conf->flex_set[i].type) {
2257 if (i >= RTE_ETH_PAYLOAD_MAX) {
2258 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2259 idx = flex_conf->nb_payloads;
2260 flex_conf->nb_payloads++;
2262 printf("The flex payload table is full. Can not set"
2263 " flex payload for type(%u).", cfg->type);
2267 (void)rte_memcpy(&flex_conf->flex_set[idx],
2269 sizeof(struct rte_eth_flex_payload_cfg));
2274 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
2278 if (port_id_is_invalid(port_id, ENABLED_WARN))
2281 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
2283 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
2287 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
2288 "diag=%d\n", port_id, diag);
2290 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
2291 "diag=%d\n", port_id, diag);
2296 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
2300 if (port_id_is_invalid(port_id, ENABLED_WARN))
2302 if (vlan_id_is_invalid(vlan_id))
2304 diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
2307 printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
2308 "diag=%d\n", port_id, diag);
2312 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
2315 struct rte_eth_link link;
2317 if (port_id_is_invalid(port_id, ENABLED_WARN))
2319 rte_eth_link_get_nowait(port_id, &link);
2320 if (rate > link.link_speed) {
2321 printf("Invalid rate value:%u bigger than link speed: %u\n",
2322 rate, link.link_speed);
2325 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
2328 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
2334 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
2337 struct rte_eth_link link;
2342 if (port_id_is_invalid(port_id, ENABLED_WARN))
2344 rte_eth_link_get_nowait(port_id, &link);
2345 if (rate > link.link_speed) {
2346 printf("Invalid rate value:%u bigger than link speed: %u\n",
2347 rate, link.link_speed);
2350 diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
2353 printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",
2359 * Functions to manage the set of filtered Multicast MAC addresses.
2361 * A pool of filtered multicast MAC addresses is associated with each port.
2362 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
2363 * The address of the pool and the number of valid multicast MAC addresses
2364 * recorded in the pool are stored in the fields "mc_addr_pool" and
2365 * "mc_addr_nb" of the "rte_port" data structure.
2367 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
2368 * to be supplied a contiguous array of multicast MAC addresses.
2369 * To comply with this constraint, the set of multicast addresses recorded
2370 * into the pool are systematically compacted at the beginning of the pool.
2371 * Hence, when a multicast address is removed from the pool, all following
2372 * addresses, if any, are copied back to keep the set contiguous.
2374 #define MCAST_POOL_INC 32
2377 mcast_addr_pool_extend(struct rte_port *port)
2379 struct ether_addr *mc_pool;
2380 size_t mc_pool_size;
2383 * If a free entry is available at the end of the pool, just
2384 * increment the number of recorded multicast addresses.
2386 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
2392 * [re]allocate a pool with MCAST_POOL_INC more entries.
2393 * The previous test guarantees that port->mc_addr_nb is a multiple
2394 * of MCAST_POOL_INC.
2396 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
2398 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
2400 if (mc_pool == NULL) {
2401 printf("allocation of pool of %u multicast addresses failed\n",
2402 port->mc_addr_nb + MCAST_POOL_INC);
2406 port->mc_addr_pool = mc_pool;
2413 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
2416 if (addr_idx == port->mc_addr_nb) {
2417 /* No need to recompact the set of multicast addressses. */
2418 if (port->mc_addr_nb == 0) {
2419 /* free the pool of multicast addresses. */
2420 free(port->mc_addr_pool);
2421 port->mc_addr_pool = NULL;
2425 memmove(&port->mc_addr_pool[addr_idx],
2426 &port->mc_addr_pool[addr_idx + 1],
2427 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
2431 eth_port_multicast_addr_list_set(uint8_t port_id)
2433 struct rte_port *port;
2436 port = &ports[port_id];
2437 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
2441 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
2442 port->mc_addr_nb, port_id, -diag);
2446 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
2448 struct rte_port *port;
2451 if (port_id_is_invalid(port_id, ENABLED_WARN))
2454 port = &ports[port_id];
2457 * Check that the added multicast MAC address is not already recorded
2458 * in the pool of multicast addresses.
2460 for (i = 0; i < port->mc_addr_nb; i++) {
2461 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
2462 printf("multicast address already filtered by port\n");
2467 if (mcast_addr_pool_extend(port) != 0)
2469 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
2470 eth_port_multicast_addr_list_set(port_id);
2474 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
2476 struct rte_port *port;
2479 if (port_id_is_invalid(port_id, ENABLED_WARN))
2482 port = &ports[port_id];
2485 * Search the pool of multicast MAC addresses for the removed address.
2487 for (i = 0; i < port->mc_addr_nb; i++) {
2488 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
2491 if (i == port->mc_addr_nb) {
2492 printf("multicast address not filtered by port %d\n", port_id);
2496 mcast_addr_pool_remove(port, i);
2497 eth_port_multicast_addr_list_set(port_id);
2501 port_dcb_info_display(uint8_t port_id)
2503 struct rte_eth_dcb_info dcb_info;
2506 static const char *border = "================";
2508 if (port_id_is_invalid(port_id, ENABLED_WARN))
2511 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
2513 printf("\n Failed to get dcb infos on port %-2d\n",
2517 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
2518 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
2520 for (i = 0; i < dcb_info.nb_tcs; i++)
2522 printf("\n Priority : ");
2523 for (i = 0; i < dcb_info.nb_tcs; i++)
2524 printf("\t%4d", dcb_info.prio_tc[i]);
2525 printf("\n BW percent :");
2526 for (i = 0; i < dcb_info.nb_tcs; i++)
2527 printf("\t%4d%%", dcb_info.tc_bws[i]);
2528 printf("\n RXQ base : ");
2529 for (i = 0; i < dcb_info.nb_tcs; i++)
2530 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
2531 printf("\n RXQ number :");
2532 for (i = 0; i < dcb_info.nb_tcs; i++)
2533 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
2534 printf("\n TXQ base : ");
2535 for (i = 0; i < dcb_info.nb_tcs; i++)
2536 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
2537 printf("\n TXQ number :");
2538 for (i = 0; i < dcb_info.nb_tcs; i++)
2539 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);