]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/examples/l3fwd/l3fwd_altivec.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / dpdk / examples / l3fwd / l3fwd_altivec.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 Intel Corporation.
3 * Copyright(c) 2017 IBM Corporation.
4 * All rights reserved.
5 */
6
7 #ifndef _L3FWD_ALTIVEC_H_
8 #define _L3FWD_ALTIVEC_H_
9
10 #include "l3fwd.h"
11 #include "l3fwd_common.h"
12
13 /*
14 * Update source and destination MAC addresses in the ethernet header.
15 * Perform RFC1812 checks and updates for IPV4 packets.
16 */
17 static inline void
18 processx4_step3(struct rte_mbuf *pkt[FWDSTEP], uint16_t dst_port[FWDSTEP])
19 {
20 vector unsigned int te[FWDSTEP];
21 vector unsigned int ve[FWDSTEP];
22 vector unsigned int *p[FWDSTEP];
23
24 p[0] = rte_pktmbuf_mtod(pkt[0], vector unsigned int *);
25 p[1] = rte_pktmbuf_mtod(pkt[1], vector unsigned int *);
26 p[2] = rte_pktmbuf_mtod(pkt[2], vector unsigned int *);
27 p[3] = rte_pktmbuf_mtod(pkt[3], vector unsigned int *);
28
29 ve[0] = (vector unsigned int)val_eth[dst_port[0]];
30 te[0] = *p[0];
31
32 ve[1] = (vector unsigned int)val_eth[dst_port[1]];
33 te[1] = *p[1];
34
35 ve[2] = (vector unsigned int)val_eth[dst_port[2]];
36 te[2] = *p[2];
37
38 ve[3] = (vector unsigned int)val_eth[dst_port[3]];
39 te[3] = *p[3];
40
41 /* Update first 12 bytes, keep rest bytes intact. */
42 te[0] = (vector unsigned int)vec_sel(
43 (vector unsigned short)ve[0],
44 (vector unsigned short)te[0],
45 (vector unsigned short) {0, 0, 0, 0,
46 0, 0, 0xffff, 0xffff});
47
48 te[1] = (vector unsigned int)vec_sel(
49 (vector unsigned short)ve[1],
50 (vector unsigned short)te[1],
51 (vector unsigned short) {0, 0, 0, 0,
52 0, 0, 0xffff, 0xffff});
53
54 te[2] = (vector unsigned int)vec_sel(
55 (vector unsigned short)ve[2],
56 (vector unsigned short)te[2],
57 (vector unsigned short) {0, 0, 0, 0, 0,
58 0, 0xffff, 0xffff});
59
60 te[3] = (vector unsigned int)vec_sel(
61 (vector unsigned short)ve[3],
62 (vector unsigned short)te[3],
63 (vector unsigned short) {0, 0, 0, 0,
64 0, 0, 0xffff, 0xffff});
65
66 *p[0] = te[0];
67 *p[1] = te[1];
68 *p[2] = te[2];
69 *p[3] = te[3];
70
71 rfc1812_process((struct ipv4_hdr *)((struct ether_hdr *)p[0] + 1),
72 &dst_port[0], pkt[0]->packet_type);
73 rfc1812_process((struct ipv4_hdr *)((struct ether_hdr *)p[1] + 1),
74 &dst_port[1], pkt[1]->packet_type);
75 rfc1812_process((struct ipv4_hdr *)((struct ether_hdr *)p[2] + 1),
76 &dst_port[2], pkt[2]->packet_type);
77 rfc1812_process((struct ipv4_hdr *)((struct ether_hdr *)p[3] + 1),
78 &dst_port[3], pkt[3]->packet_type);
79 }
80
81 /*
82 * Group consecutive packets with the same destination port in bursts of 4.
83 * Suppose we have array of destination ports:
84 * dst_port[] = {a, b, c, d,, e, ... }
85 * dp1 should contain: <a, b, c, d>, dp2: <b, c, d, e>.
86 * We doing 4 comparisons at once and the result is 4 bit mask.
87 * This mask is used as an index into prebuild array of pnum values.
88 */
89 static inline uint16_t *
90 port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp, vector unsigned short dp1,
91 vector unsigned short dp2)
92 {
93 union {
94 uint16_t u16[FWDSTEP + 1];
95 uint64_t u64;
96 } *pnum = (void *)pn;
97
98 int32_t v;
99
100 v = vec_any_eq(dp1, dp2);
101
102
103 /* update last port counter. */
104 lp[0] += gptbl[v].lpv;
105
106 /* if dest port value has changed. */
107 if (v != GRPMSK) {
108 pnum->u64 = gptbl[v].pnum;
109 pnum->u16[FWDSTEP] = 1;
110 lp = pnum->u16 + gptbl[v].idx;
111 }
112
113 return lp;
114 }
115
116 /**
117 * Process one packet:
118 * Update source and destination MAC addresses in the ethernet header.
119 * Perform RFC1812 checks and updates for IPV4 packets.
120 */
121 static inline void
122 process_packet(struct rte_mbuf *pkt, uint16_t *dst_port)
123 {
124 struct ether_hdr *eth_hdr;
125 vector unsigned int te, ve;
126
127 eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
128
129 te = *(vector unsigned int *)eth_hdr;
130 ve = (vector unsigned int)val_eth[dst_port[0]];
131
132 rfc1812_process((struct ipv4_hdr *)(eth_hdr + 1), dst_port,
133 pkt->packet_type);
134
135 /* dynamically vec_sel te and ve for MASK_ETH (0x3f) */
136 te = (vector unsigned int)vec_sel(
137 (vector unsigned short)ve,
138 (vector unsigned short)te,
139 (vector unsigned short){0, 0, 0, 0,
140 0, 0, 0xffff, 0xffff});
141
142 *(vector unsigned int *)eth_hdr = te;
143 }
144
145 /**
146 * Send packets burst from pkts_burst to the ports in dst_port array
147 */
148 static __rte_always_inline void
149 send_packets_multi(struct lcore_conf *qconf, struct rte_mbuf **pkts_burst,
150 uint16_t dst_port[MAX_PKT_BURST], int nb_rx)
151 {
152 int32_t k;
153 int j = 0;
154 uint16_t dlp;
155 uint16_t *lp;
156 uint16_t pnum[MAX_PKT_BURST + 1];
157
158 /*
159 * Finish packet processing and group consecutive
160 * packets with the same destination port.
161 */
162 k = RTE_ALIGN_FLOOR(nb_rx, FWDSTEP);
163 if (k != 0) {
164 vector unsigned short dp1, dp2;
165
166 lp = pnum;
167 lp[0] = 1;
168
169 processx4_step3(pkts_burst, dst_port);
170
171 /* dp1: <d[0], d[1], d[2], d[3], ... > */
172 dp1 = *(vector unsigned short *)dst_port;
173
174 for (j = FWDSTEP; j != k; j += FWDSTEP) {
175 processx4_step3(&pkts_burst[j], &dst_port[j]);
176
177 /*
178 * dp2:
179 * <d[j-3], d[j-2], d[j-1], d[j], ... >
180 */
181 dp2 = *((vector unsigned short *)
182 &dst_port[j - FWDSTEP + 1]);
183 lp = port_groupx4(&pnum[j - FWDSTEP], lp, dp1, dp2);
184
185 /*
186 * dp1:
187 * <d[j], d[j+1], d[j+2], d[j+3], ... >
188 */
189 dp1 = vec_sro(dp2, (vector unsigned char) {
190 0, 0, 0, 0, 0, 0, 0, 0,
191 0, 0, 0, (FWDSTEP - 1) * sizeof(dst_port[0])});
192 }
193
194 /*
195 * dp2: <d[j-3], d[j-2], d[j-1], d[j-1], ... >
196 */
197 dp2 = vec_perm(dp1, (vector unsigned short){},
198 (vector unsigned char){0xf9});
199 lp = port_groupx4(&pnum[j - FWDSTEP], lp, dp1, dp2);
200
201 /*
202 * remove values added by the last repeated
203 * dst port.
204 */
205 lp[0]--;
206 dlp = dst_port[j - 1];
207 } else {
208 /* set dlp and lp to the never used values. */
209 dlp = BAD_PORT - 1;
210 lp = pnum + MAX_PKT_BURST;
211 }
212
213 /* Process up to last 3 packets one by one. */
214 switch (nb_rx % FWDSTEP) {
215 case 3:
216 process_packet(pkts_burst[j], dst_port + j);
217 GROUP_PORT_STEP(dlp, dst_port, lp, pnum, j);
218 j++;
219 /* fall-through */
220 case 2:
221 process_packet(pkts_burst[j], dst_port + j);
222 GROUP_PORT_STEP(dlp, dst_port, lp, pnum, j);
223 j++;
224 /* fall-through */
225 case 1:
226 process_packet(pkts_burst[j], dst_port + j);
227 GROUP_PORT_STEP(dlp, dst_port, lp, pnum, j);
228 j++;
229 }
230
231 /*
232 * Send packets out, through destination port.
233 * Consecutive packets with the same destination port
234 * are already grouped together.
235 * If destination port for the packet equals BAD_PORT,
236 * then free the packet without sending it out.
237 */
238 for (j = 0; j < nb_rx; j += k) {
239
240 int32_t m;
241 uint16_t pn;
242
243 pn = dst_port[j];
244 k = pnum[j];
245
246 if (likely(pn != BAD_PORT))
247 send_packetsx4(qconf, pn, pkts_burst + j, k);
248 else
249 for (m = j; m != j + k; m++)
250 rte_pktmbuf_free(pkts_burst[m]);
251
252 }
253 }
254
255 #endif /* _L3FWD_ALTIVEC_H_ */