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