4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5 * Copyright(c) 2017 IBM Corporation.
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_ALTIVEC_H__
36 #define __L3FWD_LPM_ALTIVEC_H__
38 #include "l3fwd_altivec.h"
41 * Read packet_type and destination IPV4 addresses from 4 mbufs.
44 processx4_step1(struct rte_mbuf *pkt[FWDSTEP],
45 vector unsigned int *dip,
48 struct ipv4_hdr *ipv4_hdr;
49 struct ether_hdr *eth_hdr;
50 uint32_t x0, x1, x2, x3;
52 eth_hdr = rte_pktmbuf_mtod(pkt[0], struct ether_hdr *);
53 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
54 x0 = ipv4_hdr->dst_addr;
55 ipv4_flag[0] = pkt[0]->packet_type & RTE_PTYPE_L3_IPV4;
57 rte_compiler_barrier();
58 eth_hdr = rte_pktmbuf_mtod(pkt[1], struct ether_hdr *);
59 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
60 x1 = ipv4_hdr->dst_addr;
61 ipv4_flag[0] &= pkt[1]->packet_type;
63 rte_compiler_barrier();
64 eth_hdr = rte_pktmbuf_mtod(pkt[2], struct ether_hdr *);
65 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
66 x2 = ipv4_hdr->dst_addr;
67 ipv4_flag[0] &= pkt[2]->packet_type;
69 rte_compiler_barrier();
70 eth_hdr = rte_pktmbuf_mtod(pkt[3], struct ether_hdr *);
71 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
72 x3 = ipv4_hdr->dst_addr;
73 ipv4_flag[0] &= pkt[3]->packet_type;
75 rte_compiler_barrier();
76 dip[0] = (vector unsigned int){x0, x1, x2, x3};
80 * Lookup into LPM for destination port.
81 * If lookup fails, use incoming port (portid) as destination port.
84 processx4_step2(const struct lcore_conf *qconf,
85 vector unsigned int dip,
88 struct rte_mbuf *pkt[FWDSTEP],
89 uint16_t dprt[FWDSTEP])
92 const vector unsigned char bswap_mask = (vector unsigned char){
98 /* Byte swap 4 IPV4 addresses. */
99 dip = (vector unsigned int)vec_perm(*(vector unsigned char *)&dip,
100 (vector unsigned char){}, bswap_mask);
102 /* if all 4 packets are IPV4. */
103 if (likely(ipv4_flag)) {
104 rte_lpm_lookupx4(qconf->ipv4_lookup_struct, (xmm_t)dip,
105 (uint32_t *)&dst, portid);
106 /* get rid of unused upper 16 bit for each dport. */
107 dst.x = (xmm_t)vec_packs(dst.x, dst.x);
108 *(uint64_t *)dprt = dst.u64[0];
111 dprt[0] = lpm_get_dst_port_with_ipv4(qconf, pkt[0],
113 dprt[1] = lpm_get_dst_port_with_ipv4(qconf, pkt[1],
115 dprt[2] = lpm_get_dst_port_with_ipv4(qconf, pkt[2],
117 dprt[3] = lpm_get_dst_port_with_ipv4(qconf, pkt[3],
123 * Buffer optimized handling of packets, invoked
127 l3fwd_lpm_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
128 uint8_t portid, struct lcore_conf *qconf)
131 uint16_t dst_port[MAX_PKT_BURST];
132 vector unsigned int dip[MAX_PKT_BURST / FWDSTEP];
133 uint32_t ipv4_flag[MAX_PKT_BURST / FWDSTEP];
134 const int32_t k = RTE_ALIGN_FLOOR(nb_rx, FWDSTEP);
136 for (j = 0; j != k; j += FWDSTEP)
137 processx4_step1(&pkts_burst[j], &dip[j / FWDSTEP],
138 &ipv4_flag[j / FWDSTEP]);
140 for (j = 0; j != k; j += FWDSTEP)
141 processx4_step2(qconf, dip[j / FWDSTEP],
142 ipv4_flag[j / FWDSTEP],
143 portid, &pkts_burst[j], &dst_port[j]);
145 /* Classify last up to 3 packets one by one */
146 switch (nb_rx % FWDSTEP) {
148 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j], portid);
152 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j], portid);
156 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j], portid);
161 send_packets_multi(qconf, pkts_burst, dst_port, nb_rx);
164 #endif /* __L3FWD_LPM_ALTIVEC_H__ */