]>
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 rte_ipv4_hdr
*)
72 ((struct rte_ether_hdr
*)p
[0] + 1),
73 &dst_port
[0], pkt
[0]->packet_type
);
74 rfc1812_process((struct rte_ipv4_hdr
*)
75 ((struct rte_ether_hdr
*)p
[1] + 1),
76 &dst_port
[1], pkt
[1]->packet_type
);
77 rfc1812_process((struct rte_ipv4_hdr
*)
78 ((struct rte_ether_hdr
*)p
[2] + 1),
79 &dst_port
[2], pkt
[2]->packet_type
);
80 rfc1812_process((struct rte_ipv4_hdr
*)
81 ((struct rte_ether_hdr
*)p
[3] + 1),
82 &dst_port
[3], pkt
[3]->packet_type
);
86 * Group consecutive packets with the same destination port in bursts of 4.
87 * Suppose we have array of destination ports:
88 * dst_port[] = {a, b, c, d,, e, ... }
89 * dp1 should contain: <a, b, c, d>, dp2: <b, c, d, e>.
90 * We doing 4 comparisons at once and the result is 4 bit mask.
91 * This mask is used as an index into prebuild array of pnum values.
93 static inline uint16_t *
94 port_groupx4(uint16_t pn
[FWDSTEP
+ 1], uint16_t *lp
, vector
unsigned short dp1
,
95 vector
unsigned short dp2
)
98 uint16_t u16
[FWDSTEP
+ 1];
100 } *pnum
= (void *)pn
;
104 v
= vec_any_eq(dp1
, dp2
);
107 /* update last port counter. */
108 lp
[0] += gptbl
[v
].lpv
;
110 /* if dest port value has changed. */
112 pnum
->u64
= gptbl
[v
].pnum
;
113 pnum
->u16
[FWDSTEP
] = 1;
114 lp
= pnum
->u16
+ gptbl
[v
].idx
;
121 * Process one packet:
122 * Update source and destination MAC addresses in the ethernet header.
123 * Perform RFC1812 checks and updates for IPV4 packets.
126 process_packet(struct rte_mbuf
*pkt
, uint16_t *dst_port
)
128 struct rte_ether_hdr
*eth_hdr
;
129 vector
unsigned int te
, ve
;
131 eth_hdr
= rte_pktmbuf_mtod(pkt
, struct rte_ether_hdr
*);
133 te
= *(vector
unsigned int *)eth_hdr
;
134 ve
= (vector
unsigned int)val_eth
[dst_port
[0]];
136 rfc1812_process((struct rte_ipv4_hdr
*)(eth_hdr
+ 1), dst_port
,
139 /* dynamically vec_sel te and ve for MASK_ETH (0x3f) */
140 te
= (vector
unsigned int)vec_sel(
141 (vector
unsigned short)ve
,
142 (vector
unsigned short)te
,
143 (vector
unsigned short){0, 0, 0, 0,
144 0, 0, 0xffff, 0xffff});
146 *(vector
unsigned int *)eth_hdr
= te
;
150 * Send packets burst from pkts_burst to the ports in dst_port array
152 static __rte_always_inline
void
153 send_packets_multi(struct lcore_conf
*qconf
, struct rte_mbuf
**pkts_burst
,
154 uint16_t dst_port
[MAX_PKT_BURST
], int nb_rx
)
160 uint16_t pnum
[MAX_PKT_BURST
+ 1];
163 * Finish packet processing and group consecutive
164 * packets with the same destination port.
166 k
= RTE_ALIGN_FLOOR(nb_rx
, FWDSTEP
);
168 vector
unsigned short dp1
, dp2
;
173 processx4_step3(pkts_burst
, dst_port
);
175 /* dp1: <d[0], d[1], d[2], d[3], ... > */
176 dp1
= *(vector
unsigned short *)dst_port
;
178 for (j
= FWDSTEP
; j
!= k
; j
+= FWDSTEP
) {
179 processx4_step3(&pkts_burst
[j
], &dst_port
[j
]);
183 * <d[j-3], d[j-2], d[j-1], d[j], ... >
185 dp2
= *((vector
unsigned short *)
186 &dst_port
[j
- FWDSTEP
+ 1]);
187 lp
= port_groupx4(&pnum
[j
- FWDSTEP
], lp
, dp1
, dp2
);
191 * <d[j], d[j+1], d[j+2], d[j+3], ... >
193 dp1
= vec_sro(dp2
, (vector
unsigned char) {
194 0, 0, 0, 0, 0, 0, 0, 0,
195 0, 0, 0, (FWDSTEP
- 1) * sizeof(dst_port
[0])});
199 * dp2: <d[j-3], d[j-2], d[j-1], d[j-1], ... >
201 dp2
= vec_perm(dp1
, (vector
unsigned short){},
202 (vector
unsigned char){0xf9});
203 lp
= port_groupx4(&pnum
[j
- FWDSTEP
], lp
, dp1
, dp2
);
206 * remove values added by the last repeated
210 dlp
= dst_port
[j
- 1];
212 /* set dlp and lp to the never used values. */
214 lp
= pnum
+ MAX_PKT_BURST
;
217 /* Process up to last 3 packets one by one. */
218 switch (nb_rx
% FWDSTEP
) {
220 process_packet(pkts_burst
[j
], dst_port
+ j
);
221 GROUP_PORT_STEP(dlp
, dst_port
, lp
, pnum
, j
);
225 process_packet(pkts_burst
[j
], dst_port
+ j
);
226 GROUP_PORT_STEP(dlp
, dst_port
, lp
, pnum
, j
);
230 process_packet(pkts_burst
[j
], dst_port
+ j
);
231 GROUP_PORT_STEP(dlp
, dst_port
, lp
, pnum
, j
);
236 * Send packets out, through destination port.
237 * Consecutive packets with the same destination port
238 * are already grouped together.
239 * If destination port for the packet equals BAD_PORT,
240 * then free the packet without sending it out.
242 for (j
= 0; j
< nb_rx
; j
+= k
) {
250 if (likely(pn
!= BAD_PORT
))
251 send_packetsx4(qconf
, pn
, pkts_burst
+ j
, k
);
253 for (m
= j
; m
!= j
+ k
; m
++)
254 rte_pktmbuf_free(pkts_burst
[m
]);
259 #endif /* _L3FWD_ALTIVEC_H_ */