4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * Copyright(c) 2013 6WIND.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name of 6WIND S.A. nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72 #include <sys/queue.h>
74 #include <rte_common.h>
75 #include <rte_byteorder.h>
76 #include <rte_debug.h>
78 #include <rte_memory.h>
79 #include <rte_memcpy.h>
80 #include <rte_memzone.h>
81 #include <rte_launch.h>
82 #include <rte_tailq.h>
84 #include <rte_per_lcore.h>
85 #include <rte_lcore.h>
86 #include <rte_atomic.h>
87 #include <rte_branch_prediction.h>
89 #include <rte_mempool.h>
91 #include <rte_interrupts.h>
93 #include <rte_ether.h>
94 #include <rte_ethdev.h>
95 #include <rte_string_fns.h>
100 print_ethaddr(const char *name, struct ether_addr *eth_addr)
102 printf("%s%02X:%02X:%02X:%02X:%02X:%02X", name,
103 (unsigned int)eth_addr->addr_bytes[0],
104 (unsigned int)eth_addr->addr_bytes[1],
105 (unsigned int)eth_addr->addr_bytes[2],
106 (unsigned int)eth_addr->addr_bytes[3],
107 (unsigned int)eth_addr->addr_bytes[4],
108 (unsigned int)eth_addr->addr_bytes[5]);
112 nic_stats_display(portid_t port_id)
114 struct rte_eth_stats stats;
115 struct rte_port *port = &ports[port_id];
118 static const char *nic_stats_border = "########################";
120 if (port_id >= nb_ports) {
121 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
124 rte_eth_stats_get(port_id, &stats);
125 printf("\n %s NIC statistics for port %-2d %s\n",
126 nic_stats_border, port_id, nic_stats_border);
128 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
129 printf(" RX-packets: %-10"PRIu64" RX-errors: %-10"PRIu64"RX-bytes: "
131 " TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64"TX-bytes: "
133 stats.ipackets, stats.ierrors, stats.ibytes,
134 stats.opackets, stats.oerrors, stats.obytes);
137 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
138 " RX-bytes: %10"PRIu64"\n"
139 " TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
140 " TX-bytes: %10"PRIu64"\n",
141 stats.ipackets, stats.ierrors, stats.ibytes,
142 stats.opackets, stats.oerrors, stats.obytes);
146 if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
147 printf(" Fdirmiss: %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
151 if (port->rx_queue_stats_mapping_enabled) {
153 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
154 printf(" Stats reg %2d RX-packets: %10"PRIu64
155 " RX-errors: %10"PRIu64
156 " RX-bytes: %10"PRIu64"\n",
157 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
160 if (port->tx_queue_stats_mapping_enabled) {
162 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
163 printf(" Stats reg %2d TX-packets: %10"PRIu64
164 " TX-bytes: %10"PRIu64"\n",
165 i, stats.q_opackets[i], stats.q_obytes[i]);
169 /* Display statistics of XON/XOFF pause frames, if any. */
170 if ((stats.tx_pause_xon | stats.rx_pause_xon |
171 stats.tx_pause_xoff | stats.rx_pause_xoff) > 0) {
172 printf(" RX-XOFF: %-10"PRIu64" RX-XON: %-10"PRIu64"\n",
173 stats.rx_pause_xoff, stats.rx_pause_xon);
174 printf(" TX-XOFF: %-10"PRIu64" TX-XON: %-10"PRIu64"\n",
175 stats.tx_pause_xoff, stats.tx_pause_xon);
177 printf(" %s############################%s\n",
178 nic_stats_border, nic_stats_border);
182 nic_stats_clear(portid_t port_id)
184 if (port_id >= nb_ports) {
185 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
188 rte_eth_stats_reset(port_id);
189 printf("\n NIC statistics for port %d cleared\n", port_id);
194 nic_stats_mapping_display(portid_t port_id)
196 struct rte_port *port = &ports[port_id];
199 static const char *nic_stats_mapping_border = "########################";
201 if (port_id >= nb_ports) {
202 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
206 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
207 printf("Port id %d - either does not support queue statistic mapping or"
208 " no queue statistic mapping set\n", port_id);
212 printf("\n %s NIC statistics mapping for port %-2d %s\n",
213 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
215 if (port->rx_queue_stats_mapping_enabled) {
216 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
217 if (rx_queue_stats_mappings[i].port_id == port_id) {
218 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
219 rx_queue_stats_mappings[i].queue_id,
220 rx_queue_stats_mappings[i].stats_counter_id);
227 if (port->tx_queue_stats_mapping_enabled) {
228 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
229 if (tx_queue_stats_mappings[i].port_id == port_id) {
230 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
231 tx_queue_stats_mappings[i].queue_id,
232 tx_queue_stats_mappings[i].stats_counter_id);
237 printf(" %s####################################%s\n",
238 nic_stats_mapping_border, nic_stats_mapping_border);
242 port_infos_display(portid_t port_id)
244 struct rte_port *port;
245 struct rte_eth_link link;
247 struct rte_mempool * mp;
248 static const char *info_border = "*********************";
250 if (port_id >= nb_ports) {
251 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
254 port = &ports[port_id];
255 rte_eth_link_get_nowait(port_id, &link);
256 printf("\n%s Infos for port %-2d %s\n",
257 info_border, port_id, info_border);
258 print_ethaddr("MAC address: ", &port->eth_addr);
259 printf("\nConnect to socket: %u", port->socket_id);
261 if (port_numa[port_id] != NUMA_NO_CONFIG) {
262 mp = mbuf_pool_find(port_numa[port_id]);
264 printf("\nmemory allocation on the socket: %d",
267 printf("\nmemory allocation on the socket: %u",port->socket_id);
269 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
270 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
271 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
272 ("full-duplex") : ("half-duplex"));
273 printf("Promiscuous mode: %s\n",
274 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
275 printf("Allmulticast mode: %s\n",
276 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
277 printf("Maximum number of MAC addresses: %u\n",
278 (unsigned int)(port->dev_info.max_mac_addrs));
279 printf("Maximum number of MAC addresses of hash filtering: %u\n",
280 (unsigned int)(port->dev_info.max_hash_mac_addrs));
282 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
283 if (vlan_offload >= 0){
284 printf("VLAN offload: \n");
285 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
286 printf(" strip on \n");
288 printf(" strip off \n");
290 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
291 printf(" filter on \n");
293 printf(" filter off \n");
295 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
296 printf(" qinq(extend) on \n");
298 printf(" qinq(extend) off \n");
303 port_id_is_invalid(portid_t port_id)
305 if (port_id < nb_ports)
307 printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
312 vlan_id_is_invalid(uint16_t vlan_id)
316 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
321 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
326 printf("Port register offset 0x%X not aligned on a 4-byte "
331 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
332 if (reg_off >= pci_len) {
333 printf("Port %d: register offset %u (0x%X) out of port PCI "
334 "resource (length=%"PRIu64")\n",
335 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
342 reg_bit_pos_is_invalid(uint8_t bit_pos)
346 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
350 #define display_port_and_reg_off(port_id, reg_off) \
351 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
354 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
356 display_port_and_reg_off(port_id, (unsigned)reg_off);
357 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
361 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
366 if (port_id_is_invalid(port_id))
368 if (port_reg_off_is_invalid(port_id, reg_off))
370 if (reg_bit_pos_is_invalid(bit_x))
372 reg_v = port_id_pci_reg_read(port_id, reg_off);
373 display_port_and_reg_off(port_id, (unsigned)reg_off);
374 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
378 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
379 uint8_t bit1_pos, uint8_t bit2_pos)
385 if (port_id_is_invalid(port_id))
387 if (port_reg_off_is_invalid(port_id, reg_off))
389 if (reg_bit_pos_is_invalid(bit1_pos))
391 if (reg_bit_pos_is_invalid(bit2_pos))
393 if (bit1_pos > bit2_pos)
394 l_bit = bit2_pos, h_bit = bit1_pos;
396 l_bit = bit1_pos, h_bit = bit2_pos;
398 reg_v = port_id_pci_reg_read(port_id, reg_off);
401 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
402 display_port_and_reg_off(port_id, (unsigned)reg_off);
403 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
404 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
408 port_reg_display(portid_t port_id, uint32_t reg_off)
412 if (port_id_is_invalid(port_id))
414 if (port_reg_off_is_invalid(port_id, reg_off))
416 reg_v = port_id_pci_reg_read(port_id, reg_off);
417 display_port_reg_value(port_id, reg_off, reg_v);
421 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
426 if (port_id_is_invalid(port_id))
428 if (port_reg_off_is_invalid(port_id, reg_off))
430 if (reg_bit_pos_is_invalid(bit_pos))
433 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
436 reg_v = port_id_pci_reg_read(port_id, reg_off);
438 reg_v &= ~(1 << bit_pos);
440 reg_v |= (1 << bit_pos);
441 port_id_pci_reg_write(port_id, reg_off, reg_v);
442 display_port_reg_value(port_id, reg_off, reg_v);
446 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
447 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
454 if (port_id_is_invalid(port_id))
456 if (port_reg_off_is_invalid(port_id, reg_off))
458 if (reg_bit_pos_is_invalid(bit1_pos))
460 if (reg_bit_pos_is_invalid(bit2_pos))
462 if (bit1_pos > bit2_pos)
463 l_bit = bit2_pos, h_bit = bit1_pos;
465 l_bit = bit1_pos, h_bit = bit2_pos;
467 if ((h_bit - l_bit) < 31)
468 max_v = (1 << (h_bit - l_bit + 1)) - 1;
473 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
474 (unsigned)value, (unsigned)value,
475 (unsigned)max_v, (unsigned)max_v);
478 reg_v = port_id_pci_reg_read(port_id, reg_off);
479 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
480 reg_v |= (value << l_bit); /* Set changed bits */
481 port_id_pci_reg_write(port_id, reg_off, reg_v);
482 display_port_reg_value(port_id, reg_off, reg_v);
486 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
488 if (port_id_is_invalid(port_id))
490 if (port_reg_off_is_invalid(port_id, reg_off))
492 port_id_pci_reg_write(port_id, reg_off, reg_v);
493 display_port_reg_value(port_id, reg_off, reg_v);
497 * RX/TX ring descriptors display functions.
500 rx_queue_id_is_invalid(queueid_t rxq_id)
504 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
509 tx_queue_id_is_invalid(queueid_t txq_id)
513 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
518 rx_desc_id_is_invalid(uint16_t rxdesc_id)
520 if (rxdesc_id < nb_rxd)
522 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
528 tx_desc_id_is_invalid(uint16_t txdesc_id)
530 if (txdesc_id < nb_txd)
532 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
537 static const struct rte_memzone *
538 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
540 char mz_name[RTE_MEMZONE_NAMESIZE];
541 const struct rte_memzone *mz;
543 rte_snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
544 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
545 mz = rte_memzone_lookup(mz_name);
547 printf("%s ring memory zoneof (port %d, queue %d) not"
548 "found (zone name = %s\n",
549 ring_name, port_id, q_id, mz_name);
553 union igb_ring_dword {
561 struct igb_ring_desc {
562 union igb_ring_dword lo_dword;
563 union igb_ring_dword hi_dword;
567 ring_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
569 struct igb_ring_desc *ring;
570 struct igb_ring_desc rd;
572 ring = (struct igb_ring_desc *) ring_mz->addr;
573 rd.lo_dword = rte_le_to_cpu_64(ring[desc_id].lo_dword);
574 rd.hi_dword = rte_le_to_cpu_64(ring[desc_id].hi_dword);
575 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
576 (unsigned)rd.lo_dword.words.lo, (unsigned)rd.lo_dword.words.hi,
577 (unsigned)rd.hi_dword.words.lo, (unsigned)rd.hi_dword.words.hi);
581 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
583 const struct rte_memzone *rx_mz;
585 if (port_id_is_invalid(port_id))
587 if (rx_queue_id_is_invalid(rxq_id))
589 if (rx_desc_id_is_invalid(rxd_id))
591 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
594 ring_descriptor_display(rx_mz, rxd_id);
598 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
600 const struct rte_memzone *tx_mz;
602 if (port_id_is_invalid(port_id))
604 if (tx_queue_id_is_invalid(txq_id))
606 if (tx_desc_id_is_invalid(txd_id))
608 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
611 ring_descriptor_display(tx_mz, txd_id);
615 fwd_lcores_config_display(void)
619 printf("List of forwarding lcores:");
620 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
621 printf(" %2u", fwd_lcores_cpuids[lc_id]);
625 rxtx_config_display(void)
627 printf(" %s packet forwarding - CRC stripping %s - "
628 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
629 rx_mode.hw_strip_crc ? "enabled" : "disabled",
632 if (cur_fwd_eng == &tx_only_engine)
633 printf(" packet len=%u - nb packet segments=%d\n",
634 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
636 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
637 nb_fwd_lcores, nb_fwd_ports);
638 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
639 nb_rxq, nb_rxd, rx_free_thresh);
640 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
641 rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh);
642 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
643 nb_txq, nb_txd, tx_free_thresh);
644 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
645 tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);
646 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
647 tx_rs_thresh, txq_flags);
651 port_rss_reta_info(portid_t port_id,struct rte_eth_rss_reta *reta_conf)
656 if (port_id_is_invalid(port_id))
659 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf);
661 printf("Failed to get RSS RETA info, return code = %d\n", ret);
665 if (reta_conf->mask_lo != 0) {
666 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
667 if (reta_conf->mask_lo & (uint64_t)(1ULL << i))
668 printf("RSS RETA configuration: hash index=%d,"
669 "queue=%d\n",i,reta_conf->reta[i]);
673 if (reta_conf->mask_hi != 0) {
674 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
675 if(reta_conf->mask_hi & (uint64_t)(1ULL << i)) {
676 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
677 printf("RSS RETA configuration: hash index=%d,"
678 "queue=%d\n",j,reta_conf->reta[j]);
685 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
689 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
691 struct rte_eth_rss_conf rss_conf;
692 uint8_t rss_key[10 * 4];
697 if (port_id_is_invalid(port_id))
699 /* Get RSS hash key if asked to display it */
700 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
701 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
705 printf("port index %d invalid\n", port_id);
708 printf("operation not supported by device\n");
711 printf("operation failed - diag=%d\n", diag);
716 rss_hf = rss_conf.rss_hf;
718 printf("RSS disabled\n");
721 printf("RSS functions:\n ");
722 if (rss_hf & ETH_RSS_IPV4)
724 if (rss_hf & ETH_RSS_IPV4_TCP)
726 if (rss_hf & ETH_RSS_IPV4_UDP)
728 if (rss_hf & ETH_RSS_IPV6)
730 if (rss_hf & ETH_RSS_IPV6_EX)
732 if (rss_hf & ETH_RSS_IPV6_TCP)
734 if (rss_hf & ETH_RSS_IPV6_TCP_EX)
736 if (rss_hf & ETH_RSS_IPV6_UDP)
738 if (rss_hf & ETH_RSS_IPV6_UDP_EX)
743 printf("RSS key:\n");
744 for (i = 0; i < sizeof(rss_key); i++)
745 printf("%02X", rss_key[i]);
750 port_rss_hash_key_update(portid_t port_id, uint8_t *hash_key)
752 struct rte_eth_rss_conf rss_conf;
755 rss_conf.rss_key = NULL;
756 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
758 rss_conf.rss_key = hash_key;
759 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
766 printf("port index %d invalid\n", port_id);
769 printf("operation not supported by device\n");
772 printf("operation failed - diag=%d\n", diag);
778 * Setup forwarding configuration for each logical core.
781 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
783 streamid_t nb_fs_per_lcore;
791 nb_fs = cfg->nb_fwd_streams;
792 nb_fc = cfg->nb_fwd_lcores;
793 if (nb_fs <= nb_fc) {
797 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
798 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
801 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
803 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
804 fwd_lcores[lc_id]->stream_idx = sm_id;
805 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
806 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
810 * Assign extra remaining streams, if any.
812 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
813 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
814 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
815 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
816 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
821 simple_fwd_config_setup(void)
827 if (port_topology == PORT_TOPOLOGY_CHAINED ||
828 port_topology == PORT_TOPOLOGY_LOOP) {
830 } else if (nb_fwd_ports % 2) {
831 printf("\nWarning! Cannot handle an odd number of ports "
832 "with the current port topology. Configuration "
833 "must be changed to have an even number of ports, "
834 "or relaunch application with "
835 "--port-topology=chained\n\n");
838 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
839 cur_fwd_config.nb_fwd_streams =
840 (streamid_t) cur_fwd_config.nb_fwd_ports;
842 /* reinitialize forwarding streams */
846 * In the simple forwarding test, the number of forwarding cores
847 * must be lower or equal to the number of forwarding ports.
849 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
850 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
851 cur_fwd_config.nb_fwd_lcores =
852 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
853 setup_fwd_config_of_each_lcore(&cur_fwd_config);
855 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
856 if (port_topology != PORT_TOPOLOGY_LOOP)
857 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
860 fwd_streams[i]->rx_port = fwd_ports_ids[i];
861 fwd_streams[i]->rx_queue = 0;
862 fwd_streams[i]->tx_port = fwd_ports_ids[j];
863 fwd_streams[i]->tx_queue = 0;
864 fwd_streams[i]->peer_addr = j;
866 if (port_topology == PORT_TOPOLOGY_PAIRED) {
867 fwd_streams[j]->rx_port = fwd_ports_ids[j];
868 fwd_streams[j]->rx_queue = 0;
869 fwd_streams[j]->tx_port = fwd_ports_ids[i];
870 fwd_streams[j]->tx_queue = 0;
871 fwd_streams[j]->peer_addr = i;
877 * For the RSS forwarding test, each core is assigned on every port a transmit
878 * queue whose index is the index of the core itself. This approach limits the
879 * maximumm number of processing cores of the RSS test to the maximum number of
880 * TX queues supported by the devices.
882 * Each core is assigned a single stream, each stream being composed of
883 * a RX queue to poll on a RX port for input messages, associated with
884 * a TX queue of a TX port where to send forwarded packets.
885 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
886 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
888 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
892 rss_fwd_config_setup(void)
903 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
904 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
905 cur_fwd_config.nb_fwd_streams =
906 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
907 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
908 cur_fwd_config.nb_fwd_streams =
909 (streamid_t)cur_fwd_config.nb_fwd_lcores;
911 cur_fwd_config.nb_fwd_lcores =
912 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
914 /* reinitialize forwarding streams */
917 setup_fwd_config_of_each_lcore(&cur_fwd_config);
919 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
920 struct fwd_stream *fs;
922 fs = fwd_streams[lc_id];
924 if ((rxp & 0x1) == 0)
925 txp = (portid_t) (rxp + 1);
927 txp = (portid_t) (rxp - 1);
929 * if we are in loopback, simply send stuff out through the
932 if (port_topology == PORT_TOPOLOGY_LOOP)
935 fs->rx_port = fwd_ports_ids[rxp];
937 fs->tx_port = fwd_ports_ids[txp];
939 fs->peer_addr = fs->tx_port;
940 rxq = (queueid_t) (rxq + 1);
945 * Restart from RX queue 0 on next RX port
948 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
950 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
952 rxp = (portid_t) (rxp + 1);
957 * In DCB and VT on,the mapping of 128 receive queues to 128 transmit queues.
960 dcb_rxq_2_txq_mapping(queueid_t rxq, queueid_t *txq)
962 if(dcb_q_mapping == DCB_4_TCS_Q_MAPPING) {
969 *txq = (uint16_t)(rxq + 32);
972 /* tc2: 96-111;tc3:112-127 */
973 *txq = (uint16_t)(rxq/2 + 64);
982 *txq = (uint16_t)(rxq + 16);
986 *txq = (uint16_t)(rxq + 32);
989 /* tc4,tc5,tc6 and tc7 mapping */
990 *txq = (uint16_t)(rxq/2 + 64);
996 * For the DCB forwarding test, each core is assigned on every port multi-transmit
999 * Each core is assigned a multi-stream, each stream being composed of
1000 * a RX queue to poll on a RX port for input messages, associated with
1001 * a TX queue of a TX port where to send forwarded packets.
1002 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1003 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1006 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1009 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1010 * There is a mapping of RxQj to TxQl to be required,and the mapping was implemented
1011 * in dcb_rxq_2_txq_mapping function.
1014 dcb_fwd_config_setup(void)
1025 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1026 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1027 cur_fwd_config.nb_fwd_streams =
1028 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1030 /* reinitialize forwarding streams */
1033 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1035 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1036 /* a fwd core can run multi-streams */
1037 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++)
1039 struct fwd_stream *fs;
1040 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1041 if ((rxp & 0x1) == 0)
1042 txp = (portid_t) (rxp + 1);
1044 txp = (portid_t) (rxp - 1);
1045 fs->rx_port = fwd_ports_ids[rxp];
1047 fs->tx_port = fwd_ports_ids[txp];
1048 if (dcb_q_mapping == DCB_VT_Q_MAPPING)
1051 dcb_rxq_2_txq_mapping(rxq, &fs->tx_queue);
1052 fs->peer_addr = fs->tx_port;
1053 rxq = (queueid_t) (rxq + 1);
1057 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1059 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1061 rxp = (portid_t) (rxp + 1);
1067 icmp_echo_config_setup(void)
1074 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1075 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1076 (nb_txq * nb_fwd_ports);
1078 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1079 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1080 cur_fwd_config.nb_fwd_streams =
1081 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1082 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1083 cur_fwd_config.nb_fwd_lcores =
1084 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1085 if (verbose_level > 0) {
1086 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1088 cur_fwd_config.nb_fwd_lcores,
1089 cur_fwd_config.nb_fwd_ports,
1090 cur_fwd_config.nb_fwd_streams);
1093 /* reinitialize forwarding streams */
1095 setup_fwd_config_of_each_lcore(&cur_fwd_config);
1097 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1098 if (verbose_level > 0)
1099 printf(" core=%d: \n", lc_id);
1100 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1101 struct fwd_stream *fs;
1102 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1103 fs->rx_port = fwd_ports_ids[rxp];
1105 fs->tx_port = fs->rx_port;
1106 fs->tx_queue = lc_id;
1107 fs->peer_addr = fs->tx_port;
1108 if (verbose_level > 0)
1109 printf(" stream=%d port=%d rxq=%d txq=%d\n",
1110 sm_id, fs->rx_port, fs->rx_queue,
1112 rxq = (queueid_t) (rxq + 1);
1113 if (rxq == nb_rxq) {
1115 rxp = (portid_t) (rxp + 1);
1122 fwd_config_setup(void)
1124 cur_fwd_config.fwd_eng = cur_fwd_eng;
1125 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1126 icmp_echo_config_setup();
1129 if ((nb_rxq > 1) && (nb_txq > 1)){
1131 dcb_fwd_config_setup();
1133 rss_fwd_config_setup();
1136 simple_fwd_config_setup();
1140 pkt_fwd_config_display(struct fwd_config *cfg)
1142 struct fwd_stream *fs;
1146 printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
1147 "NUMA support %s, MP over anonymous pages %s\n",
1148 cfg->fwd_eng->fwd_mode_name,
1149 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1150 numa_support == 1 ? "enabled" : "disabled",
1151 mp_anon != 0 ? "enabled" : "disabled");
1153 if (strcmp(cfg->fwd_eng->fwd_mode_name, "mac_retry") == 0)
1154 printf("TX retry num: %u, delay between TX retries: %uus\n",
1155 burst_tx_retry_num, burst_tx_delay_time);
1156 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1157 printf("Logical Core %u (socket %u) forwards packets on "
1159 fwd_lcores_cpuids[lc_id],
1160 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1161 fwd_lcores[lc_id]->stream_nb);
1162 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1163 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1164 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
1165 "P=%d/Q=%d (socket %u) ",
1166 fs->rx_port, fs->rx_queue,
1167 ports[fs->rx_port].socket_id,
1168 fs->tx_port, fs->tx_queue,
1169 ports[fs->tx_port].socket_id);
1170 print_ethaddr("peer=",
1171 &peer_eth_addrs[fs->peer_addr]);
1180 fwd_config_display(void)
1182 if((dcb_config) && (nb_fwd_lcores == 1)) {
1183 printf("In DCB mode,the nb forwarding cores should be larger than 1\n");
1187 pkt_fwd_config_display(&cur_fwd_config);
1191 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1194 unsigned int lcore_cpuid;
1199 for (i = 0; i < nb_lc; i++) {
1200 lcore_cpuid = lcorelist[i];
1201 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1202 printf("lcore %u not enabled\n", lcore_cpuid);
1205 if (lcore_cpuid == rte_get_master_lcore()) {
1206 printf("lcore %u cannot be masked on for running "
1207 "packet forwarding, which is the master lcore "
1208 "and reserved for command line parsing only\n",
1213 fwd_lcores_cpuids[i] = lcore_cpuid;
1215 if (record_now == 0) {
1219 nb_cfg_lcores = (lcoreid_t) nb_lc;
1220 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1221 printf("previous number of forwarding cores %u - changed to "
1222 "number of configured cores %u\n",
1223 (unsigned int) nb_fwd_lcores, nb_lc);
1224 nb_fwd_lcores = (lcoreid_t) nb_lc;
1231 set_fwd_lcores_mask(uint64_t lcoremask)
1233 unsigned int lcorelist[64];
1237 if (lcoremask == 0) {
1238 printf("Invalid NULL mask of cores\n");
1242 for (i = 0; i < 64; i++) {
1243 if (! ((uint64_t)(1ULL << i) & lcoremask))
1245 lcorelist[nb_lc++] = i;
1247 return set_fwd_lcores_list(lcorelist, nb_lc);
1251 set_fwd_lcores_number(uint16_t nb_lc)
1253 if (nb_lc > nb_cfg_lcores) {
1254 printf("nb fwd cores %u > %u (max. number of configured "
1255 "lcores) - ignored\n",
1256 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1259 nb_fwd_lcores = (lcoreid_t) nb_lc;
1260 printf("Number of forwarding cores set to %u\n",
1261 (unsigned int) nb_fwd_lcores);
1265 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1273 for (i = 0; i < nb_pt; i++) {
1274 port_id = (portid_t) portlist[i];
1275 if (port_id >= nb_ports) {
1276 printf("Invalid port id %u >= %u\n",
1277 (unsigned int) port_id,
1278 (unsigned int) nb_ports);
1282 fwd_ports_ids[i] = port_id;
1284 if (record_now == 0) {
1288 nb_cfg_ports = (portid_t) nb_pt;
1289 if (nb_fwd_ports != (portid_t) nb_pt) {
1290 printf("previous number of forwarding ports %u - changed to "
1291 "number of configured ports %u\n",
1292 (unsigned int) nb_fwd_ports, nb_pt);
1293 nb_fwd_ports = (portid_t) nb_pt;
1298 set_fwd_ports_mask(uint64_t portmask)
1300 unsigned int portlist[64];
1304 if (portmask == 0) {
1305 printf("Invalid NULL mask of ports\n");
1309 for (i = 0; i < 64; i++) {
1310 if (! ((uint64_t)(1ULL << i) & portmask))
1312 portlist[nb_pt++] = i;
1314 set_fwd_ports_list(portlist, nb_pt);
1318 set_fwd_ports_number(uint16_t nb_pt)
1320 if (nb_pt > nb_cfg_ports) {
1321 printf("nb fwd ports %u > %u (number of configured "
1322 "ports) - ignored\n",
1323 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1326 nb_fwd_ports = (portid_t) nb_pt;
1327 printf("Number of forwarding ports set to %u\n",
1328 (unsigned int) nb_fwd_ports);
1332 set_nb_pkt_per_burst(uint16_t nb)
1334 if (nb > MAX_PKT_BURST) {
1335 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1337 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1340 nb_pkt_per_burst = nb;
1341 printf("Number of packets per burst set to %u\n",
1342 (unsigned int) nb_pkt_per_burst);
1346 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1348 uint16_t tx_pkt_len;
1351 if (nb_segs >= (unsigned) nb_txd) {
1352 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1353 nb_segs, (unsigned int) nb_txd);
1358 * Check that each segment length is greater or equal than
1359 * the mbuf data sise.
1360 * Check also that the total packet length is greater or equal than the
1361 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1364 for (i = 0; i < nb_segs; i++) {
1365 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1366 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1367 i, seg_lengths[i], (unsigned) mbuf_data_size);
1370 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1372 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1373 printf("total packet length=%u < %d - give up\n",
1374 (unsigned) tx_pkt_len,
1375 (int)(sizeof(struct ether_hdr) + 20 + 8));
1379 for (i = 0; i < nb_segs; i++)
1380 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1382 tx_pkt_length = tx_pkt_len;
1383 tx_pkt_nb_segs = (uint8_t) nb_segs;
1387 list_pkt_forwarding_modes(void)
1389 static char fwd_modes[128] = "";
1390 const char *separator = "|";
1391 struct fwd_engine *fwd_eng;
1394 if (strlen (fwd_modes) == 0) {
1395 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1396 strcat(fwd_modes, fwd_eng->fwd_mode_name);
1397 strcat(fwd_modes, separator);
1399 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1406 set_pkt_forwarding_mode(const char *fwd_mode_name)
1408 struct fwd_engine *fwd_eng;
1412 while ((fwd_eng = fwd_engines[i]) != NULL) {
1413 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1414 printf("Set %s packet forwarding mode\n",
1416 cur_fwd_eng = fwd_eng;
1421 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1425 set_verbose_level(uint16_t vb_level)
1427 printf("Change verbose level from %u to %u\n",
1428 (unsigned int) verbose_level, (unsigned int) vb_level);
1429 verbose_level = vb_level;
1433 vlan_extend_set(portid_t port_id, int on)
1438 if (port_id_is_invalid(port_id))
1441 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1444 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1446 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1448 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1450 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1451 "diag=%d\n", port_id, on, diag);
1455 rx_vlan_strip_set(portid_t port_id, int on)
1460 if (port_id_is_invalid(port_id))
1463 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1466 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1468 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1470 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1472 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1473 "diag=%d\n", port_id, on, diag);
1477 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1481 if (port_id_is_invalid(port_id))
1484 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1486 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1487 "diag=%d\n", port_id, queue_id, on, diag);
1491 rx_vlan_filter_set(portid_t port_id, int on)
1496 if (port_id_is_invalid(port_id))
1499 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1502 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1504 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1506 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1508 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1509 "diag=%d\n", port_id, on, diag);
1513 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1517 if (port_id_is_invalid(port_id))
1519 if (vlan_id_is_invalid(vlan_id))
1521 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1524 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1526 port_id, vlan_id, on, diag);
1530 rx_vlan_all_filter_set(portid_t port_id, int on)
1534 if (port_id_is_invalid(port_id))
1536 for (vlan_id = 0; vlan_id < 4096; vlan_id++)
1537 rx_vft_set(port_id, vlan_id, on);
1541 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1544 if (port_id_is_invalid(port_id))
1547 diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1551 printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1553 port_id, tp_id, diag);
1557 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1559 if (port_id_is_invalid(port_id))
1561 if (vlan_id_is_invalid(vlan_id))
1563 ports[port_id].tx_ol_flags |= PKT_TX_VLAN_PKT;
1564 ports[port_id].tx_vlan_id = vlan_id;
1568 tx_vlan_reset(portid_t port_id)
1570 if (port_id_is_invalid(port_id))
1572 ports[port_id].tx_ol_flags &= ~PKT_TX_VLAN_PKT;
1576 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1579 uint8_t existing_mapping_found = 0;
1581 if (port_id_is_invalid(port_id))
1584 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1587 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1588 printf("map_value not in required range 0..%d\n",
1589 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1593 if (!is_rx) { /*then tx*/
1594 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1595 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1596 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1597 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1598 existing_mapping_found = 1;
1602 if (!existing_mapping_found) { /* A new additional mapping... */
1603 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1604 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1605 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1606 nb_tx_queue_stats_mappings++;
1610 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1611 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1612 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1613 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1614 existing_mapping_found = 1;
1618 if (!existing_mapping_found) { /* A new additional mapping... */
1619 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1620 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1621 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1622 nb_rx_queue_stats_mappings++;
1628 tx_cksum_set(portid_t port_id, uint8_t cksum_mask)
1630 uint16_t tx_ol_flags;
1631 if (port_id_is_invalid(port_id))
1633 /* Clear last 4 bits and then set L3/4 checksum mask again */
1634 tx_ol_flags = (uint16_t) (ports[port_id].tx_ol_flags & 0xFFF0);
1635 ports[port_id].tx_ol_flags = (uint16_t) ((cksum_mask & 0xf) | tx_ol_flags);
1639 fdir_add_signature_filter(portid_t port_id, uint8_t queue_id,
1640 struct rte_fdir_filter *fdir_filter)
1644 if (port_id_is_invalid(port_id))
1647 diag = rte_eth_dev_fdir_add_signature_filter(port_id, fdir_filter,
1652 printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1653 "diag=%d\n", port_id, diag);
1657 fdir_update_signature_filter(portid_t port_id, uint8_t queue_id,
1658 struct rte_fdir_filter *fdir_filter)
1662 if (port_id_is_invalid(port_id))
1665 diag = rte_eth_dev_fdir_update_signature_filter(port_id, fdir_filter,
1670 printf("rte_eth_dev_fdir_update_signature_filter for port_id=%d failed "
1671 "diag=%d\n", port_id, diag);
1675 fdir_remove_signature_filter(portid_t port_id,
1676 struct rte_fdir_filter *fdir_filter)
1680 if (port_id_is_invalid(port_id))
1683 diag = rte_eth_dev_fdir_remove_signature_filter(port_id, fdir_filter);
1687 printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1688 "diag=%d\n", port_id, diag);
1693 fdir_get_infos(portid_t port_id)
1695 struct rte_eth_fdir fdir_infos;
1697 static const char *fdir_stats_border = "########################";
1699 if (port_id_is_invalid(port_id))
1702 rte_eth_dev_fdir_get_infos(port_id, &fdir_infos);
1704 printf("\n %s FDIR infos for port %-2d %s\n",
1705 fdir_stats_border, port_id, fdir_stats_border);
1707 printf(" collision: %-10"PRIu64" free: %"PRIu64"\n"
1708 " maxhash: %-10"PRIu64" maxlen: %"PRIu64"\n"
1709 " add: %-10"PRIu64" remove: %"PRIu64"\n"
1710 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
1711 (uint64_t)(fdir_infos.collision), (uint64_t)(fdir_infos.free),
1712 (uint64_t)(fdir_infos.maxhash), (uint64_t)(fdir_infos.maxlen),
1713 fdir_infos.add, fdir_infos.remove,
1714 fdir_infos.f_add, fdir_infos.f_remove);
1715 printf(" %s############################%s\n",
1716 fdir_stats_border, fdir_stats_border);
1720 fdir_add_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1721 uint8_t drop, struct rte_fdir_filter *fdir_filter)
1725 if (port_id_is_invalid(port_id))
1728 diag = rte_eth_dev_fdir_add_perfect_filter(port_id, fdir_filter,
1729 soft_id, queue_id, drop);
1733 printf("rte_eth_dev_fdir_add_perfect_filter for port_id=%d failed "
1734 "diag=%d\n", port_id, diag);
1738 fdir_update_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1739 uint8_t drop, struct rte_fdir_filter *fdir_filter)
1743 if (port_id_is_invalid(port_id))
1746 diag = rte_eth_dev_fdir_update_perfect_filter(port_id, fdir_filter,
1747 soft_id, queue_id, drop);
1751 printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1752 "diag=%d\n", port_id, diag);
1756 fdir_remove_perfect_filter(portid_t port_id, uint16_t soft_id,
1757 struct rte_fdir_filter *fdir_filter)
1761 if (port_id_is_invalid(port_id))
1764 diag = rte_eth_dev_fdir_remove_perfect_filter(port_id, fdir_filter,
1769 printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1770 "diag=%d\n", port_id, diag);
1774 fdir_set_masks(portid_t port_id, struct rte_fdir_masks *fdir_masks)
1778 if (port_id_is_invalid(port_id))
1781 diag = rte_eth_dev_fdir_set_masks(port_id, fdir_masks);
1785 printf("rte_eth_dev_set_masks_filter for port_id=%d failed "
1786 "diag=%d\n", port_id, diag);
1790 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
1794 if (port_id_is_invalid(port_id))
1797 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
1799 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
1803 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
1804 "diag=%d\n", port_id, diag);
1806 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
1807 "diag=%d\n", port_id, diag);
1812 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
1816 if (port_id_is_invalid(port_id))
1818 if (vlan_id_is_invalid(vlan_id))
1820 diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
1823 printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
1824 "diag=%d\n", port_id, diag);
1828 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
1831 struct rte_eth_link link;
1833 if (port_id_is_invalid(port_id))
1835 rte_eth_link_get_nowait(port_id, &link);
1836 if (rate > link.link_speed) {
1837 printf("Invalid rate value:%u bigger than link speed: %u\n",
1838 rate, link.link_speed);
1841 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
1844 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
1850 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
1853 struct rte_eth_link link;
1858 if (port_id_is_invalid(port_id))
1860 rte_eth_link_get_nowait(port_id, &link);
1861 if (rate > link.link_speed) {
1862 printf("Invalid rate value:%u bigger than link speed: %u\n",
1863 rate, link.link_speed);
1866 diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
1869 printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",
1875 get_ethertype_filter(uint8_t port_id, uint16_t index)
1877 struct rte_ethertype_filter filter;
1881 memset(&filter, 0, sizeof(filter));
1882 ret = rte_eth_dev_get_ethertype_filter(port_id, index,
1883 &filter, &rx_queue);
1885 if (ret == (-ENOENT))
1886 printf("filter[%d] is not enabled\n", index);
1888 printf("get ethertype filter fails(%s)\n", strerror(-ret));
1891 printf("filter[%d]:\n", index);
1892 printf(" ethertype: 0x%04x\n",
1893 rte_le_to_cpu_32(filter.ethertype));
1894 printf(" priority: %s, %d\n",
1895 filter.priority_en ? "enable" : "disable",
1897 printf(" queue: %d\n", rx_queue);
1902 get_syn_filter(uint8_t port_id)
1904 struct rte_syn_filter filter;
1908 memset(&filter, 0, sizeof(filter));
1909 ret = rte_eth_dev_get_syn_filter(port_id, &filter, &rx_queue);
1912 if (ret == (-ENOENT))
1913 printf("syn filter is not enabled\n");
1915 printf("get syn filter fails(%s)\n", strerror(-ret));
1918 printf("syn filter: priority: %s, queue: %d\n",
1919 filter.hig_pri ? "high" : "low",
1923 get_2tuple_filter(uint8_t port_id, uint16_t index)
1925 struct rte_2tuple_filter filter;
1929 memset(&filter, 0, sizeof(filter));
1930 ret = rte_eth_dev_get_2tuple_filter(port_id, index,
1931 &filter, &rx_queue);
1933 if (ret == (-ENOENT))
1934 printf("filter[%d] is not enabled\n", index);
1936 printf("get 2tuple filter fails(%s)\n", strerror(-ret));
1939 printf("filter[%d]:\n", index);
1940 printf(" Destination Port: 0x%04x mask: %d\n",
1941 rte_be_to_cpu_16(filter.dst_port),
1942 filter.dst_port_mask ? 0 : 1);
1943 printf(" protocol: 0x%02x mask:%d tcp_flags: 0x%02x\n",
1944 filter.protocol, filter.protocol_mask ? 0 : 1,
1946 printf(" priority: %d queue: %d\n",
1947 filter.priority, rx_queue);
1952 get_5tuple_filter(uint8_t port_id, uint16_t index)
1954 struct rte_5tuple_filter filter;
1958 memset(&filter, 0, sizeof(filter));
1959 ret = rte_eth_dev_get_5tuple_filter(port_id, index,
1960 &filter, &rx_queue);
1962 if (ret == (-ENOENT))
1963 printf("filter[%d] is not enabled\n", index);
1965 printf("get 5tuple filter fails(%s)\n", strerror(-ret));
1968 printf("filter[%d]:\n", index);
1969 printf(" Destination IP: 0x%08x mask: %d\n",
1970 (unsigned)rte_be_to_cpu_32(filter.dst_ip),
1971 filter.dst_ip_mask ? 0 : 1);
1972 printf(" Source IP: 0x%08x mask: %d\n",
1973 (unsigned)rte_be_to_cpu_32(filter.src_ip),
1974 filter.src_ip_mask ? 0 : 1);
1975 printf(" Destination Port: 0x%04x mask: %d\n",
1976 rte_be_to_cpu_16(filter.dst_port),
1977 filter.dst_port_mask ? 0 : 1);
1978 printf(" Source Port: 0x%04x mask: %d\n",
1979 rte_be_to_cpu_16(filter.src_port),
1980 filter.src_port_mask ? 0 : 1);
1981 printf(" protocol: 0x%02x mask: %d\n",
1983 filter.protocol_mask ? 0 : 1);
1984 printf(" priority: %d flags: 0x%02x queue: %d\n",
1985 filter.priority, filter.tcp_flags, rx_queue);
1989 get_flex_filter(uint8_t port_id, uint16_t index)
1992 struct rte_flex_filter filter;
1997 memset(&filter, 0, sizeof(filter));
1998 ret = rte_eth_dev_get_flex_filter(port_id, index,
1999 &filter, &rx_queue);
2001 if (ret == (-ENOENT))
2002 printf("filter[%d] is not enabled\n", index);
2004 printf("get flex filter fails(%s)\n", strerror(-ret));
2007 printf("filter[%d]: ", index);
2008 printf("\n length: %d", filter.len);
2009 printf("\n dword[]: 0x");
2010 for (i = 0; i < 32; i++)
2011 printf("%08x ", (unsigned)rte_be_to_cpu_32(filter.dwords[i]));
2012 printf("\n mask[]: 0b");
2013 for (i = 0; i < 16; i++) {
2014 for (j = 0; j < 8; j++)
2015 printf("%c", (filter.mask[i] & (1 << j)) ? '1' : '0');
2017 printf("\n priority: %d queue: %d\n",
2018 filter.priority, rx_queue);