]>
git.proxmox.com Git - ceph.git/blob - 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.
7 #ifndef _L3FWD_ALTIVEC_H_
8 #define _L3FWD_ALTIVEC_H_
11 #include "l3fwd_common.h"
14 * Update source and destination MAC addresses in the ethernet header.
15 * Perform RFC1812 checks and updates for IPV4 packets.
18 processx4_step3(struct rte_mbuf
*pkt
[FWDSTEP
], uint16_t dst_port
[FWDSTEP
])
20 vector
unsigned int te
[FWDSTEP
];
21 vector
unsigned int ve
[FWDSTEP
];
22 vector
unsigned int *p
[FWDSTEP
];
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 *);
29 ve
[0] = (vector
unsigned int)val_eth
[dst_port
[0]];
32 ve
[1] = (vector
unsigned int)val_eth
[dst_port
[1]];
35 ve
[2] = (vector
unsigned int)val_eth
[dst_port
[2]];
38 ve
[3] = (vector
unsigned int)val_eth
[dst_port
[3]];
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});
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});
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,
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});
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
);
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.
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
)
94 uint16_t u16
[FWDSTEP
+ 1];
100 v
= vec_any_eq(dp1
, dp2
);
103 /* update last port counter. */
104 lp
[0] += gptbl
[v
].lpv
;
106 /* if dest port value has changed. */
108 pnum
->u64
= gptbl
[v
].pnum
;
109 pnum
->u16
[FWDSTEP
] = 1;
110 lp
= pnum
->u16
+ gptbl
[v
].idx
;
117 * Process one packet:
118 * Update source and destination MAC addresses in the ethernet header.
119 * Perform RFC1812 checks and updates for IPV4 packets.
122 process_packet(struct rte_mbuf
*pkt
, uint16_t *dst_port
)
124 struct ether_hdr
*eth_hdr
;
125 vector
unsigned int te
, ve
;
127 eth_hdr
= rte_pktmbuf_mtod(pkt
, struct ether_hdr
*);
129 te
= *(vector
unsigned int *)eth_hdr
;
130 ve
= (vector
unsigned int)val_eth
[dst_port
[0]];
132 rfc1812_process((struct ipv4_hdr
*)(eth_hdr
+ 1), dst_port
,
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});
142 *(vector
unsigned int *)eth_hdr
= te
;
146 * Send packets burst from pkts_burst to the ports in dst_port array
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
)
156 uint16_t pnum
[MAX_PKT_BURST
+ 1];
159 * Finish packet processing and group consecutive
160 * packets with the same destination port.
162 k
= RTE_ALIGN_FLOOR(nb_rx
, FWDSTEP
);
164 vector
unsigned short dp1
, dp2
;
169 processx4_step3(pkts_burst
, dst_port
);
171 /* dp1: <d[0], d[1], d[2], d[3], ... > */
172 dp1
= *(vector
unsigned short *)dst_port
;
174 for (j
= FWDSTEP
; j
!= k
; j
+= FWDSTEP
) {
175 processx4_step3(&pkts_burst
[j
], &dst_port
[j
]);
179 * <d[j-3], d[j-2], d[j-1], d[j], ... >
181 dp2
= *((vector
unsigned short *)
182 &dst_port
[j
- FWDSTEP
+ 1]);
183 lp
= port_groupx4(&pnum
[j
- FWDSTEP
], lp
, dp1
, dp2
);
187 * <d[j], d[j+1], d[j+2], d[j+3], ... >
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])});
195 * dp2: <d[j-3], d[j-2], d[j-1], d[j-1], ... >
197 dp2
= vec_perm(dp1
, (vector
unsigned short){},
198 (vector
unsigned char){0xf9});
199 lp
= port_groupx4(&pnum
[j
- FWDSTEP
], lp
, dp1
, dp2
);
202 * remove values added by the last repeated
206 dlp
= dst_port
[j
- 1];
208 /* set dlp and lp to the never used values. */
210 lp
= pnum
+ MAX_PKT_BURST
;
213 /* Process up to last 3 packets one by one. */
214 switch (nb_rx
% FWDSTEP
) {
216 process_packet(pkts_burst
[j
], dst_port
+ j
);
217 GROUP_PORT_STEP(dlp
, dst_port
, lp
, pnum
, j
);
221 process_packet(pkts_burst
[j
], dst_port
+ j
);
222 GROUP_PORT_STEP(dlp
, dst_port
, lp
, pnum
, j
);
226 process_packet(pkts_burst
[j
], dst_port
+ j
);
227 GROUP_PORT_STEP(dlp
, dst_port
, lp
, pnum
, j
);
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.
238 for (j
= 0; j
< nb_rx
; j
+= k
) {
246 if (likely(pn
!= BAD_PORT
))
247 send_packetsx4(qconf
, pn
, pkts_burst
+ j
, k
);
249 for (m
= j
; m
!= j
+ k
; m
++)
250 rte_pktmbuf_free(pkts_burst
[m
]);
255 #endif /* _L3FWD_ALTIVEC_H_ */