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>
83 #include <rte_per_lcore.h>
84 #include <rte_lcore.h>
85 #include <rte_atomic.h>
86 #include <rte_branch_prediction.h>
88 #include <rte_mempool.h>
90 #include <rte_interrupts.h>
92 #include <rte_ether.h>
93 #include <rte_ethdev.h>
94 #include <rte_string_fns.h>
98 static char *flowtype_to_str(uint16_t flow_type);
100 struct rss_type_info {
105 static const struct rss_type_info rss_type_table[] = {
106 { "ipv4", ETH_RSS_IPV4 },
107 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
108 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
109 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
110 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
111 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
112 { "ipv6", ETH_RSS_IPV6 },
113 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
114 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
115 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
116 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
117 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
118 { "l2-payload", ETH_RSS_L2_PAYLOAD },
119 { "ipv6-ex", ETH_RSS_IPV6_EX },
120 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
121 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
125 print_ethaddr(const char *name, struct ether_addr *eth_addr)
127 char buf[ETHER_ADDR_FMT_SIZE];
128 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
129 printf("%s%s", name, buf);
133 nic_stats_display(portid_t port_id)
135 struct rte_eth_stats stats;
136 struct rte_port *port = &ports[port_id];
140 static const char *nic_stats_border = "########################";
142 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
143 printf("Valid port range is [0");
144 FOREACH_PORT(pid, ports)
149 rte_eth_stats_get(port_id, &stats);
150 printf("\n %s NIC statistics for port %-2d %s\n",
151 nic_stats_border, port_id, nic_stats_border);
153 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
154 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
156 stats.ipackets, stats.imissed, stats.ibytes);
157 printf(" RX-badcrc: %-10"PRIu64" RX-badlen: %-10"PRIu64" RX-errors: "
159 stats.ibadcrc, stats.ibadlen, stats.ierrors);
160 printf(" RX-nombuf: %-10"PRIu64"\n",
162 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
164 stats.opackets, stats.oerrors, stats.obytes);
167 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
168 " RX-bytes: %10"PRIu64"\n",
169 stats.ipackets, stats.ierrors, stats.ibytes);
170 printf(" RX-badcrc: %10"PRIu64" RX-badlen: %10"PRIu64
171 " RX-errors: %10"PRIu64"\n",
172 stats.ibadcrc, stats.ibadlen, stats.ierrors);
173 printf(" RX-nombuf: %10"PRIu64"\n",
175 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
176 " TX-bytes: %10"PRIu64"\n",
177 stats.opackets, stats.oerrors, stats.obytes);
181 if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
182 printf(" Fdirmiss: %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
186 if (port->rx_queue_stats_mapping_enabled) {
188 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
189 printf(" Stats reg %2d RX-packets: %10"PRIu64
190 " RX-errors: %10"PRIu64
191 " RX-bytes: %10"PRIu64"\n",
192 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
195 if (port->tx_queue_stats_mapping_enabled) {
197 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
198 printf(" Stats reg %2d TX-packets: %10"PRIu64
199 " TX-bytes: %10"PRIu64"\n",
200 i, stats.q_opackets[i], stats.q_obytes[i]);
204 /* Display statistics of XON/XOFF pause frames, if any. */
205 if ((stats.tx_pause_xon | stats.rx_pause_xon |
206 stats.tx_pause_xoff | stats.rx_pause_xoff) > 0) {
207 printf(" RX-XOFF: %-10"PRIu64" RX-XON: %-10"PRIu64"\n",
208 stats.rx_pause_xoff, stats.rx_pause_xon);
209 printf(" TX-XOFF: %-10"PRIu64" TX-XON: %-10"PRIu64"\n",
210 stats.tx_pause_xoff, stats.tx_pause_xon);
212 printf(" %s############################%s\n",
213 nic_stats_border, nic_stats_border);
217 nic_stats_clear(portid_t port_id)
221 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
222 printf("Valid port range is [0");
223 FOREACH_PORT(pid, ports)
228 rte_eth_stats_reset(port_id);
229 printf("\n NIC statistics for port %d cleared\n", port_id);
233 nic_xstats_display(portid_t port_id)
235 struct rte_eth_xstats *xstats;
238 printf("###### NIC extended statistics for port %-2d\n", port_id);
240 len = rte_eth_xstats_get(port_id, NULL, 0);
242 printf("Cannot get xstats count\n");
245 xstats = malloc(sizeof(xstats[0]) * len);
246 if (xstats == NULL) {
247 printf("Cannot allocate memory for xstats\n");
250 ret = rte_eth_xstats_get(port_id, xstats, len);
251 if (ret < 0 || ret > len) {
252 printf("Cannot get xstats\n");
256 for (i = 0; i < len; i++)
257 printf("%s: %"PRIu64"\n", xstats[i].name, xstats[i].value);
262 nic_xstats_clear(portid_t port_id)
264 rte_eth_xstats_reset(port_id);
268 nic_stats_mapping_display(portid_t port_id)
270 struct rte_port *port = &ports[port_id];
274 static const char *nic_stats_mapping_border = "########################";
276 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
277 printf("Valid port range is [0");
278 FOREACH_PORT(pid, ports)
284 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
285 printf("Port id %d - either does not support queue statistic mapping or"
286 " no queue statistic mapping set\n", port_id);
290 printf("\n %s NIC statistics mapping for port %-2d %s\n",
291 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
293 if (port->rx_queue_stats_mapping_enabled) {
294 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
295 if (rx_queue_stats_mappings[i].port_id == port_id) {
296 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
297 rx_queue_stats_mappings[i].queue_id,
298 rx_queue_stats_mappings[i].stats_counter_id);
305 if (port->tx_queue_stats_mapping_enabled) {
306 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
307 if (tx_queue_stats_mappings[i].port_id == port_id) {
308 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
309 tx_queue_stats_mappings[i].queue_id,
310 tx_queue_stats_mappings[i].stats_counter_id);
315 printf(" %s####################################%s\n",
316 nic_stats_mapping_border, nic_stats_mapping_border);
320 port_infos_display(portid_t port_id)
322 struct rte_port *port;
323 struct ether_addr mac_addr;
324 struct rte_eth_link link;
325 struct rte_eth_dev_info dev_info;
327 struct rte_mempool * mp;
328 static const char *info_border = "*********************";
331 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
332 printf("Valid port range is [0");
333 FOREACH_PORT(pid, ports)
338 port = &ports[port_id];
339 rte_eth_link_get_nowait(port_id, &link);
340 printf("\n%s Infos for port %-2d %s\n",
341 info_border, port_id, info_border);
342 rte_eth_macaddr_get(port_id, &mac_addr);
343 print_ethaddr("MAC address: ", &mac_addr);
344 printf("\nConnect to socket: %u", port->socket_id);
346 if (port_numa[port_id] != NUMA_NO_CONFIG) {
347 mp = mbuf_pool_find(port_numa[port_id]);
349 printf("\nmemory allocation on the socket: %d",
352 printf("\nmemory allocation on the socket: %u",port->socket_id);
354 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
355 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
356 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
357 ("full-duplex") : ("half-duplex"));
358 printf("Promiscuous mode: %s\n",
359 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
360 printf("Allmulticast mode: %s\n",
361 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
362 printf("Maximum number of MAC addresses: %u\n",
363 (unsigned int)(port->dev_info.max_mac_addrs));
364 printf("Maximum number of MAC addresses of hash filtering: %u\n",
365 (unsigned int)(port->dev_info.max_hash_mac_addrs));
367 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
368 if (vlan_offload >= 0){
369 printf("VLAN offload: \n");
370 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
371 printf(" strip on \n");
373 printf(" strip off \n");
375 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
376 printf(" filter on \n");
378 printf(" filter off \n");
380 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
381 printf(" qinq(extend) on \n");
383 printf(" qinq(extend) off \n");
386 memset(&dev_info, 0, sizeof(dev_info));
387 rte_eth_dev_info_get(port_id, &dev_info);
388 if (dev_info.hash_key_size > 0)
389 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
390 if (dev_info.reta_size > 0)
391 printf("Redirection table size: %u\n", dev_info.reta_size);
392 if (!dev_info.flow_type_rss_offloads)
393 printf("No flow type is supported.\n");
398 printf("Supported flow types:\n");
399 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
401 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
403 p = flowtype_to_str(i);
404 printf(" %s\n", (p ? p : "unknown"));
410 port_id_is_invalid(portid_t port_id, enum print_warning warning)
412 if (port_id == (portid_t)RTE_PORT_ALL)
415 if (port_id < RTE_MAX_ETHPORTS && ports[port_id].enabled)
418 if (warning == ENABLED_WARN)
419 printf("Invalid port %d\n", port_id);
425 vlan_id_is_invalid(uint16_t vlan_id)
429 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
434 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
439 printf("Port register offset 0x%X not aligned on a 4-byte "
444 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
445 if (reg_off >= pci_len) {
446 printf("Port %d: register offset %u (0x%X) out of port PCI "
447 "resource (length=%"PRIu64")\n",
448 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
455 reg_bit_pos_is_invalid(uint8_t bit_pos)
459 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
463 #define display_port_and_reg_off(port_id, reg_off) \
464 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
467 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
469 display_port_and_reg_off(port_id, (unsigned)reg_off);
470 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
474 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
479 if (port_id_is_invalid(port_id, ENABLED_WARN))
481 if (port_reg_off_is_invalid(port_id, reg_off))
483 if (reg_bit_pos_is_invalid(bit_x))
485 reg_v = port_id_pci_reg_read(port_id, reg_off);
486 display_port_and_reg_off(port_id, (unsigned)reg_off);
487 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
491 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
492 uint8_t bit1_pos, uint8_t bit2_pos)
498 if (port_id_is_invalid(port_id, ENABLED_WARN))
500 if (port_reg_off_is_invalid(port_id, reg_off))
502 if (reg_bit_pos_is_invalid(bit1_pos))
504 if (reg_bit_pos_is_invalid(bit2_pos))
506 if (bit1_pos > bit2_pos)
507 l_bit = bit2_pos, h_bit = bit1_pos;
509 l_bit = bit1_pos, h_bit = bit2_pos;
511 reg_v = port_id_pci_reg_read(port_id, reg_off);
514 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
515 display_port_and_reg_off(port_id, (unsigned)reg_off);
516 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
517 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
521 port_reg_display(portid_t port_id, uint32_t reg_off)
525 if (port_id_is_invalid(port_id, ENABLED_WARN))
527 if (port_reg_off_is_invalid(port_id, reg_off))
529 reg_v = port_id_pci_reg_read(port_id, reg_off);
530 display_port_reg_value(port_id, reg_off, reg_v);
534 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
539 if (port_id_is_invalid(port_id, ENABLED_WARN))
541 if (port_reg_off_is_invalid(port_id, reg_off))
543 if (reg_bit_pos_is_invalid(bit_pos))
546 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
549 reg_v = port_id_pci_reg_read(port_id, reg_off);
551 reg_v &= ~(1 << bit_pos);
553 reg_v |= (1 << bit_pos);
554 port_id_pci_reg_write(port_id, reg_off, reg_v);
555 display_port_reg_value(port_id, reg_off, reg_v);
559 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
560 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
567 if (port_id_is_invalid(port_id, ENABLED_WARN))
569 if (port_reg_off_is_invalid(port_id, reg_off))
571 if (reg_bit_pos_is_invalid(bit1_pos))
573 if (reg_bit_pos_is_invalid(bit2_pos))
575 if (bit1_pos > bit2_pos)
576 l_bit = bit2_pos, h_bit = bit1_pos;
578 l_bit = bit1_pos, h_bit = bit2_pos;
580 if ((h_bit - l_bit) < 31)
581 max_v = (1 << (h_bit - l_bit + 1)) - 1;
586 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
587 (unsigned)value, (unsigned)value,
588 (unsigned)max_v, (unsigned)max_v);
591 reg_v = port_id_pci_reg_read(port_id, reg_off);
592 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
593 reg_v |= (value << l_bit); /* Set changed bits */
594 port_id_pci_reg_write(port_id, reg_off, reg_v);
595 display_port_reg_value(port_id, reg_off, reg_v);
599 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
601 if (port_id_is_invalid(port_id, ENABLED_WARN))
603 if (port_reg_off_is_invalid(port_id, reg_off))
605 port_id_pci_reg_write(port_id, reg_off, reg_v);
606 display_port_reg_value(port_id, reg_off, reg_v);
610 port_mtu_set(portid_t port_id, uint16_t mtu)
614 if (port_id_is_invalid(port_id, ENABLED_WARN))
616 diag = rte_eth_dev_set_mtu(port_id, mtu);
619 printf("Set MTU failed. diag=%d\n", diag);
623 * RX/TX ring descriptors display functions.
626 rx_queue_id_is_invalid(queueid_t rxq_id)
630 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
635 tx_queue_id_is_invalid(queueid_t txq_id)
639 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
644 rx_desc_id_is_invalid(uint16_t rxdesc_id)
646 if (rxdesc_id < nb_rxd)
648 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
654 tx_desc_id_is_invalid(uint16_t txdesc_id)
656 if (txdesc_id < nb_txd)
658 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
663 static const struct rte_memzone *
664 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
666 char mz_name[RTE_MEMZONE_NAMESIZE];
667 const struct rte_memzone *mz;
669 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
670 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
671 mz = rte_memzone_lookup(mz_name);
673 printf("%s ring memory zoneof (port %d, queue %d) not"
674 "found (zone name = %s\n",
675 ring_name, port_id, q_id, mz_name);
679 union igb_ring_dword {
682 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
692 struct igb_ring_desc_32_bytes {
693 union igb_ring_dword lo_dword;
694 union igb_ring_dword hi_dword;
695 union igb_ring_dword resv1;
696 union igb_ring_dword resv2;
699 struct igb_ring_desc_16_bytes {
700 union igb_ring_dword lo_dword;
701 union igb_ring_dword hi_dword;
705 ring_rxd_display_dword(union igb_ring_dword dword)
707 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
708 (unsigned)dword.words.hi);
712 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
713 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
716 __rte_unused uint8_t port_id,
720 struct igb_ring_desc_16_bytes *ring =
721 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
722 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
723 struct rte_eth_dev_info dev_info;
725 memset(&dev_info, 0, sizeof(dev_info));
726 rte_eth_dev_info_get(port_id, &dev_info);
727 if (strstr(dev_info.driver_name, "i40e") != NULL) {
728 /* 32 bytes RX descriptor, i40e only */
729 struct igb_ring_desc_32_bytes *ring =
730 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
731 ring[desc_id].lo_dword.dword =
732 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
733 ring_rxd_display_dword(ring[desc_id].lo_dword);
734 ring[desc_id].hi_dword.dword =
735 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
736 ring_rxd_display_dword(ring[desc_id].hi_dword);
737 ring[desc_id].resv1.dword =
738 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
739 ring_rxd_display_dword(ring[desc_id].resv1);
740 ring[desc_id].resv2.dword =
741 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
742 ring_rxd_display_dword(ring[desc_id].resv2);
747 /* 16 bytes RX descriptor */
748 ring[desc_id].lo_dword.dword =
749 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
750 ring_rxd_display_dword(ring[desc_id].lo_dword);
751 ring[desc_id].hi_dword.dword =
752 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
753 ring_rxd_display_dword(ring[desc_id].hi_dword);
757 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
759 struct igb_ring_desc_16_bytes *ring;
760 struct igb_ring_desc_16_bytes txd;
762 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
763 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
764 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
765 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
766 (unsigned)txd.lo_dword.words.lo,
767 (unsigned)txd.lo_dword.words.hi,
768 (unsigned)txd.hi_dword.words.lo,
769 (unsigned)txd.hi_dword.words.hi);
773 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
775 const struct rte_memzone *rx_mz;
777 if (port_id_is_invalid(port_id, ENABLED_WARN))
779 if (rx_queue_id_is_invalid(rxq_id))
781 if (rx_desc_id_is_invalid(rxd_id))
783 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
786 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
790 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
792 const struct rte_memzone *tx_mz;
794 if (port_id_is_invalid(port_id, ENABLED_WARN))
796 if (tx_queue_id_is_invalid(txq_id))
798 if (tx_desc_id_is_invalid(txd_id))
800 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
803 ring_tx_descriptor_display(tx_mz, txd_id);
807 fwd_lcores_config_display(void)
811 printf("List of forwarding lcores:");
812 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
813 printf(" %2u", fwd_lcores_cpuids[lc_id]);
817 rxtx_config_display(void)
819 printf(" %s packet forwarding - CRC stripping %s - "
820 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
821 rx_mode.hw_strip_crc ? "enabled" : "disabled",
824 if (cur_fwd_eng == &tx_only_engine)
825 printf(" packet len=%u - nb packet segments=%d\n",
826 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
828 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
829 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
831 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
832 nb_fwd_lcores, nb_fwd_ports);
833 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
834 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
835 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
836 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
837 rx_conf->rx_thresh.wthresh);
838 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
839 nb_txq, nb_txd, tx_conf->tx_free_thresh);
840 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
841 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
842 tx_conf->tx_thresh.wthresh);
843 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
844 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
848 port_rss_reta_info(portid_t port_id,
849 struct rte_eth_rss_reta_entry64 *reta_conf,
852 uint16_t i, idx, shift;
855 if (port_id_is_invalid(port_id, ENABLED_WARN))
858 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
860 printf("Failed to get RSS RETA info, return code = %d\n", ret);
864 for (i = 0; i < nb_entries; i++) {
865 idx = i / RTE_RETA_GROUP_SIZE;
866 shift = i % RTE_RETA_GROUP_SIZE;
867 if (!(reta_conf[idx].mask & (1ULL << shift)))
869 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
870 i, reta_conf[idx].reta[shift]);
875 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
879 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
881 struct rte_eth_rss_conf rss_conf;
882 uint8_t rss_key[10 * 4] = "";
887 if (port_id_is_invalid(port_id, ENABLED_WARN))
891 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
892 if (!strcmp(rss_info, rss_type_table[i].str))
893 rss_conf.rss_hf = rss_type_table[i].rss_type;
896 /* Get RSS hash key if asked to display it */
897 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
898 rss_conf.rss_key_len = sizeof(rss_key);
899 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
903 printf("port index %d invalid\n", port_id);
906 printf("operation not supported by device\n");
909 printf("operation failed - diag=%d\n", diag);
914 rss_hf = rss_conf.rss_hf;
916 printf("RSS disabled\n");
919 printf("RSS functions:\n ");
920 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
921 if (rss_hf & rss_type_table[i].rss_type)
922 printf("%s ", rss_type_table[i].str);
927 printf("RSS key:\n");
928 for (i = 0; i < sizeof(rss_key); i++)
929 printf("%02X", rss_key[i]);
934 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
937 struct rte_eth_rss_conf rss_conf;
941 rss_conf.rss_key = NULL;
942 rss_conf.rss_key_len = hash_key_len;
944 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
945 if (!strcmp(rss_type_table[i].str, rss_type))
946 rss_conf.rss_hf = rss_type_table[i].rss_type;
948 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
950 rss_conf.rss_key = hash_key;
951 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
958 printf("port index %d invalid\n", port_id);
961 printf("operation not supported by device\n");
964 printf("operation failed - diag=%d\n", diag);
970 * Setup forwarding configuration for each logical core.
973 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
975 streamid_t nb_fs_per_lcore;
983 nb_fs = cfg->nb_fwd_streams;
984 nb_fc = cfg->nb_fwd_lcores;
985 if (nb_fs <= nb_fc) {
989 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
990 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
993 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
995 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
996 fwd_lcores[lc_id]->stream_idx = sm_id;
997 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
998 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1002 * Assign extra remaining streams, if any.
1004 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1005 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1006 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1007 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1008 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1013 simple_fwd_config_setup(void)
1019 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1020 port_topology == PORT_TOPOLOGY_LOOP) {
1022 } else if (nb_fwd_ports % 2) {
1023 printf("\nWarning! Cannot handle an odd number of ports "
1024 "with the current port topology. Configuration "
1025 "must be changed to have an even number of ports, "
1026 "or relaunch application with "
1027 "--port-topology=chained\n\n");
1030 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1031 cur_fwd_config.nb_fwd_streams =
1032 (streamid_t) cur_fwd_config.nb_fwd_ports;
1034 /* reinitialize forwarding streams */
1038 * In the simple forwarding test, the number of forwarding cores
1039 * must be lower or equal to the number of forwarding ports.
1041 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1042 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1043 cur_fwd_config.nb_fwd_lcores =
1044 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1045 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1047 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1048 if (port_topology != PORT_TOPOLOGY_LOOP)
1049 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1052 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1053 fwd_streams[i]->rx_queue = 0;
1054 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1055 fwd_streams[i]->tx_queue = 0;
1056 fwd_streams[i]->peer_addr = j;
1058 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1059 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1060 fwd_streams[j]->rx_queue = 0;
1061 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1062 fwd_streams[j]->tx_queue = 0;
1063 fwd_streams[j]->peer_addr = i;
1069 * For the RSS forwarding test, each core is assigned on every port a transmit
1070 * queue whose index is the index of the core itself. This approach limits the
1071 * maximumm number of processing cores of the RSS test to the maximum number of
1072 * TX queues supported by the devices.
1074 * Each core is assigned a single stream, each stream being composed of
1075 * a RX queue to poll on a RX port for input messages, associated with
1076 * a TX queue of a TX port where to send forwarded packets.
1077 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1078 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1080 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1084 rss_fwd_config_setup(void)
1095 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1096 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1097 cur_fwd_config.nb_fwd_streams =
1098 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1099 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
1100 cur_fwd_config.nb_fwd_streams =
1101 (streamid_t)cur_fwd_config.nb_fwd_lcores;
1103 cur_fwd_config.nb_fwd_lcores =
1104 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1106 /* reinitialize forwarding streams */
1109 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1111 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1112 struct fwd_stream *fs;
1114 fs = fwd_streams[lc_id];
1116 if ((rxp & 0x1) == 0)
1117 txp = (portid_t) (rxp + 1);
1119 txp = (portid_t) (rxp - 1);
1121 * if we are in loopback, simply send stuff out through the
1124 if (port_topology == PORT_TOPOLOGY_LOOP)
1127 fs->rx_port = fwd_ports_ids[rxp];
1129 fs->tx_port = fwd_ports_ids[txp];
1131 fs->peer_addr = fs->tx_port;
1132 rxq = (queueid_t) (rxq + 1);
1137 * Restart from RX queue 0 on next RX port
1140 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1142 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1144 rxp = (portid_t) (rxp + 1);
1149 * For the DCB forwarding test, each core is assigned on each traffic class.
1151 * Each core is assigned a multi-stream, each stream being composed of
1152 * a RX queue to poll on a RX port for input messages, associated with
1153 * a TX queue of a TX port where to send forwarded packets. All RX and
1154 * TX queues are mapping to the same traffic class.
1155 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1159 dcb_fwd_config_setup(void)
1161 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1162 portid_t txp, rxp = 0;
1163 queueid_t txq, rxq = 0;
1165 uint16_t nb_rx_queue, nb_tx_queue;
1166 uint16_t i, j, k, sm_id = 0;
1169 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1170 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1171 cur_fwd_config.nb_fwd_streams =
1172 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1174 /* reinitialize forwarding streams */
1177 if ((rxp & 0x1) == 0)
1178 txp = (portid_t) (rxp + 1);
1180 txp = (portid_t) (rxp - 1);
1181 /* get the dcb info on the first RX and TX ports */
1182 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1183 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
1185 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1186 fwd_lcores[lc_id]->stream_nb = 0;
1187 fwd_lcores[lc_id]->stream_idx = sm_id;
1188 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
1189 /* if the nb_queue is zero, means this tc is
1190 * not enabled on the POOL
1192 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
1194 k = fwd_lcores[lc_id]->stream_nb +
1195 fwd_lcores[lc_id]->stream_idx;
1196 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
1197 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
1198 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
1199 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
1200 for (j = 0; j < nb_rx_queue; j++) {
1201 struct fwd_stream *fs;
1203 fs = fwd_streams[k + j];
1204 fs->rx_port = fwd_ports_ids[rxp];
1205 fs->rx_queue = rxq + j;
1206 fs->tx_port = fwd_ports_ids[txp];
1207 fs->tx_queue = txq + j % nb_tx_queue;
1208 fs->peer_addr = fs->tx_port;
1210 fwd_lcores[lc_id]->stream_nb +=
1211 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
1213 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
1216 if (tc < rxp_dcb_info.nb_tcs)
1218 /* Restart from TC 0 on next RX port */
1220 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1222 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1225 if (rxp >= nb_fwd_ports)
1227 /* get the dcb information on next RX and TX ports */
1228 if ((rxp & 0x1) == 0)
1229 txp = (portid_t) (rxp + 1);
1231 txp = (portid_t) (rxp - 1);
1232 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1233 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
1238 icmp_echo_config_setup(void)
1245 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1246 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1247 (nb_txq * nb_fwd_ports);
1249 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1250 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1251 cur_fwd_config.nb_fwd_streams =
1252 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1253 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1254 cur_fwd_config.nb_fwd_lcores =
1255 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1256 if (verbose_level > 0) {
1257 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1259 cur_fwd_config.nb_fwd_lcores,
1260 cur_fwd_config.nb_fwd_ports,
1261 cur_fwd_config.nb_fwd_streams);
1264 /* reinitialize forwarding streams */
1266 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1268 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1269 if (verbose_level > 0)
1270 printf(" core=%d: \n", lc_id);
1271 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1272 struct fwd_stream *fs;
1273 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1274 fs->rx_port = fwd_ports_ids[rxp];
1276 fs->tx_port = fs->rx_port;
1277 fs->tx_queue = lc_id;
1278 fs->peer_addr = fs->tx_port;
1279 if (verbose_level > 0)
1280 printf(" stream=%d port=%d rxq=%d txq=%d\n",
1281 sm_id, fs->rx_port, fs->rx_queue,
1283 rxq = (queueid_t) (rxq + 1);
1284 if (rxq == nb_rxq) {
1286 rxp = (portid_t) (rxp + 1);
1293 fwd_config_setup(void)
1295 cur_fwd_config.fwd_eng = cur_fwd_eng;
1296 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1297 icmp_echo_config_setup();
1300 if ((nb_rxq > 1) && (nb_txq > 1)){
1302 dcb_fwd_config_setup();
1304 rss_fwd_config_setup();
1307 simple_fwd_config_setup();
1311 pkt_fwd_config_display(struct fwd_config *cfg)
1313 struct fwd_stream *fs;
1317 printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
1318 "NUMA support %s, MP over anonymous pages %s\n",
1319 cfg->fwd_eng->fwd_mode_name,
1320 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1321 numa_support == 1 ? "enabled" : "disabled",
1322 mp_anon != 0 ? "enabled" : "disabled");
1324 if (strcmp(cfg->fwd_eng->fwd_mode_name, "mac_retry") == 0)
1325 printf("TX retry num: %u, delay between TX retries: %uus\n",
1326 burst_tx_retry_num, burst_tx_delay_time);
1327 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1328 printf("Logical Core %u (socket %u) forwards packets on "
1330 fwd_lcores_cpuids[lc_id],
1331 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1332 fwd_lcores[lc_id]->stream_nb);
1333 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1334 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1335 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
1336 "P=%d/Q=%d (socket %u) ",
1337 fs->rx_port, fs->rx_queue,
1338 ports[fs->rx_port].socket_id,
1339 fs->tx_port, fs->tx_queue,
1340 ports[fs->tx_port].socket_id);
1341 print_ethaddr("peer=",
1342 &peer_eth_addrs[fs->peer_addr]);
1351 fwd_config_display(void)
1354 pkt_fwd_config_display(&cur_fwd_config);
1358 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1361 unsigned int lcore_cpuid;
1366 for (i = 0; i < nb_lc; i++) {
1367 lcore_cpuid = lcorelist[i];
1368 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1369 printf("lcore %u not enabled\n", lcore_cpuid);
1372 if (lcore_cpuid == rte_get_master_lcore()) {
1373 printf("lcore %u cannot be masked on for running "
1374 "packet forwarding, which is the master lcore "
1375 "and reserved for command line parsing only\n",
1380 fwd_lcores_cpuids[i] = lcore_cpuid;
1382 if (record_now == 0) {
1386 nb_cfg_lcores = (lcoreid_t) nb_lc;
1387 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1388 printf("previous number of forwarding cores %u - changed to "
1389 "number of configured cores %u\n",
1390 (unsigned int) nb_fwd_lcores, nb_lc);
1391 nb_fwd_lcores = (lcoreid_t) nb_lc;
1398 set_fwd_lcores_mask(uint64_t lcoremask)
1400 unsigned int lcorelist[64];
1404 if (lcoremask == 0) {
1405 printf("Invalid NULL mask of cores\n");
1409 for (i = 0; i < 64; i++) {
1410 if (! ((uint64_t)(1ULL << i) & lcoremask))
1412 lcorelist[nb_lc++] = i;
1414 return set_fwd_lcores_list(lcorelist, nb_lc);
1418 set_fwd_lcores_number(uint16_t nb_lc)
1420 if (nb_lc > nb_cfg_lcores) {
1421 printf("nb fwd cores %u > %u (max. number of configured "
1422 "lcores) - ignored\n",
1423 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1426 nb_fwd_lcores = (lcoreid_t) nb_lc;
1427 printf("Number of forwarding cores set to %u\n",
1428 (unsigned int) nb_fwd_lcores);
1432 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1440 for (i = 0; i < nb_pt; i++) {
1441 port_id = (portid_t) portlist[i];
1442 if (port_id_is_invalid(port_id, ENABLED_WARN))
1445 fwd_ports_ids[i] = port_id;
1447 if (record_now == 0) {
1451 nb_cfg_ports = (portid_t) nb_pt;
1452 if (nb_fwd_ports != (portid_t) nb_pt) {
1453 printf("previous number of forwarding ports %u - changed to "
1454 "number of configured ports %u\n",
1455 (unsigned int) nb_fwd_ports, nb_pt);
1456 nb_fwd_ports = (portid_t) nb_pt;
1461 set_fwd_ports_mask(uint64_t portmask)
1463 unsigned int portlist[64];
1467 if (portmask == 0) {
1468 printf("Invalid NULL mask of ports\n");
1472 for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
1473 if (! ((uint64_t)(1ULL << i) & portmask))
1475 portlist[nb_pt++] = i;
1477 set_fwd_ports_list(portlist, nb_pt);
1481 set_fwd_ports_number(uint16_t nb_pt)
1483 if (nb_pt > nb_cfg_ports) {
1484 printf("nb fwd ports %u > %u (number of configured "
1485 "ports) - ignored\n",
1486 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1489 nb_fwd_ports = (portid_t) nb_pt;
1490 printf("Number of forwarding ports set to %u\n",
1491 (unsigned int) nb_fwd_ports);
1495 set_nb_pkt_per_burst(uint16_t nb)
1497 if (nb > MAX_PKT_BURST) {
1498 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1500 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1503 nb_pkt_per_burst = nb;
1504 printf("Number of packets per burst set to %u\n",
1505 (unsigned int) nb_pkt_per_burst);
1509 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1511 uint16_t tx_pkt_len;
1514 if (nb_segs >= (unsigned) nb_txd) {
1515 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1516 nb_segs, (unsigned int) nb_txd);
1521 * Check that each segment length is greater or equal than
1522 * the mbuf data sise.
1523 * Check also that the total packet length is greater or equal than the
1524 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1527 for (i = 0; i < nb_segs; i++) {
1528 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1529 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1530 i, seg_lengths[i], (unsigned) mbuf_data_size);
1533 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1535 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1536 printf("total packet length=%u < %d - give up\n",
1537 (unsigned) tx_pkt_len,
1538 (int)(sizeof(struct ether_hdr) + 20 + 8));
1542 for (i = 0; i < nb_segs; i++)
1543 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1545 tx_pkt_length = tx_pkt_len;
1546 tx_pkt_nb_segs = (uint8_t) nb_segs;
1550 list_pkt_forwarding_modes(void)
1552 static char fwd_modes[128] = "";
1553 const char *separator = "|";
1554 struct fwd_engine *fwd_eng;
1557 if (strlen (fwd_modes) == 0) {
1558 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1559 strcat(fwd_modes, fwd_eng->fwd_mode_name);
1560 strcat(fwd_modes, separator);
1562 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1569 set_pkt_forwarding_mode(const char *fwd_mode_name)
1571 struct fwd_engine *fwd_eng;
1575 while ((fwd_eng = fwd_engines[i]) != NULL) {
1576 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1577 printf("Set %s packet forwarding mode\n",
1579 cur_fwd_eng = fwd_eng;
1584 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1588 set_verbose_level(uint16_t vb_level)
1590 printf("Change verbose level from %u to %u\n",
1591 (unsigned int) verbose_level, (unsigned int) vb_level);
1592 verbose_level = vb_level;
1596 vlan_extend_set(portid_t port_id, int on)
1601 if (port_id_is_invalid(port_id, ENABLED_WARN))
1604 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1607 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1609 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1611 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1613 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1614 "diag=%d\n", port_id, on, diag);
1618 rx_vlan_strip_set(portid_t port_id, int on)
1623 if (port_id_is_invalid(port_id, ENABLED_WARN))
1626 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1629 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1631 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1633 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1635 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1636 "diag=%d\n", port_id, on, diag);
1640 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1644 if (port_id_is_invalid(port_id, ENABLED_WARN))
1647 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1649 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1650 "diag=%d\n", port_id, queue_id, on, diag);
1654 rx_vlan_filter_set(portid_t port_id, int on)
1659 if (port_id_is_invalid(port_id, ENABLED_WARN))
1662 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1665 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1667 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1669 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1671 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1672 "diag=%d\n", port_id, on, diag);
1676 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1680 if (port_id_is_invalid(port_id, ENABLED_WARN))
1682 if (vlan_id_is_invalid(vlan_id))
1684 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1687 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1689 port_id, vlan_id, on, diag);
1694 rx_vlan_all_filter_set(portid_t port_id, int on)
1698 if (port_id_is_invalid(port_id, ENABLED_WARN))
1700 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
1701 if (rx_vft_set(port_id, vlan_id, on))
1707 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1710 if (port_id_is_invalid(port_id, ENABLED_WARN))
1713 diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1717 printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1719 port_id, tp_id, diag);
1723 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1725 if (port_id_is_invalid(port_id, ENABLED_WARN))
1727 if (vlan_id_is_invalid(vlan_id))
1729 tx_vlan_reset(port_id);
1730 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1731 ports[port_id].tx_vlan_id = vlan_id;
1735 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
1737 if (port_id_is_invalid(port_id, ENABLED_WARN))
1739 if (vlan_id_is_invalid(vlan_id))
1741 if (vlan_id_is_invalid(vlan_id_outer))
1743 tx_vlan_reset(port_id);
1744 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
1745 ports[port_id].tx_vlan_id = vlan_id;
1746 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
1750 tx_vlan_reset(portid_t port_id)
1752 if (port_id_is_invalid(port_id, ENABLED_WARN))
1754 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
1755 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
1756 ports[port_id].tx_vlan_id = 0;
1757 ports[port_id].tx_vlan_id_outer = 0;
1761 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
1763 if (port_id_is_invalid(port_id, ENABLED_WARN))
1766 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
1770 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1773 uint8_t existing_mapping_found = 0;
1775 if (port_id_is_invalid(port_id, ENABLED_WARN))
1778 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1781 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1782 printf("map_value not in required range 0..%d\n",
1783 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1787 if (!is_rx) { /*then tx*/
1788 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1789 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1790 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1791 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1792 existing_mapping_found = 1;
1796 if (!existing_mapping_found) { /* A new additional mapping... */
1797 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1798 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1799 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1800 nb_tx_queue_stats_mappings++;
1804 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1805 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1806 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1807 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1808 existing_mapping_found = 1;
1812 if (!existing_mapping_found) { /* A new additional mapping... */
1813 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1814 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1815 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1816 nb_rx_queue_stats_mappings++;
1822 print_fdir_mask(struct rte_eth_fdir_masks *mask)
1824 printf("\n vlan_tci: 0x%04x, ", mask->vlan_tci_mask);
1826 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
1827 printf("mac_addr: 0x%02x", mask->mac_addr_byte_mask);
1828 else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
1829 printf("mac_addr: 0x%02x, tunnel_type: 0x%01x, tunnel_id: 0x%08x",
1830 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
1831 mask->tunnel_id_mask);
1833 printf("src_ipv4: 0x%08x, dst_ipv4: 0x%08x,"
1834 " src_port: 0x%04x, dst_port: 0x%04x",
1835 mask->ipv4_mask.src_ip, mask->ipv4_mask.dst_ip,
1836 mask->src_port_mask, mask->dst_port_mask);
1838 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x,"
1839 " dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
1840 mask->ipv6_mask.src_ip[0], mask->ipv6_mask.src_ip[1],
1841 mask->ipv6_mask.src_ip[2], mask->ipv6_mask.src_ip[3],
1842 mask->ipv6_mask.dst_ip[0], mask->ipv6_mask.dst_ip[1],
1843 mask->ipv6_mask.dst_ip[2], mask->ipv6_mask.dst_ip[3]);
1850 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
1852 struct rte_eth_flex_payload_cfg *cfg;
1855 for (i = 0; i < flex_conf->nb_payloads; i++) {
1856 cfg = &flex_conf->flex_set[i];
1857 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
1859 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
1860 printf("\n L2_PAYLOAD: ");
1861 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
1862 printf("\n L3_PAYLOAD: ");
1863 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
1864 printf("\n L4_PAYLOAD: ");
1866 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
1867 for (j = 0; j < num; j++)
1868 printf(" %-5u", cfg->src_offset[j]);
1874 flowtype_to_str(uint16_t flow_type)
1876 struct flow_type_info {
1882 static struct flow_type_info flowtype_str_table[] = {
1883 {"raw", RTE_ETH_FLOW_RAW},
1884 {"ipv4", RTE_ETH_FLOW_IPV4},
1885 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
1886 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
1887 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
1888 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
1889 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
1890 {"ipv6", RTE_ETH_FLOW_IPV6},
1891 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
1892 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
1893 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
1894 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
1895 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
1896 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
1899 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
1900 if (flowtype_str_table[i].ftype == flow_type)
1901 return flowtype_str_table[i].str;
1908 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
1910 struct rte_eth_fdir_flex_mask *mask;
1914 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
1915 mask = &flex_conf->flex_mask[i];
1916 p = flowtype_to_str(mask->flow_type);
1917 printf("\n %s:\t", p ? p : "unknown");
1918 for (j = 0; j < num; j++)
1919 printf(" %02x", mask->mask[j]);
1925 print_fdir_flow_type(uint32_t flow_types_mask)
1930 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
1931 if (!(flow_types_mask & (1 << i)))
1933 p = flowtype_to_str(i);
1943 fdir_get_infos(portid_t port_id)
1945 struct rte_eth_fdir_stats fdir_stat;
1946 struct rte_eth_fdir_info fdir_info;
1949 static const char *fdir_stats_border = "########################";
1951 if (port_id_is_invalid(port_id, ENABLED_WARN))
1953 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
1955 printf("\n FDIR is not supported on port %-2d\n",
1960 memset(&fdir_info, 0, sizeof(fdir_info));
1961 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
1962 RTE_ETH_FILTER_INFO, &fdir_info);
1963 memset(&fdir_stat, 0, sizeof(fdir_stat));
1964 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
1965 RTE_ETH_FILTER_STATS, &fdir_stat);
1966 printf("\n %s FDIR infos for port %-2d %s\n",
1967 fdir_stats_border, port_id, fdir_stats_border);
1969 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
1970 printf(" PERFECT\n");
1971 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
1972 printf(" PERFECT-MAC-VLAN\n");
1973 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
1974 printf(" PERFECT-TUNNEL\n");
1975 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
1976 printf(" SIGNATURE\n");
1978 printf(" DISABLE\n");
1979 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
1980 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
1981 printf(" SUPPORTED FLOW TYPE: ");
1982 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
1984 printf(" FLEX PAYLOAD INFO:\n");
1985 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
1986 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
1987 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
1988 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
1989 fdir_info.flex_payload_unit,
1990 fdir_info.max_flex_payload_segment_num,
1991 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
1993 print_fdir_mask(&fdir_info.mask);
1994 if (fdir_info.flex_conf.nb_payloads > 0) {
1995 printf(" FLEX PAYLOAD SRC OFFSET:");
1996 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
1998 if (fdir_info.flex_conf.nb_flexmasks > 0) {
1999 printf(" FLEX MASK CFG:");
2000 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2002 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2003 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2004 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2005 fdir_info.guarant_spc, fdir_info.best_spc);
2006 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2007 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2008 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2009 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2010 fdir_stat.collision, fdir_stat.free,
2011 fdir_stat.maxhash, fdir_stat.maxlen,
2012 fdir_stat.add, fdir_stat.remove,
2013 fdir_stat.f_add, fdir_stat.f_remove);
2014 printf(" %s############################%s\n",
2015 fdir_stats_border, fdir_stats_border);
2019 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2021 struct rte_port *port;
2022 struct rte_eth_fdir_flex_conf *flex_conf;
2025 port = &ports[port_id];
2026 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2027 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2028 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2033 if (i >= RTE_ETH_FLOW_MAX) {
2034 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2035 idx = flex_conf->nb_flexmasks;
2036 flex_conf->nb_flexmasks++;
2038 printf("The flex mask table is full. Can not set flex"
2039 " mask for flow_type(%u).", cfg->flow_type);
2043 (void)rte_memcpy(&flex_conf->flex_mask[idx],
2045 sizeof(struct rte_eth_fdir_flex_mask));
2049 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2051 struct rte_port *port;
2052 struct rte_eth_fdir_flex_conf *flex_conf;
2055 port = &ports[port_id];
2056 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2057 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2058 if (cfg->type == flex_conf->flex_set[i].type) {
2063 if (i >= RTE_ETH_PAYLOAD_MAX) {
2064 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2065 idx = flex_conf->nb_payloads;
2066 flex_conf->nb_payloads++;
2068 printf("The flex payload table is full. Can not set"
2069 " flex payload for type(%u).", cfg->type);
2073 (void)rte_memcpy(&flex_conf->flex_set[idx],
2075 sizeof(struct rte_eth_flex_payload_cfg));
2080 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
2084 if (port_id_is_invalid(port_id, ENABLED_WARN))
2087 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
2089 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
2093 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
2094 "diag=%d\n", port_id, diag);
2096 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
2097 "diag=%d\n", port_id, diag);
2102 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
2106 if (port_id_is_invalid(port_id, ENABLED_WARN))
2108 if (vlan_id_is_invalid(vlan_id))
2110 diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
2113 printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
2114 "diag=%d\n", port_id, diag);
2118 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
2121 struct rte_eth_link link;
2123 if (port_id_is_invalid(port_id, ENABLED_WARN))
2125 rte_eth_link_get_nowait(port_id, &link);
2126 if (rate > link.link_speed) {
2127 printf("Invalid rate value:%u bigger than link speed: %u\n",
2128 rate, link.link_speed);
2131 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
2134 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
2140 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
2143 struct rte_eth_link link;
2148 if (port_id_is_invalid(port_id, ENABLED_WARN))
2150 rte_eth_link_get_nowait(port_id, &link);
2151 if (rate > link.link_speed) {
2152 printf("Invalid rate value:%u bigger than link speed: %u\n",
2153 rate, link.link_speed);
2156 diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
2159 printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",
2165 * Functions to manage the set of filtered Multicast MAC addresses.
2167 * A pool of filtered multicast MAC addresses is associated with each port.
2168 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
2169 * The address of the pool and the number of valid multicast MAC addresses
2170 * recorded in the pool are stored in the fields "mc_addr_pool" and
2171 * "mc_addr_nb" of the "rte_port" data structure.
2173 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
2174 * to be supplied a contiguous array of multicast MAC addresses.
2175 * To comply with this constraint, the set of multicast addresses recorded
2176 * into the pool are systematically compacted at the beginning of the pool.
2177 * Hence, when a multicast address is removed from the pool, all following
2178 * addresses, if any, are copied back to keep the set contiguous.
2180 #define MCAST_POOL_INC 32
2183 mcast_addr_pool_extend(struct rte_port *port)
2185 struct ether_addr *mc_pool;
2186 size_t mc_pool_size;
2189 * If a free entry is available at the end of the pool, just
2190 * increment the number of recorded multicast addresses.
2192 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
2198 * [re]allocate a pool with MCAST_POOL_INC more entries.
2199 * The previous test guarantees that port->mc_addr_nb is a multiple
2200 * of MCAST_POOL_INC.
2202 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
2204 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
2206 if (mc_pool == NULL) {
2207 printf("allocation of pool of %u multicast addresses failed\n",
2208 port->mc_addr_nb + MCAST_POOL_INC);
2212 port->mc_addr_pool = mc_pool;
2219 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
2222 if (addr_idx == port->mc_addr_nb) {
2223 /* No need to recompact the set of multicast addressses. */
2224 if (port->mc_addr_nb == 0) {
2225 /* free the pool of multicast addresses. */
2226 free(port->mc_addr_pool);
2227 port->mc_addr_pool = NULL;
2231 memmove(&port->mc_addr_pool[addr_idx],
2232 &port->mc_addr_pool[addr_idx + 1],
2233 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
2237 eth_port_multicast_addr_list_set(uint8_t port_id)
2239 struct rte_port *port;
2242 port = &ports[port_id];
2243 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
2247 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
2248 port->mc_addr_nb, port_id, -diag);
2252 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
2254 struct rte_port *port;
2257 if (port_id_is_invalid(port_id, ENABLED_WARN))
2260 port = &ports[port_id];
2263 * Check that the added multicast MAC address is not already recorded
2264 * in the pool of multicast addresses.
2266 for (i = 0; i < port->mc_addr_nb; i++) {
2267 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
2268 printf("multicast address already filtered by port\n");
2273 if (mcast_addr_pool_extend(port) != 0)
2275 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
2276 eth_port_multicast_addr_list_set(port_id);
2280 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
2282 struct rte_port *port;
2285 if (port_id_is_invalid(port_id, ENABLED_WARN))
2288 port = &ports[port_id];
2291 * Search the pool of multicast MAC addresses for the removed address.
2293 for (i = 0; i < port->mc_addr_nb; i++) {
2294 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
2297 if (i == port->mc_addr_nb) {
2298 printf("multicast address not filtered by port %d\n", port_id);
2302 mcast_addr_pool_remove(port, i);
2303 eth_port_multicast_addr_list_set(port_id);
2307 port_dcb_info_display(uint8_t port_id)
2309 struct rte_eth_dcb_info dcb_info;
2312 static const char *border = "================";
2314 if (port_id_is_invalid(port_id, ENABLED_WARN))
2317 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
2319 printf("\n Failed to get dcb infos on port %-2d\n",
2323 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
2324 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
2326 for (i = 0; i < dcb_info.nb_tcs; i++)
2328 printf("\n Priority : ");
2329 for (i = 0; i < dcb_info.nb_tcs; i++)
2330 printf("\t%4d", dcb_info.prio_tc[i]);
2331 printf("\n BW percent :");
2332 for (i = 0; i < dcb_info.nb_tcs; i++)
2333 printf("\t%4d%%", dcb_info.tc_bws[i]);
2334 printf("\n RXQ base : ");
2335 for (i = 0; i < dcb_info.nb_tcs; i++)
2336 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
2337 printf("\n RXQ number :");
2338 for (i = 0; i < dcb_info.nb_tcs; i++)
2339 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
2340 printf("\n TXQ base : ");
2341 for (i = 0; i < dcb_info.nb_tcs; i++)
2342 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
2343 printf("\n TXQ number :");
2344 for (i = 0; i < dcb_info.nb_tcs; i++)
2345 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);