1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
5 #ifndef __L3FWD_LPM_SSE_H__
6 #define __L3FWD_LPM_SSE_H__
11 * Read packet_type and destination IPV4 addresses from 4 mbufs.
14 processx4_step1(struct rte_mbuf *pkt[FWDSTEP],
18 struct ipv4_hdr *ipv4_hdr;
19 struct ether_hdr *eth_hdr;
20 uint32_t x0, x1, x2, x3;
22 eth_hdr = rte_pktmbuf_mtod(pkt[0], struct ether_hdr *);
23 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
24 x0 = ipv4_hdr->dst_addr;
25 ipv4_flag[0] = pkt[0]->packet_type & RTE_PTYPE_L3_IPV4;
27 eth_hdr = rte_pktmbuf_mtod(pkt[1], struct ether_hdr *);
28 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
29 x1 = ipv4_hdr->dst_addr;
30 ipv4_flag[0] &= pkt[1]->packet_type;
32 eth_hdr = rte_pktmbuf_mtod(pkt[2], struct ether_hdr *);
33 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
34 x2 = ipv4_hdr->dst_addr;
35 ipv4_flag[0] &= pkt[2]->packet_type;
37 eth_hdr = rte_pktmbuf_mtod(pkt[3], struct ether_hdr *);
38 ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
39 x3 = ipv4_hdr->dst_addr;
40 ipv4_flag[0] &= pkt[3]->packet_type;
42 dip[0] = _mm_set_epi32(x3, x2, x1, x0);
46 * Lookup into LPM for destination port.
47 * If lookup fails, use incoming port (portid) as destination port.
50 processx4_step2(const struct lcore_conf *qconf,
54 struct rte_mbuf *pkt[FWDSTEP],
55 uint16_t dprt[FWDSTEP])
58 const __m128i bswap_mask = _mm_set_epi8(12, 13, 14, 15, 8, 9, 10, 11,
59 4, 5, 6, 7, 0, 1, 2, 3);
61 /* Byte swap 4 IPV4 addresses. */
62 dip = _mm_shuffle_epi8(dip, bswap_mask);
64 /* if all 4 packets are IPV4. */
65 if (likely(ipv4_flag)) {
66 rte_lpm_lookupx4(qconf->ipv4_lookup_struct, dip, dst.u32,
68 /* get rid of unused upper 16 bit for each dport. */
69 dst.x = _mm_packs_epi32(dst.x, dst.x);
70 *(uint64_t *)dprt = dst.u64[0];
73 dprt[0] = lpm_get_dst_port_with_ipv4(qconf, pkt[0], dst.u32[0], portid);
74 dprt[1] = lpm_get_dst_port_with_ipv4(qconf, pkt[1], dst.u32[1], portid);
75 dprt[2] = lpm_get_dst_port_with_ipv4(qconf, pkt[2], dst.u32[2], portid);
76 dprt[3] = lpm_get_dst_port_with_ipv4(qconf, pkt[3], dst.u32[3], portid);
81 * Buffer optimized handling of packets, invoked
85 l3fwd_lpm_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
86 uint16_t portid, struct lcore_conf *qconf)
89 uint16_t dst_port[MAX_PKT_BURST];
90 __m128i dip[MAX_PKT_BURST / FWDSTEP];
91 uint32_t ipv4_flag[MAX_PKT_BURST / FWDSTEP];
92 const int32_t k = RTE_ALIGN_FLOOR(nb_rx, FWDSTEP);
94 for (j = 0; j != k; j += FWDSTEP)
95 processx4_step1(&pkts_burst[j], &dip[j / FWDSTEP],
96 &ipv4_flag[j / FWDSTEP]);
98 for (j = 0; j != k; j += FWDSTEP)
99 processx4_step2(qconf, dip[j / FWDSTEP],
100 ipv4_flag[j / FWDSTEP], portid, &pkts_burst[j], &dst_port[j]);
102 /* Classify last up to 3 packets one by one */
103 switch (nb_rx % FWDSTEP) {
105 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j], portid);
109 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j], portid);
113 dst_port[j] = lpm_get_dst_port(qconf, pkts_burst[j], portid);
117 send_packets_multi(qconf, pkts_burst, dst_port, nb_rx);
120 #endif /* __L3FWD_LPM_SSE_H__ */