300dfae839bd2897f4898e5e8aa93915d381eb1e
[deb_dpdk.git] / drivers / event / octeontx / ssovf_worker.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium networks Ltd. 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 networks 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
36 #include "ssovf_evdev.h"
37
38 enum {
39         SSO_SYNC_ORDERED,
40         SSO_SYNC_ATOMIC,
41         SSO_SYNC_UNTAGGED,
42         SSO_SYNC_EMPTY
43 };
44
45 #ifndef force_inline
46 #define force_inline inline __attribute__((always_inline))
47 #endif
48
49 #ifndef __hot
50 #define __hot   __attribute__((hot))
51 #endif
52
53 /* SSO Operations */
54
55 static force_inline uint16_t
56 ssows_get_work(struct ssows *ws, struct rte_event *ev)
57 {
58         uint64_t get_work0, get_work1;
59         uint64_t sched_type_queue;
60
61         ssovf_load_pair(get_work0, get_work1, ws->getwork);
62
63         sched_type_queue = (get_work0 >> 32) & 0xfff;
64         ws->cur_tt = sched_type_queue & 0x3;
65         ws->cur_grp = sched_type_queue >> 2;
66         sched_type_queue = sched_type_queue << 38;
67
68         ev->event = sched_type_queue | (get_work0 & 0xffffffff);
69         ev->u64 = get_work1;
70         return !!get_work1;
71 }
72
73 static force_inline void
74 ssows_add_work(struct ssows *ws, const uint64_t event_ptr, const uint32_t tag,
75                         const uint8_t new_tt, const uint8_t grp)
76 {
77         uint64_t add_work0;
78
79         add_work0 = tag | ((uint64_t)(new_tt) << 32);
80         ssovf_store_pair(add_work0, event_ptr, ws->grps[grp]);
81 }
82
83 static force_inline void
84 ssows_swtag_full(struct ssows *ws, const uint64_t event_ptr, const uint32_t tag,
85                         const uint8_t new_tt, const uint8_t grp)
86 {
87         uint64_t swtag_full0;
88
89         swtag_full0 = tag | ((uint64_t)(new_tt & 0x3) << 32) |
90                                 ((uint64_t)grp << 34);
91         ssovf_store_pair(swtag_full0, event_ptr, (ws->base +
92                                 SSOW_VHWS_OP_SWTAG_FULL0));
93 }
94
95 static force_inline void
96 ssows_swtag_desched(struct ssows *ws, uint32_t tag, uint8_t new_tt, uint8_t grp)
97 {
98         uint64_t val;
99
100         val = tag | ((uint64_t)(new_tt & 0x3) << 32) | ((uint64_t)grp << 34);
101         ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_DESCHED);
102 }
103
104 static force_inline void
105 ssows_swtag_norm(struct ssows *ws, uint32_t tag, uint8_t new_tt)
106 {
107         uint64_t val;
108
109         val = tag | ((uint64_t)(new_tt & 0x3) << 32);
110         ssovf_write64(val, ws->base + SSOW_VHWS_OP_SWTAG_NORM);
111 }
112
113 static force_inline void
114 ssows_swtag_untag(struct ssows *ws)
115 {
116         ssovf_write64(0, ws->base + SSOW_VHWS_OP_SWTAG_UNTAG);
117         ws->cur_tt = SSO_SYNC_UNTAGGED;
118 }
119
120 static force_inline void
121 ssows_upd_wqp(struct ssows *ws, uint8_t grp, uint64_t event_ptr)
122 {
123         ssovf_store_pair((uint64_t)grp << 34, event_ptr, (ws->base +
124                                 SSOW_VHWS_OP_UPD_WQP_GRP0));
125 }
126
127 static force_inline void
128 ssows_desched(struct ssows *ws)
129 {
130         ssovf_write64(0, ws->base + SSOW_VHWS_OP_DESCHED);
131 }
132
133 static force_inline void
134 ssows_swtag_wait(struct ssows *ws)
135 {
136         /* Wait for the SWTAG/SWTAG_FULL operation */
137         while (ssovf_read64(ws->base + SSOW_VHWS_SWTP))
138         ;
139 }