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