Merge "[JIRA ID - ODUHIGH-275] Part -5 classifying of logs of sch folder"
[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 "rl_interface.h"
48 #include "rl_common.h"
49
50 /* header/extern include files (.x) */
51 #include "tfu.x"           /* TFU types */
52 #include "lrg.x"           /* layer management typedefs for MAC */
53 #include "rgr.x"           /* layer management typedefs for MAC */
54 #include "rgm.x"           /* layer management typedefs for MAC */
55 #include "rg_sch_inf.x"         /* typedefs for Scheduler */
56 #include "rg_sch.x"        /* typedefs for Scheduler */
57 #include "rg_sch_cmn.x"
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    if (SGetSBuf(cfmPst.region, cfmPst.pool, (Data **)&cfm, sizeof(RgMngmt))
117       != ROK)
118    {
119       DU_LOG("\nERROR  -->  SCH : Memory Unavailable for Confirmation");
120       SPutSBuf(pst->region, pst->pool, (Data *)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       /*      SPutSBuf(pst->region, pst->pool, (Data *)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    /*   SPutSBuf(pst->region, pst->pool, (Data *)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          SPutSBuf(pst->region, pst->pool, (Data *)cfgReqInfo,
593                                           (Size)sizeof(*cfgReqInfo));
594          rgSCHUtlRgrSiCfgCfm(instId, spId, transId, cfmStatus); 
595          return RFAILED;
596       }
597    }
598    else
599    {
600 #if (ERRCLASS & ERRCLS_ADD_RES)      
601       DU_LOG("\nERROR  -->  SCH : Invalid SAP Id:RgUiRgrSiCfgReq failed\n");
602 #endif
603       SPutSBuf(pst->region, pst->pool, (Data *)cfgReqInfo,
604                                    (Size)sizeof(*cfgReqInfo));
605       rgSCHUtlRgrSiCfgCfm(instId, spId, transId, cfmStatus); 
606       return RFAILED;
607    }
608
609    /* Handle configuration */
610 #ifdef EMTC_ENABLE
611 if(rgSchCb[instId].rgrSap[spId].cell->emtcEnable)
612 {
613    ret = rgSCHGomEmtcHndlSiCfg(pst->region, pst->pool,
614             &rgSchCb[instId], spId, transId, 
615                         cfgReqInfo);
616 }
617 else
618 {
619    ret = rgSCHGomHndlSiCfg(pst->region, pst->pool,
620             &rgSchCb[instId], spId, transId, 
621                         cfgReqInfo);
622 }
623  #else
624    ret = rgSCHGomHndlSiCfg(pst->region, pst->pool,
625             &rgSchCb[instId], spId, transId, 
626                         cfgReqInfo);
627  #endif
628    if (ret != ROK)
629    {
630       DU_LOG("\nERROR  -->  SCH : RgUiRgrSiCfgReq:"
631                    "Configuration Request Handling Failed");
632       return RFAILED;
633    }
634
635    return ROK;
636 }  /* RgUiRgrSiCfgReq */
637
638 \f
639 /**
640  * @brief API for Warning SI configuration request from RRM towards MAC. 
641  *
642  * @details
643  *
644  *     Function: RgUiRgrWarningSiCfgReq
645  *     
646  *     This API is invoked by RRM towards MAC to configure SI at MAC. 
647  *     These API validates the Pst, spId, suId and transfers the 
648  *     config request specific information to corresponding ownership 
649  *     module (GOM) API.
650  *
651  *           
652  *  @param[in]  Pst           *pst
653  *  @param[in]  SpId          spId
654  *  @param[in]  RgrCfgTransId transId
655  *  @param[in]  RgrWarningSiCfgReqInfo *warningSiCfgReqInfo
656  *  @return  S16
657  *      -# ROK 
658  *      -# RFAILED 
659  **/
660 S16 RgUiRgrWarningSiCfgReq(Pst *pst, SpId spId,RgrCfgTransId transId,RgrWarningSiCfgReqInfo *warningSiCfgReqInfo)
661 {
662    Inst     instId = pst->dstInst-SCH_INST_START;
663    S16      ret    = ROK;
664    uint8_t  cfmStatus = RGR_CFG_CFM_NOK;
665    uint8_t  prntTrans[RGR_CFG_TRANSID_SIZE+1];
666
667    memcpy(prntTrans, transId.trans, RGR_CFG_TRANSID_SIZE);
668    prntTrans[RGR_CFG_TRANSID_SIZE] = '\0';
669
670    if (warningSiCfgReqInfo == NULLP)
671    {
672       DU_LOG("\nERROR  -->  SCH : Input Message Buffer "
673                "is NULL");
674       rgSCHUtlRgrWarningSiCfgCfm(instId, spId, 0, transId, cfmStatus);
675       return RFAILED;
676    }
677
678    if (spId < rgSchCb[instId].numSaps)
679    {
680       if(LRG_BND != rgSchCb[instId].rgrSap[spId].sapSta.sapState)
681       {
682 #if (ERRCLASS & ERRCLS_ADD_RES)      
683          DU_LOG("\nERROR  -->  SCH : Invalid SAP State: warningSiCfgReqInfo failed\n");
684 #endif
685          rgSCHUtlFreeWarningSiSeg(pst->region, pst->pool, 
686                &warningSiCfgReqInfo->siPduLst);
687          SPutSBuf(pst->region, pst->pool, (Data *)warningSiCfgReqInfo,
688                sizeof(RgrWarningSiCfgReqInfo));
689          rgSCHUtlRgrWarningSiCfgCfm(instId, spId, warningSiCfgReqInfo->siId, 
690                transId, cfmStatus);
691          return RFAILED;
692       }
693    }
694    else
695    {
696 #if (ERRCLASS & ERRCLS_ADD_RES)      
697        DU_LOG("\nERROR  -->  SCH : Invalid SAP Id:warningSiCfgReqInfo failed\n");
698 #endif
699       rgSCHUtlFreeWarningSiSeg(pst->region, pst->pool, 
700             &warningSiCfgReqInfo->siPduLst);
701       SPutSBuf(pst->region, pst->pool, (Data *)warningSiCfgReqInfo,
702             sizeof(RgrWarningSiCfgReqInfo));
703       rgSCHUtlRgrWarningSiCfgCfm(instId, spId, warningSiCfgReqInfo->siId, 
704             transId, cfmStatus);
705       return RFAILED;
706    }
707
708    /* Handle configuration */
709 #ifdef EMTC_ENABLE
710 if(rgSchCb[instId].rgrSap[spId].cell->emtcEnable)
711 {
712    ret = rgSCHGomEmtcHndlWarningSiCfg(pst->region, pst->pool,
713          &rgSchCb[instId], spId, transId, warningSiCfgReqInfo);
714 }
715 else
716 {
717    ret = rgSCHGomHndlWarningSiCfg(pst->region, pst->pool,
718          &rgSchCb[instId], spId, transId, warningSiCfgReqInfo);
719 }
720 #else
721    ret = rgSCHGomHndlWarningSiCfg(pst->region, pst->pool,
722          &rgSchCb[instId], spId, transId, warningSiCfgReqInfo);
723 #endif
724    if(ret != ROK)
725    {
726       DU_LOG("\nERROR  -->  SCH : Configuration Request Handling Failed");
727       return RFAILED;
728    }
729
730    return ROK;
731 }
732
733 \f
734 /**
735  * @brief API for Warning SI Stop  request from RRM towards MAC. 
736  *
737  * @details
738  *
739  *     Function: RgUiRgrWarningSiStopReq
740  *     
741  *     This API is invoked by RRM towards MAC to Stop warning SI at MAC. 
742  *     These API validates the Pst, spId, suId and transfers the 
743  *     stop request specific information to corresponding ownership 
744  *     module (GOM) API.
745  *
746  *           
747  *  @param[in]  Pst           *pst
748  *  @param[in]  SpId          spId
749  *  @param[in]  RgrWarningSiCfgReqInfo *warningSiCfgReqInfo
750  *  @return  S16
751  *      -# ROK 
752  *      -# RFAILED 
753  **/
754 S16 RgUiRgrWarningSiStopReq(Pst *pst,SpId  spId,RgrCfgTransId transId,uint8_t siId)
755 {         
756    Inst         instId = pst->dstInst-SCH_INST_START;
757
758    if (spId < rgSchCb[instId].numSaps)
759    {
760       if(LRG_BND != rgSchCb[instId].rgrSap[spId].sapSta.sapState)
761       {
762 #if (ERRCLASS & ERRCLS_ADD_RES)      
763          DU_LOG("\nERROR  -->  SCH : Invalid SAP State: RgUiRgrWarningSiStopReq failed\n");
764 #endif
765          return RFAILED;
766       }
767    }
768    else
769    {
770 #if (ERRCLASS & ERRCLS_ADD_RES)      
771       DU_LOG("\nERROR  -->  SCH : Invalid SAP Id:RgUiRgrWarningSiStopReq failed\n");
772 #endif
773       return RFAILED;
774    }
775
776    rgSCHGomHndlWarningSiStopReq(pst->region, pst->pool,
777          &rgSchCb[instId], siId, transId, spId);
778
779    return ROK;
780 }
781 #endif /*RGR_SI_SCH */
782
783 /* LTE_ADV_FLAG_REMOVED_START */
784
785 /**
786  * @brief API for LOAD INF request from RRM towards MAC.
787  *
788  * @details
789  *
790  *     Function: RgUiRgrLoadInfReq
791  *
792  *     This API is invoked by RRM towards MAC to configure LOAD INF Parameters at MAC.
793  *     These API validates the Pst, spId, suId and transfers the
794  *     LOAD INF request to corresponding ownership
795  *     module (GOM) API.
796  *
797  *
798  *  @param[in]  Pst               *pst
799  *  @param[in]  SpId              spId
800  *  @param[in]  RgrCfgTransId     transId
801  *  @param[in]  RgrLoadInfReqInfo *loadInfReq
802  *  @return  S16
803  *      -# ROK
804  *      -# RFAILED
805  **/
806 S16 RgUiRgrLoadInfReq(Pst *pst, SpId spId, RgrCfgTransId  transId,RgrLoadInfReqInfo *loadInfReq)
807 {
808    S16       ret       = ROK;
809    uint8_t   prntTrans[RGR_CFG_TRANSID_SIZE+1];
810    Inst      instId = pst->dstInst-SCH_INST_START;
811
812    memcpy(prntTrans, transId.trans, RGR_CFG_TRANSID_SIZE);
813    prntTrans[RGR_CFG_TRANSID_SIZE] = '\0';
814
815
816    if (loadInfReq == NULLP)
817    {
818       DU_LOG("\nERROR  -->  SCH : Input Message Buffer "
819                "is NULL");
820       return RFAILED;
821    }
822
823    if (spId < rgSchCb[instId].numSaps)
824    {
825       if(LRG_BND != rgSchCb[instId].rgrSap[spId].sapSta.sapState)
826       {
827 #if (ERRCLASS & ERRCLS_ADD_RES)
828          DU_LOG("\nERROR  -->  SCH : Invalid SAP State: RgUiRgrLoadInfReq failed\n");
829 #endif
830          SPutSBuf(pst->region, pst->pool, (Data *)loadInfReq,
831                (Size)sizeof(*loadInfReq));
832          return RFAILED;
833       }
834    }
835    else
836    {
837 #if (ERRCLASS & ERRCLS_ADD_RES)
838       DU_LOG("\nERROR  -->  SCH : Invalid SAP Id:RgUiRgrLoadInfReq failed\n");
839 #endif
840       SPutSBuf(pst->region, pst->pool, (Data *)loadInfReq,
841             (Size)sizeof(*loadInfReq));
842       return RFAILED;
843    }
844
845    /* Handle configuration */
846    ret = rgSCHGomHndlLoadInf(pst->region, pst->pool,
847          &rgSchCb[(pst->dstInst - SCH_INST_START)], spId, transId, 
848          loadInfReq);
849    if (ret != ROK)
850    {
851       DU_LOG("\nERROR  -->  SCH : Configuration Request Handling Failed");
852       return RFAILED;
853    }
854
855    return ROK;
856 }  /* RgUiRgrLoadInfReq */
857 /* LTE_ADV_FLAG_REMOVED_END */
858
859 /************** MAC SCH Interface **************/ 
860 /**
861  * @brief Function for updating dedicated channel BO at scheduler from MAC.
862  *
863  * @details
864  *
865  *     Function : rgMacSchDedBoUpdtReq
866  *     
867  *     This function shall be invoked whenever MAC gets staRsp from RLC
868  *     Scheduler shall update BO in its dedicated logical channel control block.
869  *           
870  *  @param[in] Pst*           pst
871  *  @param[in] S16            cellSapId
872  *  @param[in] RgInfDedBoRpt  *boRpt
873  *  @return  S16
874  *      -# ROK 
875  **/
876 S16 RgMacSchDedBoUpdtReq(Pst*  pst,RgInfDedBoRpt  *boRpt)
877 {
878    RgSchCellCb   *cell;
879    RgSchUeCb     *ue;
880 #ifdef SCH_STATS
881    RgSchCmnDlUe  *dlUe;
882 #endif
883
884    Inst          inst = (pst->dstInst - SCH_INST_START);
885    S16           cellSapId = boRpt->cellSapId;
886 /*
887    DU_LOG("\nDEBUG  -->  SCH : rgMacSchDedBoUpdtReq():"
888             " boRpt->rnti = %u  boRpt->lcId = %u",boRpt->rnti, boRpt->lcId);
889 */
890    /* No need to chk for cell being NULL as MAC wouldn't have found instance if
891     * it doesnt exist */
892    cell = rgSchCb[inst].rgrSap[cellSapId].cell;
893
894 #ifndef NO_ERRCLS
895    if (cell->cellId != boRpt->cellId)
896    {
897       /* Handle Cell fetch failure */
898       DU_LOG("\nERROR  -->  SCH : rgMacSchDedBoUpdtReq(): Invalid cell Id");
899       return RFAILED;
900    }
901 #endif
902
903    /* Update Bo in the given logical channel of the UE */
904    if ((ue = rgSCHDbmGetUeCb(cell, boRpt->rnti)) != NULLP)
905    {
906       RgSchDlLcCb   *dlLc;
907       /* Honor BO Reports only from PCELL */
908 #ifdef LTE_ADV
909       if (cell != ue->cell)
910       {
911          return RFAILED;
912       }
913 #endif
914       if ((dlLc = rgSCHDbmGetDlDedLcCb(ue, boRpt->lcId)) != NULLP)
915       {
916 #ifdef LTE_L2_MEAS
917          if(dlLc->lcType == CM_LTE_LCH_DTCH)
918          {
919             if((dlLc->bo == 0) &&(boRpt->bo != 0))
920             {
921                /* UE is active */
922                if(!(ue->qciActiveLCs[dlLc->qciCb->qci]))
923                {
924                   dlLc->qciCb->dlUeCount++;
925                }
926                ue->qciActiveLCs[dlLc->qciCb->qci]++;
927             }
928             else if((dlLc->bo != 0) && (boRpt->bo == 0) && (dlLc->qciCb->dlUeCount))
929             {
930                /* UE is inactive */
931                if (ue->qciActiveLCs[dlLc->qciCb->qci])
932                {
933                   ue->qciActiveLCs[dlLc->qciCb->qci]--;
934                   if (!(ue->qciActiveLCs[dlLc->qciCb->qci]))
935                   {
936                      dlLc->qciCb->dlUeCount--;
937                   }
938                }
939             }
940         }
941 #endif
942 #ifdef SCH_STATS
943          dlUe = RG_SCH_CMN_GET_DL_UE(ue, cell);
944          if (boRpt->bo > dlLc->bo)
945          {
946             dlUe->boReported += (boRpt->bo - dlLc->bo);
947          }
948 #endif
949 #ifdef TENB_STATS
950          if (boRpt->bo > dlLc->bo)
951          {
952             ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(cell)].dlBo += ((boRpt->bo - dlLc->bo)<<3);
953          }
954 #endif
955          /* RLC provides cumulative BO for each LC.
956           * Reduce the left out unscheduled bo from total bo and 
957           * update the new BO to the total bo */
958          if(ue->totalBo >= dlLc->bo)
959          {
960             ue->totalBo -= dlLc->bo;
961          }
962          else
963          {
964             ue->totalBo = 0; /* this case should not arise
965                              * Resetting for safety */
966          }
967
968          ue->totalBo +=  boRpt->bo;
969          dlLc->bo = boRpt->bo;
970          dlLc->oldestSduArrTime = boRpt->oldestSduArrTime;
971          dlLc->staPduBo = boRpt->staPduBo;
972          
973          dlLc->setMaxUlPrio = boRpt->setMaxUlPrio;
974          dlLc->setMaxDlPrio = boRpt->setMaxDlPrio;
975          /* Update the scheduler */
976          rgSCHUtlDlDedBoUpd(cell, ue, dlLc);
977          return ROK;
978       }
979    }
980    return RFAILED;
981
982 } /* end of rgMacSchDedBoUpdtReq */
983
984
985 /**
986  * @brief Function for updating common channel BO at scheduler from MAC.
987  *
988  * @details
989  *
990  *     Function : RgMacSchCmnBoUpdtReq
991  *     
992  *     This function shall be invoked whenever MAC gets staRsp from RLC
993  *     Scheduler shall update BO in its common logical channel control block.
994  *           
995  *  @param[in] Pst*            pst
996  *  @param[in] S16             cellSapId
997  *  @param[in] RgInfCmnBoRpt  *boRpt
998  *  @return  S16
999  *      -# ROK 
1000  **/
1001 S16 RgMacSchCmnBoUpdtReq(Pst* pst,RgInfCmnBoRpt  *boRpt)
1002 {
1003    RgSchCellCb   *cell;
1004    Inst          inst = (pst->dstInst - SCH_INST_START);
1005    S16           cellSapId = boRpt->cellSapId;
1006
1007
1008    /* No need to chk for cell being NULL as MAC would not have found instance if
1009     * it doesnt exist */
1010    cell = rgSchCb[inst].rgrSap[cellSapId].cell;
1011    if (cell->cellId != boRpt->cellId)
1012    {
1013       DU_LOG("\nERROR  -->  SCH : RgMacSchCmnBoUpdtReq():"
1014                "Invalid boRpt cell Id:%d",boRpt->cellId);
1015       return RFAILED;
1016    }
1017
1018    /* handle status response on CCCH */
1019    if(boRpt->lcId == cell->dlCcchId)
1020    {
1021       DU_LOG("\nDEBUG  -->  SCH : RgMacSchCmnBoUpdtReq():"
1022                " BO update for CCCH");
1023       rgSCHUtlHndlCcchBoUpdt(cell, boRpt); 
1024    }
1025    else
1026    {
1027       rgSCHUtlHndlBcchPcchBoUpdt(cell, boRpt); 
1028    }
1029    
1030    return ROK;
1031 } /* end of RgMacSchCmnBoUpdtReq */
1032 /*Fix: start: Inform UE delete to scheduler*/
1033 /**
1034  * @brief This API is used to send data indication to Scheduler instance from MAC.
1035  *
1036  * @details
1037  *
1038  *     Function : rgMacSchUeDelInd
1039  *     
1040  *     This function shall be invoked whenever MAC gets Ue delete request. 
1041  *      
1042  *           
1043  *  @param[in] Pst*            pst
1044  *  @param[in] RgInfUeDelInd   *ueDelInd
1045  *  @return  S16
1046  *      -# ROK 
1047  **/
1048 S16 RgMacSchUeDelInd(Pst* pst,RgInfUeDelInd *ueDelInd)
1049 {
1050    RgSchCellCb       *cell;
1051    Inst              inst = (pst->dstInst - SCH_INST_START);
1052    S16               cellSapId = ueDelInd->cellSapId;
1053    CmLList           *tmp;
1054    RgSchRntiLnk      *rntiLnk=NULL;
1055    
1056    if (rgSchCb[inst].rgrSap == NULLP || rgSchCb[inst].rgrSap[cellSapId].cell == NULLP)
1057    {
1058       DU_LOG("\nERROR  -->  SCH : rgrSap or cell is not configured");
1059       return ROK;
1060    }
1061    cell = rgSchCb[inst].rgrSap[cellSapId].cell;
1062 #ifndef NO_ERRCLS
1063    if (cell->cellId != ueDelInd->cellId)
1064    {
1065       /* Handle Cell fetch failure */
1066       DU_LOG("\nERROR  -->  SCH : rgMacSchUeDelInd(): Invalid ueDelInd cell Id:%d",
1067                          ueDelInd->cellId);
1068       return ROK;
1069    }
1070 #endif
1071       
1072    CM_LLIST_FIRST_NODE(&cell->rntiDb.rntiGuardPool, tmp);
1073
1074    while(tmp)
1075    {
1076       rntiLnk = (RgSchRntiLnk *)(tmp->node);
1077       if(rntiLnk->rnti == ueDelInd->rnti)
1078       {
1079          cmLListDelFrm(&cell->rntiDb.rntiGuardPool, tmp);
1080          tmp->node = NULLP;
1081          rgSCHDbmRlsRnti(cell, rntiLnk);
1082          DU_LOG("\nDEBUG  -->  SCH : RNTI:%d Released from the Guard pool(%d)",
1083                   ueDelInd->rnti, cell->rntiDb.rntiGuardPool.count);
1084          
1085          break;
1086       }
1087       CM_LLIST_NEXT_NODE(&cell->rntiDb.rntiGuardPool, tmp);
1088    }
1089
1090 #ifdef EMTC_ENABLE
1091  rgEmtcMacSchUeDelInd(cell,ueDelInd);  
1092 #endif
1093
1094    if(tmp == NULLP)
1095    {
1096       /* Fix : syed HO UE does not have a valid ue->rntiLnk */
1097       DU_LOG("\nINFO  -->  SCH : HO CRNTI:%d not present in the"
1098            "Guard Pool:%d", ueDelInd->rnti, cell->rntiDb.rntiGuardPool.count);
1099    } 
1100    
1101    return ROK;
1102 }  /* rgMacSchUeDelInd */
1103 /*Fix: end: Inform UE delete to scheduler*/
1104 /**
1105  * @brief This API is used to send data indication to Scheduler instance from MAC.
1106  *
1107  * @details
1108  *
1109  *     Function : rgMacSchSfRecpInd
1110  *     
1111  *     This function shall be invoked whenever MAC gets datInd on TFU
1112  *     Scheduler shall act on the CEs and data that are received as part of
1113  *     datInd.
1114  *           
1115  *  @param[in] Pst*            pst
1116  *  @param[in] S16             cellSapId
1117  *  @param[in] CmLteRnti       rnti
1118  *  @param[in] DatIndInfo      *datInd
1119  *  @return  S16
1120  *      -# ROK 
1121  **/
1122 S16 RgMacSchSfRecpInd(Pst*  pst,RgInfSfDatInd *subfrmInfo)
1123 {
1124    S16               ret = RFAILED;
1125    RgSchErrInfo      err;
1126    RgSchUeCb         *ue;
1127    RgInfUeDatInd     *datInd;
1128    RgSchCellCb       *cell;
1129    Inst              inst = (pst->dstInst - SCH_INST_START);
1130    CmLteRnti         rnti;
1131    CmLListCp         *lnkLst;
1132    CmLList           *tmp;
1133    S16               cellSapId = subfrmInfo->cellSapId;
1134    RgrUeStaIndInfo   *ueStaInd;
1135 #ifdef RG_UNUSED
1136 //#ifdef LTEMAC_SPS
1137    RgSchCmnUlUeSpsInfo   *ulSpsUe ;
1138 #endif
1139    /* RRM_RBC_X */
1140    uint32_t                   idx;
1141    /* RRM_RBC_Y */
1142    
1143 #ifdef LTE_L2_MEAS
1144    uint8_t               qci;
1145    uint16_t              datIndActQci = 0;
1146    uint16_t              combDatIndActQci = 0; /* Prev and Latest Dat Ind combined */
1147    uint16_t              tempUeActQci = 0; /* UE specific Active QCIs */
1148    uint16_t              diffBits = 0;
1149    uint8_t               lcCount;
1150 #endif
1151
1152    /* No need to chk for cell being NULL as MAC wouldn't have found instance if
1153     * it doesnt exist */
1154    cell = rgSchCb[inst].rgrSap[cellSapId].cell;
1155
1156    /* lnkLst assignment */
1157    lnkLst = &(subfrmInfo->ueLst);
1158
1159    CM_LLIST_FIRST_NODE(lnkLst, tmp);
1160
1161    while((NULLP != tmp) && ((RgInfUeDatInd *)tmp->node != NULLP))
1162    {
1163       ue = NULLP;
1164 #ifdef LTE_L2_MEAS
1165       qci = 0;
1166 #endif
1167       datInd   = (RgInfUeDatInd *)tmp->node;
1168       rnti     = datInd->rnti;
1169
1170       /* We shall try and find
1171        * out the RaCb based on the following - 
1172        * 1. If the incoming PDU contained a CCCH SDU i.e. this is message 3.
1173        * 2. If the incoming PDU contained a CRNTI control element, i.e. we should
1174        * have a ueCb also for this 
1175        */
1176       
1177       /* It could be that a non-msg3 pdu contains a CRNTI Control element. We
1178        * should check for CRNTI CE and if it exists the UECb must exist, also an
1179        * if the CRNTI in the CE and the one with which the message came in are
1180        * different we shall look for an raCb as well. 
1181        */
1182       if (datInd->ceInfo.bitMask & RGSCH_CRNTI_CE_PRSNT)
1183       {
1184          /* SR_RACH_STATS : CRNTI CE*/
1185          rgNumMsg3CrntiCE++;
1186
1187          if (datInd->ceInfo.bitMask & RGSCH_CCCH_SDU_PRSNT)
1188          {
1189             RGSCH_FREE_MEM(subfrmInfo);
1190             err.errType = RGSCHERR_TOM_DATIND;
1191             DU_LOG("\nDEBUG  -->  SCH : Received MSG3 with CRNTI:%d and also CCCH ", 
1192                      datInd->ceInfo.ces.cRnti);
1193             return RFAILED;
1194          }
1195          ue = rgSCHDbmGetUeCb (cell, datInd->ceInfo.ces.cRnti);
1196          if (ue == NULLP)
1197          {
1198             /* SR_RACH_STATS : CRNTI CE UECB NOT FOUND*/
1199             rgNumCrntiCeCrntiNotFound++;
1200             /* ccpu00141318 - Removed condition for SPS rnti checking*/
1201             RGSCH_FREE_MEM(subfrmInfo);
1202             err.errType = RGSCHERR_TOM_DATIND;
1203             DU_LOG("\nERROR  -->  SCH : Received MSG3 "
1204                      "with CRNTI:%d unable to find ueCb", 
1205                      datInd->ceInfo.ces.cRnti);
1206             return RFAILED;
1207          }
1208
1209          if ((ret = rgSCHUtlProcMsg3 (subfrmInfo, cell, ue, 
1210                rnti, datInd, &err)) != ROK)
1211          { 
1212             RGSCH_FREE_MEM(subfrmInfo);
1213             err.errType = RGSCHERR_TOM_DATIND;
1214             DU_LOG("\nERROR  -->  SCH : Processing for MSG3 failed for CRNTI:%d", 
1215                      datInd->rnti);
1216             return RFAILED;
1217          }
1218          
1219 #ifdef LTEMAC_SPS
1220          rgSCHUtlHdlCrntiCE (cell, ue);
1221 #endif
1222          ret = rgSCHUtlAllocSBuf (cell->instIdx,(Data**)&ueStaInd,
1223                                   sizeof(RgrUeStaIndInfo));
1224          if(ret == ROK)
1225          {
1226             ueStaInd->status = RGR_UESTA_MAC_CRNTI_CE_RECVD;
1227 #ifdef RG_UNUSED
1228 //#ifdef LTEMAC_SPS
1229             ulSpsUe = RG_SCH_CMN_GET_UL_SPS_UE(ue);
1230             if(ulSpsUe->isUlSpsActv)
1231             {
1232                ueStaInd->status = RGR_UESTA_MAC_CRNTI_CE_RECVD_IN_SPS_ACTIVE;
1233                ue->ul.ulSpsCfg.isLcSRMaskEnab = FALSE;
1234             }
1235 #endif
1236             ret = rgSCHUtlFillSndUeStaInd(cell, ue, ueStaInd);
1237             if(ret != ROK)
1238             {
1239                DU_LOG("\nERROR  -->  SCH : Could not Send Ue Sta Ind UEID:%d",ue->ueId);
1240             }
1241          }
1242          CM_LLIST_NEXT_NODE(lnkLst, tmp);
1243          continue;
1244       } /* end of CRNTI based message */
1245       else if (datInd->ceInfo.bitMask & RGSCH_CCCH_SDU_PRSNT)
1246       {
1247          /* SR_RACH_STATS : CCCH SDU */
1248          rgNumMsg3CCCHSdu++;
1249          /* SR_RACH_STATS : CCCH SDU RACB NOT FOUND*/
1250          if (NULLP == rgSCHDbmGetRaCb (cell, rnti))
1251          {
1252             rgNumCCCHSduCrntiNotFound++;
1253          }
1254
1255          if ((ret = rgSCHUtlProcMsg3 (subfrmInfo, cell, ue, 
1256                rnti, datInd, &err)) != ROK)
1257          { 
1258             RGSCH_FREE_MEM(subfrmInfo);
1259             err.errType = RGSCHERR_TOM_DATIND;
1260             DU_LOG("\nERROR  -->  SCH : Processing for MSG3 failed for CRNTI:%d", 
1261                      datInd->rnti);
1262             return RFAILED;
1263          }
1264          /* fix */
1265           CM_LLIST_NEXT_NODE(lnkLst, tmp);
1266           continue;
1267       } /* end of Msg3 processing */
1268
1269       if (ue == NULLP)
1270       {
1271          ue = rgSCHDbmGetUeCb (cell, datInd->rnti);
1272          if (ue == NULLP)
1273          {
1274 #ifdef LTEMAC_SPS 
1275          if((ue = rgSCHDbmGetSpsUeCb (cell, datInd->rnti)) == NULLP)
1276 #endif
1277             {
1278                RGSCH_FREE_MEM(subfrmInfo);
1279                err.errType = RGSCHERR_TOM_DATIND;
1280                DU_LOG("\nERROR  -->  SCH : Unable to get the UE CB for CRNTI:%d", 
1281                datInd->rnti);
1282                return RFAILED;
1283             }
1284          }
1285       }
1286 /* L2_COUNTERS */
1287 #ifdef LTE_L2_MEAS
1288       /* The LCs for which data is received at MAC is provided to SCH.
1289          This information is used to estimate the Active LCs at UE
1290          since estimates based on only BSR is not accurate */
1291       if (datInd->ceInfo.bitMask & RGSCH_ACTIVE_LC_PRSNT)
1292       {
1293       
1294         /* Compose a Bitmask with for the QCI's for which Data
1295            is received */
1296         for (lcCount = 0; lcCount < RGINF_MAX_NUM_DED_LC; lcCount++)
1297         {
1298            if ((datInd->ceInfo.ulActLCs[lcCount] == TRUE) && (TRUE == ue->ul.lcCb[lcCount].isValid))
1299            {
1300               datIndActQci |= (1 << (ue->ul.lcCb[lcCount].qciCb->qci -1));
1301            }
1302         }
1303         if (ue->ulActiveLCs && ue->lastDatIndLCs)
1304         {
1305            /* Combine previous Dat Ind and current Dat Ind to
1306               estimate active LCs at UE */
1307            combDatIndActQci = ue->lastDatIndLCs | datIndActQci;
1308            tempUeActQci = ue->ulActiveLCs;
1309            ue->ulActiveLCs = combDatIndActQci;
1310            diffBits = combDatIndActQci ^ tempUeActQci;
1311            while (diffBits)
1312            {
1313               qci++;
1314               if (0x1 & diffBits)
1315               {
1316                  if (0x1 & tempUeActQci)
1317                  {
1318                     /* An active QCI has become inactive */
1319                     cell->qciArray[qci].ulUeCount--;
1320                  }
1321                  else
1322                  {
1323                     /* An Inactive QCI has become active */
1324                     cell->qciArray[qci].ulUeCount++;
1325                  }
1326               }
1327               diffBits >>= 1;
1328               tempUeActQci >>= 1;
1329            }
1330         }
1331         ue->lastDatIndLCs = datIndActQci;
1332       
1333       }
1334
1335 #endif /* LTE_L2_MEAS */
1336       /* Just copy the timing information from the dat indication into the one
1337        * stored in the UE CB, will be later utilized to handle Timing advance 
1338        */
1339
1340       if ((ret = rgSCHUtlUpdSch (subfrmInfo, cell, ue, datInd, &err)) != ROK)
1341       {
1342          RGSCH_FREE_MEM(subfrmInfo);
1343          err.errType = RGSCHERR_TOM_DATIND;
1344          DU_LOG("\nERROR  -->  SCH : Unable to handle Data"
1345                    " Indication for UEID:%d",ue->ueId);
1346          return RFAILED;
1347       }
1348
1349       CM_LLIST_NEXT_NODE(lnkLst, tmp);
1350    }
1351    /* RRM_RBC_X */
1352    /* update the UL PRB usage for all GBR QCIs*/
1353    for (idx = 0; idx < RGM_MAX_QCI_REPORTS; idx++)
1354    {
1355       cell->prbUsage.qciPrbRpts[idx].ulTotPrbUsed += subfrmInfo->qcisUlPrbCnt[idx];
1356    }
1357    /* RRM_RBC_Y */
1358
1359    /* chk if Sch needs to dealloc datInd after unpk */
1360    RGSCH_FREE_MEM(subfrmInfo);
1361    return (ret);
1362 }  /* rgMacSchSfRecpInd */
1363
1364 #ifdef LTEMAC_SPS
1365 /**
1366  * @brief Function to handle relInd from MAC for a UE
1367  *
1368  * @details
1369  *
1370  *     Function: RgMacSchSpsRelInd
1371  *
1372  *     Handler for processing relInd for UL SPS of a UE
1373  *
1374  *     Invoked by: 
1375  *         MAC
1376  *
1377  *     Processing Steps:
1378  *           
1379  *  @param[in] Pst               *pst
1380  *  @param[in] RgInfSpsRelInfo   *relInfo
1381  *  @return  S16
1382  *      -# ROK 
1383  *      -# RFAILED 
1384  **/
1385 S16 RgMacSchSpsRelInd(Pst *pst,RgInfSpsRelInfo *relInfo)
1386 {
1387    RgSchUeCb       *ue;
1388    RgSchCellCb     *cell;
1389    Inst            inst = (pst->dstInst - SCH_INST_START);
1390
1391
1392    /* No need to chk for cell being NULL as MAC wouldn't have found instance if
1393     * it doesnt exist */
1394    cell = rgSchCb[inst].rgrSap[relInfo->cellSapId].cell;
1395
1396    if ((ue = rgSCHDbmGetUeCb(cell, relInfo->cRnti)) == NULLP)
1397    {
1398       DU_LOG("\nERROR  -->  SCH : No Ue exists with CRNTI:%d",relInfo->cRnti);
1399       return RFAILED;
1400    }
1401
1402    if ((rgSCHUtlSpsRelInd(cell, ue, relInfo->isExplRel)) != ROK)
1403    {
1404       DU_LOG("\nERROR  -->  SCH : RelInd processing for CRNTI:%d failed",relInfo->cRnti);
1405       return RFAILED;
1406    }
1407    return ROK;
1408 } /* end of RgMacSchSpsRelInd */
1409 #endif /* LTEMAC_SPS */
1410
1411 #ifdef LTE_L2_MEAS
1412
1413 /**
1414  * @brief Function to handle L2MeasCfm from MAC
1415  *
1416  * @details
1417  *
1418  *     Function: RgMacSchL2MeasCfm
1419  *
1420  *     Handler for processing L2 measurement confirm 
1421  *
1422  *     Invoked by: 
1423  *         MAC
1424  *
1425  *     Processing Steps:
1426  *           
1427  *  @param[in] Pst               *pst
1428  *  @param[in] RgInfL2MeasCfm    *measCfm
1429  *  @return  S16
1430  *      -# ROK 
1431  *      -# RFAILED 
1432  **/
1433 S16 RgMacSchL2MeasCfm(Pst *pst, RgInfL2MeasCfm *measCfm)
1434 {
1435    RgSchCellCb       *cell = NULLP;
1436    Inst              inst = (pst->dstInst - SCH_INST_START);
1437    CmLList           *lnk;
1438    RgSchL2MeasCb     *measCb = NULLP;
1439    RgSchCb           *instCb =  &rgSchCb[inst];
1440    uint32_t          idx;
1441    LrgSchMeasCfmInfo schMeasCfm;
1442    uint8_t           qciVal;
1443    uint8_t           idx1; /*LTE_L2_MEAS_PHASE2*/ 
1444    uint8_t           qciVal1;
1445
1446    /* Find the cellCb using cellId in measInfo. Iterate through all cells
1447     * in rgrsapCb in RgschCb */
1448    for (idx = 0; idx < instCb->numSaps; idx++)
1449    {
1450       if ( instCb->rgrSap[idx].cell->cellId == measCfm->cellId)
1451       {
1452          /* got the cell break the loop */
1453          cell = instCb->rgrSap[idx].cell;
1454          break;
1455       }
1456    }
1457    /* If no cellCb return Err with Invalid Cell Id */
1458    if (cell == NULLP)
1459    {
1460       DU_LOG("\nERROR  -->  SCH : Meas Cfm Failed.Invalid Cell Id");
1461       return RFAILED;
1462    }
1463    
1464
1465    /* Iterate through all meas requests in l2mList in cellCb */
1466    lnk = cell->l2mList.first;
1467    while(lnk != NULLP)
1468    {
1469       /* Get the MeasCb : RgSchL2MeasCb */
1470       measCb = (RgSchL2MeasCb *)lnk->node;
1471       lnk = lnk->next;
1472       if (measCb->measReq.hdr.transId == measCfm->transId)
1473       {
1474          break;
1475       }
1476    }
1477    if ( measCb == NULLP )
1478    {
1479       return ( RFAILED );
1480    }
1481
1482
1483    if(measCfm->cfm.status != LCM_PRIM_OK)
1484    {
1485       for (idx = 0; idx < measCb->measReq.avgPrbQciUl.numQci; idx++)
1486       {
1487         qciVal = measCb->measReq.avgPrbQciUl.qci[idx];
1488         cell->qciArray[qciVal].qci = 0;
1489       }
1490       /* Delete this measCb, send the negative confirmation to
1491        * stack manager */
1492       cmLListDelFrm(&cell->l2mList, &measCb->measLnk);
1493       /* ccpu00117052 - MOD - Passing double pointer
1494          for proper NULLP assignment*/
1495       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&measCb, sizeof(RgSchL2MeasCb));
1496       memset(&schMeasCfm, 0, sizeof(LrgSchMeasCfmInfo));
1497       schMeasCfm.measType     = measCfm->measType;
1498       schMeasCfm.cfm          = measCfm->cfm;
1499       schMeasCfm.hdr.transId  = measCfm->transId;
1500       schMeasCfm.cellId       = measCfm->cellId;
1501       RgMiLrgSchL2MeasCfm(&(instCb->rgSchInit.lmPst), &schMeasCfm);
1502       return ROK;
1503    }
1504    for(idx = 0; idx < measCfm->u.prbCfm.numQci; idx++)
1505    {
1506       measCb->avgPrbQciUl.prbUsage[idx].prbUsage = measCfm->u.prbCfm.prbUsage[idx].prbUsage;
1507       measCb->avgPrbQciUl.prbUsage[idx].qciValue = measCfm->u.prbCfm.prbUsage[idx].qciValue;
1508       /*LTE_L2_MEAS_PHASE2*/
1509       qciVal1 = measCfm->u.prbCfm.prbUsage[idx].qciValue;
1510       for(idx1=0;idx1<measCb->measReq.avgPrbQciUl.numQci;idx1++)
1511       {
1512          if(measCb->measReq.avgPrbQciUl.qci[idx1] == qciVal1)
1513          {
1514             break;
1515          }
1516       }
1517       if(idx1 == measCb->measReq.avgPrbQciUl.numQci)
1518       {
1519          measCb->measReq.avgPrbQciUl.qci[measCb->measReq.avgPrbQciUl.numQci++] = qciVal1;
1520       }
1521    }
1522    measCb->avgPrbQciUl.numQci = measCfm->u.prbCfm.numQci;
1523    measCb->cfmRcvd = TRUE;
1524    cell->sndL2Meas = TRUE;
1525    return ROK;
1526 } /* end of RgMacSchL2MeasCfm */
1527
1528 /**
1529  * @brief Function to handle L2MeasStopCfm from MAC
1530  *
1531  * @details
1532  *
1533  *     Function: RgMacSchL2MeasStopCfm
1534  *
1535  *     Handler for processing L2 measurement confirm 
1536  *
1537  *     Invoked by: 
1538  *         MAC
1539  *
1540  *     Processing Steps:
1541  *           
1542  *  @param[in] Pst               *pst
1543  *  @param[in] RgInfL2MeasCfm    *measCfm
1544  *  @return  S16
1545  *      -# ROK 
1546  *      -# RFAILED 
1547  **/
1548 S16 RgMacSchL2MeasStopCfm(Pst *pst,RgInfL2MeasCfm  *measCfm)
1549 {
1550    LrgSchMeasCfmInfo schMeasCfm;
1551    Inst              inst = (pst->dstInst - SCH_INST_START);
1552    RgSchCb           *instCb =  &rgSchCb[inst];
1553
1554    memset(&schMeasCfm, 0, sizeof(LrgSchMeasCfmInfo));
1555    schMeasCfm.measType     = measCfm->measType;
1556    schMeasCfm.cfm          = measCfm->cfm;
1557    schMeasCfm.hdr.transId  = measCfm->transId;
1558    schMeasCfm.cellId       = measCfm->cellId;
1559    RgMiLrgSchL2MeasStopCfm(&(instCb->rgSchInit.lmPst), &schMeasCfm);
1560    return ROK;
1561 }
1562 #endif
1563
1564 /************** TFU Interface *************/
1565
1566 /**
1567  * @brief Bind confirm API for TFU SAP on scheduler instance. 
1568  *
1569  * @details
1570  *
1571  *     Function : RgLiTfuSchBndCfm
1572  *      
1573  *      This API is invoked by PHY to confirm TFU SAP bind. 
1574  *     
1575  *           
1576  *  @param[in]  Pst   *pst 
1577  *  @param[in]  SuId  suId 
1578  *  @param[in]  uint8_t    status
1579  *  @return  S16
1580  *      -# ROK 
1581  *      -# RFAILED 
1582  **/
1583 S16 RgLiTfuSchBndCfm (Pst *pst,SuId suId, uint8_t status)
1584 {
1585    S16 ret;
1586    RgSchLowSapCb  *tfuSap;
1587    Inst  instId = pst->dstInst - SCH_INST_START;
1588
1589    if(suId >= rgSchCb[instId].numSaps)
1590    {
1591       DU_LOG("\nERROR  -->  SCH : Incorrect SuId");
1592       return RFAILED;
1593    }
1594    /* Lets validate suId first */
1595    tfuSap = &(rgSchCb[instId].tfuSap[suId]);
1596
1597    if (suId != tfuSap->sapCfg.suId)
1598    {
1599       DU_LOG("\nERROR  -->  SCH : Incorrect SuId. Configured (%d)"
1600             "Recieved (%d)", tfuSap->sapCfg.suId, suId);
1601       return RFAILED;
1602    }
1603    ret = rgSCHLmmBndCfm (pst, suId, status);
1604    return (ret);
1605 }  /* RgLiTfuSchBndCfm */
1606
1607 /**
1608  * @brief Random Access Request indication from PHY.
1609  *
1610  * @details
1611  *
1612  *     Function : RgLiTfuRaReqInd
1613  *      
1614  *      This API is invoked by PHY to send Random Access Request to Scheduler.
1615  *      This API contains information for Random Access Request including 
1616  *      raRnti, list of associated RAPIDs and related information.
1617  *           
1618  *  @param[in]  Pst              *pst 
1619  *  @param[in]  SuId             suId 
1620  *  @param[in]  TfuRaReqIndInfo  *raReqInd
1621  *  @return  S16
1622  *      -# ROK 
1623  *      -# RFAILED 
1624  **/
1625 S16 RgLiTfuRaReqInd(Pst *pst,SuId suId, TfuRaReqIndInfo *raReqInd)
1626 {
1627    S16   ret;
1628    Inst  inst = pst->dstInst-SCH_INST_START;
1629
1630    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1631    {
1632       DU_LOG("\nERROR  -->  SCH : SAP Validation failed SuId(%d)", suId);
1633       /* Free up the memory for the request structure */
1634       RGSCH_FREE_MEM(raReqInd);
1635       return (ret);
1636    }
1637
1638    if(raReqInd == NULLP)
1639    {
1640       DU_LOG("\nERROR  -->  SCH : Invalid input pointer for raReqInd Failed");
1641       return RFAILED;
1642    }
1643
1644    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1645    {
1646       DU_LOG("\nERROR  -->  SCH : No cell exists");
1647       return RFAILED;
1648    }
1649
1650    ret = rgSCHTomRaReqInd(rgSchCb[inst].tfuSap[suId].cell, raReqInd);
1651    /* Free up the memory for the request structure */
1652    RGSCH_FREE_MEM(raReqInd);
1653    /*SPutSBuf (pst->region, pst->pool, (Data *)raReqInd,
1654          sizeof(TfuRaReqIndInfo)); */
1655    return (ret);
1656 }  /* RgLiTfuRaReqInd */
1657
1658 /**
1659  * @brief Uplink CQI indication from PHY.
1660  *
1661  * @details
1662  *
1663  *     Function : RgLiTfuUlCqiInd
1664  *      
1665  *      This API is invoked by PHY to send Uplink CQI to Scheduler.
1666  *      This API contains Uplink CQI information reported per UE.
1667  *           
1668  *  @param[in]  Pst               *pst 
1669  *  @param[in]  SuId              suId 
1670  *  @param[in]  TfuUlCqiIndInfo   *ulCqiInd
1671  *  @return  S16
1672  *      -# ROK 
1673  *      -# RFAILED 
1674  **/
1675 S16 RgLiTfuUlCqiInd(Pst *pst, SuId suId, TfuUlCqiIndInfo *ulCqiInd)
1676 {
1677    S16   ret;
1678    Inst  inst = pst->dstInst-SCH_INST_START;
1679
1680    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1681    {
1682       DU_LOG("\nERROR  -->  SCH : SAP Validation failed");
1683       /* Free up the memory for the request structure */
1684       RGSCH_FREE_MEM(ulCqiInd);
1685       return (ret);
1686    }
1687
1688    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1689    {
1690       DU_LOG("\nERROR  -->  SCH : No cell exists");
1691       /* Free up the memory for the request structure */
1692       RGSCH_FREE_MEM(ulCqiInd);
1693       return RFAILED;
1694    }
1695    ret = rgSCHTomUlCqiInd (rgSchCb[inst].tfuSap[suId].cell, ulCqiInd);
1696    /* Free up the memory for the request structure */
1697    RGSCH_FREE_MEM(ulCqiInd);
1698    return (ret);
1699 }  /* RgLiTfuUlCqiInd */
1700
1701 /**
1702  * @brief PUCCH power adjustment indication.
1703  *
1704  * @details
1705  *
1706  *     Function : RgLiTfuPucchDeltaPwrInd
1707  *
1708  *      This API is invoked by PHY to send PUCCH power adjustment
1709  *      indication.
1710  *
1711  *  @param[in]  Pst                     *pst 
1712  *  @param[in]  SuId                    suId 
1713  *  @param[in]  TfuPucchDeltaPwrIndInfo *pucchDeltaPwr
1714  *  @return  S16
1715  *      -# ROK 
1716  *      -# RFAILED 
1717  **/
1718 S16 RgLiTfuPucchDeltaPwrInd(Pst *pst,SuId suId,TfuPucchDeltaPwrIndInfo *pucchDeltaPwr)
1719 {
1720    S16   ret;
1721    Inst  inst = pst->dstInst-SCH_INST_START;
1722
1723    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1724    {
1725       DU_LOG("\nERROR  -->  SCH : SAP Validation failed");
1726       /* Free up the memory for the request structure */
1727       RGSCH_FREE_MEM(pucchDeltaPwr);
1728       return (ret);
1729    }
1730
1731    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1732    {
1733       DU_LOG("\nERROR  -->  SCH : No cell exists");
1734       return RFAILED;
1735    }
1736    ret = rgSCHTomPucchDeltaPwrInd (rgSchCb[inst].tfuSap[suId].cell, pucchDeltaPwr);
1737    /* Free up the memory for the request structure */
1738    RGSCH_FREE_MEM(pucchDeltaPwr);
1739    return (ret);
1740 }  /* RgLiTfuPucchDeltaPwrInd */
1741
1742
1743 /**
1744  * @brief HARQ ACK indication from PHY for Downlink transmissions.
1745  *
1746  * @details
1747  *
1748  *     Function : RgLiTfuHqInd
1749  *      
1750  *      This API is invoked by PHY to send HARQ ACK information to Scheduler
1751  *      on recieving HARQ ACK/NACK from UEs.
1752  *      This API contains HARQ ACK information recieved by PHY for downlink
1753  *      transmissions.
1754  *           
1755  *  @param[in]  Pst                *pst
1756  *  @param[in]  SuId               suId 
1757  *  @param[in]  TfuHqIndInfo       *harqAckInd
1758  *  @return  S16
1759  *      -# ROK 
1760  *      -# RFAILED 
1761  **/
1762 S16 RgLiTfuHqInd(Pst *pst, SuId suId, TfuHqIndInfo *harqAckInd)
1763 {
1764    S16   ret;
1765    Inst  inst = (pst->dstInst - SCH_INST_START);
1766
1767
1768 #ifndef NO_ERRCLS
1769    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1770    {
1771       DU_LOG("\nERROR  -->  SCH : SAP Validation failed");
1772       RGSCH_FREE_MEM(harqAckInd);
1773       return (ret);
1774    }
1775
1776    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1777    {
1778       DU_LOG("\nERROR  -->  SCH : No cell exists");
1779       return RFAILED;
1780    }
1781 #endif
1782
1783    /* Now call the TOM (Tfu ownership module) primitive to process further */
1784    ret = rgSCHTomHarqAckInd (rgSchCb[inst].tfuSap[suId].cell, harqAckInd);
1785    /* Free up the memory for the request structure */
1786    RGSCH_FREE_MEM(harqAckInd);
1787    return (ret);
1788 }  /* RgLiTfuHqInd */
1789
1790
1791 /**
1792  * @brief Scheduling request(SR) indication from PHY for an UE.
1793  *
1794  * @details
1795  *
1796  *     Function : RgLiTfuSrInd
1797  *      
1798  *      This API is invoked by PHY to send Scheduling request information to
1799  *      Scheduler on recieving SR from a list of UEs.
1800  *      This API contains scheduling request information recieved by PHY for UEs.
1801  *           
1802  *  @param[in]  Pst           *pst
1803  *  @param[in]  SuId          suId 
1804  *  @param[in]  TfuSrIndInfo  *srInd
1805  *  @return  S16
1806  *      -# ROK 
1807  *      -# RFAILED 
1808  **/
1809 S16 RgLiTfuSrInd(Pst *pst, SuId suId, TfuSrIndInfo *srInd)
1810 {
1811    S16   ret;
1812    Inst  inst = pst->dstInst-SCH_INST_START;
1813
1814 #ifndef NO_ERRCLS
1815    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1816    {
1817       DU_LOG("\nERROR  -->  SCH :  SAP Validation failed");
1818       RGSCH_FREE_MEM(srInd);
1819       return (ret);
1820    }
1821
1822    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1823    {
1824       DU_LOG("\nERROR  -->  SCH : RgLiTfuSrInd()No cell exists");
1825       return RFAILED;
1826    }
1827 #endif
1828    /* Now call the TOM (Tfu ownership module) primitive to process further */
1829    ret = rgSCHTomSrInd (rgSchCb[inst].tfuSap[suId].cell, srInd);
1830    /* Free up the memory for the request structure */
1831    RGSCH_FREE_MEM(srInd);
1832    return (ret);
1833 }  /* RgLiTfuSrInd */
1834
1835
1836 /**
1837  * @brief Downlink CQI indication from PHY for an UE.
1838  *
1839  * @details
1840  *
1841  *     Function : RgLiTfuDlCqiInd
1842  *      
1843  *      This API is invoked by PHY to send Downlink CQI indication to Scheduler
1844  *      on recieving downlink CQI from UE.
1845  *      This API contains downlink CQI information recieved by PHY for an UE.
1846  *           
1847  *  @param[in]  Pst              *pst
1848  *  @param[in]  SuId             suId 
1849  *  @param[in]  TfuDlCqiIndInfo  *dlCqiInd
1850  *  @return  S16
1851  *      -# ROK 
1852  *      -# RFAILED 
1853  **/
1854 S16 RgLiTfuDlCqiInd(Pst *pst, SuId suId, TfuDlCqiIndInfo *dlCqiInd)
1855 {
1856    S16   ret;
1857    Inst  inst = pst->dstInst-SCH_INST_START;
1858
1859    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1860    {
1861       DU_LOG("\nERROR  -->  SCH : SAP Validation failed");
1862       /* Free up the memory for the request structure */
1863       RGSCH_FREE_MEM(dlCqiInd);
1864       return (ret);
1865    }
1866
1867    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1868    {
1869       DU_LOG("\nERROR  -->  SCH : No cell exists");
1870       return RFAILED;
1871    }
1872    ret = rgSCHTomDlCqiInd (rgSchCb[inst].tfuSap[suId].cell, dlCqiInd);
1873    /* Free up the memory for the request structure */
1874    RGSCH_FREE_MEM(dlCqiInd);
1875    return (ret);
1876 }  /* RgLiTfuDlCqiInd */
1877 #ifdef TFU_UPGRADE
1878
1879 /**
1880  * @brief Raw CQI indication from PHY for an UE.
1881  *
1882  * @details
1883  *
1884  *     Function : RgLiTfuRawCqiInd
1885  *      
1886  *      This API is invoked by PHY to send Raw CQI indication to Scheduler
1887  *      on receiving Raw CQI from UE.
1888  *      This API contains Raw CQI information recieved by PHY for an UE.
1889  *           
1890  *  @param[in]  Pst              *pst
1891  *  @param[in]  SuId             suId 
1892  *  @param[in]  TfuRawCqiIndInfo  *rawCqiInd
1893  *  @return  S16
1894  *      -# ROK 
1895  *      -# RFAILED 
1896  **/
1897 S16 RgLiTfuRawCqiInd(Pst *pst, SuId suId, TfuRawCqiIndInfo *rawCqiInd)
1898 {
1899    S16   ret;
1900    Inst  inst = pst->dstInst-SCH_INST_START;
1901
1902 #ifdef NO_ERRCLS
1903    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1904    {
1905       DU_LOG("\nERROR  -->  SCH : SAP Validation failed");
1906       /* Free up the memory for the request structure */
1907       RGSCH_FREE_MEM(rawCqiInd);
1908       return (ret);
1909    }
1910
1911    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1912    {
1913       DU_LOG("\nERROR  -->  SCH : No cell exists");
1914       return RFAILED;
1915    }
1916 #endif
1917    ret = rgSCHTomRawCqiInd (rgSchCb[inst].tfuSap[suId].cell, rawCqiInd);
1918    /* Free up the memory for the request structure */
1919    RGSCH_FREE_MEM(rawCqiInd);
1920    return (ret);
1921 }  /* RgLiTfuRawCqiInd */
1922
1923 /**
1924  * @brief SRS indication from PHY for an UE.
1925  *
1926  * @details
1927  *
1928  *     Function : RgLiTfuSrsInd
1929  *      
1930  *      This API is invoked by PHY to send UL SRS indication to Scheduler
1931  *      on receiving a SRS from UE.
1932  *      This API contains SRS information recieved by PHY for an UE.
1933  *           
1934  *  @param[in]  Pst              *pst
1935  *  @param[in]  SuId             suId 
1936  *  @param[in]  TfuSrsIndInfo  *srsInd
1937  *  @return  S16
1938  *      -# ROK 
1939  *      -# RFAILED 
1940  **/
1941 S16 RgLiTfuSrsInd(Pst *pst, SuId suId, TfuSrsIndInfo *srsInd)
1942 {
1943    S16   ret;
1944    Inst  inst = pst->dstInst-SCH_INST_START;
1945
1946    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1947    {
1948       DU_LOG("\nERROR  -->  SCH :  SAP Validation failed");
1949       /* Free up the memory for the request structure */
1950       RGSCH_FREE_MEM(srsInd);
1951       return (ret);
1952    }
1953
1954    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1955    {
1956       DU_LOG("\nERROR  -->  SCH : No cell exists");
1957       return RFAILED;
1958    }
1959    ret = rgSCHTomSrsInd (rgSchCb[inst].tfuSap[suId].cell, srsInd);
1960    /* Free up the memory for the request structure */
1961    RGSCH_FREE_MEM(srsInd);
1962    return (ret);
1963 }  /* RgLiTfuSrsInd */
1964
1965 #endif 
1966
1967 /**
1968  * @brief DOA indication from PHY for an UE.
1969  *
1970  * @details
1971  *
1972  *     Function : RgLiTfuDoaInd
1973  *      
1974  *      This API is invoked by PHY to send Direction Of Arrival to Scheduler
1975  *      on calculating DOA at PHYSICAL LAYER for an UE.
1976  *      This API contains DOA information calculated by PHY for an UE.
1977  *           
1978  *  @param[in]  Pst              *pst
1979  *  @param[in]  SuId             suId 
1980  *  @param[in]  TfuDoaIndInfo    *doaInd
1981  *  @return  S16
1982  *      -# ROK 
1983  *      -# RFAILED 
1984  **/
1985 S16 RgLiTfuDoaInd(Pst *pst, SuId suId, TfuDoaIndInfo *doaInd)
1986 {
1987    S16   ret;
1988    Inst  inst = pst->dstInst-SCH_INST_START;
1989
1990    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
1991    {
1992       DU_LOG("\nERROR  -->  SCH : SAP Validation failed");
1993       /* Free up the memory for the request structure */
1994       RGSCH_FREE_MEM(doaInd);
1995       return (ret);
1996    }
1997
1998    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
1999    {
2000       DU_LOG("\nERROR  -->  SCH : No cell exists");
2001       return RFAILED;
2002    }
2003    ret = rgSCHTomDoaInd (rgSchCb[inst].tfuSap[suId].cell, doaInd);
2004    /* Free up the memory for the request structure */
2005    RGSCH_FREE_MEM(doaInd);
2006    return (ret);
2007 }  /* RgLiTfuDlCqiInd */
2008
2009 /**
2010  * @brief CRC indication from PHY.
2011  *
2012  * @details
2013  *
2014  *     Function : RgLiTfuCrcInd
2015  *      
2016  *      This API is invoked by PHY to give CRC indication to scheduler.
2017  *           
2018  *  @param[in]  Pst               *pst
2019  *  @param[in]  SuId              suId 
2020  *  @param[in]  TfuCrcIndInfo *crcInd
2021  *  @return  S16
2022  *      -# ROK 
2023  *      -# RFAILED 
2024  **/
2025 S16 RgLiTfuCrcInd(Pst *pst, SuId suId, TfuCrcIndInfo  *crcInd)
2026 {
2027    S16              ret;
2028    Inst             inst      = pst->dstInst-SCH_INST_START;
2029
2030 #ifdef XEON_SPECIFIC_CHANGES
2031 struct timeval start6, end6;
2032 gettimeofday(&start6, NULL);
2033 #endif
2034 #ifndef NO_ERRCLS
2035    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2036    {
2037       DU_LOG("\nERROR  -->  SCH : SAP Validation failed");
2038       RGSCH_FREE_MEM(crcInd);
2039       return (ret);
2040    }
2041
2042    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2043    {
2044       DU_LOG("\nERROR  -->  SCH : No cell exists");
2045       return RFAILED;
2046    }
2047 #endif
2048
2049    /* Now call the TOM (Tfu ownership module) primitive to process further */
2050    ret = rgSCHTomCrcInd(rgSchCb[inst].tfuSap[suId].cell, crcInd);
2051    /* Free up the memory for the request structure */
2052    RGSCH_FREE_MEM(crcInd);
2053 #ifdef XEON_SPECIFIC_CHANGES
2054 gettimeofday(&end6, NULL);
2055 #endif
2056    return (ret);
2057 }  /* RgLiTfuCrcInd */
2058
2059 /**
2060  * @brief Timing Advance indication from PHY.
2061  *
2062  * @details
2063  *
2064  *     Function : RgLiTfuTimingAdvInd
2065  *      
2066  *      This API is invoked by PHY to indicate timing advance to Scheduler for
2067  *       an UE.
2068  *           
2069  *  @param[in]  Pst                  *pst
2070  *  @param[in]  SuId                 suId 
2071  *  @param[in]  TfuTimingAdvIndInfo  *timingAdvInd
2072  *  @return  S16
2073  *      -# ROK 
2074  *      -# RFAILED 
2075  **/
2076 S16 RgLiTfuTimingAdvInd(Pst *pst, SuId suId, TfuTimingAdvIndInfo *timingAdvInd)
2077 {
2078    S16   ret;
2079    Inst  inst = pst->dstInst-SCH_INST_START;
2080
2081    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2082    {
2083       DU_LOG("\nERROR  -->  SCH : SAP Validation failed");
2084       /* Free up the memory for the request structure */
2085       RGSCH_FREE_MEM(timingAdvInd);
2086       return (ret);
2087    }
2088
2089    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2090    {
2091       DU_LOG("\nERROR  -->  SCH : No cell exists");
2092       return RFAILED;
2093    }
2094    /* Now call the TOM (Tfu ownership module) primitive to process further */
2095    ret = rgSCHTomTimingAdvInd(rgSchCb[inst].tfuSap[suId].cell, timingAdvInd);
2096    /* Free up the memory for the request structure */
2097    RGSCH_FREE_MEM(timingAdvInd);
2098    return (ret);
2099 }  /* RgLiTfuTimingAdvInd */
2100
2101 /************* RGM  Interface ****************/
2102 /**
2103  * @brief API for bind request from RRM towards MAC. 
2104  *
2105  * @details
2106  *
2107  *     Function: RgUiRgmBndReq
2108  *     
2109  *     This API is invoked by RRM towards MAC to bind RGM SAP. 
2110  *     These API validates the Pst, spId, suId and sends the bind confirm to
2111  *     RRM.
2112  *
2113  *           
2114  *  @param[in]  Pst   *pst
2115  *  @param[in]  SuId  suId
2116  *  @param[in]  SpId  spId
2117  *  @return  S16
2118  *      -# ROK 
2119  *      -# RFAILED 
2120  **/
2121 S16 RgUiRgmBndReq(Pst *pst,SuId  suId,SpId  spId)
2122 {
2123    S16       ret = ROK;
2124    Pst       tmpPst;   /* Temporary Post Structure */
2125    Inst      instId = pst->dstInst-SCH_INST_START;
2126
2127    tmpPst.prior       = pst->prior;
2128    tmpPst.route       = pst->route;
2129    tmpPst.selector    = pst->selector;
2130    tmpPst.region      = rgSchCb[instId].rgSchInit.region;
2131    tmpPst.pool        = rgSchCb[instId].rgSchInit.pool;
2132
2133    tmpPst.srcProcId   = rgSchCb[instId].rgSchInit.procId;
2134    tmpPst.srcEnt      = rgSchCb[instId].rgSchInit.ent;
2135    tmpPst.srcInst     = rgSchCb[instId].rgSchInit.inst + SCH_INST_START;
2136
2137    tmpPst.event       = EVTNONE;
2138
2139    tmpPst.dstProcId   = pst->srcProcId;
2140    tmpPst.dstEnt      = pst->srcEnt;
2141    tmpPst.dstInst     = pst->srcInst;
2142
2143    /*TODO remove follo statement*/
2144    rgSchCb[instId].rgmSap[spId].sapSta.sapState = LRG_UNBND;
2145
2146    if(spId < rgSchCb[instId].numSaps)
2147    {
2148       /* Check the state of the SAP */
2149       switch (rgSchCb[instId].rgmSap[spId].sapSta.sapState)
2150       {
2151          /* This case might not be needed if SAP not configured then it will go
2152           * to else of above if condition */
2153          case LRG_UNBND: /* SAP is not bound */
2154             DU_LOG("\nDEBUG  -->  SCH : SAP is not yet bound");
2155             rgSchCb[instId].rgmSap[spId].sapSta.sapState = LRG_BND;
2156             rgSchCb[instId].rgmSap[spId].sapCfg.suId = suId;
2157             /* Send Bind Confirm with status as SUCCESS */
2158             ret = rgSCHUtlRgmBndCfm(instId, suId, CM_BND_OK);
2159              /*Indicate to Layer manager  */
2160             break;
2161          case LRG_BND: /* SAP is already bound*/
2162             DU_LOG("\nDEBUG  -->  SCH : SAP is already bound");
2163             ret = rgSCHUtlRgmBndCfm(instId, suId, CM_BND_OK);
2164             break;
2165          default: /* Should Never Enter here */
2166 #if (ERRCLASS & ERRCLS_ADD_RES) 
2167             DU_LOG("\nERROR  -->  SCH : Invalid SAP State:RgUiRgmBndReq failed\n");
2168 #endif
2169             ret = rgSCHUtlRgmBndCfm(instId, suId, CM_BND_NOK);
2170             break;
2171       }
2172    }
2173    else
2174    {
2175 #if (ERRCLASS & ERRCLS_ADD_RES)      
2176 /* ccpu00117035 - MOD - Changed ErrVal argument from accessing sap state 
2177    to spId to avoid seg fault due to invalid sapID */
2178       DU_LOG("\nERROR  -->  SCH : Invalid SAP Id:RgUiRrmBndReq failed\n");
2179 #endif
2180       ret = RgUiRgmBndCfm(&tmpPst, suId, CM_BND_NOK);
2181    }
2182    return (ret);
2183 }  /* RgUiRgmBndReq */
2184
2185 /**
2186  * @brief API for unbind request from RRM towards MAC. 
2187  *
2188  * @details
2189  *
2190  *     Function: RgUiRgmUbndReq
2191  *     
2192  *     This API is invoked by RRM towards MAC to unbind RGM SAP. 
2193  *     These API validates the Pst, spId, suId and transfers the unbind request 
2194  *     specific information to corresponding ownership module (GOM) API.
2195  *
2196  *           
2197  *  @param[in]  Pst    *pst
2198  *  @param[in]  SuId   suId
2199  *  @param[in]  Reason reason
2200  *  @return  S16
2201  *      -# ROK 
2202  *      -# RFAILED 
2203  **/
2204 S16 RgUiRgmUbndReq(Pst    *pst,SpId   spId,Reason reason)
2205 {
2206    Inst instId = pst->dstInst-SCH_INST_START;
2207
2208    /* SAP Id validation */
2209    if (spId < rgSchCb[instId].numSaps)
2210    {
2211       switch(rgSchCb[instId].rgmSap[spId].sapSta.sapState)
2212       {
2213          case LRG_BND: /* SAP is already bound*/
2214             /* setting SAP state to UN BOUND */
2215                  DU_LOG("\nDEBUG  -->  SCH : SAP is already bound");
2216             rgSchCb[instId].rgmSap[spId].sapSta.sapState = LRG_UNBND;
2217             break;
2218          default:
2219 #if (ERRCLASS & ERRCLS_ADD_RES)      
2220             DU_LOG("\nERROR  -->  SCH : Invalid SAP State: RgUiRgmUbndReq failed\n");
2221 #endif
2222             return RFAILED;
2223       }
2224    }
2225    else
2226    {
2227 #if (ERRCLASS & ERRCLS_ADD_RES)      
2228       DU_LOG("\nERROR  -->  SCH : Invalid SAP Id:RgUiRgmUbndReq failed\n");
2229 #endif
2230       return RFAILED;
2231    }
2232    return ROK;
2233 }  /* RgUiRgmUbndReq */
2234
2235
2236 /**
2237  * @brief API for start or stop PRB reporting from RRM towards MAC. 
2238  *
2239  * @details
2240  *
2241  *     Function: RgUiRgmCfgPrbRprt
2242  *     
2243  *     This API is invoked by RRM towards MAC to start or stop calculating
2244  *     Average PRB usage in downlink and uplink. The average PRB usage will
2245  *     be reported to RRM based on confiured periodicity.
2246  *
2247  *           
2248  *  @param[in]  Pst   *pst
2249  *  @param[in]  SuId  suId
2250  *  @param[in]  SpId  spId
2251  *  @return  S16
2252  *      -# ROK 
2253  *      -# RFAILED 
2254  **/
2255 S16 RgUiRgmCfgPrbRprt(Pst   *pst, SpId  spId,RgmPrbRprtCfg *prbRprtCfg)
2256 {
2257 /* Initalize*/
2258    RgSchCellCb   *cell;
2259    RgSchPrbUsage *prbUsage;
2260    Inst          inst = (pst->dstInst  - SCH_INST_START);
2261
2262    cell = rgSchCb[inst].rgmSap[spId].cell;
2263    prbUsage = &cell->prbUsage;
2264    prbUsage->prbRprtEnabld = prbRprtCfg->bConfigType;
2265    prbUsage->rprtPeriod = prbRprtCfg->usPrbAvgPeriodicty;
2266    RG_SCH_ADD_TO_CRNT_TIME(cell->crntTime, prbUsage->startTime, 1);
2267
2268    /* clear the qciPrbRpts for all GBR QCIs */
2269    memset(&prbUsage->qciPrbRpts[0], 0, 
2270              (RGM_MAX_QCI_REPORTS * sizeof(RgSchQciPrbUsage)));
2271    DU_LOG("\nDEBUG  -->  SCH : RgUiRgmCfgPrbRprt config type %d with the report period %d",
2272              prbUsage->prbRprtEnabld,prbUsage->rprtPeriod);
2273
2274    /* ccpu00134393 : mem leak fix */
2275       SPutSBuf(pst->region, pst->pool, (Data *)prbRprtCfg, sizeof(RgmPrbRprtCfg));
2276   
2277    return ROK;
2278 }
2279 /**
2280  * @brief ERROR INDICATION from PHY for the i failed unlicensed Scell transmission. 
2281  *
2282  * @details
2283  *
2284  *     Function : RgLiTfuErrInd
2285  *      
2286  *      This API is invoked by PHY to send ERROR INDICATION to scheduler 
2287  *      Currently invoked in the cases when the Unlicensed SCell transmission
2288  *      fails.
2289  *      This API contains the Cell and subframe information for which the
2290  *      transmission failed. 
2291  *           
2292  *  @param[in]  Pst                *pst
2293  *  @param[in]  SuId               suId 
2294  *  @param[in]  TfuErrIndInfo      *errIndInfo 
2295  *  @return  S16
2296  *      -# ROK 
2297  *      -# RFAILED 
2298  **/
2299 S16 RgLiTfuErrInd(Pst *pst, SuId suId, TfuErrIndInfo  *errInd)
2300 {
2301    S16   ret = ROK;
2302 #ifdef LTE_ADV
2303    Inst  inst = (pst->dstInst - SCH_INST_START);
2304 #endif
2305
2306 #ifndef NO_ERRCLS
2307    if ((ret = rgSCHUtlValidateTfuSap (inst, suId)) != ROK)
2308    {
2309
2310       DU_LOG("\nERROR  -->  SCH : SAP Validation failed");
2311       return (ret);
2312    }
2313
2314    if (rgSchCb[inst].tfuSap[suId].cell == NULLP)
2315    {
2316       DU_LOG("\nERROR  -->  SCH : No cell exists");
2317       return RFAILED;
2318    }
2319 #endif
2320
2321 #ifdef LTE_ADV
2322    /* Now call the TOM (Tfu ownership module) primitive to process further */
2323    ret = rgSCHLaaErrInd(rgSchCb[inst].tfuSap[suId].cell, errInd);
2324 #endif
2325    return (ret);
2326 }  /* RgLiTfuErrInd */
2327
2328
2329 \f
2330 /**********************************************************************
2331  
2332          End of file
2333 **********************************************************************/