]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/app/test-pmd/macswap.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / dpdk / app / test-pmd / macswap.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2014-2020 Mellanox Technologies, Ltd
3 */
4
5 #include <stdarg.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <errno.h>
9 #include <stdint.h>
10 #include <unistd.h>
11 #include <inttypes.h>
12
13 #include <sys/queue.h>
14 #include <sys/stat.h>
15
16 #include <rte_common.h>
17 #include <rte_byteorder.h>
18 #include <rte_log.h>
19 #include <rte_debug.h>
20 #include <rte_cycles.h>
21 #include <rte_memory.h>
22 #include <rte_memcpy.h>
23 #include <rte_launch.h>
24 #include <rte_eal.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_atomic.h>
28 #include <rte_branch_prediction.h>
29 #include <rte_mempool.h>
30 #include <rte_mbuf.h>
31 #include <rte_interrupts.h>
32 #include <rte_pci.h>
33 #include <rte_ether.h>
34 #include <rte_ethdev.h>
35 #include <rte_ip.h>
36 #include <rte_string_fns.h>
37 #include <rte_flow.h>
38
39 #include "testpmd.h"
40 #if defined(RTE_ARCH_X86)
41 #include "macswap_sse.h"
42 #elif defined(RTE_MACHINE_CPUFLAG_NEON)
43 #include "macswap_neon.h"
44 #else
45 #include "macswap.h"
46 #endif
47
48 /*
49 * MAC swap forwarding mode: Swap the source and the destination Ethernet
50 * addresses of packets before forwarding them.
51 */
52 static void
53 pkt_burst_mac_swap(struct fwd_stream *fs)
54 {
55 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
56 struct rte_port *txp;
57 uint16_t nb_rx;
58 uint16_t nb_tx;
59 uint32_t retry;
60 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
61 uint64_t start_tsc;
62 uint64_t end_tsc;
63 uint64_t core_cycles;
64 #endif
65
66 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
67 start_tsc = rte_rdtsc();
68 #endif
69
70 /*
71 * Receive a burst of packets and forward them.
72 */
73 nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
74 nb_pkt_per_burst);
75 if (unlikely(nb_rx == 0))
76 return;
77
78 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
79 fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
80 #endif
81 fs->rx_packets += nb_rx;
82 txp = &ports[fs->tx_port];
83
84 do_macswap(pkts_burst, nb_rx, txp);
85
86 nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
87 /*
88 * Retry if necessary
89 */
90 if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
91 retry = 0;
92 while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
93 rte_delay_us(burst_tx_delay_time);
94 nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
95 &pkts_burst[nb_tx], nb_rx - nb_tx);
96 }
97 }
98 fs->tx_packets += nb_tx;
99 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
100 fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
101 #endif
102 if (unlikely(nb_tx < nb_rx)) {
103 fs->fwd_dropped += (nb_rx - nb_tx);
104 do {
105 rte_pktmbuf_free(pkts_burst[nb_tx]);
106 } while (++nb_tx < nb_rx);
107 }
108 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
109 end_tsc = rte_rdtsc();
110 core_cycles = (end_tsc - start_tsc);
111 fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
112 #endif
113 }
114
115 struct fwd_engine mac_swap_engine = {
116 .fwd_mode_name = "macswap",
117 .port_fwd_begin = NULL,
118 .port_fwd_end = NULL,
119 .packet_fwd = pkt_burst_mac_swap,
120 };