1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
5 #include "ice_rxtx_vec_common.h"
9 #ifndef __INTEL_COMPILER
10 #pragma GCC diagnostic ignored "-Wcast-qual"
13 static __rte_always_inline void
14 ice_rxq_rearm(struct ice_rx_queue *rxq)
16 return ice_rxq_rearm_common(rxq, false);
19 static __rte_always_inline __m256i
20 ice_flex_rxd_to_fdir_flags_vec_avx2(const __m256i fdir_id0_7)
22 #define FDID_MIS_MAGIC 0xFFFFFFFF
23 RTE_BUILD_BUG_ON(PKT_RX_FDIR != (1 << 2));
24 RTE_BUILD_BUG_ON(PKT_RX_FDIR_ID != (1 << 13));
25 const __m256i pkt_fdir_bit = _mm256_set1_epi32(PKT_RX_FDIR |
27 /* desc->flow_id field == 0xFFFFFFFF means fdir mismatch */
28 const __m256i fdir_mis_mask = _mm256_set1_epi32(FDID_MIS_MAGIC);
29 __m256i fdir_mask = _mm256_cmpeq_epi32(fdir_id0_7,
31 /* this XOR op results to bit-reverse the fdir_mask */
32 fdir_mask = _mm256_xor_si256(fdir_mask, fdir_mis_mask);
33 const __m256i fdir_flags = _mm256_and_si256(fdir_mask, pkt_fdir_bit);
38 static __rte_always_inline uint16_t
39 _ice_recv_raw_pkts_vec_avx2(struct ice_rx_queue *rxq, struct rte_mbuf **rx_pkts,
40 uint16_t nb_pkts, uint8_t *split_packet,
43 #define ICE_DESCS_PER_LOOP_AVX 8
45 const uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
46 const __m256i mbuf_init = _mm256_set_epi64x(0, 0,
47 0, rxq->mbuf_initializer);
48 struct ice_rx_entry *sw_ring = &rxq->sw_ring[rxq->rx_tail];
49 volatile union ice_rx_flex_desc *rxdp = rxq->rx_ring + rxq->rx_tail;
50 const int avx_aligned = ((rxq->rx_tail & 1) == 0);
54 /* nb_pkts has to be floor-aligned to ICE_DESCS_PER_LOOP_AVX */
55 nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, ICE_DESCS_PER_LOOP_AVX);
57 /* See if we need to rearm the RX queue - gives the prefetch a bit
60 if (rxq->rxrearm_nb > ICE_RXQ_REARM_THRESH)
63 /* Before we start moving massive data around, check to see if
64 * there is actually a packet available
66 if (!(rxdp->wb.status_error0 &
67 rte_cpu_to_le_32(1 << ICE_RX_FLEX_DESC_STATUS0_DD_S)))
70 /* constants used in processing loop */
71 const __m256i crc_adjust =
73 (/* first descriptor */
74 0, 0, 0, /* ignore non-length fields */
75 -rxq->crc_len, /* sub crc on data_len */
76 0, /* ignore high-16bits of pkt_len */
77 -rxq->crc_len, /* sub crc on pkt_len */
78 0, 0, /* ignore pkt_type field */
79 /* second descriptor */
80 0, 0, 0, /* ignore non-length fields */
81 -rxq->crc_len, /* sub crc on data_len */
82 0, /* ignore high-16bits of pkt_len */
83 -rxq->crc_len, /* sub crc on pkt_len */
84 0, 0 /* ignore pkt_type field */
87 /* 8 packets DD mask, LSB in each 32-bit value */
88 const __m256i dd_check = _mm256_set1_epi32(1);
90 /* 8 packets EOP mask, second-LSB in each 32-bit value */
91 const __m256i eop_check = _mm256_slli_epi32(dd_check,
92 ICE_RX_DESC_STATUS_EOF_S);
94 /* mask to shuffle from desc. to mbuf (2 descriptors)*/
95 const __m256i shuf_msk =
97 (/* first descriptor */
99 0xFF, 0xFF, /* rss hash parsed separately */
100 11, 10, /* octet 10~11, 16 bits vlan_macip */
101 5, 4, /* octet 4~5, 16 bits data_len */
102 0xFF, 0xFF, /* skip hi 16 bits pkt_len, zero out */
103 5, 4, /* octet 4~5, 16 bits pkt_len */
104 0xFF, 0xFF, /* pkt_type set as unknown */
105 0xFF, 0xFF, /*pkt_type set as unknown */
106 /* second descriptor */
108 0xFF, 0xFF, /* rss hash parsed separately */
109 11, 10, /* octet 10~11, 16 bits vlan_macip */
110 5, 4, /* octet 4~5, 16 bits data_len */
111 0xFF, 0xFF, /* skip hi 16 bits pkt_len, zero out */
112 5, 4, /* octet 4~5, 16 bits pkt_len */
113 0xFF, 0xFF, /* pkt_type set as unknown */
114 0xFF, 0xFF /*pkt_type set as unknown */
117 * compile-time check the above crc and shuffle layout is correct.
118 * NOTE: the first field (lowest address) is given last in set_epi
121 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
122 offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
123 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_len) !=
124 offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
125 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, vlan_tci) !=
126 offsetof(struct rte_mbuf, rx_descriptor_fields1) + 10);
127 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, hash) !=
128 offsetof(struct rte_mbuf, rx_descriptor_fields1) + 12);
130 /* Status/Error flag masks */
132 * mask everything except Checksum Reports, RSS indication
133 * and VLAN indication.
134 * bit6:4 for IP/L4 checksum errors.
135 * bit12 is for RSS indication.
136 * bit13 is for VLAN indication.
138 const __m256i flags_mask =
139 _mm256_set1_epi32((0xF << 4) | (1 << 12) | (1 << 13));
141 * data to be shuffled by the result of the flags mask shifted by 4
142 * bits. This gives use the l3_l4 flags.
144 const __m256i l3_l4_flags_shuf =
145 _mm256_set_epi8((PKT_RX_OUTER_L4_CKSUM_BAD >> 20 |
146 PKT_RX_OUTER_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD |
147 PKT_RX_IP_CKSUM_BAD) >> 1,
148 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
149 PKT_RX_L4_CKSUM_BAD | PKT_RX_IP_CKSUM_GOOD) >> 1,
150 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
151 PKT_RX_L4_CKSUM_GOOD | PKT_RX_IP_CKSUM_BAD) >> 1,
152 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
153 PKT_RX_L4_CKSUM_GOOD | PKT_RX_IP_CKSUM_GOOD) >> 1,
154 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_L4_CKSUM_BAD |
155 PKT_RX_IP_CKSUM_BAD) >> 1,
156 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_L4_CKSUM_BAD |
157 PKT_RX_IP_CKSUM_GOOD) >> 1,
158 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_L4_CKSUM_GOOD |
159 PKT_RX_IP_CKSUM_BAD) >> 1,
160 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_L4_CKSUM_GOOD |
161 PKT_RX_IP_CKSUM_GOOD) >> 1,
162 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
163 PKT_RX_L4_CKSUM_BAD | PKT_RX_IP_CKSUM_BAD) >> 1,
164 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
165 PKT_RX_L4_CKSUM_BAD | PKT_RX_IP_CKSUM_GOOD) >> 1,
166 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
167 PKT_RX_L4_CKSUM_GOOD | PKT_RX_IP_CKSUM_BAD) >> 1,
168 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
169 PKT_RX_L4_CKSUM_GOOD | PKT_RX_IP_CKSUM_GOOD) >> 1,
170 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_L4_CKSUM_BAD |
171 PKT_RX_IP_CKSUM_BAD) >> 1,
172 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_L4_CKSUM_BAD |
173 PKT_RX_IP_CKSUM_GOOD) >> 1,
174 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_L4_CKSUM_GOOD |
175 PKT_RX_IP_CKSUM_BAD) >> 1,
176 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_L4_CKSUM_GOOD |
177 PKT_RX_IP_CKSUM_GOOD) >> 1,
180 * shift right 20 bits to use the low two bits to indicate
181 * outer checksum status
182 * shift right 1 bit to make sure it not exceed 255
184 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
185 PKT_RX_L4_CKSUM_BAD | PKT_RX_IP_CKSUM_BAD) >> 1,
186 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
187 PKT_RX_L4_CKSUM_BAD | PKT_RX_IP_CKSUM_GOOD) >> 1,
188 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
189 PKT_RX_L4_CKSUM_GOOD | PKT_RX_IP_CKSUM_BAD) >> 1,
190 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
191 PKT_RX_L4_CKSUM_GOOD | PKT_RX_IP_CKSUM_GOOD) >> 1,
192 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_L4_CKSUM_BAD |
193 PKT_RX_IP_CKSUM_BAD) >> 1,
194 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_L4_CKSUM_BAD |
195 PKT_RX_IP_CKSUM_GOOD) >> 1,
196 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_L4_CKSUM_GOOD |
197 PKT_RX_IP_CKSUM_BAD) >> 1,
198 (PKT_RX_OUTER_L4_CKSUM_BAD >> 20 | PKT_RX_L4_CKSUM_GOOD |
199 PKT_RX_IP_CKSUM_GOOD) >> 1,
200 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
201 PKT_RX_L4_CKSUM_BAD | PKT_RX_IP_CKSUM_BAD) >> 1,
202 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
203 PKT_RX_L4_CKSUM_BAD | PKT_RX_IP_CKSUM_GOOD) >> 1,
204 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
205 PKT_RX_L4_CKSUM_GOOD | PKT_RX_IP_CKSUM_BAD) >> 1,
206 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_OUTER_IP_CKSUM_BAD |
207 PKT_RX_L4_CKSUM_GOOD | PKT_RX_IP_CKSUM_GOOD) >> 1,
208 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_L4_CKSUM_BAD |
209 PKT_RX_IP_CKSUM_BAD) >> 1,
210 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_L4_CKSUM_BAD |
211 PKT_RX_IP_CKSUM_GOOD) >> 1,
212 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_L4_CKSUM_GOOD |
213 PKT_RX_IP_CKSUM_BAD) >> 1,
214 (PKT_RX_OUTER_L4_CKSUM_GOOD >> 20 | PKT_RX_L4_CKSUM_GOOD |
215 PKT_RX_IP_CKSUM_GOOD) >> 1);
216 const __m256i cksum_mask =
217 _mm256_set1_epi32(PKT_RX_IP_CKSUM_MASK |
218 PKT_RX_L4_CKSUM_MASK |
219 PKT_RX_OUTER_IP_CKSUM_BAD |
220 PKT_RX_OUTER_L4_CKSUM_MASK);
222 * data to be shuffled by result of flag mask, shifted down 12.
223 * If RSS(bit12)/VLAN(bit13) are set,
224 * shuffle moves appropriate flags in place.
226 const __m256i rss_vlan_flags_shuf = _mm256_set_epi8(0, 0, 0, 0,
229 PKT_RX_RSS_HASH | PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
230 PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
232 /* end up 128-bits */
236 PKT_RX_RSS_HASH | PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
237 PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
240 RTE_SET_USED(avx_aligned); /* for 32B descriptors we don't use this */
242 uint16_t i, received;
244 for (i = 0, received = 0; i < nb_pkts;
245 i += ICE_DESCS_PER_LOOP_AVX,
246 rxdp += ICE_DESCS_PER_LOOP_AVX) {
247 /* step 1, copy over 8 mbuf pointers to rx_pkts array */
248 _mm256_storeu_si256((void *)&rx_pkts[i],
249 _mm256_loadu_si256((void *)&sw_ring[i]));
250 #ifdef RTE_ARCH_X86_64
252 ((void *)&rx_pkts[i + 4],
253 _mm256_loadu_si256((void *)&sw_ring[i + 4]));
256 __m256i raw_desc0_1, raw_desc2_3, raw_desc4_5, raw_desc6_7;
257 #ifdef RTE_LIBRTE_ICE_16BYTE_RX_DESC
258 /* for AVX we need alignment otherwise loads are not atomic */
260 /* load in descriptors, 2 at a time, in reverse order */
261 raw_desc6_7 = _mm256_load_si256((void *)(rxdp + 6));
262 rte_compiler_barrier();
263 raw_desc4_5 = _mm256_load_si256((void *)(rxdp + 4));
264 rte_compiler_barrier();
265 raw_desc2_3 = _mm256_load_si256((void *)(rxdp + 2));
266 rte_compiler_barrier();
267 raw_desc0_1 = _mm256_load_si256((void *)(rxdp + 0));
271 const __m128i raw_desc7 =
272 _mm_load_si128((void *)(rxdp + 7));
273 rte_compiler_barrier();
274 const __m128i raw_desc6 =
275 _mm_load_si128((void *)(rxdp + 6));
276 rte_compiler_barrier();
277 const __m128i raw_desc5 =
278 _mm_load_si128((void *)(rxdp + 5));
279 rte_compiler_barrier();
280 const __m128i raw_desc4 =
281 _mm_load_si128((void *)(rxdp + 4));
282 rte_compiler_barrier();
283 const __m128i raw_desc3 =
284 _mm_load_si128((void *)(rxdp + 3));
285 rte_compiler_barrier();
286 const __m128i raw_desc2 =
287 _mm_load_si128((void *)(rxdp + 2));
288 rte_compiler_barrier();
289 const __m128i raw_desc1 =
290 _mm_load_si128((void *)(rxdp + 1));
291 rte_compiler_barrier();
292 const __m128i raw_desc0 =
293 _mm_load_si128((void *)(rxdp + 0));
296 _mm256_inserti128_si256
297 (_mm256_castsi128_si256(raw_desc6),
300 _mm256_inserti128_si256
301 (_mm256_castsi128_si256(raw_desc4),
304 _mm256_inserti128_si256
305 (_mm256_castsi128_si256(raw_desc2),
308 _mm256_inserti128_si256
309 (_mm256_castsi128_si256(raw_desc0),
316 for (j = 0; j < ICE_DESCS_PER_LOOP_AVX; j++)
317 rte_mbuf_prefetch_part2(rx_pkts[i + j]);
321 * convert descriptors 4-7 into mbufs, re-arrange fields.
322 * Then write into the mbuf.
324 __m256i mb6_7 = _mm256_shuffle_epi8(raw_desc6_7, shuf_msk);
325 __m256i mb4_5 = _mm256_shuffle_epi8(raw_desc4_5, shuf_msk);
327 mb6_7 = _mm256_add_epi16(mb6_7, crc_adjust);
328 mb4_5 = _mm256_add_epi16(mb4_5, crc_adjust);
330 * to get packet types, ptype is located in bit16-25
333 const __m256i ptype_mask =
334 _mm256_set1_epi16(ICE_RX_FLEX_DESC_PTYPE_M);
335 const __m256i ptypes6_7 =
336 _mm256_and_si256(raw_desc6_7, ptype_mask);
337 const __m256i ptypes4_5 =
338 _mm256_and_si256(raw_desc4_5, ptype_mask);
339 const uint16_t ptype7 = _mm256_extract_epi16(ptypes6_7, 9);
340 const uint16_t ptype6 = _mm256_extract_epi16(ptypes6_7, 1);
341 const uint16_t ptype5 = _mm256_extract_epi16(ptypes4_5, 9);
342 const uint16_t ptype4 = _mm256_extract_epi16(ptypes4_5, 1);
344 mb6_7 = _mm256_insert_epi32(mb6_7, ptype_tbl[ptype7], 4);
345 mb6_7 = _mm256_insert_epi32(mb6_7, ptype_tbl[ptype6], 0);
346 mb4_5 = _mm256_insert_epi32(mb4_5, ptype_tbl[ptype5], 4);
347 mb4_5 = _mm256_insert_epi32(mb4_5, ptype_tbl[ptype4], 0);
348 /* merge the status bits into one register */
349 const __m256i status4_7 = _mm256_unpackhi_epi32(raw_desc6_7,
353 * convert descriptors 0-3 into mbufs, re-arrange fields.
354 * Then write into the mbuf.
356 __m256i mb2_3 = _mm256_shuffle_epi8(raw_desc2_3, shuf_msk);
357 __m256i mb0_1 = _mm256_shuffle_epi8(raw_desc0_1, shuf_msk);
359 mb2_3 = _mm256_add_epi16(mb2_3, crc_adjust);
360 mb0_1 = _mm256_add_epi16(mb0_1, crc_adjust);
362 * to get packet types, ptype is located in bit16-25
365 const __m256i ptypes2_3 =
366 _mm256_and_si256(raw_desc2_3, ptype_mask);
367 const __m256i ptypes0_1 =
368 _mm256_and_si256(raw_desc0_1, ptype_mask);
369 const uint16_t ptype3 = _mm256_extract_epi16(ptypes2_3, 9);
370 const uint16_t ptype2 = _mm256_extract_epi16(ptypes2_3, 1);
371 const uint16_t ptype1 = _mm256_extract_epi16(ptypes0_1, 9);
372 const uint16_t ptype0 = _mm256_extract_epi16(ptypes0_1, 1);
374 mb2_3 = _mm256_insert_epi32(mb2_3, ptype_tbl[ptype3], 4);
375 mb2_3 = _mm256_insert_epi32(mb2_3, ptype_tbl[ptype2], 0);
376 mb0_1 = _mm256_insert_epi32(mb0_1, ptype_tbl[ptype1], 4);
377 mb0_1 = _mm256_insert_epi32(mb0_1, ptype_tbl[ptype0], 0);
378 /* merge the status bits into one register */
379 const __m256i status0_3 = _mm256_unpackhi_epi32(raw_desc2_3,
383 * take the two sets of status bits and merge to one
384 * After merge, the packets status flags are in the
385 * order (hi->lo): [1, 3, 5, 7, 0, 2, 4, 6]
387 __m256i status0_7 = _mm256_unpacklo_epi64(status4_7,
389 __m256i mbuf_flags = _mm256_set1_epi32(0);
392 /* now do flag manipulation */
394 /* get only flag/error bits we want */
395 const __m256i flag_bits =
396 _mm256_and_si256(status0_7, flags_mask);
398 * l3_l4_error flags, shuffle, then shift to correct adjustment
399 * of flags in flags_shuf, and finally mask out extra bits
401 __m256i l3_l4_flags = _mm256_shuffle_epi8(l3_l4_flags_shuf,
402 _mm256_srli_epi32(flag_bits, 4));
403 l3_l4_flags = _mm256_slli_epi32(l3_l4_flags, 1);
405 __m256i l4_outer_mask = _mm256_set1_epi32(0x6);
406 __m256i l4_outer_flags =
407 _mm256_and_si256(l3_l4_flags, l4_outer_mask);
408 l4_outer_flags = _mm256_slli_epi32(l4_outer_flags, 20);
410 __m256i l3_l4_mask = _mm256_set1_epi32(~0x6);
412 l3_l4_flags = _mm256_and_si256(l3_l4_flags, l3_l4_mask);
413 l3_l4_flags = _mm256_or_si256(l3_l4_flags, l4_outer_flags);
414 l3_l4_flags = _mm256_and_si256(l3_l4_flags, cksum_mask);
415 /* set rss and vlan flags */
416 const __m256i rss_vlan_flag_bits =
417 _mm256_srli_epi32(flag_bits, 12);
418 const __m256i rss_vlan_flags =
419 _mm256_shuffle_epi8(rss_vlan_flags_shuf,
423 mbuf_flags = _mm256_or_si256(l3_l4_flags,
427 if (rxq->fdir_enabled) {
428 const __m256i fdir_id4_7 =
429 _mm256_unpackhi_epi32(raw_desc6_7, raw_desc4_5);
431 const __m256i fdir_id0_3 =
432 _mm256_unpackhi_epi32(raw_desc2_3, raw_desc0_1);
434 const __m256i fdir_id0_7 =
435 _mm256_unpackhi_epi64(fdir_id4_7, fdir_id0_3);
437 const __m256i fdir_flags =
438 ice_flex_rxd_to_fdir_flags_vec_avx2(fdir_id0_7);
440 /* merge with fdir_flags */
441 mbuf_flags = _mm256_or_si256(mbuf_flags, fdir_flags);
443 /* write to mbuf: have to use scalar store here */
444 rx_pkts[i + 0]->hash.fdir.hi =
445 _mm256_extract_epi32(fdir_id0_7, 3);
447 rx_pkts[i + 1]->hash.fdir.hi =
448 _mm256_extract_epi32(fdir_id0_7, 7);
450 rx_pkts[i + 2]->hash.fdir.hi =
451 _mm256_extract_epi32(fdir_id0_7, 2);
453 rx_pkts[i + 3]->hash.fdir.hi =
454 _mm256_extract_epi32(fdir_id0_7, 6);
456 rx_pkts[i + 4]->hash.fdir.hi =
457 _mm256_extract_epi32(fdir_id0_7, 1);
459 rx_pkts[i + 5]->hash.fdir.hi =
460 _mm256_extract_epi32(fdir_id0_7, 5);
462 rx_pkts[i + 6]->hash.fdir.hi =
463 _mm256_extract_epi32(fdir_id0_7, 0);
465 rx_pkts[i + 7]->hash.fdir.hi =
466 _mm256_extract_epi32(fdir_id0_7, 4);
467 } /* if() on fdir_enabled */
470 #ifndef RTE_LIBRTE_ICE_16BYTE_RX_DESC
472 * needs to load 2nd 16B of each desc for RSS hash parsing,
473 * will cause performance drop to get into this context.
475 if (rxq->vsi->adapter->pf.dev_data->dev_conf.rxmode.offloads &
476 DEV_RX_OFFLOAD_RSS_HASH) {
477 /* load bottom half of every 32B desc */
478 const __m128i raw_desc_bh7 =
480 ((void *)(&rxdp[7].wb.status_error1));
481 rte_compiler_barrier();
482 const __m128i raw_desc_bh6 =
484 ((void *)(&rxdp[6].wb.status_error1));
485 rte_compiler_barrier();
486 const __m128i raw_desc_bh5 =
488 ((void *)(&rxdp[5].wb.status_error1));
489 rte_compiler_barrier();
490 const __m128i raw_desc_bh4 =
492 ((void *)(&rxdp[4].wb.status_error1));
493 rte_compiler_barrier();
494 const __m128i raw_desc_bh3 =
496 ((void *)(&rxdp[3].wb.status_error1));
497 rte_compiler_barrier();
498 const __m128i raw_desc_bh2 =
500 ((void *)(&rxdp[2].wb.status_error1));
501 rte_compiler_barrier();
502 const __m128i raw_desc_bh1 =
504 ((void *)(&rxdp[1].wb.status_error1));
505 rte_compiler_barrier();
506 const __m128i raw_desc_bh0 =
508 ((void *)(&rxdp[0].wb.status_error1));
510 __m256i raw_desc_bh6_7 =
511 _mm256_inserti128_si256
512 (_mm256_castsi128_si256(raw_desc_bh6),
514 __m256i raw_desc_bh4_5 =
515 _mm256_inserti128_si256
516 (_mm256_castsi128_si256(raw_desc_bh4),
518 __m256i raw_desc_bh2_3 =
519 _mm256_inserti128_si256
520 (_mm256_castsi128_si256(raw_desc_bh2),
522 __m256i raw_desc_bh0_1 =
523 _mm256_inserti128_si256
524 (_mm256_castsi128_si256(raw_desc_bh0),
528 * to shift the 32b RSS hash value to the
529 * highest 32b of each 128b before mask
531 __m256i rss_hash6_7 =
532 _mm256_slli_epi64(raw_desc_bh6_7, 32);
533 __m256i rss_hash4_5 =
534 _mm256_slli_epi64(raw_desc_bh4_5, 32);
535 __m256i rss_hash2_3 =
536 _mm256_slli_epi64(raw_desc_bh2_3, 32);
537 __m256i rss_hash0_1 =
538 _mm256_slli_epi64(raw_desc_bh0_1, 32);
540 __m256i rss_hash_msk =
541 _mm256_set_epi32(0xFFFFFFFF, 0, 0, 0,
542 0xFFFFFFFF, 0, 0, 0);
544 rss_hash6_7 = _mm256_and_si256
545 (rss_hash6_7, rss_hash_msk);
546 rss_hash4_5 = _mm256_and_si256
547 (rss_hash4_5, rss_hash_msk);
548 rss_hash2_3 = _mm256_and_si256
549 (rss_hash2_3, rss_hash_msk);
550 rss_hash0_1 = _mm256_and_si256
551 (rss_hash0_1, rss_hash_msk);
553 mb6_7 = _mm256_or_si256(mb6_7, rss_hash6_7);
554 mb4_5 = _mm256_or_si256(mb4_5, rss_hash4_5);
555 mb2_3 = _mm256_or_si256(mb2_3, rss_hash2_3);
556 mb0_1 = _mm256_or_si256(mb0_1, rss_hash0_1);
557 } /* if() on RSS hash parsing */
562 * At this point, we have the 8 sets of flags in the low 16-bits
563 * of each 32-bit value in vlan0.
564 * We want to extract these, and merge them with the mbuf init
565 * data so we can do a single write to the mbuf to set the flags
566 * and all the other initialization fields. Extracting the
567 * appropriate flags means that we have to do a shift and blend
568 * for each mbuf before we do the write. However, we can also
569 * add in the previously computed rx_descriptor fields to
570 * make a single 256-bit write per mbuf
572 /* check the structure matches expectations */
573 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, ol_flags) !=
574 offsetof(struct rte_mbuf, rearm_data) + 8);
575 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, rearm_data) !=
576 RTE_ALIGN(offsetof(struct rte_mbuf,
579 /* build up data and do writes */
580 __m256i rearm0, rearm1, rearm2, rearm3, rearm4, rearm5,
582 rearm6 = _mm256_blend_epi32(mbuf_init,
583 _mm256_slli_si256(mbuf_flags, 8),
585 rearm4 = _mm256_blend_epi32(mbuf_init,
586 _mm256_slli_si256(mbuf_flags, 4),
588 rearm2 = _mm256_blend_epi32(mbuf_init, mbuf_flags, 0x04);
589 rearm0 = _mm256_blend_epi32(mbuf_init,
590 _mm256_srli_si256(mbuf_flags, 4),
592 /* permute to add in the rx_descriptor e.g. rss fields */
593 rearm6 = _mm256_permute2f128_si256(rearm6, mb6_7, 0x20);
594 rearm4 = _mm256_permute2f128_si256(rearm4, mb4_5, 0x20);
595 rearm2 = _mm256_permute2f128_si256(rearm2, mb2_3, 0x20);
596 rearm0 = _mm256_permute2f128_si256(rearm0, mb0_1, 0x20);
598 _mm256_storeu_si256((__m256i *)&rx_pkts[i + 6]->rearm_data,
600 _mm256_storeu_si256((__m256i *)&rx_pkts[i + 4]->rearm_data,
602 _mm256_storeu_si256((__m256i *)&rx_pkts[i + 2]->rearm_data,
604 _mm256_storeu_si256((__m256i *)&rx_pkts[i + 0]->rearm_data,
607 /* repeat for the odd mbufs */
608 const __m256i odd_flags =
609 _mm256_castsi128_si256
610 (_mm256_extracti128_si256(mbuf_flags, 1));
611 rearm7 = _mm256_blend_epi32(mbuf_init,
612 _mm256_slli_si256(odd_flags, 8),
614 rearm5 = _mm256_blend_epi32(mbuf_init,
615 _mm256_slli_si256(odd_flags, 4),
617 rearm3 = _mm256_blend_epi32(mbuf_init, odd_flags, 0x04);
618 rearm1 = _mm256_blend_epi32(mbuf_init,
619 _mm256_srli_si256(odd_flags, 4),
621 /* since odd mbufs are already in hi 128-bits use blend */
622 rearm7 = _mm256_blend_epi32(rearm7, mb6_7, 0xF0);
623 rearm5 = _mm256_blend_epi32(rearm5, mb4_5, 0xF0);
624 rearm3 = _mm256_blend_epi32(rearm3, mb2_3, 0xF0);
625 rearm1 = _mm256_blend_epi32(rearm1, mb0_1, 0xF0);
626 /* again write to mbufs */
627 _mm256_storeu_si256((__m256i *)&rx_pkts[i + 7]->rearm_data,
629 _mm256_storeu_si256((__m256i *)&rx_pkts[i + 5]->rearm_data,
631 _mm256_storeu_si256((__m256i *)&rx_pkts[i + 3]->rearm_data,
633 _mm256_storeu_si256((__m256i *)&rx_pkts[i + 1]->rearm_data,
636 /* extract and record EOP bit */
638 const __m128i eop_mask =
639 _mm_set1_epi16(1 << ICE_RX_DESC_STATUS_EOF_S);
640 const __m256i eop_bits256 = _mm256_and_si256(status0_7,
642 /* pack status bits into a single 128-bit register */
643 const __m128i eop_bits =
645 (_mm256_castsi256_si128(eop_bits256),
646 _mm256_extractf128_si256(eop_bits256,
649 * flip bits, and mask out the EOP bit, which is now
650 * a split-packet bit i.e. !EOP, rather than EOP one.
652 __m128i split_bits = _mm_andnot_si128(eop_bits,
655 * eop bits are out of order, so we need to shuffle them
656 * back into order again. In doing so, only use low 8
657 * bits, which acts like another pack instruction
658 * The original order is (hi->lo): 1,3,5,7,0,2,4,6
659 * [Since we use epi8, the 16-bit positions are
660 * multiplied by 2 in the eop_shuffle value.]
662 __m128i eop_shuffle =
663 _mm_set_epi8(/* zero hi 64b */
664 0xFF, 0xFF, 0xFF, 0xFF,
665 0xFF, 0xFF, 0xFF, 0xFF,
666 /* move values to lo 64b */
669 split_bits = _mm_shuffle_epi8(split_bits, eop_shuffle);
670 *(uint64_t *)split_packet =
671 _mm_cvtsi128_si64(split_bits);
672 split_packet += ICE_DESCS_PER_LOOP_AVX;
675 /* perform dd_check */
676 status0_7 = _mm256_and_si256(status0_7, dd_check);
677 status0_7 = _mm256_packs_epi32(status0_7,
678 _mm256_setzero_si256());
680 uint64_t burst = __builtin_popcountll
682 (_mm256_extracti128_si256
684 burst += __builtin_popcountll
686 (_mm256_castsi256_si128(status0_7)));
688 if (burst != ICE_DESCS_PER_LOOP_AVX)
692 /* update tail pointers */
693 rxq->rx_tail += received;
694 rxq->rx_tail &= (rxq->nb_rx_desc - 1);
695 if ((rxq->rx_tail & 1) == 1 && received > 1) { /* keep avx2 aligned */
699 rxq->rxrearm_nb += received;
705 * - nb_pkts < ICE_DESCS_PER_LOOP, just return no packet
708 ice_recv_pkts_vec_avx2(void *rx_queue, struct rte_mbuf **rx_pkts,
711 return _ice_recv_raw_pkts_vec_avx2(rx_queue, rx_pkts,
712 nb_pkts, NULL, false);
716 ice_recv_pkts_vec_avx2_offload(void *rx_queue, struct rte_mbuf **rx_pkts,
719 return _ice_recv_raw_pkts_vec_avx2(rx_queue, rx_pkts,
720 nb_pkts, NULL, true);
724 * vPMD receive routine that reassembles single burst of 32 scattered packets
726 * - nb_pkts < ICE_DESCS_PER_LOOP, just return no packet
728 static __rte_always_inline uint16_t
729 ice_recv_scattered_burst_vec_avx2(void *rx_queue, struct rte_mbuf **rx_pkts,
730 uint16_t nb_pkts, bool offload)
732 struct ice_rx_queue *rxq = rx_queue;
733 uint8_t split_flags[ICE_VPMD_RX_BURST] = {0};
735 /* get some new buffers */
736 uint16_t nb_bufs = _ice_recv_raw_pkts_vec_avx2(rxq, rx_pkts, nb_pkts,
737 split_flags, offload);
741 /* happy day case, full burst + no packets to be joined */
742 const uint64_t *split_fl64 = (uint64_t *)split_flags;
744 if (!rxq->pkt_first_seg &&
745 split_fl64[0] == 0 && split_fl64[1] == 0 &&
746 split_fl64[2] == 0 && split_fl64[3] == 0)
749 /* reassemble any packets that need reassembly*/
752 if (!rxq->pkt_first_seg) {
753 /* find the first split flag, and only reassemble then*/
754 while (i < nb_bufs && !split_flags[i])
758 rxq->pkt_first_seg = rx_pkts[i];
760 return i + ice_rx_reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
765 * vPMD receive routine that reassembles scattered packets.
766 * Main receive routine that can handle arbitrary burst sizes
768 * - nb_pkts < ICE_DESCS_PER_LOOP, just return no packet
770 static __rte_always_inline uint16_t
771 ice_recv_scattered_pkts_vec_avx2_common(void *rx_queue,
772 struct rte_mbuf **rx_pkts,
778 while (nb_pkts > ICE_VPMD_RX_BURST) {
779 uint16_t burst = ice_recv_scattered_burst_vec_avx2(rx_queue,
780 rx_pkts + retval, ICE_VPMD_RX_BURST, offload);
783 if (burst < ICE_VPMD_RX_BURST)
786 return retval + ice_recv_scattered_burst_vec_avx2(rx_queue,
787 rx_pkts + retval, nb_pkts, offload);
791 ice_recv_scattered_pkts_vec_avx2(void *rx_queue,
792 struct rte_mbuf **rx_pkts,
795 return ice_recv_scattered_pkts_vec_avx2_common(rx_queue,
802 ice_recv_scattered_pkts_vec_avx2_offload(void *rx_queue,
803 struct rte_mbuf **rx_pkts,
806 return ice_recv_scattered_pkts_vec_avx2_common(rx_queue,
812 static __rte_always_inline void
813 ice_vtx1(volatile struct ice_tx_desc *txdp,
814 struct rte_mbuf *pkt, uint64_t flags, bool offload)
817 (ICE_TX_DESC_DTYPE_DATA |
818 ((uint64_t)flags << ICE_TXD_QW1_CMD_S) |
819 ((uint64_t)pkt->data_len << ICE_TXD_QW1_TX_BUF_SZ_S));
821 ice_txd_enable_offload(pkt, &high_qw);
823 __m128i descriptor = _mm_set_epi64x(high_qw,
824 pkt->buf_iova + pkt->data_off);
825 _mm_store_si128((__m128i *)txdp, descriptor);
828 static __rte_always_inline void
829 ice_vtx(volatile struct ice_tx_desc *txdp,
830 struct rte_mbuf **pkt, uint16_t nb_pkts, uint64_t flags, bool offload)
832 const uint64_t hi_qw_tmpl = (ICE_TX_DESC_DTYPE_DATA |
833 ((uint64_t)flags << ICE_TXD_QW1_CMD_S));
835 /* if unaligned on 32-bit boundary, do one to align */
836 if (((uintptr_t)txdp & 0x1F) != 0 && nb_pkts != 0) {
837 ice_vtx1(txdp, *pkt, flags, offload);
838 nb_pkts--, txdp++, pkt++;
841 /* do two at a time while possible, in bursts */
842 for (; nb_pkts > 3; txdp += 4, pkt += 4, nb_pkts -= 4) {
845 ((uint64_t)pkt[3]->data_len <<
846 ICE_TXD_QW1_TX_BUF_SZ_S);
848 ice_txd_enable_offload(pkt[3], &hi_qw3);
851 ((uint64_t)pkt[2]->data_len <<
852 ICE_TXD_QW1_TX_BUF_SZ_S);
854 ice_txd_enable_offload(pkt[2], &hi_qw2);
857 ((uint64_t)pkt[1]->data_len <<
858 ICE_TXD_QW1_TX_BUF_SZ_S);
860 ice_txd_enable_offload(pkt[1], &hi_qw1);
863 ((uint64_t)pkt[0]->data_len <<
864 ICE_TXD_QW1_TX_BUF_SZ_S);
866 ice_txd_enable_offload(pkt[0], &hi_qw0);
871 pkt[3]->buf_iova + pkt[3]->data_off,
873 pkt[2]->buf_iova + pkt[2]->data_off);
877 pkt[1]->buf_iova + pkt[1]->data_off,
879 pkt[0]->buf_iova + pkt[0]->data_off);
880 _mm256_store_si256((void *)(txdp + 2), desc2_3);
881 _mm256_store_si256((void *)txdp, desc0_1);
884 /* do any last ones */
886 ice_vtx1(txdp, *pkt, flags, offload);
887 txdp++, pkt++, nb_pkts--;
891 static __rte_always_inline uint16_t
892 ice_xmit_fixed_burst_vec_avx2(void *tx_queue, struct rte_mbuf **tx_pkts,
893 uint16_t nb_pkts, bool offload)
895 struct ice_tx_queue *txq = (struct ice_tx_queue *)tx_queue;
896 volatile struct ice_tx_desc *txdp;
897 struct ice_tx_entry *txep;
898 uint16_t n, nb_commit, tx_id;
899 uint64_t flags = ICE_TD_CMD;
900 uint64_t rs = ICE_TX_DESC_CMD_RS | ICE_TD_CMD;
902 /* cross rx_thresh boundary is not allowed */
903 nb_pkts = RTE_MIN(nb_pkts, txq->tx_rs_thresh);
905 if (txq->nb_tx_free < txq->tx_free_thresh)
906 ice_tx_free_bufs_vec(txq);
908 nb_commit = nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
909 if (unlikely(nb_pkts == 0))
912 tx_id = txq->tx_tail;
913 txdp = &txq->tx_ring[tx_id];
914 txep = &txq->sw_ring[tx_id];
916 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
918 n = (uint16_t)(txq->nb_tx_desc - tx_id);
919 if (nb_commit >= n) {
920 ice_tx_backlog_entry(txep, tx_pkts, n);
922 ice_vtx(txdp, tx_pkts, n - 1, flags, offload);
926 ice_vtx1(txdp, *tx_pkts++, rs, offload);
928 nb_commit = (uint16_t)(nb_commit - n);
931 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
933 /* avoid reach the end of ring */
934 txdp = &txq->tx_ring[tx_id];
935 txep = &txq->sw_ring[tx_id];
938 ice_tx_backlog_entry(txep, tx_pkts, nb_commit);
940 ice_vtx(txdp, tx_pkts, nb_commit, flags, offload);
942 tx_id = (uint16_t)(tx_id + nb_commit);
943 if (tx_id > txq->tx_next_rs) {
944 txq->tx_ring[txq->tx_next_rs].cmd_type_offset_bsz |=
945 rte_cpu_to_le_64(((uint64_t)ICE_TX_DESC_CMD_RS) <<
948 (uint16_t)(txq->tx_next_rs + txq->tx_rs_thresh);
951 txq->tx_tail = tx_id;
953 ICE_PCI_REG_WC_WRITE(txq->qtx_tail, txq->tx_tail);
958 static __rte_always_inline uint16_t
959 ice_xmit_pkts_vec_avx2_common(void *tx_queue, struct rte_mbuf **tx_pkts,
960 uint16_t nb_pkts, bool offload)
963 struct ice_tx_queue *txq = (struct ice_tx_queue *)tx_queue;
968 num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_rs_thresh);
969 ret = ice_xmit_fixed_burst_vec_avx2(tx_queue, &tx_pkts[nb_tx],
981 ice_xmit_pkts_vec_avx2(void *tx_queue, struct rte_mbuf **tx_pkts,
984 return ice_xmit_pkts_vec_avx2_common(tx_queue, tx_pkts, nb_pkts, false);
988 ice_xmit_pkts_vec_avx2_offload(void *tx_queue, struct rte_mbuf **tx_pkts,
991 return ice_xmit_pkts_vec_avx2_common(tx_queue, tx_pkts, nb_pkts, true);