net/bnxt: fix FW version query
[dpdk.git] / drivers / net / mlx5 / mlx5_rxtx_vec_altivec.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2017 6WIND S.A.
3  * Copyright 2017 Mellanox Technologies, Ltd
4  */
5
6 #ifndef RTE_PMD_MLX5_RXTX_VEC_ALTIVEC_H_
7 #define RTE_PMD_MLX5_RXTX_VEC_ALTIVEC_H_
8
9 #include <stdint.h>
10 #include <string.h>
11 #include <stdlib.h>
12
13 #include <rte_altivec.h>
14
15 #include <rte_mbuf.h>
16 #include <rte_mempool.h>
17 #include <rte_prefetch.h>
18
19 #include <mlx5_prm.h>
20
21 #include "mlx5_defs.h"
22 #include "mlx5.h"
23 #include "mlx5_utils.h"
24 #include "mlx5_rxtx.h"
25 #include "mlx5_rxtx_vec.h"
26 #include "mlx5_autoconf.h"
27
28 #ifndef __INTEL_COMPILER
29 #pragma GCC diagnostic ignored "-Wcast-qual"
30 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
31 #endif
32
33 /**
34  * Store free buffers to RX SW ring.
35  *
36  * @param rxq
37  *   Pointer to RX queue structure.
38  * @param pkts
39  *   Pointer to array of packets to be stored.
40  * @param pkts_n
41  *   Number of packets to be stored.
42  */
43 static inline void
44 rxq_copy_mbuf_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts, uint16_t n)
45 {
46         const uint16_t q_mask = (1 << rxq->elts_n) - 1;
47         struct rte_mbuf **elts = &(*rxq->elts)[rxq->rq_pi & q_mask];
48         unsigned int pos;
49         uint16_t p = n & -2;
50
51         for (pos = 0; pos < p; pos += 2) {
52                 vector unsigned char mbp;
53
54                 mbp = (vector unsigned char)vec_vsx_ld(0,
55                                 (signed int const *)&elts[pos]);
56                 *(vector unsigned char *)&pkts[pos] = mbp;
57         }
58         if (n & 1)
59                 pkts[pos] = elts[pos];
60 }
61
62 /**
63  * Decompress a compressed completion and fill in mbufs in RX SW ring with data
64  * extracted from the title completion descriptor.
65  *
66  * @param rxq
67  *   Pointer to RX queue structure.
68  * @param cq
69  *   Pointer to completion array having a compressed completion at first.
70  * @param elts
71  *   Pointer to SW ring to be filled. The first mbuf has to be pre-built from
72  *   the title completion descriptor to be copied to the rest of mbufs.
73  *
74  * @return
75  *   Number of mini-CQEs successfully decompressed.
76  */
77 static inline uint16_t
78 rxq_cq_decompress_v(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cq,
79                     struct rte_mbuf **elts)
80 {
81         volatile struct mlx5_mini_cqe8 *mcq = (void *)&(cq + 1)->pkt_info;
82         struct rte_mbuf *t_pkt = elts[0]; /* Title packet is pre-built. */
83         const vector unsigned char zero = (vector unsigned char){0};
84         /* Mask to shuffle from extracted mini CQE to mbuf. */
85         const vector unsigned char shuf_mask1 = (vector unsigned char){
86                         -1, -1, -1, -1,   /* skip packet_type */
87                          7,  6, -1, -1,   /* bswap16, pkt_len */
88                          7,  6,           /* bswap16, data_len */
89                         -1, -1,           /* skip vlan_tci */
90                          3,  2,  1,  0};  /* bswap32, rss */
91         const vector unsigned char shuf_mask2 = (vector unsigned char){
92                         -1, -1, -1, -1,   /* skip packet_type */
93                         15, 14, -1, -1,   /* bswap16, pkt_len */
94                         15, 14,           /* data_len, bswap16 */
95                         -1, -1,           /* skip vlan_tci */
96                         11, 10,  9,  8};  /* bswap32, rss */
97         /* Restore the compressed count. Must be 16 bits. */
98         const uint16_t mcqe_n = t_pkt->data_len +
99                 (rxq->crc_present * RTE_ETHER_CRC_LEN);
100         const vector unsigned char rearm =
101                 (vector unsigned char)vec_vsx_ld(0,
102                 (signed int const *)&t_pkt->rearm_data);
103         const vector unsigned char rxdf =
104                 (vector unsigned char)vec_vsx_ld(0,
105                 (signed int const *)&t_pkt->rx_descriptor_fields1);
106         const vector unsigned char crc_adj =
107                 (vector unsigned char)(vector unsigned short){
108                         0, 0, rxq->crc_present * RTE_ETHER_CRC_LEN, 0,
109                         rxq->crc_present * RTE_ETHER_CRC_LEN, 0, 0, 0};
110         const vector unsigned short rxdf_sel_mask =
111                 (vector unsigned short){
112                         0xffff, 0xffff, 0, 0, 0, 0xffff, 0, 0};
113         const uint32_t flow_tag = t_pkt->hash.fdir.hi;
114         unsigned int pos;
115         unsigned int i;
116         unsigned int inv = 0;
117
118 #ifdef MLX5_PMD_SOFT_COUNTERS
119         const vector unsigned char ones = vec_splat_u8(-1);
120         uint32_t rcvd_byte = 0;
121         /* Mask to shuffle byte_cnt to add up stats. Do bswap16 for all. */
122         const vector unsigned char len_shuf_mask = (vector unsigned char){
123                  3,  2, 11, 10,
124                  7,  6, 15, 14,
125                 -1, -1, -1, -1,
126                 -1, -1, -1, -1};
127 #endif
128
129         /*
130          * A. load mCQEs into a 128bit register.
131          * B. store rearm data to mbuf.
132          * C. combine data from mCQEs with rx_descriptor_fields1.
133          * D. store rx_descriptor_fields1.
134          * E. store flow tag (rte_flow mark).
135          */
136         for (pos = 0; pos < mcqe_n; ) {
137                 vector unsigned char mcqe1, mcqe2;
138                 vector unsigned char rxdf1, rxdf2;
139 #ifdef MLX5_PMD_SOFT_COUNTERS
140                 const vector unsigned short mcqe_sel_mask =
141                         (vector unsigned short){0, 0, 0xffff, 0xffff,
142                         0, 0, 0xfff, 0xffff};
143                 const vector unsigned char lower_half = {
144                         0, 1, 4, 5, 8, 9, 12, 13, 16,
145                         17, 20, 21, 24, 25, 28, 29};
146                 const vector unsigned char upper_half = {
147                         2, 3, 6, 7, 10, 11, 14, 15,
148                         18, 19, 22, 23, 26, 27, 30, 31};
149                 vector unsigned short left, right;
150                 vector unsigned char byte_cnt, invalid_mask;
151                 vector unsigned long lshift;
152                 __attribute__((altivec(vector__)))
153                         __attribute__((altivec(bool__)))
154                         unsigned long long shmask;
155                 const vector unsigned long shmax = {64, 64};
156 #endif
157
158                 for (i = 0; i < MLX5_VPMD_DESCS_PER_LOOP; ++i)
159                         if (likely(pos + i < mcqe_n))
160                                 rte_prefetch0((void *)(cq + pos + i));
161
162                 /* A.1 load mCQEs into a 128bit register. */
163                 mcqe1 = (vector unsigned char)vec_vsx_ld(0,
164                         (signed int const *)&mcq[pos % 8]);
165                 mcqe2 = (vector unsigned char)vec_vsx_ld(0,
166                         (signed int const *)&mcq[pos % 8 + 2]);
167
168                 /* B.1 store rearm data to mbuf. */
169                 *(vector unsigned char *)
170                         &elts[pos]->rearm_data = rearm;
171                 *(vector unsigned char *)
172                         &elts[pos + 1]->rearm_data = rearm;
173
174                 /* C.1 combine data from mCQEs with rx_descriptor_fields1. */
175                 rxdf1 = vec_perm(mcqe1, zero, shuf_mask1);
176                 rxdf2 = vec_perm(mcqe1, zero, shuf_mask2);
177                 rxdf1 = (vector unsigned char)
178                         ((vector unsigned short)rxdf1 -
179                         (vector unsigned short)crc_adj);
180                 rxdf2 = (vector unsigned char)
181                         ((vector unsigned short)rxdf2 -
182                         (vector unsigned short)crc_adj);
183                 rxdf1 = (vector unsigned char)
184                         vec_sel((vector unsigned short)rxdf1,
185                         (vector unsigned short)rxdf, rxdf_sel_mask);
186                 rxdf2 = (vector unsigned char)
187                         vec_sel((vector unsigned short)rxdf2,
188                         (vector unsigned short)rxdf, rxdf_sel_mask);
189
190                 /* D.1 store rx_descriptor_fields1. */
191                 *(vector unsigned char *)
192                         &elts[pos]->rx_descriptor_fields1 = rxdf1;
193                 *(vector unsigned char *)
194                         &elts[pos + 1]->rx_descriptor_fields1 = rxdf2;
195
196                 /* B.1 store rearm data to mbuf. */
197                 *(vector unsigned char *)
198                         &elts[pos + 2]->rearm_data = rearm;
199                 *(vector unsigned char *)
200                         &elts[pos + 3]->rearm_data = rearm;
201
202                 /* C.1 combine data from mCQEs with rx_descriptor_fields1. */
203                 rxdf1 = vec_perm(mcqe2, zero, shuf_mask1);
204                 rxdf2 = vec_perm(mcqe2, zero, shuf_mask2);
205                 rxdf1 = (vector unsigned char)
206                         ((vector unsigned short)rxdf1 -
207                         (vector unsigned short)crc_adj);
208                 rxdf2 = (vector unsigned char)
209                         ((vector unsigned short)rxdf2 -
210                         (vector unsigned short)crc_adj);
211                 rxdf1 = (vector unsigned char)
212                         vec_sel((vector unsigned short)rxdf1,
213                         (vector unsigned short)rxdf, rxdf_sel_mask);
214                 rxdf2 = (vector unsigned char)
215                         vec_sel((vector unsigned short)rxdf2,
216                         (vector unsigned short)rxdf, rxdf_sel_mask);
217
218                 /* D.1 store rx_descriptor_fields1. */
219                 *(vector unsigned char *)
220                         &elts[pos + 2]->rx_descriptor_fields1 = rxdf1;
221                 *(vector unsigned char *)
222                         &elts[pos + 3]->rx_descriptor_fields1 = rxdf2;
223
224 #ifdef MLX5_PMD_SOFT_COUNTERS
225                 invalid_mask = (vector unsigned char)(vector unsigned long){
226                         (mcqe_n - pos) * sizeof(uint16_t) * 8, 0};
227
228                 lshift =
229                         vec_splat((vector unsigned long)invalid_mask, 0);
230                 shmask = vec_cmpgt(shmax, lshift);
231                 invalid_mask = (vector unsigned char)
232                         vec_sl((vector unsigned long)ones, lshift);
233                 invalid_mask = (vector unsigned char)
234                         vec_sel((vector unsigned long)shmask,
235                         (vector unsigned long)invalid_mask, shmask);
236
237                 mcqe1 = (vector unsigned char)
238                         vec_sro((vector unsigned short)mcqe1,
239                         (vector unsigned char){32}),
240                 byte_cnt = (vector unsigned char)
241                         vec_sel((vector unsigned short)mcqe1,
242                         (vector unsigned short)mcqe2, mcqe_sel_mask);
243                 byte_cnt = vec_perm(byte_cnt, zero, len_shuf_mask);
244                 byte_cnt = (vector unsigned char)
245                         vec_andc((vector unsigned long)byte_cnt,
246                         (vector unsigned long)invalid_mask);
247                 left = vec_perm((vector unsigned short)byte_cnt,
248                         (vector unsigned short)zero, lower_half);
249                 right = vec_perm((vector unsigned short)byte_cnt,
250                         (vector unsigned short)zero, upper_half);
251                 byte_cnt = (vector unsigned char)vec_add(left, right);
252                 left = vec_perm((vector unsigned short)byte_cnt,
253                         (vector unsigned short)zero, lower_half);
254                 right = vec_perm((vector unsigned short)byte_cnt,
255                         (vector unsigned short)zero, upper_half);
256                 byte_cnt = (vector unsigned char)vec_add(left, right);
257                 rcvd_byte += ((vector unsigned long)byte_cnt)[0];
258 #endif
259
260                 if (rxq->mark) {
261                         /* E.1 store flow tag (rte_flow mark). */
262                         elts[pos]->hash.fdir.hi = flow_tag;
263                         elts[pos + 1]->hash.fdir.hi = flow_tag;
264                         elts[pos + 2]->hash.fdir.hi = flow_tag;
265                         elts[pos + 3]->hash.fdir.hi = flow_tag;
266                 }
267                 if (rxq->dynf_meta) {
268                         int32_t offs = rxq->flow_meta_offset;
269                         const uint32_t meta =
270                                 *RTE_MBUF_DYNFIELD(t_pkt, offs, uint32_t *);
271
272                         /* Check if title packet has valid metadata. */
273                         if (meta) {
274                                 MLX5_ASSERT(t_pkt->ol_flags &
275                                             rxq->flow_meta_mask);
276                                 *RTE_MBUF_DYNFIELD(elts[pos], offs,
277                                                         uint32_t *) = meta;
278                                 *RTE_MBUF_DYNFIELD(elts[pos + 1], offs,
279                                                         uint32_t *) = meta;
280                                 *RTE_MBUF_DYNFIELD(elts[pos + 2], offs,
281                                                         uint32_t *) = meta;
282                                 *RTE_MBUF_DYNFIELD(elts[pos + 3], offs,
283                                                         uint32_t *) = meta;
284                         }
285                 }
286
287                 pos += MLX5_VPMD_DESCS_PER_LOOP;
288                 /* Move to next CQE and invalidate consumed CQEs. */
289                 if (!(pos & 0x7) && pos < mcqe_n) {
290                         mcq = (void *)&(cq + pos)->pkt_info;
291                         for (i = 0; i < 8; ++i)
292                                 cq[inv++].op_own = MLX5_CQE_INVALIDATE;
293                 }
294         }
295
296         /* Invalidate the rest of CQEs. */
297         for (; inv < mcqe_n; ++inv)
298                 cq[inv].op_own = MLX5_CQE_INVALIDATE;
299
300 #ifdef MLX5_PMD_SOFT_COUNTERS
301         rxq->stats.ipackets += mcqe_n;
302         rxq->stats.ibytes += rcvd_byte;
303 #endif
304
305         rxq->cq_ci += mcqe_n;
306         return mcqe_n;
307 }
308
309 /**
310  * Calculate packet type and offload flag for mbuf and store it.
311  *
312  * @param rxq
313  *   Pointer to RX queue structure.
314  * @param cqes[4]
315  *   Array of four 16bytes completions extracted from the original completion
316  *   descriptor.
317  * @param op_err
318  *   Opcode vector having responder error status. Each field is 4B.
319  * @param pkts
320  *   Pointer to array of packets to be filled.
321  */
322 static inline void
323 rxq_cq_to_ptype_oflags_v(struct mlx5_rxq_data *rxq,
324                 vector unsigned char cqes[4], vector unsigned char op_err,
325                 struct rte_mbuf **pkts)
326 {
327         vector unsigned char pinfo0, pinfo1;
328         vector unsigned char pinfo, ptype;
329         vector unsigned char ol_flags = (vector unsigned char)
330                 (vector unsigned int){
331                         rxq->rss_hash * PKT_RX_RSS_HASH |
332                                 rxq->hw_timestamp * PKT_RX_TIMESTAMP,
333                         rxq->rss_hash * PKT_RX_RSS_HASH |
334                                 rxq->hw_timestamp * PKT_RX_TIMESTAMP,
335                         rxq->rss_hash * PKT_RX_RSS_HASH |
336                                 rxq->hw_timestamp * PKT_RX_TIMESTAMP,
337                         rxq->rss_hash * PKT_RX_RSS_HASH |
338                                 rxq->hw_timestamp * PKT_RX_TIMESTAMP};
339         vector unsigned char cv_flags;
340         const vector unsigned char zero = (vector unsigned char){0};
341         const vector unsigned char ptype_mask =
342                 (vector unsigned char)(vector unsigned int){
343                 0x0000fd06, 0x0000fd06, 0x0000fd06, 0x0000fd06};
344         const vector unsigned char ptype_ol_mask =
345                 (vector unsigned char)(vector unsigned int){
346                 0x00000106, 0x00000106, 0x00000106, 0x00000106};
347         const vector unsigned char pinfo_mask =
348                 (vector unsigned char)(vector unsigned int){
349                 0x00000003, 0x00000003, 0x00000003, 0x00000003};
350         const vector unsigned char cv_flag_sel = (vector unsigned char){
351                 0, (uint8_t)(PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED),
352                 (uint8_t)(PKT_RX_IP_CKSUM_GOOD >> 1), 0,
353                 (uint8_t)(PKT_RX_L4_CKSUM_GOOD >> 1), 0,
354                 (uint8_t)((PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD) >> 1),
355                 0, 0, 0, 0, 0, 0, 0, 0, 0};
356         const vector unsigned char cv_mask =
357                 (vector unsigned char)(vector unsigned int){
358                 PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
359                 PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
360                 PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
361                 PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
362                 PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
363                 PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED,
364                 PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
365                 PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED};
366         const vector unsigned char mbuf_init =
367                 (vector unsigned char)vec_vsx_ld
368                         (0, (vector unsigned char *)&rxq->mbuf_initializer);
369         const vector unsigned short rearm_sel_mask =
370                 (vector unsigned short){0, 0, 0, 0, 0xffff, 0xffff, 0, 0};
371         vector unsigned char rearm0, rearm1, rearm2, rearm3;
372         uint8_t pt_idx0, pt_idx1, pt_idx2, pt_idx3;
373
374         /* Extract pkt_info field. */
375         pinfo0 = (vector unsigned char)
376                 vec_mergeh((vector unsigned int)cqes[0],
377                 (vector unsigned int)cqes[1]);
378         pinfo1 = (vector unsigned char)
379                 vec_mergeh((vector unsigned int)cqes[2],
380                 (vector unsigned int)cqes[3]);
381         pinfo = (vector unsigned char)
382                 vec_mergeh((vector unsigned long)pinfo0,
383                 (vector unsigned long)pinfo1);
384
385         /* Extract hdr_type_etc field. */
386         pinfo0 = (vector unsigned char)
387                 vec_mergel((vector unsigned int)cqes[0],
388                 (vector unsigned int)cqes[1]);
389         pinfo1 = (vector unsigned char)
390                 vec_mergel((vector unsigned int)cqes[2],
391                 (vector unsigned int)cqes[3]);
392         ptype = (vector unsigned char)
393                 vec_mergeh((vector unsigned long)pinfo0,
394                 (vector unsigned long)pinfo1);
395
396         if (rxq->mark) {
397                 const vector unsigned char pinfo_ft_mask =
398                         (vector unsigned char)(vector unsigned int){
399                         0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00};
400                 const vector unsigned char fdir_flags =
401                         (vector unsigned char)(vector unsigned int){
402                         PKT_RX_FDIR, PKT_RX_FDIR,
403                         PKT_RX_FDIR, PKT_RX_FDIR};
404                 vector unsigned char fdir_id_flags =
405                         (vector unsigned char)(vector unsigned int){
406                         PKT_RX_FDIR_ID, PKT_RX_FDIR_ID,
407                         PKT_RX_FDIR_ID, PKT_RX_FDIR_ID};
408                 vector unsigned char flow_tag, invalid_mask;
409
410                 flow_tag = (vector unsigned char)
411                         vec_and((vector unsigned long)pinfo,
412                         (vector unsigned long)pinfo_ft_mask);
413
414                 /* Check if flow tag is non-zero then set PKT_RX_FDIR. */
415                 invalid_mask = (vector unsigned char)
416                         vec_cmpeq((vector unsigned int)flow_tag,
417                         (vector unsigned int)zero);
418                 ol_flags = (vector unsigned char)
419                         vec_or((vector unsigned long)ol_flags,
420                         (vector unsigned long)
421                         vec_andc((vector unsigned long)fdir_flags,
422                         (vector unsigned long)invalid_mask));
423
424                 /* Mask out invalid entries. */
425                 fdir_id_flags = (vector unsigned char)
426                         vec_andc((vector unsigned long)fdir_id_flags,
427                         (vector unsigned long)invalid_mask);
428
429                 /* Check if flow tag MLX5_FLOW_MARK_DEFAULT. */
430                 ol_flags = (vector unsigned char)
431                         vec_or((vector unsigned long)ol_flags,
432                         (vector unsigned long)
433                         vec_andc((vector unsigned long)fdir_id_flags,
434                         (vector unsigned long)
435                         vec_cmpeq((vector unsigned int)flow_tag,
436                         (vector unsigned int)pinfo_ft_mask)));
437         }
438         /*
439          * Merge the two fields to generate the following:
440          * bit[1]     = l3_ok
441          * bit[2]     = l4_ok
442          * bit[8]     = cv
443          * bit[11:10] = l3_hdr_type
444          * bit[14:12] = l4_hdr_type
445          * bit[15]    = ip_frag
446          * bit[16]    = tunneled
447          * bit[17]    = outer_l3_type
448          */
449         ptype = (vector unsigned char)
450                 vec_and((vector unsigned long)ptype,
451                 (vector unsigned long)ptype_mask);
452         pinfo = (vector unsigned char)
453                 vec_and((vector unsigned long)pinfo,
454                 (vector unsigned long)pinfo_mask);
455         pinfo = (vector unsigned char)
456                 vec_sl((vector unsigned int)pinfo,
457                 (vector unsigned int){16, 16, 16, 16});
458
459         /* Make pinfo has merged fields for ol_flags calculation. */
460         pinfo = (vector unsigned char)
461                 vec_or((vector unsigned long)ptype,
462                 (vector unsigned long)pinfo);
463         ptype = (vector unsigned char)
464                 vec_sr((vector unsigned int)pinfo,
465                 (vector unsigned int){10, 10, 10, 10});
466         ptype = (vector unsigned char)
467                 vec_packs((vector unsigned int)ptype,
468                 (vector unsigned int)zero);
469
470         /* Errored packets will have RTE_PTYPE_ALL_MASK. */
471         op_err = (vector unsigned char)
472                 vec_sr((vector unsigned short)op_err,
473                 (vector unsigned short){8, 8, 8, 8, 8, 8, 8, 8});
474         ptype = (vector unsigned char)
475                 vec_or((vector unsigned long)ptype,
476                 (vector unsigned long)op_err);
477
478         pt_idx0 = (uint8_t)((vector unsigned char)ptype)[0];
479         pt_idx1 = (uint8_t)((vector unsigned char)ptype)[2];
480         pt_idx2 = (uint8_t)((vector unsigned char)ptype)[4];
481         pt_idx3 = (uint8_t)((vector unsigned char)ptype)[6];
482
483         pkts[0]->packet_type = mlx5_ptype_table[pt_idx0] |
484                 !!(pt_idx0 & (1 << 6)) * rxq->tunnel;
485         pkts[1]->packet_type = mlx5_ptype_table[pt_idx1] |
486                 !!(pt_idx1 & (1 << 6)) * rxq->tunnel;
487         pkts[2]->packet_type = mlx5_ptype_table[pt_idx2] |
488                 !!(pt_idx2 & (1 << 6)) * rxq->tunnel;
489         pkts[3]->packet_type = mlx5_ptype_table[pt_idx3] |
490                 !!(pt_idx3 & (1 << 6)) * rxq->tunnel;
491
492         /* Fill flags for checksum and VLAN. */
493         pinfo = (vector unsigned char)
494                 vec_and((vector unsigned long)pinfo,
495                 (vector unsigned long)ptype_ol_mask);
496         pinfo = vec_perm(cv_flag_sel, zero, pinfo);
497
498         /* Locate checksum flags at byte[2:1] and merge with VLAN flags. */
499         cv_flags = (vector unsigned char)
500                 vec_sl((vector unsigned int)pinfo,
501                 (vector unsigned int){9, 9, 9, 9});
502         cv_flags = (vector unsigned char)
503                 vec_or((vector unsigned long)pinfo,
504                 (vector unsigned long)cv_flags);
505
506         /* Move back flags to start from byte[0]. */
507         cv_flags = (vector unsigned char)
508                 vec_sr((vector unsigned int)cv_flags,
509                 (vector unsigned int){8, 8, 8, 8});
510
511         /* Mask out garbage bits. */
512         cv_flags = (vector unsigned char)
513                 vec_and((vector unsigned long)cv_flags,
514                 (vector unsigned long)cv_mask);
515
516         /* Merge to ol_flags. */
517         ol_flags = (vector unsigned char)
518                 vec_or((vector unsigned long)ol_flags,
519                 (vector unsigned long)cv_flags);
520
521         /* Merge mbuf_init and ol_flags. */
522         rearm0 = (vector unsigned char)
523                 vec_sel((vector unsigned short)mbuf_init,
524                 (vector unsigned short)
525                 vec_slo((vector unsigned short)ol_flags,
526                 (vector unsigned char){64}), rearm_sel_mask);
527         rearm1 = (vector unsigned char)
528                 vec_sel((vector unsigned short)mbuf_init,
529                 (vector unsigned short)
530                 vec_slo((vector unsigned short)ol_flags,
531                 (vector unsigned char){32}), rearm_sel_mask);
532         rearm2 = (vector unsigned char)
533                 vec_sel((vector unsigned short)mbuf_init,
534                 (vector unsigned short)ol_flags, rearm_sel_mask);
535         rearm3 = (vector unsigned char)
536                 vec_sel((vector unsigned short)mbuf_init,
537                 (vector unsigned short)
538                 vec_sro((vector unsigned short)ol_flags,
539                 (vector unsigned char){32}), rearm_sel_mask);
540
541         /* Write 8B rearm_data and 8B ol_flags. */
542         vec_vsx_st(rearm0, 0,
543                 (vector unsigned char *)&pkts[0]->rearm_data);
544         vec_vsx_st(rearm1, 0,
545                 (vector unsigned char *)&pkts[1]->rearm_data);
546         vec_vsx_st(rearm2, 0,
547                 (vector unsigned char *)&pkts[2]->rearm_data);
548         vec_vsx_st(rearm3, 0,
549                 (vector unsigned char *)&pkts[3]->rearm_data);
550 }
551
552
553 /**
554  * Receive burst of packets. An errored completion also consumes a mbuf, but the
555  * packet_type is set to be RTE_PTYPE_ALL_MASK. Marked mbufs should be freed
556  * before returning to application.
557  *
558  * @param rxq
559  *   Pointer to RX queue structure.
560  * @param[out] pkts
561  *   Array to store received packets.
562  * @param pkts_n
563  *   Maximum number of packets in array.
564  * @param[out] err
565  *   Pointer to a flag. Set non-zero value if pkts array has at least one error
566  *   packet to handle.
567  *
568  * @return
569  *   Number of packets received including errors (<= pkts_n).
570  */
571 static inline uint16_t
572 rxq_burst_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts, uint16_t pkts_n,
573             uint64_t *err)
574 {
575         const uint16_t q_n = 1 << rxq->cqe_n;
576         const uint16_t q_mask = q_n - 1;
577         volatile struct mlx5_cqe *cq;
578         struct rte_mbuf **elts;
579         unsigned int pos;
580         uint64_t n;
581         uint16_t repl_n;
582         uint64_t comp_idx = MLX5_VPMD_DESCS_PER_LOOP;
583         uint16_t nocmp_n = 0;
584         uint16_t rcvd_pkt = 0;
585         unsigned int cq_idx = rxq->cq_ci & q_mask;
586         unsigned int elts_idx;
587         unsigned int ownership = !!(rxq->cq_ci & (q_mask + 1));
588         const vector unsigned char zero = (vector unsigned char){0};
589         const vector unsigned char ones = vec_splat_u8(-1);
590         const vector unsigned char owner_check =
591                 (vector unsigned char)(vector unsigned long){
592                 0x0100000001000000LL, 0x0100000001000000LL};
593         const vector unsigned char opcode_check =
594                 (vector unsigned char)(vector unsigned long){
595                 0xf0000000f0000000LL, 0xf0000000f0000000LL};
596         const vector unsigned char format_check =
597                 (vector unsigned char)(vector unsigned long){
598                 0x0c0000000c000000LL, 0x0c0000000c000000LL};
599         const vector unsigned char resp_err_check =
600                 (vector unsigned char)(vector unsigned long){
601                 0xe0000000e0000000LL, 0xe0000000e0000000LL};
602 #ifdef MLX5_PMD_SOFT_COUNTERS
603         uint32_t rcvd_byte = 0;
604         /* Mask to shuffle byte_cnt to add up stats. Do bswap16 for all. */
605         const vector unsigned char len_shuf_mask = (vector unsigned char){
606                  1,  0,  5,  4,
607                  9,  8, 13, 12,
608                 -1, -1, -1, -1,
609                 -1, -1, -1, -1};
610 #endif
611         /* Mask to shuffle from extracted CQE to mbuf. */
612         const vector unsigned char shuf_mask = (vector unsigned char){
613                  5,  4,           /* bswap16, pkt_len */
614                 -1, -1,           /* zero out 2nd half of pkt_len */
615                  5,  4,           /* bswap16, data_len */
616                 11, 10,           /* bswap16, vlan+tci */
617                 15, 14, 13, 12,   /* bswap32, rss */
618                  1,  2,  3, -1};  /* fdir.hi */
619         /* Mask to blend from the last Qword to the first DQword. */
620         /* Mask to blend from the last Qword to the first DQword. */
621         const vector unsigned char blend_mask = (vector unsigned char){
622                 -1,  0,  0,  0,
623                  0,  0,  0,  0,
624                 -1, -1, -1, -1,
625                 -1, -1, -1, -1};
626         const vector unsigned char crc_adj =
627                 (vector unsigned char)(vector unsigned short){
628                 rxq->crc_present * RTE_ETHER_CRC_LEN, 0,
629                 rxq->crc_present * RTE_ETHER_CRC_LEN, 0, 0, 0, 0, 0};
630         const vector unsigned char flow_mark_adj =
631                 (vector unsigned char)(vector unsigned int){
632                 0, 0, 0, rxq->mark * (-1)};
633         const vector unsigned short cqe_sel_mask1 =
634                 (vector unsigned short){0, 0, 0, 0, 0xffff, 0xffff, 0, 0};
635         const vector unsigned short cqe_sel_mask2 =
636                 (vector unsigned short){0, 0, 0xffff, 0, 0, 0, 0, 0};
637
638         MLX5_ASSERT(rxq->sges_n == 0);
639         MLX5_ASSERT(rxq->cqe_n == rxq->elts_n);
640         cq = &(*rxq->cqes)[cq_idx];
641         rte_prefetch0(cq);
642         rte_prefetch0(cq + 1);
643         rte_prefetch0(cq + 2);
644         rte_prefetch0(cq + 3);
645         pkts_n = RTE_MIN(pkts_n, MLX5_VPMD_RX_MAX_BURST);
646
647         repl_n = q_n - (rxq->rq_ci - rxq->rq_pi);
648         if (repl_n >= rxq->rq_repl_thresh)
649                 mlx5_rx_replenish_bulk_mbuf(rxq, repl_n);
650         /* See if there're unreturned mbufs from compressed CQE. */
651         rcvd_pkt = rxq->decompressed;
652         if (rcvd_pkt > 0) {
653                 rcvd_pkt = RTE_MIN(rcvd_pkt, pkts_n);
654                 rxq_copy_mbuf_v(rxq, pkts, rcvd_pkt);
655                 rxq->rq_pi += rcvd_pkt;
656                 rxq->decompressed -= rcvd_pkt;
657                 pkts += rcvd_pkt;
658         }
659         elts_idx = rxq->rq_pi & q_mask;
660         elts = &(*rxq->elts)[elts_idx];
661         /* Not to overflow pkts array. */
662         pkts_n = RTE_ALIGN_FLOOR(pkts_n - rcvd_pkt, MLX5_VPMD_DESCS_PER_LOOP);
663         /* Not to cross queue end. */
664         pkts_n = RTE_MIN(pkts_n, q_n - elts_idx);
665         pkts_n = RTE_MIN(pkts_n, q_n - cq_idx);
666         if (!pkts_n)
667                 return rcvd_pkt;
668         /* At this point, there shouldn't be any remaining packets. */
669         MLX5_ASSERT(rxq->decompressed == 0);
670
671         /*
672          * A. load first Qword (8bytes) in one loop.
673          * B. copy 4 mbuf pointers from elts ring to returing pkts.
674          * C. load remaining CQE data and extract necessary fields.
675          *    Final 16bytes cqes[] extracted from original 64bytes CQE has the
676          *    following structure:
677          *        struct {
678          *          uint8_t  pkt_info;
679          *          uint8_t  flow_tag[3];
680          *          uint16_t byte_cnt;
681          *          uint8_t  rsvd4;
682          *          uint8_t  op_own;
683          *          uint16_t hdr_type_etc;
684          *          uint16_t vlan_info;
685          *          uint32_t rx_has_res;
686          *        } c;
687          * D. fill in mbuf.
688          * E. get valid CQEs.
689          * F. find compressed CQE.
690          */
691         for (pos = 0;
692              pos < pkts_n;
693              pos += MLX5_VPMD_DESCS_PER_LOOP) {
694                 vector unsigned char cqes[MLX5_VPMD_DESCS_PER_LOOP];
695                 vector unsigned char cqe_tmp1, cqe_tmp2;
696                 vector unsigned char pkt_mb0, pkt_mb1, pkt_mb2, pkt_mb3;
697                 vector unsigned char op_own, op_own_tmp1, op_own_tmp2;
698                 vector unsigned char opcode, owner_mask, invalid_mask;
699                 vector unsigned char comp_mask;
700                 vector unsigned char mask;
701 #ifdef MLX5_PMD_SOFT_COUNTERS
702                 const vector unsigned char lower_half = {
703                         0, 1, 4, 5, 8, 9, 12, 13,
704                         16, 17, 20, 21, 24, 25, 28, 29};
705                 const vector unsigned char upper_half = {
706                         2, 3, 6, 7, 10, 11, 14, 15,
707                         18, 19, 22, 23, 26, 27, 30, 31};
708                 const vector unsigned long shmax = {64, 64};
709                 vector unsigned char byte_cnt;
710                 vector unsigned short left, right;
711                 vector unsigned long lshift;
712                 vector __attribute__((altivec(bool__)))
713                         unsigned long shmask;
714 #endif
715                 vector unsigned char mbp1, mbp2;
716                 vector unsigned char p =
717                         (vector unsigned char)(vector unsigned short){
718                                 0, 1, 2, 3, 0, 0, 0, 0};
719                 unsigned int p1, p2, p3;
720
721                 /* Prefetch next 4 CQEs. */
722                 if (pkts_n - pos >= 2 * MLX5_VPMD_DESCS_PER_LOOP) {
723                         rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP]);
724                         rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP + 1]);
725                         rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP + 2]);
726                         rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP + 3]);
727                 }
728
729                 /* A.0 do not cross the end of CQ. */
730                 mask = (vector unsigned char)(vector unsigned long){
731                         (pkts_n - pos) * sizeof(uint16_t) * 8, 0};
732
733                 {
734                         vector unsigned long lshift;
735                         vector __attribute__((altivec(bool__)))
736                                 unsigned long shmask;
737                         const vector unsigned long shmax = {64, 64};
738
739                         lshift = vec_splat((vector unsigned long)mask, 0);
740                         shmask = vec_cmpgt(shmax, lshift);
741                         mask = (vector unsigned char)
742                                 vec_sl((vector unsigned long)ones, lshift);
743                         mask = (vector unsigned char)
744                                 vec_sel((vector unsigned long)shmask,
745                                 (vector unsigned long)mask, shmask);
746                 }
747
748                 p = (vector unsigned char)
749                         vec_andc((vector unsigned long)p,
750                         (vector unsigned long)mask);
751
752                 /* A.1 load cqes. */
753                 p3 = (unsigned int)((vector unsigned short)p)[3];
754                 cqes[3] = (vector unsigned char)(vector unsigned long){
755                         *(__rte_aligned(8) unsigned long *)
756                         &cq[pos + p3].sop_drop_qpn, 0LL};
757                 rte_compiler_barrier();
758
759                 p2 = (unsigned int)((vector unsigned short)p)[2];
760                 cqes[2] = (vector unsigned char)(vector unsigned long){
761                         *(__rte_aligned(8) unsigned long *)
762                         &cq[pos + p2].sop_drop_qpn, 0LL};
763                 rte_compiler_barrier();
764
765                 /* B.1 load mbuf pointers. */
766                 mbp1 = (vector unsigned char)vec_vsx_ld(0,
767                         (signed int const *)&elts[pos]);
768                 mbp2 = (vector unsigned char)vec_vsx_ld(0,
769                         (signed int const *)&elts[pos + 2]);
770
771                 /* A.1 load a block having op_own. */
772                 p1 = (unsigned int)((vector unsigned short)p)[1];
773                 cqes[1] = (vector unsigned char)(vector unsigned long){
774                         *(__rte_aligned(8) unsigned long *)
775                         &cq[pos + p1].sop_drop_qpn, 0LL};
776                 rte_compiler_barrier();
777
778                 cqes[0] = (vector unsigned char)(vector unsigned long){
779                         *(__rte_aligned(8) unsigned long *)
780                         &cq[pos].sop_drop_qpn, 0LL};
781                 rte_compiler_barrier();
782
783                 /* B.2 copy mbuf pointers. */
784                 *(vector unsigned char *)&pkts[pos] = mbp1;
785                 *(vector unsigned char *)&pkts[pos + 2] = mbp2;
786                 rte_cio_rmb();
787
788                 /* C.1 load remaining CQE data and extract necessary fields. */
789                 cqe_tmp2 = *(vector unsigned char *)
790                         &cq[pos + p3].pkt_info;
791                 cqe_tmp1 = *(vector unsigned char *)
792                         &cq[pos + p2].pkt_info;
793                 cqes[3] = vec_sel(cqes[3], cqe_tmp2, blend_mask);
794                 cqes[2] = vec_sel(cqes[2], cqe_tmp1, blend_mask);
795                 cqe_tmp2 = (vector unsigned char)vec_vsx_ld(0,
796                         (signed int const *)&cq[pos + p3].csum);
797                 cqe_tmp1 = (vector unsigned char)vec_vsx_ld(0,
798                         (signed int const *)&cq[pos + p2].csum);
799                 cqes[3] = (vector unsigned char)
800                         vec_sel((vector unsigned short)cqes[3],
801                         (vector unsigned short)cqe_tmp2, cqe_sel_mask1);
802                 cqes[2] = (vector unsigned char)
803                         vec_sel((vector unsigned short)cqes[2],
804                         (vector unsigned short)cqe_tmp1, cqe_sel_mask1);
805                 cqe_tmp2 = (vector unsigned char)(vector unsigned long){
806                         *(__rte_aligned(8) unsigned long *)
807                         &cq[pos + p3].rsvd3[9], 0LL};
808                 cqe_tmp1 = (vector unsigned char)(vector unsigned long){
809                         *(__rte_aligned(8) unsigned long *)
810                         &cq[pos + p2].rsvd3[9], 0LL};
811                 cqes[3] = (vector unsigned char)
812                         vec_sel((vector unsigned short)cqes[3],
813                         (vector unsigned short)cqe_tmp2,
814                         (vector unsigned short)cqe_sel_mask2);
815                 cqes[2] = (vector unsigned char)
816                         vec_sel((vector unsigned short)cqes[2],
817                         (vector unsigned short)cqe_tmp1,
818                         (vector unsigned short)cqe_sel_mask2);
819
820                 /* C.2 generate final structure for mbuf with swapping bytes. */
821                 pkt_mb3 = vec_perm(cqes[3], zero, shuf_mask);
822                 pkt_mb2 = vec_perm(cqes[2], zero, shuf_mask);
823
824                 /* C.3 adjust CRC length. */
825                 pkt_mb3 = (vector unsigned char)
826                         ((vector unsigned short)pkt_mb3 -
827                         (vector unsigned short)crc_adj);
828                 pkt_mb2 = (vector unsigned char)
829                         ((vector unsigned short)pkt_mb2 -
830                         (vector unsigned short)crc_adj);
831
832                 /* C.4 adjust flow mark. */
833                 pkt_mb3 = (vector unsigned char)
834                         ((vector unsigned int)pkt_mb3 +
835                         (vector unsigned int)flow_mark_adj);
836                 pkt_mb2 = (vector unsigned char)
837                         ((vector unsigned int)pkt_mb2 +
838                         (vector unsigned int)flow_mark_adj);
839
840                 /* D.1 fill in mbuf - rx_descriptor_fields1. */
841                 *(vector unsigned char *)
842                         &pkts[pos + 3]->pkt_len = pkt_mb3;
843                 *(vector unsigned char *)
844                         &pkts[pos + 2]->pkt_len = pkt_mb2;
845
846                 /* E.1 extract op_own field. */
847                 op_own_tmp2 = (vector unsigned char)
848                         vec_mergeh((vector unsigned int)cqes[2],
849                         (vector unsigned int)cqes[3]);
850
851                 /* C.1 load remaining CQE data and extract necessary fields. */
852                 cqe_tmp2 = *(vector unsigned char *)
853                         &cq[pos + p1].pkt_info;
854                 cqe_tmp1 = *(vector unsigned char *)
855                         &cq[pos].pkt_info;
856                 cqes[1] = vec_sel(cqes[1], cqe_tmp2, blend_mask);
857                 cqes[0] = vec_sel(cqes[0], cqe_tmp2, blend_mask);
858                 cqe_tmp2 = (vector unsigned char)vec_vsx_ld(0,
859                         (signed int const *)&cq[pos + p1].csum);
860                 cqe_tmp1 = (vector unsigned char)vec_vsx_ld(0,
861                         (signed int const *)&cq[pos].csum);
862                 cqes[1] = (vector unsigned char)
863                         vec_sel((vector unsigned short)cqes[1],
864                         (vector unsigned short)cqe_tmp2, cqe_sel_mask1);
865                 cqes[0] = (vector unsigned char)
866                         vec_sel((vector unsigned short)cqes[0],
867                         (vector unsigned short)cqe_tmp1, cqe_sel_mask1);
868                 cqe_tmp2 = (vector unsigned char)(vector unsigned long){
869                         *(__rte_aligned(8) unsigned long *)
870                         &cq[pos + p1].rsvd3[9], 0LL};
871                 cqe_tmp1 = (vector unsigned char)(vector unsigned long){
872                         *(__rte_aligned(8) unsigned long *)
873                         &cq[pos].rsvd3[9], 0LL};
874                 cqes[1] = (vector unsigned char)
875                         vec_sel((vector unsigned short)cqes[1],
876                         (vector unsigned short)cqe_tmp2, cqe_sel_mask2);
877                 cqes[0] = (vector unsigned char)
878                         vec_sel((vector unsigned short)cqes[0],
879                         (vector unsigned short)cqe_tmp1, cqe_sel_mask2);
880
881                 /* C.2 generate final structure for mbuf with swapping bytes. */
882                 pkt_mb1 = vec_perm(cqes[1], zero, shuf_mask);
883                 pkt_mb0 = vec_perm(cqes[0], zero, shuf_mask);
884
885                 /* C.3 adjust CRC length. */
886                 pkt_mb1 = (vector unsigned char)
887                         ((vector unsigned short)pkt_mb1 -
888                         (vector unsigned short)crc_adj);
889                 pkt_mb0 = (vector unsigned char)
890                         ((vector unsigned short)pkt_mb0 -
891                         (vector unsigned short)crc_adj);
892
893                 /* C.4 adjust flow mark. */
894                 pkt_mb1 = (vector unsigned char)
895                         ((vector unsigned int)pkt_mb1 +
896                         (vector unsigned int)flow_mark_adj);
897                 pkt_mb0 = (vector unsigned char)
898                         ((vector unsigned int)pkt_mb0 +
899                         (vector unsigned int)flow_mark_adj);
900
901                 /* E.1 extract op_own byte. */
902                 op_own_tmp1 = (vector unsigned char)
903                         vec_mergeh((vector unsigned int)cqes[0],
904                         (vector unsigned int)cqes[1]);
905                 op_own = (vector unsigned char)
906                         vec_mergel((vector unsigned long)op_own_tmp1,
907                         (vector unsigned long)op_own_tmp2);
908
909                 /* D.1 fill in mbuf - rx_descriptor_fields1. */
910                 *(vector unsigned char *)
911                         &pkts[pos + 1]->pkt_len = pkt_mb1;
912                 *(vector unsigned char *)
913                         &pkts[pos]->pkt_len = pkt_mb0;
914
915                 /* E.2 flip owner bit to mark CQEs from last round. */
916                 owner_mask = (vector unsigned char)
917                         vec_and((vector unsigned long)op_own,
918                         (vector unsigned long)owner_check);
919                 if (ownership)
920                         owner_mask = (vector unsigned char)
921                                 vec_xor((vector unsigned long)owner_mask,
922                                 (vector unsigned long)owner_check);
923                 owner_mask = (vector unsigned char)
924                         vec_cmpeq((vector unsigned int)owner_mask,
925                         (vector unsigned int)owner_check);
926                 owner_mask = (vector unsigned char)
927                         vec_packs((vector unsigned int)owner_mask,
928                         (vector unsigned int)zero);
929
930                 /* E.3 get mask for invalidated CQEs. */
931                 opcode = (vector unsigned char)
932                         vec_and((vector unsigned long)op_own,
933                         (vector unsigned long)opcode_check);
934                 invalid_mask = (vector unsigned char)
935                         vec_cmpeq((vector unsigned int)opcode_check,
936                         (vector unsigned int)opcode);
937                 invalid_mask = (vector unsigned char)
938                         vec_packs((vector unsigned int)invalid_mask,
939                         (vector unsigned int)zero);
940
941                 /* E.4 mask out beyond boundary. */
942                 invalid_mask = (vector unsigned char)
943                         vec_or((vector unsigned long)invalid_mask,
944                         (vector unsigned long)mask);
945
946                 /* E.5 merge invalid_mask with invalid owner. */
947                 invalid_mask = (vector unsigned char)
948                         vec_or((vector unsigned long)invalid_mask,
949                         (vector unsigned long)owner_mask);
950
951                 /* F.1 find compressed CQE format. */
952                 comp_mask = (vector unsigned char)
953                         vec_and((vector unsigned long)op_own,
954                         (vector unsigned long)format_check);
955                 comp_mask = (vector unsigned char)
956                         vec_cmpeq((vector unsigned int)comp_mask,
957                         (vector unsigned int)format_check);
958                 comp_mask = (vector unsigned char)
959                         vec_packs((vector unsigned int)comp_mask,
960                         (vector unsigned int)zero);
961
962                 /* F.2 mask out invalid entries. */
963                 comp_mask = (vector unsigned char)
964                         vec_andc((vector unsigned long)comp_mask,
965                         (vector unsigned long)invalid_mask);
966                 comp_idx = ((vector unsigned long)comp_mask)[0];
967
968                 /* F.3 get the first compressed CQE. */
969                 comp_idx = comp_idx ? __builtin_ctzll(comp_idx) /
970                         (sizeof(uint16_t) * 8) : MLX5_VPMD_DESCS_PER_LOOP;
971
972                 /* E.6 mask out entries after the compressed CQE. */
973                 mask = (vector unsigned char)(vector unsigned long){
974                         (comp_idx * sizeof(uint16_t) * 8), 0};
975                 lshift = vec_splat((vector unsigned long)mask, 0);
976                 shmask = vec_cmpgt(shmax, lshift);
977                 mask = (vector unsigned char)
978                         vec_sl((vector unsigned long)ones, lshift);
979                 mask = (vector unsigned char)
980                         vec_sel((vector unsigned long)shmask,
981                         (vector unsigned long)mask, shmask);
982                 invalid_mask = (vector unsigned char)
983                         vec_or((vector unsigned long)invalid_mask,
984                         (vector unsigned long)mask);
985
986                 /* E.7 count non-compressed valid CQEs. */
987                 n = ((vector unsigned long)invalid_mask)[0];
988                 n = n ? __builtin_ctzll(n) / (sizeof(uint16_t) * 8) :
989                         MLX5_VPMD_DESCS_PER_LOOP;
990                 nocmp_n += n;
991
992                 /* D.2 get the final invalid mask. */
993                 mask = (vector unsigned char)(vector unsigned long){
994                         (n * sizeof(uint16_t) * 8), 0};
995                 lshift = vec_splat((vector unsigned long)mask, 0);
996                 shmask = vec_cmpgt(shmax, lshift);
997                 mask = (vector unsigned char)
998                         vec_sl((vector unsigned long)ones, lshift);
999                 mask = (vector unsigned char)
1000                         vec_sel((vector unsigned long)shmask,
1001                         (vector unsigned long)mask, shmask);
1002                 invalid_mask = (vector unsigned char)
1003                         vec_or((vector unsigned long)invalid_mask,
1004                         (vector unsigned long)mask);
1005
1006                 /* D.3 check error in opcode. */
1007                 opcode = (vector unsigned char)
1008                         vec_cmpeq((vector unsigned int)resp_err_check,
1009                         (vector unsigned int)opcode);
1010                 opcode = (vector unsigned char)
1011                         vec_packs((vector unsigned int)opcode,
1012                         (vector unsigned int)zero);
1013                 opcode = (vector unsigned char)
1014                         vec_andc((vector unsigned long)opcode,
1015                         (vector unsigned long)invalid_mask);
1016
1017                 /* D.4 mark if any error is set */
1018                 *err |= ((vector unsigned long)opcode)[0];
1019
1020                 /* D.5 fill in mbuf - rearm_data and packet_type. */
1021                 rxq_cq_to_ptype_oflags_v(rxq, cqes, opcode, &pkts[pos]);
1022                 if (rxq->hw_timestamp) {
1023                         pkts[pos]->timestamp =
1024                                 rte_be_to_cpu_64(cq[pos].timestamp);
1025                         pkts[pos + 1]->timestamp =
1026                                 rte_be_to_cpu_64(cq[pos + p1].timestamp);
1027                         pkts[pos + 2]->timestamp =
1028                                 rte_be_to_cpu_64(cq[pos + p2].timestamp);
1029                         pkts[pos + 3]->timestamp =
1030                                 rte_be_to_cpu_64(cq[pos + p3].timestamp);
1031                 }
1032                 if (rxq->dynf_meta) {
1033                         uint64_t flag = rxq->flow_meta_mask;
1034                         int32_t offs = rxq->flow_meta_offset;
1035                         uint32_t metadata;
1036
1037                         /* This code is subject for futher optimization. */
1038                         metadata = cq[pos].flow_table_metadata;
1039                         *RTE_MBUF_DYNFIELD(pkts[pos], offs, uint32_t *) =
1040                                                                 metadata;
1041                         pkts[pos]->ol_flags |= metadata ? flag : 0ULL;
1042                         metadata = cq[pos + 1].flow_table_metadata;
1043                         *RTE_MBUF_DYNFIELD(pkts[pos + 1], offs, uint32_t *) =
1044                                                                 metadata;
1045                         pkts[pos + 1]->ol_flags |= metadata ? flag : 0ULL;
1046                         metadata = cq[pos + 2].flow_table_metadata;
1047                         *RTE_MBUF_DYNFIELD(pkts[pos + 2], offs, uint32_t *) =
1048                                                                 metadata;
1049                         pkts[pos + 2]->ol_flags |= metadata ? flag : 0ULL;
1050                         metadata = cq[pos + 3].flow_table_metadata;
1051                         *RTE_MBUF_DYNFIELD(pkts[pos + 3], offs, uint32_t *) =
1052                                                                 metadata;
1053                         pkts[pos + 3]->ol_flags |= metadata ? flag : 0ULL;
1054                 }
1055 #ifdef MLX5_PMD_SOFT_COUNTERS
1056                 /* Add up received bytes count. */
1057                 byte_cnt = vec_perm(op_own, zero, len_shuf_mask);
1058                 byte_cnt = (vector unsigned char)
1059                         vec_andc((vector unsigned long)byte_cnt,
1060                         (vector unsigned long)invalid_mask);
1061                 left = vec_perm((vector unsigned short)byte_cnt,
1062                         (vector unsigned short)zero, lower_half);
1063                 right = vec_perm((vector unsigned short)byte_cnt,
1064                         (vector unsigned short)zero, upper_half);
1065                 byte_cnt = (vector unsigned char)vec_add(left, right);
1066                 left = vec_perm((vector unsigned short)byte_cnt,
1067                         (vector unsigned short)zero, lower_half);
1068                 right = vec_perm((vector unsigned short)byte_cnt,
1069                         (vector unsigned short)zero, upper_half);
1070                 byte_cnt = (vector unsigned char)vec_add(left, right);
1071                 rcvd_byte += ((vector unsigned long)byte_cnt)[0];
1072 #endif
1073
1074                 /*
1075                  * Break the loop unless more valid CQE is expected, or if
1076                  * there's a compressed CQE.
1077                  */
1078                 if (n != MLX5_VPMD_DESCS_PER_LOOP)
1079                         break;
1080         }
1081         /* If no new CQE seen, return without updating cq_db. */
1082         if (unlikely(!nocmp_n && comp_idx == MLX5_VPMD_DESCS_PER_LOOP))
1083                 return rcvd_pkt;
1084         /* Update the consumer indexes for non-compressed CQEs. */
1085         MLX5_ASSERT(nocmp_n <= pkts_n);
1086         rxq->cq_ci += nocmp_n;
1087         rxq->rq_pi += nocmp_n;
1088         rcvd_pkt += nocmp_n;
1089 #ifdef MLX5_PMD_SOFT_COUNTERS
1090         rxq->stats.ipackets += nocmp_n;
1091         rxq->stats.ibytes += rcvd_byte;
1092 #endif
1093         /* Decompress the last CQE if compressed. */
1094         if (comp_idx < MLX5_VPMD_DESCS_PER_LOOP && comp_idx == n) {
1095                 MLX5_ASSERT(comp_idx == (nocmp_n % MLX5_VPMD_DESCS_PER_LOOP));
1096                 rxq->decompressed =
1097                         rxq_cq_decompress_v(rxq, &cq[nocmp_n], &elts[nocmp_n]);
1098                 /* Return more packets if needed. */
1099                 if (nocmp_n < pkts_n) {
1100                         uint16_t n = rxq->decompressed;
1101
1102                         n = RTE_MIN(n, pkts_n - nocmp_n);
1103                         rxq_copy_mbuf_v(rxq, &pkts[nocmp_n], n);
1104                         rxq->rq_pi += n;
1105                         rcvd_pkt += n;
1106                         rxq->decompressed -= n;
1107                 }
1108         }
1109         rte_compiler_barrier();
1110         *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
1111         return rcvd_pkt;
1112 }
1113
1114 #endif /* RTE_PMD_MLX5_RXTX_VEC_ALTIVEC_H_ */