2508ef810bc7520a365412a4f8f592506e0aabd8
[o-du/l2.git] / src / mt / ss_gen.x
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:     Data structure definitions that are used by all
26                implementations of system services.
27  
28      File:     ss_gen.x
29  
30 *********************************************************************21*/
31
32
33 #ifndef __SSGENX__
34 #define __SSGENX__
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 struct cmMmGlobRegCb;
41 /* ss029.103: addition: multiple procIds related changes */ 
42 #ifdef SS_MULTIPLE_PROCS
43 typedef struct {
44    uint16_t free;
45    ProcId procId[SS_MAX_PROCS];
46 } ProcIdLst;
47 #endif /* SS_MULTIPLE_PROCS */
48
49 /* multi-core enhancements */
50 /*ss013.301 : changes for SS_AFFINITY_SUPPORT*/
51 #if defined(SS_MULTICORE_SUPPORT) || defined(SS_AFFINITY_SUPPORT)
52
53 typedef struct {
54   SCpuInfo cpuInfo; /* the info about the cores/threads per core */
55
56
57   /* the currently used core */
58   uint32_t currentCore;
59   
60   /*COMMENT: add the thread id for use on hyperthreading machines */
61   struct {
62     uint32_t thrs;                     /* available no. of threads per core */
63     S8 exclusive;                 /* exclusive flag */
64     SSTskId tskPerCoreLst[SS_MAX_THREADS_PER_CORE]; /* System tasks running on this core */
65   } coreInfo[SS_MAX_CORES];
66 } SMultiCoreInfo;
67 #endif /* SS_MULTICORE_SUPPORT || SS_AFFINITY_SUPPORT */
68
69 /* ss001.301: additions */
70 /* ss002.301: Modifications */
71 #ifdef SS_THREAD_PROFILE
72 #ifdef SS_MULTIPLE_PROCS
73 S16 SGetThrdProf(SSTskId *sTskId,ProcId procId,Ent ent,Inst inst,Event *curEvent,uint32_t *curEvtTime,uint64_t *totTime);
74 #else
75 S16 SGetThrdProf(SSTskId *sTskId,Ent ent,Inst inst,Event *curEvent,uint32_t *curEvtTime,uint64_t *totTime);
76 #endif /* SS_MULTIPLE_PROCS */
77 #endif /* SS_THERAD_PROFILE */
78
79 #ifdef SS_WATCHDOG
80
81 typedef void (*WdUserCallback)(void *);
82
83 typedef struct {
84 #ifdef SS_WATCHDOG_IPV6
85    struct in6_addr  addr;
86 #else
87    struct in_addr addr;       /* configured node addr */
88 #endif /* SS_WATCHDOG_IPV6 */
89    uint16_t port;       /* configured watchdog port */
90    uint8_t status;      /* HB ACK status */
91 } watchDogStatus;
92
93 typedef struct ssWd {
94    uint32_t            timeout;                 /* configured HB timer */
95    uint8_t             watchdogStop;            /* watchdog stop flag */
96    int            numNodes;                /* configured nodes */
97 #ifdef SS_WIN
98    unsigned int   sock;                    /* HB socket descriptor */
99 #else
100    int            sock;
101 #endif /* SS_WIN */
102
103    watchDogStatus wdsta[SS_MAX_WD_NODES];  /* node config or status */
104    WdUserCallback callback;                /* user callback */
105    void           *data;                   /* user callback data */
106 } SsWd;
107
108 typedef struct ssWdCp{
109    SSTskId               watchDgTskId;
110    SSTskId               watchDgRcvrTskId;
111    Pst                   watchDgPst;
112    CmTqCp                watchDgTqCp;  /* timing queue control point : WatchDog */
113    CmTqType              watchDgTs[2]; /*timing queue */ 
114    CmTimer               watchDgTmr[2];         
115    ProcId                watchDgprocId;
116    SsWd                  globWd;
117    SLockId               wdLock;
118 } SsWdCp;
119 S16 SInitWatchdog(uint16_t port);
120 S16 SRegCfgWd(uint32_t numNodes, uint8_t *addr[], uint16_t port[], uint32_t timeout, WdUserCallback callback, void *data);
121 S16 SDeregCfgWd(void);
122 S16 SStartHrtBt(uint8_t timeInterval);
123 S16 SStopHrtBt(void);
124 #endif /* SS_WATCHDOG */
125
126 #ifdef SS_LOGGER_SUPPORT
127 /* Logger Info */
128 typedef struct sloggerInfo
129 {
130      Bool            started;      /* flag to indicate logger status */
131
132      Bool            configured;   /* flag to indicate whether logger is configured */
133
134      Bool            opt;               /* write to file/socket based on the flags provided*/      
135    
136      FILE*           filep;
137      S8              filePath[SS_MAX_PATH];
138    
139      S32             socketdes;
140      struct sockaddr_in remoteAddr;
141    
142      uint16_t             curNumFlush;
143      uint16_t             maxNumFlush;
144      
145      S8              buffer[SS_MAX_LOGBUF_SIZE];
146      uint32_t             maxBufSiz;        /*The size of this is determined by the 
147                                             system on which its running.*/
148      uint32_t             curBufSiz;
149      SLockId         bufLock;            /* lock for global buffer access */
150 } SLoggerInfo;
151 #endif /*  SS_LOGGER_SUPPORT  */
152
153 #if defined (INTEL_WLS) || defined (SS_USE_WLS_MEM)
154 typedef struct _MtWls
155 {
156   Void   *intf;
157   Void   *allocAddr;
158 }SsMtWls;
159 #endif   /* INTEL_WLS */
160
161
162 #ifdef NTL_LIB
163 typedef struct _MtNtl
164 {
165    uint32_t        hdl;
166 }SsMtNtl;
167 #endif   /* NTL_LIB */
168
169
170
171 /* SS control point */
172 typedef struct ssos
173 {
174    
175    SsdOs                dep;                    /* implementation specific */
176
177 /* ss029.103: modification: 
178    with multiple procId support, SSI shall keep list of registered procIds  */
179 #ifndef SS_MULTIPLE_PROCS
180    ProcId               procId;                 /* processor ID */
181
182     /* TAPA task info */
183    SsIdx                tTskIds[SS_MAX_ENT][SS_MAX_INST];
184 #else
185    ProcIdLst            procLst;                /* processor ID list */
186    SsIdx                tTskIds[SS_MAX_PROCS][SS_MAX_ENT][SS_MAX_INST];
187    /* TAPA task info */
188 #endif /* SS_MULTIPLE_PROCS */
189                                                /* index table */
190    SsTTskEntry          tTskTbl[SS_MAX_TTSKS];  /* task table */
191    SsCntr               numTTsks;               /* count of tasks */
192    SsIdx                nxtTTskEntry;           /* next available slot */
193
194    SsSemaId             tTskTblSem;             /* lock for table access */
195
196
197    /* system task info */
198    SsSTskEntry          sTskTbl[SS_MAX_STSKS];  /* task table */
199
200    /* Thread to region mapping. The array is indexed with reminder
201       of thread ID after deviding it with SS_MAX_THREAD_REGION_MAP 
202     */
203 #ifdef SS_THR_REG_MAP
204    Region               threadMemoryRegionMap[SS_MAX_THREAD_REGION_MAP];
205 #endif
206    SsCntr               numSTsks;               /* count of tasks */
207    SsIdx                nxtSTskEntry;           /* next available slot */
208
209    SLockId              sTskTblLock;            /* lock for table access */
210
211
212    uint8_t                   dmndQLookupTbl[256];    /* demand queue lookup table */
213
214
215 #ifdef SS_DRVR_SUPPORT
216
217    /* driver task info */
218    SsDrvrTskEntry       drvrTskTbl[SS_MAX_DRVRTSKS];
219                                                 /* task table */
220    SsCntr               numDrvrTsks;            /* count of tasks */
221
222 #endif  /* SS_DRVR_SUPPORT */
223
224
225 #ifdef SS_RTR_SUPPORT
226
227    /* router task info */
228    ActvTsk              rtrTskTbl[SS_MAX_RTRTSKS];
229    SLockId              rtrTskLocks[SS_MAX_RTRTSKS];
230
231 #endif  /* SS_RTR_SUPPORT */
232
233
234    /* timer info */
235    SsTmrEntry           tmrTbl[SS_MAX_TMRS];        /* timer table */
236    SsCntr               numTmrs;                    /* count of timers */
237    SsIdx                nxtTmrEntry;                /* next available slot */
238
239    SLockId              tmrTblLock;                 /* lock for table access */
240
241    /* Pointer to global region */
242    struct cmMmGlobRegCb *globRegCb;                 /* Global Region Cb */
243
244    SsCntr               numRegions;                 /* count of regions */
245    SsRegionEntry        regionTbl[SS_MAX_REGS];     /* region table */
246    SsCntr               numDynRegions;              /* Number of dynamic regions */
247    SsRegionEntry        dynRegionTbl[SS_MAX_REGS];  /* Dynamic Region Table */
248
249    SsSemaId             regionTblSem;               /* lock for table access */
250
251    /* ss028.103 - Addition of lock for mBuf reference count */
252         /* ss007.301 - moved the lock to RegionTbl */
253    /* SLockId              mBufRefLock; */            /* lock for mBuf ref access */
254
255 /*ss013.301 : changes for SS_AFFINITY_SUPPORT*/
256 #if defined(SS_MULTICORE_SUPPORT) || defined(SS_AFFINITY_SUPPORT)
257    /* the Information about the CPU */
258    SMultiCoreInfo mCInfo;
259
260    SLockId mCILock;                             /* Lock for mCInfo access */
261
262 #endif /* SS_MULTICORE_SUPPORT || SS_AFFINITY_SUPPORT */
263
264 /* ss001.301: additions */
265 #ifdef SS_WATCHDOG 
266    SsWdCp                wdCp;
267 #endif /* SS_WATCHDOG */
268
269 #ifdef SS_HISTOGRAM_SUPPORT
270    uint8_t                    entId[26][26];
271 #endif /* SS_HISTOGRAM_SUPPORT */
272
273 #ifdef SS_LOGGER_SUPPORT
274  SLoggerInfo logger;
275 #endif /*  SS_LOGGER_SUPPORT  */
276  S8          *configFilePath;
277 #if defined (INTEL_WLS) || defined (SS_USE_WLS_MEM)
278    SsMtWls   wls;
279 #endif
280
281 #ifdef NTL_LIB
282    SsMtNtl   ntl;
283 #endif
284
285 } SsOs;
286
287
288
289 /* configuration data structures */
290
291 /* pool configuration */
292 typedef struct ssPoolCfg
293 {
294    SsPoolType   type;                   /* dynamic or static */
295    Size         size;                   /* size to use (for dynamic pools) */
296
297 } SsPoolCfg;
298
299
300 /* region content--pools in a region */
301 typedef struct ssRegCfg
302 {
303    Region       region;                      /* region ID */
304    SsCntr       numPools;                    /* count of pools */
305    SsPoolCfg    pools[SS_MAX_POOLS_PER_REG]; /* pools configuration */
306
307 } SsRegCfg;
308
309
310
311 /* external variable declaration */
312 /*ss014.301  osCp as volatile for SSI-4GMX*/
313 #ifdef  SS_4GMX_LCORE
314 volatile SsOs osCp;
315 #else
316 SsOs osCp;
317 #endif
318
319
320 /* functions */
321 S16 SInit ARGS((void));
322 /*ss009.301*/
323 S16 SFini ARGS((void));
324 /* ss034.103 */
325 S16 SDeInit ARGS((void));
326
327 /* implementation-specific functions */
328 S16 ssdInitGen ARGS((void));
329 S16 ssdInitMem ARGS((void));
330 S16 ssdInitTsk ARGS((void));
331 S16 ssdInitDrvr ARGS((void));
332 S16 ssdInitTmr ARGS((void));
333 S16 ssdReInitTmr ARGS((void));
334 /* ss005.301: ssdInitFinal changed to ssdInitLog */
335 S16 ssdInitLog ARGS((void));
336
337 Void ssdDeinitGen ARGS((void));
338 Void ssdDeinitMem ARGS((void));
339 Void ssdDeinitTsk ARGS((void));
340 Void ssdDeinitDrvr ARGS((void));
341 Void ssdDeinitTmr ARGS((void));
342 /* ss005.301: ssdDeinitFinal changed to ssdDeinitLog */
343 Void ssdDeinitLog ARGS((void));
344
345 Void ssdStart ARGS((void));
346
347 S16 ssdAttachTTsk ARGS((SsTTskEntry *));
348 S16 ssdDetachTTsk ARGS((SsTTskEntry *));
349 S16 ssdCreateSTsk ARGS((SsSTskEntry *));
350 S16 ssdDestroySTsk ARGS((SsSTskEntry *));
351 S16 ssdPstTsk ARGS((Pst *, Buffer *, SsTTskEntry *));
352 S16 ssdRegTmr ARGS((SsTmrEntry *));
353 S16 ssdDeregTmr ARGS((SsTmrEntry *));
354 S16 ssdError ARGS((Seq, Reason));
355 Void ssdLogError ARGS((Ent, Inst, ProcId, Txt *, S32, \
356                               ErrCls, ErrCode, ErrVal, Txt *));
357
358 Void mtTmrHdlrPublic ARGS ((void)); 
359
360 /*
361  * SDeRegTTsk patch
362  */
363 /* for TTask Dereg */
364 #ifdef SS_MULTIPLE_PROCS
365 S16 ssdProcTTskTerm ARGS((ProcId proc, SsTTskEntry *tTsk, SsIdx idx));
366 #else
367 S16 ssdProcTTskTerm ARGS((SsTTskEntry *tTsk, SsIdx idx));
368 #endif /* SS_MULTIPLE_PROCS */
369
370 #ifdef SS_DRVR_SUPPORT
371 S16 ssdRegDrvrTsk ARGS((SsDrvrTskEntry *));
372 /*ss001.301: Additions */
373 S16 ssdDeregDrvrTsk ARGS((SsDrvrTskEntry *));
374 #endif
375
376 /* ss029.103: addition: support function to implement multiple procIds */ 
377 #ifdef SS_MULTIPLE_PROCS
378 uint16_t SGetProcIdIdx ARGS((ProcId proc));
379 #endif /* SS_MULTIPLE_PROCS */
380
381 /* multi-core support */
382 /*ss013.301 : changes for SS_AFFINITY_SUPPORT*/
383 #if defined(SS_MULTICORE_SUPPORT) || defined(SS_AFFINITY_SUPPORT)
384  
385 S16 ssdSetAffinity ARGS((SSTskId *tskId, uint32_t coreId));
386 S16 ssdGetAffinity ARGS((SSTskId *tskId, uint32_t *coreId));
387 #endif /* SS_MULTICORE_SUPPORT || SS_AFFINITY_SUPPORT */
388
389 /* ss001.301: additions */
390 #ifdef SS_LOGGER_SUPPORT 
391 S16 ssdInitLogger ARGS((void));
392 S16 SFlushBufToLog ARGS (( S8 *logBuf));
393 /* ss02.301: additions */
394 S16 SCleanUp ARGS ((Void ));
395 Void SStartLogger ARGS ((Void ));
396 Void SStopLogger ARGS ((Void ));
397 #endif /* SS_LOGGER_SUPPORT  */
398 /* ss02.301: additions */
399 #ifdef SS_WATCHDOG 
400 #ifdef SS_MULTIPLE_PROCS
401 S16 ssdWatchDgActvTmr ARGS(( ProcId proc, Ent ent, Inst instVoid));
402 #else
403 S16 ssdWatchDgActvTmr ARGS(( Void ));
404 #endif /* SS_MULTIPLE_PROCS */
405 Void ssdWatchDgTmrEvt ARGS(( PTR cb, S16 event ));
406 S16 watchDgActvTsk ARGS(( Pst *pst, Buffer *mBuf));
407 S16 watchDgRcvrActvTsk ARGS(( Pst *pst, Buffer *mBuf ));
408 S16 ssdSndHrtBtMsg ARGS(( Bool  restart, uint32_t type));
409 Void ssdStartWatchDgTmr ARGS(( void *cb, S16 event, uint16_t wait));
410 Void ssdStopWatchDgTmr ARGS(( void *cb, S16 event));
411 S16 ssdInitWatchDgPst ARGS((Pst *pst));         
412 S16 ssdInitWatchDog ARGS((uint16_t port));
413 #endif
414
415 #ifdef SS_FBSED_TSK_REG
416 S16 SRegTskInfo ARGS((uint8_t *cfgFile));  
417 #endif
418 /* ss002.301 Readwrite lock additions */
419 #ifdef SS_LOCK_SUPPORT
420 S16 ssdLockNew ARGS((SLockInfo *LockId, uint8_t locktype));
421 S16 ssdInitLockNew ARGS((SLockInfo *LockId, uint8_t lockType));
422 S16 ssdUnlockNew ARGS((SLockInfo *LockId, uint8_t lockType));
423 S16 ssdDestroyLockNew ARGS((SLockInfo *LockId, uint8_t lockType));
424 #endif /* SS_LOCK_SUPPORT */
425
426 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
427 /* For Static memory leak detection */
428 #define MAX_MEM_ALLOCATIONS 100000
429
430 typedef struct _listInfo
431 {
432    uint32_t nextIdx;
433 }ListInfo;
434
435 typedef struct _eachAllocInfo
436 {
437    ListInfo listInfo;
438    /* other info should come here */
439    char *file;
440    uint32_t lineNo;
441    uint32_t age;
442    void *ptr;
443    uint32_t size;
444    /* end of other info */
445 }EachAllocInfo;
446
447 typedef struct _staticMemAllocationInfo
448 {
449    uint32_t nextFreeIdx;
450    EachAllocInfo allocations[MAX_MEM_ALLOCATIONS];
451 }StaticMemAllocInfo;
452
453 StaticMemAllocInfo SMemLeakInfo[4];
454 FILE* StaticMemLeakFileArr[4];
455 /* End Static Memory leak detection */
456 #endif
457
458 #ifdef __cplusplus
459 }
460 #endif
461
462 void DumpSSIDemandQDebugInformation ARGS((void));
463 void mtSigSegvHndlr ARGS((void));
464 void mtSigUsr2Hndlr ARGS((void));
465 #endif  /*  __SSGENX__  */
466
467
468 \f
469 /********************************************************************30**
470  
471          End of file
472 **********************************************************************/