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.
43 #include <sys/queue.h>
45 #include <rte_common.h>
46 #include <rte_byteorder.h>
47 #include <rte_debug.h>
49 #include <rte_memory.h>
50 #include <rte_memcpy.h>
51 #include <rte_memzone.h>
52 #include <rte_launch.h>
53 #include <rte_tailq.h>
55 #include <rte_per_lcore.h>
56 #include <rte_lcore.h>
57 #include <rte_atomic.h>
58 #include <rte_branch_prediction.h>
60 #include <rte_mempool.h>
62 #include <rte_interrupts.h>
64 #include <rte_ether.h>
65 #include <rte_ethdev.h>
66 #include <rte_string_fns.h>
71 print_ethaddr(const char *name, struct ether_addr *eth_addr)
73 printf("%s%02X:%02X:%02X:%02X:%02X:%02X", name,
74 eth_addr->addr_bytes[0],
75 eth_addr->addr_bytes[1],
76 eth_addr->addr_bytes[2],
77 eth_addr->addr_bytes[3],
78 eth_addr->addr_bytes[4],
79 eth_addr->addr_bytes[5]);
83 nic_stats_display(portid_t port_id)
85 struct rte_eth_stats stats;
86 struct rte_port *port = &ports[port_id];
89 static const char *nic_stats_border = "########################";
91 if (port_id >= nb_ports) {
92 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
95 rte_eth_stats_get(port_id, &stats);
96 printf("\n %s NIC statistics for port %-2d %s\n",
97 nic_stats_border, port_id, nic_stats_border);
99 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
100 printf(" RX-packets: %-10"PRIu64" RX-errors: %-10"PRIu64"RX-bytes: "
102 " TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64"TX-bytes: "
104 stats.ipackets, stats.ierrors, stats.ibytes,
105 stats.opackets, stats.oerrors, stats.obytes);
108 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64
109 " RX-bytes: %10"PRIu64"\n"
110 " TX-packets: %10"PRIu64" TX-errors: %10"PRIu64
111 " TX-bytes: %10"PRIu64"\n",
112 stats.ipackets, stats.ierrors, stats.ibytes,
113 stats.opackets, stats.oerrors, stats.obytes);
117 if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
118 printf(" Fdirmiss: %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
122 if (port->rx_queue_stats_mapping_enabled) {
124 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
125 printf(" Stats reg %2d RX-packets: %10"PRIu64
126 " RX-errors: %10"PRIu64
127 " RX-bytes: %10"PRIu64"\n",
128 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
131 if (port->tx_queue_stats_mapping_enabled) {
133 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
134 printf(" Stats reg %2d TX-packets: %10"PRIu64
135 " TX-bytes: %10"PRIu64"\n",
136 i, stats.q_opackets[i], stats.q_obytes[i]);
140 printf(" %s############################%s\n",
141 nic_stats_border, nic_stats_border);
145 nic_stats_clear(portid_t port_id)
147 if (port_id >= nb_ports) {
148 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
151 rte_eth_stats_reset(port_id);
152 printf("\n NIC statistics for port %d cleared\n", port_id);
157 nic_stats_mapping_display(portid_t port_id)
159 struct rte_port *port = &ports[port_id];
162 static const char *nic_stats_mapping_border = "########################";
164 if (port_id >= nb_ports) {
165 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
169 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
170 printf("Port id %d - either does not support queue statistic mapping or"
171 " no queue statistic mapping set\n", port_id);
175 printf("\n %s NIC statistics mapping for port %-2d %s\n",
176 nic_stats_mapping_border, port_id, nic_stats_mapping_border);
178 if (port->rx_queue_stats_mapping_enabled) {
179 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
180 if (rx_queue_stats_mappings[i].port_id == port_id) {
181 printf(" RX-queue %2d mapped to Stats Reg %2d\n",
182 rx_queue_stats_mappings[i].queue_id,
183 rx_queue_stats_mappings[i].stats_counter_id);
190 if (port->tx_queue_stats_mapping_enabled) {
191 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
192 if (tx_queue_stats_mappings[i].port_id == port_id) {
193 printf(" TX-queue %2d mapped to Stats Reg %2d\n",
194 tx_queue_stats_mappings[i].queue_id,
195 tx_queue_stats_mappings[i].stats_counter_id);
200 printf(" %s####################################%s\n",
201 nic_stats_mapping_border, nic_stats_mapping_border);
205 port_infos_display(portid_t port_id)
207 struct rte_port *port;
208 struct rte_eth_link link;
210 static const char *info_border = "*********************";
212 if (port_id >= nb_ports) {
213 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
216 port = &ports[port_id];
217 rte_eth_link_get_nowait(port_id, &link);
218 printf("\n%s Infos for port %-2d %s\n",
219 info_border, port_id, info_border);
220 print_ethaddr("MAC address: ", &port->eth_addr);
221 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
222 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
223 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
224 ("full-duplex") : ("half-duplex"));
225 printf("Promiscuous mode: %s\n",
226 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
227 printf("Allmulticast mode: %s\n",
228 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
229 printf("Maximum number of MAC addresses: %u\n",
230 (unsigned int)(port->dev_info.max_mac_addrs));
232 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
233 if (vlan_offload >= 0){
234 printf("VLAN offload: \n");
235 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
236 printf(" strip on \n");
238 printf(" strip off \n");
240 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
241 printf(" filter on \n");
243 printf(" filter off \n");
245 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
246 printf(" qinq(extend) on \n");
248 printf(" qinq(extend) off \n");
253 port_id_is_invalid(portid_t port_id)
255 if (port_id < nb_ports)
257 printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
262 vlan_id_is_invalid(uint16_t vlan_id)
266 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
271 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
276 printf("Port register offset 0x%X not aligned on a 4-byte "
281 pci_len = ports[port_id].dev_info.pci_dev->mem_resource.len;
282 if (reg_off >= pci_len) {
283 printf("Port %d: register offset %u (0x%X) out of port PCI "
284 "resource (length=%"PRIu64")\n",
285 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len);
292 reg_bit_pos_is_invalid(uint8_t bit_pos)
296 printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
300 #define display_port_and_reg_off(port_id, reg_off) \
301 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
304 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
306 display_port_and_reg_off(port_id, (unsigned)reg_off);
307 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
311 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
316 if (port_id_is_invalid(port_id))
318 if (port_reg_off_is_invalid(port_id, reg_off))
320 if (reg_bit_pos_is_invalid(bit_x))
322 reg_v = port_id_pci_reg_read(port_id, reg_off);
323 display_port_and_reg_off(port_id, (unsigned)reg_off);
324 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
328 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
329 uint8_t bit1_pos, uint8_t bit2_pos)
335 if (port_id_is_invalid(port_id))
337 if (port_reg_off_is_invalid(port_id, reg_off))
339 if (reg_bit_pos_is_invalid(bit1_pos))
341 if (reg_bit_pos_is_invalid(bit2_pos))
343 if (bit1_pos > bit2_pos)
344 l_bit = bit2_pos, h_bit = bit1_pos;
346 l_bit = bit1_pos, h_bit = bit2_pos;
348 reg_v = port_id_pci_reg_read(port_id, reg_off);
351 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
352 display_port_and_reg_off(port_id, (unsigned)reg_off);
353 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
354 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
358 port_reg_display(portid_t port_id, uint32_t reg_off)
362 if (port_id_is_invalid(port_id))
364 if (port_reg_off_is_invalid(port_id, reg_off))
366 reg_v = port_id_pci_reg_read(port_id, reg_off);
367 display_port_reg_value(port_id, reg_off, reg_v);
371 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
376 if (port_id_is_invalid(port_id))
378 if (port_reg_off_is_invalid(port_id, reg_off))
380 if (reg_bit_pos_is_invalid(bit_pos))
383 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
386 reg_v = port_id_pci_reg_read(port_id, reg_off);
388 reg_v &= ~(1 << bit_pos);
390 reg_v |= (1 << bit_pos);
391 port_id_pci_reg_write(port_id, reg_off, reg_v);
392 display_port_reg_value(port_id, reg_off, reg_v);
396 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
397 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
404 if (port_id_is_invalid(port_id))
406 if (port_reg_off_is_invalid(port_id, reg_off))
408 if (reg_bit_pos_is_invalid(bit1_pos))
410 if (reg_bit_pos_is_invalid(bit2_pos))
412 if (bit1_pos > bit2_pos)
413 l_bit = bit2_pos, h_bit = bit1_pos;
415 l_bit = bit1_pos, h_bit = bit2_pos;
417 if ((h_bit - l_bit) < 31)
418 max_v = (1 << (h_bit - l_bit + 1)) - 1;
423 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
424 (unsigned)value, (unsigned)value,
425 (unsigned)max_v, (unsigned)max_v);
428 reg_v = port_id_pci_reg_read(port_id, reg_off);
429 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
430 reg_v |= (value << l_bit); /* Set changed bits */
431 port_id_pci_reg_write(port_id, reg_off, reg_v);
432 display_port_reg_value(port_id, reg_off, reg_v);
436 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
438 if (port_id_is_invalid(port_id))
440 if (port_reg_off_is_invalid(port_id, reg_off))
442 port_id_pci_reg_write(port_id, reg_off, reg_v);
443 display_port_reg_value(port_id, reg_off, reg_v);
447 * RX/TX ring descriptors display functions.
450 rx_queue_id_is_invalid(queueid_t rxq_id)
454 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
459 tx_queue_id_is_invalid(queueid_t txq_id)
463 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
468 rx_desc_id_is_invalid(uint16_t rxdesc_id)
470 if (rxdesc_id < nb_rxd)
472 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
478 tx_desc_id_is_invalid(uint16_t txdesc_id)
480 if (txdesc_id < nb_txd)
482 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
487 static const struct rte_memzone *
488 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
490 char mz_name[RTE_MEMZONE_NAMESIZE];
491 const struct rte_memzone *mz;
493 rte_snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
494 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
495 mz = rte_memzone_lookup(mz_name);
497 printf("%s ring memory zoneof (port %d, queue %d) not"
498 "found (zone name = %s\n",
499 ring_name, port_id, q_id, mz_name);
503 union igb_ring_dword {
511 struct igb_ring_desc {
512 union igb_ring_dword lo_dword;
513 union igb_ring_dword hi_dword;
517 ring_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
519 struct igb_ring_desc *ring;
520 struct igb_ring_desc rd;
522 ring = (struct igb_ring_desc *) ring_mz->addr;
523 rd.lo_dword = rte_le_to_cpu_64(ring[desc_id].lo_dword);
524 rd.hi_dword = rte_le_to_cpu_64(ring[desc_id].hi_dword);
525 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
526 (unsigned)rd.lo_dword.words.lo, (unsigned)rd.lo_dword.words.hi,
527 (unsigned)rd.hi_dword.words.lo, (unsigned)rd.hi_dword.words.hi);
531 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
533 const struct rte_memzone *rx_mz;
535 if (port_id_is_invalid(port_id))
537 if (rx_queue_id_is_invalid(rxq_id))
539 if (rx_desc_id_is_invalid(rxd_id))
541 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
544 ring_descriptor_display(rx_mz, rxd_id);
548 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
550 const struct rte_memzone *tx_mz;
552 if (port_id_is_invalid(port_id))
554 if (tx_queue_id_is_invalid(txq_id))
556 if (tx_desc_id_is_invalid(txd_id))
558 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
561 ring_descriptor_display(tx_mz, txd_id);
565 fwd_lcores_config_display(void)
569 printf("List of forwarding lcores:");
570 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
571 printf(" %2u", fwd_lcores_cpuids[lc_id]);
575 rxtx_config_display(void)
577 printf(" %s packet forwarding - CRC stripping %s - "
578 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
579 rx_mode.hw_strip_crc ? "enabled" : "disabled",
582 if (cur_fwd_eng == &tx_only_engine)
583 printf(" packet len=%u - nb packet segments=%d\n",
584 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
586 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
587 nb_fwd_lcores, nb_fwd_ports);
588 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n",
589 nb_rxq, nb_rxd, rx_free_thresh);
590 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
591 rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh);
592 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n",
593 nb_txq, nb_txd, tx_free_thresh);
594 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
595 tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);
596 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
597 tx_rs_thresh, txq_flags);
601 * Setup forwarding configuration for each logical core.
604 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
606 streamid_t nb_fs_per_lcore;
614 nb_fs = cfg->nb_fwd_streams;
615 nb_fc = cfg->nb_fwd_lcores;
616 if (nb_fs <= nb_fc) {
620 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
621 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
623 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
625 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
627 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
628 fwd_lcores[lc_id]->stream_idx = sm_id;
629 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
630 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
634 * Assign extra remaining streams, if any.
636 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
637 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
638 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
639 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
640 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
645 simple_fwd_config_setup(void)
651 if (nb_fwd_ports % 2) {
652 if (port_topology == PORT_TOPOLOGY_CHAINED) {
656 printf("\nWarning! Cannot handle an odd number of ports "
657 "with the current port topology. Configuration "
658 "must be changed to have an even number of ports, "
659 "or relaunch application with "
660 "--port-topology=chained\n\n");
664 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
665 cur_fwd_config.nb_fwd_streams =
666 (streamid_t) cur_fwd_config.nb_fwd_ports;
668 /* reinitialize forwarding streams */
672 * In the simple forwarding test, the number of forwarding cores
673 * must be lower or equal to the number of forwarding ports.
675 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
676 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
677 cur_fwd_config.nb_fwd_lcores =
678 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
679 setup_fwd_config_of_each_lcore(&cur_fwd_config);
681 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
682 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
683 fwd_streams[i]->rx_port = fwd_ports_ids[i];
684 fwd_streams[i]->rx_queue = 0;
685 fwd_streams[i]->tx_port = fwd_ports_ids[j];
686 fwd_streams[i]->tx_queue = 0;
687 fwd_streams[i]->peer_addr = j;
689 if (port_topology == PORT_TOPOLOGY_PAIRED) {
690 fwd_streams[j]->rx_port = fwd_ports_ids[j];
691 fwd_streams[j]->rx_queue = 0;
692 fwd_streams[j]->tx_port = fwd_ports_ids[i];
693 fwd_streams[j]->tx_queue = 0;
694 fwd_streams[j]->peer_addr = i;
700 * For the RSS forwarding test, each core is assigned on every port a transmit
701 * queue whose index is the index of the core itself. This approach limits the
702 * maximumm number of processing cores of the RSS test to the maximum number of
703 * TX queues supported by the devices.
705 * Each core is assigned a single stream, each stream being composed of
706 * a RX queue to poll on a RX port for input messages, associated with
707 * a TX queue of a TX port where to send forwarded packets.
708 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
709 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
711 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
715 rss_fwd_config_setup(void)
726 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
727 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
728 cur_fwd_config.nb_fwd_streams =
729 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
730 if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
731 cur_fwd_config.nb_fwd_streams =
732 (streamid_t)cur_fwd_config.nb_fwd_lcores;
734 cur_fwd_config.nb_fwd_lcores =
735 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
737 /* reinitialize forwarding streams */
740 setup_fwd_config_of_each_lcore(&cur_fwd_config);
742 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
743 struct fwd_stream *fs;
745 fs = fwd_streams[lc_id];
746 if ((rxp & 0x1) == 0)
747 txp = (portid_t) (rxp + 1);
749 txp = (portid_t) (rxp - 1);
750 fs->rx_port = fwd_ports_ids[rxp];
752 fs->tx_port = fwd_ports_ids[txp];
754 fs->peer_addr = fs->tx_port;
755 rxq = (queueid_t) (rxq + 1);
760 * Restart from RX queue 0 on next RX port
763 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
765 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
767 rxp = (portid_t) (rxp + 1);
772 * In DCB and VT on,the mapping of 128 receive queues to 128 transmit queues.
775 dcb_rxq_2_txq_mapping(queueid_t rxq, queueid_t *txq)
777 if(dcb_q_mapping == DCB_4_TCS_Q_MAPPING) {
784 *txq = (uint16_t)(rxq + 32);
787 /* tc2: 96-111;tc3:112-127 */
788 *txq = (uint16_t)(rxq/2 + 64);
797 *txq = (uint16_t)(rxq + 16);
801 *txq = (uint16_t)(rxq + 32);
804 /* tc4,tc5,tc6 and tc7 mapping */
805 *txq = (uint16_t)(rxq/2 + 64);
811 * For the DCB forwarding test, each core is assigned on every port multi-transmit
814 * Each core is assigned a multi-stream, each stream being composed of
815 * a RX queue to poll on a RX port for input messages, associated with
816 * a TX queue of a TX port where to send forwarded packets.
817 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
818 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
821 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
824 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
825 * There is a mapping of RxQj to TxQl to be required,and the mapping was implemented
826 * in dcb_rxq_2_txq_mapping function.
829 dcb_fwd_config_setup(void)
840 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
841 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
842 cur_fwd_config.nb_fwd_streams =
843 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
845 /* reinitialize forwarding streams */
848 setup_fwd_config_of_each_lcore(&cur_fwd_config);
850 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
851 /* a fwd core can run multi-streams */
852 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++)
854 struct fwd_stream *fs;
855 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
856 if ((rxp & 0x1) == 0)
857 txp = (portid_t) (rxp + 1);
859 txp = (portid_t) (rxp - 1);
860 fs->rx_port = fwd_ports_ids[rxp];
862 fs->tx_port = fwd_ports_ids[txp];
863 if (dcb_q_mapping == DCB_VT_Q_MAPPING)
866 dcb_rxq_2_txq_mapping(rxq, &fs->tx_queue);
867 fs->peer_addr = fs->tx_port;
868 rxq = (queueid_t) (rxq + 1);
872 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
874 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
876 rxp = (portid_t) (rxp + 1);
882 fwd_config_setup(void)
884 cur_fwd_config.fwd_eng = cur_fwd_eng;
885 if ((nb_rxq > 1) && (nb_txq > 1)){
887 dcb_fwd_config_setup();
889 rss_fwd_config_setup();
892 simple_fwd_config_setup();
896 pkt_fwd_config_display(struct fwd_config *cfg)
898 struct fwd_stream *fs;
902 printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
904 cfg->fwd_eng->fwd_mode_name,
905 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
906 numa_support == 1 ? "enabled" : "disabled");
907 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
908 printf("Logical Core %u (socket %u) forwards packets on "
910 fwd_lcores_cpuids[lc_id],
911 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
912 fwd_lcores[lc_id]->stream_nb);
913 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
914 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
915 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
916 "P=%d/Q=%d (socket %u) ",
917 fs->rx_port, fs->rx_queue,
918 ports[fs->rx_port].socket_id,
919 fs->tx_port, fs->tx_queue,
920 ports[fs->tx_port].socket_id);
921 print_ethaddr("peer=",
922 &peer_eth_addrs[fs->peer_addr]);
931 fwd_config_display(void)
933 if((dcb_config) && (nb_fwd_lcores == 1)) {
934 printf("In DCB mode,the nb forwarding cores should be larger than 1\n");
938 pkt_fwd_config_display(&cur_fwd_config);
942 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
945 unsigned int lcore_cpuid;
950 for (i = 0; i < nb_lc; i++) {
951 lcore_cpuid = lcorelist[i];
952 if (! rte_lcore_is_enabled(lcore_cpuid)) {
953 printf("lcore %u not enabled\n", lcore_cpuid);
956 if (lcore_cpuid == rte_get_master_lcore()) {
957 printf("lcore %u cannot be masked on for running "
958 "packet forwarding, which is the master lcore "
959 "and reserved for command line parsing only\n",
964 fwd_lcores_cpuids[i] = lcore_cpuid;
966 if (record_now == 0) {
970 nb_cfg_lcores = (lcoreid_t) nb_lc;
971 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
972 printf("previous number of forwarding cores %u - changed to "
973 "number of configured cores %u\n",
974 (unsigned int) nb_fwd_lcores, nb_lc);
975 nb_fwd_lcores = (lcoreid_t) nb_lc;
982 set_fwd_lcores_mask(uint64_t lcoremask)
984 unsigned int lcorelist[64];
988 if (lcoremask == 0) {
989 printf("Invalid NULL mask of cores\n");
993 for (i = 0; i < 64; i++) {
994 if (! ((uint64_t)(1ULL << i) & lcoremask))
996 lcorelist[nb_lc++] = i;
998 return set_fwd_lcores_list(lcorelist, nb_lc);
1002 set_fwd_lcores_number(uint16_t nb_lc)
1004 if (nb_lc > nb_cfg_lcores) {
1005 printf("nb fwd cores %u > %u (max. number of configured "
1006 "lcores) - ignored\n",
1007 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1010 nb_fwd_lcores = (lcoreid_t) nb_lc;
1011 printf("Number of forwarding cores set to %u\n",
1012 (unsigned int) nb_fwd_lcores);
1016 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1024 for (i = 0; i < nb_pt; i++) {
1025 port_id = (portid_t) portlist[i];
1026 if (port_id >= nb_ports) {
1027 printf("Invalid port id %u > %u\n",
1028 (unsigned int) port_id,
1029 (unsigned int) nb_ports);
1033 fwd_ports_ids[i] = port_id;
1035 if (record_now == 0) {
1039 nb_cfg_ports = (portid_t) nb_pt;
1040 if (nb_fwd_ports != (portid_t) nb_pt) {
1041 printf("previous number of forwarding ports %u - changed to "
1042 "number of configured ports %u\n",
1043 (unsigned int) nb_fwd_ports, nb_pt);
1044 nb_fwd_ports = (portid_t) nb_pt;
1049 set_fwd_ports_mask(uint64_t portmask)
1051 unsigned int portlist[64];
1055 if (portmask == 0) {
1056 printf("Invalid NULL mask of ports\n");
1060 for (i = 0; i < 64; i++) {
1061 if (! ((uint64_t)(1ULL << i) & portmask))
1063 portlist[nb_pt++] = i;
1065 set_fwd_ports_list(portlist, nb_pt);
1069 set_fwd_ports_number(uint16_t nb_pt)
1071 if (nb_pt > nb_cfg_ports) {
1072 printf("nb fwd ports %u > %u (number of configured "
1073 "ports) - ignored\n",
1074 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1077 nb_fwd_ports = (portid_t) nb_pt;
1078 printf("Number of forwarding ports set to %u\n",
1079 (unsigned int) nb_fwd_ports);
1083 set_nb_pkt_per_burst(uint16_t nb)
1085 if (nb > MAX_PKT_BURST) {
1086 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1088 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1091 nb_pkt_per_burst = nb;
1092 printf("Number of packets per burst set to %u\n",
1093 (unsigned int) nb_pkt_per_burst);
1097 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1099 uint16_t tx_pkt_len;
1102 if (nb_segs >= (unsigned) nb_txd) {
1103 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1104 nb_segs, (unsigned int) nb_txd);
1109 * Check that each segment length is greater or equal than
1110 * the mbuf data sise.
1111 * Check also that the total packet length is greater or equal than the
1112 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1115 for (i = 0; i < nb_segs; i++) {
1116 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1117 printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1118 i, seg_lengths[i], (unsigned) mbuf_data_size);
1121 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1123 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1124 printf("total packet length=%u < %d - give up\n",
1125 (unsigned) tx_pkt_len,
1126 (int)(sizeof(struct ether_hdr) + 20 + 8));
1130 for (i = 0; i < nb_segs; i++)
1131 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1133 tx_pkt_length = tx_pkt_len;
1134 tx_pkt_nb_segs = (uint8_t) nb_segs;
1138 set_pkt_forwarding_mode(const char *fwd_mode_name)
1140 struct fwd_engine *fwd_eng;
1144 while ((fwd_eng = fwd_engines[i]) != NULL) {
1145 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1146 printf("Set %s packet forwarding mode\n",
1148 cur_fwd_eng = fwd_eng;
1153 printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1157 set_verbose_level(uint16_t vb_level)
1159 printf("Change verbose level from %u to %u\n",
1160 (unsigned int) verbose_level, (unsigned int) vb_level);
1161 verbose_level = vb_level;
1165 vlan_extend_set(portid_t port_id, int on)
1170 if (port_id_is_invalid(port_id))
1173 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1176 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1178 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1180 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1182 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1183 "diag=%d\n", port_id, on, diag);
1187 rx_vlan_strip_set(portid_t port_id, int on)
1192 if (port_id_is_invalid(port_id))
1195 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1198 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1200 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1202 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1204 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1205 "diag=%d\n", port_id, on, diag);
1209 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1213 if (port_id_is_invalid(port_id))
1216 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1218 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1219 "diag=%d\n", port_id, queue_id, on, diag);
1223 rx_vlan_filter_set(portid_t port_id, int on)
1228 if (port_id_is_invalid(port_id))
1231 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1234 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1236 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1238 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1240 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1241 "diag=%d\n", port_id, on, diag);
1245 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1249 if (port_id_is_invalid(port_id))
1251 if (vlan_id_is_invalid(vlan_id))
1253 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1256 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1258 port_id, vlan_id, on, diag);
1262 rx_vlan_all_filter_set(portid_t port_id, int on)
1266 if (port_id_is_invalid(port_id))
1268 for (vlan_id = 0; vlan_id < 4096; vlan_id++)
1269 rx_vft_set(port_id, vlan_id, on);
1273 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1276 if (port_id_is_invalid(port_id))
1279 diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1283 printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1285 port_id, tp_id, diag);
1289 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1291 if (port_id_is_invalid(port_id))
1293 if (vlan_id_is_invalid(vlan_id))
1295 ports[port_id].tx_ol_flags |= PKT_TX_VLAN_PKT;
1296 ports[port_id].tx_vlan_id = vlan_id;
1300 tx_vlan_reset(portid_t port_id)
1302 if (port_id_is_invalid(port_id))
1304 ports[port_id].tx_ol_flags &= ~PKT_TX_VLAN_PKT;
1308 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1311 uint8_t existing_mapping_found = 0;
1313 if (port_id_is_invalid(port_id))
1316 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1319 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1320 printf("map_value not in required range 0..%d\n",
1321 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1325 if (!is_rx) { /*then tx*/
1326 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1327 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1328 (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1329 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1330 existing_mapping_found = 1;
1334 if (!existing_mapping_found) { /* A new additional mapping... */
1335 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1336 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1337 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1338 nb_tx_queue_stats_mappings++;
1342 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1343 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1344 (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1345 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1346 existing_mapping_found = 1;
1350 if (!existing_mapping_found) { /* A new additional mapping... */
1351 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1352 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1353 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1354 nb_rx_queue_stats_mappings++;
1360 tx_cksum_set(portid_t port_id, uint8_t cksum_mask)
1362 uint16_t tx_ol_flags;
1363 if (port_id_is_invalid(port_id))
1365 /* Clear last 4 bits and then set L3/4 checksum mask again */
1366 tx_ol_flags = (uint16_t) (ports[port_id].tx_ol_flags & 0xFFF0);
1367 ports[port_id].tx_ol_flags = (uint16_t) ((cksum_mask & 0xf) | tx_ol_flags);
1371 fdir_add_signature_filter(portid_t port_id, uint8_t queue_id,
1372 struct rte_fdir_filter *fdir_filter)
1376 if (port_id_is_invalid(port_id))
1379 diag = rte_eth_dev_fdir_add_signature_filter(port_id, fdir_filter,
1384 printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1385 "diag=%d\n", port_id, diag);
1389 fdir_update_signature_filter(portid_t port_id, uint8_t queue_id,
1390 struct rte_fdir_filter *fdir_filter)
1394 if (port_id_is_invalid(port_id))
1397 diag = rte_eth_dev_fdir_update_signature_filter(port_id, fdir_filter,
1402 printf("rte_eth_dev_fdir_update_signature_filter for port_id=%d failed "
1403 "diag=%d\n", port_id, diag);
1407 fdir_remove_signature_filter(portid_t port_id,
1408 struct rte_fdir_filter *fdir_filter)
1412 if (port_id_is_invalid(port_id))
1415 diag = rte_eth_dev_fdir_remove_signature_filter(port_id, fdir_filter);
1419 printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1420 "diag=%d\n", port_id, diag);
1425 fdir_get_infos(portid_t port_id)
1427 struct rte_eth_fdir fdir_infos;
1429 static const char *fdir_stats_border = "########################";
1431 if (port_id_is_invalid(port_id))
1434 rte_eth_dev_fdir_get_infos(port_id, &fdir_infos);
1436 printf("\n %s FDIR infos for port %-2d %s\n",
1437 fdir_stats_border, port_id, fdir_stats_border);
1439 printf(" collision: %-10"PRIu64" free: %"PRIu64"\n"
1440 " maxhash: %-10"PRIu64" maxlen: %"PRIu64"\n"
1441 " add: %-10"PRIu64" remove: %"PRIu64"\n"
1442 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
1443 (uint64_t)(fdir_infos.collision), (uint64_t)(fdir_infos.free),
1444 (uint64_t)(fdir_infos.maxhash), (uint64_t)(fdir_infos.maxlen),
1445 fdir_infos.add, fdir_infos.remove,
1446 fdir_infos.f_add, fdir_infos.f_remove);
1447 printf(" %s############################%s\n",
1448 fdir_stats_border, fdir_stats_border);
1452 fdir_add_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1453 uint8_t drop, struct rte_fdir_filter *fdir_filter)
1457 if (port_id_is_invalid(port_id))
1460 diag = rte_eth_dev_fdir_add_perfect_filter(port_id, fdir_filter,
1461 soft_id, queue_id, drop);
1465 printf("rte_eth_dev_fdir_add_perfect_filter for port_id=%d failed "
1466 "diag=%d\n", port_id, diag);
1470 fdir_update_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1471 uint8_t drop, struct rte_fdir_filter *fdir_filter)
1475 if (port_id_is_invalid(port_id))
1478 diag = rte_eth_dev_fdir_update_perfect_filter(port_id, fdir_filter,
1479 soft_id, queue_id, drop);
1483 printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1484 "diag=%d\n", port_id, diag);
1488 fdir_remove_perfect_filter(portid_t port_id, uint16_t soft_id,
1489 struct rte_fdir_filter *fdir_filter)
1493 if (port_id_is_invalid(port_id))
1496 diag = rte_eth_dev_fdir_remove_perfect_filter(port_id, fdir_filter,
1501 printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1502 "diag=%d\n", port_id, diag);
1506 fdir_set_masks(portid_t port_id, struct rte_fdir_masks *fdir_masks)
1510 if (port_id_is_invalid(port_id))
1513 diag = rte_eth_dev_fdir_set_masks(port_id, fdir_masks);
1517 printf("rte_eth_dev_set_masks_filter for port_id=%d failed "
1518 "diag=%d\n", port_id, diag);