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