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);
1202 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
1203 cur_fwd_config.nb_fwd_streams =
1204 (streamid_t)cur_fwd_config.nb_fwd_lcores;
1206 cur_fwd_config.nb_fwd_lcores =
1207 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1209 /* reinitialize forwarding streams */
1212 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1214 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1215 struct fwd_stream *fs;
1217 fs = fwd_streams[lc_id];
1219 if ((rxp & 0x1) == 0)
1220 txp = (portid_t) (rxp + 1);
1222 txp = (portid_t) (rxp - 1);
1224 * if we are in loopback, simply send stuff out through the
1227 if (port_topology == PORT_TOPOLOGY_LOOP)
1230 fs->rx_port = fwd_ports_ids[rxp];
1232 fs->tx_port = fwd_ports_ids[txp];
1234 fs->peer_addr = fs->tx_port;
1235 fs->retry_enabled = retry_enabled;
1236 rxq = (queueid_t) (rxq + 1);
1241 * Restart from RX queue 0 on next RX port
1244 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1246 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1248 rxp = (portid_t) (rxp + 1);
1253 * For the DCB forwarding test, each core is assigned on each traffic class.
1255 * Each core is assigned a multi-stream, each stream being composed of
1256 * a RX queue to poll on a RX port for input messages, associated with
1257 * a TX queue of a TX port where to send forwarded packets. All RX and
1258 * TX queues are mapping to the same traffic class.
1259 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1263 dcb_fwd_config_setup(void)
1265 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1266 portid_t txp, rxp = 0;
1267 queueid_t txq, rxq = 0;
1269 uint16_t nb_rx_queue, nb_tx_queue;
1270 uint16_t i, j, k, sm_id = 0;
1273 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1274 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1275 cur_fwd_config.nb_fwd_streams =
1276 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1278 /* reinitialize forwarding streams */
1282 /* get the dcb info on the first RX and TX ports */
1283 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1284 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
1286 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1287 fwd_lcores[lc_id]->stream_nb = 0;
1288 fwd_lcores[lc_id]->stream_idx = sm_id;
1289 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
1290 /* if the nb_queue is zero, means this tc is
1291 * not enabled on the POOL
1293 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
1295 k = fwd_lcores[lc_id]->stream_nb +
1296 fwd_lcores[lc_id]->stream_idx;
1297 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
1298 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
1299 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
1300 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
1301 for (j = 0; j < nb_rx_queue; j++) {
1302 struct fwd_stream *fs;
1304 fs = fwd_streams[k + j];
1305 fs->rx_port = fwd_ports_ids[rxp];
1306 fs->rx_queue = rxq + j;
1307 fs->tx_port = fwd_ports_ids[txp];
1308 fs->tx_queue = txq + j % nb_tx_queue;
1309 fs->peer_addr = fs->tx_port;
1310 fs->retry_enabled = retry_enabled;
1312 fwd_lcores[lc_id]->stream_nb +=
1313 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
1315 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
1318 if (tc < rxp_dcb_info.nb_tcs)
1320 /* Restart from TC 0 on next RX port */
1322 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1324 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1327 if (rxp >= nb_fwd_ports)
1329 /* get the dcb information on next RX and TX ports */
1330 if ((rxp & 0x1) == 0)
1331 txp = (portid_t) (rxp + 1);
1333 txp = (portid_t) (rxp - 1);
1334 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1335 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
1340 icmp_echo_config_setup(void)
1347 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1348 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1349 (nb_txq * nb_fwd_ports);
1351 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1352 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1353 cur_fwd_config.nb_fwd_streams =
1354 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1355 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1356 cur_fwd_config.nb_fwd_lcores =
1357 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1358 if (verbose_level > 0) {
1359 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1361 cur_fwd_config.nb_fwd_lcores,
1362 cur_fwd_config.nb_fwd_ports,
1363 cur_fwd_config.nb_fwd_streams);
1366 /* reinitialize forwarding streams */
1368 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1370 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1371 if (verbose_level > 0)
1372 printf(" core=%d: \n", lc_id);
1373 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1374 struct fwd_stream *fs;
1375 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1376 fs->rx_port = fwd_ports_ids[rxp];
1378 fs->tx_port = fs->rx_port;
1380 fs->peer_addr = fs->tx_port;
1381 fs->retry_enabled = retry_enabled;
1382 if (verbose_level > 0)
1383 printf(" stream=%d port=%d rxq=%d txq=%d\n",
1384 sm_id, fs->rx_port, fs->rx_queue,
1386 rxq = (queueid_t) (rxq + 1);
1387 if (rxq == nb_rxq) {
1389 rxp = (portid_t) (rxp + 1);
1396 fwd_config_setup(void)
1398 cur_fwd_config.fwd_eng = cur_fwd_eng;
1399 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1400 icmp_echo_config_setup();
1403 if ((nb_rxq > 1) && (nb_txq > 1)){
1405 dcb_fwd_config_setup();
1407 rss_fwd_config_setup();
1410 simple_fwd_config_setup();
1414 pkt_fwd_config_display(struct fwd_config *cfg)
1416 struct fwd_stream *fs;
1420 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
1421 "NUMA support %s, MP over anonymous pages %s\n",
1422 cfg->fwd_eng->fwd_mode_name,
1423 retry_enabled == 0 ? "" : " with retry",
1424 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1425 numa_support == 1 ? "enabled" : "disabled",
1426 mp_anon != 0 ? "enabled" : "disabled");
1429 printf("TX retry num: %u, delay between TX retries: %uus\n",
1430 burst_tx_retry_num, burst_tx_delay_time);
1431 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1432 printf("Logical Core %u (socket %u) forwards packets on "
1434 fwd_lcores_cpuids[lc_id],
1435 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1436 fwd_lcores[lc_id]->stream_nb);
1437 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1438 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1439 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
1440 "P=%d/Q=%d (socket %u) ",
1441 fs->rx_port, fs->rx_queue,
1442 ports[fs->rx_port].socket_id,
1443 fs->tx_port, fs->tx_queue,
1444 ports[fs->tx_port].socket_id);
1445 print_ethaddr("peer=",
1446 &peer_eth_addrs[fs->peer_addr]);
1454 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1457 unsigned int lcore_cpuid;
1462 for (i = 0; i < nb_lc; i++) {
1463 lcore_cpuid = lcorelist[i];
1464 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1465 printf("lcore %u not enabled\n", lcore_cpuid);
1468 if (lcore_cpuid == rte_get_master_lcore()) {
1469 printf("lcore %u cannot be masked on for running "
1470 "packet forwarding, which is the master lcore "
1471 "and reserved for command line parsing only\n",
1476 fwd_lcores_cpuids[i] = lcore_cpuid;
1478 if (record_now == 0) {
1482 nb_cfg_lcores = (lcoreid_t) nb_lc;
1483 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1484 printf("previous number of forwarding cores %u - changed to "
1485 "number of configured cores %u\n",
1486 (unsigned int) nb_fwd_lcores, nb_lc);
1487 nb_fwd_lcores = (lcoreid_t) nb_lc;
1494 set_fwd_lcores_mask(uint64_t lcoremask)
1496 unsigned int lcorelist[64];
1500 if (lcoremask == 0) {
1501 printf("Invalid NULL mask of cores\n");
1505 for (i = 0; i < 64; i++) {
1506 if (! ((uint64_t)(1ULL << i) & lcoremask))
1508 lcorelist[nb_lc++] = i;
1510 return set_fwd_lcores_list(lcorelist, nb_lc);
1514 set_fwd_lcores_number(uint16_t nb_lc)
1516 if (nb_lc > nb_cfg_lcores) {
1517 printf("nb fwd cores %u > %u (max. number of configured "
1518 "lcores) - ignored\n",
1519 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1522 nb_fwd_lcores = (lcoreid_t) nb_lc;
1523 printf("Number of forwarding cores set to %u\n",
1524 (unsigned int) nb_fwd_lcores);
1528 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1536 for (i = 0; i < nb_pt; i++) {
1537 port_id = (portid_t) portlist[i];
1538 if (port_id_is_invalid(port_id, ENABLED_WARN))
1541 fwd_ports_ids[i] = port_id;
1543 if (record_now == 0) {
1547 nb_cfg_ports = (portid_t) nb_pt;
1548 if (nb_fwd_ports != (portid_t) nb_pt) {
1549 printf("previous number of forwarding ports %u - changed to "
1550 "number of configured ports %u\n",
1551 (unsigned int) nb_fwd_ports, nb_pt);
1552 nb_fwd_ports = (portid_t) nb_pt;
1557 set_fwd_ports_mask(uint64_t portmask)
1559 unsigned int portlist[64];
1563 if (portmask == 0) {
1564 printf("Invalid NULL mask of ports\n");
1568 for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
1569 if (! ((uint64_t)(1ULL << i) & portmask))
1571 portlist[nb_pt++] = i;
1573 set_fwd_ports_list(portlist, nb_pt);
1577 set_fwd_ports_number(uint16_t nb_pt)
1579 if (nb_pt > nb_cfg_ports) {
1580 printf("nb fwd ports %u > %u (number of configured "
1581 "ports) - ignored\n",
1582 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1585 nb_fwd_ports = (portid_t) nb_pt;
1586 printf("Number of forwarding ports set to %u\n",
1587 (unsigned int) nb_fwd_ports);
1591 port_is_forwarding(portid_t port_id)
1595 if (port_id_is_invalid(port_id, ENABLED_WARN))
1598 for (i = 0; i < nb_fwd_ports; i++) {
1599 if (fwd_ports_ids[i] == port_id)
1607 set_nb_pkt_per_burst(uint16_t nb)
1609 if (nb > MAX_PKT_BURST) {
1610 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1612 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1615 nb_pkt_per_burst = nb;
1616 printf("Number of packets per burst set to %u\n",
1617 (unsigned int) nb_pkt_per_burst);
1621 tx_split_get_name(enum tx_pkt_split split)
1625 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
1626 if (tx_split_name[i].split == split)
1627 return tx_split_name[i].name;
1633 set_tx_pkt_split(const char *name)
1637 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
1638 if (strcmp(tx_split_name[i].name, name) == 0) {
1639 tx_pkt_split = tx_split_name[i].split;
1643 printf("unknown value: \"%s\"\n", name);
1647 show_tx_pkt_segments(void)
1653 split = tx_split_get_name(tx_pkt_split);
1655 printf("Number of segments: %u\n", n);
1656 printf("Segment sizes: ");
1657 for (i = 0; i != n - 1; i++)
1658 printf("%hu,", tx_pkt_seg_lengths[i]);
1659 printf("%hu\n", tx_pkt_seg_lengths[i]);
1660 printf("Split packet: %s\n", split);
1664 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1666 uint16_t tx_pkt_len;
1669 if (nb_segs >= (unsigned) nb_txd) {
1670 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1671 nb_segs, (unsigned int) nb_txd);
1676 * Check that each segment length is greater or equal than
1677 * the mbuf data sise.
1678 * Check also that the total packet length is greater or equal than the
1679 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1682 for (i = 0; i < nb_segs; i++) {
1683 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1684 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1685 i, seg_lengths[i], (unsigned) mbuf_data_size);
1688 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1690 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1691 printf("total packet length=%u < %d - give up\n",
1692 (unsigned) tx_pkt_len,
1693 (int)(sizeof(struct ether_hdr) + 20 + 8));
1697 for (i = 0; i < nb_segs; i++)
1698 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1700 tx_pkt_length = tx_pkt_len;
1701 tx_pkt_nb_segs = (uint8_t) nb_segs;
1705 list_pkt_forwarding_modes(void)
1707 static char fwd_modes[128] = "";
1708 const char *separator = "|";
1709 struct fwd_engine *fwd_eng;
1712 if (strlen (fwd_modes) == 0) {
1713 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1714 strncat(fwd_modes, fwd_eng->fwd_mode_name,
1715 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
1716 strncat(fwd_modes, separator,
1717 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
1719 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1726 list_pkt_forwarding_retry_modes(void)
1728 static char fwd_modes[128] = "";
1729 const char *separator = "|";
1730 struct fwd_engine *fwd_eng;
1733 if (strlen(fwd_modes) == 0) {
1734 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1735 if (fwd_eng == &rx_only_engine)
1737 strncat(fwd_modes, fwd_eng->fwd_mode_name,
1739 strlen(fwd_modes) - 1);
1740 strncat(fwd_modes, separator,
1742 strlen(fwd_modes) - 1);
1744 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1751 set_pkt_forwarding_mode(const char *fwd_mode_name)
1753 struct fwd_engine *fwd_eng;
1757 while ((fwd_eng = fwd_engines[i]) != NULL) {
1758 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1759 printf("Set %s packet forwarding mode%s\n",
1761 retry_enabled == 0 ? "" : " with retry");
1762 cur_fwd_eng = fwd_eng;
1767 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1771 set_verbose_level(uint16_t vb_level)
1773 printf("Change verbose level from %u to %u\n",
1774 (unsigned int) verbose_level, (unsigned int) vb_level);
1775 verbose_level = vb_level;
1779 vlan_extend_set(portid_t port_id, int on)
1784 if (port_id_is_invalid(port_id, ENABLED_WARN))
1787 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1790 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1792 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1794 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1796 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1797 "diag=%d\n", port_id, on, diag);
1801 rx_vlan_strip_set(portid_t port_id, int on)
1806 if (port_id_is_invalid(port_id, ENABLED_WARN))
1809 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1812 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1814 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1816 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1818 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1819 "diag=%d\n", port_id, on, diag);
1823 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1827 if (port_id_is_invalid(port_id, ENABLED_WARN))
1830 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1832 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1833 "diag=%d\n", port_id, queue_id, on, diag);
1837 rx_vlan_filter_set(portid_t port_id, int on)
1842 if (port_id_is_invalid(port_id, ENABLED_WARN))
1845 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1848 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1850 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1852 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1854 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1855 "diag=%d\n", port_id, on, diag);
1859 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1863 if (port_id_is_invalid(port_id, ENABLED_WARN))
1865 if (vlan_id_is_invalid(vlan_id))
1867 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1870 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1872 port_id, vlan_id, on, diag);
1877 rx_vlan_all_filter_set(portid_t port_id, int on)
1881 if (port_id_is_invalid(port_id, ENABLED_WARN))
1883 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
1884 if (rx_vft_set(port_id, vlan_id, on))
1890 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
1894 if (port_id_is_invalid(port_id, ENABLED_WARN))
1897 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
1901 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
1903 port_id, vlan_type, tp_id, diag);
1907 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1910 if (port_id_is_invalid(port_id, ENABLED_WARN))
1912 if (vlan_id_is_invalid(vlan_id))
1915 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1916 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
1917 printf("Error, as QinQ has been enabled.\n");
1921 tx_vlan_reset(port_id);
1922 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1923 ports[port_id].tx_vlan_id = vlan_id;
1927 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
1930 if (port_id_is_invalid(port_id, ENABLED_WARN))
1932 if (vlan_id_is_invalid(vlan_id))
1934 if (vlan_id_is_invalid(vlan_id_outer))
1937 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1938 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
1939 printf("Error, as QinQ hasn't been enabled.\n");
1943 tx_vlan_reset(port_id);
1944 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
1945 ports[port_id].tx_vlan_id = vlan_id;
1946 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
1950 tx_vlan_reset(portid_t port_id)
1952 if (port_id_is_invalid(port_id, ENABLED_WARN))
1954 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
1955 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
1956 ports[port_id].tx_vlan_id = 0;
1957 ports[port_id].tx_vlan_id_outer = 0;
1961 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
1963 if (port_id_is_invalid(port_id, ENABLED_WARN))
1966 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
1970 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1973 uint8_t existing_mapping_found = 0;
1975 if (port_id_is_invalid(port_id, ENABLED_WARN))
1978 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1981 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1982 printf("map_value not in required range 0..%d\n",
1983 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1987 if (!is_rx) { /*then tx*/
1988 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1989 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1990 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1991 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1992 existing_mapping_found = 1;
1996 if (!existing_mapping_found) { /* A new additional mapping... */
1997 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1998 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1999 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
2000 nb_tx_queue_stats_mappings++;
2004 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2005 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2006 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
2007 rx_queue_stats_mappings[i].stats_counter_id = map_value;
2008 existing_mapping_found = 1;
2012 if (!existing_mapping_found) { /* A new additional mapping... */
2013 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
2014 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
2015 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
2016 nb_rx_queue_stats_mappings++;
2022 print_fdir_mask(struct rte_eth_fdir_masks *mask)
2024 printf("\n vlan_tci: 0x%04x, ", mask->vlan_tci_mask);
2026 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2027 printf("mac_addr: 0x%02x", mask->mac_addr_byte_mask);
2028 else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2029 printf("mac_addr: 0x%02x, tunnel_type: 0x%01x, tunnel_id: 0x%08x",
2030 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
2031 mask->tunnel_id_mask);
2033 printf("src_ipv4: 0x%08x, dst_ipv4: 0x%08x,"
2034 " src_port: 0x%04x, dst_port: 0x%04x",
2035 mask->ipv4_mask.src_ip, mask->ipv4_mask.dst_ip,
2036 mask->src_port_mask, mask->dst_port_mask);
2038 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x,"
2039 " dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
2040 mask->ipv6_mask.src_ip[0], mask->ipv6_mask.src_ip[1],
2041 mask->ipv6_mask.src_ip[2], mask->ipv6_mask.src_ip[3],
2042 mask->ipv6_mask.dst_ip[0], mask->ipv6_mask.dst_ip[1],
2043 mask->ipv6_mask.dst_ip[2], mask->ipv6_mask.dst_ip[3]);
2050 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2052 struct rte_eth_flex_payload_cfg *cfg;
2055 for (i = 0; i < flex_conf->nb_payloads; i++) {
2056 cfg = &flex_conf->flex_set[i];
2057 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
2059 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
2060 printf("\n L2_PAYLOAD: ");
2061 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
2062 printf("\n L3_PAYLOAD: ");
2063 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
2064 printf("\n L4_PAYLOAD: ");
2066 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
2067 for (j = 0; j < num; j++)
2068 printf(" %-5u", cfg->src_offset[j]);
2074 flowtype_to_str(uint16_t flow_type)
2076 struct flow_type_info {
2082 static struct flow_type_info flowtype_str_table[] = {
2083 {"raw", RTE_ETH_FLOW_RAW},
2084 {"ipv4", RTE_ETH_FLOW_IPV4},
2085 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2086 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2087 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2088 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2089 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2090 {"ipv6", RTE_ETH_FLOW_IPV6},
2091 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2092 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2093 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2094 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2095 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2096 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2099 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2100 if (flowtype_str_table[i].ftype == flow_type)
2101 return flowtype_str_table[i].str;
2108 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2110 struct rte_eth_fdir_flex_mask *mask;
2114 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2115 mask = &flex_conf->flex_mask[i];
2116 p = flowtype_to_str(mask->flow_type);
2117 printf("\n %s:\t", p ? p : "unknown");
2118 for (j = 0; j < num; j++)
2119 printf(" %02x", mask->mask[j]);
2125 print_fdir_flow_type(uint32_t flow_types_mask)
2130 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2131 if (!(flow_types_mask & (1 << i)))
2133 p = flowtype_to_str(i);
2143 fdir_get_infos(portid_t port_id)
2145 struct rte_eth_fdir_stats fdir_stat;
2146 struct rte_eth_fdir_info fdir_info;
2149 static const char *fdir_stats_border = "########################";
2151 if (port_id_is_invalid(port_id, ENABLED_WARN))
2153 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
2155 printf("\n FDIR is not supported on port %-2d\n",
2160 memset(&fdir_info, 0, sizeof(fdir_info));
2161 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2162 RTE_ETH_FILTER_INFO, &fdir_info);
2163 memset(&fdir_stat, 0, sizeof(fdir_stat));
2164 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2165 RTE_ETH_FILTER_STATS, &fdir_stat);
2166 printf("\n %s FDIR infos for port %-2d %s\n",
2167 fdir_stats_border, port_id, fdir_stats_border);
2169 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
2170 printf(" PERFECT\n");
2171 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2172 printf(" PERFECT-MAC-VLAN\n");
2173 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2174 printf(" PERFECT-TUNNEL\n");
2175 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
2176 printf(" SIGNATURE\n");
2178 printf(" DISABLE\n");
2179 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
2180 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
2181 printf(" SUPPORTED FLOW TYPE: ");
2182 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
2184 printf(" FLEX PAYLOAD INFO:\n");
2185 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
2186 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
2187 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
2188 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
2189 fdir_info.flex_payload_unit,
2190 fdir_info.max_flex_payload_segment_num,
2191 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
2193 print_fdir_mask(&fdir_info.mask);
2194 if (fdir_info.flex_conf.nb_payloads > 0) {
2195 printf(" FLEX PAYLOAD SRC OFFSET:");
2196 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2198 if (fdir_info.flex_conf.nb_flexmasks > 0) {
2199 printf(" FLEX MASK CFG:");
2200 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2202 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2203 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2204 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2205 fdir_info.guarant_spc, fdir_info.best_spc);
2206 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2207 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2208 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2209 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2210 fdir_stat.collision, fdir_stat.free,
2211 fdir_stat.maxhash, fdir_stat.maxlen,
2212 fdir_stat.add, fdir_stat.remove,
2213 fdir_stat.f_add, fdir_stat.f_remove);
2214 printf(" %s############################%s\n",
2215 fdir_stats_border, fdir_stats_border);
2219 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2221 struct rte_port *port;
2222 struct rte_eth_fdir_flex_conf *flex_conf;
2225 port = &ports[port_id];
2226 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2227 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2228 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2233 if (i >= RTE_ETH_FLOW_MAX) {
2234 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2235 idx = flex_conf->nb_flexmasks;
2236 flex_conf->nb_flexmasks++;
2238 printf("The flex mask table is full. Can not set flex"
2239 " mask for flow_type(%u).", cfg->flow_type);
2243 (void)rte_memcpy(&flex_conf->flex_mask[idx],
2245 sizeof(struct rte_eth_fdir_flex_mask));
2249 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2251 struct rte_port *port;
2252 struct rte_eth_fdir_flex_conf *flex_conf;
2255 port = &ports[port_id];
2256 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2257 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2258 if (cfg->type == flex_conf->flex_set[i].type) {
2263 if (i >= RTE_ETH_PAYLOAD_MAX) {
2264 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2265 idx = flex_conf->nb_payloads;
2266 flex_conf->nb_payloads++;
2268 printf("The flex payload table is full. Can not set"
2269 " flex payload for type(%u).", cfg->type);
2273 (void)rte_memcpy(&flex_conf->flex_set[idx],
2275 sizeof(struct rte_eth_flex_payload_cfg));
2280 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
2284 if (port_id_is_invalid(port_id, ENABLED_WARN))
2287 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
2289 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
2293 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
2294 "diag=%d\n", port_id, diag);
2296 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
2297 "diag=%d\n", port_id, diag);
2302 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
2306 if (port_id_is_invalid(port_id, ENABLED_WARN))
2308 if (vlan_id_is_invalid(vlan_id))
2310 diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
2313 printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
2314 "diag=%d\n", port_id, diag);
2318 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
2321 struct rte_eth_link link;
2323 if (port_id_is_invalid(port_id, ENABLED_WARN))
2325 rte_eth_link_get_nowait(port_id, &link);
2326 if (rate > link.link_speed) {
2327 printf("Invalid rate value:%u bigger than link speed: %u\n",
2328 rate, link.link_speed);
2331 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
2334 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
2340 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
2343 struct rte_eth_link link;
2348 if (port_id_is_invalid(port_id, ENABLED_WARN))
2350 rte_eth_link_get_nowait(port_id, &link);
2351 if (rate > link.link_speed) {
2352 printf("Invalid rate value:%u bigger than link speed: %u\n",
2353 rate, link.link_speed);
2356 diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
2359 printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",
2365 * Functions to manage the set of filtered Multicast MAC addresses.
2367 * A pool of filtered multicast MAC addresses is associated with each port.
2368 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
2369 * The address of the pool and the number of valid multicast MAC addresses
2370 * recorded in the pool are stored in the fields "mc_addr_pool" and
2371 * "mc_addr_nb" of the "rte_port" data structure.
2373 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
2374 * to be supplied a contiguous array of multicast MAC addresses.
2375 * To comply with this constraint, the set of multicast addresses recorded
2376 * into the pool are systematically compacted at the beginning of the pool.
2377 * Hence, when a multicast address is removed from the pool, all following
2378 * addresses, if any, are copied back to keep the set contiguous.
2380 #define MCAST_POOL_INC 32
2383 mcast_addr_pool_extend(struct rte_port *port)
2385 struct ether_addr *mc_pool;
2386 size_t mc_pool_size;
2389 * If a free entry is available at the end of the pool, just
2390 * increment the number of recorded multicast addresses.
2392 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
2398 * [re]allocate a pool with MCAST_POOL_INC more entries.
2399 * The previous test guarantees that port->mc_addr_nb is a multiple
2400 * of MCAST_POOL_INC.
2402 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
2404 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
2406 if (mc_pool == NULL) {
2407 printf("allocation of pool of %u multicast addresses failed\n",
2408 port->mc_addr_nb + MCAST_POOL_INC);
2412 port->mc_addr_pool = mc_pool;
2419 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
2422 if (addr_idx == port->mc_addr_nb) {
2423 /* No need to recompact the set of multicast addressses. */
2424 if (port->mc_addr_nb == 0) {
2425 /* free the pool of multicast addresses. */
2426 free(port->mc_addr_pool);
2427 port->mc_addr_pool = NULL;
2431 memmove(&port->mc_addr_pool[addr_idx],
2432 &port->mc_addr_pool[addr_idx + 1],
2433 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
2437 eth_port_multicast_addr_list_set(uint8_t port_id)
2439 struct rte_port *port;
2442 port = &ports[port_id];
2443 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
2447 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
2448 port->mc_addr_nb, port_id, -diag);
2452 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
2454 struct rte_port *port;
2457 if (port_id_is_invalid(port_id, ENABLED_WARN))
2460 port = &ports[port_id];
2463 * Check that the added multicast MAC address is not already recorded
2464 * in the pool of multicast addresses.
2466 for (i = 0; i < port->mc_addr_nb; i++) {
2467 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
2468 printf("multicast address already filtered by port\n");
2473 if (mcast_addr_pool_extend(port) != 0)
2475 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
2476 eth_port_multicast_addr_list_set(port_id);
2480 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
2482 struct rte_port *port;
2485 if (port_id_is_invalid(port_id, ENABLED_WARN))
2488 port = &ports[port_id];
2491 * Search the pool of multicast MAC addresses for the removed address.
2493 for (i = 0; i < port->mc_addr_nb; i++) {
2494 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
2497 if (i == port->mc_addr_nb) {
2498 printf("multicast address not filtered by port %d\n", port_id);
2502 mcast_addr_pool_remove(port, i);
2503 eth_port_multicast_addr_list_set(port_id);
2507 port_dcb_info_display(uint8_t port_id)
2509 struct rte_eth_dcb_info dcb_info;
2512 static const char *border = "================";
2514 if (port_id_is_invalid(port_id, ENABLED_WARN))
2517 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
2519 printf("\n Failed to get dcb infos on port %-2d\n",
2523 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
2524 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
2526 for (i = 0; i < dcb_info.nb_tcs; i++)
2528 printf("\n Priority : ");
2529 for (i = 0; i < dcb_info.nb_tcs; i++)
2530 printf("\t%4d", dcb_info.prio_tc[i]);
2531 printf("\n BW percent :");
2532 for (i = 0; i < dcb_info.nb_tcs; i++)
2533 printf("\t%4d%%", dcb_info.tc_bws[i]);
2534 printf("\n RXQ base : ");
2535 for (i = 0; i < dcb_info.nb_tcs; i++)
2536 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
2537 printf("\n RXQ number :");
2538 for (i = 0; i < dcb_info.nb_tcs; i++)
2539 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
2540 printf("\n TXQ base : ");
2541 for (i = 0; i < dcb_info.nb_tcs; i++)
2542 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
2543 printf("\n TXQ number :");
2544 for (i = 0; i < dcb_info.nb_tcs; i++)
2545 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);