1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
5 #include <rte_common.h>
6 #include <rte_branch_prediction.h>
8 #include <octeontx_mbox.h>
10 #include "ssovf_evdev.h"
11 #include "octeontx_rxtx.h"
21 #define __hot __attribute__((hot))
26 static __rte_always_inline struct rte_mbuf *
27 ssovf_octeontx_wqe_to_pkt(uint64_t work, uint16_t port_id)
29 struct rte_mbuf *mbuf;
30 octtx_wqe_t *wqe = (octtx_wqe_t *)(uintptr_t)work;
31 rte_prefetch_non_temporal(wqe);
33 /* Get mbuf from wqe */
34 mbuf = (struct rte_mbuf *)((uintptr_t)wqe -
35 OCTTX_PACKET_WQE_SKIP);
37 ptype_table[wqe->s.w2.lcty][wqe->s.w2.lety][wqe->s.w2.lfty];
38 mbuf->data_off = RTE_PTR_DIFF(wqe->s.w3.addr, mbuf->buf_addr);
39 mbuf->pkt_len = wqe->s.w1.len;
40 mbuf->data_len = mbuf->pkt_len;
44 rte_mbuf_refcnt_set(mbuf, 1);
48 static __rte_always_inline uint16_t
49 ssows_get_work(struct ssows *ws, struct rte_event *ev)
51 uint64_t get_work0, get_work1;
52 uint64_t sched_type_queue;
54 ssovf_load_pair(get_work0, get_work1, ws->getwork);
56 sched_type_queue = (get_work0 >> 32) & 0xfff;
57 ws->cur_tt = sched_type_queue & 0x3;
58 ws->cur_grp = sched_type_queue >> 2;
59 sched_type_queue = sched_type_queue << 38;
60 ev->event = sched_type_queue | (get_work0 & 0xffffffff);
61 if (get_work1 && ev->event_type == RTE_EVENT_TYPE_ETHDEV) {
62 ev->mbuf = ssovf_octeontx_wqe_to_pkt(get_work1,
63 (ev->event >> 20) & 0xF);
71 static __rte_always_inline void
72 ssows_add_work(struct ssows *ws, const uint64_t event_ptr, const uint32_t tag,
73 const uint8_t new_tt, const uint8_t grp)
77 add_work0 = tag | ((uint64_t)(new_tt) << 32);
78 ssovf_store_pair(add_work0, event_ptr, ws->grps[grp]);
81 static __rte_always_inline void
82 ssows_swtag_full(struct ssows *ws, const uint64_t event_ptr, const uint32_t tag,
83 const uint8_t new_tt, const uint8_t grp)
87 swtag_full0 = tag | ((uint64_t)(new_tt & 0x3) << 32) |
88 ((uint64_t)grp << 34);
89 ssovf_store_pair(swtag_full0, event_ptr, (ws->base +
90 SSOW_VHWS_OP_SWTAG_FULL0));
93 static __rte_always_inline void
94 ssows_swtag_desched(struct ssows *ws, uint32_t tag, uint8_t new_tt, uint8_t grp)
98 val = tag | ((uint64_t)(new_tt & 0x3) << 32) | ((uint64_t)grp << 34);
99 ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_DESCHED);
102 static __rte_always_inline void
103 ssows_swtag_norm(struct ssows *ws, uint32_t tag, uint8_t new_tt)
107 val = tag | ((uint64_t)(new_tt & 0x3) << 32);
108 ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_NORM);
111 static __rte_always_inline void
112 ssows_swtag_untag(struct ssows *ws)
114 ssovf_write64(0, ws->base + SSOW_VHWS_OP_SWTAG_UNTAG);
115 ws->cur_tt = SSO_SYNC_UNTAGGED;
118 static __rte_always_inline void
119 ssows_upd_wqp(struct ssows *ws, uint8_t grp, uint64_t event_ptr)
121 ssovf_store_pair((uint64_t)grp << 34, event_ptr, (ws->base +
122 SSOW_VHWS_OP_UPD_WQP_GRP0));
125 static __rte_always_inline void
126 ssows_desched(struct ssows *ws)
128 ssovf_write64(0, ws->base + SSOW_VHWS_OP_DESCHED);
131 static __rte_always_inline void
132 ssows_swtag_wait(struct ssows *ws)
134 /* Wait for the SWTAG/SWTAG_FULL operation */
135 while (ssovf_read64(ws->base + SSOW_VHWS_SWTP))