event/cnxk: improve Rx performance
[dpdk.git] / drivers / net / cnxk / cn10k_rx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4 #ifndef __CN10K_RX_H__
5 #define __CN10K_RX_H__
6
7 #include <rte_ether.h>
8 #include <rte_vect.h>
9
10 #include <cnxk_ethdev.h>
11
12 #define NIX_RX_OFFLOAD_NONE          (0)
13 #define NIX_RX_OFFLOAD_RSS_F         BIT(0)
14 #define NIX_RX_OFFLOAD_PTYPE_F       BIT(1)
15 #define NIX_RX_OFFLOAD_CHECKSUM_F    BIT(2)
16 #define NIX_RX_OFFLOAD_MARK_UPDATE_F BIT(3)
17 #define NIX_RX_OFFLOAD_TSTAMP_F      BIT(4)
18 #define NIX_RX_OFFLOAD_VLAN_STRIP_F  BIT(5)
19 #define NIX_RX_OFFLOAD_SECURITY_F    BIT(6)
20 #define NIX_RX_OFFLOAD_MAX           (NIX_RX_OFFLOAD_SECURITY_F << 1)
21
22 /* Flags to control cqe_to_mbuf conversion function.
23  * Defining it from backwards to denote its been
24  * not used as offload flags to pick function
25  */
26 #define NIX_RX_VWQE_F      BIT(13)
27 #define NIX_RX_MULTI_SEG_F BIT(14)
28 #define CPT_RX_WQE_F       BIT(15)
29
30 #define CNXK_NIX_CQ_ENTRY_SZ 128
31 #define NIX_DESCS_PER_LOOP   4
32 #define CQE_CAST(x)          ((struct nix_cqe_hdr_s *)(x))
33 #define CQE_SZ(x)            ((x) * CNXK_NIX_CQ_ENTRY_SZ)
34
35 #define CQE_PTR_OFF(b, i, o, f)                                                \
36         (((f) & NIX_RX_VWQE_F) ?                                               \
37                        (uint64_t *)(((uintptr_t)((uint64_t *)(b))[i]) + (o)) : \
38                        (uint64_t *)(((uintptr_t)(b)) + CQE_SZ(i) + (o)))
39
40 union mbuf_initializer {
41         struct {
42                 uint16_t data_off;
43                 uint16_t refcnt;
44                 uint16_t nb_segs;
45                 uint16_t port;
46         } fields;
47         uint64_t value;
48 };
49
50 static __rte_always_inline uint64_t
51 nix_clear_data_off(uint64_t oldval)
52 {
53         union mbuf_initializer mbuf_init = {.value = oldval};
54
55         mbuf_init.fields.data_off = 0;
56         return mbuf_init.value;
57 }
58
59 static __rte_always_inline struct rte_mbuf *
60 nix_get_mbuf_from_cqe(void *cq, const uint64_t data_off)
61 {
62         rte_iova_t buff;
63
64         /* Skip CQE, NIX_RX_PARSE_S and SG HDR(9 DWORDs) and peek buff addr */
65         buff = *((rte_iova_t *)((uint64_t *)cq + 9));
66         return (struct rte_mbuf *)(buff - data_off);
67 }
68
69 static __rte_always_inline void
70 nix_sec_flush_meta(uintptr_t laddr, uint16_t lmt_id, uint8_t loff,
71                    uintptr_t aura_handle)
72 {
73         uint64_t pa;
74
75         /* laddr is pointing to first pointer */
76         laddr -= 8;
77
78         /* Trigger free either on lmtline full or different aura handle */
79         pa = roc_npa_aura_handle_to_base(aura_handle) + NPA_LF_AURA_BATCH_FREE0;
80
81         /* Update aura handle */
82         *(uint64_t *)laddr = (((uint64_t)(loff & 0x1) << 32) |
83                               roc_npa_aura_handle_to_aura(aura_handle));
84
85         pa |= ((loff >> 1) << 4);
86         roc_lmt_submit_steorl(lmt_id, pa);
87 }
88
89 static __rte_always_inline struct rte_mbuf *
90 nix_sec_meta_to_mbuf_sc(uint64_t cq_w1, const uint64_t sa_base, uintptr_t laddr,
91                         uint8_t *loff, struct rte_mbuf *mbuf, uint16_t data_off)
92 {
93         const void *__p = (void *)((uintptr_t)mbuf + (uint16_t)data_off);
94         const struct cpt_parse_hdr_s *hdr = (const struct cpt_parse_hdr_s *)__p;
95         struct cn10k_inb_priv_data *inb_priv;
96         struct rte_mbuf *inner;
97         uint32_t sa_idx;
98         void *inb_sa;
99         uint64_t w0;
100
101         if (cq_w1 & BIT(11)) {
102                 inner = (struct rte_mbuf *)(rte_be_to_cpu_64(hdr->wqe_ptr) -
103                                             sizeof(struct rte_mbuf));
104
105                 /* Get SPI from CPT_PARSE_S's cookie(already swapped) */
106                 w0 = hdr->w0.u64;
107                 sa_idx = w0 >> 32;
108
109                 inb_sa = roc_nix_inl_ot_ipsec_inb_sa(sa_base, sa_idx);
110                 inb_priv = roc_nix_inl_ot_ipsec_inb_sa_sw_rsvd(inb_sa);
111
112                 /* Update dynamic field with userdata */
113                 *rte_security_dynfield(inner) = (uint64_t)inb_priv->userdata;
114
115                 /* Update l2 hdr length first */
116                 inner->pkt_len = (hdr->w2.il3_off -
117                                   sizeof(struct cpt_parse_hdr_s) - (w0 & 0x7));
118
119                 /* Store meta in lmtline to free
120                  * Assume all meta's from same aura.
121                  */
122                 *(uint64_t *)(laddr + (*loff << 3)) = (uint64_t)mbuf;
123                 *loff = *loff + 1;
124
125                 return inner;
126         }
127         return mbuf;
128 }
129
130 #if defined(RTE_ARCH_ARM64)
131
132 static __rte_always_inline struct rte_mbuf *
133 nix_sec_meta_to_mbuf(uint64_t cq_w1, uintptr_t sa_base, uintptr_t laddr,
134                      uint8_t *loff, struct rte_mbuf *mbuf, uint16_t data_off,
135                      uint8x16_t *rx_desc_field1, uint64_t *ol_flags)
136 {
137         const void *__p = (void *)((uintptr_t)mbuf + (uint16_t)data_off);
138         const struct cpt_parse_hdr_s *hdr = (const struct cpt_parse_hdr_s *)__p;
139         struct cn10k_inb_priv_data *inb_priv;
140         struct rte_mbuf *inner;
141         uint64_t *sg, res_w1;
142         uint32_t sa_idx;
143         void *inb_sa;
144         uint16_t len;
145         uint64_t w0;
146
147         if (cq_w1 & BIT(11)) {
148                 inner = (struct rte_mbuf *)(rte_be_to_cpu_64(hdr->wqe_ptr) -
149                                             sizeof(struct rte_mbuf));
150                 /* Get SPI from CPT_PARSE_S's cookie(already swapped) */
151                 w0 = hdr->w0.u64;
152                 sa_idx = w0 >> 32;
153
154                 inb_sa = roc_nix_inl_ot_ipsec_inb_sa(sa_base, sa_idx);
155                 inb_priv = roc_nix_inl_ot_ipsec_inb_sa_sw_rsvd(inb_sa);
156
157                 /* Update dynamic field with userdata */
158                 *rte_security_dynfield(inner) = (uint64_t)inb_priv->userdata;
159
160                 /* CPT result(struct cpt_cn10k_res_s) is at
161                  * after first IOVA in meta
162                  */
163                 sg = (uint64_t *)(inner + 1);
164                 res_w1 = sg[10];
165
166                 /* Clear checksum flags and update security flag */
167                 *ol_flags &= ~(RTE_MBUF_F_RX_L4_CKSUM_MASK | RTE_MBUF_F_RX_IP_CKSUM_MASK);
168                 *ol_flags |= (((res_w1 & 0xFF) == CPT_COMP_WARN) ?
169                               RTE_MBUF_F_RX_SEC_OFFLOAD :
170                               (RTE_MBUF_F_RX_SEC_OFFLOAD | RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED));
171                 /* Calculate inner packet length */
172                 len = ((res_w1 >> 16) & 0xFFFF) + hdr->w2.il3_off -
173                         sizeof(struct cpt_parse_hdr_s) - (w0 & 0x7);
174                 /* Update pkt_len and data_len */
175                 *rx_desc_field1 = vsetq_lane_u16(len, *rx_desc_field1, 2);
176                 *rx_desc_field1 = vsetq_lane_u16(len, *rx_desc_field1, 4);
177
178                 /* Store meta in lmtline to free
179                  * Assume all meta's from same aura.
180                  */
181                 *(uint64_t *)(laddr + (*loff << 3)) = (uint64_t)mbuf;
182                 *loff = *loff + 1;
183
184                 /* Return inner mbuf */
185                 return inner;
186         }
187
188         /* Return same mbuf as it is not a decrypted pkt */
189         return mbuf;
190 }
191 #endif
192
193 static __rte_always_inline uint32_t
194 nix_ptype_get(const void *const lookup_mem, const uint64_t in)
195 {
196         const uint16_t *const ptype = lookup_mem;
197         const uint16_t lh_lg_lf = (in & 0xFFF0000000000000) >> 52;
198         const uint16_t tu_l2 = ptype[(in & 0x000FFFF000000000) >> 36];
199         const uint16_t il4_tu = ptype[PTYPE_NON_TUNNEL_ARRAY_SZ + lh_lg_lf];
200
201         return (il4_tu << PTYPE_NON_TUNNEL_WIDTH) | tu_l2;
202 }
203
204 static __rte_always_inline uint32_t
205 nix_rx_olflags_get(const void *const lookup_mem, const uint64_t in)
206 {
207         const uint32_t *const ol_flags =
208                 (const uint32_t *)((const uint8_t *)lookup_mem +
209                                    PTYPE_ARRAY_SZ);
210
211         return ol_flags[(in & 0xfff00000) >> 20];
212 }
213
214 static inline uint64_t
215 nix_update_match_id(const uint16_t match_id, uint64_t ol_flags,
216                     struct rte_mbuf *mbuf)
217 {
218         /* There is no separate bit to check match_id
219          * is valid or not? and no flag to identify it is an
220          * RTE_FLOW_ACTION_TYPE_FLAG vs RTE_FLOW_ACTION_TYPE_MARK
221          * action. The former case addressed through 0 being invalid
222          * value and inc/dec match_id pair when MARK is activated.
223          * The later case addressed through defining
224          * CNXK_FLOW_MARK_DEFAULT as value for
225          * RTE_FLOW_ACTION_TYPE_MARK.
226          * This would translate to not use
227          * CNXK_FLOW_ACTION_FLAG_DEFAULT - 1 and
228          * CNXK_FLOW_ACTION_FLAG_DEFAULT for match_id.
229          * i.e valid mark_id's are from
230          * 0 to CNXK_FLOW_ACTION_FLAG_DEFAULT - 2
231          */
232         if (likely(match_id)) {
233                 ol_flags |= RTE_MBUF_F_RX_FDIR;
234                 if (match_id != CNXK_FLOW_ACTION_FLAG_DEFAULT) {
235                         ol_flags |= RTE_MBUF_F_RX_FDIR_ID;
236                         mbuf->hash.fdir.hi = match_id - 1;
237                 }
238         }
239
240         return ol_flags;
241 }
242
243 static __rte_always_inline void
244 nix_cqe_xtract_mseg(const union nix_rx_parse_u *rx, struct rte_mbuf *mbuf,
245                     uint64_t rearm, const uint16_t flags)
246 {
247         const rte_iova_t *iova_list;
248         struct rte_mbuf *head;
249         const rte_iova_t *eol;
250         uint8_t nb_segs;
251         uint64_t sg;
252
253         sg = *(const uint64_t *)(rx + 1);
254         nb_segs = (sg >> 48) & 0x3;
255
256         if (nb_segs == 1) {
257                 mbuf->next = NULL;
258                 return;
259         }
260
261         mbuf->pkt_len = (rx->pkt_lenm1 + 1) - (flags & NIX_RX_OFFLOAD_TSTAMP_F ?
262                                                CNXK_NIX_TIMESYNC_RX_OFFSET : 0);
263         mbuf->data_len = (sg & 0xFFFF) - (flags & NIX_RX_OFFLOAD_TSTAMP_F ?
264                                           CNXK_NIX_TIMESYNC_RX_OFFSET : 0);
265         mbuf->nb_segs = nb_segs;
266         sg = sg >> 16;
267
268         eol = ((const rte_iova_t *)(rx + 1) + ((rx->desc_sizem1 + 1) << 1));
269         /* Skip SG_S and first IOVA*/
270         iova_list = ((const rte_iova_t *)(rx + 1)) + 2;
271         nb_segs--;
272
273         rearm = rearm & ~0xFFFF;
274
275         head = mbuf;
276         while (nb_segs) {
277                 mbuf->next = ((struct rte_mbuf *)*iova_list) - 1;
278                 mbuf = mbuf->next;
279
280                 RTE_MEMPOOL_CHECK_COOKIES(mbuf->pool, (void **)&mbuf, 1, 1);
281
282                 mbuf->data_len = sg & 0xFFFF;
283                 sg = sg >> 16;
284                 *(uint64_t *)(&mbuf->rearm_data) = rearm;
285                 nb_segs--;
286                 iova_list++;
287
288                 if (!nb_segs && (iova_list + 1 < eol)) {
289                         sg = *(const uint64_t *)(iova_list);
290                         nb_segs = (sg >> 48) & 0x3;
291                         head->nb_segs += nb_segs;
292                         iova_list = (const rte_iova_t *)(iova_list + 1);
293                 }
294         }
295         mbuf->next = NULL;
296 }
297
298 static __rte_always_inline void
299 cn10k_nix_cqe_to_mbuf(const struct nix_cqe_hdr_s *cq, const uint32_t tag,
300                       struct rte_mbuf *mbuf, const void *lookup_mem,
301                       const uint64_t val, const uint16_t flag)
302 {
303         const union nix_rx_parse_u *rx =
304                 (const union nix_rx_parse_u *)((const uint64_t *)cq + 1);
305         const uint64_t w1 = *(const uint64_t *)rx;
306         uint16_t len = rx->pkt_lenm1 + 1;
307         uint64_t ol_flags = 0;
308
309         /* Mark mempool obj as "get" as it is alloc'ed by NIX */
310         RTE_MEMPOOL_CHECK_COOKIES(mbuf->pool, (void **)&mbuf, 1, 1);
311
312         if (flag & NIX_RX_OFFLOAD_PTYPE_F)
313                 mbuf->packet_type = nix_ptype_get(lookup_mem, w1);
314         else
315                 mbuf->packet_type = 0;
316
317         if (flag & NIX_RX_OFFLOAD_RSS_F) {
318                 mbuf->hash.rss = tag;
319                 ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
320         }
321
322         /* Process Security packets */
323         if (flag & NIX_RX_OFFLOAD_SECURITY_F) {
324                 if (w1 & BIT(11)) {
325                         /* CPT result(struct cpt_cn10k_res_s) is at
326                          * after first IOVA in meta
327                          */
328                         const uint64_t *sg = (const uint64_t *)(mbuf + 1);
329                         const uint64_t res_w1 = sg[10];
330                         const uint16_t uc_cc = res_w1 & 0xFF;
331
332                         /* Rlen */
333                         len = ((res_w1 >> 16) & 0xFFFF) + mbuf->pkt_len;
334                         ol_flags |= ((uc_cc == CPT_COMP_WARN) ?
335                                                    RTE_MBUF_F_RX_SEC_OFFLOAD :
336                                                    (RTE_MBUF_F_RX_SEC_OFFLOAD |
337                                               RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED));
338                 } else {
339                         if (flag & NIX_RX_OFFLOAD_CHECKSUM_F)
340                                 ol_flags |= nix_rx_olflags_get(lookup_mem, w1);
341                 }
342         } else {
343                 if (flag & NIX_RX_OFFLOAD_CHECKSUM_F)
344                         ol_flags |= nix_rx_olflags_get(lookup_mem, w1);
345         }
346
347         if (flag & NIX_RX_OFFLOAD_VLAN_STRIP_F) {
348                 if (rx->vtag0_gone) {
349                         ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
350                         mbuf->vlan_tci = rx->vtag0_tci;
351                 }
352                 if (rx->vtag1_gone) {
353                         ol_flags |= RTE_MBUF_F_RX_QINQ | RTE_MBUF_F_RX_QINQ_STRIPPED;
354                         mbuf->vlan_tci_outer = rx->vtag1_tci;
355                 }
356         }
357
358         if (flag & NIX_RX_OFFLOAD_MARK_UPDATE_F)
359                 ol_flags = nix_update_match_id(rx->match_id, ol_flags, mbuf);
360
361         mbuf->ol_flags = ol_flags;
362         mbuf->pkt_len = len;
363         mbuf->data_len = len;
364         *(uint64_t *)(&mbuf->rearm_data) = val;
365
366         if (flag & NIX_RX_MULTI_SEG_F)
367                 nix_cqe_xtract_mseg(rx, mbuf, val, flag);
368         else
369                 mbuf->next = NULL;
370 }
371
372 static inline uint16_t
373 nix_rx_nb_pkts(struct cn10k_eth_rxq *rxq, const uint64_t wdata,
374                const uint16_t pkts, const uint32_t qmask)
375 {
376         uint32_t available = rxq->available;
377
378         /* Update the available count if cached value is not enough */
379         if (unlikely(available < pkts)) {
380                 uint64_t reg, head, tail;
381
382                 /* Use LDADDA version to avoid reorder */
383                 reg = roc_atomic64_add_sync(wdata, rxq->cq_status);
384                 /* CQ_OP_STATUS operation error */
385                 if (reg & BIT_ULL(NIX_CQ_OP_STAT_OP_ERR) ||
386                     reg & BIT_ULL(NIX_CQ_OP_STAT_CQ_ERR))
387                         return 0;
388
389                 tail = reg & 0xFFFFF;
390                 head = (reg >> 20) & 0xFFFFF;
391                 if (tail < head)
392                         available = tail - head + qmask + 1;
393                 else
394                         available = tail - head;
395
396                 rxq->available = available;
397         }
398
399         return RTE_MIN(pkts, available);
400 }
401
402 static __rte_always_inline uint16_t
403 cn10k_nix_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts,
404                     const uint16_t flags)
405 {
406         struct cn10k_eth_rxq *rxq = rx_queue;
407         const uint64_t mbuf_init = rxq->mbuf_initializer;
408         const void *lookup_mem = rxq->lookup_mem;
409         const uint64_t data_off = rxq->data_off;
410         const uintptr_t desc = rxq->desc;
411         const uint64_t wdata = rxq->wdata;
412         const uint32_t qmask = rxq->qmask;
413         uint64_t lbase = rxq->lmt_base;
414         uint16_t packets = 0, nb_pkts;
415         uint8_t loff = 0, lnum = 0;
416         uint32_t head = rxq->head;
417         struct nix_cqe_hdr_s *cq;
418         struct rte_mbuf *mbuf;
419         uint64_t aura_handle;
420         uint64_t sa_base;
421         uint16_t lmt_id;
422         uint64_t laddr;
423
424         nb_pkts = nix_rx_nb_pkts(rxq, wdata, pkts, qmask);
425
426         if (flags & NIX_RX_OFFLOAD_SECURITY_F) {
427                 aura_handle = rxq->aura_handle;
428                 sa_base = rxq->sa_base;
429                 sa_base &= ~(ROC_NIX_INL_SA_BASE_ALIGN - 1);
430                 ROC_LMT_BASE_ID_GET(lbase, lmt_id);
431                 laddr = lbase;
432                 laddr += 8;
433         }
434
435         while (packets < nb_pkts) {
436                 /* Prefetch N desc ahead */
437                 rte_prefetch_non_temporal(
438                         (void *)(desc + (CQE_SZ((head + 2) & qmask))));
439                 cq = (struct nix_cqe_hdr_s *)(desc + CQE_SZ(head));
440
441                 mbuf = nix_get_mbuf_from_cqe(cq, data_off);
442
443                 /* Translate meta to mbuf */
444                 if (flags & NIX_RX_OFFLOAD_SECURITY_F) {
445                         const uint64_t cq_w1 = *((const uint64_t *)cq + 1);
446
447                         mbuf = nix_sec_meta_to_mbuf_sc(cq_w1, sa_base, laddr,
448                                                        &loff, mbuf, data_off);
449                 }
450
451                 cn10k_nix_cqe_to_mbuf(cq, cq->tag, mbuf, lookup_mem, mbuf_init,
452                                       flags);
453                 cnxk_nix_mbuf_to_tstamp(mbuf, rxq->tstamp,
454                                         (flags & NIX_RX_OFFLOAD_TSTAMP_F),
455                                         (flags & NIX_RX_MULTI_SEG_F),
456                                         (uint64_t *)((uint8_t *)mbuf
457                                                                 + data_off));
458                 rx_pkts[packets++] = mbuf;
459                 roc_prefetch_store_keep(mbuf);
460                 head++;
461                 head &= qmask;
462
463                 if (flags & NIX_RX_OFFLOAD_SECURITY_F) {
464                         /* Flush when we don't have space for 4 meta */
465                         if ((15 - loff) < 1) {
466                                 nix_sec_flush_meta(laddr, lmt_id + lnum, loff,
467                                                    aura_handle);
468                                 lnum++;
469                                 lnum &= BIT_ULL(ROC_LMT_LINES_PER_CORE_LOG2) -
470                                         1;
471                                 /* First pointer starts at 8B offset */
472                                 laddr = (uintptr_t)LMT_OFF(lbase, lnum, 8);
473                                 loff = 0;
474                         }
475                 }
476         }
477
478         rxq->head = head;
479         rxq->available -= nb_pkts;
480
481         /* Free all the CQs that we've processed */
482         plt_write64((wdata | nb_pkts), rxq->cq_door);
483
484         /* Free remaining meta buffers if any */
485         if (flags & NIX_RX_OFFLOAD_SECURITY_F && loff) {
486                 nix_sec_flush_meta(laddr, lmt_id + lnum, loff, aura_handle);
487                 plt_io_wmb();
488         }
489
490         return nb_pkts;
491 }
492
493 #if defined(RTE_ARCH_ARM64)
494
495 static __rte_always_inline uint64_t
496 nix_vlan_update(const uint64_t w2, uint64_t ol_flags, uint8x16_t *f)
497 {
498         if (w2 & BIT_ULL(21) /* vtag0_gone */) {
499                 ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
500                 *f = vsetq_lane_u16((uint16_t)(w2 >> 32), *f, 5);
501         }
502
503         return ol_flags;
504 }
505
506 static __rte_always_inline uint64_t
507 nix_qinq_update(const uint64_t w2, uint64_t ol_flags, struct rte_mbuf *mbuf)
508 {
509         if (w2 & BIT_ULL(23) /* vtag1_gone */) {
510                 ol_flags |= RTE_MBUF_F_RX_QINQ | RTE_MBUF_F_RX_QINQ_STRIPPED;
511                 mbuf->vlan_tci_outer = (uint16_t)(w2 >> 48);
512         }
513
514         return ol_flags;
515 }
516
517 static __rte_always_inline uint16_t
518 cn10k_nix_recv_pkts_vector(void *args, struct rte_mbuf **mbufs, uint16_t pkts,
519                            const uint16_t flags, void *lookup_mem,
520                            struct cnxk_timesync_info *tstamp,
521                            uintptr_t lmt_base)
522 {
523         struct cn10k_eth_rxq *rxq = args;
524         const uint64_t mbuf_initializer = (flags & NIX_RX_VWQE_F) ?
525                                                         *(uint64_t *)args :
526                                                         rxq->mbuf_initializer;
527         const uint64x2_t data_off = flags & NIX_RX_VWQE_F ?
528                                                   vdupq_n_u64(0x80ULL) :
529                                                   vdupq_n_u64(rxq->data_off);
530         const uint32_t qmask = flags & NIX_RX_VWQE_F ? 0 : rxq->qmask;
531         const uint64_t wdata = flags & NIX_RX_VWQE_F ? 0 : rxq->wdata;
532         const uintptr_t desc = flags & NIX_RX_VWQE_F ? 0 : rxq->desc;
533         uint64x2_t cq0_w8, cq1_w8, cq2_w8, cq3_w8, mbuf01, mbuf23;
534         uint64_t ol_flags0, ol_flags1, ol_flags2, ol_flags3;
535         uint64x2_t rearm0 = vdupq_n_u64(mbuf_initializer);
536         uint64x2_t rearm1 = vdupq_n_u64(mbuf_initializer);
537         uint64x2_t rearm2 = vdupq_n_u64(mbuf_initializer);
538         uint64x2_t rearm3 = vdupq_n_u64(mbuf_initializer);
539         struct rte_mbuf *mbuf0, *mbuf1, *mbuf2, *mbuf3;
540         uint64_t aura_handle, lbase, laddr;
541         uint8_t loff = 0, lnum = 0;
542         uint8x16_t f0, f1, f2, f3;
543         uint16_t lmt_id, d_off;
544         uint16_t packets = 0;
545         uint16_t pkts_left;
546         uintptr_t sa_base;
547         uint32_t head;
548         uintptr_t cq0;
549
550         if (!(flags & NIX_RX_VWQE_F)) {
551                 lookup_mem = rxq->lookup_mem;
552                 head = rxq->head;
553
554                 pkts = nix_rx_nb_pkts(rxq, wdata, pkts, qmask);
555                 pkts_left = pkts & (NIX_DESCS_PER_LOOP - 1);
556                 /* Packets has to be floor-aligned to NIX_DESCS_PER_LOOP */
557                 pkts = RTE_ALIGN_FLOOR(pkts, NIX_DESCS_PER_LOOP);
558                 if (flags & NIX_RX_OFFLOAD_TSTAMP_F)
559                         tstamp = rxq->tstamp;
560         } else {
561                 RTE_SET_USED(head);
562         }
563
564         if (flags & NIX_RX_OFFLOAD_SECURITY_F) {
565                 if (flags & NIX_RX_VWQE_F) {
566                         uint16_t port;
567
568                         mbuf0 = (struct rte_mbuf *)((uintptr_t)mbufs[0] -
569                                                     sizeof(struct rte_mbuf));
570                         /* Pick first mbuf's aura handle assuming all
571                          * mbufs are from a vec and are from same RQ.
572                          */
573                         aura_handle = mbuf0->pool->pool_id;
574                         /* Calculate offset from mbuf to actual data area */
575                         d_off = ((uintptr_t)mbuf0->buf_addr - (uintptr_t)mbuf0);
576                         d_off += (mbuf_initializer & 0xFFFF);
577
578                         /* Get SA Base from lookup tbl using port_id */
579                         port = mbuf_initializer >> 48;
580                         sa_base = cnxk_nix_sa_base_get(port, lookup_mem);
581
582                         lbase = lmt_base;
583                 } else {
584                         aura_handle = rxq->aura_handle;
585                         d_off = rxq->data_off;
586                         sa_base = rxq->sa_base;
587                         lbase = rxq->lmt_base;
588                 }
589                 sa_base &= ~(ROC_NIX_INL_SA_BASE_ALIGN - 1);
590                 ROC_LMT_BASE_ID_GET(lbase, lmt_id);
591                 lnum = 0;
592                 laddr = lbase;
593                 laddr += 8;
594         }
595
596         while (packets < pkts) {
597                 if (!(flags & NIX_RX_VWQE_F)) {
598                         /* Exit loop if head is about to wrap and become
599                          * unaligned.
600                          */
601                         if (((head + NIX_DESCS_PER_LOOP - 1) & qmask) <
602                             NIX_DESCS_PER_LOOP) {
603                                 pkts_left += (pkts - packets);
604                                 break;
605                         }
606
607                         cq0 = desc + CQE_SZ(head);
608                 } else {
609                         cq0 = (uintptr_t)&mbufs[packets];
610                 }
611
612                 /* Prefetch N desc ahead */
613                 rte_prefetch_non_temporal(CQE_PTR_OFF(cq0, 4, 64, flags));
614                 rte_prefetch_non_temporal(CQE_PTR_OFF(cq0, 5, 64, flags));
615                 rte_prefetch_non_temporal(CQE_PTR_OFF(cq0, 6, 64, flags));
616                 rte_prefetch_non_temporal(CQE_PTR_OFF(cq0, 7, 64, flags));
617
618                 /* Get NIX_RX_SG_S for size and buffer pointer */
619                 cq0_w8 = vld1q_u64(CQE_PTR_OFF(cq0, 0, 64, flags));
620                 cq1_w8 = vld1q_u64(CQE_PTR_OFF(cq0, 1, 64, flags));
621                 cq2_w8 = vld1q_u64(CQE_PTR_OFF(cq0, 2, 64, flags));
622                 cq3_w8 = vld1q_u64(CQE_PTR_OFF(cq0, 3, 64, flags));
623
624                 if (!(flags & NIX_RX_VWQE_F)) {
625                         /* Extract mbuf from NIX_RX_SG_S */
626                         mbuf01 = vzip2q_u64(cq0_w8, cq1_w8);
627                         mbuf23 = vzip2q_u64(cq2_w8, cq3_w8);
628                         mbuf01 = vqsubq_u64(mbuf01, data_off);
629                         mbuf23 = vqsubq_u64(mbuf23, data_off);
630                 } else {
631                         mbuf01 =
632                                 vsubq_u64(vld1q_u64((uint64_t *)cq0), data_off);
633                         mbuf23 = vsubq_u64(vld1q_u64((uint64_t *)(cq0 + 16)),
634                                            data_off);
635                 }
636
637                 /* Move mbufs to scalar registers for future use */
638                 mbuf0 = (struct rte_mbuf *)vgetq_lane_u64(mbuf01, 0);
639                 mbuf1 = (struct rte_mbuf *)vgetq_lane_u64(mbuf01, 1);
640                 mbuf2 = (struct rte_mbuf *)vgetq_lane_u64(mbuf23, 0);
641                 mbuf3 = (struct rte_mbuf *)vgetq_lane_u64(mbuf23, 1);
642
643                 /* Mask to get packet len from NIX_RX_SG_S */
644                 const uint8x16_t shuf_msk = {
645                         0xFF, 0xFF, /* pkt_type set as unknown */
646                         0xFF, 0xFF, /* pkt_type set as unknown */
647                         0,    1,    /* octet 1~0, low 16 bits pkt_len */
648                         0xFF, 0xFF, /* skip high 16 bits pkt_len, zero out */
649                         0,    1,    /* octet 1~0, 16 bits data_len */
650                         0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
651
652                 /* Form the rx_descriptor_fields1 with pkt_len and data_len */
653                 f0 = vqtbl1q_u8(cq0_w8, shuf_msk);
654                 f1 = vqtbl1q_u8(cq1_w8, shuf_msk);
655                 f2 = vqtbl1q_u8(cq2_w8, shuf_msk);
656                 f3 = vqtbl1q_u8(cq3_w8, shuf_msk);
657
658                 if (flags & NIX_RX_OFFLOAD_SECURITY_F) {
659                         /* Prefetch probable CPT parse header area */
660                         rte_prefetch_non_temporal(RTE_PTR_ADD(mbuf0, d_off));
661                         rte_prefetch_non_temporal(RTE_PTR_ADD(mbuf1, d_off));
662                         rte_prefetch_non_temporal(RTE_PTR_ADD(mbuf2, d_off));
663                         rte_prefetch_non_temporal(RTE_PTR_ADD(mbuf3, d_off));
664                 }
665
666                 /* Load CQE word0 and word 1 */
667                 const uint64_t cq0_w0 = *CQE_PTR_OFF(cq0, 0, 0, flags);
668                 const uint64_t cq0_w1 = *CQE_PTR_OFF(cq0, 0, 8, flags);
669                 const uint64_t cq1_w0 = *CQE_PTR_OFF(cq0, 1, 0, flags);
670                 const uint64_t cq1_w1 = *CQE_PTR_OFF(cq0, 1, 8, flags);
671                 const uint64_t cq2_w0 = *CQE_PTR_OFF(cq0, 2, 0, flags);
672                 const uint64_t cq2_w1 = *CQE_PTR_OFF(cq0, 2, 8, flags);
673                 const uint64_t cq3_w0 = *CQE_PTR_OFF(cq0, 3, 0, flags);
674                 const uint64_t cq3_w1 = *CQE_PTR_OFF(cq0, 3, 8, flags);
675
676                 if (flags & NIX_RX_OFFLOAD_RSS_F) {
677                         /* Fill rss in the rx_descriptor_fields1 */
678                         f0 = vsetq_lane_u32(cq0_w0, f0, 3);
679                         f1 = vsetq_lane_u32(cq1_w0, f1, 3);
680                         f2 = vsetq_lane_u32(cq2_w0, f2, 3);
681                         f3 = vsetq_lane_u32(cq3_w0, f3, 3);
682                         ol_flags0 = RTE_MBUF_F_RX_RSS_HASH;
683                         ol_flags1 = RTE_MBUF_F_RX_RSS_HASH;
684                         ol_flags2 = RTE_MBUF_F_RX_RSS_HASH;
685                         ol_flags3 = RTE_MBUF_F_RX_RSS_HASH;
686                 } else {
687                         ol_flags0 = 0;
688                         ol_flags1 = 0;
689                         ol_flags2 = 0;
690                         ol_flags3 = 0;
691                 }
692
693                 if (flags & NIX_RX_OFFLOAD_PTYPE_F) {
694                         /* Fill packet_type in the rx_descriptor_fields1 */
695                         f0 = vsetq_lane_u32(nix_ptype_get(lookup_mem, cq0_w1),
696                                             f0, 0);
697                         f1 = vsetq_lane_u32(nix_ptype_get(lookup_mem, cq1_w1),
698                                             f1, 0);
699                         f2 = vsetq_lane_u32(nix_ptype_get(lookup_mem, cq2_w1),
700                                             f2, 0);
701                         f3 = vsetq_lane_u32(nix_ptype_get(lookup_mem, cq3_w1),
702                                             f3, 0);
703                 }
704
705                 if (flags & NIX_RX_OFFLOAD_CHECKSUM_F) {
706                         ol_flags0 |= nix_rx_olflags_get(lookup_mem, cq0_w1);
707                         ol_flags1 |= nix_rx_olflags_get(lookup_mem, cq1_w1);
708                         ol_flags2 |= nix_rx_olflags_get(lookup_mem, cq2_w1);
709                         ol_flags3 |= nix_rx_olflags_get(lookup_mem, cq3_w1);
710                 }
711
712                 /* Translate meta to mbuf */
713                 if (flags & NIX_RX_OFFLOAD_SECURITY_F) {
714                         /* Checksum ol_flags will be cleared if mbuf is meta */
715                         mbuf0 = nix_sec_meta_to_mbuf(cq0_w1, sa_base, laddr,
716                                                      &loff, mbuf0, d_off, &f0,
717                                                      &ol_flags0);
718                         mbuf01 = vsetq_lane_u64((uint64_t)mbuf0, mbuf01, 0);
719
720                         mbuf1 = nix_sec_meta_to_mbuf(cq1_w1, sa_base, laddr,
721                                                      &loff, mbuf1, d_off, &f1,
722                                                      &ol_flags1);
723                         mbuf01 = vsetq_lane_u64((uint64_t)mbuf1, mbuf01, 1);
724
725                         mbuf2 = nix_sec_meta_to_mbuf(cq2_w1, sa_base, laddr,
726                                                      &loff, mbuf2, d_off, &f2,
727                                                      &ol_flags2);
728                         mbuf23 = vsetq_lane_u64((uint64_t)mbuf2, mbuf23, 0);
729
730                         mbuf3 = nix_sec_meta_to_mbuf(cq3_w1, sa_base, laddr,
731                                                      &loff, mbuf3, d_off, &f3,
732                                                      &ol_flags3);
733                         mbuf23 = vsetq_lane_u64((uint64_t)mbuf3, mbuf23, 1);
734                 }
735
736                 if (flags & NIX_RX_OFFLOAD_VLAN_STRIP_F) {
737                         uint64_t cq0_w2 = *(uint64_t *)(cq0 + CQE_SZ(0) + 16);
738                         uint64_t cq1_w2 = *(uint64_t *)(cq0 + CQE_SZ(1) + 16);
739                         uint64_t cq2_w2 = *(uint64_t *)(cq0 + CQE_SZ(2) + 16);
740                         uint64_t cq3_w2 = *(uint64_t *)(cq0 + CQE_SZ(3) + 16);
741
742                         ol_flags0 = nix_vlan_update(cq0_w2, ol_flags0, &f0);
743                         ol_flags1 = nix_vlan_update(cq1_w2, ol_flags1, &f1);
744                         ol_flags2 = nix_vlan_update(cq2_w2, ol_flags2, &f2);
745                         ol_flags3 = nix_vlan_update(cq3_w2, ol_flags3, &f3);
746
747                         ol_flags0 = nix_qinq_update(cq0_w2, ol_flags0, mbuf0);
748                         ol_flags1 = nix_qinq_update(cq1_w2, ol_flags1, mbuf1);
749                         ol_flags2 = nix_qinq_update(cq2_w2, ol_flags2, mbuf2);
750                         ol_flags3 = nix_qinq_update(cq3_w2, ol_flags3, mbuf3);
751                 }
752
753                 if (flags & NIX_RX_OFFLOAD_MARK_UPDATE_F) {
754                         ol_flags0 = nix_update_match_id(
755                                 *(uint16_t *)CQE_PTR_OFF(cq0, 0, 38, flags),
756                                 ol_flags0, mbuf0);
757                         ol_flags1 = nix_update_match_id(
758                                 *(uint16_t *)CQE_PTR_OFF(cq0, 1, 38, flags),
759                                 ol_flags1, mbuf1);
760                         ol_flags2 = nix_update_match_id(
761                                 *(uint16_t *)CQE_PTR_OFF(cq0, 2, 38, flags),
762                                 ol_flags2, mbuf2);
763                         ol_flags3 = nix_update_match_id(
764                                 *(uint16_t *)CQE_PTR_OFF(cq0, 3, 38, flags),
765                                 ol_flags3, mbuf3);
766                 }
767
768                 if (flags & NIX_RX_OFFLOAD_TSTAMP_F) {
769                         const uint16x8_t len_off = {
770                                 0,                           /* ptype   0:15 */
771                                 0,                           /* ptype  16:32 */
772                                 CNXK_NIX_TIMESYNC_RX_OFFSET, /* pktlen  0:15*/
773                                 0,                           /* pktlen 16:32 */
774                                 CNXK_NIX_TIMESYNC_RX_OFFSET, /* datalen 0:15 */
775                                 0,
776                                 0,
777                                 0};
778                         const uint32x4_t ptype = {RTE_PTYPE_L2_ETHER_TIMESYNC,
779                                                   RTE_PTYPE_L2_ETHER_TIMESYNC,
780                                                   RTE_PTYPE_L2_ETHER_TIMESYNC,
781                                                   RTE_PTYPE_L2_ETHER_TIMESYNC};
782                         const uint64_t ts_olf = RTE_MBUF_F_RX_IEEE1588_PTP |
783                                                 RTE_MBUF_F_RX_IEEE1588_TMST |
784                                                 tstamp->rx_tstamp_dynflag;
785                         const uint32x4_t and_mask = {0x1, 0x2, 0x4, 0x8};
786                         uint64x2_t ts01, ts23, mask;
787                         uint64_t ts[4];
788                         uint8_t res;
789
790                         /* Subtract timesync length from total pkt length. */
791                         f0 = vsubq_u16(f0, len_off);
792                         f1 = vsubq_u16(f1, len_off);
793                         f2 = vsubq_u16(f2, len_off);
794                         f3 = vsubq_u16(f3, len_off);
795
796                         /* Get the address of actual timestamp. */
797                         ts01 = vaddq_u64(mbuf01, data_off);
798                         ts23 = vaddq_u64(mbuf23, data_off);
799                         /* Load timestamp from address. */
800                         ts01 = vsetq_lane_u64(*(uint64_t *)vgetq_lane_u64(ts01,
801                                                                           0),
802                                               ts01, 0);
803                         ts01 = vsetq_lane_u64(*(uint64_t *)vgetq_lane_u64(ts01,
804                                                                           1),
805                                               ts01, 1);
806                         ts23 = vsetq_lane_u64(*(uint64_t *)vgetq_lane_u64(ts23,
807                                                                           0),
808                                               ts23, 0);
809                         ts23 = vsetq_lane_u64(*(uint64_t *)vgetq_lane_u64(ts23,
810                                                                           1),
811                                               ts23, 1);
812                         /* Convert from be to cpu byteorder. */
813                         ts01 = vrev64q_u8(ts01);
814                         ts23 = vrev64q_u8(ts23);
815                         /* Store timestamp into scalar for later use. */
816                         ts[0] = vgetq_lane_u64(ts01, 0);
817                         ts[1] = vgetq_lane_u64(ts01, 1);
818                         ts[2] = vgetq_lane_u64(ts23, 0);
819                         ts[3] = vgetq_lane_u64(ts23, 1);
820
821                         /* Store timestamp into dynfield. */
822                         *cnxk_nix_timestamp_dynfield(mbuf0, tstamp) = ts[0];
823                         *cnxk_nix_timestamp_dynfield(mbuf1, tstamp) = ts[1];
824                         *cnxk_nix_timestamp_dynfield(mbuf2, tstamp) = ts[2];
825                         *cnxk_nix_timestamp_dynfield(mbuf3, tstamp) = ts[3];
826
827                         /* Generate ptype mask to filter L2 ether timesync */
828                         mask = vdupq_n_u32(vgetq_lane_u32(f0, 0));
829                         mask = vsetq_lane_u32(vgetq_lane_u32(f1, 0), mask, 1);
830                         mask = vsetq_lane_u32(vgetq_lane_u32(f2, 0), mask, 2);
831                         mask = vsetq_lane_u32(vgetq_lane_u32(f3, 0), mask, 3);
832
833                         /* Match against L2 ether timesync. */
834                         mask = vceqq_u32(mask, ptype);
835                         /* Convert from vector from scalar mask */
836                         res = vaddvq_u32(vandq_u32(mask, and_mask));
837                         res &= 0xF;
838
839                         if (res) {
840                                 /* Fill in the ol_flags for any packets that
841                                  * matched.
842                                  */
843                                 ol_flags0 |= ((res & 0x1) ? ts_olf : 0);
844                                 ol_flags1 |= ((res & 0x2) ? ts_olf : 0);
845                                 ol_flags2 |= ((res & 0x4) ? ts_olf : 0);
846                                 ol_flags3 |= ((res & 0x8) ? ts_olf : 0);
847
848                                 /* Update Rxq timestamp with the latest
849                                  * timestamp.
850                                  */
851                                 tstamp->rx_ready = 1;
852                                 tstamp->rx_tstamp = ts[31 - __builtin_clz(res)];
853                         }
854                 }
855
856                 /* Form rearm_data with ol_flags */
857                 rearm0 = vsetq_lane_u64(ol_flags0, rearm0, 1);
858                 rearm1 = vsetq_lane_u64(ol_flags1, rearm1, 1);
859                 rearm2 = vsetq_lane_u64(ol_flags2, rearm2, 1);
860                 rearm3 = vsetq_lane_u64(ol_flags3, rearm3, 1);
861
862                 /* Update rx_descriptor_fields1 */
863                 vst1q_u64((uint64_t *)mbuf0->rx_descriptor_fields1, f0);
864                 vst1q_u64((uint64_t *)mbuf1->rx_descriptor_fields1, f1);
865                 vst1q_u64((uint64_t *)mbuf2->rx_descriptor_fields1, f2);
866                 vst1q_u64((uint64_t *)mbuf3->rx_descriptor_fields1, f3);
867
868                 /* Update rearm_data */
869                 vst1q_u64((uint64_t *)mbuf0->rearm_data, rearm0);
870                 vst1q_u64((uint64_t *)mbuf1->rearm_data, rearm1);
871                 vst1q_u64((uint64_t *)mbuf2->rearm_data, rearm2);
872                 vst1q_u64((uint64_t *)mbuf3->rearm_data, rearm3);
873
874                 /* Store the mbufs to rx_pkts */
875                 vst1q_u64((uint64_t *)&mbufs[packets], mbuf01);
876                 vst1q_u64((uint64_t *)&mbufs[packets + 2], mbuf23);
877
878                 if (flags & NIX_RX_MULTI_SEG_F) {
879                         /* Multi segment is enable build mseg list for
880                          * individual mbufs in scalar mode.
881                          */
882                         nix_cqe_xtract_mseg((union nix_rx_parse_u *)
883                                             (CQE_PTR_OFF(cq0, 0, 8, flags)),
884                                             mbuf0, mbuf_initializer, flags);
885                         nix_cqe_xtract_mseg((union nix_rx_parse_u *)
886                                             (CQE_PTR_OFF(cq0, 1, 8, flags)),
887                                             mbuf1, mbuf_initializer, flags);
888                         nix_cqe_xtract_mseg((union nix_rx_parse_u *)
889                                             (CQE_PTR_OFF(cq0, 2, 8, flags)),
890                                             mbuf2, mbuf_initializer, flags);
891                         nix_cqe_xtract_mseg((union nix_rx_parse_u *)
892                                             (CQE_PTR_OFF(cq0, 3, 8, flags)),
893                                             mbuf3, mbuf_initializer, flags);
894                 } else {
895                         /* Update that no more segments */
896                         mbuf0->next = NULL;
897                         mbuf1->next = NULL;
898                         mbuf2->next = NULL;
899                         mbuf3->next = NULL;
900                 }
901
902                 /* Prefetch mbufs */
903                 roc_prefetch_store_keep(mbuf0);
904                 roc_prefetch_store_keep(mbuf1);
905                 roc_prefetch_store_keep(mbuf2);
906                 roc_prefetch_store_keep(mbuf3);
907
908                 /* Mark mempool obj as "get" as it is alloc'ed by NIX */
909                 RTE_MEMPOOL_CHECK_COOKIES(mbuf0->pool, (void **)&mbuf0, 1, 1);
910                 RTE_MEMPOOL_CHECK_COOKIES(mbuf1->pool, (void **)&mbuf1, 1, 1);
911                 RTE_MEMPOOL_CHECK_COOKIES(mbuf2->pool, (void **)&mbuf2, 1, 1);
912                 RTE_MEMPOOL_CHECK_COOKIES(mbuf3->pool, (void **)&mbuf3, 1, 1);
913
914                 packets += NIX_DESCS_PER_LOOP;
915
916                 if (!(flags & NIX_RX_VWQE_F)) {
917                         /* Advance head pointer and packets */
918                         head += NIX_DESCS_PER_LOOP;
919                         head &= qmask;
920                 }
921
922                 if (flags & NIX_RX_OFFLOAD_SECURITY_F) {
923                         /* Flush when we don't have space for 4 meta */
924                         if ((15 - loff) < 4) {
925                                 nix_sec_flush_meta(laddr, lmt_id + lnum, loff,
926                                                    aura_handle);
927                                 lnum++;
928                                 lnum &= BIT_ULL(ROC_LMT_LINES_PER_CORE_LOG2) -
929                                         1;
930                                 /* First pointer starts at 8B offset */
931                                 laddr = (uintptr_t)LMT_OFF(lbase, lnum, 8);
932                                 loff = 0;
933                         }
934                 }
935         }
936
937         if (flags & NIX_RX_OFFLOAD_SECURITY_F && loff) {
938                 nix_sec_flush_meta(laddr, lmt_id + lnum, loff, aura_handle);
939                 if (flags & NIX_RX_VWQE_F)
940                         plt_io_wmb();
941         }
942
943         if (flags & NIX_RX_VWQE_F)
944                 return packets;
945
946         rxq->head = head;
947         rxq->available -= packets;
948
949         rte_io_wmb();
950         /* Free all the CQs that we've processed */
951         plt_write64((rxq->wdata | packets), rxq->cq_door);
952
953         if (unlikely(pkts_left))
954                 packets += cn10k_nix_recv_pkts(args, &mbufs[packets], pkts_left,
955                                                flags);
956
957         return packets;
958 }
959
960 #else
961
962 static inline uint16_t
963 cn10k_nix_recv_pkts_vector(void *args, struct rte_mbuf **mbufs, uint16_t pkts,
964                            const uint16_t flags, void *lookup_mem,
965                            struct cnxk_timesync_info *tstamp,
966                            uintptr_t lmt_base)
967 {
968         RTE_SET_USED(args);
969         RTE_SET_USED(mbufs);
970         RTE_SET_USED(pkts);
971         RTE_SET_USED(flags);
972         RTE_SET_USED(lookup_mem);
973         RTE_SET_USED(tstamp);
974         RTE_SET_USED(lmt_base);
975
976         return 0;
977 }
978
979 #endif
980
981
982 #define RSS_F     NIX_RX_OFFLOAD_RSS_F
983 #define PTYPE_F   NIX_RX_OFFLOAD_PTYPE_F
984 #define CKSUM_F   NIX_RX_OFFLOAD_CHECKSUM_F
985 #define MARK_F    NIX_RX_OFFLOAD_MARK_UPDATE_F
986 #define TS_F      NIX_RX_OFFLOAD_TSTAMP_F
987 #define RX_VLAN_F NIX_RX_OFFLOAD_VLAN_STRIP_F
988 #define R_SEC_F   NIX_RX_OFFLOAD_SECURITY_F
989
990 /* [R_SEC_F] [RX_VLAN_F] [TS] [MARK] [CKSUM] [PTYPE] [RSS] */
991 #define NIX_RX_FASTPATH_MODES_0_15                                             \
992         R(no_offload, NIX_RX_OFFLOAD_NONE)                                     \
993         R(rss, RSS_F)                                                          \
994         R(ptype, PTYPE_F)                                                      \
995         R(ptype_rss, PTYPE_F | RSS_F)                                          \
996         R(cksum, CKSUM_F)                                                      \
997         R(cksum_rss, CKSUM_F | RSS_F)                                          \
998         R(cksum_ptype, CKSUM_F | PTYPE_F)                                      \
999         R(cksum_ptype_rss, CKSUM_F | PTYPE_F | RSS_F)                          \
1000         R(mark, MARK_F)                                                        \
1001         R(mark_rss, MARK_F | RSS_F)                                            \
1002         R(mark_ptype, MARK_F | PTYPE_F)                                        \
1003         R(mark_ptype_rss, MARK_F | PTYPE_F | RSS_F)                            \
1004         R(mark_cksum, MARK_F | CKSUM_F)                                        \
1005         R(mark_cksum_rss, MARK_F | CKSUM_F | RSS_F)                            \
1006         R(mark_cksum_ptype, MARK_F | CKSUM_F | PTYPE_F)                        \
1007         R(mark_cksum_ptype_rss, MARK_F | CKSUM_F | PTYPE_F | RSS_F)
1008
1009 #define NIX_RX_FASTPATH_MODES_16_31                                            \
1010         R(ts, TS_F)                                                            \
1011         R(ts_rss, TS_F | RSS_F)                                                \
1012         R(ts_ptype, TS_F | PTYPE_F)                                            \
1013         R(ts_ptype_rss, TS_F | PTYPE_F | RSS_F)                                \
1014         R(ts_cksum, TS_F | CKSUM_F)                                            \
1015         R(ts_cksum_rss, TS_F | CKSUM_F | RSS_F)                                \
1016         R(ts_cksum_ptype, TS_F | CKSUM_F | PTYPE_F)                            \
1017         R(ts_cksum_ptype_rss, TS_F | CKSUM_F | PTYPE_F | RSS_F)                \
1018         R(ts_mark, TS_F | MARK_F)                                              \
1019         R(ts_mark_rss, TS_F | MARK_F | RSS_F)                                  \
1020         R(ts_mark_ptype, TS_F | MARK_F | PTYPE_F)                              \
1021         R(ts_mark_ptype_rss, TS_F | MARK_F | PTYPE_F | RSS_F)                  \
1022         R(ts_mark_cksum, TS_F | MARK_F | CKSUM_F)                              \
1023         R(ts_mark_cksum_rss, TS_F | MARK_F | CKSUM_F | RSS_F)                  \
1024         R(ts_mark_cksum_ptype, TS_F | MARK_F | CKSUM_F | PTYPE_F)              \
1025         R(ts_mark_cksum_ptype_rss, TS_F | MARK_F | CKSUM_F | PTYPE_F | RSS_F)
1026
1027 #define NIX_RX_FASTPATH_MODES_32_47                                            \
1028         R(vlan, RX_VLAN_F)                                                     \
1029         R(vlan_rss, RX_VLAN_F | RSS_F)                                         \
1030         R(vlan_ptype, RX_VLAN_F | PTYPE_F)                                     \
1031         R(vlan_ptype_rss, RX_VLAN_F | PTYPE_F | RSS_F)                         \
1032         R(vlan_cksum, RX_VLAN_F | CKSUM_F)                                     \
1033         R(vlan_cksum_rss, RX_VLAN_F | CKSUM_F | RSS_F)                         \
1034         R(vlan_cksum_ptype, RX_VLAN_F | CKSUM_F | PTYPE_F)                     \
1035         R(vlan_cksum_ptype_rss, RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F)         \
1036         R(vlan_mark, RX_VLAN_F | MARK_F)                                       \
1037         R(vlan_mark_rss, RX_VLAN_F | MARK_F | RSS_F)                           \
1038         R(vlan_mark_ptype, RX_VLAN_F | MARK_F | PTYPE_F)                       \
1039         R(vlan_mark_ptype_rss, RX_VLAN_F | MARK_F | PTYPE_F | RSS_F)           \
1040         R(vlan_mark_cksum, RX_VLAN_F | MARK_F | CKSUM_F)                       \
1041         R(vlan_mark_cksum_rss, RX_VLAN_F | MARK_F | CKSUM_F | RSS_F)           \
1042         R(vlan_mark_cksum_ptype, RX_VLAN_F | MARK_F | CKSUM_F | PTYPE_F)       \
1043         R(vlan_mark_cksum_ptype_rss,                                           \
1044           RX_VLAN_F | MARK_F | CKSUM_F | PTYPE_F | RSS_F)
1045
1046 #define NIX_RX_FASTPATH_MODES_48_63                                            \
1047         R(vlan_ts, RX_VLAN_F | TS_F)                                           \
1048         R(vlan_ts_rss, RX_VLAN_F | TS_F | RSS_F)                               \
1049         R(vlan_ts_ptype, RX_VLAN_F | TS_F | PTYPE_F)                           \
1050         R(vlan_ts_ptype_rss, RX_VLAN_F | TS_F | PTYPE_F | RSS_F)               \
1051         R(vlan_ts_cksum, RX_VLAN_F | TS_F | CKSUM_F)                           \
1052         R(vlan_ts_cksum_rss, RX_VLAN_F | TS_F | CKSUM_F | RSS_F)               \
1053         R(vlan_ts_cksum_ptype, RX_VLAN_F | TS_F | CKSUM_F | PTYPE_F)           \
1054         R(vlan_ts_cksum_ptype_rss,                                             \
1055           RX_VLAN_F | TS_F | CKSUM_F | PTYPE_F | RSS_F)                        \
1056         R(vlan_ts_mark, RX_VLAN_F | TS_F | MARK_F)                             \
1057         R(vlan_ts_mark_rss, RX_VLAN_F | TS_F | MARK_F | RSS_F)                 \
1058         R(vlan_ts_mark_ptype, RX_VLAN_F | TS_F | MARK_F | PTYPE_F)             \
1059         R(vlan_ts_mark_ptype_rss, RX_VLAN_F | TS_F | MARK_F | PTYPE_F | RSS_F) \
1060         R(vlan_ts_mark_cksum, RX_VLAN_F | TS_F | MARK_F | CKSUM_F)             \
1061         R(vlan_ts_mark_cksum_rss, RX_VLAN_F | TS_F | MARK_F | CKSUM_F | RSS_F) \
1062         R(vlan_ts_mark_cksum_ptype,                                            \
1063           RX_VLAN_F | TS_F | MARK_F | CKSUM_F | PTYPE_F)                       \
1064         R(vlan_ts_mark_cksum_ptype_rss,                                        \
1065           RX_VLAN_F | TS_F | MARK_F | CKSUM_F | PTYPE_F | RSS_F)
1066
1067 #define NIX_RX_FASTPATH_MODES_64_79                                            \
1068         R(sec, R_SEC_F)                                                        \
1069         R(sec_rss, R_SEC_F | RSS_F)                                            \
1070         R(sec_ptype, R_SEC_F | PTYPE_F)                                        \
1071         R(sec_ptype_rss, R_SEC_F | PTYPE_F | RSS_F)                            \
1072         R(sec_cksum, R_SEC_F | CKSUM_F)                                        \
1073         R(sec_cksum_rss, R_SEC_F | CKSUM_F | RSS_F)                            \
1074         R(sec_cksum_ptype, R_SEC_F | CKSUM_F | PTYPE_F)                        \
1075         R(sec_cksum_ptype_rss, R_SEC_F | CKSUM_F | PTYPE_F | RSS_F)            \
1076         R(sec_mark, R_SEC_F | MARK_F)                                          \
1077         R(sec_mark_rss, R_SEC_F | MARK_F | RSS_F)                              \
1078         R(sec_mark_ptype, R_SEC_F | MARK_F | PTYPE_F)                          \
1079         R(sec_mark_ptype_rss, R_SEC_F | MARK_F | PTYPE_F | RSS_F)              \
1080         R(sec_mark_cksum, R_SEC_F | MARK_F | CKSUM_F)                          \
1081         R(sec_mark_cksum_rss, R_SEC_F | MARK_F | CKSUM_F | RSS_F)              \
1082         R(sec_mark_cksum_ptype, R_SEC_F | MARK_F | CKSUM_F | PTYPE_F)          \
1083         R(sec_mark_cksum_ptype_rss,                                            \
1084           R_SEC_F | MARK_F | CKSUM_F | PTYPE_F | RSS_F)
1085
1086 #define NIX_RX_FASTPATH_MODES_80_95                                            \
1087         R(sec_ts, R_SEC_F | TS_F)                                              \
1088         R(sec_ts_rss, R_SEC_F | TS_F | RSS_F)                                  \
1089         R(sec_ts_ptype, R_SEC_F | TS_F | PTYPE_F)                              \
1090         R(sec_ts_ptype_rss, R_SEC_F | TS_F | PTYPE_F | RSS_F)                  \
1091         R(sec_ts_cksum, R_SEC_F | TS_F | CKSUM_F)                              \
1092         R(sec_ts_cksum_rss, R_SEC_F | TS_F | CKSUM_F | RSS_F)                  \
1093         R(sec_ts_cksum_ptype, R_SEC_F | TS_F | CKSUM_F | PTYPE_F)              \
1094         R(sec_ts_cksum_ptype_rss, R_SEC_F | TS_F | CKSUM_F | PTYPE_F | RSS_F)  \
1095         R(sec_ts_mark, R_SEC_F | TS_F | MARK_F)                                \
1096         R(sec_ts_mark_rss, R_SEC_F | TS_F | MARK_F | RSS_F)                    \
1097         R(sec_ts_mark_ptype, R_SEC_F | TS_F | MARK_F | PTYPE_F)                \
1098         R(sec_ts_mark_ptype_rss, R_SEC_F | TS_F | MARK_F | PTYPE_F | RSS_F)    \
1099         R(sec_ts_mark_cksum, R_SEC_F | TS_F | MARK_F | CKSUM_F)                \
1100         R(sec_ts_mark_cksum_rss, R_SEC_F | TS_F | MARK_F | CKSUM_F | RSS_F)    \
1101         R(sec_ts_mark_cksum_ptype,                                             \
1102           R_SEC_F | TS_F | MARK_F | CKSUM_F | PTYPE_F)                         \
1103         R(sec_ts_mark_cksum_ptype_rss,                                         \
1104           R_SEC_F | TS_F | MARK_F | CKSUM_F | PTYPE_F | RSS_F)
1105
1106 #define NIX_RX_FASTPATH_MODES_96_111                                           \
1107         R(sec_vlan, R_SEC_F | RX_VLAN_F)                                       \
1108         R(sec_vlan_rss, R_SEC_F | RX_VLAN_F | RSS_F)                           \
1109         R(sec_vlan_ptype, R_SEC_F | RX_VLAN_F | PTYPE_F)                       \
1110         R(sec_vlan_ptype_rss, R_SEC_F | RX_VLAN_F | PTYPE_F | RSS_F)           \
1111         R(sec_vlan_cksum, R_SEC_F | RX_VLAN_F | CKSUM_F)                       \
1112         R(sec_vlan_cksum_rss, R_SEC_F | RX_VLAN_F | CKSUM_F | RSS_F)           \
1113         R(sec_vlan_cksum_ptype, R_SEC_F | RX_VLAN_F | CKSUM_F | PTYPE_F)       \
1114         R(sec_vlan_cksum_ptype_rss,                                            \
1115           R_SEC_F | RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F)                     \
1116         R(sec_vlan_mark, R_SEC_F | RX_VLAN_F | MARK_F)                         \
1117         R(sec_vlan_mark_rss, R_SEC_F | RX_VLAN_F | MARK_F | RSS_F)             \
1118         R(sec_vlan_mark_ptype, R_SEC_F | RX_VLAN_F | MARK_F | PTYPE_F)         \
1119         R(sec_vlan_mark_ptype_rss,                                             \
1120           R_SEC_F | RX_VLAN_F | MARK_F | PTYPE_F | RSS_F)                      \
1121         R(sec_vlan_mark_cksum, R_SEC_F | RX_VLAN_F | MARK_F | CKSUM_F)         \
1122         R(sec_vlan_mark_cksum_rss,                                             \
1123           R_SEC_F | RX_VLAN_F | MARK_F | CKSUM_F | RSS_F)                      \
1124         R(sec_vlan_mark_cksum_ptype,                                           \
1125           R_SEC_F | RX_VLAN_F | MARK_F | CKSUM_F | PTYPE_F)                    \
1126         R(sec_vlan_mark_cksum_ptype_rss,                                       \
1127           R_SEC_F | RX_VLAN_F | MARK_F | CKSUM_F | PTYPE_F | RSS_F)
1128
1129 #define NIX_RX_FASTPATH_MODES_112_127                                          \
1130         R(sec_vlan_ts, R_SEC_F | RX_VLAN_F | TS_F)                             \
1131         R(sec_vlan_ts_rss, R_SEC_F | RX_VLAN_F | TS_F | RSS_F)                 \
1132         R(sec_vlan_ts_ptype, R_SEC_F | RX_VLAN_F | TS_F | PTYPE_F)             \
1133         R(sec_vlan_ts_ptype_rss, R_SEC_F | RX_VLAN_F | TS_F | PTYPE_F | RSS_F) \
1134         R(sec_vlan_ts_cksum, R_SEC_F | RX_VLAN_F | TS_F | CKSUM_F)             \
1135         R(sec_vlan_ts_cksum_rss, R_SEC_F | RX_VLAN_F | TS_F | CKSUM_F | RSS_F) \
1136         R(sec_vlan_ts_cksum_ptype,                                             \
1137           R_SEC_F | RX_VLAN_F | TS_F | CKSUM_F | PTYPE_F)                      \
1138         R(sec_vlan_ts_cksum_ptype_rss,                                         \
1139           R_SEC_F | RX_VLAN_F | TS_F | CKSUM_F | PTYPE_F | RSS_F)              \
1140         R(sec_vlan_ts_mark, R_SEC_F | RX_VLAN_F | TS_F | MARK_F)               \
1141         R(sec_vlan_ts_mark_rss, R_SEC_F | RX_VLAN_F | TS_F | MARK_F | RSS_F)   \
1142         R(sec_vlan_ts_mark_ptype,                                              \
1143           R_SEC_F | RX_VLAN_F | TS_F | MARK_F | PTYPE_F)                       \
1144         R(sec_vlan_ts_mark_ptype_rss,                                          \
1145           R_SEC_F | RX_VLAN_F | TS_F | MARK_F | PTYPE_F | RSS_F)               \
1146         R(sec_vlan_ts_mark_cksum,                                              \
1147           R_SEC_F | RX_VLAN_F | TS_F | MARK_F | CKSUM_F)                       \
1148         R(sec_vlan_ts_mark_cksum_rss,                                          \
1149           R_SEC_F | RX_VLAN_F | TS_F | MARK_F | CKSUM_F | RSS_F)               \
1150         R(sec_vlan_ts_mark_cksum_ptype,                                        \
1151           R_SEC_F | RX_VLAN_F | TS_F | MARK_F | CKSUM_F | PTYPE_F)             \
1152         R(sec_vlan_ts_mark_cksum_ptype_rss,                                    \
1153           R_SEC_F | RX_VLAN_F | TS_F | MARK_F | CKSUM_F | PTYPE_F | RSS_F)
1154
1155 #define NIX_RX_FASTPATH_MODES                                                  \
1156         NIX_RX_FASTPATH_MODES_0_15                                             \
1157         NIX_RX_FASTPATH_MODES_16_31                                            \
1158         NIX_RX_FASTPATH_MODES_32_47                                            \
1159         NIX_RX_FASTPATH_MODES_48_63                                            \
1160         NIX_RX_FASTPATH_MODES_64_79                                            \
1161         NIX_RX_FASTPATH_MODES_80_95                                            \
1162         NIX_RX_FASTPATH_MODES_96_111                                           \
1163         NIX_RX_FASTPATH_MODES_112_127
1164
1165 #define R(name, flags)                                                         \
1166         uint16_t __rte_noinline __rte_hot cn10k_nix_recv_pkts_##name(          \
1167                 void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts);     \
1168         uint16_t __rte_noinline __rte_hot cn10k_nix_recv_pkts_mseg_##name(     \
1169                 void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts);     \
1170         uint16_t __rte_noinline __rte_hot cn10k_nix_recv_pkts_vec_##name(      \
1171                 void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts);     \
1172         uint16_t __rte_noinline __rte_hot cn10k_nix_recv_pkts_vec_mseg_##name( \
1173                 void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts);
1174
1175 NIX_RX_FASTPATH_MODES
1176 #undef R
1177
1178 #define NIX_RX_RECV(fn, flags)                                                 \
1179         uint16_t __rte_noinline __rte_hot fn(                                  \
1180                 void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts)      \
1181         {                                                                      \
1182                 return cn10k_nix_recv_pkts(rx_queue, rx_pkts, pkts, (flags));  \
1183         }
1184
1185 #define NIX_RX_RECV_MSEG(fn, flags) NIX_RX_RECV(fn, flags | NIX_RX_MULTI_SEG_F)
1186
1187 #define NIX_RX_RECV_VEC(fn, flags)                                             \
1188         uint16_t __rte_noinline __rte_hot fn(                                  \
1189                 void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts)      \
1190         {                                                                      \
1191                 return cn10k_nix_recv_pkts_vector(rx_queue, rx_pkts, pkts,     \
1192                                                   (flags), NULL, NULL, 0);     \
1193         }
1194
1195 #define NIX_RX_RECV_VEC_MSEG(fn, flags)                                        \
1196         NIX_RX_RECV_VEC(fn, flags | NIX_RX_MULTI_SEG_F)
1197
1198 #endif /* __CN10K_RX_H__ */