Adding new commiter to ODU-High repo
[o-du/l2.git] / src / mt / ss_gen.h
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /********************************************************************20**
20  
21      Name:     System Services -- general
22  
23      Type:     C include file
24  
25      Desc:     Macro definitions that are used by all implementations
26                of system services.
27  
28      File:     ss_gen.h
29  
30 *********************************************************************21*/
31
32
33 #ifndef __SSGENH__
34 #define __SSGENH__
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /* ss040.103: addition */
41 /* ss002.301 : errno.h is required for all */
42 #include <errno.h>   
43
44 /* the new driver support define */
45 #ifdef ENB_RELAY
46 #ifndef SS_DRVR_SUPPORT
47 #define SS_DRVR_SUPPORT
48 #endif
49 #endif
50
51
52
53 /* general */
54 #ifndef SS_PROC_ID
55 #error "SS_PROC_ID undefined!"
56 #endif
57
58 #ifndef SS_MAX_ENT
59 #error "SS_MAX_ENT undefined!"
60 #endif
61
62 #ifndef SS_MAX_INST
63 #error "SS_MAX_INST undefined!"
64 #endif
65
66
67 /* ss029.103: modification: the data type of array modified */ 
68 #ifndef SS_MULTIPLE_PROCS
69 #define SS_INVALID_IDX                  0xFF
70 #else /* SS_MULTIPLE_PROCS */
71 #define SS_INVALID_IDX                  0xFFFF
72 #endif /* SS_MULTIPLE_PROCS */
73
74
75 /* task related */
76 #ifndef SS_MAX_TTSKS
77 #error "SS_MAX_TTSKS undefined!"
78 #endif
79
80 #ifndef SS_MAX_STSKS
81 #error "SS_MAX_STSKS undefined!"
82 #endif
83
84 #ifdef SS_DRVR_SUPPORT
85 #ifndef SS_MAX_DRVRTSKS
86 #error "SS_MAX_DRVRTSKS undefined!"
87 #endif
88 #endif /* SS_DRVR_SUPPORT */
89
90 #ifdef SS_RTR_SUPPORT
91 #ifndef SS_MAX_RTRTSKS
92 #error "SS_MAX_RTRTSKS undefined!"
93 #endif
94 #endif /* SS_RTR_SUPPORT */
95
96 /* ss029.103: modification: the data type of array modified */ 
97 #ifndef SS_MULTIPLE_PROCS
98 #define SS_TSKNC                        0xFF
99 #else /* SS_MULTIPLE_PROCS */
100 #define SS_TSKNC                        0xFFFF
101 #endif /* SS_MULTIPLE_PROCS */
102
103
104 /* timer related */
105 #ifndef SS_MAX_TMRS
106 #error "SS_MAX_TMRS undefined!"
107 #endif
108
109
110
111 /* memory related */
112 #ifndef SS_MAX_REGS
113 #error "SS_MAX_REGS undefined!"
114 #endif
115
116 #ifndef SS_MAX_POOLS_PER_REG
117 #error "SS_MAX_POOLS_PER_REG undefined!"
118 #endif
119
120
121 /* event types */
122 #define SS_EVNT_DATA                    0
123 #define SS_EVNT_TIMER                   1
124 #define SS_EVNT_TERM                    2
125 #define SS_EVNT_PERMTICK                3
126 /*
127  * SDeRegTTsk patch
128  */
129 #define SS_EVNT_TTSK_TERM                                        4
130
131 /* ss001.301: SSI Phase 2 watchdog feature additions */
132 #ifdef SS_WATCHDOG 
133 #define SS_MAX_WD_NODES 256
134 #define SS_WD_HB_MSG_VER "1.0"
135 #define SS_WD_HB_REQ 0x0001
136 #define SS_WD_HB_RSP 0x0010
137 #define SS_WD_HB_MSG_SIZE 24
138 #define SS_WD_WDPORT 8888
139 #define SS_WD_WDPROC 99
140 #endif /* SS_WATCHDOG */
141
142 /* Logger support */
143 #ifdef SS_LOGGER_SUPPORT
144 #ifndef SS_MAX_LOGBUF_SIZE
145 #define SS_MAX_LOGBUF_SIZE 8192
146 #endif
147 #ifndef SS_MAX_PATH
148 #define SS_MAX_PATH 1024
149 #endif
150 #endif /* SS_LOGGER_SUPPORT */
151
152
153 /* object lock types */
154 #if (!defined(SS_STSKTBL_LOCK) \
155         ||  !defined(SS_STSKENTRY_LOCK) \
156         ||  !defined(SS_TMRTBL_LOCK) \
157         ||  !defined(SS_DMNDQ_LOCK) \
158         ||  !defined(SS_DRVRENTRY_LOCK) \
159         ||  !defined(SS_RTRENTRY_LOCK))
160 #error "SS_?_LOCK undefined!"
161 #endif
162
163 /* The define used for mapping the memory region with threadId */
164 #ifdef SS_THR_REG_MAP
165 /* Maximum times SSI retries to create a thread in case if it 
166  * gets same pthread_self() id which already mapped with other
167  * thread. Once this limit is hit, SSI will exit. In ideal case
168  * this should not happen
169  */
170 #define SS_MAX_THREAD_CREATE_RETRY     100
171
172 /* Maximum thread to region mapping. The same is used to 
173  * to get the reminder which is used as index for memory mapping
174  * array. This is kept as 10 to avoid any issues as we see
175  * the thread IDs are always even number and we have 4 thread
176  * at this time 
177  */
178 #define SS_MAX_THREAD_REGION_MAP       16
179 #ifdef LTE_PAL_ENB
180 #define SS_MEM_THREAD_ID_SHIFT         24
181 #else
182 #define SS_MEM_THREAD_ID_SHIFT         16
183 #endif
184
185 #define SS_INVALID_THREAD_REG_MAP      0xFF
186
187 #define SS_GET_THREAD_MEM_REGION() \
188     osCp.threadMemoryRegionMap[((pthread_self() >> SS_MEM_THREAD_ID_SHIFT) % SS_MAX_THREAD_REGION_MAP)]
189 #else
190 #define SS_GET_THREAD_MEM_REGION() region
191 #endif /* SS_THR_REG_MAP */
192
193    /* ss040.103 changed how ssWaitSema is called */
194   /* ss013.13: addition */
195 /* locking macros */
196 /*ss014.301 SSI-4GMX specific changes*/    
197 #ifndef SS_4GMX_LCORE
198 #define SS_ACQUIRE_ALL_SEMA(s, ret) \
199    { \
200       S16 q; \
201       ret = ROK; \
202       for (q = 0;  q < SS_MAX_STSKS;  q++) \
203       { \
204          while ((ret = ssWaitSema(s) != ROK) && (errno == EINTR)) \
205             continue; \
206          if ( ret != ROK)\
207          {\
208              SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,\
209                         "Could not lock the Semaphore");\
210          }\
211          if (ret != ROK) \
212          { \
213             while (q > 0) \
214             { \
215                ret = ssPostSema(s); \
216                if ( ret != ROK)\
217                {\
218                    SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,\
219                            "Could not unlock the Semaphore");\
220                }\
221                q--; \
222             } \
223             break; \
224          } \
225       } \
226       if (q == 0) \
227          ret = RFAILED; \
228    }
229
230
231   /* ss006.13: addition */
232 #define SS_RELEASE_ALL_SEMA(s) \
233    { \
234       S16 q; \
235       for (q = 0;  q < SS_MAX_STSKS;  q++) \
236       {\
237          if ( (ssPostSema(s)) != ROK)\
238          {\
239             SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,\
240                          "Could not unlock the Semaphore");\
241             return RFAILED;\
242          }\
243       }\
244    }
245
246 /* ss040.103 changed how ssWaitSema is called */
247 #define SS_ACQUIRE_SEMA(s, ret) \
248    while ((ret = ssWaitSema(s) != ROK) && (errno == EINTR)) \
249       continue;\
250 /* ss041.103 removed exta lines */
251
252
253
254   /* ss006.13: addition */
255 #define SS_RELEASE_SEMA(s) \
256    ssPostSema(s)
257
258 /* ss029.103: addition: multiple procIds related changes */ 
259 #ifdef SS_MULTIPLE_PROCS
260 #define SS_INV_PROCID_IDX 0xFFFF /* invalid index in procId table */
261 #define SS_INV_PROCID     0xFFFF /* invalid proc id */ 
262
263 #define SS_HASH_IDX(_proc) (_proc % SS_MAX_PROCS)
264
265 #endif /* SS_MULTIPLE_PROCS */
266 #else
267 #define SS_ACQUIRE_ALL_SEMA(s, ret) \
268    { \
269       ret = ssWaitSema(s); \
270    }
271
272
273 #define SS_RELEASE_ALL_SEMA(s) \
274    { \
275          ssPostSema(s);\
276    }
277
278 #define SS_ACQUIRE_SEMA(s, ret) \
279       ret = ssWaitSema(s)
280
281 #define SS_RELEASE_SEMA(s) \
282    ssPostSema(s)
283 #endif  /* SS_4GMX_LCORE  */
284
285 #ifdef __cplusplus
286 }
287 #endif
288
289 #endif  /*  __SSGENH__  */
290
291
292 \f
293 /********************************************************************30**
294  
295          End of file
296 **********************************************************************/