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];
116 static const char *nic_stats_border = "########################";
118 if (port_id >= nb_ports) {
119 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
122 rte_eth_stats_get(port_id, &stats);
123 printf("\n %s NIC statistics for port %-2d %s\n",
124 nic_stats_border, port_id, nic_stats_border);
126 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
127 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
129 stats.ipackets, stats.imissed, stats.ibytes);
130 printf(" RX-badcrc: %-10"PRIu64" RX-badlen: %-10"PRIu64" RX-errors: "
132 stats.ibadcrc, stats.ibadlen, stats.ierrors);
133 printf(" RX-nombuf: %-10"PRIu64"\n",
135 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
137 stats.opackets, stats.oerrors, stats.obytes);
140 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
141 " RX-bytes: %10"PRIu64"\n",
142 stats.ipackets, stats.ierrors, stats.ibytes);
143 printf(" RX-badcrc: %10"PRIu64" RX-badlen: %10"PRIu64
144 " RX-errors: %10"PRIu64"\n",
145 stats.ibadcrc, stats.ibadlen, stats.ierrors);
146 printf(" RX-nombuf: %10"PRIu64"\n",
148 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
149 " TX-bytes: %10"PRIu64"\n",
150 stats.opackets, stats.oerrors, stats.obytes);
154 if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
155 printf(" Fdirmiss: %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
159 if (port->rx_queue_stats_mapping_enabled) {
161 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
162 printf(" Stats reg %2d RX-packets: %10"PRIu64
163 " RX-errors: %10"PRIu64
164 " RX-bytes: %10"PRIu64"\n",
165 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
168 if (port->tx_queue_stats_mapping_enabled) {
170 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
171 printf(" Stats reg %2d TX-packets: %10"PRIu64
172 " TX-bytes: %10"PRIu64"\n",
173 i, stats.q_opackets[i], stats.q_obytes[i]);
177 /* Display statistics of XON/XOFF pause frames, if any. */
178 if ((stats.tx_pause_xon | stats.rx_pause_xon |
179 stats.tx_pause_xoff | stats.rx_pause_xoff) > 0) {
180 printf(" RX-XOFF: %-10"PRIu64" RX-XON: %-10"PRIu64"\n",
181 stats.rx_pause_xoff, stats.rx_pause_xon);
182 printf(" TX-XOFF: %-10"PRIu64" TX-XON: %-10"PRIu64"\n",
183 stats.tx_pause_xoff, stats.tx_pause_xon);
185 printf(" %s############################%s\n",
186 nic_stats_border, nic_stats_border);
190 nic_stats_clear(portid_t port_id)
192 if (port_id >= nb_ports) {
193 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
196 rte_eth_stats_reset(port_id);
197 printf("\n NIC statistics for port %d cleared\n", port_id);
201 nic_xstats_display(portid_t port_id)
203 struct rte_eth_xstats *xstats;
206 printf("###### NIC extended statistics for port %-2d\n", port_id);
208 len = rte_eth_xstats_get(port_id, NULL, 0);
210 printf("Cannot get xstats count\n");
213 xstats = malloc(sizeof(xstats[0]) * len);
214 if (xstats == NULL) {
215 printf("Cannot allocate memory for xstats\n");
218 ret = rte_eth_xstats_get(port_id, xstats, len);
219 if (ret < 0 || ret > len) {
220 printf("Cannot get xstats\n");
224 for (i = 0; i < len; i++)
225 printf("%s: %"PRIu64"\n", xstats[i].name, xstats[i].value);
230 nic_xstats_clear(portid_t port_id)
232 rte_eth_xstats_reset(port_id);
236 nic_stats_mapping_display(portid_t port_id)
238 struct rte_port *port = &ports[port_id];
241 static const char *nic_stats_mapping_border = "########################";
243 if (port_id >= nb_ports) {
244 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
248 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
249 printf("Port id %d - either does not support queue statistic mapping or"
250 " no queue statistic mapping set\n", port_id);
254 printf("\n %s NIC statistics mapping for port %-2d %s\n",
255 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
257 if (port->rx_queue_stats_mapping_enabled) {
258 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
259 if (rx_queue_stats_mappings[i].port_id == port_id) {
260 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
261 rx_queue_stats_mappings[i].queue_id,
262 rx_queue_stats_mappings[i].stats_counter_id);
269 if (port->tx_queue_stats_mapping_enabled) {
270 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
271 if (tx_queue_stats_mappings[i].port_id == port_id) {
272 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
273 tx_queue_stats_mappings[i].queue_id,
274 tx_queue_stats_mappings[i].stats_counter_id);
279 printf(" %s####################################%s\n",
280 nic_stats_mapping_border, nic_stats_mapping_border);
284 port_infos_display(portid_t port_id)
286 struct rte_port *port;
287 struct ether_addr mac_addr;
288 struct rte_eth_link link;
289 struct rte_eth_dev_info dev_info;
291 struct rte_mempool * mp;
292 static const char *info_border = "*********************";
294 if (port_id >= nb_ports) {
295 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
298 port = &ports[port_id];
299 rte_eth_link_get_nowait(port_id, &link);
300 printf("\n%s Infos for port %-2d %s\n",
301 info_border, port_id, info_border);
302 rte_eth_macaddr_get(port_id, &mac_addr);
303 print_ethaddr("MAC address: ", &mac_addr);
304 printf("\nConnect to socket: %u", port->socket_id);
306 if (port_numa[port_id] != NUMA_NO_CONFIG) {
307 mp = mbuf_pool_find(port_numa[port_id]);
309 printf("\nmemory allocation on the socket: %d",
312 printf("\nmemory allocation on the socket: %u",port->socket_id);
314 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
315 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
316 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
317 ("full-duplex") : ("half-duplex"));
318 printf("Promiscuous mode: %s\n",
319 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
320 printf("Allmulticast mode: %s\n",
321 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
322 printf("Maximum number of MAC addresses: %u\n",
323 (unsigned int)(port->dev_info.max_mac_addrs));
324 printf("Maximum number of MAC addresses of hash filtering: %u\n",
325 (unsigned int)(port->dev_info.max_hash_mac_addrs));
327 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
328 if (vlan_offload >= 0){
329 printf("VLAN offload: \n");
330 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
331 printf(" strip on \n");
333 printf(" strip off \n");
335 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
336 printf(" filter on \n");
338 printf(" filter off \n");
340 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
341 printf(" qinq(extend) on \n");
343 printf(" qinq(extend) off \n");
346 memset(&dev_info, 0, sizeof(dev_info));
347 rte_eth_dev_info_get(port_id, &dev_info);
348 if (dev_info.reta_size > 0)
349 printf("Redirection table size: %u\n", dev_info.reta_size);
350 if (!dev_info.flow_type_rss_offloads)
351 printf("No flow type is supported.\n");
356 printf("Supported flow types:\n");
357 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
359 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
361 p = flowtype_to_str(i);
362 printf(" %s\n", (p ? p : "unknown"));
368 port_id_is_invalid(portid_t port_id)
370 if (port_id < nb_ports)
372 printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
377 vlan_id_is_invalid(uint16_t vlan_id)
381 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
386 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
391 printf("Port register offset 0x%X not aligned on a 4-byte "
396 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
397 if (reg_off >= pci_len) {
398 printf("Port %d: register offset %u (0x%X) out of port PCI "
399 "resource (length=%"PRIu64")\n",
400 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
407 reg_bit_pos_is_invalid(uint8_t bit_pos)
411 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
415 #define display_port_and_reg_off(port_id, reg_off) \
416 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
419 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
421 display_port_and_reg_off(port_id, (unsigned)reg_off);
422 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
426 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
431 if (port_id_is_invalid(port_id))
433 if (port_reg_off_is_invalid(port_id, reg_off))
435 if (reg_bit_pos_is_invalid(bit_x))
437 reg_v = port_id_pci_reg_read(port_id, reg_off);
438 display_port_and_reg_off(port_id, (unsigned)reg_off);
439 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
443 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
444 uint8_t bit1_pos, uint8_t bit2_pos)
450 if (port_id_is_invalid(port_id))
452 if (port_reg_off_is_invalid(port_id, reg_off))
454 if (reg_bit_pos_is_invalid(bit1_pos))
456 if (reg_bit_pos_is_invalid(bit2_pos))
458 if (bit1_pos > bit2_pos)
459 l_bit = bit2_pos, h_bit = bit1_pos;
461 l_bit = bit1_pos, h_bit = bit2_pos;
463 reg_v = port_id_pci_reg_read(port_id, reg_off);
466 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
467 display_port_and_reg_off(port_id, (unsigned)reg_off);
468 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
469 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
473 port_reg_display(portid_t port_id, uint32_t reg_off)
477 if (port_id_is_invalid(port_id))
479 if (port_reg_off_is_invalid(port_id, reg_off))
481 reg_v = port_id_pci_reg_read(port_id, reg_off);
482 display_port_reg_value(port_id, reg_off, reg_v);
486 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
491 if (port_id_is_invalid(port_id))
493 if (port_reg_off_is_invalid(port_id, reg_off))
495 if (reg_bit_pos_is_invalid(bit_pos))
498 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
501 reg_v = port_id_pci_reg_read(port_id, reg_off);
503 reg_v &= ~(1 << bit_pos);
505 reg_v |= (1 << bit_pos);
506 port_id_pci_reg_write(port_id, reg_off, reg_v);
507 display_port_reg_value(port_id, reg_off, reg_v);
511 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
512 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
519 if (port_id_is_invalid(port_id))
521 if (port_reg_off_is_invalid(port_id, reg_off))
523 if (reg_bit_pos_is_invalid(bit1_pos))
525 if (reg_bit_pos_is_invalid(bit2_pos))
527 if (bit1_pos > bit2_pos)
528 l_bit = bit2_pos, h_bit = bit1_pos;
530 l_bit = bit1_pos, h_bit = bit2_pos;
532 if ((h_bit - l_bit) < 31)
533 max_v = (1 << (h_bit - l_bit + 1)) - 1;
538 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
539 (unsigned)value, (unsigned)value,
540 (unsigned)max_v, (unsigned)max_v);
543 reg_v = port_id_pci_reg_read(port_id, reg_off);
544 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
545 reg_v |= (value << l_bit); /* Set changed bits */
546 port_id_pci_reg_write(port_id, reg_off, reg_v);
547 display_port_reg_value(port_id, reg_off, reg_v);
551 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
553 if (port_id_is_invalid(port_id))
555 if (port_reg_off_is_invalid(port_id, reg_off))
557 port_id_pci_reg_write(port_id, reg_off, reg_v);
558 display_port_reg_value(port_id, reg_off, reg_v);
562 port_mtu_set(portid_t port_id, uint16_t mtu)
566 if (port_id_is_invalid(port_id))
568 diag = rte_eth_dev_set_mtu(port_id, mtu);
571 printf("Set MTU failed. diag=%d\n", diag);
575 * RX/TX ring descriptors display functions.
578 rx_queue_id_is_invalid(queueid_t rxq_id)
582 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
587 tx_queue_id_is_invalid(queueid_t txq_id)
591 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
596 rx_desc_id_is_invalid(uint16_t rxdesc_id)
598 if (rxdesc_id < nb_rxd)
600 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
606 tx_desc_id_is_invalid(uint16_t txdesc_id)
608 if (txdesc_id < nb_txd)
610 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
615 static const struct rte_memzone *
616 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
618 char mz_name[RTE_MEMZONE_NAMESIZE];
619 const struct rte_memzone *mz;
621 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
622 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
623 mz = rte_memzone_lookup(mz_name);
625 printf("%s ring memory zoneof (port %d, queue %d) not"
626 "found (zone name = %s\n",
627 ring_name, port_id, q_id, mz_name);
631 union igb_ring_dword {
634 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
644 struct igb_ring_desc_32_bytes {
645 union igb_ring_dword lo_dword;
646 union igb_ring_dword hi_dword;
647 union igb_ring_dword resv1;
648 union igb_ring_dword resv2;
651 struct igb_ring_desc_16_bytes {
652 union igb_ring_dword lo_dword;
653 union igb_ring_dword hi_dword;
657 ring_rxd_display_dword(union igb_ring_dword dword)
659 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
660 (unsigned)dword.words.hi);
664 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
665 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
668 __rte_unused uint8_t port_id,
672 struct igb_ring_desc_16_bytes *ring =
673 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
674 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
675 struct rte_eth_dev_info dev_info;
677 memset(&dev_info, 0, sizeof(dev_info));
678 rte_eth_dev_info_get(port_id, &dev_info);
679 if (strstr(dev_info.driver_name, "i40e") != NULL) {
680 /* 32 bytes RX descriptor, i40e only */
681 struct igb_ring_desc_32_bytes *ring =
682 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
683 ring[desc_id].lo_dword.dword =
684 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
685 ring_rxd_display_dword(ring[desc_id].lo_dword);
686 ring[desc_id].hi_dword.dword =
687 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
688 ring_rxd_display_dword(ring[desc_id].hi_dword);
689 ring[desc_id].resv1.dword =
690 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
691 ring_rxd_display_dword(ring[desc_id].resv1);
692 ring[desc_id].resv2.dword =
693 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
694 ring_rxd_display_dword(ring[desc_id].resv2);
699 /* 16 bytes RX descriptor */
700 ring[desc_id].lo_dword.dword =
701 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
702 ring_rxd_display_dword(ring[desc_id].lo_dword);
703 ring[desc_id].hi_dword.dword =
704 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
705 ring_rxd_display_dword(ring[desc_id].hi_dword);
709 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
711 struct igb_ring_desc_16_bytes *ring;
712 struct igb_ring_desc_16_bytes txd;
714 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
715 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
716 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
717 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
718 (unsigned)txd.lo_dword.words.lo,
719 (unsigned)txd.lo_dword.words.hi,
720 (unsigned)txd.hi_dword.words.lo,
721 (unsigned)txd.hi_dword.words.hi);
725 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
727 const struct rte_memzone *rx_mz;
729 if (port_id_is_invalid(port_id))
731 if (rx_queue_id_is_invalid(rxq_id))
733 if (rx_desc_id_is_invalid(rxd_id))
735 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
738 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
742 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
744 const struct rte_memzone *tx_mz;
746 if (port_id_is_invalid(port_id))
748 if (tx_queue_id_is_invalid(txq_id))
750 if (tx_desc_id_is_invalid(txd_id))
752 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
755 ring_tx_descriptor_display(tx_mz, txd_id);
759 fwd_lcores_config_display(void)
763 printf("List of forwarding lcores:");
764 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
765 printf(" %2u", fwd_lcores_cpuids[lc_id]);
769 rxtx_config_display(void)
771 printf(" %s packet forwarding - CRC stripping %s - "
772 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
773 rx_mode.hw_strip_crc ? "enabled" : "disabled",
776 if (cur_fwd_eng == &tx_only_engine)
777 printf(" packet len=%u - nb packet segments=%d\n",
778 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
780 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
781 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
783 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
784 nb_fwd_lcores, nb_fwd_ports);
785 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
786 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
787 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
788 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
789 rx_conf->rx_thresh.wthresh);
790 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
791 nb_txq, nb_txd, tx_conf->tx_free_thresh);
792 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
793 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
794 tx_conf->tx_thresh.wthresh);
795 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
796 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
800 port_rss_reta_info(portid_t port_id,
801 struct rte_eth_rss_reta_entry64 *reta_conf,
804 uint16_t i, idx, shift;
807 if (port_id_is_invalid(port_id))
810 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
812 printf("Failed to get RSS RETA info, return code = %d\n", ret);
816 for (i = 0; i < nb_entries; i++) {
817 idx = i / RTE_RETA_GROUP_SIZE;
818 shift = i % RTE_RETA_GROUP_SIZE;
819 if (!(reta_conf[idx].mask & (1ULL << shift)))
821 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
822 i, reta_conf[idx].reta[shift]);
827 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
831 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
833 struct rss_type_info {
837 static const struct rss_type_info rss_type_table[] = {
838 {"ipv4", ETH_RSS_IPV4},
839 {"ipv4-frag", ETH_RSS_FRAG_IPV4},
840 {"ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP},
841 {"ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP},
842 {"ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP},
843 {"ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER},
844 {"ipv6", ETH_RSS_IPV6},
845 {"ipv6-frag", ETH_RSS_FRAG_IPV6},
846 {"ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP},
847 {"ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP},
848 {"ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP},
849 {"ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER},
850 {"l2-payload", ETH_RSS_L2_PAYLOAD},
851 {"ipv6-ex", ETH_RSS_IPV6_EX},
852 {"ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX},
853 {"ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX},
856 struct rte_eth_rss_conf rss_conf;
857 uint8_t rss_key[10 * 4];
862 if (port_id_is_invalid(port_id))
864 /* Get RSS hash key if asked to display it */
865 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
866 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
870 printf("port index %d invalid\n", port_id);
873 printf("operation not supported by device\n");
876 printf("operation failed - diag=%d\n", diag);
881 rss_hf = rss_conf.rss_hf;
883 printf("RSS disabled\n");
886 printf("RSS functions:\n ");
887 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
888 if (rss_hf & rss_type_table[i].rss_type)
889 printf("%s ", rss_type_table[i].str);
894 printf("RSS key:\n");
895 for (i = 0; i < sizeof(rss_key); i++)
896 printf("%02X", rss_key[i]);
901 port_rss_hash_key_update(portid_t port_id, uint8_t *hash_key)
903 struct rte_eth_rss_conf rss_conf;
906 rss_conf.rss_key = NULL;
907 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
909 rss_conf.rss_key = hash_key;
910 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
917 printf("port index %d invalid\n", port_id);
920 printf("operation not supported by device\n");
923 printf("operation failed - diag=%d\n", diag);
929 * Setup forwarding configuration for each logical core.
932 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
934 streamid_t nb_fs_per_lcore;
942 nb_fs = cfg->nb_fwd_streams;
943 nb_fc = cfg->nb_fwd_lcores;
944 if (nb_fs <= nb_fc) {
948 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
949 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
952 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
954 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
955 fwd_lcores[lc_id]->stream_idx = sm_id;
956 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
957 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
961 * Assign extra remaining streams, if any.
963 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
964 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
965 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
966 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
967 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
972 simple_fwd_config_setup(void)
978 if (port_topology == PORT_TOPOLOGY_CHAINED ||
979 port_topology == PORT_TOPOLOGY_LOOP) {
981 } else if (nb_fwd_ports % 2) {
982 printf("\nWarning! Cannot handle an odd number of ports "
983 "with the current port topology. Configuration "
984 "must be changed to have an even number of ports, "
985 "or relaunch application with "
986 "--port-topology=chained\n\n");
989 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
990 cur_fwd_config.nb_fwd_streams =
991 (streamid_t) cur_fwd_config.nb_fwd_ports;
993 /* reinitialize forwarding streams */
997 * In the simple forwarding test, the number of forwarding cores
998 * must be lower or equal to the number of forwarding ports.
1000 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1001 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1002 cur_fwd_config.nb_fwd_lcores =
1003 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1004 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1006 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1007 if (port_topology != PORT_TOPOLOGY_LOOP)
1008 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1011 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1012 fwd_streams[i]->rx_queue = 0;
1013 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1014 fwd_streams[i]->tx_queue = 0;
1015 fwd_streams[i]->peer_addr = j;
1017 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1018 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1019 fwd_streams[j]->rx_queue = 0;
1020 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1021 fwd_streams[j]->tx_queue = 0;
1022 fwd_streams[j]->peer_addr = i;
1028 * For the RSS forwarding test, each core is assigned on every port a transmit
1029 * queue whose index is the index of the core itself. This approach limits the
1030 * maximumm number of processing cores of the RSS test to the maximum number of
1031 * TX queues supported by the devices.
1033 * Each core is assigned a single stream, each stream being composed of
1034 * a RX queue to poll on a RX port for input messages, associated with
1035 * a TX queue of a TX port where to send forwarded packets.
1036 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1037 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1039 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1043 rss_fwd_config_setup(void)
1054 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1055 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1056 cur_fwd_config.nb_fwd_streams =
1057 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1058 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
1059 cur_fwd_config.nb_fwd_streams =
1060 (streamid_t)cur_fwd_config.nb_fwd_lcores;
1062 cur_fwd_config.nb_fwd_lcores =
1063 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1065 /* reinitialize forwarding streams */
1068 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1070 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1071 struct fwd_stream *fs;
1073 fs = fwd_streams[lc_id];
1075 if ((rxp & 0x1) == 0)
1076 txp = (portid_t) (rxp + 1);
1078 txp = (portid_t) (rxp - 1);
1080 * if we are in loopback, simply send stuff out through the
1083 if (port_topology == PORT_TOPOLOGY_LOOP)
1086 fs->rx_port = fwd_ports_ids[rxp];
1088 fs->tx_port = fwd_ports_ids[txp];
1090 fs->peer_addr = fs->tx_port;
1091 rxq = (queueid_t) (rxq + 1);
1096 * Restart from RX queue 0 on next RX port
1099 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1101 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1103 rxp = (portid_t) (rxp + 1);
1108 * In DCB and VT on,the mapping of 128 receive queues to 128 transmit queues.
1111 dcb_rxq_2_txq_mapping(queueid_t rxq, queueid_t *txq)
1113 if(dcb_q_mapping == DCB_4_TCS_Q_MAPPING) {
1118 else if (rxq < 64) {
1120 *txq = (uint16_t)(rxq + 32);
1123 /* tc2: 96-111;tc3:112-127 */
1124 *txq = (uint16_t)(rxq/2 + 64);
1131 else if (rxq < 32) {
1133 *txq = (uint16_t)(rxq + 16);
1135 else if (rxq < 64) {
1136 /*tc2,tc3 mapping */
1137 *txq = (uint16_t)(rxq + 32);
1140 /* tc4,tc5,tc6 and tc7 mapping */
1141 *txq = (uint16_t)(rxq/2 + 64);
1147 * For the DCB forwarding test, each core is assigned on every port multi-transmit
1150 * Each core is assigned a multi-stream, each stream being composed of
1151 * a RX queue to poll on a RX port for input messages, associated with
1152 * a TX queue of a TX port where to send forwarded packets.
1153 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1154 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1157 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1160 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1161 * There is a mapping of RxQj to TxQl to be required,and the mapping was implemented
1162 * in dcb_rxq_2_txq_mapping function.
1165 dcb_fwd_config_setup(void)
1176 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1177 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1178 cur_fwd_config.nb_fwd_streams =
1179 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1181 /* reinitialize forwarding streams */
1184 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1186 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1187 /* a fwd core can run multi-streams */
1188 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++)
1190 struct fwd_stream *fs;
1191 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1192 if ((rxp & 0x1) == 0)
1193 txp = (portid_t) (rxp + 1);
1195 txp = (portid_t) (rxp - 1);
1196 fs->rx_port = fwd_ports_ids[rxp];
1198 fs->tx_port = fwd_ports_ids[txp];
1199 if (dcb_q_mapping == DCB_VT_Q_MAPPING)
1202 dcb_rxq_2_txq_mapping(rxq, &fs->tx_queue);
1203 fs->peer_addr = fs->tx_port;
1204 rxq = (queueid_t) (rxq + 1);
1208 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1210 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1212 rxp = (portid_t) (rxp + 1);
1218 icmp_echo_config_setup(void)
1225 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1226 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1227 (nb_txq * nb_fwd_ports);
1229 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1230 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1231 cur_fwd_config.nb_fwd_streams =
1232 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1233 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1234 cur_fwd_config.nb_fwd_lcores =
1235 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1236 if (verbose_level > 0) {
1237 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1239 cur_fwd_config.nb_fwd_lcores,
1240 cur_fwd_config.nb_fwd_ports,
1241 cur_fwd_config.nb_fwd_streams);
1244 /* reinitialize forwarding streams */
1246 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1248 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1249 if (verbose_level > 0)
1250 printf(" core=%d: \n", lc_id);
1251 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1252 struct fwd_stream *fs;
1253 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1254 fs->rx_port = fwd_ports_ids[rxp];
1256 fs->tx_port = fs->rx_port;
1257 fs->tx_queue = lc_id;
1258 fs->peer_addr = fs->tx_port;
1259 if (verbose_level > 0)
1260 printf(" stream=%d port=%d rxq=%d txq=%d\n",
1261 sm_id, fs->rx_port, fs->rx_queue,
1263 rxq = (queueid_t) (rxq + 1);
1264 if (rxq == nb_rxq) {
1266 rxp = (portid_t) (rxp + 1);
1273 fwd_config_setup(void)
1275 cur_fwd_config.fwd_eng = cur_fwd_eng;
1276 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1277 icmp_echo_config_setup();
1280 if ((nb_rxq > 1) && (nb_txq > 1)){
1282 dcb_fwd_config_setup();
1284 rss_fwd_config_setup();
1287 simple_fwd_config_setup();
1291 pkt_fwd_config_display(struct fwd_config *cfg)
1293 struct fwd_stream *fs;
1297 printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
1298 "NUMA support %s, MP over anonymous pages %s\n",
1299 cfg->fwd_eng->fwd_mode_name,
1300 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1301 numa_support == 1 ? "enabled" : "disabled",
1302 mp_anon != 0 ? "enabled" : "disabled");
1304 if (strcmp(cfg->fwd_eng->fwd_mode_name, "mac_retry") == 0)
1305 printf("TX retry num: %u, delay between TX retries: %uus\n",
1306 burst_tx_retry_num, burst_tx_delay_time);
1307 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1308 printf("Logical Core %u (socket %u) forwards packets on "
1310 fwd_lcores_cpuids[lc_id],
1311 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1312 fwd_lcores[lc_id]->stream_nb);
1313 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1314 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1315 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
1316 "P=%d/Q=%d (socket %u) ",
1317 fs->rx_port, fs->rx_queue,
1318 ports[fs->rx_port].socket_id,
1319 fs->tx_port, fs->tx_queue,
1320 ports[fs->tx_port].socket_id);
1321 print_ethaddr("peer=",
1322 &peer_eth_addrs[fs->peer_addr]);
1331 fwd_config_display(void)
1333 if((dcb_config) && (nb_fwd_lcores == 1)) {
1334 printf("In DCB mode,the nb forwarding cores should be larger than 1\n");
1338 pkt_fwd_config_display(&cur_fwd_config);
1342 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1345 unsigned int lcore_cpuid;
1350 for (i = 0; i < nb_lc; i++) {
1351 lcore_cpuid = lcorelist[i];
1352 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1353 printf("lcore %u not enabled\n", lcore_cpuid);
1356 if (lcore_cpuid == rte_get_master_lcore()) {
1357 printf("lcore %u cannot be masked on for running "
1358 "packet forwarding, which is the master lcore "
1359 "and reserved for command line parsing only\n",
1364 fwd_lcores_cpuids[i] = lcore_cpuid;
1366 if (record_now == 0) {
1370 nb_cfg_lcores = (lcoreid_t) nb_lc;
1371 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1372 printf("previous number of forwarding cores %u - changed to "
1373 "number of configured cores %u\n",
1374 (unsigned int) nb_fwd_lcores, nb_lc);
1375 nb_fwd_lcores = (lcoreid_t) nb_lc;
1382 set_fwd_lcores_mask(uint64_t lcoremask)
1384 unsigned int lcorelist[64];
1388 if (lcoremask == 0) {
1389 printf("Invalid NULL mask of cores\n");
1393 for (i = 0; i < 64; i++) {
1394 if (! ((uint64_t)(1ULL << i) & lcoremask))
1396 lcorelist[nb_lc++] = i;
1398 return set_fwd_lcores_list(lcorelist, nb_lc);
1402 set_fwd_lcores_number(uint16_t nb_lc)
1404 if (nb_lc > nb_cfg_lcores) {
1405 printf("nb fwd cores %u > %u (max. number of configured "
1406 "lcores) - ignored\n",
1407 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1410 nb_fwd_lcores = (lcoreid_t) nb_lc;
1411 printf("Number of forwarding cores set to %u\n",
1412 (unsigned int) nb_fwd_lcores);
1416 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1424 for (i = 0; i < nb_pt; i++) {
1425 port_id = (portid_t) portlist[i];
1426 if (port_id >= nb_ports) {
1427 printf("Invalid port id %u >= %u\n",
1428 (unsigned int) port_id,
1429 (unsigned int) nb_ports);
1433 fwd_ports_ids[i] = port_id;
1435 if (record_now == 0) {
1439 nb_cfg_ports = (portid_t) nb_pt;
1440 if (nb_fwd_ports != (portid_t) nb_pt) {
1441 printf("previous number of forwarding ports %u - changed to "
1442 "number of configured ports %u\n",
1443 (unsigned int) nb_fwd_ports, nb_pt);
1444 nb_fwd_ports = (portid_t) nb_pt;
1449 set_fwd_ports_mask(uint64_t portmask)
1451 unsigned int portlist[64];
1455 if (portmask == 0) {
1456 printf("Invalid NULL mask of ports\n");
1460 for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
1461 if (! ((uint64_t)(1ULL << i) & portmask))
1463 portlist[nb_pt++] = i;
1465 set_fwd_ports_list(portlist, nb_pt);
1469 set_fwd_ports_number(uint16_t nb_pt)
1471 if (nb_pt > nb_cfg_ports) {
1472 printf("nb fwd ports %u > %u (number of configured "
1473 "ports) - ignored\n",
1474 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1477 nb_fwd_ports = (portid_t) nb_pt;
1478 printf("Number of forwarding ports set to %u\n",
1479 (unsigned int) nb_fwd_ports);
1483 set_nb_pkt_per_burst(uint16_t nb)
1485 if (nb > MAX_PKT_BURST) {
1486 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1488 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1491 nb_pkt_per_burst = nb;
1492 printf("Number of packets per burst set to %u\n",
1493 (unsigned int) nb_pkt_per_burst);
1497 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1499 uint16_t tx_pkt_len;
1502 if (nb_segs >= (unsigned) nb_txd) {
1503 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1504 nb_segs, (unsigned int) nb_txd);
1509 * Check that each segment length is greater or equal than
1510 * the mbuf data sise.
1511 * Check also that the total packet length is greater or equal than the
1512 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1515 for (i = 0; i < nb_segs; i++) {
1516 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1517 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1518 i, seg_lengths[i], (unsigned) mbuf_data_size);
1521 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1523 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1524 printf("total packet length=%u < %d - give up\n",
1525 (unsigned) tx_pkt_len,
1526 (int)(sizeof(struct ether_hdr) + 20 + 8));
1530 for (i = 0; i < nb_segs; i++)
1531 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1533 tx_pkt_length = tx_pkt_len;
1534 tx_pkt_nb_segs = (uint8_t) nb_segs;
1538 list_pkt_forwarding_modes(void)
1540 static char fwd_modes[128] = "";
1541 const char *separator = "|";
1542 struct fwd_engine *fwd_eng;
1545 if (strlen (fwd_modes) == 0) {
1546 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1547 strcat(fwd_modes, fwd_eng->fwd_mode_name);
1548 strcat(fwd_modes, separator);
1550 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1557 set_pkt_forwarding_mode(const char *fwd_mode_name)
1559 struct fwd_engine *fwd_eng;
1563 while ((fwd_eng = fwd_engines[i]) != NULL) {
1564 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1565 printf("Set %s packet forwarding mode\n",
1567 cur_fwd_eng = fwd_eng;
1572 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1576 set_verbose_level(uint16_t vb_level)
1578 printf("Change verbose level from %u to %u\n",
1579 (unsigned int) verbose_level, (unsigned int) vb_level);
1580 verbose_level = vb_level;
1584 vlan_extend_set(portid_t port_id, int on)
1589 if (port_id_is_invalid(port_id))
1592 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1595 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1597 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1599 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1601 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1602 "diag=%d\n", port_id, on, diag);
1606 rx_vlan_strip_set(portid_t port_id, int on)
1611 if (port_id_is_invalid(port_id))
1614 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1617 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1619 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1621 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1623 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1624 "diag=%d\n", port_id, on, diag);
1628 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1632 if (port_id_is_invalid(port_id))
1635 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1637 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1638 "diag=%d\n", port_id, queue_id, on, diag);
1642 rx_vlan_filter_set(portid_t port_id, int on)
1647 if (port_id_is_invalid(port_id))
1650 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1653 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1655 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1657 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1659 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1660 "diag=%d\n", port_id, on, diag);
1664 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1668 if (port_id_is_invalid(port_id))
1670 if (vlan_id_is_invalid(vlan_id))
1672 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1675 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1677 port_id, vlan_id, on, diag);
1681 rx_vlan_all_filter_set(portid_t port_id, int on)
1685 if (port_id_is_invalid(port_id))
1687 for (vlan_id = 0; vlan_id < 4096; vlan_id++)
1688 rx_vft_set(port_id, vlan_id, on);
1692 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1695 if (port_id_is_invalid(port_id))
1698 diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1702 printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1704 port_id, tp_id, diag);
1708 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1710 if (port_id_is_invalid(port_id))
1712 if (vlan_id_is_invalid(vlan_id))
1714 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1715 ports[port_id].tx_vlan_id = vlan_id;
1719 tx_vlan_reset(portid_t port_id)
1721 if (port_id_is_invalid(port_id))
1723 ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1727 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
1729 if (port_id_is_invalid(port_id))
1732 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
1736 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1739 uint8_t existing_mapping_found = 0;
1741 if (port_id_is_invalid(port_id))
1744 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1747 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1748 printf("map_value not in required range 0..%d\n",
1749 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1753 if (!is_rx) { /*then tx*/
1754 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1755 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1756 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1757 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1758 existing_mapping_found = 1;
1762 if (!existing_mapping_found) { /* A new additional mapping... */
1763 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1764 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1765 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1766 nb_tx_queue_stats_mappings++;
1770 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1771 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1772 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1773 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1774 existing_mapping_found = 1;
1778 if (!existing_mapping_found) { /* A new additional mapping... */
1779 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1780 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1781 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1782 nb_rx_queue_stats_mappings++;
1788 print_fdir_mask(struct rte_eth_fdir_masks *mask)
1790 printf("\n vlan_tci: 0x%04x, src_ipv4: 0x%08x, dst_ipv4: 0x%08x,"
1791 " src_port: 0x%04x, dst_port: 0x%04x",
1792 mask->vlan_tci_mask, mask->ipv4_mask.src_ip,
1793 mask->ipv4_mask.dst_ip,
1794 mask->src_port_mask, mask->dst_port_mask);
1796 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x,"
1797 " dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
1798 mask->ipv6_mask.src_ip[0], mask->ipv6_mask.src_ip[1],
1799 mask->ipv6_mask.src_ip[2], mask->ipv6_mask.src_ip[3],
1800 mask->ipv6_mask.dst_ip[0], mask->ipv6_mask.dst_ip[1],
1801 mask->ipv6_mask.dst_ip[2], mask->ipv6_mask.dst_ip[3]);
1806 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
1808 struct rte_eth_flex_payload_cfg *cfg;
1811 for (i = 0; i < flex_conf->nb_payloads; i++) {
1812 cfg = &flex_conf->flex_set[i];
1813 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
1815 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
1816 printf("\n L2_PAYLOAD: ");
1817 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
1818 printf("\n L3_PAYLOAD: ");
1819 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
1820 printf("\n L4_PAYLOAD: ");
1822 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
1823 for (j = 0; j < num; j++)
1824 printf(" %-5u", cfg->src_offset[j]);
1830 flowtype_to_str(uint16_t flow_type)
1832 struct flow_type_info {
1838 static struct flow_type_info flowtype_str_table[] = {
1839 {"raw", RTE_ETH_FLOW_RAW},
1840 {"ipv4", RTE_ETH_FLOW_IPV4},
1841 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
1842 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
1843 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
1844 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
1845 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
1846 {"ipv6", RTE_ETH_FLOW_IPV6},
1847 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
1848 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
1849 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
1850 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
1851 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
1852 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
1855 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
1856 if (flowtype_str_table[i].ftype == flow_type)
1857 return flowtype_str_table[i].str;
1864 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
1866 struct rte_eth_fdir_flex_mask *mask;
1870 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
1871 mask = &flex_conf->flex_mask[i];
1872 p = flowtype_to_str(mask->flow_type);
1873 printf("\n %s:\t", p ? p : "unknown");
1874 for (j = 0; j < num; j++)
1875 printf(" %02x", mask->mask[j]);
1881 print_fdir_flow_type(uint32_t flow_types_mask)
1886 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
1887 if (!(flow_types_mask & (1 << i)))
1889 p = flowtype_to_str(i);
1899 fdir_get_infos(portid_t port_id)
1901 struct rte_eth_fdir_stats fdir_stat;
1902 struct rte_eth_fdir_info fdir_info;
1905 static const char *fdir_stats_border = "########################";
1907 if (port_id_is_invalid(port_id))
1909 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
1911 printf("\n FDIR is not supported on port %-2d\n",
1916 memset(&fdir_info, 0, sizeof(fdir_info));
1917 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
1918 RTE_ETH_FILTER_INFO, &fdir_info);
1919 memset(&fdir_stat, 0, sizeof(fdir_stat));
1920 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
1921 RTE_ETH_FILTER_STATS, &fdir_stat);
1922 printf("\n %s FDIR infos for port %-2d %s\n",
1923 fdir_stats_border, port_id, fdir_stats_border);
1925 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
1926 printf(" PERFECT\n");
1927 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
1928 printf(" SIGNATURE\n");
1930 printf(" DISABLE\n");
1931 printf(" SUPPORTED FLOW TYPE: ");
1932 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
1933 printf(" FLEX PAYLOAD INFO:\n");
1934 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
1935 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
1936 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
1937 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
1938 fdir_info.flex_payload_unit,
1939 fdir_info.max_flex_payload_segment_num,
1940 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
1942 print_fdir_mask(&fdir_info.mask);
1943 if (fdir_info.flex_conf.nb_payloads > 0) {
1944 printf(" FLEX PAYLOAD SRC OFFSET:");
1945 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
1947 if (fdir_info.flex_conf.nb_flexmasks > 0) {
1948 printf(" FLEX MASK CFG:");
1949 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
1951 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
1952 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
1953 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
1954 fdir_info.guarant_spc, fdir_info.best_spc);
1955 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
1956 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
1957 " add: %-10"PRIu64" remove: %"PRIu64"\n"
1958 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
1959 fdir_stat.collision, fdir_stat.free,
1960 fdir_stat.maxhash, fdir_stat.maxlen,
1961 fdir_stat.add, fdir_stat.remove,
1962 fdir_stat.f_add, fdir_stat.f_remove);
1963 printf(" %s############################%s\n",
1964 fdir_stats_border, fdir_stats_border);
1968 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
1970 struct rte_port *port;
1971 struct rte_eth_fdir_flex_conf *flex_conf;
1974 port = &ports[port_id];
1975 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
1976 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
1977 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
1982 if (i >= RTE_ETH_FLOW_MAX) {
1983 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
1984 idx = flex_conf->nb_flexmasks;
1985 flex_conf->nb_flexmasks++;
1987 printf("The flex mask table is full. Can not set flex"
1988 " mask for flow_type(%u).", cfg->flow_type);
1992 (void)rte_memcpy(&flex_conf->flex_mask[idx],
1994 sizeof(struct rte_eth_fdir_flex_mask));
1998 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2000 struct rte_port *port;
2001 struct rte_eth_fdir_flex_conf *flex_conf;
2004 port = &ports[port_id];
2005 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2006 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2007 if (cfg->type == flex_conf->flex_set[i].type) {
2012 if (i >= RTE_ETH_PAYLOAD_MAX) {
2013 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2014 idx = flex_conf->nb_payloads;
2015 flex_conf->nb_payloads++;
2017 printf("The flex payload table is full. Can not set"
2018 " flex payload for type(%u).", cfg->type);
2022 (void)rte_memcpy(&flex_conf->flex_set[idx],
2024 sizeof(struct rte_eth_flex_payload_cfg));
2029 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
2033 if (port_id_is_invalid(port_id))
2036 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
2038 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
2042 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
2043 "diag=%d\n", port_id, diag);
2045 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
2046 "diag=%d\n", port_id, diag);
2051 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
2055 if (port_id_is_invalid(port_id))
2057 if (vlan_id_is_invalid(vlan_id))
2059 diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
2062 printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
2063 "diag=%d\n", port_id, diag);
2067 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
2070 struct rte_eth_link link;
2072 if (port_id_is_invalid(port_id))
2074 rte_eth_link_get_nowait(port_id, &link);
2075 if (rate > link.link_speed) {
2076 printf("Invalid rate value:%u bigger than link speed: %u\n",
2077 rate, link.link_speed);
2080 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
2083 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
2089 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
2092 struct rte_eth_link link;
2097 if (port_id_is_invalid(port_id))
2099 rte_eth_link_get_nowait(port_id, &link);
2100 if (rate > link.link_speed) {
2101 printf("Invalid rate value:%u bigger than link speed: %u\n",
2102 rate, link.link_speed);
2105 diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
2108 printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",