New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / net / mlx5 / mlx5_rxtx_vec_sse.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_SSE_H_
35 #define RTE_PMD_MLX5_RXTX_VEC_SSE_H_
36
37 #include <assert.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <stdlib.h>
41 #include <smmintrin.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 #ifndef __INTEL_COMPILER
56 #pragma GCC diagnostic ignored "-Wcast-qual"
57 #endif
58
59 /**
60  * Fill in buffer descriptors in a multi-packet send descriptor.
61  *
62  * @param txq
63  *   Pointer to TX queue structure.
64  * @param dseg
65  *   Pointer to buffer descriptor to be written.
66  * @param pkts
67  *   Pointer to array of packets to be sent.
68  * @param n
69  *   Number of packets to be filled.
70  */
71 static inline void
72 txq_wr_dseg_v(struct mlx5_txq_data *txq, __m128i *dseg,
73               struct rte_mbuf **pkts, unsigned int n)
74 {
75         unsigned int pos;
76         uintptr_t addr;
77         const __m128i shuf_mask_dseg =
78                 _mm_set_epi8(8,  9, 10, 11, /* addr, bswap64 */
79                             12, 13, 14, 15,
80                              7,  6,  5,  4, /* lkey */
81                              0,  1,  2,  3  /* length, bswap32 */);
82 #ifdef MLX5_PMD_SOFT_COUNTERS
83         uint32_t tx_byte = 0;
84 #endif
85
86         for (pos = 0; pos < n; ++pos, ++dseg) {
87                 __m128i desc;
88                 struct rte_mbuf *pkt = pkts[pos];
89
90                 addr = rte_pktmbuf_mtod(pkt, uintptr_t);
91                 desc = _mm_set_epi32(addr >> 32,
92                                      addr,
93                                      mlx5_tx_mb2mr(txq, pkt),
94                                      DATA_LEN(pkt));
95                 desc = _mm_shuffle_epi8(desc, shuf_mask_dseg);
96                 _mm_store_si128(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         if (unlikely(!pkts_n))
139                 return 0;
140         for (n = 0; n < pkts_n; ++n) {
141                 struct rte_mbuf *buf = pkts[n];
142                 unsigned int segs_n = buf->nb_segs;
143                 unsigned int ds = nb_dword_in_hdr;
144                 unsigned int len = PKT_LEN(buf);
145                 uint16_t wqe_ci = txq->wqe_ci;
146                 const __m128i shuf_mask_ctrl =
147                         _mm_set_epi8(15, 14, 13, 12,
148                                       8,  9, 10, 11, /* bswap32 */
149                                       4,  5,  6,  7, /* bswap32 */
150                                       0,  1,  2,  3  /* bswap32 */);
151                 uint8_t cs_flags = 0;
152                 uint16_t max_elts;
153                 uint16_t max_wqe;
154                 __m128i *t_wqe, *dseg;
155                 __m128i ctrl;
156
157                 assert(segs_n);
158                 max_elts = elts_n - (elts_head - txq->elts_tail);
159                 max_wqe = wq_n - (txq->wqe_ci - txq->wqe_pi);
160                 /*
161                  * A MPW session consumes 2 WQEs at most to
162                  * include MLX5_MPW_DSEG_MAX pointers.
163                  */
164                 if (segs_n == 1 ||
165                     max_elts < segs_n || max_wqe < 2)
166                         break;
167                 if (segs_n > MLX5_MPW_DSEG_MAX) {
168                         txq->stats.oerrors++;
169                         break;
170                 }
171                 wqe = &((volatile struct mlx5_wqe64 *)
172                          txq->wqes)[wqe_ci & wq_mask].hdr;
173                 if (buf->ol_flags &
174                      (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
175                         const uint64_t is_tunneled =
176                                 buf->ol_flags & (PKT_TX_TUNNEL_GRE |
177                                                  PKT_TX_TUNNEL_VXLAN);
178
179                         if (is_tunneled && txq->tunnel_en) {
180                                 cs_flags = MLX5_ETH_WQE_L3_INNER_CSUM |
181                                            MLX5_ETH_WQE_L4_INNER_CSUM;
182                                 if (buf->ol_flags & PKT_TX_OUTER_IP_CKSUM)
183                                         cs_flags |= MLX5_ETH_WQE_L3_CSUM;
184                         } else {
185                                 cs_flags = MLX5_ETH_WQE_L3_CSUM |
186                                            MLX5_ETH_WQE_L4_CSUM;
187                         }
188                 }
189                 /* Title WQEBB pointer. */
190                 t_wqe = (__m128i *)wqe;
191                 dseg = (__m128i *)(wqe + 1);
192                 do {
193                         if (!(ds++ % nb_dword_per_wqebb)) {
194                                 dseg = (__m128i *)
195                                         &((volatile struct mlx5_wqe64 *)
196                                            txq->wqes)[++wqe_ci & wq_mask];
197                         }
198                         txq_wr_dseg_v(txq, dseg++, &buf, 1);
199                         (*txq->elts)[elts_head++ & elts_m] = buf;
200                         buf = buf->next;
201                 } while (--segs_n);
202                 ++wqe_ci;
203                 /* Fill CTRL in the header. */
204                 ctrl = _mm_set_epi32(0, 0, txq->qp_num_8s | ds,
205                                      MLX5_OPC_MOD_MPW << 24 |
206                                      txq->wqe_ci << 8 | MLX5_OPCODE_TSO);
207                 ctrl = _mm_shuffle_epi8(ctrl, shuf_mask_ctrl);
208                 _mm_store_si128(t_wqe, ctrl);
209                 /* Fill ESEG in the header. */
210                 _mm_store_si128(t_wqe + 1,
211                                 _mm_set_epi16(0, 0, 0, 0,
212                                               rte_cpu_to_be_16(len), cs_flags,
213                                               0, 0));
214                 txq->wqe_ci = wqe_ci;
215         }
216         if (!n)
217                 return 0;
218         txq->elts_comp += (uint16_t)(elts_head - txq->elts_head);
219         txq->elts_head = elts_head;
220         if (txq->elts_comp >= MLX5_TX_COMP_THRESH) {
221                 wqe->ctrl[2] = rte_cpu_to_be_32(8);
222                 wqe->ctrl[3] = txq->elts_head;
223                 txq->elts_comp = 0;
224                 ++txq->cq_pi;
225         }
226 #ifdef MLX5_PMD_SOFT_COUNTERS
227         txq->stats.opackets += n;
228 #endif
229         mlx5_tx_dbrec(txq, wqe);
230         return n;
231 }
232
233 /**
234  * Send burst of packets with Enhanced MPW. If it encounters a multi-seg packet,
235  * it returns to make it processed by txq_scatter_v(). All the packets in
236  * the pkts list should be single segment packets having same offload flags.
237  * This must be checked by txq_check_multiseg() and txq_calc_offload().
238  *
239  * @param txq
240  *   Pointer to TX queue structure.
241  * @param pkts
242  *   Pointer to array of packets to be sent.
243  * @param pkts_n
244  *   Number of packets to be sent (<= MLX5_VPMD_TX_MAX_BURST).
245  * @param cs_flags
246  *   Checksum offload flags to be written in the descriptor.
247  *
248  * @return
249  *   Number of packets successfully transmitted (<= pkts_n).
250  */
251 static inline uint16_t
252 txq_burst_v(struct mlx5_txq_data *txq, struct rte_mbuf **pkts, uint16_t pkts_n,
253             uint8_t cs_flags)
254 {
255         struct rte_mbuf **elts;
256         uint16_t elts_head = txq->elts_head;
257         const uint16_t elts_n = 1 << txq->elts_n;
258         const uint16_t elts_m = elts_n - 1;
259         const unsigned int nb_dword_per_wqebb =
260                 MLX5_WQE_SIZE / MLX5_WQE_DWORD_SIZE;
261         const unsigned int nb_dword_in_hdr =
262                 sizeof(struct mlx5_wqe) / MLX5_WQE_DWORD_SIZE;
263         unsigned int n = 0;
264         unsigned int pos;
265         uint16_t max_elts;
266         uint16_t max_wqe;
267         uint32_t comp_req = 0;
268         const uint16_t wq_n = 1 << txq->wqe_n;
269         const uint16_t wq_mask = wq_n - 1;
270         uint16_t wq_idx = txq->wqe_ci & wq_mask;
271         volatile struct mlx5_wqe64 *wq =
272                 &((volatile struct mlx5_wqe64 *)txq->wqes)[wq_idx];
273         volatile struct mlx5_wqe *wqe = (volatile struct mlx5_wqe *)wq;
274         const __m128i shuf_mask_ctrl =
275                 _mm_set_epi8(15, 14, 13, 12,
276                               8,  9, 10, 11, /* bswap32 */
277                               4,  5,  6,  7, /* bswap32 */
278                               0,  1,  2,  3  /* bswap32 */);
279         __m128i *t_wqe, *dseg;
280         __m128i ctrl;
281
282         /* Make sure all packets can fit into a single WQE. */
283         assert(elts_n > pkts_n);
284         mlx5_tx_complete(txq);
285         max_elts = (elts_n - (elts_head - txq->elts_tail));
286         max_wqe = (1u << txq->wqe_n) - (txq->wqe_ci - txq->wqe_pi);
287         pkts_n = RTE_MIN((unsigned int)RTE_MIN(pkts_n, max_wqe), max_elts);
288         assert(pkts_n <= MLX5_DSEG_MAX - nb_dword_in_hdr);
289         if (unlikely(!pkts_n))
290                 return 0;
291         elts = &(*txq->elts)[elts_head & elts_m];
292         /* Loop for available tailroom first. */
293         n = RTE_MIN(elts_n - (elts_head & elts_m), pkts_n);
294         for (pos = 0; pos < (n & -2); pos += 2)
295                 _mm_storeu_si128((__m128i *)&elts[pos],
296                                  _mm_loadu_si128((__m128i *)&pkts[pos]));
297         if (n & 1)
298                 elts[pos] = pkts[pos];
299         /* Check if it crosses the end of the queue. */
300         if (unlikely(n < pkts_n)) {
301                 elts = &(*txq->elts)[0];
302                 for (pos = 0; pos < pkts_n - n; ++pos)
303                         elts[pos] = pkts[n + pos];
304         }
305         txq->elts_head += pkts_n;
306         /* Save title WQEBB pointer. */
307         t_wqe = (__m128i *)wqe;
308         dseg = (__m128i *)(wqe + 1);
309         /* Calculate the number of entries to the end. */
310         n = RTE_MIN(
311                 (wq_n - wq_idx) * nb_dword_per_wqebb - nb_dword_in_hdr,
312                 pkts_n);
313         /* Fill DSEGs. */
314         txq_wr_dseg_v(txq, dseg, pkts, n);
315         /* Check if it crosses the end of the queue. */
316         if (n < pkts_n) {
317                 dseg = (__m128i *)txq->wqes;
318                 txq_wr_dseg_v(txq, dseg, &pkts[n], pkts_n - n);
319         }
320         if (txq->elts_comp + pkts_n < MLX5_TX_COMP_THRESH) {
321                 txq->elts_comp += pkts_n;
322         } else {
323                 /* Request a completion. */
324                 txq->elts_comp = 0;
325                 ++txq->cq_pi;
326                 comp_req = 8;
327         }
328         /* Fill CTRL in the header. */
329         ctrl = _mm_set_epi32(txq->elts_head, comp_req,
330                              txq->qp_num_8s | (pkts_n + 2),
331                              MLX5_OPC_MOD_ENHANCED_MPSW << 24 |
332                                 txq->wqe_ci << 8 | MLX5_OPCODE_ENHANCED_MPSW);
333         ctrl = _mm_shuffle_epi8(ctrl, shuf_mask_ctrl);
334         _mm_store_si128(t_wqe, ctrl);
335         /* Fill ESEG in the header. */
336         _mm_store_si128(t_wqe + 1,
337                         _mm_set_epi8(0, 0, 0, 0,
338                                      0, 0, 0, 0,
339                                      0, 0, 0, cs_flags,
340                                      0, 0, 0, 0));
341 #ifdef MLX5_PMD_SOFT_COUNTERS
342         txq->stats.opackets += pkts_n;
343 #endif
344         txq->wqe_ci += (nb_dword_in_hdr + pkts_n + (nb_dword_per_wqebb - 1)) /
345                        nb_dword_per_wqebb;
346         /* Ring QP doorbell. */
347         mlx5_tx_dbrec_cond_wmb(txq, wqe, pkts_n < MLX5_VPMD_TX_MAX_BURST);
348         return pkts_n;
349 }
350
351 /**
352  * Store free buffers to RX SW ring.
353  *
354  * @param rxq
355  *   Pointer to RX queue structure.
356  * @param pkts
357  *   Pointer to array of packets to be stored.
358  * @param pkts_n
359  *   Number of packets to be stored.
360  */
361 static inline void
362 rxq_copy_mbuf_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts, uint16_t n)
363 {
364         const uint16_t q_mask = (1 << rxq->elts_n) - 1;
365         struct rte_mbuf **elts = &(*rxq->elts)[rxq->rq_pi & q_mask];
366         unsigned int pos;
367         uint16_t p = n & -2;
368
369         for (pos = 0; pos < p; pos += 2) {
370                 __m128i mbp;
371
372                 mbp = _mm_loadu_si128((__m128i *)&elts[pos]);
373                 _mm_storeu_si128((__m128i *)&pkts[pos], mbp);
374         }
375         if (n & 1)
376                 pkts[pos] = elts[pos];
377 }
378
379 /**
380  * Decompress a compressed completion and fill in mbufs in RX SW ring with data
381  * extracted from the title completion descriptor.
382  *
383  * @param rxq
384  *   Pointer to RX queue structure.
385  * @param cq
386  *   Pointer to completion array having a compressed completion at first.
387  * @param elts
388  *   Pointer to SW ring to be filled. The first mbuf has to be pre-built from
389  *   the title completion descriptor to be copied to the rest of mbufs.
390  */
391 static inline void
392 rxq_cq_decompress_v(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cq,
393                     struct rte_mbuf **elts)
394 {
395         volatile struct mlx5_mini_cqe8 *mcq = (void *)(cq + 1);
396         struct rte_mbuf *t_pkt = elts[0]; /* Title packet is pre-built. */
397         unsigned int pos;
398         unsigned int i;
399         unsigned int inv = 0;
400         /* Mask to shuffle from extracted mini CQE to mbuf. */
401         const __m128i shuf_mask1 =
402                 _mm_set_epi8(0,  1,  2,  3, /* rss, bswap32 */
403                             -1, -1,         /* skip vlan_tci */
404                              6,  7,         /* data_len, bswap16 */
405                             -1, -1,  6,  7, /* pkt_len, bswap16 */
406                             -1, -1, -1, -1  /* skip packet_type */);
407         const __m128i shuf_mask2 =
408                 _mm_set_epi8(8,  9, 10, 11, /* rss, bswap32 */
409                             -1, -1,         /* skip vlan_tci */
410                             14, 15,         /* data_len, bswap16 */
411                             -1, -1, 14, 15, /* pkt_len, bswap16 */
412                             -1, -1, -1, -1  /* skip packet_type */);
413         /* Restore the compressed count. Must be 16 bits. */
414         const uint16_t mcqe_n = t_pkt->data_len +
415                                 (rxq->crc_present * ETHER_CRC_LEN);
416         const __m128i rearm =
417                 _mm_loadu_si128((__m128i *)&t_pkt->rearm_data);
418         const __m128i rxdf =
419                 _mm_loadu_si128((__m128i *)&t_pkt->rx_descriptor_fields1);
420         const __m128i crc_adj =
421                 _mm_set_epi16(0, 0, 0,
422                               rxq->crc_present * ETHER_CRC_LEN,
423                               0,
424                               rxq->crc_present * ETHER_CRC_LEN,
425                               0, 0);
426         const uint32_t flow_tag = t_pkt->hash.fdir.hi;
427 #ifdef MLX5_PMD_SOFT_COUNTERS
428         const __m128i zero = _mm_setzero_si128();
429         const __m128i ones = _mm_cmpeq_epi32(zero, zero);
430         uint32_t rcvd_byte = 0;
431         /* Mask to shuffle byte_cnt to add up stats. Do bswap16 for all. */
432         const __m128i len_shuf_mask =
433                 _mm_set_epi8(-1, -1, -1, -1,
434                              -1, -1, -1, -1,
435                              14, 15,  6,  7,
436                              10, 11,  2,  3);
437 #endif
438
439         /*
440          * A. load mCQEs into a 128bit register.
441          * B. store rearm data to mbuf.
442          * C. combine data from mCQEs with rx_descriptor_fields1.
443          * D. store rx_descriptor_fields1.
444          * E. store flow tag (rte_flow mark).
445          */
446         for (pos = 0; pos < mcqe_n; ) {
447                 __m128i mcqe1, mcqe2;
448                 __m128i rxdf1, rxdf2;
449 #ifdef MLX5_PMD_SOFT_COUNTERS
450                 __m128i byte_cnt, invalid_mask;
451 #endif
452
453                 if (!(pos & 0x7) && pos + 8 < mcqe_n)
454                         rte_prefetch0((void *)(cq + pos + 8));
455                 /* A.1 load mCQEs into a 128bit register. */
456                 mcqe1 = _mm_loadu_si128((__m128i *)&mcq[pos % 8]);
457                 mcqe2 = _mm_loadu_si128((__m128i *)&mcq[pos % 8 + 2]);
458                 /* B.1 store rearm data to mbuf. */
459                 _mm_storeu_si128((__m128i *)&elts[pos]->rearm_data, rearm);
460                 _mm_storeu_si128((__m128i *)&elts[pos + 1]->rearm_data, rearm);
461                 /* C.1 combine data from mCQEs with rx_descriptor_fields1. */
462                 rxdf1 = _mm_shuffle_epi8(mcqe1, shuf_mask1);
463                 rxdf2 = _mm_shuffle_epi8(mcqe1, shuf_mask2);
464                 rxdf1 = _mm_sub_epi16(rxdf1, crc_adj);
465                 rxdf2 = _mm_sub_epi16(rxdf2, crc_adj);
466                 rxdf1 = _mm_blend_epi16(rxdf1, rxdf, 0x23);
467                 rxdf2 = _mm_blend_epi16(rxdf2, rxdf, 0x23);
468                 /* D.1 store rx_descriptor_fields1. */
469                 _mm_storeu_si128((__m128i *)
470                                   &elts[pos]->rx_descriptor_fields1,
471                                  rxdf1);
472                 _mm_storeu_si128((__m128i *)
473                                   &elts[pos + 1]->rx_descriptor_fields1,
474                                  rxdf2);
475                 /* B.1 store rearm data to mbuf. */
476                 _mm_storeu_si128((__m128i *)&elts[pos + 2]->rearm_data, rearm);
477                 _mm_storeu_si128((__m128i *)&elts[pos + 3]->rearm_data, rearm);
478                 /* C.1 combine data from mCQEs with rx_descriptor_fields1. */
479                 rxdf1 = _mm_shuffle_epi8(mcqe2, shuf_mask1);
480                 rxdf2 = _mm_shuffle_epi8(mcqe2, shuf_mask2);
481                 rxdf1 = _mm_sub_epi16(rxdf1, crc_adj);
482                 rxdf2 = _mm_sub_epi16(rxdf2, crc_adj);
483                 rxdf1 = _mm_blend_epi16(rxdf1, rxdf, 0x23);
484                 rxdf2 = _mm_blend_epi16(rxdf2, rxdf, 0x23);
485                 /* D.1 store rx_descriptor_fields1. */
486                 _mm_storeu_si128((__m128i *)
487                                   &elts[pos + 2]->rx_descriptor_fields1,
488                                  rxdf1);
489                 _mm_storeu_si128((__m128i *)
490                                   &elts[pos + 3]->rx_descriptor_fields1,
491                                  rxdf2);
492 #ifdef MLX5_PMD_SOFT_COUNTERS
493                 invalid_mask = _mm_set_epi64x(0,
494                                               (mcqe_n - pos) *
495                                               sizeof(uint16_t) * 8);
496                 invalid_mask = _mm_sll_epi64(ones, invalid_mask);
497                 mcqe1 = _mm_srli_si128(mcqe1, 4);
498                 byte_cnt = _mm_blend_epi16(mcqe1, mcqe2, 0xcc);
499                 byte_cnt = _mm_shuffle_epi8(byte_cnt, len_shuf_mask);
500                 byte_cnt = _mm_andnot_si128(invalid_mask, byte_cnt);
501                 byte_cnt = _mm_hadd_epi16(byte_cnt, zero);
502                 rcvd_byte += _mm_cvtsi128_si64(_mm_hadd_epi16(byte_cnt, zero));
503 #endif
504                 if (rxq->mark) {
505                         /* E.1 store flow tag (rte_flow mark). */
506                         elts[pos]->hash.fdir.hi = flow_tag;
507                         elts[pos + 1]->hash.fdir.hi = flow_tag;
508                         elts[pos + 2]->hash.fdir.hi = flow_tag;
509                         elts[pos + 3]->hash.fdir.hi = flow_tag;
510                 }
511                 pos += MLX5_VPMD_DESCS_PER_LOOP;
512                 /* Move to next CQE and invalidate consumed CQEs. */
513                 if (!(pos & 0x7) && pos < mcqe_n) {
514                         mcq = (void *)(cq + pos);
515                         for (i = 0; i < 8; ++i)
516                                 cq[inv++].op_own = MLX5_CQE_INVALIDATE;
517                 }
518         }
519         /* Invalidate the rest of CQEs. */
520         for (; inv < mcqe_n; ++inv)
521                 cq[inv].op_own = MLX5_CQE_INVALIDATE;
522 #ifdef MLX5_PMD_SOFT_COUNTERS
523         rxq->stats.ipackets += mcqe_n;
524         rxq->stats.ibytes += rcvd_byte;
525 #endif
526         rxq->cq_ci += mcqe_n;
527 }
528
529 /**
530  * Calculate packet type and offload flag for mbuf and store it.
531  *
532  * @param rxq
533  *   Pointer to RX queue structure.
534  * @param cqes[4]
535  *   Array of four 16bytes completions extracted from the original completion
536  *   descriptor.
537  * @param op_err
538  *   Opcode vector having responder error status. Each field is 4B.
539  * @param pkts
540  *   Pointer to array of packets to be filled.
541  */
542 static inline void
543 rxq_cq_to_ptype_oflags_v(struct mlx5_rxq_data *rxq, __m128i cqes[4],
544                          __m128i op_err, struct rte_mbuf **pkts)
545 {
546         __m128i pinfo0, pinfo1;
547         __m128i pinfo, ptype;
548         __m128i ol_flags = _mm_set1_epi32(rxq->rss_hash * PKT_RX_RSS_HASH |
549                                           rxq->hw_timestamp * PKT_RX_TIMESTAMP);
550         __m128i cv_flags;
551         const __m128i zero = _mm_setzero_si128();
552         const __m128i ptype_mask =
553                 _mm_set_epi32(0xfd06, 0xfd06, 0xfd06, 0xfd06);
554         const __m128i ptype_ol_mask =
555                 _mm_set_epi32(0x106, 0x106, 0x106, 0x106);
556         const __m128i pinfo_mask =
557                 _mm_set_epi32(0x3, 0x3, 0x3, 0x3);
558         const __m128i cv_flag_sel =
559                 _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0,
560                              (uint8_t)((PKT_RX_IP_CKSUM_GOOD |
561                                         PKT_RX_L4_CKSUM_GOOD) >> 1),
562                              0,
563                              (uint8_t)(PKT_RX_L4_CKSUM_GOOD >> 1),
564                              0,
565                              (uint8_t)(PKT_RX_IP_CKSUM_GOOD >> 1),
566                              (uint8_t)(PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED),
567                              0);
568         const __m128i cv_mask =
569                 _mm_set_epi32(PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
570                               PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
571                               PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
572                               PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
573                               PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
574                               PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
575                               PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
576                               PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED);
577         const __m128i mbuf_init =
578                 _mm_loadl_epi64((__m128i *)&rxq->mbuf_initializer);
579         __m128i rearm0, rearm1, rearm2, rearm3;
580
581         /* Extract pkt_info field. */
582         pinfo0 = _mm_unpacklo_epi32(cqes[0], cqes[1]);
583         pinfo1 = _mm_unpacklo_epi32(cqes[2], cqes[3]);
584         pinfo = _mm_unpacklo_epi64(pinfo0, pinfo1);
585         /* Extract hdr_type_etc field. */
586         pinfo0 = _mm_unpackhi_epi32(cqes[0], cqes[1]);
587         pinfo1 = _mm_unpackhi_epi32(cqes[2], cqes[3]);
588         ptype = _mm_unpacklo_epi64(pinfo0, pinfo1);
589         if (rxq->mark) {
590                 const __m128i pinfo_ft_mask =
591                         _mm_set_epi32(0xffffff00, 0xffffff00,
592                                       0xffffff00, 0xffffff00);
593                 const __m128i fdir_flags = _mm_set1_epi32(PKT_RX_FDIR);
594                 const __m128i fdir_id_flags = _mm_set1_epi32(PKT_RX_FDIR_ID);
595                 __m128i flow_tag, invalid_mask;
596
597                 flow_tag = _mm_and_si128(pinfo, pinfo_ft_mask);
598                 /* Check if flow tag is non-zero then set PKT_RX_FDIR. */
599                 invalid_mask = _mm_cmpeq_epi32(flow_tag, zero);
600                 ol_flags = _mm_or_si128(ol_flags,
601                                         _mm_andnot_si128(invalid_mask,
602                                                          fdir_flags));
603                 /* Mask out invalid entries. */
604                 flow_tag = _mm_andnot_si128(invalid_mask, flow_tag);
605                 /* Check if flow tag MLX5_FLOW_MARK_DEFAULT. */
606                 ol_flags = _mm_or_si128(ol_flags,
607                                         _mm_andnot_si128(
608                                                 _mm_cmpeq_epi32(flow_tag,
609                                                                 pinfo_ft_mask),
610                                                 fdir_id_flags));
611         }
612         /*
613          * Merge the two fields to generate the following:
614          * bit[1]     = l3_ok
615          * bit[2]     = l4_ok
616          * bit[8]     = cv
617          * bit[11:10] = l3_hdr_type
618          * bit[14:12] = l4_hdr_type
619          * bit[15]    = ip_frag
620          * bit[16]    = tunneled
621          * bit[17]    = outer_l3_type
622          */
623         ptype = _mm_and_si128(ptype, ptype_mask);
624         pinfo = _mm_and_si128(pinfo, pinfo_mask);
625         pinfo = _mm_slli_epi32(pinfo, 16);
626         /* Make pinfo has merged fields for ol_flags calculation. */
627         pinfo = _mm_or_si128(ptype, pinfo);
628         ptype = _mm_srli_epi32(pinfo, 10);
629         ptype = _mm_packs_epi32(ptype, zero);
630         /* Errored packets will have RTE_PTYPE_ALL_MASK. */
631         op_err = _mm_srli_epi16(op_err, 8);
632         ptype = _mm_or_si128(ptype, op_err);
633         pkts[0]->packet_type = mlx5_ptype_table[_mm_extract_epi8(ptype, 0)];
634         pkts[1]->packet_type = mlx5_ptype_table[_mm_extract_epi8(ptype, 2)];
635         pkts[2]->packet_type = mlx5_ptype_table[_mm_extract_epi8(ptype, 4)];
636         pkts[3]->packet_type = mlx5_ptype_table[_mm_extract_epi8(ptype, 6)];
637         /* Fill flags for checksum and VLAN. */
638         pinfo = _mm_and_si128(pinfo, ptype_ol_mask);
639         pinfo = _mm_shuffle_epi8(cv_flag_sel, pinfo);
640         /* Locate checksum flags at byte[2:1] and merge with VLAN flags. */
641         cv_flags = _mm_slli_epi32(pinfo, 9);
642         cv_flags = _mm_or_si128(pinfo, cv_flags);
643         /* Move back flags to start from byte[0]. */
644         cv_flags = _mm_srli_epi32(cv_flags, 8);
645         /* Mask out garbage bits. */
646         cv_flags = _mm_and_si128(cv_flags, cv_mask);
647         /* Merge to ol_flags. */
648         ol_flags = _mm_or_si128(ol_flags, cv_flags);
649         /* Merge mbuf_init and ol_flags. */
650         rearm0 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(ol_flags, 8), 0x30);
651         rearm1 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(ol_flags, 4), 0x30);
652         rearm2 = _mm_blend_epi16(mbuf_init, ol_flags, 0x30);
653         rearm3 = _mm_blend_epi16(mbuf_init, _mm_srli_si128(ol_flags, 4), 0x30);
654         /* Write 8B rearm_data and 8B ol_flags. */
655         _mm_store_si128((__m128i *)&pkts[0]->rearm_data, rearm0);
656         _mm_store_si128((__m128i *)&pkts[1]->rearm_data, rearm1);
657         _mm_store_si128((__m128i *)&pkts[2]->rearm_data, rearm2);
658         _mm_store_si128((__m128i *)&pkts[3]->rearm_data, rearm3);
659 }
660
661 /**
662  * Receive burst of packets. An errored completion also consumes a mbuf, but the
663  * packet_type is set to be RTE_PTYPE_ALL_MASK. Marked mbufs should be freed
664  * before returning to application.
665  *
666  * @param rxq
667  *   Pointer to RX queue structure.
668  * @param[out] pkts
669  *   Array to store received packets.
670  * @param pkts_n
671  *   Maximum number of packets in array.
672  *
673  * @return
674  *   Number of packets received including errors (<= pkts_n).
675  */
676 static inline uint16_t
677 rxq_burst_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
678 {
679         const uint16_t q_n = 1 << rxq->cqe_n;
680         const uint16_t q_mask = q_n - 1;
681         volatile struct mlx5_cqe *cq;
682         struct rte_mbuf **elts;
683         unsigned int pos;
684         uint64_t n;
685         uint16_t repl_n;
686         uint64_t comp_idx = MLX5_VPMD_DESCS_PER_LOOP;
687         uint16_t nocmp_n = 0;
688         uint16_t rcvd_pkt = 0;
689         unsigned int cq_idx = rxq->cq_ci & q_mask;
690         unsigned int elts_idx;
691         unsigned int ownership = !!(rxq->cq_ci & (q_mask + 1));
692         const __m128i owner_check =
693                 _mm_set_epi64x(0x0100000001000000LL, 0x0100000001000000LL);
694         const __m128i opcode_check =
695                 _mm_set_epi64x(0xf0000000f0000000LL, 0xf0000000f0000000LL);
696         const __m128i format_check =
697                 _mm_set_epi64x(0x0c0000000c000000LL, 0x0c0000000c000000LL);
698         const __m128i resp_err_check =
699                 _mm_set_epi64x(0xe0000000e0000000LL, 0xe0000000e0000000LL);
700 #ifdef MLX5_PMD_SOFT_COUNTERS
701         uint32_t rcvd_byte = 0;
702         /* Mask to shuffle byte_cnt to add up stats. Do bswap16 for all. */
703         const __m128i len_shuf_mask =
704                 _mm_set_epi8(-1, -1, -1, -1,
705                              -1, -1, -1, -1,
706                              12, 13,  8,  9,
707                               4,  5,  0,  1);
708 #endif
709         /* Mask to shuffle from extracted CQE to mbuf. */
710         const __m128i shuf_mask =
711                 _mm_set_epi8(-1,  3,  2,  1, /* fdir.hi */
712                              12, 13, 14, 15, /* rss, bswap32 */
713                              10, 11,         /* vlan_tci, bswap16 */
714                               4,  5,         /* data_len, bswap16 */
715                              -1, -1,         /* zero out 2nd half of pkt_len */
716                               4,  5          /* pkt_len, bswap16 */);
717         /* Mask to blend from the last Qword to the first DQword. */
718         const __m128i blend_mask =
719                 _mm_set_epi8(-1, -1, -1, -1,
720                              -1, -1, -1, -1,
721                               0,  0,  0,  0,
722                               0,  0,  0, -1);
723         const __m128i zero = _mm_setzero_si128();
724         const __m128i ones = _mm_cmpeq_epi32(zero, zero);
725         const __m128i crc_adj =
726                 _mm_set_epi16(0, 0, 0, 0, 0,
727                               rxq->crc_present * ETHER_CRC_LEN,
728                               0,
729                               rxq->crc_present * ETHER_CRC_LEN);
730         const __m128i flow_mark_adj = _mm_set_epi32(rxq->mark * (-1), 0, 0, 0);
731
732         assert(rxq->sges_n == 0);
733         assert(rxq->cqe_n == rxq->elts_n);
734         cq = &(*rxq->cqes)[cq_idx];
735         rte_prefetch0(cq);
736         rte_prefetch0(cq + 1);
737         rte_prefetch0(cq + 2);
738         rte_prefetch0(cq + 3);
739         pkts_n = RTE_MIN(pkts_n, MLX5_VPMD_RX_MAX_BURST);
740         /*
741          * Order of indexes:
742          *   rq_ci >= cq_ci >= rq_pi
743          * Definition of indexes:
744          *   rq_ci - cq_ci := # of buffers owned by HW (posted).
745          *   cq_ci - rq_pi := # of buffers not returned to app (decompressed).
746          *   N - (rq_ci - rq_pi) := # of buffers consumed (to be replenished).
747          */
748         repl_n = q_n - (rxq->rq_ci - rxq->rq_pi);
749         if (repl_n >= MLX5_VPMD_RXQ_RPLNSH_THRESH)
750                 mlx5_rx_replenish_bulk_mbuf(rxq, repl_n);
751         /* See if there're unreturned mbufs from compressed CQE. */
752         rcvd_pkt = rxq->cq_ci - rxq->rq_pi;
753         if (rcvd_pkt > 0) {
754                 rcvd_pkt = RTE_MIN(rcvd_pkt, pkts_n);
755                 rxq_copy_mbuf_v(rxq, pkts, rcvd_pkt);
756                 rxq->rq_pi += rcvd_pkt;
757                 pkts += rcvd_pkt;
758         }
759         elts_idx = rxq->rq_pi & q_mask;
760         elts = &(*rxq->elts)[elts_idx];
761         /* Not to overflow pkts array. */
762         pkts_n = RTE_ALIGN_FLOOR(pkts_n - rcvd_pkt, MLX5_VPMD_DESCS_PER_LOOP);
763         /* Not to cross queue end. */
764         pkts_n = RTE_MIN(pkts_n, q_n - elts_idx);
765         if (!pkts_n)
766                 return rcvd_pkt;
767         /* At this point, there shouldn't be any remained packets. */
768         assert(rxq->rq_pi == rxq->cq_ci);
769         /*
770          * A. load first Qword (8bytes) in one loop.
771          * B. copy 4 mbuf pointers from elts ring to returing pkts.
772          * C. load remained CQE data and extract necessary fields.
773          *    Final 16bytes cqes[] extracted from original 64bytes CQE has the
774          *    following structure:
775          *        struct {
776          *          uint8_t  pkt_info;
777          *          uint8_t  flow_tag[3];
778          *          uint16_t byte_cnt;
779          *          uint8_t  rsvd4;
780          *          uint8_t  op_own;
781          *          uint16_t hdr_type_etc;
782          *          uint16_t vlan_info;
783          *          uint32_t rx_has_res;
784          *        } c;
785          * D. fill in mbuf.
786          * E. get valid CQEs.
787          * F. find compressed CQE.
788          */
789         for (pos = 0;
790              pos < pkts_n;
791              pos += MLX5_VPMD_DESCS_PER_LOOP) {
792                 __m128i cqes[MLX5_VPMD_DESCS_PER_LOOP];
793                 __m128i cqe_tmp1, cqe_tmp2;
794                 __m128i pkt_mb0, pkt_mb1, pkt_mb2, pkt_mb3;
795                 __m128i op_own, op_own_tmp1, op_own_tmp2;
796                 __m128i opcode, owner_mask, invalid_mask;
797                 __m128i comp_mask;
798                 __m128i mask;
799 #ifdef MLX5_PMD_SOFT_COUNTERS
800                 __m128i byte_cnt;
801 #endif
802                 __m128i mbp1, mbp2;
803                 __m128i p = _mm_set_epi16(0, 0, 0, 0, 3, 2, 1, 0);
804                 unsigned int p1, p2, p3;
805
806                 /* Prefetch next 4 CQEs. */
807                 if (pkts_n - pos >= 2 * MLX5_VPMD_DESCS_PER_LOOP) {
808                         rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP]);
809                         rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP + 1]);
810                         rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP + 2]);
811                         rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP + 3]);
812                 }
813                 /* A.0 do not cross the end of CQ. */
814                 mask = _mm_set_epi64x(0, (pkts_n - pos) * sizeof(uint16_t) * 8);
815                 mask = _mm_sll_epi64(ones, mask);
816                 p = _mm_andnot_si128(mask, p);
817                 /* A.1 load cqes. */
818                 p3 = _mm_extract_epi16(p, 3);
819                 cqes[3] = _mm_loadl_epi64((__m128i *)
820                                            &cq[pos + p3].sop_drop_qpn);
821                 rte_compiler_barrier();
822                 p2 = _mm_extract_epi16(p, 2);
823                 cqes[2] = _mm_loadl_epi64((__m128i *)
824                                            &cq[pos + p2].sop_drop_qpn);
825                 rte_compiler_barrier();
826                 /* B.1 load mbuf pointers. */
827                 mbp1 = _mm_loadu_si128((__m128i *)&elts[pos]);
828                 mbp2 = _mm_loadu_si128((__m128i *)&elts[pos + 2]);
829                 /* A.1 load a block having op_own. */
830                 p1 = _mm_extract_epi16(p, 1);
831                 cqes[1] = _mm_loadl_epi64((__m128i *)
832                                            &cq[pos + p1].sop_drop_qpn);
833                 rte_compiler_barrier();
834                 cqes[0] = _mm_loadl_epi64((__m128i *)
835                                            &cq[pos].sop_drop_qpn);
836                 /* B.2 copy mbuf pointers. */
837                 _mm_storeu_si128((__m128i *)&pkts[pos], mbp1);
838                 _mm_storeu_si128((__m128i *)&pkts[pos + 2], mbp2);
839                 rte_compiler_barrier();
840                 /* C.1 load remained CQE data and extract necessary fields. */
841                 cqe_tmp2 = _mm_load_si128((__m128i *)&cq[pos + p3]);
842                 cqe_tmp1 = _mm_load_si128((__m128i *)&cq[pos + p2]);
843                 cqes[3] = _mm_blendv_epi8(cqes[3], cqe_tmp2, blend_mask);
844                 cqes[2] = _mm_blendv_epi8(cqes[2], cqe_tmp1, blend_mask);
845                 cqe_tmp2 = _mm_loadu_si128((__m128i *)&cq[pos + p3].rsvd1[3]);
846                 cqe_tmp1 = _mm_loadu_si128((__m128i *)&cq[pos + p2].rsvd1[3]);
847                 cqes[3] = _mm_blend_epi16(cqes[3], cqe_tmp2, 0x30);
848                 cqes[2] = _mm_blend_epi16(cqes[2], cqe_tmp1, 0x30);
849                 cqe_tmp2 = _mm_loadl_epi64((__m128i *)&cq[pos + p3].rsvd2[10]);
850                 cqe_tmp1 = _mm_loadl_epi64((__m128i *)&cq[pos + p2].rsvd2[10]);
851                 cqes[3] = _mm_blend_epi16(cqes[3], cqe_tmp2, 0x04);
852                 cqes[2] = _mm_blend_epi16(cqes[2], cqe_tmp1, 0x04);
853                 /* C.2 generate final structure for mbuf with swapping bytes. */
854                 pkt_mb3 = _mm_shuffle_epi8(cqes[3], shuf_mask);
855                 pkt_mb2 = _mm_shuffle_epi8(cqes[2], shuf_mask);
856                 /* C.3 adjust CRC length. */
857                 pkt_mb3 = _mm_sub_epi16(pkt_mb3, crc_adj);
858                 pkt_mb2 = _mm_sub_epi16(pkt_mb2, crc_adj);
859                 /* C.4 adjust flow mark. */
860                 pkt_mb3 = _mm_add_epi32(pkt_mb3, flow_mark_adj);
861                 pkt_mb2 = _mm_add_epi32(pkt_mb2, flow_mark_adj);
862                 /* D.1 fill in mbuf - rx_descriptor_fields1. */
863                 _mm_storeu_si128((void *)&pkts[pos + 3]->pkt_len, pkt_mb3);
864                 _mm_storeu_si128((void *)&pkts[pos + 2]->pkt_len, pkt_mb2);
865                 /* E.1 extract op_own field. */
866                 op_own_tmp2 = _mm_unpacklo_epi32(cqes[2], cqes[3]);
867                 /* C.1 load remained CQE data and extract necessary fields. */
868                 cqe_tmp2 = _mm_load_si128((__m128i *)&cq[pos + p1]);
869                 cqe_tmp1 = _mm_load_si128((__m128i *)&cq[pos]);
870                 cqes[1] = _mm_blendv_epi8(cqes[1], cqe_tmp2, blend_mask);
871                 cqes[0] = _mm_blendv_epi8(cqes[0], cqe_tmp1, blend_mask);
872                 cqe_tmp2 = _mm_loadu_si128((__m128i *)&cq[pos + p1].rsvd1[3]);
873                 cqe_tmp1 = _mm_loadu_si128((__m128i *)&cq[pos].rsvd1[3]);
874                 cqes[1] = _mm_blend_epi16(cqes[1], cqe_tmp2, 0x30);
875                 cqes[0] = _mm_blend_epi16(cqes[0], cqe_tmp1, 0x30);
876                 cqe_tmp2 = _mm_loadl_epi64((__m128i *)&cq[pos + p1].rsvd2[10]);
877                 cqe_tmp1 = _mm_loadl_epi64((__m128i *)&cq[pos].rsvd2[10]);
878                 cqes[1] = _mm_blend_epi16(cqes[1], cqe_tmp2, 0x04);
879                 cqes[0] = _mm_blend_epi16(cqes[0], cqe_tmp1, 0x04);
880                 /* C.2 generate final structure for mbuf with swapping bytes. */
881                 pkt_mb1 = _mm_shuffle_epi8(cqes[1], shuf_mask);
882                 pkt_mb0 = _mm_shuffle_epi8(cqes[0], shuf_mask);
883                 /* C.3 adjust CRC length. */
884                 pkt_mb1 = _mm_sub_epi16(pkt_mb1, crc_adj);
885                 pkt_mb0 = _mm_sub_epi16(pkt_mb0, crc_adj);
886                 /* C.4 adjust flow mark. */
887                 pkt_mb1 = _mm_add_epi32(pkt_mb1, flow_mark_adj);
888                 pkt_mb0 = _mm_add_epi32(pkt_mb0, flow_mark_adj);
889                 /* E.1 extract op_own byte. */
890                 op_own_tmp1 = _mm_unpacklo_epi32(cqes[0], cqes[1]);
891                 op_own = _mm_unpackhi_epi64(op_own_tmp1, op_own_tmp2);
892                 /* D.1 fill in mbuf - rx_descriptor_fields1. */
893                 _mm_storeu_si128((void *)&pkts[pos + 1]->pkt_len, pkt_mb1);
894                 _mm_storeu_si128((void *)&pkts[pos]->pkt_len, pkt_mb0);
895                 /* E.2 flip owner bit to mark CQEs from last round. */
896                 owner_mask = _mm_and_si128(op_own, owner_check);
897                 if (ownership)
898                         owner_mask = _mm_xor_si128(owner_mask, owner_check);
899                 owner_mask = _mm_cmpeq_epi32(owner_mask, owner_check);
900                 owner_mask = _mm_packs_epi32(owner_mask, zero);
901                 /* E.3 get mask for invalidated CQEs. */
902                 opcode = _mm_and_si128(op_own, opcode_check);
903                 invalid_mask = _mm_cmpeq_epi32(opcode_check, opcode);
904                 invalid_mask = _mm_packs_epi32(invalid_mask, zero);
905                 /* E.4 mask out beyond boundary. */
906                 invalid_mask = _mm_or_si128(invalid_mask, mask);
907                 /* E.5 merge invalid_mask with invalid owner. */
908                 invalid_mask = _mm_or_si128(invalid_mask, owner_mask);
909                 /* F.1 find compressed CQE format. */
910                 comp_mask = _mm_and_si128(op_own, format_check);
911                 comp_mask = _mm_cmpeq_epi32(comp_mask, format_check);
912                 comp_mask = _mm_packs_epi32(comp_mask, zero);
913                 /* F.2 mask out invalid entries. */
914                 comp_mask = _mm_andnot_si128(invalid_mask, comp_mask);
915                 comp_idx = _mm_cvtsi128_si64(comp_mask);
916                 /* F.3 get the first compressed CQE. */
917                 comp_idx = comp_idx ?
918                                 __builtin_ctzll(comp_idx) /
919                                         (sizeof(uint16_t) * 8) :
920                                 MLX5_VPMD_DESCS_PER_LOOP;
921                 /* E.6 mask out entries after the compressed CQE. */
922                 mask = _mm_set_epi64x(0, comp_idx * sizeof(uint16_t) * 8);
923                 mask = _mm_sll_epi64(ones, mask);
924                 invalid_mask = _mm_or_si128(invalid_mask, mask);
925                 /* E.7 count non-compressed valid CQEs. */
926                 n = _mm_cvtsi128_si64(invalid_mask);
927                 n = n ? __builtin_ctzll(n) / (sizeof(uint16_t) * 8) :
928                         MLX5_VPMD_DESCS_PER_LOOP;
929                 nocmp_n += n;
930                 /* D.2 get the final invalid mask. */
931                 mask = _mm_set_epi64x(0, n * sizeof(uint16_t) * 8);
932                 mask = _mm_sll_epi64(ones, mask);
933                 invalid_mask = _mm_or_si128(invalid_mask, mask);
934                 /* D.3 check error in opcode. */
935                 opcode = _mm_cmpeq_epi32(resp_err_check, opcode);
936                 opcode = _mm_packs_epi32(opcode, zero);
937                 opcode = _mm_andnot_si128(invalid_mask, opcode);
938                 /* D.4 mark if any error is set */
939                 rxq->pending_err |= !!_mm_cvtsi128_si64(opcode);
940                 /* D.5 fill in mbuf - rearm_data and packet_type. */
941                 rxq_cq_to_ptype_oflags_v(rxq, cqes, opcode, &pkts[pos]);
942                 if (rxq->hw_timestamp) {
943                         pkts[pos]->timestamp =
944                                 rte_be_to_cpu_64(cq[pos].timestamp);
945                         pkts[pos + 1]->timestamp =
946                                 rte_be_to_cpu_64(cq[pos + p1].timestamp);
947                         pkts[pos + 2]->timestamp =
948                                 rte_be_to_cpu_64(cq[pos + p2].timestamp);
949                         pkts[pos + 3]->timestamp =
950                                 rte_be_to_cpu_64(cq[pos + p3].timestamp);
951                 }
952 #ifdef MLX5_PMD_SOFT_COUNTERS
953                 /* Add up received bytes count. */
954                 byte_cnt = _mm_shuffle_epi8(op_own, len_shuf_mask);
955                 byte_cnt = _mm_andnot_si128(invalid_mask, byte_cnt);
956                 byte_cnt = _mm_hadd_epi16(byte_cnt, zero);
957                 rcvd_byte += _mm_cvtsi128_si64(_mm_hadd_epi16(byte_cnt, zero));
958 #endif
959                 /*
960                  * Break the loop unless more valid CQE is expected, or if
961                  * there's a compressed CQE.
962                  */
963                 if (n != MLX5_VPMD_DESCS_PER_LOOP)
964                         break;
965         }
966         /* If no new CQE seen, return without updating cq_db. */
967         if (unlikely(!nocmp_n && comp_idx == MLX5_VPMD_DESCS_PER_LOOP))
968                 return rcvd_pkt;
969         /* Update the consumer indexes for non-compressed CQEs. */
970         assert(nocmp_n <= pkts_n);
971         rxq->cq_ci += nocmp_n;
972         rxq->rq_pi += nocmp_n;
973         rcvd_pkt += nocmp_n;
974 #ifdef MLX5_PMD_SOFT_COUNTERS
975         rxq->stats.ipackets += nocmp_n;
976         rxq->stats.ibytes += rcvd_byte;
977 #endif
978         /* Decompress the last CQE if compressed. */
979         if (comp_idx < MLX5_VPMD_DESCS_PER_LOOP && comp_idx == n) {
980                 assert(comp_idx == (nocmp_n % MLX5_VPMD_DESCS_PER_LOOP));
981                 rxq_cq_decompress_v(rxq, &cq[nocmp_n], &elts[nocmp_n]);
982                 /* Return more packets if needed. */
983                 if (nocmp_n < pkts_n) {
984                         uint16_t n = rxq->cq_ci - rxq->rq_pi;
985
986                         n = RTE_MIN(n, pkts_n - nocmp_n);
987                         rxq_copy_mbuf_v(rxq, &pkts[nocmp_n], n);
988                         rxq->rq_pi += n;
989                         rcvd_pkt += n;
990                 }
991         }
992         rte_compiler_barrier();
993         *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
994         return rcvd_pkt;
995 }
996
997 #endif /* RTE_PMD_MLX5_RXTX_VEC_SSE_H_ */