1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <sys/queue.h>
16 #include <rte_common.h>
17 #include <rte_byteorder.h>
19 #include <rte_debug.h>
20 #include <rte_cycles.h>
21 #include <rte_memory.h>
22 #include <rte_launch.h>
24 #include <rte_per_lcore.h>
25 #include <rte_lcore.h>
26 #include <rte_branch_prediction.h>
27 #include <rte_memcpy.h>
28 #include <rte_mempool.h>
30 #include <rte_interrupts.h>
32 #include <rte_ether.h>
33 #include <rte_ethdev.h>
34 #include <rte_string_fns.h>
40 * Forwarding of packets in I/O mode.
41 * Forward packets "as-is".
42 * This is the fastest possible forwarding operation, as it does not access
46 pkt_burst_io_forward(struct fwd_stream *fs)
48 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
52 uint64_t start_tsc = 0;
54 get_start_cycles(&start_tsc);
57 * Receive a burst of packets and forward them.
59 nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
60 pkts_burst, nb_pkt_per_burst);
61 inc_rx_burst_stats(fs, nb_rx);
62 if (unlikely(nb_rx == 0))
64 fs->rx_packets += nb_rx;
66 nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
71 if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
73 while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
74 rte_delay_us(burst_tx_delay_time);
75 nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
76 &pkts_burst[nb_tx], nb_rx - nb_tx);
79 fs->tx_packets += nb_tx;
80 inc_tx_burst_stats(fs, nb_tx);
81 if (unlikely(nb_tx < nb_rx)) {
82 fs->fwd_dropped += (nb_rx - nb_tx);
84 rte_pktmbuf_free(pkts_burst[nb_tx]);
85 } while (++nb_tx < nb_rx);
88 get_end_cycles(fs, start_tsc);
92 stream_init_forward(struct fwd_stream *fs)
94 bool rx_stopped, tx_stopped;
96 rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
97 RTE_ETH_QUEUE_STATE_STOPPED;
98 tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
99 RTE_ETH_QUEUE_STATE_STOPPED;
100 fs->disabled = rx_stopped || tx_stopped;
103 struct fwd_engine io_fwd_engine = {
104 .fwd_mode_name = "io",
105 .port_fwd_begin = NULL,
106 .port_fwd_end = NULL,
107 .stream_init = stream_init_forward,
108 .packet_fwd = pkt_burst_io_forward,