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_info)
29 struct rte_mbuf *mbuf;
30 octtx_wqe_t *wqe = (octtx_wqe_t *)(uintptr_t)work;
32 /* Get mbuf from wqe */
33 mbuf = (struct rte_mbuf *)((uintptr_t)wqe -
34 OCTTX_PACKET_WQE_SKIP);
35 rte_prefetch_non_temporal(mbuf);
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;
43 mbuf->port = rte_octeontx_pchan_map[port_info >> 4][port_info & 0xF];
44 rte_mbuf_refcnt_set(mbuf, 1);
49 static __rte_always_inline uint16_t
50 ssows_get_work(struct ssows *ws, struct rte_event *ev)
52 uint64_t get_work0, get_work1;
53 uint64_t sched_type_queue;
55 ssovf_load_pair(get_work0, get_work1, ws->getwork);
57 sched_type_queue = (get_work0 >> 32) & 0xfff;
58 ws->cur_tt = sched_type_queue & 0x3;
59 ws->cur_grp = sched_type_queue >> 2;
60 sched_type_queue = sched_type_queue << 38;
61 ev->event = sched_type_queue | (get_work0 & 0xffffffff);
62 if (get_work1 && ev->event_type == RTE_EVENT_TYPE_ETHDEV) {
63 ev->mbuf = ssovf_octeontx_wqe_to_pkt(get_work1,
64 (ev->event >> 20) & 0x7F);
72 static __rte_always_inline void
73 ssows_add_work(struct ssows *ws, const uint64_t event_ptr, const uint32_t tag,
74 const uint8_t new_tt, const uint8_t grp)
78 add_work0 = tag | ((uint64_t)(new_tt) << 32);
79 ssovf_store_pair(add_work0, event_ptr, ws->grps[grp]);
82 static __rte_always_inline void
83 ssows_swtag_full(struct ssows *ws, const uint64_t event_ptr, const uint32_t tag,
84 const uint8_t new_tt, const uint8_t grp)
88 swtag_full0 = tag | ((uint64_t)(new_tt & 0x3) << 32) |
89 ((uint64_t)grp << 34);
90 ssovf_store_pair(swtag_full0, event_ptr, (ws->base +
91 SSOW_VHWS_OP_SWTAG_FULL0));
94 static __rte_always_inline void
95 ssows_swtag_desched(struct ssows *ws, uint32_t tag, uint8_t new_tt, uint8_t grp)
99 val = tag | ((uint64_t)(new_tt & 0x3) << 32) | ((uint64_t)grp << 34);
100 ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_DESCHED);
103 static __rte_always_inline void
104 ssows_swtag_norm(struct ssows *ws, uint32_t tag, uint8_t new_tt)
108 val = tag | ((uint64_t)(new_tt & 0x3) << 32);
109 ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_NORM);
112 static __rte_always_inline void
113 ssows_swtag_untag(struct ssows *ws)
115 ssovf_write64(0, ws->base + SSOW_VHWS_OP_SWTAG_UNTAG);
116 ws->cur_tt = SSO_SYNC_UNTAGGED;
119 static __rte_always_inline void
120 ssows_upd_wqp(struct ssows *ws, uint8_t grp, uint64_t event_ptr)
122 ssovf_store_pair((uint64_t)grp << 34, event_ptr, (ws->base +
123 SSOW_VHWS_OP_UPD_WQP_GRP0));
126 static __rte_always_inline void
127 ssows_desched(struct ssows *ws)
129 ssovf_write64(0, ws->base + SSOW_VHWS_OP_DESCHED);
132 static __rte_always_inline void
133 ssows_swtag_wait(struct ssows *ws)
135 /* Wait for the SWTAG/SWTAG_FULL operation */
136 while (ssovf_read64(ws->base + SSOW_VHWS_SWTP))