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);
353 port_id_is_invalid(portid_t port_id)
355 if (port_id < nb_ports)
357 printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
362 vlan_id_is_invalid(uint16_t vlan_id)
366 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
371 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
376 printf("Port register offset 0x%X not aligned on a 4-byte "
381 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
382 if (reg_off >= pci_len) {
383 printf("Port %d: register offset %u (0x%X) out of port PCI "
384 "resource (length=%"PRIu64")\n",
385 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
392 reg_bit_pos_is_invalid(uint8_t bit_pos)
396 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
400 #define display_port_and_reg_off(port_id, reg_off) \
401 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
404 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
406 display_port_and_reg_off(port_id, (unsigned)reg_off);
407 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
411 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
416 if (port_id_is_invalid(port_id))
418 if (port_reg_off_is_invalid(port_id, reg_off))
420 if (reg_bit_pos_is_invalid(bit_x))
422 reg_v = port_id_pci_reg_read(port_id, reg_off);
423 display_port_and_reg_off(port_id, (unsigned)reg_off);
424 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
428 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
429 uint8_t bit1_pos, uint8_t bit2_pos)
435 if (port_id_is_invalid(port_id))
437 if (port_reg_off_is_invalid(port_id, reg_off))
439 if (reg_bit_pos_is_invalid(bit1_pos))
441 if (reg_bit_pos_is_invalid(bit2_pos))
443 if (bit1_pos > bit2_pos)
444 l_bit = bit2_pos, h_bit = bit1_pos;
446 l_bit = bit1_pos, h_bit = bit2_pos;
448 reg_v = port_id_pci_reg_read(port_id, reg_off);
451 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
452 display_port_and_reg_off(port_id, (unsigned)reg_off);
453 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
454 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
458 port_reg_display(portid_t port_id, uint32_t reg_off)
462 if (port_id_is_invalid(port_id))
464 if (port_reg_off_is_invalid(port_id, reg_off))
466 reg_v = port_id_pci_reg_read(port_id, reg_off);
467 display_port_reg_value(port_id, reg_off, reg_v);
471 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
476 if (port_id_is_invalid(port_id))
478 if (port_reg_off_is_invalid(port_id, reg_off))
480 if (reg_bit_pos_is_invalid(bit_pos))
483 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
486 reg_v = port_id_pci_reg_read(port_id, reg_off);
488 reg_v &= ~(1 << bit_pos);
490 reg_v |= (1 << bit_pos);
491 port_id_pci_reg_write(port_id, reg_off, reg_v);
492 display_port_reg_value(port_id, reg_off, reg_v);
496 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
497 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
504 if (port_id_is_invalid(port_id))
506 if (port_reg_off_is_invalid(port_id, reg_off))
508 if (reg_bit_pos_is_invalid(bit1_pos))
510 if (reg_bit_pos_is_invalid(bit2_pos))
512 if (bit1_pos > bit2_pos)
513 l_bit = bit2_pos, h_bit = bit1_pos;
515 l_bit = bit1_pos, h_bit = bit2_pos;
517 if ((h_bit - l_bit) < 31)
518 max_v = (1 << (h_bit - l_bit + 1)) - 1;
523 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
524 (unsigned)value, (unsigned)value,
525 (unsigned)max_v, (unsigned)max_v);
528 reg_v = port_id_pci_reg_read(port_id, reg_off);
529 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
530 reg_v |= (value << l_bit); /* Set changed bits */
531 port_id_pci_reg_write(port_id, reg_off, reg_v);
532 display_port_reg_value(port_id, reg_off, reg_v);
536 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
538 if (port_id_is_invalid(port_id))
540 if (port_reg_off_is_invalid(port_id, reg_off))
542 port_id_pci_reg_write(port_id, reg_off, reg_v);
543 display_port_reg_value(port_id, reg_off, reg_v);
547 port_mtu_set(portid_t port_id, uint16_t mtu)
551 if (port_id_is_invalid(port_id))
553 diag = rte_eth_dev_set_mtu(port_id, mtu);
556 printf("Set MTU failed. diag=%d\n", diag);
560 * RX/TX ring descriptors display functions.
563 rx_queue_id_is_invalid(queueid_t rxq_id)
567 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
572 tx_queue_id_is_invalid(queueid_t txq_id)
576 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
581 rx_desc_id_is_invalid(uint16_t rxdesc_id)
583 if (rxdesc_id < nb_rxd)
585 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
591 tx_desc_id_is_invalid(uint16_t txdesc_id)
593 if (txdesc_id < nb_txd)
595 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
600 static const struct rte_memzone *
601 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
603 char mz_name[RTE_MEMZONE_NAMESIZE];
604 const struct rte_memzone *mz;
606 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
607 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
608 mz = rte_memzone_lookup(mz_name);
610 printf("%s ring memory zoneof (port %d, queue %d) not"
611 "found (zone name = %s\n",
612 ring_name, port_id, q_id, mz_name);
616 union igb_ring_dword {
619 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
629 struct igb_ring_desc_32_bytes {
630 union igb_ring_dword lo_dword;
631 union igb_ring_dword hi_dword;
632 union igb_ring_dword resv1;
633 union igb_ring_dword resv2;
636 struct igb_ring_desc_16_bytes {
637 union igb_ring_dword lo_dword;
638 union igb_ring_dword hi_dword;
642 ring_rxd_display_dword(union igb_ring_dword dword)
644 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
645 (unsigned)dword.words.hi);
649 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
650 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
653 __rte_unused uint8_t port_id,
657 struct igb_ring_desc_16_bytes *ring =
658 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
659 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
660 struct rte_eth_dev_info dev_info;
662 memset(&dev_info, 0, sizeof(dev_info));
663 rte_eth_dev_info_get(port_id, &dev_info);
664 if (strstr(dev_info.driver_name, "i40e") != NULL) {
665 /* 32 bytes RX descriptor, i40e only */
666 struct igb_ring_desc_32_bytes *ring =
667 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
668 ring[desc_id].lo_dword.dword =
669 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
670 ring_rxd_display_dword(ring[desc_id].lo_dword);
671 ring[desc_id].hi_dword.dword =
672 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
673 ring_rxd_display_dword(ring[desc_id].hi_dword);
674 ring[desc_id].resv1.dword =
675 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
676 ring_rxd_display_dword(ring[desc_id].resv1);
677 ring[desc_id].resv2.dword =
678 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
679 ring_rxd_display_dword(ring[desc_id].resv2);
684 /* 16 bytes RX descriptor */
685 ring[desc_id].lo_dword.dword =
686 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
687 ring_rxd_display_dword(ring[desc_id].lo_dword);
688 ring[desc_id].hi_dword.dword =
689 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
690 ring_rxd_display_dword(ring[desc_id].hi_dword);
694 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
696 struct igb_ring_desc_16_bytes *ring;
697 struct igb_ring_desc_16_bytes txd;
699 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
700 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
701 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
702 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
703 (unsigned)txd.lo_dword.words.lo,
704 (unsigned)txd.lo_dword.words.hi,
705 (unsigned)txd.hi_dword.words.lo,
706 (unsigned)txd.hi_dword.words.hi);
710 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
712 const struct rte_memzone *rx_mz;
714 if (port_id_is_invalid(port_id))
716 if (rx_queue_id_is_invalid(rxq_id))
718 if (rx_desc_id_is_invalid(rxd_id))
720 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
723 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
727 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
729 const struct rte_memzone *tx_mz;
731 if (port_id_is_invalid(port_id))
733 if (tx_queue_id_is_invalid(txq_id))
735 if (tx_desc_id_is_invalid(txd_id))
737 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
740 ring_tx_descriptor_display(tx_mz, txd_id);
744 fwd_lcores_config_display(void)
748 printf("List of forwarding lcores:");
749 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
750 printf(" %2u", fwd_lcores_cpuids[lc_id]);
754 rxtx_config_display(void)
756 printf(" %s packet forwarding - CRC stripping %s - "
757 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
758 rx_mode.hw_strip_crc ? "enabled" : "disabled",
761 if (cur_fwd_eng == &tx_only_engine)
762 printf(" packet len=%u - nb packet segments=%d\n",
763 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
765 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
766 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
768 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
769 nb_fwd_lcores, nb_fwd_ports);
770 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
771 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
772 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
773 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
774 rx_conf->rx_thresh.wthresh);
775 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
776 nb_txq, nb_txd, tx_conf->tx_free_thresh);
777 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
778 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
779 tx_conf->tx_thresh.wthresh);
780 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
781 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
785 port_rss_reta_info(portid_t port_id,
786 struct rte_eth_rss_reta_entry64 *reta_conf,
789 uint16_t i, idx, shift;
792 if (port_id_is_invalid(port_id))
795 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
797 printf("Failed to get RSS RETA info, return code = %d\n", ret);
801 for (i = 0; i < nb_entries; i++) {
802 idx = i / RTE_RETA_GROUP_SIZE;
803 shift = i % RTE_RETA_GROUP_SIZE;
804 if (!(reta_conf[idx].mask & (1ULL << shift)))
806 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
807 i, reta_conf[idx].reta[shift]);
812 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
816 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
818 struct rte_eth_rss_conf rss_conf;
819 uint8_t rss_key[10 * 4];
824 if (port_id_is_invalid(port_id))
826 /* Get RSS hash key if asked to display it */
827 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
828 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
832 printf("port index %d invalid\n", port_id);
835 printf("operation not supported by device\n");
838 printf("operation failed - diag=%d\n", diag);
843 rss_hf = rss_conf.rss_hf;
845 printf("RSS disabled\n");
848 printf("RSS functions:\n ");
849 if (rss_hf & ETH_RSS_IPV4)
851 if (rss_hf & ETH_RSS_IPV4_TCP)
853 if (rss_hf & ETH_RSS_IPV4_UDP)
855 if (rss_hf & ETH_RSS_IPV6)
857 if (rss_hf & ETH_RSS_IPV6_EX)
859 if (rss_hf & ETH_RSS_IPV6_TCP)
861 if (rss_hf & ETH_RSS_IPV6_TCP_EX)
863 if (rss_hf & ETH_RSS_IPV6_UDP)
865 if (rss_hf & ETH_RSS_IPV6_UDP_EX)
870 printf("RSS key:\n");
871 for (i = 0; i < sizeof(rss_key); i++)
872 printf("%02X", rss_key[i]);
877 port_rss_hash_key_update(portid_t port_id, uint8_t *hash_key)
879 struct rte_eth_rss_conf rss_conf;
882 rss_conf.rss_key = NULL;
883 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
885 rss_conf.rss_key = hash_key;
886 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
893 printf("port index %d invalid\n", port_id);
896 printf("operation not supported by device\n");
899 printf("operation failed - diag=%d\n", diag);
905 * Setup forwarding configuration for each logical core.
908 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
910 streamid_t nb_fs_per_lcore;
918 nb_fs = cfg->nb_fwd_streams;
919 nb_fc = cfg->nb_fwd_lcores;
920 if (nb_fs <= nb_fc) {
924 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
925 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
928 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
930 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
931 fwd_lcores[lc_id]->stream_idx = sm_id;
932 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
933 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
937 * Assign extra remaining streams, if any.
939 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
940 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
941 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
942 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
943 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
948 simple_fwd_config_setup(void)
954 if (port_topology == PORT_TOPOLOGY_CHAINED ||
955 port_topology == PORT_TOPOLOGY_LOOP) {
957 } else if (nb_fwd_ports % 2) {
958 printf("\nWarning! Cannot handle an odd number of ports "
959 "with the current port topology. Configuration "
960 "must be changed to have an even number of ports, "
961 "or relaunch application with "
962 "--port-topology=chained\n\n");
965 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
966 cur_fwd_config.nb_fwd_streams =
967 (streamid_t) cur_fwd_config.nb_fwd_ports;
969 /* reinitialize forwarding streams */
973 * In the simple forwarding test, the number of forwarding cores
974 * must be lower or equal to the number of forwarding ports.
976 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
977 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
978 cur_fwd_config.nb_fwd_lcores =
979 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
980 setup_fwd_config_of_each_lcore(&cur_fwd_config);
982 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
983 if (port_topology != PORT_TOPOLOGY_LOOP)
984 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
987 fwd_streams[i]->rx_port = fwd_ports_ids[i];
988 fwd_streams[i]->rx_queue = 0;
989 fwd_streams[i]->tx_port = fwd_ports_ids[j];
990 fwd_streams[i]->tx_queue = 0;
991 fwd_streams[i]->peer_addr = j;
993 if (port_topology == PORT_TOPOLOGY_PAIRED) {
994 fwd_streams[j]->rx_port = fwd_ports_ids[j];
995 fwd_streams[j]->rx_queue = 0;
996 fwd_streams[j]->tx_port = fwd_ports_ids[i];
997 fwd_streams[j]->tx_queue = 0;
998 fwd_streams[j]->peer_addr = i;
1004 * For the RSS forwarding test, each core is assigned on every port a transmit
1005 * queue whose index is the index of the core itself. This approach limits the
1006 * maximumm number of processing cores of the RSS test to the maximum number of
1007 * TX queues supported by the devices.
1009 * Each core is assigned a single stream, each stream being composed of
1010 * a RX queue to poll on a RX port for input messages, associated with
1011 * a TX queue of a TX port where to send forwarded packets.
1012 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1013 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1015 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1019 rss_fwd_config_setup(void)
1030 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1031 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1032 cur_fwd_config.nb_fwd_streams =
1033 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1034 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
1035 cur_fwd_config.nb_fwd_streams =
1036 (streamid_t)cur_fwd_config.nb_fwd_lcores;
1038 cur_fwd_config.nb_fwd_lcores =
1039 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1041 /* reinitialize forwarding streams */
1044 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1046 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1047 struct fwd_stream *fs;
1049 fs = fwd_streams[lc_id];
1051 if ((rxp & 0x1) == 0)
1052 txp = (portid_t) (rxp + 1);
1054 txp = (portid_t) (rxp - 1);
1056 * if we are in loopback, simply send stuff out through the
1059 if (port_topology == PORT_TOPOLOGY_LOOP)
1062 fs->rx_port = fwd_ports_ids[rxp];
1064 fs->tx_port = fwd_ports_ids[txp];
1066 fs->peer_addr = fs->tx_port;
1067 rxq = (queueid_t) (rxq + 1);
1072 * Restart from RX queue 0 on next RX port
1075 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1077 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1079 rxp = (portid_t) (rxp + 1);
1084 * In DCB and VT on,the mapping of 128 receive queues to 128 transmit queues.
1087 dcb_rxq_2_txq_mapping(queueid_t rxq, queueid_t *txq)
1089 if(dcb_q_mapping == DCB_4_TCS_Q_MAPPING) {
1094 else if (rxq < 64) {
1096 *txq = (uint16_t)(rxq + 32);
1099 /* tc2: 96-111;tc3:112-127 */
1100 *txq = (uint16_t)(rxq/2 + 64);
1107 else if (rxq < 32) {
1109 *txq = (uint16_t)(rxq + 16);
1111 else if (rxq < 64) {
1112 /*tc2,tc3 mapping */
1113 *txq = (uint16_t)(rxq + 32);
1116 /* tc4,tc5,tc6 and tc7 mapping */
1117 *txq = (uint16_t)(rxq/2 + 64);
1123 * For the DCB forwarding test, each core is assigned on every port multi-transmit
1126 * Each core is assigned a multi-stream, each stream being composed of
1127 * a RX queue to poll on a RX port for input messages, associated with
1128 * a TX queue of a TX port where to send forwarded packets.
1129 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1130 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1133 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1136 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1137 * There is a mapping of RxQj to TxQl to be required,and the mapping was implemented
1138 * in dcb_rxq_2_txq_mapping function.
1141 dcb_fwd_config_setup(void)
1152 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1153 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1154 cur_fwd_config.nb_fwd_streams =
1155 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1157 /* reinitialize forwarding streams */
1160 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1162 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1163 /* a fwd core can run multi-streams */
1164 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++)
1166 struct fwd_stream *fs;
1167 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1168 if ((rxp & 0x1) == 0)
1169 txp = (portid_t) (rxp + 1);
1171 txp = (portid_t) (rxp - 1);
1172 fs->rx_port = fwd_ports_ids[rxp];
1174 fs->tx_port = fwd_ports_ids[txp];
1175 if (dcb_q_mapping == DCB_VT_Q_MAPPING)
1178 dcb_rxq_2_txq_mapping(rxq, &fs->tx_queue);
1179 fs->peer_addr = fs->tx_port;
1180 rxq = (queueid_t) (rxq + 1);
1184 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1186 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1188 rxp = (portid_t) (rxp + 1);
1194 icmp_echo_config_setup(void)
1201 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1202 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1203 (nb_txq * nb_fwd_ports);
1205 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1206 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1207 cur_fwd_config.nb_fwd_streams =
1208 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1209 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1210 cur_fwd_config.nb_fwd_lcores =
1211 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1212 if (verbose_level > 0) {
1213 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1215 cur_fwd_config.nb_fwd_lcores,
1216 cur_fwd_config.nb_fwd_ports,
1217 cur_fwd_config.nb_fwd_streams);
1220 /* reinitialize forwarding streams */
1222 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1224 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1225 if (verbose_level > 0)
1226 printf(" core=%d: \n", lc_id);
1227 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1228 struct fwd_stream *fs;
1229 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1230 fs->rx_port = fwd_ports_ids[rxp];
1232 fs->tx_port = fs->rx_port;
1233 fs->tx_queue = lc_id;
1234 fs->peer_addr = fs->tx_port;
1235 if (verbose_level > 0)
1236 printf(" stream=%d port=%d rxq=%d txq=%d\n",
1237 sm_id, fs->rx_port, fs->rx_queue,
1239 rxq = (queueid_t) (rxq + 1);
1240 if (rxq == nb_rxq) {
1242 rxp = (portid_t) (rxp + 1);
1249 fwd_config_setup(void)
1251 cur_fwd_config.fwd_eng = cur_fwd_eng;
1252 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1253 icmp_echo_config_setup();
1256 if ((nb_rxq > 1) && (nb_txq > 1)){
1258 dcb_fwd_config_setup();
1260 rss_fwd_config_setup();
1263 simple_fwd_config_setup();
1267 pkt_fwd_config_display(struct fwd_config *cfg)
1269 struct fwd_stream *fs;
1273 printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
1274 "NUMA support %s, MP over anonymous pages %s\n",
1275 cfg->fwd_eng->fwd_mode_name,
1276 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1277 numa_support == 1 ? "enabled" : "disabled",
1278 mp_anon != 0 ? "enabled" : "disabled");
1280 if (strcmp(cfg->fwd_eng->fwd_mode_name, "mac_retry") == 0)
1281 printf("TX retry num: %u, delay between TX retries: %uus\n",
1282 burst_tx_retry_num, burst_tx_delay_time);
1283 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1284 printf("Logical Core %u (socket %u) forwards packets on "
1286 fwd_lcores_cpuids[lc_id],
1287 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1288 fwd_lcores[lc_id]->stream_nb);
1289 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1290 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1291 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
1292 "P=%d/Q=%d (socket %u) ",
1293 fs->rx_port, fs->rx_queue,
1294 ports[fs->rx_port].socket_id,
1295 fs->tx_port, fs->tx_queue,
1296 ports[fs->tx_port].socket_id);
1297 print_ethaddr("peer=",
1298 &peer_eth_addrs[fs->peer_addr]);
1307 fwd_config_display(void)
1309 if((dcb_config) && (nb_fwd_lcores == 1)) {
1310 printf("In DCB mode,the nb forwarding cores should be larger than 1\n");
1314 pkt_fwd_config_display(&cur_fwd_config);
1318 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1321 unsigned int lcore_cpuid;
1326 for (i = 0; i < nb_lc; i++) {
1327 lcore_cpuid = lcorelist[i];
1328 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1329 printf("lcore %u not enabled\n", lcore_cpuid);
1332 if (lcore_cpuid == rte_get_master_lcore()) {
1333 printf("lcore %u cannot be masked on for running "
1334 "packet forwarding, which is the master lcore "
1335 "and reserved for command line parsing only\n",
1340 fwd_lcores_cpuids[i] = lcore_cpuid;
1342 if (record_now == 0) {
1346 nb_cfg_lcores = (lcoreid_t) nb_lc;
1347 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1348 printf("previous number of forwarding cores %u - changed to "
1349 "number of configured cores %u\n",
1350 (unsigned int) nb_fwd_lcores, nb_lc);
1351 nb_fwd_lcores = (lcoreid_t) nb_lc;
1358 set_fwd_lcores_mask(uint64_t lcoremask)
1360 unsigned int lcorelist[64];
1364 if (lcoremask == 0) {
1365 printf("Invalid NULL mask of cores\n");
1369 for (i = 0; i < 64; i++) {
1370 if (! ((uint64_t)(1ULL << i) & lcoremask))
1372 lcorelist[nb_lc++] = i;
1374 return set_fwd_lcores_list(lcorelist, nb_lc);
1378 set_fwd_lcores_number(uint16_t nb_lc)
1380 if (nb_lc > nb_cfg_lcores) {
1381 printf("nb fwd cores %u > %u (max. number of configured "
1382 "lcores) - ignored\n",
1383 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1386 nb_fwd_lcores = (lcoreid_t) nb_lc;
1387 printf("Number of forwarding cores set to %u\n",
1388 (unsigned int) nb_fwd_lcores);
1392 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1400 for (i = 0; i < nb_pt; i++) {
1401 port_id = (portid_t) portlist[i];
1402 if (port_id >= nb_ports) {
1403 printf("Invalid port id %u >= %u\n",
1404 (unsigned int) port_id,
1405 (unsigned int) nb_ports);
1409 fwd_ports_ids[i] = port_id;
1411 if (record_now == 0) {
1415 nb_cfg_ports = (portid_t) nb_pt;
1416 if (nb_fwd_ports != (portid_t) nb_pt) {
1417 printf("previous number of forwarding ports %u - changed to "
1418 "number of configured ports %u\n",
1419 (unsigned int) nb_fwd_ports, nb_pt);
1420 nb_fwd_ports = (portid_t) nb_pt;
1425 set_fwd_ports_mask(uint64_t portmask)
1427 unsigned int portlist[64];
1431 if (portmask == 0) {
1432 printf("Invalid NULL mask of ports\n");
1436 for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
1437 if (! ((uint64_t)(1ULL << i) & portmask))
1439 portlist[nb_pt++] = i;
1441 set_fwd_ports_list(portlist, nb_pt);
1445 set_fwd_ports_number(uint16_t nb_pt)
1447 if (nb_pt > nb_cfg_ports) {
1448 printf("nb fwd ports %u > %u (number of configured "
1449 "ports) - ignored\n",
1450 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1453 nb_fwd_ports = (portid_t) nb_pt;
1454 printf("Number of forwarding ports set to %u\n",
1455 (unsigned int) nb_fwd_ports);
1459 set_nb_pkt_per_burst(uint16_t nb)
1461 if (nb > MAX_PKT_BURST) {
1462 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1464 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1467 nb_pkt_per_burst = nb;
1468 printf("Number of packets per burst set to %u\n",
1469 (unsigned int) nb_pkt_per_burst);
1473 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1475 uint16_t tx_pkt_len;
1478 if (nb_segs >= (unsigned) nb_txd) {
1479 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1480 nb_segs, (unsigned int) nb_txd);
1485 * Check that each segment length is greater or equal than
1486 * the mbuf data sise.
1487 * Check also that the total packet length is greater or equal than the
1488 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1491 for (i = 0; i < nb_segs; i++) {
1492 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1493 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1494 i, seg_lengths[i], (unsigned) mbuf_data_size);
1497 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1499 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1500 printf("total packet length=%u < %d - give up\n",
1501 (unsigned) tx_pkt_len,
1502 (int)(sizeof(struct ether_hdr) + 20 + 8));
1506 for (i = 0; i < nb_segs; i++)
1507 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1509 tx_pkt_length = tx_pkt_len;
1510 tx_pkt_nb_segs = (uint8_t) nb_segs;
1514 list_pkt_forwarding_modes(void)
1516 static char fwd_modes[128] = "";
1517 const char *separator = "|";
1518 struct fwd_engine *fwd_eng;
1521 if (strlen (fwd_modes) == 0) {
1522 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1523 strcat(fwd_modes, fwd_eng->fwd_mode_name);
1524 strcat(fwd_modes, separator);
1526 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1533 set_pkt_forwarding_mode(const char *fwd_mode_name)
1535 struct fwd_engine *fwd_eng;
1539 while ((fwd_eng = fwd_engines[i]) != NULL) {
1540 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1541 printf("Set %s packet forwarding mode\n",
1543 cur_fwd_eng = fwd_eng;
1548 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1552 set_verbose_level(uint16_t vb_level)
1554 printf("Change verbose level from %u to %u\n",
1555 (unsigned int) verbose_level, (unsigned int) vb_level);
1556 verbose_level = vb_level;
1560 vlan_extend_set(portid_t port_id, int on)
1565 if (port_id_is_invalid(port_id))
1568 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1571 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1573 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1575 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1577 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1578 "diag=%d\n", port_id, on, diag);
1582 rx_vlan_strip_set(portid_t port_id, int on)
1587 if (port_id_is_invalid(port_id))
1590 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1593 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1595 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1597 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1599 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1600 "diag=%d\n", port_id, on, diag);
1604 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1608 if (port_id_is_invalid(port_id))
1611 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1613 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1614 "diag=%d\n", port_id, queue_id, on, diag);
1618 rx_vlan_filter_set(portid_t port_id, int on)
1623 if (port_id_is_invalid(port_id))
1626 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1629 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1631 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1633 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1635 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1636 "diag=%d\n", port_id, on, diag);
1640 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1644 if (port_id_is_invalid(port_id))
1646 if (vlan_id_is_invalid(vlan_id))
1648 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1651 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1653 port_id, vlan_id, on, diag);
1657 rx_vlan_all_filter_set(portid_t port_id, int on)
1661 if (port_id_is_invalid(port_id))
1663 for (vlan_id = 0; vlan_id < 4096; vlan_id++)
1664 rx_vft_set(port_id, vlan_id, on);
1668 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1671 if (port_id_is_invalid(port_id))
1674 diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1678 printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1680 port_id, tp_id, diag);
1684 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1686 if (port_id_is_invalid(port_id))
1688 if (vlan_id_is_invalid(vlan_id))
1690 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1691 ports[port_id].tx_vlan_id = vlan_id;
1695 tx_vlan_reset(portid_t port_id)
1697 if (port_id_is_invalid(port_id))
1699 ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1703 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
1705 if (port_id_is_invalid(port_id))
1708 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
1712 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1715 uint8_t existing_mapping_found = 0;
1717 if (port_id_is_invalid(port_id))
1720 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1723 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1724 printf("map_value not in required range 0..%d\n",
1725 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1729 if (!is_rx) { /*then tx*/
1730 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1731 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1732 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1733 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1734 existing_mapping_found = 1;
1738 if (!existing_mapping_found) { /* A new additional mapping... */
1739 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1740 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1741 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1742 nb_tx_queue_stats_mappings++;
1746 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1747 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1748 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1749 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1750 existing_mapping_found = 1;
1754 if (!existing_mapping_found) { /* A new additional mapping... */
1755 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1756 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1757 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1758 nb_rx_queue_stats_mappings++;
1764 print_fdir_mask(struct rte_eth_fdir_masks *mask)
1766 printf("\n vlan_tci: 0x%04x, src_ipv4: 0x%08x, dst_ipv4: 0x%08x,"
1767 " src_port: 0x%04x, dst_port: 0x%04x",
1768 mask->vlan_tci_mask, mask->ipv4_mask.src_ip,
1769 mask->ipv4_mask.dst_ip,
1770 mask->src_port_mask, mask->dst_port_mask);
1772 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x,"
1773 " dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
1774 mask->ipv6_mask.src_ip[0], mask->ipv6_mask.src_ip[1],
1775 mask->ipv6_mask.src_ip[2], mask->ipv6_mask.src_ip[3],
1776 mask->ipv6_mask.dst_ip[0], mask->ipv6_mask.dst_ip[1],
1777 mask->ipv6_mask.dst_ip[2], mask->ipv6_mask.dst_ip[3]);
1782 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
1784 struct rte_eth_flex_payload_cfg *cfg;
1787 for (i = 0; i < flex_conf->nb_payloads; i++) {
1788 cfg = &flex_conf->flex_set[i];
1789 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
1791 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
1792 printf("\n L2_PAYLOAD: ");
1793 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
1794 printf("\n L3_PAYLOAD: ");
1795 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
1796 printf("\n L4_PAYLOAD: ");
1798 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
1799 for (j = 0; j < num; j++)
1800 printf(" %-5u", cfg->src_offset[j]);
1806 flowtype_to_str(uint16_t flow_type)
1808 struct flow_type_info {
1814 static struct flow_type_info flowtype_str_table[] = {
1815 {"raw", RTE_ETH_FLOW_RAW},
1816 {"ipv4", RTE_ETH_FLOW_IPV4},
1817 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
1818 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
1819 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
1820 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
1821 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
1822 {"ipv6", RTE_ETH_FLOW_IPV6},
1823 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
1824 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
1825 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
1826 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
1827 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
1828 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
1831 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
1832 if (flowtype_str_table[i].ftype == flow_type)
1833 return flowtype_str_table[i].str;
1840 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
1842 struct rte_eth_fdir_flex_mask *mask;
1846 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
1847 mask = &flex_conf->flex_mask[i];
1848 p = flowtype_to_str(mask->flow_type);
1849 printf("\n %s:\t", p ? p : "unknown");
1850 for (j = 0; j < num; j++)
1851 printf(" %02x", mask->mask[j]);
1857 print_fdir_flow_type(uint32_t flow_types_mask)
1862 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
1863 if (!(flow_types_mask & (1 << i)))
1865 p = flowtype_to_str(i);
1875 fdir_get_infos(portid_t port_id)
1877 struct rte_eth_fdir_stats fdir_stat;
1878 struct rte_eth_fdir_info fdir_info;
1881 static const char *fdir_stats_border = "########################";
1883 if (port_id_is_invalid(port_id))
1885 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
1887 printf("\n FDIR is not supported on port %-2d\n",
1892 memset(&fdir_info, 0, sizeof(fdir_info));
1893 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
1894 RTE_ETH_FILTER_INFO, &fdir_info);
1895 memset(&fdir_stat, 0, sizeof(fdir_stat));
1896 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
1897 RTE_ETH_FILTER_STATS, &fdir_stat);
1898 printf("\n %s FDIR infos for port %-2d %s\n",
1899 fdir_stats_border, port_id, fdir_stats_border);
1901 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
1902 printf(" PERFECT\n");
1903 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
1904 printf(" SIGNATURE\n");
1906 printf(" DISABLE\n");
1907 printf(" SUPPORTED FLOW TYPE: ");
1908 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
1909 printf(" FLEX PAYLOAD INFO:\n");
1910 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
1911 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
1912 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
1913 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
1914 fdir_info.flex_payload_unit,
1915 fdir_info.max_flex_payload_segment_num,
1916 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
1918 print_fdir_mask(&fdir_info.mask);
1919 if (fdir_info.flex_conf.nb_payloads > 0) {
1920 printf(" FLEX PAYLOAD SRC OFFSET:");
1921 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
1923 if (fdir_info.flex_conf.nb_flexmasks > 0) {
1924 printf(" FLEX MASK CFG:");
1925 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
1927 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
1928 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
1929 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
1930 fdir_info.guarant_spc, fdir_info.best_spc);
1931 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
1932 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
1933 " add: %-10"PRIu64" remove: %"PRIu64"\n"
1934 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
1935 fdir_stat.collision, fdir_stat.free,
1936 fdir_stat.maxhash, fdir_stat.maxlen,
1937 fdir_stat.add, fdir_stat.remove,
1938 fdir_stat.f_add, fdir_stat.f_remove);
1939 printf(" %s############################%s\n",
1940 fdir_stats_border, fdir_stats_border);
1944 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
1946 struct rte_port *port;
1947 struct rte_eth_fdir_flex_conf *flex_conf;
1950 port = &ports[port_id];
1951 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
1952 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
1953 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
1958 if (i >= RTE_ETH_FLOW_MAX) {
1959 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
1960 idx = flex_conf->nb_flexmasks;
1961 flex_conf->nb_flexmasks++;
1963 printf("The flex mask table is full. Can not set flex"
1964 " mask for flow_type(%u).", cfg->flow_type);
1968 (void)rte_memcpy(&flex_conf->flex_mask[idx],
1970 sizeof(struct rte_eth_fdir_flex_mask));
1974 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
1976 struct rte_port *port;
1977 struct rte_eth_fdir_flex_conf *flex_conf;
1980 port = &ports[port_id];
1981 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
1982 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
1983 if (cfg->type == flex_conf->flex_set[i].type) {
1988 if (i >= RTE_ETH_PAYLOAD_MAX) {
1989 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
1990 idx = flex_conf->nb_payloads;
1991 flex_conf->nb_payloads++;
1993 printf("The flex payload table is full. Can not set"
1994 " flex payload for type(%u).", cfg->type);
1998 (void)rte_memcpy(&flex_conf->flex_set[idx],
2000 sizeof(struct rte_eth_flex_payload_cfg));
2005 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
2009 if (port_id_is_invalid(port_id))
2012 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
2014 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
2018 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
2019 "diag=%d\n", port_id, diag);
2021 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
2022 "diag=%d\n", port_id, diag);
2027 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
2031 if (port_id_is_invalid(port_id))
2033 if (vlan_id_is_invalid(vlan_id))
2035 diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
2038 printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
2039 "diag=%d\n", port_id, diag);
2043 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
2046 struct rte_eth_link link;
2048 if (port_id_is_invalid(port_id))
2050 rte_eth_link_get_nowait(port_id, &link);
2051 if (rate > link.link_speed) {
2052 printf("Invalid rate value:%u bigger than link speed: %u\n",
2053 rate, link.link_speed);
2056 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
2059 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
2065 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
2068 struct rte_eth_link link;
2073 if (port_id_is_invalid(port_id))
2075 rte_eth_link_get_nowait(port_id, &link);
2076 if (rate > link.link_speed) {
2077 printf("Invalid rate value:%u bigger than link speed: %u\n",
2078 rate, link.link_speed);
2081 diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
2084 printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",