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 static const struct {
101 enum tx_pkt_split split;
103 } tx_split_name[] = {
105 .split = TX_PKT_SPLIT_OFF,
109 .split = TX_PKT_SPLIT_ON,
113 .split = TX_PKT_SPLIT_RND,
118 struct rss_type_info {
123 static const struct rss_type_info rss_type_table[] = {
124 { "ipv4", ETH_RSS_IPV4 },
125 { "ipv4-frag", ETH_RSS_FRAG_IPV4 },
126 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP },
127 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP },
128 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP },
129 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER },
130 { "ipv6", ETH_RSS_IPV6 },
131 { "ipv6-frag", ETH_RSS_FRAG_IPV6 },
132 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP },
133 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP },
134 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP },
135 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER },
136 { "l2-payload", ETH_RSS_L2_PAYLOAD },
137 { "ipv6-ex", ETH_RSS_IPV6_EX },
138 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX },
139 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX },
143 print_ethaddr(const char *name, struct ether_addr *eth_addr)
145 char buf[ETHER_ADDR_FMT_SIZE];
146 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
147 printf("%s%s", name, buf);
151 nic_stats_display(portid_t port_id)
153 struct rte_eth_stats stats;
154 struct rte_port *port = &ports[port_id];
158 static const char *nic_stats_border = "########################";
160 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
161 printf("Valid port range is [0");
162 FOREACH_PORT(pid, ports)
167 rte_eth_stats_get(port_id, &stats);
168 printf("\n %s NIC statistics for port %-2d %s\n",
169 nic_stats_border, port_id, nic_stats_border);
171 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
172 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
174 stats.ipackets, stats.imissed, stats.ibytes);
175 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
176 printf(" RX-nombuf: %-10"PRIu64"\n",
178 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
180 stats.opackets, stats.oerrors, stats.obytes);
183 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
184 " RX-bytes: %10"PRIu64"\n",
185 stats.ipackets, stats.ierrors, stats.ibytes);
186 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors);
187 printf(" RX-nombuf: %10"PRIu64"\n",
189 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
190 " TX-bytes: %10"PRIu64"\n",
191 stats.opackets, stats.oerrors, stats.obytes);
194 if (port->rx_queue_stats_mapping_enabled) {
196 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
197 printf(" Stats reg %2d RX-packets: %10"PRIu64
198 " RX-errors: %10"PRIu64
199 " RX-bytes: %10"PRIu64"\n",
200 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
203 if (port->tx_queue_stats_mapping_enabled) {
205 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
206 printf(" Stats reg %2d TX-packets: %10"PRIu64
207 " TX-bytes: %10"PRIu64"\n",
208 i, stats.q_opackets[i], stats.q_obytes[i]);
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 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
322 struct rte_eth_rxq_info qinfo;
324 static const char *info_border = "*********************";
326 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
328 printf("Failed to retrieve information for port: %hhu, "
329 "RX queue: %hu\nerror desc: %s(%d)\n",
330 port_id, queue_id, strerror(-rc), rc);
334 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
335 info_border, port_id, queue_id, info_border);
337 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
338 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
339 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
340 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
341 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
342 printf("\nRX drop packets: %s",
343 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
344 printf("\nRX deferred start: %s",
345 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
346 printf("\nRX scattered packets: %s",
347 (qinfo.scattered_rx != 0) ? "on" : "off");
348 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
353 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
355 struct rte_eth_txq_info qinfo;
357 static const char *info_border = "*********************";
359 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
361 printf("Failed to retrieve information for port: %hhu, "
362 "TX queue: %hu\nerror desc: %s(%d)\n",
363 port_id, queue_id, strerror(-rc), rc);
367 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
368 info_border, port_id, queue_id, info_border);
370 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
371 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
372 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
373 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
374 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
375 printf("\nTX flags: %#x", qinfo.conf.txq_flags);
376 printf("\nTX deferred start: %s",
377 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
378 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
383 port_infos_display(portid_t port_id)
385 struct rte_port *port;
386 struct ether_addr mac_addr;
387 struct rte_eth_link link;
388 struct rte_eth_dev_info dev_info;
390 struct rte_mempool * mp;
391 static const char *info_border = "*********************";
394 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
395 printf("Valid port range is [0");
396 FOREACH_PORT(pid, ports)
401 port = &ports[port_id];
402 rte_eth_link_get_nowait(port_id, &link);
403 printf("\n%s Infos for port %-2d %s\n",
404 info_border, port_id, info_border);
405 rte_eth_macaddr_get(port_id, &mac_addr);
406 print_ethaddr("MAC address: ", &mac_addr);
407 printf("\nConnect to socket: %u", port->socket_id);
409 if (port_numa[port_id] != NUMA_NO_CONFIG) {
410 mp = mbuf_pool_find(port_numa[port_id]);
412 printf("\nmemory allocation on the socket: %d",
415 printf("\nmemory allocation on the socket: %u",port->socket_id);
417 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
418 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
419 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
420 ("full-duplex") : ("half-duplex"));
421 printf("Promiscuous mode: %s\n",
422 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
423 printf("Allmulticast mode: %s\n",
424 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
425 printf("Maximum number of MAC addresses: %u\n",
426 (unsigned int)(port->dev_info.max_mac_addrs));
427 printf("Maximum number of MAC addresses of hash filtering: %u\n",
428 (unsigned int)(port->dev_info.max_hash_mac_addrs));
430 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
431 if (vlan_offload >= 0){
432 printf("VLAN offload: \n");
433 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
434 printf(" strip on \n");
436 printf(" strip off \n");
438 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
439 printf(" filter on \n");
441 printf(" filter off \n");
443 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
444 printf(" qinq(extend) on \n");
446 printf(" qinq(extend) off \n");
449 memset(&dev_info, 0, sizeof(dev_info));
450 rte_eth_dev_info_get(port_id, &dev_info);
451 if (dev_info.hash_key_size > 0)
452 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
453 if (dev_info.reta_size > 0)
454 printf("Redirection table size: %u\n", dev_info.reta_size);
455 if (!dev_info.flow_type_rss_offloads)
456 printf("No flow type is supported.\n");
461 printf("Supported flow types:\n");
462 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX;
464 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
466 p = flowtype_to_str(i);
467 printf(" %s\n", (p ? p : "unknown"));
471 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
472 printf("Max possible number of RXDs per queue: %hu\n",
473 dev_info.rx_desc_lim.nb_max);
474 printf("Min possible number of RXDs per queue: %hu\n",
475 dev_info.rx_desc_lim.nb_min);
476 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
478 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
479 printf("Max possible number of TXDs per queue: %hu\n",
480 dev_info.tx_desc_lim.nb_max);
481 printf("Min possible number of TXDs per queue: %hu\n",
482 dev_info.tx_desc_lim.nb_min);
483 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
487 port_id_is_invalid(portid_t port_id, enum print_warning warning)
489 if (port_id == (portid_t)RTE_PORT_ALL)
492 if (port_id < RTE_MAX_ETHPORTS && ports[port_id].enabled)
495 if (warning == ENABLED_WARN)
496 printf("Invalid port %d\n", port_id);
502 vlan_id_is_invalid(uint16_t vlan_id)
506 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
511 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
516 printf("Port register offset 0x%X not aligned on a 4-byte "
521 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
522 if (reg_off >= pci_len) {
523 printf("Port %d: register offset %u (0x%X) out of port PCI "
524 "resource (length=%"PRIu64")\n",
525 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
532 reg_bit_pos_is_invalid(uint8_t bit_pos)
536 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
540 #define display_port_and_reg_off(port_id, reg_off) \
541 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
544 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
546 display_port_and_reg_off(port_id, (unsigned)reg_off);
547 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
551 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
556 if (port_id_is_invalid(port_id, ENABLED_WARN))
558 if (port_reg_off_is_invalid(port_id, reg_off))
560 if (reg_bit_pos_is_invalid(bit_x))
562 reg_v = port_id_pci_reg_read(port_id, reg_off);
563 display_port_and_reg_off(port_id, (unsigned)reg_off);
564 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
568 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
569 uint8_t bit1_pos, uint8_t bit2_pos)
575 if (port_id_is_invalid(port_id, ENABLED_WARN))
577 if (port_reg_off_is_invalid(port_id, reg_off))
579 if (reg_bit_pos_is_invalid(bit1_pos))
581 if (reg_bit_pos_is_invalid(bit2_pos))
583 if (bit1_pos > bit2_pos)
584 l_bit = bit2_pos, h_bit = bit1_pos;
586 l_bit = bit1_pos, h_bit = bit2_pos;
588 reg_v = port_id_pci_reg_read(port_id, reg_off);
591 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
592 display_port_and_reg_off(port_id, (unsigned)reg_off);
593 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
594 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
598 port_reg_display(portid_t port_id, uint32_t reg_off)
602 if (port_id_is_invalid(port_id, ENABLED_WARN))
604 if (port_reg_off_is_invalid(port_id, reg_off))
606 reg_v = port_id_pci_reg_read(port_id, reg_off);
607 display_port_reg_value(port_id, reg_off, reg_v);
611 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
616 if (port_id_is_invalid(port_id, ENABLED_WARN))
618 if (port_reg_off_is_invalid(port_id, reg_off))
620 if (reg_bit_pos_is_invalid(bit_pos))
623 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
626 reg_v = port_id_pci_reg_read(port_id, reg_off);
628 reg_v &= ~(1 << bit_pos);
630 reg_v |= (1 << bit_pos);
631 port_id_pci_reg_write(port_id, reg_off, reg_v);
632 display_port_reg_value(port_id, reg_off, reg_v);
636 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
637 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
644 if (port_id_is_invalid(port_id, ENABLED_WARN))
646 if (port_reg_off_is_invalid(port_id, reg_off))
648 if (reg_bit_pos_is_invalid(bit1_pos))
650 if (reg_bit_pos_is_invalid(bit2_pos))
652 if (bit1_pos > bit2_pos)
653 l_bit = bit2_pos, h_bit = bit1_pos;
655 l_bit = bit1_pos, h_bit = bit2_pos;
657 if ((h_bit - l_bit) < 31)
658 max_v = (1 << (h_bit - l_bit + 1)) - 1;
663 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
664 (unsigned)value, (unsigned)value,
665 (unsigned)max_v, (unsigned)max_v);
668 reg_v = port_id_pci_reg_read(port_id, reg_off);
669 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
670 reg_v |= (value << l_bit); /* Set changed bits */
671 port_id_pci_reg_write(port_id, reg_off, reg_v);
672 display_port_reg_value(port_id, reg_off, reg_v);
676 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
678 if (port_id_is_invalid(port_id, ENABLED_WARN))
680 if (port_reg_off_is_invalid(port_id, reg_off))
682 port_id_pci_reg_write(port_id, reg_off, reg_v);
683 display_port_reg_value(port_id, reg_off, reg_v);
687 port_mtu_set(portid_t port_id, uint16_t mtu)
691 if (port_id_is_invalid(port_id, ENABLED_WARN))
693 diag = rte_eth_dev_set_mtu(port_id, mtu);
696 printf("Set MTU failed. diag=%d\n", diag);
700 * RX/TX ring descriptors display functions.
703 rx_queue_id_is_invalid(queueid_t rxq_id)
707 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
712 tx_queue_id_is_invalid(queueid_t txq_id)
716 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
721 rx_desc_id_is_invalid(uint16_t rxdesc_id)
723 if (rxdesc_id < nb_rxd)
725 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
731 tx_desc_id_is_invalid(uint16_t txdesc_id)
733 if (txdesc_id < nb_txd)
735 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
740 static const struct rte_memzone *
741 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
743 char mz_name[RTE_MEMZONE_NAMESIZE];
744 const struct rte_memzone *mz;
746 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
747 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
748 mz = rte_memzone_lookup(mz_name);
750 printf("%s ring memory zoneof (port %d, queue %d) not"
751 "found (zone name = %s\n",
752 ring_name, port_id, q_id, mz_name);
756 union igb_ring_dword {
759 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
769 struct igb_ring_desc_32_bytes {
770 union igb_ring_dword lo_dword;
771 union igb_ring_dword hi_dword;
772 union igb_ring_dword resv1;
773 union igb_ring_dword resv2;
776 struct igb_ring_desc_16_bytes {
777 union igb_ring_dword lo_dword;
778 union igb_ring_dword hi_dword;
782 ring_rxd_display_dword(union igb_ring_dword dword)
784 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
785 (unsigned)dword.words.hi);
789 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
790 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
793 __rte_unused uint8_t port_id,
797 struct igb_ring_desc_16_bytes *ring =
798 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
799 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
800 struct rte_eth_dev_info dev_info;
802 memset(&dev_info, 0, sizeof(dev_info));
803 rte_eth_dev_info_get(port_id, &dev_info);
804 if (strstr(dev_info.driver_name, "i40e") != NULL) {
805 /* 32 bytes RX descriptor, i40e only */
806 struct igb_ring_desc_32_bytes *ring =
807 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
808 ring[desc_id].lo_dword.dword =
809 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
810 ring_rxd_display_dword(ring[desc_id].lo_dword);
811 ring[desc_id].hi_dword.dword =
812 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
813 ring_rxd_display_dword(ring[desc_id].hi_dword);
814 ring[desc_id].resv1.dword =
815 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
816 ring_rxd_display_dword(ring[desc_id].resv1);
817 ring[desc_id].resv2.dword =
818 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
819 ring_rxd_display_dword(ring[desc_id].resv2);
824 /* 16 bytes RX descriptor */
825 ring[desc_id].lo_dword.dword =
826 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
827 ring_rxd_display_dword(ring[desc_id].lo_dword);
828 ring[desc_id].hi_dword.dword =
829 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
830 ring_rxd_display_dword(ring[desc_id].hi_dword);
834 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
836 struct igb_ring_desc_16_bytes *ring;
837 struct igb_ring_desc_16_bytes txd;
839 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
840 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
841 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
842 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
843 (unsigned)txd.lo_dword.words.lo,
844 (unsigned)txd.lo_dword.words.hi,
845 (unsigned)txd.hi_dword.words.lo,
846 (unsigned)txd.hi_dword.words.hi);
850 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
852 const struct rte_memzone *rx_mz;
854 if (port_id_is_invalid(port_id, ENABLED_WARN))
856 if (rx_queue_id_is_invalid(rxq_id))
858 if (rx_desc_id_is_invalid(rxd_id))
860 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
863 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
867 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
869 const struct rte_memzone *tx_mz;
871 if (port_id_is_invalid(port_id, ENABLED_WARN))
873 if (tx_queue_id_is_invalid(txq_id))
875 if (tx_desc_id_is_invalid(txd_id))
877 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
880 ring_tx_descriptor_display(tx_mz, txd_id);
884 fwd_lcores_config_display(void)
888 printf("List of forwarding lcores:");
889 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
890 printf(" %2u", fwd_lcores_cpuids[lc_id]);
894 rxtx_config_display(void)
896 printf(" %s packet forwarding - CRC stripping %s - "
897 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
898 rx_mode.hw_strip_crc ? "enabled" : "disabled",
901 if (cur_fwd_eng == &tx_only_engine)
902 printf(" packet len=%u - nb packet segments=%d\n",
903 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
905 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf;
906 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf;
908 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
909 nb_fwd_lcores, nb_fwd_ports);
910 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
911 nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
912 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
913 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh,
914 rx_conf->rx_thresh.wthresh);
915 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
916 nb_txq, nb_txd, tx_conf->tx_free_thresh);
917 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
918 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh,
919 tx_conf->tx_thresh.wthresh);
920 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
921 tx_conf->tx_rs_thresh, tx_conf->txq_flags);
925 port_rss_reta_info(portid_t port_id,
926 struct rte_eth_rss_reta_entry64 *reta_conf,
929 uint16_t i, idx, shift;
932 if (port_id_is_invalid(port_id, ENABLED_WARN))
935 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
937 printf("Failed to get RSS RETA info, return code = %d\n", ret);
941 for (i = 0; i < nb_entries; i++) {
942 idx = i / RTE_RETA_GROUP_SIZE;
943 shift = i % RTE_RETA_GROUP_SIZE;
944 if (!(reta_conf[idx].mask & (1ULL << shift)))
946 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
947 i, reta_conf[idx].reta[shift]);
952 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
956 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key)
958 struct rte_eth_rss_conf rss_conf;
959 uint8_t rss_key[10 * 4] = "";
964 if (port_id_is_invalid(port_id, ENABLED_WARN))
968 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
969 if (!strcmp(rss_info, rss_type_table[i].str))
970 rss_conf.rss_hf = rss_type_table[i].rss_type;
973 /* Get RSS hash key if asked to display it */
974 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
975 rss_conf.rss_key_len = sizeof(rss_key);
976 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
980 printf("port index %d invalid\n", port_id);
983 printf("operation not supported by device\n");
986 printf("operation failed - diag=%d\n", diag);
991 rss_hf = rss_conf.rss_hf;
993 printf("RSS disabled\n");
996 printf("RSS functions:\n ");
997 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
998 if (rss_hf & rss_type_table[i].rss_type)
999 printf("%s ", rss_type_table[i].str);
1004 printf("RSS key:\n");
1005 for (i = 0; i < sizeof(rss_key); i++)
1006 printf("%02X", rss_key[i]);
1011 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
1014 struct rte_eth_rss_conf rss_conf;
1018 rss_conf.rss_key = NULL;
1019 rss_conf.rss_key_len = hash_key_len;
1020 rss_conf.rss_hf = 0;
1021 for (i = 0; i < RTE_DIM(rss_type_table); i++) {
1022 if (!strcmp(rss_type_table[i].str, rss_type))
1023 rss_conf.rss_hf = rss_type_table[i].rss_type;
1025 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
1027 rss_conf.rss_key = hash_key;
1028 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
1035 printf("port index %d invalid\n", port_id);
1038 printf("operation not supported by device\n");
1041 printf("operation failed - diag=%d\n", diag);
1047 * Setup forwarding configuration for each logical core.
1050 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
1052 streamid_t nb_fs_per_lcore;
1060 nb_fs = cfg->nb_fwd_streams;
1061 nb_fc = cfg->nb_fwd_lcores;
1062 if (nb_fs <= nb_fc) {
1063 nb_fs_per_lcore = 1;
1066 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
1067 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
1070 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
1072 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
1073 fwd_lcores[lc_id]->stream_idx = sm_id;
1074 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
1075 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1079 * Assign extra remaining streams, if any.
1081 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
1082 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
1083 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
1084 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
1085 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
1090 simple_fwd_config_setup(void)
1096 if (port_topology == PORT_TOPOLOGY_CHAINED ||
1097 port_topology == PORT_TOPOLOGY_LOOP) {
1099 } else if (nb_fwd_ports % 2) {
1100 printf("\nWarning! Cannot handle an odd number of ports "
1101 "with the current port topology. Configuration "
1102 "must be changed to have an even number of ports, "
1103 "or relaunch application with "
1104 "--port-topology=chained\n\n");
1107 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
1108 cur_fwd_config.nb_fwd_streams =
1109 (streamid_t) cur_fwd_config.nb_fwd_ports;
1111 /* reinitialize forwarding streams */
1115 * In the simple forwarding test, the number of forwarding cores
1116 * must be lower or equal to the number of forwarding ports.
1118 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1119 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
1120 cur_fwd_config.nb_fwd_lcores =
1121 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
1122 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1124 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
1125 if (port_topology != PORT_TOPOLOGY_LOOP)
1126 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
1129 fwd_streams[i]->rx_port = fwd_ports_ids[i];
1130 fwd_streams[i]->rx_queue = 0;
1131 fwd_streams[i]->tx_port = fwd_ports_ids[j];
1132 fwd_streams[i]->tx_queue = 0;
1133 fwd_streams[i]->peer_addr = j;
1135 if (port_topology == PORT_TOPOLOGY_PAIRED) {
1136 fwd_streams[j]->rx_port = fwd_ports_ids[j];
1137 fwd_streams[j]->rx_queue = 0;
1138 fwd_streams[j]->tx_port = fwd_ports_ids[i];
1139 fwd_streams[j]->tx_queue = 0;
1140 fwd_streams[j]->peer_addr = i;
1146 * For the RSS forwarding test, each core is assigned on every port a transmit
1147 * queue whose index is the index of the core itself. This approach limits the
1148 * maximumm number of processing cores of the RSS test to the maximum number of
1149 * TX queues supported by the devices.
1151 * Each core is assigned a single 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.
1154 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1155 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1157 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1161 rss_fwd_config_setup(void)
1172 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1173 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1174 cur_fwd_config.nb_fwd_streams =
1175 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1176 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
1177 cur_fwd_config.nb_fwd_streams =
1178 (streamid_t)cur_fwd_config.nb_fwd_lcores;
1180 cur_fwd_config.nb_fwd_lcores =
1181 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1183 /* reinitialize forwarding streams */
1186 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1188 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1189 struct fwd_stream *fs;
1191 fs = fwd_streams[lc_id];
1193 if ((rxp & 0x1) == 0)
1194 txp = (portid_t) (rxp + 1);
1196 txp = (portid_t) (rxp - 1);
1198 * if we are in loopback, simply send stuff out through the
1201 if (port_topology == PORT_TOPOLOGY_LOOP)
1204 fs->rx_port = fwd_ports_ids[rxp];
1206 fs->tx_port = fwd_ports_ids[txp];
1208 fs->peer_addr = fs->tx_port;
1209 rxq = (queueid_t) (rxq + 1);
1214 * Restart from RX queue 0 on next RX port
1217 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1219 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1221 rxp = (portid_t) (rxp + 1);
1226 * For the DCB forwarding test, each core is assigned on each traffic class.
1228 * Each core is assigned a multi-stream, each stream being composed of
1229 * a RX queue to poll on a RX port for input messages, associated with
1230 * a TX queue of a TX port where to send forwarded packets. All RX and
1231 * TX queues are mapping to the same traffic class.
1232 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
1236 dcb_fwd_config_setup(void)
1238 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
1239 portid_t txp, rxp = 0;
1240 queueid_t txq, rxq = 0;
1242 uint16_t nb_rx_queue, nb_tx_queue;
1243 uint16_t i, j, k, sm_id = 0;
1246 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1247 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1248 cur_fwd_config.nb_fwd_streams =
1249 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1251 /* reinitialize forwarding streams */
1255 /* get the dcb info on the first RX and TX ports */
1256 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1257 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
1259 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1260 fwd_lcores[lc_id]->stream_nb = 0;
1261 fwd_lcores[lc_id]->stream_idx = sm_id;
1262 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) {
1263 /* if the nb_queue is zero, means this tc is
1264 * not enabled on the POOL
1266 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
1268 k = fwd_lcores[lc_id]->stream_nb +
1269 fwd_lcores[lc_id]->stream_idx;
1270 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
1271 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
1272 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
1273 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
1274 for (j = 0; j < nb_rx_queue; j++) {
1275 struct fwd_stream *fs;
1277 fs = fwd_streams[k + j];
1278 fs->rx_port = fwd_ports_ids[rxp];
1279 fs->rx_queue = rxq + j;
1280 fs->tx_port = fwd_ports_ids[txp];
1281 fs->tx_queue = txq + j % nb_tx_queue;
1282 fs->peer_addr = fs->tx_port;
1284 fwd_lcores[lc_id]->stream_nb +=
1285 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
1287 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
1290 if (tc < rxp_dcb_info.nb_tcs)
1292 /* Restart from TC 0 on next RX port */
1294 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1296 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1299 if (rxp >= nb_fwd_ports)
1301 /* get the dcb information on next RX and TX ports */
1302 if ((rxp & 0x1) == 0)
1303 txp = (portid_t) (rxp + 1);
1305 txp = (portid_t) (rxp - 1);
1306 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
1307 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
1312 icmp_echo_config_setup(void)
1319 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1320 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1321 (nb_txq * nb_fwd_ports);
1323 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1324 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1325 cur_fwd_config.nb_fwd_streams =
1326 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1327 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1328 cur_fwd_config.nb_fwd_lcores =
1329 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1330 if (verbose_level > 0) {
1331 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1333 cur_fwd_config.nb_fwd_lcores,
1334 cur_fwd_config.nb_fwd_ports,
1335 cur_fwd_config.nb_fwd_streams);
1338 /* reinitialize forwarding streams */
1340 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1342 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1343 if (verbose_level > 0)
1344 printf(" core=%d: \n", lc_id);
1345 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1346 struct fwd_stream *fs;
1347 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1348 fs->rx_port = fwd_ports_ids[rxp];
1350 fs->tx_port = fs->rx_port;
1352 fs->peer_addr = fs->tx_port;
1353 if (verbose_level > 0)
1354 printf(" stream=%d port=%d rxq=%d txq=%d\n",
1355 sm_id, fs->rx_port, fs->rx_queue,
1357 rxq = (queueid_t) (rxq + 1);
1358 if (rxq == nb_rxq) {
1360 rxp = (portid_t) (rxp + 1);
1367 fwd_config_setup(void)
1369 cur_fwd_config.fwd_eng = cur_fwd_eng;
1370 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1371 icmp_echo_config_setup();
1374 if ((nb_rxq > 1) && (nb_txq > 1)){
1376 dcb_fwd_config_setup();
1378 rss_fwd_config_setup();
1381 simple_fwd_config_setup();
1385 pkt_fwd_config_display(struct fwd_config *cfg)
1387 struct fwd_stream *fs;
1391 printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
1392 "NUMA support %s, MP over anonymous pages %s\n",
1393 cfg->fwd_eng->fwd_mode_name,
1394 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1395 numa_support == 1 ? "enabled" : "disabled",
1396 mp_anon != 0 ? "enabled" : "disabled");
1398 if (strcmp(cfg->fwd_eng->fwd_mode_name, "mac_retry") == 0)
1399 printf("TX retry num: %u, delay between TX retries: %uus\n",
1400 burst_tx_retry_num, burst_tx_delay_time);
1401 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1402 printf("Logical Core %u (socket %u) forwards packets on "
1404 fwd_lcores_cpuids[lc_id],
1405 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1406 fwd_lcores[lc_id]->stream_nb);
1407 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1408 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1409 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
1410 "P=%d/Q=%d (socket %u) ",
1411 fs->rx_port, fs->rx_queue,
1412 ports[fs->rx_port].socket_id,
1413 fs->tx_port, fs->tx_queue,
1414 ports[fs->tx_port].socket_id);
1415 print_ethaddr("peer=",
1416 &peer_eth_addrs[fs->peer_addr]);
1425 fwd_config_display(void)
1428 pkt_fwd_config_display(&cur_fwd_config);
1432 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1435 unsigned int lcore_cpuid;
1440 for (i = 0; i < nb_lc; i++) {
1441 lcore_cpuid = lcorelist[i];
1442 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1443 printf("lcore %u not enabled\n", lcore_cpuid);
1446 if (lcore_cpuid == rte_get_master_lcore()) {
1447 printf("lcore %u cannot be masked on for running "
1448 "packet forwarding, which is the master lcore "
1449 "and reserved for command line parsing only\n",
1454 fwd_lcores_cpuids[i] = lcore_cpuid;
1456 if (record_now == 0) {
1460 nb_cfg_lcores = (lcoreid_t) nb_lc;
1461 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1462 printf("previous number of forwarding cores %u - changed to "
1463 "number of configured cores %u\n",
1464 (unsigned int) nb_fwd_lcores, nb_lc);
1465 nb_fwd_lcores = (lcoreid_t) nb_lc;
1472 set_fwd_lcores_mask(uint64_t lcoremask)
1474 unsigned int lcorelist[64];
1478 if (lcoremask == 0) {
1479 printf("Invalid NULL mask of cores\n");
1483 for (i = 0; i < 64; i++) {
1484 if (! ((uint64_t)(1ULL << i) & lcoremask))
1486 lcorelist[nb_lc++] = i;
1488 return set_fwd_lcores_list(lcorelist, nb_lc);
1492 set_fwd_lcores_number(uint16_t nb_lc)
1494 if (nb_lc > nb_cfg_lcores) {
1495 printf("nb fwd cores %u > %u (max. number of configured "
1496 "lcores) - ignored\n",
1497 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1500 nb_fwd_lcores = (lcoreid_t) nb_lc;
1501 printf("Number of forwarding cores set to %u\n",
1502 (unsigned int) nb_fwd_lcores);
1506 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1514 for (i = 0; i < nb_pt; i++) {
1515 port_id = (portid_t) portlist[i];
1516 if (port_id_is_invalid(port_id, ENABLED_WARN))
1519 fwd_ports_ids[i] = port_id;
1521 if (record_now == 0) {
1525 nb_cfg_ports = (portid_t) nb_pt;
1526 if (nb_fwd_ports != (portid_t) nb_pt) {
1527 printf("previous number of forwarding ports %u - changed to "
1528 "number of configured ports %u\n",
1529 (unsigned int) nb_fwd_ports, nb_pt);
1530 nb_fwd_ports = (portid_t) nb_pt;
1535 set_fwd_ports_mask(uint64_t portmask)
1537 unsigned int portlist[64];
1541 if (portmask == 0) {
1542 printf("Invalid NULL mask of ports\n");
1546 for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
1547 if (! ((uint64_t)(1ULL << i) & portmask))
1549 portlist[nb_pt++] = i;
1551 set_fwd_ports_list(portlist, nb_pt);
1555 set_fwd_ports_number(uint16_t nb_pt)
1557 if (nb_pt > nb_cfg_ports) {
1558 printf("nb fwd ports %u > %u (number of configured "
1559 "ports) - ignored\n",
1560 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1563 nb_fwd_ports = (portid_t) nb_pt;
1564 printf("Number of forwarding ports set to %u\n",
1565 (unsigned int) nb_fwd_ports);
1569 set_nb_pkt_per_burst(uint16_t nb)
1571 if (nb > MAX_PKT_BURST) {
1572 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1574 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1577 nb_pkt_per_burst = nb;
1578 printf("Number of packets per burst set to %u\n",
1579 (unsigned int) nb_pkt_per_burst);
1583 tx_split_get_name(enum tx_pkt_split split)
1587 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
1588 if (tx_split_name[i].split == split)
1589 return tx_split_name[i].name;
1595 set_tx_pkt_split(const char *name)
1599 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
1600 if (strcmp(tx_split_name[i].name, name) == 0) {
1601 tx_pkt_split = tx_split_name[i].split;
1605 printf("unknown value: \"%s\"\n", name);
1609 show_tx_pkt_segments(void)
1615 split = tx_split_get_name(tx_pkt_split);
1617 printf("Number of segments: %u\n", n);
1618 printf("Segment sizes: ");
1619 for (i = 0; i != n - 1; i++)
1620 printf("%hu,", tx_pkt_seg_lengths[i]);
1621 printf("%hu\n", tx_pkt_seg_lengths[i]);
1622 printf("Split packet: %s\n", split);
1626 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1628 uint16_t tx_pkt_len;
1631 if (nb_segs >= (unsigned) nb_txd) {
1632 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1633 nb_segs, (unsigned int) nb_txd);
1638 * Check that each segment length is greater or equal than
1639 * the mbuf data sise.
1640 * Check also that the total packet length is greater or equal than the
1641 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1644 for (i = 0; i < nb_segs; i++) {
1645 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1646 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1647 i, seg_lengths[i], (unsigned) mbuf_data_size);
1650 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1652 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1653 printf("total packet length=%u < %d - give up\n",
1654 (unsigned) tx_pkt_len,
1655 (int)(sizeof(struct ether_hdr) + 20 + 8));
1659 for (i = 0; i < nb_segs; i++)
1660 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1662 tx_pkt_length = tx_pkt_len;
1663 tx_pkt_nb_segs = (uint8_t) nb_segs;
1667 list_pkt_forwarding_modes(void)
1669 static char fwd_modes[128] = "";
1670 const char *separator = "|";
1671 struct fwd_engine *fwd_eng;
1674 if (strlen (fwd_modes) == 0) {
1675 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1676 strcat(fwd_modes, fwd_eng->fwd_mode_name);
1677 strcat(fwd_modes, separator);
1679 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1686 set_pkt_forwarding_mode(const char *fwd_mode_name)
1688 struct fwd_engine *fwd_eng;
1692 while ((fwd_eng = fwd_engines[i]) != NULL) {
1693 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1694 printf("Set %s packet forwarding mode\n",
1696 cur_fwd_eng = fwd_eng;
1701 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1705 set_verbose_level(uint16_t vb_level)
1707 printf("Change verbose level from %u to %u\n",
1708 (unsigned int) verbose_level, (unsigned int) vb_level);
1709 verbose_level = vb_level;
1713 vlan_extend_set(portid_t port_id, int on)
1718 if (port_id_is_invalid(port_id, ENABLED_WARN))
1721 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1724 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1726 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1728 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1730 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1731 "diag=%d\n", port_id, on, diag);
1735 rx_vlan_strip_set(portid_t port_id, int on)
1740 if (port_id_is_invalid(port_id, ENABLED_WARN))
1743 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1746 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1748 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1750 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1752 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1753 "diag=%d\n", port_id, on, diag);
1757 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1761 if (port_id_is_invalid(port_id, ENABLED_WARN))
1764 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1766 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1767 "diag=%d\n", port_id, queue_id, on, diag);
1771 rx_vlan_filter_set(portid_t port_id, int on)
1776 if (port_id_is_invalid(port_id, ENABLED_WARN))
1779 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1782 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1784 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1786 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1788 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1789 "diag=%d\n", port_id, on, diag);
1793 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1797 if (port_id_is_invalid(port_id, ENABLED_WARN))
1799 if (vlan_id_is_invalid(vlan_id))
1801 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1804 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1806 port_id, vlan_id, on, diag);
1811 rx_vlan_all_filter_set(portid_t port_id, int on)
1815 if (port_id_is_invalid(port_id, ENABLED_WARN))
1817 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
1818 if (rx_vft_set(port_id, vlan_id, on))
1824 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1827 if (port_id_is_invalid(port_id, ENABLED_WARN))
1830 diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1834 printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1836 port_id, tp_id, diag);
1840 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1842 if (port_id_is_invalid(port_id, ENABLED_WARN))
1844 if (vlan_id_is_invalid(vlan_id))
1846 tx_vlan_reset(port_id);
1847 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
1848 ports[port_id].tx_vlan_id = vlan_id;
1852 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
1854 if (port_id_is_invalid(port_id, ENABLED_WARN))
1856 if (vlan_id_is_invalid(vlan_id))
1858 if (vlan_id_is_invalid(vlan_id_outer))
1860 tx_vlan_reset(port_id);
1861 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
1862 ports[port_id].tx_vlan_id = vlan_id;
1863 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
1867 tx_vlan_reset(portid_t port_id)
1869 if (port_id_is_invalid(port_id, ENABLED_WARN))
1871 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN |
1872 TESTPMD_TX_OFFLOAD_INSERT_QINQ);
1873 ports[port_id].tx_vlan_id = 0;
1874 ports[port_id].tx_vlan_id_outer = 0;
1878 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
1880 if (port_id_is_invalid(port_id, ENABLED_WARN))
1883 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
1887 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1890 uint8_t existing_mapping_found = 0;
1892 if (port_id_is_invalid(port_id, ENABLED_WARN))
1895 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1898 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1899 printf("map_value not in required range 0..%d\n",
1900 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1904 if (!is_rx) { /*then tx*/
1905 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1906 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1907 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1908 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1909 existing_mapping_found = 1;
1913 if (!existing_mapping_found) { /* A new additional mapping... */
1914 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1915 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1916 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1917 nb_tx_queue_stats_mappings++;
1921 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1922 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1923 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1924 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1925 existing_mapping_found = 1;
1929 if (!existing_mapping_found) { /* A new additional mapping... */
1930 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1931 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1932 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1933 nb_rx_queue_stats_mappings++;
1939 print_fdir_mask(struct rte_eth_fdir_masks *mask)
1941 printf("\n vlan_tci: 0x%04x, ", mask->vlan_tci_mask);
1943 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
1944 printf("mac_addr: 0x%02x", mask->mac_addr_byte_mask);
1945 else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
1946 printf("mac_addr: 0x%02x, tunnel_type: 0x%01x, tunnel_id: 0x%08x",
1947 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
1948 mask->tunnel_id_mask);
1950 printf("src_ipv4: 0x%08x, dst_ipv4: 0x%08x,"
1951 " src_port: 0x%04x, dst_port: 0x%04x",
1952 mask->ipv4_mask.src_ip, mask->ipv4_mask.dst_ip,
1953 mask->src_port_mask, mask->dst_port_mask);
1955 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x,"
1956 " dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
1957 mask->ipv6_mask.src_ip[0], mask->ipv6_mask.src_ip[1],
1958 mask->ipv6_mask.src_ip[2], mask->ipv6_mask.src_ip[3],
1959 mask->ipv6_mask.dst_ip[0], mask->ipv6_mask.dst_ip[1],
1960 mask->ipv6_mask.dst_ip[2], mask->ipv6_mask.dst_ip[3]);
1967 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
1969 struct rte_eth_flex_payload_cfg *cfg;
1972 for (i = 0; i < flex_conf->nb_payloads; i++) {
1973 cfg = &flex_conf->flex_set[i];
1974 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
1976 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
1977 printf("\n L2_PAYLOAD: ");
1978 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
1979 printf("\n L3_PAYLOAD: ");
1980 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
1981 printf("\n L4_PAYLOAD: ");
1983 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
1984 for (j = 0; j < num; j++)
1985 printf(" %-5u", cfg->src_offset[j]);
1991 flowtype_to_str(uint16_t flow_type)
1993 struct flow_type_info {
1999 static struct flow_type_info flowtype_str_table[] = {
2000 {"raw", RTE_ETH_FLOW_RAW},
2001 {"ipv4", RTE_ETH_FLOW_IPV4},
2002 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
2003 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
2004 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
2005 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
2006 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
2007 {"ipv6", RTE_ETH_FLOW_IPV6},
2008 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
2009 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
2010 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
2011 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
2012 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
2013 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
2016 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
2017 if (flowtype_str_table[i].ftype == flow_type)
2018 return flowtype_str_table[i].str;
2025 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
2027 struct rte_eth_fdir_flex_mask *mask;
2031 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
2032 mask = &flex_conf->flex_mask[i];
2033 p = flowtype_to_str(mask->flow_type);
2034 printf("\n %s:\t", p ? p : "unknown");
2035 for (j = 0; j < num; j++)
2036 printf(" %02x", mask->mask[j]);
2042 print_fdir_flow_type(uint32_t flow_types_mask)
2047 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
2048 if (!(flow_types_mask & (1 << i)))
2050 p = flowtype_to_str(i);
2060 fdir_get_infos(portid_t port_id)
2062 struct rte_eth_fdir_stats fdir_stat;
2063 struct rte_eth_fdir_info fdir_info;
2066 static const char *fdir_stats_border = "########################";
2068 if (port_id_is_invalid(port_id, ENABLED_WARN))
2070 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
2072 printf("\n FDIR is not supported on port %-2d\n",
2077 memset(&fdir_info, 0, sizeof(fdir_info));
2078 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2079 RTE_ETH_FILTER_INFO, &fdir_info);
2080 memset(&fdir_stat, 0, sizeof(fdir_stat));
2081 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR,
2082 RTE_ETH_FILTER_STATS, &fdir_stat);
2083 printf("\n %s FDIR infos for port %-2d %s\n",
2084 fdir_stats_border, port_id, fdir_stats_border);
2086 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
2087 printf(" PERFECT\n");
2088 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
2089 printf(" PERFECT-MAC-VLAN\n");
2090 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2091 printf(" PERFECT-TUNNEL\n");
2092 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
2093 printf(" SIGNATURE\n");
2095 printf(" DISABLE\n");
2096 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
2097 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
2098 printf(" SUPPORTED FLOW TYPE: ");
2099 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
2101 printf(" FLEX PAYLOAD INFO:\n");
2102 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
2103 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
2104 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
2105 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
2106 fdir_info.flex_payload_unit,
2107 fdir_info.max_flex_payload_segment_num,
2108 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
2110 print_fdir_mask(&fdir_info.mask);
2111 if (fdir_info.flex_conf.nb_payloads > 0) {
2112 printf(" FLEX PAYLOAD SRC OFFSET:");
2113 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2115 if (fdir_info.flex_conf.nb_flexmasks > 0) {
2116 printf(" FLEX MASK CFG:");
2117 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
2119 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
2120 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
2121 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
2122 fdir_info.guarant_spc, fdir_info.best_spc);
2123 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
2124 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
2125 " add: %-10"PRIu64" remove: %"PRIu64"\n"
2126 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
2127 fdir_stat.collision, fdir_stat.free,
2128 fdir_stat.maxhash, fdir_stat.maxlen,
2129 fdir_stat.add, fdir_stat.remove,
2130 fdir_stat.f_add, fdir_stat.f_remove);
2131 printf(" %s############################%s\n",
2132 fdir_stats_border, fdir_stats_border);
2136 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
2138 struct rte_port *port;
2139 struct rte_eth_fdir_flex_conf *flex_conf;
2142 port = &ports[port_id];
2143 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2144 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
2145 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
2150 if (i >= RTE_ETH_FLOW_MAX) {
2151 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
2152 idx = flex_conf->nb_flexmasks;
2153 flex_conf->nb_flexmasks++;
2155 printf("The flex mask table is full. Can not set flex"
2156 " mask for flow_type(%u).", cfg->flow_type);
2160 (void)rte_memcpy(&flex_conf->flex_mask[idx],
2162 sizeof(struct rte_eth_fdir_flex_mask));
2166 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
2168 struct rte_port *port;
2169 struct rte_eth_fdir_flex_conf *flex_conf;
2172 port = &ports[port_id];
2173 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
2174 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
2175 if (cfg->type == flex_conf->flex_set[i].type) {
2180 if (i >= RTE_ETH_PAYLOAD_MAX) {
2181 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
2182 idx = flex_conf->nb_payloads;
2183 flex_conf->nb_payloads++;
2185 printf("The flex payload table is full. Can not set"
2186 " flex payload for type(%u).", cfg->type);
2190 (void)rte_memcpy(&flex_conf->flex_set[idx],
2192 sizeof(struct rte_eth_flex_payload_cfg));
2197 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
2201 if (port_id_is_invalid(port_id, ENABLED_WARN))
2204 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
2206 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
2210 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
2211 "diag=%d\n", port_id, diag);
2213 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
2214 "diag=%d\n", port_id, diag);
2219 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
2223 if (port_id_is_invalid(port_id, ENABLED_WARN))
2225 if (vlan_id_is_invalid(vlan_id))
2227 diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
2230 printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
2231 "diag=%d\n", port_id, diag);
2235 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
2238 struct rte_eth_link link;
2240 if (port_id_is_invalid(port_id, ENABLED_WARN))
2242 rte_eth_link_get_nowait(port_id, &link);
2243 if (rate > link.link_speed) {
2244 printf("Invalid rate value:%u bigger than link speed: %u\n",
2245 rate, link.link_speed);
2248 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
2251 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
2257 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
2260 struct rte_eth_link link;
2265 if (port_id_is_invalid(port_id, ENABLED_WARN))
2267 rte_eth_link_get_nowait(port_id, &link);
2268 if (rate > link.link_speed) {
2269 printf("Invalid rate value:%u bigger than link speed: %u\n",
2270 rate, link.link_speed);
2273 diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
2276 printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",
2282 * Functions to manage the set of filtered Multicast MAC addresses.
2284 * A pool of filtered multicast MAC addresses is associated with each port.
2285 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
2286 * The address of the pool and the number of valid multicast MAC addresses
2287 * recorded in the pool are stored in the fields "mc_addr_pool" and
2288 * "mc_addr_nb" of the "rte_port" data structure.
2290 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
2291 * to be supplied a contiguous array of multicast MAC addresses.
2292 * To comply with this constraint, the set of multicast addresses recorded
2293 * into the pool are systematically compacted at the beginning of the pool.
2294 * Hence, when a multicast address is removed from the pool, all following
2295 * addresses, if any, are copied back to keep the set contiguous.
2297 #define MCAST_POOL_INC 32
2300 mcast_addr_pool_extend(struct rte_port *port)
2302 struct ether_addr *mc_pool;
2303 size_t mc_pool_size;
2306 * If a free entry is available at the end of the pool, just
2307 * increment the number of recorded multicast addresses.
2309 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
2315 * [re]allocate a pool with MCAST_POOL_INC more entries.
2316 * The previous test guarantees that port->mc_addr_nb is a multiple
2317 * of MCAST_POOL_INC.
2319 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb +
2321 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool,
2323 if (mc_pool == NULL) {
2324 printf("allocation of pool of %u multicast addresses failed\n",
2325 port->mc_addr_nb + MCAST_POOL_INC);
2329 port->mc_addr_pool = mc_pool;
2336 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
2339 if (addr_idx == port->mc_addr_nb) {
2340 /* No need to recompact the set of multicast addressses. */
2341 if (port->mc_addr_nb == 0) {
2342 /* free the pool of multicast addresses. */
2343 free(port->mc_addr_pool);
2344 port->mc_addr_pool = NULL;
2348 memmove(&port->mc_addr_pool[addr_idx],
2349 &port->mc_addr_pool[addr_idx + 1],
2350 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx));
2354 eth_port_multicast_addr_list_set(uint8_t port_id)
2356 struct rte_port *port;
2359 port = &ports[port_id];
2360 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
2364 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
2365 port->mc_addr_nb, port_id, -diag);
2369 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr)
2371 struct rte_port *port;
2374 if (port_id_is_invalid(port_id, ENABLED_WARN))
2377 port = &ports[port_id];
2380 * Check that the added multicast MAC address is not already recorded
2381 * in the pool of multicast addresses.
2383 for (i = 0; i < port->mc_addr_nb; i++) {
2384 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
2385 printf("multicast address already filtered by port\n");
2390 if (mcast_addr_pool_extend(port) != 0)
2392 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]);
2393 eth_port_multicast_addr_list_set(port_id);
2397 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr)
2399 struct rte_port *port;
2402 if (port_id_is_invalid(port_id, ENABLED_WARN))
2405 port = &ports[port_id];
2408 * Search the pool of multicast MAC addresses for the removed address.
2410 for (i = 0; i < port->mc_addr_nb; i++) {
2411 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
2414 if (i == port->mc_addr_nb) {
2415 printf("multicast address not filtered by port %d\n", port_id);
2419 mcast_addr_pool_remove(port, i);
2420 eth_port_multicast_addr_list_set(port_id);
2424 port_dcb_info_display(uint8_t port_id)
2426 struct rte_eth_dcb_info dcb_info;
2429 static const char *border = "================";
2431 if (port_id_is_invalid(port_id, ENABLED_WARN))
2434 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
2436 printf("\n Failed to get dcb infos on port %-2d\n",
2440 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
2441 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
2443 for (i = 0; i < dcb_info.nb_tcs; i++)
2445 printf("\n Priority : ");
2446 for (i = 0; i < dcb_info.nb_tcs; i++)
2447 printf("\t%4d", dcb_info.prio_tc[i]);
2448 printf("\n BW percent :");
2449 for (i = 0; i < dcb_info.nb_tcs; i++)
2450 printf("\t%4d%%", dcb_info.tc_bws[i]);
2451 printf("\n RXQ base : ");
2452 for (i = 0; i < dcb_info.nb_tcs; i++)
2453 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
2454 printf("\n RXQ number :");
2455 for (i = 0; i < dcb_info.nb_tcs; i++)
2456 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
2457 printf("\n TXQ base : ");
2458 for (i = 0; i < dcb_info.nb_tcs; i++)
2459 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
2460 printf("\n TXQ number :");
2461 for (i = 0; i < dcb_info.nb_tcs; i++)
2462 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);