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