29ecedada50f7836be800cb3999370d7ce915bff
[dpdk.git] / drivers / net / mlx5 / mlx5_rxtx_vec_neon.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2017 6WIND S.A.
5  *   Copyright 2017 Mellanox.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of 6WIND S.A. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef RTE_PMD_MLX5_RXTX_VEC_NEON_H_
35 #define RTE_PMD_MLX5_RXTX_VEC_NEON_H_
36
37 #include <assert.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <stdlib.h>
41 #include <arm_neon.h>
42
43 #include <rte_mbuf.h>
44 #include <rte_mempool.h>
45 #include <rte_prefetch.h>
46
47 #include "mlx5.h"
48 #include "mlx5_utils.h"
49 #include "mlx5_rxtx.h"
50 #include "mlx5_rxtx_vec.h"
51 #include "mlx5_autoconf.h"
52 #include "mlx5_defs.h"
53 #include "mlx5_prm.h"
54
55 #pragma GCC diagnostic ignored "-Wcast-qual"
56
57 /**
58  * Fill in buffer descriptors in a multi-packet send descriptor.
59  *
60  * @param txq
61  *   Pointer to TX queue structure.
62  * @param dseg
63  *   Pointer to buffer descriptor to be written.
64  * @param pkts
65  *   Pointer to array of packets to be sent.
66  * @param n
67  *   Number of packets to be filled.
68  */
69 static inline void
70 txq_wr_dseg_v(struct mlx5_txq_data *txq, uint8_t *dseg,
71               struct rte_mbuf **pkts, unsigned int n)
72 {
73         unsigned int pos;
74         uintptr_t addr;
75         const uint8x16_t dseg_shuf_m = {
76                  3,  2,  1,  0, /* length, bswap32 */
77                  4,  5,  6,  7, /* lkey */
78                 15, 14, 13, 12, /* addr, bswap64 */
79                 11, 10,  9,  8
80         };
81 #ifdef MLX5_PMD_SOFT_COUNTERS
82         uint32_t tx_byte = 0;
83 #endif
84
85         for (pos = 0; pos < n; ++pos, dseg += MLX5_WQE_DWORD_SIZE) {
86                 uint8x16_t desc;
87                 struct rte_mbuf *pkt = pkts[pos];
88
89                 addr = rte_pktmbuf_mtod(pkt, uintptr_t);
90                 desc = vreinterpretq_u8_u32((uint32x4_t) {
91                                 DATA_LEN(pkt),
92                                 mlx5_tx_mb2mr(txq, pkt),
93                                 addr,
94                                 addr >> 32 });
95                 desc = vqtbl1q_u8(desc, dseg_shuf_m);
96                 vst1q_u8(dseg, desc);
97 #ifdef MLX5_PMD_SOFT_COUNTERS
98                 tx_byte += DATA_LEN(pkt);
99 #endif
100         }
101 #ifdef MLX5_PMD_SOFT_COUNTERS
102         txq->stats.obytes += tx_byte;
103 #endif
104 }
105
106 /**
107  * Send multi-segmented packets until it encounters a single segment packet in
108  * the pkts list.
109  *
110  * @param txq
111  *   Pointer to TX queue structure.
112  * @param pkts
113  *   Pointer to array of packets to be sent.
114  * @param pkts_n
115  *   Number of packets to be sent.
116  *
117  * @return
118  *   Number of packets successfully transmitted (<= pkts_n).
119  */
120 static uint16_t
121 txq_scatter_v(struct mlx5_txq_data *txq, struct rte_mbuf **pkts,
122               uint16_t pkts_n)
123 {
124         uint16_t elts_head = txq->elts_head;
125         const uint16_t elts_n = 1 << txq->elts_n;
126         const uint16_t elts_m = elts_n - 1;
127         const uint16_t wq_n = 1 << txq->wqe_n;
128         const uint16_t wq_mask = wq_n - 1;
129         const unsigned int nb_dword_per_wqebb =
130                 MLX5_WQE_SIZE / MLX5_WQE_DWORD_SIZE;
131         const unsigned int nb_dword_in_hdr =
132                 sizeof(struct mlx5_wqe) / MLX5_WQE_DWORD_SIZE;
133         unsigned int n;
134         volatile struct mlx5_wqe *wqe = NULL;
135
136         assert(elts_n > pkts_n);
137         mlx5_tx_complete(txq);
138         /* A CQE slot must always be available. */
139         assert((1u << txq->cqe_n) - (txq->cq_pi - txq->cq_ci));
140         if (unlikely(!pkts_n))
141                 return 0;
142         for (n = 0; n < pkts_n; ++n) {
143                 struct rte_mbuf *buf = pkts[n];
144                 unsigned int segs_n = buf->nb_segs;
145                 unsigned int ds = nb_dword_in_hdr;
146                 unsigned int len = PKT_LEN(buf);
147                 uint16_t wqe_ci = txq->wqe_ci;
148                 const uint8x16_t ctrl_shuf_m = {
149                         3,  2,  1,  0, /* bswap32 */
150                         7,  6,  5,  4, /* bswap32 */
151                         11, 10,  9,  8, /* bswap32 */
152                         12, 13, 14, 15
153                 };
154                 uint8_t cs_flags;
155                 uint16_t max_elts;
156                 uint16_t max_wqe;
157                 uint8x16_t *t_wqe;
158                 uint8_t *dseg;
159                 uint8x16_t ctrl;
160
161                 assert(segs_n);
162                 max_elts = elts_n - (elts_head - txq->elts_tail);
163                 max_wqe = wq_n - (txq->wqe_ci - txq->wqe_pi);
164                 /*
165                  * A MPW session consumes 2 WQEs at most to
166                  * include MLX5_MPW_DSEG_MAX pointers.
167                  */
168                 if (segs_n == 1 ||
169                     max_elts < segs_n || max_wqe < 2)
170                         break;
171                 wqe = &((volatile struct mlx5_wqe64 *)
172                          txq->wqes)[wqe_ci & wq_mask].hdr;
173                 cs_flags = txq_ol_cksum_to_cs(txq, buf);
174                 /* Title WQEBB pointer. */
175                 t_wqe = (uint8x16_t *)wqe;
176                 dseg = (uint8_t *)(wqe + 1);
177                 do {
178                         if (!(ds++ % nb_dword_per_wqebb)) {
179                                 dseg = (uint8_t *)
180                                         &((volatile struct mlx5_wqe64 *)
181                                            txq->wqes)[++wqe_ci & wq_mask];
182                         }
183                         txq_wr_dseg_v(txq, dseg, &buf, 1);
184                         dseg += MLX5_WQE_DWORD_SIZE;
185                         (*txq->elts)[elts_head++ & elts_m] = buf;
186                         buf = buf->next;
187                 } while (--segs_n);
188                 ++wqe_ci;
189                 /* Fill CTRL in the header. */
190                 ctrl = vreinterpretq_u8_u32((uint32x4_t) {
191                                 MLX5_OPC_MOD_MPW << 24 |
192                                 txq->wqe_ci << 8 | MLX5_OPCODE_TSO,
193                                 txq->qp_num_8s | ds, 0, 0});
194                 ctrl = vqtbl1q_u8(ctrl, ctrl_shuf_m);
195                 vst1q_u8((void *)t_wqe, ctrl);
196                 /* Fill ESEG in the header. */
197                 vst1q_u16((void *)(t_wqe + 1),
198                           (uint16x8_t) { 0, 0, cs_flags, rte_cpu_to_be_16(len),
199                                          0, 0, 0, 0 });
200                 txq->wqe_ci = wqe_ci;
201         }
202         if (!n)
203                 return 0;
204         txq->elts_comp += (uint16_t)(elts_head - txq->elts_head);
205         txq->elts_head = elts_head;
206         if (txq->elts_comp >= MLX5_TX_COMP_THRESH) {
207                 wqe->ctrl[2] = rte_cpu_to_be_32(8);
208                 wqe->ctrl[3] = txq->elts_head;
209                 txq->elts_comp = 0;
210 #ifndef NDEBUG
211                 ++txq->cq_pi;
212 #endif
213         }
214 #ifdef MLX5_PMD_SOFT_COUNTERS
215         txq->stats.opackets += n;
216 #endif
217         mlx5_tx_dbrec(txq, wqe);
218         return n;
219 }
220
221 /**
222  * Send burst of packets with Enhanced MPW. If it encounters a multi-seg packet,
223  * it returns to make it processed by txq_scatter_v(). All the packets in
224  * the pkts list should be single segment packets having same offload flags.
225  * This must be checked by txq_count_contig_single_seg() and txq_calc_offload().
226  *
227  * @param txq
228  *   Pointer to TX queue structure.
229  * @param pkts
230  *   Pointer to array of packets to be sent.
231  * @param pkts_n
232  *   Number of packets to be sent (<= MLX5_VPMD_TX_MAX_BURST).
233  * @param cs_flags
234  *   Checksum offload flags to be written in the descriptor.
235  *
236  * @return
237  *   Number of packets successfully transmitted (<= pkts_n).
238  */
239 static inline uint16_t
240 txq_burst_v(struct mlx5_txq_data *txq, struct rte_mbuf **pkts, uint16_t pkts_n,
241             uint8_t cs_flags)
242 {
243         struct rte_mbuf **elts;
244         uint16_t elts_head = txq->elts_head;
245         const uint16_t elts_n = 1 << txq->elts_n;
246         const uint16_t elts_m = elts_n - 1;
247         const unsigned int nb_dword_per_wqebb =
248                 MLX5_WQE_SIZE / MLX5_WQE_DWORD_SIZE;
249         const unsigned int nb_dword_in_hdr =
250                 sizeof(struct mlx5_wqe) / MLX5_WQE_DWORD_SIZE;
251         unsigned int n = 0;
252         unsigned int pos;
253         uint16_t max_elts;
254         uint16_t max_wqe;
255         uint32_t comp_req = 0;
256         const uint16_t wq_n = 1 << txq->wqe_n;
257         const uint16_t wq_mask = wq_n - 1;
258         uint16_t wq_idx = txq->wqe_ci & wq_mask;
259         volatile struct mlx5_wqe64 *wq =
260                 &((volatile struct mlx5_wqe64 *)txq->wqes)[wq_idx];
261         volatile struct mlx5_wqe *wqe = (volatile struct mlx5_wqe *)wq;
262         const uint8x16_t ctrl_shuf_m = {
263                  3,  2,  1,  0, /* bswap32 */
264                  7,  6,  5,  4, /* bswap32 */
265                 11, 10,  9,  8, /* bswap32 */
266                 12, 13, 14, 15
267         };
268         uint8x16_t *t_wqe;
269         uint8_t *dseg;
270         uint8x16_t ctrl;
271
272         /* Make sure all packets can fit into a single WQE. */
273         assert(elts_n > pkts_n);
274         mlx5_tx_complete(txq);
275         max_elts = (elts_n - (elts_head - txq->elts_tail));
276         /* A CQE slot must always be available. */
277         assert((1u << txq->cqe_n) - (txq->cq_pi - txq->cq_ci));
278         max_wqe = (1u << txq->wqe_n) - (txq->wqe_ci - txq->wqe_pi);
279         pkts_n = RTE_MIN((unsigned int)RTE_MIN(pkts_n, max_wqe), max_elts);
280         if (unlikely(!pkts_n))
281                 return 0;
282         elts = &(*txq->elts)[elts_head & elts_m];
283         /* Loop for available tailroom first. */
284         n = RTE_MIN(elts_n - (elts_head & elts_m), pkts_n);
285         for (pos = 0; pos < (n & -2); pos += 2)
286                 vst1q_u64((void *)&elts[pos], vld1q_u64((void *)&pkts[pos]));
287         if (n & 1)
288                 elts[pos] = pkts[pos];
289         /* Check if it crosses the end of the queue. */
290         if (unlikely(n < pkts_n)) {
291                 elts = &(*txq->elts)[0];
292                 for (pos = 0; pos < pkts_n - n; ++pos)
293                         elts[pos] = pkts[n + pos];
294         }
295         txq->elts_head += pkts_n;
296         /* Save title WQEBB pointer. */
297         t_wqe = (uint8x16_t *)wqe;
298         dseg = (uint8_t *)(wqe + 1);
299         /* Calculate the number of entries to the end. */
300         n = RTE_MIN(
301                 (wq_n - wq_idx) * nb_dword_per_wqebb - nb_dword_in_hdr,
302                 pkts_n);
303         /* Fill DSEGs. */
304         txq_wr_dseg_v(txq, dseg, pkts, n);
305         /* Check if it crosses the end of the queue. */
306         if (n < pkts_n) {
307                 dseg = (uint8_t *)txq->wqes;
308                 txq_wr_dseg_v(txq, dseg, &pkts[n], pkts_n - n);
309         }
310         if (txq->elts_comp + pkts_n < MLX5_TX_COMP_THRESH) {
311                 txq->elts_comp += pkts_n;
312         } else {
313                 /* Request a completion. */
314                 txq->elts_comp = 0;
315 #ifndef NDEBUG
316                 ++txq->cq_pi;
317 #endif
318                 comp_req = 8;
319         }
320         /* Fill CTRL in the header. */
321         ctrl = vreinterpretq_u8_u32((uint32x4_t) {
322                         MLX5_OPC_MOD_ENHANCED_MPSW << 24 |
323                         txq->wqe_ci << 8 | MLX5_OPCODE_ENHANCED_MPSW,
324                         txq->qp_num_8s | (pkts_n + 2),
325                         comp_req,
326                         txq->elts_head });
327         ctrl = vqtbl1q_u8(ctrl, ctrl_shuf_m);
328         vst1q_u8((void *)t_wqe, ctrl);
329         /* Fill ESEG in the header. */
330         vst1q_u8((void *)(t_wqe + 1),
331                  (uint8x16_t) { 0, 0, 0, 0,
332                                 cs_flags, 0, 0, 0,
333                                 0, 0, 0, 0,
334                                 0, 0, 0, 0 });
335 #ifdef MLX5_PMD_SOFT_COUNTERS
336         txq->stats.opackets += pkts_n;
337 #endif
338         txq->wqe_ci += (nb_dword_in_hdr + pkts_n + (nb_dword_per_wqebb - 1)) /
339                        nb_dword_per_wqebb;
340         /* Ring QP doorbell. */
341         mlx5_tx_dbrec_cond_wmb(txq, wqe, pkts_n < MLX5_VPMD_TX_MAX_BURST);
342         return pkts_n;
343 }
344
345 /**
346  * Store free buffers to RX SW ring.
347  *
348  * @param rxq
349  *   Pointer to RX queue structure.
350  * @param pkts
351  *   Pointer to array of packets to be stored.
352  * @param pkts_n
353  *   Number of packets to be stored.
354  */
355 static inline void
356 rxq_copy_mbuf_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts, uint16_t n)
357 {
358         const uint16_t q_mask = (1 << rxq->elts_n) - 1;
359         struct rte_mbuf **elts = &(*rxq->elts)[rxq->rq_pi & q_mask];
360         unsigned int pos;
361         uint16_t p = n & -2;
362
363         for (pos = 0; pos < p; pos += 2) {
364                 uint64x2_t mbp;
365
366                 mbp = vld1q_u64((void *)&elts[pos]);
367                 vst1q_u64((void *)&pkts[pos], mbp);
368         }
369         if (n & 1)
370                 pkts[pos] = elts[pos];
371 }
372
373 /**
374  * Decompress a compressed completion and fill in mbufs in RX SW ring with data
375  * extracted from the title completion descriptor.
376  *
377  * @param rxq
378  *   Pointer to RX queue structure.
379  * @param cq
380  *   Pointer to completion array having a compressed completion at first.
381  * @param elts
382  *   Pointer to SW ring to be filled. The first mbuf has to be pre-built from
383  *   the title completion descriptor to be copied to the rest of mbufs.
384  */
385 static inline void
386 rxq_cq_decompress_v(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cq,
387                     struct rte_mbuf **elts)
388 {
389         volatile struct mlx5_mini_cqe8 *mcq = (void *)&(cq + 1)->pkt_info;
390         struct rte_mbuf *t_pkt = elts[0]; /* Title packet is pre-built. */
391         unsigned int pos;
392         unsigned int i;
393         unsigned int inv = 0;
394         /* Mask to shuffle from extracted mini CQE to mbuf. */
395         const uint8x16_t mcqe_shuf_m1 = {
396                 -1, -1, -1, -1, /* skip packet_type */
397                  7,  6, -1, -1, /* pkt_len, bswap16 */
398                  7,  6,         /* data_len, bswap16 */
399                 -1, -1,         /* skip vlan_tci */
400                  3,  2,  1,  0  /* hash.rss, bswap32 */
401         };
402         const uint8x16_t mcqe_shuf_m2 = {
403                 -1, -1, -1, -1, /* skip packet_type */
404                 15, 14, -1, -1, /* pkt_len, bswap16 */
405                 15, 14,         /* data_len, bswap16 */
406                 -1, -1,         /* skip vlan_tci */
407                 11, 10,  9,  8  /* hash.rss, bswap32 */
408         };
409         /* Restore the compressed count. Must be 16 bits. */
410         const uint16_t mcqe_n = t_pkt->data_len +
411                                 (rxq->crc_present * ETHER_CRC_LEN);
412         const uint64x2_t rearm =
413                 vld1q_u64((void *)&t_pkt->rearm_data);
414         const uint32x4_t rxdf_mask = {
415                 0xffffffff, /* packet_type */
416                 0,          /* skip pkt_len */
417                 0xffff0000, /* vlan_tci, skip data_len */
418                 0,          /* skip hash.rss */
419         };
420         const uint8x16_t rxdf =
421                 vandq_u8(vld1q_u8((void *)&t_pkt->rx_descriptor_fields1),
422                          vreinterpretq_u8_u32(rxdf_mask));
423         const uint16x8_t crc_adj = {
424                 0, 0,
425                 rxq->crc_present * ETHER_CRC_LEN, 0,
426                 rxq->crc_present * ETHER_CRC_LEN, 0,
427                 0, 0
428         };
429         const uint32_t flow_tag = t_pkt->hash.fdir.hi;
430 #ifdef MLX5_PMD_SOFT_COUNTERS
431         uint32_t rcvd_byte = 0;
432 #endif
433         /* Mask to shuffle byte_cnt to add up stats. Do bswap16 for all. */
434         const uint8x8_t len_shuf_m = {
435                  7,  6,         /* 1st mCQE */
436                 15, 14,         /* 2nd mCQE */
437                 23, 22,         /* 3rd mCQE */
438                 31, 30          /* 4th mCQE */
439         };
440
441         /*
442          * A. load mCQEs into a 128bit register.
443          * B. store rearm data to mbuf.
444          * C. combine data from mCQEs with rx_descriptor_fields1.
445          * D. store rx_descriptor_fields1.
446          * E. store flow tag (rte_flow mark).
447          */
448         for (pos = 0; pos < mcqe_n; ) {
449                 uint8_t *p = (void *)&mcq[pos % 8];
450                 uint8_t *e0 = (void *)&elts[pos]->rearm_data;
451                 uint8_t *e1 = (void *)&elts[pos + 1]->rearm_data;
452                 uint8_t *e2 = (void *)&elts[pos + 2]->rearm_data;
453                 uint8_t *e3 = (void *)&elts[pos + 3]->rearm_data;
454                 uint16x4_t byte_cnt;
455 #ifdef MLX5_PMD_SOFT_COUNTERS
456                 uint16x4_t invalid_mask =
457                         vcreate_u16(mcqe_n - pos < MLX5_VPMD_DESCS_PER_LOOP ?
458                                     -1UL << ((mcqe_n - pos) *
459                                              sizeof(uint16_t) * 8) : 0);
460 #endif
461
462                 if (!(pos & 0x7) && pos + 8 < mcqe_n)
463                         rte_prefetch0((void *)(cq + pos + 8));
464                 __asm__ volatile (
465                 /* A.1 load mCQEs into a 128bit register. */
466                 "ld1 {v16.16b - v17.16b}, [%[mcq]] \n\t"
467                 /* B.1 store rearm data to mbuf. */
468                 "st1 {%[rearm].2d}, [%[e0]] \n\t"
469                 "add %[e0], %[e0], #16 \n\t"
470                 "st1 {%[rearm].2d}, [%[e1]] \n\t"
471                 "add %[e1], %[e1], #16 \n\t"
472                 /* C.1 combine data from mCQEs with rx_descriptor_fields1. */
473                 "tbl v18.16b, {v16.16b}, %[mcqe_shuf_m1].16b \n\t"
474                 "tbl v19.16b, {v16.16b}, %[mcqe_shuf_m2].16b \n\t"
475                 "sub v18.8h, v18.8h, %[crc_adj].8h \n\t"
476                 "sub v19.8h, v19.8h, %[crc_adj].8h \n\t"
477                 "orr v18.16b, v18.16b, %[rxdf].16b \n\t"
478                 "orr v19.16b, v19.16b, %[rxdf].16b \n\t"
479                 /* D.1 store rx_descriptor_fields1. */
480                 "st1 {v18.2d}, [%[e0]] \n\t"
481                 "st1 {v19.2d}, [%[e1]] \n\t"
482                 /* B.1 store rearm data to mbuf. */
483                 "st1 {%[rearm].2d}, [%[e2]] \n\t"
484                 "add %[e2], %[e2], #16 \n\t"
485                 "st1 {%[rearm].2d}, [%[e3]] \n\t"
486                 "add %[e3], %[e3], #16 \n\t"
487                 /* C.1 combine data from mCQEs with rx_descriptor_fields1. */
488                 "tbl v18.16b, {v17.16b}, %[mcqe_shuf_m1].16b \n\t"
489                 "tbl v19.16b, {v17.16b}, %[mcqe_shuf_m2].16b \n\t"
490                 "sub v18.8h, v18.8h, %[crc_adj].8h \n\t"
491                 "sub v19.8h, v19.8h, %[crc_adj].8h \n\t"
492                 "orr v18.16b, v18.16b, %[rxdf].16b \n\t"
493                 "orr v19.16b, v19.16b, %[rxdf].16b \n\t"
494                 /* D.1 store rx_descriptor_fields1. */
495                 "st1 {v18.2d}, [%[e2]] \n\t"
496                 "st1 {v19.2d}, [%[e3]] \n\t"
497 #ifdef MLX5_PMD_SOFT_COUNTERS
498                 "tbl %[byte_cnt].8b, {v16.16b - v17.16b}, %[len_shuf_m].8b \n\t"
499 #endif
500                 :[byte_cnt]"=&w"(byte_cnt)
501                 :[mcq]"r"(p),
502                  [rxdf]"w"(rxdf),
503                  [rearm]"w"(rearm),
504                  [e3]"r"(e3), [e2]"r"(e2), [e1]"r"(e1), [e0]"r"(e0),
505                  [mcqe_shuf_m1]"w"(mcqe_shuf_m1),
506                  [mcqe_shuf_m2]"w"(mcqe_shuf_m2),
507                  [crc_adj]"w"(crc_adj),
508                  [len_shuf_m]"w"(len_shuf_m)
509                 :"memory", "v16", "v17", "v18", "v19");
510 #ifdef MLX5_PMD_SOFT_COUNTERS
511                 byte_cnt = vbic_u16(byte_cnt, invalid_mask);
512                 rcvd_byte += vget_lane_u64(vpaddl_u32(vpaddl_u16(byte_cnt)), 0);
513 #endif
514                 if (rxq->mark) {
515                         /* E.1 store flow tag (rte_flow mark). */
516                         elts[pos]->hash.fdir.hi = flow_tag;
517                         elts[pos + 1]->hash.fdir.hi = flow_tag;
518                         elts[pos + 2]->hash.fdir.hi = flow_tag;
519                         elts[pos + 3]->hash.fdir.hi = flow_tag;
520                 }
521                 pos += MLX5_VPMD_DESCS_PER_LOOP;
522                 /* Move to next CQE and invalidate consumed CQEs. */
523                 if (!(pos & 0x7) && pos < mcqe_n) {
524                         mcq = (void *)&(cq + pos)->pkt_info;
525                         for (i = 0; i < 8; ++i)
526                                 cq[inv++].op_own = MLX5_CQE_INVALIDATE;
527                 }
528         }
529         /* Invalidate the rest of CQEs. */
530         for (; inv < mcqe_n; ++inv)
531                 cq[inv].op_own = MLX5_CQE_INVALIDATE;
532 #ifdef MLX5_PMD_SOFT_COUNTERS
533         rxq->stats.ipackets += mcqe_n;
534         rxq->stats.ibytes += rcvd_byte;
535 #endif
536         rxq->cq_ci += mcqe_n;
537 }
538
539 /**
540  * Calculate packet type and offload flag for mbuf and store it.
541  *
542  * @param rxq
543  *   Pointer to RX queue structure.
544  * @param ptype_info
545  *   Array of four 4bytes packet type info extracted from the original
546  *   completion descriptor.
547  * @param flow_tag
548  *   Array of four 4bytes flow ID extracted from the original completion
549  *   descriptor.
550  * @param op_err
551  *   Opcode vector having responder error status. Each field is 4B.
552  * @param pkts
553  *   Pointer to array of packets to be filled.
554  */
555 static inline void
556 rxq_cq_to_ptype_oflags_v(struct mlx5_rxq_data *rxq,
557                          uint32x4_t ptype_info, uint32x4_t flow_tag,
558                          uint16x4_t op_err, struct rte_mbuf **pkts)
559 {
560         uint16x4_t ptype;
561         uint32x4_t pinfo, cv_flags;
562         uint32x4_t ol_flags =
563                 vdupq_n_u32(rxq->rss_hash * PKT_RX_RSS_HASH |
564                             rxq->hw_timestamp * PKT_RX_TIMESTAMP);
565         const uint32x4_t ptype_ol_mask = { 0x106, 0x106, 0x106, 0x106 };
566         const uint8x16_t cv_flag_sel = {
567                 0,
568                 (uint8_t)(PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED),
569                 (uint8_t)(PKT_RX_IP_CKSUM_GOOD >> 1),
570                 0,
571                 (uint8_t)(PKT_RX_L4_CKSUM_GOOD >> 1),
572                 0,
573                 (uint8_t)((PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD) >> 1),
574                 0, 0, 0, 0, 0, 0, 0, 0, 0
575         };
576         const uint32x4_t cv_mask =
577                 vdupq_n_u32(PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
578                             PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED);
579         const uint64x1_t mbuf_init = vld1_u64(&rxq->mbuf_initializer);
580         const uint64x1_t r32_mask = vcreate_u64(0xffffffff);
581         uint64x2_t rearm0, rearm1, rearm2, rearm3;
582
583         if (rxq->mark) {
584                 const uint32x4_t ft_def = vdupq_n_u32(MLX5_FLOW_MARK_DEFAULT);
585                 const uint32x4_t fdir_flags = vdupq_n_u32(PKT_RX_FDIR);
586                 uint32x4_t fdir_id_flags = vdupq_n_u32(PKT_RX_FDIR_ID);
587                 uint32x4_t invalid_mask;
588
589                 /* Check if flow tag is non-zero then set PKT_RX_FDIR. */
590                 invalid_mask = vceqzq_u32(flow_tag);
591                 ol_flags = vorrq_u32(ol_flags,
592                                      vbicq_u32(fdir_flags, invalid_mask));
593                 /* Mask out invalid entries. */
594                 fdir_id_flags = vbicq_u32(fdir_id_flags, invalid_mask);
595                 /* Check if flow tag MLX5_FLOW_MARK_DEFAULT. */
596                 ol_flags = vorrq_u32(ol_flags,
597                                      vbicq_u32(fdir_id_flags,
598                                                vceqq_u32(flow_tag, ft_def)));
599         }
600         /*
601          * ptype_info has the following:
602          * bit[1]     = l3_ok
603          * bit[2]     = l4_ok
604          * bit[8]     = cv
605          * bit[11:10] = l3_hdr_type
606          * bit[14:12] = l4_hdr_type
607          * bit[15]    = ip_frag
608          * bit[16]    = tunneled
609          * bit[17]    = outer_l3_type
610          */
611         ptype = vshrn_n_u32(ptype_info, 10);
612         /* Errored packets will have RTE_PTYPE_ALL_MASK. */
613         ptype = vorr_u16(ptype, op_err);
614         pkts[0]->packet_type =
615                 mlx5_ptype_table[vget_lane_u8(vreinterpret_u8_u16(ptype), 6)];
616         pkts[1]->packet_type =
617                 mlx5_ptype_table[vget_lane_u8(vreinterpret_u8_u16(ptype), 4)];
618         pkts[2]->packet_type =
619                 mlx5_ptype_table[vget_lane_u8(vreinterpret_u8_u16(ptype), 2)];
620         pkts[3]->packet_type =
621                 mlx5_ptype_table[vget_lane_u8(vreinterpret_u8_u16(ptype), 0)];
622         /* Fill flags for checksum and VLAN. */
623         pinfo = vandq_u32(ptype_info, ptype_ol_mask);
624         pinfo = vreinterpretq_u32_u8(
625                 vqtbl1q_u8(cv_flag_sel, vreinterpretq_u8_u32(pinfo)));
626         /* Locate checksum flags at byte[2:1] and merge with VLAN flags. */
627         cv_flags = vshlq_n_u32(pinfo, 9);
628         cv_flags = vorrq_u32(pinfo, cv_flags);
629         /* Move back flags to start from byte[0]. */
630         cv_flags = vshrq_n_u32(cv_flags, 8);
631         /* Mask out garbage bits. */
632         cv_flags = vandq_u32(cv_flags, cv_mask);
633         /* Merge to ol_flags. */
634         ol_flags = vorrq_u32(ol_flags, cv_flags);
635         /* Merge mbuf_init and ol_flags, and store. */
636         rearm0 = vcombine_u64(mbuf_init,
637                               vshr_n_u64(vget_high_u64(vreinterpretq_u64_u32(
638                                                        ol_flags)), 32));
639         rearm1 = vcombine_u64(mbuf_init,
640                               vand_u64(vget_high_u64(vreinterpretq_u64_u32(
641                                                      ol_flags)), r32_mask));
642         rearm2 = vcombine_u64(mbuf_init,
643                               vshr_n_u64(vget_low_u64(vreinterpretq_u64_u32(
644                                                       ol_flags)), 32));
645         rearm3 = vcombine_u64(mbuf_init,
646                               vand_u64(vget_low_u64(vreinterpretq_u64_u32(
647                                                     ol_flags)), r32_mask));
648         vst1q_u64((void *)&pkts[0]->rearm_data, rearm0);
649         vst1q_u64((void *)&pkts[1]->rearm_data, rearm1);
650         vst1q_u64((void *)&pkts[2]->rearm_data, rearm2);
651         vst1q_u64((void *)&pkts[3]->rearm_data, rearm3);
652 }
653
654 /**
655  * Receive burst of packets. An errored completion also consumes a mbuf, but the
656  * packet_type is set to be RTE_PTYPE_ALL_MASK. Marked mbufs should be freed
657  * before returning to application.
658  *
659  * @param rxq
660  *   Pointer to RX queue structure.
661  * @param[out] pkts
662  *   Array to store received packets.
663  * @param pkts_n
664  *   Maximum number of packets in array.
665  * @param[out] err
666  *   Pointer to a flag. Set non-zero value if pkts array has at least one error
667  *   packet to handle.
668  *
669  * @return
670  *   Number of packets received including errors (<= pkts_n).
671  */
672 static inline uint16_t
673 rxq_burst_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts, uint16_t pkts_n,
674             uint64_t *err)
675 {
676         const uint16_t q_n = 1 << rxq->cqe_n;
677         const uint16_t q_mask = q_n - 1;
678         volatile struct mlx5_cqe *cq;
679         struct rte_mbuf **elts;
680         unsigned int pos;
681         uint64_t n;
682         uint16_t repl_n;
683         uint64_t comp_idx = MLX5_VPMD_DESCS_PER_LOOP;
684         uint16_t nocmp_n = 0;
685         uint16_t rcvd_pkt = 0;
686         unsigned int cq_idx = rxq->cq_ci & q_mask;
687         unsigned int elts_idx;
688         const uint16x4_t ownership = vdup_n_u16(!(rxq->cq_ci & (q_mask + 1)));
689         const uint16x4_t owner_check = vcreate_u16(0x0001000100010001);
690         const uint16x4_t opcode_check = vcreate_u16(0x00f000f000f000f0);
691         const uint16x4_t format_check = vcreate_u16(0x000c000c000c000c);
692         const uint16x4_t resp_err_check = vcreate_u16(0x00e000e000e000e0);
693 #ifdef MLX5_PMD_SOFT_COUNTERS
694         uint32_t rcvd_byte = 0;
695 #endif
696         /* Mask to generate 16B length vector. */
697         const uint8x8_t len_shuf_m = {
698                 52, 53,         /* 4th CQE */
699                 36, 37,         /* 3rd CQE */
700                 20, 21,         /* 2nd CQE */
701                  4,  5          /* 1st CQE */
702         };
703         /* Mask to extract 16B data from a 64B CQE. */
704         const uint8x16_t cqe_shuf_m = {
705                 28, 29,         /* hdr_type_etc */
706                  0,             /* pkt_info */
707                 -1,             /* null */
708                 47, 46,         /* byte_cnt, bswap16 */
709                 31, 30,         /* vlan_info, bswap16 */
710                 15, 14, 13, 12, /* rx_hash_res, bswap32 */
711                 57, 58, 59,     /* flow_tag */
712                 63              /* op_own */
713         };
714         /* Mask to generate 16B data for mbuf. */
715         const uint8x16_t mb_shuf_m = {
716                  4,  5, -1, -1, /* pkt_len */
717                  4,  5,         /* data_len */
718                  6,  7,         /* vlan_tci */
719                  8,  9, 10, 11, /* hash.rss */
720                 12, 13, 14, -1  /* hash.fdir.hi */
721         };
722         /* Mask to generate 16B owner vector. */
723         const uint8x8_t owner_shuf_m = {
724                 63, -1,         /* 4th CQE */
725                 47, -1,         /* 3rd CQE */
726                 31, -1,         /* 2nd CQE */
727                 15, -1          /* 1st CQE */
728         };
729         /* Mask to generate a vector having packet_type/ol_flags. */
730         const uint8x16_t ptype_shuf_m = {
731                 48, 49, 50, -1, /* 4th CQE */
732                 32, 33, 34, -1, /* 3rd CQE */
733                 16, 17, 18, -1, /* 2nd CQE */
734                  0,  1,  2, -1  /* 1st CQE */
735         };
736         /* Mask to generate a vector having flow tags. */
737         const uint8x16_t ftag_shuf_m = {
738                 60, 61, 62, -1, /* 4th CQE */
739                 44, 45, 46, -1, /* 3rd CQE */
740                 28, 29, 30, -1, /* 2nd CQE */
741                 12, 13, 14, -1  /* 1st CQE */
742         };
743         const uint16x8_t crc_adj = {
744                 0, 0, rxq->crc_present * ETHER_CRC_LEN, 0, 0, 0, 0, 0
745         };
746         const uint32x4_t flow_mark_adj = { 0, 0, 0, rxq->mark * (-1) };
747
748         assert(rxq->sges_n == 0);
749         assert(rxq->cqe_n == rxq->elts_n);
750         cq = &(*rxq->cqes)[cq_idx];
751         rte_prefetch_non_temporal(cq);
752         rte_prefetch_non_temporal(cq + 1);
753         rte_prefetch_non_temporal(cq + 2);
754         rte_prefetch_non_temporal(cq + 3);
755         pkts_n = RTE_MIN(pkts_n, MLX5_VPMD_RX_MAX_BURST);
756         /*
757          * Order of indexes:
758          *   rq_ci >= cq_ci >= rq_pi
759          * Definition of indexes:
760          *   rq_ci - cq_ci := # of buffers owned by HW (posted).
761          *   cq_ci - rq_pi := # of buffers not returned to app (decompressed).
762          *   N - (rq_ci - rq_pi) := # of buffers consumed (to be replenished).
763          */
764         repl_n = q_n - (rxq->rq_ci - rxq->rq_pi);
765         if (repl_n >= MLX5_VPMD_RXQ_RPLNSH_THRESH)
766                 mlx5_rx_replenish_bulk_mbuf(rxq, repl_n);
767         /* See if there're unreturned mbufs from compressed CQE. */
768         rcvd_pkt = rxq->cq_ci - rxq->rq_pi;
769         if (rcvd_pkt > 0) {
770                 rcvd_pkt = RTE_MIN(rcvd_pkt, pkts_n);
771                 rxq_copy_mbuf_v(rxq, pkts, rcvd_pkt);
772                 rxq->rq_pi += rcvd_pkt;
773                 pkts += rcvd_pkt;
774         }
775         elts_idx = rxq->rq_pi & q_mask;
776         elts = &(*rxq->elts)[elts_idx];
777         /* Not to overflow pkts array. */
778         pkts_n = RTE_ALIGN_FLOOR(pkts_n - rcvd_pkt, MLX5_VPMD_DESCS_PER_LOOP);
779         /* Not to cross queue end. */
780         pkts_n = RTE_MIN(pkts_n, q_n - elts_idx);
781         if (!pkts_n)
782                 return rcvd_pkt;
783         /* At this point, there shouldn't be any remained packets. */
784         assert(rxq->rq_pi == rxq->cq_ci);
785         /*
786          * Note that vectors have reverse order - {v3, v2, v1, v0}, because
787          * there's no instruction to count trailing zeros. __builtin_clzl() is
788          * used instead.
789          *
790          * A. copy 4 mbuf pointers from elts ring to returing pkts.
791          * B. load 64B CQE and extract necessary fields
792          *    Final 16bytes cqes[] extracted from original 64bytes CQE has the
793          *    following structure:
794          *        struct {
795          *          uint16_t hdr_type_etc;
796          *          uint8_t  pkt_info;
797          *          uint8_t  rsvd;
798          *          uint16_t byte_cnt;
799          *          uint16_t vlan_info;
800          *          uint32_t rx_has_res;
801          *          uint8_t  flow_tag[3];
802          *          uint8_t  op_own;
803          *        } c;
804          * C. fill in mbuf.
805          * D. get valid CQEs.
806          * E. find compressed CQE.
807          */
808         for (pos = 0;
809              pos < pkts_n;
810              pos += MLX5_VPMD_DESCS_PER_LOOP) {
811                 uint16x4_t op_own;
812                 uint16x4_t opcode, owner_mask, invalid_mask;
813                 uint16x4_t comp_mask;
814                 uint16x4_t mask;
815                 uint16x4_t byte_cnt;
816                 uint32x4_t ptype_info, flow_tag;
817                 register uint64x2_t c0, c1, c2, c3;
818                 uint8_t *p0, *p1, *p2, *p3;
819                 uint8_t *e0 = (void *)&elts[pos]->pkt_len;
820                 uint8_t *e1 = (void *)&elts[pos + 1]->pkt_len;
821                 uint8_t *e2 = (void *)&elts[pos + 2]->pkt_len;
822                 uint8_t *e3 = (void *)&elts[pos + 3]->pkt_len;
823                 void *elts_p = (void *)&elts[pos];
824                 void *pkts_p = (void *)&pkts[pos];
825
826                 /* A.0 do not cross the end of CQ. */
827                 mask = vcreate_u16(pkts_n - pos < MLX5_VPMD_DESCS_PER_LOOP ?
828                                    -1UL >> ((pkts_n - pos) *
829                                             sizeof(uint16_t) * 8) : 0);
830                 p0 = (void *)&cq[pos].pkt_info;
831                 p1 = p0 + (pkts_n - pos > 1) * sizeof(struct mlx5_cqe);
832                 p2 = p1 + (pkts_n - pos > 2) * sizeof(struct mlx5_cqe);
833                 p3 = p2 + (pkts_n - pos > 3) * sizeof(struct mlx5_cqe);
834                 /* B.0 (CQE 3) load a block having op_own. */
835                 c3 = vld1q_u64((uint64_t *)(p3 + 48));
836                 /* B.0 (CQE 2) load a block having op_own. */
837                 c2 = vld1q_u64((uint64_t *)(p2 + 48));
838                 /* B.0 (CQE 1) load a block having op_own. */
839                 c1 = vld1q_u64((uint64_t *)(p1 + 48));
840                 /* B.0 (CQE 0) load a block having op_own. */
841                 c0 = vld1q_u64((uint64_t *)(p0 + 48));
842                 /* Synchronize for loading the rest of blocks. */
843                 rte_cio_rmb();
844                 /* Prefetch next 4 CQEs. */
845                 if (pkts_n - pos >= 2 * MLX5_VPMD_DESCS_PER_LOOP) {
846                         unsigned int next = pos + MLX5_VPMD_DESCS_PER_LOOP;
847                         rte_prefetch_non_temporal(&cq[next]);
848                         rte_prefetch_non_temporal(&cq[next + 1]);
849                         rte_prefetch_non_temporal(&cq[next + 2]);
850                         rte_prefetch_non_temporal(&cq[next + 3]);
851                 }
852                 __asm__ volatile (
853                 /* B.1 (CQE 3) load the rest of blocks. */
854                 "ld1 {v16.16b - v18.16b}, [%[p3]] \n\t"
855                 /* B.2 (CQE 3) move the block having op_own. */
856                 "mov v19.16b, %[c3].16b \n\t"
857                 /* B.3 (CQE 3) extract 16B fields. */
858                 "tbl v23.16b, {v16.16b - v19.16b}, %[cqe_shuf_m].16b \n\t"
859                 /* B.1 (CQE 2) load the rest of blocks. */
860                 "ld1 {v16.16b - v18.16b}, [%[p2]] \n\t"
861                 /* B.4 (CQE 3) adjust CRC length. */
862                 "sub v23.8h, v23.8h, %[crc_adj].8h \n\t"
863                 /* C.1 (CQE 3) generate final structure for mbuf. */
864                 "tbl v15.16b, {v23.16b}, %[mb_shuf_m].16b \n\t"
865                 /* B.2 (CQE 2) move the block having op_own. */
866                 "mov v19.16b, %[c2].16b \n\t"
867                 /* B.3 (CQE 2) extract 16B fields. */
868                 "tbl v22.16b, {v16.16b - v19.16b}, %[cqe_shuf_m].16b \n\t"
869                 /* B.1 (CQE 1) load the rest of blocks. */
870                 "ld1 {v16.16b - v18.16b}, [%[p1]] \n\t"
871                 /* B.4 (CQE 2) adjust CRC length. */
872                 "sub v22.8h, v22.8h, %[crc_adj].8h \n\t"
873                 /* C.1 (CQE 2) generate final structure for mbuf. */
874                 "tbl v14.16b, {v22.16b}, %[mb_shuf_m].16b \n\t"
875                 /* B.2 (CQE 1) move the block having op_own. */
876                 "mov v19.16b, %[c1].16b \n\t"
877                 /* B.3 (CQE 1) extract 16B fields. */
878                 "tbl v21.16b, {v16.16b - v19.16b}, %[cqe_shuf_m].16b \n\t"
879                 /* B.1 (CQE 0) load the rest of blocks. */
880                 "ld1 {v16.16b - v18.16b}, [%[p0]] \n\t"
881                 /* B.4 (CQE 1) adjust CRC length. */
882                 "sub v21.8h, v21.8h, %[crc_adj].8h \n\t"
883                 /* C.1 (CQE 1) generate final structure for mbuf. */
884                 "tbl v13.16b, {v21.16b}, %[mb_shuf_m].16b \n\t"
885                 /* B.2 (CQE 0) move the block having op_own. */
886                 "mov v19.16b, %[c0].16b \n\t"
887                 /* A.1 load mbuf pointers. */
888                 "ld1 {v24.2d - v25.2d}, [%[elts_p]] \n\t"
889                 /* B.3 (CQE 0) extract 16B fields. */
890                 "tbl v20.16b, {v16.16b - v19.16b}, %[cqe_shuf_m].16b \n\t"
891                 /* B.4 (CQE 0) adjust CRC length. */
892                 "sub v20.8h, v20.8h, %[crc_adj].8h \n\t"
893                 /* D.1 extract op_own byte. */
894                 "tbl %[op_own].8b, {v20.16b - v23.16b}, %[owner_shuf_m].8b \n\t"
895                 /* C.2 (CQE 3) adjust flow mark. */
896                 "add v15.4s, v15.4s, %[flow_mark_adj].4s \n\t"
897                 /* C.3 (CQE 3) fill in mbuf - rx_descriptor_fields1. */
898                 "st1 {v15.2d}, [%[e3]] \n\t"
899                 /* C.2 (CQE 2) adjust flow mark. */
900                 "add v14.4s, v14.4s, %[flow_mark_adj].4s \n\t"
901                 /* C.3 (CQE 2) fill in mbuf - rx_descriptor_fields1. */
902                 "st1 {v14.2d}, [%[e2]] \n\t"
903                 /* C.1 (CQE 0) generate final structure for mbuf. */
904                 "tbl v12.16b, {v20.16b}, %[mb_shuf_m].16b \n\t"
905                 /* C.2 (CQE 1) adjust flow mark. */
906                 "add v13.4s, v13.4s, %[flow_mark_adj].4s \n\t"
907                 /* C.3 (CQE 1) fill in mbuf - rx_descriptor_fields1. */
908                 "st1 {v13.2d}, [%[e1]] \n\t"
909 #ifdef MLX5_PMD_SOFT_COUNTERS
910                 /* Extract byte_cnt. */
911                 "tbl %[byte_cnt].8b, {v20.16b - v23.16b}, %[len_shuf_m].8b \n\t"
912 #endif
913                 /* Extract ptype_info. */
914                 "tbl %[ptype_info].16b, {v20.16b - v23.16b}, %[ptype_shuf_m].16b \n\t"
915                 /* Extract flow_tag. */
916                 "tbl %[flow_tag].16b, {v20.16b - v23.16b}, %[ftag_shuf_m].16b \n\t"
917                 /* A.2 copy mbuf pointers. */
918                 "st1 {v24.2d - v25.2d}, [%[pkts_p]] \n\t"
919                 /* C.2 (CQE 0) adjust flow mark. */
920                 "add v12.4s, v12.4s, %[flow_mark_adj].4s \n\t"
921                 /* C.3 (CQE 1) fill in mbuf - rx_descriptor_fields1. */
922                 "st1 {v12.2d}, [%[e0]] \n\t"
923                 :[op_own]"=&w"(op_own),
924                  [byte_cnt]"=&w"(byte_cnt),
925                  [ptype_info]"=&w"(ptype_info),
926                  [flow_tag]"=&w"(flow_tag)
927                 :[p3]"r"(p3), [p2]"r"(p2), [p1]"r"(p1), [p0]"r"(p0),
928                  [e3]"r"(e3), [e2]"r"(e2), [e1]"r"(e1), [e0]"r"(e0),
929                  [c3]"w"(c3), [c2]"w"(c2), [c1]"w"(c1), [c0]"w"(c0),
930                  [elts_p]"r"(elts_p),
931                  [pkts_p]"r"(pkts_p),
932                  [cqe_shuf_m]"w"(cqe_shuf_m),
933                  [mb_shuf_m]"w"(mb_shuf_m),
934                  [owner_shuf_m]"w"(owner_shuf_m),
935                  [len_shuf_m]"w"(len_shuf_m),
936                  [ptype_shuf_m]"w"(ptype_shuf_m),
937                  [ftag_shuf_m]"w"(ftag_shuf_m),
938                  [crc_adj]"w"(crc_adj),
939                  [flow_mark_adj]"w"(flow_mark_adj)
940                 :"memory",
941                  "v12", "v13", "v14", "v15",
942                  "v16", "v17", "v18", "v19",
943                  "v20", "v21", "v22", "v23",
944                  "v24", "v25");
945                 /* D.2 flip owner bit to mark CQEs from last round. */
946                 owner_mask = vand_u16(op_own, owner_check);
947                 owner_mask = vceq_u16(owner_mask, ownership);
948                 /* D.3 get mask for invalidated CQEs. */
949                 opcode = vand_u16(op_own, opcode_check);
950                 invalid_mask = vceq_u16(opcode_check, opcode);
951                 /* E.1 find compressed CQE format. */
952                 comp_mask = vand_u16(op_own, format_check);
953                 comp_mask = vceq_u16(comp_mask, format_check);
954                 /* D.4 mask out beyond boundary. */
955                 invalid_mask = vorr_u16(invalid_mask, mask);
956                 /* D.5 merge invalid_mask with invalid owner. */
957                 invalid_mask = vorr_u16(invalid_mask, owner_mask);
958                 /* E.2 mask out invalid entries. */
959                 comp_mask = vbic_u16(comp_mask, invalid_mask);
960                 /* E.3 get the first compressed CQE. */
961                 comp_idx = __builtin_clzl(vget_lane_u64(vreinterpret_u64_u16(
962                                           comp_mask), 0)) /
963                                           (sizeof(uint16_t) * 8);
964                 /* D.6 mask out entries after the compressed CQE. */
965                 mask = vcreate_u16(comp_idx < MLX5_VPMD_DESCS_PER_LOOP ?
966                                    -1UL >> (comp_idx * sizeof(uint16_t) * 8) :
967                                    0);
968                 invalid_mask = vorr_u16(invalid_mask, mask);
969                 /* D.7 count non-compressed valid CQEs. */
970                 n = __builtin_clzl(vget_lane_u64(vreinterpret_u64_u16(
971                                    invalid_mask), 0)) / (sizeof(uint16_t) * 8);
972                 nocmp_n += n;
973                 /* D.2 get the final invalid mask. */
974                 mask = vcreate_u16(n < MLX5_VPMD_DESCS_PER_LOOP ?
975                                    -1UL >> (n * sizeof(uint16_t) * 8) : 0);
976                 invalid_mask = vorr_u16(invalid_mask, mask);
977                 /* D.3 check error in opcode. */
978                 opcode = vceq_u16(resp_err_check, opcode);
979                 opcode = vbic_u16(opcode, invalid_mask);
980                 /* D.4 mark if any error is set */
981                 *err |= vget_lane_u64(vreinterpret_u64_u16(opcode), 0);
982                 /* C.4 fill in mbuf - rearm_data and packet_type. */
983                 rxq_cq_to_ptype_oflags_v(rxq, ptype_info, flow_tag,
984                                          opcode, &elts[pos]);
985                 if (rxq->hw_timestamp) {
986                         elts[pos]->timestamp =
987                                 rte_be_to_cpu_64(
988                                         container_of(p0, struct mlx5_cqe,
989                                                      pkt_info)->timestamp);
990                         elts[pos + 1]->timestamp =
991                                 rte_be_to_cpu_64(
992                                         container_of(p1, struct mlx5_cqe,
993                                                      pkt_info)->timestamp);
994                         elts[pos + 2]->timestamp =
995                                 rte_be_to_cpu_64(
996                                         container_of(p2, struct mlx5_cqe,
997                                                      pkt_info)->timestamp);
998                         elts[pos + 3]->timestamp =
999                                 rte_be_to_cpu_64(
1000                                         container_of(p3, struct mlx5_cqe,
1001                                                      pkt_info)->timestamp);
1002                 }
1003 #ifdef MLX5_PMD_SOFT_COUNTERS
1004                 /* Add up received bytes count. */
1005                 byte_cnt = vbic_u16(byte_cnt, invalid_mask);
1006                 rcvd_byte += vget_lane_u64(vpaddl_u32(vpaddl_u16(byte_cnt)), 0);
1007 #endif
1008                 /*
1009                  * Break the loop unless more valid CQE is expected, or if
1010                  * there's a compressed CQE.
1011                  */
1012                 if (n != MLX5_VPMD_DESCS_PER_LOOP)
1013                         break;
1014         }
1015         /* If no new CQE seen, return without updating cq_db. */
1016         if (unlikely(!nocmp_n && comp_idx == MLX5_VPMD_DESCS_PER_LOOP))
1017                 return rcvd_pkt;
1018         /* Update the consumer indexes for non-compressed CQEs. */
1019         assert(nocmp_n <= pkts_n);
1020         rxq->cq_ci += nocmp_n;
1021         rxq->rq_pi += nocmp_n;
1022         rcvd_pkt += nocmp_n;
1023 #ifdef MLX5_PMD_SOFT_COUNTERS
1024         rxq->stats.ipackets += nocmp_n;
1025         rxq->stats.ibytes += rcvd_byte;
1026 #endif
1027         /* Decompress the last CQE if compressed. */
1028         if (comp_idx < MLX5_VPMD_DESCS_PER_LOOP && comp_idx == n) {
1029                 assert(comp_idx == (nocmp_n % MLX5_VPMD_DESCS_PER_LOOP));
1030                 rxq_cq_decompress_v(rxq, &cq[nocmp_n], &elts[nocmp_n]);
1031                 /* Return more packets if needed. */
1032                 if (nocmp_n < pkts_n) {
1033                         uint16_t n = rxq->cq_ci - rxq->rq_pi;
1034
1035                         n = RTE_MIN(n, pkts_n - nocmp_n);
1036                         rxq_copy_mbuf_v(rxq, &pkts[nocmp_n], n);
1037                         rxq->rq_pi += n;
1038                         rcvd_pkt += n;
1039                 }
1040         }
1041         rte_compiler_barrier();
1042         *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1043         return rcvd_pkt;
1044 }
1045
1046 #endif /* RTE_PMD_MLX5_RXTX_VEC_NEON_H_ */