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