Added code for MAC-PHY interface, DU_APP, F1AP, SCTP and CU stub
[o-du/l2.git] / src / mt / ss_task.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 -- Task Management
22  
23      Type:     C source file
24  
25      Desc:     Source code for System Services functions for task mgmt.
26  
27      File:     ss_task.c
28  
29 *********************************************************************21*/
30
31 \f
32 /* header include files (.h) */
33
34 #include "envopt.h"        /* environment options */
35 #include "envdep.h"        /* environment dependent */
36 #include "envind.h"        /* environment independent */
37   
38 #include "gen.h"           /* general layer */
39 #include "ssi.h"           /* system services */
40
41 #include "ss_err.h"        /* errors */
42 #include "ss_dep.h"        /* implementation-specific */
43 #include "ss_queue.h"      /* queues */
44 #include "ss_task.h"       /* tasking */
45 #include "ss_msg.h"        /* messaging */
46 #include "ss_mem.h"        /* memory management interface */
47 #include "ss_gen.h"        /* general */
48 #include "cm_mem.h"        /* memory management */
49 #ifdef SPLIT_RLC_DL_TASK
50 #include "rgu.h"
51 #endif
52 #ifdef SS_FBSED_TSK_REG
53 #include "cm_task.h"
54 #endif /* SS_FBSED_TSK_REG */
55
56 /* header/extern include files (.x) */
57
58 #include "gen.x"           /* general layer */
59 #include "ssi.x"           /* system services */
60
61 #include "ss_dep.x"        /* implementation-specific */
62 #include "ss_queue.x"      /* queues */
63 #include "ss_task.x"       /* tasking */
64 #include "ss_timer.x"      /* timers */
65 #include "ss_strm.x"       /* STREAMS */
66 #include "ss_msg.x"        /* messaging */
67 #include "ss_mem.x"        /* memory management interface */
68 #include "ss_drvr.x"       /* driver tasks */
69 #ifdef SS_LOCKLESS_MEMORY
70 #include "cm_llist.x"
71 #include "cm_hash.x"
72 #include "cm_mem_wl.x"        /* common memory manager */
73 #else
74 #include "cm_mem.x"        /* common memory manager */
75 #endif /* SS_LOCKLESS_MEMORY */
76 #include "ss_gen.x"        /* general */
77 #include "cm_lib.x"        /* general */
78
79 /* ss001.301: additions */
80 #ifdef SS_LOGGER_SUPPORT 
81 /* ss002.301: Fixed warings */
82 #ifdef SS_MT 
83 #include <fcntl.h>
84 #include <sys/stat.h>
85 #include <sys/socket.h>
86 #include <netinet/in.h>
87 #include <arpa/inet.h>
88 #endif /* SS_MT */
89 #ifdef WIN32
90 #include <stdio.h>
91 #include "winsock2.h"
92 #include "ws2tcpip.h"
93 #endif /* WIN32 */
94 #endif /*  SS_LOGGER_SUPPORT */
95
96 /* ss001.301: additions */
97 #ifdef SS_WATCHDOG 
98 #include <stdio.h>
99 #ifdef SS_MT 
100 #include <sys/time.h>
101 #include <sys/types.h>
102 #include <unistd.h>
103 #include <sys/poll.h>
104 #include <fcntl.h>
105 #include <sys/types.h>
106 #include <sys/socket.h>
107 #include <netinet/in.h>
108 #include <arpa/inet.h>
109 #elif WIN32
110 #include "winsock2.h"
111 #include "ws2tcpip.h"
112 #endif /* WIN32 */
113 #endif /* SS_WATCHDOG */
114
115 /* ss001.301: additions */
116 #ifdef SS_FBSED_TSK_REG 
117 #include "cm_task.x"
118 #endif /* SS_FBSED_TSK_REG */
119 /* ss004.301 : Cavium changes */
120 #ifdef SS_SEUM_CAVIUM
121 /* cvmx includes files */
122 #include "cvmx-config.h"
123 #include "cvmx.h"
124 #include "cvmx-pow.h"
125 #include "cvmx-tim.h"
126 #include "cvmx-fpa.h"
127 #include "cvmx-helper-fpa.h"
128 #include "cvmx-malloc.h"
129 #endif /* SS_SEUM_CAVIUM */
130 #ifdef L2_L3_SPLIT
131 #include "signal.h"
132 #include "mt_plat_t33.h"
133 #include "mt_4gmx.x"
134 EXTERN S32 clusterMode;
135 #endif 
136
137 PUBLIC pthread_t tmpRegTidMap[20];
138
139 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
140 EXTERN unsigned int tlPost(void *handle);
141 #ifdef XEON_SPECIFIC_CHANGES
142 EXTERN int          WLS_WakeUp(void* h);
143 #endif
144 #endif
145
146 /* ss029.103: modification: 
147    Old SSI functions are not supported with multiple procIds */ 
148 #ifndef SS_MULTIPLE_PROCS
149 \f
150 /*
151 *
152 *       Fun:   SRegInit
153 *
154 *       Desc:  This function is used to register an initialization function
155 *              for the layer. The system services will invoke the function
156 *              passed to it one time. The initialization function will be
157 *              used by the layer to initilize the layer.
158 *
159 *       Ret:   ROK      - ok
160 *              RFAILED  - failed, general (optional)
161 *
162 *       Notes:
163 *
164 *       File:  ss_task.c
165 *
166 */
167   
168 #ifdef ANSI
169 PUBLIC S16 SRegInit
170 (
171 Ent ent,                    /* entity */
172 Inst inst,                  /* instance */
173 PAIFS16 initFnct            /* initialization function */
174 )
175 #else
176 PUBLIC S16 SRegInit(ent, inst, initFnct)
177 Ent ent;                    /* entity */
178 Inst inst;                  /* instance */
179 PAIFS16 initFnct;           /* initialization function */
180 #endif
181 {
182    /* ss021.103 - Addition for return value and pointer */
183    S16         ret;     /* return value */
184    SsTTskEntry *tTsk;
185
186    TRC1(SRegInit);
187
188
189 #if (ERRCLASS & ERRCLS_INT_PAR)
190    /* check entity and instance ranges */
191    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
192    {
193       SSLOGERROR(ERRCLS_INT_PAR, ESS350, ERRZERO, "Invalid entity/instance");
194       RETVALUE(RFAILED);
195    }
196
197    /* check initialization function */
198    if (initFnct == NULLP)
199    {
200       SSLOGERROR(ERRCLS_INT_PAR, ESS351, ERRZERO, "Null pointer");
201       RETVALUE(RFAILED);
202    }
203 #endif
204
205    /* ss021.103 - Modification to store initialization function */
206    /* Acquire the counting semaphore for all other system
207     *  tasks (this call is either running in one system task's
208     *  context, or in SInit()'s context). Once we have all of
209     *  them, SPstTsk() cannot run, so we can do things to the
210     *  TAPA task table.
211     */
212
213    /* ss025.103 - Addition of lock around counting semaphore */
214    /* lock system task table */
215    ret = SLock(&osCp.sTskTblLock);
216    if (ret != ROK)
217    {
218       SSLOGERROR(ERRCLS_DEBUG, ESS352, ERRZERO,
219                      "Could not lock system task table");
220       RETVALUE(RFAILED);
221    }
222
223    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
224    if (ret != ROK)
225    {
226
227 #if (ERRCLASS & ERRCLS_DEBUG)
228       SSLOGERROR(ERRCLS_DEBUG, ESS353, ERRZERO,
229                  "Could not lock TAPA task table");
230 #endif
231
232       RETVALUE(RFAILED);
233    }
234
235
236 #if (ERRCLASS & ERRCLS_INT_PAR)
237    /* check count of tasks */
238    if (osCp.numTTsks == SS_MAX_TTSKS)
239    {
240       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
241       SSLOGERROR(ERRCLS_INT_PAR, ESS354, ERRZERO, "Too many tasks");
242
243       /* ss025.103 - Addition of unlock around counting semephore */
244       if ( SUnlock(&osCp.sTskTblLock) != ROK)
245       {
246 #if (ERRCLASS & ERRCLS_DEBUG)
247          SSLOGERROR(ERRCLS_DEBUG, ESS355, ERRZERO,
248                       "Could not give the Semaphore");
249          RETVALUE(RFAILED);
250 #endif
251       }
252
253       RETVALUE(ROUTRES);
254    }
255
256    /* check if entity and instance already registered */
257    if (osCp.tTskIds[ent][inst] != SS_TSKNC)
258    {
259       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
260       SSLOGERROR(ERRCLS_INT_PAR, ESS356, ERRZERO,
261                  "Entity and instance already registered");
262
263       /* ss025.103 - Addition of unlock around counting semaphore */
264       if ( SUnlock(&osCp.sTskTblLock) != ROK)
265       {
266 #if (ERRCLASS & ERRCLS_DEBUG)
267          SSLOGERROR(ERRCLS_DEBUG, ESS357, ERRZERO,
268                          "Could not give the Semaphore");
269          RETVALUE(RFAILED);
270 #endif
271       }
272
273       RETVALUE(RFAILED);
274    }
275 #endif
276
277    tTsk = &osCp.tTskTbl[osCp.nxtTTskEntry];
278
279    tTsk->used     = TRUE;
280    tTsk->ent      = ent;
281    tTsk->inst     = inst;
282    tTsk->tskType  = (Ttype)NULLD;
283    tTsk->tskPrior = (Prior)NULLD;
284    tTsk->initTsk  = initFnct;
285    tTsk->actvTsk  = (ActvTsk)NULLP;
286    tTsk->sTsk     = NULLP;
287
288    osCp.tTskIds[ent][inst] = osCp.nxtTTskEntry;
289    osCp.nxtTTskEntry = tTsk->nxt;
290    osCp.numTTsks++;
291
292    /* Activate initialization function, if present. Like
293     *  SRegInit(), we use hard-coded parameters. Note: we
294     *  assume that the initialization function is not
295     *  going to call SRegTTsk() or SPstTsk(). If it does,
296     *  this thread will freeze up as we are holding the
297     *  TAPA task table counting semaphore.
298     */
299    /* ss024.103 - Modification for memory calculator tool */
300 #ifndef USE_MEMCAL
301    (Void)(*initFnct)(ent, inst, DFLT_REGION, PWR_UP);
302 #else
303    (Void)(*initFnct)(ent, inst, SS_STATIC_REGION, PWR_UP);
304 #endif /* USE_MEMCAL */
305
306    /* unlock the table */
307    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
308
309    /* ss025.103 - Addition of unlock around counting semaphore */
310    if ( SUnlock(&osCp.sTskTblLock) != ROK)
311    {
312 #if (ERRCLASS & ERRCLS_DEBUG)
313       SSLOGERROR(ERRCLS_DEBUG, ESS358, ERRZERO,
314                       "Could not give the Semaphore");
315       RETVALUE(RFAILED);
316 #endif
317    }
318
319    RETVALUE(ROK);
320 } /* SRegInit */
321
322
323 \f
324 /*
325 *
326 *       Fun:   SRegActvTsk
327 *
328 *       Desc:  This function is used to register an activation function
329 *              for the layer. The system services will invoke the
330 *              function passed to it whenever a task buffer is received.
331 *              The activation function will be used by the layer to receive
332 *              messages from other entities.  It allows a priority to be
333 *              associated with the task so that it can be preempted if
334 *              necessary.
335 *
336 *       Ret:   ROK      - ok
337 *              RFAILED  - failed, general (optional)
338 *              ROUTRES  - failed, out of resources (optional)
339 *
340 *       Notes: We pass NULLP for the initialization function, because
341 *              it is assumed that whoever is using this call will also
342 *              be calling SRegInit().
343 *
344 *       File:  ss_task.c
345 *
346 */
347 #ifdef ANSI
348 PUBLIC S16 SRegActvTsk
349 (
350 Ent ent,                       /* entity */
351 Inst inst,                     /* instance */
352 Ttype ttype,                   /* task type */
353 Prior prior,                   /* task priority */
354 ActvTsk actvTsk                /* activate task function */
355 )
356 #else
357 PUBLIC S16 SRegActvTsk(ent, inst, ttype, prior, actvTsk)
358 Ent ent;                       /* entity */
359 Inst inst;                     /* instance */
360 Ttype ttype;                   /* task type */
361 Prior prior;                   /* task priority */
362 ActvTsk actvTsk;               /* activate task function */
363 #endif
364 {
365    S16 ret;
366    SSTskId sTskId;
367    Prior spri;
368    /* ss021.103 - Addition for pointer */
369    SsTTskEntry *tTsk;
370
371    TRC1(SRegActvTsk);
372
373
374 #if (ERRCLASS & ERRCLS_INT_PAR)
375    /* check entity and instance ranges */
376    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
377    {
378       SSLOGERROR(ERRCLS_INT_PAR, ESS359, ERRZERO, "Invalid entity/instance");
379       RETVALUE(RFAILED);
380    }
381
382    /* check activation function */
383    if (actvTsk == NULLP)
384    {
385       SSLOGERROR(ERRCLS_INT_PAR, ESS360, ERRZERO, "Null pointer");
386       RETVALUE(RFAILED);
387    }
388
389    /* check task type */
390    if (ttype != TTNORM  &&  ttype != TTPERM)
391    {
392       SSLOGERROR(ERRCLS_INT_PAR, ESS361, ERRZERO, "Invalid task type");
393       /* ss021.103 - Addition of return fail for invalid task type */
394       RETVALUE(RFAILED);
395    }
396
397    /* check task priority */
398    if (prior > PRIOR3)
399    {
400       SSLOGERROR(ERRCLS_INT_PAR, ESS362, ERRZERO, "Invalid task priority");
401       RETVALUE(RFAILED);
402    }
403 #endif
404
405    /* lock system task table */
406    ret = SLock(&osCp.sTskTblLock);
407    if (ret != ROK)
408    {
409       SSLOGERROR(ERRCLS_DEBUG, ESS363, ERRZERO,
410                      "Could not lock system task table");
411       RETVALUE(RFAILED);
412    }
413
414    /* lock TAPA task table */
415    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
416    if (ret != ROK)
417    {
418       if ( SUnlock(&osCp.sTskTblLock) != ROK)
419       {
420 #if (ERRCLASS & ERRCLS_DEBUG)
421          SSLOGERROR(ERRCLS_DEBUG, ESS364, ERRZERO,
422                          "Could not give the Semaphore");
423          RETVALUE(RFAILED);
424 #endif
425       }
426  
427       SSLOGERROR(ERRCLS_DEBUG, ESS365, ERRZERO,
428                      "Could not lock TAPA task table");
429       RETVALUE(RFAILED);
430    }
431    /* ss021.103 - Modification for SRegInit not called yet */
432    /* check if entity and instance already registered */
433    if (osCp.tTskIds[ent][inst] == SS_TSKNC)
434    {
435
436 #if (ERRCLASS & ERRCLS_INT_PAR)
437       /* check count of tasks */
438       if (osCp.numTTsks == SS_MAX_TTSKS)
439       {
440          SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
441
442          /* ss025.103 - Addition of unlock around counting semaphore */
443          if ( SUnlock(&osCp.sTskTblLock) != ROK)
444          {
445 #if (ERRCLASS & ERRCLS_DEBUG)
446             SSLOGERROR(ERRCLS_DEBUG, ESS366, ERRZERO,
447                          "Could not give the Semaphore");
448             RETVALUE(RFAILED);
449 #endif
450          }
451          SSLOGERROR(ERRCLS_INT_PAR, ESS367, ERRZERO, "Too many tasks");
452          RETVALUE(ROUTRES);
453       }
454 #endif
455
456       tTsk = &osCp.tTskTbl[osCp.nxtTTskEntry];
457       tTsk->used     = TRUE;
458       tTsk->ent      = ent;
459       tTsk->inst     = inst;
460       tTsk->initTsk  = (PAIFS16)NULLP;
461       tTsk->actvTsk  = (ActvTsk)NULLP;
462       tTsk->sTsk     = NULLP;
463
464       osCp.tTskIds[ent][inst] = osCp.nxtTTskEntry;
465       osCp.nxtTTskEntry = tTsk->nxt;
466       osCp.numTTsks++;
467    }
468
469
470    /* check and bump the priority if it is a permanent task */
471    if(ttype == TTPERM)
472    {
473       prior = PRIOR3;
474    }
475
476    /* ss021.103 - Modification to register task information */
477    /*  We fill up the current available slot with all the
478     *  information we've been given. Update table information,
479     *  and the task is registered.
480     */
481
482    tTsk = &osCp.tTskTbl[osCp.tTskIds[ent][inst]];
483    
484 #if (ERRCLASS & ERRCLS_INT_PAR)
485    if (tTsk->actvTsk != (ActvTsk)NULLP)
486    {
487       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
488
489       if ( SUnlock(&osCp.sTskTblLock) != ROK)
490       {
491 #if (ERRCLASS & ERRCLS_DEBUG)
492          SSLOGERROR(ERRCLS_DEBUG, ESS368, ERRZERO,
493                     "Could not give the Semaphore");
494          RETVALUE(RFAILED);
495 #endif
496       }
497
498       SSLOGERROR(ERRCLS_INT_PAR, ESS369, ERRZERO, 
499                  "ActvTask already registered");
500       RETVALUE(RFAILED);
501    }
502 #endif
503
504    tTsk->tskType  = ttype;
505    tTsk->tskPrior = prior;
506    tTsk->actvTsk  = actvTsk;
507
508    /* unlock the table */
509    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
510
511    if ( SUnlock(&osCp.sTskTblLock) != ROK)
512    {
513 #if (ERRCLASS & ERRCLS_DEBUG)
514       SSLOGERROR(ERRCLS_DEBUG, ESS370, ERRZERO,
515                       "Could not give the Semaphore");
516       RETVALUE(RFAILED);
517 #endif
518    }
519
520    /*  Now we create a system task--one per TAPA task is the
521     *  semantics of SRegActvTsk().
522     */
523    if (ttype == TTNORM)
524       spri = SS_NORM_TSK_PRI;
525    else
526       spri = SS_PERM_TSK_PRI;
527
528    ret = SCreateSTsk(spri, &sTskId);
529    if (ret != ROK)
530    {
531
532 #if (ERRCLASS & ERRCLS_DEBUG)
533       SSLOGERROR(ERRCLS_DEBUG, ESS371, (ErrVal) ret,
534                      "Could not create system task");
535 #endif
536
537       SDeregTTsk(ent, inst);
538       RETVALUE(ret);
539    }
540
541
542    /*  Attach the TAPA task we just registered, to the system
543     *  task we just created.
544     */
545    ret = SAttachTTsk(ent, inst, sTskId);
546    if (ret != ROK)
547    {
548
549 #if (ERRCLASS & ERRCLS_DEBUG)
550       SSLOGERROR(ERRCLS_DEBUG, ESS372, (ErrVal) ret,
551                      "Could not attach TAPA task to system task");
552 #endif
553       SDestroySTsk(sTskId);
554       SDeregTTsk(ent, inst);
555    }
556
557
558    RETVALUE(ret);
559
560 } /* SRegActvTsk */
561  
562 \f
563 /*
564 *
565 *       Fun:   Deregister Initialize, task buffer and timer
566 *
567 *       Desc:  This function is used to deregister the initialization,
568 *              activation and timer functions for a task.
569 *
570 *       Ret:   ROK      - ok
571 *
572 *       Notes: None.
573 *
574 *       File:  ss_task.c
575 *
576 */
577 #ifdef ANSI
578 PUBLIC S16 SDeregInitTskTmr
579 (
580 Ent ent,                       /* entity */
581 Inst inst                      /* instance */
582 )
583 #else
584 PUBLIC S16 SDeregInitTskTmr(ent, inst)
585 Ent ent;                       /* entity */
586 Inst inst;                     /* instance */
587 #endif
588 {
589    SsTTskEntry *tTsk;
590    SsSTskEntry *sTsk;
591    S16         ret;
592    SSTskId     sTskId;
593    SsIdx       idx;
594    Bool        destroySTsk;
595
596
597    TRC1(SDeregInitTskTmr);
598
599
600 #if (ERRCLASS & ERRCLS_INT_PAR)
601    /* check entity and instance ranges */
602    if (ent >= SS_MAX_ENT  ||  inst >= SS_MAX_INST)
603    {
604       SSLOGERROR(ERRCLS_INT_PAR, ESS373, ERRZERO, "Invalid entity/instance");
605       RETVALUE(RFAILED);
606    }
607 #endif
608
609    /* ss025.103 - Addition of lock around counting semaphore */
610    /* lock system task table */
611    ret = SLock(&osCp.sTskTblLock);
612    if (ret != ROK)
613    {
614       SSLOGERROR(ERRCLS_DEBUG, ESS374, ERRZERO,
615                      "Could not lock system task table");
616       RETVALUE(RFAILED);
617    }
618
619    /* lock the TAPA task table */
620    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
621    if (ret != ROK)
622    {
623
624 #if (ERRCLASS & ERRCLS_DEBUG)
625       SSLOGERROR(ERRCLS_DEBUG, ESS375, ERRZERO,
626                      "Could not lock TAPA task table");
627 #endif
628
629       RETVALUE(RFAILED);
630    }
631
632
633 #if (ERRCLASS & ERRCLS_INT_PAR)
634    /* check whether this entity is registered */
635    if (osCp.tTskIds[ent][inst] == SS_TSKNC)
636    {
637       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
638       SSLOGERROR(ERRCLS_INT_PAR, ESS376, ERRZERO, "Unknown task");
639
640       /* ss025.103 - Addition of unlock around counting semaphore */
641       if ( SUnlock(&osCp.sTskTblLock) != ROK)
642       {
643 #if (ERRCLASS & ERRCLS_DEBUG)
644          SSLOGERROR(ERRCLS_DEBUG, ESS377, ERRZERO,
645                          "Could not give the Semaphore");
646          RETVALUE(RFAILED);
647 #endif
648       }
649
650       RETVALUE(RFAILED);
651    }
652 #endif
653
654
655    /* get out the TAPA task entry */
656    tTsk = &osCp.tTskTbl[osCp.tTskIds[ent][inst]];
657
658    /* get out the system task that's running this TAPA task */
659    sTsk = tTsk->sTsk;
660
661    /* get out the ID of this system task */
662    if (sTsk != NULLP)
663    {
664       sTskId = sTsk->tskId;
665    }
666    else 
667       sTskId = 0;
668
669    /* unlock the TAPA task table */
670    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
671
672    /* ss025.103 - Addition of unlock around counting semaphore */
673    if ( SUnlock(&osCp.sTskTblLock) != ROK)
674    {
675 #if (ERRCLASS & ERRCLS_DEBUG)
676       SSLOGERROR(ERRCLS_DEBUG, ESS378, ERRZERO,
677                       "Could not give the Semaphore");
678       RETVALUE(RFAILED);
679 #endif
680    }
681
682
683    /* deregister the TAPA task */
684    if (SDeregTTsk(ent, inst) != ROK)
685    {
686       RETVALUE(RFAILED);
687    }
688
689
690    /* Now, if the TAPA task was attached, and nobody else is using that
691     *  system task, we should destroy it.
692     */
693    if (sTsk != NULLP)
694    {
695       destroySTsk = FALSE;
696
697       /* lock the system task table */
698       ret = SLock(&osCp.sTskTblLock);
699       if (ret != ROK)
700       {
701
702 #if (ERRCLASS & ERRCLS_DEBUG)
703          SSLOGERROR(ERRCLS_DEBUG, ESS379, (ErrVal) ret,
704                         "Could not lock system task table");
705 #endif
706
707          RETVALUE(RFAILED);
708       }
709
710       idx = (SsIdx) sTskId;
711       sTsk = &osCp.sTskTbl[idx];
712
713       /* check if the system task is still around */
714       if (sTsk->used != TRUE)
715       {
716
717 /* ss006.13: addition */
718          if ( SUnlock(&osCp.sTskTblLock) != ROK)
719          {
720 #if (ERRCLASS & ERRCLS_DEBUG)
721             SSLOGERROR(ERRCLS_DEBUG, ESS380, ERRZERO,
722                          "Could not give the Semaphore");
723             RETVALUE(RFAILED);
724 #endif
725          }
726
727          RETVALUE(ROK);
728       }
729
730       /* check if the system task is dying already */
731       if (sTsk->termPend)
732       {
733
734   /* ss006.13: addition */
735          if ( SUnlock(&osCp.sTskTblLock) != ROK)
736          {
737 #if (ERRCLASS & ERRCLS_DEBUG)
738             SSLOGERROR(ERRCLS_DEBUG, ESS381, ERRZERO,
739                          "Could not give the Semaphore");
740             RETVALUE(RFAILED);
741 #endif
742          }
743          RETVALUE(ROK);
744       }
745
746
747       /* If this system task entry has no more TAPA tasks attached,
748        *  we destroy it, otherwise we do nothing.
749        */
750       if (sTsk->numTTsks == 0)
751       {
752          sTsk->termPend = TRUE;
753          destroySTsk = TRUE;
754       }
755
756
757       /* unlock */
758
759   /* ss006.13: addition */
760       if ( SUnlock(&osCp.sTskTblLock) != ROK)
761       {
762 #if (ERRCLASS & ERRCLS_DEBUG)
763           SSLOGERROR(ERRCLS_DEBUG, ESS382, ERRZERO,
764                       "Could not give the Semaphore");
765           RETVALUE(RFAILED);
766 #endif
767       }
768
769       /* If we're destroying the system task, ask the implementation
770        *  to do it.
771        */
772       if (destroySTsk)
773       {
774          ret = ssdDestroySTsk(sTsk);
775          if (ret != ROK)
776          {
777             /* oops? */
778
779 #if (ERRCLASS & ERRCLS_DEBUG)
780             SSLOGERROR(ERRCLS_DEBUG, ESS383, (ErrVal) ret,
781                         "Could not destroy system task");
782 #endif
783
784             RETVALUE(RFAILED);
785          }
786       }
787    }
788
789
790    RETVALUE(ROK);
791 } /* SDeregInitTskTmr */
792
793 #endif /* SS_MULTIPLE_PROCS */
794
795 \f
796 /*
797 *
798 *       Fun:   Register a TAPA task
799 *
800 *       Desc:  This function is used to register a TAPA task,
801 *              and its initialization and activation functions.
802 *
803 *       Ret:   ROK      - ok
804 *              RFAILED  - failed, general (optional)
805 *              ROUTRES  - failed, out of resources (optional)
806 *
807 *       Notes:
808 *
809 *       File:  ss_task.c
810 *
811 */
812 /* ss029.103: modification: procId added */ 
813 #ifndef SS_MULTIPLE_PROCS
814
815 #ifdef ANSI
816 PUBLIC S16 SRegTTsk
817 (
818 Ent ent,                        /* entity */
819 Inst inst,                      /* instance */
820 Ttype type,                     /* task type */
821 Prior prior,                    /* task priority */
822 PAIFS16 initTsk,                /* initialization function */
823 ActvTsk actvTsk                 /* activation function */
824 )
825 #else
826 PUBLIC S16 SRegTTsk(ent, inst, type, prior, initTsk, actvTsk)
827 Ent ent;                        /* entity */
828 Inst inst;                      /* instance */
829 Ttype type;                     /* task type */
830 Prior prior;                    /* task priority */
831 PAIFS16 initTsk;                /* initialization function */
832 ActvTsk actvTsk;                /* activation function */
833 #endif
834
835 #else /* SS_MULTIPLE_PROCS */
836
837 #ifdef ANSI
838 PUBLIC S16 SRegTTsk
839 (
840 ProcId proc,                    /* processor */
841 Ent ent,                        /* entity */
842 Inst inst,                      /* instance */
843 Ttype type,                     /* task type */
844 Prior prior,                    /* task priority */
845 PAIFS16 initTsk,                /* initialization function */
846 ActvTsk actvTsk                 /* activation function */
847 )
848 #else
849 PUBLIC S16 SRegTTsk(proc, ent, inst, type, prior, initTsk, actvTsk)
850 ProcId proc;                    /* processor */
851 Ent ent;                        /* entity */
852 Inst inst;                      /* instance */
853 Ttype type;                     /* task type */
854 Prior prior;                    /* task priority */
855 PAIFS16 initTsk;                /* initialization function */
856 ActvTsk actvTsk;                /* activation function */
857 #endif
858
859 #endif /* SS_MULTIPLE_PROCS */
860
861 {
862    S16 ret = ROK;
863    SsTTskEntry *tTsk;
864 /* ss029.103: addition: multiple procIds related changes */ 
865 #ifdef SS_MULTIPLE_PROCS
866    U16 procIdIdx;
867 #endif
868
869    TRC1(SRegTTsk);
870
871
872 #if (ERRCLASS & ERRCLS_INT_PAR)
873
874    /* check entity and instance ranges */
875 /* ss029.103: addition: multiple procIds related changes */ 
876 #ifdef SS_MULTIPLE_PROCS
877    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
878    {
879       SSLOGERROR(ERRCLS_INT_PAR, ESS384, ERRZERO, "Invalid proc/entity/instance");
880       RETVALUE(RFAILED);
881    }
882 #else /* SS_MULTIPLE_PROCS */
883    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
884    {
885       SSLOGERROR(ERRCLS_INT_PAR, ESS385, ERRZERO, "Invalid entity/instance");
886       RETVALUE(RFAILED);
887    }
888 #endif /* SS_MULTIPLE_PROCS */
889
890    /* check activation function */
891    if (actvTsk == NULLP)
892    {
893       SSLOGERROR(ERRCLS_INT_PAR, ESS386, ERRZERO, "Null pointer");
894       RETVALUE(RFAILED);
895    }
896
897    /* check task type */
898    if (type != TTNORM  &&  type != TTPERM)
899    {
900       SSLOGERROR(ERRCLS_INT_PAR, ESS387, ERRZERO, "Invalid task type");
901       /* ss021.103 - Addition of return fail for invalid task type */
902       RETVALUE(RFAILED);
903    }
904
905    /* check task priority */
906    if (prior > PRIOR3)
907    {
908       SSLOGERROR(ERRCLS_INT_PAR, ESS388, ERRZERO, "Invalid task priority");
909       RETVALUE(RFAILED);
910    }
911 #endif
912
913 /* ss029.103: addition: multiple procIds related changes */ 
914 #ifdef SS_MULTIPLE_PROCS
915    /* retrieve proc id index in the proc id table */
916    procIdIdx = SGetProcIdIdx(proc); 
917
918    /* Check whether the proc id exist in the proc id table */
919    if (procIdIdx == SS_INV_PROCID_IDX)
920    {
921 #if (ERRCLASS & ERRCLS_INT_PAR)
922        SSLOGERROR(ERRCLS_INT_PAR, ESS389, ERRZERO,
923                      "Could not find proc table index");
924 #endif
925
926       RETVALUE(RFAILED);
927    }
928 #endif /* SS_MULTIPLE_PROCS */
929
930
931
932    /* Acquire the counting semaphore for all other system
933     *  tasks (this call is either running in one system task's
934     *  context, or in SInit()'s context). Once we have all of
935     *  them, SPstTsk() cannot run, so we can do things to the
936     *  TAPA task table.
937     */
938
939    /* ss025.103 - Addition of lock around counting semaphore */
940    /* lock system task table */
941    ret = SLock(&osCp.sTskTblLock);
942    if (ret != ROK)
943    {
944       SSLOGERROR(ERRCLS_DEBUG, ESS390, ERRZERO,
945                      "Could not lock system task table");
946       RETVALUE(RFAILED);
947    }
948
949    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
950    if (ret != ROK)
951    {
952
953 #if (ERRCLASS & ERRCLS_DEBUG)
954       SSLOGERROR(ERRCLS_DEBUG, ESS391, ERRZERO,
955                      "Could not lock TAPA task table");
956 #endif
957
958       /* ss025.103 - Addition of unlock around counting semaphore */
959       if ( SUnlock(&osCp.sTskTblLock) != ROK)
960       {
961 #if (ERRCLASS & ERRCLS_DEBUG)
962          SSLOGERROR(ERRCLS_DEBUG, ESS392, ERRZERO,
963                       "Could not give the Semaphore");
964          RETVALUE(RFAILED);
965 #endif
966       }
967
968       RETVALUE(RFAILED);
969    }
970
971
972 #if (ERRCLASS & ERRCLS_DEBUG)
973    /* check count of tasks */
974    if (osCp.numTTsks == SS_MAX_TTSKS)
975    {
976       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
977       SSLOGERROR(ERRCLS_DEBUG, ESS393, ERRZERO, "Too many tasks");
978
979       /* ss025.103 - Addition of unlock around counting semaphore */
980       if ( SUnlock(&osCp.sTskTblLock) != ROK)
981       {
982 #if (ERRCLASS & ERRCLS_DEBUG)
983          SSLOGERROR(ERRCLS_DEBUG, ESS394, ERRZERO,
984                       "Could not give the Semaphore");
985          RETVALUE(RFAILED);
986 #endif
987       }
988
989       RETVALUE(ROUTRES);
990    }
991
992    /* check if entity and instance already registered */
993 /* ss029.103: addition: multiple procIds related changes */ 
994 #ifdef SS_MULTIPLE_PROCS
995    if (osCp.tTskIds[procIdIdx][ent][inst] != SS_TSKNC)
996 #else
997    if (osCp.tTskIds[ent][inst] != SS_TSKNC)
998 #endif /* SS_MULTIPLE_PROCS */
999    {
1000       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1001       SSLOGERROR(ERRCLS_DEBUG, ESS395, ERRZERO,
1002                   "Entity and instance already registered");
1003
1004       /* ss025.103 - Addition of unlock around counting semaphore */
1005       if ( SUnlock(&osCp.sTskTblLock) != ROK)
1006       {
1007 #if (ERRCLASS & ERRCLS_DEBUG)
1008          SSLOGERROR(ERRCLS_DEBUG, ESS396, ERRZERO,
1009                       "Could not give the Semaphore");
1010          RETVALUE(RFAILED);
1011 #endif
1012       }
1013
1014       RETVALUE(RFAILED);
1015    }
1016 #endif
1017
1018
1019    /*  We fill up the current available slot with all the
1020     *  information we've been given. Update table information,
1021     *  and the task is registered.
1022     */
1023    tTsk = &osCp.tTskTbl[osCp.nxtTTskEntry];
1024    tTsk->used     = TRUE;
1025 /* ss029.103: addition: procId added */ 
1026 #ifdef SS_MULTIPLE_PROCS
1027    tTsk->proc     = proc;
1028 #endif /* SS_MULTIPLE_PROCS */
1029    tTsk->ent      = ent;
1030    tTsk->inst     = inst;
1031    tTsk->tskType  = type;
1032    tTsk->tskPrior = prior;
1033    tTsk->initTsk  = initTsk;
1034    tTsk->actvTsk  = actvTsk;
1035    tTsk->sTsk     = NULLP;
1036
1037 /* ss001.301: additions */
1038 #ifdef SS_HISTOGRAM_SUPPORT 
1039    tTsk->hstReg   = 0;
1040 #endif /* SS_HISTOGRAM_SUPPORT */
1041
1042 /* ss029.103: addition: multiple procIds related changes */ 
1043 #ifdef SS_MULTIPLE_PROCS
1044    osCp.tTskIds[procIdIdx][ent][inst] = osCp.nxtTTskEntry;
1045 #else
1046    osCp.tTskIds[ent][inst] = osCp.nxtTTskEntry;
1047 #endif /* SS_MULTIPLE_PROCS */
1048    osCp.nxtTTskEntry = tTsk->nxt;
1049    osCp.numTTsks++;
1050
1051
1052    /* Activate initialization function, if present. Like
1053     *  SRegInit(), we use hard-coded parameters. Note: we
1054     *  assume that the initialization function is not
1055     *  going to call SRegTTsk() or SPstTsk(). If it does,
1056     *  this thread will freeze up as we are holding the
1057     *  TAPA task table counting semaphore.
1058     */
1059    /* ss024.103 - Modification for memory calculator tool */
1060    if (initTsk != NULLP)
1061    {
1062 /* ss029.103: addition: multiple procIds related changes */ 
1063 #ifdef SS_MULTIPLE_PROCS
1064       SsIdx idx;
1065       Void *xxCb = NULLP;
1066 #endif /* SS_MULTIPLE_PROCS */
1067
1068 /* ss029.103: addition: multiple procIds related changes */ 
1069 #ifndef SS_MULTIPLE_PROCS
1070
1071 #ifndef USE_MEMCAL
1072 #ifndef SS_MULTICORE_SUPPORT
1073       (Void)(*initTsk)(ent, inst, DFLT_REGION, PWR_UP);
1074 #endif
1075 #else
1076       (Void)(*initTsk)(ent, inst, SS_STATIC_REGION, PWR_UP);
1077 #endif /* USE_MEMCAL */
1078
1079 #else /* SS_MULTIPLE_PROCS */
1080
1081 #ifndef USE_MEMCAL
1082 #ifndef SS_MULTICORE_SUPPORT
1083       (Void)(*initTsk)(proc, ent, inst, DFLT_REGION, PWR_UP, &xxCb);
1084 #endif /* SS_MULTICORE_SUPPORT */
1085 #else
1086       (Void)(*initTsk)(proc, ent, inst, SS_STATIC_REGION, PWR_UP, &xxCb);
1087 #endif /* USE_MEMCAL */
1088
1089       /*
1090        * store the control block. The control block may be NULL in some cases
1091        */
1092       idx = osCp.tTskIds[procIdIdx][ent][inst]; 
1093
1094       osCp.tTskTbl[idx].xxCb = xxCb;
1095
1096       /* ss032.103 do a debug print if xxCb is NULLP */
1097       if (xxCb == NULLP)
1098       {
1099          SSLOGERROR(ERRCLS_INT_PAR, ERRZERO, ERRZERO, "Null pointer");
1100       }
1101 #endif /* SS_MULTIPLE_PROCS */
1102    }
1103
1104    /* unlock the table */
1105    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1106
1107    /* ss025.103 - Addition of unlock around counting semaphore */
1108    if ( SUnlock(&osCp.sTskTblLock) != ROK)
1109    {
1110 #if (ERRCLASS & ERRCLS_DEBUG)
1111       SSLOGERROR(ERRCLS_DEBUG, ESS397, ERRZERO,
1112                       "Could not give the Semaphore");
1113 #endif
1114       RETVALUE(RFAILED);
1115    }
1116
1117    RETVALUE(ROK);
1118 } /* SRegTTsk */
1119  /* ss002.301 Additions */
1120 /*
1121 *
1122 *       Fun:   Register a call back function with SSI
1123 *
1124 *       Desc:  This function is used to register a callback function
1125 *              
1126 *
1127 *       Ret:   ROK      - ok
1128 *              RFAILED  - failed, general (optional)
1129 *
1130 *       Notes:
1131 *
1132 *       File:  sm_task.c
1133 *
1134 **/
1135 #ifndef SS_MULTIPLE_PROCS
1136 #ifdef ANSI
1137 PUBLIC S16 SRegCbTsk
1138 (
1139 Ent ent,                        /* entity */
1140 Inst inst,                      /* instance */
1141 ActvTsk cbTsk                   /* Callback Function */
1142 )
1143 #else
1144 PUBLIC S16 SRegCbTsk(ent, inst, cbTsk)
1145 Ent ent;                        /* entity */
1146 Inst inst;                      /* instance */
1147 ActvTsk cbTsk;
1148 #endif
1149
1150 #else /* SS_MULTIPLE_PROCS */
1151
1152 #ifdef ANSI
1153 PUBLIC S16 SRegCbTsk 
1154 (
1155 ProcId proc,                    /* processor */
1156 Ent ent,                        /* entity */
1157 Inst inst,                       /* instance */
1158 ActvTsk cbTsk 
1159 )
1160 #else
1161 PUBLIC S16 SRegCbTsk(proc, ent, inst, cbTsk)
1162 ProcId proc;                    /* processor */
1163 Ent ent;                        /* entity */
1164 Inst inst;                      /* instance */
1165 ActvTsk cbTsk;
1166 #endif
1167 #endif /* SS_MULTIPLE_PROCS */
1168 {
1169    SsTTskEntry *tTsk;
1170    SsIdx idx;
1171         S16   ret = ROK;
1172 #ifdef SS_MULTIPLE_PROCS
1173    U16 procIdIdx;
1174 #endif /* SS_MULTIPLE_PROCS */
1175
1176    TRC1(SRegCbTsk);
1177
1178 #if (ERRCLASS & ERRCLS_INT_PAR)
1179    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
1180    {
1181       SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRegCbTsk() : Invalid entity/instance");
1182       RETVALUE(RFAILED);
1183    }
1184
1185    if (cbTsk == NULLP)
1186    {
1187       SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, " SRegCbTsk() : Null pointer");
1188       RETVALUE(RFAILED);
1189    }
1190 #endif
1191
1192 #ifdef SS_MULTIPLE_PROCS
1193    /* retrieve proc id index in the proc id table */
1194    procIdIdx = SGetProcIdIdx(proc); 
1195
1196    /* Check whether the proc id exist in the proc id table */
1197    if (procIdIdx == SS_INV_PROCID_IDX)
1198    {
1199 #if (ERRCLASS & ERRCLS_INT_PAR)
1200        SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO,
1201                      " SRegCbTsk() : Could not find proc table index");
1202 #endif
1203
1204       RETVALUE(RFAILED);
1205    }
1206 #endif /* SS_MULTIPLE_PROCS */
1207
1208    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
1209    if (ret != ROK)
1210    {
1211
1212 #if (ERRCLASS & ERRCLS_DEBUG)
1213       SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
1214                      "SRegCbTsk() : Could not lock TAPA task table");
1215 #endif
1216       RETVALUE(RFAILED);
1217    }
1218
1219 #ifdef SS_MULTIPLE_PROCS
1220    idx = osCp.tTskIds[procIdIdx][ent][inst];
1221 #else /* SS_MULTIPLE_PROCS */
1222    idx = osCp.tTskIds[ent][inst];
1223 #endif /* SS_MULTIPLE_PROCS */
1224
1225 #if (ERRCLASS & ERRCLS_INT_PAR)
1226    if (idx == SS_TSKNC)
1227    {
1228       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1229       SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRegCbTsk() : Unknown task");
1230       RETVALUE(RFAILED);
1231    }
1232 #endif
1233    tTsk = &osCp.tTskTbl[idx];
1234    tTsk->cbTsk  = cbTsk;
1235
1236    /* unlock the table */
1237    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1238    RETVALUE(ROK);
1239 }
1240
1241 \f
1242 /*
1243 *
1244 *       Fun:   Deregister TAPA task
1245 *
1246 *       Desc:  This function is used to deregister a TAPA task.
1247 *              All information about the task is removed from the
1248 *              task table.
1249 *
1250 *       Ret:   ROK      - ok
1251 *              RFAILED  - failed, general (optional)
1252 *
1253 *       Notes:
1254 *
1255 *       File:  ss_task.c
1256 *
1257 */
1258 /* ss029.103: addition: procId added */ 
1259 #ifndef SS_MULTIPLE_PROCS
1260
1261 #ifdef ANSI
1262 PUBLIC S16 SDeregTTsk
1263 (
1264 Ent ent,                        /* entity */
1265 Inst inst                       /* instance */
1266 )
1267 #else
1268 PUBLIC S16 SDeregTTsk(ent, inst)
1269 Ent ent;                        /* entity */
1270 Inst inst;                      /* instance */
1271 #endif
1272
1273 #else /* SS_MULTIPLE_PROCS */
1274
1275 #ifdef ANSI
1276 PUBLIC S16 SDeregTTsk
1277 (
1278 ProcId proc,                    /* processor */
1279 Ent ent,                        /* entity */
1280 Inst inst                       /* instance */
1281 )
1282 #else
1283 PUBLIC S16 SDeregTTsk(proc, ent, inst)
1284 ProcId proc;                    /* processor */
1285 Ent ent;                        /* entity */
1286 Inst inst;                      /* instance */
1287 #endif
1288 #endif /* SS_MULTIPLE_PROCS */
1289 {
1290    S16          ret;
1291    /* ss029.103: modification: The subscript should be consistent type */
1292    SsIdx        idx;
1293    SsTTskEntry *tTsk;
1294    SsTmrEntry  *tmr;
1295 /* ss029.103: addition: multiple procIds related changes */ 
1296 #ifdef SS_MULTIPLE_PROCS
1297    U16 procIdIdx;
1298 #endif /* SS_MULTIPLE_PROCS */
1299  /* ss002.301 Additions */
1300    Buffer *mBuf;
1301    SsMsgInfo *mInfo;
1302
1303    TRC1(SDeregTTsk);
1304
1305
1306 #if (ERRCLASS & ERRCLS_INT_PAR)
1307    /* check entity and instance ranges */
1308 /* ss029.103: addition: multiple procIds related changes */ 
1309 #ifdef SS_MULTIPLE_PROCS
1310    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
1311    {
1312       SSLOGERROR(ERRCLS_INT_PAR, ESS398, ERRZERO, "Invalid processor/entity/instance");
1313       RETVALUE(RFAILED);
1314    }
1315 #else /* SS_MULTIPLE_PROCS */
1316    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
1317    {
1318       SSLOGERROR(ERRCLS_INT_PAR, ESS399, ERRZERO, "Invalid entity/instance");
1319       RETVALUE(RFAILED);
1320    }
1321 #endif /* SS_MULTIPLE_PROCS */
1322
1323 #endif
1324
1325 /* ss029.103: addition: multiple procIds related changes */ 
1326 #ifdef SS_MULTIPLE_PROCS
1327    /* Find the proc table index */
1328    procIdIdx = SGetProcIdIdx(proc);
1329
1330    if (procIdIdx == SS_INV_PROCID)
1331    {
1332 #if (ERRCLASS & ERRCLS_DEBUG)
1333       SSLOGERROR(ERRCLS_DEBUG, ESS400, ERRZERO,
1334                              "Could not find proc id index");
1335 #endif
1336       RETVALUE(RFAILED);
1337    }
1338 #endif /* SS_MULTIPLE_PROCS */
1339
1340    /* We deregister all timers for this TAPA task, since it's going
1341     *  away now. Lock the timer table and iterate through it, removing
1342     *  all timers owned by this task.
1343     */
1344    if (SLock(&osCp.tmrTblLock) != ROK)
1345    {
1346 #if (ERRCLASS & ERRCLS_DEBUG)
1347       SSLOGERROR(ERRCLS_DEBUG, ESS401, ERRZERO,
1348                              "Could not lock timer table");
1349 #endif
1350       RETVALUE(RFAILED);
1351    }
1352
1353    for (idx = 0;  idx < SS_MAX_TMRS;  idx++)
1354    {
1355 /* ss029.103: addition: multiple procIds related changes */ 
1356 #ifdef SS_MULTIPLE_PROCS
1357       if ((osCp.tmrTbl[idx].ownerProc == proc) &&  
1358           (osCp.tmrTbl[idx].ownerEnt == ent) &&  
1359           (osCp.tmrTbl[idx].ownerInst == inst))
1360 #else /* SS_MULTIPLE_PROCS */
1361       if ((osCp.tmrTbl[idx].ownerEnt == ent) &&  
1362           (osCp.tmrTbl[idx].ownerInst == inst))
1363 #endif /* SS_MULTIPLE_PROCS */
1364       {
1365          /* shut down this timer */
1366          tmr = &osCp.tmrTbl[idx];
1367          if (ssdDeregTmr(tmr) == ROK)
1368          {
1369             tmr->used      = FALSE;
1370             tmr->tmrId     = 0;
1371 /* ss029.103: addition: multiple procIds related changes */ 
1372 #ifdef SS_MULTIPLE_PROCS
1373             tmr->ownerProc  = PROCNC;
1374             /*
1375              *  ss015.301 - Modifed in initialization as timer activation 
1376              *  functions enclosed in a union. Also initialized the mtFlag
1377              *  to FALSE 
1378              */
1379 #endif /* SS_MULTIPLE_PROCS */
1380             tmr->ownerEnt  = ENTNC;
1381             tmr->ownerInst = INSTNC;
1382             tmr->interval  = 0;
1383             tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
1384 #ifndef SS_MULTIPLE_PROCS
1385 #ifdef SS_MT_TMR 
1386             tmr->ssTmrActvFn.mtFlag = FALSE; 
1387             tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
1388 #endif
1389 #endif
1390             tmr->nxt = osCp.nxtTmrEntry;
1391             osCp.nxtTmrEntry = (SsIdx)idx;
1392             osCp.numTmrs--;
1393          }
1394          else
1395          {
1396
1397   /* ss006.13: addition */
1398           if ( SUnlock(&osCp.tmrTblLock) != ROK)
1399           {
1400 #if (ERRCLASS & ERRCLS_DEBUG)
1401              SSLOGERROR(ERRCLS_DEBUG, ESS402, ERRZERO,
1402                       "Could not give the Semaphore");
1403              RETVALUE(RFAILED);
1404 #endif
1405           }
1406
1407 #if (ERRCLASS & ERRCLS_DEBUG)
1408             SSLOGERROR(ERRCLS_DEBUG, ESS403, ERRZERO,
1409                         "Could not deregister task's timer(s)");
1410 #endif
1411             RETVALUE(RFAILED);
1412
1413          }
1414       }
1415    }
1416
1417
1418   /* ss006.13: addition */
1419           if ( SUnlock(&osCp.tmrTblLock) != ROK)
1420           {
1421 #if (ERRCLASS & ERRCLS_DEBUG)
1422              SSLOGERROR(ERRCLS_DEBUG, ESS404, ERRZERO,
1423                       "Could not give the Semaphore");
1424              RETVALUE(RFAILED);
1425 #endif
1426           }
1427  /* ss002.301 Additions */
1428    /* Acquire the counting semaphore for all TAPA tasks. Once
1429     *  we have all of them, both SPstTsk() and SRegTTsk() cannot
1430     *  run, so we can do things to the TAPA task table.
1431     */
1432    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
1433    if (ret != ROK)
1434    {
1435  /* ss002.301 Additions */
1436
1437 #if (ERRCLASS & ERRCLS_DEBUG)
1438       SSLOGERROR(ERRCLS_DEBUG, ESS411, ERRZERO,
1439                      "Could not lock TAPA task table");
1440 #endif
1441
1442       RETVALUE(RFAILED);
1443    }
1444
1445
1446    /* get out the TAPA task entry */
1447 /* ss029.103: addition: multiple procIds related changes */ 
1448 #ifdef SS_MULTIPLE_PROCS
1449    idx = osCp.tTskIds[procIdIdx][ent][inst];
1450 #else /* SS_MULTIPLE_PROCS */
1451    idx = osCp.tTskIds[ent][inst];
1452 #endif /* SS_MULTIPLE_PROCS */
1453
1454
1455    /* make sure this TAPA task exists */
1456    if (idx == SS_TSKNC)
1457    {
1458       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1459
1460       SSLOGERROR(ERRCLS_INT_PAR, ESS412, ERRZERO, "Unknown task");
1461  /* ss002.301 Additions */
1462       RETVALUE(RFAILED);
1463    }
1464
1465    tTsk = &osCp.tTskTbl[idx];
1466
1467    /* unlock the TAPA task table */
1468    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1469
1470    /*Check whether the thread calling this funtion is the same as the system task to which the 
1471      TAPA task detremined by passed entity and instance is attached*/
1472    /* 100178 */
1473    
1474 /*ss014.301 SSI-4GMX specific changes*/   
1475 #ifndef SS_4GMX_LCORE
1476    if((tTsk->sTsk == NULLP) || (SS_CHECK_CUR_STSK(tTsk->sTsk)))
1477    { 
1478 #ifdef SS_MULTIPLE_PROCS
1479       ssdProcTTskTerm(procIdIdx, tTsk, idx);
1480 #else
1481       ssdProcTTskTerm(tTsk, idx);
1482 #endif
1483
1484    }
1485    else
1486    {
1487         /*Allocate memory*/
1488         if (SGetMsg(SS_DFLT_REGION, SS_DFLT_POOL, &mBuf) != ROK)
1489         {
1490
1491 #if (ERRCLASS & ERRCLASS_DEBUG)
1492         SSLOGERROR(ERRCLS_DEBUG, ESS415, ERRZERO, "Could not get a message");
1493 #endif
1494
1495         RETVALUE(RFAILED);
1496         }
1497
1498         /* Update message*/
1499         mInfo = (SsMsgInfo *)mBuf->b_rptr;
1500         mInfo->eventInfo.event = SS_EVNT_TTSK_TERM;
1501
1502         mInfo->pst.dstEnt = ent;
1503         mInfo->pst.dstInst = inst;
1504
1505         /* we dont care who is calling SDeregTTsk()
1506         so we dont fill srcEnt and dstInst in mInfo->pst */
1507  
1508         /* mt028.201: modification: multiple procs support related changes */
1509         /* source proc id is not needed so we dont fill it */
1510 #ifndef SS_MULTIPLE_PROCS
1511         mInfo->pst.dstProcId = SFndProcId();
1512 #else /* SS_MULTIPLE_PROCS */
1513         mInfo->pst.dstProcId = proc;
1514 #endif /* SS_MULTIPLE_PROCS */
1515  /* ss002.301 Additions */
1516         mInfo->pst.selector = SEL_LC_NEW;
1517         mInfo->pst.region = DFLT_REGION;
1518         mInfo->pst.pool = DFLT_POOL;
1519         mInfo->pst.prior = PRIOR0;
1520         mInfo->pst.route = RTESPEC;
1521         mInfo->pst.event = 0;
1522    /* write the timer message to the queue of the destination task */
1523         if (ssDmndQPutLast(&tTsk->sTsk->dQ, mBuf,
1524                 (tTsk->tskPrior * SS_MAX_MSG_PRI) + PRIOR0) != ROK)
1525         {
1526         SS_RELEASE_SEMA(&osCp.tTskTblSem);
1527         SPutMsg(mBuf);
1528 #if (ERRCLASS & ERRCLS_DEBUG)
1529         SSLOGERROR(ERRCLS_INT_PAR, ESS416, ERRZERO, "Could not write to demand queue");
1530 #endif
1531         RETVALUE(RFAILED);
1532         }
1533    }
1534 #endif
1535
1536    RETVALUE(ROK);
1537 } /* SDeregTTsk */
1538
1539 \f
1540 /*
1541 *
1542 *       Fun:   Create system task
1543 *
1544 *       Desc:  This function is used to create a system task. An
1545 *              entry is located in the system task table and the
1546 *              implementation-specific function is called.
1547 *
1548 *       Ret:   ROK      - ok
1549 *              RFAILED  - failed, general (optional)
1550 *              ROUTRES  - failed, out of resources (optional)
1551 *
1552 *       Notes:
1553 *
1554 *       File:  ss_task.c
1555 *
1556 */
1557 #ifdef ANSI
1558 PUBLIC S16 SCreateSTsk
1559 (
1560 SSTskPrior tskPrior,            /* task priority */
1561 SSTskId *tskId                  /* filled in with system task ID */
1562 )
1563 #else
1564 PUBLIC S16 SCreateSTsk(tskPrior, tskId)
1565 SSTskPrior tskPrior;            /* task priority */
1566 SSTskId *tskId;                 /* filled in with system task ID */
1567 #endif
1568 {
1569    S16 ret;
1570    SsSTskEntry *sTsk;
1571
1572
1573    TRC1(SCreateSTsk);
1574
1575
1576 #if (ERRCLASS & ERRCLS_INT_PAR)
1577    /* check task ID pointer */
1578    if (tskId == NULLP)
1579    {
1580       SSLOGERROR(ERRCLS_INT_PAR, ESS417, ERRZERO, "Null pointer");
1581       RETVALUE(RFAILED);
1582    }
1583
1584    /* check system task priority */
1585    if (tskPrior > SS_LOWEST_STSK_PRIOR)
1586    {
1587       SSLOGERROR(ERRCLS_INT_PAR, ESS418, ERRZERO,
1588                      "Invalid system task priority");
1589       RETVALUE(RFAILED);
1590    }
1591 #endif
1592
1593
1594    /* lock the system task table */ 
1595    ret = SLock(&osCp.sTskTblLock);
1596    if (ret != ROK)
1597    {
1598
1599 #if (ERRCLASS & ERRCLS_DEBUG)
1600       SSLOGERROR(ERRCLS_DEBUG, ESS419, (ErrVal) ret,
1601                      "Could not lock system task table");
1602 #endif
1603
1604       RETVALUE(RFAILED);
1605    }
1606
1607
1608 #ifdef SS_SINGLE_THREADED
1609    /* When singlethreaded, we only need to create one... */
1610 /* ss001.301: additions */
1611 #ifndef SS_WATCHDOG 
1612 #ifndef SS_MULTICORE_SUPPORT
1613    if (osCp.numSTsks == 1)
1614 #else
1615    if (osCp.numSTsks == 2)
1616 #endif /* SS_MULTICORE_SUPPORT */
1617 #else
1618 #ifndef SS_MULTICORE_SUPPORT
1619    if (osCp.numSTsks == 3)
1620 #else      
1621    if (osCp.numSTsks == 4)
1622 #endif /* SS_MULTICORE_SUPPORT */
1623 #endif /* SS_WATCHDOG */
1624    {
1625 /* ss001.301: additions */
1626 #ifndef SS_WATCHDOG 
1627 #ifndef SS_MULTICORE_SUPPORT
1628       *tskId = 0;
1629       osCp.sTskTbl[0].termPend = FALSE;
1630 #else
1631       *tskId = 1;
1632       osCp.sTskTbl[1].termPend = FALSE;
1633 #endif /* SS_MULTICORE_SUPPORT */
1634 #else
1635 #ifndef SS_MULTICORE_SUPPORT
1636       *tskId = 2;
1637       osCp.sTskTbl[2].termPend = FALSE;
1638 #else 
1639       *tskId = 3;
1640       osCp.sTskTbl[3].termPend = FALSE;
1641 #endif /* SS_MULTICORE_SUPPORT */
1642 #endif /* SS_WATCHDOG */
1643
1644   /* ss006.13: addition */
1645       if ( SUnlock(&osCp.sTskTblLock) != ROK)
1646       {
1647 #if (ERRCLASS & ERRCLS_DEBUG)
1648            SSLOGERROR(ERRCLS_DEBUG, ESS420, ERRZERO,
1649                        "Could not give the Semaphore");
1650            RETVALUE(RFAILED);
1651 #endif
1652       }
1653       RETVALUE(ROK);
1654    }
1655 #endif /* SS_SINGLE_THREADED */
1656
1657
1658    /* check count of system tasks */
1659    if (osCp.numSTsks == SS_MAX_STSKS)
1660    {
1661
1662   /* ss006.13: addition */
1663       if ( SUnlock(&osCp.sTskTblLock) != ROK)
1664       {
1665 #if (ERRCLASS & ERRCLS_DEBUG)
1666            SSLOGERROR(ERRCLS_DEBUG, ESS421, ERRZERO,
1667                        "Could not give the Semaphore");
1668            RETVALUE(RFAILED);
1669 #endif
1670       }
1671
1672 #if (ERRCLASS & ERRCLS_ADD_RES)
1673       SSLOGERROR(ERRCLS_ADD_RES, ESS422, ERRZERO, "Too many system tasks");
1674 #endif
1675
1676       RETVALUE(ROUTRES);
1677    }
1678
1679
1680    /* initialize the system task entry with the information we have */
1681    sTsk = &osCp.sTskTbl[osCp.nxtSTskEntry];
1682
1683    /* store the system task priority */
1684    sTsk->tskPrior = tskPrior;
1685
1686 /*ss014.301 SSI-4GMX specific changes*/   
1687 #ifndef SS_4GMX_LCORE
1688    /* initialize the demand queue */
1689    if (ssInitDmndQ(&sTsk->dQ) != ROK)
1690    {
1691
1692   /* ss006.13: addition */
1693       if ( SUnlock(&osCp.sTskTblLock) != ROK)
1694       {
1695 #if (ERRCLASS & ERRCLS_DEBUG)
1696            SSLOGERROR(ERRCLS_DEBUG, ESS423, ERRZERO,
1697                        "Could not give the Semaphore");
1698            RETVALUE(RFAILED);
1699 #endif
1700       }
1701
1702 #if (ERRCLASS & ERRCLS_DEBUG)
1703       SSLOGERROR(ERRCLS_DEBUG, ESS424, (ErrVal) ret,
1704                   "Could not initialize demand queue");
1705 #endif
1706
1707       RETVALUE(RFAILED);
1708    }
1709
1710    /* initialize the system task entry lock */
1711    if (SInitLock(&sTsk->lock, SS_STSKENTRY_LOCK) != ROK)
1712    {
1713       ssDestroyDmndQ(&sTsk->dQ);
1714
1715   /* ss006.13: addition */
1716       if ( SUnlock(&osCp.sTskTblLock) != ROK)
1717       {
1718 #if (ERRCLASS & ERRCLS_DEBUG)
1719            SSLOGERROR(ERRCLS_DEBUG, ESS425, ERRZERO,
1720                        "Could not give the Semaphore");
1721            RETVALUE(RFAILED);
1722 #endif
1723       }
1724
1725 #if (ERRCLASS & ERRCLS_DEBUG)
1726       SSLOGERROR(ERRCLS_DEBUG, ESS426, (ErrVal) ret,
1727                   "Could not initialize system task entry lock");
1728 #endif
1729
1730       RETVALUE(RFAILED);
1731    }
1732 #endif
1733
1734    /* we ask the implementation to start this system task */
1735    ret = ssdCreateSTsk(sTsk);
1736    if (ret != ROK)
1737    {
1738       /* failed, clean up */
1739       SDestroyLock(&sTsk->lock);
1740 /*ss014.301 SSI-4GMX specific changes*/   
1741 #ifndef SS_4GMX_LCORE
1742       ssDestroyDmndQ(&sTsk->dQ);
1743 #endif
1744       sTsk->tskPrior = 0;
1745
1746
1747   /* ss006.13: addition */
1748       if ( SUnlock(&osCp.sTskTblLock) != ROK)
1749       {
1750 #if (ERRCLASS & ERRCLS_DEBUG)
1751            SSLOGERROR(ERRCLS_DEBUG, ESS427, ERRZERO,
1752                        "Could not give the Semaphore");
1753            RETVALUE(RFAILED);
1754 #endif
1755       }
1756
1757 #if (ERRCLASS & ERRCLS_DEBUG)
1758       SSLOGERROR(ERRCLS_DEBUG, ESS428, (ErrVal) ret,
1759                   "Could not create system task");
1760 #endif
1761
1762       RETVALUE(RFAILED);
1763    }
1764
1765    /* success, update the table */
1766    *tskId = osCp.nxtSTskEntry;
1767    sTsk->tskId       = osCp.nxtSTskEntry;
1768    sTsk->used        = TRUE;
1769    sTsk->termPend    = FALSE;
1770    osCp.nxtSTskEntry = sTsk->nxt;
1771    osCp.numSTsks++;
1772
1773 #ifdef SS_LOCKLESS_MEMORY
1774    tmpRegTidMap[sTsk->region] = sTsk->dep.tId;
1775 #endif /* SS_LOCKLESS_MEMORY */
1776    /* unlock the system task table */
1777
1778   /* ss006.13: addition */
1779       if ( SUnlock(&osCp.sTskTblLock) != ROK)
1780       {
1781 #if (ERRCLASS & ERRCLS_DEBUG)
1782            SSLOGERROR(ERRCLS_DEBUG, ESS429, ERRZERO,
1783                        "Could not give the Semaphore");
1784            RETVALUE(RFAILED);
1785 #endif
1786       }
1787
1788    RETVALUE(ROK);
1789
1790 } /* SCreateSTsk */
1791
1792 /* ss001.301: additions */
1793 #ifdef SS_LOGGER_SUPPORT 
1794 /*
1795 *
1796 *       Fun:   Register logger configuration 
1797 *
1798 *       Desc:  This function is used to configure the config information
1799 *              of the logger.The log file name, path and the size limits
1800 *              of the log file are updated in the SSI control block. 
1801 *
1802 *
1803 *
1804 *       Ret:   ROK      - ok
1805 *              RFAILED  - failed, general (optional)
1806 *              ROUTRES  - failed, out of resources (optional)
1807 *
1808 *       Notes:
1809 *
1810 *       File:  ss_task.c
1811 *
1812 */
1813 #ifdef ANSI
1814 PUBLIC S16 SRegLogCfg
1815 (
1816 U8 mode,
1817 S8 *path,
1818 U32 size,
1819 S8 *IPA,
1820 U16 port
1821 )
1822 #else
1823 PUBLIC S16 SRegLogCfg(mode, path, size, IPA, port)
1824 U8 mode;
1825 S8 *path;
1826 U32 size;
1827 S8 *IPA;
1828 U16 port
1829 #endif
1830 {
1831
1832 #ifdef WIN32
1833    WSADATA wsaData;
1834         U32 iRes;
1835 #endif
1836
1837    /*ss013.301: Fixed Warnings for 32/64 bit compilation*/ 
1838    struct sockaddr_in localAddr={0};
1839    struct sockaddr_in remoteAddr ={0};
1840
1841    TRC1(SRegLogCfg);
1842
1843 #if (ERRCLASS & ERRCLS_INT_PAR)
1844 #endif
1845
1846    /* Initialize the lock, return on failure */
1847    if( SInitLock(&(osCp.logger.bufLock),SS_LOCK_MUTEX) != ROK)
1848         {
1849       RETVALUE(RFAILED);
1850    } /* if */
1851
1852    SLock(&osCp.logger.bufLock);
1853
1854         /* Initialize the logger configuration flag */
1855         osCp.logger.configured = FALSE;
1856
1857    if( osCp.logger.started == TRUE)
1858    {
1859       (Void)SUnlock(&(osCp.logger.bufLock));
1860       RETVALUE(RFAILED);
1861    }
1862
1863         /* set the mode of the logging */
1864         switch (mode)
1865         {
1866            case SS_LOG_TO_FILE: 
1867                    osCp.logger.opt |= 0x01; 
1868                    break;
1869            case SS_LOG_TO_SOCKET: 
1870                    osCp.logger.opt |= 0x02; 
1871                    break;
1872            case SS_LOG_ALL: 
1873                 default:  
1874                    osCp.logger.opt |= 0x03; break;
1875         }
1876     
1877    /*Open log file*/
1878         if (osCp.logger.opt & 0x01)
1879         {
1880       osCp.logger.filep = fopen(path, "wb");
1881       if(osCp.logger.filep == NULLP)
1882       {
1883          SDisplay(0,"Error Opening Log File \n");
1884          (Void)SUnlock(&(osCp.logger.bufLock));
1885          RETVALUE(RFAILED);
1886       }
1887       strcpy(osCp.logger.filePath,path);
1888         }
1889
1890    /*Open socket */
1891         if (osCp.logger.opt & 0x02)
1892         {
1893 #ifdef WIN32
1894                         if ((iRes = WSAStartup(MAKEWORD(2,2), &wsaData)) != NO_ERROR)
1895                         {
1896                            SDisplay(0, "Error at WSAStartup!\n");
1897             (Void)SUnlock(&(osCp.logger.bufLock));
1898                                 RETVALUE(RFAILED);
1899                         }
1900 #endif
1901       osCp.logger.socketdes = socket(AF_INET, SOCK_DGRAM, 0);
1902       if(osCp.logger.socketdes == -1)
1903       {
1904          SDisplay(0,"Error Opening Log Socket  \n");
1905 #ifdef WIN32
1906                         WSACleanup();
1907 #endif
1908          (Void)SUnlock(&(osCp.logger.bufLock));
1909          RETVALUE(RFAILED);
1910       }
1911                 /* bind to local address */
1912                 localAddr.sin_family = AF_INET;
1913                 localAddr.sin_port = port;
1914                 localAddr.sin_addr.s_addr = INADDR_ANY;
1915                 if (bind(osCp.logger.socketdes, (struct sockaddr*)&localAddr, sizeof(struct sockaddr)) < 0)
1916                 {
1917          SDisplay(0,"Error binding to local port \n");
1918 #ifdef WIN32
1919                         closesocket(osCp.logger.socketdes);
1920                         WSACleanup();
1921 #else
1922                         close(osCp.logger.socketdes);
1923 #endif
1924          (Void)SUnlock(&(osCp.logger.bufLock));
1925          RETVALUE(RFAILED);
1926                 }
1927                 /* remote address */
1928                 remoteAddr.sin_family = AF_INET;
1929                 remoteAddr.sin_port = htons(port);
1930                 if (!IPA)
1931                 {
1932          SDisplay(0,"Invalid remote IP Address \n");
1933 #ifdef WIN32
1934                         closesocket(osCp.logger.socketdes);
1935                         WSACleanup();
1936 #else
1937                         close(osCp.logger.socketdes);
1938 #endif
1939          (Void)SUnlock(&(osCp.logger.bufLock));
1940          RETVALUE(RFAILED);
1941                 }
1942                 remoteAddr.sin_addr.s_addr = inet_addr(IPA);
1943                 osCp.logger.remoteAddr = remoteAddr;
1944
1945         }
1946
1947    cmMemset((U8*)osCp.logger.buffer, '\0', sizeof(osCp.logger.buffer));
1948    
1949    osCp.logger.maxBufSiz = SS_MAX_LOGBUF_SIZE;
1950    osCp.logger.curBufSiz = 0;
1951
1952    osCp.logger.maxNumFlush = size/osCp.logger.maxBufSiz;
1953    osCp.logger.curNumFlush = 0;
1954
1955
1956    osCp.logger.started = FALSE;
1957         osCp.logger.configured = TRUE;
1958
1959    (Void)SUnlock(&(osCp.logger.bufLock));
1960
1961    RETVALUE(ROK);
1962 } /* SRegLogCfg */
1963
1964 /*
1965 *
1966 *       Fun:   SFlushBufToLog
1967 *
1968 *       Desc:  This function is used flush the buffer to file/socket.
1969 *
1970 *       Ret:   ROK
1971 *
1972 *       Notes:
1973 *
1974 *       File:  ss_task.c
1975 *
1976 --*/
1977 #ifdef ANSI
1978 PUBLIC S16 SFlushBufToLog 
1979 (
1980 S8 *logBuf
1981 )
1982 #else
1983 PUBLIC S16 SFlushBufToLog(logBuf)
1984 S8 *logBuf
1985 #endif
1986 {
1987    S8 *buffer;
1988    PRIVATE U16 logFileCnt = 0;
1989    S8 newFileName[SS_MAX_PATH];
1990 #ifdef WIN32
1991    size_t writeNum;
1992 #else
1993    ssize_t writeNum;
1994 #endif
1995    FILE* oldFileP;
1996    /*ss013.301 :Fix for TRACE5 feature crash due to missing TRC MACRO*/
1997    TRC1(SFlushBufToLog)
1998
1999    buffer = logBuf;
2000
2001         if (osCp.logger.opt & 0x01)
2002         {
2003       writeNum = fwrite(buffer, sizeof(U8), cmStrlen((U8 *)buffer), 
2004                                   osCp.logger.filep);
2005         }
2006         if (osCp.logger.opt & 0x02)
2007         {
2008       writeNum = sendto(osCp.logger.socketdes, buffer, cmStrlen((U8 *)buffer), 0, (struct sockaddr*)&osCp.logger.remoteAddr, sizeof(osCp.logger.remoteAddr));
2009       /*ss013.301 : Returned after sending to socket*/
2010       RETVALUE(ROK);
2011         }
2012    osCp.logger.curNumFlush++;
2013    if(osCp.logger.curNumFlush == osCp.logger.maxNumFlush)
2014    {
2015       cmMemset((U8 *)newFileName,'\0',sizeof(newFileName));
2016       /*Store the current File*/
2017       oldFileP = osCp.logger.filep;
2018       /*Open a new file and use it as a new log file*/
2019       osCp.logger.curNumFlush = 0;
2020       logFileCnt++;
2021       sprintf(newFileName, "%s%d", osCp.logger.filePath, logFileCnt);
2022       osCp.logger.filep = fopen(newFileName, "wb");
2023       if(osCp.logger.filep == NULLP)
2024       {
2025           /*MTLOGERROR(ERRCLS_DEBUG, EMTXXX, ERRZERO, "Error Opening Log File. \n");*/
2026       }
2027
2028       fclose(oldFileP);
2029    }
2030    /*SPutSBuf(DFLT_REGION,DFLT_POOL,
2031             (Data *)buffer, (Size)(osCp.logger.maxBufSiz * sizeof(S8)));*/
2032  
2033    RETVALUE(ROK);
2034 } /* SFlushBufToLog */
2035
2036 /*
2037 *
2038 *       Fun:   SCleanUp
2039 *
2040 *       Desc:  This function is used to clean up the logger info.
2041 *
2042 *       Ret:   task id
2043 *
2044 *       Notes:
2045 *
2046 *       File:  ss_task.c
2047 *
2048 --*/
2049 #ifdef ANSI
2050 PUBLIC S16 SCleanUp
2051 (
2052 Void
2053 )
2054 #else
2055 PUBLIC S16 SCleanUp()
2056 #endif
2057 {
2058
2059    TRC1(SCleanUp);
2060    /*Flush the remaining data in the log file*/
2061    SLock(&osCp.logger.bufLock);
2062    if(osCp.logger.started == FALSE)
2063    {
2064       (Void)SUnlock(&(osCp.logger.bufLock));
2065       RETVALUE(ROK);
2066    }
2067    if(osCp.logger.curBufSiz)
2068    {
2069       SFlushBufToLog(osCp.logger.buffer);
2070       osCp.logger.curBufSiz = 0;
2071
2072    }
2073         if (osCp.logger.opt & 0x01)
2074         {
2075       fclose(osCp.logger.filep);
2076         }
2077         if (osCp.logger.opt & 0x02)
2078         {
2079 #ifdef WIN32
2080       closesocket(osCp.logger.socketdes);
2081 #else
2082       close(osCp.logger.socketdes);
2083 #endif
2084         }
2085    osCp.logger.started = FALSE;
2086
2087    (Void)SUnlock(&(osCp.logger.bufLock));
2088 #ifdef L2_L3_SPLIT
2089    signal(SIGINT, App_SigExitCallBack);
2090 #endif 
2091
2092    RETVALUE(ROK);
2093
2094 } /* end of SCleanUp */
2095
2096 /*
2097 *
2098 *       Fun:   Unregister the logger.
2099 *
2100 *       Desc:  This function is used to deregister a logger task. 
2101 *
2102 *       Ret:   ROK      - ok
2103 *              RFAILED  - failed, general (optional)
2104 *              ROUTRES  - failed, out of resources (optional)
2105 *
2106 *       Notes:
2107 *
2108 *       File:  ss_task.c
2109 *
2110 */
2111 #ifdef ANSI
2112 PUBLIC S16 SDeregLogCfg
2113 (
2114 )
2115 #else
2116 PUBLIC S16 SDeregLogCfg()
2117 #endif
2118 {
2119
2120
2121    TRC1(SDeregLogCfg);
2122  
2123    SCleanUp();   
2124
2125    RETVALUE(ROK);
2126
2127 } /* SDeregLogCfg */
2128
2129 /*
2130 *
2131 *       Fun:   SStartLogger
2132 *
2133 *       Desc:  To start logger.
2134 *
2135 *       Ret:   Void
2136 *
2137 *       Notes:
2138 *
2139 *       File:  ss_task.c
2140 *
2141 */
2142 #ifdef ANSI
2143 PUBLIC Void SStartLogger
2144 (
2145 void
2146 )
2147 #else
2148 PUBLIC Void SStartLogger()
2149 #endif
2150 {
2151         if (osCp.logger.configured == TRUE)
2152         {
2153       osCp.logger.started = TRUE;
2154         }
2155 }
2156
2157
2158 /*
2159 *
2160 *       Fun:   SStopLogger
2161 *
2162 *       Desc:  To stop logging to file/socket.
2163 *
2164 *       Ret:   Void
2165 *
2166 *       Notes:
2167 *
2168 *       File:  ss_task.c
2169 *
2170 */
2171 #ifdef ANSI
2172 PUBLIC Void SStopLogger
2173 (
2174 void
2175 )
2176 #else
2177 PUBLIC Void SStopLogger()
2178 #endif
2179 {
2180    osCp.logger.started = FALSE;
2181 }
2182 #endif /* SS_LOGGER_SUPPORT */
2183
2184 /** for multi-core support **/
2185 /*ss013.301 : changes related to SS_AFFINITY_SUPPORT*/
2186 #if defined(SS_MULTICORE_SUPPORT) || defined(SS_AFFINITY_SUPPORT)
2187
2188 /*
2189 *
2190 *       Fun:   Register the CPU information
2191 *
2192 *       Desc:  This function is used to register the number of cores
2193 *              present and the number of threads which can be run on
2194 *              each core.
2195 *
2196 *       Ret:   ROK      - ok
2197 *              RFAILED  - failed, general (optional)
2198 *
2199 *       Notes:
2200 *
2201 *       File:  ss_task.c
2202 *
2203 */
2204 #ifdef ANSI
2205 PUBLIC S16 SRegCpuInfo 
2206 (
2207 SCpuInfo *cpuInfo    /* Information about the cores/threads per core */
2208 )
2209 #else
2210 PUBLIC S16 SRegCpuInfo (cpuInfo)
2211 SCpuInfo *cpuInfo;  /* Information about the cores/threads per core */
2212 #endif
2213 {
2214    U32 coreCount = 0;
2215
2216    /*ss013.301 :Fix for TRACE5 feature crash due to missing TRC MACRO*/
2217    TRC1(SRegCpuInfo)
2218    /* check the number of cores */
2219    if ( cpuInfo->numCores > SS_MAX_CORES || 
2220         cpuInfo->threadsPerCore > SS_MAX_THREADS_PER_CORE || 
2221         cpuInfo->numCores < 1 || cpuInfo->threadsPerCore < 1 )
2222    {
2223        SSLOGERROR(ERRCLS_INT_PAR, ESS430, ERRZERO, "Invalid number of cores\n");
2224        RETVALUE(RFAILED);
2225    }
2226
2227    /* lock mCInfo */
2228    SLock(&osCp.mCILock);
2229    osCp.mCInfo.cpuInfo.numCores = cpuInfo->numCores;
2230    osCp.mCInfo.cpuInfo.threadsPerCore = cpuInfo->threadsPerCore;
2231    /* if the cpu register is supplied then use it */
2232    for (; coreCount < cpuInfo->numCores; coreCount++)
2233    {
2234       U32 thrCnt = 0;
2235       for (;thrCnt < SS_MAX_THREADS_PER_CORE;thrCnt++)
2236       {
2237          osCp.mCInfo.coreInfo[coreCount].tskPerCoreLst[thrCnt] = -1;
2238       } /* for */
2239       osCp.mCInfo.coreInfo[coreCount].exclusive = FALSE;
2240       osCp.mCInfo.coreInfo[coreCount].thrs = osCp.mCInfo.cpuInfo.threadRegister[coreCount] 
2241       = cpuInfo->threadRegister[coreCount];
2242    }
2243    /* unlock mCInfo */
2244    SUnlock(&osCp.mCILock);
2245
2246    RETVALUE(ROK);
2247
2248 } /* SRegCpuInfo */
2249
2250
2251
2252 /*
2253 *
2254 *       Fun:   Get the current core/cpu affinity for a thread/lwp
2255 *
2256 *       Desc:  This function is used to get the current processor/core 
2257 *              affinity for a a system task (thread/lwp). It sets the 
2258 *              affinity based on the mode supplied by the caller. 
2259 *
2260 *       Ret:   ROK      - ok
2261 *              RFAILED  - failed, general (optional)
2262 *
2263 *       Notes:
2264 *
2265 *       File:  ss_task.c
2266 *
2267 */
2268 #ifdef ANSI
2269 PUBLIC S16 SGetAffinity
2270 (
2271 SSTskId *tskId,                  /* filled in with system task ID */
2272 U32 *coreId                      /* the core/processor id to which the affinity is set */
2273 )
2274 #else
2275 PUBLIC S16 SGetAffinity(tskId, coreId)
2276 SSTskId *tskId;                 /* filled in with system task ID */
2277 U32 *coreId;                    /* the core/processor id to which the affinity is set */
2278 #endif
2279 {
2280    S16 ret;
2281
2282     /*ss013.301 :Fix for TRACE5 feature crash due to missing TRC MACRO*/
2283     TRC1(SGetAffinity)
2284     /* implementation specific */
2285     ret = ssdGetAffinity(tskId, coreId);
2286
2287     if (ret != ROK)
2288     {
2289        SSLOGERROR(ERRCLS_INT_PAR, ESS431, ERRZERO, "Failed to get affinity\n");
2290        RETVALUE(RFAILED);
2291     } /* end if */
2292
2293    RETVALUE(ROK);
2294 } /* SGetAffinity */
2295
2296
2297 /*
2298 *
2299 *       Fun:   Set the core/cpu affinity for a thread/lwp
2300 *
2301 *       Desc:  This function is used to set processor/core affinity for a 
2302 *              a system task (thread/lwp). It sets the affinity based on the
2303 *              mode supplied by the caller. 
2304 *
2305 *       Ret:   ROK      - ok
2306 *              RFAILED  - failed, general (optional)
2307 *
2308 *       Notes:
2309 *
2310 *       File:  ss_task.c
2311 *
2312 */
2313 #ifdef ANSI
2314 PUBLIC S16 SSetAffinity
2315 (
2316 SSTskId *tskId,                  /* filled in with system task ID */
2317 SsAffinityMode mode,             /* the mode according to which the affinty is set */
2318 U32 coreId,                      /* the core/processor id to which the affinity has to be set */
2319 SSTskId *tskAssociatedTskId      /* filled in with system task ID of the associated layer */
2320 )
2321 #else
2322 PUBLIC S16 SSetAffinity(tskId, mode, coreId, tskAssociatedTskId)
2323 SSTskId *tskId;                 /* filled in with system task ID */
2324 SsAffinityMode mode;            /* the mode according to which the affinty is set */
2325 U32 coreId;                     /* the core/processor id to which the affinity has to be set */
2326 SSTskId *tskAssociatedTskId;    /* filled in with system task ID of the associated layer */
2327 #endif
2328 {
2329    S16 ret;
2330   
2331    /*ss013.301 :Fix for TRACE5 feature crash due to missing TRC MACRO*/
2332    TRC1(SSetAffinity)
2333    /* validate the mode */
2334    if (mode < SS_AFFINITY_MODE_DEFAULT || 
2335        mode > SS_AFFINITY_MODE_EXCL)
2336    {
2337       SSLOGERROR(ERRCLS_INT_PAR, ESS432, ERRZERO, "Invalid mode for setting core affinity\n");
2338       RETVALUE(RFAILED);
2339    } /* end if */
2340
2341    /* check the value of core id */
2342    if (SS_AFFINITY_MODE_SPECIFIC == mode && 
2343        (coreId > osCp.mCInfo.cpuInfo.numCores || coreId < 0))
2344    {
2345       SSLOGERROR(ERRCLS_INT_PAR, ESS433, ERRZERO, "Invalid core id\n");
2346       RETVALUE(RFAILED);
2347    } /* end if */
2348
2349    /* set affinity according to the mode supplied */
2350    switch (mode)
2351    {
2352        case SS_AFFINITY_MODE_DEFAULT:
2353        {
2354            U32 coreCounter = 0, coreIndex = 0;
2355            S8 repeatFlag = 1;
2356            SEARCH_FOR_CORE:
2357               /*ss013.301: Fixed Warnings for 32/64 bit compilation*/ 
2358               for (coreIndex = osCp.mCInfo.currentCore;  
2359                    coreCounter < osCp.mCInfo.cpuInfo.numCores; 
2360                    coreCounter++ )
2361                   {
2362                      /* again start from core 0 */ 
2363                      ++coreIndex;
2364                      coreIndex = (coreIndex)%osCp.mCInfo.cpuInfo.numCores;
2365                      if (!osCp.mCInfo.coreInfo[coreIndex].exclusive 
2366                          && osCp.mCInfo.cpuInfo.threadRegister[coreIndex])
2367                      {
2368                          if (osCp.mCInfo.coreInfo[coreIndex].thrs || !repeatFlag)  
2369                          {
2370                              /* call the implementation specific affinity function */
2371                              ret = ssdSetAffinity(tskId, coreIndex); 
2372      
2373                              if (ret != ROK)
2374                              {
2375                                  SSLOGERROR(ERRCLS_INT_PAR, ESS434, ERRZERO, \
2376                                             "Failed to set core affinity\n");
2377                                  RETVALUE(RFAILED);
2378                              } /* end if */
2379   
2380                              /* lock mCInfo */
2381                              SLock(&osCp.mCILock);
2382
2383                              /* move the current core index */
2384                              osCp.mCInfo.currentCore = (coreIndex+1)%osCp.mCInfo.cpuInfo.numCores;
2385   
2386                              /* save the tskId in tskList */
2387                               osCp.mCInfo.coreInfo[coreIndex].tskPerCoreLst[
2388                               osCp.mCInfo.cpuInfo.threadRegister[coreIndex] - 
2389                               osCp.mCInfo.coreInfo[coreIndex].thrs] = *tskId;
2390
2391                              /* decrement the available thread count in the thread register */
2392                               osCp.mCInfo.coreInfo[coreIndex].thrs--;
2393
2394                              /* unlock mCInfo */
2395                               SUnlock(&osCp.mCILock);
2396   
2397                               break;
2398                           } /* end if there are threads available in the core */    
2399                       } /* end if the core is not exclusive flagged and 
2400                            the core has threads for SSI use */
2401                   } /* end for */
2402                  if (coreCounter == osCp.mCInfo.cpuInfo.numCores && repeatFlag)
2403                  {
2404                      repeatFlag = 0;
2405                      SSLOGERROR(ERRCLS_INT_PAR, ESS435, ERRZERO, "Overloading of threads per core!!\n");
2406                      goto SEARCH_FOR_CORE; 
2407                  } /* end if no thrs on cores available and overallocation is needed */
2408               break;
2409           } /* end case SS_AFFINITY_MODE_DEFAULT */
2410           case SS_AFFINITY_MODE_SPECIFIC:
2411           {
2412               /* check if the core is used exclusively for any task */
2413               if (osCp.mCInfo.coreInfo[coreId].exclusive)
2414               {
2415                   SSLOGERROR(ERRCLS_INT_PAR, ESS436, ERRZERO,\
2416                              "Can not set core affinity, core is exclusively used for other task\n");
2417                   RETVALUE(RFAILED);
2418               } /* end if */
2419               /* call the implementation specific affinity function with the core id supplied by caller */
2420               ret = ssdSetAffinity(tskId, coreId);
2421
2422               if (ret != ROK)
2423               {
2424                   SSLOGERROR(ERRCLS_INT_PAR, ESS437, ERRZERO, "Failed to set core affinity\n");
2425                   RETVALUE(RFAILED);
2426               } /* end if */
2427
2428               /* lock mCInfo */
2429               SLock(&osCp.mCILock);
2430
2431               /* move the current core index */
2432                osCp.mCInfo.currentCore = (coreId+1)%osCp.mCInfo.cpuInfo.numCores;
2433
2434               /* save the tskId in tskList */
2435               osCp.mCInfo.coreInfo[coreId].tskPerCoreLst[
2436               osCp.mCInfo.cpuInfo.threadRegister[coreId] - 
2437               osCp.mCInfo.coreInfo[coreId].thrs] = *tskId;
2438  
2439               /* decrement the available thread count in the thread register */
2440               osCp.mCInfo.coreInfo[coreId].thrs--;
2441  
2442               /* unlock mCInfo */
2443               SUnlock(&osCp.mCILock);
2444
2445               if (osCp.mCInfo.coreInfo[coreId].thrs < 0)
2446               {
2447                   SSLOGERROR(ERRCLS_INT_PAR, ESS438, ERRZERO, "Overloading of threads per core!!\n");
2448               } /* end else */
2449
2450              break;
2451           } /* end case SS_AFFINITY_MODE_SPECIFIC */
2452           case SS_AFFINITY_MODE_ASSOC:
2453           {
2454               /* search for the associated tsk id in osCp */
2455               U32 coreIndex = 0, threadIndex = 0;
2456               Bool tskNotFound = TRUE;
2457               for (;tskNotFound && coreIndex < SS_MAX_CORES; coreIndex++)
2458               {
2459                   for (threadIndex = 0; threadIndex < SS_MAX_THREADS_PER_CORE; threadIndex++)
2460                   {
2461                       if (osCp.mCInfo.coreInfo[coreIndex].tskPerCoreLst[threadIndex] == *tskAssociatedTskId)
2462                       {
2463                           if (!osCp.mCInfo.coreInfo[coreIndex].exclusive)
2464                           {
2465                               /* set the affinity for the given task on to the core coreIndex */
2466                               ret = ssdSetAffinity(tskId, coreIndex);
2467                               if (ret != ROK)
2468                               {
2469                                   SSLOGERROR(ERRCLS_INT_PAR, ESS439, ERRZERO, "Failed to set core affinity\n");
2470                                   RETVALUE(RFAILED);
2471                               } /* end if */
2472     
2473                               /* lock mCInfo */
2474                               SLock(&osCp.mCILock);
2475
2476                              /* move the current core index */
2477                               osCp.mCInfo.currentCore = (coreIndex+1)%osCp.mCInfo.cpuInfo.numCores;
2478     
2479                              /* save the tskId in tskList */
2480                              osCp.mCInfo.coreInfo[coreIndex].tskPerCoreLst[               
2481                              osCp.mCInfo.cpuInfo.threadRegister[coreIndex] - 
2482                              osCp.mCInfo.coreInfo[coreIndex].thrs] = *tskId;
2483  
2484                             /* decrement the available thread count in the thread register */
2485                              osCp.mCInfo.coreInfo[coreIndex].thrs--;
2486  
2487                             /* unlock mCInfo */
2488                             SUnlock(&osCp.mCILock);
2489
2490                             if (osCp.mCInfo.coreInfo[coreIndex].thrs < 0) 
2491                             {
2492                                 SSLOGERROR(ERRCLS_INT_PAR, ESS440, ERRZERO, 
2493                                            "Overloading of threads per core!!\n");
2494                             } /* end if */
2495
2496                          } /* end if */
2497                          else
2498                          {
2499                              SSLOGERROR(ERRCLS_INT_PAR, ESS441, ERRZERO, 
2500                                         "Can not set core affinity, core is exclusively used for other task\n");
2501                              RETVALUE(RFAILED);
2502                          } /* end else */
2503                          tskNotFound = FALSE;
2504                            break;
2505                       } /* end if */
2506                   } /* end inner for */
2507                } /* end for */
2508
2509                /* check if tskAssociatedTskId is valid or not */
2510                if (coreIndex == SS_MAX_CORES)
2511                 {
2512                     SSLOGERROR(ERRCLS_INT_PAR, ESS442, ERRZERO, "Invalid core id\n");
2513                     RETVALUE(RFAILED);
2514                 } /* if */
2515              break;
2516           } /* end case SS_AFFINITY_MODE_ASSOC */
2517           case SS_AFFINITY_MODE_EXCL:
2518           {
2519              /* check if any thread is already running on the core */
2520              if (coreId != SS_DEFAULT_CORE && 
2521                  osCp.mCInfo.coreInfo[coreId].thrs == osCp.mCInfo.cpuInfo.threadRegister[coreId] &&
2522                 !osCp.mCInfo.coreInfo[coreId].exclusive)
2523               {
2524                  /* call the implementation specific affinity function */
2525                  ret = ssdSetAffinity(tskId, coreId);
2526     
2527                  if (ret != ROK)
2528                  {
2529                     SSLOGERROR(ERRCLS_INT_PAR, ESS443, ERRZERO, "Failed to set core affinity\n");
2530                     RETVALUE(RFAILED);
2531                  } /* end if */
2532
2533                  /* lock mCInfo */
2534                  SLock(&osCp.mCILock);
2535
2536                  /* set the exclusive flag so that the core will not be used for other system tasks */
2537                   osCp.mCInfo.coreInfo[coreId].exclusive = TRUE;
2538  
2539                   /* save the tskId in tskList */
2540                   osCp.mCInfo.coreInfo[coreId].tskPerCoreLst[osCp.mCInfo.cpuInfo.threadRegister[coreId] - 
2541                   osCp.mCInfo.coreInfo[coreId].thrs] = *tskId;
2542
2543                   /* decrement the available thread count in the thread register */
2544                   osCp.mCInfo.coreInfo[coreId].thrs--;
2545  
2546                  /* unlock mCInfo */
2547                   SUnlock(&osCp.mCILock);
2548
2549              } /* end if */
2550              else if (coreId == SS_DEFAULT_CORE)
2551              {
2552                  U32 coreCounter = 0;
2553                  U32 coreIndex = 0;
2554                  /*ss013.301: Fixed Warnings for 32/64 bit compilation*/ 
2555                  for (coreIndex = osCp.mCInfo.currentCore;  
2556                       coreCounter < osCp.mCInfo.cpuInfo.numCores; 
2557                       coreCounter++)
2558                      {
2559                         ++coreIndex;
2560                         coreIndex = (coreIndex)%osCp.mCInfo.cpuInfo.numCores;
2561                         if (!osCp.mCInfo.coreInfo[coreIndex].exclusive 
2562                             && osCp.mCInfo.cpuInfo.threadRegister[coreIndex])
2563                         {
2564                             if ( osCp.mCInfo.coreInfo[coreIndex].thrs == 
2565                                  osCp.mCInfo.cpuInfo.threadRegister[coreIndex] &&
2566                                  osCp.mCInfo.coreInfo[coreIndex].thrs)  
2567                             {
2568                                /* call the implementation specific affinity function */
2569                                 ret = ssdSetAffinity(tskId, coreIndex);
2570         
2571                                 if (ret != ROK)
2572                                  {
2573                                     SSLOGERROR(ERRCLS_INT_PAR, ESS444, ERRZERO, "Failed to set core affinity\n");
2574                                     RETVALUE(RFAILED);
2575                                  } /* end if */
2576      
2577                                  /* lock mCInfo */
2578                                  SLock(&osCp.mCILock);
2579
2580                                  /* move the current core index */
2581                                  osCp.mCInfo.currentCore = (coreIndex+1)%osCp.mCInfo.cpuInfo.numCores;
2582       
2583                                  /* save the tskId in tskList */
2584                                  osCp.mCInfo.coreInfo[coreIndex].tskPerCoreLst[               
2585                                  osCp.mCInfo.cpuInfo.threadRegister[coreIndex] - 
2586                                  osCp.mCInfo.coreInfo[coreIndex].thrs] = *tskId;
2587  
2588                                 /* decrement the available thread count in the thread register */
2589                                  osCp.mCInfo.coreInfo[coreIndex].thrs--;
2590  
2591                                /* set the exclusive flag so that the core will not 
2592                                   be used for other system tasks */
2593                                   osCp.mCInfo.coreInfo[coreIndex].exclusive = TRUE;
2594
2595                                   /* unlock mCInfo */
2596                                   SUnlock(&osCp.mCILock);
2597
2598                                   break;
2599                                } /* end if there are threads available in the core */    
2600                             } /* end if the core is not exclusive flagged and 
2601                                  the core has threads for SSI use */
2602                          } /* end for */
2603                   if (coreCounter == osCp.mCInfo.cpuInfo.numCores)
2604                   {
2605                      SSLOGERROR(ERRCLS_INT_PAR, ESS445, ERRZERO, 
2606                                 "Failed to set core affinity, no threads on cores available\n");
2607                      RETVALUE(RFAILED);
2608                   } /* end if no thrs on cores available */
2609
2610               } /* else if */
2611               else
2612               {
2613                  SSLOGERROR(ERRCLS_INT_PAR, ESS446, ERRZERO, "Can not set exclusive affinity for the core\n");
2614                  RETVALUE(RFAILED);
2615               } /* end else */
2616             break;
2617          } /* end case SS_AFFINITY_MODE_EXCL */
2618          default:
2619          {
2620             SSLOGERROR(ERRCLS_INT_PAR, ESS447, ERRZERO, "Invalid mode for setting core affinity\n");
2621             RETVALUE(RFAILED);
2622          } /* end default case */
2623     } /* end of switch */
2624
2625     RETVALUE(ROK);
2626                
2627
2628 } /* SSetAffinity */
2629
2630 #endif /* SS_MULTICORE_SUPPORT || SS_AFFINITY_SUPPORT*/
2631
2632 /** end multi-core support **/
2633
2634 \f
2635 /*
2636 *
2637 *       Fun:   Destroy system task
2638 *
2639 *       Desc:  This function is used to destroy a system task. The
2640 *              entry is located in the system task table and the
2641 *              implementation-specific function is called.
2642 *
2643 *       Ret:   ROK      - ok
2644 *              RFAILED  - failed, general (optional)
2645 *
2646 *       Notes:
2647 *
2648 *       File:  ss_task.c
2649 *
2650 */
2651 #ifdef ANSI
2652 PUBLIC S16 SDestroySTsk
2653 (
2654 SSTskId tskId                   /* system task to be destroyed */
2655 )
2656 #else
2657 PUBLIC S16 SDestroySTsk(tskId)
2658 SSTskId tskId;                  /* system task to be destroyed */
2659 #endif
2660 {
2661    S16 ret;
2662    /* ss029.103: modification: the subscript should be of same type */
2663    SsIdx i;
2664    SsIdx idx;
2665    SsSTskEntry *sTsk;
2666         /* ss002.301 Additions */
2667 /*ss013.301 : changes related to SS_AFFINITY_SUPPORT*/
2668 #if defined(SS_MULTICORE_SUPPORT) || defined(SS_AFFINITY_SUPPORT)
2669    U32 tskInd = 0;
2670 #endif /* SS_MULTICORE_SUPPORT || SS_AFFINITY_SUPPORT*/
2671
2672
2673    TRC1(SDestroySTsk);
2674
2675
2676 #if (ERRCLASS & ERRCLS_INT_PAR)
2677    /* validate the system task ID */
2678    if (tskId >= SS_MAX_STSKS)
2679    {
2680       SSLOGERROR(ERRCLS_INT_PAR, ESS448, (ErrVal) tskId, "Invalid task ID");
2681       RETVALUE(RFAILED);
2682    }
2683 #endif
2684
2685
2686    /* lock the system task table */
2687    ret = SLock(&osCp.sTskTblLock);
2688    if (ret != ROK)
2689    {
2690
2691 #if (ERRCLASS & ERRCLS_DEBUG)
2692       SSLOGERROR(ERRCLS_DEBUG, ESS449, (ErrVal) ret,
2693                      "Could not lock system task table");
2694 #endif
2695
2696       RETVALUE(RFAILED);
2697    }
2698
2699
2700    idx = (SsIdx) tskId;
2701    sTsk = &osCp.sTskTbl[idx];
2702
2703
2704 #if (ERRCLASS & ERRCLS_INT_PAR)
2705    /* 
2706     * check to see this system task exists and it is not already scheduled
2707     *  for termination 
2708     */
2709    if (sTsk->used != TRUE)
2710    {
2711
2712   /* ss006.13: addition */
2713       if ( SUnlock(&osCp.sTskTblLock) != ROK)
2714       {
2715 #if (ERRCLASS & ERRCLS_DEBUG)
2716            SSLOGERROR(ERRCLS_DEBUG, ESS450, ERRZERO,
2717                        "Could not give the Semaphore");
2718            RETVALUE(RFAILED);
2719 #endif
2720       }
2721
2722       SSLOGERROR(ERRCLS_INT_PAR, ESS451, (ErrVal) idx,
2723                         "Invalid system task ID");
2724       RETVALUE(RFAILED);
2725    }
2726    else if (sTsk->termPend != FALSE)
2727    {
2728
2729   /* ss006.13: addition */
2730       if ( SUnlock(&osCp.sTskTblLock) != ROK)
2731       {
2732 #if (ERRCLASS & ERRCLS_DEBUG)
2733            SSLOGERROR(ERRCLS_DEBUG, ESS452, ERRZERO,
2734                        "Could not give the Semaphore");
2735            RETVALUE(RFAILED);
2736 #endif
2737       }
2738
2739       SSLOGERROR(ERRCLS_INT_PAR, ESS453, (ErrVal) idx,
2740                         "Invalid system task ID");
2741       RETVALUE(RFAILED);
2742    }
2743 #endif
2744
2745
2746    /* lock this system task entry */
2747    if (!SS_CHECK_CUR_STSK(sTsk))
2748    {
2749       ret = SLock(&sTsk->lock);
2750       if (ret != ROK)
2751       {
2752
2753   /* ss006.13: addition */
2754          if ( SUnlock(&osCp.sTskTblLock) != ROK)
2755          {
2756 #if (ERRCLASS & ERRCLS_DEBUG)
2757              SSLOGERROR(ERRCLS_DEBUG, ESS454, ERRZERO,
2758                        "Could not give the Semaphore");
2759              RETVALUE(RFAILED);
2760 #endif
2761          }
2762
2763 #if (ERRCLASS & ERRCLS_DEBUG)
2764          SSLOGERROR(ERRCLS_DEBUG, ESS455, (ErrVal) ret,
2765                         "Could not lock system task entry");
2766 #endif
2767
2768          RETVALUE(RFAILED);
2769       }
2770    }
2771
2772    /* lock the TAPA task table */
2773    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
2774    if (ret != ROK)
2775    {
2776       if (!SS_CHECK_CUR_STSK(sTsk))
2777       {
2778
2779   /* ss006.13: addition */
2780          if ( SUnlock(&sTsk->lock) != ROK)
2781          {
2782 #if (ERRCLASS & ERRCLS_DEBUG)
2783              SSLOGERROR(ERRCLS_DEBUG, ESS456, ERRZERO,
2784                        "Could not give the Semaphore");
2785              RETVALUE(RFAILED);
2786 #endif
2787          }
2788       }
2789
2790   /* ss006.13: addition */
2791          if ( SUnlock(&osCp.sTskTblLock) != ROK)
2792          {
2793 #if (ERRCLASS & ERRCLS_DEBUG)
2794              SSLOGERROR(ERRCLS_DEBUG, ESS457, ERRZERO,
2795                        "Could not give the Semaphore");
2796              RETVALUE(RFAILED);
2797 #endif
2798          }
2799
2800 #if (ERRCLASS & ERRCLS_DEBUG)
2801       SSLOGERROR(ERRCLS_DEBUG, ESS458, ERRZERO,
2802                      "Could not lock TAPA task table");
2803 #endif
2804
2805       RETVALUE(RFAILED);
2806    }
2807
2808
2809    /* If this system task entry has any TAPA tasks attached,
2810     *  we have to detach them
2811     */
2812    if (sTsk->numTTsks)
2813    {
2814       /* detach all TAPA tasks that are attached here */
2815       for (i = 0;  i < SS_MAX_TTSKS;  i++)
2816       {
2817          if (sTsk->tTsks[i] == SS_INVALID_IDX)
2818             continue;
2819
2820          osCp.tTskTbl[sTsk->tTsks[i]].sTsk = NULLP;
2821          sTsk->tTsks[i] = SS_INVALID_IDX;
2822          sTsk->numTTsks--;
2823       }
2824    }
2825
2826
2827    /* set the termination pending flag to TRUE */
2828    sTsk->termPend = TRUE;
2829
2830
2831    /* unlock everything */
2832    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
2833
2834    if (!SS_CHECK_CUR_STSK(sTsk))
2835    {
2836
2837   /* ss006.13: addition */
2838       if ( SUnlock(&sTsk->lock) != ROK)
2839       {
2840 #if (ERRCLASS & ERRCLS_DEBUG)
2841           SSLOGERROR(ERRCLS_DEBUG, ESS459, ERRZERO,
2842                        "Could not give the Semaphore");
2843           RETVALUE(RFAILED);
2844 #endif
2845       }
2846    }
2847
2848
2849   /* ss006.13: addition */
2850    if ( SUnlock(&osCp.sTskTblLock) != ROK)
2851    {
2852 #if (ERRCLASS & ERRCLS_DEBUG)
2853         SSLOGERROR(ERRCLS_DEBUG, ESS460, ERRZERO,
2854                      "Could not give the Semaphore");
2855         RETVALUE(RFAILED);
2856 #endif
2857     }
2858
2859
2860    /* We call this after unlocking because it is possible that the
2861     *  caller is this very system task and we need to take care of
2862     *  that. The actual mechanism of notifying the thread that it
2863     *  has to die, or actually killing the thread is left to the
2864     *  implementation.
2865     */
2866    ret = ssdDestroySTsk(sTsk);
2867    if (ret != ROK)
2868    {
2869       /* Here, we're a little messed up. We've pretty much made this
2870        *  system task unusable, but now, its not going to die. So..??
2871        */
2872
2873 #if (ERRCLASS & ERRCLS_DEBUG)
2874       SSLOGERROR(ERRCLS_DEBUG, ESS461, (ErrVal) ret,
2875                   "Could not destroy system task");
2876 #endif
2877
2878       RETVALUE(RFAILED);
2879    }
2880    
2881    /* multi-core support */
2882 /*ss013.301 : changes related to SS_AFFINITY_SUPPORT*/
2883 #if defined(SS_MULTICORE_SUPPORT) || defined(SS_AFFINITY_SUPPORT)
2884
2885    /* Remove CPU affinity if any */
2886    for (tskInd = 0;  tskInd < SS_MAX_STSKS;  tskInd++)
2887    {
2888       if (osCp.sTskTbl[tskInd].tskId == sTsk->tskId)
2889       {
2890           /* search for the tskId in coreInfo */
2891           U32 coreId = 0;
2892           for (coreId = 0; coreId < SS_MAX_CORES; coreId++)
2893           {
2894              U32 thrId = 0;
2895              for (thrId = 0; thrId < SS_MAX_THREADS_PER_CORE; thrId++)
2896              {
2897                 if (sTsk->tskId == osCp.mCInfo.coreInfo[coreId].tskPerCoreLst[thrId])
2898                  {
2899                     /* lock mCInfo */
2900                     SLock(&osCp.mCILock);
2901
2902                     /* increment the available threads */
2903                     osCp.mCInfo.coreInfo[coreId].thrs++;
2904
2905                     /* reset the thread id */
2906                     osCp.mCInfo.coreInfo[coreId].tskPerCoreLst[thrId] = 0;
2907
2908                     /* if exclusive flag is set then remove it */
2909                    if (osCp.mCInfo.coreInfo[coreId].exclusive)
2910                    {
2911                       osCp.mCInfo.coreInfo[coreId].exclusive = FALSE;
2912                    } /* end if excl set */
2913
2914                    /* unlock mCInfo */
2915                    SUnlock(&osCp.mCILock);
2916
2917                    break;
2918                 } /* end if sTsk matched a thread */
2919              } /* end for loop of thread Ids */
2920           } /* for */
2921           break;
2922       } /* end if */
2923    } /* end for */
2924
2925 #endif /* SS_MULTICORE_SUPPORT || SS_AFFINITY_SUPPORT*/
2926 /* end multi-core support */
2927
2928    /* ss019.103 - added to release semaphore for system task */
2929 #ifndef NS
2930    if (ssPostSema(&osCp.dep.ssStarted) != ROK)
2931    {
2932 #if (ERRCLASS & ERRCLS_DEBUG)
2933        SSLOGERROR(ERRCLS_DEBUG, ESS462, ERRZERO,
2934                          "Could not unlock the Semaphore");
2935        RETVALUE(RFAILED);
2936 #endif
2937    }
2938 #endif
2939    
2940    RETVALUE(ROK);
2941 } /* SDestroySTsk */
2942
2943
2944 \f
2945 /*
2946 *
2947 *       Fun:   Attach TAPA task
2948 *
2949 *       Desc:  This function is used to attach a TAPA task to a
2950 *              system task. The system task will begin to execute
2951 *              the TAPA task.
2952 *
2953 *       Ret:   ROK      - ok
2954 *              RFAILED  - failed, general (optional)
2955 *              ROUTRES  - failed, out of resources (optional)
2956 *
2957 *       Notes:
2958 *
2959 *       File:  ss_task.c
2960 *
2961 */
2962 /* ss029.103: addition: procId added */ 
2963 #ifndef SS_MULTIPLE_PROCS
2964
2965 #ifdef ANSI
2966 PUBLIC S16 SAttachTTsk
2967 (
2968 Ent ent,                        /* entity ID of the task */
2969 Inst inst,                      /* instance ID of the task */
2970 SSTskId sTskId                  /* system task to use */
2971 )
2972 #else
2973 PUBLIC S16 SAttachTTsk(ent, inst, sTskId)
2974 Ent ent;                        /* entity ID of the task */
2975 Inst inst;                      /* instance ID of the task */
2976 SSTskId sTskId;                 /* system task to use */
2977 #endif
2978
2979 #else /* SS_MULTIPLE_PROCS */
2980
2981 #ifdef ANSI
2982 PUBLIC S16 SAttachTTsk
2983 (
2984 ProcId proc,                    /* processor ID of the task */
2985 Ent ent,                        /* entity ID of the task */
2986 Inst inst,                      /* instance ID of the task */
2987 SSTskId sTskId                  /* system task to use */
2988 )
2989 #else
2990 PUBLIC S16 SAttachTTsk(proc, ent, inst, sTskId)
2991 ProcId proc;                    /* processor ID of the task */
2992 Ent ent;                        /* entity ID of the task */
2993 Inst inst;                      /* instance ID of the task */
2994 SSTskId sTskId;                 /* system task to use */
2995 #endif
2996
2997 #endif /* SS_MULTIPLE_PROCS */
2998
2999 {
3000    S16 ret;
3001    S16 i;
3002    SsIdx idx;
3003    SsSTskEntry *sTsk;
3004 /* ss029.103: addition: multiple procIds related changes */ 
3005 #ifdef SS_MULTIPLE_PROCS
3006    U16 procIdIdx;
3007 #endif /* SS_MULTIPLE_PROCS */
3008 #ifdef SS_MULTICORE_SUPPORT
3009    SsTTskEntry *tTsk;
3010 #ifdef SS_MULTIPLE_PROCS
3011    void *xxCb;
3012 #endif /* SS_MULTIPLE_PROCS */
3013 #endif
3014
3015
3016    TRC1(SAttachTTsk);
3017
3018
3019 #if (ERRCLASS & ERRCLS_INT_PAR)
3020    /* check entity and instance range */
3021 /* ss029.103: addition: multiple procIds related changes */ 
3022 #ifdef SS_MULTIPLE_PROCS
3023    /* check proc, entity and instance range */
3024    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
3025    {
3026       SSLOGERROR(ERRCLS_INT_PAR, ESS463, ERRZERO, "Invalid processor/entity/instance");
3027       RETVALUE(RFAILED);
3028    }
3029 #else /* SS_MULTIPLE_PROCS */
3030    /* check entity and instance range */
3031    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
3032    {
3033       SSLOGERROR(ERRCLS_INT_PAR, ESS464, ERRZERO, "Invalid entity/instance");
3034       RETVALUE(RFAILED);
3035    }
3036 #endif /* SS_MULTIPLE_PROCS */
3037
3038    /* check the system task index */
3039    if ((SsIdx)sTskId >= SS_MAX_STSKS)
3040    {
3041       SSLOGERROR(ERRCLS_INT_PAR, ESS465, (ErrVal) sTskId,
3042                   "Invalid system task ID");
3043       RETVALUE(RFAILED);
3044    }
3045 #endif
3046
3047 /* ss029.103: addition: multiple procIds related changes */ 
3048 #ifdef SS_MULTIPLE_PROCS
3049    /* get the proc id idx */
3050    procIdIdx = SGetProcIdIdx(proc);
3051
3052    if (procIdIdx == SS_INV_PROCID)
3053    {
3054 #if (ERRCLASS & ERRCLS_DEBUG)
3055       SSLOGERROR(ERRCLS_DEBUG, ESS466, ERRZERO,
3056                              "Could not find proc id index");
3057 #endif
3058       RETVALUE(RFAILED);
3059    }
3060 #endif /* SS_MULTIPLE_PROCS */
3061
3062    /* lock the system task table */
3063    ret = SLock(&osCp.sTskTblLock);
3064    if (ret != ROK)
3065    {
3066
3067 #if (ERRCLASS & ERRCLS_DEBUG)
3068       SSLOGERROR(ERRCLS_DEBUG, ESS467, (ErrVal) ret,
3069                      "Could not lock system task table");
3070 #endif
3071
3072       RETVALUE(RFAILED);
3073    }
3074
3075
3076    sTsk = &osCp.sTskTbl[(SsIdx)sTskId];
3077
3078
3079 #if (ERRCLASS & ERRCLS_INT_PAR)
3080    /* verify that this system task exists */
3081    if (sTsk->used == FALSE)
3082    {
3083
3084   /* ss006.13: addition */
3085       if ( SUnlock(&osCp.sTskTblLock) != ROK)
3086       {
3087 #if (ERRCLASS & ERRCLS_DEBUG)
3088           SSLOGERROR(ERRCLS_DEBUG, ESS468, ERRZERO,
3089                      "Could not give the Semaphore");
3090           RETVALUE(RFAILED);
3091 #endif
3092       }
3093
3094       SSLOGERROR(ERRCLS_INT_PAR, ESS469, (ErrVal) sTskId,
3095                      "Unknown system task ID");
3096       RETVALUE(RFAILED);
3097    }
3098 #endif
3099
3100
3101    /* lock the system task entry */
3102    if (!SS_CHECK_CUR_STSK(sTsk))
3103    {
3104       ret = SLock(&sTsk->lock);
3105       if (ret != ROK)
3106       {
3107
3108   /* ss006.13: addition */
3109         if ( SUnlock(&osCp.sTskTblLock) != ROK)
3110         {
3111 #if (ERRCLASS & ERRCLS_DEBUG)
3112             SSLOGERROR(ERRCLS_DEBUG, ESS470, ERRZERO,
3113                      "Could not give the Semaphore");
3114             RETVALUE(RFAILED);
3115 #endif
3116         }
3117
3118 #if (ERRCLASS & ERRCLS_DEBUG)
3119          SSLOGERROR(ERRCLS_DEBUG, ESS471, (ErrVal) ret,
3120                         "Could not lock system task entry");
3121 #endif
3122
3123          RETVALUE(RFAILED);
3124       }
3125    }
3126
3127
3128    /* if this system task is about to die, we don't attach */
3129    if (sTsk->termPend == TRUE)
3130    {
3131       if (!SS_CHECK_CUR_STSK(sTsk))
3132       {
3133
3134   /* ss006.13: addition */
3135         if ( SUnlock(&sTsk->lock) != ROK)
3136         {
3137 #if (ERRCLASS & ERRCLS_DEBUG)
3138             SSLOGERROR(ERRCLS_DEBUG, ESS472, ERRZERO,
3139                      "Could not give the Semaphore");
3140             RETVALUE(RFAILED);
3141 #endif
3142         }
3143       }
3144
3145   /* ss006.13: addition */
3146       if ( SUnlock(&osCp.sTskTblLock) != ROK)
3147       {
3148 #if (ERRCLASS & ERRCLS_DEBUG)
3149           SSLOGERROR(ERRCLS_DEBUG, ESS473, ERRZERO,
3150                      "Could not give the Semaphore");
3151           RETVALUE(RFAILED);
3152 #endif
3153       }
3154
3155       RETVALUE(RFAILED);
3156    }
3157
3158
3159    /* lock the TAPA task table */
3160    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
3161    if (ret != ROK)
3162    {
3163       if (!SS_CHECK_CUR_STSK(sTsk))
3164       {
3165
3166   /* ss006.13: addition */
3167         if ( SUnlock(&sTsk->lock) != ROK)
3168         {
3169 #if (ERRCLASS & ERRCLS_DEBUG)
3170             SSLOGERROR(ERRCLS_DEBUG, ESS474, ERRZERO,
3171                      "Could not give the Semaphore");
3172             RETVALUE(RFAILED);
3173 #endif
3174         }
3175       }
3176
3177
3178   /* ss006.13: addition */
3179       if ( SUnlock(&osCp.sTskTblLock) != ROK)
3180       {
3181 #if (ERRCLASS & ERRCLS_DEBUG)
3182           SSLOGERROR(ERRCLS_DEBUG, ESS475, ERRZERO,
3183                      "Could not give the Semaphore");
3184           RETVALUE(RFAILED);
3185 #endif
3186       }
3187
3188 #if (ERRCLASS & ERRCLS_DEBUG)
3189       SSLOGERROR(ERRCLS_DEBUG, ESS476, ERRZERO,
3190                      "Could not lock TAPA task table");
3191 #endif
3192
3193       RETVALUE(RFAILED);
3194    }
3195
3196
3197    /* get the index of the TAPA task entry in the table */
3198 /* ss029.103: addition: multiple procIds related changes */ 
3199 #ifdef SS_MULTIPLE_PROCS
3200    idx = osCp.tTskIds[procIdIdx][ent][inst];
3201 #else /* SS_MULTIPLE_PROCS */
3202    idx = osCp.tTskIds[ent][inst];
3203 #endif /* SS_MULTIPLE_PROCS */
3204
3205 #if (ERRCLASS & ERRCLS_INT_PAR)
3206    /* check out the TAPA task ID */
3207    if (idx == SS_TSKNC)
3208    {
3209       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
3210       if (!SS_CHECK_CUR_STSK(sTsk))
3211       {
3212
3213   /* ss006.13: addition */
3214         if ( SUnlock(&sTsk->lock) != ROK)
3215         {
3216 #if (ERRCLASS & ERRCLS_DEBUG)
3217             SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
3218                      "Could not give the Semaphore");
3219             RETVALUE(RFAILED);
3220 #endif
3221         }
3222       }
3223
3224   /* ss006.13: addition */
3225       if ( SUnlock(&osCp.sTskTblLock) != ROK)
3226       {
3227 #if (ERRCLASS & ERRCLS_DEBUG)
3228           SSLOGERROR(ERRCLS_DEBUG, ESS478, ERRZERO,
3229                      "Could not give the Semaphore");
3230           RETVALUE(RFAILED);
3231 #endif
3232       }
3233
3234       SSLOGERROR(ERRCLS_INT_PAR, ESS479, ERRZERO, "Unknown task");
3235       RETVALUE(RFAILED);
3236    }
3237 #endif
3238
3239
3240    /* verify that this TAPA task is not already attached */
3241    if (osCp.tTskTbl[idx].sTsk != NULLP)
3242    {
3243       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
3244       if (!SS_CHECK_CUR_STSK(sTsk))
3245       {
3246
3247   /* ss006.13: addition */
3248         if ( SUnlock(&sTsk->lock) != ROK)
3249         {
3250 #if (ERRCLASS & ERRCLS_DEBUG)
3251             SSLOGERROR(ERRCLS_DEBUG, ESS480, ERRZERO,
3252                      "Could not give the Semaphore");
3253             RETVALUE(RFAILED);
3254 #endif
3255         }
3256       }
3257
3258   /* ss006.13: addition */
3259       if ( SUnlock(&osCp.sTskTblLock) != ROK)
3260       {
3261 #if (ERRCLASS & ERRCLS_DEBUG)
3262           SSLOGERROR(ERRCLS_DEBUG, ESS481, ERRZERO,
3263                      "Could not give the Semaphore");
3264           RETVALUE(RFAILED);
3265 #endif
3266       }
3267
3268       RETVALUE(RFAILED);
3269    }
3270
3271
3272    /* verify that there is space for another TAPA task */
3273    if (sTsk->numTTsks == SS_MAX_TTSKS)
3274    {
3275       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
3276       if (!SS_CHECK_CUR_STSK(sTsk))
3277       {
3278
3279   /* ss006.13: addition */
3280         if ( SUnlock(&sTsk->lock) != ROK)
3281         {
3282 #if (ERRCLASS & ERRCLS_DEBUG)
3283             SSLOGERROR(ERRCLS_DEBUG, ESS482, ERRZERO,
3284                      "Could not give the Semaphore");
3285             RETVALUE(RFAILED);
3286 #endif
3287         }
3288       }
3289
3290   /* ss006.13: addition */
3291       if ( SUnlock(&osCp.sTskTblLock) != ROK)
3292       {
3293 #if (ERRCLASS & ERRCLS_DEBUG)
3294           SSLOGERROR(ERRCLS_DEBUG, ESS483, ERRZERO,
3295                      "Could not give the Semaphore");
3296           RETVALUE(RFAILED);
3297 #endif
3298       }
3299
3300       RETVALUE(ROUTRES);
3301    }
3302
3303
3304    /*  Find place for this TAPA task in the system task's list
3305     *  of TAPA tasks to run. Plug in this TAPA task.
3306     */
3307    for (i = 0;  i < SS_MAX_TTSKS;  i++)
3308    {
3309       if (sTsk->tTsks[i] == SS_INVALID_IDX)
3310       {
3311          sTsk->tTsks[i] = idx;
3312          sTsk->numTTsks++;
3313          break;
3314       }
3315    }
3316
3317
3318    /* Fill in the system task info in the TAPA task entry, so
3319     *  the TAPA task knows who's running it.
3320     */
3321    osCp.tTskTbl[idx].sTsk = sTsk;
3322 #ifdef SS_MULTICORE_SUPPORT
3323    tTsk = &osCp.tTskTbl[idx];
3324    if(tTsk->initTsk != NULLP)
3325    {
3326 #ifndef SS_MULTIPLE_PROCS 
3327        (Void)(tTsk->initTsk)(tTsk->ent, tTsk->inst, sTsk->region, PWR_UP);
3328 #else
3329           /* retrieve proc id index in the proc id table */
3330         procIdIdx = SGetProcIdIdx(tTsk->proc);
3331
3332         /* Check whether the proc id exist in the proc id table */
3333         if (procIdIdx == SS_INV_PROCID_IDX)
3334         {
3335 #if (ERRCLASS & ERRCLS_INT_PAR)
3336                 SSLOGERROR(ERRCLS_INT_PAR, ESS389, ERRZERO,
3337                      "Could not find proc table index");
3338 #endif
3339
3340               RETVALUE(RFAILED);
3341         }
3342        (Void)(tTsk->initTsk)(tTsk->proc, tTsk->ent, tTsk->inst, sTsk->region, PWR_UP, &xxCb);
3343        /* 
3344         * store the control block. The control block may be NULL in some cases
3345         */
3346        idx = osCp.tTskIds[procIdIdx][tTsk->ent][tTsk->inst];
3347 #if (ERRCLASS & ERRCLS_INT_PAR)
3348        if ( xxCb == NULLP )
3349        {
3350                 SSLOGERROR(ERRCLS_INT_PAR, ERRZERO, ERRZERO,
3351                                          "Null pointer");
3352        }
3353 #endif
3354         osCp.tTskTbl[idx].xxCb = xxCb;
3355 #endif /* SS_MULTIPLE_PROCS */
3356    }
3357 #endif /* SS_MULTICORE_SUPPORT */
3358
3359
3360    /* call the implementation to do anything implementation-specific */
3361    ret = ssdAttachTTsk(&osCp.tTskTbl[idx]);
3362
3363
3364    /* unlock the tables; we're done */
3365    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
3366    if (!SS_CHECK_CUR_STSK(sTsk))
3367    {
3368
3369   /* ss006.13: addition */
3370       if ( SUnlock(&sTsk->lock) != ROK)
3371       {
3372 #if (ERRCLASS & ERRCLS_DEBUG)
3373           SSLOGERROR(ERRCLS_DEBUG, ESS484, ERRZERO,
3374                      "Could not give the Semaphore");
3375           RETVALUE(RFAILED);
3376 #endif
3377       }
3378    }
3379
3380   /* ss006.13: addition */
3381    if ( SUnlock(&osCp.sTskTblLock) != ROK)
3382    {
3383 #if (ERRCLASS & ERRCLS_DEBUG)
3384         SSLOGERROR(ERRCLS_DEBUG, ESS485, ERRZERO,
3385                      "Could not give the Semaphore");
3386         RETVALUE(RFAILED);
3387 #endif
3388    }
3389
3390
3391    /* If the implementation didn't succeed, we have to undo everything.
3392     *  We call SDetachTTsk, to make it easier.
3393     */
3394    if (ret != ROK)
3395    {
3396 /* ss029.103: addition: multiple procIds related changes */ 
3397 #ifdef SS_MULTIPLE_PROCS
3398       SDetachTTsk(proc, ent, inst);
3399 #else /* SS_MULTIPLE_PROCS */
3400       SDetachTTsk(ent, inst);
3401 #endif /* SS_MULTIPLE_PROCS */
3402       RETVALUE(RFAILED);
3403    }
3404
3405
3406    RETVALUE(ROK);
3407 } /* SAttachTTsk */
3408
3409 \f
3410 /*
3411 *
3412 *       Fun:   Detach TAPA task
3413 *
3414 *       Desc:  This function is used to detach a TAPA task from a
3415 *              system task. The system task will stop executing
3416 *              the TAPA task.
3417 *
3418 *       Ret:   ROK      - ok
3419 *              RFAILED  - failed, general (optional)
3420 *
3421 *       Notes:
3422 *
3423 *       File:  ss_task.c
3424 *
3425 */
3426 /* ss029.103: addition: procId added */ 
3427 #ifndef SS_MULTIPLE_PROCS
3428
3429 #ifdef ANSI
3430 PUBLIC S16 SDetachTTsk
3431 (
3432 Ent ent,                        /* entity ID of the task */
3433 Inst inst                       /* instance ID of the task */
3434 )
3435 #else
3436 PUBLIC S16 SDetachTTsk(ent, inst)
3437 Ent ent;                        /* entity ID of the task */
3438 Inst inst;                      /* instance ID of the task */
3439 #endif
3440
3441 #else /* SS_MULTIPLE_PROCS */
3442
3443 #ifdef ANSI
3444 PUBLIC S16 SDetachTTsk
3445 (
3446 ProcId proc,                    /* processor ID of the task */
3447 Ent ent,                        /* entity ID of the task */
3448 Inst inst                       /* instance ID of the task */
3449 )
3450 #else
3451 PUBLIC S16 SDetachTTsk(proc, ent, inst)
3452 ProcId proc;                    /* processor ID of the task */
3453 Ent ent;                        /* entity ID of the task */
3454 Inst inst;                      /* instance ID of the task */
3455 #endif
3456
3457 #endif /* SS_MULTIPLE_PROCS */
3458
3459 {
3460    S16 ret;
3461    S16 i;
3462    SsIdx idx;
3463    SsTTskEntry *tTsk;
3464    SsSTskEntry *sTsk;
3465 /* ss029.103: addition: multiple procIds related changes */ 
3466 #ifdef SS_MULTIPLE_PROCS
3467    U16 procIdIdx;
3468 #endif /* SS_MULTIPLE_PROCS */
3469
3470    TRC1(SDetachTTsk);
3471
3472
3473 #if (ERRCLASS & ERRCLS_INT_PAR)
3474    /* check entity and instance ranges */
3475 /* ss029.103: addition: multiple procIds related changes */ 
3476 #ifdef SS_MULTIPLE_PROCS
3477    /* check entity and instance ranges */
3478    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
3479    {
3480       SSLOGERROR(ERRCLS_INT_PAR, ESS486, ERRZERO, "Invalid processor/entity/instance");
3481       RETVALUE(RFAILED);
3482    }
3483 #else /* SS_MULTIPLE_PROCS */
3484    /* check entity and instance ranges */
3485    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
3486    {
3487       SSLOGERROR(ERRCLS_INT_PAR, ESS487, ERRZERO, "Invalid entity/instance");
3488       RETVALUE(RFAILED);
3489    }
3490 #endif /* SS_MULTIPLE_PROCS */
3491 #endif
3492
3493 /* ss029.103: addition: multiple procIds related changes */ 
3494 #ifdef SS_MULTIPLE_PROCS
3495    /* get the proc id idx */
3496    procIdIdx = SGetProcIdIdx(proc);
3497
3498    if (procIdIdx == SS_INV_PROCID)
3499    {
3500 #if (ERRCLASS & ERRCLS_DEBUG)
3501       SSLOGERROR(ERRCLS_DEBUG, ESS488, ERRZERO,
3502                              "Could not find proc id index");
3503 #endif
3504       RETVALUE(RFAILED);
3505    }
3506 #endif /* SS_MULTIPLE_PROCS */
3507
3508
3509    /* Lock the system task table. We do this to prevent
3510     *  the system task from being destroyed and confusing
3511     *  matters before we detach.
3512     */
3513    ret = SLock(&osCp.sTskTblLock);
3514    if (ret != ROK)
3515    {
3516
3517 #if (ERRCLASS & ERRCLS_DEBUG)
3518       SSLOGERROR(ERRCLS_DEBUG, ESS489, (ErrVal) ret,
3519                      "Could not lock system task table");
3520 #endif
3521
3522       RETVALUE(RFAILED);
3523    }
3524
3525
3526    /* lock the TAPA task table */
3527    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
3528    if (ret != ROK)
3529    {
3530
3531   /* ss006.13: addition */
3532     if ( SUnlock(&osCp.sTskTblLock) != ROK)
3533     {
3534 #if (ERRCLASS & ERRCLS_DEBUG)
3535         SSLOGERROR(ERRCLS_DEBUG, ESS490, ERRZERO,
3536                      "Could not give the Semaphore");
3537         RETVALUE(RFAILED);
3538 #endif
3539     }
3540
3541 #if (ERRCLASS & ERRCLS_DEBUG)
3542       SSLOGERROR(ERRCLS_DEBUG, ESS491, ERRZERO,
3543                      "Could not lock TAPA task table");
3544 #endif
3545
3546       RETVALUE(RFAILED);
3547    }
3548
3549
3550 #if (ERRCLASS & ERRCLS_INT_PAR)
3551    /* Check this TAPA task. We do this with the TAPA task table
3552     *  locked, coz we don't want the task to be found, but then
3553     *  be deregistered before we lock
3554     */
3555 /* ss029.103: addition: multiple procIds related changes */ 
3556 #ifdef SS_MULTIPLE_PROCS
3557    if (osCp.tTskIds[procIdIdx][ent][inst] == SS_TSKNC)
3558 #else /* SS_MULTIPLE_PROCS */
3559    if (osCp.tTskIds[ent][inst] == SS_TSKNC)
3560 #endif /* SS_MULTIPLE_PROCS */
3561    {
3562       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
3563
3564   /* ss006.13: addition */
3565      if ( SUnlock(&osCp.sTskTblLock) != ROK)
3566      {
3567 #if (ERRCLASS & ERRCLS_DEBUG)
3568         SSLOGERROR(ERRCLS_DEBUG, ESS492, ERRZERO,
3569                      "Could not give the Semaphore");
3570         RETVALUE(RFAILED);
3571 #endif
3572      }
3573
3574       SSLOGERROR(ERRCLS_INT_PAR, ESS493, ERRZERO, "Unknown task");
3575       RETVALUE(RFAILED);
3576    }
3577 #endif
3578
3579 /* ss029.103: addition: multiple procIds related changes */ 
3580 #ifdef SS_MULTIPLE_PROCS
3581    idx = osCp.tTskIds[procIdIdx][ent][inst];
3582 #else /* SS_MULTIPLE_PROCS */
3583    idx = osCp.tTskIds[ent][inst];
3584 #endif /* SS_MULTIPLE_PROCS */
3585
3586    tTsk = &osCp.tTskTbl[idx];
3587
3588    /* check if this TAPA task is attached to anyone */
3589    if (tTsk->sTsk == NULLP)
3590    {
3591       SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
3592
3593   /* ss006.13: addition */
3594      if ( SUnlock(&osCp.sTskTblLock) != ROK)
3595      {
3596 #if (ERRCLASS & ERRCLS_DEBUG)
3597         SSLOGERROR(ERRCLS_DEBUG, ESS494, ERRZERO,
3598                      "Could not give the Semaphore");
3599         RETVALUE(RFAILED);
3600 #endif
3601      }
3602       RETVALUE(ROK);
3603    }
3604
3605
3606    /* we get the system task entry out */
3607    sTsk = tTsk->sTsk;
3608
3609
3610    /* We unlock the TAPA task table here, and then re-lock it later
3611     *  because of lock sequencing--we have to lock the system task
3612     *  entry first, and then the TAPA task table. Note, the system
3613     *  task table is locked, so nobody can sneak in and destroy the
3614     *  system task while we're doing this.
3615     */
3616    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
3617
3618
3619    /* lock the system task entry */
3620    if (!SS_CHECK_CUR_STSK(sTsk))
3621    {
3622       ret = SLock(&sTsk->lock);
3623       if (ret != ROK)
3624       {
3625
3626   /* ss006.13: addition */
3627        if ( SUnlock(&osCp.sTskTblLock) != ROK)
3628        {
3629 #if (ERRCLASS & ERRCLS_DEBUG)
3630           SSLOGERROR(ERRCLS_DEBUG, ESS495, ERRZERO,
3631                      "Could not give the Semaphore");
3632           RETVALUE(RFAILED);
3633 #endif
3634        }
3635
3636 #if (ERRCLASS & ERRCLS_DEBUG)
3637          SSLOGERROR(ERRCLS_DEBUG, ESS496, (ErrVal) ret,
3638                         "Could not lock system task entry");
3639 #endif
3640
3641          RETVALUE(RFAILED);
3642       }
3643    }
3644
3645
3646    /* now we lock the TAPA task table */
3647    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
3648    if (ret != ROK)
3649    {
3650
3651   /* ss006.13: addition */
3652       if ( SUnlock(&sTsk->lock) != ROK)
3653       {
3654 #if (ERRCLASS & ERRCLS_DEBUG)
3655           SSLOGERROR(ERRCLS_DEBUG, ESS497, ERRZERO,
3656                      "Could not give the Semaphore");
3657           RETVALUE(RFAILED);
3658 #endif
3659       }
3660       if ( SUnlock(&osCp.sTskTblLock) != ROK)
3661       {
3662 #if (ERRCLASS & ERRCLS_DEBUG)
3663           SSLOGERROR(ERRCLS_DEBUG, ESS498, ERRZERO,
3664                      "Could not give the Semaphore");
3665           RETVALUE(RFAILED);
3666 #endif
3667       }
3668
3669 #if (ERRCLASS & ERRCLS_DEBUG)
3670       SSLOGERROR(ERRCLS_DEBUG, ESS499, ERRZERO,
3671                      "Could not lock TAPA task table");
3672 #endif
3673
3674       RETVALUE(RFAILED);
3675    }
3676
3677
3678    /* Now, we can safely update both the system task entry
3679     *  and the TAPA task entry. First, we update the TAPA
3680     *  task entry--nobody is running it now.
3681     */
3682    tTsk->sTsk = NULLP;
3683
3684
3685    /*  Remove this TAPA task from the system task's list of
3686     *  TAPA tasks to run.
3687     */
3688    for (i = 0;  i < SS_MAX_TTSKS;  i++)
3689    {
3690       if (sTsk->tTsks[i] == idx)
3691       {
3692          sTsk->tTsks[i] = SS_INVALID_IDX;
3693          sTsk->numTTsks--;
3694          break;
3695       }
3696    }
3697
3698
3699    /* call the implementation to do anything it needs to */
3700    ret = ssdDetachTTsk(tTsk);
3701
3702
3703    /* unlock the TAPA task table */
3704    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
3705
3706    /* unlock the system task entry */
3707    if (!SS_CHECK_CUR_STSK(sTsk))
3708    {
3709
3710   /* ss006.13: addition */
3711       if ( SUnlock(&sTsk->lock) != ROK)
3712       {
3713 #if (ERRCLASS & ERRCLS_DEBUG)
3714           SSLOGERROR(ERRCLS_DEBUG, ESS500, ERRZERO,
3715                      "Could not give the Semaphore");
3716           RETVALUE(RFAILED);
3717 #endif
3718       }
3719    }
3720
3721    /* unlock the system task table */
3722
3723   /* ss006.13: addition */
3724       if ( SUnlock(&osCp.sTskTblLock) != ROK)
3725       {
3726 #if (ERRCLASS & ERRCLS_DEBUG)
3727           SSLOGERROR(ERRCLS_DEBUG, ESS501, ERRZERO,
3728                      "Could not give the Semaphore");
3729           RETVALUE(RFAILED);
3730 #endif
3731       }
3732
3733
3734    /* If the implementation couldn't detach the task, we just
3735     *  return an error, nothing else we can do.
3736     */
3737    if (ret != ROK)
3738    {
3739       RETVALUE(RFAILED);
3740    }
3741
3742
3743    RETVALUE(ROK);
3744 } /* SDetachTTsk */
3745
3746 \f
3747 /*
3748 *
3749 *       Fun:   Post a message to a task
3750 *
3751 *       Desc:  This function is used to post a message to a TAPA
3752 *              task. The message is delivered to the demand queue
3753 *              of the system task that is running the specified
3754 *              destination task.
3755 *
3756 *       Ret:   ROK      - ok
3757 *              RFAILED  - failed, general (optional)
3758 *
3759 *       Notes:
3760 *
3761 *       File:  ss_task.c
3762 *
3763 */
3764 #ifdef ANSI
3765 PUBLIC S16 SPstTsk
3766 (
3767 Pst *pst,                       /* post information */
3768 Buffer *mBuf                    /* message to post */
3769 )
3770 #else
3771 PUBLIC S16 SPstTsk(pst, mBuf)
3772 Pst *pst;                       /* post information */
3773 Buffer *mBuf;                   /* message to post */
3774 #endif
3775 {
3776    S16 r;
3777    S16 i;
3778 #if (defined(SS_DRVR_SUPPORT))
3779    S16 j;
3780 #endif
3781    SsIdx dstIdx;
3782    SsIdx srcIdx;
3783    Prior prior;
3784    SsTTskEntry *tTsk;
3785    SsMsgInfo *msgInfo;
3786 #if (defined(SS_DRVR_SUPPORT)  ||  defined(SS_RTR_SUPPORT))
3787    Pst nPst;
3788 #endif
3789 #ifdef SS_DRVR_SUPPORT
3790    Bool nPstUsed = FALSE;
3791 #endif
3792 #if (defined(SS_RTR_SUPPORT))
3793    Route rte;
3794 #endif
3795 /* ss029.103: addition: multiple procIds related changes */ 
3796 #ifdef SS_MULTIPLE_PROCS
3797    U16 srcProcIdIdx;
3798    U16 dstProcIdIdx;
3799 #endif /* SS_MULTIPLE_PROCS */
3800 /*ss004.301: Cavium changes */
3801 #ifdef SS_SEUM_CAVIUM
3802    Buffer  *wqBuf;
3803    S16     ret;
3804    cvmx_wqe_t *workPtr;
3805 #endif /* SS_SEUM_CAVIUM */
3806
3807         S16  retValue = 0; 
3808    Pst  tempPst;
3809
3810 #ifdef MSPD_MLOG_NEW
3811    U32 t = MacGetTick();
3812 #endif
3813  
3814    TRC1(SPstTsk);
3815
3816
3817 #if (ERRCLASS & ERRCLS_INT_PAR)
3818    /* check the message buffer */
3819    if (mBuf == NULLP)
3820    {
3821       SSLOGERROR(ERRCLS_INT_PAR, ESS502, ERRZERO, "Invalid message buffer");
3822       RETVALUE(RFAILED);
3823    }
3824
3825    /* check the pst structure */
3826    if (pst == NULLP)
3827    {
3828       SPutMsg(mBuf);
3829       SSLOGERROR(ERRCLS_INT_PAR, ESS503, ERRZERO, "Null pointer");
3830       RETVALUE(RFAILED);
3831    }
3832    /* ss021.103 - Addition to check for valid route */
3833    /* ss023.103 - Modification to fix bug in route validation */
3834    /* check the route */
3835    if (pst->route == RTENC)
3836    {
3837       SPutMsg(mBuf);
3838       SSLOGERROR(ERRCLS_INT_PAR, ESS504, ERRZERO, "No route defined");
3839       RETVALUE(RFAILED);
3840    }
3841 #endif
3842
3843 #ifndef TENB_RTLIN_CHANGES
3844    /* lock the TAPA task table */
3845    SS_ACQUIRE_SEMA(&osCp.tTskTblSem, r);
3846    if (r != ROK)
3847    {
3848       SPutMsg(mBuf);
3849
3850 #if (ERRCLASS & ERRCLS_DEBUG)
3851       SSLOGERROR(ERRCLS_DEBUG, ESS505, ERRZERO,
3852                      "Could not lock TAPA task table");
3853 #endif
3854
3855       RETVALUE(RFAILED);
3856    }
3857 #endif
3858
3859 #if (ERRCLASS & ERRCLS_INT_PAR)
3860 /* ss029.103: addition: multiple procIds related changes */ 
3861 #ifdef SS_MULTIPLE_PROCS
3862    if (pst->srcProcId == SS_INV_PROCID || pst->srcEnt >= SS_MAX_ENT       ||
3863        pst->srcInst >= SS_MAX_INST     || pst->dstProcId == SS_INV_PROCID ||
3864        pst->dstEnt >= SS_MAX_ENT       ||  pst->dstInst >= SS_MAX_INST)
3865 #else /* SS_MULTIPLE_PROCS */
3866    if (pst->srcEnt >= SS_MAX_ENT       ||  pst->srcInst >= SS_MAX_INST    ||
3867        pst->dstEnt >= SS_MAX_ENT       ||  pst->dstInst >= SS_MAX_INST)
3868 #endif /* SS_MULTIPLE_PROCS */
3869    {
3870 #ifndef TENB_RTLIN_CHANGES
3871  /* ss006.13: addition */
3872       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
3873       {
3874 #if (ERRCLASS & ERRCLS_DEBUG)
3875       SSLOGERROR(ERRCLS_DEBUG, ESS506, ERRZERO,
3876                      "Could not release the semaphore");
3877       RETVALUE(RFAILED);
3878 #endif
3879       }
3880 #endif
3881
3882       SPutMsg(mBuf);
3883
3884       SSLOGERROR(ERRCLS_INT_PAR, ESS507, ERRZERO,
3885                   "Invalid source/destination entity/instance");
3886
3887       RETVALUE(RFAILED);
3888    }
3889 #endif
3890
3891    /* ss019.103 - modified for use with message router in virtual/physical
3892     * configuration */
3893
3894 #ifdef SS_RTR_SUPPORT
3895    /* check if we have a router task registered for this route */
3896    if (pst->route < RTENC  &&  osCp.rtrTskTbl[pst->route] != NULLP)
3897    {
3898       /* copy the Pst structure into a local duplicate */
3899       for (i = 0;  i < (S16)sizeof(Pst);  i++)
3900       {
3901          *(((U8 *)(&nPst)) + i) = *(((U8 *) pst) + i);
3902       }
3903       pst = &nPst;
3904 #ifdef SS_DRVR_SUPPORT
3905       nPstUsed = TRUE;
3906 #endif
3907
3908       /* lock the router task entry */
3909       rte = pst->route;
3910       r = SLock(&osCp.rtrTskLocks[rte]);
3911       if (r != ROK)
3912       {
3913  /* ss006.13: addition */
3914 #ifndef TENB_RTLIN_CHANGES
3915          if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
3916          {
3917 #if (ERRCLASS & ERRCLS_DEBUG)
3918             SSLOGERROR(ERRCLS_DEBUG, ESS508, ERRZERO,
3919                      "Could not release the semaphore");
3920             RETVALUE(RFAILED);
3921 #endif
3922           }
3923 #endif
3924          SPutMsg(mBuf);
3925
3926 #if (ERRCLASS & ERRCLS_DEBUG)
3927          SSLOGERROR(ERRCLS_DEBUG, ESS509, ERRZERO,
3928                      "Could not lock router task entry");
3929 #endif
3930
3931          RETVALUE(RFAILED);
3932       }
3933
3934       /* call the router activation function */
3935       r = (*osCp.rtrTskTbl[rte])(pst, mBuf);
3936
3937       /* unlock the router task entry */
3938
3939   /* ss006.13: addition */
3940       if ( SUnlock(&osCp.rtrTskLocks[rte]) != ROK)
3941       {
3942 #if (ERRCLASS & ERRCLS_DEBUG)
3943           SSLOGERROR(ERRCLS_DEBUG, ESS510, ERRZERO,
3944                      "Could not give the Semaphore");
3945           RETVALUE(RFAILED);
3946 #endif
3947       }
3948
3949       if (r == RFAILED  ||  r == ROKIGNORE)
3950       {
3951  /* ss006.13: addition */
3952 #ifndef TENB_RTLIN_CHANGES
3953          if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
3954          {
3955 #if (ERRCLASS & ERRCLS_DEBUG)
3956             SSLOGERROR(ERRCLS_DEBUG, ESS511, ERRZERO,
3957                      "Could not release the semaphore");
3958             RETVALUE(RFAILED);
3959 #endif
3960           }
3961 #endif
3962          RETVALUE((r == RFAILED) ? RFAILED : ROK);
3963       }
3964    }
3965 #endif  /* SS_RTR_SUPPORT */
3966
3967 /* ss029.103: addition: multiple procIds related changes */ 
3968 #ifdef SS_MULTIPLE_PROCS
3969
3970    /* get proc id index */
3971    srcProcIdIdx = SGetProcIdIdx(pst->srcProcId);
3972    dstProcIdIdx = SGetProcIdIdx(pst->dstProcId);
3973
3974    if (srcProcIdIdx != SS_INV_PROCID_IDX)
3975       srcIdx = osCp.tTskIds[srcProcIdIdx][pst->srcEnt][pst->srcInst];
3976
3977    if (dstProcIdIdx != SS_INV_PROCID_IDX)
3978       dstIdx = osCp.tTskIds[dstProcIdIdx][pst->dstEnt][pst->dstInst];
3979
3980    if (((srcProcIdIdx != SS_INV_PROCID_IDX) && (srcIdx == SS_TSKNC)) || 
3981        ((dstProcIdIdx != SS_INV_PROCID_IDX) && (dstIdx == SS_TSKNC)))
3982    {
3983 #ifndef TENB_RTLIN_CHANGES
3984       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
3985       {
3986 #if (ERRCLASS & ERRCLS_DEBUG)
3987       SSLOGERROR(ERRCLS_DEBUG, ESS512, ERRZERO,
3988                      "Could not release the semaphore");
3989       RETVALUE(RFAILED);
3990 #endif
3991       }
3992 #endif
3993
3994       SPutMsg(mBuf);
3995
3996 #if (ERRCLASS & ERRCLS_DEBUG)
3997       SSLOGERROR(ERRCLS_DEBUG, ESS513, ERRZERO, "Unknown task");
3998 #endif
3999
4000       RETVALUE(RFAILED);
4001    }
4002
4003 #else /* SS_MULTIPLE_PROCS */
4004    /* ss019.103 - modified for use with message router in virtual/physical
4005     * configuration */
4006
4007    /* get the src and destination task */
4008    srcIdx = osCp.tTskIds[pst->srcEnt][pst->srcInst];
4009    dstIdx = osCp.tTskIds[pst->dstEnt][pst->dstInst];
4010
4011
4012    /* If the source/destination processor ID is local, the
4013     *  source/destination TAPA task must be local.
4014     */
4015    if ((pst->srcProcId == osCp.procId  &&  srcIdx == SS_TSKNC) 
4016       ||  (pst->dstProcId == osCp.procId  &&  dstIdx == SS_TSKNC))
4017    {
4018  /* ss006.13: addition */
4019 #ifndef TENB_RTLIN_CHANGES
4020       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4021       {
4022 #if (ERRCLASS & ERRCLS_DEBUG)
4023       SSLOGERROR(ERRCLS_DEBUG, ESS514, ERRZERO,
4024                      "Could not release the semaphore");
4025       RETVALUE(RFAILED);
4026 #endif
4027       }
4028 #endif
4029       SPutMsg(mBuf);
4030
4031 #if (ERRCLASS & ERRCLS_DEBUG)
4032       SSLOGERROR(ERRCLS_DEBUG, ESS515, ERRZERO, "Unknown task");
4033 #endif
4034
4035       RETVALUE(RFAILED);
4036    }
4037
4038 #endif /* SS_MULTIPLE_PROCS */
4039
4040 #ifdef SS_DRVR_SUPPORT
4041    /* Check for the destination procId. If it is non-local,
4042     *  we need to find the driver task that will handle this
4043     *  message.
4044     */
4045 /* ss029.103: addition: multiple procIds related changes */ 
4046 #ifdef SS_MULTIPLE_PROCS
4047    if (dstProcIdIdx == SS_INV_PROCID_IDX)
4048 #else /* SS_MULTIPLE_PROCS */
4049    if (pst->dstProcId != osCp.procId)
4050 #endif /* SS_MULTIPLE_PROCS */
4051    {
4052       /*  Need to optimize this search.
4053        */
4054       for (i = 0;  i < SS_MAX_DRVRTSKS;  i++)
4055       {
4056          if (osCp.drvrTskTbl[i].used
4057                &&  pst->dstProcId >= osCp.drvrTskTbl[i].low
4058                &&  pst->dstProcId <= osCp.drvrTskTbl[i].high)
4059          {
4060             /* Copy the Pst structure into a local duplicate if not
4061              *  already done.
4062              */
4063             if (!nPstUsed)
4064             {
4065                for (j = 0;  j < (S16)sizeof(Pst);  j++)
4066                {
4067                   *(((U8 *)(&nPst)) + j) = *(((U8 *) pst) + j);
4068                }
4069                pst = &nPst;
4070                nPstUsed = TRUE;
4071             }
4072
4073
4074 #ifdef L2_L3_SPLIT           
4075 //if (clusterMode == NET_CLUSTER_MODE)
4076 {
4077 #endif
4078             /* lock the driver task entry */
4079             r = SLock(&osCp.drvrTskTbl[i].lock);
4080             if (r != ROK)
4081             {
4082  /* ss006.13: addition */
4083 #ifndef TENB_RTLIN_CHANGES
4084                if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4085                {
4086 #if (ERRCLASS & ERRCLS_DEBUG)
4087                   SSLOGERROR(ERRCLS_DEBUG, ESS516, ERRZERO,
4088                      "Could not release the semaphore");
4089                   RETVALUE(RFAILED);
4090 #endif
4091                }
4092 #endif
4093                SPutMsg(mBuf);
4094
4095 #if (ERRCLASS & ERRCLS_DEBUG)
4096                SSLOGERROR(ERRCLS_DEBUG, ESS517, ERRZERO,
4097                            "Could not lock driver task entry");
4098 #endif
4099
4100                RETVALUE(RFAILED);
4101             }
4102 #ifdef L2_L3_SPLIT
4103 }
4104 #endif
4105 /*ss014.301 SSI-4GMX specific change*/
4106 #ifndef SS_4GMX_LCORE
4107             CMCHKPKLOG(cmPkInst, osCp.drvrTskTbl[i].channel, mBuf, ESS518, pst);
4108 #endif
4109
4110             (osCp.drvrTskTbl[i].actvTsk)(pst, mBuf);
4111
4112             /* unlock */
4113 #ifdef L2_L3_SPLIT           
4114 //if (clusterMode == NET_CLUSTER_MODE)
4115 {
4116 #endif
4117              /* ss006.13: addition */
4118             if ( SUnlock(&osCp.drvrTskTbl[i].lock) != ROK)
4119             {
4120 #if (ERRCLASS & ERRCLS_DEBUG)
4121               SSLOGERROR(ERRCLS_DEBUG, ESS519, ERRZERO,
4122                      "Could not give the Semaphore");
4123               RETVALUE(RFAILED);
4124 #endif
4125             }
4126 #ifdef L2_L3_SPLIT
4127 }
4128 #endif
4129
4130  /* ss006.13: addition */
4131 #ifndef TENB_RTLIN_CHANGES
4132             if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4133             {
4134 #if (ERRCLASS & ERRCLS_DEBUG)
4135                SSLOGERROR(ERRCLS_DEBUG, ESS520, ERRZERO,
4136                      "Could not release the semaphore");
4137                RETVALUE(RFAILED);
4138 #endif
4139             }
4140 #endif
4141             RETVALUE(ROK);
4142          }
4143       }
4144
4145  /* ss006.13: addition */
4146 #ifndef TENB_RTLIN_CHANGES
4147       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4148       {
4149 #if (ERRCLASS & ERRCLS_DEBUG)
4150            SSLOGERROR(ERRCLS_DEBUG, ESS521, ERRZERO,
4151                      "Could not release the semaphore");
4152             RETVALUE(RFAILED);
4153 #endif
4154       }
4155 #endif
4156       SPutMsg(mBuf);
4157
4158 #if (ERRCLASS & ERRCLS_DEBUG)
4159       SSLOGERROR(ERRCLS_DEBUG, ESS522, ERRZERO,
4160                   "Could not find a driver task to handle this proc ID");
4161 #endif
4162
4163       RETVALUE(RFAILED);
4164    }
4165 #endif  /* SS_DRVR_SUPPORT */
4166  /* ss002.301 Modifications */
4167    /*  Write the message to the demand queue of the system
4168     *  task which is running the destination task
4169     */
4170    tTsk = &osCp.tTskTbl[dstIdx];
4171
4172         cmMemcpy((U8*)&tempPst, (U8*)pst, sizeof(Pst));
4173    if(tTsk->cbTsk != NULLP)
4174    {
4175       retValue = tTsk->cbTsk(&tempPst,mBuf);
4176                 if(retValue != ROK)
4177                 {
4178 #ifndef TENB_RTLIN_CHANGES
4179               if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4180            {
4181 #if (ERRCLASS & ERRCLS_DEBUG)
4182                 SSLOGERROR(ERRCLS_DEBUG, ESS512, ERRZERO,
4183                      "Could not release the semaphore");
4184                 RETVALUE(RFAILED);
4185 #endif
4186         }
4187 #endif
4188
4189 #if (ERRCLASS & ERRCLS_DEBUG)
4190         SSLOGERROR(ERRCLS_DEBUG, ESS513, ERRZERO, "call back function failed\n");
4191 #endif
4192                         RETVALUE(ROK);
4193                 }
4194 #ifdef SS_MULTIPLE_PROCS
4195                 dstIdx = osCp.tTskIds[dstProcIdIdx][tempPst.dstEnt][tempPst.dstInst];
4196 #else
4197       dstIdx = osCp.tTskIds[tempPst.dstEnt][tempPst.dstInst];
4198 #endif 
4199       tTsk = &osCp.tTskTbl[dstIdx];
4200    }
4201
4202    /* plug the Pst structure into the message information portion */
4203    msgInfo = (SsMsgInfo *) (mBuf->b_rptr);
4204    for (i = 0;  i < (S16 )sizeof(Pst);  i++)
4205       *(((U8 *)(&msgInfo->pst)) + i) = *(((U8 *) &(tempPst)) + i);
4206
4207 /* ss004.301 : Cavium cahnges */
4208 #ifdef SS_SEUM_CAVIUM
4209    if (pst->dstProcId != osCp.procId)
4210    {
4211       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4212       {
4213 #if (ERRCLASS & ERRCLS_DEBUG)
4214          SSLOGERROR(ERRCLS_DEBUG, ESS527, ERRZERO,
4215             "Could not release the semaphore");
4216          RETVALUE(RFAILED);
4217 #endif
4218       }
4219
4220       /* Copy the message to the FPA region */
4221       ret = SCpyMsgFpa(mBuf, &wqBuf);
4222       if( ret != ROK )
4223       {
4224          /* No need to free the buffer, its already done in called fun */
4225          RETVALUE(RFAILED);
4226       }
4227
4228       /* Allocate for the mBuf */
4229       /* ss010.301: Cavium 32 bit changes */
4230       workPtr = cvmx_fpa_alloc(SS_CVMX_WQE_POOL);
4231       if( workPtr == NULLP )
4232       {
4233          SPutFpaMsg(wqBuf);
4234          RETVALUE(RFAILED);
4235       }
4236
4237       /* Convert the pointers to physical address */
4238       ret = SConvPtrPhy(&wqBuf);
4239       if( ret != ROK )
4240       {
4241          SPutFpaMsg(wqBuf);
4242          RETVALUE(RFAILED);
4243       }
4244
4245       /* Assign the values for work ptr */
4246       workPtr->qos      = 0;
4247       workPtr->grp      = pst->dstProcId;
4248       workPtr->tag_type = CVMX_POW_TAG_TYPE_NULL;
4249       workPtr->tag      = SS_CVMX_MBUF_TAG;
4250
4251       workPtr->packet_ptr.ptr = (Void*)wqBuf;
4252
4253       cvmx_pow_work_submit(workPtr, workPtr->tag, workPtr->tag_type, \
4254             workPtr->qos, workPtr->grp);
4255
4256       RETVALUE(ROK);
4257    }
4258 #endif /* SS_SEUM_CAVIUM */
4259
4260
4261    /*  Write the message to the demand queue of the system
4262     *  task which is running the destination task
4263     */
4264    tTsk = &osCp.tTskTbl[dstIdx];
4265    prior = tTsk->tskPrior;
4266
4267    if (tTsk->sTsk == NULLP)
4268    {
4269  /* ss006.13: addition */
4270 #ifndef TENB_RTLIN_CHANGES
4271       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4272       {
4273 #if (ERRCLASS & ERRCLS_DEBUG)
4274            SSLOGERROR(ERRCLS_DEBUG, ESS523, ERRZERO,
4275                      "Could not release the semaphore");
4276             RETVALUE(RFAILED);
4277 #endif
4278       }
4279 #endif
4280       SPutMsg(mBuf);
4281
4282 #if (ERRCLASS & ERRCLS_DEBUG)
4283       SSLOGERROR(ERRCLS_DEBUG, ESS524, (ErrVal) 0,
4284                  "Destination TAPA task is not attached");
4285 #endif
4286
4287       RETVALUE(RFAILED);
4288    }
4289
4290 #ifdef SS_LOCKLESS_MEMORY
4291    msgInfo->region = tTsk->sTsk->region;
4292    msgInfo->pst.region = tTsk->sTsk->region;
4293 #endif /* SS_LOCKLESS_MEMORY */
4294
4295 /*ss014.301 SSI-4GMX specific changes*/   
4296 #ifndef SS_4GMX_LCORE
4297    r = ssDmndQPutLast(&tTsk->sTsk->dQ, mBuf,
4298                            ((prior * SS_MAX_MSG_PRI) + tempPst.prior));
4299 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
4300    {
4301       extern Bool g_usettitmr;
4302       if (g_usettitmr)
4303       {
4304          if (tTsk->sTsk->tskPrior == PRIOR0)
4305          {
4306             SsTTskEntry *srctTsk;
4307             srctTsk = &osCp.tTskTbl[srcIdx];
4308             if ((srctTsk->sTsk == tTsk->sTsk)
4309 #if defined(SPLIT_RLC_DL_TASK) && !defined(RLC_MAC_DAT_REQ_RBUF)
4310                 ||
4311                 ((pst->dstEnt == ENTRG) && 
4312                  (pst->srcEnt == ENTKW) && 
4313                  (pst->event == EVTRGUDDATREQ))
4314 #endif
4315                )
4316 #ifdef RGL_SPECIFIC_CHANGES
4317                WLS_WakeUp(mtGetWlsHdl());
4318 #else
4319                tlPost(NULLP);
4320 #endif
4321          }
4322       }
4323       else if (tTsk->sTsk->tskPrior == PRIOR0)
4324 #ifdef RGL_SPECIFIC_CHANGES
4325          WLS_WakeUp(mtGetWlsHdl());
4326 #else
4327          tlPost(NULLP);
4328 #endif
4329    }
4330 #endif 
4331 #else
4332    if(tTsk->actvTsk != NULLP)
4333    {
4334        if(tTsk->cbTsk != NULLP)
4335        {
4336            r = rbICorePstTsk(&tempPst, mBuf, tTsk);
4337        }
4338        else
4339        {
4340            r = rbICorePstTsk(pst, mBuf, tTsk);
4341        }
4342    }
4343    else
4344    {
4345        r = RFAILED;
4346    }
4347 #endif
4348    if (r != ROK)
4349    {
4350  /* ss006.13: addition */
4351 #ifndef TENB_RTLIN_CHANGES
4352       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4353       {
4354 #if (ERRCLASS & ERRCLS_DEBUG)
4355            SSLOGERROR(ERRCLS_DEBUG, ESS525, ERRZERO,
4356                      "Could not release the semaphore");
4357             RETVALUE(RFAILED);
4358 #endif
4359       }
4360 #endif
4361       SPutMsg(mBuf);
4362
4363 #if (ERRCLASS & ERRCLS_ADD_RES)
4364       SSLOGERROR(ERRCLS_ADD_RES, ESS526, (ErrVal) r,
4365                      "Could not write to demand queue");
4366 #endif
4367
4368       RETVALUE(RFAILED);
4369    }
4370
4371
4372    /* unlock, we're done */
4373  /* ss006.13: addition */
4374 #ifndef TENB_RTLIN_CHANGES
4375    if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4376    {
4377 #if (ERRCLASS & ERRCLS_DEBUG)
4378         SSLOGERROR(ERRCLS_DEBUG, ESS527, ERRZERO,
4379                   "Could not release the semaphore");
4380         RETVALUE(RFAILED);
4381 #endif
4382    }
4383 #endif
4384
4385
4386    /* If the implementation has anything to do... note that
4387     *  we call it unlocked at this time.
4388     */
4389    ssdPstTsk(tempPst, mBuf, tTsk);
4390
4391    RETVALUE(ROK);
4392 } /* SPstTsk */
4393
4394 /* ss001.301: additions */
4395 #ifdef SS_HISTOGRAM_SUPPORT 
4396 /*
4397 *
4398 *       fun :  SGetTapaTskEntIds
4399 *
4400 *       Desc:  Get the tapa task entity id, which are registerd for SSI.
4401 *
4402 *       Ret:   ROK      - ok
4403 *              RFAILED  - failed, general (optional)
4404 *              ROUTRES  - failed, out of resources (optional)
4405 *
4406 *       Notes:
4407 *
4408 *       File:  ss_task.c
4409 *
4410 */
4411 /* ss029.103: modification: procId added */
4412
4413 #ifdef ANSI
4414 PUBLIC S16 SGetTapaTskEntIds
4415 (
4416 Ent *ent                        /* entity */
4417 )
4418 #else
4419 PUBLIC S16 SGetTapaTskEntIds(ent)
4420 Ent *ent;                        /* entity */
4421 #endif
4422 {
4423
4424    U32 tskCnt = 0;
4425
4426    TRC1(SGetTapaTskEntIds);
4427    /* Get the tapa task entity Ids from the osCp structure */
4428    for(tskCnt = 0; tskCnt < osCp.numTTsks; tskCnt++)
4429    {
4430       ent[tskCnt] = osCp.tTskTbl[tskCnt].ent;
4431    }
4432
4433    RETVALUE(ROK);
4434 } /* SGetTapaTskEntIds */
4435
4436 /*
4437 *
4438 *       Fun:   SRegForHstGrm
4439 *
4440 *       Desc:  This function is used to register a TAPA task,
4441 *              for histogram facilty.
4442 *
4443 *       Ret:   ROK      - ok
4444 *              RFAILED  - failed, general (optional)
4445 *              ROUTRES  - failed, out of resources (optional)
4446 *
4447 *       Notes:
4448 *
4449 *       File:  ss_task.c
4450 *
4451 */
4452 /* ss029.103: modification: procId added */
4453
4454 #ifdef ANSI
4455 PUBLIC S16 SRegForHstGrm
4456 (
4457 Ent ent                        /* entity */
4458 )
4459 #else
4460 PUBLIC S16 SRegForHstGrm(ent)
4461 Ent ent;                        /* entity */
4462 #endif
4463 {
4464
4465    U32 tskCnt = 0;
4466    S16 r = 0;
4467
4468    TRC1(SRegForHstGrm);
4469
4470    SS_ACQUIRE_SEMA(&osCp.tTskTblSem, r);
4471    if (r != ROK)
4472    {
4473 #if (ERRCLASS & ERRCLS_DEBUG)
4474       SSLOGERROR(ERRCLS_DEBUG, ESS623, ERRZERO,
4475                      "Could not lock TAPA task table");
4476 #endif
4477
4478       RETVALUE(RFAILED);
4479    }
4480
4481    for(tskCnt = 0; tskCnt < osCp.numTTsks; tskCnt++)
4482    {
4483       if(osCp.tTskTbl[tskCnt].ent == ent)
4484       {
4485          osCp.tTskTbl[tskCnt].hstReg = TRUE;
4486          break;
4487       }
4488    }
4489
4490    if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
4491    {
4492 #if (ERRCLASS & ERRCLS_DEBUG)
4493          SSLOGERROR(ERRCLS_DEBUG, ESS639, ERRZERO,
4494                    "Could not release the semaphore");
4495           RETVALUE(RFAILED);
4496 #endif
4497     }
4498
4499    RETVALUE(ROK);
4500 } /* SGetTapaTskEntIds */
4501
4502 /*
4503 *
4504 *       Fun:   SGetHstGrmInfo
4505 *
4506 *       Desc : Get the Histogram registration for TAPA task
4507 *
4508 *       Ret:   ROK      - ok
4509 *              RFAILED  - failed, general (optional)
4510 *              ROUTRES  - failed, out of resources (optional)
4511 *
4512 *       Notes:
4513 *
4514 *       File:  ss_task.c
4515 *
4516 */
4517 #ifdef ANSI
4518 PUBLIC S16 SGetHstGrmInfo
4519 (
4520 Ent   *entId,
4521 Bool  *hstReg                        /* entity */
4522 )
4523 #else
4524 PUBLIC S16 SGetHstGrmInfo(entId, hstReg)
4525 Ent   *entId;
4526 Bool  *hstReg;                        /* entity */
4527 #endif
4528 {
4529
4530    U32 tskCnt = 0;
4531    Bool found = FALSE;
4532    *hstReg = 0;
4533
4534    TRC1(SGetHstGrmInfo);
4535    for(tskCnt = 0; tskCnt < osCp.numTTsks; tskCnt++)
4536    {
4537       if( *entId == osCp.tTskTbl[tskCnt].ent)
4538       {
4539          *hstReg = osCp.tTskTbl[tskCnt].hstReg;
4540          found = TRUE;
4541           break;
4542       }
4543    }
4544
4545    if(!found)
4546    {
4547       *entId = ENTNC;
4548       *hstReg = TRUE;
4549    }
4550
4551    RETVALUE(ROK);
4552 } /* SGetTapaTskEntIds */
4553
4554 #endif /* SS_HISTOGRAM_SUPPORT */
4555
4556 #ifdef SS_WATCHDOG
4557 #ifdef ANSI
4558 PUBLIC S16 SInitWatchdog
4559 (
4560 U16 port
4561 )
4562 #else
4563 PUBLIC S16 SInitWatchdog(port)
4564 U16 port;
4565 #endif
4566 {
4567  return ssdInitWatchDog(port);
4568 }
4569
4570 #ifdef ANSI
4571 PUBLIC S16 SRegCfgWd
4572 (
4573 U32 numNodes,
4574 U8  *addr[],
4575 U16 port[],
4576 U32 timeout,
4577 WdUserCallback callback,
4578 void *data
4579 )
4580 #else
4581 PUBLIC S16 SRegCfgWd(numNodes, addr, port, timeout, callback, data)
4582 U32 numNodes;
4583 U8  *addr[];
4584 U16 port[];
4585 U32 timeout;
4586 WdUserCallback callback;
4587 void *data;
4588 #endif
4589 {
4590    Txt prntBuf[PRNTSZE];
4591    int i = 0;
4592
4593    /*ss013.301 :Fix for TRACE5 feature crash due to missing TRC MACRO*/
4594    TRC1(SRegCfgWd)
4595
4596    osCp.wdCp.globWd.timeout = timeout;
4597    osCp.wdCp.globWd.callback = callback;
4598    osCp.wdCp.globWd.data = data;
4599    osCp.wdCp.globWd.numNodes = numNodes;
4600
4601    SLock(&osCp.wdCp.wdLock);
4602    for(i = 0; i < SS_MAX_WD_NODES && i < numNodes; i++)
4603    {
4604 #ifdef SS_WATCHDOG_IPV6
4605  /* ss002.301 Modifications */
4606       inet_pton(AF_INET6,(const char *)addr[i],osCp.wdCp.globWd.wdsta[i].addr);
4607 #else
4608       osCp.wdCp.globWd.wdsta[i].addr.s_addr = inet_addr((const char *)addr[i]);
4609 #endif /* SS_WATCHDOG_IPV6 */
4610       osCp.wdCp.globWd.wdsta[i].port = htons(port[i]);
4611       sprintf(prntBuf, "Configured [%s:%d] for watchdog\n", addr[i], port[i]);
4612       SPrint(prntBuf);
4613    }
4614    SUnlock(&osCp.wdCp.wdLock);
4615  /* ss002.301 Compilation fixes */
4616    /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
4617 #ifdef ALIGN_64BIT
4618    sprintf(prntBuf, "Configured %d nodes with timeout %u for Watchdog\n", osCp.wdCp.globWd.numNodes, osCp.wdCp.globWd.timeout);
4619 #else
4620    sprintf(prntBuf, "Configured %d nodes with timeout %lu for Watchdog\n", osCp.wdCp.globWd.numNodes, osCp.wdCp.globWd.timeout);
4621 #endif
4622    SPrint(prntBuf);
4623
4624    RETVALUE(ROK);
4625 }
4626
4627 #ifdef ANSI
4628 PUBLIC S16 SDeregCfgWd
4629 (
4630 void
4631 )
4632 #else
4633 PUBLIC S16 SDeregCfgWd(void)
4634 void;
4635 #endif
4636 {
4637    Txt prntBuf[PRNTSZE];
4638    int i = 0;
4639
4640    /*ss013.301 :Fix for TRACE5 feature crash due to missing TRC MACRO*/
4641    TRC1(SDeregCfgWd)
4642
4643    osCp.wdCp.globWd.timeout = 0;
4644    osCp.wdCp.globWd.callback = 0;
4645    osCp.wdCp.globWd.data = 0;
4646    osCp.wdCp.globWd.numNodes = 0;
4647
4648    SLock(&osCp.wdCp.wdLock);
4649    for(i = 0; i < SS_MAX_WD_NODES; i++)
4650    {
4651            /* ss002.301 Modifications */
4652       sprintf(prntBuf, "Deregister [%s:%d] for watchdog\n", inet_ntoa(osCp.wdCp.globWd.wdsta[i
4653 ].addr), osCp.wdCp.globWd.wdsta[i].port);
4654       osCp.wdCp.globWd.wdsta[i].addr.s_addr = 0;
4655        osCp.wdCp.globWd.wdsta[i].port = 0;
4656       SPrint(prntBuf);
4657    }
4658    SUnlock(&osCp.wdCp.wdLock);
4659
4660    /* Implicit watchdog stop during dereg */
4661    SStopHrtBt();
4662
4663    RETVALUE(ROK);
4664 }
4665
4666 #ifdef ANSI
4667 PUBLIC S16 SStartHrtBt
4668 (
4669 U8 timeInterval /* time interval */
4670 )
4671 #else
4672 PUBLIC S16 SStartHrtBt(timeInterval)
4673 U8 timeInterval;
4674 #endif
4675 {
4676    TRC1(SStartHrtBt);
4677
4678    ssdStartWatchDgTmr(NULLP, SS_TMR_HRTBT, timeInterval);
4679    ssdSndHrtBtMsg(TRUE, SS_WD_HB_REQ);
4680
4681    RETVALUE(ROK);
4682 }
4683
4684 #ifdef ANSI
4685 PUBLIC S16 SStopHrtBt
4686 (
4687 void
4688 )
4689 #else
4690 PUBLIC S16 SStopHrtBt()
4691 void
4692 #endif
4693 {
4694    TRC1(SStopHrtBt);
4695
4696    osCp.wdCp.globWd.watchdogStop = 1;
4697
4698    RETVALUE(ROK);
4699 }
4700
4701 #ifdef ANSI
4702 PUBLIC S16 watchDgActvTsk
4703 (
4704 Pst *pst,                   /* post */
4705 Buffer *mBuf                /* message buffer */
4706 )
4707 #else
4708 PUBLIC S16 watchDgActvTsk(pst, mBuf)
4709 Pst *pst;                   /* post */
4710 Buffer *mBuf;               /* message buffer */
4711 #endif
4712 {
4713 /* ss002.301 Fixed warnings */
4714 #ifdef DEBUGP
4715    DateTime dt;
4716    Txt prntBuf[PRNTSZE];
4717 #endif /* DEBUGP */
4718
4719    TRC3(watchDgActvTsk)
4720 #ifdef DEBUGP
4721    SGetDateTime(&dt);
4722    sprintf(prntBuf,"watchDgActvTsk: Time: %02d:%02d:%02d\n",dt.hour,dt.min, dt.sec
4723 );
4724    SPrint(prntBuf);
4725 #endif /* DEBUGP */
4726         RETVALUE(ROK);
4727 }
4728
4729 #ifdef ANSI
4730 PUBLIC S16 watchDgRcvrActvTsk
4731 (
4732 Pst *pst,                   /* post */
4733 Buffer *mBuf                /* message buffer */
4734 )
4735 #else
4736 PUBLIC S16 watchDgRcvrActvTsk(pst, mBuf)
4737 Pst *pst;                   /* post */
4738 Buffer *mBuf;               /* message buffer */
4739 #endif
4740 {
4741 #ifdef DEBUGP
4742    DateTime dt;
4743 #endif /* DEBUGP */
4744    Txt prntBuf[PRNTSZE];
4745    U16           n;
4746    S16                    err;
4747    struct sockaddr_in tmpaddr;
4748    Txt           hbMsg[SS_WD_HB_MSG_SIZE];
4749  /* ss002.301 Modifications */
4750 #ifdef SS_LINUX
4751         socklen_t         socklen = sizeof(struct sockaddr);
4752 #else
4753    int           socklen = sizeof(struct sockaddr);
4754 #endif
4755
4756    TRC3(watchDgActvTsk)
4757
4758 #ifdef DEBUGP
4759    SGetDateTime(&dt);
4760    sprintf(prntBuf,"watchDgRcvrActvTsk: Time: %02d:%02d:%02d\n",dt.hour, dt.min, dt.sec);
4761    SPrint(prntBuf);
4762 #endif /* DEBUGP */
4763
4764    while(!osCp.wdCp.globWd.watchdogStop)
4765    {
4766       err = recvfrom(osCp.wdCp.globWd.sock, hbMsg, SS_WD_HB_MSG_SIZE, 0, (struct sockaddr *)&tmpaddr, &socklen);
4767       if(err == -1)
4768       {
4769          sprintf(prntBuf,"watchDgRcvrActvTsk: recvfrom failed, errno %d\n", errno);
4770          SPrint(prntBuf);
4771          continue;
4772       }
4773
4774       if(strcmp(hbMsg, "<HB>REQ</HB>") == 0)
4775       {
4776          /* Send back the reply */
4777 #ifdef DEBUGP
4778          sprintf(prntBuf,"watchDgRcvrActvTsk: Recvd HB REQ message from [%s:%d]\n", inet_ntoa(tmpaddr.sin_addr), ntohs(tmpaddr.sin_port));
4779          SPrint(prntBuf);
4780 #endif /* DEBUGP */
4781
4782          strcpy(hbMsg, "<HB>RSP</HB>");
4783          sendto(osCp.wdCp.globWd.sock, hbMsg, strlen(hbMsg), 0, (struct sockaddr *)&tmpaddr, sizeof(tmpaddr));
4784       }
4785       else if(strcmp(hbMsg, "<HB>RSP</HB>") == 0)
4786       {
4787          /* Got a HB RSP, set the status for the correcponding node */
4788 #ifdef DEBUGP
4789          sprintf(prntBuf,"watchDgRcvrActvTsk: Recvd HB RSP message from [%s:%d]\n", inet_ntoa(tmpaddr.sin_addr), ntohs(tmpaddr.sin_port)); 
4790          SPrint(prntBuf);
4791 #endif /* DEBUGP */
4792
4793          SLock(&osCp.wdCp.wdLock);
4794          for(n = 0; n < osCp.wdCp.globWd.numNodes; n++)
4795          {
4796             if(osCp.wdCp.globWd.wdsta[n].addr.s_addr == tmpaddr.sin_addr.s_addr)
4797             {
4798                osCp.wdCp.globWd.wdsta[n].status = 1;
4799             }
4800          }
4801          SUnlock(&osCp.wdCp.wdLock);
4802       }
4803       else
4804       {
4805 #ifdef DEBUGP
4806          sprintf(prntBuf,"watchDgRcvrActvTsk: Rcvd invalid message\n");
4807          SPrint(prntBuf);
4808 #endif /* DEBUGP */
4809       }
4810    }
4811         RETVALUE(ROK);
4812 }
4813
4814 #endif /* SS_WATCHDOG */
4815
4816 /* ss002.301 Modifications */
4817 #ifdef SS_THREAD_PROFILE
4818 /*
4819 *
4820 *       Fun:   SGetThrdProf
4821 *
4822 *       Desc:  This function gets the current profile of a system task
4823 *              The function sets the Entity, Instance, Event and time taken
4824 *              for that thread to execurte the activate function of
4825 *              that entity.
4826 *
4827 *       Ret:   ROK      - ok
4828 *              RFAILED  - failed, general (optional)
4829 *
4830 *       Notes: This function may be called by the OS or Layer 1
4831 *              hardware drivers.
4832 *
4833 *       File:  mt_ss.c
4834 *
4835 */
4836 #ifdef SS_MULTIPLE_PROCS
4837 #ifdef ANSI
4838 PUBLIC S16 SGetThrdProf
4839 (
4840 SSTskId *sTskId,
4841 ProcId procId,
4842 Ent ent,                       /* entity */
4843 Inst inst,
4844 Event *curEvent,
4845 U32 *curEvtTime,
4846 U64 *totTime
4847 )
4848 #else
4849 PUBLIC S16 SGetThrdProf(sTskId, procId, ent, inst, evnt, curEvent, curEvtTime, totTime)
4850 SSTskId *sTskId;
4851 ProcId procId;
4852 Ent ent;                      /* entity */
4853 Inst inst;
4854 Event *curEvent;
4855 U32 *curEvtTime;
4856 U64 *totTime;
4857 #endif
4858 #else
4859 #ifdef ANSI
4860 PUBLIC S16 SGetThrdProf
4861 (
4862 SSTskId *sTskId,
4863 Ent ent,                       /* entity */
4864 Inst inst,
4865 Event *curEvent,
4866 U32 *curEvtTime,
4867 U64 *totTime
4868 )
4869 #else
4870 PUBLIC S16 SGetThrdProf(sTskId, ent, inst, curEvent,curEvtTime, totTime)
4871 SSTskId *sTskId;
4872 Ent ent;                      /* entity */
4873 Inst inst;
4874 Event *curEvent;
4875 U32 *curEvtTime;
4876 U64 *totTime;
4877 #endif
4878 #endif /* SS_MULTIPLE_PROCS */
4879 {
4880   S16 ret;
4881    SsIdx idx;
4882    SsTTskEntry *tTsk;
4883 #ifdef SS_MULTIPLE_PROCS
4884    U16 procIdIdx;
4885 #endif
4886
4887
4888    TRC1(SGetThrdProf);
4889
4890 #if (ERRCLASS & ERRCLS_INT_PAR)
4891    /* check entity and instance range */
4892 #ifdef SS_MULTIPLE_PROCS
4893    /* check proc, entity and instance range */
4894    if ((procId == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
4895    {
4896       SSLOGERROR(ERRCLS_INT_PAR, ESS463, ERRZERO, "Invalid processor/entity/instance");
4897       RETVALUE(RFAILED);
4898    }
4899 #else /* SS_MULTIPLE_PROCS */
4900    /* check entity and instance range */
4901    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
4902    {
4903       SSLOGERROR(ERRCLS_INT_PAR, ESS464, ERRZERO, "Invalid entity/instance");
4904       RETVALUE(RFAILED);
4905    }
4906 #endif /* SS_MULTIPLE_PROCS */
4907 #endif
4908
4909
4910    ret = SLock(&osCp.sTskTblLock);
4911    if (ret != ROK)
4912    {
4913       RETVALUE(RFAILED);
4914    }
4915
4916
4917 #ifdef SS_MULTIPLE_PROCS
4918     procIdIdx = SGetProcIdIdx(procId);
4919
4920     if (procIdIdx == SS_INV_PROCID_IDX)
4921     {
4922       RETVALUE(RFAILED);
4923     }
4924
4925     idx = osCp.tTskIds[procIdIdx][ent][inst];
4926 #else /* SS_MULTIPLE_PROCS */
4927     idx = osCp.tTskIds[ent][inst];
4928 #endif /* SS_MULTIPLE_PROCS */
4929
4930     tTsk = &osCp.tTskTbl[idx];
4931     if(tTsk == NULLP )
4932     {
4933              SUnlock(&osCp.sTskTblLock);
4934              RETVALUE(RFAILED);
4935     }
4936     *curEvent      = osCp.tTskTbl[idx].curEvent;
4937     *curEvtTime    = osCp.tTskTbl[idx].curEvtTime;
4938     *totTime       = osCp.tTskTbl[idx].totTime;
4939     *sTskId        = osCp.tTskTbl[idx].sTsk->tskId;
4940
4941    SUnlock(&osCp.sTskTblLock);
4942    RETVALUE(ROK);
4943 }
4944 #endif /* SS_THREAD_PROFILE */
4945
4946 #ifdef SS_FBSED_TSK_REG
4947 /*
4948 *
4949 *       Fun:   SRegTskInfo
4950 *
4951 *       Desc:  This function is used to register tasks based on cfg file.
4952 *
4953 *       Ret:   ROK      - ok
4954 *              RFAILED  - failed, general (optional)
4955 *
4956 *
4957 *       File:  ss_task.c
4958 *
4959 */
4960 #ifdef ANSI
4961 PUBLIC S16 SRegTskInfo
4962 (
4963 U8 *cfgFile
4964 )
4965 #else
4966 PUBLIC S16 SRegTskInfo(cfgFile)
4967 U8 *cfgFile;
4968 #endif
4969 {
4970    return cmCfgrTskReg(cfgFile); 
4971 }
4972 #endif /* SS_FBSED_TSK_REG */
4973
4974 /**********************************************************************
4975          End of file
4976 **********************************************************************/