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