1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2021 NVIDIA Corporation & Affiliates
5 #include <rte_ethdev.h>
10 * Rx only sub-burst forwarding.
13 forward_rx_only(uint16_t nb_rx, struct rte_mbuf **pkts_burst)
15 rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
19 * Get packet source stream by source port and queue.
20 * All streams of same shared Rx queue locates on same core.
22 static struct fwd_stream *
23 forward_stream_get(struct fwd_stream *fs, uint16_t port)
27 struct fwd_stream **fsm;
31 fsm = &fwd_streams[fc->stream_idx];
32 nb_fs = fc->stream_nb;
33 for (sm_id = 0; sm_id < nb_fs; sm_id++) {
34 if (fsm[sm_id]->rx_port == port &&
35 fsm[sm_id]->rx_queue == fs->rx_queue)
42 * Forward packet by source port and queue.
45 forward_sub_burst(struct fwd_stream *src_fs, uint16_t port, uint16_t nb_rx,
46 struct rte_mbuf **pkts)
48 struct fwd_stream *fs = forward_stream_get(src_fs, port);
51 fs->rx_packets += nb_rx;
52 forward_rx_only(nb_rx, pkts);
54 /* Source stream not found, drop all packets. */
55 src_fs->fwd_dropped += nb_rx;
57 rte_pktmbuf_free(pkts[--nb_rx]);
62 * Forward packets from shared Rx queue.
64 * Source port of packets are identified by mbuf->port.
67 forward_shared_rxq(struct fwd_stream *fs, uint16_t nb_rx,
68 struct rte_mbuf **pkts_burst)
70 uint16_t i, nb_sub_burst, port, last_port;
73 last_port = pkts_burst[0]->port;
74 /* Locate sub-burst according to mbuf->port. */
75 for (i = 0; i < nb_rx - 1; ++i) {
76 rte_prefetch0(pkts_burst[i + 1]);
77 port = pkts_burst[i]->port;
78 if (i > 0 && last_port != port) {
79 /* Forward packets with same source port. */
80 forward_sub_burst(fs, last_port, nb_sub_burst,
81 &pkts_burst[i - nb_sub_burst]);
89 forward_sub_burst(fs, last_port, nb_sub_burst,
90 &pkts_burst[nb_rx - nb_sub_burst]);
94 shared_rxq_fwd(struct fwd_stream *fs)
96 struct rte_mbuf *pkts_burst[nb_pkt_per_burst];
98 uint64_t start_tsc = 0;
100 get_start_cycles(&start_tsc);
101 nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
103 inc_rx_burst_stats(fs, nb_rx);
104 if (unlikely(nb_rx == 0))
106 forward_shared_rxq(fs, nb_rx, pkts_burst);
107 get_end_cycles(fs, start_tsc);
111 shared_rxq_stream_init(struct fwd_stream *fs)
113 fs->disabled = ports[fs->rx_port].rxq[fs->rx_queue].state ==
114 RTE_ETH_QUEUE_STATE_STOPPED;
117 struct fwd_engine shared_rxq_engine = {
118 .fwd_mode_name = "shared_rxq",
119 .port_fwd_begin = NULL,
120 .port_fwd_end = NULL,
121 .stream_init = shared_rxq_stream_init,
122 .packet_fwd = shared_rxq_fwd,