4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5 * Copyright(c) 2017, Linaro Limited
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef __L3FWD_LPM_NEON_H__
36 #define __L3FWD_LPM_NEON_H__
40 #include "l3fwd_neon.h"
43 * Read packet_type and destination IPV4 addresses from 4 mbufs.
46 processx4_step1(struct rte_mbuf *pkt[FWDSTEP],
50 struct ipv4_hdr *ipv4_hdr;
51 struct ether_hdr *eth_hdr;
54 eth_hdr = rte_pktmbuf_mtod(pkt[0], struct ether_hdr *);
55 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
56 dst[0] = ipv4_hdr->dst_addr;
57 ipv4_flag[0] = pkt[0]->packet_type & RTE_PTYPE_L3_IPV4;
59 eth_hdr = rte_pktmbuf_mtod(pkt[1], struct ether_hdr *);
60 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
61 dst[1] = ipv4_hdr->dst_addr;
62 ipv4_flag[0] &= pkt[1]->packet_type;
64 eth_hdr = rte_pktmbuf_mtod(pkt[2], struct ether_hdr *);
65 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
66 dst[2] = ipv4_hdr->dst_addr;
67 ipv4_flag[0] &= pkt[2]->packet_type;
69 eth_hdr = rte_pktmbuf_mtod(pkt[3], struct ether_hdr *);
70 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
71 dst[3] = ipv4_hdr->dst_addr;
72 ipv4_flag[0] &= pkt[3]->packet_type;
74 dip[0] = vld1q_s32(dst);
78 * Lookup into LPM for destination port.
79 * If lookup fails, use incoming port (portid) as destination port.
82 processx4_step2(const struct lcore_conf *qconf,
86 struct rte_mbuf *pkt[FWDSTEP],
87 uint16_t dprt[FWDSTEP])
91 dip = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(dip)));
93 /* if all 4 packets are IPV4. */
94 if (likely(ipv4_flag)) {
95 rte_lpm_lookupx4(qconf->ipv4_lookup_struct, dip, dst.u32,
97 /* get rid of unused upper 16 bit for each dport. */
98 vst1_s16((int16_t *)dprt, vqmovn_s32(dst.x));
101 dprt[0] = lpm_get_dst_port_with_ipv4(qconf, pkt[0],
103 dprt[1] = lpm_get_dst_port_with_ipv4(qconf, pkt[1],
105 dprt[2] = lpm_get_dst_port_with_ipv4(qconf, pkt[2],
107 dprt[3] = lpm_get_dst_port_with_ipv4(qconf, pkt[3],
113 * Buffer optimized handling of packets, invoked
117 l3fwd_lpm_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
118 uint16_t portid, struct lcore_conf *qconf)
120 int32_t i = 0, j = 0;
121 uint16_t dst_port[MAX_PKT_BURST];
124 const int32_t k = RTE_ALIGN_FLOOR(nb_rx, FWDSTEP);
125 const int32_t m = nb_rx % FWDSTEP;
128 for (i = 0; i < FWDSTEP; i++) {
129 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[i],
130 struct ether_hdr *) + 1);
133 for (j = 0; j != k - FWDSTEP; j += FWDSTEP) {
134 for (i = 0; i < FWDSTEP; i++) {
135 rte_prefetch0(rte_pktmbuf_mtod(
136 pkts_burst[j + i + FWDSTEP],
137 struct ether_hdr *) + 1);
140 processx4_step1(&pkts_burst[j], &dip, &ipv4_flag);
141 processx4_step2(qconf, dip, ipv4_flag, portid,
142 &pkts_burst[j], &dst_port[j]);
145 processx4_step1(&pkts_burst[j], &dip, &ipv4_flag);
146 processx4_step2(qconf, dip, ipv4_flag, portid, &pkts_burst[j],
153 /* Prefetch last up to 3 packets one by one */
156 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j],
157 struct ether_hdr *) + 1);
161 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j],
162 struct ether_hdr *) + 1);
166 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j],
167 struct ether_hdr *) + 1);
172 /* Classify last up to 3 packets one by one */
175 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j],
180 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j],
185 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j],
190 send_packets_multi(qconf, pkts_burst, dst_port, nb_rx);
193 #endif /* __L3FWD_LPM_NEON_H__ */