4 * Copyright(c) 2010-2012 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.
36 * Copyright(c) 2013 6WIND.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name of 6WIND S.A. nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 #include <sys/queue.h>
75 #include <rte_common.h>
76 #include <rte_byteorder.h>
77 #include <rte_debug.h>
79 #include <rte_memory.h>
80 #include <rte_memcpy.h>
81 #include <rte_memzone.h>
82 #include <rte_launch.h>
83 #include <rte_tailq.h>
85 #include <rte_per_lcore.h>
86 #include <rte_lcore.h>
87 #include <rte_atomic.h>
88 #include <rte_branch_prediction.h>
90 #include <rte_mempool.h>
92 #include <rte_interrupts.h>
94 #include <rte_ether.h>
95 #include <rte_ethdev.h>
96 #include <rte_string_fns.h>
101 print_ethaddr(const char *name, struct ether_addr *eth_addr)
103 printf("%s%02X:%02X:%02X:%02X:%02X:%02X", name,
104 eth_addr->addr_bytes[0],
105 eth_addr->addr_bytes[1],
106 eth_addr->addr_bytes[2],
107 eth_addr->addr_bytes[3],
108 eth_addr->addr_bytes[4],
109 eth_addr->addr_bytes[5]);
113 nic_stats_display(portid_t port_id)
115 struct rte_eth_stats stats;
116 struct rte_port *port = &ports[port_id];
119 static const char *nic_stats_border = "########################";
121 if (port_id >= nb_ports) {
122 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
125 rte_eth_stats_get(port_id, &stats);
126 printf("\n %s NIC statistics for port %-2d %s\n",
127 nic_stats_border, port_id, nic_stats_border);
129 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
130 printf(" RX-packets: %-10"PRIu64" RX-errors: %-10"PRIu64"RX-bytes: "
132 " TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64"TX-bytes: "
134 stats.ipackets, stats.ierrors, stats.ibytes,
135 stats.opackets, stats.oerrors, stats.obytes);
138 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
139 " RX-bytes: %10"PRIu64"\n"
140 " TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
141 " TX-bytes: %10"PRIu64"\n",
142 stats.ipackets, stats.ierrors, stats.ibytes,
143 stats.opackets, stats.oerrors, stats.obytes);
147 if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
148 printf(" Fdirmiss: %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
152 if (port->rx_queue_stats_mapping_enabled) {
154 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
155 printf(" Stats reg %2d RX-packets: %10"PRIu64
156 " RX-errors: %10"PRIu64
157 " RX-bytes: %10"PRIu64"\n",
158 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
161 if (port->tx_queue_stats_mapping_enabled) {
163 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
164 printf(" Stats reg %2d TX-packets: %10"PRIu64
165 " TX-bytes: %10"PRIu64"\n",
166 i, stats.q_opackets[i], stats.q_obytes[i]);
170 printf(" %s############################%s\n",
171 nic_stats_border, nic_stats_border);
175 nic_stats_clear(portid_t port_id)
177 if (port_id >= nb_ports) {
178 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
181 rte_eth_stats_reset(port_id);
182 printf("\n NIC statistics for port %d cleared\n", port_id);
187 nic_stats_mapping_display(portid_t port_id)
189 struct rte_port *port = &ports[port_id];
192 static const char *nic_stats_mapping_border = "########################";
194 if (port_id >= nb_ports) {
195 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
199 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
200 printf("Port id %d - either does not support queue statistic mapping or"
201 " no queue statistic mapping set\n", port_id);
205 printf("\n %s NIC statistics mapping for port %-2d %s\n",
206 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
208 if (port->rx_queue_stats_mapping_enabled) {
209 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
210 if (rx_queue_stats_mappings[i].port_id == port_id) {
211 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
212 rx_queue_stats_mappings[i].queue_id,
213 rx_queue_stats_mappings[i].stats_counter_id);
220 if (port->tx_queue_stats_mapping_enabled) {
221 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
222 if (tx_queue_stats_mappings[i].port_id == port_id) {
223 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
224 tx_queue_stats_mappings[i].queue_id,
225 tx_queue_stats_mappings[i].stats_counter_id);
230 printf(" %s####################################%s\n",
231 nic_stats_mapping_border, nic_stats_mapping_border);
235 port_infos_display(portid_t port_id)
237 struct rte_port *port;
238 struct rte_eth_link link;
240 static const char *info_border = "*********************";
242 if (port_id >= nb_ports) {
243 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
246 port = &ports[port_id];
247 rte_eth_link_get_nowait(port_id, &link);
248 printf("\n%s Infos for port %-2d %s\n",
249 info_border, port_id, info_border);
250 print_ethaddr("MAC address: ", &port->eth_addr);
251 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
252 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
253 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
254 ("full-duplex") : ("half-duplex"));
255 printf("Promiscuous mode: %s\n",
256 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
257 printf("Allmulticast mode: %s\n",
258 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
259 printf("Maximum number of MAC addresses: %u\n",
260 (unsigned int)(port->dev_info.max_mac_addrs));
262 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
263 if (vlan_offload >= 0){
264 printf("VLAN offload: \n");
265 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
266 printf(" strip on \n");
268 printf(" strip off \n");
270 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
271 printf(" filter on \n");
273 printf(" filter off \n");
275 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
276 printf(" qinq(extend) on \n");
278 printf(" qinq(extend) off \n");
283 port_id_is_invalid(portid_t port_id)
285 if (port_id < nb_ports)
287 printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
292 vlan_id_is_invalid(uint16_t vlan_id)
296 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
301 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
306 printf("Port register offset 0x%X not aligned on a 4-byte "
311 pci_len = ports[port_id].dev_info.pci_dev->mem_resource.len;
312 if (reg_off >= pci_len) {
313 printf("Port %d: register offset %u (0x%X) out of port PCI "
314 "resource (length=%"PRIu64")\n",
315 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
322 reg_bit_pos_is_invalid(uint8_t bit_pos)
326 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
330 #define display_port_and_reg_off(port_id, reg_off) \
331 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
334 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
336 display_port_and_reg_off(port_id, (unsigned)reg_off);
337 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
341 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
346 if (port_id_is_invalid(port_id))
348 if (port_reg_off_is_invalid(port_id, reg_off))
350 if (reg_bit_pos_is_invalid(bit_x))
352 reg_v = port_id_pci_reg_read(port_id, reg_off);
353 display_port_and_reg_off(port_id, (unsigned)reg_off);
354 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
358 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
359 uint8_t bit1_pos, uint8_t bit2_pos)
365 if (port_id_is_invalid(port_id))
367 if (port_reg_off_is_invalid(port_id, reg_off))
369 if (reg_bit_pos_is_invalid(bit1_pos))
371 if (reg_bit_pos_is_invalid(bit2_pos))
373 if (bit1_pos > bit2_pos)
374 l_bit = bit2_pos, h_bit = bit1_pos;
376 l_bit = bit1_pos, h_bit = bit2_pos;
378 reg_v = port_id_pci_reg_read(port_id, reg_off);
381 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
382 display_port_and_reg_off(port_id, (unsigned)reg_off);
383 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
384 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
388 port_reg_display(portid_t port_id, uint32_t reg_off)
392 if (port_id_is_invalid(port_id))
394 if (port_reg_off_is_invalid(port_id, reg_off))
396 reg_v = port_id_pci_reg_read(port_id, reg_off);
397 display_port_reg_value(port_id, reg_off, reg_v);
401 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
406 if (port_id_is_invalid(port_id))
408 if (port_reg_off_is_invalid(port_id, reg_off))
410 if (reg_bit_pos_is_invalid(bit_pos))
413 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
416 reg_v = port_id_pci_reg_read(port_id, reg_off);
418 reg_v &= ~(1 << bit_pos);
420 reg_v |= (1 << bit_pos);
421 port_id_pci_reg_write(port_id, reg_off, reg_v);
422 display_port_reg_value(port_id, reg_off, reg_v);
426 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
427 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
434 if (port_id_is_invalid(port_id))
436 if (port_reg_off_is_invalid(port_id, reg_off))
438 if (reg_bit_pos_is_invalid(bit1_pos))
440 if (reg_bit_pos_is_invalid(bit2_pos))
442 if (bit1_pos > bit2_pos)
443 l_bit = bit2_pos, h_bit = bit1_pos;
445 l_bit = bit1_pos, h_bit = bit2_pos;
447 if ((h_bit - l_bit) < 31)
448 max_v = (1 << (h_bit - l_bit + 1)) - 1;
453 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
454 (unsigned)value, (unsigned)value,
455 (unsigned)max_v, (unsigned)max_v);
458 reg_v = port_id_pci_reg_read(port_id, reg_off);
459 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
460 reg_v |= (value << l_bit); /* Set changed bits */
461 port_id_pci_reg_write(port_id, reg_off, reg_v);
462 display_port_reg_value(port_id, reg_off, reg_v);
466 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
468 if (port_id_is_invalid(port_id))
470 if (port_reg_off_is_invalid(port_id, reg_off))
472 port_id_pci_reg_write(port_id, reg_off, reg_v);
473 display_port_reg_value(port_id, reg_off, reg_v);
477 * RX/TX ring descriptors display functions.
480 rx_queue_id_is_invalid(queueid_t rxq_id)
484 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
489 tx_queue_id_is_invalid(queueid_t txq_id)
493 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
498 rx_desc_id_is_invalid(uint16_t rxdesc_id)
500 if (rxdesc_id < nb_rxd)
502 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
508 tx_desc_id_is_invalid(uint16_t txdesc_id)
510 if (txdesc_id < nb_txd)
512 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
517 static const struct rte_memzone *
518 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
520 char mz_name[RTE_MEMZONE_NAMESIZE];
521 const struct rte_memzone *mz;
523 rte_snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
524 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
525 mz = rte_memzone_lookup(mz_name);
527 printf("%s ring memory zoneof (port %d, queue %d) not"
528 "found (zone name = %s\n",
529 ring_name, port_id, q_id, mz_name);
533 union igb_ring_dword {
541 struct igb_ring_desc {
542 union igb_ring_dword lo_dword;
543 union igb_ring_dword hi_dword;
547 ring_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
549 struct igb_ring_desc *ring;
550 struct igb_ring_desc rd;
552 ring = (struct igb_ring_desc *) ring_mz->addr;
553 rd.lo_dword = rte_le_to_cpu_64(ring[desc_id].lo_dword);
554 rd.hi_dword = rte_le_to_cpu_64(ring[desc_id].hi_dword);
555 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
556 (unsigned)rd.lo_dword.words.lo, (unsigned)rd.lo_dword.words.hi,
557 (unsigned)rd.hi_dword.words.lo, (unsigned)rd.hi_dword.words.hi);
561 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
563 const struct rte_memzone *rx_mz;
565 if (port_id_is_invalid(port_id))
567 if (rx_queue_id_is_invalid(rxq_id))
569 if (rx_desc_id_is_invalid(rxd_id))
571 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
574 ring_descriptor_display(rx_mz, rxd_id);
578 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
580 const struct rte_memzone *tx_mz;
582 if (port_id_is_invalid(port_id))
584 if (tx_queue_id_is_invalid(txq_id))
586 if (tx_desc_id_is_invalid(txd_id))
588 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
591 ring_descriptor_display(tx_mz, txd_id);
595 fwd_lcores_config_display(void)
599 printf("List of forwarding lcores:");
600 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
601 printf(" %2u", fwd_lcores_cpuids[lc_id]);
605 rxtx_config_display(void)
607 printf(" %s packet forwarding - CRC stripping %s - "
608 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
609 rx_mode.hw_strip_crc ? "enabled" : "disabled",
612 if (cur_fwd_eng == &tx_only_engine)
613 printf(" packet len=%u - nb packet segments=%d\n",
614 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
616 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
617 nb_fwd_lcores, nb_fwd_ports);
618 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
619 nb_rxq, nb_rxd, rx_free_thresh);
620 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
621 rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh);
622 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
623 nb_txq, nb_txd, tx_free_thresh);
624 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
625 tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);
626 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
627 tx_rs_thresh, txq_flags);
631 * Setup forwarding configuration for each logical core.
634 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
636 streamid_t nb_fs_per_lcore;
644 nb_fs = cfg->nb_fwd_streams;
645 nb_fc = cfg->nb_fwd_lcores;
646 if (nb_fs <= nb_fc) {
650 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
651 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
654 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
656 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
657 fwd_lcores[lc_id]->stream_idx = sm_id;
658 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
659 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
663 * Assign extra remaining streams, if any.
665 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
666 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
667 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
668 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
669 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
674 simple_fwd_config_setup(void)
680 if (port_topology == PORT_TOPOLOGY_CHAINED) {
682 } else if (nb_fwd_ports % 2) {
683 printf("\nWarning! Cannot handle an odd number of ports "
684 "with the current port topology. Configuration "
685 "must be changed to have an even number of ports, "
686 "or relaunch application with "
687 "--port-topology=chained\n\n");
690 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
691 cur_fwd_config.nb_fwd_streams =
692 (streamid_t) cur_fwd_config.nb_fwd_ports;
694 /* reinitialize forwarding streams */
698 * In the simple forwarding test, the number of forwarding cores
699 * must be lower or equal to the number of forwarding ports.
701 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
702 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
703 cur_fwd_config.nb_fwd_lcores =
704 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
705 setup_fwd_config_of_each_lcore(&cur_fwd_config);
707 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
708 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
709 fwd_streams[i]->rx_port = fwd_ports_ids[i];
710 fwd_streams[i]->rx_queue = 0;
711 fwd_streams[i]->tx_port = fwd_ports_ids[j];
712 fwd_streams[i]->tx_queue = 0;
713 fwd_streams[i]->peer_addr = j;
715 if (port_topology == PORT_TOPOLOGY_PAIRED) {
716 fwd_streams[j]->rx_port = fwd_ports_ids[j];
717 fwd_streams[j]->rx_queue = 0;
718 fwd_streams[j]->tx_port = fwd_ports_ids[i];
719 fwd_streams[j]->tx_queue = 0;
720 fwd_streams[j]->peer_addr = i;
726 * For the RSS forwarding test, each core is assigned on every port a transmit
727 * queue whose index is the index of the core itself. This approach limits the
728 * maximumm number of processing cores of the RSS test to the maximum number of
729 * TX queues supported by the devices.
731 * Each core is assigned a single stream, each stream being composed of
732 * a RX queue to poll on a RX port for input messages, associated with
733 * a TX queue of a TX port where to send forwarded packets.
734 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
735 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
737 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
741 rss_fwd_config_setup(void)
752 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
753 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
754 cur_fwd_config.nb_fwd_streams =
755 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
756 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
757 cur_fwd_config.nb_fwd_streams =
758 (streamid_t)cur_fwd_config.nb_fwd_lcores;
760 cur_fwd_config.nb_fwd_lcores =
761 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
763 /* reinitialize forwarding streams */
766 setup_fwd_config_of_each_lcore(&cur_fwd_config);
768 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
769 struct fwd_stream *fs;
771 fs = fwd_streams[lc_id];
772 if ((rxp & 0x1) == 0)
773 txp = (portid_t) (rxp + 1);
775 txp = (portid_t) (rxp - 1);
776 fs->rx_port = fwd_ports_ids[rxp];
778 fs->tx_port = fwd_ports_ids[txp];
780 fs->peer_addr = fs->tx_port;
781 rxq = (queueid_t) (rxq + 1);
786 * Restart from RX queue 0 on next RX port
789 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
791 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
793 rxp = (portid_t) (rxp + 1);
798 * In DCB and VT on,the mapping of 128 receive queues to 128 transmit queues.
801 dcb_rxq_2_txq_mapping(queueid_t rxq, queueid_t *txq)
803 if(dcb_q_mapping == DCB_4_TCS_Q_MAPPING) {
810 *txq = (uint16_t)(rxq + 32);
813 /* tc2: 96-111;tc3:112-127 */
814 *txq = (uint16_t)(rxq/2 + 64);
823 *txq = (uint16_t)(rxq + 16);
827 *txq = (uint16_t)(rxq + 32);
830 /* tc4,tc5,tc6 and tc7 mapping */
831 *txq = (uint16_t)(rxq/2 + 64);
837 * For the DCB forwarding test, each core is assigned on every port multi-transmit
840 * Each core is assigned a multi-stream, each stream being composed of
841 * a RX queue to poll on a RX port for input messages, associated with
842 * a TX queue of a TX port where to send forwarded packets.
843 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
844 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
847 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
850 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
851 * There is a mapping of RxQj to TxQl to be required,and the mapping was implemented
852 * in dcb_rxq_2_txq_mapping function.
855 dcb_fwd_config_setup(void)
866 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
867 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
868 cur_fwd_config.nb_fwd_streams =
869 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
871 /* reinitialize forwarding streams */
874 setup_fwd_config_of_each_lcore(&cur_fwd_config);
876 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
877 /* a fwd core can run multi-streams */
878 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++)
880 struct fwd_stream *fs;
881 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
882 if ((rxp & 0x1) == 0)
883 txp = (portid_t) (rxp + 1);
885 txp = (portid_t) (rxp - 1);
886 fs->rx_port = fwd_ports_ids[rxp];
888 fs->tx_port = fwd_ports_ids[txp];
889 if (dcb_q_mapping == DCB_VT_Q_MAPPING)
892 dcb_rxq_2_txq_mapping(rxq, &fs->tx_queue);
893 fs->peer_addr = fs->tx_port;
894 rxq = (queueid_t) (rxq + 1);
898 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
900 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
902 rxp = (portid_t) (rxp + 1);
908 fwd_config_setup(void)
910 cur_fwd_config.fwd_eng = cur_fwd_eng;
911 if ((nb_rxq > 1) && (nb_txq > 1)){
913 dcb_fwd_config_setup();
915 rss_fwd_config_setup();
918 simple_fwd_config_setup();
922 pkt_fwd_config_display(struct fwd_config *cfg)
924 struct fwd_stream *fs;
928 printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
930 cfg->fwd_eng->fwd_mode_name,
931 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
932 numa_support == 1 ? "enabled" : "disabled");
933 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
934 printf("Logical Core %u (socket %u) forwards packets on "
936 fwd_lcores_cpuids[lc_id],
937 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
938 fwd_lcores[lc_id]->stream_nb);
939 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
940 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
941 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
942 "P=%d/Q=%d (socket %u) ",
943 fs->rx_port, fs->rx_queue,
944 ports[fs->rx_port].socket_id,
945 fs->tx_port, fs->tx_queue,
946 ports[fs->tx_port].socket_id);
947 print_ethaddr("peer=",
948 &peer_eth_addrs[fs->peer_addr]);
957 fwd_config_display(void)
959 if((dcb_config) && (nb_fwd_lcores == 1)) {
960 printf("In DCB mode,the nb forwarding cores should be larger than 1\n");
964 pkt_fwd_config_display(&cur_fwd_config);
968 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
971 unsigned int lcore_cpuid;
976 for (i = 0; i < nb_lc; i++) {
977 lcore_cpuid = lcorelist[i];
978 if (! rte_lcore_is_enabled(lcore_cpuid)) {
979 printf("lcore %u not enabled\n", lcore_cpuid);
982 if (lcore_cpuid == rte_get_master_lcore()) {
983 printf("lcore %u cannot be masked on for running "
984 "packet forwarding, which is the master lcore "
985 "and reserved for command line parsing only\n",
990 fwd_lcores_cpuids[i] = lcore_cpuid;
992 if (record_now == 0) {
996 nb_cfg_lcores = (lcoreid_t) nb_lc;
997 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
998 printf("previous number of forwarding cores %u - changed to "
999 "number of configured cores %u\n",
1000 (unsigned int) nb_fwd_lcores, nb_lc);
1001 nb_fwd_lcores = (lcoreid_t) nb_lc;
1008 set_fwd_lcores_mask(uint64_t lcoremask)
1010 unsigned int lcorelist[64];
1014 if (lcoremask == 0) {
1015 printf("Invalid NULL mask of cores\n");
1019 for (i = 0; i < 64; i++) {
1020 if (! ((uint64_t)(1ULL << i) & lcoremask))
1022 lcorelist[nb_lc++] = i;
1024 return set_fwd_lcores_list(lcorelist, nb_lc);
1028 set_fwd_lcores_number(uint16_t nb_lc)
1030 if (nb_lc > nb_cfg_lcores) {
1031 printf("nb fwd cores %u > %u (max. number of configured "
1032 "lcores) - ignored\n",
1033 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1036 nb_fwd_lcores = (lcoreid_t) nb_lc;
1037 printf("Number of forwarding cores set to %u\n",
1038 (unsigned int) nb_fwd_lcores);
1042 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1050 for (i = 0; i < nb_pt; i++) {
1051 port_id = (portid_t) portlist[i];
1052 if (port_id >= nb_ports) {
1053 printf("Invalid port id %u > %u\n",
1054 (unsigned int) port_id,
1055 (unsigned int) nb_ports);
1059 fwd_ports_ids[i] = port_id;
1061 if (record_now == 0) {
1065 nb_cfg_ports = (portid_t) nb_pt;
1066 if (nb_fwd_ports != (portid_t) nb_pt) {
1067 printf("previous number of forwarding ports %u - changed to "
1068 "number of configured ports %u\n",
1069 (unsigned int) nb_fwd_ports, nb_pt);
1070 nb_fwd_ports = (portid_t) nb_pt;
1075 set_fwd_ports_mask(uint64_t portmask)
1077 unsigned int portlist[64];
1081 if (portmask == 0) {
1082 printf("Invalid NULL mask of ports\n");
1086 for (i = 0; i < 64; i++) {
1087 if (! ((uint64_t)(1ULL << i) & portmask))
1089 portlist[nb_pt++] = i;
1091 set_fwd_ports_list(portlist, nb_pt);
1095 set_fwd_ports_number(uint16_t nb_pt)
1097 if (nb_pt > nb_cfg_ports) {
1098 printf("nb fwd ports %u > %u (number of configured "
1099 "ports) - ignored\n",
1100 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1103 nb_fwd_ports = (portid_t) nb_pt;
1104 printf("Number of forwarding ports set to %u\n",
1105 (unsigned int) nb_fwd_ports);
1109 set_nb_pkt_per_burst(uint16_t nb)
1111 if (nb > MAX_PKT_BURST) {
1112 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1114 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1117 nb_pkt_per_burst = nb;
1118 printf("Number of packets per burst set to %u\n",
1119 (unsigned int) nb_pkt_per_burst);
1123 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1125 uint16_t tx_pkt_len;
1128 if (nb_segs >= (unsigned) nb_txd) {
1129 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1130 nb_segs, (unsigned int) nb_txd);
1135 * Check that each segment length is greater or equal than
1136 * the mbuf data sise.
1137 * Check also that the total packet length is greater or equal than the
1138 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1141 for (i = 0; i < nb_segs; i++) {
1142 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1143 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1144 i, seg_lengths[i], (unsigned) mbuf_data_size);
1147 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1149 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1150 printf("total packet length=%u < %d - give up\n",
1151 (unsigned) tx_pkt_len,
1152 (int)(sizeof(struct ether_hdr) + 20 + 8));
1156 for (i = 0; i < nb_segs; i++)
1157 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1159 tx_pkt_length = tx_pkt_len;
1160 tx_pkt_nb_segs = (uint8_t) nb_segs;
1164 set_pkt_forwarding_mode(const char *fwd_mode_name)
1166 struct fwd_engine *fwd_eng;
1170 while ((fwd_eng = fwd_engines[i]) != NULL) {
1171 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1172 printf("Set %s packet forwarding mode\n",
1174 cur_fwd_eng = fwd_eng;
1179 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1183 set_verbose_level(uint16_t vb_level)
1185 printf("Change verbose level from %u to %u\n",
1186 (unsigned int) verbose_level, (unsigned int) vb_level);
1187 verbose_level = vb_level;
1191 vlan_extend_set(portid_t port_id, int on)
1196 if (port_id_is_invalid(port_id))
1199 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1202 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1204 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1206 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1208 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1209 "diag=%d\n", port_id, on, diag);
1213 rx_vlan_strip_set(portid_t port_id, int on)
1218 if (port_id_is_invalid(port_id))
1221 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1224 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1226 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1228 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1230 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1231 "diag=%d\n", port_id, on, diag);
1235 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1239 if (port_id_is_invalid(port_id))
1242 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1244 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1245 "diag=%d\n", port_id, queue_id, on, diag);
1249 rx_vlan_filter_set(portid_t port_id, int on)
1254 if (port_id_is_invalid(port_id))
1257 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1260 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1262 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1264 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1266 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1267 "diag=%d\n", port_id, on, diag);
1271 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1275 if (port_id_is_invalid(port_id))
1277 if (vlan_id_is_invalid(vlan_id))
1279 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1282 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1284 port_id, vlan_id, on, diag);
1288 rx_vlan_all_filter_set(portid_t port_id, int on)
1292 if (port_id_is_invalid(port_id))
1294 for (vlan_id = 0; vlan_id < 4096; vlan_id++)
1295 rx_vft_set(port_id, vlan_id, on);
1299 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1302 if (port_id_is_invalid(port_id))
1305 diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1309 printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1311 port_id, tp_id, diag);
1315 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1317 if (port_id_is_invalid(port_id))
1319 if (vlan_id_is_invalid(vlan_id))
1321 ports[port_id].tx_ol_flags |= PKT_TX_VLAN_PKT;
1322 ports[port_id].tx_vlan_id = vlan_id;
1326 tx_vlan_reset(portid_t port_id)
1328 if (port_id_is_invalid(port_id))
1330 ports[port_id].tx_ol_flags &= ~PKT_TX_VLAN_PKT;
1334 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1337 uint8_t existing_mapping_found = 0;
1339 if (port_id_is_invalid(port_id))
1342 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1345 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1346 printf("map_value not in required range 0..%d\n",
1347 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1351 if (!is_rx) { /*then tx*/
1352 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1353 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1354 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1355 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1356 existing_mapping_found = 1;
1360 if (!existing_mapping_found) { /* A new additional mapping... */
1361 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1362 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1363 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1364 nb_tx_queue_stats_mappings++;
1368 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1369 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1370 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1371 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1372 existing_mapping_found = 1;
1376 if (!existing_mapping_found) { /* A new additional mapping... */
1377 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1378 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1379 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1380 nb_rx_queue_stats_mappings++;
1386 tx_cksum_set(portid_t port_id, uint8_t cksum_mask)
1388 uint16_t tx_ol_flags;
1389 if (port_id_is_invalid(port_id))
1391 /* Clear last 4 bits and then set L3/4 checksum mask again */
1392 tx_ol_flags = (uint16_t) (ports[port_id].tx_ol_flags & 0xFFF0);
1393 ports[port_id].tx_ol_flags = (uint16_t) ((cksum_mask & 0xf) | tx_ol_flags);
1397 fdir_add_signature_filter(portid_t port_id, uint8_t queue_id,
1398 struct rte_fdir_filter *fdir_filter)
1402 if (port_id_is_invalid(port_id))
1405 diag = rte_eth_dev_fdir_add_signature_filter(port_id, fdir_filter,
1410 printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1411 "diag=%d\n", port_id, diag);
1415 fdir_update_signature_filter(portid_t port_id, uint8_t queue_id,
1416 struct rte_fdir_filter *fdir_filter)
1420 if (port_id_is_invalid(port_id))
1423 diag = rte_eth_dev_fdir_update_signature_filter(port_id, fdir_filter,
1428 printf("rte_eth_dev_fdir_update_signature_filter for port_id=%d failed "
1429 "diag=%d\n", port_id, diag);
1433 fdir_remove_signature_filter(portid_t port_id,
1434 struct rte_fdir_filter *fdir_filter)
1438 if (port_id_is_invalid(port_id))
1441 diag = rte_eth_dev_fdir_remove_signature_filter(port_id, fdir_filter);
1445 printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1446 "diag=%d\n", port_id, diag);
1451 fdir_get_infos(portid_t port_id)
1453 struct rte_eth_fdir fdir_infos;
1455 static const char *fdir_stats_border = "########################";
1457 if (port_id_is_invalid(port_id))
1460 rte_eth_dev_fdir_get_infos(port_id, &fdir_infos);
1462 printf("\n %s FDIR infos for port %-2d %s\n",
1463 fdir_stats_border, port_id, fdir_stats_border);
1465 printf(" collision: %-10"PRIu64" free: %"PRIu64"\n"
1466 " maxhash: %-10"PRIu64" maxlen: %"PRIu64"\n"
1467 " add: %-10"PRIu64" remove: %"PRIu64"\n"
1468 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
1469 (uint64_t)(fdir_infos.collision), (uint64_t)(fdir_infos.free),
1470 (uint64_t)(fdir_infos.maxhash), (uint64_t)(fdir_infos.maxlen),
1471 fdir_infos.add, fdir_infos.remove,
1472 fdir_infos.f_add, fdir_infos.f_remove);
1473 printf(" %s############################%s\n",
1474 fdir_stats_border, fdir_stats_border);
1478 fdir_add_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1479 uint8_t drop, struct rte_fdir_filter *fdir_filter)
1483 if (port_id_is_invalid(port_id))
1486 diag = rte_eth_dev_fdir_add_perfect_filter(port_id, fdir_filter,
1487 soft_id, queue_id, drop);
1491 printf("rte_eth_dev_fdir_add_perfect_filter for port_id=%d failed "
1492 "diag=%d\n", port_id, diag);
1496 fdir_update_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1497 uint8_t drop, struct rte_fdir_filter *fdir_filter)
1501 if (port_id_is_invalid(port_id))
1504 diag = rte_eth_dev_fdir_update_perfect_filter(port_id, fdir_filter,
1505 soft_id, queue_id, drop);
1509 printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1510 "diag=%d\n", port_id, diag);
1514 fdir_remove_perfect_filter(portid_t port_id, uint16_t soft_id,
1515 struct rte_fdir_filter *fdir_filter)
1519 if (port_id_is_invalid(port_id))
1522 diag = rte_eth_dev_fdir_remove_perfect_filter(port_id, fdir_filter,
1527 printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1528 "diag=%d\n", port_id, diag);
1532 fdir_set_masks(portid_t port_id, struct rte_fdir_masks *fdir_masks)
1536 if (port_id_is_invalid(port_id))
1539 diag = rte_eth_dev_fdir_set_masks(port_id, fdir_masks);
1543 printf("rte_eth_dev_set_masks_filter for port_id=%d failed "
1544 "diag=%d\n", port_id, diag);