4 * Copyright(c) 2010-2014 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>
82 #include <rte_tailq.h>
84 #include <rte_per_lcore.h>
85 #include <rte_lcore.h>
86 #include <rte_atomic.h>
87 #include <rte_branch_prediction.h>
89 #include <rte_mempool.h>
91 #include <rte_interrupts.h>
93 #include <rte_ether.h>
94 #include <rte_ethdev.h>
95 #include <rte_string_fns.h>
99 static char *flowtype_to_str(uint16_t flow_type);
102 print_ethaddr(const char *name, struct ether_addr *eth_addr)
104 char buf[ETHER_ADDR_FMT_SIZE];
105 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
106 printf("%s%s", name, buf);
110 nic_stats_display(portid_t port_id)
112 struct rte_eth_stats stats;
113 struct rte_port *port = &ports[port_id];
117 static const char *nic_stats_border = "########################";
119 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
120 printf("Valid port range is [0");
121 FOREACH_PORT(pid, ports)
126 rte_eth_stats_get(port_id, &stats);
127 printf("\n %s NIC statistics for port %-2d %s\n",
128 nic_stats_border, port_id, nic_stats_border);
130 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
131 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
133 stats.ipackets, stats.imissed, stats.ibytes);
134 printf(" RX-badcrc: %-10"PRIu64" RX-badlen: %-10"PRIu64" RX-errors: "
136 stats.ibadcrc, stats.ibadlen, stats.ierrors);
137 printf(" RX-nombuf: %-10"PRIu64"\n",
139 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
141 stats.opackets, stats.oerrors, stats.obytes);
144 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
145 " RX-bytes: %10"PRIu64"\n",
146 stats.ipackets, stats.ierrors, stats.ibytes);
147 printf(" RX-badcrc: %10"PRIu64" RX-badlen: %10"PRIu64
148 " RX-errors: %10"PRIu64"\n",
149 stats.ibadcrc, stats.ibadlen, stats.ierrors);
150 printf(" RX-nombuf: %10"PRIu64"\n",
152 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
153 " TX-bytes: %10"PRIu64"\n",
154 stats.opackets, stats.oerrors, stats.obytes);
158 if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
159 printf(" Fdirmiss: %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
163 if (port->rx_queue_stats_mapping_enabled) {
165 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
166 printf(" Stats reg %2d RX-packets: %10"PRIu64
167 " RX-errors: %10"PRIu64
168 " RX-bytes: %10"PRIu64"\n",
169 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
172 if (port->tx_queue_stats_mapping_enabled) {
174 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
175 printf(" Stats reg %2d TX-packets: %10"PRIu64
176 " TX-bytes: %10"PRIu64"\n",
177 i, stats.q_opackets[i], stats.q_obytes[i]);
181 /* Display statistics of XON/XOFF pause frames, if any. */
182 if ((stats.tx_pause_xon | stats.rx_pause_xon |
183 stats.tx_pause_xoff | stats.rx_pause_xoff) > 0) {
184 printf(" RX-XOFF: %-10"PRIu64" RX-XON: %-10"PRIu64"\n",
185 stats.rx_pause_xoff, stats.rx_pause_xon);
186 printf(" TX-XOFF: %-10"PRIu64" TX-XON: %-10"PRIu64"\n",
187 stats.tx_pause_xoff, stats.tx_pause_xon);
189 printf(" %s############################%s\n",
190 nic_stats_border, nic_stats_border);
194 nic_stats_clear(portid_t port_id)
198 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
199 printf("Valid port range is [0");
200 FOREACH_PORT(pid, ports)
205 rte_eth_stats_reset(port_id);
206 printf("\n NIC statistics for port %d cleared\n", port_id);
210 nic_xstats_display(portid_t port_id)
212 struct rte_eth_xstats *xstats;
215 printf("###### NIC extended statistics for port %-2d\n", port_id);
217 len = rte_eth_xstats_get(port_id, NULL, 0);
219 printf("Cannot get xstats count\n");
222 xstats = malloc(sizeof(xstats[0]) * len);
223 if (xstats == NULL) {
224 printf("Cannot allocate memory for xstats\n");
227 ret = rte_eth_xstats_get(port_id, xstats, len);
228 if (ret < 0 || ret > len) {
229 printf("Cannot get xstats\n");
233 for (i = 0; i < len; i++)
234 printf("%s: %"PRIu64"\n", xstats[i].name, xstats[i].value);
239 nic_xstats_clear(portid_t port_id)
241 rte_eth_xstats_reset(port_id);
245 nic_stats_mapping_display(portid_t port_id)
247 struct rte_port *port = &ports[port_id];
251 static const char *nic_stats_mapping_border = "########################";
253 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
254 printf("Valid port range is [0");
255 FOREACH_PORT(pid, ports)
261 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
262 printf("Port id %d - either does not support queue statistic mapping or"
263 " no queue statistic mapping set\n", port_id);
267 printf("\n %s NIC statistics mapping for port %-2d %s\n",
268 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
270 if (port->rx_queue_stats_mapping_enabled) {
271 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
272 if (rx_queue_stats_mappings[i].port_id == port_id) {
273 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
274 rx_queue_stats_mappings[i].queue_id,
275 rx_queue_stats_mappings[i].stats_counter_id);
282 if (port->tx_queue_stats_mapping_enabled) {
283 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
284 if (tx_queue_stats_mappings[i].port_id == port_id) {
285 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
286 tx_queue_stats_mappings[i].queue_id,
287 tx_queue_stats_mappings[i].stats_counter_id);
292 printf(" %s####################################%s\n",
293 nic_stats_mapping_border, nic_stats_mapping_border);
297 port_infos_display(portid_t port_id)
299 struct rte_port *port;
300 struct ether_addr mac_addr;
301 struct rte_eth_link link;
302 struct rte_eth_dev_info dev_info;
304 struct rte_mempool * mp;
305 static const char *info_border = "*********************";
308 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
309 printf("Valid port range is [0");
310 FOREACH_PORT(pid, ports)
315 port = &ports[port_id];
316 rte_eth_link_get_nowait(port_id, &link);
317 printf("\n%s Infos for port %-2d %s\n",
318 info_border, port_id, info_border);
319 rte_eth_macaddr_get(port_id, &mac_addr);
320 print_ethaddr("MAC address: ", &mac_addr);
321 printf("\nConnect to socket: %u", port->socket_id);
323 if (port_numa[port_id] != NUMA_NO_CONFIG) {
324 mp = mbuf_pool_find(port_numa[port_id]);
326 printf("\nmemory allocation on the socket: %d",
329 printf("\nmemory allocation on the socket: %u",port->socket_id);
331 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
332 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
333 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
334 ("full-duplex") : ("half-duplex"));
335 printf("Promiscuous mode: %s\n",
336 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
337 printf("Allmulticast mode: %s\n",
338 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
339 printf("Maximum number of MAC addresses: %u\n",
340 (unsigned int)(port->dev_info.max_mac_addrs));
341 printf("Maximum number of MAC addresses of hash filtering: %u\n",
342 (unsigned int)(port->dev_info.max_hash_mac_addrs));
344 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
345 if (vlan_offload >= 0){
346 printf("VLAN offload: \n");
347 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
348 printf(" strip on \n");
350 printf(" strip off \n");
352 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
353 printf(" filter on \n");
355 printf(" filter off \n");
357 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
358 printf(" qinq(extend) on \n");
360 printf(" qinq(extend) off \n");
363 memset(&dev_info, 0, sizeof(dev_info));
364 rte_eth_dev_info_get(port_id, &dev_info);
365 if (dev_info.reta_size > 0)
366 printf("Redirection table size: %u\n", dev_info.reta_size);
367 if (!dev_info.flow_type_rss_offloads)
368 printf("No flow type is supported.\n");
373 printf("Supported flow types:\n");
374 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
376 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
378 p = flowtype_to_str(i);
379 printf(" %s\n", (p ? p : "unknown"));
385 port_id_is_invalid(portid_t port_id, enum print_warning warning)
387 if (port_id == (portid_t)RTE_PORT_ALL)
390 if (ports[port_id].enabled)
393 if (warning == ENABLED_WARN)
394 printf("Invalid port %d\n", port_id);
400 vlan_id_is_invalid(uint16_t vlan_id)
404 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
409 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
414 printf("Port register offset 0x%X not aligned on a 4-byte "
419 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
420 if (reg_off >= pci_len) {
421 printf("Port %d: register offset %u (0x%X) out of port PCI "
422 "resource (length=%"PRIu64")\n",
423 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
430 reg_bit_pos_is_invalid(uint8_t bit_pos)
434 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
438 #define display_port_and_reg_off(port_id, reg_off) \
439 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
442 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
444 display_port_and_reg_off(port_id, (unsigned)reg_off);
445 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
449 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
454 if (port_id_is_invalid(port_id, ENABLED_WARN))
456 if (port_reg_off_is_invalid(port_id, reg_off))
458 if (reg_bit_pos_is_invalid(bit_x))
460 reg_v = port_id_pci_reg_read(port_id, reg_off);
461 display_port_and_reg_off(port_id, (unsigned)reg_off);
462 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
466 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
467 uint8_t bit1_pos, uint8_t bit2_pos)
473 if (port_id_is_invalid(port_id, ENABLED_WARN))
475 if (port_reg_off_is_invalid(port_id, reg_off))
477 if (reg_bit_pos_is_invalid(bit1_pos))
479 if (reg_bit_pos_is_invalid(bit2_pos))
481 if (bit1_pos > bit2_pos)
482 l_bit = bit2_pos, h_bit = bit1_pos;
484 l_bit = bit1_pos, h_bit = bit2_pos;
486 reg_v = port_id_pci_reg_read(port_id, reg_off);
489 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
490 display_port_and_reg_off(port_id, (unsigned)reg_off);
491 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
492 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
496 port_reg_display(portid_t port_id, uint32_t reg_off)
500 if (port_id_is_invalid(port_id, ENABLED_WARN))
502 if (port_reg_off_is_invalid(port_id, reg_off))
504 reg_v = port_id_pci_reg_read(port_id, reg_off);
505 display_port_reg_value(port_id, reg_off, reg_v);
509 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
514 if (port_id_is_invalid(port_id, ENABLED_WARN))
516 if (port_reg_off_is_invalid(port_id, reg_off))
518 if (reg_bit_pos_is_invalid(bit_pos))
521 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
524 reg_v = port_id_pci_reg_read(port_id, reg_off);
526 reg_v &= ~(1 << bit_pos);
528 reg_v |= (1 << bit_pos);
529 port_id_pci_reg_write(port_id, reg_off, reg_v);
530 display_port_reg_value(port_id, reg_off, reg_v);
534 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
535 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
542 if (port_id_is_invalid(port_id, ENABLED_WARN))
544 if (port_reg_off_is_invalid(port_id, reg_off))
546 if (reg_bit_pos_is_invalid(bit1_pos))
548 if (reg_bit_pos_is_invalid(bit2_pos))
550 if (bit1_pos > bit2_pos)
551 l_bit = bit2_pos, h_bit = bit1_pos;
553 l_bit = bit1_pos, h_bit = bit2_pos;
555 if ((h_bit - l_bit) < 31)
556 max_v = (1 << (h_bit - l_bit + 1)) - 1;
561 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
562 (unsigned)value, (unsigned)value,
563 (unsigned)max_v, (unsigned)max_v);
566 reg_v = port_id_pci_reg_read(port_id, reg_off);
567 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
568 reg_v |= (value << l_bit); /* Set changed bits */
569 port_id_pci_reg_write(port_id, reg_off, reg_v);
570 display_port_reg_value(port_id, reg_off, reg_v);
574 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
576 if (port_id_is_invalid(port_id, ENABLED_WARN))
578 if (port_reg_off_is_invalid(port_id, reg_off))
580 port_id_pci_reg_write(port_id, reg_off, reg_v);
581 display_port_reg_value(port_id, reg_off, reg_v);
585 port_mtu_set(portid_t port_id, uint16_t mtu)
589 if (port_id_is_invalid(port_id, ENABLED_WARN))
591 diag = rte_eth_dev_set_mtu(port_id, mtu);
594 printf("Set MTU failed. diag=%d\n", diag);
598 * RX/TX ring descriptors display functions.
601 rx_queue_id_is_invalid(queueid_t rxq_id)
605 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
610 tx_queue_id_is_invalid(queueid_t txq_id)
614 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
619 rx_desc_id_is_invalid(uint16_t rxdesc_id)
621 if (rxdesc_id < nb_rxd)
623 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
629 tx_desc_id_is_invalid(uint16_t txdesc_id)
631 if (txdesc_id < nb_txd)
633 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
638 static const struct rte_memzone *
639 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
641 char mz_name[RTE_MEMZONE_NAMESIZE];
642 const struct rte_memzone *mz;
644 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
645 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
646 mz = rte_memzone_lookup(mz_name);
648 printf("%s ring memory zoneof (port %d, queue %d) not"
649 "found (zone name = %s\n",
650 ring_name, port_id, q_id, mz_name);
654 union igb_ring_dword {
657 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
667 struct igb_ring_desc_32_bytes {
668 union igb_ring_dword lo_dword;
669 union igb_ring_dword hi_dword;
670 union igb_ring_dword resv1;
671 union igb_ring_dword resv2;
674 struct igb_ring_desc_16_bytes {
675 union igb_ring_dword lo_dword;
676 union igb_ring_dword hi_dword;
680 ring_rxd_display_dword(union igb_ring_dword dword)
682 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
683 (unsigned)dword.words.hi);
687 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
688 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
691 __rte_unused uint8_t port_id,
695 struct igb_ring_desc_16_bytes *ring =
696 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
697 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
698 struct rte_eth_dev_info dev_info;
700 memset(&dev_info, 0, sizeof(dev_info));
701 rte_eth_dev_info_get(port_id, &dev_info);
702 if (strstr(dev_info.driver_name, "i40e") != NULL) {
703 /* 32 bytes RX descriptor, i40e only */
704 struct igb_ring_desc_32_bytes *ring =
705 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
706 ring[desc_id].lo_dword.dword =
707 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
708 ring_rxd_display_dword(ring[desc_id].lo_dword);
709 ring[desc_id].hi_dword.dword =
710 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
711 ring_rxd_display_dword(ring[desc_id].hi_dword);
712 ring[desc_id].resv1.dword =
713 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
714 ring_rxd_display_dword(ring[desc_id].resv1);
715 ring[desc_id].resv2.dword =
716 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
717 ring_rxd_display_dword(ring[desc_id].resv2);
722 /* 16 bytes RX descriptor */
723 ring[desc_id].lo_dword.dword =
724 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
725 ring_rxd_display_dword(ring[desc_id].lo_dword);
726 ring[desc_id].hi_dword.dword =
727 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
728 ring_rxd_display_dword(ring[desc_id].hi_dword);
732 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
734 struct igb_ring_desc_16_bytes *ring;
735 struct igb_ring_desc_16_bytes txd;
737 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
738 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
739 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
740 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
741 (unsigned)txd.lo_dword.words.lo,
742 (unsigned)txd.lo_dword.words.hi,
743 (unsigned)txd.hi_dword.words.lo,
744 (unsigned)txd.hi_dword.words.hi);
748 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
750 const struct rte_memzone *rx_mz;
752 if (port_id_is_invalid(port_id, ENABLED_WARN))
754 if (rx_queue_id_is_invalid(rxq_id))
756 if (rx_desc_id_is_invalid(rxd_id))
758 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
761 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
765 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
767 const struct rte_memzone *tx_mz;
769 if (port_id_is_invalid(port_id, ENABLED_WARN))
771 if (tx_queue_id_is_invalid(txq_id))
773 if (tx_desc_id_is_invalid(txd_id))
775 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
778 ring_tx_descriptor_display(tx_mz, txd_id);
782 fwd_lcores_config_display(void)
786 printf("List of forwarding lcores:");
787 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
788 printf(" %2u", fwd_lcores_cpuids[lc_id]);
792 rxtx_config_display(void)
794 printf(" %s packet forwarding - CRC stripping %s - "
795 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
796 rx_mode.hw_strip_crc ? "enabled" : "disabled",
799 if (cur_fwd_eng == &tx_only_engine)
800 printf(" packet len=%u - nb packet segments=%d\n",
801 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
803 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
804 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
806 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
807 nb_fwd_lcores, nb_fwd_ports);
808 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
809 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
810 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
811 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
812 rx_conf->rx_thresh.wthresh);
813 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
814 nb_txq, nb_txd, tx_conf->tx_free_thresh);
815 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
816 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
817 tx_conf->tx_thresh.wthresh);
818 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
819 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
823 port_rss_reta_info(portid_t port_id,
824 struct rte_eth_rss_reta_entry64 *reta_conf,
827 uint16_t i, idx, shift;
830 if (port_id_is_invalid(port_id, ENABLED_WARN))
833 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
835 printf("Failed to get RSS RETA info, return code = %d\n", ret);
839 for (i = 0; i < nb_entries; i++) {
840 idx = i / RTE_RETA_GROUP_SIZE;
841 shift = i % RTE_RETA_GROUP_SIZE;
842 if (!(reta_conf[idx].mask & (1ULL << shift)))
844 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
845 i, reta_conf[idx].reta[shift]);
850 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
854 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
856 struct rss_type_info {
860 static const struct rss_type_info rss_type_table[] = {
861 {"ipv4", ETH_RSS_IPV4},
862 {"ipv4-frag", ETH_RSS_FRAG_IPV4},
863 {"ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP},
864 {"ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP},
865 {"ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP},
866 {"ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER},
867 {"ipv6", ETH_RSS_IPV6},
868 {"ipv6-frag", ETH_RSS_FRAG_IPV6},
869 {"ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP},
870 {"ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP},
871 {"ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP},
872 {"ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER},
873 {"l2-payload", ETH_RSS_L2_PAYLOAD},
874 {"ipv6-ex", ETH_RSS_IPV6_EX},
875 {"ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX},
876 {"ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX},
879 struct rte_eth_rss_conf rss_conf;
880 uint8_t rss_key[10 * 4];
885 if (port_id_is_invalid(port_id, ENABLED_WARN))
887 /* Get RSS hash key if asked to display it */
888 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
889 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
893 printf("port index %d invalid\n", port_id);
896 printf("operation not supported by device\n");
899 printf("operation failed - diag=%d\n", diag);
904 rss_hf = rss_conf.rss_hf;
906 printf("RSS disabled\n");
909 printf("RSS functions:\n ");
910 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
911 if (rss_hf & rss_type_table[i].rss_type)
912 printf("%s ", rss_type_table[i].str);
917 printf("RSS key:\n");
918 for (i = 0; i < sizeof(rss_key); i++)
919 printf("%02X", rss_key[i]);
924 port_rss_hash_key_update(portid_t port_id, uint8_t *hash_key)
926 struct rte_eth_rss_conf rss_conf;
929 rss_conf.rss_key = NULL;
930 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
932 rss_conf.rss_key = hash_key;
933 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
940 printf("port index %d invalid\n", port_id);
943 printf("operation not supported by device\n");
946 printf("operation failed - diag=%d\n", diag);
952 * Setup forwarding configuration for each logical core.
955 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
957 streamid_t nb_fs_per_lcore;
965 nb_fs = cfg->nb_fwd_streams;
966 nb_fc = cfg->nb_fwd_lcores;
967 if (nb_fs <= nb_fc) {
971 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
972 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
975 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
977 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
978 fwd_lcores[lc_id]->stream_idx = sm_id;
979 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
980 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
984 * Assign extra remaining streams, if any.
986 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
987 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
988 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
989 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
990 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
995 simple_fwd_config_setup(void)
1001 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1002 port_topology == PORT_TOPOLOGY_LOOP) {
1004 } else if (nb_fwd_ports % 2) {
1005 printf("\nWarning! Cannot handle an odd number of ports "
1006 "with the current port topology. Configuration "
1007 "must be changed to have an even number of ports, "
1008 "or relaunch application with "
1009 "--port-topology=chained\n\n");
1012 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1013 cur_fwd_config.nb_fwd_streams =
1014 (streamid_t) cur_fwd_config.nb_fwd_ports;
1016 /* reinitialize forwarding streams */
1020 * In the simple forwarding test, the number of forwarding cores
1021 * must be lower or equal to the number of forwarding ports.
1023 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1024 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1025 cur_fwd_config.nb_fwd_lcores =
1026 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1027 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1029 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1030 if (port_topology != PORT_TOPOLOGY_LOOP)
1031 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1034 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1035 fwd_streams[i]->rx_queue = 0;
1036 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1037 fwd_streams[i]->tx_queue = 0;
1038 fwd_streams[i]->peer_addr = j;
1040 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1041 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1042 fwd_streams[j]->rx_queue = 0;
1043 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1044 fwd_streams[j]->tx_queue = 0;
1045 fwd_streams[j]->peer_addr = i;
1051 * For the RSS forwarding test, each core is assigned on every port a transmit
1052 * queue whose index is the index of the core itself. This approach limits the
1053 * maximumm number of processing cores of the RSS test to the maximum number of
1054 * TX queues supported by the devices.
1056 * Each core is assigned a single stream, each stream being composed of
1057 * a RX queue to poll on a RX port for input messages, associated with
1058 * a TX queue of a TX port where to send forwarded packets.
1059 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1060 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1062 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1066 rss_fwd_config_setup(void)
1077 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1078 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1079 cur_fwd_config.nb_fwd_streams =
1080 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1081 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
1082 cur_fwd_config.nb_fwd_streams =
1083 (streamid_t)cur_fwd_config.nb_fwd_lcores;
1085 cur_fwd_config.nb_fwd_lcores =
1086 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1088 /* reinitialize forwarding streams */
1091 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1093 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1094 struct fwd_stream *fs;
1096 fs = fwd_streams[lc_id];
1098 if ((rxp & 0x1) == 0)
1099 txp = (portid_t) (rxp + 1);
1101 txp = (portid_t) (rxp - 1);
1103 * if we are in loopback, simply send stuff out through the
1106 if (port_topology == PORT_TOPOLOGY_LOOP)
1109 fs->rx_port = fwd_ports_ids[rxp];
1111 fs->tx_port = fwd_ports_ids[txp];
1113 fs->peer_addr = fs->tx_port;
1114 rxq = (queueid_t) (rxq + 1);
1119 * Restart from RX queue 0 on next RX port
1122 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1124 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1126 rxp = (portid_t) (rxp + 1);
1131 * In DCB and VT on,the mapping of 128 receive queues to 128 transmit queues.
1134 dcb_rxq_2_txq_mapping(queueid_t rxq, queueid_t *txq)
1136 if(dcb_q_mapping == DCB_4_TCS_Q_MAPPING) {
1141 else if (rxq < 64) {
1143 *txq = (uint16_t)(rxq + 32);
1146 /* tc2: 96-111;tc3:112-127 */
1147 *txq = (uint16_t)(rxq/2 + 64);
1154 else if (rxq < 32) {
1156 *txq = (uint16_t)(rxq + 16);
1158 else if (rxq < 64) {
1159 /*tc2,tc3 mapping */
1160 *txq = (uint16_t)(rxq + 32);
1163 /* tc4,tc5,tc6 and tc7 mapping */
1164 *txq = (uint16_t)(rxq/2 + 64);
1170 * For the DCB forwarding test, each core is assigned on every port multi-transmit
1173 * Each core is assigned a multi-stream, each stream being composed of
1174 * a RX queue to poll on a RX port for input messages, associated with
1175 * a TX queue of a TX port where to send forwarded packets.
1176 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1177 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1180 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1183 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1184 * There is a mapping of RxQj to TxQl to be required,and the mapping was implemented
1185 * in dcb_rxq_2_txq_mapping function.
1188 dcb_fwd_config_setup(void)
1199 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1200 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1201 cur_fwd_config.nb_fwd_streams =
1202 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1204 /* reinitialize forwarding streams */
1207 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1209 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1210 /* a fwd core can run multi-streams */
1211 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++)
1213 struct fwd_stream *fs;
1214 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1215 if ((rxp & 0x1) == 0)
1216 txp = (portid_t) (rxp + 1);
1218 txp = (portid_t) (rxp - 1);
1219 fs->rx_port = fwd_ports_ids[rxp];
1221 fs->tx_port = fwd_ports_ids[txp];
1222 if (dcb_q_mapping == DCB_VT_Q_MAPPING)
1225 dcb_rxq_2_txq_mapping(rxq, &fs->tx_queue);
1226 fs->peer_addr = fs->tx_port;
1227 rxq = (queueid_t) (rxq + 1);
1231 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1233 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1235 rxp = (portid_t) (rxp + 1);
1241 icmp_echo_config_setup(void)
1248 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1249 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1250 (nb_txq * nb_fwd_ports);
1252 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1253 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1254 cur_fwd_config.nb_fwd_streams =
1255 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1256 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1257 cur_fwd_config.nb_fwd_lcores =
1258 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1259 if (verbose_level > 0) {
1260 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1262 cur_fwd_config.nb_fwd_lcores,
1263 cur_fwd_config.nb_fwd_ports,
1264 cur_fwd_config.nb_fwd_streams);
1267 /* reinitialize forwarding streams */
1269 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1271 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1272 if (verbose_level > 0)
1273 printf(" core=%d: \n", lc_id);
1274 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1275 struct fwd_stream *fs;
1276 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1277 fs->rx_port = fwd_ports_ids[rxp];
1279 fs->tx_port = fs->rx_port;
1280 fs->tx_queue = lc_id;
1281 fs->peer_addr = fs->tx_port;
1282 if (verbose_level > 0)
1283 printf(" stream=%d port=%d rxq=%d txq=%d\n",
1284 sm_id, fs->rx_port, fs->rx_queue,
1286 rxq = (queueid_t) (rxq + 1);
1287 if (rxq == nb_rxq) {
1289 rxp = (portid_t) (rxp + 1);
1296 fwd_config_setup(void)
1298 cur_fwd_config.fwd_eng = cur_fwd_eng;
1299 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1300 icmp_echo_config_setup();
1303 if ((nb_rxq > 1) && (nb_txq > 1)){
1305 dcb_fwd_config_setup();
1307 rss_fwd_config_setup();
1310 simple_fwd_config_setup();
1314 pkt_fwd_config_display(struct fwd_config *cfg)
1316 struct fwd_stream *fs;
1320 printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
1321 "NUMA support %s, MP over anonymous pages %s\n",
1322 cfg->fwd_eng->fwd_mode_name,
1323 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1324 numa_support == 1 ? "enabled" : "disabled",
1325 mp_anon != 0 ? "enabled" : "disabled");
1327 if (strcmp(cfg->fwd_eng->fwd_mode_name, "mac_retry") == 0)
1328 printf("TX retry num: %u, delay between TX retries: %uus\n",
1329 burst_tx_retry_num, burst_tx_delay_time);
1330 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1331 printf("Logical Core %u (socket %u) forwards packets on "
1333 fwd_lcores_cpuids[lc_id],
1334 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1335 fwd_lcores[lc_id]->stream_nb);
1336 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1337 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1338 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
1339 "P=%d/Q=%d (socket %u) ",
1340 fs->rx_port, fs->rx_queue,
1341 ports[fs->rx_port].socket_id,
1342 fs->tx_port, fs->tx_queue,
1343 ports[fs->tx_port].socket_id);
1344 print_ethaddr("peer=",
1345 &peer_eth_addrs[fs->peer_addr]);
1354 fwd_config_display(void)
1356 if((dcb_config) && (nb_fwd_lcores == 1)) {
1357 printf("In DCB mode,the nb forwarding cores should be larger than 1\n");
1361 pkt_fwd_config_display(&cur_fwd_config);
1365 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1368 unsigned int lcore_cpuid;
1373 for (i = 0; i < nb_lc; i++) {
1374 lcore_cpuid = lcorelist[i];
1375 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1376 printf("lcore %u not enabled\n", lcore_cpuid);
1379 if (lcore_cpuid == rte_get_master_lcore()) {
1380 printf("lcore %u cannot be masked on for running "
1381 "packet forwarding, which is the master lcore "
1382 "and reserved for command line parsing only\n",
1387 fwd_lcores_cpuids[i] = lcore_cpuid;
1389 if (record_now == 0) {
1393 nb_cfg_lcores = (lcoreid_t) nb_lc;
1394 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1395 printf("previous number of forwarding cores %u - changed to "
1396 "number of configured cores %u\n",
1397 (unsigned int) nb_fwd_lcores, nb_lc);
1398 nb_fwd_lcores = (lcoreid_t) nb_lc;
1405 set_fwd_lcores_mask(uint64_t lcoremask)
1407 unsigned int lcorelist[64];
1411 if (lcoremask == 0) {
1412 printf("Invalid NULL mask of cores\n");
1416 for (i = 0; i < 64; i++) {
1417 if (! ((uint64_t)(1ULL << i) & lcoremask))
1419 lcorelist[nb_lc++] = i;
1421 return set_fwd_lcores_list(lcorelist, nb_lc);
1425 set_fwd_lcores_number(uint16_t nb_lc)
1427 if (nb_lc > nb_cfg_lcores) {
1428 printf("nb fwd cores %u > %u (max. number of configured "
1429 "lcores) - ignored\n",
1430 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1433 nb_fwd_lcores = (lcoreid_t) nb_lc;
1434 printf("Number of forwarding cores set to %u\n",
1435 (unsigned int) nb_fwd_lcores);
1439 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1447 for (i = 0; i < nb_pt; i++) {
1448 port_id = (portid_t) portlist[i];
1449 if (port_id_is_invalid(port_id, ENABLED_WARN))
1452 fwd_ports_ids[i] = port_id;
1454 if (record_now == 0) {
1458 nb_cfg_ports = (portid_t) nb_pt;
1459 if (nb_fwd_ports != (portid_t) nb_pt) {
1460 printf("previous number of forwarding ports %u - changed to "
1461 "number of configured ports %u\n",
1462 (unsigned int) nb_fwd_ports, nb_pt);
1463 nb_fwd_ports = (portid_t) nb_pt;
1468 set_fwd_ports_mask(uint64_t portmask)
1470 unsigned int portlist[64];
1474 if (portmask == 0) {
1475 printf("Invalid NULL mask of ports\n");
1479 for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
1480 if (! ((uint64_t)(1ULL << i) & portmask))
1482 portlist[nb_pt++] = i;
1484 set_fwd_ports_list(portlist, nb_pt);
1488 set_fwd_ports_number(uint16_t nb_pt)
1490 if (nb_pt > nb_cfg_ports) {
1491 printf("nb fwd ports %u > %u (number of configured "
1492 "ports) - ignored\n",
1493 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1496 nb_fwd_ports = (portid_t) nb_pt;
1497 printf("Number of forwarding ports set to %u\n",
1498 (unsigned int) nb_fwd_ports);
1502 set_nb_pkt_per_burst(uint16_t nb)
1504 if (nb > MAX_PKT_BURST) {
1505 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1507 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1510 nb_pkt_per_burst = nb;
1511 printf("Number of packets per burst set to %u\n",
1512 (unsigned int) nb_pkt_per_burst);
1516 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1518 uint16_t tx_pkt_len;
1521 if (nb_segs >= (unsigned) nb_txd) {
1522 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1523 nb_segs, (unsigned int) nb_txd);
1528 * Check that each segment length is greater or equal than
1529 * the mbuf data sise.
1530 * Check also that the total packet length is greater or equal than the
1531 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1534 for (i = 0; i < nb_segs; i++) {
1535 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1536 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1537 i, seg_lengths[i], (unsigned) mbuf_data_size);
1540 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1542 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1543 printf("total packet length=%u < %d - give up\n",
1544 (unsigned) tx_pkt_len,
1545 (int)(sizeof(struct ether_hdr) + 20 + 8));
1549 for (i = 0; i < nb_segs; i++)
1550 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1552 tx_pkt_length = tx_pkt_len;
1553 tx_pkt_nb_segs = (uint8_t) nb_segs;
1557 list_pkt_forwarding_modes(void)
1559 static char fwd_modes[128] = "";
1560 const char *separator = "|";
1561 struct fwd_engine *fwd_eng;
1564 if (strlen (fwd_modes) == 0) {
1565 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1566 strcat(fwd_modes, fwd_eng->fwd_mode_name);
1567 strcat(fwd_modes, separator);
1569 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1576 set_pkt_forwarding_mode(const char *fwd_mode_name)
1578 struct fwd_engine *fwd_eng;
1582 while ((fwd_eng = fwd_engines[i]) != NULL) {
1583 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1584 printf("Set %s packet forwarding mode\n",
1586 cur_fwd_eng = fwd_eng;
1591 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1595 set_verbose_level(uint16_t vb_level)
1597 printf("Change verbose level from %u to %u\n",
1598 (unsigned int) verbose_level, (unsigned int) vb_level);
1599 verbose_level = vb_level;
1603 vlan_extend_set(portid_t port_id, int on)
1608 if (port_id_is_invalid(port_id, ENABLED_WARN))
1611 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1614 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1616 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1618 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1620 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1621 "diag=%d\n", port_id, on, diag);
1625 rx_vlan_strip_set(portid_t port_id, int on)
1630 if (port_id_is_invalid(port_id, ENABLED_WARN))
1633 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1636 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1638 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1640 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1642 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1643 "diag=%d\n", port_id, on, diag);
1647 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1651 if (port_id_is_invalid(port_id, ENABLED_WARN))
1654 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1656 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1657 "diag=%d\n", port_id, queue_id, on, diag);
1661 rx_vlan_filter_set(portid_t port_id, int on)
1666 if (port_id_is_invalid(port_id, ENABLED_WARN))
1669 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1672 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1674 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1676 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1678 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1679 "diag=%d\n", port_id, on, diag);
1683 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1687 if (port_id_is_invalid(port_id, ENABLED_WARN))
1689 if (vlan_id_is_invalid(vlan_id))
1691 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1694 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1696 port_id, vlan_id, on, diag);
1701 rx_vlan_all_filter_set(portid_t port_id, int on)
1705 if (port_id_is_invalid(port_id, ENABLED_WARN))
1707 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
1708 if (rx_vft_set(port_id, vlan_id, on))
1714 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1717 if (port_id_is_invalid(port_id, ENABLED_WARN))
1720 diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1724 printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1726 port_id, tp_id, diag);
1730 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1732 if (port_id_is_invalid(port_id, ENABLED_WARN))
1734 if (vlan_id_is_invalid(vlan_id))
1736 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1737 ports[port_id].tx_vlan_id = vlan_id;
1741 tx_vlan_reset(portid_t port_id)
1743 if (port_id_is_invalid(port_id, ENABLED_WARN))
1745 ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1749 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
1751 if (port_id_is_invalid(port_id, ENABLED_WARN))
1754 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
1758 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1761 uint8_t existing_mapping_found = 0;
1763 if (port_id_is_invalid(port_id, ENABLED_WARN))
1766 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1769 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1770 printf("map_value not in required range 0..%d\n",
1771 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1775 if (!is_rx) { /*then tx*/
1776 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1777 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1778 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1779 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1780 existing_mapping_found = 1;
1784 if (!existing_mapping_found) { /* A new additional mapping... */
1785 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1786 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1787 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1788 nb_tx_queue_stats_mappings++;
1792 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1793 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1794 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1795 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1796 existing_mapping_found = 1;
1800 if (!existing_mapping_found) { /* A new additional mapping... */
1801 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1802 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1803 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1804 nb_rx_queue_stats_mappings++;
1810 print_fdir_mask(struct rte_eth_fdir_masks *mask)
1812 printf("\n vlan_tci: 0x%04x, src_ipv4: 0x%08x, dst_ipv4: 0x%08x,"
1813 " src_port: 0x%04x, dst_port: 0x%04x",
1814 mask->vlan_tci_mask, mask->ipv4_mask.src_ip,
1815 mask->ipv4_mask.dst_ip,
1816 mask->src_port_mask, mask->dst_port_mask);
1818 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x,"
1819 " dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
1820 mask->ipv6_mask.src_ip[0], mask->ipv6_mask.src_ip[1],
1821 mask->ipv6_mask.src_ip[2], mask->ipv6_mask.src_ip[3],
1822 mask->ipv6_mask.dst_ip[0], mask->ipv6_mask.dst_ip[1],
1823 mask->ipv6_mask.dst_ip[2], mask->ipv6_mask.dst_ip[3]);
1828 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
1830 struct rte_eth_flex_payload_cfg *cfg;
1833 for (i = 0; i < flex_conf->nb_payloads; i++) {
1834 cfg = &flex_conf->flex_set[i];
1835 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
1837 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
1838 printf("\n L2_PAYLOAD: ");
1839 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
1840 printf("\n L3_PAYLOAD: ");
1841 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
1842 printf("\n L4_PAYLOAD: ");
1844 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
1845 for (j = 0; j < num; j++)
1846 printf(" %-5u", cfg->src_offset[j]);
1852 flowtype_to_str(uint16_t flow_type)
1854 struct flow_type_info {
1860 static struct flow_type_info flowtype_str_table[] = {
1861 {"raw", RTE_ETH_FLOW_RAW},
1862 {"ipv4", RTE_ETH_FLOW_IPV4},
1863 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
1864 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
1865 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
1866 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
1867 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
1868 {"ipv6", RTE_ETH_FLOW_IPV6},
1869 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
1870 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
1871 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
1872 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
1873 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
1874 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
1877 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
1878 if (flowtype_str_table[i].ftype == flow_type)
1879 return flowtype_str_table[i].str;
1886 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
1888 struct rte_eth_fdir_flex_mask *mask;
1892 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
1893 mask = &flex_conf->flex_mask[i];
1894 p = flowtype_to_str(mask->flow_type);
1895 printf("\n %s:\t", p ? p : "unknown");
1896 for (j = 0; j < num; j++)
1897 printf(" %02x", mask->mask[j]);
1903 print_fdir_flow_type(uint32_t flow_types_mask)
1908 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
1909 if (!(flow_types_mask & (1 << i)))
1911 p = flowtype_to_str(i);
1921 fdir_get_infos(portid_t port_id)
1923 struct rte_eth_fdir_stats fdir_stat;
1924 struct rte_eth_fdir_info fdir_info;
1927 static const char *fdir_stats_border = "########################";
1929 if (port_id_is_invalid(port_id, ENABLED_WARN))
1931 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
1933 printf("\n FDIR is not supported on port %-2d\n",
1938 memset(&fdir_info, 0, sizeof(fdir_info));
1939 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
1940 RTE_ETH_FILTER_INFO, &fdir_info);
1941 memset(&fdir_stat, 0, sizeof(fdir_stat));
1942 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
1943 RTE_ETH_FILTER_STATS, &fdir_stat);
1944 printf("\n %s FDIR infos for port %-2d %s\n",
1945 fdir_stats_border, port_id, fdir_stats_border);
1947 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
1948 printf(" PERFECT\n");
1949 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
1950 printf(" SIGNATURE\n");
1952 printf(" DISABLE\n");
1953 printf(" SUPPORTED FLOW TYPE: ");
1954 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
1955 printf(" FLEX PAYLOAD INFO:\n");
1956 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
1957 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
1958 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
1959 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
1960 fdir_info.flex_payload_unit,
1961 fdir_info.max_flex_payload_segment_num,
1962 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
1964 print_fdir_mask(&fdir_info.mask);
1965 if (fdir_info.flex_conf.nb_payloads > 0) {
1966 printf(" FLEX PAYLOAD SRC OFFSET:");
1967 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
1969 if (fdir_info.flex_conf.nb_flexmasks > 0) {
1970 printf(" FLEX MASK CFG:");
1971 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
1973 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
1974 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
1975 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
1976 fdir_info.guarant_spc, fdir_info.best_spc);
1977 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
1978 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
1979 " add: %-10"PRIu64" remove: %"PRIu64"\n"
1980 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
1981 fdir_stat.collision, fdir_stat.free,
1982 fdir_stat.maxhash, fdir_stat.maxlen,
1983 fdir_stat.add, fdir_stat.remove,
1984 fdir_stat.f_add, fdir_stat.f_remove);
1985 printf(" %s############################%s\n",
1986 fdir_stats_border, fdir_stats_border);
1990 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
1992 struct rte_port *port;
1993 struct rte_eth_fdir_flex_conf *flex_conf;
1996 port = &ports[port_id];
1997 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
1998 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
1999 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2004 if (i >= RTE_ETH_FLOW_MAX) {
2005 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2006 idx = flex_conf->nb_flexmasks;
2007 flex_conf->nb_flexmasks++;
2009 printf("The flex mask table is full. Can not set flex"
2010 " mask for flow_type(%u).", cfg->flow_type);
2014 (void)rte_memcpy(&flex_conf->flex_mask[idx],
2016 sizeof(struct rte_eth_fdir_flex_mask));
2020 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2022 struct rte_port *port;
2023 struct rte_eth_fdir_flex_conf *flex_conf;
2026 port = &ports[port_id];
2027 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2028 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2029 if (cfg->type == flex_conf->flex_set[i].type) {
2034 if (i >= RTE_ETH_PAYLOAD_MAX) {
2035 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2036 idx = flex_conf->nb_payloads;
2037 flex_conf->nb_payloads++;
2039 printf("The flex payload table is full. Can not set"
2040 " flex payload for type(%u).", cfg->type);
2044 (void)rte_memcpy(&flex_conf->flex_set[idx],
2046 sizeof(struct rte_eth_flex_payload_cfg));
2051 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
2055 if (port_id_is_invalid(port_id, ENABLED_WARN))
2058 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
2060 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
2064 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
2065 "diag=%d\n", port_id, diag);
2067 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
2068 "diag=%d\n", port_id, diag);
2073 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
2077 if (port_id_is_invalid(port_id, ENABLED_WARN))
2079 if (vlan_id_is_invalid(vlan_id))
2081 diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
2084 printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
2085 "diag=%d\n", port_id, diag);
2089 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
2092 struct rte_eth_link link;
2094 if (port_id_is_invalid(port_id, ENABLED_WARN))
2096 rte_eth_link_get_nowait(port_id, &link);
2097 if (rate > link.link_speed) {
2098 printf("Invalid rate value:%u bigger than link speed: %u\n",
2099 rate, link.link_speed);
2102 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
2105 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
2111 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
2114 struct rte_eth_link link;
2119 if (port_id_is_invalid(port_id, ENABLED_WARN))
2121 rte_eth_link_get_nowait(port_id, &link);
2122 if (rate > link.link_speed) {
2123 printf("Invalid rate value:%u bigger than link speed: %u\n",
2124 rate, link.link_speed);
2127 diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
2130 printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",