4 * Copyright(c) 2010-2016 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.
34 #ifndef __L3FWD_LPM_SSE_H__
35 #define __L3FWD_LPM_SSE_H__
37 #include "l3fwd_sse.h"
40 * Read packet_type and destination IPV4 addresses from 4 mbufs.
43 processx4_step1(struct rte_mbuf *pkt[FWDSTEP],
47 struct ipv4_hdr *ipv4_hdr;
48 struct ether_hdr *eth_hdr;
49 uint32_t x0, x1, x2, x3;
51 eth_hdr = rte_pktmbuf_mtod(pkt[0], struct ether_hdr *);
52 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
53 x0 = ipv4_hdr->dst_addr;
54 ipv4_flag[0] = pkt[0]->packet_type & RTE_PTYPE_L3_IPV4;
56 eth_hdr = rte_pktmbuf_mtod(pkt[1], struct ether_hdr *);
57 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
58 x1 = ipv4_hdr->dst_addr;
59 ipv4_flag[0] &= pkt[1]->packet_type;
61 eth_hdr = rte_pktmbuf_mtod(pkt[2], struct ether_hdr *);
62 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
63 x2 = ipv4_hdr->dst_addr;
64 ipv4_flag[0] &= pkt[2]->packet_type;
66 eth_hdr = rte_pktmbuf_mtod(pkt[3], struct ether_hdr *);
67 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
68 x3 = ipv4_hdr->dst_addr;
69 ipv4_flag[0] &= pkt[3]->packet_type;
71 dip[0] = _mm_set_epi32(x3, x2, x1, x0);
75 * Lookup into LPM for destination port.
76 * If lookup fails, use incoming port (portid) as destination port.
79 processx4_step2(const struct lcore_conf *qconf,
83 struct rte_mbuf *pkt[FWDSTEP],
84 uint16_t dprt[FWDSTEP])
87 const __m128i bswap_mask = _mm_set_epi8(12, 13, 14, 15, 8, 9, 10, 11,
88 4, 5, 6, 7, 0, 1, 2, 3);
90 /* Byte swap 4 IPV4 addresses. */
91 dip = _mm_shuffle_epi8(dip, bswap_mask);
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 dst.x = _mm_packs_epi32(dst.x, dst.x);
99 *(uint64_t *)dprt = dst.u64[0];
102 dprt[0] = lpm_get_dst_port_with_ipv4(qconf, pkt[0], dst.u32[0], portid);
103 dprt[1] = lpm_get_dst_port_with_ipv4(qconf, pkt[1], dst.u32[1], portid);
104 dprt[2] = lpm_get_dst_port_with_ipv4(qconf, pkt[2], dst.u32[2], portid);
105 dprt[3] = lpm_get_dst_port_with_ipv4(qconf, pkt[3], dst.u32[3], portid);
110 * Buffer optimized handling of packets, invoked
114 l3fwd_lpm_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
115 uint8_t portid, struct lcore_conf *qconf)
118 uint16_t dst_port[MAX_PKT_BURST];
119 __m128i dip[MAX_PKT_BURST / FWDSTEP];
120 uint32_t ipv4_flag[MAX_PKT_BURST / FWDSTEP];
121 const int32_t k = RTE_ALIGN_FLOOR(nb_rx, FWDSTEP);
123 for (j = 0; j != k; j += FWDSTEP)
124 processx4_step1(&pkts_burst[j], &dip[j / FWDSTEP],
125 &ipv4_flag[j / FWDSTEP]);
127 for (j = 0; j != k; j += FWDSTEP)
128 processx4_step2(qconf, dip[j / FWDSTEP],
129 ipv4_flag[j / FWDSTEP], portid, &pkts_burst[j], &dst_port[j]);
131 /* Classify last up to 3 packets one by one */
132 switch (nb_rx % FWDSTEP) {
134 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j], portid);
138 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j], portid);
142 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j], portid);
146 send_packets_multi(qconf, pkts_burst, dst_port, nb_rx);
149 #endif /* __L3FWD_LPM_SSE_H__ */