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