Added code for MAC-PHY interface, DU_APP, F1AP, SCTP and CU stub
[o-du/l2.git] / src / mt / ss_gen.c
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 \f
19 /********************************************************************20**
20  
21      Name:     System Services -- general functions
22  
23      Type:     C source file
24  
25      Desc:     Source code for System Services startup and general
26                System Services.
27  
28      File:     ss_gen.c
29  
30 *********************************************************************21*/
31
32 \f
33 /* header include files (.h) */
34
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include "envopt.h"        /* environment options */
38 #include "envdep.h"        /* environment dependent */
39 #include "envind.h"        /* environment independent */
40   
41 #include "gen.h"           /* general layer */
42 #include "ssi.h"           /* system services */
43
44 #include "ss_err.h"        /* errors */
45 #include "ss_dep.h"        /* implementation-specific */
46 #include "ss_queue.h"      /* queues */
47 #include "ss_task.h"       /* tasking */
48 #include "ss_msg.h"        /* messaging */
49 #include "ss_mem.h"        /* memory management interface */
50 #include "ss_gen.h"        /* general */
51 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
52 #ifdef SS_FBSED_TSK_REG
53 #include "cm_task.h"
54 #endif /* SS_FBSED_TSK_REG */
55 #include "cm_llist.h"
56 #include "cm_hash.h"
57 /* ss001.301: additions */
58 #include "cm_mem.h"        /* memory management */
59
60 /* header/extern include files (.x) */
61
62 #include "gen.x"           /* general layer */
63 #include "ssi.x"           /* system services */
64
65 #include "ss_dep.x"        /* implementation-specific */
66 #include "ss_queue.x"      /* queues */
67 #include "ss_task.x"       /* tasking */
68 #include "ss_timer.x"      /* timers */
69 #include "ss_strm.x"       /* STREAMS */
70 #include "ss_msg.x"        /* messaging */
71 #include "ss_mem.x"        /* memory management interface */
72 #include "ss_drvr.x"       /* driver tasks */
73 #ifdef SS_LOCKLESS_MEMORY
74 #include "cm_llist.x"
75 #include "cm_hash.x"
76 #include "cm_mem_wl.x"        /* common memory manager */
77 #else
78 #include "cm_mem.x"        /* common memory manager */
79 #endif /* SS_LOCKLESS_MEMORY */
80 #include "ss_gen.x"        /* general */
81 /* ss001.301: additions */
82 #ifdef SS_LOGGER_SUPPORT 
83 #include "cm_lib.x"
84 #endif /* SS_LOGGER_SUPPORT  */
85 #ifdef SS_MULTICORE_SUPPORT
86 #include "cm_llist.x"
87 #include "cm_hash.x"
88 #include "cm_mem.h"
89 #include "cm_mem_wl.x"
90 #include "cm_lib.x"
91 #endif
92
93 /* Cavium Changes:ss004.301 */
94 #ifdef SS_SEUM_CAVIUM
95 #include "cvmx-config.h"
96 #include "cvmx.h"
97 #endif /* SS_SEUM_CAVIUM */
98
99 /*ss011.301 : RMIOS release related changes*/
100 #ifdef SS_RMIOS
101 #include "mt_msgr.x"
102 #endif
103 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
104 #ifdef SS_FBSED_TSK_REG
105 #include "cm_task.x"
106 #endif /* SS_FBSED_TSK_REG */
107 #include <signal.h>
108 \f
109 /* public variable declarations */
110
111 /*ss014.301: SSI-4GMX related changes*/
112 #ifdef SS_4GMX_LCORE
113 PUBLIC VOLATILE SsOs     osCp;           /* common OS control point */
114 #else
115 PUBLIC SsOs     osCp;           /* common OS control point */
116 #endif
117
118  
119 EXTERN Cntr     cfgNumRegs;
120 EXTERN SsRegCfg cfgRegInfo[SS_MAX_REGS];
121
122 \f
123 /* ss029.103: modification: multiple procId related changes */ 
124 #ifdef SS_MULTIPLE_PROCS
125 /* PRIVATE functions */
126 PRIVATE S16 SInsProcId ARGS((ProcId proc));
127 PRIVATE S16 SRemProcId ARGS((ProcId proc));
128 PRIVATE S16 SLockOsCp  ARGS((Void));
129 PRIVATE S16 SULockOsCp ARGS((Void));
130 #endif /* SS_MULTIPLE_PROCS */
131
132 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
133 PRIVATE void InitializeForStaticMemLeak ARGS((void));
134 PRIVATE void InitializeStaticMemAllocInfo ARGS((StaticMemAllocInfo* memAllocInfo));
135 PUBLIC U32 GetNextFreeIdx ARGS((StaticMemAllocInfo * memAllocInfo));
136 PUBLIC void FreeIdx ARGS((U8* ptr, U32 idx, StaticMemAllocInfo* memAllocInfo,U32 size, char*
137       file, U32 line));
138 PUBLIC void LogForStaticMemLeak ARGS((StaticMemAllocInfo* memAllocInfo, char* file,
139       U32 line, U32 size, void* ptr, U32 idx));
140 PRIVATE void PrintStaticMemAllocInfo ARGS((StaticMemAllocInfo* memAllocInfo, FILE
141       *opFile));
142 #endif
143 /* ss001.301: additions */
144
145 PUBLIC void DumpSSIDemandQDebugInformation()
146 {
147    U32 i,j;
148    RTLIN_DUMP_DEBUG("Demand Q Information\n");
149    RTLIN_DUMP_DEBUG("====================\n");
150    for(i = 0; i < osCp.numSTsks; i++)
151    {
152       SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
153       
154       for(j = 0; j < SS_MAX_NUM_DQ; j++)
155       {
156 #ifndef ALIGN_64BIT
157          RTLIN_DUMP_DEBUG("Task[%lu] Q[%lu] QSize = %lu region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
158 #else
159          RTLIN_DUMP_DEBUG("Task[%u] Q[%u] QSize = %u region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
160 #endif
161       }
162    }
163 }
164
165 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
166 pthread_mutex_t dumpingLock = PTHREAD_MUTEX_INITIALIZER;
167
168 PUBLIC Void mtSigSegvHndlr()
169 {
170    int i;
171
172    printf("Backtrace for thread Id (%lu) total threads = %d\n", (unsigned long) pthread_self(), osCp.numSTsks);   
173    ysPrntBkTrace();
174    for(i = 0; i < osCp.numSTsks; i++)
175    {
176       SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
177       if((tskEntry->dep.tId != pthread_self()) && (tskEntry->dep.tId != 0))
178       {
179           pthread_kill(tskEntry->dep.tId, SIGUSR2);
180       }
181    }
182
183    sleep(5);
184 }
185
186 PUBLIC Void mtSigUsr2Hndlr()
187 {
188    printf("Backtrace for thread Id (%lu) cause:SIGUSR2(%d)\n",(unsigned long) pthread_self(),SIGUSR2);   
189
190    pthread_mutex_lock(&dumpingLock);  
191    ysPrntBkTrace();
192    pthread_mutex_unlock(&dumpingLock);  
193
194    sleep(5);
195    
196    exit(0);
197 }
198
199 #endif
200
201 \f
202 /*
203 *
204 *       Fun:   System Services initialization function
205 *
206 *       Desc:  This is the general initialization function for
207 *              all System Services implementations. It initializes
208 *              all the common global data structures and calls the
209 *              implementation-specific initialization and start
210 *              functions.
211 *
212 *       Ret:   Void
213 *
214 *       Notes: 
215 *
216 *       File:  ss_gen.c
217 *
218 */
219 #ifdef ANSI
220 PUBLIC S16 SInit
221 (
222 void
223 )
224 #else
225 PUBLIC S16 SInit()
226 #endif
227 {
228    S16 ret;
229    REG1 S16 i;
230    REG2 S16 j;
231    REG3 S16 k;
232    SsTTskEntry *tTsk;
233    SsSTskEntry *sTsk;
234    SsTmrEntry *tmr;
235    SsRegionEntry *reg;
236    /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
237    Txt prntBufLoc[1000];
238 #ifdef SS_DRVR_SUPPORT
239    SsDrvrTskEntry *drvrTsk;
240 #endif
241 /* ss002.301 : Modications */
242    TRC1(SInit);
243
244    osCp.configFilePath = "/mnt/tmp/configFile";
245
246    /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
247  
248    /* ss019.103 - Modified for correct initialization of OS control point */
249    /* start initializing OS control point */
250 /* ss029.103: modification: multiple procId related changes */ 
251 #ifndef SS_MULTIPLE_PROCS
252 /* ss004.301: Cavium changes */
253 #ifdef SS_SEUM_CAVIUM
254                   osCp.procId = cvmx_get_core_num();
255 #else
256                   osCp.procId = SS_PROC_ID;
257 #endif /* SS_SEUM_CAVIUM */
258 #else /* SS_MULTIPLE_PROCS */
259    for (i = 0; i < SS_MAX_PROCS; i++)
260       osCp.procLst.procId[i] = PROCNC;
261
262    osCp.procLst.free = SS_MAX_PROCS;
263 #endif /* SS_MULTIPLE_PROCS */
264
265 #ifdef SS_THR_REG_MAP
266    cmMemset(osCp.threadMemoryRegionMap, SS_INVALID_THREAD_REG_MAP, 
267             (sizeof(Region) * SS_MAX_THREAD_REGION_MAP));
268    ssRegMainThread();
269 #endif
270
271    /* implementation specific general initialization */
272    ret = ssdInitGen();
273    if (ret != ROK)
274         {
275    /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
276           sprintf(prntBufLoc,"\n SInit(): ssdInitGen failed to initialize\
277                                                                 implementation specific general information \n");
278       SDisplay(1,prntBufLoc);
279       RETVALUE(RFAILED);
280         }
281  
282 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
283    InitializeForStaticMemLeak();
284 #endif
285    /* initialize memory information */
286    osCp.numRegions = 0;
287
288    for (i = 0;  i < SS_MAX_REGS;  i++)
289    {
290       reg = &osCp.regionTbl[i];
291
292       reg->used = FALSE;
293
294       reg->start = NULLP;
295       reg->size = 0;
296       reg->regCb = NULLP;
297       reg->flags = 0;
298       reg->alloc = NULLP;
299       reg->free = NULLP;
300       reg->ctl = NULLP;
301       /* ss007.301 initializing the per region mBufRefLock */
302       SInitLock(&reg->mBufRefLock, SS_LOCK_MUTEX);
303
304       /* zero the pool information */
305       reg->numPools = 0;
306       for (j = 0;  j < SS_MAX_POOLS_PER_REG;  j++)
307          reg->poolTbl[j].type = SS_POOL_UND;
308
309       /* find this region ID in the region configuration structure */
310       for (j = 0;  j < cfgNumRegs;  j++)
311          if (cfgRegInfo[j].region == i)
312             break;
313
314       /* this region is not configured */
315       if (j == cfgNumRegs)
316          continue;
317
318       /* Load the configuration information into the region table.
319        *  Note, the region still has to be registered, for it to
320        *  be usable.
321        */
322       for (k = 0;  k < cfgRegInfo[j].numPools;  k++)
323       {
324          reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
325          if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
326             reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
327       }
328    }
329
330    /* Initialization of dynamic regions */
331    for (i = 0;  i < SS_MAX_REGS;  i++)
332    {
333       reg = &osCp.dynRegionTbl[i];
334
335       reg->used = FALSE;
336
337       reg->start = NULLP;
338       reg->size = 0;
339       reg->regCb = NULLP;
340       reg->flags = 0;
341       reg->alloc = NULLP;
342       reg->free = NULLP;
343       reg->ctl = NULLP;
344       /* ss007.301 initializing the per region mBufRefLock */
345       SInitLock(&reg->mBufRefLock, SS_LOCK_MUTEX);
346
347       /* zero the pool information */
348       reg->numPools = 0;
349       for (j = 0;  j < SS_MAX_POOLS_PER_REG;  j++)
350          reg->poolTbl[j].type = SS_POOL_UND;
351
352       /* find this region ID in the region configuration structure */
353       for (j = 0;  j < cfgNumRegs;  j++)
354          if (cfgRegInfo[j].region == i)
355             break;
356
357       /* this region is not configured */
358       if (j == cfgNumRegs)
359          continue;
360
361       /* Load the configuration information into the region table.
362        *  Note, the region still has to be registered, for it to
363        *  be usable.
364        */
365       for (k = 0;  k < cfgRegInfo[j].numPools;  k++)
366       {
367          reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
368          if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
369             reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
370       }
371    }
372
373    ret = ssInitSema(&osCp.regionTblSem, SS_MAX_STSKS);
374    if (ret != ROK)
375         {
376     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
377           sprintf(prntBufLoc,"\n SInit(): Could not initialize the region Table Semaphore \n");
378       SDisplay(1,prntBufLoc);
379           goto cleanup0;
380         }
381
382    /* implementation specific memory initialization */
383    ret = ssdInitMem();
384    if (ret != ROK)
385         {
386     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
387           sprintf(prntBufLoc,"\n SInit(): Memory initialization failed \n");
388       SDisplay(1,prntBufLoc);
389           goto cleanup1;
390         }
391
392
393    /* initialize TAPA and system task information */
394 /* ss029.103: modification: multiple procId related changes */ 
395 #ifndef SS_MULTIPLE_PROCS
396    for (i = 0;  i < SS_MAX_ENT;  i++)
397       for (j = 0;  j < SS_MAX_INST;  j++)
398          osCp.tTskIds[i][j] = SS_TSKNC;
399 #else /* SS_MULTIPLE_PROCS */
400    for (i = 0;  i < SS_MAX_PROCS;  i++)
401       for (j = 0;  j < SS_MAX_ENT;  j++)
402          for (k = 0;  k < SS_MAX_INST;  k++)
403             osCp.tTskIds[i][j][k] = SS_TSKNC;
404 #endif /* SS_MULTIPLE_PROCS */
405
406    for (i = 0;  i < SS_MAX_TTSKS;  i++)
407    {
408       tTsk = &osCp.tTskTbl[i];
409
410       tTsk->used = FALSE;
411       tTsk->ent = ENTNC;
412       tTsk->inst = INSTNC;
413       tTsk->tskType = TTUND;
414       tTsk->tskPrior = 0;
415       tTsk->initTsk = NULLP;
416       tTsk->actvTsk = NULLP;
417       tTsk->sTsk = NULLP;
418 /* ss029.103: addition: TAPA task control block added */
419 #ifdef SS_MULTIPLE_PROCS
420       tTsk->xxCb = NULLP;
421 #endif /* SS_MULTIPLE_PROCS */
422
423       tTsk->nxt = i + 1;
424    }
425
426    osCp.numTTsks = 0;
427    osCp.nxtTTskEntry = 0;
428
429    ret = ssInitSema(&osCp.tTskTblSem, SS_MAX_STSKS);
430    if (ret != ROK)
431         {
432     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
433           sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
434       SDisplay(1,prntBufLoc);
435           goto cleanup2;
436         }
437
438 #ifdef SS_MULTICORE_SUPPORT
439   /* check whether number of system tasks is
440    * equal to number of (regions-1).
441    * The last region is meant for timer task
442    * which under the current feature has as entry
443    * in system task table.
444    */
445   if(SS_MAX_STSKS > SS_MAX_REGS)
446   {
447     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
448       goto cleanup3;
449   }
450 #endif
451
452    /* initialize system task information */
453    for (i = 0;  i < SS_MAX_STSKS;  i++)
454    {
455       sTsk = &osCp.sTskTbl[i];
456
457       sTsk->used = FALSE;
458       sTsk->termPend = FALSE;
459       sTsk->tskPrior = 0;
460       for (j = 0;  j < SS_MAX_TTSKS;  j++)
461          sTsk->tTsks[j] = SS_INVALID_IDX;
462       sTsk->numTTsks = 0;
463
464       sTsk->nxt = i + 1;
465 /* ss002.301 : Modifications */
466 #ifdef SS_MULTICORE_SUPPORT
467       if(i == 0)
468       {
469          sTsk->region = (SS_MAX_REGS - 1);
470       }
471       else
472       {
473          sTsk->region = i-1;
474       }
475 #endif
476    }
477
478    osCp.numSTsks = 0;
479    osCp.nxtSTskEntry = 0;
480
481    ret = SInitLock(&osCp.sTskTblLock, SS_STSKTBL_LOCK);
482    if (ret != ROK)
483    {
484     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
485           sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
486       SDisplay(1,prntBufLoc);
487       goto cleanup3;
488    }
489
490         /* ss028.103 - Addition of lock for mBuf reference count */
491         /* ss007.301 moving the mBufRefLock from common to per region */
492         /* SInitLock(&osCp.mBufRefLock, SS_LOCK_MUTEX);*/
493
494    /* implementation specific task initialization */
495    ret = ssdInitTsk();
496    if (ret != ROK)
497    {
498     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
499           sprintf(prntBufLoc,"\n SInit(): implementation specific task initialization Failed \n");
500       SDisplay(1,prntBufLoc);
501       goto cleanup4;
502    }
503
504 #ifdef SS_DRVR_SUPPORT
505    /* initialize driver task information */
506    for (i = 0;  i < SS_MAX_DRVRTSKS;  i++)
507    {
508       drvrTsk = &osCp.drvrTskTbl[i];
509
510       drvrTsk->used = FALSE;
511
512       drvrTsk->channel = 0;
513       drvrTsk->actvTsk = NULLP;
514       drvrTsk->isTsk = NULLP;
515       drvrTsk->low = 0;
516       drvrTsk->high = 0;
517    }
518
519    osCp.numDrvrTsks = 0;
520
521    /* implementation specific driver initialization */
522    ret = ssdInitDrvr();
523    if (ret != ROK)
524         {
525     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
526           sprintf(prntBufLoc,"\n SInit(): ssdInitDrvr failed \n");
527       SDisplay(1,prntBufLoc);
528           goto cleanup5;
529         }
530 #endif
531
532         /*ss004.301: Cavium Changes */
533 #ifdef SS_SEUM_CAVIUM
534         ret = ssInitRcvWork();
535         if (ret != ROK)
536         {
537     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
538           goto cleanup6;
539         }
540 #endif /* SS_SEUM_CAVIUM */
541
542
543    /* initialize the demand queue lookup table */
544    osCp.dmndQLookupTbl[0] = 255;
545    osCp.dmndQLookupTbl[1] = 0;
546    osCp.dmndQLookupTbl[2] = 1;
547    osCp.dmndQLookupTbl[3] = 1;
548    for (i = 4;  i < 256;  i++)
549    {
550       if (i >= 128  &&  i <= 255)
551          osCp.dmndQLookupTbl[i] = 7;
552       if (i >= 64  &&  i <= 127)
553          osCp.dmndQLookupTbl[i] = 6;
554       if (i >= 32  &&  i <= 63)
555          osCp.dmndQLookupTbl[i] = 5;
556       if (i >= 16  &&  i <= 31)
557          osCp.dmndQLookupTbl[i] = 4;
558       if (i >= 8  &&  i <= 15)
559          osCp.dmndQLookupTbl[i] = 3;
560       if (i >= 4  &&  i <= 7)
561          osCp.dmndQLookupTbl[i] = 2;
562    }
563
564
565    /* initialize timer information */
566    for (i = 0;  i < SS_MAX_TMRS;  i++)
567    {
568       tmr = &osCp.tmrTbl[i];
569
570       tmr->used = FALSE;
571       tmr->tmrId = 0;
572       tmr->ownerEnt = ENTNC;
573       tmr->ownerInst = INSTNC;
574       tmr->interval = 0;
575       /*
576        *  ss015.301 - Modifed in initialization as timer activation 
577        *  functions enclosed in a union. Also initialized the mtFlag
578        *  to FALSE 
579        */
580       tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
581 #ifndef SS_MULTIPLE_PROCS
582 #ifdef SS_MT_TMR
583       tmr->ssTmrActvFn.mtFlag = FALSE; 
584       tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
585 #endif
586 #endif
587       tmr->nxt = i + 1;
588    }
589
590    osCp.numTmrs = 0;
591    osCp.nxtTmrEntry = 0;
592
593    ret = SInitLock(&osCp.tmrTblLock, SS_TMRTBL_LOCK);
594    if (ret != ROK)
595    {
596     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
597        goto cleanup6;
598    }
599
600    /* implementation specific timer initialization */
601    ret = ssdInitTmr();
602    if (ret != ROK)
603    {
604        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
605        sprintf(prntBufLoc,"\n SInit(): Could not initialize the timer \n");
606        SDisplay(1,prntBufLoc);
607        goto cleanup7;
608    }
609
610    /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
611    /* ss005.201: Initialize logging streams */
612    /* implementation specific logging initialization */
613    ret = ssdInitLog();
614    if (ret != ROK)
615    {
616        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
617        sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logging streams \n");
618        SDisplay(1,prntBufLoc);
619        goto cleanup8;
620    }
621
622 #ifdef SS_LOGGER_SUPPORT /* ss001.301: additions */
623    /* Initialize the lock, return on failure */
624    if( SInitLock(&(osCp.logger.bufLock),SS_LOCK_MUTEX) != ROK)
625    {
626        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
627        sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logger Buffer Lock  \n");
628        SDisplay(1,prntBufLoc);
629        goto cleanup9;
630    } /* if */
631    
632    /* Initialize the logger configuration flag */
633    osCp.logger.configured = FALSE;
634    /* Ss002.301 : Initialised */
635    osCp.logger.started = FALSE;
636 #endif /* SS_LOGGER_SUPPORT */
637 /* ss001.301: additions */
638
639 #ifdef SS_HISTOGRAM_SUPPORT
640    /* Here we are filling all the tapa entity Ids, which will be
641     * helpful to get the entity Id using file name. */
642    ret = SFillEntIds();
643 #endif /* SS_HISTOGRAM_SUPPORT */
644
645
646 #ifdef SS_FBSED_TSK_REG
647    /* Configure task registration based on the configuration */
648    /*ss013.301 : Fixed warnings for 32/64 bit compilation*/
649    cmCfgrTskReg((U8 *)"task_info.t");
650 #endif /* SS_FBSED_TSK_REG  */
651
652 /*ss011.301 : RMIOS release related changes*/
653 #ifdef SS_RMIOS
654    spInit();
655 #endif
656
657    /* call tst() function */
658    ret = tst();
659    if (ret != ROK)
660    {
661        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
662       goto cleanup10;
663    }
664
665
666    /* call implementation-specific starter function */
667    ssdStart();
668
669
670    RETVALUE(ROK);
671
672
673 /* clean up code */
674 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
675 cleanup10:
676 #ifdef SS_LOGGER_SUPPORT 
677    /* ss005.301: Deinitialize the logging at the end */
678    SDestroyLock(&(osCp.logger.bufLock));
679    /*ss013.301 : Fix for compile time warning*/
680 cleanup9:
681 #endif /* SS_LOGGER_SUPPORT */
682    ssdDeinitLog();
683 cleanup8:
684    ssdDeinitTmr();
685 cleanup7:
686    SDestroyLock(&osCp.tmrTblLock);
687
688 cleanup6:
689 #ifdef SS_DRVR_SUPPORT
690    ssdDeinitDrvr();
691 cleanup5:
692 #endif
693    ssdDeinitTsk();
694 cleanup4:
695    SDestroyLock(&osCp.sTskTblLock);
696 cleanup3:
697    if ( (ssDestroySema(&osCp.tTskTblSem)) != ROK)
698       {
699 #if (ERRCLASS & ERRCLS_DEBUG)
700          SSLOGERROR(ERRCLS_DEBUG, ESS012, ERRZERO,
701                          "Could not destroy the Semaphore");
702         /* ss005.301: Changes, clean the threads and exit */
703 #endif
704       }
705
706 cleanup2:
707    ssdDeinitMem();
708 cleanup1:
709         /* ss007.301 destroying the per region mBufRefLock */
710         for (i= 0;i<SS_MAX_REGS;i++)
711         {
712           SDestroyLock(&osCp.regionTbl[i].mBufRefLock);
713         }
714    /* ss006.13: addition */
715    if ( (ssDestroySema(&osCp.regionTblSem)) != ROK)
716    {
717 #if (ERRCLASS & ERRCLS_DEBUG)
718          SSLOGERROR(ERRCLS_DEBUG, ESS013, ERRZERO,
719                "Could not destroy the Semaphore");
720        /* ss005.301: Changes, clean the threads and exit */
721 #endif
722    }
723 cleanup0:
724    ssdDeinitGen();
725
726
727    RETVALUE(RFAILED);
728 }
729
730 \f
731 /* ss033.103: Added SDeInit API to free all the resources */
732 /*
733 *
734 *       Fun:   System Services de-initialization function
735 *
736 *       Desc:  This is the de-initialization function for System 
737 *              Services implementations. It releases all the common
738 *              global data structures.
739 *
740 *       Ret:   Void
741 *
742 *       Notes: 
743 *
744 *       File:  ss_gen.c
745 *
746 */
747 #ifdef ANSI
748 PUBLIC S16 SDeInit
749 (
750 void
751 )
752 #else
753 PUBLIC S16 SDeInit()
754 #endif
755 {
756   /* ss007.301 */
757   U16    regCnt;
758
759    TRC1(SDeInit);
760
761
762    ssdDeinitTmr();
763    SDestroyLock(&osCp.tmrTblLock);
764
765 #ifdef SS_DRVR_SUPPORT
766    ssdDeinitDrvr();
767 #endif
768
769    ssdDeinitTsk();
770    SDestroyLock(&osCp.sTskTblLock);
771
772    if ((ssDestroySema(&osCp.tTskTblSem)) != ROK)
773    {
774 #if (ERRCLASS & ERRCLS_DEBUG)
775     SSLOGERROR(ERRCLS_DEBUG, ESS014, ERRZERO,
776                       "Could not destroy the Semaphore");
777     RETVALUE(RFAILED);
778
779 #endif
780    }
781
782    ssdDeinitMem();
783
784    if ((ssDestroySema(&osCp.regionTblSem)) != ROK)
785    {
786 #if (ERRCLASS & ERRCLS_DEBUG)
787       SSLOGERROR(ERRCLS_DEBUG, ESS015, ERRZERO,
788                       "Could not destroy the Semaphore");
789       RETVALUE(RFAILED);
790
791 #endif
792    }
793
794         ssdDeinitGen();
795         /* ss007.301 destroying the per region mBufRefLock */
796         for (regCnt = 0;  regCnt < SS_MAX_REGS;  regCnt++)
797         {
798           SDestroyLock(&osCp.regionTbl[regCnt].mBufRefLock);
799         }
800
801         /* ss005.301: Deinitialize the logging at the end */
802 #ifdef SS_LOGGER_SUPPORT 
803    SDestroyLock(&(osCp.logger.bufLock));
804 #endif /* SS_LOGGER_SUPPORT */
805    ssdDeinitLog();
806    RETVALUE(ROK);
807
808 }
809 /* ss001.301: additions */
810 #ifdef SS_LOGGER_SUPPORT 
811 #ifdef ANSI
812 PUBLIC S16 SWrtLogBuf
813 (
814 Txt *buf                        /* buffer */
815 )
816 #else
817 PUBLIC S16 SWrtLogBuf(buf)
818 Txt *buf;                       /* buffer */
819 #endif
820 {
821    S16 bufSz;
822    TRC1(SWrtLogBuf);
823    /* buffer synchronisation*/
824    bufSz = cmStrlen((U8 *)buf);
825    SLock(&osCp.logger.bufLock);
826    if(osCp.logger.started == FALSE)
827    {
828       (Void)SUnlock(&(osCp.logger.bufLock));
829       RETVALUE(ROK);
830    }
831    /*
832     * Append the buffer to the global buffer
833     * and increment the current buffer size of the global buffer
834     */
835    if(((osCp.logger.curBufSiz) + bufSz) >= osCp.logger.maxBufSiz)
836    {
837       SFlushBufToLog(osCp.logger.buffer);
838       osCp.logger.curBufSiz = 0;
839       cmMemset((U8 *)osCp.logger.buffer, '\0', osCp.logger.maxBufSiz);
840       sprintf(osCp.logger.buffer, "%s", buf);
841       osCp.logger.curBufSiz += bufSz;
842    }
843    else
844    {
845       strcat(osCp.logger.buffer,buf);
846       osCp.logger.curBufSiz += bufSz;
847    }
848    (Void)SUnlock(&(osCp.logger.bufLock));
849    RETVALUE(ROK);
850 }
851 #endif /* SS_LOGGER_SUPPORT  */
852 /*
853 *
854 *       Fun:   SPrint
855 *
856 *       Desc:  Print a string.
857 *
858 *              This function should be used for debugging only.
859 *
860 *       Ret:   ROK      - ok
861 *
862 *       Notes: Text buffer should be null terminated.
863 *
864 *              SDisplay will replace SPrint.
865 *
866 *              Typical usage consists of a call to sprintf to
867 *              format the string into a buffer followed by a
868 *              call to SPrint
869 *
870 *       File:  ss_gen.c
871 *
872 */
873 #ifdef ANSI
874 PUBLIC S16 SPrint
875 (
876 Txt *buf                        /* buffer */
877 )
878 #else
879 PUBLIC S16 SPrint(buf)
880 Txt *buf;                       /* buffer */
881 #endif
882 {
883    TRC1(SPrint);
884
885 /* ss001.301: additions */
886    SDisplay(0, buf);
887 #ifdef SS_LOGGER_SUPPORT 
888    SWrtLogBuf(buf);
889 #endif /* SS_LOGGER_SUPPORT  */
890
891    RETVALUE(ROK);
892
893 } /* end of SPrint */
894
895 \f
896 /*
897 *
898 *       Fun:   SError
899 *
900 *       Desc:  Invoked by layer when an unrecoverable
901 *              software error is detected. This function should
902 *              never return.
903 *
904 *       Ret:   None
905 *
906 *       Notes: None
907 *
908 *       File:  ss_gen.c
909 *
910 */
911 #ifdef ANSI
912 PUBLIC S16 SError
913 (
914 Seq seq,                    /* sequence */
915 Reason reason               /* reason */
916 )
917 #else
918 PUBLIC S16 SError(seq, reason)
919 Seq seq;                    /* sequence */
920 Reason reason;              /* reason */
921 #endif
922 {
923    S16 ret;
924    DateTime dt;
925    Txt errBuf[256];
926
927
928    TRC1(SError);
929
930
931    SGetDateTime(&dt);
932    sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
933           (int)dt.month,(int)dt.day,(int)dt.year + 1900,
934           (int)dt.hour,(int)dt.min,(int)dt.sec);
935    SPrint(errBuf);
936
937
938    ret = ssdError(seq, reason);
939
940
941    RETVALUE(ret);
942 }
943
944 \f
945 /*
946 *
947 *       Fun:   SLogError
948 *
949 *       Desc:  Invoked by layer to log an error.
950 *
951 *       Ret:   None
952 *
953 *       Notes: None
954 *
955 *       File:  ss_gen.c
956 *
957 */
958 #ifdef ANSI
959 PUBLIC Void SLogError
960 (
961 Ent ent,                    /* Calling layer's entity id */
962 Inst inst,                  /* Calling layer's instance id */
963 ProcId procId,              /* Calling layer's processor id */
964 Txt *file,                  /* file name where error occured */
965 S32 line,                   /* line in file where error occured */
966 ErrCls errCls,              /* error class */
967 ErrCode errCode,            /* layer unique error code */
968 ErrVal errVal,              /* error value */
969 Txt *errDesc                /* description of error */
970 )
971 #else
972 PUBLIC Void SLogError(ent, inst, procId, file, line,
973                         errCls, errCode, errVal, errDesc)
974 Ent ent;                    /* Calling layer's entity id */
975 Inst inst;                  /* Calling layer's instance id */
976 ProcId procId;              /* Calling layer's processor id */
977 Txt *file;                  /* file name where error occured */
978 S32 line;                   /* line in file where error occured */
979 ErrCls errCls;              /* error class */
980 ErrCode errCode;            /* layer unique error code */
981 ErrVal errVal;              /* error value */
982 Txt *errDesc;               /* description of error */
983 #endif
984 {
985    DateTime dt;
986    Txt errBuf[512];
987
988
989    TRC1(SLogError);
990
991 /*ss014.301: SSI-4GMX related changes*/
992 #ifndef SS_4GMX_LCORE
993    SGetDateTime(&dt);
994    sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
995           (int)dt.month,(int)dt.day,(int)dt.year + 1900,
996           (int)dt.hour,(int)dt.min,(int)dt.sec);
997    SDisplay(0,errBuf);
998 #endif
999
1000 /* ss001.301: additions */
1001 #ifdef SS_LOGGER_SUPPORT 
1002    SWrtLogBuf(errBuf);
1003 #endif /* SS_LOGGER_SUPPORT  */
1004
1005    ssdLogError(ent, inst, procId, file, line,
1006                      errCls, errCode, errVal, errDesc);
1007
1008
1009    RETVOID;
1010 }
1011
1012 /* ss029.103: modification: 
1013    SFndProcId function is not supported with multiple procIds */ 
1014 #ifndef SS_MULTIPLE_PROCS
1015 \f
1016 /*
1017 *
1018 *       Fun:   SFndProcId
1019 *
1020 *       Desc:  This function finds the local processor ID.
1021 *
1022 *       Ret:   local processor id
1023 *
1024 *       Notes:
1025 *
1026 *       File:  ss_gen.c
1027 *
1028 */
1029 #ifdef ANSI
1030 PUBLIC ProcId SFndProcId
1031 (
1032 void
1033 )
1034 #else
1035 PUBLIC ProcId SFndProcId()
1036 #endif
1037 {
1038    TRC1(SFndProcId);
1039
1040    RETVALUE(osCp.procId);
1041 } /* end of SFndProcId */
1042
1043 \f
1044 /*
1045 *
1046 *       Fun:   SSetProcId
1047 *
1048 *       Desc:  This function stores the local processor ID.
1049 *
1050 *       Ret:   Void
1051 *
1052 *       Notes: 
1053 *
1054 *       File:  ss_gen.c
1055 *
1056 */
1057 #ifdef ANSI
1058 PUBLIC Void SSetProcId
1059 (
1060 ProcId procId
1061 )
1062 #else
1063 PUBLIC Void SSetProcId(procId)
1064 ProcId procId;
1065 #endif
1066 {
1067    TRC1(SSetProcId);
1068
1069    osCp.procId = procId;
1070
1071    RETVOID;
1072 }
1073
1074 #endif /* SS_MULTIPLE_PROCS */
1075
1076 /* ss029.103: addition: New SSI functions with multiple proc support */ 
1077 #ifdef SS_MULTIPLE_PROCS
1078 \f
1079 /*
1080 *
1081 *       Fun:   SGetProcIdIdx
1082 *
1083 *       Desc:  This function finds index of procId in the process id table 
1084 *
1085 *       Ret:   ROK/RFAILED 
1086 *
1087 *       Notes: 
1088 *
1089 *       File:  ss_gen.c
1090 *
1091 */
1092 #ifdef ANSI
1093 PUBLIC U16 SGetProcIdIdx
1094 (
1095 ProcId proc
1096 )
1097 #else
1098 PUBLIC U16 SGetProcIdIdx(proc)
1099 ProcId proc; 
1100 #endif
1101 {
1102    U16 i;
1103    U16 idx;
1104
1105    TRC1(SGetProcIdIdx);
1106
1107    idx = SS_HASH_IDX(proc);
1108
1109    for (i = idx; i < SS_MAX_PROCS; i++)
1110       if (osCp.procLst.procId[i] == proc)
1111          return i;
1112
1113    /* search upto idx */
1114    for (i = 0; i < idx; i++)
1115       if (osCp.procLst.procId[i] == proc)
1116          return i;
1117
1118    RETVALUE(SS_INV_PROCID_IDX);
1119 } /* SGetProcIdIdx */
1120
1121 \f
1122 /*
1123 *
1124 *       Fun:   SInsProcId
1125 *
1126 *       Desc:  This function inserts procId in the process id table 
1127 *
1128 *       Ret:   ROK/RFAILED 
1129 *
1130 *       Notes: 
1131 *
1132 *       File:  ss_gen.c
1133 *
1134 */
1135 #ifdef ANSI
1136 PRIVATE S16 SInsProcId
1137 (
1138 ProcId proc
1139 )
1140 #else
1141 PRIVATE S16 SInsProcId(proc)
1142 ProcId proc; 
1143 #endif
1144 {
1145    U16 i;
1146    U16 idx;
1147
1148    TRC1(SInsProcId);
1149
1150    idx = SS_HASH_IDX(proc);
1151
1152    for (i = idx; i < SS_MAX_PROCS; i++)
1153       if (osCp.procLst.procId[i] == SS_INV_PROCID)
1154       {
1155          osCp.procLst.procId[i] = proc;
1156          osCp.procLst.free--;
1157          RETVALUE(ROK);
1158       }
1159
1160    /* search for free entry upto idx */
1161    for (i = 0; i < idx; i++)
1162       if (osCp.procLst.procId[i] == SS_INV_PROCID)
1163       {
1164          osCp.procLst.procId[i] = proc;
1165          osCp.procLst.free--;
1166          RETVALUE(ROK);
1167       }
1168
1169    RETVALUE(RFAILED);
1170 } /* SInsProcId */
1171
1172 \f
1173 /*
1174 *
1175 *       Fun:   SRemProcId
1176 *
1177 *       Desc:  This function inserts procId in the process id table 
1178 *
1179 *       Ret:   ROK/RFAILED 
1180 *
1181 *       Notes: 
1182 *
1183 *       File:  ss_gen.c
1184 *
1185 */
1186 #ifdef ANSI
1187 PRIVATE S16 SRemProcId
1188 (
1189 ProcId proc
1190 )
1191 #else
1192 PRIVATE S16 SRemProcId(proc)
1193 ProcId proc; 
1194 #endif
1195 {
1196    U16 i;
1197    U16 idx;
1198
1199    TRC1(SRemProcId);
1200
1201    idx = SS_HASH_IDX(proc);
1202
1203    for (i = idx; i < SS_MAX_PROCS; i++)
1204       if (osCp.procLst.procId[i] == proc)
1205       {
1206          osCp.procLst.procId[i] = SS_INV_PROCID;
1207          osCp.procLst.free++;
1208          RETVALUE(ROK);
1209       }
1210
1211    /* search upto idx */
1212    for (i = 0; i < idx; i++)
1213       if (osCp.procLst.procId[i] == proc)
1214       {
1215          osCp.procLst.procId[i] = SS_INV_PROCID;
1216          osCp.procLst.free++;
1217          RETVALUE(ROK);
1218       }
1219
1220    RETVALUE(RFAILED);
1221 } /* SRemProcId */
1222
1223 \f
1224 /*
1225 *
1226 *       Fun:   SLockOsCp
1227 *
1228 *       Desc:  This function locks OsCp 
1229 *
1230 *       Ret:   ROK/RFAILED 
1231 *
1232 *       Notes: 
1233 *
1234 *       File:  ss_gen.c
1235 *
1236 */
1237 #ifdef ANSI
1238 PRIVATE S16 SLockOsCp
1239 (
1240 Void
1241 )
1242 #else
1243 PRIVATE S16 SLockOsCp(Void)
1244 #endif
1245 {
1246    S16 ret;
1247
1248    TRC1(SLockOsCp);
1249
1250    ret = SLock(&osCp.sTskTblLock);
1251    if (ret != ROK)
1252    {
1253       SSLOGERROR(ERRCLS_DEBUG, ESS016, ERRZERO,
1254                      "Could not lock system task table");
1255       RETVALUE(RFAILED);
1256    }
1257
1258    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
1259    if (ret != ROK)
1260    {
1261
1262 #if (ERRCLASS & ERRCLS_DEBUG)
1263       SSLOGERROR(ERRCLS_DEBUG, ESS017, ERRZERO,
1264                      "Could not lock TAPA task table");
1265 #endif
1266
1267       if ( SUnlock(&osCp.sTskTblLock) != ROK)
1268       {
1269 #if (ERRCLASS & ERRCLS_DEBUG)
1270          SSLOGERROR(ERRCLS_DEBUG, ESS018, ERRZERO,
1271                       "Could not give the Semaphore");
1272          RETVALUE(RFAILED);
1273 #endif
1274       }
1275
1276       RETVALUE(RFAILED);
1277    }
1278
1279    RETVALUE(ROK);
1280
1281 } /* SLockOsCp */
1282
1283 \f
1284 /*
1285 *
1286 *       Fun:   SULockOsCp
1287 *
1288 *       Desc:  This function locks OsCp 
1289 *
1290 *       Ret:   ROK/RFAILED 
1291 *
1292 *       Notes: 
1293 *
1294 *       File:  ss_gen.c
1295 *
1296 */
1297 #ifdef ANSI
1298 PRIVATE S16 SULockOsCp
1299 (
1300 Void
1301 )
1302 #else
1303 PRIVATE S16 SULockOsCp(Void)
1304 #endif
1305 {
1306    TRC1(SULockOsCp);
1307
1308    /* unlock the table */
1309    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1310
1311    if ( SUnlock(&osCp.sTskTblLock) != ROK)
1312    {
1313 #if (ERRCLASS & ERRCLS_DEBUG)
1314       SSLOGERROR(ERRCLS_DEBUG, ESS019, ERRZERO,
1315                       "Could not give the Semaphore");
1316       RETVALUE(RFAILED);
1317 #endif
1318    }
1319
1320    RETVALUE(ROK);
1321
1322 } /* SULockOsCp */
1323
1324
1325 \f
1326 /*
1327 *
1328 *       Fun:   SAddProcIdLst
1329 *
1330 *       Desc:  This function adds given proc ids to the list 
1331 *
1332 *       Ret:   ROK/RFAILED 
1333 *
1334 *       Notes: 
1335 *
1336 *       File:  ss_gen.c
1337 *
1338 */
1339 #ifdef ANSI
1340 PUBLIC S16 SAddProcIdLst
1341 (
1342 U16 numPIds,
1343 ProcId *pIdLst
1344 )
1345 #else
1346 PUBLIC S16 SAddProcIdLst(numPIds, pIdLst)
1347 U16 numPIds;
1348 ProcId *pIdLst;
1349 #endif
1350 {
1351    U16 i;
1352    S16 ret;
1353
1354    TRC1(SAddProcIdLst);
1355
1356 #if (ERRCLASS & ERRCLS_INT_PAR)
1357    /* range check */
1358    if (numPIds > SS_MAX_PROCS)
1359    {
1360       SSLOGERROR(ERRCLS_INT_PAR, ESS020, ERRZERO, "number of proc Ids exceeds\
1361  limit");
1362       RETVALUE(RFAILED);
1363    }
1364
1365    /* find if the entry exist in the table */
1366    for (i = 0; i < numPIds; i++)
1367    {
1368       if (pIdLst[i] == SS_INV_PROCID)
1369       {
1370          SSLOGERROR(ERRCLS_INT_PAR, ESS021, ERRZERO, "Invalid proc Ids");
1371          RETVALUE(RFAILED);
1372       }
1373    }
1374
1375 #endif
1376    
1377    if (SLockOsCp() != ROK)
1378       RETVALUE(RFAILED);
1379
1380 #if (ERRCLASS & ERRCLS_INT_PAR)
1381    for (i = 0; i < numPIds; i++)
1382       if (SGetProcIdIdx(pIdLst[i]) != SS_INV_PROCID_IDX)
1383       {
1384          SSLOGERROR(ERRCLS_INT_PAR, ESS022, ERRZERO, "Duplicate proc id");
1385          (Void) SULockOsCp();
1386          RETVALUE(RFAILED);
1387       }
1388
1389    if (numPIds > osCp.procLst.free)
1390    {
1391       SSLOGERROR(ERRCLS_INT_PAR, ESS023, ERRZERO, "Total number of proc id \
1392 exceeds");
1393       (Void) SULockOsCp();
1394       RETVALUE(RFAILED);
1395    }
1396 #endif 
1397
1398    /* insert the entries in the table */
1399    ret = ROK;
1400
1401    for (i = 0; i < numPIds; i++)
1402    {
1403       if (SInsProcId(pIdLst[i]) == RFAILED)
1404       {
1405 #if (ERRCLASS & ERRCLS_DEBUG)
1406          SSLOGERROR(ERRCLS_DEBUG, ESS024, ERRZERO,
1407                       "Could not insert the proc id");
1408 #endif
1409          (Void) SULockOsCp();
1410          RETVALUE(RFAILED);
1411       }
1412    }
1413
1414    /* unlock the table */
1415    if (SULockOsCp() != ROK)
1416       RETVALUE(RFAILED);
1417
1418    RETVALUE(ret);
1419 } /* SAddProcIdLst */
1420
1421 \f
1422 /*
1423 *
1424 *       Fun:   SRemProcIdLst
1425 *
1426 *       Desc:  This function adds given proc ids to the list 
1427 *
1428 *       Ret:   ROK/RFAILED 
1429 *
1430 *       Notes: 
1431 *
1432 *       File:  ss_gen.c
1433 *
1434 */
1435 #ifdef ANSI
1436 PUBLIC S16 SRemProcIdLst
1437 (
1438 U16 numPIds,
1439 ProcId *pIdLst
1440 )
1441 #else
1442 PUBLIC S16 SRemProcIdLst(numPIds, pIdLst)
1443 U16 numPIds;
1444 ProcId *pIdLst;
1445 #endif
1446 {
1447    U16 i;
1448
1449    TRC1(SRemProcIdLst);
1450
1451 #if (ERRCLASS & ERRCLS_INT_PAR)
1452    /* range check */
1453    if (numPIds > SS_MAX_PROCS)
1454       RETVALUE(RFAILED);
1455 #endif
1456
1457    if (SLockOsCp() != ROK)
1458       RETVALUE(RFAILED);
1459
1460    if (numPIds > (SS_MAX_PROCS - osCp.procLst.free))
1461    {
1462       (Void) SULockOsCp();
1463       RETVALUE(RFAILED);
1464    }
1465
1466    /* find if the entry exist in the table */
1467    for (i = 0; i < numPIds; i++)
1468    {
1469       if (SGetProcIdIdx(pIdLst[i]) == SS_INV_PROCID_IDX)
1470       {
1471          (Void) SULockOsCp();
1472          RETVALUE(RFAILED);
1473       }
1474    }
1475
1476    /* insert the entries in the table */
1477    for (i = 0; i < numPIds; i++)
1478       SRemProcId(pIdLst[i]);
1479
1480    if (SULockOsCp() != ROK)
1481       RETVALUE(RFAILED);
1482
1483    RETVALUE(ROK);
1484 } /* SRemProcIdLst */
1485
1486 \f
1487 /*
1488 *
1489 *       Fun:   SGetProcIdLst
1490 *
1491 *       Desc:  This function retrieves proc Id list 
1492 *
1493 *       Ret:   ROK/RFAILED 
1494 *
1495 *       Notes: 
1496 *
1497 *       File:  ss_gen.c
1498 *
1499 */
1500 #ifdef ANSI
1501 PUBLIC S16 SGetProcIdLst
1502 (
1503 U16 *numPIds,
1504 ProcId *pIdLst
1505 )
1506 #else
1507 PUBLIC S16 SGetProcIdLst(numPIds, pIdLst)
1508 U16 *numPIds;
1509 ProcId *pIdLst;
1510 #endif
1511 {
1512    U16 i;
1513    U16 count = 0;
1514
1515    TRC1(SGetProcIdLst);
1516
1517 #if (ERRCLASS & ERRCLS_INT_PAR)
1518    if ((numPIds == NULLP) || (pIdLst == NULLP))
1519    {
1520       SSLOGERROR(ERRCLS_INT_PAR, ESS025, ERRZERO, "Invalid numPIds/pIdLst");
1521       RETVALUE(RFAILED);
1522    }
1523 #endif 
1524
1525    if (SLockOsCp() != ROK)
1526       RETVALUE(RFAILED);
1527
1528    for (i = 0; i < SS_MAX_PROCS; i++)
1529    {
1530       if (osCp.procLst.procId[i] != PROCNC)
1531          pIdLst[count++] = osCp.procLst.procId[i];
1532    }
1533
1534    *numPIds = count;
1535
1536    if (SULockOsCp() != ROK)
1537       RETVALUE(RFAILED);
1538
1539    if (count == 0)
1540       RETVALUE(RFAILED);
1541
1542    RETVALUE(ROK);
1543 } /* SGetProcIdLst */
1544
1545 \f
1546 /*
1547 *
1548 *       Fun:   SGetXxCb
1549 *
1550 *       Desc:  This function retrieves protocol layer control block for given proc,
1551 *              ent and inst IDs
1552 *
1553 *       Ret:   ROK/RFAILED 
1554 *
1555 *       Notes: 
1556 *
1557 *       File:  ss_gen.c
1558 *
1559 */
1560 #ifdef ANSI
1561 PUBLIC S16 SGetXxCb
1562 (
1563 ProcId proc,
1564 Ent ent,
1565 Inst inst,
1566 Void **xxCb
1567 )
1568 #else
1569 PUBLIC S16 SGetXxCb(proc, ent, inst, xxCb)
1570 ProcId proc;
1571 Ent ent;
1572 Inst inst;
1573 Void **xxCb;
1574 #endif
1575 {
1576    U16 procIdIdx;
1577    SsIdx idx;
1578
1579    TRC1(SGetXxCb);
1580
1581 #if (ERRCLASS & ERRCLS_INT_PAR)
1582    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
1583    {
1584       SSLOGERROR(ERRCLS_INT_PAR, ESS026, ERRZERO, "Invalid proc/entity/instance");
1585       RETVALUE(RFAILED);
1586    }
1587 #endif 
1588    
1589    /* 
1590     * ss030.103: delete: locking/unlocking removed as it causes
1591     * deadlock/blockage in some cases
1592     */
1593
1594    procIdIdx = SGetProcIdIdx(proc);
1595
1596    if (procIdIdx == SS_INV_PROCID_IDX)
1597    {
1598 #if (ERRCLASS & ERRCLS_INT_PAR)
1599       SSLOGERROR(ERRCLS_INT_PAR, ESS027, ERRZERO, "Could not get proc table idx");
1600 #endif
1601       RETVALUE(RFAILED);
1602    }
1603
1604    idx = osCp.tTskIds[procIdIdx][ent][inst];
1605    if (idx == SS_TSKNC)
1606    {
1607       RETVALUE(RFAILED);
1608    }
1609
1610    /* update the CB */
1611    *xxCb = osCp.tTskTbl[idx].xxCb;
1612    /*ss032.103 added a check for NULLP */
1613    if (*xxCb == NULLP)
1614       RETVALUE(RFAILED);
1615
1616    RETVALUE(ROK);
1617 } /* SGetXxCb */
1618
1619 #endif /* SS_MULTIPLE_PROCS */
1620
1621 /* ss001.301: additions */
1622 #ifdef SS_HISTOGRAM_SUPPORT 
1623 /*
1624 *
1625 *       Fun:   SFillEntIds
1626 *
1627 *       Desc:  It is static data base contains all entity Ids of tapa task.
1628 *              This Data base is used to find the entity id using two letter
1629 *              prifix product code.
1630 *
1631 *       Ret:   ROK/RFAILED
1632 *
1633 *       Notes:
1634 *
1635 *       File:  ss_gen.c
1636 *
1637 */
1638 #ifdef ANSI
1639 PUBLIC S16 SFillEntIds
1640 (
1641 Void
1642 )
1643 #else
1644 PUBLIC S16 SFillEntIds(Void)
1645 #endif
1646 {
1647
1648    U8 entInfo[26][26] = {
1649                            /* A      B      C      D      E      F      G      H      I      J      K  *
1650                               L      M      N      O      P      Q      R      S      T      U      V  *
1651                               W      X      Y      Z */
1652                            {ENTAA, ENTAB, ENTAC, ENTNC, ENTAE, ENTAF, ENTNC, ENTAH, ENTNC, ENTNC, ENTNC,
1653                   /* A */   ENTAL, ENTAM, ENTNC, ENTNC, ENTAP, ENTAQ, ENTAR, ENTAS, ENTNC, ENTAU, ENTNC,
1654                             ENTAW, ENTNC, ENTNC, ENTNC},
1655
1656                            /* A      B      C      D      E      F      G      H      I      J      K  *
1657                               L      M      N      O      P      Q      R      S      T      U      V  *
1658                               W      X      Y      Z */
1659                            {ENTNC, ENTNC, ENTNC, ENTBD, ENTNC, ENTNC, ENTNC, ENTNC, ENTBI, ENTNC, ENTNC,
1660                   /* B */   ENTNC, ENTBM, ENTNC, ENTNC, ENTNC, ENTNC, ENTBR, ENTBS, ENTNC, ENTNC, ENTBV,
1661                             ENTBW, ENTNC, ENTNC, ENTNC},
1662                            /* A      B      C      D      E      F      G      H      I      J      K  *
1663                               L      M      N      O      P      Q      R      S      T      U      V  *
1664                               W      X      Y      Z */
1665                            {ENTNC, ENTNC, ENTCC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCH, ENTNC, ENTNC, ENTNC,
1666                   /* C */   ENTCL, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCS, ENTNC, ENTCU, ENTCV,
1667                             ENTNC, ENTNC, ENTNC, ENTNC},
1668                            /* A      B      C      D      E      F      G      H      I      J      K  *
1669                               L      M      N      O      P      Q      R      S      T      U      V  *
1670                               W      X      Y      Z */
1671                            {ENTNC, ENTDB, ENTNC, ENTNC, ENTNC, ENTNC, ENTDG, ENTNC, ENTDI, ENTNC, ENTDK,
1672                   /* D */   ENTNC, ENTDM, ENTDN, ENTNC, ENTDP, ENTNC, ENTNC, ENTNC, ENTDT, ENTDU, ENTDV,
1673                             ENTNC, ENTNC, ENTNC, ENTNC},
1674                            /* A      B      C      D      E      F      G      H      I      J      K  *
1675                               L      M      N      O      P      Q      R      S      T      U      V  *
1676                               W      X      Y      Z */
1677                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTEC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1678                   /* E */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTER, ENTES, ENTNC, ENTNC, ENTEV,
1679                             ENTNC, ENTNC, ENTNC, ENTNC},
1680                            /* A      B      C      D      E      F      G      H      I      J      K  *
1681                               L      M      N      O      P      Q      R      S      T      U      V  *
1682                               W      X      Y      Z */
1683                            {ENTFA, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1684                   /* F */   ENTNC, ENTFM, ENTFN, ENTNC, ENTFP, ENTNC, ENTFR, ENTNC, ENTNC, ENTFU, ENTNC,
1685                             ENTFW, ENTNC, ENTNC, ENTNC},
1686                            /* A      B      C      D      E      F      G      H      I      J      K  *
1687                               L      M      N      O      P      Q      R      S      T      U      V  *
1688                               W      X      Y      Z */
1689                            {ENTGA, ENTGB, ENTGC, ENTGD, ENTGE, ENTGF, ENTGG, ENTGH, ENTGI, ENTNC, ENTNC,
1690                   /* G */   ENTGL, ENTGM, ENTGN, ENTGO, ENTGP, ENTNC, ENTGR, ENTGS, ENTGT, ENTGU, ENTNC,
1691                             ENTGW, ENTGX, ENTGY, ENTGZ},
1692                            /* A      B      C      D      E      F      G      H      I      J      K  *
1693                               L      M      N      O      P      Q      R      S      T      U      V  *
1694                               W      X      Y      Z */
1695                            {ENTNC, ENTNC, ENTHC, ENTNC, ENTHE, ENTNC, ENTHG, ENTNC, ENTHI, ENTNC, ENTNC,
1696                   /* H */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTHR, ENTHS, ENTNC, ENTHU, ENTNC,
1697                             ENTNC, ENTNC, ENTNC, ENTNC},
1698                            /* A      B      C      D      E      F      G      H      I      J      K  *
1699                               L      M      N      O      P      Q      R      S      T      U      V  *
1700                               W      X      Y      Z */
1701                            {ENTIA, ENTIB, ENTNC, ENTID, ENTIE, ENTNC, ENTNC, ENTNC, ENTII, ENTNC, ENTNC,
1702                   /* I */   ENTNC, ENTIM, ENTIN, ENTNC, ENTNC, ENTIQ, ENTNC, ENTIS, ENTIT, ENTIU, ENTNC,
1703                             ENTIW, ENTIX, ENTNC, ENTNC},
1704                            /* A      B      C      D      E      F      G      H      I      J      K  *
1705                               L      M      N      O      P      Q      R      S      T      U      V  *
1706                               W      X      Y      Z */
1707                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1708                   /* J */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1709                             ENTNC, ENTNC, ENTNC, ENTNC},
1710                            /* A      B      C      D      E      F      G      H      I      J      K  *
1711                               L      M      N      O      P      Q      R      S      T      U      V  *
1712                               W      X      Y      Z */
1713                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1714                   /* K */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1715                             ENTKW, ENTNC, ENTNC, ENTNC},
1716                            /* A      B      C      D      E      F      G      H      I      J      K  *
1717                               L      M      N      O      P      Q      R      S      T      U      V  *
1718                               W      X      Y      Z */
1719                            {ENTLA, ENTLB, ENTLC, ENTLD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTLK,
1720                   /* L */   ENTNC, ENTLM, ENTLN, ENTNC, ENTNC, ENTNC, ENTLR, ENTNC, ENTLT, ENTLU, ENTLV,
1721                             ENTNC, ENTLX, ENTNC, ENTNC},
1722                            /* A      B      C      D      E      F      G      H      I      J      K  *
1723                               L      M      N      O      P      Q      R      S      T      U      V  *
1724                               W      X      Y      Z */
1725                            {ENTMA, ENTNC, ENTMC, ENTMD, ENTME, ENTNC, ENTMG, ENTNC, ENTNC, ENTNC, ENTMK,
1726                   /* M */   ENTML, ENTMM, ENTNC, ENTNC, ENTNC, ENTNC, ENTMR, ENTMS, ENTMT, ENTMU, ENTMV,
1727                             ENTMW, ENTMX, ENTNC, ENTMZ},
1728                            /* A      B      C      D      E      F      G      H      I      J      K  *
1729                               L      M      N      O      P      Q      R      S      T      U      V  *
1730                               W      X      Y      Z */
1731                            {ENTNC, ENTNC, ENTNC, ENTND, ENTNC, ENTNF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1732                   /* N */   ENTNC, ENTNM, ENTNC, ENTNC, ENTNP, ENTNC, ENTNC, ENTNS, ENTNC, ENTNC, ENTNV,
1733                             ENTNW, ENTNC, ENTNC, ENTNC},
1734                            /* A      B      C      D      E      F      G      H      I      J      K  *
1735                               L      M      N      O      P      Q      R      S      T      U      V  *
1736                               W      X      Y      Z */
1737                            {ENTNC, ENTNC, ENTNC, ENTOD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1738                   /* O */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1739                             ENTNC, ENTNC, ENTNC, ENTNC},
1740                            /* A      B      C      D      E      F      G      H      I      J      K  *
1741                               L      M      N      O      P      Q      R      S      T      U      V  *
1742                               W      X      Y      Z */
1743                            {ENTPA, ENTNC, ENTNC, ENTPD, ENTNC, ENTNC, ENTNC, ENTPH, ENTNC, ENTNC, ENTNC,
1744                   /* P */   ENTPL, ENTNC, ENTPN, ENTNC, ENTPN, ENTPQ, ENTPR, ENTNC, ENTNC, ENTPU, ENTPV,
1745                             ENTNC, ENTNC, ENTNC, ENTNC},
1746                            /* A      B      C      D      E      F      G      H      I      J      K  *
1747                               L      M      N      O      P      Q      R      S      T      U      V  *
1748                               W      X      Y      Z */
1749                            {ENTNC, ENTNC, ENTQC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTQI, ENTNC, ENTNC,
1750                   /* Q */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1751                             ENTQW, ENTNC, ENTNC, ENTNC},
1752                            /* A      B      C      D      E      F      G      H      I      J      K  *
1753                               L      M      N      O      P      Q      R      S      T      U      V  *
1754                               W      X      Y      Z */
1755                            {ENTRA, ENTNC, ENTNC, ENTRD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1756                   /* R */   ENTRL, ENTRM, ENTRN, ENTNC, ENTRP, ENTNC, ENTRR, ENTNC, ENTRT, ENTRU, ENTNC,
1757                             ENTNC, ENTRX, ENTRY, ENTNC},
1758                            /* A      B      C      D      E      F      G      H      I      J      K  *
1759                               L      M      N      O      P      Q      R      S      T      U      V  *
1760                               W      X      Y      Z */
1761                            {ENTSA, ENTSB, ENTSC, ENTSD, ENTSE, ENTSF, ENTSG, ENTSH, ENTSI, ENTNC, ENTNC,
1762                   /* S */   ENTNC, ENTSM, ENTSN, ENTSO, ENTSP, ENTNC, ENTSR, ENTSS, ENTST, ENTSU, ENTSV,
1763                             ENTNC, ENTNC, ENTNC, ENTSZ},
1764                            /* A      B      C      D      E      F      G      H      I      J      K  *
1765                               L      M      N      O      P      Q      R      S      T      U      V  *
1766                               W      X      Y      Z */
1767                            {ENTNC, ENTNC, ENTTC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1768                   /* T */   ENTNC, ENTTM, ENTNC, ENTNC, ENTTP, ENTNC, ENTNC, ENTTS, ENTTT, ENTTU, ENTNC,
1769                             ENTNC, ENTNC, ENTNC, ENTNC},
1770                            /* A      B      C      D      E      F      G      H      I      J      K  *
1771                               L      M      N      O      P      Q      R      S      T      U      V  *
1772                               W      X      Y      Z */
1773                            {ENTNC, ENTNC, ENTNC, ENTUD, ENTNC, ENTNC, ENTNC, ENTUH, ENTNC, ENTNC, ENTNC,
1774                   /* U */   ENTUL, ENTUM, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTUS, ENTNC, ENTNC, ENTNC,
1775                             ENTNC, ENTNC, ENTNC, ENTUZ},
1776                            /* A      B      C      D      E      F      G      H      I      J      K  *
1777                               L      M      N      O      P      Q      R      S      T      U      V  *
1778                               W      X      Y      Z */
1779                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1780                   /* V */   ENTNC, ENTVM, ENTNC, ENTVO, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVU, ENTNC,
1781                             ENTNC, ENTNC, ENTNC, ENTNC},
1782                            /* A      B      C      D      E      F      G      H      I      J      K  *
1783                               L      M      N      O      P      Q      R      S      T      U      V  *
1784                               W      X      Y      Z */
1785                            {ENTNC, ENTNC, ENTWC, ENTWD, ENTNC, ENTNC, ENTNC, ENTNC, ENTWI, ENTNC, ENTNC,
1786                   /* W */   ENTNC, ENTNC, ENTWN, ENTNC, ENTNC, ENTNC, ENTNC, ENTWS, ENTNC, ENTWU, ENTNC,
1787                             ENTNC, ENTNC, ENTNC, ENTNC},
1788                            /* A      B      C      D      E      F      G      H      I      J      K  *
1789                               L      M      N      O      P      Q      R      S      T      U      V  *
1790                               W      X      Y      Z */
1791                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXG, ENTNC, ENTXI, ENTNC, ENTNC,
1792                   /* X */   ENTNC, ENTXM, ENTXN, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXU, ENTNC,
1793                             ENTNC, ENTXX, ENTXY, ENTNC},
1794                            /* A      B      C      D      E      F      G      H      I      J      K  *
1795                               L      M      N      O      P      Q      R      S      T      U      V  *
1796                               W      X      Y      Z */
1797                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1798                   /* Y */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1799                             ENTNC, ENTNC, ENTNC, ENTNC},
1800                            /* A      B      C      D      E      F      G      H      I      J      K  *
1801                               L      M      N      O      P      Q      R      S      T      U      V  *
1802                               W      X      Y      Z */
1803                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1804                   /* Z */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1805                             ENTNC, ENTNC, ENTNC, ENTNC}
1806                         };
1807
1808    /*ss013.301 :Adding  TRC MACRO*/
1809    TRC2(SFillEntIds)
1810             memcpy((U8*)osCp.entId, (U8*)entInfo, sizeof(entInfo));
1811
1812    RETVALUE(ROK);
1813 } /* SFillEntIds */
1814
1815
1816 /*
1817 *
1818 *       Fun:   SGetEntInd 
1819 *
1820 *       Desc:  This function gives the entity Id depending in the 
1821 *              file name. This function uses the first two letter
1822 *              of file name to find the entity id. 
1823 *              
1824 *              
1825 *
1826 *       Ret:   ROK              OK
1827 *              RFAILED          Region not registered
1828 *
1829 *
1830 */
1831 #ifdef ANSI
1832 PUBLIC S16 SGetEntInd 
1833 (
1834 Ent      *entId,
1835 U8       *fileName
1836 )
1837 #else
1838 PUBLIC S16 SGetEntInd(entId, fileName)
1839 Ent      *entId;
1840 U8       *fileName;
1841 #endif
1842 {
1843
1844
1845         U8   *letter = NULLP;
1846    /* ss002.301 Additions */
1847         S8   *strippedName = NULLP;
1848         U8   count = 0;
1849         U8   tempIdx = 0;
1850         U8   firstIdx = 0;
1851         U8   secondIdx = 0;
1852
1853    TRC1(SGetEntInd);
1854
1855    /* ss002.301 Additions */
1856         if ((strippedName = strrchr((const char *)fileName, '/')))
1857         {
1858            fileName = (U8 *)strippedName + 1;
1859         }
1860
1861         if(fileName[0] =='l' && fileName[3] == '.')
1862    { 
1863            /* Usally layer manager interface files starts
1864                  * with l. so leave the first letter and take
1865                  * other two letter.
1866                  * Eg. Layer manger inteface file name for TUCL is lhi.c.
1867                  * so here we leave l and we take hi to get the entity Id. */
1868       letter = ++fileName; 
1869         } 
1870         else
1871         { 
1872            letter = fileName;
1873            /* Handle exceptional file names */
1874            switch(letter[0])
1875            {
1876               case 'g':
1877                      if (letter[1] == 'g' && letter[2] == 'u')
1878                      {
1879                         *entId = ENTGT;
1880                              RETVALUE(ROK);
1881                      }
1882                    default: 
1883                              break;
1884
1885            }
1886         }
1887
1888
1889    /* here first two charactes of file name should be alphabets.
1890          * if any one of the letter is non alphabet then we return ENTNC 
1891          * as an entity Id */
1892    /* Eg. In fileName l4_ptui.c, second letter is numeral. so we consider
1893          * this file belogs to entity Id ENTNC. */
1894         for(count = 0; count < 2; count++)
1895         {
1896                 /* ss002.301 - Optimizations */
1897             if(letter[count] < 'a' || letter[count] > 'z')
1898             {
1899                    *entId = ENTNC;
1900                    RETVALUE(ROK);
1901             }
1902             else
1903             {
1904                    tempIdx = letter[count] - 'a';
1905             }
1906                  if(count == 0)
1907                  {
1908                         firstIdx = tempIdx;
1909                  }/* End of if */
1910                  else
1911                  {
1912                         secondIdx = tempIdx;
1913                  }/* End of else */
1914         } /* End of for */
1915         /* First two letter of file name are alphabets the get the 
1916          * entity id from the static data base which is loaded in sFillEntIds() */
1917         *entId = osCp.entId[firstIdx][secondIdx];
1918         RETVALUE(ROK);
1919 } /* SGetEntInd */
1920
1921 #endif /* SS_HISTOGRAM_SUPPORT */
1922 #ifdef SS_LOCK_SUPPORT
1923 /* ss002.301 Readwrite lock additions */
1924 /*
1925 *
1926 *       Fun:   SLockNew 
1927 *
1928 *       Desc:  This function is used to aquire the read write lock
1929 *
1930 *       Ret:   ROK   OK
1931 *
1932 *       Notes:
1933 *
1934 *       File:  mt_ss.c
1935 *
1936 */
1937 #ifdef ANSI
1938 PUBLIC S16 SLockNew 
1939 (
1940 SLockInfo *lockId,
1941 U8         lockType
1942
1943 )
1944 #else
1945 PUBLIC S16 SLockNew(lockId, lockType)
1946 SLockInfo *lockId;
1947 U8         lockType;
1948 #endif
1949 {
1950    S16    retVal = ROK;
1951
1952   TRC1(SLockNew);
1953
1954   if((retVal = ssdLockNew(lockId, lockType)) != ROK) 
1955   {
1956     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SLockNew(): Failed to aquire the lock\n");
1957     RETVALUE(RFAILED);
1958   }
1959    RETVALUE(ROK);
1960 }
1961
1962 /*
1963 *
1964 *       Fun:   SInitLockNew 
1965 *
1966 *       Desc:  This function is used to aquire the read write lock
1967 *
1968 *       Ret:   ROK   OK
1969 *
1970 *       Notes:
1971 *
1972 *       File:  mt_ss.c
1973 *
1974 */
1975 #ifdef ANSI
1976 PUBLIC S16 SInitLockNew 
1977 (
1978 SLockInfo *lockId,
1979 U8         lockType
1980 )
1981 #else
1982 PUBLIC S16 SInitLockNew(lockId, lockType)
1983 SLockInfo *lockId;
1984 U8         lockType;
1985 #endif
1986 {
1987    S16    retVal = ROK;
1988
1989   TRC1(SInitLockNew);
1990
1991   if((retVal = ssdInitLockNew(lockId, lockType)) != ROK) 
1992   {
1993     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SInitLockNew(): Initialization of lock Failed\n");
1994     RETVALUE(RFAILED);
1995   }
1996    RETVALUE(ROK);
1997 }
1998
1999 /*
2000 *
2001 *       Fun:   SUnlockNew 
2002 *
2003 *       Desc:  This function is used to Unlock the read write lock 
2004 *
2005 *       Ret:   ROK   OK
2006 *
2007 *       Notes:
2008 *
2009 *       File:  mt_ss.c
2010 *
2011 */
2012 #ifdef ANSI
2013 PUBLIC S16 SUnlockNew 
2014 (
2015 SLockInfo *lockId,
2016 U8         lockType
2017 )
2018 #else
2019 PUBLIC S16 SUnlockNew(lockId, lockType)
2020 SLockInfo *lockId;
2021 U8         lockType;
2022 #endif
2023 {
2024    S16    retVal = ROK;
2025
2026   TRC1(SUnlockNew);
2027
2028   if((retVal = ssdUnlockNew(lockId, lockType)) != ROK) 
2029   {
2030     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SUnlockNew(): Failed to release the lock\n");
2031     RETVALUE(RFAILED);
2032   }
2033    RETVALUE(ROK);
2034 }
2035
2036 /*
2037 *
2038 *       Fun:   SDestroyLockNew 
2039 *
2040 *       Desc:  This function is used to destroy the read write lock 
2041 *
2042 *       Ret:   ROK   OK
2043 *
2044 *       Notes:
2045 *
2046 *       File:  mt_ss.c
2047 *
2048 */
2049 #ifdef ANSI
2050 PUBLIC S16 SDestroyLockNew 
2051 (
2052 SLockInfo *lockId,
2053 U8         lockType
2054 )
2055 #else
2056 PUBLIC S16 SDestroyLockNew(lockId, lockType)
2057 SLockInfo *lockId;
2058 U8         lockType;
2059 #endif
2060 {
2061    S16    retVal = ROK;
2062
2063   TRC1(SDestroyLockNew);
2064
2065   if((retVal = ssdDestroyLockNew(lockId, lockType)) != ROK) 
2066   {
2067     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SDestroyLockNew(): Failed to destroy the lock\n");
2068     RETVALUE(RFAILED);
2069   }
2070    RETVALUE(ROK);
2071 }
2072 #endif /* SS_LOCK_SUPPORT */
2073
2074 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
2075 /* Static memory leak detection changes */
2076 static U32 StaticMemLeakAge;
2077 static U32 StaticMemLeakIntCount = 1;
2078
2079 void PrintStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo, FILE *opFile)
2080 {
2081    int i;
2082
2083    fprintf(opFile, "Current Time = %ld\n",StaticMemLeakAge);
2084
2085    for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
2086    {
2087       if(memAllocInfo->allocations[i].ptr)
2088       {
2089          fprintf(opFile, "p = %p f = %s l = %ld s = %ld a = %ld\n",
2090                           memAllocInfo->allocations[i].ptr, 
2091                           memAllocInfo->allocations[i].file, 
2092                           memAllocInfo->allocations[i].lineNo, 
2093                           memAllocInfo->allocations[i].size, 
2094                           memAllocInfo->allocations[i].age);
2095       }
2096    }
2097
2098    fclose(opFile);
2099 }
2100
2101 void InitializeStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo)
2102 {
2103    U32 i;
2104    /* index 0 is not used; nextIdx as 0 means end of list */
2105    memAllocInfo->nextFreeIdx = 1;
2106
2107    for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
2108    {
2109       memAllocInfo->allocations[i].listInfo.nextIdx = i + 1;
2110       memAllocInfo->allocations[i].ptr = 0;
2111    }
2112
2113    /* override the last one to point to 0 meaning end of list */
2114    memAllocInfo->allocations[MAX_MEM_ALLOCATIONS - 1].listInfo.nextIdx = 0;
2115 }
2116
2117 U32 GetNextFreeIdx(StaticMemAllocInfo * memAllocInfo)
2118 {
2119    U32 toBeReturned = memAllocInfo->nextFreeIdx;
2120
2121    U32 newNextFreeIdx = memAllocInfo->allocations[memAllocInfo->nextFreeIdx].listInfo.nextIdx;
2122
2123    if(newNextFreeIdx == 0 || newNextFreeIdx >= MAX_MEM_ALLOCATIONS)
2124    {
2125       printf("Something wrong in GetNextFreeIdx newNextIdx = %ld\n",newNextFreeIdx);
2126    }
2127
2128    memAllocInfo->nextFreeIdx = newNextFreeIdx;
2129    
2130    return toBeReturned;
2131 }
2132
2133 #define CRASH_ENB {int *p = 0; *p = 100;}
2134 void FreeIdx(U8* ptr, U32 idx, StaticMemAllocInfo* memAllocInfo,U32 size, char* file, U32 line)
2135 {
2136    if(idx == 0 || idx >= MAX_MEM_ALLOCATIONS)
2137    {
2138       printf("Something wrong in FreeIdx... idx = %ld called from %s:%ld\n",idx,file,line);
2139       CRASH_ENB
2140    }
2141    /*printf("FreeIdx... idx = %d nexFree = %d\n",idx, memAllocInfo->nextFreeIdx);*/
2142    memAllocInfo->allocations[idx].listInfo.nextIdx = memAllocInfo->nextFreeIdx;
2143    if((ptr != memAllocInfo->allocations[idx].ptr) ||
2144       (size != memAllocInfo->allocations[idx].size))
2145    {
2146 #ifdef XEON_SPECIFIC_CHANGES
2147 CRASH_ENB
2148 #endif   
2149       
2150       printf("Freeing wrong ptr stored = %p trying to free %p freeing size (%ld)"
2151             "allocated size(%ld) from %s:%ld\n",
2152               memAllocInfo->allocations[idx].ptr, 
2153               ptr,
2154               size,
2155               memAllocInfo->allocations[idx].size,
2156               file,
2157               line);
2158       printf("Allocation was done from %s:%ld\n",memAllocInfo->allocations[idx].file, memAllocInfo->allocations[idx].lineNo);
2159       printf("***********************************************************\n");
2160       CRASH_ENB
2161    }
2162
2163    memAllocInfo->allocations[idx].ptr = 0;
2164
2165    memAllocInfo->nextFreeIdx = idx;
2166 }
2167
2168
2169 void LogForStaticMemLeak(StaticMemAllocInfo* memAllocInfo, char* file, U32 line, U32 size, void* ptr, U32 idx)
2170 {
2171
2172    memAllocInfo->allocations[idx].file = file;
2173    memAllocInfo->allocations[idx].lineNo = line;
2174    memAllocInfo->allocations[idx].size = size;
2175    memAllocInfo->allocations[idx].ptr = ptr;
2176    memAllocInfo->allocations[idx].age = StaticMemLeakAge;
2177
2178    if(StaticMemLeakIntCount++ % 256 == 0)
2179    {
2180       StaticMemLeakAge++;
2181    }
2182 }
2183
2184 void InitializeForStaticMemLeak()
2185 {
2186    int i;
2187
2188    StaticMemLeakFileArr[0] = fopen("region0.log","w");
2189    StaticMemLeakFileArr[1] = fopen("region1.log","w");
2190    StaticMemLeakFileArr[2] = fopen("region2.log","w");
2191    StaticMemLeakFileArr[3] = fopen("region3.log","w");
2192
2193    if(StaticMemLeakFileArr[0] == NULL ||
2194          StaticMemLeakFileArr[1] == NULL ||
2195          StaticMemLeakFileArr[2] == NULL ||
2196          StaticMemLeakFileArr[3] == NULL)
2197    {
2198       int *p = 0;
2199       printf("Could not open files for Static Mem Leak detection logging :( crashing...\n");
2200       *p = 100;
2201    }
2202
2203    for(i = 0; i < 4; i++)
2204    {
2205       InitializeStaticMemAllocInfo(&SMemLeakInfo[i]);
2206    }
2207 }
2208
2209 PUBLIC void DumpStaticMemLeakFiles()
2210 {
2211    int i;
2212
2213    for(i = 0; i < 4; i++)
2214    {
2215       PrintStaticMemAllocInfo(&SMemLeakInfo[i], StaticMemLeakFileArr[i]);
2216    }
2217 }
2218 /* Static memory leak detection changes */
2219 #endif
2220
2221 /*
2222  *
2223  *       Fun:   ssRegMainThread
2224  *
2225  *       Desc:  This function is used to add the memory region
2226  *              mapping for the main thread.
2227  *
2228  *       Ret:   VOID (Always successful)
2229  *
2230  *       Notes:
2231  *
2232  *       File: mt_ss.c
2233  *
2234  */
2235 #ifdef ANSI
2236 PUBLIC S16 SReInitTmr
2237 (
2238 void
2239 )
2240 #else
2241 PUBLIC S16 SReInitTmr()
2242 #endif
2243 {
2244    U8 ret = ROK;
2245    Txt prntBuf[PRNTSZE];
2246
2247    sprintf(prntBuf, "\n SReInitTmr(): ReStarting the Tmr\n");
2248    SDisplay(1,prntBuf);
2249    ret = ssdReInitTmr();
2250    if (ret != ROK)
2251    {
2252        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
2253     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SReInitTmr(): Failed to Restart the Tmr\n");
2254     RETVALUE(RFAILED);
2255    }
2256    RETVALUE(ROK);
2257 }
2258
2259 /*
2260  *
2261  *       Fun:   SGetConfigPath 
2262  *
2263  *       Desc:  This function is used to Get config files path
2264  *
2265  *       Ret:   S8* config file Path
2266  *
2267  *       Notes:
2268  *
2269  *       File: ss_gen.c
2270  *
2271  */
2272 PUBLIC S8* SGetConfigPath(Void)
2273 {
2274    return osCp.configFilePath;
2275 }
2276
2277 /**********************************************************************
2278          End of file
2279  **********************************************************************/