New upstream version 17.11.1
[deb_dpdk.git] / drivers / event / octeontx / ssovf_worker.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium, Inc. 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium, Inc nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33
34 #include <rte_common.h>
35 #include <rte_branch_prediction.h>
36
37 #include <octeontx_mbox.h>
38
39 #include "ssovf_evdev.h"
40 #include "octeontx_rxtx.h"
41
42 enum {
43         SSO_SYNC_ORDERED,
44         SSO_SYNC_ATOMIC,
45         SSO_SYNC_UNTAGGED,
46         SSO_SYNC_EMPTY
47 };
48
49 #ifndef __hot
50 #define __hot   __attribute__((hot))
51 #endif
52
53 /* SSO Operations */
54
55 static __rte_always_inline struct rte_mbuf *
56 ssovf_octeontx_wqe_to_pkt(uint64_t work, uint16_t port_info)
57 {
58         struct rte_mbuf *mbuf;
59         octtx_wqe_t *wqe = (octtx_wqe_t *)(uintptr_t)work;
60         rte_prefetch_non_temporal(wqe);
61
62         /* Get mbuf from wqe */
63         mbuf = (struct rte_mbuf *)((uintptr_t)wqe -
64                         OCTTX_PACKET_WQE_SKIP);
65         mbuf->packet_type =
66                 ptype_table[wqe->s.w2.lcty][wqe->s.w2.lety][wqe->s.w2.lfty];
67         mbuf->data_off = RTE_PTR_DIFF(wqe->s.w3.addr, mbuf->buf_addr);
68         mbuf->pkt_len = wqe->s.w1.len;
69         mbuf->data_len = mbuf->pkt_len;
70         mbuf->nb_segs = 1;
71         mbuf->ol_flags = 0;
72         mbuf->port = rte_octeontx_pchan_map[port_info >> 4][port_info & 0xF];
73         rte_mbuf_refcnt_set(mbuf, 1);
74         return mbuf;
75 }
76
77 static __rte_always_inline uint16_t
78 ssows_get_work(struct ssows *ws, struct rte_event *ev)
79 {
80         uint64_t get_work0, get_work1;
81         uint64_t sched_type_queue;
82
83         ssovf_load_pair(get_work0, get_work1, ws->getwork);
84
85         sched_type_queue = (get_work0 >> 32) & 0xfff;
86         ws->cur_tt = sched_type_queue & 0x3;
87         ws->cur_grp = sched_type_queue >> 2;
88         sched_type_queue = sched_type_queue << 38;
89         ev->event = sched_type_queue | (get_work0 & 0xffffffff);
90         if (get_work1 && ev->event_type == RTE_EVENT_TYPE_ETHDEV) {
91                 ev->mbuf = ssovf_octeontx_wqe_to_pkt(get_work1,
92                                 (ev->event >> 20) & 0x7F);
93         } else {
94                 ev->u64 = get_work1;
95         }
96
97         return !!get_work1;
98 }
99
100 static __rte_always_inline void
101 ssows_add_work(struct ssows *ws, const uint64_t event_ptr, const uint32_t tag,
102                         const uint8_t new_tt, const uint8_t grp)
103 {
104         uint64_t add_work0;
105
106         add_work0 = tag | ((uint64_t)(new_tt) << 32);
107         ssovf_store_pair(add_work0, event_ptr, ws->grps[grp]);
108 }
109
110 static __rte_always_inline void
111 ssows_swtag_full(struct ssows *ws, const uint64_t event_ptr, const uint32_t tag,
112                         const uint8_t new_tt, const uint8_t grp)
113 {
114         uint64_t swtag_full0;
115
116         swtag_full0 = tag | ((uint64_t)(new_tt & 0x3) << 32) |
117                                 ((uint64_t)grp << 34);
118         ssovf_store_pair(swtag_full0, event_ptr, (ws->base +
119                                 SSOW_VHWS_OP_SWTAG_FULL0));
120 }
121
122 static __rte_always_inline void
123 ssows_swtag_desched(struct ssows *ws, uint32_t tag, uint8_t new_tt, uint8_t grp)
124 {
125         uint64_t val;
126
127         val = tag | ((uint64_t)(new_tt & 0x3) << 32) | ((uint64_t)grp << 34);
128         ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_DESCHED);
129 }
130
131 static __rte_always_inline void
132 ssows_swtag_norm(struct ssows *ws, uint32_t tag, uint8_t new_tt)
133 {
134         uint64_t val;
135
136         val = tag | ((uint64_t)(new_tt & 0x3) << 32);
137         ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_NORM);
138 }
139
140 static __rte_always_inline void
141 ssows_swtag_untag(struct ssows *ws)
142 {
143         ssovf_write64(0, ws->base + SSOW_VHWS_OP_SWTAG_UNTAG);
144         ws->cur_tt = SSO_SYNC_UNTAGGED;
145 }
146
147 static __rte_always_inline void
148 ssows_upd_wqp(struct ssows *ws, uint8_t grp, uint64_t event_ptr)
149 {
150         ssovf_store_pair((uint64_t)grp << 34, event_ptr, (ws->base +
151                                 SSOW_VHWS_OP_UPD_WQP_GRP0));
152 }
153
154 static __rte_always_inline void
155 ssows_desched(struct ssows *ws)
156 {
157         ssovf_write64(0, ws->base + SSOW_VHWS_OP_DESCHED);
158 }
159
160 static __rte_always_inline void
161 ssows_swtag_wait(struct ssows *ws)
162 {
163         /* Wait for the SWTAG/SWTAG_FULL operation */
164         while (ssovf_read64(ws->base + SSOW_VHWS_SWTP))
165         ;
166 }