common/cnxk: support CNF10KB SoC
[dpdk.git] / drivers / event / cnxk / cn10k_worker.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #ifndef __CN10K_WORKER_H__
6 #define __CN10K_WORKER_H__
7
8 #include <rte_vect.h>
9
10 #include "cn10k_cryptodev_ops.h"
11 #include "cnxk_ethdev.h"
12 #include "cnxk_eventdev.h"
13 #include "cnxk_worker.h"
14
15 #include "cn10k_ethdev.h"
16 #include "cn10k_rx.h"
17 #include "cn10k_tx.h"
18
19 /* SSO Operations */
20
21 static __rte_always_inline uint8_t
22 cn10k_sso_hws_new_event(struct cn10k_sso_hws *ws, const struct rte_event *ev)
23 {
24         const uint32_t tag = (uint32_t)ev->event;
25         const uint8_t new_tt = ev->sched_type;
26         const uint64_t event_ptr = ev->u64;
27         const uint16_t grp = ev->queue_id;
28
29         rte_atomic_thread_fence(__ATOMIC_ACQ_REL);
30         if (ws->xaq_lmt <= *ws->fc_mem)
31                 return 0;
32
33         cnxk_sso_hws_add_work(event_ptr, tag, new_tt,
34                               ws->grp_base + (grp << 12));
35         return 1;
36 }
37
38 static __rte_always_inline void
39 cn10k_sso_hws_fwd_swtag(struct cn10k_sso_hws *ws, const struct rte_event *ev)
40 {
41         const uint32_t tag = (uint32_t)ev->event;
42         const uint8_t new_tt = ev->sched_type;
43         const uint8_t cur_tt = CNXK_TT_FROM_TAG(ws->gw_rdata);
44
45         /* CNXK model
46          * cur_tt/new_tt     SSO_TT_ORDERED SSO_TT_ATOMIC SSO_TT_UNTAGGED
47          *
48          * SSO_TT_ORDERED        norm           norm             untag
49          * SSO_TT_ATOMIC         norm           norm               untag
50          * SSO_TT_UNTAGGED       norm           norm             NOOP
51          */
52
53         if (new_tt == SSO_TT_UNTAGGED) {
54                 if (cur_tt != SSO_TT_UNTAGGED)
55                         cnxk_sso_hws_swtag_untag(ws->base +
56                                                  SSOW_LF_GWS_OP_SWTAG_UNTAG);
57         } else {
58                 cnxk_sso_hws_swtag_norm(tag, new_tt,
59                                         ws->base + SSOW_LF_GWS_OP_SWTAG_NORM);
60         }
61         ws->swtag_req = 1;
62 }
63
64 static __rte_always_inline void
65 cn10k_sso_hws_fwd_group(struct cn10k_sso_hws *ws, const struct rte_event *ev,
66                         const uint16_t grp)
67 {
68         const uint32_t tag = (uint32_t)ev->event;
69         const uint8_t new_tt = ev->sched_type;
70
71         plt_write64(ev->u64, ws->base + SSOW_LF_GWS_OP_UPD_WQP_GRP1);
72         cnxk_sso_hws_swtag_desched(tag, new_tt, grp,
73                                    ws->base + SSOW_LF_GWS_OP_SWTAG_DESCHED);
74 }
75
76 static __rte_always_inline void
77 cn10k_sso_hws_forward_event(struct cn10k_sso_hws *ws,
78                             const struct rte_event *ev)
79 {
80         const uint8_t grp = ev->queue_id;
81
82         /* Group hasn't changed, Use SWTAG to forward the event */
83         if (CNXK_GRP_FROM_TAG(ws->gw_rdata) == grp)
84                 cn10k_sso_hws_fwd_swtag(ws, ev);
85         else
86                 /*
87                  * Group has been changed for group based work pipelining,
88                  * Use deschedule/add_work operation to transfer the event to
89                  * new group/core
90                  */
91                 cn10k_sso_hws_fwd_group(ws, ev, grp);
92 }
93
94 static __rte_always_inline void
95 cn10k_wqe_to_mbuf(uint64_t wqe, const uint64_t __mbuf, uint8_t port_id,
96                   const uint32_t tag, const uint32_t flags,
97                   const void *const lookup_mem)
98 {
99         const uint64_t mbuf_init = 0x100010000ULL | RTE_PKTMBUF_HEADROOM |
100                                    (flags & NIX_RX_OFFLOAD_TSTAMP_F ? 8 : 0);
101         struct rte_mbuf *mbuf = (struct rte_mbuf *)__mbuf;
102
103         /* Mark mempool obj as "get" as it is alloc'ed by NIX */
104         RTE_MEMPOOL_CHECK_COOKIES(mbuf->pool, (void **)&mbuf, 1, 1);
105
106         cn10k_nix_cqe_to_mbuf((struct nix_cqe_hdr_s *)wqe, tag,
107                               (struct rte_mbuf *)mbuf, lookup_mem,
108                               mbuf_init | ((uint64_t)port_id) << 48, flags);
109 }
110
111 static __rte_always_inline void
112 cn10k_process_vwqe(uintptr_t vwqe, uint16_t port_id, const uint32_t flags,
113                    void *lookup_mem, void *tstamp, uintptr_t lbase)
114 {
115         uint64_t mbuf_init = 0x100010000ULL | RTE_PKTMBUF_HEADROOM |
116                              (flags & NIX_RX_OFFLOAD_TSTAMP_F ? 8 : 0);
117         struct rte_event_vector *vec;
118         uint64_t aura_handle, laddr;
119         uint16_t nb_mbufs, non_vec;
120         uint16_t lmt_id, d_off;
121         struct rte_mbuf **wqe;
122         struct rte_mbuf *mbuf;
123         uint8_t loff = 0;
124         uint64_t sa_base;
125         int i;
126
127         mbuf_init |= ((uint64_t)port_id) << 48;
128         vec = (struct rte_event_vector *)vwqe;
129         wqe = vec->mbufs;
130
131         rte_prefetch0(&vec->ptrs[0]);
132 #define OBJS_PER_CLINE (RTE_CACHE_LINE_SIZE / sizeof(void *))
133         for (i = OBJS_PER_CLINE; i < vec->nb_elem; i += OBJS_PER_CLINE)
134                 rte_prefetch0(&vec->ptrs[i]);
135
136         nb_mbufs = RTE_ALIGN_FLOOR(vec->nb_elem, NIX_DESCS_PER_LOOP);
137         nb_mbufs = cn10k_nix_recv_pkts_vector(&mbuf_init, wqe, nb_mbufs,
138                                               flags | NIX_RX_VWQE_F, lookup_mem,
139                                               tstamp, lbase);
140         wqe += nb_mbufs;
141         non_vec = vec->nb_elem - nb_mbufs;
142
143         if (flags & NIX_RX_OFFLOAD_SECURITY_F && non_vec) {
144                 mbuf = (struct rte_mbuf *)((uintptr_t)wqe[0] -
145                                            sizeof(struct rte_mbuf));
146                 /* Pick first mbuf's aura handle assuming all
147                  * mbufs are from a vec and are from same RQ.
148                  */
149                 aura_handle = mbuf->pool->pool_id;
150                 ROC_LMT_BASE_ID_GET(lbase, lmt_id);
151                 laddr = lbase;
152                 laddr += 8;
153                 d_off = ((uintptr_t)mbuf->buf_addr - (uintptr_t)mbuf);
154                 d_off += (mbuf_init & 0xFFFF);
155                 sa_base = cnxk_nix_sa_base_get(mbuf_init >> 48, lookup_mem);
156                 sa_base &= ~(ROC_NIX_INL_SA_BASE_ALIGN - 1);
157         }
158
159         while (non_vec) {
160                 struct nix_cqe_hdr_s *cqe = (struct nix_cqe_hdr_s *)wqe[0];
161                 uint64_t tstamp_ptr;
162
163                 mbuf = (struct rte_mbuf *)((char *)cqe -
164                                            sizeof(struct rte_mbuf));
165
166                 /* Mark mempool obj as "get" as it is alloc'ed by NIX */
167                 RTE_MEMPOOL_CHECK_COOKIES(mbuf->pool, (void **)&mbuf, 1, 1);
168
169                 /* Translate meta to mbuf */
170                 if (flags & NIX_RX_OFFLOAD_SECURITY_F) {
171                         const uint64_t cq_w1 = *((const uint64_t *)cqe + 1);
172                         const uint64_t cq_w5 = *((const uint64_t *)cqe + 5);
173
174                         mbuf = nix_sec_meta_to_mbuf_sc(cq_w1, cq_w5, sa_base, laddr,
175                                                        &loff, mbuf, d_off,
176                                                        flags, mbuf_init);
177                 }
178
179                 cn10k_nix_cqe_to_mbuf(cqe, cqe->tag, mbuf, lookup_mem,
180                                       mbuf_init, flags);
181                 /* Extracting tstamp, if PTP enabled*/
182                 tstamp_ptr = *(uint64_t *)(((struct nix_wqe_hdr_s *)cqe) +
183                                            CNXK_SSO_WQE_SG_PTR);
184                 cn10k_nix_mbuf_to_tstamp((struct rte_mbuf *)mbuf, tstamp,
185                                         flags & NIX_RX_OFFLOAD_TSTAMP_F,
186                                         (uint64_t *)tstamp_ptr);
187                 wqe[0] = (struct rte_mbuf *)mbuf;
188                 non_vec--;
189                 wqe++;
190         }
191
192         /* Free remaining meta buffers if any */
193         if (flags & NIX_RX_OFFLOAD_SECURITY_F && loff) {
194                 nix_sec_flush_meta(laddr, lmt_id, loff, aura_handle);
195                 plt_io_wmb();
196         }
197 }
198
199 static __rte_always_inline void
200 cn10k_sso_hws_post_process(struct cn10k_sso_hws *ws, uint64_t *u64,
201                            const uint32_t flags)
202 {
203         uint64_t tstamp_ptr;
204
205         u64[0] = (u64[0] & (0x3ull << 32)) << 6 |
206                  (u64[0] & (0x3FFull << 36)) << 4 | (u64[0] & 0xffffffff);
207         if ((flags & CPT_RX_WQE_F) &&
208             (CNXK_EVENT_TYPE_FROM_TAG(u64[0]) == RTE_EVENT_TYPE_CRYPTODEV)) {
209                 u64[1] = cn10k_cpt_crypto_adapter_dequeue(u64[1]);
210         } else if (CNXK_EVENT_TYPE_FROM_TAG(u64[0]) == RTE_EVENT_TYPE_ETHDEV) {
211                 uint8_t port = CNXK_SUB_EVENT_FROM_TAG(u64[0]);
212                 uint64_t mbuf;
213
214                 mbuf = u64[1] - sizeof(struct rte_mbuf);
215                 rte_prefetch0((void *)mbuf);
216                 if (flags & NIX_RX_OFFLOAD_SECURITY_F) {
217                         const uint64_t mbuf_init =
218                                 0x100010000ULL | RTE_PKTMBUF_HEADROOM |
219                                 (flags & NIX_RX_OFFLOAD_TSTAMP_F ? 8 : 0);
220                         struct rte_mbuf *m;
221                         uintptr_t sa_base;
222                         uint64_t iova = 0;
223                         uint8_t loff = 0;
224                         uint16_t d_off;
225                         uint64_t cq_w1;
226                         uint64_t cq_w5;
227
228                         m = (struct rte_mbuf *)mbuf;
229                         d_off = (uintptr_t)(m->buf_addr) - (uintptr_t)m;
230                         d_off += RTE_PKTMBUF_HEADROOM;
231
232                         cq_w1 = *(uint64_t *)(u64[1] + 8);
233                         cq_w5 = *(uint64_t *)(u64[1] + 40);
234
235                         sa_base = cnxk_nix_sa_base_get(port, ws->lookup_mem);
236                         sa_base &= ~(ROC_NIX_INL_SA_BASE_ALIGN - 1);
237
238                         mbuf = (uint64_t)nix_sec_meta_to_mbuf_sc(
239                                 cq_w1, cq_w5, sa_base, (uintptr_t)&iova, &loff,
240                                 (struct rte_mbuf *)mbuf, d_off, flags,
241                                 mbuf_init | ((uint64_t)port) << 48);
242                         if (loff)
243                                 roc_npa_aura_op_free(m->pool->pool_id, 0, iova);
244                 }
245
246                 u64[0] = CNXK_CLR_SUB_EVENT(u64[0]);
247                 cn10k_wqe_to_mbuf(u64[1], mbuf, port, u64[0] & 0xFFFFF, flags,
248                                   ws->lookup_mem);
249                 /* Extracting tstamp, if PTP enabled*/
250                 tstamp_ptr = *(uint64_t *)(((struct nix_wqe_hdr_s *)u64[1]) +
251                                            CNXK_SSO_WQE_SG_PTR);
252                 cn10k_nix_mbuf_to_tstamp((struct rte_mbuf *)mbuf, ws->tstamp,
253                                          flags & NIX_RX_OFFLOAD_TSTAMP_F,
254                                          (uint64_t *)tstamp_ptr);
255                 u64[1] = mbuf;
256         } else if (CNXK_EVENT_TYPE_FROM_TAG(u64[0]) ==
257                    RTE_EVENT_TYPE_ETHDEV_VECTOR) {
258                 uint8_t port = CNXK_SUB_EVENT_FROM_TAG(u64[0]);
259                 __uint128_t vwqe_hdr = *(__uint128_t *)u64[1];
260
261                 vwqe_hdr = ((vwqe_hdr >> 64) & 0xFFF) | BIT_ULL(31) |
262                            ((vwqe_hdr & 0xFFFF) << 48) | ((uint64_t)port << 32);
263                 *(uint64_t *)u64[1] = (uint64_t)vwqe_hdr;
264                 cn10k_process_vwqe(u64[1], port, flags, ws->lookup_mem,
265                                    ws->tstamp, ws->lmt_base);
266                 /* Mark vector mempool object as get */
267                 RTE_MEMPOOL_CHECK_COOKIES(rte_mempool_from_obj((void *)u64[1]),
268                                           (void **)&u64[1], 1, 1);
269         }
270 }
271
272 static __rte_always_inline uint16_t
273 cn10k_sso_hws_get_work(struct cn10k_sso_hws *ws, struct rte_event *ev,
274                        const uint32_t flags)
275 {
276         union {
277                 __uint128_t get_work;
278                 uint64_t u64[2];
279         } gw;
280
281         gw.get_work = ws->gw_wdata;
282 #if defined(RTE_ARCH_ARM64) && !defined(__clang__)
283         asm volatile(
284                 PLT_CPU_FEATURE_PREAMBLE
285                 "caspal %[wdata], %H[wdata], %[wdata], %H[wdata], [%[gw_loc]]\n"
286                 : [wdata] "+r"(gw.get_work)
287                 : [gw_loc] "r"(ws->base + SSOW_LF_GWS_OP_GET_WORK0)
288                 : "memory");
289 #else
290         plt_write64(gw.u64[0], ws->base + SSOW_LF_GWS_OP_GET_WORK0);
291         do {
292                 roc_load_pair(gw.u64[0], gw.u64[1],
293                               ws->base + SSOW_LF_GWS_WQE0);
294         } while (gw.u64[0] & BIT_ULL(63));
295 #endif
296         ws->gw_rdata = gw.u64[0];
297         if (gw.u64[1])
298                 cn10k_sso_hws_post_process(ws, gw.u64, flags);
299
300         ev->event = gw.u64[0];
301         ev->u64 = gw.u64[1];
302
303         return !!gw.u64[1];
304 }
305
306 /* Used in cleaning up workslot. */
307 static __rte_always_inline uint16_t
308 cn10k_sso_hws_get_work_empty(struct cn10k_sso_hws *ws, struct rte_event *ev,
309                              const uint32_t flags)
310 {
311         union {
312                 __uint128_t get_work;
313                 uint64_t u64[2];
314         } gw;
315
316 #ifdef RTE_ARCH_ARM64
317         asm volatile(PLT_CPU_FEATURE_PREAMBLE
318                      "          ldp %[tag], %[wqp], [%[tag_loc]]        \n"
319                      "          tbz %[tag], 63, done%=                  \n"
320                      "          sevl                                    \n"
321                      "rty%=:    wfe                                     \n"
322                      "          ldp %[tag], %[wqp], [%[tag_loc]]        \n"
323                      "          tbnz %[tag], 63, rty%=                  \n"
324                      "done%=:   dmb ld                                  \n"
325                      : [tag] "=&r"(gw.u64[0]), [wqp] "=&r"(gw.u64[1])
326                      : [tag_loc] "r"(ws->base + SSOW_LF_GWS_WQE0)
327                      : "memory");
328 #else
329         do {
330                 roc_load_pair(gw.u64[0], gw.u64[1],
331                               ws->base + SSOW_LF_GWS_WQE0);
332         } while (gw.u64[0] & BIT_ULL(63));
333 #endif
334
335         ws->gw_rdata = gw.u64[0];
336         if (gw.u64[1])
337                 cn10k_sso_hws_post_process(ws, gw.u64, flags);
338
339         ev->event = gw.u64[0];
340         ev->u64 = gw.u64[1];
341
342         return !!gw.u64[1];
343 }
344
345 /* CN10K Fastpath functions. */
346 uint16_t __rte_hot cn10k_sso_hws_enq(void *port, const struct rte_event *ev);
347 uint16_t __rte_hot cn10k_sso_hws_enq_burst(void *port,
348                                            const struct rte_event ev[],
349                                            uint16_t nb_events);
350 uint16_t __rte_hot cn10k_sso_hws_enq_new_burst(void *port,
351                                                const struct rte_event ev[],
352                                                uint16_t nb_events);
353 uint16_t __rte_hot cn10k_sso_hws_enq_fwd_burst(void *port,
354                                                const struct rte_event ev[],
355                                                uint16_t nb_events);
356 uint16_t __rte_hot cn10k_sso_hws_ca_enq(void *port, struct rte_event ev[],
357                                         uint16_t nb_events);
358
359 #define R(name, flags)                                                         \
360         uint16_t __rte_hot cn10k_sso_hws_deq_##name(                           \
361                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
362         uint16_t __rte_hot cn10k_sso_hws_deq_burst_##name(                     \
363                 void *port, struct rte_event ev[], uint16_t nb_events,         \
364                 uint64_t timeout_ticks);                                       \
365         uint16_t __rte_hot cn10k_sso_hws_deq_tmo_##name(                       \
366                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
367         uint16_t __rte_hot cn10k_sso_hws_deq_tmo_burst_##name(                 \
368                 void *port, struct rte_event ev[], uint16_t nb_events,         \
369                 uint64_t timeout_ticks);                                       \
370         uint16_t __rte_hot cn10k_sso_hws_deq_ca_##name(                        \
371                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
372         uint16_t __rte_hot cn10k_sso_hws_deq_ca_burst_##name(                  \
373                 void *port, struct rte_event ev[], uint16_t nb_events,         \
374                 uint64_t timeout_ticks);                                       \
375         uint16_t __rte_hot cn10k_sso_hws_deq_tmo_ca_##name(                    \
376                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
377         uint16_t __rte_hot cn10k_sso_hws_deq_tmo_ca_burst_##name(              \
378                 void *port, struct rte_event ev[], uint16_t nb_events,         \
379                 uint64_t timeout_ticks);                                       \
380         uint16_t __rte_hot cn10k_sso_hws_deq_seg_##name(                       \
381                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
382         uint16_t __rte_hot cn10k_sso_hws_deq_seg_burst_##name(                 \
383                 void *port, struct rte_event ev[], uint16_t nb_events,         \
384                 uint64_t timeout_ticks);                                       \
385         uint16_t __rte_hot cn10k_sso_hws_deq_tmo_seg_##name(                   \
386                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
387         uint16_t __rte_hot cn10k_sso_hws_deq_tmo_seg_burst_##name(             \
388                 void *port, struct rte_event ev[], uint16_t nb_events,         \
389                 uint64_t timeout_ticks);                                       \
390         uint16_t __rte_hot cn10k_sso_hws_deq_ca_seg_##name(                    \
391                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
392         uint16_t __rte_hot cn10k_sso_hws_deq_ca_seg_burst_##name(              \
393                 void *port, struct rte_event ev[], uint16_t nb_events,         \
394                 uint64_t timeout_ticks);                                       \
395         uint16_t __rte_hot cn10k_sso_hws_deq_tmo_ca_seg_##name(                \
396                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
397         uint16_t __rte_hot cn10k_sso_hws_deq_tmo_ca_seg_burst_##name(          \
398                 void *port, struct rte_event ev[], uint16_t nb_events,         \
399                 uint64_t timeout_ticks);                                       \
400         uint16_t __rte_hot cn10k_sso_hws_reas_deq_##name(                      \
401                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
402         uint16_t __rte_hot cn10k_sso_hws_reas_deq_burst_##name(                \
403                 void *port, struct rte_event ev[], uint16_t nb_events,         \
404                 uint64_t timeout_ticks);                                       \
405         uint16_t __rte_hot cn10k_sso_hws_reas_deq_tmo_##name(                  \
406                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
407         uint16_t __rte_hot cn10k_sso_hws_reas_deq_tmo_burst_##name(            \
408                 void *port, struct rte_event ev[], uint16_t nb_events,         \
409                 uint64_t timeout_ticks);                                       \
410         uint16_t __rte_hot cn10k_sso_hws_reas_deq_ca_##name(                   \
411                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
412         uint16_t __rte_hot cn10k_sso_hws_reas_deq_ca_burst_##name(             \
413                 void *port, struct rte_event ev[], uint16_t nb_events,         \
414                 uint64_t timeout_ticks);                                       \
415         uint16_t __rte_hot cn10k_sso_hws_reas_deq_tmo_ca_##name(               \
416                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
417         uint16_t __rte_hot cn10k_sso_hws_reas_deq_tmo_ca_burst_##name(         \
418                 void *port, struct rte_event ev[], uint16_t nb_events,         \
419                 uint64_t timeout_ticks);                                       \
420         uint16_t __rte_hot cn10k_sso_hws_reas_deq_seg_##name(                  \
421                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
422         uint16_t __rte_hot cn10k_sso_hws_reas_deq_seg_burst_##name(            \
423                 void *port, struct rte_event ev[], uint16_t nb_events,         \
424                 uint64_t timeout_ticks);                                       \
425         uint16_t __rte_hot cn10k_sso_hws_reas_deq_tmo_seg_##name(              \
426                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
427         uint16_t __rte_hot cn10k_sso_hws_reas_deq_tmo_seg_burst_##name(        \
428                 void *port, struct rte_event ev[], uint16_t nb_events,         \
429                 uint64_t timeout_ticks);                                       \
430         uint16_t __rte_hot cn10k_sso_hws_reas_deq_ca_seg_##name(               \
431                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
432         uint16_t __rte_hot cn10k_sso_hws_reas_deq_ca_seg_burst_##name(         \
433                 void *port, struct rte_event ev[], uint16_t nb_events,         \
434                 uint64_t timeout_ticks);                                       \
435         uint16_t __rte_hot cn10k_sso_hws_reas_deq_tmo_ca_seg_##name(           \
436                 void *port, struct rte_event *ev, uint64_t timeout_ticks);     \
437         uint16_t __rte_hot cn10k_sso_hws_reas_deq_tmo_ca_seg_burst_##name(     \
438                 void *port, struct rte_event ev[], uint16_t nb_events,         \
439                 uint64_t timeout_ticks);
440
441 NIX_RX_FASTPATH_MODES
442 #undef R
443
444 #define SSO_DEQ(fn, flags)                                                     \
445         uint16_t __rte_hot fn(void *port, struct rte_event *ev,                \
446                               uint64_t timeout_ticks)                          \
447         {                                                                      \
448                 struct cn10k_sso_hws *ws = port;                               \
449                 RTE_SET_USED(timeout_ticks);                                   \
450                 if (ws->swtag_req) {                                           \
451                         ws->swtag_req = 0;                                     \
452                         ws->gw_rdata = cnxk_sso_hws_swtag_wait(                \
453                                 ws->base + SSOW_LF_GWS_WQE0);                  \
454                         return 1;                                              \
455                 }                                                              \
456                 return cn10k_sso_hws_get_work(ws, ev, flags);                  \
457         }
458
459 #define SSO_DEQ_SEG(fn, flags)    SSO_DEQ(fn, flags | NIX_RX_MULTI_SEG_F)
460 #define SSO_DEQ_CA(fn, flags)     SSO_DEQ(fn, flags | CPT_RX_WQE_F)
461 #define SSO_DEQ_CA_SEG(fn, flags) SSO_DEQ_SEG(fn, flags | CPT_RX_WQE_F)
462
463 #define SSO_DEQ_TMO(fn, flags)                                                 \
464         uint16_t __rte_hot fn(void *port, struct rte_event *ev,                \
465                               uint64_t timeout_ticks)                          \
466         {                                                                      \
467                 struct cn10k_sso_hws *ws = port;                               \
468                 uint16_t ret = 1;                                              \
469                 uint64_t iter;                                                 \
470                 if (ws->swtag_req) {                                           \
471                         ws->swtag_req = 0;                                     \
472                         ws->gw_rdata = cnxk_sso_hws_swtag_wait(                \
473                                 ws->base + SSOW_LF_GWS_WQE0);                  \
474                         return ret;                                            \
475                 }                                                              \
476                 ret = cn10k_sso_hws_get_work(ws, ev, flags);                   \
477                 for (iter = 1; iter < timeout_ticks && (ret == 0); iter++)     \
478                         ret = cn10k_sso_hws_get_work(ws, ev, flags);           \
479                 return ret;                                                    \
480         }
481
482 #define SSO_DEQ_TMO_SEG(fn, flags)    SSO_DEQ_TMO(fn, flags | NIX_RX_MULTI_SEG_F)
483 #define SSO_DEQ_TMO_CA(fn, flags)     SSO_DEQ_TMO(fn, flags | CPT_RX_WQE_F)
484 #define SSO_DEQ_TMO_CA_SEG(fn, flags) SSO_DEQ_TMO_SEG(fn, flags | CPT_RX_WQE_F)
485
486 #define SSO_CMN_DEQ_BURST(fnb, fn, flags)                                      \
487         uint16_t __rte_hot fnb(void *port, struct rte_event ev[],              \
488                                uint16_t nb_events, uint64_t timeout_ticks)     \
489         {                                                                      \
490                 RTE_SET_USED(nb_events);                                       \
491                 return fn(port, ev, timeout_ticks);                            \
492         }
493
494 #define SSO_CMN_DEQ_SEG_BURST(fnb, fn, flags)                                  \
495         uint16_t __rte_hot fnb(void *port, struct rte_event ev[],              \
496                                uint16_t nb_events, uint64_t timeout_ticks)     \
497         {                                                                      \
498                 RTE_SET_USED(nb_events);                                       \
499                 return fn(port, ev, timeout_ticks);                            \
500         }
501
502 static __rte_always_inline struct cn10k_eth_txq *
503 cn10k_sso_hws_xtract_meta(struct rte_mbuf *m, const uint64_t *txq_data)
504 {
505         return (struct cn10k_eth_txq
506                         *)(txq_data[(txq_data[m->port] >> 48) +
507                                     rte_event_eth_tx_adapter_txq_get(m)] &
508                            (BIT_ULL(48) - 1));
509 }
510
511 static __rte_always_inline void
512 cn10k_sso_txq_fc_wait(const struct cn10k_eth_txq *txq)
513 {
514         while ((uint64_t)txq->nb_sqb_bufs_adj <=
515                __atomic_load_n(txq->fc_mem, __ATOMIC_RELAXED))
516                 ;
517 }
518
519 static __rte_always_inline void
520 cn10k_sso_tx_one(struct cn10k_sso_hws *ws, struct rte_mbuf *m, uint64_t *cmd,
521                  uint16_t lmt_id, uintptr_t lmt_addr, uint8_t sched_type,
522                  const uint64_t *txq_data, const uint32_t flags)
523 {
524         uint8_t lnum = 0, loff = 0, shft = 0;
525         struct cn10k_eth_txq *txq;
526         uintptr_t laddr;
527         uint16_t segdw;
528         uintptr_t pa;
529         bool sec;
530
531         txq = cn10k_sso_hws_xtract_meta(m, txq_data);
532         cn10k_nix_tx_skeleton(txq, cmd, flags, 0);
533         /* Perform header writes before barrier
534          * for TSO
535          */
536         if (flags & NIX_TX_OFFLOAD_TSO_F)
537                 cn10k_nix_xmit_prepare_tso(m, flags);
538
539         cn10k_nix_xmit_prepare(m, cmd, flags, txq->lso_tun_fmt, &sec,
540                                txq->mark_flag, txq->mark_fmt);
541
542         laddr = lmt_addr;
543         /* Prepare CPT instruction and get nixtx addr if
544          * it is for CPT on same lmtline.
545          */
546         if (flags & NIX_TX_OFFLOAD_SECURITY_F && sec)
547                 cn10k_nix_prep_sec(m, cmd, &laddr, lmt_addr, &lnum, &loff,
548                                    &shft, txq->sa_base, flags);
549
550         /* Move NIX desc to LMT/NIXTX area */
551         cn10k_nix_xmit_mv_lmt_base(laddr, cmd, flags);
552
553         if (flags & NIX_TX_MULTI_SEG_F)
554                 segdw = cn10k_nix_prepare_mseg(m, (uint64_t *)laddr, flags);
555         else
556                 segdw = cn10k_nix_tx_ext_subs(flags) + 2;
557
558         cn10k_nix_xmit_prepare_tstamp(txq, laddr, m->ol_flags, segdw, flags);
559         if (flags & NIX_TX_OFFLOAD_SECURITY_F && sec)
560                 pa = txq->cpt_io_addr | 3 << 4;
561         else
562                 pa = txq->io_addr | ((segdw - 1) << 4);
563
564         if (!CNXK_TAG_IS_HEAD(ws->gw_rdata) && !sched_type)
565                 ws->gw_rdata = roc_sso_hws_head_wait(ws->base);
566
567         cn10k_sso_txq_fc_wait(txq);
568         roc_lmt_submit_steorl(lmt_id, pa);
569 }
570
571 static __rte_always_inline void
572 cn10k_sso_vwqe_split_tx(struct cn10k_sso_hws *ws, struct rte_mbuf **mbufs,
573                         uint16_t nb_mbufs, uint64_t *cmd, uint16_t lmt_id,
574                         uintptr_t lmt_addr, uint8_t sched_type,
575                         const uint64_t *txq_data, const uint32_t flags)
576 {
577         uint16_t port[4], queue[4];
578         uint16_t i, j, pkts, scalar;
579         struct cn10k_eth_txq *txq;
580
581         scalar = nb_mbufs & (NIX_DESCS_PER_LOOP - 1);
582         pkts = RTE_ALIGN_FLOOR(nb_mbufs, NIX_DESCS_PER_LOOP);
583
584         for (i = 0; i < pkts; i += NIX_DESCS_PER_LOOP) {
585                 port[0] = mbufs[i]->port;
586                 port[1] = mbufs[i + 1]->port;
587                 port[2] = mbufs[i + 2]->port;
588                 port[3] = mbufs[i + 3]->port;
589
590                 queue[0] = rte_event_eth_tx_adapter_txq_get(mbufs[i]);
591                 queue[1] = rte_event_eth_tx_adapter_txq_get(mbufs[i + 1]);
592                 queue[2] = rte_event_eth_tx_adapter_txq_get(mbufs[i + 2]);
593                 queue[3] = rte_event_eth_tx_adapter_txq_get(mbufs[i + 3]);
594
595                 if (((port[0] ^ port[1]) & (port[2] ^ port[3])) ||
596                     ((queue[0] ^ queue[1]) & (queue[2] ^ queue[3]))) {
597                         for (j = 0; j < 4; j++)
598                                 cn10k_sso_tx_one(ws, mbufs[i + j], cmd, lmt_id,
599                                                  lmt_addr, sched_type, txq_data,
600                                                  flags);
601                 } else {
602                         txq = (struct cn10k_eth_txq
603                                        *)(txq_data[(txq_data[port[0]] >> 48) +
604                                                    queue[0]] &
605                                           (BIT_ULL(48) - 1));
606                         cn10k_nix_xmit_pkts_vector(txq, (uint64_t *)ws,
607                                                    &mbufs[i], 4, cmd,
608                                                    flags | NIX_TX_VWQE_F);
609                 }
610         }
611
612         mbufs += i;
613
614         for (i = 0; i < scalar; i++) {
615                 cn10k_sso_tx_one(ws, mbufs[i], cmd, lmt_id, lmt_addr,
616                                  sched_type, txq_data, flags);
617         }
618 }
619
620 static __rte_always_inline uint16_t
621 cn10k_sso_hws_event_tx(struct cn10k_sso_hws *ws, struct rte_event *ev,
622                        uint64_t *cmd, const uint64_t *txq_data,
623                        const uint32_t flags)
624 {
625         struct cn10k_eth_txq *txq;
626         struct rte_mbuf *m;
627         uintptr_t lmt_addr;
628         uint16_t lmt_id;
629
630         lmt_addr = ws->lmt_base;
631         ROC_LMT_BASE_ID_GET(lmt_addr, lmt_id);
632
633         if (ev->event_type & RTE_EVENT_TYPE_VECTOR) {
634                 struct rte_mbuf **mbufs = ev->vec->mbufs;
635                 uint64_t meta = *(uint64_t *)ev->vec;
636
637                 if (meta & BIT(31)) {
638                         txq = (struct cn10k_eth_txq
639                                        *)(txq_data[(txq_data[meta >> 32] >>
640                                                     48) +
641                                                    (meta >> 48)] &
642                                           (BIT_ULL(48) - 1));
643
644                         cn10k_nix_xmit_pkts_vector(txq, (uint64_t *)ws, mbufs,
645                                                    meta & 0xFFFF, cmd,
646                                                    flags | NIX_TX_VWQE_F);
647                 } else {
648                         cn10k_sso_vwqe_split_tx(
649                                 ws, mbufs, meta & 0xFFFF, cmd, lmt_id, lmt_addr,
650                                 ev->sched_type, txq_data, flags);
651                 }
652                 rte_mempool_put(rte_mempool_from_obj(ev->vec), ev->vec);
653                 rte_prefetch0(ws);
654                 return 1;
655         }
656
657         m = ev->mbuf;
658         cn10k_sso_tx_one(ws, m, cmd, lmt_id, lmt_addr, ev->sched_type, txq_data,
659                          flags);
660
661         return 1;
662 }
663
664 #define T(name, sz, flags)                                                     \
665         uint16_t __rte_hot cn10k_sso_hws_tx_adptr_enq_##name(                  \
666                 void *port, struct rte_event ev[], uint16_t nb_events);        \
667         uint16_t __rte_hot cn10k_sso_hws_tx_adptr_enq_seg_##name(              \
668                 void *port, struct rte_event ev[], uint16_t nb_events);
669
670 NIX_TX_FASTPATH_MODES
671 #undef T
672
673 #define SSO_TX(fn, sz, flags)                                                  \
674         uint16_t __rte_hot fn(void *port, struct rte_event ev[],               \
675                               uint16_t nb_events)                              \
676         {                                                                      \
677                 struct cn10k_sso_hws *ws = port;                               \
678                 uint64_t cmd[sz];                                              \
679                 RTE_SET_USED(nb_events);                                       \
680                 return cn10k_sso_hws_event_tx(                                 \
681                         ws, &ev[0], cmd, (const uint64_t *)ws->tx_adptr_data,  \
682                         flags);                                                \
683         }
684
685 #define SSO_TX_SEG(fn, sz, flags)                                              \
686         uint16_t __rte_hot fn(void *port, struct rte_event ev[],               \
687                               uint16_t nb_events)                              \
688         {                                                                      \
689                 uint64_t cmd[(sz) + CNXK_NIX_TX_MSEG_SG_DWORDS - 2];           \
690                 struct cn10k_sso_hws *ws = port;                               \
691                 RTE_SET_USED(nb_events);                                       \
692                 return cn10k_sso_hws_event_tx(                                 \
693                         ws, &ev[0], cmd, (const uint64_t *)ws->tx_adptr_data,  \
694                         (flags) | NIX_TX_MULTI_SEG_F);                         \
695         }
696
697 #endif