1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 Cavium, Inc 3 */ 4 5 #include <rte_common.h> 6 #include <rte_branch_prediction.h> 7 8 #include <octeontx_mbox.h> 9 10 #include "ssovf_evdev.h" 11 #include "octeontx_rxtx.h" 12 13 enum { 14 SSO_SYNC_ORDERED, 15 SSO_SYNC_ATOMIC, 16 SSO_SYNC_UNTAGGED, 17 SSO_SYNC_EMPTY 18 }; 19 20 #ifndef __hot 21 #define __hot __attribute__((hot)) 22 #endif 23 24 /* SSO Operations */ 25 26 static __rte_always_inline struct rte_mbuf * 27 ssovf_octeontx_wqe_to_pkt(uint64_t work, uint16_t port_info) 28 { 29 struct rte_mbuf *mbuf; 30 octtx_wqe_t *wqe = (octtx_wqe_t *)(uintptr_t)work; 31 rte_prefetch_non_temporal(wqe); 32 33 /* Get mbuf from wqe */ 34 mbuf = (struct rte_mbuf *)((uintptr_t)wqe - 35 OCTTX_PACKET_WQE_SKIP); 36 mbuf->packet_type = 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; 41 mbuf->nb_segs = 1; 42 mbuf->ol_flags = 0; 43 mbuf->port = rte_octeontx_pchan_map[port_info >> 4][port_info & 0xF]; 44 rte_mbuf_refcnt_set(mbuf, 1); 45 return mbuf; 46 } 47 48 static __rte_always_inline uint16_t 49 ssows_get_work(struct ssows *ws, struct rte_event *ev) 50 { 51 uint64_t get_work0, get_work1; 52 uint64_t sched_type_queue; 53 54 ssovf_load_pair(get_work0, get_work1, ws->getwork); 55 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) & 0x7F); 64 } else { 65 ev->u64 = get_work1; 66 } 67 68 return !!get_work1; 69 } 70 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) 74 { 75 uint64_t add_work0; 76 77 add_work0 = tag | ((uint64_t)(new_tt) << 32); 78 ssovf_store_pair(add_work0, event_ptr, ws->grps[grp]); 79 } 80 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) 84 { 85 uint64_t swtag_full0; 86 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)); 91 } 92 93 static __rte_always_inline void 94 ssows_swtag_desched(struct ssows *ws, uint32_t tag, uint8_t new_tt, uint8_t grp) 95 { 96 uint64_t val; 97 98 val = tag | ((uint64_t)(new_tt & 0x3) << 32) | ((uint64_t)grp << 34); 99 ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_DESCHED); 100 } 101 102 static __rte_always_inline void 103 ssows_swtag_norm(struct ssows *ws, uint32_t tag, uint8_t new_tt) 104 { 105 uint64_t val; 106 107 val = tag | ((uint64_t)(new_tt & 0x3) << 32); 108 ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_NORM); 109 } 110 111 static __rte_always_inline void 112 ssows_swtag_untag(struct ssows *ws) 113 { 114 ssovf_write64(0, ws->base + SSOW_VHWS_OP_SWTAG_UNTAG); 115 ws->cur_tt = SSO_SYNC_UNTAGGED; 116 } 117 118 static __rte_always_inline void 119 ssows_upd_wqp(struct ssows *ws, uint8_t grp, uint64_t event_ptr) 120 { 121 ssovf_store_pair((uint64_t)grp << 34, event_ptr, (ws->base + 122 SSOW_VHWS_OP_UPD_WQP_GRP0)); 123 } 124 125 static __rte_always_inline void 126 ssows_desched(struct ssows *ws) 127 { 128 ssovf_write64(0, ws->base + SSOW_VHWS_OP_DESCHED); 129 } 130 131 static __rte_always_inline void 132 ssows_swtag_wait(struct ssows *ws) 133 { 134 /* Wait for the SWTAG/SWTAG_FULL operation */ 135 while (ssovf_read64(ws->base + SSOW_VHWS_SWTP)) 136 ; 137 } 138