4 * Copyright(c) 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_EM_HLM_H__
36 #define __L3FWD_EM_HLM_H__
38 #if defined RTE_ARCH_X86
39 #include "l3fwd_sse.h"
40 #include "l3fwd_em_hlm_sse.h"
41 #elif defined RTE_MACHINE_CPUFLAG_NEON
42 #include "l3fwd_neon.h"
43 #include "l3fwd_em_hlm_neon.h"
46 static __rte_always_inline void
47 em_get_dst_port_ipv4x8(struct lcore_conf *qconf, struct rte_mbuf *m[8],
48 uint8_t portid, uint16_t dst_port[8])
51 union ipv4_5tuple_host key[8];
53 get_ipv4_5tuple(m[0], mask0.x, &key[0]);
54 get_ipv4_5tuple(m[1], mask0.x, &key[1]);
55 get_ipv4_5tuple(m[2], mask0.x, &key[2]);
56 get_ipv4_5tuple(m[3], mask0.x, &key[3]);
57 get_ipv4_5tuple(m[4], mask0.x, &key[4]);
58 get_ipv4_5tuple(m[5], mask0.x, &key[5]);
59 get_ipv4_5tuple(m[6], mask0.x, &key[6]);
60 get_ipv4_5tuple(m[7], mask0.x, &key[7]);
62 const void *key_array[8] = {&key[0], &key[1], &key[2], &key[3],
63 &key[4], &key[5], &key[6], &key[7]};
65 rte_hash_lookup_bulk(qconf->ipv4_lookup_struct, &key_array[0], 8, ret);
67 dst_port[0] = (uint8_t) ((ret[0] < 0) ?
68 portid : ipv4_l3fwd_out_if[ret[0]]);
69 dst_port[1] = (uint8_t) ((ret[1] < 0) ?
70 portid : ipv4_l3fwd_out_if[ret[1]]);
71 dst_port[2] = (uint8_t) ((ret[2] < 0) ?
72 portid : ipv4_l3fwd_out_if[ret[2]]);
73 dst_port[3] = (uint8_t) ((ret[3] < 0) ?
74 portid : ipv4_l3fwd_out_if[ret[3]]);
75 dst_port[4] = (uint8_t) ((ret[4] < 0) ?
76 portid : ipv4_l3fwd_out_if[ret[4]]);
77 dst_port[5] = (uint8_t) ((ret[5] < 0) ?
78 portid : ipv4_l3fwd_out_if[ret[5]]);
79 dst_port[6] = (uint8_t) ((ret[6] < 0) ?
80 portid : ipv4_l3fwd_out_if[ret[6]]);
81 dst_port[7] = (uint8_t) ((ret[7] < 0) ?
82 portid : ipv4_l3fwd_out_if[ret[7]]);
84 if (dst_port[0] >= RTE_MAX_ETHPORTS ||
85 (enabled_port_mask & 1 << dst_port[0]) == 0)
88 if (dst_port[1] >= RTE_MAX_ETHPORTS ||
89 (enabled_port_mask & 1 << dst_port[1]) == 0)
92 if (dst_port[2] >= RTE_MAX_ETHPORTS ||
93 (enabled_port_mask & 1 << dst_port[2]) == 0)
96 if (dst_port[3] >= RTE_MAX_ETHPORTS ||
97 (enabled_port_mask & 1 << dst_port[3]) == 0)
100 if (dst_port[4] >= RTE_MAX_ETHPORTS ||
101 (enabled_port_mask & 1 << dst_port[4]) == 0)
102 dst_port[4] = portid;
104 if (dst_port[5] >= RTE_MAX_ETHPORTS ||
105 (enabled_port_mask & 1 << dst_port[5]) == 0)
106 dst_port[5] = portid;
108 if (dst_port[6] >= RTE_MAX_ETHPORTS ||
109 (enabled_port_mask & 1 << dst_port[6]) == 0)
110 dst_port[6] = portid;
112 if (dst_port[7] >= RTE_MAX_ETHPORTS ||
113 (enabled_port_mask & 1 << dst_port[7]) == 0)
114 dst_port[7] = portid;
118 static __rte_always_inline void
119 em_get_dst_port_ipv6x8(struct lcore_conf *qconf, struct rte_mbuf *m[8],
120 uint8_t portid, uint16_t dst_port[8])
123 union ipv6_5tuple_host key[8];
125 get_ipv6_5tuple(m[0], mask1.x, mask2.x, &key[0]);
126 get_ipv6_5tuple(m[1], mask1.x, mask2.x, &key[1]);
127 get_ipv6_5tuple(m[2], mask1.x, mask2.x, &key[2]);
128 get_ipv6_5tuple(m[3], mask1.x, mask2.x, &key[3]);
129 get_ipv6_5tuple(m[4], mask1.x, mask2.x, &key[4]);
130 get_ipv6_5tuple(m[5], mask1.x, mask2.x, &key[5]);
131 get_ipv6_5tuple(m[6], mask1.x, mask2.x, &key[6]);
132 get_ipv6_5tuple(m[7], mask1.x, mask2.x, &key[7]);
134 const void *key_array[8] = {&key[0], &key[1], &key[2], &key[3],
135 &key[4], &key[5], &key[6], &key[7]};
137 rte_hash_lookup_bulk(qconf->ipv6_lookup_struct, &key_array[0], 8, ret);
139 dst_port[0] = (uint8_t) ((ret[0] < 0) ?
140 portid : ipv6_l3fwd_out_if[ret[0]]);
141 dst_port[1] = (uint8_t) ((ret[1] < 0) ?
142 portid : ipv6_l3fwd_out_if[ret[1]]);
143 dst_port[2] = (uint8_t) ((ret[2] < 0) ?
144 portid : ipv6_l3fwd_out_if[ret[2]]);
145 dst_port[3] = (uint8_t) ((ret[3] < 0) ?
146 portid : ipv6_l3fwd_out_if[ret[3]]);
147 dst_port[4] = (uint8_t) ((ret[4] < 0) ?
148 portid : ipv6_l3fwd_out_if[ret[4]]);
149 dst_port[5] = (uint8_t) ((ret[5] < 0) ?
150 portid : ipv6_l3fwd_out_if[ret[5]]);
151 dst_port[6] = (uint8_t) ((ret[6] < 0) ?
152 portid : ipv6_l3fwd_out_if[ret[6]]);
153 dst_port[7] = (uint8_t) ((ret[7] < 0) ?
154 portid : ipv6_l3fwd_out_if[ret[7]]);
156 if (dst_port[0] >= RTE_MAX_ETHPORTS ||
157 (enabled_port_mask & 1 << dst_port[0]) == 0)
158 dst_port[0] = portid;
160 if (dst_port[1] >= RTE_MAX_ETHPORTS ||
161 (enabled_port_mask & 1 << dst_port[1]) == 0)
162 dst_port[1] = portid;
164 if (dst_port[2] >= RTE_MAX_ETHPORTS ||
165 (enabled_port_mask & 1 << dst_port[2]) == 0)
166 dst_port[2] = portid;
168 if (dst_port[3] >= RTE_MAX_ETHPORTS ||
169 (enabled_port_mask & 1 << dst_port[3]) == 0)
170 dst_port[3] = portid;
172 if (dst_port[4] >= RTE_MAX_ETHPORTS ||
173 (enabled_port_mask & 1 << dst_port[4]) == 0)
174 dst_port[4] = portid;
176 if (dst_port[5] >= RTE_MAX_ETHPORTS ||
177 (enabled_port_mask & 1 << dst_port[5]) == 0)
178 dst_port[5] = portid;
180 if (dst_port[6] >= RTE_MAX_ETHPORTS ||
181 (enabled_port_mask & 1 << dst_port[6]) == 0)
182 dst_port[6] = portid;
184 if (dst_port[7] >= RTE_MAX_ETHPORTS ||
185 (enabled_port_mask & 1 << dst_port[7]) == 0)
186 dst_port[7] = portid;
190 static __rte_always_inline uint16_t
191 em_get_dst_port(const struct lcore_conf *qconf, struct rte_mbuf *pkt,
195 struct ipv4_hdr *ipv4_hdr;
196 struct ipv6_hdr *ipv6_hdr;
200 tcp_or_udp = pkt->packet_type & (RTE_PTYPE_L4_TCP | RTE_PTYPE_L4_UDP);
201 l3_ptypes = pkt->packet_type & RTE_PTYPE_L3_MASK;
203 if (tcp_or_udp && (l3_ptypes == RTE_PTYPE_L3_IPV4)) {
205 /* Handle IPv4 headers.*/
206 ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct ipv4_hdr *,
207 sizeof(struct ether_hdr));
209 next_hop = em_get_ipv4_dst_port(ipv4_hdr, portid,
210 qconf->ipv4_lookup_struct);
212 if (next_hop >= RTE_MAX_ETHPORTS ||
213 (enabled_port_mask & 1 << next_hop) == 0)
218 } else if (tcp_or_udp && (l3_ptypes == RTE_PTYPE_L3_IPV6)) {
220 /* Handle IPv6 headers.*/
221 ipv6_hdr = rte_pktmbuf_mtod_offset(pkt, struct ipv6_hdr *,
222 sizeof(struct ether_hdr));
224 next_hop = em_get_ipv6_dst_port(ipv6_hdr, portid,
225 qconf->ipv6_lookup_struct);
227 if (next_hop >= RTE_MAX_ETHPORTS ||
228 (enabled_port_mask & 1 << next_hop) == 0)
239 * Buffer optimized handling of packets, invoked
243 l3fwd_em_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
244 uint8_t portid, struct lcore_conf *qconf)
247 uint16_t dst_port[MAX_PKT_BURST];
250 * Send nb_rx - nb_rx%8 packets
253 int32_t n = RTE_ALIGN_FLOOR(nb_rx, 8);
255 for (j = 0; j < 8 && j < nb_rx; j++) {
256 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j],
257 struct ether_hdr *) + 1);
260 for (j = 0; j < n; j += 8) {
263 pkts_burst[j]->packet_type &
264 pkts_burst[j+1]->packet_type &
265 pkts_burst[j+2]->packet_type &
266 pkts_burst[j+3]->packet_type &
267 pkts_burst[j+4]->packet_type &
268 pkts_burst[j+5]->packet_type &
269 pkts_burst[j+6]->packet_type &
270 pkts_burst[j+7]->packet_type;
272 uint32_t l3_type = pkt_type & RTE_PTYPE_L3_MASK;
273 uint32_t tcp_or_udp = pkt_type &
274 (RTE_PTYPE_L4_TCP | RTE_PTYPE_L4_UDP);
276 for (i = 0, pos = j + 8; i < 8 && pos < nb_rx; i++, pos++) {
277 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[pos],
278 struct ether_hdr *) + 1);
281 if (tcp_or_udp && (l3_type == RTE_PTYPE_L3_IPV4)) {
283 em_get_dst_port_ipv4x8(qconf, &pkts_burst[j], portid,
286 } else if (tcp_or_udp && (l3_type == RTE_PTYPE_L3_IPV6)) {
288 em_get_dst_port_ipv6x8(qconf, &pkts_burst[j], portid,
292 dst_port[j] = em_get_dst_port(qconf, pkts_burst[j],
294 dst_port[j+1] = em_get_dst_port(qconf, pkts_burst[j+1],
296 dst_port[j+2] = em_get_dst_port(qconf, pkts_burst[j+2],
298 dst_port[j+3] = em_get_dst_port(qconf, pkts_burst[j+3],
300 dst_port[j+4] = em_get_dst_port(qconf, pkts_burst[j+4],
302 dst_port[j+5] = em_get_dst_port(qconf, pkts_burst[j+5],
304 dst_port[j+6] = em_get_dst_port(qconf, pkts_burst[j+6],
306 dst_port[j+7] = em_get_dst_port(qconf, pkts_burst[j+7],
311 for (; j < nb_rx; j++)
312 dst_port[j] = em_get_dst_port(qconf, pkts_burst[j], portid);
314 send_packets_multi(qconf, pkts_burst, dst_port, nb_rx);
317 #endif /* __L3FWD_EM_HLM_H__ */