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(c) 2013 6WIND.
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>
100 print_ethaddr(const char *name, struct ether_addr *eth_addr)
102 printf("%s%02X:%02X:%02X:%02X:%02X:%02X", name,
103 (unsigned int)eth_addr->addr_bytes[0],
104 (unsigned int)eth_addr->addr_bytes[1],
105 (unsigned int)eth_addr->addr_bytes[2],
106 (unsigned int)eth_addr->addr_bytes[3],
107 (unsigned int)eth_addr->addr_bytes[4],
108 (unsigned int)eth_addr->addr_bytes[5]);
112 nic_stats_display(portid_t port_id)
114 struct rte_eth_stats stats;
115 struct rte_port *port = &ports[port_id];
118 static const char *nic_stats_border = "########################";
120 if (port_id >= nb_ports) {
121 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
124 rte_eth_stats_get(port_id, &stats);
125 printf("\n %s NIC statistics for port %-2d %s\n",
126 nic_stats_border, port_id, nic_stats_border);
128 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
129 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
131 stats.ipackets, stats.imissed, stats.ibytes);
132 printf(" RX-badcrc: %-10"PRIu64" RX-badlen: %-10"PRIu64" RX-errors: "
134 stats.ibadcrc, stats.ibadlen, stats.ierrors);
135 printf(" RX-nombuf: %-10"PRIu64"\n",
137 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
139 stats.opackets, stats.oerrors, stats.obytes);
142 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
143 " RX-bytes: %10"PRIu64"\n",
144 stats.ipackets, stats.ierrors, stats.ibytes);
145 printf(" RX-badcrc: %10"PRIu64" RX-badlen: %10"PRIu64
146 " RX-errors: %10"PRIu64"\n",
147 stats.ibadcrc, stats.ibadlen, stats.ierrors);
148 printf(" RX-nombuf: %10"PRIu64"\n",
150 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
151 " TX-bytes: %10"PRIu64"\n",
152 stats.opackets, stats.oerrors, stats.obytes);
156 if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
157 printf(" Fdirmiss: %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
161 if (port->rx_queue_stats_mapping_enabled) {
163 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
164 printf(" Stats reg %2d RX-packets: %10"PRIu64
165 " RX-errors: %10"PRIu64
166 " RX-bytes: %10"PRIu64"\n",
167 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
170 if (port->tx_queue_stats_mapping_enabled) {
172 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
173 printf(" Stats reg %2d TX-packets: %10"PRIu64
174 " TX-bytes: %10"PRIu64"\n",
175 i, stats.q_opackets[i], stats.q_obytes[i]);
179 /* Display statistics of XON/XOFF pause frames, if any. */
180 if ((stats.tx_pause_xon | stats.rx_pause_xon |
181 stats.tx_pause_xoff | stats.rx_pause_xoff) > 0) {
182 printf(" RX-XOFF: %-10"PRIu64" RX-XON: %-10"PRIu64"\n",
183 stats.rx_pause_xoff, stats.rx_pause_xon);
184 printf(" TX-XOFF: %-10"PRIu64" TX-XON: %-10"PRIu64"\n",
185 stats.tx_pause_xoff, stats.tx_pause_xon);
187 printf(" %s############################%s\n",
188 nic_stats_border, nic_stats_border);
192 nic_stats_clear(portid_t port_id)
194 if (port_id >= nb_ports) {
195 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
198 rte_eth_stats_reset(port_id);
199 printf("\n NIC statistics for port %d cleared\n", port_id);
203 nic_xstats_display(portid_t port_id)
205 struct rte_eth_xstats *xstats;
208 printf("###### NIC extended statistics for port %-2d\n", port_id);
210 len = rte_eth_xstats_get(port_id, NULL, 0);
212 printf("Cannot get xstats count\n");
215 xstats = malloc(sizeof(xstats[0]) * len);
216 if (xstats == NULL) {
217 printf("Cannot allocate memory for xstats\n");
220 ret = rte_eth_xstats_get(port_id, xstats, len);
221 if (ret < 0 || ret > len) {
222 printf("Cannot get xstats\n");
226 for (i = 0; i < len; i++)
227 printf("%s: %"PRIu64"\n", xstats[i].name, xstats[i].value);
232 nic_xstats_clear(portid_t port_id)
234 rte_eth_xstats_reset(port_id);
238 nic_stats_mapping_display(portid_t port_id)
240 struct rte_port *port = &ports[port_id];
243 static const char *nic_stats_mapping_border = "########################";
245 if (port_id >= nb_ports) {
246 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
250 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
251 printf("Port id %d - either does not support queue statistic mapping or"
252 " no queue statistic mapping set\n", port_id);
256 printf("\n %s NIC statistics mapping for port %-2d %s\n",
257 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
259 if (port->rx_queue_stats_mapping_enabled) {
260 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
261 if (rx_queue_stats_mappings[i].port_id == port_id) {
262 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
263 rx_queue_stats_mappings[i].queue_id,
264 rx_queue_stats_mappings[i].stats_counter_id);
271 if (port->tx_queue_stats_mapping_enabled) {
272 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
273 if (tx_queue_stats_mappings[i].port_id == port_id) {
274 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
275 tx_queue_stats_mappings[i].queue_id,
276 tx_queue_stats_mappings[i].stats_counter_id);
281 printf(" %s####################################%s\n",
282 nic_stats_mapping_border, nic_stats_mapping_border);
286 port_infos_display(portid_t port_id)
288 struct rte_port *port;
289 struct ether_addr mac_addr;
290 struct rte_eth_link link;
292 struct rte_mempool * mp;
293 static const char *info_border = "*********************";
295 if (port_id >= nb_ports) {
296 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
299 port = &ports[port_id];
300 rte_eth_link_get_nowait(port_id, &link);
301 printf("\n%s Infos for port %-2d %s\n",
302 info_border, port_id, info_border);
303 rte_eth_macaddr_get(port_id, &mac_addr);
304 print_ethaddr("MAC address: ", &mac_addr);
305 printf("\nConnect to socket: %u", port->socket_id);
307 if (port_numa[port_id] != NUMA_NO_CONFIG) {
308 mp = mbuf_pool_find(port_numa[port_id]);
310 printf("\nmemory allocation on the socket: %d",
313 printf("\nmemory allocation on the socket: %u",port->socket_id);
315 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
316 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
317 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
318 ("full-duplex") : ("half-duplex"));
319 printf("Promiscuous mode: %s\n",
320 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
321 printf("Allmulticast mode: %s\n",
322 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
323 printf("Maximum number of MAC addresses: %u\n",
324 (unsigned int)(port->dev_info.max_mac_addrs));
325 printf("Maximum number of MAC addresses of hash filtering: %u\n",
326 (unsigned int)(port->dev_info.max_hash_mac_addrs));
328 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
329 if (vlan_offload >= 0){
330 printf("VLAN offload: \n");
331 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
332 printf(" strip on \n");
334 printf(" strip off \n");
336 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
337 printf(" filter on \n");
339 printf(" filter off \n");
341 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
342 printf(" qinq(extend) on \n");
344 printf(" qinq(extend) off \n");
349 port_id_is_invalid(portid_t port_id)
351 if (port_id < nb_ports)
353 printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
358 vlan_id_is_invalid(uint16_t vlan_id)
362 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
367 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
372 printf("Port register offset 0x%X not aligned on a 4-byte "
377 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
378 if (reg_off >= pci_len) {
379 printf("Port %d: register offset %u (0x%X) out of port PCI "
380 "resource (length=%"PRIu64")\n",
381 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
388 reg_bit_pos_is_invalid(uint8_t bit_pos)
392 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
396 #define display_port_and_reg_off(port_id, reg_off) \
397 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
400 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
402 display_port_and_reg_off(port_id, (unsigned)reg_off);
403 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
407 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
412 if (port_id_is_invalid(port_id))
414 if (port_reg_off_is_invalid(port_id, reg_off))
416 if (reg_bit_pos_is_invalid(bit_x))
418 reg_v = port_id_pci_reg_read(port_id, reg_off);
419 display_port_and_reg_off(port_id, (unsigned)reg_off);
420 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
424 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
425 uint8_t bit1_pos, uint8_t bit2_pos)
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(bit1_pos))
437 if (reg_bit_pos_is_invalid(bit2_pos))
439 if (bit1_pos > bit2_pos)
440 l_bit = bit2_pos, h_bit = bit1_pos;
442 l_bit = bit1_pos, h_bit = bit2_pos;
444 reg_v = port_id_pci_reg_read(port_id, reg_off);
447 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
448 display_port_and_reg_off(port_id, (unsigned)reg_off);
449 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
450 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
454 port_reg_display(portid_t port_id, uint32_t reg_off)
458 if (port_id_is_invalid(port_id))
460 if (port_reg_off_is_invalid(port_id, reg_off))
462 reg_v = port_id_pci_reg_read(port_id, reg_off);
463 display_port_reg_value(port_id, reg_off, reg_v);
467 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
472 if (port_id_is_invalid(port_id))
474 if (port_reg_off_is_invalid(port_id, reg_off))
476 if (reg_bit_pos_is_invalid(bit_pos))
479 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
482 reg_v = port_id_pci_reg_read(port_id, reg_off);
484 reg_v &= ~(1 << bit_pos);
486 reg_v |= (1 << bit_pos);
487 port_id_pci_reg_write(port_id, reg_off, reg_v);
488 display_port_reg_value(port_id, reg_off, reg_v);
492 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
493 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
500 if (port_id_is_invalid(port_id))
502 if (port_reg_off_is_invalid(port_id, reg_off))
504 if (reg_bit_pos_is_invalid(bit1_pos))
506 if (reg_bit_pos_is_invalid(bit2_pos))
508 if (bit1_pos > bit2_pos)
509 l_bit = bit2_pos, h_bit = bit1_pos;
511 l_bit = bit1_pos, h_bit = bit2_pos;
513 if ((h_bit - l_bit) < 31)
514 max_v = (1 << (h_bit - l_bit + 1)) - 1;
519 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
520 (unsigned)value, (unsigned)value,
521 (unsigned)max_v, (unsigned)max_v);
524 reg_v = port_id_pci_reg_read(port_id, reg_off);
525 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
526 reg_v |= (value << l_bit); /* Set changed bits */
527 port_id_pci_reg_write(port_id, reg_off, reg_v);
528 display_port_reg_value(port_id, reg_off, reg_v);
532 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
534 if (port_id_is_invalid(port_id))
536 if (port_reg_off_is_invalid(port_id, reg_off))
538 port_id_pci_reg_write(port_id, reg_off, reg_v);
539 display_port_reg_value(port_id, reg_off, reg_v);
543 port_mtu_set(portid_t port_id, uint16_t mtu)
547 if (port_id_is_invalid(port_id))
549 diag = rte_eth_dev_set_mtu(port_id, mtu);
552 printf("Set MTU failed. diag=%d\n", diag);
556 * RX/TX ring descriptors display functions.
559 rx_queue_id_is_invalid(queueid_t rxq_id)
563 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
568 tx_queue_id_is_invalid(queueid_t txq_id)
572 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
577 rx_desc_id_is_invalid(uint16_t rxdesc_id)
579 if (rxdesc_id < nb_rxd)
581 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
587 tx_desc_id_is_invalid(uint16_t txdesc_id)
589 if (txdesc_id < nb_txd)
591 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
596 static const struct rte_memzone *
597 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
599 char mz_name[RTE_MEMZONE_NAMESIZE];
600 const struct rte_memzone *mz;
602 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
603 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
604 mz = rte_memzone_lookup(mz_name);
606 printf("%s ring memory zoneof (port %d, queue %d) not"
607 "found (zone name = %s\n",
608 ring_name, port_id, q_id, mz_name);
612 union igb_ring_dword {
620 struct igb_ring_desc_32_bytes {
621 union igb_ring_dword lo_dword;
622 union igb_ring_dword hi_dword;
623 union igb_ring_dword resv1;
624 union igb_ring_dword resv2;
627 struct igb_ring_desc_16_bytes {
628 union igb_ring_dword lo_dword;
629 union igb_ring_dword hi_dword;
633 ring_rxd_display_dword(union igb_ring_dword dword)
635 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
636 (unsigned)dword.words.hi);
640 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
641 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
644 __rte_unused uint8_t port_id,
648 struct igb_ring_desc_16_bytes *ring =
649 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
650 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
651 struct rte_eth_dev_info dev_info;
653 memset(&dev_info, 0, sizeof(dev_info));
654 rte_eth_dev_info_get(port_id, &dev_info);
655 if (strstr(dev_info.driver_name, "i40e") != NULL) {
656 /* 32 bytes RX descriptor, i40e only */
657 struct igb_ring_desc_32_bytes *ring =
658 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
660 ring_rxd_display_dword(rte_le_to_cpu_64(
661 ring[desc_id].lo_dword));
662 ring_rxd_display_dword(rte_le_to_cpu_64(
663 ring[desc_id].hi_dword));
664 ring_rxd_display_dword(rte_le_to_cpu_64(
665 ring[desc_id].resv1));
666 ring_rxd_display_dword(rte_le_to_cpu_64(
667 ring[desc_id].resv2));
671 /* 16 bytes RX descriptor */
672 ring_rxd_display_dword(rte_le_to_cpu_64(
673 ring[desc_id].lo_dword));
674 ring_rxd_display_dword(rte_le_to_cpu_64(
675 ring[desc_id].hi_dword));
679 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
681 struct igb_ring_desc_16_bytes *ring;
682 struct igb_ring_desc_16_bytes txd;
684 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
685 txd.lo_dword = rte_le_to_cpu_64(ring[desc_id].lo_dword);
686 txd.hi_dword = rte_le_to_cpu_64(ring[desc_id].hi_dword);
687 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
688 (unsigned)txd.lo_dword.words.lo,
689 (unsigned)txd.lo_dword.words.hi,
690 (unsigned)txd.hi_dword.words.lo,
691 (unsigned)txd.hi_dword.words.hi);
695 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
697 const struct rte_memzone *rx_mz;
699 if (port_id_is_invalid(port_id))
701 if (rx_queue_id_is_invalid(rxq_id))
703 if (rx_desc_id_is_invalid(rxd_id))
705 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
708 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
712 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
714 const struct rte_memzone *tx_mz;
716 if (port_id_is_invalid(port_id))
718 if (tx_queue_id_is_invalid(txq_id))
720 if (tx_desc_id_is_invalid(txd_id))
722 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
725 ring_tx_descriptor_display(tx_mz, txd_id);
729 fwd_lcores_config_display(void)
733 printf("List of forwarding lcores:");
734 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
735 printf(" %2u", fwd_lcores_cpuids[lc_id]);
739 rxtx_config_display(void)
741 printf(" %s packet forwarding - CRC stripping %s - "
742 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
743 rx_mode.hw_strip_crc ? "enabled" : "disabled",
746 if (cur_fwd_eng == &tx_only_engine)
747 printf(" packet len=%u - nb packet segments=%d\n",
748 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
750 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
751 nb_fwd_lcores, nb_fwd_ports);
752 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
753 nb_rxq, nb_rxd, rx_free_thresh);
754 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
755 rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh);
756 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
757 nb_txq, nb_txd, tx_free_thresh);
758 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
759 tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);
760 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
761 tx_rs_thresh, txq_flags);
765 port_rss_reta_info(portid_t port_id,struct rte_eth_rss_reta *reta_conf)
770 if (port_id_is_invalid(port_id))
773 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf);
775 printf("Failed to get RSS RETA info, return code = %d\n", ret);
779 if (reta_conf->mask_lo != 0) {
780 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
781 if (reta_conf->mask_lo & (uint64_t)(1ULL << i))
782 printf("RSS RETA configuration: hash index=%d,"
783 "queue=%d\n",i,reta_conf->reta[i]);
787 if (reta_conf->mask_hi != 0) {
788 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
789 if(reta_conf->mask_hi & (uint64_t)(1ULL << i)) {
790 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
791 printf("RSS RETA configuration: hash index=%d,"
792 "queue=%d\n",j,reta_conf->reta[j]);
799 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
803 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
805 struct rte_eth_rss_conf rss_conf;
806 uint8_t rss_key[10 * 4];
811 if (port_id_is_invalid(port_id))
813 /* Get RSS hash key if asked to display it */
814 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
815 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
819 printf("port index %d invalid\n", port_id);
822 printf("operation not supported by device\n");
825 printf("operation failed - diag=%d\n", diag);
830 rss_hf = rss_conf.rss_hf;
832 printf("RSS disabled\n");
835 printf("RSS functions:\n ");
836 if (rss_hf & ETH_RSS_IPV4)
838 if (rss_hf & ETH_RSS_IPV4_TCP)
840 if (rss_hf & ETH_RSS_IPV4_UDP)
842 if (rss_hf & ETH_RSS_IPV6)
844 if (rss_hf & ETH_RSS_IPV6_EX)
846 if (rss_hf & ETH_RSS_IPV6_TCP)
848 if (rss_hf & ETH_RSS_IPV6_TCP_EX)
850 if (rss_hf & ETH_RSS_IPV6_UDP)
852 if (rss_hf & ETH_RSS_IPV6_UDP_EX)
857 printf("RSS key:\n");
858 for (i = 0; i < sizeof(rss_key); i++)
859 printf("%02X", rss_key[i]);
864 port_rss_hash_key_update(portid_t port_id, uint8_t *hash_key)
866 struct rte_eth_rss_conf rss_conf;
869 rss_conf.rss_key = NULL;
870 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
872 rss_conf.rss_key = hash_key;
873 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
880 printf("port index %d invalid\n", port_id);
883 printf("operation not supported by device\n");
886 printf("operation failed - diag=%d\n", diag);
892 * Setup forwarding configuration for each logical core.
895 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
897 streamid_t nb_fs_per_lcore;
905 nb_fs = cfg->nb_fwd_streams;
906 nb_fc = cfg->nb_fwd_lcores;
907 if (nb_fs <= nb_fc) {
911 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
912 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
915 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
917 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
918 fwd_lcores[lc_id]->stream_idx = sm_id;
919 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
920 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
924 * Assign extra remaining streams, if any.
926 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
927 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
928 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
929 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
930 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
935 simple_fwd_config_setup(void)
941 if (port_topology == PORT_TOPOLOGY_CHAINED ||
942 port_topology == PORT_TOPOLOGY_LOOP) {
944 } else if (nb_fwd_ports % 2) {
945 printf("\nWarning! Cannot handle an odd number of ports "
946 "with the current port topology. Configuration "
947 "must be changed to have an even number of ports, "
948 "or relaunch application with "
949 "--port-topology=chained\n\n");
952 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
953 cur_fwd_config.nb_fwd_streams =
954 (streamid_t) cur_fwd_config.nb_fwd_ports;
956 /* reinitialize forwarding streams */
960 * In the simple forwarding test, the number of forwarding cores
961 * must be lower or equal to the number of forwarding ports.
963 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
964 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
965 cur_fwd_config.nb_fwd_lcores =
966 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
967 setup_fwd_config_of_each_lcore(&cur_fwd_config);
969 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
970 if (port_topology != PORT_TOPOLOGY_LOOP)
971 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
974 fwd_streams[i]->rx_port = fwd_ports_ids[i];
975 fwd_streams[i]->rx_queue = 0;
976 fwd_streams[i]->tx_port = fwd_ports_ids[j];
977 fwd_streams[i]->tx_queue = 0;
978 fwd_streams[i]->peer_addr = j;
980 if (port_topology == PORT_TOPOLOGY_PAIRED) {
981 fwd_streams[j]->rx_port = fwd_ports_ids[j];
982 fwd_streams[j]->rx_queue = 0;
983 fwd_streams[j]->tx_port = fwd_ports_ids[i];
984 fwd_streams[j]->tx_queue = 0;
985 fwd_streams[j]->peer_addr = i;
991 * For the RSS forwarding test, each core is assigned on every port a transmit
992 * queue whose index is the index of the core itself. This approach limits the
993 * maximumm number of processing cores of the RSS test to the maximum number of
994 * TX queues supported by the devices.
996 * Each core is assigned a single stream, each stream being composed of
997 * a RX queue to poll on a RX port for input messages, associated with
998 * a TX queue of a TX port where to send forwarded packets.
999 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1000 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1002 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1006 rss_fwd_config_setup(void)
1017 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1018 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1019 cur_fwd_config.nb_fwd_streams =
1020 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1021 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
1022 cur_fwd_config.nb_fwd_streams =
1023 (streamid_t)cur_fwd_config.nb_fwd_lcores;
1025 cur_fwd_config.nb_fwd_lcores =
1026 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1028 /* reinitialize forwarding streams */
1031 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1033 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1034 struct fwd_stream *fs;
1036 fs = fwd_streams[lc_id];
1038 if ((rxp & 0x1) == 0)
1039 txp = (portid_t) (rxp + 1);
1041 txp = (portid_t) (rxp - 1);
1043 * if we are in loopback, simply send stuff out through the
1046 if (port_topology == PORT_TOPOLOGY_LOOP)
1049 fs->rx_port = fwd_ports_ids[rxp];
1051 fs->tx_port = fwd_ports_ids[txp];
1053 fs->peer_addr = fs->tx_port;
1054 rxq = (queueid_t) (rxq + 1);
1059 * Restart from RX queue 0 on next RX port
1062 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1064 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1066 rxp = (portid_t) (rxp + 1);
1071 * In DCB and VT on,the mapping of 128 receive queues to 128 transmit queues.
1074 dcb_rxq_2_txq_mapping(queueid_t rxq, queueid_t *txq)
1076 if(dcb_q_mapping == DCB_4_TCS_Q_MAPPING) {
1081 else if (rxq < 64) {
1083 *txq = (uint16_t)(rxq + 32);
1086 /* tc2: 96-111;tc3:112-127 */
1087 *txq = (uint16_t)(rxq/2 + 64);
1094 else if (rxq < 32) {
1096 *txq = (uint16_t)(rxq + 16);
1098 else if (rxq < 64) {
1099 /*tc2,tc3 mapping */
1100 *txq = (uint16_t)(rxq + 32);
1103 /* tc4,tc5,tc6 and tc7 mapping */
1104 *txq = (uint16_t)(rxq/2 + 64);
1110 * For the DCB forwarding test, each core is assigned on every port multi-transmit
1113 * Each core is assigned a multi-stream, each stream being composed of
1114 * a RX queue to poll on a RX port for input messages, associated with
1115 * a TX queue of a TX port where to send forwarded packets.
1116 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1117 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1120 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1123 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1124 * There is a mapping of RxQj to TxQl to be required,and the mapping was implemented
1125 * in dcb_rxq_2_txq_mapping function.
1128 dcb_fwd_config_setup(void)
1139 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1140 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1141 cur_fwd_config.nb_fwd_streams =
1142 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1144 /* reinitialize forwarding streams */
1147 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1149 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1150 /* a fwd core can run multi-streams */
1151 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++)
1153 struct fwd_stream *fs;
1154 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1155 if ((rxp & 0x1) == 0)
1156 txp = (portid_t) (rxp + 1);
1158 txp = (portid_t) (rxp - 1);
1159 fs->rx_port = fwd_ports_ids[rxp];
1161 fs->tx_port = fwd_ports_ids[txp];
1162 if (dcb_q_mapping == DCB_VT_Q_MAPPING)
1165 dcb_rxq_2_txq_mapping(rxq, &fs->tx_queue);
1166 fs->peer_addr = fs->tx_port;
1167 rxq = (queueid_t) (rxq + 1);
1171 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1173 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1175 rxp = (portid_t) (rxp + 1);
1181 icmp_echo_config_setup(void)
1188 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1189 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1190 (nb_txq * nb_fwd_ports);
1192 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1193 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1194 cur_fwd_config.nb_fwd_streams =
1195 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1196 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1197 cur_fwd_config.nb_fwd_lcores =
1198 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1199 if (verbose_level > 0) {
1200 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1202 cur_fwd_config.nb_fwd_lcores,
1203 cur_fwd_config.nb_fwd_ports,
1204 cur_fwd_config.nb_fwd_streams);
1207 /* reinitialize forwarding streams */
1209 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1211 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1212 if (verbose_level > 0)
1213 printf(" core=%d: \n", lc_id);
1214 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1215 struct fwd_stream *fs;
1216 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1217 fs->rx_port = fwd_ports_ids[rxp];
1219 fs->tx_port = fs->rx_port;
1220 fs->tx_queue = lc_id;
1221 fs->peer_addr = fs->tx_port;
1222 if (verbose_level > 0)
1223 printf(" stream=%d port=%d rxq=%d txq=%d\n",
1224 sm_id, fs->rx_port, fs->rx_queue,
1226 rxq = (queueid_t) (rxq + 1);
1227 if (rxq == nb_rxq) {
1229 rxp = (portid_t) (rxp + 1);
1236 fwd_config_setup(void)
1238 cur_fwd_config.fwd_eng = cur_fwd_eng;
1239 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1240 icmp_echo_config_setup();
1243 if ((nb_rxq > 1) && (nb_txq > 1)){
1245 dcb_fwd_config_setup();
1247 rss_fwd_config_setup();
1250 simple_fwd_config_setup();
1254 pkt_fwd_config_display(struct fwd_config *cfg)
1256 struct fwd_stream *fs;
1260 printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
1261 "NUMA support %s, MP over anonymous pages %s\n",
1262 cfg->fwd_eng->fwd_mode_name,
1263 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1264 numa_support == 1 ? "enabled" : "disabled",
1265 mp_anon != 0 ? "enabled" : "disabled");
1267 if (strcmp(cfg->fwd_eng->fwd_mode_name, "mac_retry") == 0)
1268 printf("TX retry num: %u, delay between TX retries: %uus\n",
1269 burst_tx_retry_num, burst_tx_delay_time);
1270 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1271 printf("Logical Core %u (socket %u) forwards packets on "
1273 fwd_lcores_cpuids[lc_id],
1274 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1275 fwd_lcores[lc_id]->stream_nb);
1276 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1277 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1278 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
1279 "P=%d/Q=%d (socket %u) ",
1280 fs->rx_port, fs->rx_queue,
1281 ports[fs->rx_port].socket_id,
1282 fs->tx_port, fs->tx_queue,
1283 ports[fs->tx_port].socket_id);
1284 print_ethaddr("peer=",
1285 &peer_eth_addrs[fs->peer_addr]);
1294 fwd_config_display(void)
1296 if((dcb_config) && (nb_fwd_lcores == 1)) {
1297 printf("In DCB mode,the nb forwarding cores should be larger than 1\n");
1301 pkt_fwd_config_display(&cur_fwd_config);
1305 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1308 unsigned int lcore_cpuid;
1313 for (i = 0; i < nb_lc; i++) {
1314 lcore_cpuid = lcorelist[i];
1315 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1316 printf("lcore %u not enabled\n", lcore_cpuid);
1319 if (lcore_cpuid == rte_get_master_lcore()) {
1320 printf("lcore %u cannot be masked on for running "
1321 "packet forwarding, which is the master lcore "
1322 "and reserved for command line parsing only\n",
1327 fwd_lcores_cpuids[i] = lcore_cpuid;
1329 if (record_now == 0) {
1333 nb_cfg_lcores = (lcoreid_t) nb_lc;
1334 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1335 printf("previous number of forwarding cores %u - changed to "
1336 "number of configured cores %u\n",
1337 (unsigned int) nb_fwd_lcores, nb_lc);
1338 nb_fwd_lcores = (lcoreid_t) nb_lc;
1345 set_fwd_lcores_mask(uint64_t lcoremask)
1347 unsigned int lcorelist[64];
1351 if (lcoremask == 0) {
1352 printf("Invalid NULL mask of cores\n");
1356 for (i = 0; i < 64; i++) {
1357 if (! ((uint64_t)(1ULL << i) & lcoremask))
1359 lcorelist[nb_lc++] = i;
1361 return set_fwd_lcores_list(lcorelist, nb_lc);
1365 set_fwd_lcores_number(uint16_t nb_lc)
1367 if (nb_lc > nb_cfg_lcores) {
1368 printf("nb fwd cores %u > %u (max. number of configured "
1369 "lcores) - ignored\n",
1370 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1373 nb_fwd_lcores = (lcoreid_t) nb_lc;
1374 printf("Number of forwarding cores set to %u\n",
1375 (unsigned int) nb_fwd_lcores);
1379 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1387 for (i = 0; i < nb_pt; i++) {
1388 port_id = (portid_t) portlist[i];
1389 if (port_id >= nb_ports) {
1390 printf("Invalid port id %u >= %u\n",
1391 (unsigned int) port_id,
1392 (unsigned int) nb_ports);
1396 fwd_ports_ids[i] = port_id;
1398 if (record_now == 0) {
1402 nb_cfg_ports = (portid_t) nb_pt;
1403 if (nb_fwd_ports != (portid_t) nb_pt) {
1404 printf("previous number of forwarding ports %u - changed to "
1405 "number of configured ports %u\n",
1406 (unsigned int) nb_fwd_ports, nb_pt);
1407 nb_fwd_ports = (portid_t) nb_pt;
1412 set_fwd_ports_mask(uint64_t portmask)
1414 unsigned int portlist[64];
1418 if (portmask == 0) {
1419 printf("Invalid NULL mask of ports\n");
1423 for (i = 0; i < 64; i++) {
1424 if (! ((uint64_t)(1ULL << i) & portmask))
1426 portlist[nb_pt++] = i;
1428 set_fwd_ports_list(portlist, nb_pt);
1432 set_fwd_ports_number(uint16_t nb_pt)
1434 if (nb_pt > nb_cfg_ports) {
1435 printf("nb fwd ports %u > %u (number of configured "
1436 "ports) - ignored\n",
1437 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1440 nb_fwd_ports = (portid_t) nb_pt;
1441 printf("Number of forwarding ports set to %u\n",
1442 (unsigned int) nb_fwd_ports);
1446 set_nb_pkt_per_burst(uint16_t nb)
1448 if (nb > MAX_PKT_BURST) {
1449 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1451 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1454 nb_pkt_per_burst = nb;
1455 printf("Number of packets per burst set to %u\n",
1456 (unsigned int) nb_pkt_per_burst);
1460 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1462 uint16_t tx_pkt_len;
1465 if (nb_segs >= (unsigned) nb_txd) {
1466 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1467 nb_segs, (unsigned int) nb_txd);
1472 * Check that each segment length is greater or equal than
1473 * the mbuf data sise.
1474 * Check also that the total packet length is greater or equal than the
1475 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1478 for (i = 0; i < nb_segs; i++) {
1479 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1480 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1481 i, seg_lengths[i], (unsigned) mbuf_data_size);
1484 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1486 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1487 printf("total packet length=%u < %d - give up\n",
1488 (unsigned) tx_pkt_len,
1489 (int)(sizeof(struct ether_hdr) + 20 + 8));
1493 for (i = 0; i < nb_segs; i++)
1494 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1496 tx_pkt_length = tx_pkt_len;
1497 tx_pkt_nb_segs = (uint8_t) nb_segs;
1501 list_pkt_forwarding_modes(void)
1503 static char fwd_modes[128] = "";
1504 const char *separator = "|";
1505 struct fwd_engine *fwd_eng;
1508 if (strlen (fwd_modes) == 0) {
1509 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1510 strcat(fwd_modes, fwd_eng->fwd_mode_name);
1511 strcat(fwd_modes, separator);
1513 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1520 set_pkt_forwarding_mode(const char *fwd_mode_name)
1522 struct fwd_engine *fwd_eng;
1526 while ((fwd_eng = fwd_engines[i]) != NULL) {
1527 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1528 printf("Set %s packet forwarding mode\n",
1530 cur_fwd_eng = fwd_eng;
1535 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1539 set_verbose_level(uint16_t vb_level)
1541 printf("Change verbose level from %u to %u\n",
1542 (unsigned int) verbose_level, (unsigned int) vb_level);
1543 verbose_level = vb_level;
1547 vlan_extend_set(portid_t port_id, int on)
1552 if (port_id_is_invalid(port_id))
1555 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1558 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1560 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1562 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1564 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1565 "diag=%d\n", port_id, on, diag);
1569 rx_vlan_strip_set(portid_t port_id, int on)
1574 if (port_id_is_invalid(port_id))
1577 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1580 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1582 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1584 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1586 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1587 "diag=%d\n", port_id, on, diag);
1591 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1595 if (port_id_is_invalid(port_id))
1598 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1600 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1601 "diag=%d\n", port_id, queue_id, on, diag);
1605 rx_vlan_filter_set(portid_t port_id, int on)
1610 if (port_id_is_invalid(port_id))
1613 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1616 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1618 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1620 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1622 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1623 "diag=%d\n", port_id, on, diag);
1627 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1631 if (port_id_is_invalid(port_id))
1633 if (vlan_id_is_invalid(vlan_id))
1635 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1638 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1640 port_id, vlan_id, on, diag);
1644 rx_vlan_all_filter_set(portid_t port_id, int on)
1648 if (port_id_is_invalid(port_id))
1650 for (vlan_id = 0; vlan_id < 4096; vlan_id++)
1651 rx_vft_set(port_id, vlan_id, on);
1655 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1658 if (port_id_is_invalid(port_id))
1661 diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1665 printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1667 port_id, tp_id, diag);
1671 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1673 if (port_id_is_invalid(port_id))
1675 if (vlan_id_is_invalid(vlan_id))
1677 ports[port_id].tx_ol_flags |= PKT_TX_VLAN_PKT;
1678 ports[port_id].tx_vlan_id = vlan_id;
1682 tx_vlan_reset(portid_t port_id)
1684 if (port_id_is_invalid(port_id))
1686 ports[port_id].tx_ol_flags &= ~PKT_TX_VLAN_PKT;
1690 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
1692 if (port_id_is_invalid(port_id))
1695 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
1699 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1702 uint8_t existing_mapping_found = 0;
1704 if (port_id_is_invalid(port_id))
1707 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1710 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1711 printf("map_value not in required range 0..%d\n",
1712 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1716 if (!is_rx) { /*then tx*/
1717 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1718 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1719 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1720 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1721 existing_mapping_found = 1;
1725 if (!existing_mapping_found) { /* A new additional mapping... */
1726 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1727 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1728 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1729 nb_tx_queue_stats_mappings++;
1733 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1734 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1735 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1736 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1737 existing_mapping_found = 1;
1741 if (!existing_mapping_found) { /* A new additional mapping... */
1742 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1743 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1744 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1745 nb_rx_queue_stats_mappings++;
1751 tx_cksum_set(portid_t port_id, uint64_t ol_flags)
1753 uint64_t tx_ol_flags;
1754 if (port_id_is_invalid(port_id))
1756 /* Clear last 8 bits and then set L3/4 checksum mask again */
1757 tx_ol_flags = ports[port_id].tx_ol_flags & (~0x0FFull);
1758 ports[port_id].tx_ol_flags = ((ol_flags & 0xff) | tx_ol_flags);
1762 fdir_add_signature_filter(portid_t port_id, uint8_t queue_id,
1763 struct rte_fdir_filter *fdir_filter)
1767 if (port_id_is_invalid(port_id))
1770 diag = rte_eth_dev_fdir_add_signature_filter(port_id, fdir_filter,
1775 printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1776 "diag=%d\n", port_id, diag);
1780 fdir_update_signature_filter(portid_t port_id, uint8_t queue_id,
1781 struct rte_fdir_filter *fdir_filter)
1785 if (port_id_is_invalid(port_id))
1788 diag = rte_eth_dev_fdir_update_signature_filter(port_id, fdir_filter,
1793 printf("rte_eth_dev_fdir_update_signature_filter for port_id=%d failed "
1794 "diag=%d\n", port_id, diag);
1798 fdir_remove_signature_filter(portid_t port_id,
1799 struct rte_fdir_filter *fdir_filter)
1803 if (port_id_is_invalid(port_id))
1806 diag = rte_eth_dev_fdir_remove_signature_filter(port_id, fdir_filter);
1810 printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1811 "diag=%d\n", port_id, diag);
1816 fdir_get_infos(portid_t port_id)
1818 struct rte_eth_fdir fdir_infos;
1820 static const char *fdir_stats_border = "########################";
1822 if (port_id_is_invalid(port_id))
1825 rte_eth_dev_fdir_get_infos(port_id, &fdir_infos);
1827 printf("\n %s FDIR infos for port %-2d %s\n",
1828 fdir_stats_border, port_id, fdir_stats_border);
1830 printf(" collision: %-10"PRIu64" free: %"PRIu64"\n"
1831 " maxhash: %-10"PRIu64" maxlen: %"PRIu64"\n"
1832 " add: %-10"PRIu64" remove: %"PRIu64"\n"
1833 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
1834 (uint64_t)(fdir_infos.collision), (uint64_t)(fdir_infos.free),
1835 (uint64_t)(fdir_infos.maxhash), (uint64_t)(fdir_infos.maxlen),
1836 fdir_infos.add, fdir_infos.remove,
1837 fdir_infos.f_add, fdir_infos.f_remove);
1838 printf(" %s############################%s\n",
1839 fdir_stats_border, fdir_stats_border);
1843 fdir_add_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1844 uint8_t drop, struct rte_fdir_filter *fdir_filter)
1848 if (port_id_is_invalid(port_id))
1851 diag = rte_eth_dev_fdir_add_perfect_filter(port_id, fdir_filter,
1852 soft_id, queue_id, drop);
1856 printf("rte_eth_dev_fdir_add_perfect_filter for port_id=%d failed "
1857 "diag=%d\n", port_id, diag);
1861 fdir_update_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1862 uint8_t drop, struct rte_fdir_filter *fdir_filter)
1866 if (port_id_is_invalid(port_id))
1869 diag = rte_eth_dev_fdir_update_perfect_filter(port_id, fdir_filter,
1870 soft_id, queue_id, drop);
1874 printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1875 "diag=%d\n", port_id, diag);
1879 fdir_remove_perfect_filter(portid_t port_id, uint16_t soft_id,
1880 struct rte_fdir_filter *fdir_filter)
1884 if (port_id_is_invalid(port_id))
1887 diag = rte_eth_dev_fdir_remove_perfect_filter(port_id, fdir_filter,
1892 printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1893 "diag=%d\n", port_id, diag);
1897 fdir_set_masks(portid_t port_id, struct rte_fdir_masks *fdir_masks)
1901 if (port_id_is_invalid(port_id))
1904 diag = rte_eth_dev_fdir_set_masks(port_id, fdir_masks);
1908 printf("rte_eth_dev_set_masks_filter for port_id=%d failed "
1909 "diag=%d\n", port_id, diag);
1913 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
1917 if (port_id_is_invalid(port_id))
1920 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
1922 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
1926 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
1927 "diag=%d\n", port_id, diag);
1929 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
1930 "diag=%d\n", port_id, diag);
1935 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
1939 if (port_id_is_invalid(port_id))
1941 if (vlan_id_is_invalid(vlan_id))
1943 diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
1946 printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
1947 "diag=%d\n", port_id, diag);
1951 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
1954 struct rte_eth_link link;
1956 if (port_id_is_invalid(port_id))
1958 rte_eth_link_get_nowait(port_id, &link);
1959 if (rate > link.link_speed) {
1960 printf("Invalid rate value:%u bigger than link speed: %u\n",
1961 rate, link.link_speed);
1964 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
1967 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
1973 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
1976 struct rte_eth_link link;
1981 if (port_id_is_invalid(port_id))
1983 rte_eth_link_get_nowait(port_id, &link);
1984 if (rate > link.link_speed) {
1985 printf("Invalid rate value:%u bigger than link speed: %u\n",
1986 rate, link.link_speed);
1989 diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
1992 printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",
1998 get_ethertype_filter(uint8_t port_id, uint16_t index)
2000 struct rte_ethertype_filter filter;
2004 memset(&filter, 0, sizeof(filter));
2005 ret = rte_eth_dev_get_ethertype_filter(port_id, index,
2006 &filter, &rx_queue);
2008 if (ret == (-ENOENT))
2009 printf("filter[%d] is not enabled\n", index);
2011 printf("get ethertype filter fails(%s)\n", strerror(-ret));
2014 printf("filter[%d]:\n", index);
2015 printf(" ethertype: 0x%04x\n",
2016 rte_le_to_cpu_32(filter.ethertype));
2017 printf(" priority: %s, %d\n",
2018 filter.priority_en ? "enable" : "disable",
2020 printf(" queue: %d\n", rx_queue);
2025 get_syn_filter(uint8_t port_id)
2027 struct rte_syn_filter filter;
2031 memset(&filter, 0, sizeof(filter));
2032 ret = rte_eth_dev_get_syn_filter(port_id, &filter, &rx_queue);
2035 if (ret == (-ENOENT))
2036 printf("syn filter is not enabled\n");
2038 printf("get syn filter fails(%s)\n", strerror(-ret));
2041 printf("syn filter: priority: %s, queue: %d\n",
2042 filter.hig_pri ? "high" : "low",
2046 get_2tuple_filter(uint8_t port_id, uint16_t index)
2048 struct rte_2tuple_filter filter;
2052 memset(&filter, 0, sizeof(filter));
2053 ret = rte_eth_dev_get_2tuple_filter(port_id, index,
2054 &filter, &rx_queue);
2056 if (ret == (-ENOENT))
2057 printf("filter[%d] is not enabled\n", index);
2059 printf("get 2tuple filter fails(%s)\n", strerror(-ret));
2062 printf("filter[%d]:\n", index);
2063 printf(" Destination Port: 0x%04x mask: %d\n",
2064 rte_be_to_cpu_16(filter.dst_port),
2065 filter.dst_port_mask ? 0 : 1);
2066 printf(" protocol: 0x%02x mask:%d tcp_flags: 0x%02x\n",
2067 filter.protocol, filter.protocol_mask ? 0 : 1,
2069 printf(" priority: %d queue: %d\n",
2070 filter.priority, rx_queue);
2075 get_5tuple_filter(uint8_t port_id, uint16_t index)
2077 struct rte_5tuple_filter filter;
2081 memset(&filter, 0, sizeof(filter));
2082 ret = rte_eth_dev_get_5tuple_filter(port_id, index,
2083 &filter, &rx_queue);
2085 if (ret == (-ENOENT))
2086 printf("filter[%d] is not enabled\n", index);
2088 printf("get 5tuple filter fails(%s)\n", strerror(-ret));
2091 printf("filter[%d]:\n", index);
2092 printf(" Destination IP: 0x%08x mask: %d\n",
2093 (unsigned)rte_be_to_cpu_32(filter.dst_ip),
2094 filter.dst_ip_mask ? 0 : 1);
2095 printf(" Source IP: 0x%08x mask: %d\n",
2096 (unsigned)rte_be_to_cpu_32(filter.src_ip),
2097 filter.src_ip_mask ? 0 : 1);
2098 printf(" Destination Port: 0x%04x mask: %d\n",
2099 rte_be_to_cpu_16(filter.dst_port),
2100 filter.dst_port_mask ? 0 : 1);
2101 printf(" Source Port: 0x%04x mask: %d\n",
2102 rte_be_to_cpu_16(filter.src_port),
2103 filter.src_port_mask ? 0 : 1);
2104 printf(" protocol: 0x%02x mask: %d\n",
2106 filter.protocol_mask ? 0 : 1);
2107 printf(" priority: %d flags: 0x%02x queue: %d\n",
2108 filter.priority, filter.tcp_flags, rx_queue);
2112 get_flex_filter(uint8_t port_id, uint16_t index)
2115 struct rte_flex_filter filter;
2120 memset(&filter, 0, sizeof(filter));
2121 ret = rte_eth_dev_get_flex_filter(port_id, index,
2122 &filter, &rx_queue);
2124 if (ret == (-ENOENT))
2125 printf("filter[%d] is not enabled\n", index);
2127 printf("get flex filter fails(%s)\n", strerror(-ret));
2130 printf("filter[%d]: ", index);
2131 printf("\n length: %d", filter.len);
2132 printf("\n dword[]: 0x");
2133 for (i = 0; i < 32; i++)
2134 printf("%08x ", (unsigned)rte_be_to_cpu_32(filter.dwords[i]));
2135 printf("\n mask[]: 0b");
2136 for (i = 0; i < 16; i++) {
2137 for (j = 0; j < 8; j++)
2138 printf("%c", (filter.mask[i] & (1 << j)) ? '1' : '0');
2140 printf("\n priority: %d queue: %d\n",
2141 filter.priority, rx_queue);