Initial commit for Bronze release
[o-du/l2.git] / src / 5gnrsch / rg_sch_lmm.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
19 /************************************************************************
20  
21      Name:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code for Layer Manager Interface Module 
26   
27      File:     rg_sch_lmm.c 
28   
29 **********************************************************************/
30
31 /** @file rg_sch_lmm.c
32 @brief This file contains the Layer Management interface module implementation for scheduler.
33        The functions for the configuration, control, status and statistics 
34        request primitives are defined here.
35 */
36
37 static const char* RLOG_MODULE_NAME="MAC";
38 static int RLOG_MODULE_ID=4096;
39 static int RLOG_FILE_ID=167;
40
41 /* header include files (.h) */
42 #include "envopt.h"        /* environment options */
43 #include "envdep.h"        /* environment dependent */
44 #include "envind.h"        /* environment independent */
45 #include "gen.h"           /* general */
46 #include "ssi.h"           /* system services */
47 #include "cm_tkns.h"       /* Common Token Defines */
48 #include "cm_llist.h"      /* Common Link List Defines */
49 #include "cm_hash.h"       /* Common Hash List Defines */
50 #include "cm_mblk.h"       /* common memory link list library */
51 #include "cm_lte.h"        /* Common LTE Defines */
52 #include "rg_env.h"        /* MAC Environment Defines */
53 #include "rgr.h"           /* RGR Interface defines */
54 #include "tfu.h"           /* RGU Interface defines */
55 #include "lrg.h"           /* LRG Interface defines */
56 #include "rgm.h"           /* RGM Interface defines */
57 #include "rg_sch.h"        /* Scheduler defines */
58 #include "rg_sch_inf.h"        /* Scheduler defines */
59 #include "rg_sch_err.h"        /* MAC error defines */
60 #ifdef LTE_L2_MEAS
61 #include "rg_sch_cmn.h"    /* typedefs for Scheduler */
62 #endif
63 #include "rl_interface.h"
64 #include "rl_common.h"
65
66 /* header/extern include files (.x) */
67 #include "gen.x"           /* general */
68 #include "ssi.x"           /* system services */
69 #include "cm5.x"           /* system services */
70 #include "cm_tkns.x"       /* Common Token Definitions */
71 #include "cm_llist.x"      /* Common Link List Definitions */
72 #include "cm_lib.x"        /* Common Library Definitions */
73 #include "cm_hash.x"       /* Common Hash List Definitions */
74 #include "cm_mblk.x"       /* common memory link list library */
75 #include "cm_lte.x"        /* Common LTE Defines */
76 #include "rgr.x"           /* RGR Interface includes */
77 #include "rgm.x"           /* RGM Interface includes */
78 #include "tfu.x"           /* RGU Interface includes */
79 #include "lrg.x"           /* LRG Interface includes */
80 #include "rg_sch_inf.x"    /* Scheduler defines */
81 #include "rg_sch.x"        /* Scheduler includes */
82 #ifdef LTE_L2_MEAS
83 #include "rg_sch_cmn.x"    /* typedefs for Scheduler */
84 #endif 
85 #ifndef LTE_L2_MEAS
86 PUBLIC Void rgSCHCmnInit ARGS((Void));
87 #endif 
88 /* forward references */
89
90
91 PRIVATE U16 rgSCHLmmSapCfg ARGS((
92    Inst           inst,
93    RgCfg          *cfg,
94    U8             sapIdx,
95    Elmnt          sapType
96 ));
97
98 PRIVATE Void rgSCHLmmShutdown ARGS((
99    Inst inst
100 ));
101
102
103 PUBLIC void printSchCellInfo(void)
104 {
105    U8 idx=0;
106    U8 inst=0;
107    for (idx = 0; idx < rgSchCb[inst].numSaps; idx++)
108    {
109       /* Unbind all the TFU SAP */
110       /* Free the memory held by the cell associated
111        * with this SAP */
112       if (rgSchCb[inst].tfuSap[idx].cell != NULLP)
113       {
114          RLOG1(L_INFO,"CELL %d\n", idx);
115          RLOG1(L_INFO,"NUM UEs :%d\n",rgSchCb[inst].tfuSap[idx].cell->ueLst.nmbEnt);
116       }
117    }
118 }
119
120 \f
121 /**
122  * @brief Task Initiation callback function. 
123  *
124  * @details
125  *
126  *     Function : schActvInit
127  *     
128  *     This function is supplied as one of parameters during MAC's 
129  *     task registration. SSI will invoke this function once, after
130  *     it creates and attaches this TAPA Task to a system task.
131  *     
132  *  @param[in]  Ent Entity, the entity ID of this task.     
133  *  @param[in]  Inst Inst, the instance ID of this task.
134  *  @param[in]  Region Region, the region ID registered for memory 
135  *              usage of this task.
136  *  @param[in]  Reason Reason.
137  *  @return  S16
138  *      -# ROK
139  **/
140 #ifdef ANSI
141 PUBLIC S16 schActvInit
142 (
143 Ent    entity,            /* entity */
144 Inst   instId,             /* instance */
145 Region region,         /* region */
146 Reason reason          /* reason */
147 )
148 #else
149 PUBLIC S16 schActvInit(entity, instId, region, reason)
150 Ent    entity;            /* entity */
151 Inst   instId;             /* instance */
152 Region region;         /* region */
153 Reason reason;         /* reason */
154 #endif
155 {
156    Inst inst = (instId  - SCH_INST_START);
157
158    TRC2(schActvInit);
159
160    /* Initialize the MAC TskInit structure to zero */
161    cmMemset ((U8 *)&rgSchCb[inst], 0, sizeof(RgSchCb));
162
163    /* Initialize the MAC TskInit with received values */
164    rgSchCb[inst].rgSchInit.ent = entity;
165    rgSchCb[inst].rgSchInit.inst = inst;
166    rgSchCb[inst].rgSchInit.region = region;
167    rgSchCb[inst].rgSchInit.pool = 0;
168    rgSchCb[inst].rgSchInit.reason = reason;
169    rgSchCb[inst].rgSchInit.cfgDone = FALSE;
170    rgSchCb[inst].rgSchInit.acnt = FALSE;
171    rgSchCb[inst].rgSchInit.usta = FALSE;
172    rgSchCb[inst].rgSchInit.trc = FALSE;
173 #ifdef DEBUGP
174 #ifdef RG_DEBUG
175    /*  disabling debugs by default */
176    /* rgSchCb[inst].rgSchInit.dbgMask = 0xffffffff; */
177 #endif
178 #endif /* DEBUGP */
179    rgSchCb[inst].rgSchInit.procId = SFndProcId();
180
181    rgSchCb[inst].rgrSap = NULLP;
182    rgSchCb[inst].tfuSap = NULLP;
183    rgSchCb[inst].rgmSap = NULLP;
184    rgSCHCmnInit();
185
186    RETVALUE(ROK);
187 } /* schActvInit */
188 \f
189 \f
190 /**
191  * @brief SAP Configuration Handler. 
192  *
193  * @details
194  *
195  *     Function : rgSCHLmmSapCfg
196  *     
197  *     This function in called by HandleSchGenCfgReq(). It handles the
198  *     interface SAP configuration of the scheduler instance. It 
199  *     initializes the sapState to LRG_UNBND. Returns
200  *     reason for success/failure of this function.
201  *     
202  *  @param[in]  RgCfg *cfg, the Configuaration information 
203  *  @return  U16
204  *      -# LCM_REASON_GENCFG_NOT_DONE
205  *      -# LCM_REASON_INVALID_SAP
206  *      -# LCM_REASON_NOT_APPL
207  **/
208 #ifdef ANSI
209 PRIVATE U16 rgSCHLmmSapCfg
210 (
211 Inst  dInst,
212 RgCfg *cfg,            /* Configuaration information */
213 U8    sapIdx,          /* SAP index */
214 Elmnt sapType             /* SAP Type */
215 )
216 #else
217 PRIVATE U16 rgSCHLmmSapCfg(dInst, cfg, sapIdx, sapType)
218 Inst  dInst;
219 RgCfg *cfg;            /* Configuaration information */
220 U8    sapIdx;          /* SAP index */
221 Elmnt sapType;            /* SAP Type */
222 #endif
223 {
224    U16                  ret = LCM_REASON_NOT_APPL;
225    RgSchLowSapCfgInfo   *lowSapCfg = NULLP;
226    RgSchUpSapCfgInfo    *upSapCfg = NULLP;
227    Inst  inst = (dInst - SCH_INST_START);
228
229    TRC2(rgSCHLmmSapCfg)
230
231    /* Check if Gen Config has been done */
232
233    switch(sapType)
234    {   
235       case STRGRSAP:
236 #ifndef CL_MAC_LWLC
237          if ((cfg->s.schInstCfg.rgrSap[sapIdx].selector != RGR_SEL_TC) &&
238              (cfg->s.schInstCfg.rgrSap[sapIdx].selector != RGR_SEL_LC))
239          {
240             ret = LCM_REASON_INVALID_PAR_VAL;
241             RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "rgSCHLmmSapCfg(): unsupported"
242                " Selector value for RGR.");
243             break;
244          }
245 #endif
246          if(rgSchCb[inst].rgrSap[sapIdx].sapSta.sapState == LRG_NOT_CFG)
247          { 
248             rgSchCb[inst].rgrSap[sapIdx].sapSta.sapState = LRG_UNBND;
249          }
250          upSapCfg = &rgSchCb[inst].rgrSap[sapIdx].sapCfg;
251
252          upSapCfg->sapPst.dstEnt = cfg->s.schInstCfg.rgrSap[sapIdx].ent;
253          upSapCfg->sapPst.dstInst = cfg->s.schInstCfg.rgrSap[sapIdx].inst;
254          upSapCfg->sapPst.dstProcId = cfg->s.schInstCfg.rgrSap[sapIdx].procId;
255          upSapCfg->sapPst.srcEnt = rgSchCb[inst].rgSchInit.ent;
256          upSapCfg->sapPst.srcInst = rgSchCb[inst].rgSchInit.inst +
257          SCH_INST_START;
258          upSapCfg->sapPst.srcProcId = rgSchCb[inst].rgSchInit.procId;
259          upSapCfg->sapPst.region = cfg->s.schInstCfg.rgrSap[sapIdx].mem.region;
260          upSapCfg->sapPst.pool = cfg->s.schInstCfg.rgrSap[sapIdx].mem.pool;
261          upSapCfg->sapPst.selector = cfg->s.schInstCfg.rgrSap[sapIdx].selector;
262          upSapCfg->sapPst.route = cfg->s.schInstCfg.rgrSap[sapIdx].route;
263          upSapCfg->sapPst.intfVer = 0; 
264          upSapCfg->sapPst.event = 0; 
265          upSapCfg->sapPst.prior = cfg->s.schInstCfg.rgrSap[sapIdx].prior;
266          upSapCfg->suId = cfg->s.schInstCfg.rgrSap[sapIdx].suId;
267          upSapCfg->spId = cfg->s.schInstCfg.rgrSap[sapIdx].spId;
268          break;
269       case STTFUSAP:
270 #ifndef CL_MAC_LWLC
271          if ((cfg->s.schInstCfg.tfuSap[sapIdx].selector != TFU_SEL_TC) &&
272              (cfg->s.schInstCfg.tfuSap[sapIdx].selector != TFU_SEL_LC))
273          {
274             ret = LCM_REASON_INVALID_PAR_VAL;
275             RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "rgSCHLmmSapCfg(): unsupported"
276                      " Selector value for TFU.");
277             break;
278          }
279 #endif
280          if (rgSchCb[inst].tfuSap[sapIdx].sapSta.sapState == LRG_NOT_CFG) 
281          { 
282             rgSchCb[inst].tfuSap[sapIdx].sapSta.sapState = LRG_UNBND;
283          }
284          /* Initialize the  sap timer */
285          cmInitTimers(&(rgSchCb[inst].tfuSap[sapIdx].tmrBlk), 1);
286          lowSapCfg = &rgSchCb[inst].tfuSap[sapIdx].sapCfg;
287
288          lowSapCfg->sapPst.dstEnt = cfg->s.schInstCfg.tfuSap[sapIdx].ent;
289          lowSapCfg->sapPst.dstInst = cfg->s.schInstCfg.tfuSap[sapIdx].inst;
290          lowSapCfg->sapPst.dstProcId = cfg->s.schInstCfg.tfuSap[sapIdx].procId;
291          lowSapCfg->sapPst.srcEnt = rgSchCb[inst].rgSchInit.ent;
292          lowSapCfg->sapPst.srcInst = rgSchCb[inst].rgSchInit.inst +
293          SCH_INST_START;
294          lowSapCfg->sapPst.srcProcId = rgSchCb[inst].rgSchInit.procId;
295          lowSapCfg->sapPst.region = cfg->s.schInstCfg.tfuSap[sapIdx].mem.region;
296          lowSapCfg->sapPst.pool = cfg->s.schInstCfg.tfuSap[sapIdx].mem.pool;
297          lowSapCfg->sapPst.selector = cfg->s.schInstCfg.tfuSap[sapIdx].selector;
298          lowSapCfg->sapPst.route = cfg->s.schInstCfg.tfuSap[sapIdx].route;
299          lowSapCfg->sapPst.intfVer = 0; 
300           lowSapCfg->sapPst.event = 0; 
301          lowSapCfg->sapPst.prior = cfg->s.schInstCfg.tfuSap[sapIdx].prior;
302          lowSapCfg->suId = cfg->s.schInstCfg.tfuSap[sapIdx].suId;
303          lowSapCfg->spId = cfg->s.schInstCfg.tfuSap[sapIdx].spId;
304          cmMemcpy((U8 *)&lowSapCfg->bndTmr, 
305                   (U8 *)&cfg->s.schInstCfg.tfuSap[sapIdx].bndTmr,
306                   sizeof(TmrCfg));
307          break;
308       case STRGMSAP:
309 #ifndef RGM_LWLC
310          if ((cfg->s.schInstCfg.rgmSap[sapIdx].selector != RGM_SEL_LWLC) &&
311              (cfg->s.schInstCfg.rgmSap[sapIdx].selector != RGM_SEL_LC) &&
312              (cfg->s.schInstCfg.rgmSap[sapIdx].selector != RGM_SEL_TC))
313          {
314             ret = LCM_REASON_INVALID_PAR_VAL;
315             RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "rgSCHLmmSapCfg(): unsupported"
316                      " Selector value for RGM.");
317             break;
318          }
319 #endif
320          if (rgSchCb[inst].rgmSap[sapIdx].sapSta.sapState == LRG_NOT_CFG) 
321          { 
322             rgSchCb[inst].rgmSap[sapIdx].sapSta.sapState = LRG_UNBND;
323          }
324          upSapCfg = &rgSchCb[inst].rgmSap[sapIdx].sapCfg;
325          upSapCfg->sapPst.dstEnt = cfg->s.schInstCfg.rgmSap[sapIdx].ent;
326          upSapCfg->sapPst.dstInst = cfg->s.schInstCfg.rgmSap[sapIdx].inst;
327          upSapCfg->sapPst.dstProcId = cfg->s.schInstCfg.rgmSap[sapIdx].procId;
328          upSapCfg->sapPst.srcEnt = rgSchCb[inst].rgSchInit.ent;
329          upSapCfg->sapPst.srcInst = rgSchCb[inst].rgSchInit.inst +
330          SCH_INST_START;
331          upSapCfg->sapPst.srcProcId = rgSchCb[inst].rgSchInit.procId;
332          upSapCfg->sapPst.region = cfg->s.schInstCfg.rgmSap[sapIdx].mem.region;
333          upSapCfg->sapPst.pool = cfg->s.schInstCfg.rgmSap[sapIdx].mem.pool;
334          upSapCfg->sapPst.selector = cfg->s.schInstCfg.rgmSap[sapIdx].selector;
335          upSapCfg->sapPst.route = cfg->s.schInstCfg.rgmSap[sapIdx].route;
336          upSapCfg->sapPst.intfVer = 0; 
337          upSapCfg->sapPst.event = 0; 
338          upSapCfg->sapPst.prior = cfg->s.schInstCfg.rgmSap[sapIdx].prior;
339          upSapCfg->suId = cfg->s.schInstCfg.rgmSap[sapIdx].suId;
340          upSapCfg->spId = cfg->s.schInstCfg.rgmSap[sapIdx].spId;
341
342          break;
343       default:
344          /* would never reach here */
345          break;
346    }
347    RETVALUE(ret);
348 }
349
350 \f
351 /**
352  * @brief Scheduler instance Configuration Handler. 
353  *
354  * @details
355  *
356  *     Function : SchInstCfg
357  *     
358  *     This function in called by HandleSchGenCfgReq(). It handles the
359  *     general and SAP configurations of the scheduler instance. It initializes
360  *     the hash lists of rgSchCb. Returns
361  *     reason for success/failure of this function.
362  *     
363  *  @param[in]  RgCfg *cfg, the Configuaration information 
364  *  @return  U16
365  *      -# LCM_REASON_NOT_APPL 
366  *      -# LCM_REASON_INVALID_MSGTYPE
367  *      -# LCM_REASON_MEM_NOAVAIL
368  **/
369 #ifdef ANSI
370 PUBLIC U16 SchInstCfg
371 (
372 RgCfg *cfg,            /* Configuaration information */
373 Inst  dInst
374 )
375 #else
376 PUBLIC U16 SchInstCfg(cfg,dInst)
377 RgCfg *cfg;            /* Configuaration information */
378 Inst  dInst;
379 #endif
380 {
381    U16    ret = LCM_REASON_NOT_APPL;
382    Inst   inst = (dInst - SCH_INST_START);
383
384    TRC2(SchInstCfg)
385
386    printf("\nEntered SchInstCfg()");
387    /* Check if Instance Configuration is done already */
388    if (rgSchCb[inst].rgSchInit.cfgDone == TRUE)
389    {
390       RETVALUE(LCM_REASON_INVALID_MSGTYPE);
391    }
392    if ((cfg->s.schInstCfg.genCfg.lmPst.selector != LRG_SEL_TC) &&
393        (cfg->s.schInstCfg.genCfg.lmPst.selector != LRG_SEL_LC))
394    {
395       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg(): unsupported "
396                  "Selector value for lmPst.");
397       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
398    }
399    /* Update the Pst structure for LM interface */
400    cmMemcpy((U8 *)&rgSchCb[inst].rgSchInit.lmPst,
401             (U8 *)&cfg->s.schInstCfg.genCfg.lmPst,
402              sizeof(Pst));
403    
404    rgSchCb[inst].rgSchInit.inst = inst;
405    rgSchCb[inst].rgSchInit.lmPst.srcProcId = rgSchCb[inst].rgSchInit.procId;
406    rgSchCb[inst].rgSchInit.lmPst.srcEnt = rgSchCb[inst].rgSchInit.ent;
407    rgSchCb[inst].rgSchInit.lmPst.srcInst = rgSchCb[inst].rgSchInit.inst +
408    SCH_INST_START;
409    rgSchCb[inst].rgSchInit.lmPst.event = EVTNONE;
410
411    rgSchCb[inst].rgSchInit.region = cfg->s.schInstCfg.genCfg.mem.region;
412    rgSchCb[inst].rgSchInit.pool = cfg->s.schInstCfg.genCfg.mem.pool;
413    rgSchCb[inst].genCfg.tmrRes = cfg->s.schInstCfg.genCfg.tmrRes;
414 #ifdef LTE_ADV
415    rgSchCb[inst].genCfg.forceCntrlSrbBoOnPCel =  cfg->s.schInstCfg.genCfg.forceCntrlSrbBoOnPCel;
416    rgSchCb[inst].genCfg.isSCellActDeactAlgoEnable =  cfg->s.schInstCfg.genCfg.isSCellActDeactAlgoEnable;
417 #endif
418    rgSchCb[inst].genCfg.startCellId    = cfg->s.schInstCfg.genCfg.startCellId;
419
420 /* Not adding any SAPs towards SCH now */
421 #if 0
422    /* allocate RGR saps */
423    if (SGetSBuf(rgSchCb[inst].rgSchInit.region,
424                 rgSchCb[inst].rgSchInit.pool,
425                 (Data **)&rgSchCb[inst].rgrSap,
426                 (sizeof(RgSchUpSapCb) * cfg->s.schInstCfg.numSaps)) != ROK)
427    {
428       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg: SGetSBuf for "
429                    "RGR saps failed");
430       RETVALUE(RFAILED);
431    }
432    /* allocate RGM saps */
433    if (SGetSBuf(rgSchCb[inst].rgSchInit.region,
434                 rgSchCb[inst].rgSchInit.pool,
435                 (Data **)&rgSchCb[inst].rgmSap,
436                 (sizeof(RgSchUpSapCb) * cfg->s.schInstCfg.numSaps)) != ROK)
437    {
438       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg: SGetSBuf for "
439                    "RGM saps failed");
440       RETVALUE(RFAILED);
441    }
442
443
444    /* allocate TFU saps */
445    if (SGetSBuf(rgSchCb[inst].rgSchInit.region,
446                 rgSchCb[inst].rgSchInit.pool,
447                 (Data **)&rgSchCb[inst].tfuSap,
448                 (sizeof(RgSchLowSapCb) * cfg->s.schInstCfg.numSaps)) != ROK)
449    {
450       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg: SGetSBuf for TFU "
451                  "saps failed");
452       RETVALUE(RFAILED);
453    }
454
455    /* allocate for bndCfmResponses */
456    if (SGetSBuf(rgSchCb[inst].rgSchInit.region,
457                 rgSchCb[inst].rgSchInit.pool,
458                 (Data **)&rgSchCb[inst].genCfg.bndCfmResp,
459                 (sizeof(RgSchLmResponse) * cfg->s.schInstCfg.numSaps)) != ROK)
460    {
461       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg: SGetSBuf for bind"
462            " confirm responses failed");
463       RETVALUE(RFAILED);
464    }
465 #ifdef LTE_ADV
466    rgSCHLaaInitEnbCb(&rgSchCb[inst]);
467 #endif
468    rgSchCb[inst].numSaps = cfg->s.schInstCfg.numSaps;
469    for (idx = 0; idx < cfg->s.schInstCfg.numSaps; idx++)
470    {
471       /* Initialize SAP State and configure SAP */
472       rgSchCb[inst].rgrSap[idx].sapSta.sapState = LRG_NOT_CFG;
473       rgSchCb[inst].rgrSap[idx].cell = NULLP;
474       rgSCHLmmSapCfg(dInst, cfg, idx, STRGRSAP);
475
476       rgSchCb[inst].rgmSap[idx].sapSta.sapState = LRG_NOT_CFG;
477       rgSchCb[inst].rgmSap[idx].cell = NULLP;
478       rgSCHLmmSapCfg(dInst, cfg, idx, STRGMSAP);
479
480       rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_NOT_CFG;
481       rgSchCb[inst].tfuSap[idx].cell = NULLP;
482       rgSCHLmmSapCfg(dInst, cfg, idx, STTFUSAP);
483       rgSchCb[inst].tfuSap[idx].numBndRetries = 0;
484    }
485 #endif
486    /* Initialzie the timer queue */   
487    cmMemset((U8 *)&rgSchCb[inst].tmrTq, 0, sizeof(CmTqType)*RGSCH_TQ_SIZE);
488    /* Initialize the timer control point */
489    cmMemset((U8 *)&rgSchCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
490    rgSchCb[inst].tmrTqCp.tmrLen = RGSCH_TQ_SIZE;
491
492    /* SS_MT_TMR needs to be enabled as schActvTmr needs instance information */
493    /* Timer Registration request to SSI */
494    if (SRegTmrMt(rgSchCb[inst].rgSchInit.ent, dInst,
495       (S16)rgSchCb[inst].genCfg.tmrRes, schActvTmr) != ROK)
496    {
497       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg(): Failed to "
498              "register timer.");
499       RETVALUE(LCM_REASON_MEM_NOAVAIL);
500    }   
501                     
502    /* Set Config done in TskInit */
503    rgSchCb[inst].rgSchInit.cfgDone = TRUE;
504    printf("\nScheduler gen config done");
505    
506    RETVALUE(ret);
507 }
508
509 \f
510 /***********************************************************
511  *
512  *     Func : rgSCHLmmShutdown
513  *        
514  *
515  *     Desc : Handles the scheduler instance shutdown request. Calls 
516  *     rgSCHCfgFreeCellCb(RgSchCellCb*) to handle each cellCb deallocation.
517  *            
518  *
519  *     Ret  : Void
520  *
521  *     Notes: 
522  *
523  *     File : rg_sch_lmm.c 
524  *
525  **********************************************************/
526 #ifdef ANSI
527 PRIVATE Void rgSCHLmmShutdown
528 (
529 Inst inst
530 )
531 #else
532 PRIVATE Void rgSCHLmmShutdown(inst)
533 Inst inst;
534 #endif
535 {
536    Inst          dInst = inst + SCH_INST_START;
537    U8            idx;
538 #ifdef LTE_L2_MEAS
539    CmLList       *lnk = NULLP;
540    RgSchCb       *instCb =  &rgSchCb[inst];
541    RgSchCellCb   *cell = NULLP;
542    RgSchL2MeasCb *measCb;
543    U8            ulAllocIdx;
544    RgSchCmnUlCell *cellUl;
545    RgSchClcBoRpt  *bo = NULL;
546 #endif
547
548    TRC2(rgSCHLmmShutdown)
549
550 #ifdef LTE_L2_MEAS
551    for (idx = 0; idx < instCb->numSaps; idx++)
552    {
553      /* got the cell break the loop */
554      cell = instCb->rgrSap[idx].cell;
555      if(cell != NULLP)
556      {
557         /* Free the memory held up by  ulAllocInfo */
558         cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
559 #ifdef LTE_TDD
560         for(ulAllocIdx = 0; ulAllocIdx < RGSCH_SF_ALLOC_SIZE; ulAllocIdx++)
561 #else
562         for(ulAllocIdx = 0; ulAllocIdx < RGSCH_NUM_SUB_FRAMES; ulAllocIdx++)
563 #endif
564         {
565            if(cell->sfAllocArr[ulAllocIdx].ulUeInfo.ulAllocInfo != NULLP)
566            {
567              /* ccpu00117052 - MOD - Passing double pointer
568              for proper NULLP assignment*/
569              rgSCHUtlFreeSBuf(cell->instIdx, 
570                     (Data **)(&(cell->sfAllocArr[ulAllocIdx].ulUeInfo.\
571                                 ulAllocInfo)),
572                     cellUl->maxAllocPerUlSf * sizeof(RgInfUeUlAlloc));
573            }
574         }
575         /* Free the memory allocated to measCb */
576         lnk = cell->l2mList.first;
577         while(lnk != NULLP)
578         {
579            measCb = (RgSchL2MeasCb *)lnk->node;
580            cmLListDelFrm(&cell->l2mList, lnk);
581            lnk = lnk->next;
582              /* ccpu00117052 - MOD - Passing double pointer
583              for proper NULLP assignment*/
584            rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&measCb,\
585                           sizeof(RgSchL2MeasCb));
586         }
587
588         /* Free mem if any present for boLst for common channels */
589         for(idx = 0; idx < RGSCH_MAX_CMN_LC_CB; idx++)
590         {
591            lnk = (CmLList *)cell->cmnLcCb[idx].boLst.first;
592            while (lnk)
593            {
594               bo = (RgSchClcBoRpt *)(lnk->node);
595               lnk = lnk->next;
596               cmLListDelFrm(&cell->cmnLcCb[idx].boLst, &bo->boLstEnt);
597               rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&bo, sizeof(RgSchClcBoRpt));
598            }
599         }
600      }
601    }
602 #endif
603
604 #ifdef LTE_ADV
605    rgSCHLaaDeInitEnbCb(&rgSchCb[inst]);
606 #endif
607    for (idx = 0; idx < rgSchCb[inst].numSaps; idx++)
608    {
609       /* Unbind all the TFU SAP */
610       if(rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_WAIT_BNDCFM)
611       {
612          rgSCHUtlTfuUBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg, LRG_UNBND);
613          if (rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.enb == TRUE)
614          {
615             rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR, (PTR)&rgSchCb[inst].tfuSap[idx]); 
616          }
617          rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_UNBND;
618       }
619       if(rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_BND)
620       {
621          rgSCHUtlTfuUBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg, LRG_UNBND);
622          rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_UNBND;
623       }
624       /* Free the memory held by the cell associated with this SAP */
625       if (rgSchCb[inst].tfuSap[idx].cell != NULLP)
626          rgSCHCfgFreeCellCb(rgSchCb[inst].tfuSap[idx].cell);
627       rgSchCb[inst].tfuSap[idx].cell = NULLP;
628    }
629    /* Free the memory held by the scheduler instance */
630    /* Deallocate RGR saps */
631    SPutSBuf(rgSchCb[inst].rgSchInit.region,
632                 rgSchCb[inst].rgSchInit.pool,
633                 (Data *)rgSchCb[inst].rgrSap,
634                 (sizeof(RgSchUpSapCb) * rgSchCb[inst].numSaps));
635    rgSchCb[inst].rgrSap = NULLP;
636    /* Deallocate RGM saps */
637    SPutSBuf(rgSchCb[inst].rgSchInit.region,
638                 rgSchCb[inst].rgSchInit.pool,
639                 (Data *)rgSchCb[inst].rgmSap,
640                 (sizeof(RgSchUpSapCb) * rgSchCb[inst].numSaps));
641    rgSchCb[inst].rgmSap = NULLP;
642
643    /* Deallocate TFU saps */
644    SPutSBuf(rgSchCb[inst].rgSchInit.region,
645                 rgSchCb[inst].rgSchInit.pool,
646                 (Data *)rgSchCb[inst].tfuSap,
647                 (sizeof(RgSchLowSapCb) * rgSchCb[inst].numSaps));
648    rgSchCb[inst].tfuSap = NULLP;
649
650    /* Deallocate bndCfmResponses */
651    SPutSBuf(rgSchCb[inst].rgSchInit.region,
652                 rgSchCb[inst].rgSchInit.pool,
653                 (Data *)rgSchCb[inst].genCfg.bndCfmResp,
654                 (sizeof(RgSchLmResponse) * rgSchCb[inst].numSaps));
655    rgSchCb[inst].genCfg.bndCfmResp = NULLP;
656    /* De-register the Timer Service */
657    (Void) SDeregTmrMt(rgSchCb[inst].rgSchInit.ent, dInst,
658                      (S16)rgSchCb[inst].genCfg.tmrRes, schActvTmr); 
659
660    /* call back the task initialization function to intialize
661     * the global rgSchCb[inst] Struct */
662    schActvInit(rgSchCb[inst].rgSchInit.ent, dInst, rgSchCb[inst].rgSchInit.region, 
663               rgSchCb[inst].rgSchInit.reason);
664    
665    /* Set Config done in TskInit */
666    rgSchCb[inst].rgSchInit.cfgDone = FALSE;
667
668    RETVOID;
669 }
670
671 \f
672 /***********************************************************
673  *
674  *     Func : rgSCHLmmGenCntrl 
675  *        
676  *
677  *     Desc : Processes the LM control request for STGEN elmnt.
678  *            
679  *
680  *     Ret  : Void
681  *
682  *     Notes: 
683  *
684  *     File : rg_sch_lmm.c 
685  *
686  **********************************************************/
687 #ifdef ANSI
688 PUBLIC Void rgSCHLmmGenCntrl 
689 (
690 RgMngmt       *cntrl,
691 RgMngmt       *cfm,
692 Pst           *cfmPst
693 )
694 #else
695 PUBLIC Void rgSCHLmmGenCntrl(cntrl, cfm, cfmPst)
696 RgMngmt       *cntrl;
697 RgMngmt       *cfm;
698 Pst           *cfmPst;
699 #endif
700 {
701    Inst      inst = (cfmPst->srcInst - SCH_INST_START); /* Scheduler instance ID */
702    TRC2(rgSCHLmmGenCntrl)
703
704    cfm->cfm.status = LCM_PRIM_OK;
705    cfm->cfm.reason = LCM_REASON_NOT_APPL;
706    
707
708    switch(cntrl->t.cntrl.action)
709    {
710       case AENA:
711          /* Action is Enable */
712          switch(cntrl->t.cntrl.subAction)
713          {
714             case SAUSTA:   
715             /* Enable Unsolicited Status (alarms) */
716                rgSchCb[inst].rgSchInit.usta = TRUE;
717                /*Store the response and TransId for sending the Alarms */
718                cmMemcpy((U8 *)&rgSchCb[inst].genCfg.ustaResp.response, 
719                (U8 *)&cntrl->hdr.response, sizeof(Resp));
720                rgSchCb[inst].genCfg.ustaResp.transId = cntrl->hdr.transId;
721                break;
722             case SADBG:
723             /* Enable Debug Printing */
724 #ifdef DEBUGP
725                rgSchCb[inst].rgSchInit.dbgMask |= cntrl->t.cntrl.s.rgDbgCntrl.dbgMask;
726 #endif
727                break;
728 #ifdef PHY_ERROR_LOGING
729             case SAELMNT:
730                {
731                   rgSchUlAllocCntr.mcs = cntrl->t.cntrl.s.rgSchUlAllocCntrl.mcs;
732                   rgSchUlAllocCntr.numOfRb = cntrl->t.cntrl.s.rgSchUlAllocCntrl.numOfRb;
733                   rgSchUlAllocCntr.rbStart = cntrl->t.cntrl.s.rgSchUlAllocCntrl.rbStart;
734                   rgSchUlAllocCntr.testStart = cntrl->t.cntrl.s.rgSchUlAllocCntrl.testStart;
735                   rgSchUlAllocCntr.enaLog = cntrl->t.cntrl.s.rgSchUlAllocCntrl.enaLog;
736                   rgSchUlAllocCntr.logTime = cntrl->t.cntrl.s.rgSchUlAllocCntrl.logTime;
737                   rgSchUlAllocCntr.crcOk = 0;
738                   rgSchUlAllocCntr.crcErr = 0;
739                   rgSchUlAllocCntr.numUlPackets = 0;
740                   rgSchUlAllocCntr.numPrach = 0;
741                   rgSchUlAllocCntr.taZero = 0;
742 #ifdef MAC_SCH_STATS
743                   /* Reset
744                    * L2
745                    * statistics
746                    * */
747                   cmMemset((U8 *)&hqRetxStats, 0, sizeof(RgSchHqRetxStats));
748                   cmMemset((U8 *)&hqFailStats, 0, sizeof(RgSchNackAckStats));
749 #endif
750                   break;
751                }
752 #endif
753             default:
754                cfm->cfm.status = LCM_PRIM_NOK;
755                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
756                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmGenCntrl(): "
757                   "invalid subaction=%d", cntrl->t.cntrl.subAction);
758                break;
759          }
760          break;
761       case ADISIMM:
762          /* Action is Diable immidiately */
763          switch(cntrl->t.cntrl.subAction)
764          {
765             case SAUSTA:
766             /* Disable Unsolicited Status (alarms) */
767                rgSchCb[inst].rgSchInit.usta = FALSE;
768                break;
769             case SADBG:
770             /* Disable Debug Printing */
771 #ifdef DEBUGP
772                rgSchCb[inst].rgSchInit.dbgMask &=\
773                           ~cntrl->t.cntrl.s.rgDbgCntrl.dbgMask;
774 #endif
775                break;
776
777             default:
778                cfm->cfm.status = LCM_PRIM_NOK;
779                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
780                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmGenCntrl():"
781                  " invalid subaction=%d", cntrl->t.cntrl.subAction);
782                break;
783          }
784          break;
785       case ASHUTDOWN:
786          /* Free all the memory dynamically allocated by MAC */
787          rgSCHLmmShutdown(inst);
788          break;
789       default:
790          cfm->cfm.status = LCM_PRIM_NOK;
791          cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
792          RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmGenCntrl(): invalid"
793           " action=%d", cntrl->t.cntrl.action);
794          break;
795    }
796    RgMiLrgSchCntrlCfm(cfmPst, cfm);
797    RETVOID;
798 }
799
800 \f
801 /***********************************************************
802  *
803  *     Func : rgSCHLmmSapCntrl 
804  *        
805  *
806  *     Desc : Processes the LM control request for STxxxSAP elmnt.
807  *            
808  *
809  *     Ret  : Void
810  *
811  *     Notes: 
812  *
813  *     File : rg_sch_lmm.c 
814  *
815  **********************************************************/
816 #ifdef ANSI
817 PUBLIC Void rgSCHLmmSapCntrl 
818 (
819 RgMngmt       *cntrl,
820 RgMngmt       *cfm,
821 Pst           *cfmPst
822 )
823 #else
824 PUBLIC Void rgSCHLmmSapCntrl(cntrl, cfm, cfmPst)
825 RgMngmt       *cntrl;
826 RgMngmt       *cfm;
827 Pst           *cfmPst;
828 #endif
829 {
830    U8       idx;
831
832    /* TODO Pass InstId instead of using InstId from cfmPst */
833    Inst      inst = (cfmPst->srcInst - SCH_INST_START); /* Scheduler instance Id */
834    TRC2(rgSCHLmmSapCntrl)
835
836    /* Only TFU SAP can be controlled by LM */
837    switch(cntrl->hdr.elmId.elmnt)
838    {
839       case STTFUSAP:
840          idx = (U8)cntrl->t.cntrl.s.rgSapCntrl.suId;
841          if (idx > LRG_MAX_SAPS_PER_INST)
842          {
843             cfm->cfm.status = LCM_PRIM_NOK;
844             cfm->cfm.reason = LCM_REASON_INVALID_SAP;
845          }
846          switch(cntrl->t.cntrl.action)
847          {
848             case ABND:
849                /* Bind Enable Request */
850                if ((rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_NOT_CFG) ||
851                    (rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_BND))
852                {
853                   cfm->cfm.status = LCM_PRIM_NOK;
854                   cfm->cfm.reason = LCM_REASON_INVALID_SAP;
855                }
856                else
857                {
858                   if (rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.enb == TRUE)
859                   {
860                      rgSCHLmmStartTmr(inst, RGSCH_BNDREQ_TMR,
861                                   rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.val, 
862                                   (PTR)&rgSchCb[inst].tfuSap[idx]);
863                   }
864                   /* Change SAP state */
865                   rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_WAIT_BNDCFM;
866                   rgSchCb[inst].tfuSap[idx].numBndRetries++;
867                   /* Store the response and TransId for sending 
868                    * the Control confirm */
869                   cmMemcpy((U8 *)&rgSchCb[inst].genCfg.bndCfmResp[idx].response,
870                            (U8 *)&cntrl->hdr.response, sizeof(Resp));
871                   rgSchCb[inst].genCfg.bndCfmResp[idx].transId = 
872                                                 cntrl->hdr.transId;
873                   
874                   cfm->cfm.status = LCM_PRIM_OK_NDONE;
875                   cfm->cfm.reason = LCM_REASON_NOT_APPL;
876
877                   /* Sending Control Confirm before sending Bind
878                    * Request to TFU  */
879                   RgMiLrgSchCntrlCfm(cfmPst, cfm);
880                   
881                   rgSCHUtlTfuBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg.suId, 
882                                  rgSchCb[inst].tfuSap[idx].sapCfg.spId);
883                  RETVOID; 
884                }
885                break;
886             case AUBND:
887             /* Unbind request */
888
889                /* Check if the SAP is configured */
890                if( (rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_NOT_CFG) ||
891                      (rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_UNBND))
892                {
893                   cfm->cfm.status = LCM_PRIM_NOK;
894                   cfm->cfm.reason = LCM_REASON_INVALID_MSGTYPE;
895                }
896                else
897                {
898                   rgSCHUtlTfuUBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg,
899                                   TFU_UBNDREQ_MNGMT);
900                   if (rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.enb == TRUE)
901                   {
902                      rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR, 
903                                        (PTR)&rgSchCb[inst].tfuSap[idx]);
904                   }
905                   /* Change SAP state */
906                   rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_UNBND;
907                   cfm->cfm.status = LCM_PRIM_OK;
908                   cfm->cfm.reason = LCM_REASON_NOT_APPL;
909                }
910                break;
911             case ADEL:
912                /* Delete SAP, does initialization of SAP */
913                if ((rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_WAIT_BNDCFM) ||
914                    (rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_BND))
915                {
916                   rgSCHUtlTfuUBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg,
917                                   TFU_UBNDREQ_MNGMT);
918                   if (rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.enb == TRUE)
919                   {
920                      rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR,
921                                      (PTR)&rgSchCb[inst].tfuSap[idx]);
922                   }
923                }
924                cmMemset((U8 *)&rgSchCb[inst].tfuSap[idx], 0, sizeof(RgSchLowSapCb));
925                rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_NOT_CFG;
926                cfm->cfm.status = LCM_PRIM_OK;
927                cfm->cfm.reason = LCM_REASON_NOT_APPL;
928                break;
929             default:
930                cfm->cfm.status = LCM_PRIM_NOK;
931                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
932                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmSapCntrl(): "
933                   "invalid action=%d", cntrl->t.cntrl.action);
934                break;
935          }
936          break;
937       case STRGRSAP:
938          idx = (U8)cntrl->t.cntrl.s.rgSapCntrl.spId;
939          if (idx > LRG_MAX_SAPS_PER_INST)
940          {
941             cfm->cfm.status = LCM_PRIM_NOK;
942             cfm->cfm.reason = LCM_REASON_INVALID_SAP;
943          }
944          switch(cntrl->t.cntrl.action)
945          {
946             case ADEL:
947                cmMemset((U8 *)&rgSchCb[inst].rgrSap[idx], 0, sizeof(RgSchUpSapCb));
948                rgSchCb[inst].rgrSap[idx].sapSta.sapState = LRG_NOT_CFG;
949                cfm->cfm.status = LCM_PRIM_OK;
950                cfm->cfm.reason = LCM_REASON_NOT_APPL;
951                break;
952             default:
953                cfm->cfm.status = LCM_PRIM_NOK;
954                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
955                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmSapCntrl(): "
956                      "invalid action=%d", cntrl->t.cntrl.action);
957                break;
958          }
959          break;
960       case STRGMSAP:
961          idx = (U8)cntrl->t.cntrl.s.rgSapCntrl.spId;
962          if (idx > LRG_MAX_SAPS_PER_INST)
963          {
964             cfm->cfm.status = LCM_PRIM_NOK;
965             cfm->cfm.reason = LCM_REASON_INVALID_SAP;
966          }
967          switch(cntrl->t.cntrl.action)
968          {
969             case ADEL:
970                cmMemset((U8 *)&rgSchCb[inst].rgmSap[idx], 0, sizeof(RgSchUpSapCb));
971                rgSchCb[inst].rgmSap[idx].sapSta.sapState = LRG_NOT_CFG;
972                cfm->cfm.status = LCM_PRIM_OK;
973                cfm->cfm.reason = LCM_REASON_NOT_APPL;
974                break;
975             default:
976                cfm->cfm.status = LCM_PRIM_NOK;
977                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
978                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmSapCntrl(): "
979                      "invalid action=%d", cntrl->t.cntrl.action);
980                break;
981          }
982          break;
983
984        default:
985          /* Would never come here. */
986          RETVOID;
987    }
988    RgMiLrgSchCntrlCfm(cfmPst, cfm);
989    RETVOID;
990 }
991
992 \f
993 /***********************************************************
994  *
995  *     Func : SchFillCfmPst 
996  *        
997  *
998  *     Desc : Fills the Confirmation Post Structure cfmPst using the reqPst 
999  *            and the cfm->hdr.response.
1000  *            
1001  *
1002  *     Ret  : Void
1003  *
1004  *     Notes: 
1005  *
1006  *     File : rg_sch_lmm.c 
1007  *
1008  **********************************************************/
1009 #ifdef ANSI
1010 PUBLIC Void SchFillCfmPst
1011 (
1012 Pst           *reqPst,
1013 Pst           *cfmPst,
1014 RgMngmt       *cfm
1015 )
1016 #else
1017 PUBLIC Void SchFillCfmPst(reqPst, cfmPst, cfm)
1018 Pst           *reqPst;
1019 Pst           *cfmPst;
1020 RgMngmt       *cfm;
1021 #endif
1022 {
1023    Inst inst;
1024
1025    TRC2(SchFillCfmPst)
1026
1027    inst = (reqPst->dstInst - SCH_INST_START);
1028
1029    cfmPst->srcEnt    = rgSchCb[inst].rgSchInit.ent;
1030    cfmPst->srcInst   = (Inst) 0;
1031    cfmPst->srcProcId = rgSchCb[inst].rgSchInit.procId;
1032    cfmPst->dstEnt    = reqPst->srcEnt;
1033    cfmPst->dstInst   = (Inst) 0;
1034    cfmPst->dstProcId = reqPst->srcProcId;
1035
1036    cfmPst->selector  = cfm->hdr.response.selector;
1037    cfmPst->prior     = cfm->hdr.response.prior;
1038    cfmPst->route     = cfm->hdr.response.route;
1039    cfmPst->region    = cfm->hdr.response.mem.region;
1040    cfmPst->pool      = cfm->hdr.response.mem.pool;
1041
1042    RETVOID;
1043 }
1044
1045 \f
1046 /**
1047  * @brief Timer start handler. 
1048  *
1049  * @details
1050  *
1051  *     Function : rgSCHLmmStartTmr
1052  *     
1053  *     This function based on the input parameters starts the timer for 
1054  *     "tmrVal" duration. As of now scheduler instance uses the timer 
1055  *     functionality for BndReq only. Hence there is no conditional
1056  *     code based on "tmrEvnt".
1057  *     
1058  *  @param[in]  S16   tmrEvnt, the Timer Event    
1059  *  @param[in]  U32   tmrVal,  the Wait Time
1060  *  @param[in]  PTR   cb,  Entry for which Timer expired
1061  *  @return  S16
1062  *      -# ROK
1063  **/
1064 #ifdef ANSI
1065 PUBLIC S16 rgSCHLmmStartTmr
1066 (
1067 Inst               inst,
1068 S16                tmrEvnt,            /* Timer Event */
1069 U32                tmrVal,             /* Wait Time */
1070 PTR                cb                  /* Entry for which Timer Expired */
1071 )
1072 #else
1073 PUBLIC S16 rgSCHLmmStartTmr(inst, tmrEvnt, tmrVal, cb)
1074 Inst               inst;             /* scheduler instance ID */
1075 S16                tmrEvnt;            /* Timer Event */
1076 U32                tmrVal;             /* Wait Time */
1077 PTR                cb;                 /* Entry for which Timer Expired */
1078 #endif
1079 {
1080    CmTmrArg    arg;
1081 /*   Inst        dInst = inst + SCH_INST_START; */
1082
1083    TRC2(rgSCHLmmStartTmr)
1084
1085    UNUSED(tmrEvnt);
1086
1087    /* Initialize the arg structure */
1088    cmMemset((U8 *)&arg, 0, sizeof(CmTmrArg));
1089
1090    arg.tqCp = &rgSchCb[inst].tmrTqCp;
1091    arg.tq = rgSchCb[inst].tmrTq;
1092    arg.timers = &((RgSchLowSapCb *)cb)->tmrBlk;
1093    arg.cb = cb;
1094    arg.tNum = 0;
1095    arg.max = RGSCH_MAX_TIMER;
1096    arg.evnt = RGSCH_BNDREQ_TMR;
1097    arg.wait = tmrVal;      
1098    cmPlcCbTq(&arg);
1099
1100    RETVALUE(ROK);
1101 }
1102
1103 \f
1104 /**
1105  * @brief Timer stop handler. 
1106  *
1107  * @details
1108  *
1109  *     Function : rgSCHLmmStopTmr
1110  *     
1111  *     This function based on the input parameters stops the timer for 
1112  *     "tmrEvnt". As of now Scheduler instance uses the timer functionality for
1113  *     BndReq only. Hence there is no conditional code based on "tmrEvnt".
1114  *     Once the bind happens and this timer is stopped, the timer functionality
1115  *     is deregistered with SSI. As there is no further use of timer processing.
1116  *     
1117  *  @param[in]  S16   tmrEvnt, the Timer Event    
1118  *  @param[in]  PTR   cb,  Entry for which Timer expired
1119  *  @return  S16
1120  *      -# ROK
1121  *      -# RFAILED
1122  **/
1123 #ifdef ANSI
1124 PUBLIC S16 rgSCHLmmStopTmr
1125 (
1126 Inst               inst,             /* Scheduler instance */
1127 S16                tmrEvnt,            /* Timer Event */
1128 PTR                cb                  /* Entry for which Timer Expired */
1129 )
1130 #else
1131 PUBLIC S16 rgSCHLmmStopTmr(inst, tmrEvnt, cb)
1132 Inst               inst;             /* Scheduler instance */
1133 S16                tmrEvnt;            /* Timer Event */
1134 PTR                cb;                 /* Entry for which Timer Expired */
1135 #endif
1136 {
1137    CmTmrArg   arg;
1138    U8         i;
1139    S16        ret; 
1140
1141    TRC2(rgSCHLmmStopTmr)
1142
1143    ret = RFAILED;
1144
1145    for(i=0;i<RGSCH_MAX_TIMER;i++)
1146    {
1147       /* Search for the Timer Blocks */
1148       if(((RgSchLowSapCb *)cb)->tmrBlk.tmrEvnt == tmrEvnt)
1149       {
1150          /* Initialize the arg structure */
1151          cmMemset((U8 *)&arg, 0, sizeof(CmTmrArg));
1152
1153          arg.tqCp = &rgSchCb[inst].tmrTqCp;
1154          arg.tq = rgSchCb[inst].tmrTq;
1155          arg.timers = &(((RgSchLowSapCb *)cb)->tmrBlk);
1156          arg.cb = cb;
1157          arg.max = RGSCH_MAX_TIMER;
1158          arg.evnt = tmrEvnt;
1159
1160          arg.tNum = i;   
1161          cmRmvCbTq(&arg);
1162          ret = ROK;
1163          break;
1164       }
1165
1166    }
1167
1168
1169    RETVALUE(ret);
1170 }
1171
1172 \f
1173 /**
1174  * @brief Timer Expiry handler. 
1175  *
1176  * @details
1177  *
1178  *     Function : rgSCHLmmTmrExpiry
1179  *     
1180  *     This is a callback function used as an input parameter to cmPrcTmr()
1181  *     to check expiry of any timer. In this function, we are only concerned
1182  *     about tmrEvnt=Bind timer.
1183  *     
1184  *  @param[in]  PTR   cb,  Entry for which Timer expired
1185  *  @param[in]  S16   tmrEvnt, the Timer Event    
1186  *  @return  S16
1187  *      -# ROK
1188  **/
1189 #ifdef ANSI
1190 PUBLIC S16 rgSCHLmmTmrExpiry
1191 (
1192 PTR cb,               /* Pointer to timer control block */
1193 S16 tmrEvnt           /* Timer Event */
1194 )
1195 #else
1196 PUBLIC S16 rgSCHLmmTmrExpiry(cb,tmrEvnt)
1197 PTR cb;               /* Pointer to timer control block */
1198 S16 tmrEvnt;          /* Timer Event */
1199 #endif
1200 {
1201    S16           ret = ROK;
1202    RgSchLowSapCb *tfuSap = (RgSchLowSapCb *)cb;
1203 #ifdef DEBUGP
1204    Inst          inst = tfuSap->cell->instIdx;
1205 #endif
1206    TRC2(rgSCHLmmTmrExpiry)
1207
1208    
1209    switch(tmrEvnt)
1210    {
1211       case RGSCH_BNDREQ_TMR:
1212          tfuSap->numBndRetries++;
1213          if(tfuSap->numBndRetries > RGSCH_MAX_BNDRETRY)
1214          {
1215             rgSCHLmmStaInd((U8)(tfuSap->sapCfg.sapPst.srcInst - SCH_INST_START),
1216                            (U16)LCM_CATEGORY_INTERFACE, (U16)LCM_EVENT_BND_FAIL,
1217                            (U16)LCM_CAUSE_TMR_EXPIRED, (RgUstaDgn *)NULLP);
1218          }
1219          else
1220          {
1221             /* Restart the bind timer */
1222             if (tfuSap->sapCfg.bndTmr.enb == TRUE)
1223             {
1224                ret = rgSCHLmmStartTmr((U8)(tfuSap->sapCfg.sapPst.srcInst - SCH_INST_START),
1225                                   RGSCH_BNDREQ_TMR, 
1226                                  (U32)tfuSap->sapCfg.bndTmr.val, cb);
1227             }
1228
1229             /* Send bind request */
1230             rgSCHUtlTfuBndReq((U8)(tfuSap->sapCfg.sapPst.srcInst - SCH_INST_START), 
1231             tfuSap->sapCfg.suId, tfuSap->sapCfg.spId);
1232          }
1233          break;
1234       default:
1235          RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmTmrExpiry(): Invalid"
1236                  " tmrEvnt=%d", tmrEvnt);
1237          ret = RFAILED;
1238          break;
1239    }
1240    RETVALUE(ret);
1241 }
1242
1243 \f
1244 /**
1245  * @brief Layer Manager Control Confirm generation handler
1246  *        for Bind Confirm reception at TFU interface.
1247  *        RgLiTfuBndCfm() forwards the confirmation to this 
1248  *        function. All SAP state related handling is restricted
1249  *        to LMM modules, hence the cfm forwarding.
1250  *
1251  * @details
1252  *
1253  *     Function : rgSCHLmmBndCfm 
1254  *     
1255  *     This API is used by the LIM module of MAC to forward
1256  *     the Bind Confirm it receives over the TFU interface.
1257  *     
1258  *  @param[in]   Pst *pst, Post Structure
1259  *  @param[in]   SuId suId, Service user ID
1260  *  @param[in]   U8 status, Status
1261  *  @return  S16
1262  *      -# ROK
1263  **/
1264 #ifdef ANSI
1265 PUBLIC S16 rgSCHLmmBndCfm
1266 (
1267 Pst *pst,               /* Post Structure */
1268 SuId suId,              /* Service user ID */
1269 U8 status               /* Status */
1270 )
1271 #else
1272 PUBLIC S16 rgSCHLmmBndCfm(pst,suId,status)
1273 Pst *pst;               /* Post Structure */
1274 SuId suId;              /* Service user Id */
1275 U8 status;              /* Status */
1276 #endif
1277 {
1278    S16       ret = ROK;
1279    RgMngmt   cntrlCfm;
1280    Pst       cfmPst;
1281    Inst      inst = (pst->dstInst - SCH_INST_START); /* scheduler instance */
1282
1283    TRC2(rgSCHLmmBndCfm)
1284
1285
1286    /* check the SAP State */
1287    switch(rgSchCb[inst].tfuSap[suId].sapSta.sapState)
1288    {
1289       case LRG_WAIT_BNDCFM:
1290          break;
1291       case LRG_BND:
1292          /* SAP is already bound */
1293          RETVALUE(ROK);
1294       default:
1295          RETVALUE(RFAILED);
1296    }
1297
1298    cfmPst = rgSchCb[inst].rgSchInit.lmPst;
1299    cfmPst.selector = rgSchCb[inst].genCfg.bndCfmResp[suId].response.selector;
1300    cfmPst.prior = rgSchCb[inst].genCfg.bndCfmResp[suId].response.prior;
1301    cfmPst.route = rgSchCb[inst].genCfg.bndCfmResp[suId].response.route;
1302    cfmPst.region = rgSchCb[inst].genCfg.bndCfmResp[suId].response.mem.region;
1303    cfmPst.pool = rgSchCb[inst].genCfg.bndCfmResp[suId].response.mem.pool;
1304    
1305    cmMemset((U8 *)&cntrlCfm, 0, sizeof(RgMngmt));
1306
1307    switch(status)
1308    {
1309       case CM_BND_OK: /* status is OK */
1310          /* Change SAP state to Bound */
1311          rgSchCb[inst].tfuSap[suId].sapSta.sapState = LRG_BND;
1312          if (rgSchCb[inst].tfuSap[suId].sapCfg.bndTmr.enb == TRUE)
1313          {
1314             ret = rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR, (PTR)&rgSchCb[inst].tfuSap[suId]);
1315          }
1316          /* Send Control Confirm with status as OK to Layer Manager */
1317          cntrlCfm.cfm.status = LCM_PRIM_OK;
1318          cntrlCfm.cfm.reason = LCM_REASON_NOT_APPL;
1319         /* Sending Status Indication to Layer Manager */
1320          rgSCHLmmStaInd((U8)(rgSchCb[inst].tfuSap->sapCfg.sapPst.srcInst - SCH_INST_START),
1321                LCM_CATEGORY_INTERFACE, LCM_EVENT_BND_OK,
1322                LCM_CAUSE_LYR_SPECIFIC, (RgUstaDgn *)NULLP);
1323          break;
1324
1325       default:
1326          /* Change SAP state to UnBound */
1327          rgSchCb[inst].tfuSap[suId].sapSta.sapState = LRG_UNBND;
1328          if (rgSchCb[inst].tfuSap[suId].sapCfg.bndTmr.enb == TRUE)
1329          {
1330             ret = rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR, (PTR)&rgSchCb[inst].tfuSap[suId]);
1331          }
1332          /* Send Control Confirm with status as NOK to Layer Manager */
1333          cntrlCfm.cfm.status = LCM_PRIM_NOK;
1334          cntrlCfm.cfm.reason = LCM_REASON_NEG_CFM;
1335          break;
1336    }
1337    rgSchCb[inst].tfuSap[suId].numBndRetries = 0;
1338    cntrlCfm.hdr.elmId.elmnt = STTFUSAP;
1339    cntrlCfm.hdr.transId = rgSchCb[inst].genCfg.bndCfmResp[suId].transId;
1340
1341    ret = RgMiLrgSchCntrlCfm(&cfmPst, &cntrlCfm);
1342
1343    RETVALUE(ret);
1344 }
1345
1346 /**
1347  * @brief Layer Manager Unsolicited Status Indication generation. 
1348  *
1349  * @details
1350  *
1351  *     Function : rgSCHLmmStaInd 
1352  *     
1353  *     This API is used by the other modules of MAC to send a unsolicited
1354  *     status indication to the Layer Manager.
1355  *     
1356  *  @param[in]  U16 category, the Alarm category
1357  *  @param[in]  U16 event, the Alarm event
1358  *  @param[in]  U16 cause, the cause of the Alarm
1359  *  @param[in]  RgUstaDgn *dgn, Alarm Diagonostics
1360  *  @return  S16
1361  *      -# ROK
1362  **/
1363 #ifdef ANSI
1364 PUBLIC S16 rgSCHLmmStaInd
1365 (
1366 Inst inst,
1367 U16  category,
1368 U16  event,
1369 U16  cause,
1370 RgUstaDgn *dgn
1371 )
1372 #else
1373 PUBLIC S16 rgSCHLmmStaInd(inst, category, event, cause, dgn) 
1374 Inst inst;
1375 U16 category;
1376 U16 event;
1377 U16 cause;
1378 RgUstaDgn *dgn;
1379 #endif
1380 {
1381    RgMngmt    usta;
1382
1383    TRC2(rgSCHLmmStaInd)
1384
1385    if(rgSchCb[inst].rgSchInit.usta == FALSE)
1386    {
1387       RETVALUE(ROK);
1388    }
1389
1390    cmMemset((U8 *)&usta, 0, sizeof(RgMngmt));
1391
1392    SGetDateTime(&usta.t.usta.cmAlarm.dt);
1393    usta.t.usta.cmAlarm.category = category;
1394    usta.t.usta.cmAlarm.event = event;
1395    usta.t.usta.cmAlarm.cause = cause;
1396    if (dgn != NULLP)
1397    {
1398       cmMemcpy((U8 *)&usta.t.usta.dgn, (U8 *)dgn, sizeof(RgUstaDgn));
1399    }
1400
1401    rgSchCb[inst].rgSchInit.lmPst.selector = 
1402                        rgSchCb[inst].genCfg.ustaResp.response.selector;
1403    rgSchCb[inst].rgSchInit.lmPst.prior = 
1404                        rgSchCb[inst].genCfg.ustaResp.response.prior;
1405    rgSchCb[inst].rgSchInit.lmPst.route = 
1406                        rgSchCb[inst].genCfg.ustaResp.response.route;
1407    rgSchCb[inst].rgSchInit.lmPst.region = 
1408                        rgSchCb[inst].genCfg.ustaResp.response.mem.region;
1409    rgSchCb[inst].rgSchInit.lmPst.pool = 
1410                        rgSchCb[inst].genCfg.ustaResp.response.mem.pool;
1411    usta.hdr.transId = rgSchCb[inst].genCfg.ustaResp.transId;
1412
1413    RETVALUE(RgMiLrgSchStaInd(&rgSchCb[inst].rgSchInit.lmPst, &usta));
1414 }
1415
1416 \f
1417 /**
1418  * @brief Scheduler instance timer call back function registered with SSI. 
1419  *
1420  * @details
1421  *
1422  *     Function :  schActvTmr
1423  *     
1424  *     This function is invoked by SSI for every timer activation
1425  *     period expiry. Note that SS_MT_TMR flag needs to be enabled for this
1426  *     as isntId is needed.As part of SRegTmr call for scheduler instance 
1427  *     SS_MT_TMR flag needs to be enabled and schActvTmr needs to be given as 
1428  *     callback function
1429  *     
1430  *  @return  S16
1431  *      -# ROK
1432  **/
1433 #ifdef ANSI
1434 PUBLIC S16 schActvTmr
1435 (
1436 Ent ent,
1437 Inst inst
1438 )
1439 #else
1440 PUBLIC S16 schActvTmr(ent, inst)
1441 Ent ent;
1442 Inst inst;
1443 #endif
1444 {
1445    Inst schInst = (inst  - SCH_INST_START);
1446    TRC2(schActvTmr)
1447
1448    /* Check if any timer in the scheduler instance has expired */ 
1449    cmPrcTmr(&rgSchCb[schInst].tmrTqCp,
1450             rgSchCb[schInst].tmrTq, (PFV) rgSCHLmmTmrExpiry);
1451  
1452    RETVALUE(ROK);
1453  
1454 } /* end of schActvTmr */
1455
1456 \f
1457 /**********************************************************************
1458  
1459          End of file
1460 **********************************************************************/