Adding release file
[o-du/l2.git] / src / 5gnrmac / 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  - RGSCH_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 RgMiLrgSchCfgReq(). 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 - RGSCH_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          RGSCH_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          RGSCH_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          RGSCH_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 : rgSCHLmmInstCfg
357  *     
358  *     This function in called by RgMiLrgSchCfgReq(). 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 rgSCHLmmInstCfg
371 (
372 RgCfg *cfg,            /* Configuaration information */
373 Inst  dInst
374 )
375 #else
376 PUBLIC U16 rgSCHLmmInstCfg(cfg,dInst)
377 RgCfg *cfg;            /* Configuaration information */
378 Inst  dInst;
379 #endif
380 {
381    U16    ret = LCM_REASON_NOT_APPL;
382    Inst   inst = (dInst - RGSCH_INST_START);
383    U8     idx;
384
385    TRC2(rgSCHLmmInstCfg)
386
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, "rgSCHLmmInstCfg(): 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    RGSCH_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    /* allocate RGR saps */
421    if (SGetSBuf(rgSchCb[inst].rgSchInit.region,
422                 rgSchCb[inst].rgSchInit.pool,
423                 (Data **)&rgSchCb[inst].rgrSap,
424                 (sizeof(RgSchUpSapCb) * cfg->s.schInstCfg.numSaps)) != ROK)
425    {
426       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "rgSCHLmmInstCfg: SGetSBuf for "
427                    "RGR saps failed");
428       RETVALUE(RFAILED);
429    }
430    /* allocate RGM saps */
431    if (SGetSBuf(rgSchCb[inst].rgSchInit.region,
432                 rgSchCb[inst].rgSchInit.pool,
433                 (Data **)&rgSchCb[inst].rgmSap,
434                 (sizeof(RgSchUpSapCb) * cfg->s.schInstCfg.numSaps)) != ROK)
435    {
436       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "rgSCHLmmInstCfg: SGetSBuf for "
437                    "RGM saps failed");
438       RETVALUE(RFAILED);
439    }
440
441
442    /* allocate TFU saps */
443    if (SGetSBuf(rgSchCb[inst].rgSchInit.region,
444                 rgSchCb[inst].rgSchInit.pool,
445                 (Data **)&rgSchCb[inst].tfuSap,
446                 (sizeof(RgSchLowSapCb) * cfg->s.schInstCfg.numSaps)) != ROK)
447    {
448       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "rgSCHLmmInstCfg: SGetSBuf for TFU "
449                  "saps failed");
450       RETVALUE(RFAILED);
451    }
452
453    /* allocate for bndCfmResponses */
454    if (SGetSBuf(rgSchCb[inst].rgSchInit.region,
455                 rgSchCb[inst].rgSchInit.pool,
456                 (Data **)&rgSchCb[inst].genCfg.bndCfmResp,
457                 (sizeof(RgSchLmResponse) * cfg->s.schInstCfg.numSaps)) != ROK)
458    {
459       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "rgSCHLmmInstCfg: SGetSBuf for bind"
460            " confirm responses failed");
461       RETVALUE(RFAILED);
462    }
463
464 #ifdef LTE_ADV
465    rgSCHLaaInitEnbCb(&rgSchCb[inst]);
466 #endif
467
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    /* Initialzie the timer queue */   
486    cmMemset((U8 *)&rgSchCb[inst].tmrTq, 0, sizeof(CmTqType)*RGSCH_TQ_SIZE);
487    /* Initialize the timer control point */
488    cmMemset((U8 *)&rgSchCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
489    rgSchCb[inst].tmrTqCp.tmrLen = RGSCH_TQ_SIZE;
490
491    /* SS_MT_TMR needs to be enabled as schActvTmr needs instance information */
492    /* Timer Registration request to SSI */
493    if (SRegTmrMt(rgSchCb[inst].rgSchInit.ent, dInst,
494       (S16)rgSchCb[inst].genCfg.tmrRes, schActvTmr) != ROK)
495    {
496       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "rgSCHLmmInstCfg(): Failed to "
497              "register timer.");
498       RETVALUE(LCM_REASON_MEM_NOAVAIL);
499    }   
500                     
501    /* Set Config done in TskInit */
502    rgSchCb[inst].rgSchInit.cfgDone = TRUE;
503
504    RETVALUE(ret);
505 }
506
507 \f
508 /***********************************************************
509  *
510  *     Func : rgSCHLmmShutdown
511  *        
512  *
513  *     Desc : Handles the scheduler instance shutdown request. Calls 
514  *     rgSCHCfgFreeCellCb(RgSchCellCb*) to handle each cellCb deallocation.
515  *            
516  *
517  *     Ret  : Void
518  *
519  *     Notes: 
520  *
521  *     File : rg_sch_lmm.c 
522  *
523  **********************************************************/
524 #ifdef ANSI
525 PRIVATE Void rgSCHLmmShutdown
526 (
527 Inst inst
528 )
529 #else
530 PRIVATE Void rgSCHLmmShutdown(inst)
531 Inst inst;
532 #endif
533 {
534    Inst          dInst = inst + RGSCH_INST_START;
535    U8            idx;
536 #ifdef LTE_L2_MEAS
537    CmLList       *lnk = NULLP;
538    RgSchCb       *instCb =  &rgSchCb[inst];
539    RgSchCellCb   *cell = NULLP;
540    RgSchL2MeasCb *measCb;
541    U8            ulAllocIdx;
542    RgSchCmnUlCell *cellUl;
543    RgSchClcBoRpt  *bo = NULL;
544 #endif
545
546    TRC2(rgSCHLmmShutdown)
547
548 #ifdef LTE_L2_MEAS
549    for (idx = 0; idx < instCb->numSaps; idx++)
550    {
551      /* got the cell break the loop */
552      cell = instCb->rgrSap[idx].cell;
553      if(cell != NULLP)
554      {
555         /* Free the memory held up by  ulAllocInfo */
556         cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
557 #ifdef LTE_TDD
558         for(ulAllocIdx = 0; ulAllocIdx < RGSCH_SF_ALLOC_SIZE; ulAllocIdx++)
559 #else
560         for(ulAllocIdx = 0; ulAllocIdx < RGSCH_NUM_SUB_FRAMES; ulAllocIdx++)
561 #endif
562         {
563            if(cell->sfAllocArr[ulAllocIdx].ulUeInfo.ulAllocInfo != NULLP)
564            {
565              /* ccpu00117052 - MOD - Passing double pointer
566              for proper NULLP assignment*/
567              rgSCHUtlFreeSBuf(cell->instIdx, 
568                     (Data **)(&(cell->sfAllocArr[ulAllocIdx].ulUeInfo.\
569                                 ulAllocInfo)),
570                     cellUl->maxAllocPerUlSf * sizeof(RgInfUeUlAlloc));
571            }
572         }
573         /* Free the memory allocated to measCb */
574         lnk = cell->l2mList.first;
575         while(lnk != NULLP)
576         {
577            measCb = (RgSchL2MeasCb *)lnk->node;
578            cmLListDelFrm(&cell->l2mList, lnk);
579            lnk = lnk->next;
580              /* ccpu00117052 - MOD - Passing double pointer
581              for proper NULLP assignment*/
582            rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&measCb,\
583                           sizeof(RgSchL2MeasCb));
584         }
585
586         /* Free mem if any present for boLst for common channels */
587         for(idx = 0; idx < RGSCH_MAX_CMN_LC_CB; idx++)
588         {
589            lnk = (CmLList *)cell->cmnLcCb[idx].boLst.first;
590            while (lnk)
591            {
592               bo = (RgSchClcBoRpt *)(lnk->node);
593               lnk = lnk->next;
594               cmLListDelFrm(&cell->cmnLcCb[idx].boLst, &bo->boLstEnt);
595               rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&bo, sizeof(RgSchClcBoRpt));
596            }
597         }
598      }
599    }
600 #endif
601
602 #ifdef LTE_ADV
603    rgSCHLaaDeInitEnbCb(&rgSchCb[inst]);
604 #endif
605    for (idx = 0; idx < rgSchCb[inst].numSaps; idx++)
606    {
607       /* Unbind all the TFU SAP */
608       if(rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_WAIT_BNDCFM)
609       {
610          rgSCHUtlTfuUBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg, LRG_UNBND);
611          if (rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.enb == TRUE)
612          {
613             rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR, (PTR)&rgSchCb[inst].tfuSap[idx]); 
614          }
615          rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_UNBND;
616       }
617       if(rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_BND)
618       {
619          rgSCHUtlTfuUBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg, LRG_UNBND);
620          rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_UNBND;
621       }
622       /* Free the memory held by the cell associated with this SAP */
623       if (rgSchCb[inst].tfuSap[idx].cell != NULLP)
624          rgSCHCfgFreeCellCb(rgSchCb[inst].tfuSap[idx].cell);
625       rgSchCb[inst].tfuSap[idx].cell = NULLP;
626    }
627    /* Free the memory held by the scheduler instance */
628    /* Deallocate RGR saps */
629    SPutSBuf(rgSchCb[inst].rgSchInit.region,
630                 rgSchCb[inst].rgSchInit.pool,
631                 (Data *)rgSchCb[inst].rgrSap,
632                 (sizeof(RgSchUpSapCb) * rgSchCb[inst].numSaps));
633    rgSchCb[inst].rgrSap = NULLP;
634    /* Deallocate RGM saps */
635    SPutSBuf(rgSchCb[inst].rgSchInit.region,
636                 rgSchCb[inst].rgSchInit.pool,
637                 (Data *)rgSchCb[inst].rgmSap,
638                 (sizeof(RgSchUpSapCb) * rgSchCb[inst].numSaps));
639    rgSchCb[inst].rgmSap = NULLP;
640
641    /* Deallocate TFU saps */
642    SPutSBuf(rgSchCb[inst].rgSchInit.region,
643                 rgSchCb[inst].rgSchInit.pool,
644                 (Data *)rgSchCb[inst].tfuSap,
645                 (sizeof(RgSchLowSapCb) * rgSchCb[inst].numSaps));
646    rgSchCb[inst].tfuSap = NULLP;
647
648    /* Deallocate bndCfmResponses */
649    SPutSBuf(rgSchCb[inst].rgSchInit.region,
650                 rgSchCb[inst].rgSchInit.pool,
651                 (Data *)rgSchCb[inst].genCfg.bndCfmResp,
652                 (sizeof(RgSchLmResponse) * rgSchCb[inst].numSaps));
653    rgSchCb[inst].genCfg.bndCfmResp = NULLP;
654    /* De-register the Timer Service */
655    (Void) SDeregTmrMt(rgSchCb[inst].rgSchInit.ent, dInst,
656                      (S16)rgSchCb[inst].genCfg.tmrRes, schActvTmr); 
657
658    /* call back the task initialization function to intialize
659     * the global rgSchCb[inst] Struct */
660    schActvInit(rgSchCb[inst].rgSchInit.ent, dInst, rgSchCb[inst].rgSchInit.region, 
661               rgSchCb[inst].rgSchInit.reason);
662    
663    /* Set Config done in TskInit */
664    rgSchCb[inst].rgSchInit.cfgDone = FALSE;
665
666    RETVOID;
667 }
668
669 \f
670 /***********************************************************
671  *
672  *     Func : rgSCHLmmGenCntrl 
673  *        
674  *
675  *     Desc : Processes the LM control request for STGEN elmnt.
676  *            
677  *
678  *     Ret  : Void
679  *
680  *     Notes: 
681  *
682  *     File : rg_sch_lmm.c 
683  *
684  **********************************************************/
685 #ifdef ANSI
686 PUBLIC Void rgSCHLmmGenCntrl 
687 (
688 RgMngmt       *cntrl,
689 RgMngmt       *cfm,
690 Pst           *cfmPst
691 )
692 #else
693 PUBLIC Void rgSCHLmmGenCntrl(cntrl, cfm, cfmPst)
694 RgMngmt       *cntrl;
695 RgMngmt       *cfm;
696 Pst           *cfmPst;
697 #endif
698 {
699    Inst      inst = (cfmPst->srcInst - RGSCH_INST_START); /* Scheduler instance ID */
700    TRC2(rgSCHLmmGenCntrl)
701
702    cfm->cfm.status = LCM_PRIM_OK;
703    cfm->cfm.reason = LCM_REASON_NOT_APPL;
704    
705
706    switch(cntrl->t.cntrl.action)
707    {
708       case AENA:
709          /* Action is Enable */
710          switch(cntrl->t.cntrl.subAction)
711          {
712             case SAUSTA:   
713             /* Enable Unsolicited Status (alarms) */
714                rgSchCb[inst].rgSchInit.usta = TRUE;
715                /*Store the response and TransId for sending the Alarms */
716                cmMemcpy((U8 *)&rgSchCb[inst].genCfg.ustaResp.response, 
717                (U8 *)&cntrl->hdr.response, sizeof(Resp));
718                rgSchCb[inst].genCfg.ustaResp.transId = cntrl->hdr.transId;
719                break;
720             case SADBG:
721             /* Enable Debug Printing */
722 #ifdef DEBUGP
723                rgSchCb[inst].rgSchInit.dbgMask |= cntrl->t.cntrl.s.rgDbgCntrl.dbgMask;
724 #endif
725                break;
726 #ifdef PHY_ERROR_LOGING
727             case SAELMNT:
728                {
729                   rgSchUlAllocCntr.mcs = cntrl->t.cntrl.s.rgSchUlAllocCntrl.mcs;
730                   rgSchUlAllocCntr.numOfRb = cntrl->t.cntrl.s.rgSchUlAllocCntrl.numOfRb;
731                   rgSchUlAllocCntr.rbStart = cntrl->t.cntrl.s.rgSchUlAllocCntrl.rbStart;
732                   rgSchUlAllocCntr.testStart = cntrl->t.cntrl.s.rgSchUlAllocCntrl.testStart;
733                   rgSchUlAllocCntr.enaLog = cntrl->t.cntrl.s.rgSchUlAllocCntrl.enaLog;
734                   rgSchUlAllocCntr.logTime = cntrl->t.cntrl.s.rgSchUlAllocCntrl.logTime;
735                   rgSchUlAllocCntr.crcOk = 0;
736                   rgSchUlAllocCntr.crcErr = 0;
737                   rgSchUlAllocCntr.numUlPackets = 0;
738                   rgSchUlAllocCntr.numPrach = 0;
739                   rgSchUlAllocCntr.taZero = 0;
740 #ifdef MAC_SCH_STATS
741                   /* Reset
742                    * L2
743                    * statistics
744                    * */
745                   cmMemset((U8 *)&hqRetxStats, 0, sizeof(RgSchHqRetxStats));
746                   cmMemset((U8 *)&hqFailStats, 0, sizeof(RgSchNackAckStats));
747 #endif
748                   break;
749                }
750 #endif
751             default:
752                cfm->cfm.status = LCM_PRIM_NOK;
753                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
754                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmGenCntrl(): "
755                   "invalid subaction=%d", cntrl->t.cntrl.subAction);
756                break;
757          }
758          break;
759       case ADISIMM:
760          /* Action is Diable immidiately */
761          switch(cntrl->t.cntrl.subAction)
762          {
763             case SAUSTA:
764             /* Disable Unsolicited Status (alarms) */
765                rgSchCb[inst].rgSchInit.usta = FALSE;
766                break;
767             case SADBG:
768             /* Disable Debug Printing */
769 #ifdef DEBUGP
770                rgSchCb[inst].rgSchInit.dbgMask &=\
771                           ~cntrl->t.cntrl.s.rgDbgCntrl.dbgMask;
772 #endif
773                break;
774
775             default:
776                cfm->cfm.status = LCM_PRIM_NOK;
777                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
778                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmGenCntrl():"
779                  " invalid subaction=%d", cntrl->t.cntrl.subAction);
780                break;
781          }
782          break;
783       case ASHUTDOWN:
784          /* Free all the memory dynamically allocated by MAC */
785          rgSCHLmmShutdown(inst);
786          break;
787       default:
788          cfm->cfm.status = LCM_PRIM_NOK;
789          cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
790          RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmGenCntrl(): invalid"
791           " action=%d", cntrl->t.cntrl.action);
792          break;
793    }
794    RgMiLrgSchCntrlCfm(cfmPst, cfm);
795    RETVOID;
796 }
797
798 \f
799 /***********************************************************
800  *
801  *     Func : rgSCHLmmSapCntrl 
802  *        
803  *
804  *     Desc : Processes the LM control request for STxxxSAP elmnt.
805  *            
806  *
807  *     Ret  : Void
808  *
809  *     Notes: 
810  *
811  *     File : rg_sch_lmm.c 
812  *
813  **********************************************************/
814 #ifdef ANSI
815 PUBLIC Void rgSCHLmmSapCntrl 
816 (
817 RgMngmt       *cntrl,
818 RgMngmt       *cfm,
819 Pst           *cfmPst
820 )
821 #else
822 PUBLIC Void rgSCHLmmSapCntrl(cntrl, cfm, cfmPst)
823 RgMngmt       *cntrl;
824 RgMngmt       *cfm;
825 Pst           *cfmPst;
826 #endif
827 {
828    U8       idx;
829
830    /* TODO Pass InstId instead of using InstId from cfmPst */
831    Inst      inst = (cfmPst->srcInst - RGSCH_INST_START); /* Scheduler instance Id */
832    TRC2(rgSCHLmmSapCntrl)
833
834    /* Only TFU SAP can be controlled by LM */
835    switch(cntrl->hdr.elmId.elmnt)
836    {
837       case STTFUSAP:
838          idx = (U8)cntrl->t.cntrl.s.rgSapCntrl.suId;
839          if (idx > LRG_MAX_SAPS_PER_INST)
840          {
841             cfm->cfm.status = LCM_PRIM_NOK;
842             cfm->cfm.reason = LCM_REASON_INVALID_SAP;
843          }
844          switch(cntrl->t.cntrl.action)
845          {
846             case ABND:
847                /* Bind Enable Request */
848                if ((rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_NOT_CFG) ||
849                    (rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_BND))
850                {
851                   cfm->cfm.status = LCM_PRIM_NOK;
852                   cfm->cfm.reason = LCM_REASON_INVALID_SAP;
853                }
854                else
855                {
856                   if (rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.enb == TRUE)
857                   {
858                      rgSCHLmmStartTmr(inst, RGSCH_BNDREQ_TMR,
859                                   rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.val, 
860                                   (PTR)&rgSchCb[inst].tfuSap[idx]);
861                   }
862                   /* Change SAP state */
863                   rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_WAIT_BNDCFM;
864                   rgSchCb[inst].tfuSap[idx].numBndRetries++;
865                   /* Store the response and TransId for sending 
866                    * the Control confirm */
867                   cmMemcpy((U8 *)&rgSchCb[inst].genCfg.bndCfmResp[idx].response,
868                            (U8 *)&cntrl->hdr.response, sizeof(Resp));
869                   rgSchCb[inst].genCfg.bndCfmResp[idx].transId = 
870                                                 cntrl->hdr.transId;
871                   
872                   cfm->cfm.status = LCM_PRIM_OK_NDONE;
873                   cfm->cfm.reason = LCM_REASON_NOT_APPL;
874
875                   /* Sending Control Confirm before sending Bind
876                    * Request to TFU  */
877                   RgMiLrgSchCntrlCfm(cfmPst, cfm);
878                   
879                   rgSCHUtlTfuBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg.suId, 
880                                  rgSchCb[inst].tfuSap[idx].sapCfg.spId);
881                  RETVOID; 
882                }
883                break;
884             case AUBND:
885             /* Unbind request */
886
887                /* Check if the SAP is configured */
888                if( (rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_NOT_CFG) ||
889                      (rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_UNBND))
890                {
891                   cfm->cfm.status = LCM_PRIM_NOK;
892                   cfm->cfm.reason = LCM_REASON_INVALID_MSGTYPE;
893                }
894                else
895                {
896                   rgSCHUtlTfuUBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg,
897                                   TFU_UBNDREQ_MNGMT);
898                   if (rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.enb == TRUE)
899                   {
900                      rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR, 
901                                        (PTR)&rgSchCb[inst].tfuSap[idx]);
902                   }
903                   /* Change SAP state */
904                   rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_UNBND;
905                   cfm->cfm.status = LCM_PRIM_OK;
906                   cfm->cfm.reason = LCM_REASON_NOT_APPL;
907                }
908                break;
909             case ADEL:
910                /* Delete SAP, does initialization of SAP */
911                if ((rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_WAIT_BNDCFM) ||
912                    (rgSchCb[inst].tfuSap[idx].sapSta.sapState == LRG_BND))
913                {
914                   rgSCHUtlTfuUBndReq(inst, rgSchCb[inst].tfuSap[idx].sapCfg,
915                                   TFU_UBNDREQ_MNGMT);
916                   if (rgSchCb[inst].tfuSap[idx].sapCfg.bndTmr.enb == TRUE)
917                   {
918                      rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR,
919                                      (PTR)&rgSchCb[inst].tfuSap[idx]);
920                   }
921                }
922                cmMemset((U8 *)&rgSchCb[inst].tfuSap[idx], 0, sizeof(RgSchLowSapCb));
923                rgSchCb[inst].tfuSap[idx].sapSta.sapState = LRG_NOT_CFG;
924                cfm->cfm.status = LCM_PRIM_OK;
925                cfm->cfm.reason = LCM_REASON_NOT_APPL;
926                break;
927             default:
928                cfm->cfm.status = LCM_PRIM_NOK;
929                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
930                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmSapCntrl(): "
931                   "invalid action=%d", cntrl->t.cntrl.action);
932                break;
933          }
934          break;
935       case STRGRSAP:
936          idx = (U8)cntrl->t.cntrl.s.rgSapCntrl.spId;
937          if (idx > LRG_MAX_SAPS_PER_INST)
938          {
939             cfm->cfm.status = LCM_PRIM_NOK;
940             cfm->cfm.reason = LCM_REASON_INVALID_SAP;
941          }
942          switch(cntrl->t.cntrl.action)
943          {
944             case ADEL:
945                cmMemset((U8 *)&rgSchCb[inst].rgrSap[idx], 0, sizeof(RgSchUpSapCb));
946                rgSchCb[inst].rgrSap[idx].sapSta.sapState = LRG_NOT_CFG;
947                cfm->cfm.status = LCM_PRIM_OK;
948                cfm->cfm.reason = LCM_REASON_NOT_APPL;
949                break;
950             default:
951                cfm->cfm.status = LCM_PRIM_NOK;
952                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
953                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmSapCntrl(): "
954                      "invalid action=%d", cntrl->t.cntrl.action);
955                break;
956          }
957          break;
958       case STRGMSAP:
959          idx = (U8)cntrl->t.cntrl.s.rgSapCntrl.spId;
960          if (idx > LRG_MAX_SAPS_PER_INST)
961          {
962             cfm->cfm.status = LCM_PRIM_NOK;
963             cfm->cfm.reason = LCM_REASON_INVALID_SAP;
964          }
965          switch(cntrl->t.cntrl.action)
966          {
967             case ADEL:
968                cmMemset((U8 *)&rgSchCb[inst].rgmSap[idx], 0, sizeof(RgSchUpSapCb));
969                rgSchCb[inst].rgmSap[idx].sapSta.sapState = LRG_NOT_CFG;
970                cfm->cfm.status = LCM_PRIM_OK;
971                cfm->cfm.reason = LCM_REASON_NOT_APPL;
972                break;
973             default:
974                cfm->cfm.status = LCM_PRIM_NOK;
975                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
976                RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmSapCntrl(): "
977                      "invalid action=%d", cntrl->t.cntrl.action);
978                break;
979          }
980          break;
981
982        default:
983          /* Would never come here. */
984          RETVOID;
985    }
986    RgMiLrgSchCntrlCfm(cfmPst, cfm);
987    RETVOID;
988 }
989
990 \f
991 /***********************************************************
992  *
993  *     Func : rgSCHLmmFillCfmPst 
994  *        
995  *
996  *     Desc : Fills the Confirmation Post Structure cfmPst using the reqPst 
997  *            and the cfm->hdr.response.
998  *            
999  *
1000  *     Ret  : Void
1001  *
1002  *     Notes: 
1003  *
1004  *     File : rg_sch_lmm.c 
1005  *
1006  **********************************************************/
1007 #ifdef ANSI
1008 PUBLIC Void rgSCHLmmFillCfmPst
1009 (
1010 Pst           *reqPst,
1011 Pst           *cfmPst,
1012 RgMngmt       *cfm
1013 )
1014 #else
1015 PUBLIC Void rgSCHLmmFillCfmPst(reqPst, cfmPst, cfm)
1016 Pst           *reqPst;
1017 Pst           *cfmPst;
1018 RgMngmt       *cfm;
1019 #endif
1020 {
1021    Inst inst;
1022
1023    TRC2(rgSCHLmmFillCfmPst)
1024
1025    inst = (reqPst->dstInst - RGSCH_INST_START);
1026
1027    cfmPst->srcEnt    = rgSchCb[inst].rgSchInit.ent;
1028    cfmPst->srcInst   = rgSchCb[inst].rgSchInit.inst + RGSCH_INST_START;
1029    cfmPst->srcProcId = rgSchCb[inst].rgSchInit.procId;
1030    cfmPst->dstEnt    = reqPst->srcEnt;
1031    cfmPst->dstInst   = reqPst->srcInst;
1032    cfmPst->dstProcId = reqPst->srcProcId;
1033
1034    cfmPst->selector  = cfm->hdr.response.selector;
1035    cfmPst->prior     = cfm->hdr.response.prior;
1036    cfmPst->route     = cfm->hdr.response.route;
1037    cfmPst->region    = cfm->hdr.response.mem.region;
1038    cfmPst->pool      = cfm->hdr.response.mem.pool;
1039
1040    RETVOID;
1041 }
1042
1043 \f
1044 /**
1045  * @brief Timer start handler. 
1046  *
1047  * @details
1048  *
1049  *     Function : rgSCHLmmStartTmr
1050  *     
1051  *     This function based on the input parameters starts the timer for 
1052  *     "tmrVal" duration. As of now scheduler instance uses the timer 
1053  *     functionality for BndReq only. Hence there is no conditional
1054  *     code based on "tmrEvnt".
1055  *     
1056  *  @param[in]  S16   tmrEvnt, the Timer Event    
1057  *  @param[in]  U32   tmrVal,  the Wait Time
1058  *  @param[in]  PTR   cb,  Entry for which Timer expired
1059  *  @return  S16
1060  *      -# ROK
1061  **/
1062 #ifdef ANSI
1063 PUBLIC S16 rgSCHLmmStartTmr
1064 (
1065 Inst               inst,
1066 S16                tmrEvnt,            /* Timer Event */
1067 U32                tmrVal,             /* Wait Time */
1068 PTR                cb                  /* Entry for which Timer Expired */
1069 )
1070 #else
1071 PUBLIC S16 rgSCHLmmStartTmr(inst, tmrEvnt, tmrVal, cb)
1072 Inst               inst;             /* scheduler instance ID */
1073 S16                tmrEvnt;            /* Timer Event */
1074 U32                tmrVal;             /* Wait Time */
1075 PTR                cb;                 /* Entry for which Timer Expired */
1076 #endif
1077 {
1078    CmTmrArg    arg;
1079 /*   Inst        dInst = inst + RGSCH_INST_START; */
1080
1081    TRC2(rgSCHLmmStartTmr)
1082
1083    UNUSED(tmrEvnt);
1084
1085    /* Initialize the arg structure */
1086    cmMemset((U8 *)&arg, 0, sizeof(CmTmrArg));
1087
1088    arg.tqCp = &rgSchCb[inst].tmrTqCp;
1089    arg.tq = rgSchCb[inst].tmrTq;
1090    arg.timers = &((RgSchLowSapCb *)cb)->tmrBlk;
1091    arg.cb = cb;
1092    arg.tNum = 0;
1093    arg.max = RGSCH_MAX_TIMER;
1094    arg.evnt = RGSCH_BNDREQ_TMR;
1095    arg.wait = tmrVal;      
1096    cmPlcCbTq(&arg);
1097
1098    RETVALUE(ROK);
1099 }
1100
1101 \f
1102 /**
1103  * @brief Timer stop handler. 
1104  *
1105  * @details
1106  *
1107  *     Function : rgSCHLmmStopTmr
1108  *     
1109  *     This function based on the input parameters stops the timer for 
1110  *     "tmrEvnt". As of now Scheduler instance uses the timer functionality for
1111  *     BndReq only. Hence there is no conditional code based on "tmrEvnt".
1112  *     Once the bind happens and this timer is stopped, the timer functionality
1113  *     is deregistered with SSI. As there is no further use of timer processing.
1114  *     
1115  *  @param[in]  S16   tmrEvnt, the Timer Event    
1116  *  @param[in]  PTR   cb,  Entry for which Timer expired
1117  *  @return  S16
1118  *      -# ROK
1119  *      -# RFAILED
1120  **/
1121 #ifdef ANSI
1122 PUBLIC S16 rgSCHLmmStopTmr
1123 (
1124 Inst               inst,             /* Scheduler instance */
1125 S16                tmrEvnt,            /* Timer Event */
1126 PTR                cb                  /* Entry for which Timer Expired */
1127 )
1128 #else
1129 PUBLIC S16 rgSCHLmmStopTmr(inst, tmrEvnt, cb)
1130 Inst               inst;             /* Scheduler instance */
1131 S16                tmrEvnt;            /* Timer Event */
1132 PTR                cb;                 /* Entry for which Timer Expired */
1133 #endif
1134 {
1135    CmTmrArg   arg;
1136    U8         i;
1137    S16        ret; 
1138
1139    TRC2(rgSCHLmmStopTmr)
1140
1141    ret = RFAILED;
1142
1143    for(i=0;i<RGSCH_MAX_TIMER;i++)
1144    {
1145       /* Search for the Timer Blocks */
1146       if(((RgSchLowSapCb *)cb)->tmrBlk.tmrEvnt == tmrEvnt)
1147       {
1148          /* Initialize the arg structure */
1149          cmMemset((U8 *)&arg, 0, sizeof(CmTmrArg));
1150
1151          arg.tqCp = &rgSchCb[inst].tmrTqCp;
1152          arg.tq = rgSchCb[inst].tmrTq;
1153          arg.timers = &(((RgSchLowSapCb *)cb)->tmrBlk);
1154          arg.cb = cb;
1155          arg.max = RGSCH_MAX_TIMER;
1156          arg.evnt = tmrEvnt;
1157
1158          arg.tNum = i;   
1159          cmRmvCbTq(&arg);
1160          ret = ROK;
1161          break;
1162       }
1163
1164    }
1165
1166
1167    RETVALUE(ret);
1168 }
1169
1170 \f
1171 /**
1172  * @brief Timer Expiry handler. 
1173  *
1174  * @details
1175  *
1176  *     Function : rgSCHLmmTmrExpiry
1177  *     
1178  *     This is a callback function used as an input parameter to cmPrcTmr()
1179  *     to check expiry of any timer. In this function, we are only concerned
1180  *     about tmrEvnt=Bind timer.
1181  *     
1182  *  @param[in]  PTR   cb,  Entry for which Timer expired
1183  *  @param[in]  S16   tmrEvnt, the Timer Event    
1184  *  @return  S16
1185  *      -# ROK
1186  **/
1187 #ifdef ANSI
1188 PUBLIC S16 rgSCHLmmTmrExpiry
1189 (
1190 PTR cb,               /* Pointer to timer control block */
1191 S16 tmrEvnt           /* Timer Event */
1192 )
1193 #else
1194 PUBLIC S16 rgSCHLmmTmrExpiry(cb,tmrEvnt)
1195 PTR cb;               /* Pointer to timer control block */
1196 S16 tmrEvnt;          /* Timer Event */
1197 #endif
1198 {
1199    S16           ret = ROK;
1200    RgSchLowSapCb *tfuSap = (RgSchLowSapCb *)cb;
1201 #ifdef DEBUGP
1202    Inst          inst = tfuSap->cell->instIdx;
1203 #endif
1204    TRC2(rgSCHLmmTmrExpiry)
1205
1206    
1207    switch(tmrEvnt)
1208    {
1209       case RGSCH_BNDREQ_TMR:
1210          tfuSap->numBndRetries++;
1211          if(tfuSap->numBndRetries > RGSCH_MAX_BNDRETRY)
1212          {
1213             rgSCHLmmStaInd((U8)(tfuSap->sapCfg.sapPst.srcInst - RGSCH_INST_START),
1214                            (U16)LCM_CATEGORY_INTERFACE, (U16)LCM_EVENT_BND_FAIL,
1215                            (U16)LCM_CAUSE_TMR_EXPIRED, (RgUstaDgn *)NULLP);
1216          }
1217          else
1218          {
1219             /* Restart the bind timer */
1220             if (tfuSap->sapCfg.bndTmr.enb == TRUE)
1221             {
1222                ret = rgSCHLmmStartTmr((U8)(tfuSap->sapCfg.sapPst.srcInst - RGSCH_INST_START),
1223                                   RGSCH_BNDREQ_TMR, 
1224                                  (U32)tfuSap->sapCfg.bndTmr.val, cb);
1225             }
1226
1227             /* Send bind request */
1228             rgSCHUtlTfuBndReq((U8)(tfuSap->sapCfg.sapPst.srcInst - RGSCH_INST_START), 
1229             tfuSap->sapCfg.suId, tfuSap->sapCfg.spId);
1230          }
1231          break;
1232       default:
1233          RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "rgSCHLmmTmrExpiry(): Invalid"
1234                  " tmrEvnt=%d", tmrEvnt);
1235          ret = RFAILED;
1236          break;
1237    }
1238    RETVALUE(ret);
1239 }
1240
1241 \f
1242 /**
1243  * @brief Layer Manager Control Confirm generation handler
1244  *        for Bind Confirm reception at TFU interface.
1245  *        RgLiTfuBndCfm() forwards the confirmation to this 
1246  *        function. All SAP state related handling is restricted
1247  *        to LMM modules, hence the cfm forwarding.
1248  *
1249  * @details
1250  *
1251  *     Function : rgSCHLmmBndCfm 
1252  *     
1253  *     This API is used by the LIM module of MAC to forward
1254  *     the Bind Confirm it receives over the TFU interface.
1255  *     
1256  *  @param[in]   Pst *pst, Post Structure
1257  *  @param[in]   SuId suId, Service user ID
1258  *  @param[in]   U8 status, Status
1259  *  @return  S16
1260  *      -# ROK
1261  **/
1262 #ifdef ANSI
1263 PUBLIC S16 rgSCHLmmBndCfm
1264 (
1265 Pst *pst,               /* Post Structure */
1266 SuId suId,              /* Service user ID */
1267 U8 status               /* Status */
1268 )
1269 #else
1270 PUBLIC S16 rgSCHLmmBndCfm(pst,suId,status)
1271 Pst *pst;               /* Post Structure */
1272 SuId suId;              /* Service user Id */
1273 U8 status;              /* Status */
1274 #endif
1275 {
1276    S16       ret = ROK;
1277    RgMngmt   cntrlCfm;
1278    Pst       cfmPst;
1279    Inst      inst = (pst->dstInst - RGSCH_INST_START); /* scheduler instance */
1280
1281    TRC2(rgSCHLmmBndCfm)
1282
1283
1284    /* check the SAP State */
1285    switch(rgSchCb[inst].tfuSap[suId].sapSta.sapState)
1286    {
1287       case LRG_WAIT_BNDCFM:
1288          break;
1289       case LRG_BND:
1290          /* SAP is already bound */
1291          RETVALUE(ROK);
1292       default:
1293          RETVALUE(RFAILED);
1294    }
1295
1296    cfmPst = rgSchCb[inst].rgSchInit.lmPst;
1297    cfmPst.selector = rgSchCb[inst].genCfg.bndCfmResp[suId].response.selector;
1298    cfmPst.prior = rgSchCb[inst].genCfg.bndCfmResp[suId].response.prior;
1299    cfmPst.route = rgSchCb[inst].genCfg.bndCfmResp[suId].response.route;
1300    cfmPst.region = rgSchCb[inst].genCfg.bndCfmResp[suId].response.mem.region;
1301    cfmPst.pool = rgSchCb[inst].genCfg.bndCfmResp[suId].response.mem.pool;
1302    
1303    cmMemset((U8 *)&cntrlCfm, 0, sizeof(RgMngmt));
1304
1305    switch(status)
1306    {
1307       case CM_BND_OK: /* status is OK */
1308          /* Change SAP state to Bound */
1309          rgSchCb[inst].tfuSap[suId].sapSta.sapState = LRG_BND;
1310          if (rgSchCb[inst].tfuSap[suId].sapCfg.bndTmr.enb == TRUE)
1311          {
1312             ret = rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR, (PTR)&rgSchCb[inst].tfuSap[suId]);
1313          }
1314          /* Send Control Confirm with status as OK to Layer Manager */
1315          cntrlCfm.cfm.status = LCM_PRIM_OK;
1316          cntrlCfm.cfm.reason = LCM_REASON_NOT_APPL;
1317         /* Sending Status Indication to Layer Manager */
1318          rgSCHLmmStaInd((U8)(rgSchCb[inst].tfuSap->sapCfg.sapPst.srcInst - RGSCH_INST_START),
1319                LCM_CATEGORY_INTERFACE, LCM_EVENT_BND_OK,
1320                LCM_CAUSE_LYR_SPECIFIC, (RgUstaDgn *)NULLP);
1321          break;
1322
1323       default:
1324          /* Change SAP state to UnBound */
1325          rgSchCb[inst].tfuSap[suId].sapSta.sapState = LRG_UNBND;
1326          if (rgSchCb[inst].tfuSap[suId].sapCfg.bndTmr.enb == TRUE)
1327          {
1328             ret = rgSCHLmmStopTmr(inst, RGSCH_BNDREQ_TMR, (PTR)&rgSchCb[inst].tfuSap[suId]);
1329          }
1330          /* Send Control Confirm with status as NOK to Layer Manager */
1331          cntrlCfm.cfm.status = LCM_PRIM_NOK;
1332          cntrlCfm.cfm.reason = LCM_REASON_NEG_CFM;
1333          break;
1334    }
1335    rgSchCb[inst].tfuSap[suId].numBndRetries = 0;
1336    cntrlCfm.hdr.elmId.elmnt = STTFUSAP;
1337    cntrlCfm.hdr.transId = rgSchCb[inst].genCfg.bndCfmResp[suId].transId;
1338
1339    ret = RgMiLrgSchCntrlCfm(&cfmPst, &cntrlCfm);
1340
1341    RETVALUE(ret);
1342 }
1343
1344 /**
1345  * @brief Layer Manager Unsolicited Status Indication generation. 
1346  *
1347  * @details
1348  *
1349  *     Function : rgSCHLmmStaInd 
1350  *     
1351  *     This API is used by the other modules of MAC to send a unsolicited
1352  *     status indication to the Layer Manager.
1353  *     
1354  *  @param[in]  U16 category, the Alarm category
1355  *  @param[in]  U16 event, the Alarm event
1356  *  @param[in]  U16 cause, the cause of the Alarm
1357  *  @param[in]  RgUstaDgn *dgn, Alarm Diagonostics
1358  *  @return  S16
1359  *      -# ROK
1360  **/
1361 #ifdef ANSI
1362 PUBLIC S16 rgSCHLmmStaInd
1363 (
1364 Inst inst,
1365 U16  category,
1366 U16  event,
1367 U16  cause,
1368 RgUstaDgn *dgn
1369 )
1370 #else
1371 PUBLIC S16 rgSCHLmmStaInd(inst, category, event, cause, dgn) 
1372 Inst inst;
1373 U16 category;
1374 U16 event;
1375 U16 cause;
1376 RgUstaDgn *dgn;
1377 #endif
1378 {
1379    RgMngmt    usta;
1380
1381    TRC2(rgSCHLmmStaInd)
1382
1383    if(rgSchCb[inst].rgSchInit.usta == FALSE)
1384    {
1385       RETVALUE(ROK);
1386    }
1387
1388    cmMemset((U8 *)&usta, 0, sizeof(RgMngmt));
1389
1390    SGetDateTime(&usta.t.usta.cmAlarm.dt);
1391    usta.t.usta.cmAlarm.category = category;
1392    usta.t.usta.cmAlarm.event = event;
1393    usta.t.usta.cmAlarm.cause = cause;
1394    if (dgn != NULLP)
1395    {
1396       cmMemcpy((U8 *)&usta.t.usta.dgn, (U8 *)dgn, sizeof(RgUstaDgn));
1397    }
1398
1399    rgSchCb[inst].rgSchInit.lmPst.selector = 
1400                        rgSchCb[inst].genCfg.ustaResp.response.selector;
1401    rgSchCb[inst].rgSchInit.lmPst.prior = 
1402                        rgSchCb[inst].genCfg.ustaResp.response.prior;
1403    rgSchCb[inst].rgSchInit.lmPst.route = 
1404                        rgSchCb[inst].genCfg.ustaResp.response.route;
1405    rgSchCb[inst].rgSchInit.lmPst.region = 
1406                        rgSchCb[inst].genCfg.ustaResp.response.mem.region;
1407    rgSchCb[inst].rgSchInit.lmPst.pool = 
1408                        rgSchCb[inst].genCfg.ustaResp.response.mem.pool;
1409    usta.hdr.transId = rgSchCb[inst].genCfg.ustaResp.transId;
1410
1411    RETVALUE(RgMiLrgSchStaInd(&rgSchCb[inst].rgSchInit.lmPst, &usta));
1412 }
1413
1414 \f
1415 /**
1416  * @brief Scheduler instance timer call back function registered with SSI. 
1417  *
1418  * @details
1419  *
1420  *     Function :  schActvTmr
1421  *     
1422  *     This function is invoked by SSI for every timer activation
1423  *     period expiry. Note that SS_MT_TMR flag needs to be enabled for this
1424  *     as isntId is needed.As part of SRegTmr call for scheduler instance 
1425  *     SS_MT_TMR flag needs to be enabled and schActvTmr needs to be given as 
1426  *     callback function
1427  *     
1428  *  @return  S16
1429  *      -# ROK
1430  **/
1431 #ifdef ANSI
1432 PUBLIC S16 schActvTmr
1433 (
1434 Ent ent,
1435 Inst inst
1436 )
1437 #else
1438 PUBLIC S16 schActvTmr(ent, inst)
1439 Ent ent;
1440 Inst inst;
1441 #endif
1442 {
1443    Inst schInst = (inst  - RGSCH_INST_START);
1444    TRC2(schActvTmr)
1445
1446    /* Check if any timer in the scheduler instance has expired */ 
1447    cmPrcTmr(&rgSchCb[schInst].tmrTqCp,
1448             rgSchCb[schInst].tmrTq, (PFV) rgSCHLmmTmrExpiry);
1449  
1450    RETVALUE(ROK);
1451  
1452 } /* end of schActvTmr */
1453
1454 \f
1455 /**********************************************************************
1456  
1457          End of file
1458 **********************************************************************/