Adding release file
[o-du/l2.git] / src / 5gnrsch / rg_sch_ram.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_ram.c
28   
29 **********************************************************************/
30
31 /** @file rg_sch_ram.c
32 @brief This file has APIs to handle the random access procedure functionality for the scheduler.
33 */
34
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_MODULE_ID=4096;
37 static int RLOG_FILE_ID=171;
38
39 /* header include files (.h) */
40 #include "envopt.h"        /* environment options */
41 #include "envdep.h"        /* environment dependent */
42 #include "envind.h"        /* environment independent */
43   
44 #include "gen.h"           /* general */
45 #include "ssi.h"           /* system services */
46
47 #include "cm_tkns.h"       /* Common Token Defines */
48 #include "cm_llist.h"      /* Common Link List Defines */
49 #include "cm_hash.h"       /* Common Hash List Defines */
50 #include "cm_mblk.h"       /* common memory link list library */
51 #include "cm_lte.h"        /* Common LTE */
52
53 #include "rg_env.h"        /* MAC Environment Defines */
54 #include "rgr.h"           /* RGR Interface defines */
55 #include "rgm.h"           /* RGR Interface defines */
56 #include "tfu.h"           /* TFU Interface defines */
57 #include "lrg.h"           /* LRG Interface defines */
58 #include "rg_env.h"    /* Scheduler error defines */
59 #include "rg_sch_inf.h"        /* Scheduler defines */
60 #include "rg_sch_err.h"    /* Scheduler error defines */
61 #include "rg_sch.h"        /* Scheduler defines */
62 #include "rg_sch_cmn.h"
63 #include "rl_interface.h"
64 #include "rl_common.h"
65
66 /* header/extern include files (.x) */
67 #include "gen.x"           /* general */
68 #include "ssi.x"           /* system services */
69 #include "cm5.x"           /* Timer */
70 #include "cm_tkns.x"       /* Common Token Definitions */
71 #include "cm_llist.x"      /* Common Link List Definitions */
72 #include "cm_lib.x"        /* Common Library Definitions */
73 #include "cm_hash.x"       /* Common Hash List Definitions */
74 #include "cm_mblk.x"       /* common memory link list library */
75 #include "cm_lte.x"        /* Common LTE */
76
77 #include "rgr.x"           /* RGR Interface includes */
78 #include "rgm.x"           /* RGR Interface includes */
79 #include "tfu.x"           /* TFU Interface includes */
80 #include "lrg.x"           /* LRG Interface includes */
81
82 #include "rg_sch_inf.x"         /* typedefs for Scheduler */
83 #include "rg_sch.x"        /* Scheduler includes */
84 #include "rg_sch_cmn.x"
85 #ifdef EMTC_ENABLE
86 EXTERN Bool rgSCHRamVldtRgrEmtcUeCfg  ARGS((
87 RgSchCellCb  *cell,
88 RgrUeCfg     *ueCfg
89 ));
90
91 EXTERN S16 rgSCHRamRmvAllFrmEmtcRaInfoSchdLst
92 (
93 RgSchCellCb       *cell
94 );
95 EXTERN Void rgSCHEmtcUtlUpdCmnNb 
96 (
97 RgSchRaCb      *raCb
98 );
99 EXTERN Void rgSCHEmtcHqPAlloc 
100 (
101 RgSchCellCb       *cell,
102 RgSchDlHqEnt      *hqEnt
103 );
104 #endif
105 /* local defines */
106 /* local typedefs */
107 PRIVATE Void rgSCHRamUlFreeAllocation ARGS((RgSchUlSf *sf,RgSchUlAlloc *alloc, 
108          RgSchCellCb     *cell,Bool isEmtc));
109
110 PRIVATE S16 rgSCHRamContResCrnti   ARGS((RgSchCellCb *cell, RgSchUeCb *ue, 
111                                       RgSchRaCb *raCb, RgSchErrInfo *err));
112 PRIVATE S16 rgSCHRamContResCcchsdu ARGS((RgSchCellCb *cell, RgSchRaCb *raCb));
113 #ifdef EMTC_ENABLE
114
115 EXTERN S16 rgSCHEmtcRamContResCcchsdu ARGS((RgSchCellCb *cell, RgSchRaCb *raCb));
116 EXTERN S16 rgSCHRamEmtcContResCcchsdu ARGS((RgSchCellCb *cell, RgSchRaCb *raCb));
117 EXTERN Void rgSCHChkEmtcContResGrdTmrExp ARGS((RgSchCellCb        *cell));
118 EXTERN Void rgSCHChkEmtcContResTmrExp ARGS((RgSchCellCb        *cell));
119 EXTERN Void rgSCHEmtcRaInfoFree ARGS((RgSchCellCb *cell, RgSchRaCb *raCb));
120 #endif
121 #ifdef RGR_V1
122 PRIVATE Void rgSCHChkContResGrdTmrExp ARGS((RgSchCellCb        *cell));
123 PRIVATE Void rgSCHChkContResTmrExp ARGS((RgSchCellCb        *cell));
124 PRIVATE Void rgSCHRamProcContResExp ARGS((RgSchCellCb *cell, 
125                                  RgSchRaCb  *raCb));
126 PRIVATE Void rgSCHRamProcContResGrdExp ARGS((RgSchCellCb *cell,
127                                       RgSchRaCb  *raCb));
128 #ifdef EMTC_ENABLE
129 EXTERN Void rgSCHChkEmtcContResGrdTmrExp ARGS((RgSchCellCb        *cell));
130 EXTERN Void rgSCHChkEmtcContResTmrExp ARGS((RgSchCellCb        *cell));
131 #endif
132 #endif
133 /* forward references */
134
135 /**
136  * @brief Check configured preamble id not colliding with non dedicated or PDCCH
137  * order preamble sets. When valid preamble id given check that C-RNTI given
138  * in configuration is not amongst the C-RNTI'smanaged by scheduler
139  *
140  * @details
141  *
142  *     Function : rgSCHRamVldtUeCfg 
143  *
144  *     Processing Steps: Check configured preamble id not colliding with non dedicated or PDCCH
145  *       order preamble sets. When valid preamble id given check that C-RNTI given
146  *       in configuration is not amongst the C-RNTI'smanaged by scheduler
147  *
148  *  @param[in]  RgSchCellCb  *cell
149  *  @param[in]  RgrUeCfg     *ueCfg
150  *  @return  S16
151  *      -# ROK
152  *      -# RFAILED
153  **/
154 #ifdef ANSI
155 PUBLIC S16 rgSCHRamVldtUeCfg 
156 (
157 RgSchCellCb  *cell,
158 RgrUeCfg     *ueCfg
159 )
160 #else
161 PUBLIC S16 rgSCHRamVldtUeCfg(cell, ueCfg)
162 RgSchCellCb  *cell;
163 RgrUeCfg     *ueCfg;
164 #endif
165 {
166    TRC2(rgSCHRamVldtUeCfg);
167    if (ueCfg->dedPreambleId.pres == PRSNT_NODEF)
168    {
169       if ((ueCfg->dedPreambleId.val < cell->rachCfg.numRaPreamble) ||
170           (ueCfg->dedPreambleId.val >= RGSCH_MAX_NUM_RA_PREAMBLE) ||
171           ((ueCfg->dedPreambleId.val >= cell->macPreambleSet.start) && 
172            (ueCfg->dedPreambleId.val <= cell->macPreambleSet.start +
173                                        cell->macPreambleSet.size - 1)) ||
174           ((ueCfg->crnti >= cell->rntiDb.rntiStart) && 
175            (ueCfg->crnti < cell->rntiDb.rntiStart + cell->rntiDb.maxRntis-1))
176 #ifdef EMTC_ENABLE
177           || (rgSCHRamVldtRgrEmtcUeCfg(cell,ueCfg))
178 #endif          
179           )
180       {
181          RETVALUE(RFAILED);
182       }
183    }
184    RETVALUE(ROK);
185 }
186
187 /**
188  * @brief Handler for Random Access Request
189  *
190  * @details
191  *
192  *     Function : rgSCHRamProcRaReq
193  *     
194  *     -# Create a node for each TfuRaReqInfo element received
195  *     -# Initialize the list with the above elements at the raRnti index 
196  *        in the cell. 
197  *     
198  *           
199  *  @param[in]  RgSchCellCb       *cell
200  *  @param[in]  CmLteRnti      raRnti
201  *  @param[in]  RgTfuRaReqInd *raReqInd
202  *  @param[out] RgSchErrInfo      *err
203  *  @return  S16
204  *      -# ROK 
205  *      -# RFAILED 
206  **/
207 #ifdef ANSI
208 PUBLIC S16 rgSCHRamProcRaReq
209 (
210 U8                raReqCnt,
211 RgSchCellCb       *cell,
212 CmLteRnti         raRnti,
213 TfuRachInfo       *raReqInd,
214 CmLteTimingInfo   timingInfo,
215 RgSchUeCb         *ue,
216 RgSchErrInfo      *err
217 )
218 #else
219 PUBLIC S16 rgSCHRamProcRaReq(raReqCnt, cell, raRnti, raReqInd, timingInfo, ue, err)
220 U8                raReqCnt;
221 RgSchCellCb       *cell;
222 CmLteRnti         raRnti;
223 TfuRachInfo       *raReqInd;
224 CmLteTimingInfo   timingInfo;
225 RgSchUeCb         *ue;
226 RgSchErrInfo      *err;
227 #endif
228 {
229    RgSchRaReqInfo *raReqInfo;
230    U16            raIndex;
231 #ifdef LTE_TDD
232    U8             fid;
233    U8             tid;
234 #endif
235
236    TRC2(rgSCHRamProcRaReq)
237
238
239       /* SR_RACH_STATS : RACH REQ */
240       rgNumPrachRecvd += raReqInd->numRaReqInfo;
241
242    /* ccpu00132523- Moved out this from for loop as updating of raIndex is 
243     * relates to only raRnti and all preambles having same raRnti*/
244 #ifdef LTE_TDD
245    /* UL subframes do not occupy all the subframes in a radio frame.
246     * So RA Rnti index to be calculated based on actual UL subframe index. */
247    /* Get the actual subframe number */
248    tid = (raRnti-1)%RGSCH_NUM_SUB_FRAMES;
249    /* Get the frequency index in the subframe */
250    fid = ((raRnti-1) / RGSCH_NUM_SUB_FRAMES)* RGSCH_NUM_SUB_FRAMES;
251    /* Get the index of RA RNTI in the array */
252    raIndex = ((timingInfo.sfn % cell->raInfo.maxRaSize) \
253                * RGSCH_MAX_RA_RNTI_PER_SUBFRM * RGSCH_NUM_SUB_FRAMES) + \
254                tid + fid;
255    /* Fixes for RACH handling in TDD: Removed deletion of queued RaReq */
256 #else
257    /* ccpu00132523- Placing the raReq into array based on RA SFN */
258    raIndex = (timingInfo.sfn & 1) * RGSCH_MAX_RA_RNTI + raRnti-1;
259 #endif
260
261    /* allocate new raReqInfos and enqueue them */
262    if (raReqInd->raReqInfoArr[raReqCnt].rapId >= RGSCH_MAX_NUM_RA_PREAMBLE)
263    {
264       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
265                "RARNTI:%d rgSCHTomRaReqInd(): RAM processing failed errType(%d) ",
266                raReqInd->raRnti);
267       RETVALUE(RFAILED);
268    }
269
270    /* SR_RACH_STATS : DED PREAMB*/
271    if (RGSCH_IS_DEDPRM(cell, raReqInd->raReqInfoArr[raReqCnt].rapId))
272    {
273       rgNumDedPream++;
274    }
275
276
277 #ifdef LTE_L2_MEAS
278    if (raReqInd->raReqInfoArr[raReqCnt].rapId < cell->rachCfg.sizeRaPreambleGrpA)
279    {
280       cell->raPrmbs.preamGrpA++;
281    }
282    else if (RGSCH_IS_DEDPRM(cell, raReqInd->raReqInfoArr[raReqCnt].rapId))
283    {
284       cell->raPrmbs.dedPream++;
285    }
286    else
287    {
288       cell->raPrmbs.preamGrpB++;
289    }
290 #endif
291
292    if((rgSCHUtlAllocSBuf(cell->instIdx, (Data **)(&raReqInfo), 
293                sizeof(RgSchRaReqInfo))) == RFAILED)
294    {
295       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHRamProcRaReq(): Allocation"
296             " of RaReq failed RARNTI:%d",raRnti);
297       err->errCause = RGSCHERR_RAM_MEM_EXHAUST;
298       RETVALUE(RFAILED);
299    }
300
301    /* Insert the given raReqInfo */
302    /* RACHO */
303    raReqInfo->timingInfo = timingInfo;
304    raReqInfo->raReq = raReqInd->raReqInfoArr[raReqCnt]; 
305    raReqInfo->raReqLstEnt.next = NULLP;
306    raReqInfo->raReqLstEnt.prev = NULLP;
307    raReqInfo->raReqLstEnt.node = (PTR)raReqInfo;
308    /* ccpu00133504 */
309    raReqInfo->ue = ue;
310
311 #ifndef LTE_TDD
312    RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, cell->raInfo.raReqLst, raIndex);
313 #endif
314    /* RACHO: If dedicated preamble, then give preference by appending at front */
315    if (RGSCH_IS_DEDPRM(cell, raReqInd->raReqInfoArr[raReqCnt].rapId))
316    {
317       cmLListFirst(&cell->raInfo.raReqLst[raIndex]);
318       cmLListInsCrnt(&cell->raInfo.raReqLst[raIndex], &raReqInfo->raReqLstEnt);
319    }
320    else
321    {
322       cmLListAdd2Tail(&cell->raInfo.raReqLst[raIndex], &raReqInfo->raReqLstEnt);
323    }
324
325    RETVALUE(ROK);
326 }  /* rgSCHRamProcRaReq */
327
328 /**
329  * @brief Handler for Random Access control block creation
330  *
331  * @details
332  *
333  *     Function : rgSCHRamCreateRaCb
334  *                Creates a raCb and gives the same to scheduler for its updation
335  *     
336  *
337  *  @param[in]       RgSchCellCb       *cell 
338  *  @param[in, out]  RgSchRaCb         **raCb 
339  *  @param[out]      RgSchErrInfo         *err
340  *  @return  S16
341  *      -# ROK 
342  *      -# RFAILED 
343  **/
344 #ifdef ANSI
345 PUBLIC S16 rgSCHRamCreateRaCb
346 (
347 RgSchCellCb       *cell,
348 RgSchRaCb         **raCb,
349 RgSchErrInfo      *err
350 )
351 #else
352 PUBLIC S16 rgSCHRamCreateRaCb(cell, raCb, err)
353 RgSchCellCb       *cell;
354 RgSchRaCb         **raCb;
355 RgSchErrInfo      *err;
356 #endif
357 {
358    RgSchRntiLnk *rntiLnk;
359    Inst         inst = cell->instIdx;
360
361    TRC2(rgSCHRamCreateRaCb)
362
363    if((rgSCHUtlAllocSBuf(inst, (Data **)(raCb),
364                       sizeof(RgSchRaCb))) == RFAILED)
365    {
366       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHRamCreateRaCb(): Allocation of "
367          "RaCb failed");
368       err->errCause = RGSCHERR_RAM_MEM_EXHAUST;
369       RETVALUE(RFAILED);
370    }
371
372    rntiLnk = rgSCHDbmGetRnti(cell);
373    if(rntiLnk != NULLP)
374    {
375       (*raCb)->rntiLnk = rntiLnk;
376       (*raCb)->tmpCrnti = rntiLnk->rnti;
377    }
378    else
379    {
380
381       /* SR_RACH_STATS: RNTI POOL Exhaution */
382       rgNumRarFailDuetoRntiExhaustion++;
383
384       /* No rnti available! */
385       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHRamCreateRaCb(): Allocation of "
386          "temporary RNTI failed at MAC(CRNTI exhausted)");
387       /* ccpu00117052 - MOD - Passing double pointer
388       for proper NULLP assignment*/
389       rgSCHUtlFreeSBuf(inst, (Data **)(raCb), sizeof(RgSchRaCb));
390       err->errCause = RGSCHERR_RAM_RNTI_EXHAUST;
391       RETVALUE(RFAILED);
392    }
393
394    /* Allocate and initialize the DL HARQ portion of the RACB */
395    (*raCb)->dlHqE = rgSCHDhmHqEntInit(cell);
396    if ((*raCb)->dlHqE == NULLP)
397    {
398       /* No memory available! */
399       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHRamCreateRaCb(): Creation of"
400          " DL HARQ failed");
401           /* ccpu00117052 - MOD - Passing double pointer
402       for proper NULLP assignment*/
403       rgSCHUtlFreeSBuf(inst, (Data **)(raCb), sizeof(RgSchRaCb));
404       err->errCause = RGSCHERR_RAM_MEM_EXHAUST;
405       RETVALUE(RFAILED);
406    }
407 #ifdef EMTC_ENABLE
408    (*raCb)->isEmtcRaCb = FALSE;
409    rgSCHEmtcHqPAlloc(cell, (*raCb)->dlHqE);
410 #endif
411    (*raCb)->dlHqE->raCb = (*raCb);
412    /* Initialize RaCb's contents */
413    (*raCb)->timingInfo = cell->crntTime;
414    (*raCb)->raState = RGSCH_RA_MSG3_PENDING;
415    (*raCb)->toDel = FALSE;
416    (*raCb)->phr.pres = FALSE;
417
418    /* Insert the created raCb into raCb list of cell */
419    (*raCb)->raCbLnk.node = (PTR)(*raCb);
420    cmLListAdd2Tail(&cell->raInfo.raCbLst, &(*raCb)->raCbLnk);
421    
422    RETVALUE(ROK);
423 }  /* rgSCHRamCreateRaCb */
424
425 /**
426  * @brief Handler for Ue Configuration Request
427  *
428  * @details
429  *
430  *     Function : rgSCHRamRgrUeCfg
431  *     
432  *     This function handles the UE config received based on the state of the
433  *     raCb.
434  *     -# If raCb is in RGSCH_RA_MSG4_PENDING state, it shall update the harq 
435  *        information to UeCb and update the references.
436  *     -# If raCb is in RGSCH_RA_MSG4_DONE, then it shall free the raCb
437  *     
438  *           
439  *  @param[in]     RgSchCellCb    *cell
440  *  @param[in,out] RgSchUeCb      *ue 
441  *  @param[in,out] RgSchRaCb      *raCb 
442  *  @param[out]    RgSchErrInfo   *err
443  *  @return  S16
444  *      -# ROK 
445  *      -# RFAILED 
446  **/
447 #ifdef ANSI
448 PUBLIC S16 rgSCHRamRgrUeCfg
449 (
450 RgSchCellCb    *cell,
451 RgSchUeCb      *ue,
452 RgSchRaCb      *raCb,
453 RgSchErrInfo   *err
454 )
455 #else
456 PUBLIC S16 rgSCHRamRgrUeCfg(cell, ue, raCb, err)
457 RgSchCellCb    *cell;
458 RgSchUeCb      *ue;
459 RgSchRaCb      *raCb;
460 RgSchErrInfo   *err;
461 #endif
462 {
463    /* Releasing HARQ processes of old UE when ue
464     *           reconfig with new crnti */
465   /* U32 cnt; */
466    RgSchDlHqEnt          **hqEnt = &(RG_SCH_CMN_GET_UE_HQE(ue, cell));
467    RgSchCmnUlUe *ueUl = RG_SCH_CMN_GET_UL_UE(ue, cell);
468    TRC2(rgSCHRamRgrUeCfg)
469
470
471    /* Fix : set UE inactive in DL until UE is reinitialization completed */
472    ue->dl.dlInactvMask |= RG_HQENT_INACTIVE;
473    ue->ul.ulInactvMask |= RG_HQENT_INACTIVE;
474
475    if(raCb->raState ==  RGSCH_RA_MSG4_PENDING)
476    {
477       raCb->ue = ue;
478       ue->rntiLnk = raCb->rntiLnk;
479       /* Update UL Harq process information */
480       /*ccpu00128820 - MOD - Msg3 alloc double delete issue*/
481       ueUl->hqEnt.hqProcCb[raCb->msg3HqProcId].ndi = raCb->msg3HqProc.ndi;    
482    }
483    else if(raCb->raState == RGSCH_RA_MSG4_DONE)
484    {
485       ue->rntiLnk = raCb->rntiLnk;
486       /* Update UL Harq process information */
487       /*ccpu00128820 - MOD - Msg3 alloc double delete issue*/
488       ueUl->hqEnt.hqProcCb[raCb->msg3HqProcId].ndi = raCb->msg3HqProc.ndi;      
489       /* Fix : syed Assign hqEnt to UE only if msg4 is done */
490       rgSCHDhmAssgnUeHqEntFrmRaCb(ue, raCb);
491    }
492    else
493    {
494       err->errCause = RGSCHERR_RAM_NO_MSG3_RCVD;
495       *hqEnt = NULLP;
496       raCb->dlHqE->ue = NULLP;
497       RETVALUE(RFAILED);
498    }
499
500    RETVALUE(ROK);
501 }  /* rgSCHRamRgrUeCfg */
502
503
504 /**
505  * @brief Handler for C-RNTI based contention resolution
506  *
507  * @details
508  *
509  *     Function : rgSCHRamContResCrnti
510  *     
511  *     This function shall be invoked once Msg3 indicates C-RNTI based
512  *     contention resolution.This shall indicate the scheduler regarding
513  *     C-RNTI based uplink grant.
514  *     
515  *           
516  *  @param[in,out] RgSchCellCb *cell 
517  *  @param[in,out] RgSchUeCb   *ue 
518  *  @param[in,out] RgSchRaCb   *raCb 
519  *  @return  S16
520  *      -# ROK 
521  **/
522 #ifdef ANSI
523 PRIVATE S16 rgSCHRamContResCrnti
524 (
525 RgSchCellCb  *cell,
526 RgSchUeCb    *ue,
527 RgSchRaCb    *raCb,
528 RgSchErrInfo *err
529 )
530 #else
531 PRIVATE S16 rgSCHRamContResCrnti(cell, ue, raCb, err)
532 RgSchCellCb  *cell;
533 RgSchUeCb    *ue;
534 RgSchRaCb    *raCb;
535 RgSchErrInfo *err;
536 #endif
537 {
538    TfuUlCqiRpt   ulCqiRpt;
539    RgSchCmnCell  *cellSch= (RgSchCmnCell *)(cell->sc.sch);
540    TRC2(rgSCHRamContResCrnti)
541
542
543    /* Fix: syed It is incorrect to copy over msg3HqProc to ueCb's 
544     * UL harq proc. In case of Crnti based RACH, ueCb has valid context which
545     * cannot be over written. It was leading to a crash. */ 
546
547    rgSCHUtlRecMsg3Alloc(cell, ue, raCb);
548
549    /* Fix for ccpu00123908: Reset the UL CQI to the cell default value here */
550    ulCqiRpt.isTxPort0 = TRUE;
551    ulCqiRpt.numSubband = 0;
552    /* Fix : syed HO UE does not have a valid ue->rntiLnk */        
553    ulCqiRpt.rnti = ue->ueId;
554    /* rg002.301:[ccpu00124018]-MOD- Avoiding hard coding of CQI and retriving from cell config*/
555    ulCqiRpt.wideCqi = cellSch->ul.dfltUlCqi;
556    rgSCHUtlUlCqiInd(cell, ue, &ulCqiRpt);
557
558    
559    /* Invoke scheduler to indicate UL grant req for contention resolution */
560    rgSCHUtlContResUlGrant(cell, ue, err);
561
562    if (raCb->phr.pres == TRUE)
563    {
564       rgSCHUtlUpdPhr(cell, ue, raCb->phr.val, err);
565    }
566    /* No need of raCb any more */
567    rgSCHRamDelRaCb(cell, raCb, TRUE);
568
569    RETVALUE(ROK);
570 }  /* rgSCHRamContResCrnti */
571
572
573 /**
574  * @brief Handler for CCCH SDU based contention resolution
575  *
576  * @details
577  *
578  *     Function : rgSCHRamContResCcchsdu
579  *     
580  *     This function shall be invoked once Msg3 indicates contention resolution
581  *     based on CCCH sdu. This shall update the raCb state to 
582  *     RGSCH_RA_MSG4_PENDING.
583  *     
584  *           
585  *  @param[in,out] RgSchRaCb *raCb 
586  *  @return  S16
587  *      -# ROK 
588  **/
589 #ifdef ANSI
590 PRIVATE S16 rgSCHRamContResCcchsdu
591 (
592 RgSchCellCb *cell,
593 RgSchRaCb *raCb
594 )
595 #else
596 PRIVATE S16 rgSCHRamContResCcchsdu(cell, raCb)
597 RgSchCellCb *cell;
598 RgSchRaCb *raCb;
599 #endif
600 {
601 #ifdef RGR_V1 
602    CmLteTimingInfo expTime = {0}; 
603    RgSchCmnCell  *cellSch  = RG_SCH_CMN_GET_CELL(cell);
604 #endif
605    TRC2(rgSCHRamContResCcchsdu)
606    if(raCb->raState != RGSCH_RA_MSG3_PENDING)
607    {
608       RLOG_ARG2(L_DEBUG,DBG_CELLID,cell->cellId,
609                "RNTI:%d RaCb in wrong State %d Drop Msg 3",
610                raCb->rntiLnk->rnti, 
611                raCb->raState);
612       RETVALUE(ROK);
613    }
614
615    raCb->raState = RGSCH_RA_MSG4_PENDING;
616
617 #ifdef RGR_V1 
618    if(cell->rachCfg.contResTmr - cellSch->dl.msg4TxDelay > 0)
619       {
620       /* Set the contension resolution guard timer = 
621          Cont Res Timer - Max msg4 Tx Delay */
622          RG_SCH_ADD_TO_CRNT_TIME(cell->crntTime, expTime,
623             (cell->rachCfg.contResTmr - cellSch->dl.msg4TxDelay));
624       }
625       else
626       {
627       /* Schedule the CRI CE in the next Sf itself */
628          RG_SCH_ADD_TO_CRNT_TIME(cell->crntTime, expTime, 1);
629       }
630       raCb->expiryTime = expTime;
631       raCb->contResTmrLnk.node = (PTR)(raCb);
632       cmLListAdd2Tail(&(cell->contResGrdTmrLst), &(raCb->contResTmrLnk));
633 #endif
634    RETVALUE(ROK);
635 }  /* rgSCHRamContResCcchsdu */
636
637
638 /**
639  * @brief Handler for Msg3
640  *
641  * @details
642  *
643  *     Function : rgSCHRamProcMsg3
644  *     
645  *     This function processes the received Msg3 and identifies the type of 
646  *     contention resolution and act accordingly. 
647  *     
648  *           
649  *  @param[in,out]  RgSchCellCb     *cell
650  *  @param[in,out]  RgSchUeCb       *ue
651  *  @param[in,out] RgSchRaCb        *raCb 
652  *  @return  S16
653  *      -# ROK 
654  **/
655 #ifdef ANSI
656 PUBLIC S16 rgSCHRamProcMsg3
657 (
658 RgSchCellCb     *cell,
659 RgSchUeCb       *ue,
660 RgSchRaCb       *raCb,
661 RgInfUeDatInd   *pdu,
662 RgSchErrInfo    *err
663 )
664 #else
665 PUBLIC S16 rgSCHRamProcMsg3(cell, ue, raCb, pdu, err)
666 RgSchCellCb     *cell;
667 RgSchUeCb       *ue;
668 RgSchRaCb       *raCb;
669 RgInfUeDatInd   *pdu;
670 RgSchErrInfo    *err;
671 #endif
672 {
673    TRC2(rgSCHRamProcMsg3)
674
675
676    /* Update raCb with PHR if received along with Msg3 */ 
677    if (pdu->ceInfo.bitMask & RGSCH_PHR_CE_PRSNT)
678    {
679       /* PHR present */
680       raCb->phr.pres = TRUE;
681       raCb->phr.val = pdu->ceInfo.ces.phr;
682    } 
683    if (ue)
684    {
685       rgSCHRamContResCrnti(cell, ue, raCb, err);
686    }
687    else
688    {
689 #ifdef EMTC_ENABLE
690       if(TRUE == raCb->isEmtcRaCb)
691       {
692          /* starting the emtc Contention resolution timer */
693          rgSCHRamEmtcContResCcchsdu(cell,raCb);
694       }
695       else
696 #endif
697       {
698          rgSCHRamContResCcchsdu(cell, raCb);
699       }
700    } 
701
702    RETVALUE(ROK);
703 }  /* rgSCHRamProcMsg3 */
704
705
706 /**
707  * @brief Handler for Updating Bo received in StaRsp
708  *
709  * @details
710  *
711  *     Function : rgSCHRamUpdtBo
712  *     
713  *     This function shall be invoked by RAM once it receives staRsp on CCCH
714  *  
715  *  @param[in]     RgSchCellCb       *cell         
716  *  @param[in,out] RgSchRaCb         *raCb 
717  *  @param[in]     RgRguCmnStaRsp *staRsp
718  *  @return  S16
719  *      -# ROK 
720  **/
721 #ifdef ANSI
722 PUBLIC S16 rgSCHRamUpdtBo
723 (
724 RgSchCellCb       *cell,
725 RgSchRaCb         *raCb,
726 RgInfCmnBoRpt     *staRsp
727 )
728 #else
729 PUBLIC S16 rgSCHRamUpdtBo(cell, raCb, staRsp)
730 RgSchCellCb       *cell;
731 RgSchRaCb         *raCb;
732 RgInfCmnBoRpt     *staRsp;
733 #endif
734 {
735    TRC2(rgSCHRamUpdtBo)
736
737    /* Update Bo in RaCb */
738    raCb->dlCcchInfo.bo = (U32)(staRsp->bo);
739    /* SR_RACH_STATS : MSG4 WITH CCCH SDU */
740    rgNumMsg4WithCCCHSdu++;
741
742    /* add this to the "tobeSchdLst" */
743    /* MSG4 Fix  Start */   
744    rgSCHRamAddToRaInfoSchdLst(cell, raCb);
745    /* MSG4 Fix  End */      
746    
747    RETVALUE(ROK);
748 } /* rgSCHRamUpdtBo */
749
750 /**
751  * @brief Handler for Msg3 Feedback indication
752  *
753  * @details
754  *
755  *     Function : rgSCHRamMsg3DatInd
756  *     
757  *     This function shall be invoked by TOM once the transmission of Msg4 is
758  *     ACKed/NACKed.
759  *     This shall invoke UHM to set ACK for Msg3 reception.
760  *           
761  *  @param[in,out] RgSchRaCb *raCb 
762  *  @return  S16
763  *      -# ROK 
764  **/
765 #ifdef ANSI
766 PUBLIC S16 rgSCHRamMsg3DatInd
767 (
768 RgSchRaCb      *raCb
769 )
770 #else
771 PUBLIC S16 rgSCHRamMsg3DatInd(raCb)
772 RgSchRaCb      *raCb;
773 #endif
774 {
775    TRC2(rgSCHRamMsg3DatInd)
776
777    /* SR_RACH_STATS : MSG3 ACK*/
778    rgNumMsg3CrcPassed++;
779    /*ccpu00128820 - MOD - Msg3 alloc double delete issue*/
780    rgSCHUhmProcMsg3DatInd(&(raCb->msg3HqProc));
781
782    RETVALUE(ROK);
783 }  /* rgSCHRamMsg3DatInd */
784
785 /**
786  * @brief Handler for Msg3 Feedback indication
787  *
788  * @details
789  *
790  *     Function : rgSCHRamMsg3FailureInd
791  *     
792  *     This function shall be invoked by TOM once the transmission of Msg4 is
793  *     ACKed/NACKed.
794  *     This shall invoke UHM to set ACK for Msg3 reception.
795  *           
796  *  @param[in,out] RgSchRaCb *raCb 
797  *  @return  S16
798  *      -# ROK 
799  **/
800 #ifdef ANSI
801 PUBLIC S16 rgSCHRamMsg3FailureInd
802 (
803 RgSchRaCb      *raCb
804 )
805 #else
806 PUBLIC S16 rgSCHRamMsg3FailureInd(raCb)
807 RgSchRaCb      *raCb;
808 #endif
809 {
810    TRC2(rgSCHRamMsg3FailureInd)
811
812    /*ccpu00128820 - MOD - Msg3 alloc double delete issue*/
813    rgSCHUhmProcMsg3Failure(&(raCb->msg3HqProc));
814
815    RETVALUE(ROK);
816 }  /* rgSCHRamMsg3FailureInd */
817
818 /**
819  * @brief Handler for Msg4 Feedback indication
820  *
821  * @details
822  *
823  *     Function : rgSCHRamMsg4FdbkInd
824  *     
825  *     This function shall be invoked by TOM once the transmission of Msg4 is
826  *     ACKed/NACKed.
827  *     This shall invoke UHM to set ACK for Msg3 reception.
828  *           
829  *  @param[in,out] RgSchRaCb *raCb 
830  *  @return  S16
831  *      -# ROK 
832  **/
833 #ifdef ANSI
834 PUBLIC S16 rgSCHRamMsg4FdbkInd
835 (
836 RgSchRaCb      *raCb
837 )
838 #else
839 PUBLIC S16 rgSCHRamMsg4FdbkInd(raCb)
840 RgSchRaCb      *raCb;
841 #endif
842 {
843    TRC2(rgSCHRamMsg4FdbkInd)
844
845    RETVALUE(ROK);
846 }  /* rgSCHRamMsg4FdbkInd */
847
848
849 /**
850  * @brief Handler for Msg4 state updation
851  *
852  * @details
853  *
854  *     Function : rgSCHRamMsg4Done
855  *     
856  *     This function shall be invoked by DHM once the transmission of Msg4 is
857  *     done. This shall delete the raCb if there is a valid Ue or if this is to
858  *     be deleted. If not this shall update the state of the raCb.
859  *     
860  *           
861  *  @param[in]     RgSchCellCb    *cell
862  *  @param[in,out] RgSchRaCb      *raCb 
863  *  @return  S16
864  *      -# ROK 
865  **/
866 #ifdef ANSI
867 PUBLIC S16 rgSCHRamMsg4Done
868 (
869 RgSchCellCb    *cell,
870 RgSchRaCb      *raCb
871 )
872 #else
873 PUBLIC S16 rgSCHRamMsg4Done(cell, raCb)
874 RgSchCellCb    *cell;
875 RgSchRaCb      *raCb;
876 #endif
877 {
878    TRC2(rgSCHRamMsg4Done)
879
880    RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,
881             "rgSCHRamMsg4Done(): tmpCRNTI = %u",
882             raCb->tmpCrnti);
883
884    if(raCb->ue != NULLP) 
885    {
886       /* Fix : syed Let this funtion decide on releasing
887        * hqP than the caller of this function otherwise sometimes it 
888        * might lead to incorrec NDI setting. */    
889       rgSCHDhmRlsHqpTb(raCb->dlHqE->msg4Proc, 0, TRUE);
890       /* Fix : syed Assign hqEnt to UE only if msg4 is done */
891       rgSCHDhmAssgnUeHqEntFrmRaCb(raCb->ue, raCb);
892 #ifdef EMTC_ENABLE
893       if(TRUE == raCb->isEmtcRaCb)
894       {
895          rgSCHEmtcUtlUpdCmnNb(raCb);
896       }
897 #endif
898       /* MS_FIX :Proceed to CCCH scheduling irrespective of
899        * MSG4 result */
900       if (raCb->ue->dlCcchInfo.bo)
901       {
902 #ifdef EMTC_ENABLE
903          /*if CR-ID Ack has been received ,Add emtc Ue to cchSduUeLst*/
904          if(TRUE == raCb->isEmtcRaCb)
905          {
906             rgSCHUtlAddUeToEmtcCcchSduLst(cell, raCb->ue);
907          }
908          else
909 #endif
910          {
911             rgSCHUtlAddUeToCcchSduLst(cell, raCb->ue);
912          }
913       }
914       /* Rnti shall not be released as Ue exists with this rnti */
915       rgSCHRamDelRaCb(cell, raCb, FALSE);
916    }
917    else if(raCb->toDel == TRUE)
918    {
919 #ifdef XEON_SPECIFIC_CHANGES
920       CM_LOG_DEBUG(CM_LOG_ID_SCH, "Deleting RacB:%d\n", raCb->tmpCrnti);
921 #endif
922       /* Delete RACB and release RNTI */
923       rgSCHRamDelRaCb(cell, raCb, TRUE);
924    }
925    else
926    {
927 #ifdef XEON_SPECIFIC_CHANGES
928       CM_LOG_DEBUG(CM_LOG_ID_SCH, "Releasing Harq of RacB:%d\n", raCb->tmpCrnti);
929 #endif
930       raCb->raState = RGSCH_RA_MSG4_DONE;
931       /* Release harq process as final feedback is received for Msg4. In other
932        * cases, delRaCb will take care of releasing the harq process */
933       printf("=======Harq process released \n"); 
934       RLOG_ARG0(L_DEBUG,DBG_CELLID,cell->cellId,
935                                          "Harq process released "); 
936       rgSCHDhmRlsHqpTb(raCb->dlHqE->msg4Proc, 0, TRUE);
937    }
938
939    RETVALUE(ROK);
940 }  /* rgSCHRamMsg4Done */
941
942
943 /**
944  * @brief Handler for deletion
945  *
946  * @details
947  *
948  *     Function : rgSCHRamDelRaCb
949  *     
950  *     This function shall be invoked whenever a raCb needs to be deleted. 
951  *    Invoked by both RAM and downlink scheduler 
952  *           
953  *  @param[in]     RgSchCellCb *cell 
954  *  @param[in,out] RgSchRaCb   *raCb
955  *  @param[in]     Bool        rlsRnti 
956  *  @return  S16
957  *      -# ROK 
958  *      -# RFAILED 
959  **/
960 #ifdef ANSI
961 PUBLIC S16 rgSCHRamDelRaCb
962 (
963 RgSchCellCb *cell,
964 RgSchRaCb   *raCb,
965 Bool        rlsRnti
966 )
967 #else
968 PUBLIC S16 rgSCHRamDelRaCb(cell, raCb, rlsRnti)
969 RgSchCellCb *cell;
970 RgSchRaCb   *raCb;
971 Bool        rlsRnti;
972 #endif
973 {
974    Inst         inst = cell->instIdx;
975    Bool         isEmtc = FALSE;
976    TRC2(rgSCHRamDelRaCb)
977  
978     /* Delete from all the lists it is enqueued */
979     cmLListDelFrm(&(cell->raInfo.raCbLst),&(raCb->raCbLnk));
980 #ifdef EMTC_ENABLE
981     /*ue Type is EMTC, then Delete the toBeSchedLst and stop the Guard Timer */
982    if(TRUE == raCb->isEmtcRaCb)
983    {
984       rgSCHRamEmtcDelRaCb(cell,raCb);
985       isEmtc = TRUE;
986    }
987     else
988 #endif
989     {
990       if (raCb->schdLnk.node == (PTR)raCb)
991       {
992          rgSCHRamRmvFrmRaInfoSchdLst(cell, raCb);
993       }
994 #ifdef RGR_V1
995       else if(raCb->contResTmrLnk.node != NULLP)
996       {
997          cmLListDelFrm(&cell->contResGrdTmrLst, &(raCb->contResTmrLnk));
998          raCb->contResTmrLnk.node = NULLP;
999       }
1000 #endif
1001     }
1002
1003    if(rlsRnti == TRUE)
1004    {
1005       rgSCHUtlRlsRnti(cell, raCb->rntiLnk, FALSE, 0);
1006    }
1007
1008    /* Check if msg4 Hq Proc has been released. If not, release it */
1009    if (raCb->dlHqE )
1010    {
1011       if (raCb->dlHqE->msg4Proc != NULLP)
1012       {
1013          /* Fix: syed Remove the msg4Proc if it waiting in sf->tbs list for
1014           * harq feedback */          
1015          if ((raCb->dlHqE->msg4Proc->subFrm != NULLP) &&
1016              (raCb->dlHqE->msg4Proc->hqPSfLnk.node != NULLP))
1017          {
1018             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"TMP CRNTI:%d RACH FAILURE!! "
1019                "msg4proc  removed from SF", raCb->tmpCrnti);
1020             rgSCHUtlDlHqPTbRmvFrmTx(raCb->dlHqE->msg4Proc->subFrm, 
1021                                     raCb->dlHqE->msg4Proc, 0, FALSE);
1022          }            
1023          /* Fix: syed Remove the msg4Proc from cell
1024           * msg4Retx Queue. I have used CMN scheduler function
1025           * directly. Please define a new API and call this
1026           * function through that. */         
1027          rgSCHCmnDlMsg4ProcRmvFrmRetx(cell, raCb->dlHqE->msg4Proc);           
1028          rgSCHDhmRlsHqpTb(raCb->dlHqE->msg4Proc, 0, TRUE);
1029       }
1030
1031       /* Mark the raCb pointer in dlHqE to NULLP */
1032       raCb->dlHqE->raCb = NULLP;
1033
1034       rgSCHDhmDelHqEnt(cell, &raCb->dlHqE);
1035    }
1036    /* Fix: syed Adaptive Msg3 Retx crash. Remove the harqProc
1037     * from adaptive retx List. Free the alloc if it exists. */
1038    if (raCb->msg3HqProc.reTxLnk.node)
1039    {
1040       //TODO_SID: Need to take care of retxLst
1041       //cmLListDelFrm(raCb->msg3HqProc.reTxAlloc.reTxLst, &raCb->msg3HqProc.reTxLnk); 
1042       raCb->msg3HqProc.reTxLnk.node = (PTR)NULLP;
1043    }
1044
1045    if (raCb->msg3HqProc.alloc)
1046    {
1047       /* Fix: syed During GPR, please write an API instead of direct
1048        * call to cmn scheduler function */         
1049       RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
1050       /*ccpu00130356 - MOD- To avoid segmentation problem because of double
1051        free due to recursive calling of rgSCHRamDelRaCb*/
1052       rgSCHRamUlFreeAllocation(&cellUl->ulSfArr[raCb->msg3HqProc.ulSfIdx],
1053                                                    raCb->msg3HqProc.alloc,
1054                                                    cell,isEmtc);
1055    }
1056
1057 #ifdef EMTC_ENABLE
1058    if(TRUE == raCb->isEmtcRaCb)
1059    {
1060       rgSCHEmtcRaInfoFree(cell, raCb);
1061    }
1062 #endif
1063    rgSCHUtlFreeSBuf(inst, (Data **)&raCb, sizeof(RgSchRaCb));
1064
1065    RETVALUE(ROK);
1066 }  /* rgSCHRamDelRaCb */
1067
1068
1069 /**
1070  * @brief  TTI Handler for RAM module
1071  *
1072  * @details
1073  *
1074  *     Function : rgSCHRamTtiHndlr
1075  *     
1076  *     This function shall be invoked upon TtiInd by TOM
1077  *     This shall
1078  *         - remove RaReqs added to the queue for a raRnti for which PHY may
1079  *           give the requests in the next subframe
1080  *         - remove raCbs which are not yet processed once the 
1081  *           counter for raCb processing expires.
1082  *     
1083  *           
1084  *  @param[in,out] RgSchCellCb  *cell
1085  *  @return  S16
1086  *      -# ROK 
1087  **/
1088 #ifdef ANSI
1089 PUBLIC S16 rgSCHRamTtiHndlr
1090 (
1091 RgSchCellCb  *cell
1092 )
1093 #else
1094 PUBLIC S16 rgSCHRamTtiHndlr(cell)
1095 RgSchCellCb  *cell;
1096 #endif
1097 {
1098    RgSchRaCb   *raCb;
1099    U16         raSfn;
1100    U16         crntSfn;
1101    U16         dist;       /* Number of frames between raCb's creation and crnt
1102                               frame */
1103    U8          idx;
1104    U32         maxCnt;
1105 #ifndef LTE_TDD
1106    U8          winGap;        
1107    U8          raIdx;
1108    RgSchRaReqInfo *raReqInfo;
1109 #else
1110    CmLteTimingInfo      frm;
1111    U8                   raIdx;
1112 #endif
1113
1114    TRC2(rgSCHRamTtiHndlr)
1115
1116    crntSfn = cell->crntTime.sfn;
1117   
1118 #ifdef RGR_V1
1119    /*Check if Contention resolution guard timer expiring in the TTI*/
1120    rgSCHChkContResGrdTmrExp(cell);
1121    /*Check if Contention resolution timer expiring in the TTI*/
1122    rgSCHChkContResTmrExp(cell);
1123 #ifdef EMTC_ENABLE
1124       /*Check if EMTC Contention resolution guard timer expiring in the TTI*/
1125       rgSCHChkEmtcContResGrdTmrExp(cell);
1126       /*Check if EMTC Contention resolution timer expiring in the TTI*/
1127       rgSCHChkEmtcContResTmrExp(cell);
1128 #endif
1129 #endif
1130 #ifndef LTE_TDD
1131
1132    /* Delete the RA requests for which RAR window expired in this subframe 
1133     * And were not considered for RAR scheduling*/
1134    winGap = (rgRaPrmblToRaFrmTbl[cell->rachCfg.preambleFormat]-1)+ 
1135       (cell->rachCfg.raWinSize -1 ) + RGSCH_RARSP_WAIT_PERIOD;   
1136  
1137    raIdx = (((crntSfn & 1) * RGSCH_MAX_RA_RNTI+ cell->crntTime.subframe 
1138             + RG_SCH_CMN_DL_DELTA - winGap)+ RGSCH_RAREQ_ARRAY_SIZE ) 
1139            % RGSCH_RAREQ_ARRAY_SIZE;
1140
1141    /* Flush the already existing raReqs against the given raRnti */
1142
1143    maxCnt = cell->raInfo.raReqLst[raIdx].count;
1144    for (idx = 0; idx < maxCnt; idx++)
1145    {
1146       raReqInfo = (RgSchRaReqInfo *)(cell->raInfo.raReqLst[raIdx].first->node);
1147       cmLListDelFrm(&(cell->raInfo.raReqLst[raIdx]),&(raReqInfo->raReqLstEnt));
1148       /* ccpu00117052 - MOD - Passing double pointer
1149       for proper NULLP assignment*/
1150       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&raReqInfo,
1151             sizeof(RgSchRaReqInfo));
1152    }
1153 #else
1154    /* Fixes for RACH handling: Added deletion of queued RaReq */
1155    frm   = cell->crntTime;
1156    RGSCH_INCR_SUB_FRAME(frm, RG_SCH_CMN_DL_DELTA);
1157    if(rgSchTddUlDlSubfrmTbl[cell->ulDlCfgIdx][frm.subframe] !=
1158                      RG_SCH_TDD_UL_SUBFRAME)
1159    {
1160       raIdx = rgSchTddNumDlSubfrmTbl[cell->ulDlCfgIdx][frm.subframe]-1;
1161       rgSCHRamDelRaReq(cell, cell->crntTime, raIdx);
1162    }
1163 #endif
1164    
1165    /* Remove the RACBs which are timed out */
1166    /* ccpu00132536:MOD- racb timeout will be verified in each SFN such that 
1167     * the RACB whose processing is not completed in RG_MAX_RA_PRC_FRM
1168     * will be deleted*/
1169    if (cell->crntTime.subframe == 0)
1170    {
1171       maxCnt = cell->raInfo.raCbLst.count;
1172       for (idx = 0; idx < maxCnt; idx++)
1173       {
1174          raCb = (RgSchRaCb *)(cell->raInfo.raCbLst.first->node);
1175          /* Calculate number of frames between raCb's creation and crnt frame */
1176          raSfn = raCb->timingInfo.sfn;
1177          dist = (crntSfn + (RGSCH_MAX_SFN - raSfn)) % RGSCH_MAX_SFN;
1178          /* Delete RaCbs whose processing is not complete within 
1179           * "cell->t300TmrVal" frames */
1180           /* raCb not to be deleted if msg4 is not completed */
1181           /* raCb should not be deleted(RNTI should not be released) if UE is present
1182            * as it means the application still holds the RNTI. raCb will get deleted
1183            * as part of UE deletion. raCb will anyway get deleted without releasing RNTI on success/failure of MSG4*/
1184          
1185          if (dist >= cell->t300TmrVal) 
1186          {
1187             if ((raCb->dlHqE->msg4Proc == NULLP) && (raCb->dlHqE->ue == NULLP))
1188             {
1189                rgSCHRamDelRaCb(cell, raCb, TRUE);
1190             }
1191          }
1192          else
1193          {
1194             break;
1195          }
1196       }
1197    }
1198    
1199    RETVALUE(ROK); 
1200 }  /* rgSCHRamTtiHndlr */
1201
1202
1203 /**
1204  * @brief Function for handling cell delete
1205  *
1206  * @details
1207  *
1208  *     Function : rgSCHRamFreeCell
1209  *     
1210  *     This function shall be invoked whenever a cell needs to be deleted.
1211  *     This shall remove raCbs and raReqs stored in cell.
1212  *     
1213  *           
1214  *  @param[in,out] RgSchCellCb  *cell
1215  *  @return  S16
1216  *      -# ROK 
1217  **/
1218 #ifdef ANSI
1219 PUBLIC S16 rgSCHRamFreeCell
1220 (
1221 RgSchCellCb    *cell
1222 )
1223 #else
1224 PUBLIC S16 rgSCHRamFreeCell(cell)
1225 RgSchCellCb    *cell;
1226 #endif
1227 {
1228    RgSchRaReqInfo  *raReqInfo;
1229    RgSchRaCb       *raCb;
1230    U8              idx;
1231    U8              raCbCnt;
1232    Inst            inst = cell->instIdx;
1233    U8              lstSz;
1234 #ifdef LTE_TDD
1235    U8              maxUlSubframes;
1236    U8              maxDlSubframes;
1237 #endif
1238
1239
1240    TRC2(rgSCHRamFreeCell)
1241
1242
1243 #ifdef LTE_TDD
1244    maxUlSubframes =
1245       rgSchTddNumUlSubfrmTbl[cell->ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
1246    maxDlSubframes =
1247       rgSchTddNumDlSubfrmTbl[cell->ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
1248    lstSz = cell->raInfo.maxRaSize * RGSCH_MAX_RA_RNTI_PER_SUBFRM * \
1249                                                       maxUlSubframes;
1250 #else
1251    /* ccpu00133557- MEM LEAK FIX- Need to free all the nodes in RA Array list */
1252    lstSz = RGSCH_RAREQ_ARRAY_SIZE;
1253 #endif
1254
1255    for (idx = 0; idx < lstSz; idx++)
1256    {
1257       /* Delete and free raReqs stored */
1258       /* ccpu00133557- MEM LEAK FIX- Need to be freed till the count is non-zero */
1259       while(cell->raInfo.raReqLst[idx].count)
1260       {
1261          raReqInfo = (RgSchRaReqInfo *)(cell->raInfo.raReqLst[idx].first->node);
1262          cmLListDelFrm(&(cell->raInfo.raReqLst[idx]),&(raReqInfo->raReqLstEnt));
1263          /* ccpu00117052 - MOD - Passing double pointer
1264          for proper NULLP assignment*/
1265          rgSCHUtlFreeSBuf(inst, (Data **)&raReqInfo, sizeof(RgSchRaReqInfo));
1266       }
1267    }
1268
1269 #ifdef LTE_TDD
1270    /* Delete the RACH response list*/
1271       /* ccpu00117052 - MOD - Passing double pointer
1272       for proper NULLP assignment*/
1273    rgSCHUtlFreeSBuf(inst, 
1274          (Data **)(&(cell->rachRspLst)), sizeof(RgSchTddRachRspLst) * \
1275                                     maxDlSubframes);
1276 #endif
1277
1278    /* Delete raCbs in the "to be scheduled" list */
1279    /* ccpu00133557- MEM LEAK FIX- Need to be freed till the count is non-zero */
1280    while(cell->raInfo.toBeSchdLst.count)
1281    {
1282       raCb = (RgSchRaCb *)(cell->raInfo.toBeSchdLst.first->node);
1283       /* MSG4 Fix Start */
1284                   
1285       rgSCHRamRmvFrmRaInfoSchdLst(cell, raCb);
1286       /* MSG4 Fix End */          
1287    }
1288 #ifdef EMTC_ENABLE
1289    /* Delete raCbs in the "Emtc to be scheduled" list */
1290       if(cell->emtcEnable)
1291       {
1292           rgSCHRamRmvAllFrmEmtcRaInfoSchdLst(cell);
1293       }
1294 #endif
1295
1296    raCbCnt =  cell->raInfo.raCbLst.count;
1297
1298    /* Delete and free raCbs stored */ 
1299    for (idx = 0; idx < raCbCnt; idx++)
1300    {
1301       raCb = (RgSchRaCb *)(cell->raInfo.raCbLst.first->node);
1302       rgSCHRamDelRaCb(cell, raCb, TRUE);
1303    }
1304
1305    RETVALUE(ROK); 
1306 } /* rgSCHRamFreeCell */
1307 #ifdef RGR_V1
1308 #ifdef ANSI
1309 PRIVATE Void rgSCHRamProcContResExp
1310 (
1311 RgSchCellCb *cell,
1312 RgSchRaCb  *raCb
1313 )
1314 #else
1315 PRIVATE Void rgSCHRamProcContResExp (cell, raCb)
1316 RgSchCellCb *cell;
1317 RgSchRaCb  *raCb;
1318 #endif
1319 {
1320    TRC2(rgSCHRamProcContResExp);
1321    raCb->expiryTime.sfn = RGSCH_CONTRES_EXP;
1322    /*MSG4 Fix*/
1323    if (raCb->ue)
1324    {
1325       /* UE exists and RNTI will be released as part of UE DEL */          
1326       rgSCHRamDelRaCb(cell, raCb, FALSE);
1327    }
1328    else
1329    {
1330       /* Calling Release RNTI, which would perform Racb deletion
1331        * RNTI removal and RNTI release indication to MAC. */       
1332       /* Delete RACB and release RNTI */
1333       rgSCHRamDelRaCb(cell, raCb, TRUE);
1334    }
1335    RETVOID;
1336 }
1337
1338 #ifdef ANSI
1339 PRIVATE Void rgSCHRamProcContResGrdExp
1340 (
1341 RgSchCellCb *cell,
1342 RgSchRaCb  *raCb
1343 )
1344 #else
1345 PRIVATE Void rgSCHRamProcContResGrdExp (cell, raCb)
1346 RgSchCellCb  *cell;
1347 RgSchRaCb  *raCb;
1348 #endif
1349 {
1350    TRC2(rgSCHRamProcContResGrdExp)
1351
1352
1353 /*Guard timer has expired, schedule only the contention REsolution CE with 
1354  * zero bo*/
1355    raCb->dlCcchInfo.bo = 0; 
1356    /* SR_RACH_STATS : MSG4 WO CCCH SDU */
1357    rgNumMsg4WoCCCHSdu++;
1358
1359    /* add this to the "tobeSchdLst" */
1360    raCb->schdLnk.node = (PTR)(raCb);
1361    
1362    cmLListDelFrm(&cell->contResGrdTmrLst, &(raCb->contResTmrLnk));
1363    raCb->contResTmrLnk.node = NULLP;
1364
1365    /* MSG4 Fix Start */
1366    RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,
1367             "Con Res Grd Tmr exp RNTI:%d", 
1368             raCb->rntiLnk->rnti);   
1369    rgSCHRamAddToRaInfoSchdLst(cell, raCb);
1370    /* MSG4 Fix End */    
1371    RETVOID;
1372    
1373 }
1374 /**
1375  * @brief Check the Contention Resolution Guard Timer Expiry. 
1376  *
1377  * @details
1378  *
1379  *     Function: rgSCHChkContResTmrExp 
1380  *
1381  *
1382  *     Invoked by: Scheduler 
1383  *  @param[in] RgSchCellCb        *cell 
1384  *  @return  S16
1385  *      -# ROK 
1386  *      -# RFAILED 
1387  **/
1388 #ifdef ANSI
1389 PRIVATE Void rgSCHChkContResTmrExp
1390 (
1391 RgSchCellCb        *cell
1392 )
1393 #else
1394 PRIVATE Void rgSCHChkContResTmrExp(cell)
1395 RgSchCellCb        *cell;
1396 #endif
1397 {
1398    CmLList         *chkLnk    = NULLP;
1399    RgSchRaCb       *raCb = NULLP;
1400    
1401    TRC2(rgSCHChkContResTmrExp)
1402       
1403    chkLnk = cmLListFirst(&(cell->contResTmrLst));
1404    
1405    for (; chkLnk; chkLnk = chkLnk->next)
1406    {
1407       raCb = (RgSchRaCb *)(chkLnk->node);
1408       
1409       if(RGSCH_TIMEINFO_SAME(raCb->expiryTime, cell->crntTime))
1410       {
1411          /*If timer expired, call the handler function*/
1412          rgSCHRamProcContResExp(cell, raCb);
1413       }
1414           /*Fix: Need to traverse till end of list as the entries may not be in ascending order*/
1415    /*   else
1416       {
1417     break;
1418       }*/
1419    }
1420 }
1421 /**
1422  * @brief Check the Contention Resolution Guard Timer Expiry. 
1423  *
1424  * @details
1425  *
1426  *     Function: rgSCHChkContResGrdTmrExp 
1427  *
1428  *
1429  *     Invoked by: Scheduler 
1430  *  @param[in] RgSchCellCb        *cell 
1431  *  @return  S16
1432  *      -# ROK 
1433  *      -# RFAILED 
1434  **/
1435 #ifdef ANSI
1436 PRIVATE Void rgSCHChkContResGrdTmrExp
1437 (
1438 RgSchCellCb        *cell
1439 )
1440 #else
1441 PRIVATE Void rgSCHChkContResGrdTmrExp(cell)
1442 RgSchCellCb        *cell;
1443 #endif
1444 {
1445    CmLList         *chkLnk    = NULLP;
1446    RgSchRaCb       *raCb = NULLP;
1447    
1448    TRC2(rgSCHChkContResGrdTmrExp)
1449       
1450    chkLnk = cmLListFirst(&(cell->contResGrdTmrLst));
1451    
1452    /*[ccpu00131941]-MOD-List traversal should be done using the listCp */
1453    for (; chkLnk; chkLnk = cmLListNext(&cell->contResGrdTmrLst))
1454    {
1455       raCb = (RgSchRaCb *)(chkLnk->node);
1456       
1457       if(RGSCH_TIMEINFO_SAME(raCb->expiryTime, cell->crntTime))
1458       {
1459     /*If timer expired, call the handler function*/
1460     rgSCHRamProcContResGrdExp(cell, raCb);
1461       }
1462       else
1463       {
1464     break;
1465       }
1466    }
1467 }
1468 #endif
1469 #ifdef LTE_TDD
1470 /**
1471  * @brief Function for handling RACH Request deletion
1472  *
1473  * @details
1474  *
1475  *     Function : rgSCHRamDelRaReq
1476  *
1477  *     This function shall be invoked to delete the RACH Requests
1478  *     that is not scheduled within the RA window size.
1479  *
1480  *
1481  *  @param[in,out] RgSchCellCb      *cell
1482  *  @param[in]     CmLteTimingInfo  timingInfo
1483  *  @param[in]     U8               raIdx
1484  *  @return  S16
1485  *      -# ROK
1486  **/
1487 #ifdef ANSI
1488 PUBLIC S16 rgSCHRamDelRaReq
1489 (
1490 RgSchCellCb          *cell,
1491 CmLteTimingInfo      timingInfo,
1492 U8                   raIdx
1493 )
1494 #else
1495 PUBLIC S16 rgSCHRamDelRaReq(cell, timingInfo, raIdx)
1496 RgSchCellCb          *cell;
1497 CmLteTimingInfo      timingInfo;
1498 U8                   raIdx;
1499 #endif
1500 {
1501    U8                   subfrmIdx;
1502    RgSchTddRachRspLst   *rachRsp;
1503    U16                   sfnIdx;
1504    S16                  calcSfn;
1505    U8                   subfrm;
1506    RgSchRaReqInfo       *raReqInfo;
1507    U8                   idx;
1508    U8                   i;
1509    U8                   raRntiIdx;
1510    CmLteRnti            raRnti;
1511
1512    TRC2(rgSCHRamDelRaReq)
1513
1514
1515    rachRsp = &cell->rachRspLst[raIdx];
1516    /* Get the SFN Index to be deleted */
1517    calcSfn = timingInfo.sfn - rachRsp->delInfo.sfnOffset;
1518    if(calcSfn < 0)
1519    {
1520       sfnIdx = (calcSfn + RGSCH_MAX_SFN) % cell->raInfo.maxRaSize;
1521    }
1522    else
1523    {
1524       sfnIdx = calcSfn;
1525    }
1526
1527    /* Iterate through all the subframes to be delted in the SFN */
1528    for(subfrmIdx=0; subfrmIdx < rachRsp->delInfo.numSubfrms; subfrmIdx++)
1529    {
1530       subfrm = rachRsp->delInfo.subframe[subfrmIdx];
1531       /* Get the subframe Index to be deleted */
1532       /* Fixes for RACH handling in TDD: 
1533        * Corrected the computation of raRntiIdx
1534        * */
1535       raRntiIdx = ((sfnIdx % cell->raInfo.maxRaSize) * \
1536                      RGSCH_MAX_RA_RNTI_PER_SUBFRM * \
1537                      RGSCH_NUM_SUB_FRAMES) + subfrm;
1538
1539       /* Iterate through all the RNTIs in the subframe */
1540       for(i=0; i < RGSCH_MAX_RA_RNTI_PER_SUBFRM; i++)
1541       {
1542          raRnti = raRntiIdx + (i*RGSCH_NUM_SUB_FRAMES);
1543          for (idx = 0; idx < cell->raInfo.raReqLst[raRnti].count; idx++)
1544          {
1545             raReqInfo = 
1546                (RgSchRaReqInfo *)(cell->raInfo.raReqLst[raRnti].first->node);
1547             cmLListDelFrm(&(cell->raInfo.raReqLst[raRnti]),
1548                                     &(raReqInfo->raReqLstEnt));
1549             /* ccpu00117052 - MOD - Passing double pointer
1550             for proper NULLP assignment*/
1551             rgSCHUtlFreeSBuf(cell->instIdx,
1552                               (Data **)&raReqInfo, sizeof(RgSchRaReqInfo));
1553          }
1554       }
1555    }
1556
1557    RETVALUE(ROK);
1558 }
1559 #endif
1560
1561 /*MSG4 Fix Start */
1562 #ifdef ANSI
1563 PUBLIC S16 rgSCHRamAddToRaInfoSchdLst
1564 (
1565 RgSchCellCb       *cell,
1566 RgSchRaCb         *raCb
1567 )
1568 #else
1569 PUBLIC S16 rgSCHRamAddToRaInfoSchdLst(cell, raCb)
1570 RgSchCellCb       *cell;
1571 RgSchRaCb         *raCb;
1572 #endif
1573 {
1574    CmLteTimingInfo expTime ={0};
1575    RgSchCmnCell    *cellSch =  RG_SCH_CMN_GET_CELL(cell);
1576
1577    TRC2(rgSCHRamAddToRaInfoSchdLst)
1578
1579    /*Fix: This can be called even when guard timer is not expired. 
1580        * In this case CR timer expiry should be guard timer expiry time + Guard timer time*/
1581    RG_SCH_ADD_TO_CRNT_TIME(raCb->expiryTime, expTime, cellSch->dl.msg4TxDelay);
1582    raCb->expiryTime = expTime;
1583    raCb->schdLnk.node = (PTR)(raCb);
1584    cmLListAdd2Tail(&(cell->raInfo.toBeSchdLst), &(raCb->schdLnk));
1585    raCb->contResTmrLnk.node = (PTR)(raCb);
1586    cmLListAdd2Tail(&(cell->contResTmrLst), &(raCb->contResTmrLnk));
1587    RETVALUE(ROK);
1588 } /* rgSCHRamAddToRaInfoSchdLst */
1589
1590
1591
1592 #ifdef ANSI
1593 PUBLIC S16 rgSCHRamRmvFrmRaInfoSchdLst
1594 (
1595 RgSchCellCb       *cell,
1596 RgSchRaCb         *raCb
1597 )
1598 #else
1599 PUBLIC S16 rgSCHRamRmvFrmRaInfoSchdLst(cell, raCb)
1600 RgSchCellCb       *cell;
1601 RgSchRaCb         *raCb;
1602 #endif
1603 {
1604    TRC2(rgSCHRamRmvFrmRaInfoSchdLst)
1605
1606    cmLListDelFrm(&(cell->raInfo.toBeSchdLst), &(raCb->schdLnk));
1607    raCb->schdLnk.node = NULLP;   
1608    cmLListDelFrm(&(cell->contResTmrLst), &(raCb->contResTmrLnk));
1609    raCb->contResTmrLnk.node = NULLP;
1610    RETVALUE(ROK);
1611 } /* rgSCHRamRmvFrmRaInfoSchdLst */
1612
1613 /*MSG4 Fix End*/
1614
1615 /***********************************************************
1616  *
1617  *     Func : rgSCHRamUlFreeAllocation
1618  *
1619  *     Desc : Free an allocation - invokes UHM and releases
1620  *            alloc
1621  *
1622  *     Ret  :
1623  *
1624  *     Notes:
1625  *
1626  *     File :
1627  *
1628  **********************************************************/
1629 #ifdef ANSI
1630 PRIVATE Void rgSCHRamUlFreeAllocation
1631 (
1632 RgSchUlSf       *sf,
1633 RgSchUlAlloc    *alloc,
1634 RgSchCellCb     *cell,
1635 Bool            isEmtc
1636
1637 )
1638 #else
1639 PRIVATE Void rgSCHRamUlFreeAllocation(sf, alloc, cell,isEmtc)
1640 RgSchUlSf       *sf;
1641 RgSchUlAlloc    *alloc;
1642 RgSchCellCb     *cell;
1643 Bool            isEmtc;
1644 #endif
1645 {
1646    TRC2(rgSCHRamUlFreeAllocation);
1647
1648    rgSCHUhmFreeProc(alloc->hqProc, cell);
1649    if(!isEmtc)
1650    {
1651       rgSCHUtlUlAllocRls(sf, alloc);
1652    }
1653    RETVOID;
1654 }
1655
1656 /**********************************************************************
1657  
1658          End of file
1659 **********************************************************************/