Moving all common header file into common_def.h file
[o-du/l2.git] / src / 5gnrsch / rg_sch.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 Entry point fucntions
26   
27      File:     rg_sch.c
28   
29 **********************************************************************/
30
31 /** @file rg_sch.c
32 @brief This file implements the schedulers main access to MAC layer code.
33 */
34
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_FILE_ID=185;
37 static int RLOG_MODULE_ID=4096;
38
39 /* header include files -- defines (.h) */
40 #include "common_def.h"
41 #include "lrg.h"
42 #include "rgr.h"
43 #include "tfu.h"
44 #include "rgm.h"
45 #include "rg_env.h"
46 #include "rg_sch_inf.h"
47 #include "rg_sch.h"
48 #include "rg_sch_err.h"
49 #include "rg_sch_cmn.h"
50 #include "rl_interface.h"
51 #include "rl_common.h"
52
53 /* header/extern include files (.x) */
54 #include "tfu.x"           /* TFU types */
55 #include "lrg.x"           /* layer management typedefs for MAC */
56 #include "rgr.x"           /* layer management typedefs for MAC */
57 #include "rgm.x"           /* layer management typedefs for MAC */
58 #include "rg_sch_inf.x"         /* typedefs for Scheduler */
59 #include "rg_sch.x"        /* typedefs for Scheduler */
60 #include "rg_sch_cmn.x"
61
62 #ifdef EMTC_ENABLE
63 EXTERN S16 rgEmtcMacSchUeDelInd ARGS((RgSchCellCb *cell,RgInfUeDelInd *ueDelInd));
64 EXTERN S16 rgSCHGomEmtcHndlSiCfg ARGS((
65 Region        reg,
66 Pool          pool,
67 RgSchCb       *instCb,
68 SpId          spId,
69 RgrCfgTransId transId,
70 RgrSiCfgReqInfo *cfgReqInfo
71 ));
72 EXTERN S16 rgSCHGomEmtcHndlWarningSiCfg ARGS((
73 Region        reg,
74 Pool          pool,
75 RgSchCb       *instCb,
76 SpId          spId,
77 RgrCfgTransId transId,
78 RgrWarningSiCfgReqInfo *warningSiCfgReqInfo
79 ));
80 #endif
81 /* local defines */
82 /************** LRG Interface ****************/
83 \f
84 /**
85  * @brief Layer Manager Control request handler. 
86  *
87  * @details
88  *
89  *     Function : RgMiLrgSchCntrlReq
90  *     
91  *     This function handles the control
92  *     request received from the Layer Manager.
93  *      -# Based on cntrl->hdr.elmId.elmnt, cntrl->t.cntrl.action
94  *      and cntrl->t.cntrl.subAction, it performs the appropriate control action
95  *      of SAP (enable/disable) and layer shutdown.
96  *      -# Invokes the RgMiLrgSchCntrlCfm to send back the confirmation to LM.
97  *     
98  *  @param[in]  Pst *pst, the post structure     
99  *  @param[in]  RgMngmt *cntrl, the control parameter's structure
100  *  @return  S16
101  *      -# ROK
102  **/
103 #ifdef ANSI
104 PUBLIC S16 RgMiLrgSchCntrlReq
105 (
106 Pst      *pst,    /* post structure  */
107 RgMngmt  *cntrl   /* control structure  */
108 )
109 #else
110 PUBLIC S16 RgMiLrgSchCntrlReq(pst, cntrl)
111 Pst      *pst;    /* post structure  */
112 RgMngmt  *cntrl;  /* control structure  */
113 #endif    
114 {
115    S16       ret = ROK;            /* return value */
116    Pst       cfmPst;
117    RgMngmt   cfm;
118    
119    Inst      inst = (pst->dstInst - SCH_INST_START); /* Scheduler instance Id */
120    TRC3(RgMiLrgSchCntrlReq)
121    
122
123    /* Fill the post structure for sending the confirmation */
124    SchFillCfmPst(pst, &cfmPst, cntrl);
125
126    /* Initialize the cfg cfm structure 
127    if (SGetSBuf(cfmPst.region, cfmPst.pool, (Data **)&cfm, sizeof(RgMngmt))
128       != ROK)
129    {
130       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "Memory Unavailable for Confirmation");
131       SPutSBuf(pst->region, pst->pool, (Data *)cntrl, sizeof(RgMngmt));
132       RETVALUE(ROK);
133    } */
134    cmMemset((U8 *)&cfm, 0, sizeof(RgMngmt));
135
136 #ifdef LMINT3
137    cfm.hdr.transId =
138       cntrl->hdr.transId;
139 #endif
140
141    cfm.hdr.elmId.elmnt = cntrl->hdr.elmId.elmnt;
142    cfm.t.cntrl.action = cntrl->t.cntrl.action;
143    cfm.t.cntrl.subAction = cntrl->t.cntrl.subAction;
144
145    /* Check if General Config Done*/
146    if(rgSchCb[inst].rgSchInit.cfgDone != TRUE)
147    {
148       cfm.cfm.status = LCM_PRIM_NOK;
149       cfm.cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
150       cfm.hdr.elmId.elmnt = cntrl->hdr.elmId.elmnt;
151       RgMiLrgSchCntrlCfm(&cfmPst, &cfm);
152       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "Gen Cfg not done.");
153       /*      SPutSBuf(pst->region, pst->pool, (Data *)cntrl, sizeof(RgMngmt)); */
154       RETVALUE(ROK);
155    }
156
157    /* General Config done, process the Control request */   
158    switch(cntrl->hdr.elmId.elmnt)
159    {
160       case STGEN:
161          rgSCHLmmGenCntrl(cntrl, &cfm, &cfmPst);
162          break;
163       case STTFUSAP:
164       case STRGRSAP:
165          rgSCHLmmSapCntrl(cntrl, &cfm, &cfmPst);
166          break;
167       default:
168          cfm.cfm.status = LCM_PRIM_NOK;
169          cfm.cfm.reason = LCM_REASON_INVALID_PAR_VAL;
170          RgMiLrgSchCntrlCfm(&cfmPst, &cfm);
171          RLOG_ARG1(L_ERROR,DBG_INSTID,inst, "invalid elmnt=%d",
172                   cntrl->hdr.elmId.elmnt);
173          break;
174    }
175    /*   SPutSBuf(pst->region, pst->pool, (Data *)cntrl, sizeof(RgMngmt)); */
176    RETVALUE(ret);
177 }/*-- RgMiLrgSchCntrlReq --*/
178
179 #ifdef LTE_L2_MEAS
180 /**
181  * @brief Layer Manager L2 Measurement request handler. 
182  *
183  * @details
184  *
185  *     Function : RgMiLrgSchL2MeasReq
186  *     
187  *     This function handles the control
188  *     measurement request received from the Layer Manager.
189  *     
190  *  @param[in]  Pst *pst, the post structure     
191  *  @param[in]  LrgSchMeasReqInfo *measInfo, measurement request info
192  *  @return  S16
193  *      -# ROK
194  **/
195 #ifdef ANSI
196 PUBLIC S16 RgMiLrgSchL2MeasReq
197 (
198 Pst               *pst,     /* post structure  */
199 LrgSchMeasReqInfo *measInfo /* Meas Req Info */
200 )
201 #else
202 PUBLIC S16 RgMiLrgSchL2MeasReq(pst, measInfo)
203    Pst               *pst;     /* post structure  */
204    LrgSchMeasReqInfo *measInfo; /* Meas Req Info */
205 #endif    
206 {
207    Pst                 cfmPst;
208    RgSchCellCb         *cell;
209    RgSchErrInfo        err;
210    S16                 ret = ROK; 
211    RgSchCb             *instCb =  &rgSchCb[(pst->dstInst - SCH_INST_START)];
212 #if (ERRCLASS & ERRCLS_ADD_RES) 
213    CmLList             *lnk;
214 #endif
215    U32                 idx;
216    RgSchL2MeasCb       *measCb = NULLP;
217 #ifdef DEBUGP
218    Inst      inst = (pst->dstInst - SCH_INST_START); /* Scheduler instance Id */
219 #endif
220
221    err.errType  = 0;
222    err.errCause = 0;
223
224    TRC3(RgMiLrgSchL2MeasReq)
225
226
227    /* Find the cellCb using cellId in measInfo. Iterate through all cells
228     * in rgrsapCb in RgschCb */
229    cell = NULLP;
230    for (idx = 0; idx < instCb->numSaps; idx++)
231    {
232       if ( instCb->rgrSap[idx].cell->cellId == measInfo->cellId)
233       {
234          /* got the cell break the loop */
235          cell = instCb->rgrSap[idx].cell;
236          break;
237       }
238    }
239    /* If no cellCb return Err with Invalid Cell Id */
240    if (cell == NULLP)
241    {
242       rgSchL2mFillCfmPst(pst, &cfmPst, measInfo);
243       RGSCHFILLERR(err, RGSCHERR_L2M_MEASREQ, RGSCHERR_SCH_INVALID_CELLID);
244       rgSchL2mSndCfm(&cfmPst, NULLP, measInfo, TRUE);
245       RLOG_ARG2(L_ERROR,DBG_INSTID,inst, 
246                "Meas req Failed.Invalid Cell Id errType(%d) errCause(%d)",
247                err.errType, err.errCause);
248       RETVALUE(RFAILED);
249    }
250    /* Validate for Meas Types */
251    if ( (ret = rgSCHUtlValidateMeasReq(cell, measInfo, &err)) != ROK)
252    {
253       rgSchL2mFillCfmPst(pst, &cfmPst, measInfo);
254       RGSCHFILLERR(err, RGSCHERR_L2M_MEASREQ, RGSCHERR_SCH_INVALID_MEASTYPE);
255       rgSchL2mSndCfm(&cfmPst, NULLP, measInfo, TRUE);
256       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,
257                "Meas req Failed.Invalid Measurement Type"
258                "errCasue(%d) errType(%d)", err.errType, err.errCause);
259       RETVALUE(RFAILED);
260    }
261    /* Iterate through all meas requests in l2mList in cellCb */
262 #if (ERRCLASS & ERRCLS_ADD_RES) 
263    lnk = cell->l2mList.first;
264    while(lnk != NULLP)
265    {
266       /* Get the MeasCb : RgSchL2MeasCb */
267       measCb = (RgSchL2MeasCb *)lnk->node;
268       lnk = lnk->next;
269       if (measCb->measReq.hdr.transId == measInfo->hdr.transId)
270       {
271          rgSchL2mFillCfmPst(pst, &cfmPst, measInfo);
272          RGSCHFILLERR(err, RGSCHERR_L2M_MEASREQ, RGSCHERR_SCH_DUP_TRANSID);
273          rgSchL2mSndCfm(&cfmPst, measCb, measInfo, TRUE);
274          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,
275                   "Meas req Failed.Dublicate TransId"
276                   "errType(%d) errCause(%d)", err.errType, err.errCause);
277          RETVALUE(RFAILED);
278       }
279    }
280 #endif
281    /* Call L2M Function to store Meas req */
282    ret = rgSchL2mMeasReq(cell, measInfo, err);
283    if (ret != ROK)
284    {
285       rgSchL2mFillCfmPst(pst, &cfmPst, measInfo);
286       RGSCHFILLERR(err, RGSCHERR_L2M_MEASREQ, RGSCHERR_SCH_L2MEAS_FAILED);
287       rgSchL2mSndCfm(&cfmPst, measCb, measInfo, TRUE);
288       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId, 
289                "Meas req Failed.errType(%d) errCause(%d)",
290                err.errType, err.errCause);
291       RETVALUE(RFAILED);
292    }
293    RETVALUE(ret);
294 } /* -- RRgMiLrgSchL2MeasReq-- */
295
296 /**
297  * @brief Layer Manager L2 Measurement Stop request handler. 
298  *
299  * @details
300  *
301  *     Function : RgMiLrgSchL2MeasStopReq
302  *     
303  *     This function handles the control
304  *     measurement stop request received from the Layer Manager.
305  *     
306  *  @param[in]  Pst *pst, the post structure     
307  *  @param[in]  LrgSchMeasReqInfo *measInfo, measurement stop request info
308  *  @return  S16
309  *      -# ROK
310  **/
311 #ifdef ANSI
312 PUBLIC S16 RgMiLrgSchL2MeasStopReq
313 (
314 Pst               *pst,     /* post structure  */
315 LrgSchMeasStopReqInfo *measInfo /* Meas Req Info */
316 )
317 #else
318 PUBLIC S16 RgMiLrgSchL2MeasStopReq(pst, measInfo)
319    Pst               *pst;     /* post structure  */
320    LrgSchMeasStopReqInfo *measInfo; /* Meas Req Info */
321 #endif
322 {
323    S16                 ret = ROK;
324    RgSchCellCb         *cell = NULLP;
325    RgSchCb             *instCb =  &rgSchCb[(pst->dstInst - SCH_INST_START)];
326    CmLList             *node = NULLP;
327    RgSchL2MeasCb       *measCb = NULLP;
328    LrgSchMeasCfmInfo measCfm;
329    U8                  idx;
330
331
332    TRC3(RgMiLrgSchL2MeasStopReq)
333
334
335    for (idx = 0; idx < instCb->numSaps; idx++)
336    {
337       if ( instCb->rgrSap[idx].cell->cellId == measInfo->cellId)
338       {
339          /* got the cell break the loop */
340          cell = instCb->rgrSap[idx].cell;
341          break;
342       }
343    }
344    if (cell == NULLP)
345    {
346       RLOG_ARG0(L_ERROR,DBG_CELLID,measInfo->cellId,
347                "Stop req Failed.Invalid Cell Id ");
348       RETVALUE(RFAILED);
349    }
350    cmMemset((U8 *)&measCfm, 0, sizeof(LrgSchMeasCfmInfo));
351    node = cell->l2mList.first;
352    while(node != NULLP)
353    {
354       measCb = (RgSchL2MeasCb *)(node)->node;
355
356       node = (node)->next;
357       cmLListDelFrm(&cell->l2mList, &measCb->measLnk);
358       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&measCb,
359             sizeof(RgSchL2MeasCb));    
360    }
361
362    if(measInfo->measType & LRG_L2MEAS_AVG_PRB_PER_QCI_UL)
363    {
364       RgInfL2MeasStopReq measStopReq;
365       Pst               pstMac;
366       cmMemset((U8 *)&measStopReq, 0, sizeof(RgInfL2MeasStopReq));
367       measStopReq.transId  = measInfo->hdr.transId;
368       measStopReq.measType = measInfo->measType;
369       /* measReq.timePrd  = measInfo->timePrd; */
370       measStopReq.cellId   = measInfo->cellId;
371       rgSCHUtlGetPstToLyr(&pstMac, &rgSchCb[cell->instIdx], cell->macInst);
372       RgSchMacL2MeasStop(&pstMac,&measStopReq);
373    }
374    else
375    { 
376       RgMiLrgSchL2MeasStopCfm(&(rgSchCb[cell->instIdx].rgSchInit.lmPst),
377             &measCfm);
378    }
379    RETVALUE(ret);
380 }/*RgMiLrgSchL2MeasStopReq*/
381 /**
382  * @brief Layer Manager L2 Measurement request handler. 
383  *        for Send l2 measurement req
384  * @details
385  *
386  *     Function : RgMiLrgSchL2MeasSendReq
387  *     
388  *     This function handles the control
389  *     measurement send request received from the Layer Manager.
390  *     
391  *  @param[in]  Pst *pst, the post structure     
392  *  @param[in]  LrgSchMeasReqInfo *measInfo, measurement stop request info
393  *  @return  S16
394  *      -# ROK
395  **/
396 #ifdef ANSI
397 PUBLIC S16 RgMiLrgSchL2MeasSendReq
398 (
399 Pst               *pst,     /* post structure  */
400 LrgSchMeasSndReqInfo *measInfo /* Meas Req Info */
401 )
402 #else
403 PUBLIC S16 RgMiLrgSchL2MeasSendReq(pst, measInfo)
404    Pst               *pst;     /* post structure  */
405    LrgSchMeasSndReqInfo *measInfo; /* Meas Req Info */
406 #endif
407 {
408    S16                 ret = ROK;
409    RgSchCellCb         *cell;
410    RgSchCb             *instCb =  &rgSchCb[(pst->dstInst - SCH_INST_START)];
411    U8                  idx;
412
413    TRC3(RgMiLrgSchL2MeasSendReq)
414
415
416
417    cell = NULLP;
418    for (idx = 0; idx < instCb->numSaps; idx++)
419    {
420       if ( instCb->rgrSap[idx].cell->cellId == measInfo->cellId)
421       {
422          /* got the cell break the loop */
423          cell = instCb->rgrSap[idx].cell;
424          break;
425       }
426    }
427    if (cell == NULLP)
428    {
429       RLOG_ARG0(L_ERROR,DBG_CELLID,measInfo->cellId,
430                "Send req Failed.Invalid Cell Id");
431       RETVALUE(RFAILED);
432    }
433
434    if(measInfo->measType & LRG_L2MEAS_AVG_PRB_PER_QCI_UL)
435    {
436       RgInfL2MeasSndReq measSndReq;
437       Pst               pstMac;
438       cmMemset((U8 *)&measSndReq, 0, sizeof(RgInfL2MeasSndReq));
439       measSndReq.transId  = measInfo->hdr.transId;
440       measSndReq.measType = measInfo->measType;
441       measSndReq.timePrd  = measInfo->timePrd;
442       measSndReq.cellId   = measInfo->cellId;
443       rgSCHUtlGetPstToLyr(&pstMac, &rgSchCb[cell->instIdx], cell->macInst);
444       RgSchMacL2MeasSend(&pstMac, &measSndReq);
445    }
446    else
447    { 
448       cell->sndL2Meas = TRUE;
449    }
450
451    RETVALUE(ret);
452 }/*RgMiLrgSchL2MeasSendReq*/
453 #endif /* LTE_L2_MEAS */
454
455
456
457
458 /************* RGR  Interface ****************/
459 /**
460  * @brief API for bind request from RRM towards MAC. 
461  *
462  * @details
463  *
464  *     Function: RgUiRgrBndReq
465  *     
466  *     This API is invoked by RRM towards MAC to bind RGR SAP. 
467  *     These API validates the Pst, spId, suId and sends the bind confirm to
468  *     RRM.
469  *
470  *           
471  *  @param[in]  Pst   *pst
472  *  @param[in]  SuId  suId
473  *  @param[in]  SpId  spId
474  *  @return  S16
475  *      -# ROK 
476  *      -# RFAILED 
477  **/
478 #ifdef ANSI
479 PUBLIC S16 RgUiRgrBndReq
480 (
481  Pst   *pst, 
482  SuId  suId,
483  SpId  spId
484  )
485 #else
486 PUBLIC S16 RgUiRgrBndReq(pst, suId, spId)
487    Pst   *pst; 
488    SuId  suId;
489    SpId  spId;
490 #endif
491 {
492    S16       ret = ROK;
493    Pst       tmpPst;   /* Temporary Post Structure */
494    Inst      instId = pst->dstInst-SCH_INST_START;
495    RgUstaDgn dgn;      /* Alarm diagnostics structure */
496
497    TRC3(RgUiRgrBndReq)
498
499
500    tmpPst.prior       = pst->prior;
501    tmpPst.route       = pst->route;
502    tmpPst.selector    = pst->selector;
503    tmpPst.region      = rgSchCb[instId].rgSchInit.region;
504    tmpPst.pool        = rgSchCb[instId].rgSchInit.pool;
505    tmpPst.srcProcId   = rgSchCb[instId].rgSchInit.procId;
506    tmpPst.srcEnt      = rgSchCb[instId].rgSchInit.ent;
507    tmpPst.srcInst     = rgSchCb[instId].rgSchInit.inst + SCH_INST_START;
508    tmpPst.event       = EVTNONE;
509    tmpPst.dstProcId   = pst->srcProcId;
510    tmpPst.dstEnt      = pst->srcEnt;
511    tmpPst.dstInst     = pst->srcInst;
512
513    if(spId < rgSchCb[instId].numSaps)
514    {
515       /* Check the state of the SAP */
516       switch (rgSchCb[instId].rgrSap[spId].sapSta.sapState)
517       {
518          /* This case might not be needed if SAP not configured then it will go
519           * to else of above if condition */
520          case LRG_UNBND: /* SAP is not bound */
521             RLOG0(L_DEBUG,"SAP Not yet bound");
522             rgSchCb[instId].rgrSap[spId].sapSta.sapState = LRG_BND;
523             rgSchCb[instId].rgrSap[spId].sapCfg.suId = suId;
524             /* Send Bind Confirm with status as SUCCESS */
525             ret = rgSCHUtlRgrBndCfm(instId, suId, CM_BND_OK);
526             /*Indicate to Layer manager  */
527             rgSCHUtlFillDgnParams(instId, &dgn, LRG_USTA_DGNVAL_MEM); 
528             ret = rgSCHLmmStaInd(instId, LCM_CATEGORY_INTERFACE,
529                   LRG_EVENT_RGRSAP_ENB, LCM_CAUSE_UNKNOWN, &dgn);
530             break;
531          case LRG_BND: /* SAP is already bound*/
532             RLOG0(L_DEBUG,"SAP is already bound");
533             ret = rgSCHUtlRgrBndCfm(instId, suId, CM_BND_OK);
534             break;
535          default: /* Should Never Enter here */
536 #if (ERRCLASS & ERRCLS_ADD_RES) 
537             RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG001, 
538                   (ErrVal)rgSchCb[instId].rgrSap[spId].sapSta.sapState,
539                   "Invalid SAP State:RgUiRrgBndReq failed\n");
540 #endif
541             ret = rgSCHUtlRgrBndCfm(instId, suId, CM_BND_NOK);
542             break;
543       }
544    }
545    else
546    {
547 #if (ERRCLASS & ERRCLS_ADD_RES)      
548       /* ccpu00117035 - MOD - Changed ErrVal argument from accessing sap state 
549          to spId to avoid seg fault due to invalid sapID */
550       RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG002,
551             (ErrVal)spId, "Invalid SAP Id:RgUiRrgBndReq failed\n");
552 #endif
553       ret = RgUiRgrBndCfm(&tmpPst, suId, CM_BND_NOK);
554    }
555    RETVALUE(ret);
556 }  /* RgUiRgrBndReq */
557
558 /**
559  * @brief API for unbind request from RRM towards MAC. 
560  *
561  * @details
562  *
563  *     Function: RgUiRgrUbndReq
564  *     
565  *     This API is invoked by RRM towards MAC to unbind RGR SAP. 
566  *     These API validates the Pst, spId, suId and transfers the unbind request 
567  *     specific information to corresponding ownership module (GOM) API.
568  *
569  *           
570  *  @param[in]  Pst    *pst
571  *  @param[in]  SuId   suId
572  *  @param[in]  Reason reason
573  *  @return  S16
574  *      -# ROK 
575  *      -# RFAILED 
576  **/
577 #ifdef ANSI
578 PUBLIC S16 RgUiRgrUbndReq
579 (
580  Pst    *pst,
581  SpId   spId,
582  Reason reason
583  )
584 #else
585 PUBLIC S16 RgUiRgrUbndReq(pst, spId, reason)
586    Pst    *pst; 
587    SpId   spId;
588    Reason reason;
589 #endif
590 {
591    Inst instId = pst->dstInst-SCH_INST_START;
592    TRC3(RgUiRgrUbndReq)
593
594
595    /* SAP Id validation */
596    if (spId < rgSchCb[instId].numSaps)
597    {
598       switch(rgSchCb[instId].rgrSap[spId].sapSta.sapState)
599       {
600          case LRG_BND: /* SAP is already bound*/
601             RLOG0(L_DEBUG,"SAP is already bound");
602             /* setting SAP state to UN BOUND */
603             rgSchCb[instId].rgrSap[spId].sapSta.sapState = LRG_UNBND;
604             break;
605          default:
606 #if (ERRCLASS & ERRCLS_ADD_RES)      
607             RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG003,
608                   (ErrVal)rgSchCb[instId].rgrSap[spId].sapSta.sapState,
609                   "Invalid SAP State: RgUiRgrUbndReq failed\n");
610 #endif
611             RETVALUE(RFAILED);
612       }
613    }
614    else
615    {
616 #if (ERRCLASS & ERRCLS_ADD_RES)      
617       RGSCHLOGERROR(instId,ERRCLS_INT_PAR, ERG004, 
618             (ErrVal)rgSchCb[instId].rgrSap[spId].sapSta.sapState,
619             "Invalid SAP Id:RgUiRgrUbndReq failed\n");
620 #endif
621       RETVALUE(RFAILED);
622    }
623    RETVALUE(ROK);
624 }  /* RgUiRgrUbndReq */
625
626 #ifdef RGR_SI_SCH
627 /**
628  * @brief API for SI configuration request from RRM towards MAC. 
629  *
630  * @details
631  *
632  *     Function: RgUiRgrSiCfgReq
633  *     
634  *     This API is invoked by RRM towards MAC to configure SI at MAC. 
635  *     These API validates the Pst, spId, suId and transfers the 
636  *     config request specific information to corresponding ownership 
637  *     module (GOM) API.
638  *
639  *           
640  *  @param[in]  Pst           *pst
641  *  @param[in]  SpId          spId
642  *  @param[in]  RgrCfgTransId transId
643  *  @param[in]  RgrSiCfgReqInfo *cfgReqInfo
644  *  @return  S16
645  *      -# ROK 
646  *      -# RFAILED 
647  **/
648 #ifdef ANSI
649 PUBLIC S16 RgUiRgrSiCfgReq
650 (
651 Pst           *pst, 
652 SpId          spId,
653 RgrCfgTransId transId,
654 RgrSiCfgReqInfo *cfgReqInfo
655 )
656 #else
657 PUBLIC S16 RgUiRgrSiCfgReq(pst, spId, transId, cfgReqInfo)
658 Pst           *pst; 
659 SpId          spId;
660 RgrCfgTransId transId;
661 RgrSiCfgReqInfo *cfgReqInfo;
662 #endif
663 {
664    S16       ret       = ROK;
665    U8        cfmStatus = RGR_CFG_CFM_NOK;
666    U8        prntTrans[RGR_CFG_TRANSID_SIZE+1];
667    Inst      instId = pst->dstInst-SCH_INST_START;
668
669    TRC2(RgUiRgrSiCfgReq);
670
671    cmMemcpy((U8 *)prntTrans, (U8 *)transId.trans, RGR_CFG_TRANSID_SIZE);
672    prntTrans[RGR_CFG_TRANSID_SIZE] = '\0';
673
674
675    if (cfgReqInfo == NULLP)
676    {
677       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,"Input Message Buffer "
678                    "is NULL");
679       rgSCHUtlRgrSiCfgCfm(instId, spId, transId, cfmStatus); 
680       RETVALUE(RFAILED);
681    }
682
683    if (spId < rgSchCb[instId].numSaps)
684    {
685       if(LRG_BND != rgSchCb[instId].rgrSap[spId].sapSta.sapState)
686       {
687 #if (ERRCLASS & ERRCLS_ADD_RES)      
688          RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG007, 
689                   (ErrVal)rgSchCb[instId].rgrSap[spId].sapSta.sapState,
690                   "Invalid SAP State: RgUiRgrSiCfgReq failed\n");
691 #endif
692          SPutSBuf(pst->region, pst->pool, (Data *)cfgReqInfo,
693                                           (Size)sizeof(*cfgReqInfo));
694          rgSCHUtlRgrSiCfgCfm(instId, spId, transId, cfmStatus); 
695          RETVALUE(RFAILED);
696       }
697    }
698    else
699    {
700 #if (ERRCLASS & ERRCLS_ADD_RES)      
701       RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG008,
702             (ErrVal)rgSchCb[instId].rgrSap[spId].sapCfg.spId,
703             "Invalid SAP Id:RgUiRgrSiCfgReq failed\n");
704 #endif
705       SPutSBuf(pst->region, pst->pool, (Data *)cfgReqInfo,
706                                    (Size)sizeof(*cfgReqInfo));
707       rgSCHUtlRgrSiCfgCfm(instId, spId, transId, cfmStatus); 
708       RETVALUE(RFAILED);
709    }
710
711    /* Handle configuration */
712 #ifdef EMTC_ENABLE
713 if(rgSchCb[instId].rgrSap[spId].cell->emtcEnable)
714 {
715    ret = rgSCHGomEmtcHndlSiCfg(pst->region, pst->pool,
716             &rgSchCb[instId], spId, transId, 
717                         cfgReqInfo);
718 }
719 else
720 {
721    ret = rgSCHGomHndlSiCfg(pst->region, pst->pool,
722             &rgSchCb[instId], spId, transId, 
723                         cfgReqInfo);
724 }
725  #else
726    ret = rgSCHGomHndlSiCfg(pst->region, pst->pool,
727             &rgSchCb[instId], spId, transId, 
728                         cfgReqInfo);
729  #endif
730    if (ret != ROK)
731    {
732       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,"RgUiRgrSiCfgReq:"
733                    "Configuration Request Handling Failed");
734       RETVALUE(RFAILED);
735    }
736
737    RETVALUE(ROK);
738 }  /* RgUiRgrSiCfgReq */
739
740 \f
741 /**
742  * @brief API for Warning SI configuration request from RRM towards MAC. 
743  *
744  * @details
745  *
746  *     Function: RgUiRgrWarningSiCfgReq
747  *     
748  *     This API is invoked by RRM towards MAC to configure SI at MAC. 
749  *     These API validates the Pst, spId, suId and transfers the 
750  *     config request specific information to corresponding ownership 
751  *     module (GOM) API.
752  *
753  *           
754  *  @param[in]  Pst           *pst
755  *  @param[in]  SpId          spId
756  *  @param[in]  RgrCfgTransId transId
757  *  @param[in]  RgrWarningSiCfgReqInfo *warningSiCfgReqInfo
758  *  @return  S16
759  *      -# ROK 
760  *      -# RFAILED 
761  **/
762 #ifdef ANSI
763 PUBLIC S16 RgUiRgrWarningSiCfgReq
764 (
765 Pst           *pst, 
766 SpId          spId,
767 RgrCfgTransId transId,
768 RgrWarningSiCfgReqInfo *warningSiCfgReqInfo
769 )
770 #else
771 PUBLIC S16 RgUiRgrWarningSiCfgReq(pst, spId, transId, warningSiCfgReqInfo)
772 Pst           *pst; 
773 SpId          spId;
774 RgrCfgTransId transId;
775 RgrWarningSiCfgReqInfo *warningSiCfgReqInfo;
776 #endif
777 {
778    Inst     instId = pst->dstInst-SCH_INST_START;
779    S16      ret    = ROK;
780    U8       cfmStatus = RGR_CFG_CFM_NOK;
781    U8       prntTrans[RGR_CFG_TRANSID_SIZE+1];
782
783    TRC2(RgUiRgrWarningSiCfgReq);
784
785    cmMemcpy((U8 *)prntTrans, (U8 *)transId.trans, RGR_CFG_TRANSID_SIZE);
786    prntTrans[RGR_CFG_TRANSID_SIZE] = '\0';
787
788
789
790    if (warningSiCfgReqInfo == NULLP)
791    {
792       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,"Input Message Buffer "
793                "is NULL");
794       rgSCHUtlRgrWarningSiCfgCfm(instId, spId, 0, transId, cfmStatus);
795       RETVALUE(RFAILED);
796    }
797
798    if (spId < rgSchCb[instId].numSaps)
799    {
800       if(LRG_BND != rgSchCb[instId].rgrSap[spId].sapSta.sapState)
801       {
802 #if (ERRCLASS & ERRCLS_ADD_RES)      
803          RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG023, 
804                (ErrVal)rgSchCb[instId].rgrSap[spId].sapSta.sapState,
805                "Invalid SAP State: warningSiCfgReqInfo failed\n");
806 #endif
807          rgSCHUtlFreeWarningSiSeg(pst->region, pst->pool, 
808                &warningSiCfgReqInfo->siPduLst);
809          SPutSBuf(pst->region, pst->pool, (Data *)warningSiCfgReqInfo,
810                sizeof(RgrWarningSiCfgReqInfo));
811          rgSCHUtlRgrWarningSiCfgCfm(instId, spId, warningSiCfgReqInfo->siId, 
812                transId, cfmStatus);
813          RETVALUE(RFAILED);
814       }
815    }
816    else
817    {
818 #if (ERRCLASS & ERRCLS_ADD_RES)      
819       RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG024,
820             (ErrVal)rgSchCb[instId].rgrSap[spId].sapCfg.spId,
821             "Invalid SAP Id:warningSiCfgReqInfo failed\n");
822 #endif
823       rgSCHUtlFreeWarningSiSeg(pst->region, pst->pool, 
824             &warningSiCfgReqInfo->siPduLst);
825       SPutSBuf(pst->region, pst->pool, (Data *)warningSiCfgReqInfo,
826             sizeof(RgrWarningSiCfgReqInfo));
827       rgSCHUtlRgrWarningSiCfgCfm(instId, spId, warningSiCfgReqInfo->siId, 
828             transId, cfmStatus);
829       RETVALUE(RFAILED);
830    }
831
832    /* Handle configuration */
833 #ifdef EMTC_ENABLE
834 if(rgSchCb[instId].rgrSap[spId].cell->emtcEnable)
835 {
836    ret = rgSCHGomEmtcHndlWarningSiCfg(pst->region, pst->pool,
837          &rgSchCb[instId], spId, transId, warningSiCfgReqInfo);
838 }
839 else
840 {
841    ret = rgSCHGomHndlWarningSiCfg(pst->region, pst->pool,
842          &rgSchCb[instId], spId, transId, warningSiCfgReqInfo);
843 }
844 #else
845    ret = rgSCHGomHndlWarningSiCfg(pst->region, pst->pool,
846          &rgSchCb[instId], spId, transId, warningSiCfgReqInfo);
847 #endif
848    if(ret != ROK)
849    {
850       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,
851                "Configuration Request Handling Failed");
852       RETVALUE(RFAILED);
853    }
854
855    RETVALUE(ROK);
856 }
857
858 \f
859 /**
860  * @brief API for Warning SI Stop  request from RRM towards MAC. 
861  *
862  * @details
863  *
864  *     Function: RgUiRgrWarningSiStopReq
865  *     
866  *     This API is invoked by RRM towards MAC to Stop warning SI at MAC. 
867  *     These API validates the Pst, spId, suId and transfers the 
868  *     stop request specific information to corresponding ownership 
869  *     module (GOM) API.
870  *
871  *           
872  *  @param[in]  Pst           *pst
873  *  @param[in]  SpId          spId
874  *  @param[in]  RgrWarningSiCfgReqInfo *warningSiCfgReqInfo
875  *  @return  S16
876  *      -# ROK 
877  *      -# RFAILED 
878  **/
879 #ifdef ANSI
880 PUBLIC S16 RgUiRgrWarningSiStopReq
881 (
882 Pst           *pst,
883 SpId          spId,
884 RgrCfgTransId transId,
885 U8            siId
886 )
887 #else
888 PUBLIC S16 RgUiRgrWarningSiStopReq(pst,spId, transId, siId)
889 Pst           *pst;
890 SpId          spId;
891 RgrCfgTransId transId;
892 U8            siId;
893 #endif
894 {         
895    Inst         instId = pst->dstInst-SCH_INST_START;
896
897    TRC3(RgUiRgrWarningSiStopReq)
898
899
900
901    if (spId < rgSchCb[instId].numSaps)
902    {
903       if(LRG_BND != rgSchCb[instId].rgrSap[spId].sapSta.sapState)
904       {
905 #if (ERRCLASS & ERRCLS_ADD_RES)      
906          RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG025, 
907                (ErrVal)rgSchCb[instId].rgrSap[spId].sapSta.sapState,
908                "Invalid SAP State: RgUiRgrWarningSiStopReq failed\n");
909 #endif
910          RETVALUE(RFAILED);
911       }
912    }
913    else
914    {
915 #if (ERRCLASS & ERRCLS_ADD_RES)      
916       RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG026,
917             (ErrVal)rgSchCb[instId].rgrSap[spId].sapCfg.spId,
918             "Invalid SAP Id:RgUiRgrWarningSiStopReq failed\n");
919 #endif
920       RETVALUE(RFAILED);
921    }
922
923    rgSCHGomHndlWarningSiStopReq(pst->region, pst->pool,
924          &rgSchCb[instId], siId, transId, spId);
925
926    RETVALUE(ROK);
927 }
928 #endif /*RGR_SI_SCH */
929
930 /* LTE_ADV_FLAG_REMOVED_START */
931
932 /**
933  * @brief API for LOAD INF request from RRM towards MAC.
934  *
935  * @details
936  *
937  *     Function: RgUiRgrLoadInfReq
938  *
939  *     This API is invoked by RRM towards MAC to configure LOAD INF Parameters at MAC.
940  *     These API validates the Pst, spId, suId and transfers the
941  *     LOAD INF request to corresponding ownership
942  *     module (GOM) API.
943  *
944  *
945  *  @param[in]  Pst               *pst
946  *  @param[in]  SpId              spId
947  *  @param[in]  RgrCfgTransId     transId
948  *  @param[in]  RgrLoadInfReqInfo *loadInfReq
949  *  @return  S16
950  *      -# ROK
951  *      -# RFAILED
952  **/
953 #ifdef ANSI
954 PUBLIC S16 RgUiRgrLoadInfReq
955 (
956  Pst               *pst,
957  SpId              spId,
958  RgrCfgTransId     transId,
959  RgrLoadInfReqInfo *loadInfReq
960  )
961 #else
962 PUBLIC S16 RgUiRgrLoadInfReq(pst, spId, transId, loadInfReq)
963    Pst               *pst;
964    SpId              spId;
965    RgrCfgTransId     transId;
966    RgrLoadInfReqInfo *loadInfReq;
967 #endif
968 {
969    S16       ret       = ROK;
970    U8        prntTrans[RGR_CFG_TRANSID_SIZE+1];
971    Inst      instId = pst->dstInst-SCH_INST_START;
972
973    TRC2(RgUiRgrLoadInfReq);
974
975    cmMemcpy((U8 *)prntTrans, (U8 *)transId.trans, RGR_CFG_TRANSID_SIZE);
976    prntTrans[RGR_CFG_TRANSID_SIZE] = '\0';
977
978
979    if (loadInfReq == NULLP)
980    {
981       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,"Input Message Buffer "
982                "is NULL");
983       RETVALUE(RFAILED);
984    }
985
986    if (spId < rgSchCb[instId].numSaps)
987    {
988       if(LRG_BND != rgSchCb[instId].rgrSap[spId].sapSta.sapState)
989       {
990 #if (ERRCLASS & ERRCLS_ADD_RES)
991          RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG007, 
992                (ErrVal)rgSchCb[instId].rgrSap[spId].sapSta.sapState,
993                "Invalid SAP State: RgUiRgrLoadInfReq failed\n");
994 #endif
995          SPutSBuf(pst->region, pst->pool, (Data *)loadInfReq,
996                (Size)sizeof(*loadInfReq));
997          RETVALUE(RFAILED);
998       }
999    }
1000    else
1001    {
1002 #if (ERRCLASS & ERRCLS_ADD_RES)
1003       RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG008,
1004             (ErrVal)rgSchCb[instId].rgrSap[spId].sapCfg.spId,
1005             "Invalid SAP Id:RgUiRgrLoadInfReq failed\n");
1006 #endif
1007       SPutSBuf(pst->region, pst->pool, (Data *)loadInfReq,
1008             (Size)sizeof(*loadInfReq));
1009       RETVALUE(RFAILED);
1010    }
1011
1012    /* Handle configuration */
1013    ret = rgSCHGomHndlLoadInf(pst->region, pst->pool,
1014          &rgSchCb[(pst->dstInst - SCH_INST_START)], spId, transId, 
1015          loadInfReq);
1016    if (ret != ROK)
1017    {
1018       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,
1019                "Configuration Request Handling Failed");
1020       RETVALUE(RFAILED);
1021    }
1022
1023    RETVALUE(ROK);
1024 }  /* RgUiRgrLoadInfReq */
1025 /* LTE_ADV_FLAG_REMOVED_END */
1026
1027 /************** MAC SCH Interface **************/ 
1028 /**
1029  * @brief Function for updating dedicated channel BO at scheduler from MAC.
1030  *
1031  * @details
1032  *
1033  *     Function : rgMacSchDedBoUpdtReq
1034  *     
1035  *     This function shall be invoked whenever MAC gets staRsp from RLC
1036  *     Scheduler shall update BO in its dedicated logical channel control block.
1037  *           
1038  *  @param[in] Pst*           pst
1039  *  @param[in] S16            cellSapId
1040  *  @param[in] RgInfDedBoRpt  *boRpt
1041  *  @return  S16
1042  *      -# ROK 
1043  **/
1044 #ifdef ANSI
1045 PUBLIC S16 RgMacSchDedBoUpdtReq
1046 (
1047 Pst*           pst,
1048 RgInfDedBoRpt  *boRpt
1049 )
1050 #else
1051 PUBLIC S16 RgMacSchDedBoUpdtReq(pst, boRpt)
1052 Pst*           pst;
1053 RgInfDedBoRpt  *boRpt;
1054 #endif
1055 {
1056    RgSchCellCb   *cell;
1057    RgSchUeCb     *ue;
1058 #ifdef SCH_STATS
1059       RgSchCmnDlUe  *dlUe;
1060 #endif
1061
1062
1063    Inst          inst = (pst->dstInst - SCH_INST_START);
1064    S16           cellSapId = boRpt->cellSapId;
1065
1066    TRC3(RgMacSchDedBoUpdtReq)
1067 /*
1068    RLOG_ARG2(L_DEBUG,DBG_CELLID,boRpt->cellId,"rgMacSchDedBoUpdtReq():"
1069             " boRpt->rnti = %u  boRpt->lcId = %u",boRpt->rnti, boRpt->lcId);
1070 */
1071    /* No need to chk for cell being NULL as MAC wouldn't have found instance if
1072     * it doesnt exist */
1073    cell = rgSchCb[inst].rgrSap[cellSapId].cell;
1074
1075 #ifndef NO_ERRCLS
1076    if (cell->cellId != boRpt->cellId)
1077    {
1078       /* Handle Cell fetch failure */
1079       RGSCHLOGERROR(inst, ERRCLS_INT_PAR,ERG009,(ErrVal)boRpt->cellId,
1080                             "rgMacSchDedBoUpdtReq(): Invalid cell Id");
1081       RETVALUE(RFAILED);
1082    }
1083 #endif
1084
1085    /* Update Bo in the given logical channel of the UE */
1086    if ((ue = rgSCHDbmGetUeCb(cell, boRpt->rnti)) != NULLP)
1087    {
1088       RgSchDlLcCb   *dlLc;
1089       /* Honor BO Reports only from PCELL */
1090 #ifdef LTE_ADV
1091       if (cell != ue->cell)
1092       {
1093          RETVALUE(RFAILED);
1094       }
1095 #endif
1096       if ((dlLc = rgSCHDbmGetDlDedLcCb(ue, boRpt->lcId)) != NULLP)
1097       {
1098 #ifdef LTE_L2_MEAS
1099          if(dlLc->lcType == CM_LTE_LCH_DTCH)
1100          {
1101             if((dlLc->bo == 0) &&(boRpt->bo != 0))
1102             {
1103                /* UE is active */
1104                if(!(ue->qciActiveLCs[dlLc->qciCb->qci]))
1105                {
1106                   dlLc->qciCb->dlUeCount++;
1107                }
1108                ue->qciActiveLCs[dlLc->qciCb->qci]++;
1109             }
1110             else if((dlLc->bo != 0) && (boRpt->bo == 0) && (dlLc->qciCb->dlUeCount))
1111             {
1112                /* UE is inactive */
1113                if (ue->qciActiveLCs[dlLc->qciCb->qci])
1114                {
1115                   ue->qciActiveLCs[dlLc->qciCb->qci]--;
1116                   if (!(ue->qciActiveLCs[dlLc->qciCb->qci]))
1117                   {
1118                      dlLc->qciCb->dlUeCount--;
1119                   }
1120                }
1121             }
1122         }
1123 #endif
1124 #ifdef SCH_STATS
1125          dlUe = RG_SCH_CMN_GET_DL_UE(ue, cell);
1126          if (boRpt->bo > dlLc->bo)
1127          {
1128             dlUe->boReported += (boRpt->bo - dlLc->bo);
1129          }
1130 #endif
1131 #ifdef TENB_STATS
1132          if (boRpt->bo > dlLc->bo)
1133          {
1134             ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(cell)].dlBo += ((boRpt->bo - dlLc->bo)<<3);
1135          }
1136 #endif
1137          /* RLC provides cumulative BO for each LC.
1138           * Reduce the left out unscheduled bo from total bo and 
1139           * update the new BO to the total bo */
1140          if(ue->totalBo >= dlLc->bo)
1141          {
1142             ue->totalBo -= dlLc->bo;
1143          }
1144          else
1145          {
1146             ue->totalBo = 0; /* this case should not arise
1147                              * Resetting for safety */
1148          }
1149
1150          ue->totalBo +=  boRpt->bo;
1151          dlLc->bo = boRpt->bo;
1152          dlLc->oldestSduArrTime = boRpt->oldestSduArrTime;
1153          dlLc->staPduBo = boRpt->staPduBo;
1154          
1155          dlLc->setMaxUlPrio = boRpt->setMaxUlPrio;
1156          dlLc->setMaxDlPrio = boRpt->setMaxDlPrio;
1157          /* Update the scheduler */
1158          rgSCHUtlDlDedBoUpd(cell, ue, dlLc);
1159          RETVALUE(ROK);
1160       }
1161    }
1162    RETVALUE(RFAILED);
1163
1164 } /* end of rgMacSchDedBoUpdtReq */
1165
1166
1167 /**
1168  * @brief Function for updating common channel BO at scheduler from MAC.
1169  *
1170  * @details
1171  *
1172  *     Function : RgMacSchCmnBoUpdtReq
1173  *     
1174  *     This function shall be invoked whenever MAC gets staRsp from RLC
1175  *     Scheduler shall update BO in its common logical channel control block.
1176  *           
1177  *  @param[in] Pst*            pst
1178  *  @param[in] S16             cellSapId
1179  *  @param[in] RgInfCmnBoRpt  *boRpt
1180  *  @return  S16
1181  *      -# ROK 
1182  **/
1183 #ifdef ANSI
1184 PUBLIC S16 RgMacSchCmnBoUpdtReq
1185 (
1186 Pst*           pst,
1187 RgInfCmnBoRpt  *boRpt
1188 )
1189 #else
1190 PUBLIC S16 RgMacSchCmnBoUpdtReq(pst, boRpt)
1191 Pst*           pst;
1192 RgInfCmnBoRpt  *boRpt;
1193 #endif
1194 {
1195    RgSchCellCb   *cell;
1196    Inst          inst = (pst->dstInst - SCH_INST_START);
1197    S16           cellSapId = boRpt->cellSapId;
1198
1199    TRC3(RgMacSchCmnBoUpdtReq)
1200
1201    /* No need to chk for cell being NULL as MAC would not have found instance if
1202     * it doesnt exist */
1203    cell = rgSchCb[inst].rgrSap[cellSapId].cell;
1204    if (cell->cellId != boRpt->cellId)
1205    {
1206       RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,"RgMacSchCmnBoUpdtReq():"
1207                "Invalid boRpt cell Id:%d",boRpt->cellId);
1208       RETVALUE(RFAILED);
1209    }
1210
1211    /* handle status response on CCCH */
1212    if(boRpt->lcId == cell->dlCcchId)
1213    {
1214       RLOG_ARG0(L_DEBUG,DBG_CELLID,cell->cellId,"RgMacSchCmnBoUpdtReq():"
1215                " BO update for CCCH");
1216       rgSCHUtlHndlCcchBoUpdt(cell, boRpt); 
1217    }
1218    else
1219    {
1220       rgSCHUtlHndlBcchPcchBoUpdt(cell, boRpt); 
1221    }
1222    
1223    RETVALUE(ROK);
1224 } /* end of RgMacSchCmnBoUpdtReq */
1225 /*Fix: start: Inform UE delete to scheduler*/
1226 /**
1227  * @brief This API is used to send data indication to Scheduler instance from MAC.
1228  *
1229  * @details
1230  *
1231  *     Function : rgMacSchUeDelInd
1232  *     
1233  *     This function shall be invoked whenever MAC gets Ue delete request. 
1234  *      
1235  *           
1236  *  @param[in] Pst*            pst
1237  *  @param[in] RgInfUeDelInd   *ueDelInd
1238  *  @return  S16
1239  *      -# ROK 
1240  **/
1241 #ifdef ANSI
1242 PUBLIC S16 RgMacSchUeDelInd
1243 (
1244 Pst*             pst,
1245 RgInfUeDelInd    *ueDelInd
1246 )
1247 #else
1248 PUBLIC S16 RgMacSchUeDelInd(pst, ueDelInd)
1249 Pst*             pst;
1250 RgInfUeDelInd    *ueDelInd;
1251 #endif
1252 {
1253    RgSchCellCb       *cell;
1254    Inst              inst = (pst->dstInst - SCH_INST_START);
1255    S16               cellSapId = ueDelInd->cellSapId;
1256    CmLList           *tmp;
1257    RgSchRntiLnk      *rntiLnk=NULL;
1258    
1259    TRC3(RgMacSchUeDelInd)
1260
1261    if (rgSchCb[inst].rgrSap == NULLP || rgSchCb[inst].rgrSap[cellSapId].cell == NULLP)
1262    {
1263       RLOG_ARG0(L_ERROR,DBG_CELLID,ueDelInd->cellId,"rgrSap or cell is not configured");
1264       RETVALUE(ROK);
1265    }
1266    cell = rgSchCb[inst].rgrSap[cellSapId].cell;
1267 #ifndef NO_ERRCLS
1268    if (cell->cellId != ueDelInd->cellId)
1269    {
1270       /* Handle Cell fetch failure */
1271       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1272                         "rgMacSchUeDelInd(): Invalid ueDelInd cell Id:%d",
1273                          ueDelInd->cellId);
1274       RETVALUE(ROK);
1275    }
1276 #endif
1277       
1278    CM_LLIST_FIRST_NODE(&cell->rntiDb.rntiGuardPool, tmp);
1279
1280    while(tmp)
1281    {
1282       rntiLnk = (RgSchRntiLnk *)(tmp->node);
1283       if(rntiLnk->rnti == ueDelInd->rnti)
1284       {
1285          cmLListDelFrm(&cell->rntiDb.rntiGuardPool, tmp);
1286          tmp->node = NULLP;
1287          rgSCHDbmRlsRnti(cell, rntiLnk);
1288          RLOG_ARG2(L_DEBUG,DBG_CELLID,cell->cellId,
1289                   "RNTI:%d Released from the Guard pool(%ld)",
1290                   ueDelInd->rnti, cell->rntiDb.rntiGuardPool.count);
1291          
1292          break;
1293       }
1294       CM_LLIST_NEXT_NODE(&cell->rntiDb.rntiGuardPool, tmp);
1295    }
1296
1297 #ifdef EMTC_ENABLE
1298  rgEmtcMacSchUeDelInd(cell,ueDelInd);  
1299 #endif
1300
1301    if(tmp == NULLP)
1302    {
1303       /* Fix : syed HO UE does not have a valid ue->rntiLnk */
1304       RLOG_ARG2(L_INFO,DBG_CELLID,ueDelInd->cellId,"HO CRNTI:%d not present in the"
1305            "Guard Pool:%ld", ueDelInd->rnti, cell->rntiDb.rntiGuardPool.count);
1306    } 
1307    
1308    RETVALUE(ROK);
1309 }  /* rgMacSchUeDelInd */
1310 /*Fix: end: Inform UE delete to scheduler*/
1311 /**
1312  * @brief This API is used to send data indication to Scheduler instance from MAC.
1313  *
1314  * @details
1315  *
1316  *     Function : rgMacSchSfRecpInd
1317  *     
1318  *     This function shall be invoked whenever MAC gets datInd on TFU
1319  *     Scheduler shall act on the CEs and data that are received as part of
1320  *     datInd.
1321  *           
1322  *  @param[in] Pst*            pst
1323  *  @param[in] S16             cellSapId
1324  *  @param[in] CmLteRnti       rnti
1325  *  @param[in] DatIndInfo      *datInd
1326  *  @return  S16
1327  *      -# ROK 
1328  **/
1329 #ifdef ANSI
1330 PUBLIC S16 RgMacSchSfRecpInd
1331 (
1332 Pst*             pst,
1333 RgInfSfDatInd    *subfrmInfo
1334 )
1335 #else
1336 PUBLIC S16 RgMacSchSfRecpInd(pst, subfrmInfo)
1337 Pst*             pst;
1338 RgInfSfDatInd    *subfrmInfo;
1339 #endif
1340 {
1341    S16               ret = RFAILED;
1342    RgSchErrInfo      err;
1343    RgSchUeCb         *ue;
1344    RgInfUeDatInd     *datInd;
1345    RgSchCellCb       *cell;
1346    Inst              inst = (pst->dstInst - SCH_INST_START);
1347    CmLteRnti         rnti;
1348    CmLListCp         *lnkLst;
1349    CmLList           *tmp;
1350    S16               cellSapId = subfrmInfo->cellSapId;
1351    RgrUeStaIndInfo   *ueStaInd;
1352 #ifdef RG_UNUSED
1353 //#ifdef LTEMAC_SPS
1354    RgSchCmnUlUeSpsInfo   *ulSpsUe ;
1355 #endif
1356    /* RRM_RBC_X */
1357    U32                   idx;
1358    /* RRM_RBC_Y */
1359    
1360 #ifdef LTE_L2_MEAS
1361    U8               qci;
1362    U16              datIndActQci = 0;
1363    U16              combDatIndActQci = 0; /* Prev and Latest Dat Ind combined */
1364    U16              tempUeActQci = 0; /* UE specific Active QCIs */
1365    U16              diffBits = 0;
1366    U8               lcCount;
1367 #endif
1368    TRC3(RgMacSchSfRecpInd)
1369
1370    /* No need to chk for cell being NULL as MAC wouldn't have found instance if
1371     * it doesnt exist */
1372    cell = rgSchCb[inst].rgrSap[cellSapId].cell;
1373
1374    /* lnkLst assignment */
1375    lnkLst = &(subfrmInfo->ueLst);
1376
1377    CM_LLIST_FIRST_NODE(lnkLst, tmp);
1378
1379    while((NULLP != tmp) && ((RgInfUeDatInd *)tmp->node != NULLP))
1380    {
1381       ue = NULLP;
1382 #ifdef LTE_L2_MEAS
1383       qci = 0;
1384 #endif
1385       datInd   = (RgInfUeDatInd *)tmp->node;
1386       rnti     = datInd->rnti;
1387
1388       /* We shall try and find
1389        * out the RaCb based on the following - 
1390        * 1. If the incoming PDU contained a CCCH SDU i.e. this is message 3.
1391        * 2. If the incoming PDU contained a CRNTI control element, i.e. we should
1392        * have a ueCb also for this 
1393        */
1394       
1395       /* It could be that a non-msg3 pdu contains a CRNTI Control element. We
1396        * should check for CRNTI CE and if it exists the UECb must exist, also an
1397        * if the CRNTI in the CE and the one with which the message came in are
1398        * different we shall look for an raCb as well. 
1399        */
1400       if (datInd->ceInfo.bitMask & RGSCH_CRNTI_CE_PRSNT)
1401       {
1402          /* SR_RACH_STATS : CRNTI CE*/
1403          rgNumMsg3CrntiCE++;
1404
1405          if (datInd->ceInfo.bitMask & RGSCH_CCCH_SDU_PRSNT)
1406          {
1407             RGSCH_FREE_MEM(subfrmInfo);
1408             err.errType = RGSCHERR_TOM_DATIND;
1409             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1410                       "Received MSG3 with CRNTI:%d and also CCCH ", 
1411                      datInd->ceInfo.ces.cRnti);
1412             RETVALUE(RFAILED);
1413          }
1414          ue = rgSCHDbmGetUeCb (cell, datInd->ceInfo.ces.cRnti);
1415          if (ue == NULLP)
1416          {
1417             /* SR_RACH_STATS : CRNTI CE UECB NOT FOUND*/
1418             rgNumCrntiCeCrntiNotFound++;
1419             /* ccpu00141318 - Removed condition for SPS rnti checking*/
1420             RGSCH_FREE_MEM(subfrmInfo);
1421             err.errType = RGSCHERR_TOM_DATIND;
1422             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "Received MSG3 "
1423                      "with CRNTI:%d unable to find ueCb", 
1424                      datInd->ceInfo.ces.cRnti);
1425             RETVALUE(RFAILED);
1426          }
1427
1428          if ((ret = rgSCHUtlProcMsg3 (subfrmInfo, cell, ue, 
1429                rnti, datInd, &err)) != ROK)
1430          { 
1431             RGSCH_FREE_MEM(subfrmInfo);
1432             err.errType = RGSCHERR_TOM_DATIND;
1433             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "Processing for MSG3 failed for CRNTI:%d", 
1434                      datInd->rnti);
1435             RETVALUE(RFAILED);
1436          }
1437          
1438 #ifdef LTEMAC_SPS
1439          rgSCHUtlHdlCrntiCE (cell, ue);
1440 #endif
1441          ret = rgSCHUtlAllocSBuf (cell->instIdx,(Data**)&ueStaInd,
1442                                   sizeof(RgrUeStaIndInfo));
1443          if(ret == ROK)
1444          {
1445             ueStaInd->status = RGR_UESTA_MAC_CRNTI_CE_RECVD;
1446 #ifdef RG_UNUSED
1447 //#ifdef LTEMAC_SPS
1448             ulSpsUe = RG_SCH_CMN_GET_UL_SPS_UE(ue);
1449             if(ulSpsUe->isUlSpsActv)
1450             {
1451                ueStaInd->status = RGR_UESTA_MAC_CRNTI_CE_RECVD_IN_SPS_ACTIVE;
1452                ue->ul.ulSpsCfg.isLcSRMaskEnab = FALSE;
1453             }
1454 #endif
1455             ret = rgSCHUtlFillSndUeStaInd(cell, ue, ueStaInd);
1456             if(ret != ROK)
1457             {
1458                RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1459                    "Could not Send Ue Sta Ind UEID:%d",ue->ueId);
1460             }
1461          }
1462          CM_LLIST_NEXT_NODE(lnkLst, tmp);
1463          continue;
1464       } /* end of CRNTI based message */
1465       else if (datInd->ceInfo.bitMask & RGSCH_CCCH_SDU_PRSNT)
1466       {
1467          /* SR_RACH_STATS : CCCH SDU */
1468          rgNumMsg3CCCHSdu++;
1469          /* SR_RACH_STATS : CCCH SDU RACB NOT FOUND*/
1470          if (NULLP == rgSCHDbmGetRaCb (cell, rnti))
1471          {
1472             rgNumCCCHSduCrntiNotFound++;
1473          }
1474
1475          if ((ret = rgSCHUtlProcMsg3 (subfrmInfo, cell, ue, 
1476                rnti, datInd, &err)) != ROK)
1477          { 
1478             RGSCH_FREE_MEM(subfrmInfo);
1479             err.errType = RGSCHERR_TOM_DATIND;
1480             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Processing for MSG3 failed for CRNTI:%d", 
1481                      datInd->rnti);
1482             RETVALUE(RFAILED);
1483          }
1484          /* fix */
1485           CM_LLIST_NEXT_NODE(lnkLst, tmp);
1486           continue;
1487       } /* end of Msg3 processing */
1488
1489       if (ue == NULLP)
1490       {
1491          ue = rgSCHDbmGetUeCb (cell, datInd->rnti);
1492          if (ue == NULLP)
1493          {
1494 #ifdef LTEMAC_SPS 
1495          if((ue = rgSCHDbmGetSpsUeCb (cell, datInd->rnti)) == NULLP)
1496 #endif
1497             {
1498                RGSCH_FREE_MEM(subfrmInfo);
1499                err.errType = RGSCHERR_TOM_DATIND;
1500                RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Unable to get the UE CB for CRNTI:%d", 
1501                datInd->rnti);
1502                RETVALUE(RFAILED);
1503             }
1504          }
1505       }
1506 /* L2_COUNTERS */
1507 #ifdef LTE_L2_MEAS
1508       /* The LCs for which data is received at MAC is provided to SCH.
1509          This information is used to estimate the Active LCs at UE
1510          since estimates based on only BSR is not accurate */
1511       if (datInd->ceInfo.bitMask & RGSCH_ACTIVE_LC_PRSNT)
1512       {
1513       
1514         /* Compose a Bitmask with for the QCI's for which Data
1515            is received */
1516         for (lcCount = 0; lcCount < RGINF_MAX_NUM_DED_LC; lcCount++)
1517         {
1518            if ((datInd->ceInfo.ulActLCs[lcCount] == TRUE) && (TRUE == ue->ul.lcCb[lcCount].isValid))
1519            {
1520               datIndActQci |= (1 << (ue->ul.lcCb[lcCount].qciCb->qci -1));
1521            }
1522         }
1523         if (ue->ulActiveLCs && ue->lastDatIndLCs)
1524         {
1525            /* Combine previous Dat Ind and current Dat Ind to
1526               estimate active LCs at UE */
1527            combDatIndActQci = ue->lastDatIndLCs | datIndActQci;
1528            tempUeActQci = ue->ulActiveLCs;
1529            ue->ulActiveLCs = combDatIndActQci;
1530            diffBits = combDatIndActQci ^ tempUeActQci;
1531            while (diffBits)
1532            {
1533               qci++;
1534               if (0x1 & diffBits)
1535               {
1536                  if (0x1 & tempUeActQci)
1537                  {
1538                     /* An active QCI has become inactive */
1539                     cell->qciArray[qci].ulUeCount--;
1540                  }
1541                  else
1542                  {
1543                     /* An Inactive QCI has become active */
1544                     cell->qciArray[qci].ulUeCount++;
1545                  }
1546               }
1547               diffBits >>= 1;
1548               tempUeActQci >>= 1;
1549            }
1550         }
1551         ue->lastDatIndLCs = datIndActQci;
1552       
1553       }
1554
1555 #endif /* LTE_L2_MEAS */
1556       /* Just copy the timing information from the dat indication into the one
1557        * stored in the UE CB, will be later utilized to handle Timing advance 
1558        */
1559
1560       if ((ret = rgSCHUtlUpdSch (subfrmInfo, cell, ue, datInd, &err)) != ROK)
1561       {
1562          RGSCH_FREE_MEM(subfrmInfo);
1563          err.errType = RGSCHERR_TOM_DATIND;
1564          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Unable to handle Data"
1565                    " Indication for UEID:%d",ue->ueId);
1566          RETVALUE(RFAILED);
1567       }
1568
1569       CM_LLIST_NEXT_NODE(lnkLst, tmp);
1570    }
1571    /* RRM_RBC_X */
1572    /* update the UL PRB usage for all GBR QCIs*/
1573    for (idx = 0; idx < RGM_MAX_QCI_REPORTS; idx++)
1574    {
1575       cell->prbUsage.qciPrbRpts[idx].ulTotPrbUsed += subfrmInfo->qcisUlPrbCnt[idx];
1576    }
1577    /* RRM_RBC_Y */
1578
1579    /* chk if Sch needs to dealloc datInd after unpk */
1580    RGSCH_FREE_MEM(subfrmInfo);
1581    RETVALUE(ret);
1582 }  /* rgMacSchSfRecpInd */
1583
1584 #ifdef LTEMAC_SPS
1585 /**
1586  * @brief Function to handle relInd from MAC for a UE
1587  *
1588  * @details
1589  *
1590  *     Function: RgMacSchSpsRelInd
1591  *
1592  *     Handler for processing relInd for UL SPS of a UE
1593  *
1594  *     Invoked by: 
1595  *         MAC
1596  *
1597  *     Processing Steps:
1598  *           
1599  *  @param[in] Pst               *pst
1600  *  @param[in] RgInfSpsRelInfo   *relInfo
1601  *  @return  S16
1602  *      -# ROK 
1603  *      -# RFAILED 
1604  **/
1605 #ifdef ANSI
1606 PUBLIC S16 RgMacSchSpsRelInd
1607 (
1608 Pst                *pst, 
1609 RgInfSpsRelInfo    *relInfo
1610 )
1611 #else
1612 PUBLIC S16 RgMacSchSpsRelInd(pst, relInfo)
1613 Pst                *pst;
1614 RgInfSpsRelInfo    *relInfo;
1615 #endif
1616 {
1617    RgSchUeCb       *ue;
1618    RgSchCellCb     *cell;
1619    Inst            inst = (pst->dstInst - SCH_INST_START);
1620
1621    TRC2(RgMacSchSpsRelInd);
1622
1623    /* No need to chk for cell being NULL as MAC wouldn't have found instance if
1624     * it doesnt exist */
1625    cell = rgSchCb[inst].rgrSap[relInfo->cellSapId].cell;
1626
1627    if ((ue = rgSCHDbmGetUeCb(cell, relInfo->cRnti)) == NULLP)
1628    {
1629       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
1630            "No Ue exists with CRNTI:%d",relInfo->cRnti);
1631       RETVALUE(RFAILED);
1632    }
1633
1634    if ((rgSCHUtlSpsRelInd(cell, ue, relInfo->isExplRel)) != ROK)
1635    {
1636       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
1637            "RelInd processing for CRNTI:%d failed",relInfo->cRnti);
1638       RETVALUE(RFAILED);
1639    }
1640    RETVALUE(ROK);
1641 } /* end of RgMacSchSpsRelInd */
1642 #endif /* LTEMAC_SPS */
1643
1644 #ifdef LTE_L2_MEAS
1645
1646 /**
1647  * @brief Function to handle L2MeasCfm from MAC
1648  *
1649  * @details
1650  *
1651  *     Function: RgMacSchL2MeasCfm
1652  *
1653  *     Handler for processing L2 measurement confirm 
1654  *
1655  *     Invoked by: 
1656  *         MAC
1657  *
1658  *     Processing Steps:
1659  *           
1660  *  @param[in] Pst               *pst
1661  *  @param[in] RgInfL2MeasCfm    *measCfm
1662  *  @return  S16
1663  *      -# ROK 
1664  *      -# RFAILED 
1665  **/
1666 #ifdef ANSI
1667 PUBLIC S16 RgMacSchL2MeasCfm
1668 (
1669 Pst                *pst, 
1670 RgInfL2MeasCfm     *measCfm
1671 )
1672 #else
1673 PUBLIC S16 RgMacSchL2MeasCfm(pst, measCfm)
1674 Pst                *pst;
1675 RgInfL2MeasCfm     *measCfm;
1676 #endif
1677 {
1678    RgSchCellCb       *cell = NULLP;
1679    Inst              inst = (pst->dstInst - SCH_INST_START);
1680    CmLList           *lnk;
1681    RgSchL2MeasCb     *measCb = NULLP;
1682    RgSchCb           *instCb =  &rgSchCb[inst];
1683    U32               idx;
1684    LrgSchMeasCfmInfo schMeasCfm;
1685    U8                qciVal;
1686    U8                idx1; /*LTE_L2_MEAS_PHASE2*/ 
1687    U8                qciVal1;
1688    TRC2(RgMacSchL2MeasCfm);
1689
1690    /* Find the cellCb using cellId in measInfo. Iterate through all cells
1691     * in rgrsapCb in RgschCb */
1692    for (idx = 0; idx < instCb->numSaps; idx++)
1693    {
1694       if ( instCb->rgrSap[idx].cell->cellId == measCfm->cellId)
1695       {
1696          /* got the cell break the loop */
1697          cell = instCb->rgrSap[idx].cell;
1698          break;
1699       }
1700    }
1701    /* If no cellCb return Err with Invalid Cell Id */
1702    if (cell == NULLP)
1703    {
1704       RLOG_ARG0(L_ERROR,DBG_CELLID,measCfm->cellId,
1705                   "Meas Cfm Failed.Invalid Cell Id");
1706       RETVALUE(RFAILED);
1707    }
1708    
1709
1710    /* Iterate through all meas requests in l2mList in cellCb */
1711    lnk = cell->l2mList.first;
1712    while(lnk != NULLP)
1713    {
1714       /* Get the MeasCb : RgSchL2MeasCb */
1715       measCb = (RgSchL2MeasCb *)lnk->node;
1716       lnk = lnk->next;
1717       if (measCb->measReq.hdr.transId == measCfm->transId)
1718       {
1719          break;
1720       }
1721    }
1722    if ( measCb == NULLP )
1723    {
1724       RETVALUE( RFAILED );
1725    }
1726
1727
1728    if(measCfm->cfm.status != LCM_PRIM_OK)
1729    {
1730       for (idx = 0; idx < measCb->measReq.avgPrbQciUl.numQci; idx++)
1731       {
1732         qciVal = measCb->measReq.avgPrbQciUl.qci[idx];
1733         cell->qciArray[qciVal].qci = 0;
1734       }
1735       /* Delete this measCb, send the negative confirmation to
1736        * stack manager */
1737       cmLListDelFrm(&cell->l2mList, &measCb->measLnk);
1738       /* ccpu00117052 - MOD - Passing double pointer
1739          for proper NULLP assignment*/
1740       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&measCb, sizeof(RgSchL2MeasCb));
1741       cmMemset((U8 *)&schMeasCfm, 0, sizeof(LrgSchMeasCfmInfo));
1742       schMeasCfm.measType     = measCfm->measType;
1743       schMeasCfm.cfm          = measCfm->cfm;
1744       schMeasCfm.hdr.transId  = measCfm->transId;
1745       schMeasCfm.cellId       = measCfm->cellId;
1746       RgMiLrgSchL2MeasCfm(&(instCb->rgSchInit.lmPst), &schMeasCfm);
1747       RETVALUE(ROK);
1748    }
1749    for(idx = 0; idx < measCfm->u.prbCfm.numQci; idx++)
1750    {
1751       measCb->avgPrbQciUl.prbUsage[idx].prbUsage = measCfm->u.prbCfm.prbUsage[idx].prbUsage;
1752       measCb->avgPrbQciUl.prbUsage[idx].qciValue = measCfm->u.prbCfm.prbUsage[idx].qciValue;
1753       /*LTE_L2_MEAS_PHASE2*/
1754       qciVal1 = measCfm->u.prbCfm.prbUsage[idx].qciValue;
1755       for(idx1=0;idx1<measCb->measReq.avgPrbQciUl.numQci;idx1++)
1756       {
1757          if(measCb->measReq.avgPrbQciUl.qci[idx1] == qciVal1)
1758          {
1759             break;
1760          }
1761       }
1762       if(idx1 == measCb->measReq.avgPrbQciUl.numQci)
1763       {
1764          measCb->measReq.avgPrbQciUl.qci[measCb->measReq.avgPrbQciUl.numQci++] = qciVal1;
1765       }
1766    }
1767    measCb->avgPrbQciUl.numQci = measCfm->u.prbCfm.numQci;
1768    measCb->cfmRcvd = TRUE;
1769    cell->sndL2Meas = TRUE;
1770    RETVALUE(ROK);
1771 } /* end of RgMacSchL2MeasCfm */
1772
1773 /**
1774  * @brief Function to handle L2MeasStopCfm from MAC
1775  *
1776  * @details
1777  *
1778  *     Function: RgMacSchL2MeasStopCfm
1779  *
1780  *     Handler for processing L2 measurement confirm 
1781  *
1782  *     Invoked by: 
1783  *         MAC
1784  *
1785  *     Processing Steps:
1786  *           
1787  *  @param[in] Pst               *pst
1788  *  @param[in] RgInfL2MeasCfm    *measCfm
1789  *  @return  S16
1790  *      -# ROK 
1791  *      -# RFAILED 
1792  **/
1793 #ifdef ANSI
1794 PUBLIC S16 RgMacSchL2MeasStopCfm
1795 (
1796 Pst                *pst,
1797 RgInfL2MeasCfm     *measCfm
1798 )
1799 #else
1800 PUBLIC S16 RgMacSchL2MeasStopCfm(pst, measCfm)
1801 Pst                *pst;
1802 RgInfL2MeasCfm     *measCfm;
1803 #endif
1804 {
1805    LrgSchMeasCfmInfo schMeasCfm;
1806    Inst              inst = (pst->dstInst - SCH_INST_START);
1807    RgSchCb           *instCb =  &rgSchCb[inst];
1808
1809    TRC2(RgMacSchL2MeasStopCfm);
1810
1811    cmMemset((U8 *)&schMeasCfm, 0, sizeof(LrgSchMeasCfmInfo));
1812    schMeasCfm.measType     = measCfm->measType;
1813    schMeasCfm.cfm          = measCfm->cfm;
1814    schMeasCfm.hdr.transId  = measCfm->transId;
1815    schMeasCfm.cellId       = measCfm->cellId;
1816    RgMiLrgSchL2MeasStopCfm(&(instCb->rgSchInit.lmPst), &schMeasCfm);
1817    RETVALUE(ROK);
1818 }
1819 #endif
1820
1821 /************** TFU Interface *************/
1822
1823 /**
1824  * @brief Bind confirm API for TFU SAP on scheduler instance. 
1825  *
1826  * @details
1827  *
1828  *     Function : RgLiTfuSchBndCfm
1829  *      
1830  *      This API is invoked by PHY to confirm TFU SAP bind. 
1831  *     
1832  *           
1833  *  @param[in]  Pst   *pst 
1834  *  @param[in]  SuId  suId 
1835  *  @param[in]  U8    status
1836  *  @return  S16
1837  *      -# ROK 
1838  *      -# RFAILED 
1839  **/
1840 #ifdef ANSI
1841 PUBLIC S16 RgLiTfuSchBndCfm 
1842 (
1843 Pst     *pst,
1844 SuId    suId, 
1845 U8      status
1846 )
1847 #else
1848 PUBLIC S16 RgLiTfuSchBndCfm(pst, suId, status)
1849 Pst     *pst; 
1850 SuId    suId; 
1851 U8      status;
1852 #endif
1853 {
1854    S16 ret;
1855    RgSchLowSapCb  *tfuSap;
1856    Inst  instId = pst->dstInst - SCH_INST_START;
1857
1858    TRC3(RgLiTfuSchBndCfm);
1859
1860
1861    if(suId >= rgSchCb[instId].numSaps)
1862    {
1863       RLOG_ARG0(L_ERROR,DBG_INSTID,instId, "Incorrect SuId");
1864       RETVALUE(RFAILED);
1865    }
1866    /* Lets validate suId first */
1867    tfuSap = &(rgSchCb[instId].tfuSap[suId]);
1868
1869    if (suId != tfuSap->sapCfg.suId)
1870    {
1871       RLOG_ARG2(L_ERROR,DBG_INSTID,instId, "Incorrect SuId. Configured (%d)"
1872             "Recieved (%d)", tfuSap->sapCfg.suId, suId);
1873       RETVALUE(RFAILED);
1874    }
1875    ret = rgSCHLmmBndCfm (pst, suId, status);
1876    RETVALUE(ret);
1877 }  /* RgLiTfuSchBndCfm */
1878
1879 /**
1880  * @brief Random Access Request indication from PHY.
1881  *
1882  * @details
1883  *
1884  *     Function : RgLiTfuRaReqInd
1885  *      
1886  *      This API is invoked by PHY to send Random Access Request to Scheduler.
1887  *      This API contains information for Random Access Request including 
1888  *      raRnti, list of associated RAPIDs and related information.
1889  *           
1890  *  @param[in]  Pst              *pst 
1891  *  @param[in]  SuId             suId 
1892  *  @param[in]  TfuRaReqIndInfo  *raReqInd
1893  *  @return  S16
1894  *      -# ROK 
1895  *      -# RFAILED 
1896  **/
1897 #ifdef ANSI
1898 PUBLIC S16 RgLiTfuRaReqInd
1899 (
1900 Pst              *pst, 
1901 SuId             suId, 
1902 TfuRaReqIndInfo  *raReqInd
1903 )
1904 #else
1905 PUBLIC S16 RgLiTfuRaReqInd(pst, suId, raReqInd)
1906 Pst              *pst; 
1907 SuId             suId; 
1908 TfuRaReqIndInfo  *raReqInd;
1909 #endif
1910 {
1911    S16   ret;
1912    Inst  inst = pst->dstInst-SCH_INST_START;
1913
1914    TRC3(RgLiTfuRaReqInd);
1915
1916    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1917    {
1918       RLOG_ARG1(L_ERROR,DBG_INSTID,inst,"SAP Validation failed SuId(%d)", suId);
1919       /* Free up the memory for the request structure */
1920       RGSCH_FREE_MEM(raReqInd);
1921       RETVALUE(ret);
1922    }
1923
1924    if(raReqInd == NULLP)
1925    {
1926       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"Invalid input pointer for raReqInd Failed");
1927       RETVALUE(RFAILED);
1928    }
1929
1930    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1931    {
1932       RLOG_ARG0(L_ERROR,DBG_CELLID,raReqInd->cellId,"No cell exists");
1933       RETVALUE(RFAILED);
1934    }
1935
1936    ret = rgSCHTomRaReqInd(rgSchCb[inst].tfuSap[suId].cell, raReqInd);
1937    /* Free up the memory for the request structure */
1938    RGSCH_FREE_MEM(raReqInd);
1939    /*SPutSBuf (pst->region, pst->pool, (Data *)raReqInd,
1940          sizeof(TfuRaReqIndInfo)); */
1941    RETVALUE(ret);
1942 }  /* RgLiTfuRaReqInd */
1943
1944 /**
1945  * @brief Uplink CQI indication from PHY.
1946  *
1947  * @details
1948  *
1949  *     Function : RgLiTfuUlCqiInd
1950  *      
1951  *      This API is invoked by PHY to send Uplink CQI to Scheduler.
1952  *      This API contains Uplink CQI information reported per UE.
1953  *           
1954  *  @param[in]  Pst               *pst 
1955  *  @param[in]  SuId              suId 
1956  *  @param[in]  TfuUlCqiIndInfo   *ulCqiInd
1957  *  @return  S16
1958  *      -# ROK 
1959  *      -# RFAILED 
1960  **/
1961 #ifdef ANSI
1962 PUBLIC S16 RgLiTfuUlCqiInd
1963 (
1964 Pst              *pst, 
1965 SuId             suId, 
1966 TfuUlCqiIndInfo  *ulCqiInd
1967 )
1968 #else
1969 PUBLIC S16 RgLiTfuUlCqiInd(pst, suId, ulCqiInd)
1970 Pst              *pst; 
1971 SuId             suId; 
1972 TfuUlCqiIndInfo  *ulCqiInd;
1973 #endif
1974 {
1975    S16   ret;
1976    Inst  inst = pst->dstInst-SCH_INST_START;
1977
1978    TRC3(RgLiTfuUlCqiInd);
1979
1980    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1981    {
1982       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"SAP Validation failed");
1983       /* Free up the memory for the request structure */
1984       RGSCH_FREE_MEM(ulCqiInd);
1985       RETVALUE(ret);
1986    }
1987
1988    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1989    {
1990       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"No cell exists");
1991       /* Free up the memory for the request structure */
1992       RGSCH_FREE_MEM(ulCqiInd);
1993       RETVALUE(RFAILED);
1994    }
1995    ret = rgSCHTomUlCqiInd (rgSchCb[inst].tfuSap[suId].cell, ulCqiInd);
1996    /* Free up the memory for the request structure */
1997    RGSCH_FREE_MEM(ulCqiInd);
1998    RETVALUE(ret);
1999 }  /* RgLiTfuUlCqiInd */
2000
2001 /**
2002  * @brief PUCCH power adjustment indication.
2003  *
2004  * @details
2005  *
2006  *     Function : RgLiTfuPucchDeltaPwrInd
2007  *
2008  *      This API is invoked by PHY to send PUCCH power adjustment
2009  *      indication.
2010  *
2011  *  @param[in]  Pst                     *pst 
2012  *  @param[in]  SuId                    suId 
2013  *  @param[in]  TfuPucchDeltaPwrIndInfo *pucchDeltaPwr
2014  *  @return  S16
2015  *      -# ROK 
2016  *      -# RFAILED 
2017  **/
2018 #ifdef ANSI
2019 PUBLIC S16 RgLiTfuPucchDeltaPwrInd
2020 (
2021 Pst                     *pst,
2022 SuId                    suId,
2023 TfuPucchDeltaPwrIndInfo *pucchDeltaPwr
2024 )
2025 #else
2026 PUBLIC S16 RgLiTfuPucchDeltaPwrInd(pst, suId, pucchDeltaPwr)
2027 Pst                     *pst;
2028 SuId                    suId;
2029 TfuPucchDeltaPwrIndInfo *pucchDeltaPwr;
2030 #endif
2031 {
2032    S16   ret;
2033    Inst  inst = pst->dstInst-SCH_INST_START;
2034
2035    TRC3(RgLiTfuPucchDeltaPwrInd);
2036
2037    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2038    {
2039       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"SAP Validation failed");
2040       /* Free up the memory for the request structure */
2041       RGSCH_FREE_MEM(pucchDeltaPwr);
2042       RETVALUE(ret);
2043    }
2044
2045    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2046    {
2047       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"No cell exists");
2048       RETVALUE(RFAILED);
2049    }
2050    ret = rgSCHTomPucchDeltaPwrInd (rgSchCb[inst].tfuSap[suId].cell, pucchDeltaPwr);
2051    /* Free up the memory for the request structure */
2052    RGSCH_FREE_MEM(pucchDeltaPwr);
2053    RETVALUE(ret);
2054 }  /* RgLiTfuPucchDeltaPwrInd */
2055
2056
2057 /**
2058  * @brief HARQ ACK indication from PHY for Downlink transmissions.
2059  *
2060  * @details
2061  *
2062  *     Function : RgLiTfuHqInd
2063  *      
2064  *      This API is invoked by PHY to send HARQ ACK information to Scheduler
2065  *      on recieving HARQ ACK/NACK from UEs.
2066  *      This API contains HARQ ACK information recieved by PHY for downlink
2067  *      transmissions.
2068  *           
2069  *  @param[in]  Pst                *pst
2070  *  @param[in]  SuId               suId 
2071  *  @param[in]  TfuHqIndInfo       *harqAckInd
2072  *  @return  S16
2073  *      -# ROK 
2074  *      -# RFAILED 
2075  **/
2076 #ifdef ANSI
2077 PUBLIC S16 RgLiTfuHqInd
2078 (
2079 Pst                *pst, 
2080 SuId               suId, 
2081 TfuHqIndInfo       *harqAckInd
2082 )
2083 #else
2084 PUBLIC S16 RgLiTfuHqInd(pst, suId, harqAckInd)
2085 Pst                *pst; 
2086 SuId               suId; 
2087 TfuHqIndInfo       *harqAckInd;
2088 #endif
2089 {
2090    S16   ret;
2091    Inst  inst = (pst->dstInst - SCH_INST_START);
2092
2093    TRC3(RgLiTfuHqInd);
2094
2095 #ifndef NO_ERRCLS
2096    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2097    {
2098       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"SAP Validation failed");
2099       RGSCH_FREE_MEM(harqAckInd);
2100       RETVALUE(ret);
2101    }
2102
2103    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2104    {
2105       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"No cell exists");
2106       RETVALUE(RFAILED);
2107    }
2108 #endif
2109
2110    /* Now call the TOM (Tfu ownership module) primitive to process further */
2111    ret = rgSCHTomHarqAckInd (rgSchCb[inst].tfuSap[suId].cell, harqAckInd);
2112    /* Free up the memory for the request structure */
2113    RGSCH_FREE_MEM(harqAckInd);
2114    RETVALUE(ret);
2115 }  /* RgLiTfuHqInd */
2116
2117
2118 /**
2119  * @brief Scheduling request(SR) indication from PHY for an UE.
2120  *
2121  * @details
2122  *
2123  *     Function : RgLiTfuSrInd
2124  *      
2125  *      This API is invoked by PHY to send Scheduling request information to
2126  *      Scheduler on recieving SR from a list of UEs.
2127  *      This API contains scheduling request information recieved by PHY for UEs.
2128  *           
2129  *  @param[in]  Pst           *pst
2130  *  @param[in]  SuId          suId 
2131  *  @param[in]  TfuSrIndInfo  *srInd
2132  *  @return  S16
2133  *      -# ROK 
2134  *      -# RFAILED 
2135  **/
2136 #ifdef ANSI
2137 PUBLIC S16 RgLiTfuSrInd
2138 (
2139 Pst                *pst, 
2140 SuId               suId, 
2141 TfuSrIndInfo       *srInd
2142 )
2143 #else 
2144 PUBLIC S16 RgLiTfuSrInd(pst, suId, srInd)
2145 Pst                *pst; 
2146 SuId               suId; 
2147 TfuSrIndInfo       *srInd;
2148 #endif
2149 {
2150    S16   ret;
2151    Inst  inst = pst->dstInst-SCH_INST_START;
2152
2153    TRC3(RgLiTfuSrInd);
2154
2155 #ifndef NO_ERRCLS
2156    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2157    {
2158       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"() SAP Validation failed");
2159       RGSCH_FREE_MEM(srInd);
2160       RETVALUE(ret);
2161    }
2162
2163    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2164    {
2165       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"RgLiTfuSrInd()No cell exists");
2166       RETVALUE(RFAILED);
2167    }
2168 #endif
2169    /* Now call the TOM (Tfu ownership module) primitive to process further */
2170    ret = rgSCHTomSrInd (rgSchCb[inst].tfuSap[suId].cell, srInd);
2171    /* Free up the memory for the request structure */
2172    RGSCH_FREE_MEM(srInd);
2173    RETVALUE(ret);
2174 }  /* RgLiTfuSrInd */
2175
2176
2177 /**
2178  * @brief Downlink CQI indication from PHY for an UE.
2179  *
2180  * @details
2181  *
2182  *     Function : RgLiTfuDlCqiInd
2183  *      
2184  *      This API is invoked by PHY to send Downlink CQI indication to Scheduler
2185  *      on recieving downlink CQI from UE.
2186  *      This API contains downlink CQI information recieved by PHY for an UE.
2187  *           
2188  *  @param[in]  Pst              *pst
2189  *  @param[in]  SuId             suId 
2190  *  @param[in]  TfuDlCqiIndInfo  *dlCqiInd
2191  *  @return  S16
2192  *      -# ROK 
2193  *      -# RFAILED 
2194  **/
2195 #ifdef ANSI
2196 PUBLIC S16 RgLiTfuDlCqiInd
2197 (
2198 Pst                *pst, 
2199 SuId               suId, 
2200 TfuDlCqiIndInfo    *dlCqiInd
2201 )
2202 #else
2203 PUBLIC S16 RgLiTfuDlCqiInd(pst, suId, dlCqiInd)
2204 Pst                *pst; 
2205 SuId               suId; 
2206 TfuDlCqiIndInfo    *dlCqiInd;
2207 #endif
2208 {
2209    S16   ret;
2210    Inst  inst = pst->dstInst-SCH_INST_START;
2211
2212    TRC3(RgLiTfuDlCqiInd);
2213
2214    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2215    {
2216       RLOG_ARG0(L_ERROR,DBG_INSTID,inst," SAP Validation failed");
2217       /* Free up the memory for the request structure */
2218       RGSCH_FREE_MEM(dlCqiInd);
2219       RETVALUE(ret);
2220    }
2221
2222    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2223    {
2224       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"No cell exists");
2225       RETVALUE(RFAILED);
2226    }
2227    ret = rgSCHTomDlCqiInd (rgSchCb[inst].tfuSap[suId].cell, dlCqiInd);
2228    /* Free up the memory for the request structure */
2229    RGSCH_FREE_MEM(dlCqiInd);
2230    RETVALUE(ret);
2231 }  /* RgLiTfuDlCqiInd */
2232 #ifdef TFU_UPGRADE
2233
2234 /**
2235  * @brief Raw CQI indication from PHY for an UE.
2236  *
2237  * @details
2238  *
2239  *     Function : RgLiTfuRawCqiInd
2240  *      
2241  *      This API is invoked by PHY to send Raw CQI indication to Scheduler
2242  *      on receiving Raw CQI from UE.
2243  *      This API contains Raw CQI information recieved by PHY for an UE.
2244  *           
2245  *  @param[in]  Pst              *pst
2246  *  @param[in]  SuId             suId 
2247  *  @param[in]  TfuRawCqiIndInfo  *rawCqiInd
2248  *  @return  S16
2249  *      -# ROK 
2250  *      -# RFAILED 
2251  **/
2252 #ifdef ANSI
2253 PUBLIC S16 RgLiTfuRawCqiInd
2254 (
2255 Pst                *pst, 
2256 SuId               suId, 
2257 TfuRawCqiIndInfo    *rawCqiInd
2258 )
2259 #else
2260 PUBLIC S16 RgLiTfuRawCqiInd(pst, suId, rawCqiInd)
2261 Pst                *pst; 
2262 SuId               suId; 
2263 TfuRawCqiIndInfo    *rawCqiInd;
2264 #endif
2265 {
2266    S16   ret;
2267    Inst  inst = pst->dstInst-SCH_INST_START;
2268
2269    TRC3(RgLiTfuRawCqiInd);
2270
2271 #ifdef NO_ERRCLS
2272    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2273    {
2274       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"SAP Validation failed");
2275       /* Free up the memory for the request structure */
2276       RGSCH_FREE_MEM(rawCqiInd);
2277       RETVALUE(ret);
2278    }
2279
2280    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2281    {
2282       RLOG_ARG0(L_ERROR,DBG_INSTID,inst," No cell exists");
2283       RETVALUE(RFAILED);
2284    }
2285 #endif
2286    ret = rgSCHTomRawCqiInd (rgSchCb[inst].tfuSap[suId].cell, rawCqiInd);
2287    /* Free up the memory for the request structure */
2288    RGSCH_FREE_MEM(rawCqiInd);
2289    RETVALUE(ret);
2290 }  /* RgLiTfuRawCqiInd */
2291
2292 /**
2293  * @brief SRS indication from PHY for an UE.
2294  *
2295  * @details
2296  *
2297  *     Function : RgLiTfuSrsInd
2298  *      
2299  *      This API is invoked by PHY to send UL SRS indication to Scheduler
2300  *      on receiving a SRS from UE.
2301  *      This API contains SRS information recieved by PHY for an UE.
2302  *           
2303  *  @param[in]  Pst              *pst
2304  *  @param[in]  SuId             suId 
2305  *  @param[in]  TfuSrsIndInfo  *srsInd
2306  *  @return  S16
2307  *      -# ROK 
2308  *      -# RFAILED 
2309  **/
2310 #ifdef ANSI
2311 PUBLIC S16 RgLiTfuSrsInd
2312 (
2313 Pst                *pst, 
2314 SuId               suId, 
2315 TfuSrsIndInfo    *srsInd
2316 )
2317 #else
2318 PUBLIC S16 RgLiTfuSrsInd(pst, suId, srsInd)
2319 Pst                *pst; 
2320 SuId               suId; 
2321 TfuSrsIndInfo    *srsInd;
2322 #endif
2323 {
2324    S16   ret;
2325    Inst  inst = pst->dstInst-SCH_INST_START;
2326
2327    TRC3(RgLiTfuSrsInd);
2328
2329    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2330    {
2331       RLOG_ARG0(L_ERROR,DBG_INSTID,inst," SAP Validation failed");
2332       /* Free up the memory for the request structure */
2333       RGSCH_FREE_MEM(srsInd);
2334       RETVALUE(ret);
2335    }
2336
2337    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2338    {
2339       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"No cell exists");
2340       RETVALUE(RFAILED);
2341    }
2342    ret = rgSCHTomSrsInd (rgSchCb[inst].tfuSap[suId].cell, srsInd);
2343    /* Free up the memory for the request structure */
2344    RGSCH_FREE_MEM(srsInd);
2345    RETVALUE(ret);
2346 }  /* RgLiTfuSrsInd */
2347
2348 #endif 
2349
2350 /**
2351  * @brief DOA indication from PHY for an UE.
2352  *
2353  * @details
2354  *
2355  *     Function : RgLiTfuDoaInd
2356  *      
2357  *      This API is invoked by PHY to send Direction Of Arrival to Scheduler
2358  *      on calculating DOA at PHYSICAL LAYER for an UE.
2359  *      This API contains DOA information calculated by PHY for an UE.
2360  *           
2361  *  @param[in]  Pst              *pst
2362  *  @param[in]  SuId             suId 
2363  *  @param[in]  TfuDoaIndInfo    *doaInd
2364  *  @return  S16
2365  *      -# ROK 
2366  *      -# RFAILED 
2367  **/
2368 #ifdef ANSI
2369 PUBLIC S16 RgLiTfuDoaInd 
2370 (
2371 Pst                *pst, 
2372 SuId               suId, 
2373 TfuDoaIndInfo      *doaInd
2374 )
2375 #else
2376 PUBLIC S16 RgLiTfuDoaInd(pst, suId, doaInd)
2377 Pst                *pst; 
2378 SuId               suId; 
2379 TfuDoaIndInfo      *doaInd;
2380 #endif
2381 {
2382    S16   ret;
2383    Inst  inst = pst->dstInst-SCH_INST_START;
2384
2385    TRC2(RgLiTfuDoaInd);
2386
2387    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2388    {
2389       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"SAP Validation failed");
2390       /* Free up the memory for the request structure */
2391       RGSCH_FREE_MEM(doaInd);
2392       RETVALUE(ret);
2393    }
2394
2395    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2396    {
2397       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"No cell exists");
2398       RETVALUE(RFAILED);
2399    }
2400    ret = rgSCHTomDoaInd (rgSchCb[inst].tfuSap[suId].cell, doaInd);
2401    /* Free up the memory for the request structure */
2402    RGSCH_FREE_MEM(doaInd);
2403    RETVALUE(ret);
2404 }  /* RgLiTfuDlCqiInd */
2405
2406 /**
2407  * @brief CRC indication from PHY.
2408  *
2409  * @details
2410  *
2411  *     Function : RgLiTfuCrcInd
2412  *      
2413  *      This API is invoked by PHY to give CRC indication to scheduler.
2414  *           
2415  *  @param[in]  Pst               *pst
2416  *  @param[in]  SuId              suId 
2417  *  @param[in]  TfuCrcIndInfo *crcInd
2418  *  @return  S16
2419  *      -# ROK 
2420  *      -# RFAILED 
2421  **/
2422 #ifdef ANSI
2423 PUBLIC S16 RgLiTfuCrcInd
2424 (
2425 Pst                *pst, 
2426 SuId               suId, 
2427 TfuCrcIndInfo  *crcInd
2428 )
2429 #else
2430 PUBLIC S16 RgLiTfuCrcInd (pst, suId, crcInd)
2431 Pst                *pst; 
2432 SuId               suId; 
2433 TfuCrcIndInfo  *crcInd;
2434 #endif
2435 {
2436    S16              ret;
2437    Inst             inst      = pst->dstInst-SCH_INST_START;
2438
2439    TRC3(RgLiTfuCrcInd);
2440 #ifdef XEON_SPECIFIC_CHANGES
2441 struct timeval start6, end6;
2442 gettimeofday(&start6, NULL);
2443 #endif
2444 #ifndef NO_ERRCLS
2445    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2446    {
2447       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"SAP Validation failed");
2448       RGSCH_FREE_MEM(crcInd);
2449       RETVALUE(ret);
2450    }
2451
2452    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2453    {
2454       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"No cell exists");
2455       RETVALUE(RFAILED);
2456    }
2457 #endif
2458
2459    /* Now call the TOM (Tfu ownership module) primitive to process further */
2460    ret = rgSCHTomCrcInd(rgSchCb[inst].tfuSap[suId].cell, crcInd);
2461    /* Free up the memory for the request structure */
2462    RGSCH_FREE_MEM(crcInd);
2463 #ifdef XEON_SPECIFIC_CHANGES
2464 gettimeofday(&end6, NULL);
2465 #endif
2466    RETVALUE(ret);
2467 }  /* RgLiTfuCrcInd */
2468
2469 /**
2470  * @brief Timing Advance indication from PHY.
2471  *
2472  * @details
2473  *
2474  *     Function : RgLiTfuTimingAdvInd
2475  *      
2476  *      This API is invoked by PHY to indicate timing advance to Scheduler for
2477  *       an UE.
2478  *           
2479  *  @param[in]  Pst                  *pst
2480  *  @param[in]  SuId                 suId 
2481  *  @param[in]  TfuTimingAdvIndInfo  *timingAdvInd
2482  *  @return  S16
2483  *      -# ROK 
2484  *      -# RFAILED 
2485  **/
2486 #ifdef ANSI
2487 PUBLIC S16 RgLiTfuTimingAdvInd
2488 (
2489 Pst                  *pst, 
2490 SuId                 suId, 
2491 TfuTimingAdvIndInfo  *timingAdvInd
2492 )
2493 #else
2494 PUBLIC S16 RgLiTfuTimingAdvInd(pst, suId, timingAdvInd)
2495 Pst                  *pst; 
2496 SuId                 suId; 
2497 TfuTimingAdvIndInfo  *timingAdvInd;
2498 #endif
2499 {
2500    S16   ret;
2501    Inst  inst = pst->dstInst-SCH_INST_START;
2502
2503    TRC3(RgLiTfuTimingAdvInd);
2504
2505    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2506    {
2507       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"SAP Validation failed");
2508       /* Free up the memory for the request structure */
2509       RGSCH_FREE_MEM(timingAdvInd);
2510       RETVALUE(ret);
2511    }
2512
2513    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2514    {
2515       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"No cell exists");
2516       RETVALUE(RFAILED);
2517    }
2518    /* Now call the TOM (Tfu ownership module) primitive to process further */
2519    ret = rgSCHTomTimingAdvInd(rgSchCb[inst].tfuSap[suId].cell, timingAdvInd);
2520    /* Free up the memory for the request structure */
2521    RGSCH_FREE_MEM(timingAdvInd);
2522    RETVALUE(ret);
2523 }  /* RgLiTfuTimingAdvInd */
2524
2525 /************* RGM  Interface ****************/
2526 /**
2527  * @brief API for bind request from RRM towards MAC. 
2528  *
2529  * @details
2530  *
2531  *     Function: RgUiRgmBndReq
2532  *     
2533  *     This API is invoked by RRM towards MAC to bind RGM SAP. 
2534  *     These API validates the Pst, spId, suId and sends the bind confirm to
2535  *     RRM.
2536  *
2537  *           
2538  *  @param[in]  Pst   *pst
2539  *  @param[in]  SuId  suId
2540  *  @param[in]  SpId  spId
2541  *  @return  S16
2542  *      -# ROK 
2543  *      -# RFAILED 
2544  **/
2545 #ifdef ANSI
2546 PUBLIC S16 RgUiRgmBndReq
2547 (
2548 Pst   *pst, 
2549 SuId  suId,
2550 SpId  spId
2551 )
2552 #else
2553 PUBLIC S16 RgUiRgmBndReq(pst, suId, spId)
2554 Pst   *pst; 
2555 SuId  suId;
2556 SpId  spId;
2557 #endif
2558 {
2559    S16       ret = ROK;
2560    Pst       tmpPst;   /* Temporary Post Structure */
2561    Inst      instId = pst->dstInst-SCH_INST_START;
2562
2563    TRC3(RgUiRgmBndReq)
2564    
2565    
2566    tmpPst.prior       = pst->prior;
2567    tmpPst.route       = pst->route;
2568    tmpPst.selector    = pst->selector;
2569    tmpPst.region      = rgSchCb[instId].rgSchInit.region;
2570    tmpPst.pool        = rgSchCb[instId].rgSchInit.pool;
2571
2572    tmpPst.srcProcId   = rgSchCb[instId].rgSchInit.procId;
2573    tmpPst.srcEnt      = rgSchCb[instId].rgSchInit.ent;
2574    tmpPst.srcInst     = rgSchCb[instId].rgSchInit.inst + SCH_INST_START;
2575
2576    tmpPst.event       = EVTNONE;
2577
2578    tmpPst.dstProcId   = pst->srcProcId;
2579    tmpPst.dstEnt      = pst->srcEnt;
2580    tmpPst.dstInst     = pst->srcInst;
2581
2582    /*TODO remove follo statement*/
2583    rgSchCb[instId].rgmSap[spId].sapSta.sapState = LRG_UNBND;
2584
2585    if(spId < rgSchCb[instId].numSaps)
2586    {
2587       /* Check the state of the SAP */
2588       switch (rgSchCb[instId].rgmSap[spId].sapSta.sapState)
2589       {
2590          /* This case might not be needed if SAP not configured then it will go
2591           * to else of above if condition */
2592          case LRG_UNBND: /* SAP is not bound */
2593                  RLOG0(L_DEBUG,"SAP is not yet bound");
2594             rgSchCb[instId].rgmSap[spId].sapSta.sapState = LRG_BND;
2595             rgSchCb[instId].rgmSap[spId].sapCfg.suId = suId;
2596             /* Send Bind Confirm with status as SUCCESS */
2597             ret = rgSCHUtlRgmBndCfm(instId, suId, CM_BND_OK);
2598              /*Indicate to Layer manager  */
2599             break;
2600          case LRG_BND: /* SAP is already bound*/
2601                  RLOG0(L_DEBUG,"SAP is already bound");
2602             ret = rgSCHUtlRgmBndCfm(instId, suId, CM_BND_OK);
2603             break;
2604          default: /* Should Never Enter here */
2605 #if (ERRCLASS & ERRCLS_ADD_RES) 
2606             RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG001, 
2607                  (ErrVal)rgSchCb[instId].rgmSap[spId].sapSta.sapState,
2608                   "Invalid SAP State:RgUiRgmBndReq failed\n");
2609 #endif
2610             ret = rgSCHUtlRgmBndCfm(instId, suId, CM_BND_NOK);
2611             break;
2612       }
2613    }
2614    else
2615    {
2616 #if (ERRCLASS & ERRCLS_ADD_RES)      
2617 /* ccpu00117035 - MOD - Changed ErrVal argument from accessing sap state 
2618    to spId to avoid seg fault due to invalid sapID */
2619       RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG002,
2620             (ErrVal)spId, "Invalid SAP Id:RgUiRrmBndReq failed\n");
2621 #endif
2622       ret = RgUiRgmBndCfm(&tmpPst, suId, CM_BND_NOK);
2623    }
2624    RETVALUE(ret);
2625 }  /* RgUiRgmBndReq */
2626
2627 /**
2628  * @brief API for unbind request from RRM towards MAC. 
2629  *
2630  * @details
2631  *
2632  *     Function: RgUiRgmUbndReq
2633  *     
2634  *     This API is invoked by RRM towards MAC to unbind RGM SAP. 
2635  *     These API validates the Pst, spId, suId and transfers the unbind request 
2636  *     specific information to corresponding ownership module (GOM) API.
2637  *
2638  *           
2639  *  @param[in]  Pst    *pst
2640  *  @param[in]  SuId   suId
2641  *  @param[in]  Reason reason
2642  *  @return  S16
2643  *      -# ROK 
2644  *      -# RFAILED 
2645  **/
2646 #ifdef ANSI
2647 PUBLIC S16 RgUiRgmUbndReq
2648 (
2649 Pst    *pst,
2650 SpId   spId,
2651 Reason reason
2652 )
2653 #else
2654 PUBLIC S16 RgUiRgmUbndReq(pst, spId, reason)
2655 Pst    *pst; 
2656 SpId   spId;
2657 Reason reason;
2658 #endif
2659 {
2660    Inst instId = pst->dstInst-SCH_INST_START;
2661    TRC3(RgUiRgmUbndReq)
2662    
2663
2664    /* SAP Id validation */
2665    if (spId < rgSchCb[instId].numSaps)
2666    {
2667       switch(rgSchCb[instId].rgmSap[spId].sapSta.sapState)
2668       {
2669          case LRG_BND: /* SAP is already bound*/
2670             /* setting SAP state to UN BOUND */
2671                  RLOG0(L_DEBUG,"SAP is already bound");
2672             rgSchCb[instId].rgmSap[spId].sapSta.sapState = LRG_UNBND;
2673             break;
2674          default:
2675 #if (ERRCLASS & ERRCLS_ADD_RES)      
2676             RGSCHLOGERROR(instId, ERRCLS_INT_PAR, ERG003,
2677                    (ErrVal)rgSchCb[instId].rgmSap[spId].sapSta.sapState,
2678                   "Invalid SAP State: RgUiRgmUbndReq failed\n");
2679 #endif
2680             RETVALUE(RFAILED);
2681       }
2682    }
2683    else
2684    {
2685 #if (ERRCLASS & ERRCLS_ADD_RES)      
2686       RGSCHLOGERROR(instId,ERRCLS_INT_PAR, ERG004, 
2687             (ErrVal)rgSchCb[instId].rgmSap[spId].sapSta.sapState,
2688             "Invalid SAP Id:RgUiRgmUbndReq failed\n");
2689 #endif
2690       RETVALUE(RFAILED);
2691    }
2692    RETVALUE(ROK);
2693 }  /* RgUiRgmUbndReq */
2694
2695
2696 /**
2697  * @brief API for start or stop PRB reporting from RRM towards MAC. 
2698  *
2699  * @details
2700  *
2701  *     Function: RgUiRgmCfgPrbRprt
2702  *     
2703  *     This API is invoked by RRM towards MAC to start or stop calculating
2704  *     Average PRB usage in downlink and uplink. The average PRB usage will
2705  *     be reported to RRM based on confiured periodicity.
2706  *
2707  *           
2708  *  @param[in]  Pst   *pst
2709  *  @param[in]  SuId  suId
2710  *  @param[in]  SpId  spId
2711  *  @return  S16
2712  *      -# ROK 
2713  *      -# RFAILED 
2714  **/
2715 #ifdef ANSI
2716 PUBLIC S16 RgUiRgmCfgPrbRprt
2717 (
2718 Pst   *pst, 
2719 SpId  spId,
2720 RgmPrbRprtCfg   *prbRprtCfg
2721 )
2722 #else
2723 PUBLIC S16 RgUiRgmCfgPrbRprt(pst, spId, prbRprtCfg)
2724 Pst   *pst; 
2725 SpId  spId;
2726 RgmPrbRprtCfg   *prbRprtCfg;
2727 #endif
2728 {
2729 /* Initalize*/
2730    RgSchCellCb   *cell;
2731    RgSchPrbUsage *prbUsage;
2732    Inst          inst = (pst->dstInst  - SCH_INST_START);
2733
2734    TRC2(RgUiRgmCfgPrbRprt);
2735    cell = rgSchCb[inst].rgmSap[spId].cell;
2736    prbUsage = &cell->prbUsage;
2737    prbUsage->prbRprtEnabld = prbRprtCfg->bConfigType;
2738    prbUsage->rprtPeriod = prbRprtCfg->usPrbAvgPeriodicty;
2739    RG_SCH_ADD_TO_CRNT_TIME(cell->crntTime, prbUsage->startTime, 1);
2740
2741    /* clear the qciPrbRpts for all GBR QCIs */
2742    cmMemset((U8*)&prbUsage->qciPrbRpts[0], 0, 
2743              (RGM_MAX_QCI_REPORTS * sizeof(RgSchQciPrbUsage)));
2744
2745    RLOG_ARG2(L_DEBUG,DBG_CELLID,cell->cellId,
2746              "RgUiRgmCfgPrbRprt config type %d with the report period %d",
2747              prbUsage->prbRprtEnabld,prbUsage->rprtPeriod);
2748
2749    /* ccpu00134393 : mem leak fix */
2750       SPutSBuf(pst->region, pst->pool, (Data *)prbRprtCfg, sizeof(RgmPrbRprtCfg));
2751   
2752    RETVALUE(ROK);
2753 }
2754 /**
2755  * @brief ERROR INDICATION from PHY for the i failed unlicensed Scell transmission. 
2756  *
2757  * @details
2758  *
2759  *     Function : RgLiTfuErrInd
2760  *      
2761  *      This API is invoked by PHY to send ERROR INDICATION to scheduler 
2762  *      Currently invoked in the cases when the Unlicensed SCell transmission
2763  *      fails.
2764  *      This API contains the Cell and subframe information for which the
2765  *      transmission failed. 
2766  *           
2767  *  @param[in]  Pst                *pst
2768  *  @param[in]  SuId               suId 
2769  *  @param[in]  TfuErrIndInfo      *errIndInfo 
2770  *  @return  S16
2771  *      -# ROK 
2772  *      -# RFAILED 
2773  **/
2774 #ifdef ANSI
2775 PUBLIC S16 RgLiTfuErrInd
2776 (
2777 Pst                *pst, 
2778 SuId               suId, 
2779 TfuErrIndInfo       *errInd
2780 )
2781 #else
2782 PUBLIC S16 RgLiTfuErrInd(pst, suId, errInd)
2783 Pst                *pst; 
2784 SuId               suId; 
2785 TfuErrIndInfo       *errInd;
2786 #endif
2787 {
2788    S16   ret = ROK;
2789 #ifdef LTE_ADV
2790    Inst  inst = (pst->dstInst - SCH_INST_START);
2791 #endif
2792
2793    TRC3(RgLiTfuErrInd);
2794
2795 #ifndef NO_ERRCLS
2796    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2797    {
2798
2799       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"SAP Validation failed");
2800       RETVALUE(ret);
2801    }
2802
2803    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2804    {
2805       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"No cell exists");
2806       RETVALUE(RFAILED);
2807    }
2808 #endif
2809
2810 #ifdef LTE_ADV
2811    /* Now call the TOM (Tfu ownership module) primitive to process further */
2812    ret = rgSCHLaaErrInd(rgSchCb[inst].tfuSap[suId].cell, errInd);
2813 #endif
2814    RETVALUE(ret);
2815 }  /* RgLiTfuErrInd */
2816
2817
2818 \f
2819 /**********************************************************************
2820  
2821          End of file
2822 **********************************************************************/