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