replaced cmMemSet, cmMemcpy with memset and memcpy resp AND Removed TRC() traces...
[o-du/l2.git] / src / 5gnrsch / rg_sch_utl.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_utl.c
28
29 **********************************************************************/
30
31 /** @file rg_sch_utl.c
32 @brief This file implements the schedulers main access to MAC layer code.
33 */
34
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_MODULE_ID=4096;
37 static int RLOG_FILE_ID=177;
38
39 /* header include files -- defines (.h) */
40 #include "common_def.h"
41 #include "lrg.h"
42 #include "rgr.h"
43 #include "tfu.h"
44 #include "rg_env.h"
45 #include "rg_sch_err.h"
46 #include "rg_sch_inf.h"
47 #include "rg_sch.h"
48 #include "rg_sch_cmn.h"
49 #include "rgm.h"
50 #include "rl_interface.h"
51 #include "rl_common.h"
52
53 /* header/extern include files (.x) */
54 #include "tfu.x"           /* TFU types */
55 #include "lrg.x"           /* layer management typedefs for MAC */
56 #include "rgr.x"           /* layer management typedefs for MAC */
57 #include "rgm.x"
58 #include "rg_sch_inf.x"         /* typedefs for Scheduler */
59 #include "rg_sch.x"        /* typedefs for Scheduler */
60 #include "rg_sch_cmn.x"        /* typedefs for Scheduler */
61 #ifdef EMTC_ENABLE
62 #include "rg_sch_emtc_ext.x"
63 #endif
64
65
66 /* SR_RACH_STATS */
67 U32 rgNumPrachRecvd =0;       /* Num of Rach Req received including dedicated preambles */
68 U32 rgNumRarSched =0;         /* Num of RARs sent */
69 U32 rgNumBI =0;               /* Num of BackOff Ind sent */
70 U32 rgNumMsg3CrcPassed =0;    /* Num of CRC success for Msg3 */
71 U32 rgNumMsg3CrcFailed =0;    /* Num of CRC fail for Msg 3 */
72 U32 rgNumMsg3FailMaxRetx =0;  /* Num of Msg3 fail after Max Retx attempts */
73 U32 rgNumMsg4Ack =0;          /* Num of Acks for Msg4 Tx */
74 U32 rgNumMsg4Nack =0; 
75        /* Num of Nacks for Msg4 Tx */
76 U32 rgNumMsg4FailMaxRetx =0;  /* Num of Msg4 Tx failed after Max Retx attempts */
77 U32 rgNumSrRecvd =0;          /* Num of Sched Req received */
78 U32 rgNumSrGrant =0;          /* Num of Sched Req Grants sent */
79 U32 rgNumMsg3CrntiCE =0;      /* Num of Msg 3 CRNTI CE received */
80 U32 rgNumDedPream =0;         /* Num of Dedicated Preambles recvd */
81 U32 rgNumMsg3CCCHSdu =0;      /* Num of Msg 3 CCCH Sdus recvd */
82 U32 rgNumCCCHSduCrntiNotFound =0;  /*UE Ctx not found for CCCH SDU Msg 3 */
83 U32 rgNumCrntiCeCrntiNotFound =0;  /*UE Ctx not found for CRNTI CE Msg 3 */
84 U32 rgNumMsg4WithCCCHSdu =0;       /* Num of Msg4 with CCCH Sdu */
85 U32 rgNumMsg4WoCCCHSdu =0;         /* Num of Msg4 without CCCH Sdu */
86 U32 rgNumMsg4Dtx =0;               /* Num of DTX received for Msg 4 */
87 U32 rgNumMsg3AckSent =0;           /* Num of PHICH Ack sent for Msg 3 */
88 U32 rgNumMsg3NackSent =0;          /* Num of PHICH Nack sent for Msg 3 */
89 U32 rgNumMsg4PdcchWithCrnti =0;    /* Num of PDCCH for CRNTI based contention resolution */
90 U32 rgNumRarFailDuetoRntiExhaustion =0; /* Num of RACH Failures due to RNTI pool exhaution */
91 U32 rgNumTAModified =0;            /* Num of times TA received is different from prev value */
92 U32 rgNumTASent =0;               /* Num of TA Command sent */
93 U32 rgNumMsg4ToBeTx =0;           /* Num of times MSG4 that should be sent */
94 U32 rgNumMsg4Txed =0;             /* Num of MSG4 actually sent *//* ysNumMsg4ToBeTx -ysNumMsg4Txed == Failed MSG4 TX */
95 U32 rgNumMsg3DtxRcvd  =0;         /* CRC Fail with SINR < 0 */
96
97 U32 rgNumDedPreamUECtxtFound =0;         /* Num of Dedicated Preambles recvd */
98
99 PRIVATE U8 rgSchDciAmbigSizeTbl[61] = {0,0,0,0,0,0,0,0,0,0,0,
100                          0,1,0,1,0,1,0,0,0,1,
101                          0,0,0,1,0,1,0,0,0,0,
102                          0,1,0,0,0,0,0,0,0,1,
103                          0,0,0,1,0,0,0,0,0,0,
104                          0,0,0,0,0,1,0,0,0,0};
105
106 /* local defines */
107
108 EXTERN U32 rgSchCmnBetaCqiOffstTbl[16];
109 EXTERN U32 rgSchCmnBetaRiOffstTbl[16]; 
110 EXTERN RgSchdApis rgSchCmnApis;
111 EXTERN S16 RgUiRgmSendPrbRprtInd ARGS((
112 Pst* pst, 
113 SuId suId, 
114 RgmPrbRprtInd *prbRprtInd
115 ));
116
117 EXTERN S16 RgUiRgmSendTmModeChangeInd ARGS((
118 Pst* pst, 
119 SuId suId, 
120 RgmTransModeInd *txModeChngInd
121 ));
122 #ifdef EMTC_ENABLE
123 EXTERN S16 rgSCHEmtcUtlGetSfAlloc ARGS((
124 RgSchCellCb *cell
125 ));
126 EXTERN S16 rgSCHEmtcUtlPutSfAlloc ARGS((
127 RgSchCellCb *cell
128 ));
129 EXTERN Void rgSCHEmtcUtlUpdUeDciSize ARGS((
130 RgSchCellCb *cell,
131 RgSchUeCb *ueCb
132 ));
133 EXTERN Void rgSCHEmtcGetDciFrmt61ASize ARGS((
134 RgSchCellCb *cell
135 ));
136 EXTERN Void rgSCHEmtcGetDciFrmt60ASize ARGS((
137 RgSchCellCb *cell
138 ));
139 EXTERN S16 rgSCHEmtcUtlFillPdschDciInfo ARGS((
140 TfuPdschDciInfo *pdsch,
141 TfuDciInfo      *pdcchDci
142 ));
143 EXTERN Void rgSCHEmtcUtlRlsRnti ARGS((
144 RgSchCellCb *cell,
145 RgSchRntiLnk   *rntiLnk,
146 U8             *isLegacy
147 ));
148 EXTERN S16 rgSCHEmtcPdcchAlloc ARGS((
149 RgSchCellCb *cell,
150 RgSchPdcch  *pdcch
151 ));
152 EXTERN Void rgSCHEmtcPdcchFree ARGS((
153 RgSchCellCb *cell,
154 RgSchPdcch  *pdcch
155 ));
156 #endif
157 /* Functions specific to TM1/TM2/TM6/TM7 for PRB calculation*/
158 Void rgSchUtlDlCalc1CwPrb ARGS(( RgSchCellCb    *cell,
159                                         RgSchUeCb      *ue,
160                                         U32             bo,
161                                         U32            *prbReqrd));
162
163 /* Functions specific to TM3/TM4 for PRB calculation*/
164 Void rgSchUtlDlCalc2CwPrb ARGS(( RgSchCellCb    *cell,
165                                         RgSchUeCb      *ue,
166                                         U32             bo,
167                                         U32            *prbReqrd));
168
169 #ifdef LTE_ADV
170 RgSchCellCb* rgSchUtlGetCellCb ARGS(( Inst       inst,
171                                              U16        cellId
172 ));
173 #endif
174
175 typedef Void (*RgSchUtlDlCalcPrbFunc) ARGS((RgSchCellCb *cell, RgSchUeCb *ue,
176                                             U32 bo, U32 *prbRequrd));
177 #ifndef LTE_ADV
178 /* Functions specific to each transmission mode for PRB calculation*/
179 RgSchUtlDlCalcPrbFunc  dlCalcPrbFunc[7] = {rgSchUtlDlCalc1CwPrb,
180 rgSchUtlDlCalc1CwPrb, rgSchUtlDlCalc2CwPrb, rgSchUtlDlCalc2CwPrb,
181 NULLP, rgSchUtlDlCalc1CwPrb, rgSchUtlDlCalc1CwPrb};
182
183 #else
184 /* Functions specific to each transmission mode for PRB calculation*/
185 RgSchUtlDlCalcPrbFunc  dlCalcPrbFunc[9] = {rgSchUtlDlCalc1CwPrb,
186 rgSchUtlDlCalc1CwPrb, rgSchUtlDlCalc2CwPrb, rgSchUtlDlCalc2CwPrb,
187 NULLP, rgSchUtlDlCalc1CwPrb, rgSchUtlDlCalc1CwPrb, NULLP, NULLP};
188
189 #endif
190
191 #ifdef LTE_TDD
192 /* The below table will be used to map the UL SF number in a TDD Cfg 0 
193    frame to the ul Sf array maintained in cellCb */
194 PRIVATE U8  rgSchTddCfg0UlSfTbl[] = {2, 3, 4, 7, 8, 9};
195 #endif
196
197 PRIVATE S16 rgSCHUtlUlAllocDbInit ARGS((
198          RgSchCellCb    *cell,
199          RgSchUlAllocDb *db,
200          U8 maxAllocs
201          ));
202 PRIVATE Void rgSCHUtlUlAllocDbDeinit ARGS((
203          RgSchCellCb    *cell,
204          RgSchUlAllocDb *db
205          ));
206 PRIVATE S16 rgSCHUtlUlHoleDbInit ARGS((
207          RgSchCellCb    *cell,
208          RgSchUlHoleDb *db,
209          U8 maxHoles,
210          U8 start,
211          U8 num
212          ));
213 PRIVATE Void rgSCHUtlUlHoleDbDeinit ARGS((
214          RgSchCellCb   *cell,
215          RgSchUlHoleDb *db
216          ));
217
218 PRIVATE S16 rgSCHChkBoUpdate ARGS((
219          RgSchCellCb    *cell,
220          RgInfCmnBoRpt  *boUpdt
221          ));
222 #ifdef UNUSE_FUN
223 #ifdef TFU_UPGRADE
224 PRIVATE U8 rgSCHUtlFetchPcqiBitSz ARGS((
225  RgSchCellCb    *cell,
226  RgSchUeCb    *ueCb, 
227  U8           numTxAnt
228  ));
229 #endif
230 #endif
231 /* sorted in ascending order of tbSz */
232 CONSTANT struct rgSchUtlBcchPcchTbSz
233 {
234    U8   rbIndex;    /* RB index {2,3} */
235    U16  tbSz;       /* one of the Transport block size in bits of
236                      * rbIndex 2 or 3 */
237    /* Corrected allocation for common channels */
238    U8   mcs;        /* imcs */
239 } rgSchUtlBcchPcchTbSzTbl[44] = {
240    { 2,   32,  0 }, { 2,   56,  1 }, { 2,   72,  2 }, { 3,   88,  1 },
241    { 2,  104,  3 }, { 2,  120,  4 }, { 2,  144,  5 }, { 2,  176,  6 },
242    { 3,  208,  4 }, { 2,  224,  7 }, { 2,  256,  8 }, { 2,  296,  9 },
243    { 2,  328, 10 }, { 2,  376, 11 }, { 3,  392,  8 }, { 2,  440, 12 },
244    { 3,  456,  9 }, { 2,  488, 13 }, { 3,  504, 10 }, { 2,  552, 14 },
245    { 3,  584, 11 }, { 2,  600, 15 }, { 2,  632, 16 }, { 3,  680, 12 },
246    { 2,  696, 17 }, { 3,  744, 13 }, { 2,  776, 18 }, { 2,  840, 19 },
247    { 2,  904, 20 }, { 3,  968, 16 }, { 2, 1000, 21 }, { 2, 1064, 22 },
248    { 2, 1128, 23 }, { 3, 1160, 18 }, { 2, 1192, 24 }, { 2, 1256, 25 },
249    { 3, 1288, 19 }, { 3, 1384, 20 }, { 2, 1480, 26 }, { 3, 1608, 22 },
250    { 3, 1736, 23 }, { 3, 1800, 24 }, { 3, 1864, 25 }, { 3, 2216, 26 }
251 };
252
253 /* local typedefs */
254
255 /* local externs */
256
257 /* forward references */
258 #ifdef LTE_TDD
259 PRIVATE Void rgSCHUtlUpdPrachOcc ARGS((
260 RgSchCellCb *cell,
261 RgrTddPrachInfo *cellCfg));
262 #endif
263
264 #define RGSCH_NUM_PCFICH_REG 4
265 #define RGSCH_NUM_REG_PER_CCE 9
266 #define RGSCH_NUM_REG_PER_PHICH_GRP 3
267
268 #ifdef LTE_TDD
269 #define RGSCH_INITPHICH(_phich, _hqFeedBack, _nDmrs, _rbStart, _iPhich) {\
270    (_phich)->hqFeedBack = _hqFeedBack; \
271    (_phich)->rbStart = _rbStart; \
272    (_phich)->nDmrs = _nDmrs; \
273    (_phich)->iPhich = _iPhich; \
274    (_phich)->lnk.next = NULLP; \
275    (_phich)->lnk.prev = NULLP; \
276    (_phich)->lnk.node = (PTR)(_phich); \
277 }
278 #else
279 #define RGSCH_INITPHICH(_phich, _hqFeedBack, _nDmrs, _rbStart, _isForMsg3) {\
280    (_phich)->hqFeedBack = _hqFeedBack; \
281    (_phich)->rbStart = _rbStart; \
282    (_phich)->nDmrs = _nDmrs; \
283    (_phich)->isForMsg3 = _isForMsg3; \
284    (_phich)->lnk.next = NULLP; \
285    (_phich)->lnk.prev = NULLP; \
286    (_phich)->lnk.node = (PTR)(_phich); \
287 }
288 #endif
289
290 #define RGSCH_PHICH_ALLOC(_inst,_dataPtr, _size, _ret) {\
291    _ret = rgSCHUtlAllocSBuf(_inst, (Data **)&_dataPtr, _size); \
292 }
293
294 /* ccpu00117052 - MOD - Passing double pointer
295 for proper NULLP assignment*/
296 #define RGSCH_PHICH_FREE(_inst, _dataPtr, _size) {\
297       rgSCHUtlFreeSBuf(_inst, (Data **)(&(_dataPtr)), _size); \
298 }
299
300 #ifdef TFU_UPGRADE
301 #define RGSCH_GETBIT(a, b)     ((((U8*)a)[(b)>>3] >> ((7-((b)&7)))) & 1)
302
303 /*
304 *
305 *       Fun:   rgSCHUtlPower
306 *
307 *       Desc:  This function finds of the Power of x raised to n
308 *
309 *       Ret:   value of x raised to n
310 *
311 *       Notes: None
312 *
313 *       File:  rg_sch_utl.c
314 *
315 */
316 #ifdef ANSI
317 F64 rgSCHUtlPower
318 (
319 F64    x,
320 F64    n
321 )
322 #else
323 F64 rgSCHUtlPower(x, n)
324 F64    x;
325 F64    n;
326 #endif
327 {
328  if( n==0 )
329  {
330    return ( 1 );
331  }
332  else if ( n>0 )
333  {
334    return ( x * rgSCHUtlPower( x, n-1 ) );
335  }
336  else
337  {
338    return ( (1/x) * rgSCHUtlPower( x, n+1 ) );
339  }
340 } /* end of rgSCHUtlPower*/
341
342 /*
343 *
344 *       Fun:   rgSCHUtlParse
345 *
346 *       Desc:  This function parses bits x to y of an array and
347 *                  returns the integer value  out of it.
348 *
349 *       Ret:   integer value of z bits
350 *
351 *       Notes: None
352 *
353 *       File:  rg_sch_utl.c
354 *
355 */
356 #ifdef ANSI
357 U32 rgSCHUtlParse
358 (
359 U8     *buff,
360 U8     startPos,
361 U8     endPos,
362 U8     buffSize
363 )
364 #else
365 U32 rgSCHUtlParse(buff, startPos, endPos, buffSize)
366 U8     *buff;
367 U8     startPos;
368 U8     endPos;
369 U8     buffSize;
370 #endif
371 {
372  U8 pointToChar,pointToEnd, loop;
373  U8 size =  endPos - startPos;
374  F64 result = 0;
375  pointToEnd = (startPos)%8;
376    for ( loop=0; loop<size; loop++)
377    {
378       pointToChar = (((startPos)+loop)/8);
379       if (RGSCH_GETBIT(buff+pointToChar,pointToEnd%8)==1)
380       {
381          result=result+(rgSCHUtlPower(2,(size-loop-1)));
382       }
383       pointToEnd++;
384    }
385    return ((U32)result);
386 } /* end of rgSCHUtlParse*/
387
388 /*
389 *
390 *       Fun:   rgSCHUtlFindDist
391 *
392 *       Desc:  This function calculates the iterations need to cover
393 *                  before the valid Index can be used for next possible Reception
394 *
395 *       Ret:   integer value of z bits
396 *
397 *       Notes: None
398 *
399 *       File:  rg_sch_utl.c
400 *
401 */
402 #ifdef ANSI
403 U8 rgSCHUtlFindDist
404 (
405 U16    crntTime,
406 U16    tempIdx
407 )
408 #else
409 U8 rgSCHUtlFindDist(crntTime, tempIdx)
410 U16    crntTime;
411 U16    tempIdx;
412 #endif
413 {
414  U8  dist =0;
415  /* ccpu00137113- Distance is not estimated properly if the periodicity is 
416   * equal to RG_SCH_PCQI_SRS_SR_TRINS_SIZE.
417   */
418  while(crntTime<=tempIdx)
419  {
420     crntTime += RG_SCH_PCQI_SRS_SR_TRINS_SIZE;
421     dist+=1;
422  }
423  return (dist-1);
424 } /* end of rgSCHUtlFindDist*/
425 #endif
426
427 \f
428 /**
429  * @brief This function checks availability of a PDCCH
430  *
431  * @details
432  *
433  *     Function: rgSCHUtlPdcchAvail
434  *     Purpose:  This function checks if a particular PDCCH is in use.
435  *               map field of PDCCH is used to track the CCEs arleady
436  *               allocated. Each bit of map represents one CCE and the
437  *               LSBit of first byte represents CCE 0.
438  *               steps:
439  *               1. Locate the set of bits that represent the PDCCH for
440  *               the provided location.
441  *               2.  If the value of the bits is non-zero one or many CCEs
442  *               for the PDCCH are in use and hence the PDCCH is not available.
443  *               3. If pdcch is available, assign it to [out]pdcch.
444  *               4.  Set all of the bits to one. There is no check performed
445  *               to see if the PDCCH is available.
446  *
447  *     Invoked by: scheduler
448  *
449  *  @param[in]  RgSchCellCb*     cell
450  *  @param[in]  RgSchPdcchInfo*  pdcchInfo
451  *  @param[in]  U8            loc
452  *  @param[in]  U8            aggrLvl
453  *  @param[out] RgSchPdcch**     pdcch
454  *  @return  Boolean
455  *         -#   TRUE  if available
456  *         -#   FALSE otherwise
457  *
458  **/
459 #ifdef ANSI
460 Bool rgSCHUtlPdcchAvail
461 (
462 RgSchCellCb             *cell,
463 RgSchPdcchInfo          *pdcchInfo,
464 CmLteAggrLvl            aggrLvl,
465 RgSchPdcch              **pdcch
466 )
467 #else
468 Bool rgSCHUtlPdcchAvail(cell, pdcchInfo, aggrLvl, pdcch)
469 RgSchCellCb             *cell;
470 RgSchPdcchInfo          *pdcchInfo;
471 CmLteAggrLvl            aggrLvl;
472 RgSchPdcch              **pdcch;
473 #endif
474 {
475    U8                                                   *byte;
476    U16                                          offset;
477         U16                  initMask;
478         U16                  currMask;
479    Inst                 inst = cell->instIdx;
480    S16                  ret;
481         U16                  offsetStepMask;
482
483    /* V5G_213 : 10.1 */
484         offset = 0;
485         byte = &pdcchInfo->map[0];
486         initMask = (0xffff >> (16 - aggrLvl));
487         currMask = initMask;
488         /* if N(symbol, xPDCCH) =2, then xPDCCH will be candidates in 
489           * search space of index {0,1,2,3} and {8,9,..14}
490           */
491         if ((cell->cell5gtfCb.cfi == 2) && (aggrLvl == CM_LTE_AGGR_LVL2))
492         {
493                 offsetStepMask = 0xc;
494         }
495         else
496         {
497                 offsetStepMask = 0xc0;
498         }
499
500         /* Loop till the number of bytes available in the CCE map */
501         while (offset < ((pdcchInfo->nCce+ 7) >> 3))
502         {
503            byte = &pdcchInfo->map[offset];
504                 /* Checking for available CCE */
505                 if ((*byte & currMask) == 0)
506            {
507               break;
508            }
509                 /* if the number of CCEs required are not available, move to next offset */
510                 if (currMask & offsetStepMask)
511                 {
512                         offset++;
513                         currMask = initMask;
514                 }
515                 else
516                 {
517                    /* Move to the next available CCE index in the current byte(cce map) */
518                         currMask = currMask << aggrLvl;
519                 }
520         }
521
522         if ((offset >= ((pdcchInfo->nCce + 7) >> 3)) || 
523                   ((aggrLvl == CM_LTE_AGGR_LVL16) && (offset > 0)))
524         {
525                 return (FALSE);
526         }
527
528         byte = &pdcchInfo->map[offset];
529    
530    if (cell->pdcchLst.first != NULLP)
531    {
532       *pdcch = (RgSchPdcch *)(cell->pdcchLst.first->node);
533       cmLListDelFrm(&cell->pdcchLst, cell->pdcchLst.first);
534    }
535    else
536    {
537       ret = rgSCHUtlAllocSBuf(inst, (Data **)pdcch, sizeof(RgSchPdcch));
538       if(ROK != ret)
539       {
540          return (FALSE);
541       }
542    }
543
544    if (*pdcch)
545    {
546       (*byte) |= currMask;
547                 /* ALL CCEs will be used in case of level 16 */
548                 if (aggrLvl == CM_LTE_AGGR_LVL16)
549                 {
550                         *(byte+1) |= currMask;
551                 }
552       (*pdcch)->aggrLvl = aggrLvl;
553       cmLListAdd2Tail(&pdcchInfo->pdcchs, &((*pdcch)->lnk));
554       (*pdcch)->lnk.node = (PTR)*pdcch;
555       (*pdcch)->nCce = aggrLvl;
556       (*pdcch)->ue = NULLP;
557    }
558    return (TRUE);
559 }
560
561
562 \f
563 /**
564  * @brief This function releases a PDCCH
565  *
566  * @details
567  *
568  *     Function: rgSCHUtlPdcchPut
569  *     Purpose:  This function releases a PDCCH.
570  *               steps:
571  *               1. Locate the set of bits that represent the PDCCH for
572  *               the provided location.
573  *               2. Set all of the bits to zero.
574  *               3. Release the memory of PDCCH to the cell free Q
575  *
576  *     Invoked by: scheduler
577  *
578  *  @param[in]  RgSchPdcchInfo*  pdcchInfo
579  *  @param[in]  U8            loc
580  *  @param[in]  U8            aggrLvl
581  *  @return     Void
582  *
583  **/
584 #ifdef ANSI
585 Void rgSCHUtlPdcchPut
586 (
587 RgSchCellCb                *cell,
588 RgSchPdcchInfo             *pdcchInfo,
589 RgSchPdcch                 *pdcch
590 )
591 #else
592 Void rgSCHUtlPdcchPut(cell, pdcchInfo, pdcch)
593 RgSchCellCb                *cell;
594 RgSchPdcchInfo             *pdcchInfo;
595 RgSchPdcch                 *pdcch;
596 #endif
597 {
598    U8                   *byte;
599    U8                   offset;
600    uint16_t             mask;
601
602    switch(pdcch->aggrLvl)
603    {
604       case CM_LTE_AGGR_LVL2:
605          offset = (pdcch->nCce >> 1) & 3;
606          mask = 0x3 << (offset * 2); /*ccpu00128826 - Offset Correction */
607          break;
608       case CM_LTE_AGGR_LVL4:
609          offset = (pdcch->nCce >> 2) & 1;
610          mask = 0xf << (offset * 4);/*ccpu00128826 - Offset Correction */
611          break;
612       case CM_LTE_AGGR_LVL8:
613          mask = 0xff;
614          break;
615                 case CM_LTE_AGGR_LVL16:
616          mask = 0xffff;
617          break;
618       default:
619          RETVOID;
620    }
621    /* Placing common computation of byte from all the cases above here
622       for optimization */
623    byte = &pdcchInfo->map[pdcch->nCce >> 3];
624
625    cmLListDelFrm(&pdcchInfo->pdcchs, &pdcch->lnk);
626    cmLListAdd2Tail(&cell->pdcchLst, &pdcch->lnk);
627    pdcch->lnk.node = (PTR)pdcch;
628    pdcch->ue = NULLP;
629    (*byte) &= ~mask;
630
631   RETVOID;
632 }
633
634 \f
635 /**
636  * @brief This function initializes PDCCH information for frame
637  *
638  * @details
639  *
640  *     Function: rgSCHUtlPdcchInit
641  *     Purpose:  This function initializes PDCCH information for
642  *               a slot. It removes the list of PDCCHs allocated
643  *               in the prior use of this slot structure.
644  *
645  *     Invoked by: rgSCHUtlSubFrmPut
646  *
647  *  @param[in]  RgSchCellCb*     cell
648  *  @param[in]  RgSubFrm*     subFrm
649  *  @return  Void
650  *
651  **/
652 #ifdef ANSI
653 Void rgSCHUtlPdcchInit
654 (
655 RgSchCellCb             *cell,
656 RgSchDlSf               *subFrm,
657 U16                     nCce
658 )
659 #else
660 Void rgSCHUtlPdcchInit(cell, subFrm, nCce)
661 RgSchCellCb             *cell;
662 RgSchDlSf               *subFrm;
663 U16                     nCce;
664 #endif
665 {
666    RgSchPdcchInfo       *pdcchInfo;
667    RgSchPdcch           *pdcch;
668    Inst                 inst = cell->instIdx;
669    U8                   extraBits;
670    U32                  cceMapSz;
671
672    pdcchInfo = &subFrm->pdcchInfo;
673    while(pdcchInfo->pdcchs.first != NULLP)
674    {
675       pdcch = (RgSchPdcch *)pdcchInfo->pdcchs.first->node;
676       cmLListDelFrm(&pdcchInfo->pdcchs, pdcchInfo->pdcchs.first);
677       cmLListAdd2Tail(&cell->pdcchLst, &pdcch->lnk);
678       pdcch->ue = NULLP;
679    }
680    cmLListInit(&pdcchInfo->pdcchs);
681    
682 #ifdef LTEMAC_SPS
683    subFrm->relPdcch = NULLP;
684 #endif
685    
686    cceMapSz = ((pdcchInfo->nCce + 7) >> 3);
687
688         /* The bitMap array size is the number of ceiling(CCEs/8) */
689         /* If nCce received is not the same as the one stored in    
690         * pdcchInfo, free the pdcchInfo map                      */
691
692    if(pdcchInfo->nCce != nCce)
693    {
694       if(pdcchInfo->nCce)
695       {
696         rgSCHUtlFreeSBuf(inst, (Data **)(&(pdcchInfo->map)), cceMapSz);
697       }
698       pdcchInfo->nCce = nCce;
699       cceMapSz = ((pdcchInfo->nCce + 7) >> 3);
700       rgSCHUtlAllocSBuf(inst, (Data **)&pdcchInfo->map,  
701       cceMapSz);
702       if (pdcchInfo->map == NULLP)
703       {
704          /* Generate log error here */
705          RETVOID;
706       }    
707    }
708
709    memset(subFrm->pdcchInfo.map, 0, cceMapSz);
710    /*   If nCce is not exactly same as the bitMap size(no of bits allocated
711         * to represent the Cce's, then mark the extra bits as unavailable
712         extra bits = (((pdcchInfo->nCce + 7) >> 3)*8) - pdcchInfo->nCce
713         The last byte of bit map = subFrm->pdcchInfo.map[((pdcchInfo->nCce + 7) >> 3) - 1]
714          NOTE : extra bits are most significant of the last byte eg.  */
715    extraBits = (cceMapSz)*8 - pdcchInfo->nCce;
716    subFrm->pdcchInfo.map[cceMapSz - 1] |=
717      ((1 << extraBits) - 1) << (8 - extraBits);
718    RETVOID;
719 }
720
721 /* LTE_ADV_FLAG_REMOVED_START */
722 /**
723  * @brief This function frees Pool
724  * @details
725  *
726  *     Function: rgSchSFRTotalPoolFree
727  *
728  *     Invoked by: rgSchSFRTotalPoolInit
729  *
730  *  @param[in]  RgSchCellCb*     cell
731  *  @param[in]  RgSubFrm*     subFrm
732  *  @return  Void
733  *
734  **/
735 #ifdef ANSI
736 Void rgSchSFRTotalPoolFree
737 (
738  RgSchSFRTotalPoolInfo  *sfrTotalPoolInfo,
739  RgSchCellCb             *cell
740  )
741 #else
742 Void rgSchSFRTotalPoolFree(sfrTotalPoolInfo, cell)
743    RgSchSFRTotalPoolInfo  *sfrTotalPoolInfo;
744    RgSchCellCb             *cell;
745 #endif
746 {
747    CmLListCp   *l;
748    CmLList     *n;
749
750    /*Deinitialise if  these cc pools and ce pools are already existent*/
751    l = &sfrTotalPoolInfo->ccPool;
752    n = cmLListFirst(l);
753    while (n != NULL)
754    {
755       /*REMOVING Cell Centred POOLS IF ANY*/
756       n = cmLListDelFrm(l, n);
757
758       /* Deallocate buffer */
759       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(n->node)), sizeof(RgSchSFRPoolInfo));
760
761       /* Deallocate buffer */
762       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(n)), sizeof(CmLList));   
763       n = cmLListNext(l);
764    }
765
766    /*REMOVING Cell Edged POOLS IF ANY*/
767    l = &sfrTotalPoolInfo->cePool;
768    n = cmLListFirst(l);
769    while (n != NULL)
770    {
771       n = cmLListDelFrm(l, n);
772
773       /* Deallocate buffer */
774       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(n->node)), sizeof(RgSchSFRPoolInfo));
775
776       /* Deallocate buffer */
777       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(n)), sizeof(CmLList));   
778       n = cmLListNext(l);
779    } 
780
781 }
782
783 /**
784  * @brief This function resets temporary variables in Pool
785  * @details
786  *
787  *     Function: rgSchSFRResetPoolVariables
788  *
789  *     Invoked by: rgSCHSFRUtlTotalPoolInit
790  *
791  *  @param[in]  RgSchCellCb*     cell
792  *  @param[in]  RgSubFrm*     subFrm
793  *  @return  Void
794  *
795  **/
796 #ifdef ANSI
797 S16 rgSchSFRTotalPoolInit
798 (
799  RgSchCellCb             *cell,
800  RgSchDlSf               *sf
801  )
802 #else
803 PRIVATE Void rgSchSFRTotalPoolInit(cell, sf)
804    RgSchCellCb             *cell;
805    RgSchDlSf               *sf;
806 #endif
807 {      
808    /*  Initialise the variables */
809    RgSchSFRPoolInfo *sfrCCPool;
810    RgSchSFRPoolInfo *sfrCEPool;
811    CmLListCp   *l;
812    CmLList     *n;
813    CmLList *temp = NULLP;
814    S16 ret = 0;
815
816    rgSchSFRTotalPoolFree(&sf->sfrTotalPoolInfo, cell);  
817    sf->sfrTotalPoolInfo.CCPool1BwAvlbl          = 0;
818    sf->sfrTotalPoolInfo.CCPool2BwAvlbl          = 0;
819    sf->sfrTotalPoolInfo.CEPoolBwAvlbl           = 0;
820    sf->sfrTotalPoolInfo.CC1                     = FALSE;
821    sf->sfrTotalPoolInfo.CC2                     = FALSE;
822    /*Initialise the CE Pools*/
823    cmLListInit (&(sf->sfrTotalPoolInfo.cePool));
824
825    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&temp, sizeof(CmLList));
826    if (ret != ROK)
827    {
828       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
829                       "CE Pool memory allocation FAILED for cell");       
830       rgSchSFRTotalPoolFree(&sf->sfrTotalPoolInfo, cell);
831       return RFAILED;
832    }
833
834    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&temp->node, sizeof(RgSchSFRPoolInfo));
835    if (ret != ROK)
836    {
837       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
838                       "CE Pool memory allocation FAILED for cell ");       
839       rgSchSFRTotalPoolFree(&sf->sfrTotalPoolInfo,cell);
840       return RFAILED;
841    }
842
843    l = &sf->sfrTotalPoolInfo.cePool;
844    cmLListAdd2Tail(l, temp);
845
846    /*Initialise Bandwidth and startRB and endRB for each pool*/
847    n = cmLListFirst(l);
848
849    /* Initialise the CE Pools */
850    sfrCEPool = (RgSchSFRPoolInfo*)n->node;
851
852    sfrCEPool->poolstartRB             = cell->lteAdvCb.sfrCfg.cellEdgeRbRange.startRb;
853    sfrCEPool->poolendRB               = cell->lteAdvCb.sfrCfg.cellEdgeRbRange.endRb;
854    sfrCEPool->bw                      = sfrCEPool->poolendRB - sfrCEPool->poolstartRB + 1;
855    sf->sfrTotalPoolInfo.CEPoolBwAvlbl = sfrCEPool->bw;
856
857    sfrCEPool->bwAlloced               = 0;
858    sfrCEPool->type2Start              = sfrCEPool->poolstartRB;
859    sfrCEPool->type2End                = RGSCH_CEIL(sfrCEPool->poolstartRB, cell->rbgSize);   
860    sfrCEPool->type0End                = ((sfrCEPool->poolendRB + 1) / cell->rbgSize) - 1;
861    sfrCEPool->pwrHiCCRange.startRb    = 0;
862    sfrCEPool->pwrHiCCRange.endRb      = 0;
863
864    /*Initialise CC Pool*/
865    cmLListInit (&(sf->sfrTotalPoolInfo.ccPool));
866
867    /*Add memory and Update CCPool*/
868    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&temp, sizeof(CmLList));
869    if (ret != ROK)
870    {
871       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
872                       "CC Pool memory allocation FAILED for cell ");       
873       rgSchSFRTotalPoolFree(&sf->sfrTotalPoolInfo,cell);
874       return RFAILED;
875    }
876
877    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&temp->node, sizeof(RgSchSFRPoolInfo));
878    if (ret != ROK)
879    {
880       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
881                       "CC Pool memory allocation FAILED for cell ");       
882       rgSchSFRTotalPoolFree(&sf->sfrTotalPoolInfo,cell);
883       return RFAILED;
884    }
885
886    l = &sf->sfrTotalPoolInfo.ccPool;
887    cmLListAdd2Tail(l, temp);
888
889    /*Initialise Bandwidth and startRB and endRB for each pool*/
890    if(sfrCEPool->poolstartRB)
891    {
892       n = cmLListFirst(l);
893       sfrCCPool = (RgSchSFRPoolInfo*)n->node;
894
895       sfrCCPool->poolstartRB              = 0;
896       sfrCCPool->poolendRB                = sfrCEPool->poolstartRB - 1;
897       sfrCCPool->bw                       = sfrCCPool->poolendRB - sfrCCPool->poolstartRB + 1;
898       sf->sfrTotalPoolInfo.CCPool1BwAvlbl = sfrCCPool->bw;
899       sfrCCPool->bwAlloced                = 0;
900       sfrCCPool->type2Start               = 0;
901       sfrCCPool->type2End                 = 0;
902       sfrCCPool->type0End                 = ((sfrCCPool->poolendRB + 1) / cell->rbgSize) - 1;
903       sf->sfrTotalPoolInfo.CC1            = TRUE;
904       sfrCCPool->pwrHiCCRange.startRb     = 0;
905       sfrCCPool->pwrHiCCRange.endRb       = 0;
906    }
907    else
908    {
909       n = cmLListFirst(l);
910       sfrCCPool = (RgSchSFRPoolInfo*)n->node;
911
912       sfrCCPool->poolstartRB              = sfrCEPool->poolendRB + 1;
913       sfrCCPool->poolendRB                = sf->bw - 1;
914       sfrCCPool->bw                       = sfrCCPool->poolendRB - sfrCCPool->poolstartRB + 1;
915       sf->sfrTotalPoolInfo.CCPool2BwAvlbl = sfrCCPool->bw;
916       sfrCCPool->CCPool2Exists            = TRUE;
917       sfrCCPool->bwAlloced                = 0;
918       sfrCCPool->type2Start               = sfrCCPool->poolstartRB;
919       sfrCCPool->type2End                 = RGSCH_CEIL(sfrCCPool->poolstartRB, cell->rbgSize);
920       sfrCCPool->type0End                 = ((sfrCCPool->poolendRB + 1) / cell->rbgSize) - 1;
921       sf->sfrTotalPoolInfo.CC2            = TRUE;
922       sfrCEPool->adjCCPool                = sfrCCPool; /* SFR_FIX */
923       sfrCCPool->pwrHiCCRange.startRb     = 0;
924       sfrCCPool->pwrHiCCRange.endRb       = 0;
925    }
926
927    if((sfrCEPool->poolendRB != sf->bw - 1) && (!sfrCCPool->poolstartRB))
928    {    
929       /*Add memory and Update CCPool*/
930       ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&temp, sizeof(CmLList));
931       if (ret != ROK)
932       {
933          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
934                          "CC Pool memory allocation FAILED for cell ");       
935          rgSchSFRTotalPoolFree(&sf->sfrTotalPoolInfo,cell);
936          return RFAILED;
937       }
938
939       ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&temp->node, sizeof(RgSchSFRPoolInfo));
940       if (ret != ROK)
941       {
942          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
943                          "CC Pool memory allocation FAILED for cell ");       
944          rgSchSFRTotalPoolFree(&sf->sfrTotalPoolInfo,cell);
945          return RFAILED;
946       }
947
948       cmLListAdd2Tail(l, temp);
949
950       n = cmLListCrnt(l);
951       sfrCCPool = (RgSchSFRPoolInfo*)n->node;
952
953       sfrCCPool->poolstartRB              = sfrCEPool->poolendRB + 1;
954       sfrCCPool->poolendRB                = sf->bw - 1;
955       sfrCCPool->bw                       = sfrCCPool->poolendRB - sfrCCPool->poolstartRB + 1;
956       sf->sfrTotalPoolInfo.CCPool2BwAvlbl = sfrCCPool->bw;
957       sfrCCPool->CCPool2Exists            = TRUE;
958       sfrCCPool->bwAlloced                = 0;
959       sfrCCPool->type2Start               = sfrCCPool->poolstartRB;      
960       sfrCCPool->type2End                 = RGSCH_CEIL(sfrCCPool->poolstartRB, cell->rbgSize);
961       sfrCCPool->type0End                 = ((sfrCCPool->poolendRB + 1) / cell->rbgSize) - 1;
962       sf->sfrTotalPoolInfo.CC2            = TRUE;
963       sfrCEPool->adjCCPool                = sfrCCPool; /* SFR_FIX */
964       sfrCCPool->pwrHiCCRange.startRb     = 0;
965       sfrCCPool->pwrHiCCRange.endRb       = 0;
966    }   
967
968    sf->sfrTotalPoolInfo.CCRetx            = FALSE;
969    sf->sfrTotalPoolInfo.CERetx            = FALSE;
970
971    sf->sfrTotalPoolInfo.ccBwFull          = FALSE;
972    sf->sfrTotalPoolInfo.ceBwFull          = FALSE;
973    sf->sfrTotalPoolInfo.isUeCellEdge      = FALSE;
974    return ROK;
975 }
976 /**
977  * @brief This function resets temporary variables in RNTP Prepration
978  * @details
979  *
980  *     Function:   rgSchDSFRRntpInfoInit 
981  *
982  *     Invoked by: rgSCHSFRUtlTotalPoolInit
983  *
984  *  @param[in]  TknStrOSXL*     rntpPtr
985  *  @param[in]  RgSubFrm*        subFrm
986  *  @return  S16
987  *
988  **/
989 #ifdef ANSI
990 S16   rgSchDSFRRntpInfoInit 
991 (
992  TknStrOSXL              *rntpPtr,
993  RgSchCellCb             *cell,
994  U16                      bw
995  )
996 #else
997 PRIVATE Void rgSchDSFRRntpInfoInit(rntpPtr, cell, bw)
998    TknStrOSXL              *rntpPtr;
999    RgSchCellCb             *cell;
1000    U16                      bw;
1001 #endif
1002 {   
1003    Inst inst = cell->instIdx;
1004    U16 len;
1005
1006    rntpPtr->pres = PRSNT_NODEF;
1007
1008    len = (bw % 8 == 0) ? (bw/8) : (bw/8 + 1);
1009
1010    rntpPtr->len  = len;   
1011
1012    /* Allocate memory for "scheduled UE" Info */
1013    if((rgSCHUtlAllocSBuf(inst, (Data**)&(rntpPtr->val),
1014                (len * sizeof(U8)))) != ROK)
1015    {
1016       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Memory allocation FAILED for RNTP Alloc");
1017       return RFAILED;
1018    }
1019
1020    return ROK;
1021 }
1022
1023 /**
1024  * @brief This function release RNTP pattern from slot and Cell 
1025  * @details
1026  *
1027  *     Function:   rgSchDSFRRntpInfoFree 
1028  *
1029  *     Invoked by: rgSCHSFRUtlTotalPoolInit
1030  *
1031  *  @param[in]  TknStrOSXL*     rntpPtr
1032  *  @param[in]  RgSubFrm*        subFrm
1033  *  @return  S16
1034  *
1035  **/
1036 #ifdef ANSI
1037 S16   rgSchDSFRRntpInfoFree 
1038 (
1039  TknStrOSXL              *rntpPtr,
1040  RgSchCellCb             *cell,
1041  U16                      bw
1042  )
1043 #else
1044 PRIVATE Void rgSchDSFRRntpInfoFree(rntpPtr, cell, bw)
1045    TknStrOSXL              *rntpPtr;
1046    RgSchCellCb             *cell;
1047    U16                      bw;
1048 #endif
1049 {   
1050    Inst inst = cell->instIdx;
1051    U16 len;
1052
1053    len = (bw % 8 == 0) ? (bw/8) : (bw/8 + 1);
1054
1055    if(rntpPtr->pres == PRSNT_NODEF)
1056    {   
1057       rgSCHUtlFreeSBuf(inst, (Data **)(&(rntpPtr->val)),(len * sizeof(U8)));
1058       rntpPtr->pres = NOTPRSNT;
1059       rntpPtr->len  = 0;   
1060    }
1061
1062    return ROK;
1063 }
1064
1065 /**
1066  * @brief This function resets temporary variables in Pool
1067  * @details
1068  *
1069  *     Function: rgSchSFRResetPoolVariables
1070  *     Purpose:  Initialise the dynamic variables in each pool.
1071  *                    Reset bwAlloced, bwAssigned, type2End, type0End, type2Start
1072  *     Invoked by: rgSCHSFRUtlTotalPoolReset
1073  *
1074  *  @param[in]  RgSchCellCb*     cell
1075  *  @param[in]  RgSchSFRPoolInfo *pool
1076  *  @return  Void
1077  *
1078  **/
1079 #ifdef ANSI
1080 PRIVATE Void rgSchSFRResetPoolVariables
1081 (
1082  RgSchCellCb             *cell,
1083  RgSchSFRPoolInfo        *pool
1084  )
1085 #else
1086 PRIVATE Void rgSchSFRResetPoolVariables(cell, pool)
1087    RgSchCellCb             *cell;
1088    RgSchSFRPoolInfo *pool;
1089 #endif
1090 {
1091
1092    pool->bwAlloced  = 0;
1093
1094    /*type0end will be the last RBG in pool with all available RBs*/
1095    pool->type0End = (((pool->poolendRB + 1)/cell->rbgSize) - 1);
1096
1097    /*type2end will be the first RBG in pool with all available RBs*/
1098    pool->type2End = RGSCH_CEIL(pool->poolstartRB, cell->rbgSize);
1099    pool->type2Start = pool->poolstartRB;
1100    pool->bw = pool->poolendRB - pool->poolstartRB + 1;
1101
1102       RETVOID;
1103 }
1104 /**
1105  * @brief This function resets SFR Pool information for frame
1106  *
1107  * @details
1108  *
1109  *     Function: rgSCHSFRUtlTotalPooReset
1110  *     Purpose:  Update the dynamic variables in each pool as they will be modified in each slot.
1111  *                    Dont modify the static variables like startRB, endRB, BW
1112  *     Invoked by: rgSCHUtlSubFrmPut
1113  *
1114  *  @param[in]  RgSchCellCb*     cell
1115  *  @param[in]  RgSchDlSf*     subFrm
1116  *  @return  Void
1117  *
1118  **/
1119 #ifdef ANSI
1120 PRIVATE Void rgSCHSFRUtlTotalPoolReset
1121 (
1122  RgSchCellCb             *cell,
1123  RgSchDlSf               *subFrm
1124  )
1125 #else
1126 PRIVATE Void rgSCHSFRUtlTotalPoolReset(cell, subFrm)
1127    RgSchCellCb             *cell;
1128    RgSchDlSf               *subFrm;
1129 #endif
1130 {
1131    RgSchSFRTotalPoolInfo *totalPoolInfo = &subFrm->sfrTotalPoolInfo;
1132    CmLListCp    *ccPool = &totalPoolInfo->ccPool;
1133    CmLListCp    *cePool = &totalPoolInfo->cePool;
1134    CmLList *node = NULLP;
1135    RgSchSFRPoolInfo *tempPool = NULLP;
1136
1137    totalPoolInfo->ccBwFull          = FALSE;
1138    totalPoolInfo->ceBwFull          = FALSE;
1139    totalPoolInfo->isUeCellEdge      = FALSE;
1140    totalPoolInfo->CCPool1BwAvlbl    = 0;
1141    totalPoolInfo->CCPool2BwAvlbl    = 0;
1142    totalPoolInfo->CEPoolBwAvlbl     = 0;
1143    totalPoolInfo->CCRetx            = FALSE;
1144    totalPoolInfo->CERetx            = FALSE;
1145
1146    node = ccPool->first;
1147    while(node)
1148    {
1149       tempPool = (RgSchSFRPoolInfo *)(node->node);
1150       node = node->next;
1151       rgSchSFRResetPoolVariables(cell, tempPool);
1152       if(tempPool->poolstartRB == 0)
1153          totalPoolInfo->CCPool1BwAvlbl = tempPool->bw;
1154       else
1155          totalPoolInfo->CCPool2BwAvlbl = tempPool->bw;
1156    }
1157
1158    node = cePool->first;
1159    while(node)
1160    {
1161       tempPool = (RgSchSFRPoolInfo *)(node->node);
1162       node = node->next;
1163       rgSchSFRResetPoolVariables(cell, tempPool);
1164       totalPoolInfo->CEPoolBwAvlbl = tempPool->bw;    
1165    }
1166
1167    RETVOID;
1168 }
1169 /* LTE_ADV_FLAG_REMOVED_END */
1170 /**
1171  * @brief This function appends PHICH information for frame
1172  *
1173  * @details
1174  *
1175  *     Function: rgSCHUtlAddPhich
1176  *     Purpose:  This function appends PHICH information for
1177  *               a slot.
1178  *
1179  *     Invoked by: TOM
1180  *
1181  *  @param[in]  RgSchCellCb*     cell
1182  *  @param[in]  RgSubFrm*     subFrm
1183  *  @param[in]  U8            hqFeedBack
1184  *  @param[in]  U8            nDmrs
1185  *  @param[in]  U8            rbStart
1186  *  @return  S16
1187  *      -# ROK
1188  *      -# RFAILED
1189  **/
1190 #ifdef LTE_TDD
1191 #ifdef ANSI
1192 S16 rgSCHUtlAddPhich
1193 (
1194 RgSchCellCb             *cell,
1195 CmLteTimingInfo         frm,
1196 U8                      hqFeedBack,
1197 U8                      nDmrs,
1198 U8                      rbStart,
1199 U8                      iPhich
1200 )
1201 #else
1202 S16 rgSCHUtlAddPhich(cell, frm, hqFeedBack, nDmrs, rbStart, iPhich)
1203 RgSchCellCb             *cell;
1204 CmLteTimingInfo         frm;
1205 U8                      hqFeedBack;
1206 U8                      nDmrs;
1207 U8                      rbStart;
1208 U8                      iPhich;
1209 #endif
1210 #else
1211 #ifdef ANSI
1212 S16 rgSCHUtlAddPhich
1213 (
1214 RgSchCellCb             *cell,
1215 CmLteTimingInfo         frm,
1216 U8                      hqFeedBack,
1217 U8                      nDmrs,
1218 U8                      rbStart,
1219 Bool                    isForMsg3
1220 )
1221 #else
1222 S16 rgSCHUtlAddPhich(cell, frm, hqFeedBack, nDmrs, rbStart, isForMsg3)
1223 RgSchCellCb             *cell;
1224 CmLteTimingInfo         frm;
1225 U8                      hqFeedBack;
1226 U8                      nDmrs;
1227 U8                      rbStart;
1228 Bool                    isForMsg3;
1229 #endif
1230 #endif
1231 {
1232    S16                ret;
1233    RgSchPhich         *phich;
1234    RgSchDlSf          *dlSf;
1235    Inst               inst = cell->instIdx;
1236
1237    dlSf = rgSCHUtlSubFrmGet(cell, frm);
1238    RGSCH_PHICH_ALLOC(inst, phich,sizeof(RgSchPhich), ret);
1239
1240    if(ret != ROK)
1241    {
1242       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId, " rgSCHUtlAddPhich(): "
1243                "Allocation of RgSchPhich failed");
1244       return RFAILED;
1245    }
1246 #ifdef LTE_TDD
1247    RGSCH_INITPHICH(phich, hqFeedBack, nDmrs, rbStart, iPhich);
1248 #else
1249    RGSCH_INITPHICH(phich, hqFeedBack, nDmrs, rbStart, isForMsg3); /*SR_RACH_STATS */
1250 #endif
1251    cmLListAdd2Tail(&dlSf->phichInfo.phichs, &phich->lnk);
1252    return ROK;
1253 } /* rgSCHUtlAddPhich */
1254
1255 /**
1256  * @brief This function resets PHICH information for frame
1257  *
1258  * @details
1259  *
1260  *     Function: rgSCHUtlPhichReset
1261  *     Purpose:  This function initializes PHICH information for
1262  *               a slot. It removes the list of PHICHs allocated
1263  *               in the prior use of this slot structure.
1264  *
1265  *     Invoked by: rgSCHUtlSubFrmPut
1266  *
1267  *  @param[in]  RgSchCellCb*     cell
1268  *  @param[in]  RgSubFrm*     subFrm
1269  *  @return  Void
1270  *
1271  **/
1272 #ifdef ANSI
1273 PRIVATE Void rgSCHUtlPhichReset
1274 (
1275 RgSchCellCb                *cell,
1276 RgSchDlSf                  *subFrm
1277 )
1278 #else
1279 PRIVATE Void rgSCHUtlPhichReset(cell, subFrm)
1280 RgSchCellCb                *cell;
1281 RgSchDlSf                  *subFrm;
1282 #endif
1283 {
1284    RgSchPhichInfo          *phichInfo;
1285    RgSchPhich              *phich;
1286
1287    UNUSED(cell);
1288
1289    phichInfo = &subFrm->phichInfo;
1290    while(phichInfo->phichs.first != NULLP)
1291    {
1292       phich = (RgSchPhich *)phichInfo->phichs.first->node;
1293       cmLListDelFrm(&phichInfo->phichs, phichInfo->phichs.first);
1294       RGSCH_PHICH_FREE(cell->instIdx, phich, sizeof(RgSchPhich));
1295    }
1296    cmLListInit(&phichInfo->phichs);
1297    RETVOID;
1298 } /* rgSCHUtlPhichReset */
1299
1300 \f
1301 /**
1302  * @brief This function returns slot data structure for a cell
1303  *
1304  * @details
1305  *
1306  *     Function: rgSCHUtlSubFrmGet
1307  *     Purpose:  This function resets the slot data structure
1308  *               when the slot is released
1309  *
1310  *     Invoked by: scheduler
1311  *
1312  *  @param[in]  RgSubFrm  subFrm
1313  *  @return  Void
1314  *
1315  **/
1316 #ifdef ANSI
1317 RgSchDlSf* rgSCHUtlSubFrmGet
1318 (
1319 RgSchCellCb            *cell,
1320 CmLteTimingInfo        frm
1321 )
1322 #else
1323 RgSchDlSf* rgSCHUtlSubFrmGet(cell, frm)
1324 RgSchCellCb            *cell;
1325 CmLteTimingInfo        frm;
1326 #endif
1327 {
1328    RgSchDlSf            *sf;
1329    U8                   dlIdx;
1330
1331 #ifdef LTE_TDD
1332    dlIdx = rgSCHUtlGetDlSfIdx(cell, &frm);
1333    //RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, cell->subFrms, dlIdx);
1334    sf = cell->subFrms[dlIdx];
1335 #else
1336    /* Changing the idexing
1337       so that proper slot is selected */
1338    dlIdx = (((frm.sfn & 1) * RGSCH_NUM_SUB_FRAMES) + (frm.slot % RGSCH_NUM_SUB_FRAMES));
1339    RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, cell->subFrms, dlIdx);
1340    sf = cell->subFrms[dlIdx];
1341 #endif
1342   /* CA dev Start */
1343    sf->dlIdx    = dlIdx;
1344   /* CA dev End */
1345    return (sf);
1346 }
1347
1348 \f
1349 /**
1350  * @brief This function returns slot data structure for a cell
1351  *
1352  * @details
1353  *
1354  *     Function: rgSCHUtlSubFrmPut
1355  *     Purpose:  This function resets the slot data structure
1356  *               when the slot is released
1357  *
1358  *     Invoked by: scheduler
1359  *
1360  *  @param[in]  RgSubFrm  subFrm
1361  *  @return  Void
1362  *
1363  **/
1364 #ifdef ANSI
1365 Void rgSCHUtlSubFrmPut
1366 (
1367 RgSchCellCb            *cell,
1368 RgSchDlSf              *sf
1369 )
1370 #else
1371 Void rgSCHUtlSubFrmPut(cell, sf)
1372 RgSchCellCb            *cell;
1373 RgSchDlSf              *sf;
1374 #endif
1375 {
1376    U8                  i;
1377    U8                  noRaRsps;
1378
1379 #ifdef LTE_TDD
1380    /* Release all the held PDCCH information */
1381    rgSCHUtlPdcchInit(cell, sf, sf->nCce);
1382 #else
1383    /* Release all the held PDCCH information */
1384    rgSCHUtlPdcchInit(cell, sf, cell->nCce);
1385 #endif
1386    rgSCHUtlPhichReset(cell, sf);
1387
1388    /* Reset the bw allocated. */
1389    sf->bwAssigned = 0;
1390 #ifdef LTEMAC_SPS
1391    /* Setting allocated bandwidth to SPS bandwidth for non-SPS RB allocator */
1392    sf->bwAlloced = ((cell->spsCellCfg.maxSpsDlBw +
1393       cell->rbgSize - 1)/cell->rbgSize) * cell->rbgSize;
1394    if (sf->bwAlloced > sf->bw)
1395    {
1396       sf->bwAlloced = sf->bw;
1397    }
1398    sf->spsAllocdBw = 0;
1399    sf->type2Start = sf->bwAlloced;
1400    memset( &sf->dlSfAllocInfo, 0, sizeof(RgSchDlSfAllocInfo));
1401 #else
1402    sf->bwAlloced = 0;
1403    /* Fix for ccpu00123918*/
1404    sf->type2Start = 0;
1405    /* LTE_ADV_FLAG_REMOVED_START */
1406    /* dsfr_pal_fixes ** 21-March-2013 ** SKS */
1407    if (cell->lteAdvCb.dsfrCfg.status == RGR_ENABLE)
1408    {
1409       memset(sf->rntpInfo.val, 0, sf->rntpInfo.len);
1410    }
1411    /* LTE_ADV_FLAG_REMOVED_END */
1412 #endif
1413    sf->txDone = FALSE;
1414    /*[ccpu00138609]-ADD-Reset the CCCH UE counter */
1415    sf->schdCcchUe = 0;
1416
1417    /* Non DLFS scheduling using Type0 RA requires the following
1418     * parameter's tracking */
1419    /* Type 2 localized allocations start from 0th RBG and onwards */
1420    /* Type 0 allocations start from last RBG and backwards*/
1421 #ifndef LTEMAC_SPS
1422    sf->type2End   = 0;
1423 #else
1424    sf->type2End   = RGSCH_CEIL(sf->bwAlloced,cell->rbgSize);
1425 #endif
1426    sf->type0End   = cell->noOfRbgs - 1;
1427    /* If last RBG is of incomplete size then special handling */
1428    (sf->bw % cell->rbgSize == 0)? (sf->lstRbgDfct = 0) :
1429       (sf->lstRbgDfct = cell->rbgSize - (sf->bw % cell->rbgSize));
1430    /* This resets the allocation for BCCH and PDCCH */
1431 #ifdef EMTC_ENABLE
1432    /* TODO we need to move this reset for emtc functions */
1433    if(!(cell->emtcEnable))
1434    {
1435       sf->bch.tb     = NULLP;
1436       sf->bch.tbSize = 0;
1437    }
1438 #else
1439    sf->bch.tb     = NULLP;
1440    sf->bch.tbSize = 0;
1441 #endif
1442    sf->bcch.pdcch = NULLP;
1443    sf->pcch.pdcch = NULLP;
1444 #ifdef LTE_TDD
1445    noRaRsps = RGSCH_MAX_TDD_RA_RSP_ALLOC;
1446 #else
1447    noRaRsps = RGSCH_MAX_RA_RSP_ALLOC;
1448 #endif
1449    for (i = 0; i < noRaRsps; i++)
1450    {
1451       sf->raRsp[i].pdcch = NULLP;
1452       cmLListInit(&(sf->raRsp[i].raRspLst));
1453    }
1454    /* LTE_ADV_FLAG_REMOVED_START */
1455    if (cell->lteAdvCb.sfrCfg.status == RGR_ENABLE)
1456    {
1457       rgSCHSFRUtlTotalPoolReset(cell, sf);
1458    }
1459    /* LTE_ADV_FLAG_REMOVED_END */
1460 #ifdef LTE_ADV
1461    cmLListInit(&sf->n1PucchResLst);
1462 #endif
1463
1464    sf->cceCnt = 0;
1465    sf->isCceFailure = FALSE;
1466    sf->dlUlBothCmplt = 0;
1467    RETVOID;
1468 }
1469
1470 \f
1471 /**
1472  * @brief This function computes log N (32 bit Unsigned) to the base 2
1473  *
1474  * @details
1475  *
1476  *     Function: rgSCHUtlLog32bitNbase2
1477  *     Purpose:  This function computes log N (32 bit Unsigned) to the base 2.
1478  *               For n= 0,1 ret = 0.
1479  *
1480  *     Invoked by: Scheduler
1481  *
1482  *  @param[in]  U32       n
1483  *  @return  U8
1484  *
1485  **/
1486 #ifdef ANSI
1487 U8 rgSCHUtlLog32bitNbase2
1488 (
1489 U32               n
1490 )
1491 #else
1492 U8 rgSCHUtlLog32bitNbase2(n)
1493 U32               n;
1494 #endif
1495 {
1496    U32            b[] = {0x2, 0xc, 0xf0, 0xff00, 0xffff0000};
1497    U32            s[] = {1, 2, 4, 8, 16};
1498    S16            i;
1499    U8             ret = 0;
1500
1501    for (i=4; i >= 0; i--)
1502    {
1503       if (n & b[i])
1504       {
1505          n >>= s[i];
1506          ret |= s[i];
1507       }
1508    }
1509    return (ret);
1510 }
1511
1512 #ifdef LTEMAC_SPS
1513
1514 /**
1515  * @brief This function is a wrapper to call scheduler specific API.
1516  *
1517  * @details
1518  *
1519  *     Function: rgSCHUtlDlRelPdcchFbk
1520  *     Purpose:  Calls scheduler's handler for SPS release PDCCH feedback
1521  *     information.
1522  *
1523  *     Invoked by: DHM
1524  *
1525  *  @param[in]   RgSchCellCb     *cell
1526  *  @param[in]   RgSchUeCb       *ue
1527  *  @param[in]   U8            isAck
1528  *  @return  Void
1529  *
1530  **/
1531 #ifdef ANSI
1532 Void rgSCHUtlDlRelPdcchFbk
1533 (
1534 RgSchCellCb        *cell,
1535 RgSchUeCb          *ue,
1536 U8               isAck
1537 )
1538 #else
1539 Void rgSCHUtlDlRelPdcchFbk(cell, ue, isAck)
1540 RgSchCellCb        *cell;
1541 RgSchUeCb          *ue;
1542 U8               isAck;
1543 #endif
1544 {
1545    cell->sc.apis->rgSCHDlRelPdcchFbk(cell, ue, isAck);
1546    RETVOID;
1547 }
1548
1549
1550
1551 /**
1552  * @brief This function is a wrapper to call scheduler specific API.
1553  *
1554  * @details
1555  *
1556  *     Function: rgSCHUtlDlProcAck
1557  *     Purpose:  Calls scheduler's handler to process Ack
1558  *     information.
1559  *
1560  *     Invoked by: DHM
1561  *
1562  *  @param[in]   RgSchCellCb     *cell
1563  *  @param[in]   RgSchDlHqProcCb *hqP
1564  *  @return  Void
1565  *
1566  **/
1567 #ifdef ANSI
1568 Void rgSCHUtlDlProcAck
1569 (
1570 RgSchCellCb        *cell,
1571 RgSchDlHqProcCb    *hqP
1572 )
1573 #else
1574 Void rgSCHUtlDlProcAck(cell, hqP)
1575 RgSchCellCb        *cell;
1576 RgSchDlHqProcCb    *hqP;
1577 #endif
1578 {
1579    cell->sc.apis->rgSCHDlProcAck(cell, hqP);
1580    RETVOID;
1581 }
1582
1583 /**
1584  * @brief CRNTI CE Handler
1585  *
1586  * @details
1587  *
1588  *     Function : rgSCHUtlHdlCrntiCE
1589  *
1590  *     - Call scheduler common API
1591  *
1592  *
1593  *  @param[in]  RgSchCellCb   *cell
1594  *  @param[in]  RgSchUeCb     *ue
1595  *  @param[out] RgSchErrInfo  *err
1596  *  @return  Void
1597  **/
1598 #ifdef ANSI
1599 Void rgSCHUtlHdlCrntiCE
1600 (
1601 RgSchCellCb  *cell,
1602 RgSchUeCb    *ue
1603 )
1604 #else
1605 Void rgSCHUtlHdlCrntiCE(cell, ue)
1606 RgSchCellCb  *cell;
1607 RgSchUeCb    *ue;
1608 #endif
1609 {
1610
1611    cell->sc.apis->rgSCHHdlCrntiCE(cell, ue);
1612    RETVOID;
1613 }  /* rgSCHUtlHdlCrntiCE */
1614 #endif /* LTEMAC_SPS */
1615
1616 /***********************************************************
1617  *
1618  *     Func : rgSCHUtlCalcTotalRegs
1619  *
1620  *     Desc : Calculate total REGs, given a bandwidth, CFI
1621  *            and number of antennas.
1622  *
1623  *     Ret  : Total REGs (U16)
1624  *
1625  *     Notes: Could optimise if bw values are limited
1626  *            (taken from RRC spec) by indexing values from
1627  *            a table.
1628  *            Input values are not validated. CFI is assumed
1629  *            to be 1/2/3/4.
1630  *
1631  *     File :
1632  *
1633  **********************************************************/
1634 #ifdef ANSI
1635 PRIVATE U16 rgSCHUtlCalcTotalRegs
1636 (
1637 U8    bw,
1638 U8    cfi,
1639 U8    numAntna,
1640 Bool  isEcp
1641 )
1642 #else
1643 PRIVATE U16 rgSCHUtlCalcTotalRegs(bw, cfi, numAntna, isEcp)
1644 U8    bw;
1645 U8    cfi;
1646 U8    numAntna;
1647 Bool  isEcp;
1648 #endif
1649 {
1650    U16 regs = 0;
1651
1652    /*ccpu00116757-  removed check for (ERRCLASS & ERRCLS_DEBUG)*/
1653
1654    if (bw <= 10)
1655       ++cfi;
1656    switch (cfi)
1657    {
1658       /* Refer 36.211 section 6.10.1.2
1659        * For symbols 2 and 4, the REGs per RB will be based on cyclic prefix
1660        *  and number of antenna ports.
1661        * For symbol 1, there are 2 REGs per RB always. Similarly symbol 3
1662        * will have 3 REGS.
1663        */
1664       case 4:
1665          /*CR changes [ccpu00124416] - MOD*/
1666          if(isEcp)
1667          {
1668             regs =  bw * RGSCH_NUM_REGS_4TH_SYM_EXT_CP;
1669          }
1670          else
1671          {
1672             regs =  bw * RGSCH_NUM_REGS_4TH_SYM_NOR_CP;
1673          }
1674       case 3:
1675          regs += bw * RGSCH_NUM_REGS_3RD_SYM;
1676       case 2:
1677             /*CR changes [ccpu00124416] - MOD using number of antenna ports*/
1678          regs += (numAntna == RGSCH_NUM_ANT_PORT_FOUR) ? \
1679             (bw * RGSCH_NUM_REGS_2ND_SYM_FOUR_ANT_PORT) : \
1680             (bw * RGSCH_NUM_REGS_2ND_SYM_1OR2_ANT_PORT);
1681       default: /* case 1 */
1682          regs += bw * RGSCH_NUM_REGS_1ST_SYM;
1683    }
1684    return (regs);
1685 }
1686
1687 /***********************************************************
1688  *
1689  *     Func : rgSCHUtlCalcPhichRegs
1690  *
1691  *     Desc : Calculates number of PHICH REGs
1692  *
1693  *     Ret  : Number of PHICH REGs (U8)
1694  *
1695  *     Notes: ng6 is Ng multiplied by 6
1696  *
1697  *     File :
1698  *
1699  **********************************************************/
1700 #ifdef ANSI
1701 PRIVATE U16 rgSCHUtlCalcPhichRegs
1702 (
1703 U8 bw,
1704 U8 ng6
1705 )
1706 #else
1707 PRIVATE U16 rgSCHUtlCalcPhichRegs(bw, ng6)
1708 U8 bw;
1709 U8 ng6;
1710 #endif
1711 {
1712    /* ccpu00115330: Corrected the calculation for number of PHICH groups*/
1713    return (RGSCH_CEIL((bw * ng6) ,(8 * 6)) * RGSCH_NUM_REG_PER_PHICH_GRP);
1714 }
1715
1716 #ifdef LTE_TDD
1717 /**
1718  * @brief Calculates total CCEs (N_cce)
1719  *
1720  * @details
1721  *
1722  *     Function: rgSCHUtlCalcNCce
1723  *     Purpose:  This function calculates and returns total CCEs for a
1724  *               cell, given the following: bandwidth, Ng configuration
1725  *               (multiplied by six), cfi (actual number of control
1726  *               symbols), m factor for PHICH  and number of antennas.
1727  *
1728  *     Invoked by: Scheduler
1729  *
1730  *  @param[in]  U8      bw
1731  *  @param[in]  U8      ng6
1732  *  @param[in]  U8      cfi
1733  *  @param[in]  U8      mPhich
1734  *  @param[in]  U8      numAntna
1735  *  @param[in]  Bool    isEcp
1736  *  @return     N_cce (U8)
1737  *
1738  **/
1739 #ifdef ANSI
1740 U8 rgSCHUtlCalcNCce
1741 (
1742 U8            bw,
1743 RgrPhichNg    ng,
1744 U8            cfi,
1745 U8            mPhich,
1746 U8            numAntna,
1747 Bool          isEcp
1748 )
1749 #else
1750 U8 rgSCHUtlCalcNCce(bw, ng, cfi, mPhich, numAntna, isEcp)
1751 U8             bw;
1752 RgrPhichNg     ng;
1753 U8             cfi;
1754 U8             mPhich;
1755 U8             numAntna;
1756 Bool           isEcp;
1757 #endif
1758 {
1759    U16         totalRegs;
1760    U16         phichRegs;
1761    U16         cceRegs;
1762    U8          ng6;
1763
1764    /*ccpu00116757-  removed check for (ERRCLASS & ERRCLS_DEBUG)*/
1765
1766    switch (ng)
1767    {
1768       case RGR_NG_ONESIXTH:
1769          ng6 = 1;
1770          break;
1771       case RGR_NG_HALF:
1772          ng6 = 3;
1773          break;
1774       case RGR_NG_ONE:
1775          ng6 = 6;
1776          break;
1777       case RGR_NG_TWO:
1778       default:
1779          ng6 = 12;
1780          break;
1781    }
1782
1783    totalRegs = rgSCHUtlCalcTotalRegs(bw, cfi, numAntna, isEcp);
1784    phichRegs = rgSCHUtlCalcPhichRegs(bw, ng6);
1785    cceRegs   = totalRegs - mPhich*phichRegs - RGSCH_NUM_PCFICH_REG;
1786
1787    return ((U8)(cceRegs/RGSCH_NUM_REG_PER_CCE));
1788 }
1789
1790 #else
1791 /**
1792  * @brief Calculates total CCEs (N_cce)
1793  *
1794  * @details
1795  *
1796  *     Function: rgSCHUtlCalcNCce
1797  *     Purpose:  This function calculates and returns total CCEs for a
1798  *               cell, given the following: bandwidth, Ng configuration
1799  *               (multiplied by six), cfi (actual number of control
1800  *               symbols) and number of antennas.
1801  *
1802  *     Invoked by: Scheduler
1803  *
1804  *  @param[in]  U8      bw
1805  *  @param[in]  U8      ng6
1806  *  @param[in]  U8      cfi
1807  *  @param[in]  U8      numAntna
1808  *  @return     N_cce (U8)
1809  *
1810  **/
1811 #ifdef ANSI
1812 U8 rgSCHUtlCalcNCce
1813 (
1814 U8            bw,
1815 RgrPhichNg    ng,
1816 U8            cfi,
1817 U8            numAntna,
1818 Bool          isEcp
1819 )
1820 #else
1821 U8 rgSCHUtlCalcNCce(bw, ng, cfi, numAntna, isEcp)
1822 U8             bw;
1823 RgrPhichNg     ng;
1824 U8             cfi;
1825 U8             numAntna;
1826 Bool           isEcp;
1827 #endif
1828 {
1829    U16         totalRegs;
1830    U16         phichRegs;
1831    U16         cceRegs;
1832    U8          ng6;
1833
1834    /*ccpu00116757-  removed check for (ERRCLASS & ERRCLS_DEBUG)*/
1835
1836    switch (ng)
1837    {
1838       case RGR_NG_ONESIXTH:
1839          ng6 = 1;
1840          break;
1841       case RGR_NG_HALF:
1842          ng6 = 3;
1843          break;
1844       case RGR_NG_ONE:
1845          ng6 = 6;
1846          break;
1847       case RGR_NG_TWO:
1848       default:
1849          ng6 = 12;
1850          break;
1851    }
1852
1853    totalRegs = rgSCHUtlCalcTotalRegs(bw, cfi, numAntna, isEcp);
1854    phichRegs = rgSCHUtlCalcPhichRegs(bw, ng6);
1855    cceRegs   = totalRegs - phichRegs - RGSCH_NUM_PCFICH_REG;
1856
1857    return ((U8)(cceRegs/RGSCH_NUM_REG_PER_CCE));
1858 }
1859 #endif
1860
1861 /**
1862  * @brief Returns PHICH info associated with an uplink
1863  *        HARQ process allocation
1864  *
1865  * @details
1866  *
1867  *     Function: rgSCHUtlGetPhichInfo
1868  *     Purpose:  This function returns PHICH info associated with
1869  *               an uplink HARQ process allocation. PHICH info
1870  *               comprises RB start and N_dmrs.
1871  *
1872  *  @param[in]  RgSchUlHqProcCb   *hqProc
1873  *  @param[out] U8             *rbStartRef
1874  *  @param[out] U8             *nDmrsRef
1875  *  @return  S16
1876  **/
1877 #ifdef LTE_TDD
1878 #ifdef ANSI
1879 S16 rgSCHUtlGetPhichInfo
1880 (
1881 RgSchUlHqProcCb   *hqProc,
1882 U8                *rbStartRef,
1883 U8                *nDmrsRef,
1884 U8                *iPhich
1885 )
1886 #else
1887 S16 rgSCHUtlGetPhichInfo(hqProc, rbStartRef, nDmrsRef, iPhich)
1888 RgSchUlHqProcCb   *hqProc;
1889 U8                *rbStartRef;
1890 U8                *nDmrsRef;
1891 U8                *iPhich;
1892 #endif
1893 #else
1894 #ifdef ANSI
1895 S16 rgSCHUtlGetPhichInfo
1896 (
1897 RgSchUlHqProcCb   *hqProc,
1898 U8                *rbStartRef,
1899 U8                *nDmrsRef
1900 )
1901 #else
1902 S16 rgSCHUtlGetPhichInfo(hqProc, rbStartRef, nDmrsRef)
1903 RgSchUlHqProcCb   *hqProc;
1904 U8                *rbStartRef;
1905 U8                *nDmrsRef;
1906 #endif
1907 #endif
1908 {
1909 /* ACC-TDD */
1910         S16 ret = RFAILED;
1911
1912         if ((hqProc != NULLP) && (hqProc->alloc != NULLP))
1913     {
1914        *rbStartRef = hqProc->alloc->grnt.rbStart;
1915        *nDmrsRef   = hqProc->alloc->grnt.nDmrs;
1916 #ifdef LTE_TDD
1917    *iPhich     = hqProc->iPhich;
1918 #endif
1919        ret = ROK;
1920     }
1921     return (ret);
1922 }
1923 #ifndef TFU_UPGRADE
1924 /**
1925  * @brief Returns uplink grant information required to permit
1926  *        PHY to receive data
1927  *
1928  * @details
1929  *
1930  *     Function: rgSCHUtlAllocRcptInfo
1931  *     Purpose:  Given an uplink allocation, this function returns
1932  *               uplink grant information which is needed by PHY to
1933  *               decode data sent from UE. This information includes:
1934  *               - RB start
1935  *               - Number of RBs
1936  *               - RV
1937  *
1938  *  @param[in]  RgSchUlAlloc   *alloc
1939  *  @param[out] U8             *rbStartRef
1940  *  @param[out] U8             *numRbRef
1941  *  @param[out] U8             *rvRef
1942  *  @param[out] U16            *size
1943  *  @param[out] TfuModScheme   *modType
1944  *  @param[out] Bool           *isRtx
1945  *  @param[out] U8             *nDmrs
1946  *  @param[out] Bool           *ndi
1947  *  @param[out] U8             *hqPId
1948  *  @return  S16
1949  **/
1950 #ifdef ANSI
1951 S16 rgSCHUtlAllocRcptInfo
1952 (
1953 RgSchUlAlloc   *alloc,
1954 CmLteRnti      *rnti,
1955 U8             *iMcsRef,
1956 U8             *rbStartRef,
1957 U8             *numRbRef,
1958 U8             *rvRef,
1959 U16            *size,
1960 TfuModScheme   *modType,
1961 Bool           *isRtx,
1962 U8             *nDmrs,
1963 Bool           *ndi,
1964 U8             *hqPId
1965 )
1966 #else
1967 S16 rgSCHUtlAllocRcptInfo(alloc, rnti, iMcsRef, rbStartRef, numRbRef,
1968                                  rvRef, size, modType, isRtx, nDmrs, ndi,
1969                                  hqPId)
1970 RgSchUlAlloc   *alloc;
1971 CmLteRnti      *rnti;
1972 U8             *iMcsRef;
1973 U8             *rbStartRef;
1974 U8             *numRbRef;
1975 U8             *rvRef;
1976 U16            *size;
1977 TfuModScheme   *modType;
1978 Bool           *isRtx;
1979 U8             *nDmrs;
1980 Bool           *ndi;
1981 U8             *hqPId;
1982 #endif
1983 {
1984    /* Modulation order for 16qam UEs would be
1985     * min(4,modulation order in grant). Please refer to 36.213-8.6.1*/
1986    CmLteUeCategory ueCtgy;
1987
1988 #if (ERRCLASS & ERRCLS_DEBUG)
1989    if ((alloc == NULLP) || (alloc->hqProc == NULLP))
1990    {
1991       return RFAILED;
1992    }
1993 #endif
1994
1995    if ( !alloc->forMsg3 )
1996    {
1997       if ( ((alloc->ue) == NULLP) ||  (RG_SCH_CMN_GET_UE(alloc->ue, alloc->ue->cell) == NULLP))
1998       {
1999          RLOG_ARG2(L_ERROR,DBG_CELLID,alloc->ue->cell->cellId,
2000                      "Failed: ue->sch is null RNTI:%d,isRetx=%d",
2001                      alloc->rnti, alloc->grnt.isRtx);
2002          return RFAILED; 
2003       }
2004      ueCtgy =  (RG_SCH_CMN_GET_UE_CTGY(alloc->ue));
2005    }
2006
2007    *iMcsRef    = alloc->grnt.iMcs;
2008    *rbStartRef = alloc->grnt.rbStart;
2009    *numRbRef   = alloc->grnt.numRb;
2010    *rvRef      = rgRvTable[alloc->hqProc->rvIdx];
2011    *rnti       = alloc->rnti;
2012    *size       = alloc->grnt.datSz;
2013    *modType    = (alloc->forMsg3)? alloc->grnt.modOdr:
2014                          ((ueCtgy == CM_LTE_UE_CAT_5)?
2015                          alloc->grnt.modOdr:
2016                          (RGSCH_MIN(RGSCH_QM_QPSK,alloc->grnt.modOdr)));
2017    *isRtx      = alloc->grnt.isRtx;
2018    *nDmrs      = alloc->grnt.nDmrs;
2019    *ndi        = alloc->hqProc->ndi;
2020    *hqPId      = alloc->hqProc->procId;
2021
2022    return ROK;
2023 }
2024 #else
2025 /**
2026  * @brief Returns uplink grant information required to permit
2027  *        PHY to receive data
2028  *
2029  * @details
2030  *
2031  *     Function: rgSCHUtlAllocRcptInfo
2032  *     Purpose:  Given an uplink allocation, this function returns
2033  *               uplink grant information which is needed by PHY to
2034  *               decode data sent from UE. This information includes:
2035  *               - RB start
2036  *               - Number of RBs
2037  *               - RV
2038  *
2039  *  @param[in]  RgSchUlAlloc   *alloc
2040  *  @param[out] U8             *rbStartRef
2041  *  @param[out] U8             *numRbRef
2042  *  @param[out] U8             *rvRef
2043  *  @param[out] U16            *size
2044  *  @param[out] TfuModScheme   *modType
2045  *  @return  S16
2046  **/
2047 #ifdef ANSI
2048 S16 rgSCHUtlAllocRcptInfo
2049 (
2050 RgSchCellCb             *cell,
2051 RgSchUlAlloc            *alloc,
2052 CmLteTimingInfo         *timeInfo,
2053 TfuUeUlSchRecpInfo      *recpReq
2054 )
2055 #else
2056 S16 rgSCHUtlAllocRcptInfo(cell, alloc, timeInfo, recpReq)
2057 RgSchCellCb             *cell;
2058 RgSchUlAlloc            *alloc;
2059 CmLteTimingInfo         *timeInfo;
2060 TfuUeUlSchRecpInfo      *recpReq;
2061 #endif
2062 {
2063 #if (ERRCLASS & ERRCLS_DEBUG)
2064    if ((alloc == NULLP) || (alloc->hqProc == NULLP))
2065    {
2066       return RFAILED;
2067    }
2068 #endif
2069    recpReq->size           = alloc->grnt.datSz;
2070    recpReq->rbStart        = alloc->grnt.rbStart;
2071    recpReq->numRb          = alloc->grnt.numRb;
2072    /* Modulation order min(4,mod in grant) for 16 qam UEs.
2073     * Please refer to 36.213-8.6.1*/
2074 #ifdef FOUR_TX_ANTENNA
2075    recpReq->modType        = (TfuModScheme)((alloc->forMsg3)?alloc->grnt.modOdr:
2076          (/*(alloc->ue->ueCatEnum == CM_LTE_UE_CAT_5)?
2077             alloc->grnt.modOdr:    *//* Chandra:TmpFx-TM500 Cat5 with Only16QAM */
2078           (RGSCH_MIN(RGSCH_QM_QPSK,alloc->grnt.modOdr))));
2079 #else
2080    recpReq->modType        = (TfuModScheme)((alloc->forMsg3)?alloc->grnt.modOdr:
2081                              ((alloc->ue->ueCatEnum == CM_LTE_UE_CAT_5)?
2082                               alloc->grnt.modOdr:
2083                              (RGSCH_MIN(RGSCH_QM_QPSK,alloc->grnt.modOdr))));
2084 #endif
2085    recpReq->nDmrs          = alloc->grnt.nDmrs;
2086    recpReq->hoppingEnbld   = FALSE;
2087    recpReq->hoppingBits    = 0;
2088    recpReq->isRtx          = alloc->grnt.isRtx;
2089    recpReq->ndi            = alloc->hqProc->ndi;   
2090    recpReq->rv             = rgRvTable[alloc->hqProc->rvIdx];
2091 #ifndef LTE_TDD
2092    recpReq->harqProcId = alloc->hqProc->procId;
2093 #else
2094    recpReq->harqProcId = rgSCHCmnGetUlHqProcIdx(timeInfo, cell);
2095 #endif
2096    /* Transmission mode is SISO till Uplink MIMO is implemented. */
2097    recpReq->txMode   = 0;
2098    /* This value needs to filled in in the case of frequency hopping. */
2099    recpReq->crntTxNb = 0;
2100
2101    recpReq->mcs = alloc->grnt.iMcs;
2102 #ifdef RG_5GTF
2103    recpReq->rbgStart = alloc->grnt.vrbgStart;
2104    recpReq->numRbg = alloc->grnt.numVrbg;
2105    recpReq->xPUSCHRange = alloc->grnt.xPUSCHRange;
2106    //TODO_SID Need to check
2107    recpReq->nAntPortLayer = 0;
2108    recpReq->SCID = alloc->grnt.SCID;
2109    recpReq->PMI = alloc->grnt.PMI;
2110    recpReq->uciWoTBFlag = alloc->grnt.uciOnxPUSCH;
2111    if(alloc->ue)
2112    {
2113       recpReq->beamIndex = alloc->ue->ue5gtfCb.BeamId;
2114    }
2115 #endif
2116
2117 #ifdef TENB_STATS
2118    if (!alloc->forMsg3)
2119    {
2120       if (alloc->grnt.isRtx)
2121       {
2122          alloc->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(alloc->ue->cell)].ulRetxOccns++;
2123       }
2124       else
2125       {
2126          alloc->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(alloc->ue->cell)].ulTxOccns++;
2127          alloc->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(alloc->ue->cell)].ulSumiTbs += \
2128             rgSCHCmnUlGetITbsFrmIMcs(alloc->grnt.iMcs);
2129          alloc->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(alloc->ue->cell)].ulNumiTbs ++;
2130          cell->tenbStats->sch.ulSumiTbs += \
2131             rgSCHCmnUlGetITbsFrmIMcs(alloc->grnt.iMcs);
2132          cell->tenbStats->sch.ulNumiTbs ++;
2133       }
2134       alloc->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(alloc->ue->cell)].ulPrbUsg += alloc->grnt.numRb;
2135       cell->tenbStats->sch.ulPrbUsage[0] += alloc->grnt.numRb;
2136    }
2137 #endif
2138   /* ccpu00117050 - DEL - nSrs setting at rgSCHUtlAllocRcptInfo */
2139    return ROK;
2140 }
2141 #endif
2142
2143 #ifdef LTE_TDD
2144 /**
2145  * @brief This function initialises the PRACH slot occasions
2146  *
2147  * @details
2148  *
2149  *     Function: rgSCHUtlUpdPrachOcc
2150  *     Purpose:  This function updates the PRACH slots based on
2151  *               RGR configuration.
2152  *
2153  *     Invoked by: Scheduler
2154  *
2155  *  @param[in]  RgSchCellCb      *cell
2156  *  @param[in]  RgrTddPrachInfo  *cellCfg
2157  *  @return     Void
2158  *
2159  **/
2160 #ifdef ANSI
2161 PRIVATE Void rgSCHUtlUpdPrachOcc
2162 (
2163 RgSchCellCb       *cell,
2164 RgrTddPrachInfo   *cellCfg
2165 )
2166 #else
2167 PRIVATE Void rgSCHUtlUpdPrachOcc(cell, cellCfg)
2168 RgSchCellCb       *cell;
2169 RgrTddPrachInfo   *cellCfg;
2170 #endif
2171 {
2172    U8   idx;
2173    U8    count = 0;
2174    U8    size;
2175    U8    startIdx;
2176    U8    endIdx;
2177
2178    /* In the 1st half frame */
2179    if(cellCfg->halfFrm == 0)
2180    {
2181       startIdx = 2;
2182       endIdx = 6;
2183    }
2184    /* In the 2nd half frame */
2185    else
2186    {
2187       startIdx = 6;
2188       endIdx = 10;
2189    }
2190    for(idx = startIdx; idx < endIdx; idx++)
2191    {
2192       if(rgSchTddUlDlSubfrmTbl[cell->ulDlCfgIdx][idx]
2193             == RG_SCH_TDD_UL_slot)
2194       {
2195          if(cellCfg->ulStartSfIdx == count)
2196          {
2197             size = cell->rachCfg.raOccasion.size;
2198             cell->rachCfg.raOccasion.slotNum[size] = idx;
2199             cell->rachCfg.raOccasion.size++;
2200             break;
2201          }
2202          count ++;
2203       }
2204    }
2205    RETVOID;
2206 }
2207
2208 /**
2209  * @brief This function initialises the PRACH occasions
2210  *
2211  * @details
2212  *
2213  *     Function: rgSCHUtlPrachCfgInit
2214  *     Purpose:  This function initialises the PRACH occasions based on
2215  *               RGR configuration.
2216  *
2217  *     Invoked by: Scheduler
2218  *
2219  *  @param[in]  RgSchCellCb       *cell
2220  *  @param[in]  RgrCellCfg        *cellCfg
2221  *  @return     Void
2222  *
2223  **/
2224 #ifdef ANSI
2225 Void rgSCHUtlPrachCfgInit
2226 (
2227 RgSchCellCb       *cell,
2228 RgrCellCfg        *cellCfg
2229 )
2230 #else
2231 Void rgSCHUtlPrachCfgInit(cell, cellCfg)
2232 RgSchCellCb       *cell;
2233 RgrCellCfg        *cellCfg;
2234 #endif
2235 {
2236    U8 idx;
2237    U8 subfrmIdx;
2238    U8 splFrm;
2239
2240    if(cellCfg->prachRscInfo.numRsc <= 0)
2241    {
2242       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId, "Invalid"
2243                   "PRACH resources Configuration ");
2244       RETVOID;
2245    }
2246
2247    /* Update SFN occasions */
2248    cell->rachCfg.raOccasion.sfnEnum =
2249                      cellCfg->prachRscInfo.prachInfo[0].sfn;
2250
2251    cell->rachCfg.raOccasion.size = 0;
2252
2253    /* Update slot occasions */
2254    for(idx = 0; idx < cellCfg->prachRscInfo.numRsc; idx++)
2255    {
2256       if(cellCfg->prachRscInfo.prachInfo[idx].freqIdx == 0)
2257       {
2258          if(cellCfg->prachRscInfo.prachInfo[idx].halfFrm == 0)
2259          {
2260             splFrm = 1;
2261          }
2262          else
2263          {
2264             splFrm = 6;
2265          }
2266          if(cellCfg->prachRscInfo.prachInfo[idx].ulStartSfIdx ==
2267                                                 RGR_TDD_SPL_UL_IDX)
2268          {
2269             subfrmIdx = cell->rachCfg.raOccasion.size;
2270             cell->rachCfg.raOccasion.slotNum[subfrmIdx] = splFrm;
2271             cell->rachCfg.raOccasion.size++;
2272          }
2273          else
2274          {
2275             rgSCHUtlUpdPrachOcc(cell,
2276                   &cellCfg->prachRscInfo.prachInfo[idx]);
2277          }
2278       }
2279    }
2280    RETVOID;
2281 }
2282
2283 /**
2284  * @brief This function performs RGR cell initialization
2285  *
2286  * @details
2287  *
2288  *     Function: rgSCHUtlRgrCellCfg
2289  *     Purpose:  This function initialises the cell with RGR configuration
2290  *               and slot related initialization.
2291  *
2292  *     Invoked by: Scheduler
2293  *
2294  *  @param[in]  RgSchCellCb       *cell
2295  *  @param[in]  RgrCellCfg        *cellCfg
2296  *  @param[in]  RgSchErrInfo      *errInfo
2297  *  @return     Void
2298  *
2299  **/
2300 #ifdef ANSI
2301 S16 rgSCHUtlRgrCellCfg
2302 (
2303 RgSchCellCb       *cell,
2304 RgrCellCfg        *cellCfg,
2305 RgSchErrInfo      *errInfo
2306 )
2307 #else
2308 S16 rgSCHUtlRgrCellCfg(cell, cellCfg, errInfo)
2309 RgSchCellCb       *cell;
2310 RgrCellCfg        *cellCfg;
2311 RgSchErrInfo      *errInfo;
2312 #endif
2313 {
2314    U8              i;
2315    U8              sfn=0;
2316    U8              sfNum = 0;
2317    RgSchDlSf       *sf;
2318    CmLteTimingInfo frm;
2319    U8              ulDlCfgIdx = cellCfg->ulDlCfgIdx;
2320    U8              maxslots ;
2321    U8              maxDlslots;
2322    S16             ret = ROK;
2323    U16             bw;         /*!< Number of RBs in the cell */
2324    
2325    memset(&frm,0,sizeof(CmLteTimingInfo));
2326
2327    /* ccpu00132657-MOD- Determining DLSF array size independent of DELTAS */
2328    maxDlslots = rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
2329    maxslots = 2 * maxDlslots;
2330    cell->numDlSubfrms = maxslots;
2331 /* ACC-TDD <ccpu00130639> */
2332    cell->tddHqSfnCycle = -1;
2333    cell->ulDlCfgIdx = ulDlCfgIdx;
2334
2335    /* PRACH Occasions Initialization */
2336    rgSCHUtlPrachCfgInit(cell, cellCfg);
2337
2338    /* ccpu00132658- Moved out of below for loop since the updating rbgSize and 
2339     * bw are independent of sfNum*/
2340    /* determine the RBG size and no of RBGs for the configured
2341     * DL BW */
2342    if (cell->bwCfg.dlTotalBw > 63)
2343    {
2344       cell->rbgSize  = 4;
2345    }
2346    else if (cell->bwCfg.dlTotalBw > 26)
2347    {
2348       cell->rbgSize  = 3;
2349    }
2350    else if (cell->bwCfg.dlTotalBw > 10)
2351    {
2352       cell->rbgSize  = 2;
2353    }
2354    else
2355    {
2356       cell->rbgSize  = 1;
2357    }
2358    cell->noOfRbgs = RGSCH_CEIL(cell->bwCfg.dlTotalBw, cell->rbgSize);
2359
2360    bw    = cell->bwCfg.dlTotalBw;
2361
2362    rgSCHUtlAllocSBuf(cell->instIdx,
2363                (Data **)&cell->subFrms, sizeof(RgSchDlSf *) * maxslots);
2364    if (cell->subFrms == NULLP)
2365    {
2366       return RFAILED;
2367    }
2368
2369    /* Create memory for each frame. */
2370    for(i = 0; i < maxslots; i++)
2371    {
2372       while(rgSchTddUlDlSubfrmTbl[ulDlCfgIdx][sfNum] ==
2373             RG_SCH_TDD_UL_slot)
2374       {
2375          sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
2376       }
2377
2378       rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&sf, sizeof(RgSchDlSf));
2379       if (sf == NULLP)
2380       {
2381          break;
2382       }
2383       memset(sf, 0, sizeof(*sf));
2384
2385 #ifdef LTE_ADV
2386       if (ROK != rgSCHLaaInitDlSfCb(cell, sf))
2387       {
2388          break;
2389       }
2390 #endif
2391       sf->sfNum = sfNum;
2392       sf->bw    = bw;
2393 #ifdef LTEMAC_SPS
2394    /* Mark SPS bandwidth to be occupied */
2395    sf->bwAlloced = ((cellCfg->spsCfg.maxSpsDlBw +
2396       cell->rbgSize - 1)/cell->rbgSize) * cell->rbgSize;
2397    sf->spsAllocdBw = 0;
2398    sf->type2End = sf->bwAlloced/cell->rbgSize;
2399 #else
2400    sf->bwAlloced = 0;
2401    /* Fix for ccpu00123918*/
2402    sf->type2Start = 0;
2403 #endif /* LTEMAC_SPS */
2404       /* Initialize the ackNakRepQ here */
2405 #ifdef RG_MAC_MEASGAP
2406       cmLListInit (&(sf->ackNakRepQ));
2407 #endif
2408       cell->subFrms[i] = sf;
2409       sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
2410    }
2411    if (i != maxslots)
2412    {
2413       for (; i > 0; i--)
2414       {
2415          /* ccpu00117052 - MOD - Passing double pointer
2416          for proper NULLP assignment*/
2417          rgSCHUtlFreeSBuf(cell->instIdx,
2418                (Data **)(&(cell->subFrms[i-1])), sizeof(RgSchDlSf));
2419 #ifdef LTE_ADV
2420          rgSCHLaaDeInitDlSfCb(cell, sf);
2421 #endif
2422       }
2423       /* ccpu00117052 - MOD - Passing double pointer
2424       for proper NULLP assignment*/
2425       rgSCHUtlFreeSBuf(cell->instIdx,
2426             (Data **)(&(cell->subFrms)), sizeof(RgSchDlSf *) * maxslots);
2427
2428       return RFAILED;
2429    }
2430
2431    if (cell->sc.apis == NULLP)
2432    {
2433       cell->sc.apis = &rgSchCmnApis;
2434    }
2435    ret = cell->sc.apis->rgSCHRgrCellCfg(cell, cellCfg, errInfo);
2436
2437    if (ret != ROK)
2438    {
2439       /* ccpu00132286- Removed deletion of sf nodes as the deletion will be 
2440        * happening during CellDelete. Added return handling to provide negative
2441        * confirm*/
2442       return (ret);
2443    }
2444
2445    /* Release the slots and thereby perform the initialization */
2446    for (i = 0; i < maxslots; i++)
2447    {
2448      if((i > 0) && (i%maxDlslots == 0))
2449      {
2450       sfn++;
2451      }
2452      frm.sfn = sfn;
2453      frm.slot = cell->subFrms[i]->sfNum;
2454      rgSCHUtlDlRlsSubFrm(cell, frm);
2455    }
2456
2457    return (ret);
2458 }
2459
2460 #else
2461 \f
2462 /**
2463  * @brief This function performs scheduler related cell creation
2464  *
2465  * @details
2466  *
2467  *     Function: rgSCHUtlRgrCellCfg
2468  *     Purpose:  This function creates the slots needed for the
2469  *               cell. It then peforms init of the scheduler by calling
2470  *               scheduler specific cell init function.
2471  *
2472  *     Invoked by: Scheduler
2473  *
2474  *  @param[in]  RgSchCellCb          *cell
2475  *  @param[in]  RgrCellCfg        *cellCfg
2476  *  @param[in]  RgSchErrInfo         *errInfo
2477  *  @return     Void
2478  *
2479  **/
2480 #ifdef ANSI
2481 S16 rgSCHUtlRgrCellCfg
2482 (
2483 RgSchCellCb       *cell,
2484 RgrCellCfg        *cellCfg,
2485 RgSchErrInfo      *errInfo
2486 )
2487 #else
2488 S16 rgSCHUtlRgrCellCfg(cell, cellCfg, errInfo)
2489 RgSchCellCb       *cell;
2490 RgrCellCfg        *cellCfg;
2491 RgSchErrInfo      *errInfo;
2492 #endif
2493 {
2494    U8              i;
2495    RgSchDlSf       *sf;
2496    CmLteTimingInfo frm;
2497    S16             ret;
2498    Inst            inst = cell->instIdx;
2499    /* LTE_ADV_FLAG_REMOVED_START */
2500    U16             len;
2501    len = (U16)((cell->bwCfg.dlTotalBw % 8 == 0) ? (cell->bwCfg.dlTotalBw/8) : (cell->bwCfg.dlTotalBw/8 + 1)); /*KW fix for LTE_ADV */
2502    /* LTE_ADV_FLAG_REMOVED_END */
2503
2504    memset(&frm,0,sizeof(CmLteTimingInfo));
2505
2506    /* determine the RBG size and no of RBGs for the configured
2507     * DL BW */
2508    if (cell->bwCfg.dlTotalBw > 63)
2509    {
2510       cell->rbgSize  = 4;
2511    }
2512    else if (cell->bwCfg.dlTotalBw > 26)
2513    {
2514       cell->rbgSize  = 3;
2515    }
2516    else if (cell->bwCfg.dlTotalBw > 10)
2517    {
2518       cell->rbgSize  = 2;
2519    }
2520    else
2521    {
2522       cell->rbgSize  = 1;
2523    }
2524    cell->noOfRbgs = RGSCH_CEIL(cell->bwCfg.dlTotalBw, cell->rbgSize);
2525    /* Create memory for each frame. */
2526    /* Changing loop limit from
2527       RGSCH_NUM_SUB_FRAMES to RGSCH_NUM_DL_slotS */
2528    for(i = 0; i < RGSCH_NUM_DL_slotS; i++)
2529    {
2530       rgSCHUtlAllocSBuf(inst, (Data **)&sf, sizeof(RgSchDlSf));
2531       if (sf == NULLP)
2532       {
2533          break;
2534       }
2535       memset(sf, 0, sizeof(*sf));
2536
2537 #ifdef LTE_ADV
2538       if (ROK != rgSCHLaaInitDlSfCb(cell, sf))
2539       {
2540          break;
2541       }
2542 #endif
2543       /* Doing MOD operation before assigning value of i */
2544       sf->sfNum = i % RGSCH_NUM_SUB_FRAMES;
2545       sf->bw    = cell->bwCfg.dlTotalBw;
2546       /* Initialize the ackNakRepQ here */
2547 #ifdef RG_MAC_MEASGAP
2548       cmLListInit (&(sf->ackNakRepQ));
2549 #endif
2550       cell->subFrms[i] = sf;
2551       /* LTE_ADV_FLAG_REMOVED_START */
2552       if (cell->lteAdvCb.dsfrCfg.status == RGR_ENABLE)
2553       {
2554          /*initialize the RNTP Buffer*/
2555          if(rgSchDSFRRntpInfoInit(&sf->rntpInfo, cell, sf->bw))
2556          {
2557             return RFAILED; 
2558          }
2559       }
2560
2561       if (cell->lteAdvCb.sfrCfg.status == RGR_ENABLE)
2562       {
2563          /*initialise the pools of CC and CE*/
2564          if(rgSchSFRTotalPoolInit(cell, sf))
2565          {
2566             return RFAILED; 
2567          }
2568       }
2569       /* LTE_ADV_FLAG_REMOVED_END */
2570    }
2571
2572    /* LTE_ADV_FLAG_REMOVED_START */
2573    /* Allocate memory for "scheduled UE" Info */
2574    if (cell->lteAdvCb.dsfrCfg.status == RGR_ENABLE)
2575    {    
2576       if((rgSCHUtlAllocSBuf(inst, (Data**)&(cell->rntpAggrInfo.val),
2577                   (len * sizeof(U8)))) != ROK)
2578       {
2579          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Memory allocation FAILED for RNTP Alloc");
2580          return RFAILED;
2581       }
2582       cell->rntpAggrInfo.pres = PRSNT_NODEF;
2583       cell->rntpAggrInfo.len  = len;
2584    }     
2585    /* LTE_ADV_FLAG_REMOVED_END */
2586
2587    /* Changing loop limit from
2588       RGSCH_NUM_SUB_FRAMES to RGSCH_NUM_DL_slotS */
2589    if (i != RGSCH_NUM_DL_slotS)
2590    {
2591       for (; i > 0; i--)
2592       {
2593          /* ccpu00117052 - MOD - Passing double pointer
2594          for proper NULLP assignment*/
2595          rgSCHUtlFreeSBuf(inst, (Data **)(&(cell->subFrms[i-1])),
2596                sizeof(RgSchDlSf));
2597 #ifdef LTE_ADV
2598          rgSCHLaaDeInitDlSfCb(cell, sf);
2599 #endif
2600       }
2601       return RFAILED;
2602    }
2603
2604    if (cell->sc.apis == NULLP)
2605    {
2606       cell->sc.apis = &rgSchCmnApis;
2607    }
2608
2609    /* Release the slots and thereby perform the initialization */
2610    for (i = 0; i < RGSCH_NUM_DL_slotS; i++)
2611    {
2612       if (i >= RGSCH_NUM_SUB_FRAMES)
2613       {
2614          /* [ccpu00123828]-MOD-The below statement sfn += 1incorrectly modified
2615           * the value of sfn for i>=10 thru 19. Correct way is to assign
2616           it to one */
2617          frm.sfn = 1;
2618       }
2619       frm.slot = i % RGSCH_NUM_SUB_FRAMES;
2620       rgSCHUtlDlRlsSubFrm(cell, frm);
2621    }
2622
2623    ret = cell->sc.apis->rgSCHRgrCellCfg(cell, cellCfg, errInfo);
2624    if (ret != ROK)
2625    {
2626       errInfo->errCause = RGSCHERR_SCH_CFG;
2627       return RFAILED;
2628    }
2629 #ifdef EMTC_ENABLE
2630       if(cell->emtcEnable)
2631       {
2632          /* TODO: Repetition framework in RGR and APP */
2633          if (rgSCHUtlEmtcResMngmtInit(
2634                   cell, 
2635                   RGSCH_IOT_PDSCH_POOLSZ, RGSCH_IOT_PDSCH_DELTA, cellCfg->bwCfg.dlTotalBw,
2636                   RGSCH_IOT_PUSCH_POOLSZ, RGSCH_IOT_PUSCH_DELTA, RGSCH_IOT_PUSCH_MAXFREQSZ,
2637                   RGSCH_IOT_PUCCH_POOLSZ, RGSCH_IOT_PUCCH_DELTA, RGSCH_IOT_PUCCH_MAXFREQSZ) != ROK)
2638          {
2639             errInfo->errCause = RGSCHERR_SCH_CFG;
2640             return RFAILED;
2641          }
2642       }
2643 #endif
2644
2645    return (ret);
2646 }
2647 #endif
2648
2649 \f
2650 /**
2651  * @brief This function performs the cell reconfiguration at RGR interface
2652  *
2653  * @details
2654  *
2655  *     Function: rgSCHUtlRgrCellRecfg
2656  *     Purpose:  This function updates the reconfigurable parameters
2657  *               on the cell control block for the scheduler.
2658  *
2659  *     Invoked by: Scheduler
2660  *
2661  *  @param[in]  RgSchCellCb          *cell
2662  *  @param[in]  RgrCellCfg        *cellCfg
2663  *  @param[in]  RgSchErrInfo         *errInfo
2664  *  @return     Void
2665  *
2666  **/
2667 #ifdef ANSI
2668 S16 rgSCHUtlRgrCellRecfg
2669 (
2670 RgSchCellCb       *cell,
2671 RgrCellRecfg      *recfg,
2672 RgSchErrInfo      *err
2673 )
2674 #else
2675 S16 rgSCHUtlRgrCellRecfg(cell, recfg, err)
2676 RgSchCellCb       *cell;
2677 RgrCellRecfg      *recfg;
2678 RgSchErrInfo      *err;
2679 #endif
2680 {
2681    return (cell->sc.apis->rgSCHRgrCellRecfg(cell, recfg, err));
2682 }
2683
2684
2685 \f
2686 /**
2687  * @brief This function returns the Y value of UE for a sub frame
2688  *
2689  * @details
2690  *
2691  *     Function: rgSCHUtlFreeCell
2692  *     Purpose:  This function updates the value of Y stored in the
2693  *               UE control block. It uses the previously computed
2694  *               value for computing for this slot.
2695  *
2696  *     Invoked by: Scheduler
2697  *
2698  *  @param[in]  RgSchCellCb          *cell
2699  *  @return     Void
2700  *
2701  **/
2702 #ifdef ANSI
2703 S16 rgSCHUtlFreeCell
2704 (
2705 RgSchCellCb          *cell
2706 )
2707 #else
2708 S16 rgSCHUtlFreeCell(cell)
2709 RgSchCellCb          *cell;
2710 #endif
2711 {
2712    U8               i;
2713    CmLListCp        *lst;
2714    RgSchPdcch       *pdcch;
2715    RgSchPdcchInfo   *pdcchInfo;
2716    RgSchPhichInfo   *phichInfo;
2717    RgSchPhich       *phich;
2718    Inst             inst = cell->instIdx;
2719    U8               maxslots;
2720 #ifdef LTE_TDD
2721    RgSchRaReqInfo *raReqInfo;
2722    U8                idx;
2723 #endif
2724
2725 #ifdef LTE_TDD
2726    maxslots = cell->numDlSubfrms;
2727 #else
2728    maxslots = RGSCH_NUM_DL_slotS;
2729 #endif
2730
2731
2732    /* Invoke the index for scheduler, cell deletion */
2733    cell->sc.apis->rgSCHFreeCell(cell);
2734
2735    /* Release the slots allocated               */
2736    for (i = 0; i < maxslots; i++)
2737    {
2738 #ifdef LTE_ADV
2739       rgSCHLaaDeInitDlSfCb(cell, cell->subFrms[i]);
2740 #endif
2741       pdcchInfo = &cell->subFrms[i]->pdcchInfo;
2742       /* ccpu00117052 - MOD - Passing double pointer
2743       for proper NULLP assignment*/
2744       rgSCHUtlFreeSBuf(inst, (Data **)(&(pdcchInfo->map)),
2745             (pdcchInfo->nCce + 7) >> 3);
2746       while (pdcchInfo->pdcchs.first != NULLP)
2747       {
2748          pdcch = (RgSchPdcch *)pdcchInfo->pdcchs.first->node;
2749          cmLListDelFrm(&pdcchInfo->pdcchs, pdcchInfo->pdcchs.first);
2750       /* ccpu00117052 - MOD - Passing double pointer
2751       for proper NULLP assignment*/
2752          rgSCHUtlFreeSBuf(inst, (Data **)&pdcch, sizeof(RgSchPdcch));
2753       }
2754
2755       phichInfo = &cell->subFrms[i]->phichInfo;
2756       while(phichInfo->phichs.first != NULLP)
2757       {
2758          phich = (RgSchPhich *)phichInfo->phichs.first->node;
2759          cmLListDelFrm(&phichInfo->phichs, phichInfo->phichs.first);
2760          RGSCH_PHICH_FREE(inst, phich, sizeof(RgSchPhich));
2761       }
2762
2763       /* LTE_ADV_FLAG_REMOVED_START */
2764       /*releasing SFR pool entries*/
2765       rgSchSFRTotalPoolFree(&cell->subFrms[i]->sfrTotalPoolInfo, cell);
2766
2767       /*releasing dsfr rntp pattern info*/
2768       rgSchDSFRRntpInfoFree(&cell->subFrms[i]->rntpInfo, cell, 
2769                                        cell->bwCfg.dlTotalBw);
2770       /* LTE_ADV_FLAG_REMOVED_END */
2771
2772       /* ccpu00117052 - MOD - Passing double pointer
2773       for proper NULLP assignment*/
2774       rgSCHUtlFreeSBuf(inst, (Data **)(&(cell->subFrms[i])), sizeof(RgSchDlSf));
2775    }
2776 #ifdef LTE_TDD
2777    /* Release the slot pointers */
2778    /* ccpu00117052 - MOD - Passing double pointer
2779    for proper NULLP assignment*/
2780    rgSCHUtlFreeSBuf(inst,
2781          (Data **) (&(cell->subFrms)), sizeof(RgSchDlSf *) * maxslots);
2782
2783    for(idx=0; idx < cell->raInfo.lstSize; idx++)
2784    {
2785       lst = &cell->raInfo.raReqLst[idx];
2786       while (lst->first != NULLP)
2787       {
2788          raReqInfo = (RgSchRaReqInfo *)lst->first->node;
2789          cmLListDelFrm(lst, &raReqInfo->raReqLstEnt);
2790          /* ccpu00117052 - MOD - Passing double pointer
2791          for proper NULLP assignment*/
2792          rgSCHUtlFreeSBuf(inst,(Data **)&raReqInfo, sizeof(RgSchRaReqInfo));
2793       }
2794    }
2795    /* ccpu00117052 - MOD - Passing double pointer
2796    for proper NULLP assignment*/
2797    rgSCHUtlFreeSBuf(inst,
2798          (Data **)(&(cell->raInfo.raReqLst)),
2799             sizeof(CmLListCp) * (cell->raInfo.lstSize));
2800 #endif
2801
2802    /* Release allocated pdcchs */
2803    lst = &cell->pdcchLst;
2804    while (lst->first != NULLP)
2805    {
2806       pdcch = (RgSchPdcch *)lst->first->node;
2807       cmLListDelFrm(lst, &pdcch->lnk);
2808 #ifdef EMTC_ENABLE
2809       if(cell->emtcEnable)
2810       {
2811          rgSCHEmtcPdcchFree(cell, pdcch);
2812          rgSCHUtlEmtcResMngmtDeinit(cell);
2813       }
2814 #endif
2815       /* ccpu00117052 - MOD - Passing double pointer
2816       for proper NULLP assignment*/
2817       rgSCHUtlFreeSBuf(inst,(Data **)&pdcch, sizeof(RgSchPdcch));
2818    }
2819 #ifdef LTE_ADV
2820    rgSCHLaaFreeLists(cell);
2821 #endif
2822
2823    /* LTE_ADV_FLAG_REMOVED_START */
2824    /* releasing RNTP Aggregation Info from CellCb*/
2825    rgSchDSFRRntpInfoFree(&cell->rntpAggrInfo, cell, cell->bwCfg.dlTotalBw);
2826    /* LTE_ADV_FLAG_REMOVED_END */
2827
2828    return ROK;
2829 }
2830
2831 \f
2832 /**
2833  * @brief This function adds the UE to scheduler
2834  *
2835  * @details
2836  *
2837  *     Function: rgSCHUtlRgrUeCfg
2838  *     Purpose:  This function performs addition of UE to scheduler
2839  *               1. First, it updates the Y table in the UE
2840  *               2. Then, it calls the scheduler's handler for UE addition
2841  *
2842  *     Invoked by: Scheduler
2843  *
2844  *  @param[in]  RgSchCellCb          *cell
2845  *  @param[in]  RgSchUeCb            *ue
2846  *  @param[in]  RgrUeCfg             *cfg
2847  *  @param[in]  RgSchErrInfo            *err
2848  *  @return     S16
2849  *
2850  **/
2851 #ifdef ANSI
2852 S16 rgSCHUtlRgrUeCfg
2853 (
2854 RgSchCellCb                *cell,
2855 RgSchUeCb                  *ue,
2856 RgrUeCfg                   *cfg,
2857 RgSchErrInfo               *err
2858 )
2859 #else
2860 S16 rgSCHUtlRgrUeCfg(cell, ue, cfg, err)
2861 RgSchCellCb                *cell;
2862 RgSchUeCb                  *ue;
2863 RgrUeCfg                   *cfg;
2864 RgSchErrInfo               *err;
2865 #endif
2866 {
2867
2868    /* Assign TM 1 as UE's default TM */
2869    ue->mimoInfo.txMode = RGR_UE_TM_1;
2870    ue->txModeTransCmplt = TRUE;
2871    cmInitTimers(&ue->txModeTransTmr, 1);
2872    if (cfg->txMode.pres == PRSNT_NODEF)
2873    {
2874       /* DL MU-MIMO not supported */
2875       if (cfg->txMode.txModeEnum == RGR_UE_TM_5)
2876       {
2877          err->errCause = RGSCHERR_SCH_CFG;
2878          return RFAILED;
2879       }
2880       ue->mimoInfo.txMode = cfg->txMode.txModeEnum;
2881    }
2882    ue->ul.ulTxAntSel = cfg->ulTxAntSel;
2883    ue->mimoInfo.cdbkSbstRstrctn = cfg->ueCodeBookRstCfg;
2884 #ifdef TFU_UPGRADE
2885    ue->ueCatEnum = cfg->ueCatEnum;
2886    if ((cfg->puschDedCfg.bACKIdx > 15) ||
2887        (cfg->puschDedCfg.bCQIIdx > 15) ||
2888        (cfg->puschDedCfg.bRIIdx > 15))
2889    {
2890       err->errCause = RGSCHERR_SCH_CFG;
2891       return RFAILED;
2892    }
2893    ue->ul.betaHqOffst = cfg->puschDedCfg.bACKIdx;
2894    ue->ul.betaCqiOffst = cfg->puschDedCfg.bCQIIdx;
2895    ue->ul.betaRiOffst = cfg->puschDedCfg.bRIIdx;
2896 #endif
2897    ue->csgMmbrSta = cfg->csgMmbrSta;
2898 #ifdef RG_PFS_STATS
2899    memset(&ue->pfsStats, 0, sizeof(RgSchPfsStats));
2900 #endif
2901    /* Call the handler of the scheduler based on cell configuration */
2902    return (cell->sc.apis->rgSCHRgrUeCfg(cell, ue, cfg, err));
2903 }
2904 /* Start : LTEMAC_2.1_DEV_CFG */
2905 \f
2906 /**
2907  * @brief This function adds a service to scheduler
2908  *
2909  * @details
2910  *
2911  *     Function: rgSCHUtlRgrLcCfg
2912  *     Purpose:  This function performs addition of service to scheduler
2913  *               The addition is performed for each direction based
2914  *               the direction field of the configuration
2915  *
2916  *     Invoked by: Scheduler
2917  *
2918  *  @param[in]  RgSchCellCb          *cell
2919  *  @param[in]  RgSchUeCb            *ue
2920  *  @param[in]  RgSchDlLcCb          *dlLc
2921  *  @param[in]  RgrLchCfg            *cfg
2922  *  @param[in]  RgSchErrInfo         *err
2923  *  @return     S16
2924  *
2925  **/
2926 #ifdef ANSI
2927 S16 rgSCHUtlRgrLcCfg
2928 (
2929 RgSchCellCb                *cell,
2930 RgSchUeCb                  *ue,
2931 RgSchDlLcCb                *dlLc,
2932 RgrLchCfg               *cfg,
2933 RgSchErrInfo               *errInfo
2934 )
2935 #else
2936 S16 rgSCHUtlRgrLcCfg(cell, ue, dlLc, cfg, errInfo)
2937 RgSchCellCb                *cell;
2938 RgSchUeCb                  *ue;
2939 RgSchDlLcCb                *dlLc;
2940 RgrLchCfg               *cfg;
2941 RgSchErrInfo               *errInfo;
2942 #endif
2943 {
2944    return (cell->sc.apis->rgSCHRgrLchCfg(cell, ue, dlLc, cfg, errInfo));
2945 }
2946
2947 \f
2948 /**
2949  * @brief This function modifies a service to scheduler
2950  *
2951  * @details
2952  *
2953  *     Function: rgSCHUtlRgrLcRecfg
2954  *     Purpose:  This function performs modification of a service in
2955  *               scheduler. The modification is performed for each direction
2956  *               based the direction field of the configuration
2957  *
2958  *     Invoked by: Scheduler
2959  *
2960  *  @param[in]  RgSchCellCb          *cell
2961  *  @param[in]  RgSchUeCb            *ue
2962  *  @param[in]  RgSchDlLcCb          *dlLc
2963  *  @param[in]  RgrLchRecfg          *recfg
2964  *  @param[in]  RgSchErrInfo         *err
2965  *  @return     S16
2966  *
2967  **/
2968 #ifdef ANSI
2969 S16 rgSCHUtlRgrLcRecfg
2970 (
2971 RgSchCellCb                *cell,
2972 RgSchUeCb                  *ue,
2973 RgSchDlLcCb                *dlLc,
2974 RgrLchRecfg                *recfg,
2975 RgSchErrInfo               *err
2976 )
2977 #else
2978 S16 rgSCHUtlRgrLcRecfg(cell, ue, dlLc, recfg, err)
2979 RgSchCellCb                *cell;
2980 RgSchUeCb                  *ue;
2981 RgSchDlLcCb                *dlLc;
2982 RgrLchRecfg                *recfg;
2983 RgSchErrInfo               *err;
2984 #endif
2985 {
2986    return (cell->sc.apis->rgSCHRgrLchRecfg(cell, ue, dlLc, recfg, err));
2987 }
2988
2989 /**
2990  * @brief This function deletes a Lc in scheduler
2991  *
2992  * @details
2993  *
2994  *     Function: rgSCHUtlRgrLcDel
2995  *     Purpose:  This function performs deletion of Lc in scheduler
2996  *
2997  *     Invoked by: Scheduler
2998  *
2999  *  @param[in]  RgSchCellCb   *cell
3000  *  @param[in]  RgSchUeCb     *ue
3001  *  @param[in]  CmLteLcId     lcId
3002  *  @param[in]  U8            lcgId
3003  *  @return     S16
3004  *
3005  **/
3006 #ifdef ANSI
3007 S16 rgSCHUtlRgrLcDel
3008 (
3009 RgSchCellCb                *cell,
3010 RgSchUeCb                  *ue,
3011 CmLteLcId                  lcId,
3012 U8                         lcgId
3013 )
3014 #else
3015 S16 rgSCHUtlRgrLcDel(cell, ue, lcId, lcgId)
3016 RgSchCellCb                *cell;
3017 RgSchUeCb                  *ue;
3018 CmLteLcId                  lcId;
3019 U8                         lcgId;
3020 #endif
3021 {
3022    cell->sc.apis->rgSCHRgrLchDel(cell, ue, lcId, lcgId);
3023
3024    return  (ROK);
3025 } /* rgSCHUtlRgrLcDel */
3026
3027 /**
3028  * @brief This function adds a service to scheduler
3029  *
3030  * @details
3031  *
3032  *     Function: rgSCHUtlRgrLcgCfg
3033  *     Purpose:  This function performs addition of service to scheduler
3034  *               The addition is performed for each direction based
3035  *               the direction field of the configuration
3036  *
3037  *     Invoked by: Scheduler
3038  *
3039  *  @param[in]  RgSchCellCb          *cell
3040  *  @param[in]  RgSchUeCb            *ue
3041  *  @param[in]  RgrLchCfg            *cfg
3042  *  @param[in]  RgSchErrInfo         *err
3043  *  @return     S16
3044  *
3045  **/
3046 #ifdef ANSI
3047 S16 rgSCHUtlRgrLcgCfg
3048 (
3049 RgSchCellCb                *cell,
3050 RgSchUeCb                  *ue,
3051 RgrLcgCfg               *cfg,
3052 RgSchErrInfo               *errInfo
3053 )
3054 #else
3055 S16 rgSCHUtlRgrLcgCfg(cell, ue, cfg, errInfo)
3056 RgSchCellCb                *cell;
3057 RgSchUeCb                  *ue;
3058 RgrLcgCfg               *cfg;
3059 RgSchErrInfo               *errInfo;
3060 #endif
3061 {
3062    return (cell->sc.apis->rgSCHRgrLcgCfg(cell, ue, &(ue->ul.lcgArr[cfg->ulInfo.lcgId]), cfg, errInfo));
3063 }
3064
3065 \f
3066 /**
3067  * @brief This function modifies a service to scheduler
3068  *
3069  * @details
3070  *
3071  *     Function: rgSCHUtlRgrLcgRecfg
3072  *     Purpose:  This function performs modification of a service in
3073  *               scheduler. The modification is performed for each direction
3074  *               based the direction field of the configuration
3075  *
3076  *     Invoked by: Scheduler
3077  *
3078  *  @param[in]  RgSchCellCb          *cell
3079  *  @param[in]  RgSchUeCb            *ue
3080  *  @param[in]  RgrLcgRecfg          *recfg
3081  *  @param[in]  RgSchErrInfo         *err
3082  *  @return     S16
3083  *
3084  **/
3085 #ifdef ANSI
3086 S16 rgSCHUtlRgrLcgRecfg
3087 (
3088 RgSchCellCb                *cell,
3089 RgSchUeCb                  *ue,
3090 RgrLcgRecfg                *recfg,
3091 RgSchErrInfo               *err
3092 )
3093 #else
3094 S16 rgSCHUtlRgrLcgRecfg(cell, ue, recfg, err)
3095 RgSchCellCb                *cell;
3096 RgSchUeCb                  *ue;
3097 RgrLcgRecfg                *recfg;
3098 RgSchErrInfo               *err;
3099 #endif
3100 {
3101    return (cell->sc.apis->rgSCHRgrLcgRecfg(cell, ue, &(ue->ul.lcgArr[recfg->ulRecfg.lcgId]), recfg, err));
3102 } /* rgSCHUtlRgrLcRecfg */
3103
3104 /**
3105  * @brief This function modifies a service to scheduler
3106  *
3107  * @details
3108  *
3109  *     Function: rgSCHUtlRgrLcgDel
3110  *     Purpose:  This function performs modification of a service in
3111  *               scheduler. The modification is performed for each direction
3112  *               based the direction field of the configuration
3113  *
3114  *     Invoked by: Scheduler
3115  *
3116  *  @param[in]  RgSchCellCb   *cell
3117  *  @param[in]  RgSchUeCb     *ue
3118  *  @param[in]  RgrDel        *lcDelInfo
3119  *  @return     S16
3120  *
3121  **/
3122 #ifdef ANSI
3123 Void rgSCHUtlRgrLcgDel
3124 (
3125 RgSchCellCb                *cell,
3126 RgSchUeCb                  *ue,
3127 U8                         lcgId
3128 )
3129 #else
3130 Void rgSCHUtlRgrLcgDel(cell, ue, lcgId)
3131 RgSchCellCb                *cell;
3132 RgSchUeCb                  *ue;
3133 U8                         lcgId;
3134 #endif
3135 {
3136    cell->sc.apis->rgSCHFreeLcg(cell, ue, &ue->ul.lcgArr[lcgId]);
3137
3138   /* Stack Crash problem for TRACE5 changes. added the return below . */
3139  RETVOID;
3140
3141 } /* rgSCHUtlRgrLcgDel */
3142
3143
3144 /* End: LTEMAC_2.1_DEV_CFG */
3145
3146 /**
3147  * @brief This function is a wrapper to call scheduler specific API.
3148  *
3149  * @details
3150  *
3151  *     Function: rgSCHUtlDoaInd
3152  *     Purpose:  Updates the DOA for the UE
3153  *
3154  *     Invoked by: TOM
3155  *
3156  *  @param[in]  RgSchCellCb        *cell
3157  *  @param[in]  RgSchUeCb          *ue
3158  *  @param[in]  TfuDoaRpt          *doaRpt
3159  *  @return  Void
3160  *
3161  **/
3162 #ifdef ANSI
3163 Void  rgSCHUtlDoaInd
3164 (
3165 RgSchCellCb        *cell,
3166 RgSchUeCb          *ue,
3167 TfuDoaRpt          *doaRpt
3168 )
3169 #else
3170 Void rgSCHUtlDoaInd(cell, ue, doaRpt)
3171 RgSchCellCb        *cell;
3172 RgSchUeCb          *ue;
3173 TfuDoaRpt          *doaRpt;
3174 #endif
3175 {
3176    ue->mimoInfo.doa.pres = PRSNT_NODEF;
3177    ue->mimoInfo.doa.val = doaRpt->doa;
3178    RETVOID;
3179 }
3180 \f
3181 /**
3182  * @brief This function is a wrapper to call scheduler specific API.
3183  *
3184  * @details
3185  *
3186  *     Function: rgSCHUtlDlCqiInd
3187  *     Purpose:  Updates the DL CQI for the UE
3188  *
3189  *     Invoked by: TOM
3190  *
3191  *  @param[in]  RgSchCellCb        *cell
3192  *  @param[in]  RgSchUeCb          *ue
3193  *  @param[in]  TfuDlCqiRpt        *dlCqiRpt
3194  *  @param[in]  CmLteTimingInfo    timingInfo
3195  *  @return  Void
3196  *
3197  **/
3198 #ifdef ANSI
3199 Void rgSCHUtlDlCqiInd
3200 (
3201 RgSchCellCb        *cell,
3202 RgSchUeCb          *ue,
3203 TfuDlCqiRpt        *dlCqiRpt,
3204 CmLteTimingInfo    timingInfo
3205 )
3206 #else
3207 Void rgSCHUtlDlCqiInd(cell, ue, dlCqiRpt, timingInfo)
3208 RgSchCellCb        *cell;
3209 RgSchUeCb          *ue;
3210 TfuDlCqiRpt        *dlCqiRpt;
3211 CmLteTimingInfo    timingInfo;
3212 #endif
3213 {
3214    RgSchCellCb        *sCellCb = NULLP;
3215    if (dlCqiRpt->isPucchInfo)
3216    {
3217       sCellCb = ue->cellInfo[dlCqiRpt->dlCqiInfo.pucchCqi.cellIdx]->cell;
3218       sCellCb->sc.apis->rgSCHDlCqiInd(sCellCb, ue, dlCqiRpt->isPucchInfo, \
3219             (Void *)&dlCqiRpt->dlCqiInfo.pucchCqi, timingInfo);
3220    }
3221    else
3222    {
3223       U32 idx;
3224       for (idx = 0; idx < dlCqiRpt->dlCqiInfo.pusch.numOfCells; idx++)
3225       {
3226          sCellCb = ue->cellInfo[dlCqiRpt->dlCqiInfo.pusch.puschCqi[idx].cellIdx]->cell;
3227          sCellCb->sc.apis->rgSCHDlCqiInd(sCellCb, ue, dlCqiRpt->isPucchInfo, \
3228                (Void *)&dlCqiRpt->dlCqiInfo.pusch.puschCqi[idx], timingInfo);
3229       }
3230    }
3231    RETVOID;
3232 }
3233
3234 \f
3235 #ifdef TFU_UPGRADE
3236 /**
3237  * @brief This function is a wrapper to call scheduler specific API.
3238  *
3239  * @details
3240  *
3241  *     Function: rgSCHUtlSrsInd
3242  *     Purpose:  Updates the UL SRS for the UE
3243  *
3244  *     Invoked by: TOM
3245  *
3246  *  @param[in]  RgSchCellCb        *cell
3247  *  @param[in]  RgSchUeCb          *ue
3248  *  @param[in]  TfuSrsRpt*     srsRpt
3249  *  @param[in]  CmLteTimingInfo    timingInfo
3250  *  @return  Void
3251  *
3252  **/
3253 #ifdef ANSI
3254 Void rgSCHUtlSrsInd
3255 (
3256 RgSchCellCb        *cell,
3257 RgSchUeCb          *ue,
3258 TfuSrsRpt          *srsRpt,
3259 CmLteTimingInfo    timingInfo
3260 )
3261 #else
3262 Void rgSCHUtlSrsInd(cell, ue, srsRpt, timingInfo)
3263 RgSchCellCb        *cell;
3264 RgSchUeCb          *ue;
3265 TfuSrsRpt        *srsRpt;
3266 CmLteTimingInfo    timingInfo;
3267 #endif
3268 {
3269    cell->sc.apis->rgSCHSrsInd(cell, ue, srsRpt, timingInfo);
3270    RETVOID;
3271 }
3272 #endif
3273
3274 /**
3275  * @brief This function is a wrapper to call scheduler specific API.
3276  *
3277  * @details
3278  *
3279  *     Function: rgSCHUtlDlTARpt
3280  *     Purpose:  Reports PHY TA for a UE.
3281  *
3282  *     Invoked by: TOM
3283  *
3284  *  @param[in]  RgSchCellCb        *cell
3285  *  @param[in]  RgSchUeCb          *ue
3286  *  @return  Void
3287  *
3288  **/
3289 #ifdef ANSI
3290 Void rgSCHUtlDlTARpt
3291 (
3292 RgSchCellCb        *cell,
3293 RgSchUeCb          *ue
3294 )
3295 #else
3296 Void rgSCHUtlDlTARpt(cell, ue)
3297 RgSchCellCb        *cell;
3298 RgSchUeCb          *ue;
3299 #endif
3300 {
3301    cell->sc.apis->rgSCHDlTARpt(cell, ue);
3302    RETVOID;
3303 }
3304
3305 \f
3306 /**
3307  * @brief This function is a wrapper to call scheduler specific API.
3308  *
3309  * @details
3310  *
3311  *     Function: rgSCHUtlDlRlsSubFrm
3312  *     Purpose:  Releases scheduler Information from DL SubFrm.
3313  *
3314  *     Invoked by: DHM
3315  *
3316  *  @param[in]   RgSchCellCb     *cell
3317  *  @param[out]  CmLteTimingInfo subFrm
3318  *  @return  Void
3319  *
3320  **/
3321 #ifdef ANSI
3322 Void rgSCHUtlDlRlsSubFrm
3323 (
3324 RgSchCellCb        *cell,
3325 CmLteTimingInfo    subFrm
3326 )
3327 #else
3328 Void rgSCHUtlDlRlsSubFrm(cell, subFrm)
3329 RgSchCellCb        *cell;
3330 CmLteTimingInfo    subFrm;
3331 #endif
3332 {
3333    cell->sc.apis->rgSCHDlRlsSubFrm(cell, subFrm);
3334    RETVOID;
3335 }
3336
3337 #ifdef TFU_UPGRADE
3338 /**
3339  * @brief This API is invoked to update the AperCQI trigger
3340  *        weight.
3341  *
3342  * @details
3343  *
3344  *     Function : rgSCHUtlUpdACqiTrigWt
3345  *              - If HqFdbk is ACK then add up weight corresponding
3346  *                to ACK to the AcqiTrigWt.
3347  *              - If HqFdbk is NACK then add up weight corresponding
3348  *                to NACK to the AcqiTrigWt.
3349  *              - If AcqiTrigWt crosses threshold then trigger
3350  *                grant req for APERCQI to SCH.
3351  *
3352  *  @param[in]  RgSchUeCb       *ue
3353  *  @param[in]  U8              isAck 
3354  *
3355  *  @return Void
3356  **/
3357 #ifdef ANSI
3358 Void rgSCHUtlUpdACqiTrigWt
3359 (
3360 RgSchUeCb       *ue,
3361 RgSchUeCellInfo *cellInfo,
3362 U8              isAck 
3363 )
3364 #else
3365 Void rgSCHUtlUpdACqiTrigWt(ue,cellInfo, isAck)
3366 RgSchUeCb       *ue;
3367 RgSchUeCellInfo *cellInfo;
3368 U8              isAck; 
3369 #endif
3370 {
3371 #ifdef LTE_ADV
3372    U8 triggerSet  = 0;
3373    U8 sIdx        = 0;
3374 #endif
3375
3376    if (isAck == TFU_HQFDB_ACK)
3377    {
3378       cellInfo->acqiCb.aCqiTrigWt += RG_APER_CQI_ACK_WGT;
3379    }
3380    else
3381    {
3382       cellInfo->acqiCb.aCqiTrigWt += RG_APER_CQI_NACK_WGT;
3383    }
3384
3385    if (cellInfo->acqiCb.aCqiTrigWt > RG_APER_CQI_THRESHOLD_WGT)
3386    {
3387       RgSchCellCb  *cell = ue->cell;
3388       RgSchErrInfo unUsed;
3389
3390       if(ue->dl.reqForCqi)
3391       {
3392          /* Already one ACQI trigger procedure is going on
3393           * which is not yet satisfied. Delaying this request till
3394           * the previous is getting satisfied*/
3395          RETVOID;
3396       }
3397
3398      ue->dl.reqForCqi = TRUE;
3399 #ifdef LTE_ADV
3400       rgSchCmnSetCqiReqField(cellInfo,ue,&ue->dl.reqForCqi);
3401       //Reset aCqiTrigWt for all the serving cells for which we have triggered ACQI 
3402       rgSCHTomUtlGetTrigSet(cell, ue, ue->dl.reqForCqi, &triggerSet);
3403       for (sIdx = 0; sIdx < CM_LTE_MAX_CELLS; sIdx++)
3404       {
3405          /* The Aperiodic requested for SCell index sIdx */
3406          if ((triggerSet >> (7 - sIdx)) & 0x01)
3407          {
3408             /* The Aperiodic request for SCell index sIdx */
3409             ue->cellInfo[sIdx]->acqiCb.aCqiTrigWt = 0;
3410          }
3411       }
3412  
3413 #endif
3414       /* Force SCH to send UL grant by indicating fake SR.
3415        * If this UE already in UL SCH Qs this SR Ind will
3416        * be ignored */
3417       rgSCHUtlSrRcvd(cell, ue, cell->crntTime, &unUsed);
3418    }
3419
3420    RETVOID;
3421 }
3422 #endif
3423
3424 /**
3425  * @brief This API is invoked to indicate scheduler of a CRC indication.
3426  *
3427  * @details
3428  *
3429  *     Function : rgSCHUtlHdlUlTransInd
3430  *      This API is invoked to indicate scheduler of a CRC indication.
3431  *
3432  *  @param[in]  RgSchCellCb     *cell
3433  *  @param[in]  RgSchUeCb       *ue
3434  *  @param[in]  CmLteTimingInfo timingInfo
3435  *
3436  *  @return Void
3437  **/
3438 #ifdef ANSI
3439 Void rgSCHUtlHdlUlTransInd
3440 (
3441 RgSchCellCb     *cell,
3442 RgSchUeCb       *ue,
3443 CmLteTimingInfo timingInfo
3444 )
3445 #else
3446 Void rgSCHUtlHdlUlTransInd(cell, ue, timingInfo)
3447 RgSchCellCb     *cell;
3448 RgSchUeCb       *ue;
3449 CmLteTimingInfo timingInfo;
3450 #endif
3451 {
3452    cell->sc.apis->rgSCHHdlUlTransInd(cell, ue, timingInfo);
3453    RETVOID;
3454 }
3455 #ifdef LTEMAC_SPS
3456 /**
3457  * @brief This API is invoked to indicate scheduler of a CRC failure.
3458  *
3459  * @details
3460  *
3461  *     Function : rgSCHUtlHdlCrcInd
3462  *      This API is invoked to indicate CRC  to scheduler.
3463  *
3464  *  @param[in]  RgSchCellCb     *cell
3465  *  @param[in]  RgSchUeCb       *ue
3466  *  @param[in]  CmLteTimingInfo timingInfo
3467  *
3468  *  @return Void
3469  **/
3470 #ifdef ANSI
3471 Void rgSCHUtlHdlCrcInd
3472 (
3473 RgSchCellCb     *cell,
3474 RgSchUeCb       *ue,
3475 CmLteTimingInfo timingInfo
3476 )
3477 #else
3478 Void rgSCHUtlHdlCrcInd(cell, ue, timingInfo)
3479 RgSchCellCb     *cell;
3480 RgSchUeCb       *ue;
3481 CmLteTimingInfo timingInfo;
3482 #endif
3483 {
3484    cell->sc.apis->rgSCHUlCrcInd(cell, ue, timingInfo);
3485    RETVOID;
3486 } /* end of rgSCHUtlHdlCrcFailInd */
3487
3488 /**
3489  * @brief This API is invoked to indicate scheduler of a CRC failure.
3490  *
3491  * @details
3492  *
3493  *     Function : rgSCHUtlHdlCrcFailInd
3494  *      This API is invoked to indicate CRC failure to scheduler.
3495  *
3496  *  @param[in]  RgSchCellCb     *cell
3497  *  @param[in]  RgSchUeCb       *ue
3498  *  @param[in]  CmLteTimingInfo timingInfo
3499  *
3500  *  @return Void
3501  **/
3502 #ifdef ANSI
3503 Void rgSCHUtlHdlCrcFailInd
3504 (
3505 RgSchCellCb     *cell,
3506 RgSchUeCb       *ue,
3507 CmLteTimingInfo timingInfo
3508 )
3509 #else
3510 Void rgSCHUtlHdlCrcFailInd(cell, ue, timingInfo)
3511 RgSchCellCb     *cell;
3512 RgSchUeCb       *ue;
3513 CmLteTimingInfo timingInfo;
3514 #endif
3515 {
3516    cell->sc.apis->rgSCHUlCrcFailInd(cell, ue, timingInfo);
3517    RETVOID;
3518 } /* end of rgSCHUtlHdlCrcFailInd */
3519 #endif /* LTEMAC_SPS */
3520
3521 \f
3522 /**
3523  * @brief This function is a wrapper to call scheduler specific API.
3524  *
3525  * @details
3526  *
3527  *     Function: rgSCHUtlDlProcAddToRetx
3528  *     Purpose:  This function adds a HARQ process to retransmission
3529  *               queue. This may be performed when a HARQ ack is
3530  *               unsuccessful.
3531  *
3532  *     Invoked by: HARQ feedback processing
3533  *
3534  *  @param[in]  RgSchCellCb*     cell
3535  *  @param[in]  RgSchDlHqProc*   hqP
3536  *  @return  Void
3537  *
3538  **/
3539 #ifdef ANSI
3540 Void rgSCHUtlDlProcAddToRetx
3541 (
3542 RgSchCellCb                *cell,
3543 RgSchDlHqProcCb            *hqP
3544 )
3545 #else
3546 Void rgSCHUtlDlProcAddToRetx(cell, hqP)
3547 RgSchCellCb                *cell;
3548 RgSchDlHqProcCb            *hqP;
3549 #endif
3550 {
3551    cell->sc.apis->rgSCHDlProcAddToRetx(cell, hqP);
3552    RETVOID;
3553 }
3554
3555 \f
3556 /**
3557  * @brief This function adds a HARQ process TB to transmission
3558  *
3559  * @details
3560  *
3561  *     Function: rgSCHUtlDlHqPTbAddToTx
3562  *     Purpose:  This function a HarqProcess TB to the slot
3563  *               list.
3564  *
3565  *     Invoked by: Scheduler
3566  *
3567  *  @param[in]  RgSubFrm*     subFrm
3568  *  @param[in]  RgDlHqProc*   hqP
3569  *  @param[in]  U8            tbIdx
3570  *  @return  Void
3571  *
3572  **/
3573 #ifdef ANSI
3574 Void rgSCHUtlDlHqPTbAddToTx
3575 (
3576 RgSchDlSf                  *subFrm,
3577 RgSchDlHqProcCb            *hqP,
3578 U8                         tbIdx
3579 )
3580 #else
3581 Void rgSCHUtlDlHqPTbAddToTx(subFrm, hqP, tbIdx)
3582 RgSchDlSf                  *subFrm;
3583 RgSchDlHqProcCb            *hqP;
3584 U8                         tbIdx;
3585 #endif
3586 {
3587    RgSchUeCb *ue = NULLP;
3588    RgSchCellCb *cell = hqP->hqE->cell;
3589    /* CA Dev Start */
3590    /* Addition of UE to dlSf->ueLst shall be done only to UE's PCell */
3591    /* ue->cell will always hold PCell information */
3592    if (NULLP == hqP->hqPSfLnk.node)
3593    {
3594       if (hqP->hqE->ue)
3595       {
3596          ue = hqP->hqE->ue;
3597          if(NULLP == ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].dlSfUeLnk.node)
3598          {
3599             ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].dlSfUeLnk.node = (PTR)ue;
3600             cmLListAdd2Tail(&cell->subFrms[subFrm->dlIdx]->ueLst, 
3601                   &ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].dlSfUeLnk);
3602
3603             ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].isPuschHarqRecpPres = FALSE;
3604
3605          }
3606
3607          /* Add Hq proc in particular dlIdx List for this UE 
3608             This list will be used while processing feedback*/
3609          hqP->hqPSfLnk.node = (PTR)hqP;
3610          cmLListAdd2Tail(&ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].hqPLst,&hqP->hqPSfLnk); 
3611 #ifdef CA_DBG
3612          {
3613             extern U32 gSCellSchedCount,gPrimarySchedCount;
3614             if(RG_SCH_IS_CELL_SEC(hqP->hqE->ue,hqP->hqE->cell))
3615             {
3616                gSCellSchedCount++;
3617             }else
3618                gPrimarySchedCount++;
3619          }
3620 #endif
3621       }
3622       else if (hqP->hqE->msg4Proc == hqP)
3623       {
3624          /* Msg4 will be scheduled on PCELL only hence add directly to subFrm msg4HqpList */
3625          hqP->hqPSfLnk.node = (PTR)hqP;
3626          cmLListAdd2Tail(&subFrm->msg4HqPLst, &hqP->hqPSfLnk);
3627       }
3628    }
3629    else
3630    {
3631       ue = hqP->hqE->ue; 
3632    }
3633    if((ue) && (HQ_TB_WAITING == hqP->tbInfo[tbIdx].state))
3634          
3635    {   
3636       ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].totalTbCnt++;
3637    }
3638    /*totalTbCnt will hold the total number of TBs across all harq Proc from all 
3639     * cells*/
3640
3641    hqP->subFrm = subFrm; 
3642
3643    /* CA Dev End */
3644    RETVOID;
3645 }
3646
3647
3648 \f
3649 /**
3650  * @brief This function removes a HARQ process TB from transmission
3651  *
3652  * @details
3653  *
3654  *     Function: rgSCHUtlDlHqPTbRmvFrmTx
3655  *     Purpose:  This function removes a HarqProcess TB to the slot
3656  *               list.
3657  *
3658  *     Invoked by: Scheduler
3659  *
3660  *  @param[in]  RgSubFrm*     subFrm
3661  *  @param[in]  RgDlHqProc*   hqP
3662  *  @param[in]  U8            tbIdx
3663  *  @param[in]  Bool          isRepeting
3664  *  @return  Void
3665  *
3666  **/
3667 #ifdef ANSI
3668 Void rgSCHUtlDlHqPTbRmvFrmTx
3669 (
3670 RgSchDlSf                  *subFrm,
3671 RgSchDlHqProcCb            *hqP,
3672 U8                         tbIdx,
3673 Bool                       isRepeting
3674 )
3675 #else
3676 Void rgSCHUtlDlHqPTbRmvFrmTx(subFrm, hqP, tbIdx, isRepeting)
3677 RgSchDlSf                  *subFrm;
3678 RgSchDlHqProcCb            *hqP;
3679 U8                         tbIdx;
3680 Bool                       isRepeting;
3681 #endif
3682 {
3683    RgSchCellCb *cell = NULLP;
3684    /* Check with TDD */
3685    if ((isRepeting) &&
3686          (hqP->hqE->ue->ackNakRepCb.cfgRepCnt !=
3687           hqP->tbInfo[tbIdx].fbkRepCntr))
3688    {
3689       cmLListDelFrm(&subFrm->ackNakRepQ,
3690          &hqP->tbInfo[tbIdx].anRepLnk[hqP->tbInfo[tbIdx].fbkRepCntr]);
3691    }
3692    else
3693    {
3694       if (NULLP != hqP->hqPSfLnk.node)
3695       {
3696          /* CA dev Start */
3697          if (hqP->hqE->msg4Proc == hqP)
3698          {
3699             /* Msg4 will be scheduled on PCELL only hence delete directly from subFrm msg4HqpList */
3700             cmLListDelFrm(&subFrm->msg4HqPLst, &hqP->hqPSfLnk); 
3701          }
3702          else
3703          {
3704             cell = hqP->hqE->cell;
3705             /* Addition of UE to dlSf->ueLst shall be done only to UE's PCell */
3706             /* ue->cell will always hold PCell information */
3707             cmLListDelFrm(&hqP->hqE->ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].hqPLst,&hqP->hqPSfLnk); 
3708             if (0 == hqP->hqE->ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].hqPLst.count)
3709             {
3710
3711                cmLListDelFrm(&cell->subFrms[subFrm->dlIdx]->ueLst, 
3712                      &hqP->hqE->ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].dlSfUeLnk);
3713                hqP->hqE->ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].dlSfUeLnk.node = (PTR)NULLP;
3714                hqP->hqE->ue->dl.dlSfHqInfo[cell->cellId][subFrm->dlIdx].totalTbCnt = 0;
3715             }
3716          }
3717          hqP->hqPSfLnk.node = NULLP;
3718       }
3719       hqP->subFrm = NULLP;
3720    }
3721    RETVOID;
3722 }
3723
3724 #ifdef LTE_ADV
3725 /**
3726  * @brief Handler for accessing the existing SCellCb identified by the key
3727  * SCellId under the CellCb.
3728  *
3729  * @details
3730  *
3731  *     Function : rgSchUtlGetCellCb
3732  *     
3733  *           
3734  *  @param[in]  *cellCb
3735  *  @param[in]  ueId
3736  *  @return  RgSchUeCb*
3737  **/
3738 #ifdef ANSI
3739 RgSchCellCb* rgSchUtlGetCellCb
3740 (
3741  Inst         inst,
3742  U16          cellId
3743 )
3744 #else
3745 RgSchCellCb* rgSchUtlGetCellCb(inst, cellId)
3746  Inst          inst;
3747  U16           cellId;
3748 #endif
3749 {
3750    RgSchCellCb    *cellCb = NULLP; 
3751    U8              strtCellId;
3752
3753    strtCellId = rgSchCb[inst].genCfg.startCellId;
3754    cellCb     = rgSchCb[inst].cells[cellId - strtCellId];
3755
3756    return (cellCb);
3757
3758 }  /* rgSchUtlGetCellCb */
3759
3760 /**
3761  * @brief Handler for deriving the servCellidx
3762  *
3763  * @details
3764  *
3765  *     Function : rgSchUtlGetServCellIdx
3766  *     
3767  *           
3768  *  @param[in]  *cellId
3769  *  @param[in]  RgSchUeCb *ue
3770  *  @return   U8 servCellIdx
3771  **/
3772 #ifdef ANSI
3773 U8 rgSchUtlGetServCellIdx
3774 (
3775  Inst         inst,
3776  U16          cellId,
3777  RgSchUeCb    *ue
3778 )
3779 #else
3780 U8 rgSchUtlGetServCellIdx(inst,cellId,ue)
3781  Inst         inst;
3782  U16          cellId;
3783  RgSchUeCb    *ue;
3784 #endif
3785 {
3786    U8 servCellIdx;
3787    U16 strtCellId;
3788
3789    strtCellId = rgSchCb[inst].genCfg.startCellId;
3790
3791    servCellIdx = ue->cellIdToCellIdxMap[cellId - strtCellId];
3792
3793    return (servCellIdx);
3794
3795 }  /* rgSchUtlGetCellCb */
3796
3797 /**
3798  * @brief Handler for validating the Cell Id received secondary Cell Addition
3799  *
3800  * @details
3801  *
3802  *     Function : rgSchUtlGetCellId
3803  *     
3804  *           
3805  *  @param[in]  *cellCb
3806  *  @param[in]  ueId
3807  *  @return  RgSchUeCb*
3808  **/
3809 #ifdef ANSI
3810 S16 rgSchUtlVldtCellId
3811 (
3812  Inst         inst,
3813  U16          cellId
3814 )
3815 #else
3816 S16 rgSchUtlVldtCellId(inst, cellId)
3817  Inst          inst;
3818  U16           cellId;
3819 #endif
3820 {
3821    U8              strtCellId;
3822
3823    strtCellId = rgSchCb[inst].genCfg.startCellId;
3824    if((cellId >= strtCellId) && ((cellId - strtCellId) < CM_LTE_MAX_CELLS))
3825    {
3826       return ROK;
3827    }
3828    return RFAILED;
3829 }  /* rgSchUtlVldtCellId */
3830
3831 #endif /* LTE_ADV*/
3832 /**
3833  * @brief UE reconfiguration for scheduler
3834  *
3835  * @details
3836  *
3837  *     Function : rgSCHUtlRgrUeRecfg
3838  *
3839  *     This functions updates UE specific scheduler
3840  *     information upon UE reconfiguration
3841  *
3842  *  @param[in]  RgSchCellCb  *cell
3843  *  @param[in]  RgSchUeCb    *ue
3844  *  @param[int] RgrUeRecfg   *ueRecfg
3845  *  @param[out] RgSchErrInfo *err
3846  *  @return  S16
3847  *      -# ROK
3848  *      -# RFAILED
3849  **/
3850 #ifdef ANSI
3851 S16 rgSCHUtlRgrUeRecfg
3852 (
3853 RgSchCellCb  *cell,
3854 RgSchUeCb    *ue,
3855 RgrUeRecfg   *ueRecfg,
3856 RgSchErrInfo *err
3857 )
3858 #else
3859 S16 rgSCHUtlRgrUeRecfg(cell, ue, ueRecfg, err)
3860 RgSchCellCb  *cell;
3861 RgSchUeCb    *ue;
3862 RgrUeRecfg   *ueRecfg;
3863 RgSchErrInfo *err;
3864 #endif
3865 {
3866 /* Changes for UE Category Reconfiguration feature addition */
3867    RgSchCmnUe    *ueSch = RG_SCH_CMN_GET_UE(ue, cell);
3868
3869    /* Changes for UE Category Reconfiguration feature addition */
3870    if (ueRecfg->ueRecfgTypes & RGR_UE_UECAT_RECFG)
3871    {
3872       ueSch->cmn.ueCat = ueRecfg->ueCatEnum-1;
3873 #ifdef TFU_UPGRADE
3874       ue->ueCatEnum = ueRecfg->ueCatEnum;
3875 #endif
3876    } 
3877
3878    /* DL MU-MIMO not supported */
3879    if (ueRecfg->ueRecfgTypes & RGR_UE_TXMODE_RECFG)
3880    {
3881
3882       if (ueRecfg->txMode.pres == PRSNT_NODEF)
3883       {
3884          if (ueRecfg->txMode.txModeEnum == RGR_UE_TM_5)
3885          {
3886             err->errCause = RGSCHERR_SCH_CFG;
3887             return RFAILED;
3888          }
3889 #ifdef LTE_ADV
3890         if(ue->mimoInfo.txMode != ueRecfg->txMode.txModeEnum)
3891          {
3892             /* Decremnt the previos A value for this cell */
3893             ue->f1bCsAVal -= rgSCHUtlGetMaxTbSupp(ue->mimoInfo.txMode);
3894             /* Update A value with the new TM Mode */
3895             ue->f1bCsAVal += rgSCHUtlGetMaxTbSupp(ueRecfg->txMode.txModeEnum);
3896
3897
3898             RLOG1(L_INFO,"UeReCfg A valie is %d\n",ue->f1bCsAVal);
3899          }
3900 #endif
3901          ue->mimoInfo.txMode = ueRecfg->txMode.txModeEnum;
3902       }
3903    }
3904 #ifdef TFU_UPGRADE
3905    /* [ccpu00123958]-ADD- Check for PUSCH related Reconfig from the bit mask  */
3906     if(ueRecfg->ueRecfgTypes & RGR_UE_PUSCH_RECFG)
3907     {
3908        /* Fix: ccpu00124012 */
3909        /* TODO:: Need to check if this is 
3910           mandatory to be re-configured on UE category re-configuration */
3911        /* ue->ul.betaHqOffst = ueRecfg->puschDedCfg.bACKIdx;
3912           ue->ul.betaCqiOffst = ueRecfg->puschDedCfg.bCQIIdx;
3913           ue->ul.betaRiOffst = ueRecfg->puschDedCfg.bRIIdx;*/
3914     }
3915 #endif
3916    if (ueRecfg->ueRecfgTypes & RGR_UE_ULTXANTSEL_RECFG)
3917    {
3918       ue->ul.ulTxAntSel = ueRecfg->ulTxAntSel;
3919    }
3920    if (ueRecfg->ueRecfgTypes & RGR_UE_CDBKSBST_RECFG)
3921    {
3922       ue->mimoInfo.cdbkSbstRstrctn = ueRecfg->ueCodeBookRstRecfg;
3923    }
3924
3925    /* Commenting here to assign garbage value when it is not set in APP. */
3926    //ue->accessStratumRls = ueRecfg->accessStratumRls;
3927    return (cell->sc.apis->rgSCHRgrUeRecfg(cell, ue, ueRecfg, err));
3928 }  /* rgSCHUtlRgrUeRecfg */
3929
3930 /**
3931  * @brief This function deletes a service from scheduler
3932  *
3933  * @details
3934  *
3935  *     Function: rgSCHUtlFreeDlLc
3936  *     Purpose:  This function is made available through a FP for
3937  *               making scheduler aware of a service being deleted from UE
3938  *
3939  *     Invoked by: BO and Scheduler
3940  *
3941  *  @param[in]  RgSchCellCb*  cell
3942  *  @param[in]  RgSchUeCb*    ue
3943  *  @param[in]  RgSchDlLcCb*  svc
3944  *  @return  Void
3945  **/
3946 #ifdef ANSI
3947 Void rgSCHUtlFreeDlLc
3948 (
3949 RgSchCellCb                *cell,
3950 RgSchUeCb                  *ue,
3951 RgSchDlLcCb                *svc
3952 )
3953 #else
3954 Void rgSCHUtlFreeDlLc(cell, ue, svc)
3955 RgSchCellCb                *cell;
3956 RgSchUeCb                  *ue;
3957 RgSchDlLcCb                *svc;
3958 #endif
3959 {
3960    cell->sc.apis->rgSCHFreeDlLc(cell, ue, svc);
3961
3962   /* Stack Crash problem for TRACE5 changes. added the return below . */
3963  RETVOID;
3964
3965 }
3966
3967 /**
3968  * @brief UE deletion for scheduler
3969  *
3970  * @details
3971  *
3972  *     Function : rgSCHUtlFreeUe
3973  *
3974  *     This functions deletes all scheduler information
3975  *     pertaining to a UE
3976  *
3977  *  @param[in]  RgSchCellCb  *cell
3978  *  @param[in]  RgSchUeCb    *ue
3979  *  @return  Void
3980  **/
3981 #ifdef ANSI
3982 Void rgSCHUtlFreeUe
3983 (
3984 RgSchCellCb  *cell,
3985 RgSchUeCb    *ue
3986 )
3987 #else
3988 Void rgSCHUtlFreeUe(cell, ue)
3989 RgSchCellCb  *cell;
3990 RgSchUeCb    *ue;
3991 #endif
3992 {
3993 #ifdef LTE_TDD
3994    rgSCHUtlDelUeANFdbkInfo(ue,RGSCH_PCELL_INDEX);
3995 #endif
3996    cell->sc.apis->rgSCHFreeUe(cell, ue);
3997
3998   /* Stack Crash problem for TRACE5 changes. added the return below . */
3999  RETVOID;
4000
4001 }  /* rgSCHUtlFreeUe */
4002
4003 /**
4004  * @brief This function updates the scheduler with service for a UE
4005  *
4006  * @details
4007  *
4008  *     Function: rgSCHUtlDlDedBoUpd
4009  *     Purpose:  This function should be called whenever there is a
4010  *               change BO for a service.
4011  *
4012  *     Invoked by: BO and Scheduler
4013  *
4014  *  @param[in]  RgSchCellCb*  cell
4015  *  @param[in]  RgSchUeCb*    ue
4016  *  @param[in]  RgSchDlLcCb*  lc
4017  *  @return  Void
4018  **/
4019 #ifdef ANSI
4020 Void rgSCHUtlDlDedBoUpd
4021 (
4022 RgSchCellCb                *cell,
4023 RgSchUeCb                  *ue,
4024 RgSchDlLcCb                *lc
4025 )
4026 #else
4027 Void rgSCHUtlDlDedBoUpd(cell, ue, lc)
4028 RgSchCellCb                *cell;
4029 RgSchUeCb                  *ue;
4030 RgSchDlLcCb                *lc;
4031 #endif
4032 {
4033    cell->sc.apis->rgSCHDlDedBoUpd(cell, ue, lc);
4034    RETVOID;
4035 }
4036 /**
4037  * @brief Record MSG3 allocation into the UE
4038  *
4039  * @details
4040  *
4041  *     Function : rgSCHUtlRecMsg3Alloc
4042  *
4043  *     This function is invoked to update record msg3 allocation information
4044  *    in the UE when UE is detected for RaCb
4045  *
4046  *  @param[in]  RgSchCellCb     *cell
4047  *  @param[in]  RgSchUeCb       *ue
4048  *  @param[in] RgSchRaCb       *raCb
4049  *
4050  **/
4051 #ifdef ANSI
4052 Void rgSCHUtlRecMsg3Alloc
4053 (
4054 RgSchCellCb      *cell,
4055 RgSchUeCb        *ue,
4056 RgSchRaCb        *raCb
4057 )
4058 #else
4059 Void rgSCHUtlRecMsg3Alloc(cell, ue, raCb)
4060 RgSchCellCb      *cell;
4061 RgSchUeCb        *ue;
4062 RgSchRaCb        *raCb;
4063 #endif
4064 {
4065    cell->sc.apis->rgSCHUlRecMsg3Alloc(cell, ue, raCb);
4066    RETVOID;
4067
4068 }  /* rgSCHRecMsg3Alloc */
4069
4070 #ifdef RG_UNUSED
4071 /**
4072  * @brief Update harq process for allocation
4073  *
4074  * @details
4075  *
4076  *     Function : rgSCHUtlUpdUlHqProc
4077  *
4078  *     This function is invoked when harq process
4079  *     control block is now in a new memory location
4080  *     thus requiring a pointer/reference update.
4081  *
4082  *  @param[in] RgSchCellCb      *cell
4083  *  @param[in] RgSchUlHqProcCb  *curProc
4084  *  @param[in] RgSchUlHqProcCb  *oldProc
4085  *  @return  S16
4086  *      -# ROK
4087  *      -# RFAILED
4088  **/
4089 #ifdef ANSI
4090 S16 rgSCHUtlUpdUlHqProc
4091 (
4092 RgSchCellCb      *cell,
4093 RgSchUlHqProcCb  *curProc,
4094 RgSchUlHqProcCb  *oldProc
4095 )
4096 #else
4097 S16 rgSCHUtlUpdUlHqProc(cell, curProc, oldProc)
4098 RgSchCellCb      *cell;
4099 RgSchUlHqProcCb  *curProc;
4100 RgSchUlHqProcCb  *oldProc;
4101 #endif
4102 {
4103    return (cell->sc.apis->rgSCHUpdUlHqProc(cell, curProc, oldProc));
4104 }  /* rgSCHUtlUpdUlHqProc */
4105 #endif
4106 /**
4107  * @brief UL grant for contention resolution
4108  *
4109  * @details
4110  *
4111  *     Function : rgSCHUtlContResUlGrant
4112  *
4113  *     Add UE to another queue specifically for CRNTI based contention
4114  *     resolution
4115  *
4116  *  @param[in]  RgSchCellCb *cell
4117  *  @param[in]  RgSchUeCb  *ue
4118  *  @param[out] RgSchErrInfo *err
4119  *  @return  S16
4120  *      -# ROK
4121  *      -# RFAILED
4122  **/
4123 #ifdef ANSI
4124 S16 rgSCHUtlContResUlGrant
4125 (
4126 RgSchCellCb  *cell,
4127 RgSchUeCb    *ue,
4128 RgSchErrInfo *err
4129 )
4130 #else
4131 S16 rgSCHUtlContResUlGrant(cell, ue, err)
4132 RgSchCellCb  *cell;
4133 RgSchUeCb    *ue;
4134 RgSchErrInfo *err;
4135 #endif
4136 {
4137
4138    ue->isMsg4PdcchWithCrnti = TRUE; 
4139
4140    return (cell->sc.apis->rgSCHContResUlGrant(cell, ue, err));
4141 }  /* rgSCHUtlContResUlGrant */
4142
4143 /**
4144  * @brief SR reception handling
4145  *
4146  * @details
4147  *
4148  *     Function : rgSCHUtlSrRcvd
4149  *
4150  *     - Handles SR reception for UE
4151  *
4152  *  @param[in]  RgSchCellCb  *cell
4153  *  @param[in]  RgSchUeCb    *ue
4154  *  @param[out] RgSchErrInfo *err
4155  *  @return  S16
4156  *      -# ROK
4157  *      -# RFAILED
4158  **/
4159 #ifdef ANSI
4160 S16 rgSCHUtlSrRcvd
4161 (
4162 RgSchCellCb  *cell,
4163 RgSchUeCb    *ue,
4164 CmLteTimingInfo frm,
4165 RgSchErrInfo *err
4166 )
4167 #else
4168 S16 rgSCHUtlSrRcvd(cell, ue, frm, err)
4169 RgSchCellCb  *cell;
4170 RgSchUeCb    *ue;
4171 CmLteTimingInfo frm;
4172 RgSchErrInfo *err;
4173 #endif
4174 {
4175    return (cell->sc.apis->rgSCHSrRcvd(cell, ue, frm, err));
4176 }  /* rgSCHUtlSrRcvd */
4177
4178 /**
4179  * @brief Short BSR update
4180  *
4181  * @details
4182  *
4183  *     Function : rgSCHUtlUpdBsrShort
4184  *
4185  *     This functions does requisite updates to handle short BSR reporting
4186  *
4187  *  @param[in]  RgSchCellCb  *cell
4188  *  @param[in]  RgSchUeCb    *ue
4189  *  @param[in]  U8           lcgId
4190  *  @param[in]  U8           bsr
4191  *  @param[out] RgSchErrInfo *err
4192  *  @return  Void
4193  *      -# ROK
4194  *      -# RFAILED
4195  **/
4196 #ifdef ANSI
4197 Void rgSCHUtlUpdBsrShort
4198 (
4199 RgSchCellCb  *cell,
4200 RgSchUeCb    *ue,
4201 U8           lcgId,
4202 U8           bsr,
4203 RgSchErrInfo *err
4204 )
4205 #else
4206 Void rgSCHUtlUpdBsrShort(cell, ue, lcgId, bsr, err)
4207 RgSchCellCb  *cell;
4208 RgSchUeCb    *ue;
4209 U8           lcgId;
4210 U8           bsr;
4211 RgSchErrInfo *err;
4212 #endif
4213 {
4214    cell->sc.apis->rgSCHUpdBsrShort(cell, ue, &ue->ul.lcgArr[lcgId], bsr, err);
4215    RETVOID;
4216 }  /* rgSCHUtlUpdBsrShort */
4217
4218
4219 /**
4220  * @brief Truncated BSR update
4221  *
4222  * @details
4223  *
4224  *     Function : rgSCHUtlUpdBsrTrunc
4225  *
4226  *     This functions does required updates to handle truncated BSR report
4227  *
4228  *
4229  *  @param[in]  RgSchCellCb  *cell
4230  *  @param[in]  RgSchUeCb    *ue
4231  *  @param[in]  U8           lcgId
4232  *  @param[in]  U8           bsr
4233  *  @param[out] RgSchErrInfo *err
4234  *  @return  Void
4235  *      -# ROK
4236  *      -# RFAILED
4237  **/
4238 #ifdef ANSI
4239 Void rgSCHUtlUpdBsrTrunc
4240 (
4241 RgSchCellCb  *cell,
4242 RgSchUeCb    *ue,
4243 U8           lcgId,
4244 U8           bsr,
4245 RgSchErrInfo *err
4246 )
4247 #else
4248 Void rgSCHUtlUpdBsrTrunc(cell, ue, lcgId, bsr, err)
4249 RgSchCellCb   *cell;
4250 RgSchUeCb     *ue;
4251 U8            lcgId;
4252 U8            bsr;
4253 RgSchErrInfo *err;
4254 #endif
4255 {
4256    cell->sc.apis->rgSCHUpdBsrTrunc(cell, ue, &ue->ul.lcgArr[lcgId], bsr, err);
4257    RETVOID; 
4258 }  /* rgSCHUtlUpdBsrTrunc */
4259
4260
4261 /**
4262  * @brief Long BSR update
4263  *
4264  * @details
4265  *
4266  *     Function : rgSCHUtlUpdBsrLong
4267  *
4268  *     - Update BSRs for all configured LCGs
4269  *     - Update priority of LCGs if needed
4270  *     - Update UE's position within/across uplink scheduling queues
4271  *
4272  *
4273  *  @param[in]  RgSchCellCb   *cell
4274  *  @param[in]  RgSchUeCb     *ue
4275  *  @param[in]  U8            bsr0
4276  *  @param[in]  U8            bsr1
4277  *  @param[in]  U8            bsr2
4278  *  @param[in]  U8            bsr3
4279  *  @param[out] RgSchErrInfo  *err
4280  *  @return  Void
4281  *      -# ROK
4282  *      -# RFAILED
4283  **/
4284 #ifdef ANSI
4285 Void rgSCHUtlUpdBsrLong
4286 (
4287 RgSchCellCb  *cell,
4288 RgSchUeCb    *ue,
4289 U8           bsr0,
4290 U8           bsr1,
4291 U8           bsr2,
4292 U8           bsr3,
4293 RgSchErrInfo *err
4294 )
4295 #else
4296 Void rgSCHUtlUpdBsrLong(cell, ue, bsr0, bsr1, bsr2, bsr3, err)
4297 RgSchCellCb  *cell;
4298 RgSchUeCb    *ue;
4299 U8           bsr0;
4300 U8           bsr1;
4301 U8           bsr2;
4302 U8           bsr3;
4303 RgSchErrInfo *err;
4304 #endif
4305 {
4306    U8 bsArr[4];
4307
4308    bsArr[0] = bsr0;
4309    bsArr[1] = bsr1;
4310    bsArr[2] = bsr2;
4311    bsArr[3] = bsr3;
4312    cell->sc.apis->rgSCHUpdBsrLong(cell, ue, bsArr, err);
4313    RETVOID;
4314 }  /* rgSCHUtlUpdBsrLong */
4315
4316 /**
4317  * @brief EXT PHR update
4318  *
4319  * @details
4320  *
4321  *     Function : rgSCHUtlUpdExtPhr
4322  *
4323  *     Updates extended power headroom info for a UE
4324  *
4325  *  @param[in]  RgSchCellCb  *cell
4326  *  @param[in]  RgSchUeCb    *ue
4327  *  @param[in]  U8           phr
4328  *  @param[out] RgSchErrInfo *err
4329  *  @return  S16
4330  *      -# ROK
4331  *      -# RFAILED
4332  **/
4333 #ifdef ANSI
4334 S16 rgSCHUtlUpdExtPhr
4335 (
4336 RgSchCellCb  *cell,
4337 RgSchUeCb    *ue,
4338 RgInfExtPhrCEInfo * extPhr,
4339 RgSchErrInfo *err
4340 )
4341 #else
4342 S16 rgSCHUtlUpdExtPhr(cell, ue, extPhr, err)
4343 RgSchCellCb  *cell;
4344 RgSchUeCb    *ue;
4345 RgInfExtPhrCEInfo * extPhr;
4346 RgSchErrInfo *err;
4347 #endif
4348 {
4349    return (cell->sc.apis->rgSCHUpdExtPhr(cell, ue, extPhr, err));
4350 }  /* rgSCHUtlUpdExtPhr */
4351
4352
4353
4354 /**
4355  * @brief PHR update
4356  *
4357  * @details
4358  *
4359  *     Function : rgSCHUtlUpdPhr
4360  *
4361  *     Updates power headroom info for a UE
4362  *
4363  *  @param[in]  RgSchCellCb  *cell
4364  *  @param[in]  RgSchUeCb    *ue
4365  *  @param[in]  U8           phr
4366  *  @param[out] RgSchErrInfo *err
4367  *  @return  S16
4368  *      -# ROK
4369  *      -# RFAILED
4370  **/
4371 #ifdef ANSI
4372 S16 rgSCHUtlUpdPhr
4373 (
4374 RgSchCellCb  *cell,
4375 RgSchUeCb    *ue,
4376 U8           phr,
4377 RgSchErrInfo *err
4378 )
4379 #else
4380 S16 rgSCHUtlUpdPhr(cell, ue, phr, err)
4381 RgSchCellCb  *cell;
4382 RgSchUeCb    *ue;
4383 U8           phr;
4384 RgSchErrInfo *err;
4385 #endif
4386 {
4387    return (cell->sc.apis->rgSCHUpdPhr(cell, ue, phr, err));
4388 }  /* rgSCHUtlUpdPhr */
4389
4390
4391 /**
4392  * @brief Indication of UL CQI
4393  *
4394  * @details
4395  *
4396  *     Function : rgSCHUtlUlCqiInd
4397  *
4398  *     - Updates uplink CQI information for the UE. Computes and
4399  *       stores the lowest CQI of CQIs reported in all subbands
4400  *
4401  *  @param[in]  RgSchCellCb         *cell
4402  *  @param[in]  RgSchUeCb           *ue
4403  *  @param[in]  TfuUlCqiRpt         *ulCqiInfo
4404  *  @return  Void
4405  **/
4406 #ifdef ANSI
4407 Void rgSCHUtlUlCqiInd
4408 (
4409 RgSchCellCb          *cell,
4410 RgSchUeCb            *ue,
4411 TfuUlCqiRpt          *ulCqiInfo
4412 )
4413 #else
4414 Void rgSCHUtlUlCqiInd(cell, ue, ulCqiInfo)
4415 RgSchCellCb          *cell;
4416 RgSchUeCb            *ue;
4417 TfuUlCqiRpt          *ulCqiInfo;
4418 #endif
4419 {
4420    cell->sc.apis->rgSCHUlCqiInd(cell, ue, ulCqiInfo);
4421    RETVOID;
4422 }  /* rgSCHUtlUlCqiInd */
4423
4424 /**
4425  * @brief Indication of PUCCH power adjustment
4426  *
4427  * @details
4428  *
4429  *     Function : rgSCHUtlPucchDeltaPwrInd
4430  *
4431  *     - Updates uplink CQI information for the UE. Computes and
4432  *       stores the lowest CQI of CQIs reported in all subbands
4433  *
4434  *  @param[in]  RgSchCellCb         *cell
4435  *  @param[in]  RgSchUeCb           *ue
4436  *  @param[in]  U8                  delta
4437  *  @return  Void
4438  **/
4439 #ifdef ANSI
4440 Void rgSCHUtlPucchDeltaPwrInd
4441 (
4442 RgSchCellCb          *cell,
4443 RgSchUeCb            *ue,
4444 S8                   delta
4445 )
4446 #else
4447 Void rgSCHUtlPucchDeltaPwrInd(cell, ue, delta)
4448 RgSchCellCb          *cell;
4449 RgSchUeCb            *ue;
4450 S8                   delta;
4451 #endif
4452 {
4453    cell->sc.apis->rgSCHPucchDeltaPwrInd(cell, ue, delta);
4454    RETVOID;
4455 }  /* rgSCHUtlPucchDeltaPwrInd */
4456
4457 /* Start: LTEMAC_2.1_DEV_CFG */
4458 /**
4459  * @brief Ue Reset Request
4460  *
4461  * @details
4462  *
4463  *     Function : rgSCHUtlUeReset
4464  *
4465  *
4466  *  @param[in]  RgSchCellCb         *cell
4467  *  @param[in]  RgSchUeCb           *ue
4468  *  @return  S16
4469  **/
4470 #ifdef ANSI
4471 Void rgSCHUtlUeReset
4472 (
4473 RgSchCellCb          *cell,
4474 RgSchUeCb            *ue
4475 )
4476 #else
4477 Void rgSCHUtlUeReset(cell, ue)
4478 RgSchCellCb          *cell;
4479 RgSchUeCb            *ue;
4480 #endif
4481 {
4482    ue->remBoCnt = 0;
4483    cell->sc.apis->rgSCHUeReset(cell, ue);
4484    RETVOID;
4485 }  /* rgSCHUtlUeReset */
4486 /* End: LTEMAC_2.1_DEV_CFG */
4487
4488 /**
4489  * @brief Returns HARQ proc for which data expected now
4490  *
4491  * @details
4492  *
4493  *     Function: rgSCHUtlUlHqProcForUe
4494  *     Purpose:  This function returns the harq process for
4495  *               which data is expected in the current slot.
4496  *               It does not validate if the HARQ process
4497  *               has an allocation.
4498  *
4499  *     Invoked by: TOM
4500  *
4501  *  @param[in]  RgSchCellCb         *cell
4502  *  @param[in]  CmLteTimingInfo     frm
4503  *  @param[in]  RgSchUeCb           *ue
4504  *  @param[out] RgSchUlHqProcCb     **procRef
4505  *  @return  Void
4506  **/
4507 #ifdef ANSI
4508 Void rgSCHUtlUlHqProcForUe
4509 (
4510 RgSchCellCb         *cell,
4511 CmLteTimingInfo     frm,
4512 RgSchUeCb           *ue,
4513 RgSchUlHqProcCb     **procRef
4514 )
4515 #else
4516 Void rgSCHUtlUlHqProcForUe(cell, frm, ue, procRef)
4517 RgSchCellCb         *cell;
4518 CmLteTimingInfo     frm;
4519 RgSchUeCb           *ue;
4520 RgSchUlHqProcCb     **procRef;
4521 #endif
4522 {
4523    cell->sc.apis->rgSCHUlHqProcForUe(cell, frm, ue, procRef);
4524
4525  /* Stack Crash problems for TRACE5 changes. added the return below */
4526  RETVOID;
4527
4528 }
4529
4530 /**
4531  * @brief Returns first uplink allocation to send reception
4532  *        request to PHY
4533  *
4534  * @details
4535  *
4536  *     Function: rgSCHUtlFirstRcptnReq(cell)
4537  *     Purpose:  This function returns the first uplink allocation
4538  *               (or NULLP if there is none) in the slot
4539  *               in which is expected to prepare and send reception
4540  *               request to PHY.
4541  *
4542  *     Invoked by: TOM
4543  *
4544  *  @param[in]  RgSchCellCb      *cell
4545  *  @return  RgSchUlAlloc*
4546  **/
4547 #ifdef ANSI
4548 RgSchUlAlloc *rgSCHUtlFirstRcptnReq
4549 (
4550 RgSchCellCb      *cell
4551 )
4552 #else
4553 RgSchUlAlloc *rgSCHUtlFirstRcptnReq(cell)
4554 RgSchCellCb      *cell;
4555 #endif
4556 {
4557    return (cell->sc.apis->rgSCHFirstRcptnReq(cell));
4558 }
4559
4560 /**
4561  * @brief Returns first uplink allocation to send reception
4562  *        request to PHY
4563  *
4564  * @details
4565  *
4566  *     Function: rgSCHUtlNextRcptnReq(cell)
4567  *     Purpose:  This function returns the next uplink allocation
4568  *               (or NULLP if there is none) in the slot
4569  *               in which is expected to prepare and send reception
4570  *               request to PHY.
4571  *
4572  *     Invoked by: TOM
4573  *
4574  *  @param[in]  RgSchCellCb      *cell
4575  *  @return  RgSchUlAlloc*
4576  **/
4577 #ifdef ANSI
4578 RgSchUlAlloc *rgSCHUtlNextRcptnReq
4579 (
4580 RgSchCellCb      *cell,
4581 RgSchUlAlloc     *alloc
4582 )
4583 #else
4584 RgSchUlAlloc *rgSCHUtlNextRcptnReq(cell, alloc)
4585 RgSchCellCb      *cell;
4586 RgSchUlAlloc     *alloc;
4587 #endif
4588 {
4589    return (cell->sc.apis->rgSCHNextRcptnReq(cell, alloc));
4590 }
4591
4592 /**
4593  * @brief Returns first uplink allocation to send HARQ feedback
4594  *        request to PHY
4595  *
4596  * @details
4597  *
4598  *     Function: rgSCHUtlFirstHqFdbkAlloc
4599  *     Purpose:  This function returns the first uplink allocation
4600  *               (or NULLP if there is none) in the slot
4601  *               in which it is expected to prepare and send HARQ
4602  *               feedback to PHY.
4603  *
4604  *     Invoked by: TOM
4605  *
4606  *  @param[in]  RgSchCellCb      *cell
4607  *  @param[in]  U8                idx  
4608  *  @return  RgSchUlAlloc*
4609  **/
4610 #ifdef ANSI
4611 RgSchUlAlloc *rgSCHUtlFirstHqFdbkAlloc
4612 (
4613 RgSchCellCb      *cell,
4614 U8               idx
4615 )
4616 #else
4617 RgSchUlAlloc *rgSCHUtlFirstHqFdbkAlloc(cell, idx)
4618 RgSchCellCb      *cell;
4619 U8               idx;
4620 #endif
4621 {
4622    return (cell->sc.apis->rgSCHFirstHqFdbkAlloc(cell, idx));
4623 }
4624
4625 \f
4626 /**
4627  * @brief Returns next allocation to send HARQ feedback for
4628  *
4629  * @details
4630  *
4631  *     Function: rgSCHUtlNextHqFdbkAlloc(cell)
4632  *     Purpose:  This function returns the next uplink allocation
4633  *               (or NULLP if there is none) in the slot
4634  *               for which HARQ feedback needs to be sent.
4635  *
4636  *     Invoked by: TOM
4637  *
4638  *  @param[in]  RgSchCellCb      *cell
4639  *  @return  RgSchUlAlloc*
4640  **/
4641 #ifdef ANSI
4642 RgSchUlAlloc *rgSCHUtlNextHqFdbkAlloc
4643 (
4644 RgSchCellCb      *cell,
4645 RgSchUlAlloc     *alloc,
4646 U8               idx 
4647 )
4648 #else
4649 RgSchUlAlloc *rgSCHUtlNextHqFdbkAlloc(cell, alloc, idx)
4650 RgSchCellCb      *cell;
4651 RgSchUlAlloc     *alloc;
4652 U8               idx; 
4653 #endif
4654 {
4655    return (cell->sc.apis->rgSCHNextHqFdbkAlloc(cell, alloc, idx));
4656 }
4657
4658 /***********************************
4659 ***********************************/
4660 /**
4661  * @brief This API is invoked to send TFU SAP bind request to PHY.
4662  *
4663  * @details
4664  *
4665  *     Function : rgSCHUtlTfuBndReq
4666  *
4667  *      This API is invoked to send TFU SAP bind request to PHY from scheduler
4668  *      isntance. It fills in the Pst structure, spId and suId values and
4669  *      invokes bind request primitive at TFU.
4670  *
4671  *  @param[in]  Inst            instId
4672  *  @param[in]  SuId            suId
4673  *  @param[in]  SpId            spId
4674  *  @return  S16
4675  *      -# ROK
4676  *      -# RFAILED
4677  **/
4678 #ifdef ANSI
4679 S16 rgSCHUtlTfuBndReq
4680 (
4681 Inst    instId,
4682 SuId    suId,
4683 SpId    spId
4684 )
4685 #else
4686 S16 rgSCHUtlTfuBndReq(instId, suId, spId)
4687 Inst    instId;
4688 SuId    suId;
4689 SpId    spId;
4690 #endif
4691 {
4692    S16            ret;
4693    RgSchLowSapCb  *tfuSap;
4694    Pst            pst;
4695
4696    /* Get the lower SAP control block from the layer control block. */
4697    tfuSap = &(rgSchCb[instId].tfuSap[suId]);
4698    memcpy (&pst, &(tfuSap->sapCfg.sapPst), sizeof(Pst));
4699    if((ret = RgLiTfuSchBndReq (&pst, suId, spId)) != ROK)
4700    {
4701       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,"rgSCHUtlTfuBndReq() Call to RgLiTfuBndReq()"
4702                     " failed");
4703    }
4704    return (ret);
4705 }  /* rgSCHUtlTfuBndReq */
4706
4707 /**
4708  * @brief This API is invoked to send TFU SAP unbind request to PHY.
4709  *
4710  * @details
4711  *
4712  *     Function : rgSCHUtlTfuUBndReq
4713  *      This API is invoked to send TFU SAP unbind request to PHY from Scheduler
4714  *      isntance. It fills in the Pst structure and spId value and invokes
4715  *      unbind request primitive at TFU.
4716  *
4717  *  @param[in]  SpId            spId
4718  *  @return  S16
4719  *      -# ROK
4720  *      -# RFAILED
4721  **/
4722 #ifdef ANSI
4723 S16 rgSCHUtlTfuUBndReq
4724 (
4725 Inst    inst,
4726 RgSchLowSapCfgInfo sapCfg,
4727 Reason  reason
4728 )
4729 #else
4730 S16 rgSCHUtlTfuUBndReq(inst, sapCfg, reason)
4731 Inst    inst;
4732 RgSchLowSapCfgInfo sapCfg;
4733 Reason  reason;
4734 #endif
4735 {
4736    S16            ret;
4737    Pst            pst;
4738
4739    /* Get the lower SAP control block from the layer control block. */
4740    memcpy (&pst, &(sapCfg.sapPst), sizeof(Pst));
4741    if((ret = RgLiTfuSchUbndReq (&pst, sapCfg.spId, reason)) != ROK)
4742    {
4743       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"rgSCHUtlTfuUBndReq() Call to"
4744                                     " RgLiTfuUbndReq() failed");
4745    }
4746    return (ret);
4747
4748 }  /* rgSCHUtlTfuUBndReq */
4749
4750 /***********************************************************
4751  *
4752  *     Func : rgSCHUtlResetSfAlloc
4753  *
4754  *     Desc : Utility Function to Reset slot allocation information.
4755  *
4756  *
4757  *     Ret  : ROK
4758  *            RFAILED
4759  *
4760  *
4761  *     File : rg_utl.c
4762  *
4763  **********************************************************/
4764 #ifdef ANSI
4765 S16 rgSCHUtlResetSfAlloc
4766 (
4767 RgInfSfAlloc *sfAlloc,
4768 Bool         resetCmnLcInfo,
4769 Bool         restAlloc
4770 )
4771 #else
4772 S16 rgSCHUtlResetSfAlloc(sfAlloc,resetCmnLcInfo,restAlloc)
4773 RgInfSfAlloc *sfAlloc;
4774 Bool         resetCmnLcInfo;
4775 Bool         restAlloc;
4776 #endif
4777 {
4778    if(TRUE == restAlloc)
4779    {
4780       if(sfAlloc->ueInfo.numUes)
4781       {
4782          memset(sfAlloc->ueInfo.allocInfo,0x00,
4783                (sizeof(RgInfUeAlloc)*sfAlloc->ueInfo.numUes));
4784       }
4785       sfAlloc->ueInfo.numUes = 0;
4786       sfAlloc->rarInfo.numRaRntis = 0;
4787       sfAlloc->flowCntrlInfo.numUes = 0;
4788    }
4789    if(TRUE == resetCmnLcInfo)
4790    {
4791       sfAlloc->cmnLcInfo.bitMask = 0;
4792    }
4793    return ROK;
4794 }
4795
4796 /***********************************************************
4797  *
4798  *     Func : rgSCHUtlGetRlsHqAlloc
4799  *
4800  *     Desc : Utility Function to Allocate slot allocation information.
4801  *
4802  *
4803  *     Ret  : ROK
4804  *            RFAILED
4805  *
4806  *
4807  *     File : rg_utl.c
4808  *
4809  **********************************************************/
4810 #ifdef ANSI
4811 S16 rgSCHUtlGetRlsHqAlloc
4812 (
4813 RgSchCellCb *cell
4814 )
4815 #else
4816 S16 rgSCHUtlGetRlsHqAlloc(cell)
4817 RgSchCellCb *cell;
4818 #endif
4819 {
4820    U8    idx = 0;
4821    Inst  inst = cell->instIdx;
4822    for(idx=0; idx < RGSCH_NUM_SUB_FRAMES; idx++)
4823    {
4824       cell->rlsHqArr[idx].cellId = cell->cellId;
4825
4826       /* Allocating with additional location, to accommodate
4827          TA scheduling along with maximum no of UEs per SF */
4828
4829       /* Allocate memory for "scheduled UE" Info */
4830       if((rgSCHUtlAllocSBuf(inst,
4831                      (Data**)&(cell->rlsHqArr[idx].ueHqInfo),
4832                       (sizeof(RgInfUeHqInfo)*RGSCH_MAX_UE_PER_DL_SF))) != ROK)
4833       {
4834          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Memory allocation FAILED for "
4835             "UE Alloc");
4836          return RFAILED;
4837       }
4838    }
4839
4840    return ROK;
4841
4842 }
4843
4844 /***********************************************************
4845  *
4846  *     Func : rgSCHUtlPutRlsHqAlloc
4847  *
4848  *     Desc : Utility Function to deallocate slot allocation information.
4849  *
4850  *
4851  *     Ret  : ROK
4852  *            RFAILED
4853  *
4854  *
4855  *     File : rg_utl.c
4856  *
4857  **********************************************************/
4858 #ifdef ANSI
4859 S16 rgSCHUtlPutRlsHqAlloc
4860 (
4861 RgSchCellCb *cell
4862 )
4863 #else
4864 S16 rgSCHUtlPutRlsHqAlloc(cell)
4865 RgSchCellCb *cell;
4866 #endif
4867 {
4868    U8    idx = 0;
4869    Inst  inst = cell->instIdx;
4870
4871    for(idx=0; idx < RGSCH_NUM_SUB_FRAMES; idx++)
4872    {
4873       /* Deallocate memory for "scheduled UE" Info */
4874       if (cell->rlsHqArr[idx].ueHqInfo != NULLP)
4875       {
4876          /* Freeing with additional location, to accommodate TA
4877             scheduling along with maximum no of UEs per SF */
4878          /* ccpu00117052 - MOD - Passing double pointer
4879             for proper NULLP assignment*/
4880          rgSCHUtlFreeSBuf(inst,
4881                (Data **)(&(cell->rlsHqArr[idx].ueHqInfo)),
4882              (sizeof(RgInfUeHqInfo)*RGSCH_MAX_UE_PER_DL_SF));
4883       }
4884    }
4885
4886    return ROK;
4887
4888 }
4889
4890
4891 /***********************************************************
4892  *
4893  *     Func : rgSCHUtlGetSfAlloc
4894  *
4895  *     Desc : Utility Function to Allocate slot allocation information.
4896  *
4897  *
4898  *     Ret  : ROK
4899  *            RFAILED
4900  *
4901  *
4902  *     File : rg_utl.c
4903  *
4904  **********************************************************/
4905 #ifdef ANSI
4906 S16 rgSCHUtlGetSfAlloc
4907 (
4908 RgSchCellCb *cell
4909 )
4910 #else
4911 S16 rgSCHUtlGetSfAlloc(cell)
4912 RgSchCellCb *cell;
4913 #endif
4914 {
4915    U8    idx;
4916    U8    indx;
4917    Inst  inst = cell->instIdx;
4918    RgSchCmnUlCell *cellUl      = RG_SCH_CMN_GET_UL_CELL(cell);
4919
4920 #ifdef LTE_TDD
4921    for(idx=0; idx < RGSCH_SF_ALLOC_SIZE; idx++)
4922 #else
4923    for(idx=0; idx < RGSCH_NUM_SUB_FRAMES; idx++)
4924 #endif
4925    {
4926       cell->sfAllocArr[idx].cellId = cell->cellId;
4927
4928       /* Allocating with additional location, to accommodate
4929          TA scheduling along with maximum no of UEs per SF */
4930
4931       /* Allocate memory for "scheduled UE" Info */
4932       if((rgSCHUtlAllocSBuf(inst,
4933                      (Data**)&(cell->sfAllocArr[idx].ueInfo.allocInfo),
4934                       (sizeof(RgInfUeAlloc)*RGSCH_MAX_UE_PER_DL_SF))) != ROK)
4935       {
4936          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Memory allocation FAILED for "
4937             "UE Alloc");
4938          return RFAILED;
4939       }
4940
4941       /* Allocate memory for "scheduled RAR" Info */
4942       if((rgSCHUtlAllocSBuf(inst,
4943                      (Data**)&(cell->sfAllocArr[idx].rarInfo.raRntiInfo),
4944                       (sizeof(RgInfRaRntiInfo)*RGSCH_MAX_RARNTI_PER_DL_SF))) != ROK)
4945       {
4946          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Memory allocation FAILED for "
4947             "RARNTI");
4948          return RFAILED;
4949       }
4950       for(indx = 0; indx < RGSCH_MAX_RARNTI_PER_DL_SF; indx++)
4951       {
4952          if((rgSCHUtlAllocSBuf(inst,
4953             (Data**)&(cell->sfAllocArr[idx].rarInfo.raRntiInfo[indx].crntiInfo),
4954                    (sizeof(RgInfCrntiInfo)* (cellUl->maxMsg3PerUlSf)))) != ROK)
4955          {
4956             RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Memory allocation FAILED for "
4957                "RNTI");
4958             return RFAILED;
4959          }
4960       }
4961
4962    }
4963
4964 #ifdef EMTC_ENABLE
4965    rgSCHEmtcUtlGetSfAlloc(cell);
4966 #endif
4967
4968    return ROK;
4969
4970 }
4971
4972 /***********************************************************
4973  *
4974  *     Func : rgSCHUtlPutSfAlloc
4975  *
4976  *     Desc : Utility Function to deallocate slot allocation information.
4977  *
4978  *
4979  *     Ret  : ROK
4980  *            RFAILED
4981  *
4982  *
4983  *     File : rg_utl.c
4984  *
4985  **********************************************************/
4986 #ifdef ANSI
4987 S16 rgSCHUtlPutSfAlloc
4988 (
4989 RgSchCellCb *cell
4990 )
4991 #else
4992 S16 rgSCHUtlPutSfAlloc(cell)
4993 RgSchCellCb *cell;
4994 #endif
4995 {
4996    U8    idx;
4997    U8    indx;
4998    Inst  inst = cell->instIdx;
4999    RgSchCmnUlCell *cellUl      = RG_SCH_CMN_GET_UL_CELL(cell);
5000
5001 #ifdef LTE_TDD
5002    for(idx=0; idx < RGSCH_SF_ALLOC_SIZE; idx++)
5003 #else
5004       for(idx=0; idx < RGSCH_NUM_SUB_FRAMES; idx++)
5005 #endif
5006       {
5007          if (cell->sfAllocArr[idx].rarInfo.raRntiInfo != NULLP)
5008          {
5009             for(indx = 0; indx < RGSCH_MAX_RARNTI_PER_DL_SF; indx++)
5010             {
5011                if (cell->sfAllocArr[idx].rarInfo.raRntiInfo[indx].crntiInfo != NULLP)
5012                   /* ccpu00117052 - MOD - Passing double pointer
5013                      for proper NULLP assignment*/
5014                   rgSCHUtlFreeSBuf(inst,
5015                         (Data**)(&(cell->sfAllocArr[idx].rarInfo.raRntiInfo[indx].\
5016                               crntiInfo)),
5017                         (sizeof(RgInfCrntiInfo)* (cellUl->maxMsg3PerUlSf)));
5018             }
5019             /* Deallocate memory for "scheduled RAR" Info */
5020             /* ccpu00117052 - MOD - Passing double pointer
5021                for proper NULLP assignment*/
5022             rgSCHUtlFreeSBuf(inst,
5023                   (Data**)(&(cell->sfAllocArr[idx].rarInfo.raRntiInfo)),
5024                   (sizeof(RgInfRaRntiInfo)*RGSCH_MAX_RARNTI_PER_DL_SF));
5025          }
5026          /* Deallocate memory for "scheduled UE" Info */
5027          if (cell->sfAllocArr[idx].ueInfo.allocInfo != NULLP)
5028          {
5029             /* Freeing with additional location, to accommodate TA
5030                scheduling along with maximum no of UEs per SF */
5031             /* ccpu00117052 - MOD - Passing double pointer
5032                for proper NULLP assignment*/
5033             rgSCHUtlFreeSBuf(inst,
5034                   (Data**)(&(cell->sfAllocArr[idx].ueInfo.allocInfo)),
5035                   (sizeof(RgInfUeAlloc)*RGSCH_MAX_UE_PER_DL_SF));
5036          }
5037       }
5038
5039 #ifdef EMTC_ENABLE
5040    rgSCHEmtcUtlPutSfAlloc(cell);
5041 #endif
5042    return ROK;
5043
5044 }
5045
5046 /***********************************************************
5047  *
5048  *     Func : rgSCHUtlAllocSBuf
5049  *
5050  *     Desc : Utility Function to Allocate static buffer.
5051  *            Memory allocated is assumed contiguous.
5052  *
5053  *
5054  *     Ret  : ROK
5055  *            RFAILED
5056  *
5057  *     Notes: Caller doesnt need to raise the alarm in case of memory
5058  *            allocation gets failed.
5059  *
5060  *     File : rg_utl.c
5061  *
5062  **********************************************************/
5063 #ifdef ANSI
5064 S16 rgSCHUtlAllocSBuf
5065 (
5066 Inst    inst,               /* Instance of the invoking scheduler */
5067 Data    **pData,            /* Pointer of the data to be returned */
5068 Size    size                /* size */
5069 )
5070 #else
5071 S16 rgSCHUtlAllocSBuf(inst, pData, size)
5072 Inst    inst;              /* Instance of the invoking scheduler */
5073 Data    **pData;            /* Pointer of the data to be returned */
5074 Size    size;               /* size */
5075 #endif
5076 {
5077    /* Moving alarm diagnostics to available scope */
5078
5079    /* Initialize the param to NULLP */
5080    *pData = NULLP;
5081
5082    /* May not be necessary for data performance path */
5083 #ifndef NO_ERRCLS
5084    if (size == 0)
5085    {
5086       return RFAILED;
5087    }
5088 #endif
5089
5090    /* allocate buffer */
5091 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
5092    MS_BUF_ADD_ALLOC_CALLER();
5093 #endif /* */
5094    if (SGetSBuf(rgSchCb[inst].rgSchInit.region, rgSchCb[inst].rgSchInit.pool,
5095                       pData, size) != ROK)
5096    {
5097      RgUstaDgn dgn;      /* Alarm diagnostics structure */
5098      dgn.type = LRG_USTA_DGNVAL_MEM;
5099      dgn.u.mem.region = rgSchCb[inst].rgSchInit.region;
5100      dgn.u.mem.pool = rgSchCb[inst].rgSchInit.pool;
5101      /*  Send an alarm to Layer Manager */
5102      rgSCHLmmStaInd(inst, LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
5103                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
5104      RGSCHLOGERROR(inst, ERRCLS_DEBUG, ERG015, 0, "Unable to Allocate Buffer");
5105      RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "Unable to Allocate the Buffer");
5106      return RFAILED;
5107    }
5108
5109
5110    /* zero out the allocated memory */
5111    memset(*pData, 0x00, size);
5112
5113    return ROK;
5114
5115 } /* end of rgSCHUtlAllocSBuf */
5116
5117 \f
5118 /*
5119 *
5120 *       Fun:   rgSCHUtlFreeSBuf
5121 *
5122 *       Desc:  The argument to rgSCHUtlFreeSBuf() is a pointer to a block
5123 *              previously allocated by rgSCHUtlAllocSBuf() and size. It
5124 *              deallocates the memory.
5125 *
5126 *       Ret:   RETVOID
5127 *
5128 *       Notes: None
5129 *       File:  rg_utl.c
5130 */
5131 #ifdef ANSI
5132 Void rgSCHUtlFreeSBuf
5133 (
5134 Inst inst,          /* Instance of the invoking scheduler */
5135 Data **data,         /* pointer to data */
5136 Size size           /* size */
5137 )
5138 #else
5139 Void rgSCHUtlFreeSBuf(inst, data, size)
5140 Inst inst;          /* Instance of the invoking scheduler */
5141 Data **data;         /* pointer to data */
5142 Size size;          /* size */
5143 #endif
5144 {
5145
5146    S16 ret;
5147
5148    if ((data == NULLP) || (*data == NULLP) || (size == 0))
5149    {
5150       RETVOID;
5151    }
5152
5153
5154 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
5155    MS_BUF_ADD_CALLER();
5156 #endif /* */
5157    /* Deallocate buffer */
5158    ret = SPutSBuf(rgSchCb[inst].rgSchInit.region,
5159                   rgSchCb[inst].rgSchInit.pool, (*data), size);
5160
5161    if (ret != ROK)
5162    {
5163       RGSCHLOGERROR(inst, ERRCLS_DEBUG, ERG016, (ErrVal) 0,
5164                  "rgSCHUtlFreeSBuf failed.\n");
5165       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "rgSCHUtlFreeSBuf failed");
5166       RETVOID;
5167    }
5168
5169    /* ccpu00117052 - ADD - Assigning the pointer to NULLP */
5170    *data = NULLP;
5171
5172    RETVOID;
5173 } /* end of rgSCHUtlFreeSBuf */
5174
5175 \f
5176 #ifdef RGR_SI_SCH
5177 /*
5178 *
5179 *       Fun:   rgSCHUtlFreeWarningSiSeg
5180 *
5181 *       Desc:  This is used to deallocate Warning SI Seg.
5182 *
5183 *       Ret:   RETVOID
5184 *
5185 *       Notes: None
5186 *
5187 *       File:  rg_utl.c
5188 */
5189 #ifdef ANSI
5190 Void rgSCHUtlFreeWarningSiSeg
5191 (
5192 Region        reg,
5193 Pool          pool,
5194 CmLListCp     *siPduLst          
5195 )
5196 #else
5197 Void rgSCHUtlFreeWarningSiSeg(reg, pool, siPduLst)
5198 Region        reg;
5199 Pool          pool;
5200 CmLListCp     *siPduLst;          
5201 #endif
5202 {
5203    CmLList      *node;
5204    Buffer       *pdu;
5205
5206       while (siPduLst->first != NULLP)
5207       {
5208          node = siPduLst->first;
5209          pdu = (Buffer *)node->node;
5210          cmLListDelFrm(siPduLst, node);
5211          RGSCH_FREE_MSG(pdu);
5212          SPutSBuf(reg, pool, (Data *)node,sizeof(CmLList));
5213          node = NULLP;
5214       }
5215
5216    RETVOID;
5217 } /* end of rgSCHUtlFreeWarningSiSeg */         
5218
5219 \f
5220 /*
5221 *
5222 *       Fun:   rgSCHUtlFreeWarningSiPdu
5223 *
5224 *       Desc:  This is used to deallocate Warning SI PDU.
5225 *
5226 *       Ret:   RETVOID
5227 *
5228 *       Notes: None
5229 *
5230 *       File:  rg_utl.c
5231 */
5232 #ifdef ANSI
5233 Void rgSCHUtlFreeWarningSiPdu
5234 (
5235 RgSchCellCb       *cell
5236 )
5237 #else
5238 Void rgSCHUtlFreeWarningSiPdu(cell)
5239 RgSchCellCb       *cell;
5240 #endif
5241 {
5242    CmLList            *node;
5243    Buffer             *pdu;
5244    RgSchWarningSiInfo *warningSi;
5245    RgSchWarningSiPdu  *warningSiPdu; 
5246
5247    warningSi = (RgSchWarningSiInfo *) cell->siCb.\
5248                   siArray[cell->siCb.siCtx.siId-1].si; 
5249    /* ccpu00136659: CMAS ETWS design changes */
5250    CM_LLIST_FIRST_NODE(&warningSi->warningSiMsg.segLstCp, node);
5251    if (node == NULLP)
5252    {
5253       RETVOID;
5254    }
5255
5256    warningSiPdu = (RgSchWarningSiPdu *)node->node;
5257    pdu = warningSiPdu->pdu;
5258    /* ccpu00136659: CMAS ETWS design changes */
5259    cmLListDelFrm(&warningSi->warningSiMsg.segLstCp, node); 
5260    RGSCH_FREE_MSG(pdu);
5261    if(warningSi->warningSiMsg.segLstCp.count == 0)
5262    {
5263       /* ccpu00136659: CMAS ETWS design changes */
5264       cell->siCb.siArray[cell->siCb.siCtx.siId-1].si = NULLP;
5265       rgSCHUtlRgrWarningSiCfgCfm(cell->instIdx,
5266             rgSchCb[cell->instIdx].rgrSap->sapCfg.spId,
5267             cell->siCb.warningSi[warningSi->idx].siId,
5268             warningSi->warningSiMsg.transId, RGR_CFG_CFM_TX_COMPLETE);
5269    }                                                                                 
5270
5271    RETVOID;
5272
5273 } /* end of rgSCHUtlFreeWarningSiPdu */         
5274  
5275 \f
5276 /*
5277 *
5278 *       Fun:   rgSCHUtlGetWarningSiPdu
5279 *
5280 *       Desc:  This is used to get Warning SI PDU for Scheduling. 
5281 *
5282 *       Ret:   
5283 *
5284 *       Notes: None
5285 *
5286 *       File:  rg_utl.c
5287 */
5288 #ifdef ANSI
5289 Buffer *rgSCHUtlGetWarningSiPdu
5290 (
5291 RgSchCellCb             *cell
5292 )
5293 #else
5294 Buffer *rgSCHUtlGetWarningSiPdu(cell)
5295 RgSchCellCb             *cell;
5296 #endif
5297 {
5298    RgSchWarningSiInfo  *warningSi;
5299    RgSchWarningSiPdu  *warningSiPdu; 
5300    Buffer       *pdu;
5301    CmLList      *node;
5302
5303    warningSi = (RgSchWarningSiInfo *) cell->siCb.
5304    siArray[cell->siCb.siCtx.siId-1].si; 
5305    /* ccpu00136659: CMAS ETWS design changes */
5306    CM_LLIST_FIRST_NODE(&warningSi->warningSiMsg.segLstCp, node);
5307    if (node != NULLP)
5308    {
5309       warningSiPdu = (RgSchWarningSiPdu *)node->node;
5310       pdu = warningSiPdu->pdu;
5311       return (pdu);
5312    }
5313    else
5314    {
5315       return (NULLP);
5316    }                                                  
5317 } /* rgSCHUtlGetWarningSiPdu  */    
5318
5319 \f
5320 /*
5321 *
5322 *       Fun:   rgSCHUtlGetMcsAndNPrb
5323 *
5324 *       Desc:  This is used to get mcs and nPrb value. 
5325 *
5326 *       Ret:   
5327 *
5328 *       Notes: None
5329 *
5330 *       File:  rg_utl.c
5331 */
5332 #ifdef ANSI
5333 S16 rgSCHUtlGetMcsAndNPrb
5334 (
5335 RgSchCellCb         *cell,
5336 U8                  *nPrb,
5337 U8                  *mcs,
5338 MsgLen              *msgLen
5339 )
5340 #else
5341 S16 rgSCHUtlGetMcsAndNPrb(cell, nPrb, mcs, msgLen)
5342 RgSchCellCb         *cell;
5343 U8                  *nPrb;
5344 U8                  *mcs;
5345 MsgLen              *msgLen;
5346 #endif
5347 {
5348    RgSchWarningSiInfo  *warningSi;
5349    RgSchWarningSiPdu  *warningSiPdu; 
5350    CmLList      *node;
5351
5352    if(cell->siCb.siCtx.warningSiFlag == FALSE)
5353    {
5354       *mcs =  cell->siCb.crntSiInfo.siInfo[cell->siCb.siCtx.siId-1].mcs;
5355       *nPrb =  cell->siCb.crntSiInfo.siInfo[cell->siCb.siCtx.siId-1].nPrb;
5356       *msgLen = cell->siCb.crntSiInfo.siInfo[cell->siCb.siCtx.siId-1].msgLen;
5357    }
5358    else
5359    {
5360       warningSi = (RgSchWarningSiInfo *) cell->siCb.
5361             siArray[cell->siCb.siCtx.siId-1].si; 
5362       /* ccpu00136659: CMAS ETWS design changes */
5363       CM_LLIST_FIRST_NODE(&warningSi->warningSiMsg.segLstCp, node);
5364       if (node == NULLP)
5365       {
5366         return RFAILED;
5367       }
5368       
5369       warningSiPdu = (RgSchWarningSiPdu *)node->node;
5370       *mcs = warningSiPdu->mcs;
5371       *nPrb = warningSiPdu->nPrb;
5372       *msgLen = warningSiPdu->msgLen;
5373       return ROK;
5374             
5375    }
5376    return ROK;
5377 } /* rgSCHUtlGetMcsAndNPrb  */     
5378
5379 /*
5380 *
5381 *       Fun:   rgSCHUtlCalMacAndPrb
5382 *
5383 *       Desc:  This is used to Calculate mcs and nPrb value for SIB1 and SIs. 
5384 *
5385 *       Ret:   
5386 *
5387 *       Notes: None
5388 *
5389 *       File:  rg_utl.c
5390 */
5391 #ifdef ANSI
5392 S16 rgSCHUtlCalMcsAndNPrb
5393 (
5394 RgSchCellCb         *cell,
5395 U8                  cfgType,
5396 MsgLen              msgLen,
5397 U8                  siId
5398 )
5399 #else
5400 S16 rgSCHUtlCalMcsAndNPrb(cell, nPrb, mcs, msgLen)
5401 RgSchCellCb         *cell;
5402 U8                  cfgType;
5403 MsgLen              msgLen;
5404 U8                  siId;
5405 #endif
5406 {
5407    U8 mcs = 0;
5408    U8 nPrb = 0;
5409
5410       /*Get the nPrb and mcs parametr values */
5411    if (rgSCHUtlGetAllwdCchTbSz(msgLen*8, &nPrb, &mcs) != (msgLen*8))
5412       {
5413          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId, "msgLen does "
5414             "not match any valid TB Size");
5415          return RFAILED;
5416       }
5417
5418
5419    if(cfgType == RGR_SI_CFG_TYPE_SIB1 || cfgType == RGR_SI_CFG_TYPE_SIB1_PWS)
5420    {
5421
5422       if(cell->siCb.crntSiInfo.sib1Info.sib1 == NULLP)
5423       {
5424          cell->siCb.crntSiInfo.sib1Info.mcs = mcs;
5425          cell->siCb.crntSiInfo.sib1Info.nPrb = nPrb;
5426          cell->siCb.crntSiInfo.sib1Info.msgLen = msgLen;
5427       }
5428       else
5429       {
5430          cell->siCb.newSiInfo.sib1Info.mcs = mcs;
5431          cell->siCb.newSiInfo.sib1Info.nPrb= nPrb;
5432          cell->siCb.newSiInfo.sib1Info.msgLen = msgLen;
5433       }
5434    }
5435
5436     
5437    if(cfgType == RGR_SI_CFG_TYPE_SI)
5438    {
5439       if(cell->siCb.crntSiInfo.siInfo[siId-1].si == NULLP &&
5440          !(cell->siCb.siBitMask & RGSCH_SI_SICFG_UPD))
5441       {
5442          cell->siCb.crntSiInfo.siInfo[siId-1].mcs = mcs;
5443          cell->siCb.crntSiInfo.siInfo[siId-1].nPrb = nPrb;
5444          cell->siCb.crntSiInfo.siInfo[siId-1].msgLen = msgLen;
5445       }
5446       else
5447       {
5448          cell->siCb.newSiInfo.siInfo[siId-1].mcs = mcs;
5449          cell->siCb.newSiInfo.siInfo[siId-1].nPrb= nPrb;
5450          cell->siCb.newSiInfo.siInfo[siId-1].msgLen = msgLen;
5451       }
5452    }
5453
5454    if(cfgType == RGR_SI_CFG_TYPE_SIB8_CDMA)
5455    {
5456       cell->siCb.crntSiInfo.siInfo[siId-1].mcs = mcs;
5457       cell->siCb.crntSiInfo.siInfo[siId-1].nPrb = nPrb;
5458       cell->siCb.crntSiInfo.siInfo[siId-1].msgLen = msgLen;
5459    }
5460
5461     return ROK;
5462 }
5463 #endif
5464
5465 /***********************************************************
5466  *
5467  *     Func : rgSCHUtlFillDgnParams
5468  *
5469  *     Desc : Utility Function to Fill Diagonostic params.
5470  *
5471  *     Ret  : None.
5472  *
5473  *     Notes: None.
5474  *
5475  *     File : rg_utl.c
5476  *
5477  **********************************************************/
5478 #ifdef ANSI
5479 Void rgSCHUtlFillDgnParams
5480 (
5481 Inst        inst,
5482 RgUstaDgn   *dgn,
5483 U8          dgnType
5484 )
5485 #else
5486 Void rgSCHUtlFillDgnParams(inst, dgn, dgnType)
5487 Inst        inst;
5488 RgUstaDgn   *dgn;
5489 U8          dgnType;
5490 #endif
5491 {
5492
5493    switch(dgnType)
5494    {
5495       case LRG_USTA_DGNVAL_MEM:
5496          dgn->type = (U8) LRG_USTA_DGNVAL_MEM;
5497          dgn->u.mem.region  = rgSchCb[inst].rgSchInit.region;
5498          dgn->u.mem.pool    = rgSchCb[inst].rgSchInit.pool;
5499       break;
5500
5501       default:
5502       break;
5503    }
5504
5505    RETVOID;
5506 } /* end of rgSCHUtlFillDgnParams */
5507
5508 /***********************************************************
5509  *
5510  *     Func : rgSCHUtlGetPstToLyr
5511  *
5512  *     Desc : Utility Function to get the pst structure to post a message to MAC
5513  *
5514  *
5515  *     Ret  : ROK
5516  *            RFAILED
5517  *
5518  *     Notes: This function should be called while sending a msg from
5519  *     scheduler instance to MAC
5520  *
5521  *     File : rg_utl.c
5522  *
5523  **********************************************************/
5524 #ifdef ANSI
5525 Void rgSCHUtlGetPstToLyr
5526 (
5527 Pst     *pst,
5528 RgSchCb *schCb,
5529 Inst    macInst
5530 )
5531 #else
5532 Void rgSCHUtlGetPstToLyr (pst, schCb, macInst)
5533 Pst     *pst;
5534 RgSchCb *schCb;
5535 Inst    macInst;
5536 #endif
5537 {
5538
5539    /* Only the needed params are filled */
5540    pst->region = schCb->rgSchInit.region;
5541    pst->pool = schCb->rgSchInit.pool;
5542    pst->srcInst = schCb->rgSchInit.inst+SCH_INST_START;
5543    pst->srcProcId = schCb->rgSchInit.procId;
5544    pst->dstProcId = schCb->rgSchInit.procId;
5545
5546    pst->dstInst = macInst;
5547    pst->dstEnt = ENTMAC;
5548    pst->srcEnt = ENTMAC;
5549    pst->selector = 0;
5550    pst->prior     = PRIOR0;
5551    pst->intfVer   = 0;
5552    pst->route   = RTESPEC;
5553
5554    RETVOID;
5555 } /* end of rgSCHUtlGetPstToLyr */
5556
5557 /** @brief This function fills in the common lc information to be sent to MAC
5558  *
5559  * @details
5560  *
5561  *     Function: rgSCHUtlFillRgInfCmnLcInfo
5562  *       @param  RgSchDlSf       *sf,
5563  *       @param  RgInfSfAlloc    *sfAlloc,
5564  *       @param  CmLteLcId       lcId,
5565  *       @param  Bool            sendInd
5566  *
5567  * @return  S16
5568  *      -# ROK
5569  *      -# RFAILED
5570  */
5571 #ifdef ANSI
5572 S16 rgSCHUtlFillRgInfCmnLcInfo
5573 (
5574 RgSchDlSf       *sf,
5575 RgInfSfAlloc    *sfAlloc,
5576 CmLteLcId       lcId,
5577 Bool            sendInd
5578 )
5579 #else
5580 S16 rgSCHUtlFillRgInfCmnLcInfo(sf, sfAlloc, lcId, sendInd)
5581 RgSchDlSf       *sf;
5582 RgInfSfAlloc    *sfAlloc;
5583 CmLteLcId       lcId;
5584 Bool            sendInd;
5585 #endif
5586 {
5587
5588    if((sf->bch.tbSize)&&
5589       !(sfAlloc->cmnLcInfo.bitMask & RGINF_BCH_INFO))
5590    {
5591 #ifndef RGR_SI_SCH
5592       sfAlloc->cmnLcInfo.bchInfo.lcId = lcId;
5593 #endif
5594       sfAlloc->cmnLcInfo.bitMask |= RGINF_BCH_INFO;
5595    }
5596    else if((sf->bcch.pdcch != NULLP)&&
5597       !(sfAlloc->cmnLcInfo.bitMask & RGINF_BCCH_INFO))
5598    {
5599       sfAlloc->cmnLcInfo.bcchInfo.rnti = RGSCH_SI_RNTI;
5600       rgSCHUtlFillPdschDciInfo(&(sfAlloc->cmnLcInfo.bcchInfo.dciInfo),
5601                                        &(sf->bcch.pdcch->dci));
5602 #ifndef RGR_SI_SCH
5603       sfAlloc->cmnLcInfo.bcchInfo.lcId = lcId;
5604       sfAlloc->cmnLcInfo.bcchInfo.sndStatInd = sendInd;
5605 #endif
5606       sfAlloc->cmnLcInfo.bitMask |= RGINF_BCCH_INFO;
5607    }
5608    else if((sf->pcch.pdcch != NULLP) &&
5609       !(sfAlloc->cmnLcInfo.bitMask & RGINF_PCCH_INFO))
5610    {
5611       sfAlloc->cmnLcInfo.pcchInfo.rnti = RGSCH_P_RNTI;
5612       rgSCHUtlFillPdschDciInfo(&(sfAlloc->cmnLcInfo.pcchInfo.dciInfo),
5613                                          &(sf->pcch.pdcch->dci));
5614       sfAlloc->cmnLcInfo.pcchInfo.lcId = lcId;
5615       sfAlloc->cmnLcInfo.bitMask |= RGINF_PCCH_INFO;
5616    }
5617    return ROK;
5618 }
5619
5620 /** @brief This function fills in the RAR information to be sent to MAC
5621  *
5622  * @details
5623  *
5624  *     Function: rgSCHUtlFillRgInfRarInfo
5625  *
5626  * @param  RgSchCellCb  *cell 
5627  * @param  RgSchDlSf    *sf 
5628  * @param  RgInfSfAlloc *sfAlloc
5629  * @return  S16
5630  *      -# ROK
5631  *      -# RFAILED
5632  */
5633 #ifdef ANSI
5634 S16 rgSCHUtlFillRgInfRarInfo
5635 (
5636 RgSchDlSf       *sf,
5637 RgInfSfAlloc    *sfAlloc,
5638 RgSchCellCb     *cell
5639 )
5640 #else
5641 S16 rgSCHUtlFillRgInfRarInfo(sf, sfAlloc, cell)
5642 RgSchDlSf       *sf;
5643 RgInfSfAlloc    *sfAlloc;
5644 RgSchCellCb     *cell;
5645 #endif 
5646 {
5647    U8               idx;
5648    CmLListCp        *lnkLst;
5649    CmLList          *tmp;
5650    RgSchRaCb        *raCb;
5651    RgSchUeCb        *ue;
5652    RgInfRaRntiInfo  *raRntiAlloc;
5653    U8               noRaRsps;
5654    RgSchCmnDlCell   *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
5655
5656 #ifdef LTE_TDD
5657    noRaRsps = RGSCH_MAX_TDD_RA_RSP_ALLOC;
5658 #else
5659    noRaRsps = RGSCH_MAX_RA_RSP_ALLOC;
5660 #endif
5661
5662    for(idx =0; idx < noRaRsps; idx++)
5663    {
5664       if (sf->raRsp[idx].pdcch == NULLP)
5665       {
5666          /* No further raResp Allocations. */
5667          break;
5668       }
5669       /* Added Dl TB count for RACH Response transmission*/
5670 #ifdef LTE_L2_MEAS
5671       cell->dlUlTbCnt.tbTransDlTotalCnt++;
5672 #endif      
5673       raRntiAlloc = &(sfAlloc->rarInfo.raRntiInfo[idx]);
5674       raRntiAlloc->raRnti = sf->raRsp[idx].raRnti;
5675       raRntiAlloc->schdTbSz = sf->raRsp[idx].tbSz;
5676       raRntiAlloc->numCrnti = 0;
5677       rgSCHUtlFillPdschDciInfo(&(raRntiAlloc->dciInfo),
5678                       &(sf->raRsp[idx].pdcch->dci));
5679       /* RACHO : fill backoff indicator information */
5680       raRntiAlloc->backOffInd = sf->raRsp[idx].backOffInd;
5681
5682       /* Fill for contention free UEs*/
5683       lnkLst = &(sf->raRsp[idx].contFreeUeLst);
5684       CM_LLIST_FIRST_NODE(lnkLst, tmp);
5685       while (tmp)
5686       {
5687          ue = (RgSchUeCb *)tmp->node;
5688          tmp = tmp->next;
5689          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].tmpCrnti = ue->ueId;
5690          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].isContFree = TRUE;
5691          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].rapId = ue->ul.rarGrnt.rapId;
5692 #ifndef MAC_5GTF_UPDATE
5693          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.hop =
5694                                                         ue->ul.rarGrnt.hop;
5695          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.cqiBit =
5696                                                         ue->ul.rarGrnt.cqiReqBit;
5697 #endif
5698          /* SHASHAHNK ADD RIV CALC */
5699          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.rbStart =
5700                                                         ue->ul.rarGrnt.rbStart;
5701          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.numRb =
5702                                                         ue->ul.rarGrnt.numRb;
5703          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.tpc =
5704                                                         ue->ul.rarGrnt.tpc;
5705          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.iMcsCrnt =
5706                                                         ue->ul.rarGrnt.iMcsCrnt;
5707          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].ta = ue->ul.rarGrnt.ta;
5708          raRntiAlloc->numCrnti++;
5709          cmLListDelFrm(lnkLst, &ue->ul.rarGrnt.raRspLnk);
5710          ue->ul.rarGrnt.raRspLnk.node = (PTR)NULLP;
5711       }
5712       /* Fill for contention based UEs*/
5713       lnkLst = &(sf->raRsp[idx].raRspLst);
5714
5715       CM_LLIST_FIRST_NODE(lnkLst, tmp);
5716
5717       while((NULLP != tmp) && ((RgSchRaCb *)tmp->node != NULLP))
5718       {
5719          raCb     = (RgSchRaCb *)tmp->node;
5720
5721          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].tmpCrnti = raCb->tmpCrnti;
5722          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].isContFree = FALSE;
5723          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].rapId = raCb->rapId;
5724          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].ta.pres = TRUE;
5725          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].ta.val = raCb->ta.val;
5726 #ifndef MAC_5GTF_UPDATE
5727          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.hop =
5728                                                         raCb->msg3Grnt.hop;
5729          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.cqiBit = FALSE;
5730 #endif
5731          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.rbStart =
5732                                                         raCb->msg3Grnt.rbStart;
5733          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.numRb =
5734                                                         raCb->msg3Grnt.numRb;
5735          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.tpc =
5736                                                         raCb->msg3Grnt.tpc;
5737          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.iMcsCrnt =
5738                                                         raCb->msg3Grnt.iMcsCrnt;
5739          raRntiAlloc->crntiInfo[raRntiAlloc->numCrnti].grnt.delayBit =
5740                                                         raCb->msg3Grnt.delayBit;
5741          /* For initial attaching UEs Aperiodic CQI need not be triggered */
5742          raRntiAlloc->numCrnti++;
5743          /* Search the next node */
5744          CM_LLIST_NEXT_NODE(lnkLst, tmp);
5745       }
5746    }
5747    sfAlloc->rarInfo.numRaRntis = idx;
5748    /* ccpu00132314-ADD-Update the tx power allocation info  
5749       TODO-Need to add a check for max tx power per symbol */
5750    sfAlloc->rarInfo.txPwrOffset = cellDl->rarTxPwrOffset;
5751
5752    return ROK;
5753 } /* end of rgSCHUtlFillRgInfRarInfo */
5754
5755 /** @brief This function fills in the pdsch data related allocation Info
5756  *         from the pdcch DCI info.
5757  * slot
5758  *
5759  * @details
5760  *
5761  *     Function: rgSCHUtlFillPdschDciInfo
5762  *
5763  *         Processing steps:
5764  *         - Depending upon the DCI Format, fill the appropriate fields.
5765  *
5766  * @param  [out] TfuPdschDciInfo *pdschDci
5767  * @param  [in]  TfuDciInfo      *pdcchDci
5768  * @return  S16
5769  *      -# ROK
5770  *      -# RFAILED
5771  */
5772 #ifdef ANSI
5773 S16 rgSCHUtlFillPdschDciInfo
5774 (
5775 TfuPdschDciInfo *pdsch,
5776 TfuDciInfo      *pdcchDci
5777 )
5778 #else
5779 S16 rgSCHUtlFillPdschDciInfo(pdsch, pdcchDci)
5780 TfuPdschDciInfo *pdsch;
5781 TfuDciInfo      *pdcchDci;
5782 #endif
5783 {
5784
5785 #ifdef EMTC_ENABLE
5786   S16 ret = ROK; 
5787 #endif
5788    pdsch->format = pdcchDci->dciFormat;
5789    switch(pdcchDci->dciFormat)
5790    {
5791       case TFU_DCI_FORMAT_1:
5792          pdsch->u.format1AllocInfo = pdcchDci->u.format1Info.allocInfo;
5793          break;
5794       case TFU_DCI_FORMAT_1A:
5795          if (pdcchDci->u.format1aInfo.isPdcchOrder == FALSE)
5796          {
5797             pdsch->u.format1aAllocInfo = pdcchDci->u.format1aInfo.t.pdschInfo.allocInfo;
5798          }
5799          break;
5800       case TFU_DCI_FORMAT_1B:
5801          pdsch->u.format1bAllocInfo = pdcchDci->u.format1bInfo.allocInfo;
5802          break;
5803       case TFU_DCI_FORMAT_1C:
5804          pdsch->u.format1cAllocInfo = pdcchDci->u.format1cInfo;
5805          break;
5806       case TFU_DCI_FORMAT_1D:
5807          pdsch->u.format1dAllocInfo = pdcchDci->u.format1dInfo.allocInfo;
5808          break;
5809       case TFU_DCI_FORMAT_2:
5810          pdsch->u.format2AllocInfo = pdcchDci->u.format2Info.allocInfo;
5811          break;
5812       case TFU_DCI_FORMAT_2A:
5813          pdsch->u.format2AAllocInfo = pdcchDci->u.format2AInfo.allocInfo;
5814          break;
5815 #ifdef RG_5GTF
5816                 case TFU_DCI_FORMAT_B1:
5817          pdsch->u.formatB1Info = pdcchDci->u.formatB1Info;
5818          break;
5819       case TFU_DCI_FORMAT_B2:
5820          pdsch->u.formatB2Info = pdcchDci->u.formatB2Info;
5821          break;
5822 #endif
5823       default:
5824 #ifdef EMTC_ENABLE
5825  ret = rgSCHEmtcUtlFillPdschDciInfo(pdsch, pdcchDci);
5826  if(RFAILED == ret)
5827  {
5828       return RFAILED;
5829          }
5830 #else  
5831          return RFAILED;
5832 #endif
5833    }
5834    return ROK;
5835 }
5836
5837 /* LTE_ADV_FLAG_REMOVED_START */
5838 /**
5839  * @brief This function resets temporary variables in Pool
5840  * @details
5841  *
5842  *     Function: rgSchSFRResetPoolVariables
5843  *
5844  *     Invoked by: rgSCHSFRUtlTotalPoolInit
5845  *
5846  *  @param[in]  RgSchCellCb*     cell
5847  *  @param[in]  RgSubFrm*     subFrm
5848  *  @return  Void
5849  *
5850  **/
5851 #ifdef ANSI
5852 Void rgSchDSFRPwrCheck
5853 (
5854  RgSchDlSf               *sf,
5855  Bool                    *isAllUePwrHigh
5856  )
5857 #else
5858 PRIVATE Void rgSchDSFRPwrCheck(sf, isAllUePwrHigh)
5859    RgSchDlSf               *sf;
5860    Bool                    *isAllUePwrHigh;
5861
5862 #endif
5863 {     
5864    RgSchSFRPoolInfo *sfrCCPool;
5865
5866    CmLListCp   *l;
5867    CmLList     *n;   
5868
5869    l = &sf->sfrTotalPoolInfo.ccPool;    
5870    n = cmLListFirst(l);
5871    while(n)
5872    {    
5873       sfrCCPool = (RgSchSFRPoolInfo*)n->node;
5874       if((sfrCCPool->poolstartRB == sfrCCPool->pwrHiCCRange.startRb) &&
5875             (sfrCCPool->poolendRB == sfrCCPool->pwrHiCCRange.endRb))
5876       {
5877          n = cmLListNext(l);
5878          if(n)
5879          {
5880             continue;
5881          }
5882          *isAllUePwrHigh = TRUE;
5883          break;
5884       }
5885       else
5886          break;   
5887    } 
5888 }
5889 /* LTE_ADV_FLAG_REMOVED_END */
5890 /***********************************************************
5891  *
5892  *     Func : rgSCHUtlFillRgInfTbInfo
5893  *
5894  *     Desc : Utility Function to fill the allocation info of each Tb
5895  *
5896  *
5897  *     Ret  :  RETVOID
5898  *
5899  *
5900  *     Notes: This function should be called while sending a msg from
5901  *     scheduler instance to MAC
5902  *
5903  *     File : rg_utl.c
5904  *
5905  **********************************************************/
5906 #ifdef ANSI
5907 PRIVATE Void rgSCHUtlFillRgInfTbInfo
5908 (
5909 RgSchDlHqProcCb *hqP,
5910 RgInfUeAlloc    *allocInfo,
5911 RgSchCellCb     *cell
5912 )
5913 #else
5914 PRIVATE Void rgSCHUtlFillRgInfTbInfo (hqP, allocInfo, cell)
5915 RgSchDlHqProcCb *hqP;
5916 RgInfUeAlloc    *allocInfo;
5917 RgSchCellCb     *cell;
5918 #endif
5919 {
5920    RgSchDlSf       *sf;
5921    U8              idx;
5922    RgInfUeTbInfo   *tbInfo;
5923    U8              tbCnt;
5924    /* LTE_ADV_FLAG_REMOVED_START */
5925 #ifdef TFU_UPGRADE
5926    PRIVATE         U32  tmpCnt = 0;
5927    Bool            isAllUePwrHigh = FALSE;
5928 #endif 
5929    /* LTE_ADV_FLAG_REMOVED_END */
5930    RgSchDlLcCb    *dlLcCb = NULLP;
5931    U16             rlcHdrEstmt;
5932    U8              lcId;
5933    /* RRM_RBC_X */
5934 #ifdef LTE_L2_MEAS
5935    U8              prbUsed = 0;
5936 #endif
5937    /* RRM_RBC_Y */
5938
5939    CmLteTimingInfo        frm;
5940
5941    /* Get Downlink slot */
5942    frm   = cell->crntTime;
5943    RGSCH_INCR_SUB_FRAME(frm, RG_SCH_CMN_DL_DELTA);
5944    sf = rgSCHUtlSubFrmGet(cell, frm);
5945    /* Setting of fillCtrlPdu flag
5946       If both P-cell and S-cell are present,
5947       make TRUE for P-cell and FALSE for all s-cells
5948       For all other cases set TRUE */
5949 #ifdef LTE_ADV
5950    if ((rgSchCb[cell->instIdx].genCfg.forceCntrlSrbBoOnPCel) &&
5951          !RG_SCH_CMN_IS_PCELL_HQP(hqP))
5952    {
5953       allocInfo->fillCtrlPdu = FALSE;
5954    }
5955    else
5956    {
5957       allocInfo->fillCtrlPdu = TRUE;
5958    }
5959 #endif
5960
5961    allocInfo->tbStrtIdx = -1;
5962
5963
5964 #ifdef LTE_ADV
5965    allocInfo->tbReqInfo.sCellHqPId = 0xff;
5966    rgSCHLaaHndlFillRgInfTbInfo(cell, hqP, allocInfo);
5967 #endif
5968
5969    /*TODO:REEMA: Check and fill the isRetx */
5970    for(tbCnt = 0; tbCnt < 2; tbCnt++)
5971    {
5972       RgSchUeCb  *ue = NULLP;
5973       /*Changed as a result of CR timer*/
5974       if ((hqP->hqE->ue != NULLP)/* &&
5975       ((hqP->tbInfo[tbCnt].lchSchdData[0].lcId != 0) || \
5976        (hqP->tbInfo[tbCnt].schdTa.pres == PRSNT_NODEF))*/)
5977       {
5978          ue = hqP->hqE->ue;
5979          allocInfo->rnti = ue->ueId;
5980          allocInfo->doa = hqP->hqE->ue->mimoInfo.doa;
5981          allocInfo->txMode = (TfuTxMode)(hqP->hqE->ue->mimoInfo.txMode);
5982          allocInfo->puschRptUsd = hqP->hqE->ue->mimoInfo.puschFdbkVld;
5983          allocInfo->puschPmiInfo = hqP->hqE->ue->mimoInfo.puschPmiInfo;
5984          if(hqP->tbInfo[tbCnt].schdTa.pres == PRSNT_NODEF)
5985          {
5986             hqP->tbInfo[tbCnt].taSnt = TRUE;
5987          }
5988 #ifdef TFU_UPGRADE
5989          if (RG_SCH_IS_PAPRSNT(ue,hqP->hqE->cell))
5990          {
5991             /*update pA value */
5992             allocInfo->pa = (RG_SCH_CMN_GET_PA(ue,hqP->hqE->cell)).val;
5993          }
5994 #endif
5995
5996          /* LTE_ADV_FLAG_REMOVED_START */
5997          /* If ABS is enabled, calculate resource used */
5998          if((0 == tbCnt) && (RGR_ENABLE == ue->cell->lteAdvCb.absCfg.status))
5999          {
6000             /* For Macro count number resource used in Non-ABS SF */
6001             if(RGR_ABS_MUTE == ue->cell->lteAdvCb.absCfg.absPatternType)
6002             {
6003                if(RG_SCH_ABS_ENABLED_NONABS_SF == ue->cell->lteAdvCb.absDlSfInfo)
6004                {
6005                   ue->cell->lteAdvCb.absLoadInfo[ue->cell->lteAdvCb.absPatternDlIdx]+=
6006                      hqP->tbInfo[tbCnt].dlGrnt.numRb;
6007                }
6008             }
6009             /* For pico count number resource used in ABS SF for ABS UE */
6010             else if(RGR_ABS_TRANSMIT == ue->cell->lteAdvCb.absCfg.absPatternType)
6011             {
6012                if(RG_SCH_ABS_ENABLED_ABS_SF == ue->cell->lteAdvCb.absDlSfInfo)
6013                {
6014                   if(TRUE == ue->lteAdvUeCb.rgrLteAdvUeCfg.isAbsUe)
6015                   {
6016                      ue->cell->lteAdvCb.absLoadInfo[ue->cell->lteAdvCb.absPatternDlIdx]+=
6017                         hqP->tbInfo[tbCnt].dlGrnt.numRb;
6018                   }
6019                }
6020             }
6021          } 
6022
6023 #ifdef TFU_UPGRADE         
6024          /*if SFR is enabled*/
6025          allocInfo->isEnbSFR = (U8)RG_SCH_CMN_IS_SFR_ENB(ue->cell); /* KW fix for LTE_ADV */
6026          if((ue->cell->lteAdvCb.dsfrCfg.status == RGR_ENABLE) && 
6027                (ue->lteAdvUeCb.rgrLteAdvUeCfg.isUeCellEdge == FALSE))
6028          {         
6029             rgSchDSFRPwrCheck(sf, &isAllUePwrHigh);          
6030          } 
6031          if(isAllUePwrHigh)
6032          {  
6033             allocInfo->pa = (U8)ue->cell->lteAdvCb.sfrCfg.pwrThreshold.pHigh;  /* KW fix for LTE_ADV */  
6034             if(tmpCnt++ == 100000)
6035             {
6036                RLOG_ARG2(L_DEBUG,DBG_CELLID,ue->cell->cellId, 
6037                         "DSFR::ll UEs can go HIGH, PHigh(%d) for UE(%d)",allocInfo->pa, ue->ueId);
6038                tmpCnt = 0;
6039             }
6040          }    
6041          else
6042          {  
6043             if (allocInfo->isEnbSFR)
6044             {
6045                /*Update pA to Plow if it is cell-centred ,else pA will be pHigh*/
6046                if (ue->lteAdvUeCb.rgrLteAdvUeCfg.isUeCellEdge == TRUE)
6047                {  
6048                   allocInfo->pa = ue->cell->lteAdvCb.sfrCfg.pwrThreshold.pHigh;
6049                   if(tmpCnt++ == 100000)
6050                   {
6051                      RLOG_ARG2(L_DEBUG,DBG_CELLID,ue->cell->cellId, 
6052                               "SFR::UE is CELL EDGE, PHigh(%d) for UE(%d)",allocInfo->pa, ue->ueId);
6053                      tmpCnt = 0;
6054                   }
6055
6056                }  
6057                else
6058                {
6059                   if(TRUE == ue->lteAdvUeCb.isCCUePHigh)
6060                   {
6061                      allocInfo->pa = ue->cell->lteAdvCb.sfrCfg.pwrThreshold.pHigh;
6062                      ue->lteAdvUeCb.isCCUePHigh = FALSE;
6063                   }
6064                   else
6065                   {
6066                      allocInfo->pa = ue->cell->lteAdvCb.sfrCfg.pwrThreshold.pLow;
6067                      if(tmpCnt++ == 100000)
6068                      {
6069                         RLOG_ARG2(L_DEBUG,DBG_CELLID,ue->cell->cellId, 
6070                                  "SFR::UE is CELL CENTRE, PLow(%d) for UE(%d)\n",allocInfo->pa, ue->ueId);
6071                         tmpCnt = 0;
6072                      }
6073                   }
6074                }
6075             }
6076          }
6077          /* LTE_ADV_FLAG_REMOVED_END */
6078 #endif         
6079       }
6080       else
6081       {
6082          if (hqP->hqE->raCb)
6083          {
6084 #ifdef TFU_UPGRADE
6085             RgSchCmnDlCell   *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
6086 #endif 
6087 #ifdef LTEMAC_SPS
6088             allocInfo->pdcchRnti = hqP->hqE->raCb->tmpCrnti;
6089 #endif
6090             allocInfo->rnti  =  hqP->hqE->raCb->tmpCrnti;
6091 #ifdef TFU_UPGRADE
6092             /*ccpu00132314-ADD-Use a default pA value
6093               for msg4 */
6094             allocInfo->pa = cellDl->msg4pAVal; 
6095 #endif 
6096          }
6097       }
6098       /* If TB Is scheduled for this SF */
6099       if(hqP->tbInfo[tbCnt].state == HQ_TB_WAITING)
6100       {
6101          if (allocInfo->tbStrtIdx == -1){
6102             allocInfo->tbStrtIdx = tbCnt;
6103 #ifndef LTEMAC_SPS
6104             rgSCHUtlFillPdschDciInfo(&(allocInfo->dciInfo),
6105                                &(hqP->pdcch->dci));
6106 #else
6107             if (hqP->pdcch)
6108             {
6109                rgSCHUtlFillPdschDciInfo(&(allocInfo->dciInfo),
6110                      &(hqP->pdcch->dci));
6111             }
6112             else if ((ue) && (ue->dl.spsOccPdcch.rnti == ue->spsRnti))
6113             {
6114                rgSCHUtlFillPdschDciInfo(&(allocInfo->dciInfo),
6115                      &(ue->dl.spsOccPdcch.dci));
6116             }
6117 #endif /* ifndef LTEMAC_SPS */
6118          }
6119 #ifdef LTEMAC_SPS
6120             if (hqP->pdcch)
6121             {
6122                allocInfo->pdcchRnti = hqP->pdcch->rnti;
6123             }
6124             else if (ue)
6125             {
6126                allocInfo->pdcchRnti = ue->spsRnti;
6127             }
6128 #endif
6129          tbInfo = &(allocInfo->tbInfo[tbCnt]);
6130          allocInfo->nmbOfTBs++;
6131          allocInfo->hqProcId = hqP->procId;
6132          allocInfo->tbInfo[tbCnt].schdTbSz = hqP->tbInfo[tbCnt].tbSz;
6133
6134          tbInfo->disTb  = FALSE;
6135          if(!(hqP->tbInfo[tbCnt].txCntr))
6136          {
6137 #ifdef LTE_ADV
6138             if(!((rgSCHLaaCheckIfLAAProc(hqP)) && (TRUE ==
6139                         rgSCHLaaSCellEnabled(cell))))
6140 #endif
6141             {
6142                hqP->tbInfo[tbCnt].txCntr++;
6143             }
6144             for(idx = 0; idx < hqP->tbInfo[tbCnt].numLch; idx++)
6145             {
6146                tbInfo->schdDat[idx].lcId =\
6147                   hqP->tbInfo[tbCnt].lchSchdData[idx].lcId;
6148                tbInfo->schdDat[idx].numBytes =\
6149                   hqP->tbInfo[tbCnt].lchSchdData[idx].schdData;
6150                if(hqP->hqE->ue)
6151                {
6152                   lcId = hqP->tbInfo[tbCnt].lchSchdData[idx].lcId; 
6153                   if(lcId != 0)
6154                   {
6155                      dlLcCb = hqP->hqE->ue->dl.lcCb[lcId-1];
6156                      if(dlLcCb != NULLP)
6157                      {
6158                         RG_SCH_CMN_DL_GET_HDR_EST(dlLcCb, rlcHdrEstmt);
6159                         /* Update the totalBo with the scheduled bo */
6160                         (hqP->hqE->ue->totalBo <= tbInfo->schdDat[idx].numBytes - rlcHdrEstmt)?\
6161                                                   (hqP->hqE->ue->totalBo = 0):\
6162                                                   (hqP->hqE->ue->totalBo -= tbInfo->schdDat[idx].numBytes-rlcHdrEstmt);
6163
6164                         /* RRM_RBC_X */
6165 #ifdef LTE_L2_MEAS
6166                         prbUsed = ((hqP->tbInfo[tbCnt].\
6167                                  lchSchdData[idx].schdData  *
6168                                  hqP->tbInfo[tbCnt].dlGrnt.numRb) /
6169                               (hqP->tbInfo[0].tbSz + hqP->tbInfo[1].tbSz));
6170                         dlLcCb->qciCb->dlPrbCount += prbUsed;
6171                         if(dlLcCb->qciCb->qci > 0)
6172                         {
6173                            RG_SCH_CALC_GBR_UTILIZATION(cell, dlLcCb, prbUsed);
6174                         }
6175 #endif                        /* RRM_RBC_Y */
6176
6177 #ifdef RG_PFS_STATS
6178                         //if(!(hqP->hqE->ue->pfsStats.lcStats[lcId-1].isLcCntSet))
6179                         if(tbCnt == 0)
6180                         {
6181                            U8 idx = 0;
6182                            if (hqP->hqE->ue->cell == hqP->hqE->cell)
6183                            {
6184                               idx = RGSCH_PCELL_INDEX;
6185                            }
6186                            else
6187                            {
6188                               idx = RG_SCH_GET_SCELL_INDEX((hqP->hqE->ue), (hqP->hqE->cell));
6189                            }
6190                            hqP->hqE->ue->pfsStats.lcStats[lcId-1].ueSchdOcc[idx]++;
6191                            hqP->hqE->ue->pfsStats.lcStats[lcId-1].perRefresh[ue->pfsStats.lcStats[lcId-1].lastIdx].lcSchdOcc++;
6192                         }   
6193 #endif
6194                      }
6195                   }
6196                }
6197             }
6198             /* Added Dl TB count for SRB/DRB data transmission*/
6199 #ifdef LTE_L2_MEAS 
6200             cell->dlUlTbCnt.tbTransDlTotalCnt++;  
6201 #endif            
6202             tbInfo->ta.pres = hqP->tbInfo[tbCnt].schdTa.pres;
6203             tbInfo->ta.val =  hqP->tbInfo[tbCnt].schdTa.val;
6204 #ifdef LTE_ADV
6205             tbInfo->sCellActCe = hqP->tbInfo[tbCnt].schdSCellActCe;
6206 #endif
6207             tbInfo->numSchLch = hqP->tbInfo[tbCnt].numLch;
6208             if(!(hqP->tbInfo[tbCnt].numLch))
6209             {
6210                tbInfo->schdDat[tbInfo->numSchLch].numBytes= hqP->tbInfo[tbCnt].tbSz;
6211                /* Fix: If only TA is scheduled, use some dummy LCID */
6212                if (tbInfo->ta.pres)
6213                   tbInfo->schdDat[tbInfo->numSchLch].lcId = RG_TA_LCID;
6214             }
6215
6216             tbInfo->contResCe = hqP->tbInfo[tbCnt].contResCe;
6217             tbInfo->isReTx = FALSE;
6218          }
6219          else
6220          {
6221 #ifdef LTE_ADV
6222             if(!((rgSCHLaaCheckIfLAAProc(hqP)) && (TRUE ==
6223                         rgSCHLaaSCellEnabled(cell))))
6224 #endif
6225             {
6226                hqP->tbInfo[tbCnt].txCntr++;
6227             }
6228             tbInfo->isReTx = TRUE;
6229             /* RRM_RBC_X */
6230             /* As per 36.314, harq retransmission also considered for 
6231              * prb utilization calculation*/
6232             for(idx = 0; idx < hqP->tbInfo[tbCnt].numLch; idx++)
6233             {
6234 #ifdef LTE_L2_MEAS
6235                if(hqP->hqE->ue)
6236                {
6237                   lcId = hqP->tbInfo[tbCnt].lchSchdData[idx].lcId; 
6238                   if(lcId != 0)
6239                   {
6240                      dlLcCb = hqP->hqE->ue->dl.lcCb[lcId-1];
6241                      if(dlLcCb != NULLP)
6242                      {
6243                         prbUsed = ((hqP->tbInfo[tbCnt].\
6244                                lchSchdData[idx].schdData  *
6245                                hqP->tbInfo[tbCnt].dlGrnt.numRb) /
6246                                   (hqP->tbInfo[0].tbSz + hqP->tbInfo[1].tbSz));
6247                         if(dlLcCb->qciCb->qci > 0)
6248                         {
6249                            RG_SCH_CALC_GBR_UTILIZATION(cell, dlLcCb, prbUsed);
6250                         }
6251                      }
6252                   }
6253                }
6254 #endif
6255             }
6256             /* RRM_RBC_Y */
6257          }
6258       }
6259     }
6260 #ifdef LTE_ADV 
6261    rgSCHLaaResetDlHqProcCb(hqP);
6262 #endif
6263
6264    RETVOID;
6265 }
6266 /***********************************************************
6267  *
6268  *     Func : rgSCHUtlFillRgInfUeInfo
6269  *
6270  *     Desc : Utility Function to fill the allocation info of Ue
6271  *             : MIMO : Filling 2TB's of each UE
6272  *
6273  *     Ret  : ROK
6274  *            RFAILED
6275  *
6276  *     Notes: This function should be called while sending a msg from
6277  *     scheduler instance to MAC
6278  *
6279  *     File : rg_utl.c
6280  *
6281  **********************************************************/
6282   /* CA dev Start */
6283 #ifdef ANSI
6284 Void rgSCHUtlFillRgInfUeInfo
6285 (
6286 RgSchDlSf       *sf,
6287 RgSchCellCb     *cell,
6288 CmLListCp       *dlDrxInactvTmrLst,
6289 CmLListCp       *dlInActvLst,
6290 CmLListCp       *ulInActvLst
6291 )
6292 #else
6293 Void rgSCHUtlFillRgInfUeInfo (sf,cell, dlDrxInactvTmrLst, dlInActvLst, ulInActvLst)
6294 {
6295 RgSchDlSf       *sf;
6296 RgSchCellCb     *cell;
6297 CmLListCp       *dlDrxInactvTmrLst;
6298 CmLListCp       *dlInActvLst;
6299 CmLListCp       *ulInActvLst;
6300 #endif
6301 {
6302    RgInfSfAlloc    *sfAlloc;
6303    CmLListCp       *lnkLst;   /* lnkLst assignment */
6304    CmLList         *tmp;
6305    CmLList         *hqPNode;
6306    RgSchUeCb       *ue = NULLP;
6307    RgInfUeInfo     *ueInfo = NULLP;
6308    RgInfUeAlloc    *ueAlloc = NULLP;
6309    RgSchDlHqProcCb *hqCb = NULLP;
6310
6311    /* Since Msg4 is sched only on PCELL, use cell arg's sfAllocArr */
6312    sfAlloc = &(cell->sfAllocArr[cell->crntSfIdx]);
6313    ueInfo = &(sfAlloc->ueInfo);
6314    ueAlloc = sfAlloc->ueInfo.allocInfo;
6315
6316    lnkLst = &(sf->msg4HqPLst);
6317    CM_LLIST_FIRST_NODE(lnkLst, tmp);
6318    while(NULLP != tmp)
6319    {
6320       printf("5GTF_ERROR MSG4 Consolidation\n");
6321       hqCb = (RgSchDlHqProcCb *)(tmp->node);
6322       CM_LLIST_NEXT_NODE(lnkLst, tmp);
6323
6324       rgSCHUtlFillRgInfTbInfo(hqCb, &ueAlloc[ueInfo->numUes], cell);
6325
6326       ue = hqCb->hqE->ue;
6327
6328       if(ue != NULLP)
6329       {   
6330          if((!(ue->dl.dlInactvMask & RG_HQENT_INACTIVE)) && (ue->isDrxEnabled))
6331          {   
6332             rgSCHUtlGetDrxSchdUesInDl(cell, ue, hqCb, &ueAlloc[ueInfo->numUes], 
6333                   dlDrxInactvTmrLst, dlInActvLst, ulInActvLst);
6334          }
6335       }
6336       ueInfo->numUes++;
6337    }
6338  
6339    lnkLst = &(sf->ueLst);
6340    CM_LLIST_FIRST_NODE(lnkLst, tmp);
6341    while(NULLP != tmp)
6342    {
6343 #if defined (TENB_STATS) && defined (RG_5GTF)
6344       cell->tenbStats->sch.dl5gtfPdschCons++;
6345 #endif
6346       ue = (RgSchUeCb *)(tmp->node);
6347       CM_LLIST_NEXT_NODE(lnkLst, tmp);
6348
6349       hqPNode = ue->dl.dlSfHqInfo[cell->cellId][sf->dlIdx].hqPLst.first;
6350       while (hqPNode)
6351       {
6352          hqCb = (RgSchDlHqProcCb *)hqPNode->node;
6353          hqPNode = hqPNode->next;
6354
6355          sfAlloc = &(hqCb->hqE->cell->sfAllocArr[hqCb->hqE->cell->crntSfIdx]);
6356          ueInfo = &(sfAlloc->ueInfo);
6357          ueAlloc = sfAlloc->ueInfo.allocInfo;
6358
6359          rgSCHUtlFillRgInfTbInfo(hqCb, &ueAlloc[ueInfo->numUes], 
6360                hqCb->hqE->cell);
6361
6362          if(ue->isDrxEnabled)
6363          {   
6364             rgSCHUtlGetDrxSchdUesInDl(cell, ue, hqCb, &ueAlloc[ueInfo->numUes], 
6365                   dlDrxInactvTmrLst, dlInActvLst, ulInActvLst);
6366          }
6367          ueInfo->numUes++;
6368       }
6369 #ifdef LTE_ADV
6370       if (rgSchCb[cell->instIdx].genCfg.isSCellActDeactAlgoEnable == TRUE)
6371       {
6372          /*If remaining BO is left then increment the count*/
6373          if(ue->totalBo > 0)
6374          {
6375             ue->remBoCnt++;
6376             /* Check if trigger for Activation is met or not */
6377             if(rgSCHIsActvReqd(cell, ue))
6378             {
6379                ue->remBoCnt = 0;
6380                /*Passing primary cell*/
6381                rgSCHSCellSelectAndActDeAct(ue->cell, ue, RGR_SCELL_ACT);
6382             }
6383          }
6384          else
6385          {
6386             /*If remaining BO is 0 then reset the count*/
6387             ue->remBoCnt = 0;
6388          }
6389       }
6390 #endif
6391    }
6392   
6393    RETVOID;
6394 } /* end of rgSCHUtlFillRgInfUeInfo */
6395   /* CA dev End */
6396
6397
6398 /** @brief This function  shall update the scheduler with the CEs and data rcvd
6399  *
6400  * @details
6401  *
6402  *     Function: rgSCHUtlUpdSch
6403  *
6404  *         Processing steps:
6405  *         - Collate the information of all the SDUs received and inform the
6406  *         scheduler rgSCHDataRcvd
6407  *         - Send Data indication to the higher layer with the dedicated data
6408  *         (rgUIMSndDedDatInd)
6409  *         - Inform scheduler with any MAC CEs if present.
6410  *
6411  * @param  [in] RgCellCb   *cellCb
6412  * @param  [in] RgUeCb     *ueCb
6413  * @param  [in] RgMacPdu   *pdu
6414  * @param  [in] RgSchErrInfo  *err
6415  *  @return  S16
6416  *      -# ROK
6417  *      -# RFAILED
6418  */
6419 #ifdef ANSI
6420 S16 rgSCHUtlUpdSch
6421 (
6422 RgInfSfDatInd    *subfrmInfo,
6423 RgSchCellCb      *cellCb,
6424 RgSchUeCb        *ueCb,
6425 RgInfUeDatInd    *pdu,
6426 RgSchErrInfo     *err
6427 )
6428 #else
6429 S16 rgSCHUtlUpdSch (subfrmInfo, cellCb, ueCb, pdu, err)
6430 RgInfSfDatInd    *subfrmInfo;
6431 RgSchCellCb      *cellCb;
6432 RgSchUeCb        *ueCb;
6433 RgInfUeDatInd    *pdu;
6434 RgSchErrInfo     *err;
6435 #endif
6436 {
6437
6438    S16               ret;
6439
6440 #ifdef LTEMAC_SPS
6441    if (RGSCH_UL_SPS_ACT_PRSENT & pdu->ceInfo.bitMask)
6442    {
6443       /* SPS to be activated due to data on SPS LCG ID*/
6444       rgSCHUtlSpsActInd(cellCb, ueCb, pdu->ceInfo.spsSduSize);
6445    }
6446 #endif
6447    /* TODO : Temp Fix for crash due to UL SDU corruption*/
6448    if (RGSCH_PHR_CE_PRSNT & pdu->ceInfo.bitMask)
6449    {
6450       /* PHR present */
6451       RGSCHCPYTIMEINFO(subfrmInfo->timingInfo, ueCb->macCeRptTime);
6452       if ((ret = rgSCHUtlUpdPhr(cellCb, ueCb, pdu->ceInfo.ces.phr, err)) != ROK)
6453          return (ret);
6454    }
6455    /* Note: Order of indication to Sch now is
6456     *       1st Indicate the DataInd info for each LCG's
6457     *       2nd Update the BSR reports received along with data
6458     *       this is to make sure the effBsr is updated to the latest BSR 
6459     *       received.
6460     */
6461    cellCb->sc.apis->rgSCHUpdUeDataIndLcg(cellCb, ueCb, pdu);
6462
6463 #ifndef MAC_5GTF_UPDATE
6464    if (RGSCH_TRUNC_BSR_CE_PRSNT & pdu->ceInfo.bitMask)
6465    {
6466       RGSCHCPYTIMEINFO(subfrmInfo->timingInfo, ueCb->macCeRptTime);
6467       /*ccpu00129922 - MOD - Deleted return value
6468        * checking since it returns void*/
6469       rgSCHUtlUpdBsrTrunc (cellCb, ueCb,
6470                   (U8)(pdu->ceInfo.ces.bsr.truncBsr >> 6),
6471                   (U8)(pdu->ceInfo.ces.bsr.truncBsr & 0x3F), err); 
6472    }
6473    else
6474    {
6475       if (RGSCH_SHORT_BSR_CE_PRSNT & pdu->ceInfo.bitMask)
6476       {
6477          RGSCHCPYTIMEINFO(subfrmInfo->timingInfo, ueCb->macCeRptTime);
6478          /*ccpu00129922 - MOD - Deleted return value
6479           checking since it returns void*/
6480          rgSCHUtlUpdBsrShort (cellCb, ueCb,
6481                      (U8)(pdu->ceInfo.ces.bsr.shortBsr >> 6),
6482                      (U8)(pdu->ceInfo.ces.bsr.shortBsr & 0x3F), err);
6483       }
6484       else
6485       {
6486          if (RGSCH_LONG_BSR_CE_PRSNT & pdu->ceInfo.bitMask)
6487 #else
6488          if (RGSCH_BSR_CE_PRSNT & pdu->ceInfo.bitMask)
6489 #endif
6490          {
6491             RGSCHCPYTIMEINFO(subfrmInfo->timingInfo, ueCb->macCeRptTime);
6492             /*ccpu00129922 - MOD - Deleted return value
6493               checking since it returns void*/
6494             rgSCHUtlUpdBsrLong (cellCb, ueCb,
6495                         pdu->ceInfo.ces.bsr.longBsr.bs1,
6496                         pdu->ceInfo.ces.bsr.longBsr.bs2,
6497                         pdu->ceInfo.ces.bsr.longBsr.bs3,
6498                         pdu->ceInfo.ces.bsr.longBsr.bs4,
6499                         err);
6500          }
6501 #ifndef MAC_5GTF_UPDATE
6502       }
6503  
6504    }
6505 #endif
6506             
6507    return ROK;
6508 } /* end of rgSCHUtlUpdSch */
6509 #ifdef RGR_V1
6510 /**
6511  * @brief Handler for Updating Bo received in StaRsp
6512  *
6513  * @details
6514  *
6515  *     Function : rgSCHUtlAddUeToCcchSduLst
6516  *
6517  *     This function shall be invoked once it receives staRsp on CCCH
6518  *
6519  *  @param[in]     RgSchCellCb       *cell
6520  *  @param[in]     RgSchUeCb       *ueCb
6521  *  @return  S16
6522  *      -# ROK
6523  **/
6524 #ifdef ANSI
6525 S16 rgSCHUtlAddUeToCcchSduLst
6526 (
6527 RgSchCellCb       *cell,
6528 RgSchUeCb         *ueCb
6529 )
6530 #else
6531 S16 rgSCHUtlAddUeToCcchSduLst(cell, ueCb)
6532 RgSchCellCb       *cell;
6533 RgSchUeCb         *ueCb;
6534 #endif
6535 {
6536    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ueCb, cell);
6537    RgSchDlHqProcCb *hqP  = (RgSchDlHqProcCb *)ueDl->proc;
6538
6539    /* Temp Guard: For back to back CCCH SDU BO 
6540     * twice. Hence an extra guard. If already added to scheduling
6541     * queue or if scheduled and waiting for HQ FDBK, ignore */
6542    if ((ueCb->ccchSduLnk.node) ||
6543        ((!(ueCb->dl.dlInactvMask & RG_HQENT_INACTIVE)) &&
6544        ((hqP != NULLP) && (hqP->hqE->ccchSduProc))))
6545    {
6546       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"RNTI:%d Unexpected CCCH SDU BO",
6547          ueCb->ueId);
6548       return ROK;
6549    }
6550
6551    ueCb->ccchSduLnk.node = (PTR)(ueCb);
6552    cmLListAdd2Tail(&(cell->ccchSduUeLst), &(ueCb->ccchSduLnk));
6553
6554    return ROK;
6555 }
6556 /**
6557  *
6558  * @details
6559  *
6560  *     Function : rgSCHUtlUpdtBo
6561  *
6562  *     This function shall be invoked once it receives staRsp on CCCH
6563  *
6564  *  @param[in]     RgSchCellCb       *cell
6565  *  @param[in]     RgRguCmnStaRsp *staRsp
6566  *  @return  S16
6567  *      -# ROK
6568  **/
6569 #ifdef ANSI
6570 S16 rgSCHUtlUpdtBo
6571 (
6572 RgSchCellCb       *cell,
6573 RgInfCmnBoRpt     *staRsp
6574 )
6575 #else
6576 S16 rgSCHUtlUpdtBo(cell, staRsp)
6577 RgSchCellCb       *cell;
6578 RgInfCmnBoRpt     *staRsp;
6579 #endif
6580 {
6581    RgSchUeCb *ueCb;
6582
6583    if ((ueCb = rgSCHDbmGetUeCb(cell, staRsp->u.rnti)) == NULLP)
6584    {
6585       /* Handle Ue fetch failure */
6586       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Invalid UEID:%d",staRsp->u.rnti);
6587       return RFAILED;
6588    }
6589    /* Update Bo in ueCb */
6590    ueCb->dlCcchInfo.bo = (U32)(staRsp->bo);
6591 #ifdef EMTC_ENABLE
6592      if(ueCb->isEmtcUe)
6593      {
6594         rgSCHUtlAddUeToEmtcCcchSduLst(cell,ueCb);
6595      }
6596      else
6597 #endif
6598     {
6599       rgSCHUtlAddUeToCcchSduLst(cell, ueCb);
6600     }
6601
6602    return ROK;
6603 } /* rgSCHUtlUpdtBo */
6604
6605 #endif
6606 /**
6607  *
6608  * @details
6609  *     Function : rgSCHUtlHndlCcchBoUpdt
6610  *
6611  *     This function shall fetch the raCb with the given rnti and ask RAM to
6612  *     update BO
6613  *
6614  *
6615  *  @param[in]  RgSchCellCb    *cell
6616  *  @param[in]  RgInfCmnBoRpt *boRpt
6617  *  @return  S16
6618  *      -# ROK
6619  *      -# RFAILED
6620  **/
6621 #ifdef ANSI
6622 S16 rgSCHUtlHndlCcchBoUpdt
6623 (
6624 RgSchCellCb    *cell,
6625 RgInfCmnBoRpt  *boRpt
6626 )
6627 #else
6628 S16 rgSCHUtlHndlCcchBoUpdt(cell, boRpt)
6629 RgSchCellCb    *cell;
6630 RgInfCmnBoRpt  *boRpt;
6631 #endif
6632 {
6633    RgSchRaCb       *raCb;
6634    RgSchUeCb *ueCb;
6635
6636    if ((raCb = rgSCHDbmGetRaCb(cell, boRpt->u.rnti)) == NULLP)
6637    {
6638 #ifdef RGR_V1
6639    /* CR timer implementation changes*/
6640       /*If no raCb, schedule ueCb, ueCb is extracted in rgSCHUtlUpdtBo*/
6641       return (rgSCHUtlUpdtBo(cell, boRpt));
6642 #else
6643       /* Handle RaCb fetch failure */
6644       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
6645                       "Invalid RNTI:%d to fetch raCb",boRpt->u.rnti);
6646       return RFAILED;
6647 #endif
6648    }
6649
6650 #ifdef RGR_V1
6651
6652       /*Fix: If RaCb exists, then MSG4 is not completed yet*/
6653       /*Check if guard timer has expired, if not CR CE + CCCH SDU will be scheduled*/
6654       if((raCb->contResTmrLnk.node != NULLP) && \
6655             (raCb->schdLnk.node == NULLP) && (raCb->dlHqE->msg4Proc == NULLP))
6656       {
6657 #ifdef EMTC_ENABLE
6658          /*if contention resolution timer left ,Stop the Contention Resolution Guard Timer ,
6659          add in toBeSchduled list and update the Bo */
6660          if(TRUE == raCb->isEmtcRaCb)
6661          {
6662             rgSCHRamEmtcUpdtBo(cell, raCb, boRpt);
6663          }
6664          else
6665 #endif
6666          {
6667             cmLListDelFrm(&cell->contResGrdTmrLst, &(raCb->contResTmrLnk));
6668             raCb->contResTmrLnk.node=NULLP;               
6669             rgSCHRamUpdtBo(cell, raCb, boRpt);
6670          }
6671        }
6672       else
6673       {
6674          /*Fix:Guard timer has expired */
6675          /*Update the BO in UE CB but dont add it to the scheduling list. 
6676           *Should be added to the list after MSG4 completion*/
6677          if ((ueCb = rgSCHDbmGetUeCb(cell, boRpt->u.rnti)) == NULLP)
6678          {
6679             /* Handle Ue fetch failure */
6680             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Invalid RNTI:%d",boRpt->u.rnti);
6681             return RFAILED;
6682          }
6683          /* Update Bo in ueCb */
6684          ueCb->dlCcchInfo.bo = (U32)(boRpt->bo);     
6685       }
6686
6687 #else
6688       rgSCHRamUpdtBo(cell, raCb, boRpt);
6689 #endif
6690
6691    return ROK;
6692 } /* rgSCHUtlHndlCcchBoUpdt */
6693
6694 /**
6695  * @brief Validates BO received for BCCH or PCCH.
6696  *
6697  * @details
6698  *
6699  *     Function : rgSCHUtlGetAllwdCchTbSz
6700  *
6701  *     This function shall return the tbSz equal to or
6702  *     the nearest greater value for a given bo.
6703  *     If no such value found return -1. The nPrb value is
6704  *     accordingly set.
6705  *
6706  *
6707  *  @param[in]  U32            bo
6708  *  @param[out] U8             *nPrb
6709  *  @return  S32
6710  *      -# ROK
6711  *      -# RFAILED
6712  **/
6713 #ifdef ANSI
6714 S32 rgSCHUtlGetAllwdCchTbSz
6715 (
6716 U32 bo,
6717 U8  *nPrb,
6718 U8  *mcs
6719 )
6720 #else
6721 S32 rgSCHUtlGetAllwdCchTbSz(bo, nPrb, mcs)
6722 U32 bo;
6723 U8  *nPrb;
6724 U8  *mcs;
6725 #endif
6726 {
6727    S32 lt;
6728    S32 cn;
6729    S32 rt;
6730
6731    for (lt = 0, rt = 43; lt <= rt;)
6732    {
6733       cn = (lt + rt)/2;
6734       if (rgSchUtlBcchPcchTbSzTbl[cn].tbSz == bo)
6735       {
6736          *nPrb = rgSchUtlBcchPcchTbSzTbl[cn].rbIndex;
6737          *mcs  = rgSchUtlBcchPcchTbSzTbl[cn].mcs;
6738          return (rgSchUtlBcchPcchTbSzTbl[cn].tbSz);
6739       }
6740       else if (rgSchUtlBcchPcchTbSzTbl[cn].tbSz < bo)
6741          lt = cn + 1;
6742       else
6743          rt = cn - 1;
6744    }
6745    if (lt == 44)
6746    {
6747       return RFAILED;
6748    }
6749    *nPrb = rgSchUtlBcchPcchTbSzTbl[lt].rbIndex;
6750    *mcs  = rgSchUtlBcchPcchTbSzTbl[lt].mcs;
6751    return (rgSchUtlBcchPcchTbSzTbl[lt].tbSz);
6752 }
6753
6754 /**
6755  * @brief Handler for BO Updt received for BCCH or PCCH.
6756  *
6757  * @details
6758  *
6759  *     Function : rgSCHUtlHndlBcchPcchBoUpdt
6760  *
6761  *     This function shall store the buffer and time to transmit in lcCb
6762  *
6763  *
6764  *  @param[in]  RgSchCellCb    *cell
6765  *  @param[in]  RgInfCmnBoRpt  *boRpt
6766  *  @return  S16
6767  *      -# ROK
6768  *      -# RFAILED
6769  **/
6770 #ifdef ANSI
6771 S16 rgSCHUtlHndlBcchPcchBoUpdt
6772 (
6773 RgSchCellCb    *cell,
6774 RgInfCmnBoRpt  *boUpdt
6775 )
6776 #else
6777 S16 rgSCHUtlHndlBcchPcchBoUpdt(cell, boUpdt)
6778 RgSchCellCb    *cell;
6779 RgInfCmnBoRpt  *boUpdt;
6780 #endif
6781 {
6782    RgSchClcDlLcCb *dlLc;
6783    RgSchClcBoRpt  *boRpt;
6784    Inst           inst = cell->instIdx;
6785    U8             nPrb=0;
6786    U8             mcs=0;
6787
6788    dlLc = rgSCHDbmGetBcchOnBch(cell);
6789    if (dlLc == NULLP)
6790    {
6791       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,
6792       "No Logical Channel dlLc is NULLP for RNTI:%d LCID:%d",boUpdt->u.rnti,boUpdt->lcId);
6793       return RFAILED;
6794    }
6795    if (boUpdt->lcId != dlLc->lcId)
6796    {
6797       /* Added for dropping paging Message*/      
6798           /*suman*/
6799       if ((rgSCHChkBoUpdate(cell,boUpdt))== ROK)  /* Checking if received BO falls within the window of 5120 slots*/
6800       {
6801          if (rgSCHUtlGetAllwdCchTbSz(boUpdt->bo*8, &nPrb, &mcs) 
6802                != (boUpdt->bo*8))
6803          {
6804             RLOG_ARG3(L_ERROR,DBG_CELLID,cell->cellId,"[%ld]BO: does not match any "
6805                   "valid TB Size RNTI:%d LCID:%d", boUpdt->bo,boUpdt->u.rnti,boUpdt->lcId);
6806             return RFAILED;
6807          }
6808       }/*end of rgSCHChkBoUpdate*/
6809       else
6810       {
6811           return ROK;
6812       } 
6813    }
6814    if ((dlLc = rgSCHDbmGetCmnLcCb(cell, boUpdt->lcId)) == NULLP)
6815    {
6816       /* Handle lcCb fetch failure */
6817       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,
6818                       "LCID:%d Invalid for RNTI:%d",boUpdt->lcId,boUpdt->u.rnti);
6819    }
6820
6821    if (((rgSCHUtlAllocSBuf(inst, (Data **)(&boRpt), sizeof(RgSchClcBoRpt))) ==RFAILED) ||
6822        (!boRpt))
6823    {
6824       RLOG_ARG3(L_ERROR,DBG_CELLID,cell->cellId, "Allocation of common bo %dreport "
6825          "failed  RNTI:%d LCID:%d", boUpdt->bo,boUpdt->u.rnti,boUpdt->lcId);
6826       return RFAILED;
6827    }
6828
6829    boRpt->bo = boUpdt->bo;
6830    boRpt->mcs = mcs;
6831    boRpt->timeToTx = boUpdt->u.timeToTx;
6832    boRpt->nPrb = nPrb;
6833 #ifdef EMTC_ENABLE
6834    if(cell->emtcEnable)
6835    {
6836       boRpt->emtcDIReason = boUpdt->emtcDIReason;
6837       boRpt->pnb = boUpdt->pnb;
6838    }
6839 #endif
6840    RG_SCH_ADD_TO_CRNT_TIME(boRpt->timeToTx, 
6841          boRpt->maxTimeToTx, cell->siCfg.siWinSize)
6842    if((NULLP != dlLc) && (dlLc->si))
6843    {
6844       boRpt->retxCnt = cell->siCfg.retxCnt;
6845    }
6846    else
6847    {
6848       boRpt->retxCnt = 0;
6849    }
6850    rgSCHDbmInsCmnLcBoRpt(dlLc, boRpt);
6851
6852    return ROK;
6853 } /* rgSCHUtlHndlBcchPcchBoUpdt */
6854
6855 /**
6856  * @brief API for sending bind confirm from Scheduler instance to RRM
6857  *
6858  * @details
6859  *
6860  *     Function: rgSCHUtlRgrBndCfm
6861  *
6862  *     This API is invoked to send bind confirm from Scheduler instance to RRM.
6863  *     This API fills in Pst structure and SAP Ids and invokes
6864  *     bind confirm API towards RRM.
6865  *
6866  *  @param[in]  SuId          suId
6867  *  @param[in]  U8            status
6868  *  @return  S16
6869  *      -# ROK
6870  *      -# RFAILED
6871  **/
6872 #ifdef ANSI
6873 S16 rgSCHUtlRgrBndCfm
6874 (
6875 Inst          instId,
6876 SuId          suId,
6877 U8            status
6878 )
6879 #else
6880 S16 rgSCHUtlRgrBndCfm(instId, suId, status)
6881 Inst          instId;
6882 SuId          suId;
6883 U8            status;
6884 #endif
6885 {
6886    S16  ret = ROK;
6887
6888    ret = RgUiRgrBndCfm(&rgSchCb[instId].rgrSap[suId].sapCfg.sapPst, rgSchCb[instId].rgrSap[suId].sapCfg.suId, status);
6889    if (ret != ROK)
6890    {
6891       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,"rgSCHUtlRgrBndCfm: RgUiRgrBndCfm Failed ");
6892       return (ret);
6893    }
6894    return (ret);
6895 }  /* rgSCHUtlRgrBndCfm*/
6896
6897 /**
6898  * @brief API for sending bind confirm from Scheduler instance to RRM via RGM
6899  *        interface
6900  *
6901  * @details
6902  *
6903  *     Function: rgSCHUtlRgmBndCfm
6904  *
6905  *     This API is invoked to send bind confirm from Scheduler instance to RRM.
6906  *     This API fills in Pst structure and SAP Ids and invokes
6907  *
6908  *  @param[in]  SuId          suId
6909  *  @param[in]  U8            status
6910  *  @return  S16
6911  *      -# ROK
6912  *      -# RFAILED
6913  **/
6914 #ifdef ANSI
6915 S16 rgSCHUtlRgmBndCfm
6916 (
6917 Inst          instId,
6918 SuId          suId,
6919 U8            status
6920 )
6921 #else
6922 S16 rgSCHUtlRgmBndCfm(instId, suId, status)
6923 Inst          instId;
6924 SuId          suId;
6925 U8            status;
6926 #endif
6927 {
6928    S16  ret = ROK;
6929
6930    ret = RgUiRgmBndCfm(&rgSchCb[instId].rgmSap[suId].sapCfg.sapPst, rgSchCb[instId].rgmSap[suId].sapCfg.suId, status);
6931    if (ret != ROK)
6932    {
6933       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,"rgSCHUtlRgmBndCfm: RgUiRgrBndCfm Failed ");
6934       return (ret);
6935    }
6936    return (ret);
6937 }  /* rgSCHUtlRgmBndCfm*/
6938
6939
6940
6941 /**
6942  * @brief API for sending configuration confirm from Scheduler to DU APP
6943  *
6944  * @details
6945  *
6946  *     Function: schSendCfgCfm 
6947  *
6948  *     This API is invoked to send configuration confirm from Scheduler to DU
6949  *     APP.
6950  *
6951  *  @param[in]  Pst           pst 
6952  *  @param[in]  RgrCfgTransId transId
6953  *  @param[in]  U8            status
6954  *  @return  S16
6955  *      -# ROK
6956  *      -# RFAILED
6957  **/
6958 #ifdef ANSI
6959 S16 schSendCfgCfm
6960 (
6961 Region        reg,
6962 Pool          pool,
6963 RgrCfgTransId transId,
6964 U8            status
6965 )
6966 #else
6967 S16 schSendCfgCfm(reg, pool, transId, status)
6968 Region        reg;
6969 Pool          pool;
6970 RgrCfgTransId transId;
6971 U8            status;
6972 #endif
6973 {
6974    Pst cfmPst;
6975    Inst inst = 0;
6976
6977    memset((&cfmPst), 0, sizeof(Pst));
6978
6979    cfmPst.srcEnt    = (Ent)ENTDUAPP;
6980    cfmPst.srcInst   = (Inst) 0;
6981    cfmPst.srcProcId = SFndProcId();
6982    cfmPst.dstEnt    = (Ent)ENTMAC;
6983    cfmPst.dstInst   = (Inst) 0;
6984    cfmPst.dstProcId = SFndProcId();
6985    cfmPst.selector  = ODU_SELECTOR_LC;
6986    cfmPst.region    = reg;
6987    cfmPst.pool      = pool;
6988
6989    if(RgUiRgrCfgCfm(&cfmPst,transId, status) != ROK)
6990    {
6991       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"schSendCfgCfm: RgUiRgrCfgCfm Failed");
6992       printf("\nschSendCfgCfm: RgUiRgrCfgCfm Failed ");
6993       return RFAILED;
6994    }
6995    return ROK;
6996 }  /* schSendCfgCfm*/
6997 #ifdef RGR_RRM_TICK
6998 /**
6999  * @brief API for sending TTI indication from Scheduler to RRM.
7000  *
7001  * @details
7002  *
7003  *     Function: rgSCHUtlRgrTtiInd
7004  *
7005  *     This API is invoked to send TTI indication from Scheduler instance to RRM.
7006  *     This API fills in Pst structure and RgrTtiIndInfo
7007  *
7008  *  @param[in]  cell                   RgSchCellCb
7009  *  @param[in]  CmLteTimingInfo        status
7010  *  @return  S16
7011  *      -# ROK
7012  *      -# RFAILED
7013  **/
7014 #ifdef ANSI
7015 S16 rgSCHUtlRgrTtiInd
7016 (
7017 RgSchCellCb          *cell,
7018 RgrTtiIndInfo        *rgrTti
7019 )
7020 #else
7021 S16 rgSCHUtlRgrTtiInd(cell, rgrTti)
7022 RgSchCellCb          *cell;
7023 RgrTtiIndInfo        *rgrTti;
7024 #endif
7025 {
7026    S16           ret = ROK;
7027    RgSchUpSapCb  *rgrSap;                    /*!< RGR SAP Control Block */
7028 #ifdef L2_L3_SPLIT
7029    extern Bool g_usettitmr;
7030    extern Void mtTmrHdlrPublic(void);
7031 #endif
7032
7033    rgrSap = cell->rgrSap;
7034    if (rgrSap->sapSta.sapState != LRG_BND)
7035    {
7036       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
7037                "rgSCHUtlRgrTtiInd() Upper SAP not bound (%d) ",
7038                rgrSap->sapSta.sapState);
7039       return RFAILED;
7040    }
7041    RgUiRgrTtiInd(&(cell->rgrSap->sapCfg.sapPst),
7042          cell->rgrSap->sapCfg.suId, rgrTti);
7043 #ifdef L2_L3_SPLIT
7044    {
7045       g_usettitmr = TRUE;
7046       mtTmrHdlrPublic();
7047    }
7048 #endif
7049    return (ret);
7050 }  /* rgSCHUtlRgrTtiInd*/
7051 #endif
7052 /** @brief This function is called by rgMacSchSfRecpInd. This function invokes the
7053  * scheduler with the information of the received Data and any Control Elements
7054  * if present.
7055  *
7056  * @details
7057  *
7058  *     Function:
7059  *
7060  *         Processing steps:
7061  *         - Retrieves the RaCb with the rnti provided, if it doesnt exist
7062  *         return failure.
7063  *         - If UE exists then update the Schduler with any MAC CEs if present.
7064  *         - Invoke RAM module to do Msg3 related processing rgSCHRamProcMsg3
7065  *
7066  * @param  [in] RgSchCellCb   *cellCb
7067  * @param  [in] RgSchUeCb     *ueCb
7068  * @param  [in] CmLteRnti     rnti
7069  * @param  [in] RgMacPdu   *pdu
7070  * @param  [in] RgSchErrInfo  *err
7071  * @param
7072  *  @return  S16
7073  *      -# ROK
7074  *      -# RFAILED
7075  */
7076 #ifdef ANSI
7077 S16 rgSCHUtlProcMsg3
7078 (
7079 RgInfSfDatInd    *subfrmInfo,
7080 RgSchCellCb      *cellCb,
7081 RgSchUeCb        *ueCb,
7082 CmLteRnti        rnti,
7083 RgInfUeDatInd    *pdu,
7084 RgSchErrInfo     *err
7085  )
7086 #else
7087 S16 rgSCHUtlProcMsg3 (subfrmInfo, cellCb, ueCb, rnti, pdu, err)
7088 RgInfSfDatInd    *subfrmInfo;
7089 RgSchCellCb      *cellCb;
7090 RgSchUeCb        *ueCb;
7091 CmLteRnti        rnti;
7092 RgInfUeDatInd    *pdu;
7093 RgSchErrInfo     *err;
7094 #endif
7095 {
7096    S16               ret;
7097    RgSchRaCb         *raCb;
7098
7099    /* must have an raCb for this case */
7100    raCb = rgSCHDbmGetRaCb (cellCb, rnti);
7101    if (raCb == NULLP)
7102    {
7103       RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId, "RNTI:%d Received MSG3, unable to "
7104          "find raCb",rnti);
7105       return RFAILED;
7106    }
7107
7108    /* ccpu00130982: Processing CRNTI MAC CE before Short BSR, if any, such that 
7109     * effBsr of current case only will be considered in scheduling of ContResLst*/
7110    ret = rgSCHRamProcMsg3 (cellCb, ueCb, raCb, pdu, err);
7111    if (ret != ROK)
7112    {
7113       RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"Processing failed in the RAM "
7114          "RNTI:%d ",rnti);
7115       return (ret);
7116    }
7117    /* if ueCb is present */
7118    if (ueCb != NULLP)
7119    {
7120       rgSCHUtlUpdSch (subfrmInfo, cellCb, ueCb, pdu, err);
7121    }
7122
7123    return ROK;
7124 }
7125 #ifdef LTEMAC_SPS
7126 /** @brief This function is called by RgMacSchSpsRelInd. This function invokes the
7127  * scheduler with the information of the received Data.
7128  *
7129  * @details
7130  *
7131  *     Function: rgSCHUtlSpsRelInd
7132  *
7133  *         Processing steps:
7134  *         TODO
7135  *
7136  * @param  [in] RgSchCellCb        *cellCb
7137  * @param  [in] RgSchUeCb          *ueCb
7138  * @param  [in] Bool               *isExplRel
7139  * @param
7140  *  @return  S16
7141  *      -# ROK
7142  *      -# RFAILED
7143  */
7144 #ifdef ANSI
7145 S16 rgSCHUtlSpsRelInd
7146 (
7147 RgSchCellCb        *cellCb,
7148 RgSchUeCb          *ueCb,
7149 Bool               isExplRel
7150 )
7151 #else
7152 S16 rgSCHUtlSpsRelInd (cellCb, ueCb, isExplRel)
7153 RgSchCellCb        *cellCb;
7154 RgSchUeCb          *ueCb;
7155 Bool               isExplRel;
7156 #endif
7157 {
7158    cellCb->sc.apis->rgSCHUlSpsRelInd(cellCb, ueCb, isExplRel);
7159    return ROK;
7160 } /* end of rgSCHUtlSpsRelInd */
7161
7162
7163 /** @brief This function is called by RgMacSchSpsRelInd. This function invokes the
7164  * scheduler with the information of the received Data.
7165  *
7166  * @details
7167  *
7168  *     Function: rgSCHUtlSpsActInd
7169  *
7170  *         Processing steps:
7171  *         TODO
7172  *
7173  * @param  [in] RgSchCellCb        *cellCb
7174  * @param  [in] RgSchUeCb          *ueCb
7175  * @param  [in] U16                spsSduSize
7176  * @param
7177  *  @return  S16
7178  *      -# ROK
7179  *      -# RFAILED
7180  */
7181 #ifdef ANSI
7182 S16 rgSCHUtlSpsActInd
7183 (
7184 RgSchCellCb        *cellCb,
7185 RgSchUeCb          *ueCb,
7186 U16                spsSduSize
7187 )
7188 #else
7189 S16 rgSCHUtlSpsActInd (cellCb, ueCb, spsSduSize)
7190 RgSchCellCb        *cellCb;
7191 RgSchUeCb          *ueCb;
7192 U16                spsSduSize;
7193 #endif
7194 {
7195    cellCb->sc.apis->rgSCHUlSpsActInd(cellCb, ueCb, spsSduSize);
7196    return ROK;
7197 } /* end of rgSCHUtlSpsActInd */
7198
7199
7200 #endif /* LTEMAC_SPS */
7201
7202 #ifdef RG_PHASE_2
7203 /**
7204  * @brief This API is invoked to send uplink group power control request to PHY.
7205  *
7206  * @details
7207  *
7208  *     Function : rgSCHUtlTfuGrpPwrCntrlReq
7209  *
7210  *      This API is invoked to send uplink group power control request to PHY.
7211  *      It fills in the Pst structure, spId value and invokes group power
7212  *      control request primitive at TFU.
7213  *
7214  *  @param[in]  TfuGrpPwrCntrlReqInfo *grpPwrCntrlReq
7215  *  @return  S16
7216  *      -# ROK
7217  *      -# RFAILED
7218  **/
7219 #ifdef ANSI
7220 S16 rgSCHUtlTfuGrpPwrCntrlReq
7221 (
7222 Inst                  inst,
7223 S16                   sapId,
7224 TfuGrpPwrCntrlReqInfo *grpPwrCntrlReq
7225 )
7226 #else
7227 S16 rgSCHUtlTfuGrpPwrCntrlReq(inst, sapId, grpPwrCntrlReq)
7228 Inst                  inst;
7229 S16                   sapId;
7230 TfuGrpPwrCntrlReqInfo *grpPwrCntrlReq;
7231 #endif
7232 {
7233    S16             ret;
7234    RgSchLowSapCb  *tfuSap;
7235    Pst             pst;
7236
7237
7238    /* Get the lower SAP control block from the layer control block. */
7239    tfuSap = &(rgSchCb[inst].tfuSap[sapId]);
7240    if (tfuSap->sapSta.sapState != LRG_BND)
7241    {
7242       RLOG_ARG1(L_ERROR,DBG_CELLID,grpPwrCntrlReq->cellId,
7243                       "rgSCHUtlTfuGrpPwrCntrlReq() Lower SAP not bound (%d) ",tfuSap->sapSta.sapState);
7244       return RFAILED;
7245    }
7246    memcpy (&pst, &(tfuSap->sapCfg.sapPst), sizeof(Pst));
7247    if((ret = RgLiTfuGrpPwrCntrlReq (&pst, tfuSap->sapCfg.spId, grpPwrCntrlReq)) != ROK)
7248    {
7249       RLOG_ARG0(L_ERROR,DBG_CELLID,grpPwrCntrlReq->cellId,
7250                       "rgSCHUtlTfuGrpPwrCntrlReq() Call to RgLiTfuGrpPwrCntrlReq() failed");
7251    }
7252    return (ret);
7253 }  /* rgSCHUtlTfuGrpPwrCntrlReq */
7254 #endif
7255
7256 /**
7257  * @brief This API is invoked to send Control Info to PHY.
7258  *
7259  * @details
7260  *
7261  *     Function : rgSCHUtlTfuCntrlReq
7262  *
7263  *      This API is invoked to send Control Info to PHY. It
7264  *      fills in the Pst structure, spId value and invokes Cntrl
7265  *      request primitive at TFU.
7266  *
7267  *  @param[in]  TfuCntrlReqInfo *cntrlReq
7268  *  @return  S16
7269  *      -# ROK
7270  *      -# RFAILED
7271  **/
7272 #ifdef ANSI
7273 S16 rgSCHUtlTfuCntrlReq
7274 (
7275 Inst            inst,
7276 S16             sapId,
7277 TfuCntrlReqInfo *cntrlReq
7278 )
7279 #else
7280 S16 rgSCHUtlTfuCntrlReq(inst, sapId, cntrlReq)
7281 Inst            inst;
7282 S16             sapId;
7283 TfuCntrlReqInfo *cntrlReq;
7284 #endif
7285 {
7286    S16            ret;
7287    RgSchLowSapCb  *tfuSap;
7288
7289    /* Get the lower SAP control block from the layer control block. */
7290    tfuSap = &(rgSchCb[inst].tfuSap[sapId]);
7291
7292 #ifndef NO_ERRCLS
7293    if (tfuSap->sapSta.sapState != LRG_BND)
7294    {
7295       RLOG_ARG1(L_ERROR,DBG_INSTID,inst,"rgSCHUtlTfuCntrlReq() Lower SAP not bound (%d) ",
7296             tfuSap->sapSta.sapState);
7297       RGSCH_FREE_MEM(cntrlReq);
7298       return RFAILED;
7299    }
7300 #endif
7301
7302   /* Using local variable for pst is unnecessary - for optimization */
7303    if((ret = RgLiTfuCntrlReq(&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
7304                              cntrlReq)) != ROK)
7305    {
7306       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"rgSCHUtlTfuCntrlReq() Call to RgLiTfuCntrlReq() failed");
7307    }
7308    return (ret);
7309 }  /* rgSCHUtlTfuCntrlReq*/
7310
7311
7312 /* FOR ACK NACK REP */
7313
7314 /**
7315  * @brief This API is invoked to tell the DL Scheduler to add the UE back into
7316  * its scheduling queues.
7317  *
7318  * @details
7319  *
7320  *     Function : rgSCHUtlDlActvtUe
7321  *
7322  *      This API is invoked from Measurement gap moduled.
7323  *
7324  *  @param[in]  RgSchCellCb    *cell
7325  *  @param[in]  RgSchUeCb        *ueCb
7326  *
7327  *  @return  S16
7328  *      -# ROK
7329  *      -# RFAILED
7330  **/
7331 #ifdef ANSI
7332 S16 rgSCHUtlDlActvtUe
7333 (
7334 RgSchCellCb *cell,
7335 RgSchUeCb   *ue
7336 )
7337 #else
7338 S16 rgSCHUtlDlActvtUe(cell, ue)
7339 RgSchCellCb *cell;
7340 RgSchUeCb   *ue;
7341 #endif
7342 {
7343    cell->sc.apis->rgSCHActvtDlUe(cell, ue);
7344    return ROK;
7345 }
7346
7347 /**
7348  * @brief This API is invoked to tell the UL Scheduler to add the UE back into
7349  * its scheduling queues.
7350  *
7351  * @details
7352  *
7353  *     Function : rgSCHUtlUlActvtUe
7354  *
7355  *      This API is invoked from Measurement gap moduled.
7356  *
7357  *  @param[in]  RgSchCellCb    *cell
7358  *  @param[in]  RgSchUeCb        *ueCb
7359  *
7360  *  @return  S16
7361  *      -# ROK
7362  *      -# RFAILED
7363  **/
7364 #ifdef ANSI
7365 S16 rgSCHUtlUlActvtUe
7366 (
7367 RgSchCellCb *cell,
7368 RgSchUeCb   *ue
7369 )
7370 #else
7371 S16 rgSCHUtlUlActvtUe(cell, ue)
7372 RgSchCellCb *cell;
7373 RgSchUeCb   *ue;
7374 #endif
7375 {
7376    cell->sc.apis->rgSCHActvtUlUe(cell, ue);
7377    return ROK;
7378 }
7379
7380 /**
7381  * @brief This API is invoked to send Reception Request Info to PHY.
7382  *
7383  * @details
7384  *
7385  *     Function : rgSCHUtlTfuRecpReq
7386  *
7387  *      This API is invoked to send Reception Request Info to PHY. It
7388  *      fills in the Pst structure, spId value and invokes Reception
7389  *      request primitive at TFU.
7390  *
7391  *  @param[in]  TfuRecpReqInfo *recpReq
7392  *  @return  S16
7393  *      -# ROK
7394  *      -# RFAILED
7395  **/
7396 #ifdef ANSI
7397 S16 rgSCHUtlTfuRecpReq
7398 (
7399 Inst            inst,
7400 S16             sapId,
7401 TfuRecpReqInfo *recpReq
7402 )
7403 #else
7404 S16 rgSCHUtlTfuRecpReq(inst, sapId, recpReq)
7405 Inst            inst;
7406 S16             sapId;
7407 TfuRecpReqInfo *recpReq;
7408 #endif
7409 {
7410    S16            ret;
7411    RgSchLowSapCb  *tfuSap;
7412
7413
7414    /* Get the lower SAP control block from the layer control block. */
7415    tfuSap = &(rgSchCb[inst].tfuSap[sapId]);
7416
7417 #ifndef NO_ERRCLS
7418    if (tfuSap->sapSta.sapState != LRG_BND)
7419    {
7420       RLOG_ARG1(L_ERROR,DBG_INSTID,inst,"rgSCHUtlTfuRecpReq() Lower SAP not bound (%d) ",
7421             tfuSap->sapSta.sapState);
7422       RGSCH_FREE_MEM(recpReq);
7423       return RFAILED;
7424    }
7425 #endif
7426
7427   /* Using local variable for pst is unnecessary - for optimization */
7428    if((ret = RgLiTfuRecpReq(&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
7429                             recpReq)) != ROK)
7430    {
7431       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"rgSCHUtlTfuRecpReq() Call to RgLiTfuRecpReq() failed");
7432    }
7433    return (ret);
7434 }  /* rgSCHUtlTfuRecpReq */
7435
7436  /** @brief This function Validates the SAP information received along with the
7437   * primitive from the lower layer.
7438   *
7439   * Function: rgSCHUtlValidateTfuSap
7440   *
7441   *                      Validates SAP information.
7442   * @param  suId The SAP Id
7443   * @return
7444   *   -# ROK
7445   *   -# RFAILED
7446   */
7447 #ifdef ANSI
7448 S16 rgSCHUtlValidateTfuSap
7449 (
7450 Inst  inst,
7451 SuId  suId
7452 )
7453 #else
7454 S16 rgSCHUtlValidateTfuSap(inst, suId)
7455 Inst  inst;
7456 SuId  suId;
7457 #endif
7458 {
7459    RgSchLowSapCb  *tfuSap;
7460
7461    if(suId >= rgSchCb[inst].numSaps)
7462    {
7463       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "Incorrect SuId");
7464       return RFAILED;
7465    }
7466    tfuSap = &(rgSchCb[inst].tfuSap[suId]);
7467
7468    /* First lets check the suId */
7469    if( suId != tfuSap->sapCfg.suId)
7470    {
7471       RLOG_ARG2(L_ERROR,DBG_INSTID,inst,"Incorrect SuId. Configured (%d) Recieved (%d)",
7472             tfuSap->sapCfg.suId, suId);
7473       return RFAILED;
7474    }
7475    if (tfuSap->sapSta.sapState != LRG_BND)
7476    {
7477       RLOG_ARG1(L_ERROR,DBG_INSTID,inst,"Lower SAP not enabled SuId (%d)",
7478             tfuSap->sapCfg.suId);
7479       return RFAILED;
7480    }
7481    return ROK;
7482 } /* end of rgSCHUtlValidateTfuSap */
7483
7484 /*
7485 *
7486 *       Fun:   rgSCHUtlAllocEventMem
7487 *
7488 *       Desc:  This function allocates event memory
7489 *
7490 *       Ret:   ROK      - on success
7491 *              RFAILED  - on failure
7492 *
7493 *       Notes: None
7494 *
7495 *       File:  rg_utl.c
7496 *
7497 */
7498 #ifdef ANSI
7499 S16 rgSCHUtlAllocEventMem
7500 (
7501 Inst      inst,
7502 Ptr       *memPtr,
7503 Size      memSize
7504 )
7505 #else
7506 S16 rgSCHUtlAllocEventMem(inst, memPtr, memSize)
7507 Inst      inst;
7508 Ptr       *memPtr;
7509 Size      memSize;
7510 #endif
7511 {
7512    Mem              sMem;
7513    VOLATILE U32     startTime=0;
7514
7515    sMem.region = rgSchCb[inst].rgSchInit.region;
7516    sMem.pool = rgSchCb[inst].rgSchInit.pool;
7517
7518 #if (ERRCLASS & ERRCLS_DEBUG)
7519    if (memSize<= 0)
7520    {
7521       RGSCHLOGERROR(inst, ERRCLS_INT_PAR, ERG022, memSize,
7522                    "rgAllocEventMem(): memSize invalid\n");
7523       return  (RFAILED);
7524    }
7525 #endif /* ERRCLASS & ERRCLS_DEBUG */
7526    /*starting Task*/
7527    SStartTask(&startTime, PID_SCHUTL_CMALLCEVT);
7528
7529 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
7530    MS_BUF_ADD_ALLOC_CALLER();
7531 #endif /* */
7532 #ifdef TFU_ALLOC_EVENT_NO_INIT
7533    if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
7534 #else
7535    if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
7536 #endif /* */
7537    {
7538       RLOG_ARG0(L_ERROR,DBG_INSTID,inst,"cmAllocEvnt Failed.");
7539       return RFAILED;
7540    }
7541    /*stoping Task*/
7542    SStopTask(startTime, PID_SCHUTL_CMALLCEVT);
7543    return ROK;
7544 } /* end of rgSCHUtlAllocEventMem*/
7545
7546 /*
7547 *
7548 *       Fun:   rgGetEventMem
7549 *
7550 *       Desc:  This function allocates event memory
7551 *
7552 *       Ret:   ROK      - on success
7553 *              RFAILED  - on failure
7554 *
7555 *       Notes: None
7556 *
7557 *       File:  rg_utl.c
7558 *
7559 */
7560 #ifdef ANSI
7561 S16 rgSCHUtlGetEventMem
7562 (
7563 Ptr       *ptr,
7564 Size      len,
7565 Ptr       memCp
7566 )
7567 #else
7568 S16 rgSCHUtlGetEventMem(ptr, len, memCp)
7569 Ptr       *ptr;
7570 Size      len;
7571 Ptr       memCp;
7572 #endif
7573 {
7574    S16   ret;
7575
7576 #ifdef TFU_ALLOC_EVENT_NO_INIT
7577    ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
7578 #else
7579    ret = cmGetMem(memCp, len, (Ptr *)ptr);
7580 #endif
7581    return (ret);
7582 } /* end of rgSCHUtlGetEventMem*/
7583
7584 #ifdef LTE_TDD
7585
7586
7587 /**
7588  * @brief Handler to allocate memory for ACK/NACk feedback information
7589  *
7590  * @details
7591  *
7592  *     Function : rgSCHUtlAllocUeANFdbkInfo
7593  *
7594  *   It allocates memory for the UE related ACK NACK information.
7595  *
7596  *  @param[in]  RgSchUeCb           *ue
7597  *  @return     S16
7598  **/
7599 #ifdef ANSI
7600 S16 rgSCHUtlAllocUeANFdbkInfo
7601 (
7602 RgSchUeCb            *ue,
7603 U8                   servCellIdx
7604 )
7605 #else
7606 S16 rgSCHUtlAllocUeANFdbkInfo(ue,servCellIdx)
7607 RgSchUeCb            *ue;
7608 U8                   servCellIdx;
7609 #endif
7610 {
7611    U8 idx;
7612
7613    if (rgSCHUtlAllocSBuf(ue->cell->instIdx,
7614                (Data **) &(ue->cellInfo[servCellIdx]->anInfo), sizeof(RgSchTddANInfo) * \
7615                ue->cell->ackNackFdbkArrSize) != ROK)
7616    {
7617       return RFAILED;
7618    }
7619
7620    for(idx=0; idx < ue->cell->ackNackFdbkArrSize; idx++)
7621    {
7622       rgSCHUtlInitUeANFdbkInfo(&ue->cellInfo[servCellIdx]->anInfo[idx]);
7623    }
7624
7625    /* Set it to the first index */
7626    ue->cellInfo[servCellIdx]->nextFreeANIdx = 0;
7627    return ROK;
7628 } /* rgSCHUtlAllocUeANFdbkInfo */
7629
7630 /**
7631  * @brief Handler to release memory for ACK/NACk feedback information
7632  *
7633  * @details
7634  *
7635  *     Function : rgSCHUtlDelUeANFdbkInfo
7636  *
7637  *   It releases memory for the UE related ACK NACK information.
7638  *
7639  *  @param[in]  RgSchUeCb           *ue
7640  *  @return     Void
7641  **/
7642 #ifdef ANSI
7643 Void rgSCHUtlDelUeANFdbkInfo
7644 (
7645 RgSchUeCb            *ue,
7646 U8                   servCellIdx
7647 )
7648 #else
7649 Void rgSCHUtlDelUeANFdbkInfo(ue,servCellIdx)
7650 RgSchUeCb            *ue;
7651 U8                   servCellIdx;
7652 #endif
7653 {
7654
7655    /* ccpu00117052 - MOD - Passing double pointer
7656    for proper NULLP assignment*/
7657    rgSCHUtlFreeSBuf(ue->cell->instIdx,
7658          (Data **)(&( ue->cellInfo[servCellIdx]->anInfo)), sizeof(RgSchTddANInfo) * \
7659                         ue->cell->ackNackFdbkArrSize);
7660
7661    RETVOID;
7662 } /* rgSCHUtlDelUeANFdbkInfo */
7663
7664 /**
7665  * @brief Handler to initialise UE ACK/NACk feedback information
7666  *
7667  * @details
7668  *
7669  *     Function : rgSCHUtlInitUeANFdbkInfo
7670  *
7671  *   It initialises UE related ACK NACK information.
7672  *
7673  *  @param[in]  RgSchTddANInfo   *anFdInfo
7674  *  @return     S16
7675  **/
7676 #ifdef ANSI
7677 S16 rgSCHUtlInitUeANFdbkInfo
7678 (
7679 RgSchTddANInfo       *anFdInfo
7680 )
7681 #else
7682 S16 rgSCHUtlInitUeANFdbkInfo(anFdInfo)
7683 RgSchTddANInfo       *anFdInfo;
7684 #endif
7685 {
7686
7687    anFdInfo->sfn = RGSCH_MAX_SFN+1; /* defensively setting invalid sfn */
7688    anFdInfo->slot = 0;
7689    anFdInfo->ulDai = RG_SCH_INVALID_DAI_VAL;
7690    anFdInfo->dlDai = RG_SCH_INVALID_DAI_VAL;
7691    anFdInfo->latestMIdx = RG_SCH_INVALID_M_VAL;
7692
7693    return ROK;
7694 } /* rgSCHUtlInitUeANFdbkInfo */
7695
7696 /**
7697  * @brief Handler to get UE related ACK NACK feedback information
7698  *
7699  * @details
7700  *
7701  *     Function : rgSCHUtlGetUeANFdbkInfo
7702  *
7703  *   It gets the UE related ACK NACK information based on
7704  *   SFN and slot number.
7705  *
7706  *  @param[in]  RgSchUeCb        *ueCb
7707  *  @param[in]  CmLteTimingInfo  *time
7708  *  @return     RgSchTddANInfo*
7709  **/
7710 #ifdef ANSI
7711 RgSchTddANInfo* rgSCHUtlGetUeANFdbkInfo
7712 (
7713 RgSchUeCb         *ueCb,
7714 CmLteTimingInfo   *timeInfo,
7715 U8                servCellIdx
7716 )
7717 #else
7718 RgSchTddANInfo* rgSCHUtlGetUeANFdbkInfo(ueCb, timeInfo,servCellIdx)
7719 RgSchUeCb         *ueCb;
7720 CmLteTimingInfo   *timeInfo;
7721 U8                servCellIdx;
7722 #endif
7723 {
7724    U8 idx;
7725
7726    for (idx = 0; idx < ueCb->cell->ackNackFdbkArrSize; ++idx)
7727    {
7728        if( (timeInfo->sfn == ueCb->cellInfo[servCellIdx]->anInfo[idx].sfn) &&
7729                (timeInfo->slot == ueCb->cellInfo[servCellIdx]->anInfo[idx].slot))
7730        {
7731             return (&ueCb->cellInfo[servCellIdx]->anInfo[idx]);
7732        }
7733    }
7734
7735    return (NULLP);
7736 } /* rgSCHUtlGetUeANFdbkInfo */
7737
7738 /**
7739  * @brief To get downlink slot index
7740  *
7741  * @details
7742  *
7743  *     Function: rgSCHUtlGetDlSfIdx
7744  *     Purpose:  Gets downlink slot index based on SFN and slot no
7745  *
7746  *  @param[in]  CmLteTimingInfo  *timeInfo
7747  *  @param[in]  RgSchCellCb         *cell
7748  *  @return U8
7749  *
7750  **/
7751 #ifdef ANSI
7752 U8  rgSCHUtlGetDlSfIdx
7753 (
7754 RgSchCellCb        *cell,
7755 CmLteTimingInfo *timeInfo
7756 )
7757 #else
7758 U8  rgSCHUtlGetDlSfIdx(cell, timeInfo)
7759 RgSchCellCb        *cell;
7760 CmLteTimingInfo *timeInfo;
7761 #endif
7762 {
7763    U16       idx = 0;
7764
7765    idx = RGSCH_NUM_SUB_FRAMES - \
7766          rgSchTddNumUlSubfrmTbl[cell->ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
7767    idx = ((idx * timeInfo->sfn) + \
7768          rgSchTddNumDlSubfrmTbl[cell->ulDlCfgIdx][timeInfo->slot]) - 1;
7769    idx = idx % cell->numDlSubfrms;
7770
7771    return ((U8)idx);
7772 }
7773
7774 /**
7775  * @brief To get the next downlink slot
7776  *
7777  * @details
7778  *
7779  *     Function: rgSCHUtlGetNxtDlSfInfo
7780  *     Purpose:  Gets next downlink slot based on current DL slot
7781  *
7782  *  @param[in]  CmLteTimingInfo  curDlTime
7783  *  @param[in]  RgSchCellCb      *cell
7784  *  @param[in]  RgSchDlSf        *dlSf
7785  *  @param[in]  RgSchDlSf        **nxtDlsf
7786  *  @param[in]  CmLteTimingInfo  *nxtDlTime
7787  *  @return U8
7788  *
7789  **/
7790 #ifdef ANSI
7791 Void rgSCHUtlGetNxtDlSfInfo
7792 (
7793 CmLteTimingInfo   curDlTime,
7794 RgSchCellCb       *cell,
7795 RgSchDlSf         *dlSf,
7796 RgSchDlSf         **nxtDlsf,
7797 CmLteTimingInfo   *nxtDlTime
7798 )
7799 #else
7800 Void rgSCHUtlGetNxtDlSfInfo(curDlTime, cell, dlSf, nxtDlsf, nxtDlTime)
7801 CmLteTimingInfo   curDlTime;
7802 RgSchCellCb       *cell;
7803 RgSchDlSf         *dlSf;
7804 RgSchDlSf         **nxtDlsf;
7805 CmLteTimingInfo   *nxtDlTime;
7806 #endif
7807 {
7808    U16  idx = curDlTime.slot;
7809    U8   count = 0;
7810
7811    while(TRUE)
7812    {
7813       do
7814       {
7815          idx = (idx + 1) % RGSCH_NUM_SUB_FRAMES;
7816          count++;
7817       }while(rgSchTddUlDlSubfrmTbl[cell->ulDlCfgIdx][idx]
7818                                        != RG_SCH_TDD_DL_slot);
7819       RG_SCH_ADD_TO_CRNT_TIME(curDlTime, (*nxtDlTime), count);
7820       *nxtDlsf = rgSCHUtlSubFrmGet(cell, *nxtDlTime);
7821       if(dlSf->dlFdbkInfo.slot != (*nxtDlsf)->dlFdbkInfo.slot)
7822       {
7823          break;
7824       }
7825    }
7826    RETVOID;
7827 }
7828
7829 /**
7830  * @brief To get the previous downlink slot
7831  *
7832  * @details
7833  *
7834  *     Function: rgSCHUtlGetPrevDlSfInfo
7835  *     Purpose:  Gets previous downlink slot based on current DL slot
7836  *
7837  *  @param[in]  RgSchCellCb      *cell
7838  *  @param[in]  CmLteTimingInfo  curDlTime
7839  *  @param[in]  CmLteTimingInfo  *prevDlTime
7840  *  @param[in]  U8               *numSubfrm
7841  *  @return U8
7842  *
7843  **/
7844 #ifdef ANSI
7845 Void rgSCHUtlGetPrevDlSfInfo
7846 (
7847 RgSchCellCb       *cell,
7848 CmLteTimingInfo   curDlTime,
7849 CmLteTimingInfo   *prevDlTime,
7850 U8                *numSubfrm
7851 )
7852 #else
7853 Void rgSCHUtlGetPrevDlSfInfo(cell, curDlTime, prevDlTime, numSubfrm)
7854 RgSchCellCb       *cell;
7855 CmLteTimingInfo   curDlTime;
7856 CmLteTimingInfo   *prevDlTime;
7857 U8                *numSubfrm;
7858 #endif
7859 {
7860    S16 idx = curDlTime.slot;
7861    U8  count = 0;
7862
7863    do
7864    {
7865       idx--;
7866       if(idx < 0)
7867       {
7868          idx = RGSCH_NUM_SUB_FRAMES-1;
7869       }
7870       count++;
7871    }while(rgSchTddUlDlSubfrmTbl[cell->ulDlCfgIdx][idx]
7872          !=  RG_SCH_TDD_DL_slot);
7873    *numSubfrm = count;
7874    RGSCHDECRFRMCRNTTIME(curDlTime, (*prevDlTime), count);
7875    RETVOID;
7876 }
7877
7878 #endif
7879 /* Added Holes Management functions for Adaptive Re transmission */
7880 /******* </AllocHolesMemMgmnt>: START *****/
7881 /***********************************************************
7882  *
7883  *     Func : rgSCHUtlUlSfInit
7884  *
7885  *     Desc : UL slot init.
7886  *
7887  *     Ret  : S16
7888  *
7889  *     Notes:
7890  *
7891  *     File :
7892  *
7893  **********************************************************/
7894 #ifdef ANSI
7895 S16 rgSCHUtlUlSfInit
7896 (
7897 RgSchCellCb  *cell,
7898 RgSchUlSf    *sf,
7899 U8           idx,
7900 U8           maxUePerSf
7901 )
7902 #else
7903 S16 rgSCHUtlUlSfInit(cell, sf, idx, maxUePerSf)
7904 RgSchCellCb  *cell;
7905 RgSchUlSf    *sf;
7906 U8           idx;
7907 U8           maxUePerSf;
7908 #endif
7909 {
7910    S16             ret=ROK;
7911
7912    sf->idx = idx;
7913 #ifdef RG_5GTF
7914    U8 index;
7915 #endif
7916
7917 #ifdef LTE_TDD   
7918    if(cell->ulDlCfgIdx == 0)
7919    {
7920       /* Store the Uplink slot number corresponding to the idx */
7921       sf->ulSfIdx = rgSchTddCfg0UlSfTbl[idx%6]; 
7922    }
7923 #endif   
7924    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&sf->allocDb,
7925                            sizeof(RgSchUlAllocDb));
7926    if (ret != ROK)
7927    {
7928       return (ret);
7929    }
7930    ret = rgSCHUtlUlAllocDbInit(cell, sf->allocDb, maxUePerSf);
7931    if (ret != ROK)
7932    {
7933       /* ccpu00117052 - MOD - Passing double pointer
7934       for proper NULLP assignment*/
7935       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(sf->allocDb)),
7936                        sizeof(RgSchUlAllocDb));
7937       return (ret);
7938    }
7939    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&sf->holeDb,
7940          sizeof(RgSchUlHoleDb));
7941    if (ret != ROK)
7942    {
7943       rgSCHUtlUlAllocDbDeinit(cell, sf->allocDb);
7944       /* ccpu00117052 - MOD - Passing double pointer
7945       for proper NULLP assignment*/
7946       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(sf->allocDb)),
7947                        sizeof(RgSchUlAllocDb));
7948       return (ret);
7949    }
7950    /* Initialize the hole with CFI 1 Pusch Bw Info */ 
7951    ret = rgSCHUtlUlHoleDbInit(cell, sf->holeDb, (U8)(maxUePerSf + 2), \
7952                               0, cell->dynCfiCb.bwInfo[1].numSb);
7953
7954    if (ret != ROK)
7955    {
7956       rgSCHUtlUlAllocDbDeinit(cell, sf->allocDb);
7957       /* ccpu00117052 - MOD - Passing double pointer
7958       for proper NULLP assignment*/
7959       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(sf->allocDb)),
7960                        sizeof(RgSchUlAllocDb));
7961       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(sf->holeDb)),
7962                        sizeof(RgSchUlHoleDb));
7963       return (ret);
7964    }
7965    cmLListInit(&sf->reTxLst);
7966
7967    /* Fix ccpu00120610*/
7968    sf->allocCountRef = &sf->allocDb->count;
7969
7970    /* initialize UL available subbands for current sub-frame */
7971    sf->availSubbands = cell->dynCfiCb.bwInfo[1].numSb;
7972 #ifdef RG_5GTF
7973    sf->numGrpPerTti = cell->cell5gtfCb.ueGrpPerTti;
7974    sf->numUePerGrp = cell->cell5gtfCb.uePerGrpPerTti;
7975    for(index = 0; index < MAX_5GTF_BEAMS; index++)
7976    {
7977       sf->sfBeamInfo[index].totVrbgAllocated = 0;
7978       sf->sfBeamInfo[index].totVrbgRequired = 0;
7979       sf->sfBeamInfo[index].vrbgStart = 0;
7980    }
7981 #endif
7982
7983    return (ret);
7984 }
7985
7986
7987 /***********************************************************
7988  *
7989  *     Func : rgSCHUtlUlSfDeinit
7990  *
7991  *     Desc : Deinitialises a slot
7992  *
7993  *     Ret  : Void
7994  *
7995  *     Notes:
7996  *
7997  *     File :
7998  *
7999  **********************************************************/
8000 #ifdef ANSI
8001 Void rgSCHUtlUlSfDeinit
8002 (
8003 RgSchCellCb  *cell,
8004 RgSchUlSf    *sf
8005 )
8006 #else
8007 Void rgSCHUtlUlSfDeinit(cell, sf)
8008 RgSchCellCb  *cell;
8009 RgSchUlSf    *sf;
8010 #endif
8011 {
8012    if (sf->allocDb)
8013    {
8014       rgSCHUtlUlAllocDbDeinit(cell, sf->allocDb);
8015       /* ccpu00117052 - MOD - Passing double pointer
8016       for proper NULLP assignment*/
8017       /* ccpu00117052 - MOD - Passing double pointer
8018       for proper NULLP assignment*/
8019       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(sf->allocDb)),
8020                        sizeof(RgSchUlAllocDb));
8021    }
8022    if (sf->holeDb)
8023    {
8024       rgSCHUtlUlHoleDbDeinit(cell, sf->holeDb);
8025       /* ccpu00117052 - MOD - Passing double pointer
8026       for proper NULLP assignment*/
8027       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(sf->holeDb)),
8028                        sizeof(RgSchUlHoleDb));
8029    }
8030    RETVOID;
8031 }
8032
8033 /***********************************************************
8034  *
8035  *     Func : rgSCHUtlUlAllocDbInit
8036  *
8037  *     Desc : Initialise allocation DB
8038  *
8039  *     Ret  : S16 (ROK/RFAILED)
8040  *
8041  *     Notes:
8042  *
8043  *     File :
8044  *
8045  **********************************************************/
8046 #ifdef ANSI
8047 PRIVATE S16 rgSCHUtlUlAllocDbInit
8048 (
8049 RgSchCellCb    *cell,
8050 RgSchUlAllocDb *allocDb,
8051 U8             maxAllocs
8052 )
8053 #else
8054 PRIVATE S16 rgSCHUtlUlAllocDbInit(cell, allocDb, maxAllocs)
8055 RgSchCellCb    *cell;
8056 RgSchUlAllocDb *allocDb;
8057 U8             maxAllocs;
8058 #endif
8059 {
8060    S16 ret = rgSCHUtlUlAllocMemInit(cell, &allocDb->mem, maxAllocs);
8061    if (ret != ROK)
8062    {
8063       return (ret);
8064    }
8065    allocDb->count = 0;
8066    allocDb->first = NULLP;
8067    return ROK;
8068 }
8069
8070 /***********************************************************
8071  *
8072  *     Func : rgSCHUtlUlAllocDbDeinit
8073  *
8074  *     Desc : Deinitialises allocation DB
8075  *            sent to UE, for a UE with accumulation disabled
8076  *
8077  *     Ret  : Void
8078  *
8079  *     Notes:
8080  *
8081  *     File :
8082  *
8083  **********************************************************/
8084 #ifdef ANSI
8085 PRIVATE Void rgSCHUtlUlAllocDbDeinit
8086 (
8087 RgSchCellCb     *cell,
8088 RgSchUlAllocDb *allocDb
8089 )
8090 #else
8091 PRIVATE Void rgSCHUtlUlAllocDbDeinit(cell, allocDb)
8092 RgSchCellCb     *cell;
8093 RgSchUlAllocDb *allocDb;
8094 #endif
8095 {
8096    rgSCHUtlUlAllocMemDeinit(cell, &allocDb->mem);
8097    allocDb->count = 0;
8098    allocDb->first = NULLP;
8099    RETVOID;
8100 }
8101
8102 /***********************************************************
8103  *
8104  *     Func : rgSCHUtlUlHoleDbInit
8105  *
8106  *     Desc : Initialise hole DB
8107  *
8108  *     Ret  : S16 (ROK/RFAILED)
8109  *
8110  *     Notes:
8111  *
8112  *     File :
8113  *
8114  **********************************************************/
8115 #ifdef ANSI
8116 PRIVATE S16 rgSCHUtlUlHoleDbInit
8117 (
8118 RgSchCellCb   *cell,
8119 RgSchUlHoleDb *holeDb,
8120 U8            maxHoles,
8121 U8            start,
8122 U8            num
8123 )
8124 #else
8125 PRIVATE S16 rgSCHUtlUlHoleDbInit(cell, holeDb, maxHoles, start, num)
8126 RgSchCellCb   *cell;
8127 RgSchUlHoleDb *holeDb;
8128 U8            maxHoles;
8129 U8            start;
8130 U8            num;
8131 #endif
8132 {
8133    S16 ret;
8134    RgSchUlHole *hole = NULLP;
8135
8136    ret = rgSCHUtlUlHoleMemInit(cell, &holeDb->mem, maxHoles, &hole);
8137    if (ret != ROK)
8138    {
8139       return (ret);
8140    }
8141    holeDb->count = 1;
8142    holeDb->first = hole;
8143    hole->start = start;
8144    hole->num = num;
8145    hole->prv = hole->nxt = NULLP;
8146    return ROK;
8147 }
8148
8149 /***********************************************************
8150  *
8151  *     Func : rgSCHUtlUlHoleDbDeinit
8152  *
8153  *     Desc : Deinitialises hole DB
8154  *
8155  *     Ret  : Void
8156  *
8157  *     Notes:
8158  *
8159  *     File :
8160  *
8161  **********************************************************/
8162 #ifdef ANSI
8163 PRIVATE Void rgSCHUtlUlHoleDbDeinit
8164 (
8165 RgSchCellCb   *cell,
8166 RgSchUlHoleDb *holeDb
8167 )
8168 #else
8169 PRIVATE Void rgSCHUtlUlHoleDbDeinit(cell, holeDb)
8170 RgSchCellCb   *cell;
8171 RgSchUlHoleDb *holeDb;
8172 #endif
8173 {
8174    rgSCHUtlUlHoleMemDeinit(cell, &holeDb->mem);
8175    holeDb->count = 0;
8176    holeDb->first = NULLP;
8177    RETVOID;
8178 }
8179
8180
8181 /***********************************************************
8182  *
8183  *     Func : rgSCHUtlUlAllocGetHole
8184  *
8185  *     Desc : Get allocation from hole
8186  *
8187  *     Ret  : RgSchUlAlloc *
8188  *
8189  *     Notes:
8190  *
8191  *     File :
8192  *
8193  **********************************************************/
8194 #ifdef ANSI
8195 RgSchUlAlloc *rgSCHUtlUlAllocGetHole
8196 (
8197 RgSchUlSf   *sf,
8198 U8       numSb,
8199 RgSchUlHole *hole
8200 )
8201 #else
8202 RgSchUlAlloc *rgSCHUtlUlAllocGetHole(sf, numSb, hole)
8203 RgSchUlSf   *sf;
8204 U8       numSb;
8205 RgSchUlHole *hole;
8206 #endif
8207 {
8208    if (numSb < hole->num)
8209    {
8210       return (rgSCHUtlUlAllocGetPartHole(sf, numSb, hole));
8211    }
8212    else
8213    {
8214       return (rgSCHUtlUlAllocGetCompHole(sf, hole));
8215    }
8216 }
8217
8218
8219 /***********************************************************
8220  *
8221  *     Func : rgSCHUtlUlAllocGetCompHole
8222  *
8223  *     Desc : Get an allocation corresponding to an entire hole
8224  *
8225  *     Ret  : RgSchUlAlloc *
8226  *
8227  *     Notes:
8228  *
8229  *     File :
8230  *
8231  **********************************************************/
8232 #ifdef ANSI
8233 RgSchUlAlloc *rgSCHUtlUlAllocGetCompHole
8234 (
8235 RgSchUlSf   *sf,
8236 RgSchUlHole *hole
8237 )
8238 #else
8239 RgSchUlAlloc *rgSCHUtlUlAllocGetCompHole(sf, hole)
8240 RgSchUlSf   *sf;
8241 RgSchUlHole *hole;
8242 #endif
8243 {
8244    RgSchUlAlloc *alloc;
8245       /* alloc = rgSCHUtlUlAllocGetAndIns(sf->allocDb, hole->prvAlloc, hole->nxtAlloc); */
8246    /* Calling rgSchCmnUlAllocGetAndIns is ok, but prv alloc needs to have nxtHole
8247     * updated, causing another check for prv */
8248    RgSchUlAlloc *prv = hole->prvAlloc;
8249    RgSchUlAlloc *nxt = hole->nxtAlloc;
8250
8251    if (prv)
8252    {
8253       if (hole->start == prv->nxtHole->start)
8254       {
8255          prv->nxtHole = NULLP;
8256       }
8257       alloc = rgSCHUtlUlAllocGetAdjNxt(sf->allocDb, prv);
8258    }
8259    else
8260    {
8261       alloc = rgSCHUtlUlAllocGetFirst(sf->allocDb);
8262    }
8263
8264    RGSCH_NULL_CHECK( 0, alloc);
8265    alloc->prvHole = NULLP;
8266    alloc->nxtHole = NULLP;
8267
8268    alloc->sbStart = hole->start;
8269    alloc->numSb = hole->num;
8270
8271    if (nxt)
8272    {
8273       nxt->prvHole = NULLP;
8274    }
8275
8276    rgSCHUtlUlHoleRls(sf->holeDb, hole);
8277
8278    /* UL_ALLOC_CHANGES*/
8279    alloc->allocDbRef = (void*)sf->allocDb;
8280    alloc->holeDbRef  = (void*)sf->holeDb;
8281    return (alloc);
8282 }
8283
8284 /***********************************************************
8285  *
8286  *     Func : rgSCHUtlUlAllocGetPartHole
8287  *
8288  *     Desc : Get an allocation corresponding to a part of a hole.
8289  *            The initial 'numSb' part of the hole shall be taken
8290  *            away for this alloc.
8291  *
8292  *     Ret  : RgSchUlAlloc *
8293  *
8294  *     Notes:
8295  *
8296  *     File :
8297  *
8298  **********************************************************/
8299 #ifdef ANSI
8300 RgSchUlAlloc *rgSCHUtlUlAllocGetPartHole
8301 (
8302 RgSchUlSf   *sf,
8303 U8       numSb,
8304 RgSchUlHole *hole
8305 )
8306 #else
8307 RgSchUlAlloc *rgSCHUtlUlAllocGetPartHole(sf, numSb, hole)
8308 RgSchUlSf   *sf;
8309 U8       numSb;
8310 RgSchUlHole *hole;
8311 #endif
8312 {
8313    RgSchUlAlloc *alloc;
8314       /* alloc = rgSCHUtlUlAllocGetAndIns(sf->allocDb, hole->prvAlloc, hole->nxtAlloc); */
8315    /* Calling rgSchCmnUlAllocGetAndIns is ok, but prv alloc needs to have nxtHole
8316     * updated, causing another check for prv */
8317    RgSchUlAlloc *prv = hole->prvAlloc;
8318
8319    if (prv)
8320    {
8321       if (hole->start == prv->nxtHole->start)
8322       {
8323          prv->nxtHole = NULLP;
8324       }
8325       alloc = rgSCHUtlUlAllocGetAdjNxt(sf->allocDb, prv);
8326    }
8327    else
8328    {
8329       alloc = rgSCHUtlUlAllocGetFirst(sf->allocDb);
8330    }
8331
8332    RGSCH_NULL_CHECK( 0, alloc);
8333    alloc->prvHole = NULLP;
8334    alloc->nxtHole = hole;
8335    hole->prvAlloc = alloc;
8336
8337    alloc->sbStart = hole->start;
8338    alloc->numSb = numSb;
8339    hole->start += numSb;
8340    hole->num -= numSb;
8341
8342    rgSCHUtlUlHoleDecr(sf->holeDb, hole);
8343
8344    /* UL_ALLOC_CHANGES*/
8345    alloc->allocDbRef = (void*)sf->allocDb;
8346    alloc->holeDbRef  = (void*)sf->holeDb;
8347
8348    return (alloc);
8349 }
8350
8351 /***********************************************************
8352  *
8353  *     Func : rgSCHUtlUlAllocFirst
8354  *
8355  *     Desc : Get first alloc in slot
8356  *
8357  *     Ret  : RgSchUlAlloc *
8358  *
8359  *     Notes:
8360  *
8361  *     File :
8362  *
8363  **********************************************************/
8364 #ifdef ANSI
8365 RgSchUlAlloc *rgSCHUtlUlAllocFirst
8366 (
8367 RgSchUlSf *sf
8368 )
8369 #else
8370 RgSchUlAlloc *rgSCHUtlUlAllocFirst(sf)
8371 RgSchUlSf *sf;
8372 #endif
8373 {
8374    return (sf->allocDb->first);
8375 }
8376
8377 /***********************************************************
8378  *
8379  *     Func : rgSCHUtlUlAllocNxt
8380  *
8381  *     Desc : Get next alloc
8382  *
8383  *     Ret  : RgSchUlAlloc *
8384  *
8385  *     Notes:
8386  *
8387  *     File :
8388  *
8389  **********************************************************/
8390 #ifdef ANSI
8391 RgSchUlAlloc *rgSCHUtlUlAllocNxt
8392 (
8393 RgSchUlSf    *sf,
8394 RgSchUlAlloc *alloc
8395 )
8396 #else
8397 RgSchUlAlloc *rgSCHUtlUlAllocNxt(sf, alloc)
8398 RgSchUlSf    *sf;
8399 RgSchUlAlloc *alloc;
8400 #endif
8401 {
8402    UNUSED(sf);
8403    return (alloc->nxt);
8404 }
8405
8406 /***********************************************************
8407  *
8408  *     Func : rgSCHUtlUlAllocGetAdjNxt
8409  *
8410  *     Desc : Get alloc which is immediately after the passed one.
8411  *            1. Gets alloc from mem.
8412  *            2. Inserts alloc into list (between prv and
8413  *                prv->nxt, prv is not NULLP).
8414  *            3. Increments alloc count.
8415  *            Note 1: Holes are not dealt with here.
8416  *            Note 2: Assumes prv to be NULL.
8417  *
8418  *     Ret  : RgSchUlAlloc *
8419  *
8420  *     Notes:
8421  *
8422  *     File :
8423  *
8424  **********************************************************/
8425 #ifdef ANSI
8426 RgSchUlAlloc *rgSCHUtlUlAllocGetAdjNxt
8427 (
8428 RgSchUlAllocDb *db,
8429 RgSchUlAlloc   *prv
8430 )
8431 #else
8432 RgSchUlAlloc *rgSCHUtlUlAllocGetAdjNxt(db, prv)
8433 RgSchUlAllocDb *db;
8434 RgSchUlAlloc   *prv;
8435 #endif
8436 {
8437    RgSchUlAlloc *alloc = rgSCHUtlUlAllocMemGet(&db->mem);
8438    RgSchUlAlloc *nxt = prv->nxt;
8439
8440 #if (ERRCLASS & ERRCLS_DEBUG)
8441    if ( alloc == NULLP )
8442    {
8443        return  ( NULLP );
8444    }
8445 #endif
8446    alloc->prv = prv;
8447    alloc->nxt = nxt;
8448    prv->nxt = alloc;
8449    if (nxt)
8450    {
8451       nxt->prv = alloc;
8452    }
8453
8454    ++db->count;
8455
8456    return (alloc);
8457 }
8458
8459 /***********************************************************
8460  *
8461  *     Func : rgSCHUtlUlAllocGetFirst
8462  *
8463  *     Desc : Get alloc which is to be the first one in the alloc list
8464  *            1. Gets alloc from mem.
8465  *            2. Inserts alloc as first element into list.
8466  *            3. Increments alloc count.
8467  *            Note 1: Holes are not dealt with here.
8468  *            Note 2: prv to necessarily NULLP.
8469  *
8470  *     Ret  : RgSchUlAlloc *
8471  *
8472  *     Notes:
8473  *
8474  *     File :
8475  *
8476  **********************************************************/
8477 #ifdef ANSI
8478 RgSchUlAlloc *rgSCHUtlUlAllocGetFirst
8479 (
8480 RgSchUlAllocDb *db
8481 )
8482 #else
8483 RgSchUlAlloc *rgSCHUtlUlAllocGetFirst(db)
8484 RgSchUlAllocDb *db;
8485 #endif
8486 {
8487    RgSchUlAlloc *alloc = rgSCHUtlUlAllocMemGet(&db->mem);
8488    RgSchUlAlloc *nxt = db->first;
8489
8490 #if (ERRCLASS & ERRCLS_DEBUG)
8491     if ( alloc == NULLP )
8492     {
8493        return  ( NULLP );
8494     }
8495 #endif
8496
8497    alloc->prv = NULLP;
8498    alloc->nxt = nxt;
8499    if (nxt)
8500    {
8501       nxt->prv = alloc;
8502    }
8503    db->first = alloc;
8504
8505    ++db->count;
8506
8507    return (alloc);
8508 }
8509
8510 /* UL_ALLOC_ENHANCEMENT */
8511 /***********************************************************
8512  *
8513  *     Func : rgSCHUtlUlHoleAddAllocation
8514  *
8515  *     Desc : On freeing an alloc, add to hole
8516  *
8517  *     Ret  : Void
8518  *
8519  *     Notes:
8520  *
8521  *     File :
8522  *
8523  **********************************************************/
8524 #ifdef ANSI
8525 Void rgSCHUtlUlHoleAddAllocation
8526 (
8527 RgSchUlAlloc *alloc
8528 )
8529 #else
8530 Void rgSCHUtlUlHoleAddAllocation(alloc)
8531 RgSchUlAlloc *alloc;
8532 #endif
8533 {
8534    /* Note: rgSchCmnUlHoleUpdAllocLnks function that is used should not exist as
8535     * one, if such excessive branching is done (AllocNone, AllocNoPrv etc).
8536     * The excessive branching is meant to utilise the knowledge of whether prv
8537     * and nxt allocs exist or not. Hence for each kind (none, noprv, nonxt,
8538     * both), there should be a rgSchCmnUlHoleUpdAllocLnks... function (such as
8539     * rgSchCmnUlHoleUpdAllocLnksNone/NoPrv etc. */
8540    RgSchUlHoleDb *db = alloc->holeDbRef;
8541    RgSchUlHole *prv = alloc->prvHole;
8542    RgSchUlHole *nxt = alloc->nxtHole;
8543
8544    if (prv)
8545    {
8546       if (nxt)
8547       {
8548          rgSCHUtlUlHoleJoin(db, prv, nxt, alloc);
8549       }
8550       else
8551          rgSCHUtlUlHoleExtndRight(db, prv, alloc);
8552    }
8553    else
8554    {
8555       if (nxt)
8556       {
8557          rgSCHUtlUlHoleExtndLeft(db, nxt, alloc);
8558       }
8559       else
8560          rgSCHUtlUlHoleNew(db, alloc);
8561    }
8562    RETVOID;
8563 }
8564
8565
8566 /***********************************************************
8567  *
8568  *     Func : rgSCHUtlUlAllocRelease
8569  *
8570  *     Desc : Releases an uplink allocation, only take alloc ptr
8571  *
8572  *     Ret  : Void
8573  *
8574  *     Notes:
8575  *
8576  *     File :
8577  *
8578  **********************************************************/
8579 #ifdef ANSI
8580 Void rgSCHUtlUlAllocRelease
8581 (
8582 RgSchUlAlloc *alloc
8583 )
8584 #else
8585 Void rgSCHUtlUlAllocRelease(alloc)
8586 RgSchUlAlloc *alloc;
8587 #endif
8588 {
8589    RgSchUlAllocDb *allocDb = alloc->allocDbRef;
8590    RgSchUlAlloc   *prv = alloc->prv;
8591    RgSchUlAlloc   *nxt = alloc->nxt;
8592
8593    alloc->ue = NULLP;
8594    alloc->raCb = NULLP;
8595    alloc->isAdaptive = FALSE;
8596
8597    if (prv)
8598    {
8599       prv->nxt = nxt;
8600       if (nxt)           /* general case: this allocation lies btw two */
8601       {
8602          nxt->prv = prv;
8603       }
8604    }
8605    else
8606    {
8607       allocDb->first = nxt;
8608       if (nxt)
8609       {
8610          nxt->prv = NULLP;
8611       }
8612    }
8613    --allocDb->count;
8614    rgSCHUtlUlHoleAddAllocation(alloc);
8615    rgSCHUtlUlAllocMemRls(&allocDb->mem, alloc);
8616
8617    RETVOID;
8618 }
8619
8620
8621 /***********************************************************
8622  *
8623  *     Func : rgSCHUtlUlAllocRls
8624  *
8625  *     Desc : Releases an uplink allocation
8626  *
8627  *     Ret  : Void
8628  *
8629  *     Notes:
8630  *
8631  *     File :
8632  *
8633  **********************************************************/
8634 #ifdef ANSI
8635 Void rgSCHUtlUlAllocRls
8636 (
8637 RgSchUlSf    *sf,
8638 RgSchUlAlloc *alloc
8639 )
8640 #else
8641 Void rgSCHUtlUlAllocRls(sf, alloc)
8642 RgSchUlSf    *sf;
8643 RgSchUlAlloc *alloc;
8644 #endif
8645 {
8646    RgSchUlAllocDb *allocDb = sf->allocDb;
8647    RgSchUlAlloc   *prv = alloc->prv;
8648    RgSchUlAlloc   *nxt = alloc->nxt;
8649
8650    alloc->ue = NULLP;
8651    alloc->raCb = NULLP;
8652    alloc->isAdaptive = FALSE;
8653
8654    if(allocDb->count)
8655    {
8656       if (prv)
8657       {
8658          prv->nxt = nxt;
8659          if (nxt)           /* general case: this allocation lies btw two */
8660          {
8661             nxt->prv = prv;
8662          }
8663       }
8664       else
8665       {
8666          allocDb->first = nxt;
8667          if (nxt)
8668          {
8669             nxt->prv = NULLP;
8670          }
8671       }
8672       --allocDb->count;
8673       rgSCHUtlUlHoleAddAlloc(sf, alloc);
8674       rgSCHUtlUlAllocMemRls(&allocDb->mem, alloc);
8675    }
8676    else
8677    {
8678
8679       printf("\nError: allocDb->count is ZERO ====\n");
8680    }
8681
8682    //printf("\nallocDb->count:%u\n",allocDb->count);
8683
8684    RETVOID;
8685 }
8686
8687 /***********************************************************
8688  *
8689  *     Func : rgSCHUtlUlHoleFirst
8690  *
8691  *     Desc : Get first (largest) hole
8692  *
8693  *     Ret  : RgSchUlHole *
8694  *
8695  *     Notes:
8696  *
8697  *     File :
8698  *
8699  **********************************************************/
8700 #ifdef ANSI
8701 RgSchUlHole *rgSCHUtlUlHoleFirst
8702 (
8703 RgSchUlSf *sf
8704 )
8705 #else
8706 RgSchUlHole *rgSCHUtlUlHoleFirst(sf)
8707 RgSchUlSf *sf;
8708 #endif
8709 {
8710    return (sf->holeDb->first);
8711 }
8712
8713 /***********************************************************
8714  *
8715  *     Func : rgSCHUtlUlHoleNxt
8716  *
8717  *     Desc : Get next largest hole
8718  *
8719  *     Ret  : RgSchUlHole *
8720  *
8721  *     Notes:
8722  *
8723  *     File :
8724  *
8725  **********************************************************/
8726 #ifdef ANSI
8727 RgSchUlHole *rgSCHUtlUlHoleNxt
8728 (
8729 RgSchUlSf   *sf,
8730 RgSchUlHole *hole
8731 )
8732 #else
8733 RgSchUlHole *rgSCHUtlUlHoleNxt(sf, hole)
8734 RgSchUlSf   *sf;
8735 RgSchUlHole *hole;
8736 #endif
8737 {
8738    UNUSED(sf);
8739    return (hole->nxt);
8740 }
8741
8742 /***********************************************************
8743  *
8744  *     Func : rgSCHUtlUlHoleAddAlloc
8745  *
8746  *     Desc : On freeing an alloc, add to hole
8747  *
8748  *     Ret  : Void
8749  *
8750  *     Notes:
8751  *
8752  *     File :
8753  *
8754  **********************************************************/
8755 #ifdef ANSI
8756 Void rgSCHUtlUlHoleAddAlloc
8757 (
8758 RgSchUlSf    *sf,
8759 RgSchUlAlloc *alloc
8760 )
8761 #else
8762 Void rgSCHUtlUlHoleAddAlloc(sf, alloc)
8763 RgSchUlSf    *sf;
8764 RgSchUlAlloc *alloc;
8765 #endif
8766 {
8767    /* Note: rgSchCmnUlHoleUpdAllocLnks function that is used should not exist as
8768     * one, if such excessive branching is done (AllocNone, AllocNoPrv etc).
8769     * The excessive branching is meant to utilise the knowledge of whether prv
8770     * and nxt allocs exist or not. Hence for each kind (none, noprv, nonxt,
8771     * both), there should be a rgSchCmnUlHoleUpdAllocLnks... function (such as
8772     * rgSchCmnUlHoleUpdAllocLnksNone/NoPrv etc. */
8773    RgSchUlHoleDb *db = sf->holeDb;
8774    RgSchUlHole *prv = alloc->prvHole;
8775    RgSchUlHole *nxt = alloc->nxtHole;
8776
8777    if (prv)
8778    {
8779       if (nxt)
8780       {
8781          rgSCHUtlUlHoleJoin(db, prv, nxt, alloc);
8782       }
8783       else
8784          rgSCHUtlUlHoleExtndRight(db, prv, alloc);
8785    }
8786    else
8787    {
8788       if (nxt)
8789       {
8790          rgSCHUtlUlHoleExtndLeft(db, nxt, alloc);
8791       }
8792       else
8793          rgSCHUtlUlHoleNew(db, alloc);
8794    }
8795
8796    /* increment the number of subbands getting freed to total available list */
8797    sf->availSubbands += alloc->numSb;
8798
8799    RETVOID;
8800 }
8801
8802 /***********************************************************
8803  *
8804  *     Func : rgSCHUtlUlHoleJoin
8805  *
8806  *     Desc : Join two holes (due to alloc being deleted)
8807  *
8808  *     Ret  : Void
8809  *
8810  *     Notes:
8811  *
8812  *     File :
8813  *
8814  **********************************************************/
8815 #ifdef ANSI
8816 Void rgSCHUtlUlHoleJoin
8817 (
8818 RgSchUlHoleDb *db,
8819 RgSchUlHole   *prv,
8820 RgSchUlHole   *nxt,
8821 RgSchUlAlloc  *alloc
8822 )
8823 #else
8824 Void rgSCHUtlUlHoleJoin(db, prv, nxt, alloc)
8825 RgSchUlHoleDb *db;
8826 RgSchUlHole   *prv;
8827 RgSchUlHole   *nxt;
8828 RgSchUlAlloc  *alloc;
8829 #endif
8830 {
8831    prv->num += alloc->numSb + nxt->num;
8832    rgSCHUtlUlHoleRls(db, nxt);
8833    rgSCHUtlUlHoleIncr(db, prv);
8834    rgSCHUtlUlHoleUpdAllocLnks(prv, alloc->prv, alloc->nxt);
8835
8836    RETVOID;
8837 }
8838
8839 /***********************************************************
8840  *
8841  *     Func : rgSCHUtlUlHoleExtndRight
8842  *
8843  *     Desc : Extend hole due to alloc coming 'after' the hole
8844  *            being deleted
8845  *
8846  *     Ret  : Void
8847  *
8848  *     Notes:
8849  *
8850  *     File :
8851  *
8852  **********************************************************/
8853 #ifdef ANSI
8854 Void rgSCHUtlUlHoleExtndRight
8855 (
8856 RgSchUlHoleDb *db,
8857 RgSchUlHole   *prv,
8858 RgSchUlAlloc  *alloc
8859 )
8860 #else
8861 Void rgSCHUtlUlHoleExtndRight(db, prv, alloc)
8862 RgSchUlHoleDb *db;
8863 RgSchUlHole   *prv;
8864 RgSchUlAlloc  *alloc;
8865 #endif
8866 {
8867    prv->num += alloc->numSb;
8868    rgSCHUtlUlHoleIncr(db, prv);
8869    rgSCHUtlUlHoleUpdAllocLnks(prv, alloc->prv, alloc->nxt);
8870    RETVOID;
8871 }
8872
8873 /***********************************************************
8874  *
8875  *     Func : rgSCHUtlUlHoleExtndLeft
8876  *
8877  *     Desc : Extend hole due to alloc coming 'before' the hole
8878  *            being deleted
8879  *
8880  *     Ret  : Void
8881  *
8882  *     Notes:
8883  *
8884  *     File :
8885  *
8886  **********************************************************/
8887 #ifdef ANSI
8888 Void rgSCHUtlUlHoleExtndLeft
8889 (
8890 RgSchUlHoleDb *db,
8891 RgSchUlHole   *nxt,
8892 RgSchUlAlloc  *alloc
8893 )
8894 #else
8895 Void rgSCHUtlUlHoleExtndLeft(db, nxt, alloc)
8896 RgSchUlHoleDb *db;
8897 RgSchUlHole   *nxt;
8898 RgSchUlAlloc  *alloc;
8899 #endif
8900 {
8901    nxt->num += alloc->numSb;
8902    nxt->start = alloc->sbStart;
8903    rgSCHUtlUlHoleIncr(db, nxt);
8904    rgSCHUtlUlHoleUpdAllocLnks(nxt, alloc->prv, alloc->nxt);
8905    RETVOID;
8906 }
8907
8908 /***********************************************************
8909  *
8910  *     Func : rgSCHUtlUlHoleNew
8911  *
8912  *     Desc : Create new hole due to alloc being deleted
8913  *
8914  *     Ret  : Void
8915  *
8916  *     Notes:
8917  *
8918  *     File :
8919  *
8920  **********************************************************/
8921 #ifdef ANSI
8922 Void rgSCHUtlUlHoleNew
8923 (
8924 RgSchUlHoleDb *db,
8925 RgSchUlAlloc  *alloc
8926 )
8927 #else
8928 Void rgSCHUtlUlHoleNew(db, alloc)
8929 RgSchUlHoleDb *db;
8930 RgSchUlAlloc  *alloc;
8931 #endif
8932 {
8933    RgSchUlHole *hole = rgSCHUtlUlHoleMemGet(&db->mem);
8934 #if (ERRCLASS & ERRCLS_DEBUG)
8935    if ( hole == NULLP )
8936    {
8937       RETVOID;
8938    }
8939 #endif
8940    hole->start = alloc->sbStart;
8941    hole->num = alloc->numSb;
8942    ++db->count;
8943    rgSCHUtlUlHoleIns(db, hole);
8944    rgSCHUtlUlHoleUpdAllocLnks(hole, alloc->prv, alloc->nxt);
8945    RETVOID;
8946 }
8947
8948 /***********************************************************
8949  *
8950  *     Func : rgSCHUtlUlHoleUpdAllocLnks
8951  *
8952  *     Desc : Update alloc links in hole
8953  *
8954  *     Ret  : Void
8955  *
8956  *     Notes:
8957  *
8958  *     File :
8959  *
8960  **********************************************************/
8961 #ifdef ANSI
8962 Void rgSCHUtlUlHoleUpdAllocLnks
8963 (
8964 RgSchUlHole  *hole,
8965 RgSchUlAlloc *prvAlloc,
8966 RgSchUlAlloc *nxtAlloc
8967 )
8968 #else
8969 Void rgSCHUtlUlHoleUpdAllocLnks(hole, prvAlloc, nxtAlloc)
8970 RgSchUlHole  *hole;
8971 RgSchUlAlloc *prvAlloc;
8972 RgSchUlAlloc *nxtAlloc;
8973 #endif
8974 {
8975    if (prvAlloc)
8976    {
8977       prvAlloc->nxtHole = hole;
8978    }
8979    if (nxtAlloc)
8980    {
8981       nxtAlloc->prvHole = hole;
8982    }
8983    hole->prvAlloc = prvAlloc;
8984    hole->nxtAlloc = nxtAlloc;
8985    RETVOID;
8986 }
8987
8988
8989 /***********************************************************
8990  *
8991  *     Func : rgSCHUtlUlHoleIns
8992  *
8993  *     Desc : Insert (newly created) hole in sorted list of holes.
8994  *            Searches linearly, beginning with the largest hole.
8995  *
8996  *     Ret  : Void
8997  *
8998  *     Notes:
8999  *
9000  *     File :
9001  *
9002  **********************************************************/
9003 #ifdef ANSI
9004 Void rgSCHUtlUlHoleIns
9005 (
9006 RgSchUlHoleDb *db,
9007 RgSchUlHole   *hole
9008 )
9009 #else
9010 Void rgSCHUtlUlHoleIns(db, hole)
9011 RgSchUlHoleDb *db;
9012 RgSchUlHole   *hole;
9013 #endif
9014 {
9015    RgSchUlHole *cur;
9016
9017    if ((cur = db->first) != NULLP)
9018    {
9019       RgSchUlHole *nxt;
9020       if (cur->num < hole->num)
9021       {
9022          /* Add at front */
9023          hole->nxt = cur;
9024          cur->prv = hole;
9025          db->first = hole;
9026          hole->prv = NULLP;
9027          RETVOID;
9028       }
9029
9030       for (nxt = cur->nxt; nxt; cur = nxt, nxt = nxt->nxt)
9031       {
9032          if (nxt->num < hole->num)
9033          {
9034             /* Insert hole:  cur <-> hole <-> nxt */
9035             cur->nxt = hole;
9036             hole->prv = cur;
9037             hole->nxt = nxt;
9038             nxt->prv = hole;
9039             RETVOID;
9040          }
9041       }
9042
9043       /* Add at end */
9044       cur->nxt = hole;
9045       hole->prv = cur;
9046       hole->nxt = NULLP;
9047       RETVOID;
9048    }
9049
9050    /* This is the first hole */
9051    db->first = hole;
9052    hole->prv = NULLP; /* may not be needed */
9053    hole->nxt = NULLP;
9054    RETVOID;
9055 }
9056
9057
9058 /***********************************************************
9059  *
9060  *     Func : rgSCHUtlUlHoleIncr
9061  *
9062  *     Desc : hole->num has increeased, reposition in sorted
9063  *            list if needed
9064  *
9065  *     Ret  : Void
9066  *
9067  *     Notes:
9068  *
9069  *     File :
9070  *
9071  **********************************************************/
9072 #ifdef ANSI
9073 Void rgSCHUtlUlHoleIncr
9074 (
9075 RgSchUlHoleDb *db,
9076 RgSchUlHole   *hole
9077 )
9078 #else
9079 Void rgSCHUtlUlHoleIncr(db, hole)
9080 RgSchUlHoleDb *db;
9081 RgSchUlHole   *hole;
9082 #endif
9083 {
9084    RgSchUlHole *cur;
9085
9086    if ((cur = hole->prv) != NULLP)
9087    {
9088       RgSchUlHole *prv;
9089
9090       if (cur->num > hole->num)
9091       {
9092          RETVOID;
9093       }
9094
9095       /* Remove hole from current position */
9096       cur->nxt = hole->nxt;
9097       if (hole->nxt)
9098       {
9099          hole->nxt->prv = cur;
9100       }
9101
9102       for (prv = cur->prv; prv; cur = prv, prv = prv->prv)
9103       {
9104          if (prv->num > hole->num)
9105          {
9106             /* Insert hole:  prv <-> hole <-> cur */
9107             prv->nxt = hole;
9108             hole->prv = prv;
9109             hole->nxt = cur;
9110             cur->prv = hole;
9111             RETVOID;
9112          }
9113       }
9114
9115       /* Add at front */
9116       hole->nxt = cur;
9117       cur->prv = hole;
9118       db->first = hole;
9119       hole->prv = NULLP;
9120       RETVOID;
9121    }
9122    RETVOID;
9123 }
9124
9125 /***********************************************************
9126  *
9127  *     Func : rgSCHUtlUlHoleDecr
9128  *
9129  *     Desc : hole->num has decreeased, reposition in sorted
9130  *            list if needed
9131  *
9132  *     Ret  : Void
9133  *
9134  *     Notes:
9135  *
9136  *     File :
9137  *
9138  **********************************************************/
9139 #ifdef ANSI
9140 Void rgSCHUtlUlHoleDecr
9141 (
9142 RgSchUlHoleDb *db,
9143 RgSchUlHole   *hole
9144 )
9145 #else
9146 Void rgSCHUtlUlHoleDecr(db, hole)
9147 RgSchUlHoleDb *db;
9148 RgSchUlHole   *hole;
9149 #endif
9150 {
9151    RgSchUlHole *cur;
9152
9153    if ((cur = hole->nxt) != NULLP)
9154    {
9155       RgSchUlHole *nxt;
9156
9157       if (cur->num < hole->num)
9158       {
9159          RETVOID;
9160       }
9161
9162       /* Remove hole from current position */
9163       cur->prv = hole->prv;
9164       if (hole->prv)
9165       {
9166          hole->prv->nxt = cur;
9167       }
9168       else /* no prv, so cur to replace hole as first in list */
9169       {
9170          db->first = cur;
9171       }
9172
9173       for (nxt = cur->nxt; nxt; cur = nxt, nxt = nxt->nxt)
9174       {
9175          if (nxt->num < hole->num)
9176          {
9177             /* Insert hole:  cur <-> hole <-> nxt */
9178             cur->nxt = hole;
9179             hole->prv = cur;
9180             hole->nxt = nxt;
9181             nxt->prv = hole;
9182             RETVOID;
9183          }
9184       }
9185
9186       /* Add at end */
9187       cur->nxt = hole;
9188       hole->prv = cur;
9189       hole->nxt = NULLP;
9190       RETVOID;
9191    }
9192    RETVOID;
9193 }
9194
9195 /***********************************************************
9196  *
9197  *     Func : rgSCHUtlUlHoleRls
9198  *
9199  *     Desc : Releases hole.
9200  *            1. Decrements hole count.
9201  *            2. Deletes hole from list.
9202  *            3. Frees hole (hole memory release).
9203  *
9204  *     Ret  : Void
9205  *
9206  *     Notes:
9207  *
9208  *     File :
9209  *
9210  **********************************************************/
9211 #ifdef ANSI
9212 Void rgSCHUtlUlHoleRls
9213 (
9214 RgSchUlHoleDb *db,
9215 RgSchUlHole   *hole
9216 )
9217 #else
9218 Void rgSCHUtlUlHoleRls(db, hole)
9219 RgSchUlHoleDb *db;
9220 RgSchUlHole   *hole;
9221 #endif
9222 {
9223    RgSchUlHole *prv = hole->prv;
9224    RgSchUlHole *nxt = hole->nxt;
9225
9226    --db->count;
9227    if (prv)
9228    {
9229       prv->nxt = nxt;
9230       if (nxt)
9231       {
9232          nxt->prv = prv;
9233       }
9234    }
9235    else
9236    {
9237       db->first = nxt;
9238       if (nxt)
9239       {
9240          nxt->prv = NULLP;
9241       }
9242    }
9243
9244    rgSCHUtlUlHoleMemRls(&db->mem, hole);
9245    RETVOID;
9246 }
9247
9248
9249 /***********************************************************
9250  *
9251  *     Func : rgSCHUtlUlAllocMemInit
9252  *
9253  *     Desc : Initialises alloc free pool
9254  *
9255  *     Ret  : S16 (ROK/RFAILED)
9256  *
9257  *     Notes:
9258  *
9259  *     File :
9260  *
9261  **********************************************************/
9262 #ifdef ANSI
9263 S16 rgSCHUtlUlAllocMemInit
9264 (
9265 RgSchCellCb     *cell,
9266 RgSchUlAllocMem *mem,
9267 U8           maxAllocs
9268 )
9269 #else
9270 S16 rgSCHUtlUlAllocMemInit(cell, mem, maxAllocs)
9271 RgSchCellCb     *cell;
9272 RgSchUlAllocMem *mem;
9273 U8           maxAllocs;
9274 #endif
9275 {
9276    S16 ret;
9277    RgSchUlAlloc *allocs;
9278
9279    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&allocs,
9280                            maxAllocs * sizeof(*allocs));
9281    if (ret != ROK)
9282    {
9283       return (ret);
9284    }
9285    mem->allocs = allocs;
9286    mem->maxAllocs = maxAllocs;
9287    if (mem->maxAllocs == 1)
9288    {
9289       allocs[0].prv = NULLP;
9290       allocs[0].nxt = NULLP;
9291    }
9292    else
9293    {
9294       U8 i;
9295       allocs[0].prv = NULLP;
9296       allocs[0].nxt = &allocs[1];
9297       for (i = 1; i < mem->maxAllocs - 1; ++i)
9298       {
9299          allocs[i].prv = &allocs[i-1];
9300          allocs[i].nxt = &allocs[i+1];
9301       }
9302       allocs[i].prv = &allocs[i-1];
9303       allocs[i].nxt = NULLP;
9304    }
9305    mem->firstFree = &allocs[0];
9306    return ROK;
9307 }
9308
9309 /***********************************************************
9310  *
9311  *     Func : rgSCHUtlUlAllocMemDeinit
9312  *
9313  *     Desc : Deinitialises alloc free pool
9314  *
9315  *     Ret  : Void
9316  *
9317  *     Notes:
9318  *
9319  *     File :
9320  *
9321  **********************************************************/
9322 #ifdef ANSI
9323 Void rgSCHUtlUlAllocMemDeinit
9324 (
9325 RgSchCellCb     *cell,
9326 RgSchUlAllocMem *mem
9327 )
9328 #else
9329 Void rgSCHUtlUlAllocMemDeinit(cell, mem)
9330 RgSchCellCb     *cell;
9331 RgSchUlAllocMem *mem;
9332 #endif
9333 {
9334    /* ccpu00117052 - MOD - Passing double pointer
9335    for proper NULLP assignment*/
9336    rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(mem->allocs)),
9337                     mem->maxAllocs * sizeof(*mem->allocs));
9338    mem->maxAllocs = 0;
9339    mem->firstFree = NULLP;
9340    RETVOID;
9341 }
9342
9343 /***********************************************************
9344  *
9345  *     Func : rgSCHUtlUlHoleMemInit
9346  *
9347  *     Desc : Initialises hole free pool. Assumes maxHoles
9348  *            to be at least 2.
9349  *
9350  *     Ret  : S16 (ROK/RFAILED)
9351  *
9352  *     Notes:
9353  *
9354  *     File :
9355  *
9356  **********************************************************/
9357 #ifdef ANSI
9358 S16 rgSCHUtlUlHoleMemInit
9359 (
9360 RgSchCellCb    *cell,
9361 RgSchUlHoleMem *mem,
9362 U8          maxHoles,
9363 RgSchUlHole    **holeRef
9364 )
9365 #else
9366 S16 rgSCHUtlUlHoleMemInit(cell, mem, maxHoles, holeRef)
9367 RgSchCellCb     *cell;
9368 RgSchUlHoleMem *mem;
9369 U8          maxHoles;
9370 RgSchUlHole    **holeRef;
9371 #endif
9372 {
9373    S16 ret;
9374    RgSchUlHole *holes;
9375
9376    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&holes,
9377                            maxHoles * sizeof(*holes));
9378    if (ret != ROK)
9379    {
9380       return (ret);
9381    }
9382
9383    mem->holes = holes;
9384    mem->maxHoles = maxHoles;
9385
9386    /* first hole is taken up */
9387    holes[0].prv = NULLP; /* not needed */
9388    holes[0].nxt = NULLP; /* not needed */
9389    *holeRef = &holes[0];
9390
9391    if (mem->maxHoles == 2)
9392    {
9393       holes[1].prv = NULLP; /* may not be needed */
9394       holes[1].nxt = NULLP; /* may not be needed */
9395    }
9396    else
9397    {
9398       U8 i;
9399       holes[1].prv = NULLP;
9400       holes[0].nxt = &holes[1];
9401       for (i = 1; i < mem->maxHoles - 1; ++i)
9402       {
9403          holes[i].prv = &holes[i-1];
9404          holes[i].nxt = &holes[i+1];
9405       }
9406       holes[i].prv = &holes[i-1];
9407       holes[i].nxt = NULLP;
9408    }
9409    mem->firstFree = &holes[1];
9410
9411    return ROK;
9412 }
9413
9414 /***********************************************************
9415  *
9416  *     Func : rgSCHUtlUlHoleMemDeinit
9417  *
9418  *     Desc : Deinitialises hole free pool
9419  *
9420  *     Ret  : Void
9421  *
9422  *     Notes:
9423  *
9424  *     File :
9425  *
9426  **********************************************************/
9427 #ifdef ANSI
9428 Void rgSCHUtlUlHoleMemDeinit
9429 (
9430 RgSchCellCb    *cell,
9431 RgSchUlHoleMem *mem
9432 )
9433 #else
9434 Void rgSCHUtlUlHoleMemDeinit(cell, mem)
9435 RgSchCellCb    *cell;
9436 RgSchUlHoleMem *mem;
9437 #endif
9438 {
9439    /* ccpu00117052 - MOD - Passing double pointer
9440    for proper NULLP assignment*/
9441    rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(mem->holes)),
9442                     mem->maxHoles * sizeof(*mem->holes));
9443    mem->maxHoles = 0;
9444    mem->firstFree = NULLP;
9445    RETVOID;
9446 }
9447
9448 /***********************************************************
9449  *
9450  *     Func : rgSCHUtlUlAllocMemGet
9451  *
9452  *     Desc : Gets an 'alloc' from the free pool
9453  *
9454  *     Ret  : RgSchUlAlloc *
9455  *
9456  *     Notes:
9457  *
9458  *     File :
9459  *
9460  **********************************************************/
9461 #ifdef ANSI
9462 RgSchUlAlloc *rgSCHUtlUlAllocMemGet
9463 (
9464 RgSchUlAllocMem *mem
9465 )
9466 #else
9467 RgSchUlAlloc *rgSCHUtlUlAllocMemGet(mem)
9468 RgSchUlAllocMem *mem;
9469 #endif
9470 {
9471    RgSchUlAlloc *alloc;
9472
9473 #if (ERRCLASS & ERRCLS_DEBUG)
9474    if (mem->firstFree == NULLP)
9475    {
9476       return (NULLP);
9477    }
9478 #endif
9479
9480    alloc = mem->firstFree;
9481    mem->firstFree = alloc->nxt;
9482    alloc->nxt = NULLP; /* probably not needed */
9483    /* alloc->prv might already be NULLP, in case was needed to set it to NULLP */
9484
9485    return (alloc);
9486 }
9487
9488 /***********************************************************
9489  *
9490  *     Func : rgSCHUtlUlAllocMemRls
9491  *
9492  *     Desc : Returns an 'alloc' to the free pool
9493  *
9494  *     Ret  :
9495  *
9496  *     Notes:
9497  *
9498  *     File :
9499  *
9500  **********************************************************/
9501 #ifdef ANSI
9502 Void rgSCHUtlUlAllocMemRls
9503 (
9504 RgSchUlAllocMem *mem,
9505 RgSchUlAlloc    *alloc
9506 )
9507 #else
9508 Void rgSCHUtlUlAllocMemRls(mem, alloc)
9509 RgSchUlAllocMem *mem;
9510 RgSchUlAlloc    *alloc;
9511 #endif
9512 {
9513    alloc->prv = NULLP;
9514
9515    alloc->nxt = mem->firstFree;
9516    if (mem->firstFree != NULLP)
9517    {
9518       mem->firstFree->prv = alloc;
9519    }
9520    mem->firstFree = alloc;
9521    RETVOID;
9522 }
9523
9524 /***********************************************************
9525  *
9526  *     Func : rgSCHUtlUlHoleMemGet
9527  *
9528  *     Desc : Gets a 'hole' from the free pool
9529  *
9530  *     Ret  : RgSchUlHole *
9531  *
9532  *     Notes:
9533  *
9534  *     File :
9535  *
9536  **********************************************************/
9537 #ifdef ANSI
9538 RgSchUlHole *rgSCHUtlUlHoleMemGet
9539 (
9540 RgSchUlHoleMem *mem
9541 )
9542 #else
9543 RgSchUlHole *rgSCHUtlUlHoleMemGet(mem)
9544 RgSchUlHoleMem *mem;
9545 #endif
9546 {
9547    RgSchUlHole *hole;
9548
9549 #if (ERRCLASS & ERRCLS_DEBUG)
9550    if (mem->firstFree == NULLP)
9551    {
9552       return (NULLP);
9553    }
9554 #endif
9555
9556    hole = mem->firstFree;
9557    mem->firstFree = hole->nxt;
9558    mem->firstFree->prv = NULLP; /* may not be needed, under error class */
9559    hole->nxt = NULLP; /* probably not needed */
9560    /* hole->prv is might already be NULLP, in case was needed to set it to NULLP */
9561
9562    return (hole);
9563 }
9564
9565 /***********************************************************
9566  *
9567  *     Func : rgSCHUtlUlHoleMemRls
9568  *
9569  *     Desc : Returns a 'hole' to the free pool
9570  *
9571  *     Ret  : Void
9572  *
9573  *     Notes:
9574  *
9575  *     File :
9576  *
9577  **********************************************************/
9578 #ifdef ANSI
9579 Void rgSCHUtlUlHoleMemRls
9580 (
9581 RgSchUlHoleMem *mem,
9582 RgSchUlHole    *hole
9583 )
9584 #else
9585 Void rgSCHUtlUlHoleMemRls(mem, hole)
9586 RgSchUlHoleMem *mem;
9587 RgSchUlHole    *hole;
9588 #endif
9589 {
9590    hole->prv = NULLP;
9591
9592    hole->nxt = mem->firstFree;
9593    if (mem->firstFree != NULLP)
9594    {
9595       mem->firstFree->prv = hole;
9596    }
9597    mem->firstFree = hole;
9598    RETVOID;
9599 }
9600
9601 /**
9602  * @brief Get an alloc from the specified position in the BW.
9603  *
9604  * @details
9605  *
9606  *     Function : rgSCHUtlUlGetSpfcAlloc
9607  *
9608  *      - Return an alloc from the specified position in the BW.
9609  *        Note: This function assumes there is always a hole
9610  *              Existing which completely has the specified
9611  *              allocation. The reason for such an assumption is
9612  *              the function's usage as of now guarantees that there
9613  *              will always be such hole. And also for efficiency.
9614  *
9615  *  @param[in]  RgSchUlSf     *sf
9616  *  @param[in]  U8            startSb
9617  *  @param[in]  U8            numSb
9618  *  @return  RgSchUlAlloc*
9619  **/
9620 #ifdef ANSI
9621 RgSchUlAlloc *rgSCHUtlUlGetSpfcAlloc
9622 (
9623 RgSchUlSf       *sf,
9624 U8              startSb,
9625 U8              numSb
9626 )
9627 #else
9628 RgSchUlAlloc *rgSCHUtlUlGetSpfcAlloc(sf, startSb, numSb)
9629 RgSchUlSf       *sf;
9630 U8              startSb;
9631 U8              numSb;
9632 #endif
9633 {
9634    RgSchUlHole     *hole, *nxtHole;
9635    RgSchUlAlloc    *alloc = NULLP;
9636
9637    if ((hole = rgSCHUtlUlHoleFirst(sf)) == NULLP)
9638    {
9639       return (NULLP);
9640    }
9641    do
9642    {
9643       nxtHole = rgSCHUtlUlHoleNxt(sf, hole);
9644       if ((startSb >= hole->start) &&
9645           (startSb+numSb <= hole->start+hole->num))
9646       {
9647          if (startSb != hole->start)
9648          {
9649             /* Create a new hole to accomodate Subbands between
9650              * hole start and req alloc start */
9651             RgSchUlHole *newHole = rgSCHUtlUlHoleMemGet(&(sf->holeDb->mem));
9652
9653 #if (ERRCLASS & ERRCLS_DEBUG)
9654             if ( newHole == NULLP )
9655             {
9656                 return ( NULLP );
9657             }
9658 #endif
9659             newHole->start = hole->start;
9660             newHole->num = startSb - hole->start;
9661             hole->start = startSb;
9662             /* [ccpu00122847]-MOD- Correctly updating the hole->num */
9663             hole->num -= newHole->num;
9664             ++(sf->holeDb->count);
9665             rgSCHUtlUlHoleIns(sf->holeDb, newHole);
9666             newHole->prvAlloc = hole->prvAlloc;
9667             if (newHole->prvAlloc)
9668             {
9669                newHole->prvAlloc->nxtHole = newHole;
9670             }
9671             if (numSb == hole->num)
9672             {
9673                alloc = rgSCHUtlUlAllocGetCompHole(sf, hole);
9674             }
9675             else
9676             {
9677                alloc = rgSCHUtlUlAllocGetPartHole(sf, numSb, hole);
9678             }
9679             alloc->prvHole = newHole;
9680             newHole->nxtAlloc = alloc;
9681          }
9682          else /* Hole start and req alloc start are same */
9683          {
9684             if (numSb == hole->num)
9685             {
9686                alloc = rgSCHUtlUlAllocGetCompHole(sf, hole);
9687             }
9688             else
9689             {
9690                alloc = rgSCHUtlUlAllocGetPartHole(sf, numSb, hole);
9691             }
9692          }
9693          break;
9694       }
9695    } while ((hole = nxtHole) != NULLP);
9696    return (alloc);
9697 }
9698 #ifdef LTE_L2_MEAS
9699 /**
9700  * @brief  Validates the qci values
9701  *
9702  * @details
9703  *
9704  *     Function :rgSCHUtlValidateQci
9705  *
9706  *  @param[in]  RgSchCellCb     *cellCb
9707  *  @param[in]  U8              numQci
9708  *  @param[out] U8              *qci
9709  *  @return  S16
9710  *           ROK
9711  *           RFAILED
9712  **/
9713 #ifdef ANSI
9714 PRIVATE S16 rgSCHUtlValidateQci
9715 (
9716 RgSchCellCb  *cellCb,
9717 U8           numQci,
9718 U8           *qci
9719 )
9720 #else
9721 PRIVATE S16 rgSCHUtlValidateQci(cellCb, numQci, qci)
9722 RgSchCellCb  *cellCb;
9723 U8           numQci;
9724 U8           *qci;
9725 #endif
9726 {
9727    U8        qciIdx;
9728    U8        qciVal;
9729
9730
9731    for(qciIdx = 0; qciIdx < numQci; qciIdx++)
9732    {
9733       qciVal = qci[qciIdx];
9734       if(qciVal == 0 || qciVal > 9)
9735       {
9736          return RFAILED;
9737       }
9738       if(qciVal != cellCb->qciArray[qciVal].qci)
9739       {
9740          return RFAILED;
9741       }
9742    }
9743
9744    return ROK;
9745 }/* rgSCHUtlValidateQci */
9746 /**
9747  * @brief  Validates the measurement request parameters.
9748  *
9749  * @details
9750  *
9751  *     Function :rgSCHUtlValidateMeasReq
9752  *
9753  *  @param[in]  RgSchCellCb        *cellCb
9754  *  @param[in]  LrgSchMeasReqInfo  *schL2MeasInfo
9755  *  @param[out] RgSchErrInfo       *err
9756  *  @return  RgSchUlAlloc*
9757  **/
9758 #ifdef ANSI
9759 S16 rgSCHUtlValidateMeasReq
9760 (
9761 RgSchCellCb       *cellCb, 
9762 LrgSchMeasReqInfo *schL2MeasInfo,
9763 RgSchErrInfo      *err
9764 )
9765 #else
9766 S16 rgSCHUtlValidateMeasReq(cellCb, schL2MeasInfo, err)
9767 RgSchCellCb       *cellCb;
9768 LrgSchMeasReqInfo *schL2MeasInfo;
9769 RgSchErrInfo      *err;
9770 #endif
9771 {
9772    U16    measType;
9773    S16   ret;
9774
9775
9776    measType = schL2MeasInfo->measType;
9777
9778    if((measType == 0) ||
9779        measType > 2047)
9780    {
9781       err->errType = RGSCHERR_SCH_INVALID_MEAS_TYPE;
9782       err->errCause = RGSCHERR_SCH_L2MEAS;
9783       return RFAILED;
9784    }
9785    if((schL2MeasInfo->timePrd !=0) &&
9786       (measType & LRG_L2MEAS_AVG_PRB_PER_QCI_DL) &&
9787       ((schL2MeasInfo->avgPrbQciDl.numQci > LRG_MAX_QCI_PER_REQ)||
9788        (schL2MeasInfo->avgPrbQciDl.numQci == 0)))
9789    {
9790       err->errType = RGSCHERR_SCH_INVALID_PARAM_RANGE;
9791       err->errCause = RGSCHERR_SCH_L2MEAS;
9792       return RFAILED;
9793    }
9794    if((schL2MeasInfo->timePrd !=0) &&
9795      (measType & LRG_L2MEAS_AVG_PRB_PER_QCI_UL) &&
9796       (schL2MeasInfo->avgPrbQciUl.numQci > LRG_MAX_QCI_PER_REQ)) 
9797    {
9798       err->errType = RGSCHERR_SCH_INVALID_PARAM_RANGE;
9799       err->errCause = RGSCHERR_SCH_L2MEAS;
9800       return RFAILED;
9801    }
9802    if((measType & LRG_L2MEAS_NMB_ACTV_UE_PER_QCI_DL) &&
9803          ((schL2MeasInfo->nmbActvUeQciDl.numQci > LRG_MAX_QCI_PER_REQ) ||
9804           (schL2MeasInfo->nmbActvUeQciDl.sampPrd == 0)||
9805           ((schL2MeasInfo->timePrd !=0)&&
9806            (schL2MeasInfo->timePrd < schL2MeasInfo->nmbActvUeQciDl.sampPrd)) ||
9807          (schL2MeasInfo->nmbActvUeQciDl.sampPrd > LRG_MAX_SAMP_PRD)))
9808    {
9809       err->errType = RGSCHERR_SCH_INVALID_PARAM_RANGE;
9810       err->errCause = RGSCHERR_SCH_L2MEAS;
9811       return RFAILED;
9812    }
9813    if((measType & LRG_L2MEAS_NMB_ACTV_UE_PER_QCI_UL) &&
9814       ((schL2MeasInfo->nmbActvUeQciUl.numQci > LRG_MAX_QCI_PER_REQ) ||
9815        (schL2MeasInfo->nmbActvUeQciUl.sampPrd == 0)||
9816        ((schL2MeasInfo->timePrd !=0) &&
9817         (schL2MeasInfo->timePrd < schL2MeasInfo->nmbActvUeQciUl.sampPrd)) ||
9818         (schL2MeasInfo->nmbActvUeQciUl.sampPrd > LRG_MAX_SAMP_PRD)))
9819    {
9820       err->errType = RGSCHERR_SCH_INVALID_PARAM_RANGE;
9821       err->errCause = RGSCHERR_SCH_L2MEAS;
9822       return RFAILED;
9823    }
9824    if((schL2MeasInfo->timePrd !=0) &&
9825        (measType & LRG_L2MEAS_AVG_PRB_PER_QCI_DL))
9826    {
9827       RGSCH_ARRAY_BOUND_CHECK(cellCb->instIdx, schL2MeasInfo->avgPrbQciDl.qci,  \
9828       (schL2MeasInfo->avgPrbQciDl.numQci));
9829       ret  = rgSCHUtlValidateQci(cellCb, schL2MeasInfo->avgPrbQciDl.numQci,
9830                                  schL2MeasInfo->avgPrbQciDl.qci);
9831       if(ret != ROK)
9832       {
9833           err->errType = RGSCHERR_SCH_INVALID_QCI_VAL;
9834           err->errCause = RGSCHERR_SCH_L2MEAS;
9835           return RFAILED;
9836       }
9837    }
9838    return ROK;
9839 }/* rgSCHUtlValidateMeasReq */
9840 #endif /* LTE_L2_MEAS */
9841 /******* </AllocHolesMemMgmnt>: END *****/
9842 #ifdef RGR_SI_SCH
9843 /**
9844  * @brief API for sending SI configuration confirm from Scheduler to RRM
9845  *
9846  * @details
9847  *
9848  *     Function: rgSCHUtlRgrSiCfgCfm
9849  *
9850  *     This API is invoked to send SI configuration confirm from Scheduler
9851  *     to RRM.
9852  *     This API fills in Pst structure and SAP Ids and invokes
9853  *     config confirm API towards RRM.
9854  *
9855  *  @param[in]  RgrCfgTransId transId
9856  *  @param[in]  U8            status
9857  *  @return  S16
9858  *      -# ROK
9859  *      -# RFAILED
9860  **/
9861 #ifdef ANSI
9862 S16 rgSCHUtlRgrSiCfgCfm
9863 (
9864 Inst          instId,
9865 SpId          spId,
9866 RgrCfgTransId transId,
9867 U8            status
9868 )
9869 #else
9870 S16 rgSCHUtlRgrSiCfgCfm(instId, spId, transId, status)
9871 Inst          instId;
9872 SpId          spId;
9873 RgrCfgTransId transId;
9874 U8            status;
9875 #endif
9876 {
9877    U8        prntTrans[RGR_CFG_TRANSID_SIZE+1];
9878
9879
9880    memcpy(prntTrans, transId.trans, RGR_CFG_TRANSID_SIZE);
9881    prntTrans[RGR_CFG_TRANSID_SIZE] = '\0';
9882
9883
9884    if(RgUiRgrSiCfgCfm(&rgSchCb[instId].rgrSap[spId].sapCfg.sapPst,
9885                     rgSchCb[instId].rgrSap[spId].sapCfg.suId,
9886                     transId, status) != ROK)
9887    {
9888       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,"rgSCHUtlRgrSiCfgCfm: "
9889                 "RgUiRgrSiCfgCfm Failed ");
9890       return RFAILED;
9891    }
9892
9893    return ROK;
9894 }  /* rgSCHUtlRgrSiCfgCfm */
9895
9896 \f
9897 /**
9898  * @brief API for sending Warning SI configuration confirm from 
9899  * Scheduler to RRM
9900  *
9901  * @details
9902  *
9903  *
9904  *     This API is invoked to send Warning SI configuration confirm 
9905  *     from Scheduler to RRM.
9906  *     This API fills in Pst structure and SAP Ids and invokes
9907  *     config confirm API towards RRM.
9908  *
9909  *  @param[in]  RgrCfgTransId transId
9910  *  @param[in]  U8            status
9911  *  @return  S16
9912  *      -# ROK
9913  *      -# RFAILED
9914  **/
9915 #ifdef ANSI
9916 S16 rgSCHUtlRgrWarningSiCfgCfm
9917 (
9918 Inst          instId,
9919 SpId          spId,
9920 U8            siId,
9921 RgrCfgTransId transId,
9922 U8            status
9923 )
9924 #else
9925 S16 rgSCHUtlRgrWarningSiCfgCfm(instId, spId, siId, transId, status)
9926 Inst          instId;
9927 SpId          spId;
9928 U8            siId;
9929 RgrCfgTransId transId;
9930 U8            status;
9931 #endif
9932 {
9933    U8        prntTrans[RGR_CFG_TRANSID_SIZE+1];
9934
9935
9936    memcpy(prntTrans, transId.trans, RGR_CFG_TRANSID_SIZE);
9937    prntTrans[RGR_CFG_TRANSID_SIZE] = '\0';
9938
9939
9940    if(RgUiRgrWarningSiCfgCfm(&rgSchCb[instId].rgrSap[spId].sapCfg.sapPst,
9941                     rgSchCb[instId].rgrSap[spId].sapCfg.suId, 
9942                     transId, siId, status) != ROK)
9943    {
9944       RLOG_ARG0(L_ERROR,DBG_INSTID,instId,"rgSCHUtlRgrSiCfgCfm: "
9945                 "RgUiRgrSiCfgCfm Failed ");
9946       return RFAILED;
9947    }
9948
9949    return ROK;
9950 }  /* rgSCHUtlRgrWarningSiCfgCfm */
9951
9952 /***********************************************************
9953  *
9954  *     Func : rgSCHUtlPutSiInfo
9955  *
9956  *     Desc : Utility Function to deallocate SI information
9957  *
9958  *
9959  *            RFAILED
9960  *
9961  *
9962  *     File : rg_utl.c
9963  *
9964  **********************************************************/
9965 #ifdef ANSI
9966 Void rgSCHUtlPutSiInfo
9967 (
9968 RgSchCellCb *cell
9969 )
9970 #else
9971 Void rgSCHUtlPutSiInfo(cell)
9972 RgSchCellCb *cell;
9973 #endif
9974 {
9975    U8    idx = 0;
9976    U32   sizeOfSiInfo = 0;
9977    /*Free the buffers in crntSiInfo*/
9978    RGSCH_FREE_MSG(cell->siCb.crntSiInfo.mib)
9979    RGSCH_FREE_MSG(cell->siCb.crntSiInfo.sib1Info.sib1)
9980    
9981    sizeOfSiInfo = sizeof(cell->siCb.crntSiInfo.siInfo)/sizeof(cell->siCb.crntSiInfo.siInfo[0]);
9982    
9983    for(idx=0; idx < sizeOfSiInfo; idx++)
9984    {
9985       RGSCH_FREE_MSG(cell->siCb.crntSiInfo.siInfo[idx].si)
9986    }
9987
9988    /*Free the buffers in newSiInfo */
9989    RGSCH_FREE_MSG(cell->siCb.newSiInfo.mib)
9990    RGSCH_FREE_MSG(cell->siCb.newSiInfo.sib1Info.sib1)
9991
9992    sizeOfSiInfo = sizeof(cell->siCb.newSiInfo.siInfo)/sizeof(cell->siCb.newSiInfo.siInfo[0]);
9993
9994    for(idx=0; idx < sizeOfSiInfo; idx++)
9995    {
9996       RGSCH_FREE_MSG(cell->siCb.newSiInfo.siInfo[idx].si)
9997    }
9998
9999    RETVOID;
10000 }
10001 #endif /*RGR_SI_SCH */
10002
10003
10004
10005 /***********************************************************
10006  *
10007  *     Func : rgSCHUtlGetDrxSchdUesInDl
10008  *
10009  *     Desc : Utility Function to fill the get the list of
10010  *            scheduled UEs. On these UE's, drx-inactivity
10011  *            timer will be started/restarted.
10012  *
10013  *     Ret  : ROK
10014  *            RFAILED
10015  *
10016  *     Notes:
10017  *
10018  *     File : rg_utl.c
10019  *
10020  **********************************************************/
10021 #ifdef ANSI
10022 S16 rgSCHUtlGetDrxSchdUesInDl
10023 (
10024 RgSchCellCb     *cellCb,
10025 RgSchUeCb       *ueCb,
10026 RgSchDlHqProcCb *dlHq,
10027 RgInfUeAlloc    *allocInfo,
10028 CmLListCp       *dlDrxInactvTmrLst,
10029 CmLListCp       *dlInActvLst,
10030 CmLListCp       *ulInActvLst
10031 )
10032 #else
10033 S16 rgSCHUtlGetDrxSchdUesInDl(cellCb, ueCb, dlHq, allocInfo, dlDrxInactvTmrLst, dlInActvLst, ulInActvLst)
10034 RgSchCellCb     *cellCb;
10035 RgSchUeCb       *ueCb;
10036 RgSchDlHqProcCb *dlHq;
10037 RgInfUeAlloc    *allocInfo;
10038 CmLListCp       *dlDrxInactvTmrLst;
10039 CmLListCp       *dlInActvLst;
10040 CmLListCp       *ulInActvLst;
10041 #endif
10042 {
10043    Bool                  isNewTx = FALSE;
10044    U8                    idx;
10045    RgSchDrxDlHqProcCb    *drxHq;
10046    RgSchDRXCellCb        *drxCell = cellCb->drxCb;
10047    RgSchDrxUeCb          *drxUe;
10048 #ifdef DEBUGP
10049    Inst                  inst = cellCb->instIdx;
10050 #endif
10051    U8                    cellIdx = ueCb->cellIdToCellIdxMap[RG_SCH_CELLINDEX(dlHq->hqE->cell)];
10052    U32                   dlInactvMask;
10053    U32                   ulInactvMask;
10054
10055    for(idx = 0; idx < allocInfo->nmbOfTBs; idx++)
10056    {
10057       if(allocInfo->tbInfo[idx].isReTx == FALSE)
10058       {
10059          isNewTx = TRUE;
10060          /* Removing break here, since in 2 TB case if 2nd TB is proceeding with 
10061             retx then drxretx timer should be stopped.*/
10062       }
10063       else
10064       {
10065          /*Stop the DRX retransmission timer as UE scheduled for retx. Here
10066           * we stop the timer and inactivate the UE for both UL and DL.
10067           * This may result in loss of one slot for UL but this trade
10068           * off is taken to avoid the overhead of maintaining a list of UEs
10069           * to be inactivated in the next slot.*/
10070          drxHq = RG_SCH_DRX_GET_DL_HQ(dlHq);
10071          drxUe = RG_SCH_DRX_GET_UE(ueCb);
10072          if(drxHq->reTxIndx != DRX_INVALID)
10073          {  
10074             /* This condition should never occur */      
10075             if(drxHq->reTxIndx >= RG_SCH_MAX_DRXQ_SIZE)
10076             {
10077                RGSCHDBGERRNEW(inst,(rgSchPBuf(inst),"[%d]UE:DRXUE RETX IDX[%d]"
10078                         "is out of bound,dlInactvMask %d,procId %d\n", ueCb->ueId,
10079                         drxHq->reTxIndx,ueCb->dl.dlInactvMask, dlHq->procId));
10080             }
10081
10082             drxUe->drxDlInactvMaskPerCell[cellIdx]  |= (RG_SCH_DRX_DLHQ_BITMASK << dlHq->procId);
10083             drxUe->drxUlInactvMaskPerCell[cellIdx]  |= (RG_SCH_DRX_DLHQ_BITMASK << dlHq->procId);
10084
10085             dlInactvMask = RG_SCH_DRX_DLHQ_BITMASK << dlHq->procId;
10086             ulInactvMask = RG_SCH_DRX_DLHQ_BITMASK << dlHq->procId;
10087
10088             for(cellIdx = 0; cellIdx < CM_LTE_MAX_CELLS; cellIdx++)
10089             {
10090                dlInactvMask &= drxUe->drxDlInactvMaskPerCell[cellIdx];
10091                ulInactvMask &= drxUe->drxUlInactvMaskPerCell[cellIdx];
10092             }
10093
10094             drxUe->drxDlInactvMask |= dlInactvMask;
10095             drxUe->drxUlInactvMask |= ulInactvMask;
10096
10097             /* if no other condition is keeping ue active,
10098              * inactivate the Ue
10099              */
10100             if(!RG_SCH_DRX_DL_IS_UE_ACTIVE(drxUe))
10101             {
10102                /* BUG 2 : HARQ_RTT, changed for consistency */
10103                ueCb->dl.dlInactvMask |= (RG_DRX_INACTIVE);
10104
10105                /* Add to DL inactive list */
10106                cmLListAdd2Tail(dlInActvLst,&(ueCb->dlDrxInactvLnk));
10107                ueCb->dlDrxInactvLnk.node = (PTR)ueCb;
10108             }
10109
10110             if(!RG_SCH_DRX_UL_IS_UE_ACTIVE(drxUe))
10111             {
10112                /*BUG 2: HARQ_RTT changed for consistency */
10113                ueCb->ul.ulInactvMask |= (RG_DRX_INACTIVE);
10114
10115                cmLListAdd2Tail(ulInActvLst,&(ueCb->ulDrxInactvLnk));
10116                ueCb->ulDrxInactvLnk.node  = (PTR)ueCb;
10117             }
10118
10119             /* Deleting entry from HARQ RTT queue for the same HARQ proc, 
10120              * if exist. This is the special case which can happen iF UL 
10121              * scheduling is done later. */
10122             if(drxHq->rttIndx != DRX_INVALID)
10123             {
10124                cmLListDelFrm (&(cellCb->drxCb->drxQ[drxHq->rttIndx].harqRTTQ),
10125                      &(drxHq->harqRTTEnt));
10126
10127                drxHq->rttIndx = DRX_INVALID;
10128             }   
10129
10130             cmLListDelFrm (&(drxCell->drxQ[drxHq->reTxIndx].harqRetxQ),
10131                   &(drxHq->harqRetxEnt));
10132             drxHq->reTxIndx = DRX_INVALID;
10133          }
10134       }
10135    }
10136
10137    if(isNewTx == TRUE)
10138    {
10139       if(ueCb->drxCb->raRcvd == TRUE)
10140       {
10141          ueCb->drxCb->raRcvd = FALSE;
10142
10143          /* mark the ra bit */
10144          ueCb->drxCb->drxUlInactvMask |= RG_SCH_DRX_RA_BITMASK;
10145          ueCb->drxCb->drxDlInactvMask |= RG_SCH_DRX_RA_BITMASK;
10146
10147       }/*if(ra->rcvd) == TRUE */
10148
10149       if(ueCb->dlDrxInactvTmrLnk.node == NULLP)
10150       {   
10151          cmLListAdd2Tail(dlDrxInactvTmrLst,&(ueCb->dlDrxInactvTmrLnk));
10152          ueCb->dlDrxInactvTmrLnk.node = (PTR)ueCb;
10153       }
10154    }/*if(isNewTx == TRUE) */
10155
10156    return ROK;
10157 }/* rgSCHUtlGetSchdUes*/
10158 \f
10159 /* ccpu00117452 - MOD - Changed macro name from
10160    RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
10161 #ifdef RGR_CQI_REPT
10162 /**
10163  * @brief This function fills StaInd struct
10164  *
10165  * @details
10166  *
10167  *     Function: rgSCHUtlFillSndStaInd
10168  *     Purpose:  Fills StaInd struct and sends the
10169  *               StaInd to RRM
10170  *
10171  *  @param[in]  RgSchCellCb        *cell  pointer to Cell Control block
10172  *  @param[in]  RgSchUeCb          *ue  pointer to Ue Control block
10173  *  @param[in]  RgrStaIndInfo      *staInfo Sta Ind struct to be filled
10174  *  @param[in]  U8                 numCqiRept NUmber of reports to be filled
10175  *  @return  Void
10176  *
10177  **/
10178 #ifdef ANSI
10179 S16 rgSCHUtlFillSndStaInd
10180 (
10181 RgSchCellCb        *cell,
10182 RgSchUeCb          *ue,
10183 RgrStaIndInfo      *staInfo,
10184 U8                 numCqiRept
10185 )
10186 #else
10187 S16 rgSCHUtlFillSndStaInd(cell, ue, staInfo, numCqiRept)
10188 RgSchCellCb        *cell;
10189 RgSchUeCb          *ue;
10190 RgrStaIndInfo      *staInfo;
10191 U8                 numCqiRept;
10192 #endif
10193 {
10194    U8 idxStart;
10195
10196    /* Fill StaInd for sending collated Latest N CQI rpeorts */
10197    /* Find index in the array from where Latest N
10198       reports needs to be fetched. Use this value to index in the array
10199       and copy the reports into staInfo */
10200
10201    /* Fill the Cell Id of PCC of the UE */
10202    staInfo->cellId = ue->cell->cellId;
10203    staInfo->crnti = ue->ueId;
10204
10205    idxStart = ue->schCqiInfo.cqiCount - numCqiRept;
10206
10207    memcpy (&(staInfo->ueCqiInfo.cqiRept),
10208             &(ue->schCqiInfo.cqiRept[idxStart]),
10209             numCqiRept * sizeof(RgrUeCqiRept));
10210
10211    staInfo->ueCqiInfo.numCqiRept = numCqiRept;
10212
10213    ue->schCqiInfo.cqiCount = 0;
10214
10215    /* Call utility function (rgSCHUtlRgrStaInd) to send rpts to RRM */
10216    if(rgSCHUtlRgrStaInd(cell, staInfo) != ROK)
10217    {
10218       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Could not send "
10219          "CQI reports for RNTI:%d",ue->ueId);
10220       return RFAILED;
10221    }
10222
10223    return ROK;
10224
10225 }/* End of rgSCHUtlFillSndStaInd */
10226
10227
10228 \f
10229 /**
10230  * @brief API for sending STA indication from Scheduler to RRM.
10231  *
10232  * @details
10233  *
10234  *     Function: rgSCHUtlRgrStaInd
10235  *
10236  *     This API is invoked to send STA indication from Scheduler instance to RRM.
10237  *     This API fills in Pst structure and RgrStaIndInfo
10238  *     and calls the Sta primitive API towards RRM.
10239  *
10240  *  @param[in]  cell                   RgSchCellCb
10241  *  @param[in]  RgrStsIndInfo          *rgrSta
10242  *  @return  S16
10243  *      -# ROK
10244  *      -# RFAILED
10245  **/
10246 #ifdef ANSI
10247 S16 rgSCHUtlRgrStaInd
10248 (
10249 RgSchCellCb          *cell,
10250 RgrStaIndInfo        *rgrSta
10251 )
10252 #else
10253 S16 rgSCHUtlRgrStaInd(cell, rgrSta)
10254 RgSchCellCb          *cell;
10255 RgrStaIndInfo        *rgrSta;
10256 #endif
10257 {
10258    S16           ret = ROK;
10259    RgSchUpSapCb  *rgrSap;                    /*!< RGR SAP Control Block */
10260
10261
10262
10263    rgrSap = cell->rgrSap;
10264    if (rgrSap->sapSta.sapState != LRG_BND)
10265    {
10266       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
10267                "rgSCHUtlRgrStaInd() Upper SAP not bound (%d) ",
10268                rgrSap->sapSta.sapState);
10269       return RFAILED;
10270    }
10271    RgUiRgrStaInd(&(cell->rgrSap->sapCfg.sapPst),
10272          cell->rgrSap->sapCfg.suId, rgrSta);
10273    return (ret);
10274 }  /* rgSCHUtlRgrStaInd*/
10275 #endif /* End of RGR_CQI_REPT */
10276
10277 /* Fix : syed HO UE does not have a valid ue->rntiLnk */
10278 /**
10279  * @brief Indicates MAC to release any rnti context it has.
10280  *
10281  * @details
10282  *     Function : rgSCHUtlIndRntiRls2Mac 
10283  *       This function indicates MAC for this rnti release.
10284  *       In case of ueId change it will indicate MAC
10285  *       about the new rnti to be updated.
10286  *       It will post a release RNTI indication to MAC.
10287  *     
10288  *    
10289  *           
10290  *  @param[in]     RgSchCellCb    *cell
10291  *  @param[in]     CmLteRnti      rnti 
10292  *  @param[in]     Bool           ueIdChng
10293  *  @param[in]     CmLteRnti      newRnti
10294  *  @return  Void
10295  *      -# ROK 
10296  **/
10297 #ifdef ANSI
10298 Void rgSCHUtlIndRntiRls2Mac 
10299 (
10300 RgSchCellCb    *cell,
10301 CmLteRnti      rnti,
10302 Bool           ueIdChng,
10303 CmLteRnti      newRnti
10304 )
10305 #else
10306 Void rgSCHUtlIndRntiRls2Mac(cell, rnti, ueIdChng, newRnti)
10307 RgSchCellCb    *cell;
10308 CmLteRnti      rnti;
10309 Bool           ueIdChng;
10310 CmLteRnti      newRnti;
10311 #endif
10312 {
10313    Pst          pst;
10314    Inst         inst = cell->instIdx;
10315    RgInfRlsRnti rntiInfo;
10316
10317
10318    /* Copy the info to rntiInfo */
10319    rntiInfo.cellId = cell->cellId;
10320    rntiInfo.rnti   = rnti;
10321    /* Fix : syed ueId change as part of reestablishment.
10322     * Now SCH to trigger this. CRG ueRecfg for ueId change 
10323     * is dummy */          
10324    rntiInfo.ueIdChng = ueIdChng;
10325    rntiInfo.newRnti  = newRnti;
10326 #ifdef LTE_ADV
10327    rntiInfo.isUeSCellDel = FALSE;
10328 #endif
10329    /* Invoke MAC to release the rnti */
10330    rgSCHUtlGetPstToLyr(&pst, &rgSchCb[inst], cell->macInst);
10331    RgSchMacRlsRnti(&pst, &rntiInfo);
10332    RETVOID;
10333 }
10334
10335 /* LTE_ADV_FLAG_REMOVED_START */
10336 /**
10337  * @brief API for sending LOAD INF indication from Scheduler to RRM.
10338  * @details
10339  *
10340  *     Function: rgSCHUtlRgrLoadInfInd
10341  *
10342  *     This API is invoked to send LOAD INF indication from Scheduler instance to RRM.
10343  *     This API fills in Pst structure and RgrLoadInfIndInfo
10344  *     and calls the Sta primitive API towards RRM.
10345  *
10346  *  @param[in]  cell                    RgSchCellCb
10347  *  @param[in]  RgrLoadInfIndInfo       *rgrLoadInf
10348  *  @return  S16
10349  *      -# ROK
10350  *      -# RFAILED
10351  **/
10352 #ifdef ANSI
10353 S16 rgSCHUtlRgrLoadInfInd
10354 (
10355  RgSchCellCb           *cell,
10356  RgrLoadInfIndInfo     *rgrLoadInf
10357  )
10358 #else
10359 S16 rgSCHUtlRgrLoadInfInd(cell, rgrLoadInf)
10360    RgSchCellCb           *cell;
10361    RgrLoadInfIndInfo     *rgrLoadInf;
10362 #endif
10363 {
10364    S16           ret = ROK;
10365    RgSchUpSapCb  *rgrSap;                    /*!< RGR SAP Control Block */
10366
10367    rgrSap = cell->rgrSap;
10368    if (rgrSap->sapSta.sapState != LRG_BND)
10369    {
10370       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
10371                "rgSCHUtlRgrLoadInfInd() Upper SAP not bound (%d) ",
10372                rgrSap->sapSta.sapState);
10373       return RFAILED;
10374    }
10375    RgUiRgrLoadInfInd(&(cell->rgrSap->sapCfg.sapPst),
10376          cell->rgrSap->sapCfg.suId, rgrLoadInf);
10377    return (ret);
10378 }  /* rgSCHUtlRgrLoadInfInd*/
10379 /* LTE_ADV_FLAG_REMOVED_END */
10380
10381 /* MS_FIX : syed SCH to act as MASTER in maintaining
10382  * rnti related context. Trigger to rnti del/Chng at SCH
10383  * will result in a Indication to MAC to release its
10384  * RNTI context. MAC inturn indicates the context cleared
10385  * indication to SCH, upon which SCH would set this
10386 /**
10387  * @brief API for sending STA indication from Scheduler to RRM.
10388  *
10389  * @details
10390  *
10391  *     Function: rgSCHUtlRlsRnti
10392  *
10393  *     This API is invoked to indicate MAC to release rnti
10394  *
10395  *  @param[in]  RgSchCellCb    *cellCb                   
10396  *  @param[in]  RgSchRntiLnk   *rntiLnk,
10397  *  @param[in]  Bool           ueIdChngd,
10398  *  @param[in]  CmLteRnti      newRnti
10399  *  @return  Void
10400  **/
10401
10402 #ifdef ANSI
10403 Void rgSCHUtlRlsRnti
10404 (
10405 RgSchCellCb    *cell,
10406 RgSchRntiLnk   *rntiLnk,
10407 Bool           ueIdChngd,
10408 CmLteRnti      newRnti
10409 )
10410 #else
10411 Void rgSCHUtlRlsRnti(cell, rntiLnk, ueIdChngd, newRnti)
10412 RgSchCellCb    *cell;
10413 RgSchRntiLnk   *rntiLnk;
10414 Bool           ueIdChngd;
10415 CmLteRnti      newRnti;
10416 #endif
10417 {
10418
10419    U8 isLegacy = 0;
10420 #ifdef EMTC_ENABLE
10421    if(cell->emtcEnable)
10422    {
10423       rgSCHEmtcUtlRlsRnti(cell, rntiLnk, &isLegacy);
10424    }
10425 #endif
10426    if(!isLegacy)
10427    {
10428       /*Add to Guard Pool*/
10429       cmLListAdd2Tail(&cell->rntiDb.rntiGuardPool, &rntiLnk->rntiGrdPoolLnk);
10430       rntiLnk->rntiGrdPoolLnk.node = (PTR)rntiLnk;
10431    }
10432    /* Fix: syed Explicitly Inidcate MAC to release RNTI */
10433    rgSCHUtlIndRntiRls2Mac(cell, rntiLnk->rnti, ueIdChngd, newRnti);
10434
10435    RETVOID;
10436 }
10437
10438
10439 /**
10440  * @brief This function fills StaInd struct
10441  *
10442  * @details
10443  *
10444  *     Function: rgSCHUtlFillSndUeStaInd
10445  *     Purpose:  Fills StaInd struct and sends the
10446  *               StaInd to RRM
10447  *
10448  *  @param[in]  RgSchCellCb        *cell  pointer to Cell Control block
10449  *  @param[in]  RgSchUeCb          *ue  pointer to Ue Control block
10450  *  @param[in]  U8                 numCqiRept NUmber of reports to be filled
10451  *  @return  Void
10452  *
10453  **/
10454 #ifdef ANSI
10455 S16 rgSCHUtlFillSndUeStaInd
10456 (
10457 RgSchCellCb          *cell,
10458 RgSchUeCb            *ue,
10459 RgrUeStaIndInfo      *ueStaInfo
10460 )
10461 #else
10462 S16 rgSCHUtlFillSndUeStaInd(cell, ue, ueStaInfo)
10463 RgSchCellCb          *cell;
10464 RgSchUeCb            *ue;
10465 RgrUeStaIndInfo      *ueStaInfo;
10466 #endif
10467 {
10468
10469    ueStaInfo->cellId = cell->cellId;
10470    ueStaInfo->crnti = ue->ueId;
10471
10472    /* Call utility function (rgSCHUtlRgrUeStaInd) to send rpts to RRM */
10473    if(rgSCHUtlRgrUeStaInd(cell, ueStaInfo) != ROK)
10474    {
10475       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Could not send "
10476          "UE Sta reports CRNTI:%d",ue->ueId);
10477       return RFAILED;
10478    }
10479
10480    return ROK;
10481
10482 }/* End of rgSCHUtlFillSndStaInd */
10483
10484
10485 \f
10486 /**
10487  * @brief API for sending STA indication from Scheduler to RRM.
10488  *
10489  * @details
10490  *
10491  *     Function: rgSCHUtlRgrStaInd
10492  *
10493  *     This API is invoked to send STA indication from Scheduler instance to RRM.
10494  *     This API fills in Pst structure and RgrStaIndInfo
10495  *     and calls the Sta primitive API towards RRM.
10496  *
10497  *  @param[in]  cell                   RgSchCellCb
10498  *  @param[in]  RgrStsIndInfo          *rgrSta
10499  *  @return  S16
10500  *      -# ROK
10501  *      -# RFAILED
10502  **/
10503 #ifdef ANSI
10504 S16 rgSCHUtlRgrUeStaInd
10505 (
10506 RgSchCellCb          *cell,
10507 RgrUeStaIndInfo      *rgrUeSta
10508 )
10509 #else
10510 S16 rgSCHUtlRgrUeStaInd(cell, rgrUeSta)
10511 RgSchCellCb          *cell;
10512 RgrUeStaIndInfo      *rgrUeSta;
10513 #endif
10514 {
10515    S16           ret = ROK;
10516    RgSchUpSapCb  *rgrSap;                    /*!< RGR SAP Control Block */
10517
10518    rgrSap = cell->rgrSap;
10519    if (rgrSap->sapSta.sapState != LRG_BND)
10520    {
10521       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
10522                "rgSCHUtlRgrUeStaInd() Upper SAP not bound (%d) ",
10523                rgrSap->sapSta.sapState);
10524       return RFAILED;
10525    }
10526    RgUiRgrUeStaInd(&(cell->rgrSap->sapCfg.sapPst),
10527          cell->rgrSap->sapCfg.suId, rgrUeSta);
10528    return (ret);
10529 }  /* rgSCHUtlRgrStaInd*/
10530
10531 /* RRM_RBC_X */
10532 /**
10533  * @brief function to report DL and UL PRB usage to RRM.
10534  *
10535  *
10536  *     Function: rgSCHUtlUpdAvgPrbUsage
10537  *               This function sends the PRB usage report to 
10538  *               RRM with the interval configured by RRM.
10539  *
10540  *  @param[in]  cell       *RgSchCellCb
10541  *  @return  S16
10542  *      -# ROK
10543  *      -# RFAILED
10544  **/
10545 #ifdef ANSI
10546 S16 rgSCHUtlUpdAvgPrbUsage
10547 (
10548 RgSchCellCb          *cell
10549 )
10550 #else
10551 S16 rgSCHUtlUpdAvgPrbUsage(cell)
10552 RgSchCellCb       *cell;
10553 #endif
10554 {
10555    CmLteTimingInfo  frm;
10556    RgmPrbRprtInd    *prbRprtInd;
10557    S16              ret = ROK;
10558    U32              idx;
10559 #ifdef DBG_MAC_RRM_PRB_PRINT
10560    static U32       count = 0;
10561    const U32 reprotForEvery20Sec = 20000/cell->prbUsage.rprtPeriod;
10562
10563    count++;
10564 #endif
10565
10566    frm   = cell->crntTime;
10567    RGSCH_INCR_SUB_FRAME(frm, RG_SCH_CMN_DL_DELTA);
10568
10569    U16 numDlSf;
10570    U16 numUlSf;
10571 #ifdef LTE_TDD
10572   
10573    if(cell->prbUsage.rprtPeriod >= RGSCH_NUM_SUB_FRAMES)
10574    {
10575       /* Get the total number of DL and UL slots within the reporting period*/
10576       numDlSf = (cell->prbUsage.rprtPeriod * 
10577             rgSchTddNumDlSubfrmTbl[cell->ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1])
10578          / RGSCH_NUM_SUB_FRAMES;
10579       numUlSf = (cell->prbUsage.rprtPeriod * 
10580             rgSchTddNumUlSubfrmTbl[cell->ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1])
10581          / RGSCH_NUM_SUB_FRAMES;
10582    }
10583    else
10584    {
10585       /* Get the total number of DL and UL slots < 10 ms interval */
10586       numDlSf = rgSchTddNumDlSubfrmTbl[cell->ulDlCfgIdx][frm.slot];
10587       numUlSf = rgSchTddNumUlSubfrmTbl[cell->ulDlCfgIdx][frm.slot];
10588    }
10589 #else
10590      numDlSf = cell->prbUsage.rprtPeriod;
10591      numUlSf = cell->prbUsage.rprtPeriod;
10592 #endif
10593
10594    if(SGetSBuf(cell->rgmSap->sapCfg.sapPst.region, 
10595                cell->rgmSap->sapCfg.sapPst.pool, (Data**)&prbRprtInd, 
10596                sizeof(RgmPrbRprtInd)) != ROK)
10597    {
10598       return RFAILED;
10599    }
10600
10601    memset(&prbRprtInd->stQciPrbRpts[0],
10602             0,
10603             (RGM_MAX_QCI_REPORTS * sizeof(RgmPrbRptPerQci)));
10604
10605    prbRprtInd->bCellId            = cell->cellId;
10606
10607    if(numDlSf > 0)
10608    {
10609       prbRprtInd->bPrbUsageMask |= RGM_PRB_USAGE_DL; 
10610       for (idx = 0; idx < RGM_MAX_QCI_REPORTS; idx++ )
10611       {
10612          prbRprtInd->stQciPrbRpts[idx].bAvgPrbDlUsage  = 
10613            RGSCH_DIV_ROUND((cell->prbUsage.qciPrbRpts[idx].dlTotPrbUsed*100),
10614                            (numDlSf * cell->bwCfg.dlTotalBw));
10615          prbRprtInd->stQciPrbRpts[idx].bQci = cell->prbUsage.qciPrbRpts[idx].qci;
10616          cell->prbUsage.qciPrbRpts[idx].dlTotPrbUsed = 0;
10617       }
10618    }
10619
10620    if(numUlSf > 0)
10621    {
10622       prbRprtInd->bPrbUsageMask |= RGM_PRB_USAGE_UL; 
10623       for (idx = 0; idx < RGM_MAX_QCI_REPORTS; idx++ )
10624       {
10625          prbRprtInd->stQciPrbRpts[idx].bAvgPrbUlUsage  = 
10626            RGSCH_DIV_ROUND((cell->prbUsage.qciPrbRpts[idx].ulTotPrbUsed*100),
10627                            (numUlSf * cell->ulAvailBw));
10628          prbRprtInd->stQciPrbRpts[idx].bQci = cell->prbUsage.qciPrbRpts[idx].qci;
10629          cell->prbUsage.qciPrbRpts[idx].ulTotPrbUsed = 0;
10630       }
10631    }
10632
10633 #ifdef DBG_MAC_RRM_PRB_PRINT
10634    if((count % reprotForEvery20Sec) == 0 )
10635    {
10636       printf("\n====================================================================");
10637       printf("\nMAC:  QCI-1[DL:UL]  | QCI-2[DL:UL]  | QCI-3[DL:UL]  | QCI-4[DL:UL] \n");
10638       printf("======================================================================\n");
10639       printf(" [%d: %d]\t | [%d: %d]\t | [%d: %d]\t| [%d: %d]\t\n", 
10640                  prbRprtInd->stQciPrbRpts[0].bAvgPrbDlUsage,
10641                  prbRprtInd->stQciPrbRpts[0].bAvgPrbUlUsage,
10642                  prbRprtInd->stQciPrbRpts[1].bAvgPrbDlUsage,
10643                  prbRprtInd->stQciPrbRpts[1].bAvgPrbUlUsage,
10644                  prbRprtInd->stQciPrbRpts[2].bAvgPrbDlUsage,
10645                  prbRprtInd->stQciPrbRpts[2].bAvgPrbUlUsage,
10646                  prbRprtInd->stQciPrbRpts[3].bAvgPrbDlUsage,
10647                  prbRprtInd->stQciPrbRpts[3].bAvgPrbUlUsage);
10648    }
10649 #endif
10650    RgUiRgmSendPrbRprtInd(&(cell->rgmSap->sapCfg.sapPst), 
10651                     cell->rgmSap->sapCfg.suId, prbRprtInd);
10652
10653
10654    return (ret);
10655 }
10656 /* RRM_RBC_Y */
10657
10658 /**
10659  * @brief This function resends the Ta in case of 
10660  *        max retx failure or DTX for the Ta transmitted 
10661  *
10662  * @details
10663  *
10664  *     Function: rgSCHUtlReTxTa
10665  *     Purpose:  
10666  *                
10667  *  @param[in]  RgSchCellCb           *cell
10668  *  @param[in]  RgSchUeCb             *ue
10669  *  @return  Void 
10670  *
10671  **/
10672 #ifdef ANSI
10673 Void rgSCHUtlReTxTa 
10674 (
10675 RgSchCellCb       *cellCb,
10676 RgSchUeCb         *ueCb
10677 )
10678 #else
10679 Void rgSCHUtlReTxTa(cellCb, ueCb)
10680 RgSchCellCb       *cellCb;
10681 RgSchUeCb         *ueCb;
10682 #endif
10683 {
10684
10685    /* If TA Timer is running. Stop it */
10686    if (ueCb->taTmr.tmrEvnt != TMR_NONE)
10687    {
10688       rgSCHTmrStopTmr(cellCb, ueCb->taTmr.tmrEvnt, ueCb);
10689    }
10690    /*[ccpu00121813]-ADD-If maxretx is reached then 
10691     * use outstanding TA val for scheduling again */
10692    if(ueCb->dl.taCb.outStndngTa == TRUE)
10693    {
10694       ueCb->dl.taCb.ta = ueCb->dl.taCb.outStndngTaval;
10695       ueCb->dl.taCb.outStndngTaval = RGSCH_NO_TA_RQD;
10696       ueCb->dl.taCb.outStndngTa = FALSE;
10697
10698    }
10699    /* Fix : syed TA state updation missing */
10700    ueCb->dl.taCb.state = RGSCH_TA_TOBE_SCHEDULED;
10701    rgSCHUtlDlTARpt(cellCb, ueCb); 
10702
10703    RETVOID;
10704 }
10705
10706 /* Added function for dropping Paging Message*/
10707 /**
10708  * @brief Handler for BO Updt received for BCCH or PCCH.
10709  *
10710  * @details
10711  *
10712  *     Function : rgSCHChkBoUpdate
10713  *
10714  *     This function shall check for BO received falls within the scheduling window or not
10715  *
10716  *
10717  *  @param[in]  RgSchCellCb    *cell
10718  *  @return  S16
10719  *      -# ROK 
10720  *      -# RFAILED
10721  **/
10722 #ifdef ANSI
10723 PRIVATE S16 rgSCHChkBoUpdate
10724 (
10725 RgSchCellCb    *cell,
10726 RgInfCmnBoRpt  *boUpdt
10727 )
10728 #else
10729 PRIVATE S16 rgSCHChkBoUpdate (cell, boUpdt)
10730 RgSchCellCb    *cell;
10731 RgInfCmnBoRpt  *boUpdt;
10732 #endif
10733 {
10734
10735    U32 crntTimeInSubFrms = 0;
10736    U32 boUpdTimeInSubFrms = 0;
10737    U32 distance = 0;
10738
10739    crntTimeInSubFrms = (cell->crntTime.sfn * RGSCH_NUM_SUB_FRAMES_5G) +  cell->crntTime.slot +
10740            RG_SCH_CMN_DL_DELTA + 2;  /* As bo received will scheduled in next TTI
10741                                         so incrementing with +1 more */
10742    boUpdTimeInSubFrms = (boUpdt->u.timeToTx.sfn * RGSCH_NUM_SUB_FRAMES_5G)+ boUpdt->u.timeToTx.slot;
10743
10744
10745    distance = boUpdTimeInSubFrms > crntTimeInSubFrms ? \
10746               boUpdTimeInSubFrms - crntTimeInSubFrms : \
10747               (RGSCH_MAX_SUBFRM_5G - crntTimeInSubFrms + boUpdTimeInSubFrms);
10748
10749    if (distance > RGSCH_PCCHBCCH_WIN)
10750    {
10751            return RFAILED;
10752    }
10753    return ROK;
10754
10755 }/*rgSCHChkBoUpdate*/
10756
10757
10758 #ifdef LTE_TDD
10759 /**
10760  * @brief  Utility function to calculate the UL reTxIdx in TDD cfg0
10761  *
10762  * @details
10763  *
10764  *     Function : rgSchUtlCfg0ReTxIdx
10765  *
10766  *     Update the reTxIdx according to the rules mentioned
10767  *     in 3GPP TS 36.213 section 8 for TDD Cfg0
10768  *
10769  *  @param[in]  RgSchCellCb     *cell
10770  *  @param[in]  CmLteTimingInfo  phichTime 
10771  *  @param[in]  U8               hqFdbkIdx
10772  *  @return     U8
10773  **/
10774 #ifdef ANSI
10775 U8 rgSchUtlCfg0ReTxIdx
10776 (
10777 RgSchCellCb    *cell,
10778 CmLteTimingInfo phichTime,
10779 U8              hqFdbkIdx
10780 )
10781 #else
10782 U8 rgSchUtlCfg0ReTxIdx (cell, phichTime, hqFdbkIdx)
10783 RgSchCellCb    *cell;
10784 CmLteTimingInfo phichTime;
10785 U8              hqFdbkIdx;
10786 #endif
10787 {
10788    U8 reTxIdx = RGSCH_INVALID_INFO;
10789    U8 iPhich = 0; 
10790    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
10791    RgSchUlSf       *ulSf;   
10792    U8               ulSF; /* UL SF in the TDD frame */
10793          
10794    ulSf = &cellUl->ulSfArr[hqFdbkIdx];
10795    ulSF = ulSf->ulSfIdx;
10796     
10797    /* Check for the UL SF 4 or 9 */
10798    if(ulSF == 9 || ulSF == 4)
10799    {
10800      iPhich = 1;  
10801    }
10802    if(phichTime.slot == 0 || phichTime.slot == 5)
10803    {    
10804       if(iPhich == 0)
10805       {
10806          /* Retx will happen according to the Pusch k table */
10807          reTxIdx = cellUl->schdIdx;
10808       }
10809       if(iPhich == 1)
10810       {
10811          /* Retx will happen at n+7 */
10812          RGSCHCMNADDTOCRNTTIME(phichTime, phichTime, 7);
10813          /* Fetch the corresponding  UL slot Idx in UL sf array */ 
10814          reTxIdx = rgSCHCmnGetUlSfIdx(&phichTime, cell);
10815       }   
10816    }
10817    else if(phichTime.slot == 1 || phichTime.slot == 6) 
10818    { 
10819       /* Retx will happen at n+7 */
10820       RGSCHCMNADDTOCRNTTIME(phichTime, phichTime, 7);
10821       /* Fetch the corresponding  UL slot Idx in UL sf array */ 
10822       reTxIdx = rgSCHCmnGetUlSfIdx(&phichTime, cell);
10823    }
10824    return (reTxIdx);
10825 }
10826 #endif
10827
10828 /**
10829  * @brief  Utility function to calculate total num of PRBs required to
10830  *         satisfy DL BO for TM1/TM2/TM6/TM7
10831  *
10832  * @details
10833  *
10834  *     Function : rgSchUtlDlCalc1CwPrb
10835  *
10836  *    Calculate PRBs required for UE to satisfy BO in DL
10837  *   
10838  *    Note : Total calculated PRBs will be assigned to *prbReqrd
10839  *    
10840  *
10841  *  @param[in]  RgSchCellCb     *cell
10842  *  @param[in]  RgSchUeCb       *ue 
10843  *  @param[in]  U32              bo 
10844  *  @param[out] U32             *prbReqrd 
10845  *  @return Void
10846  **/
10847 #ifdef ANSI
10848 Void rgSchUtlDlCalc1CwPrb
10849 (
10850 RgSchCellCb    *cell,
10851 RgSchUeCb      *ue,
10852 U32             bo,
10853 U32            *prbReqrd
10854 )
10855 #else
10856 Void rgSchUtlDlCalc1CwPrb(cell, ue, bo, prbReqrd)
10857 RgSchCellCb   *cell;
10858 RgSchUeCb     *ue;
10859 U32            bo;
10860 U32           *prbReqrd;
10861 #endif
10862 {
10863    RgSchCmnDlCell *dlCell  = RG_SCH_CMN_GET_DL_CELL(cell); 
10864    RgSchCmnDlUe   *dlUe  = RG_SCH_CMN_GET_DL_UE(ue, cell); 
10865    U32            eff;
10866    U32            noRes;
10867    U8             iTbs;
10868    U8             cfi = dlCell->currCfi;               
10869
10870    iTbs  = dlUe->mimoInfo.cwInfo[0].iTbs[0];
10871    eff   = (*(RgSchCmnTbSzEff *)(dlCell->cqiToEffTbl[0][cfi]))[iTbs];
10872
10873    /* Optimization to convert totalBo (which is in-terms of bytes) to bits 
10874     * i.e, << 3 and multiply with 1024 i.e, << 10 */
10875    noRes = ((U64)((bo << 3) << 10)) / (eff);
10876    /* Get the number of RBs needed for this transmission */
10877    /* Number of RBs = No of REs / No of REs per RB       */
10878    *prbReqrd = RGSCH_CEIL(noRes, dlCell->noResPerRb[cfi]);
10879
10880    RETVOID;
10881 } /* rgSchUtlDlCalc1CwPrb*/
10882
10883 /**
10884  * @brief  Utility function to calculate total num of PRBs required to
10885  *         satisfy DL BO(BO sum of all logical channels for that UE or an LC BO)
10886  *         for TM3/TM4
10887  *
10888  * @details
10889  *
10890  *     Function : rgSchUtlDlCalc2CwPrb
10891  *
10892  *    Calculate PRBs required for UE to satisfy BO in DL
10893  *   
10894  *    Note : Total calculated PRBs will be assigned to *prbReqrd
10895  *    
10896  *
10897  *  @param[in]  RgSchCellCb     *cell
10898  *  @param[in]  RgSchUeCb       *ue 
10899  *  @param[in]  U32              bo 
10900  *  @param[out] U32             *prbReqrd 
10901  *  @return Void
10902  **/
10903 #ifdef ANSI
10904 Void rgSchUtlDlCalc2CwPrb
10905 (
10906 RgSchCellCb    *cell,
10907 RgSchUeCb      *ue,
10908 U32             bo,
10909 U32            *prbReqrd
10910 )
10911 #else
10912 Void rgSchUtlDlCalc2CwPrb(cell, ue, bo, prbReqrd)
10913 RgSchCellCb   *cell;
10914 RgSchUeCb     *ue;
10915 U32            bo;
10916 U32           *prbReqrd;
10917 #endif
10918 {
10919    RgSchCmnDlCell *dlCell  = RG_SCH_CMN_GET_DL_CELL(cell); 
10920    RgSchCmnDlUe   *dlUe  = RG_SCH_CMN_GET_DL_UE(ue, cell); 
10921    U32            eff1, eff2;
10922    U32            noRes;
10923    U8             noLyr1, noLyr2;
10924    U8             iTbs1, iTbs2;
10925    U8             cfi = dlCell->currCfi;               
10926
10927    if ((dlUe->mimoInfo.forceTD) ||/* Transmit Diversity (TD) */
10928        (dlUe->mimoInfo.ri < 2))/* 1 layer precoding */
10929    {
10930       iTbs1  = dlUe->mimoInfo.cwInfo[0].iTbs[0];
10931       eff1   = (*(RgSchCmnTbSzEff *)(dlCell->cqiToEffTbl[0][cfi]))[iTbs1];
10932
10933       /* Optimization to convert totalBo (which is in-terms of bytes) to bits 
10934        * i.e, << 3 and multiply with 1024 i.e, << 10 */
10935       noRes = ((U64)((bo << 3) << 10)) / (eff1);
10936       /* Get the number of RBs needed for this transmission */
10937       /* Number of RBs = No of REs / No of REs per RB       */
10938       *prbReqrd = RGSCH_CEIL(noRes, dlCell->noResPerRb[cfi]);
10939    }
10940    else
10941    {
10942       noLyr1 = dlUe->mimoInfo.cwInfo[0].noLyr;
10943       noLyr2 = dlUe->mimoInfo.cwInfo[1].noLyr;
10944       iTbs1  = dlUe->mimoInfo.cwInfo[0].iTbs[noLyr1 - 1];
10945       iTbs2  = dlUe->mimoInfo.cwInfo[1].iTbs[noLyr2 - 1];
10946       eff1 = (*(RgSchCmnTbSzEff *)(dlCell->cqiToEffTbl[noLyr1 - 1][cfi]))[iTbs1];
10947       eff2 = (*(RgSchCmnTbSzEff *)(dlCell->cqiToEffTbl[noLyr2 - 1][cfi]))[iTbs2];
10948
10949       /* Optimization to convert totalBo (which is in-terms of bytes) to bits 
10950        * i.e, << 3 and multiply with 1024 i.e, << 10 */
10951       noRes = ((U64)((bo << 3) << 10)) / (eff1 + eff2);
10952       /* Get the number of RBs needed for this transmission */
10953       /* Number of RBs = No of REs / No of REs per RB       */
10954       *prbReqrd = RGSCH_CEIL(noRes, dlCell->noResPerRb[cfi]);
10955    }
10956    RETVOID;
10957 } /* rgSchUtlDlCalc2CwPrb */
10958
10959 /**
10960  * @brief  Utility function to calculate total num of PRBs required to
10961  *         satisfy DL BO(BO sum of all logical channels for that UE or an LC BO)
10962  *
10963  * @details
10964  *
10965  *     Function : rgSchUtlCalcTotalPrbReq
10966  *
10967  *    This function calls TM specific routine to calculate PRB
10968  *   
10969  *
10970  *  @param[in]  RgSchCellCb     *cell
10971  *  @param[in]  RgSchUeCb       *ue 
10972  *  @param[in]  U32              bo 
10973  *  @param[out] U32             *prbReqrd 
10974  *  @return Void
10975  **/
10976 #ifdef ANSI
10977 Void rgSchUtlCalcTotalPrbReq
10978 (
10979 RgSchCellCb    *cell,
10980 RgSchUeCb      *ue,
10981 U32             bo,
10982 U32            *prbReqrd
10983 )
10984 #else
10985 Void rgSchUtlCalcTotalPrbReq(cell, ue, bo, prbReqrd)
10986 RgSchCellCb   *cell;
10987 RgSchUeCb     *ue;
10988 U32            bo;
10989 U32           *prbReqrd;
10990 #endif
10991 {
10992    /* Call TM specific Prb calculation routine */
10993    (dlCalcPrbFunc[ue->mimoInfo.txMode - 1])(cell, ue, bo, prbReqrd);
10994
10995    RETVOID;
10996 } /* rgSchUtlCalcTotalPrbReq */
10997 #ifdef UNUSE_FUN
10998 #ifdef TFU_UPGRADE
10999 /***********************************************************
11000  *
11001  *     Func : rgSCHUtlFetchPcqiBitSz
11002  *
11003  *
11004  *     Desc : Fetch the CQI/PMI bits for a UE based on the mode, periodicity.
11005  *
11006  *     Ret  : U8
11007  *            ROK - Success
11008  *
11009  *     Notes:
11010  *
11011  *     File :
11012  *
11013  **********************************************************/
11014 #ifdef ANSI
11015 PRIVATE U8 rgSCHUtlFetchPcqiBitSz
11016 (
11017  RgSchCellCb    *cell,
11018  RgSchUeCb    *ueCb, 
11019  U8           numTxAnt
11020  )
11021 #else
11022 PRIVATE U8 rgSCHUtlFetchPcqiBitSz (cell, ueCb, numTxAnt)
11023 RgSchCellCb   *cell;
11024 RgSchUeCb     *ueCb;
11025 U8            numTxAnt;
11026 #endif
11027 {
11028    U8   confRepMode;
11029    U8   pcqiSz;
11030    U8   ri;
11031    RgSchUePCqiCb *cqiCb = RG_SCH_GET_UE_CELL_CQI_CB(ueCb,cell);
11032
11033    confRepMode = cqiCb->cqiCfg.cqiSetup.prdModeEnum;
11034    if((ueCb->mimoInfo.txMode != RGR_UE_TM_3) && 
11035          (ueCb->mimoInfo.txMode != RGR_UE_TM_4))
11036    {
11037       ri =1;
11038    }
11039    else
11040    {
11041       ri = cqiCb->perRiVal;
11042    }
11043    switch(confRepMode)
11044    {
11045       case RGR_PRD_CQI_MOD10:
11046       {
11047          pcqiSz = 4;
11048       }
11049       break;
11050
11051       case RGR_PRD_CQI_MOD11:
11052       {
11053          if(numTxAnt == 2)
11054          {
11055             if (ri ==1)
11056             {
11057                pcqiSz = 6;
11058             }
11059             else
11060             {
11061                pcqiSz = 8;
11062             }
11063          }
11064          else if(numTxAnt == 4)
11065          {
11066             if (ri ==1)
11067             {
11068                pcqiSz = 8;
11069             }
11070             else
11071             {
11072                pcqiSz = 11;
11073             }
11074          }
11075          else
11076          {
11077             /* This is number of antenna case 1.
11078              * This is not applicable for Mode 1-1. 
11079              * So setting it to invalid value */
11080             pcqiSz = 0;
11081          }
11082       }
11083       break;
11084
11085       case RGR_PRD_CQI_MOD20:
11086       {
11087          if(cqiCb->isWb)
11088          {
11089             pcqiSz = 4;
11090          }
11091          else
11092          {
11093             pcqiSz = 4 + cqiCb->label;
11094          }
11095       }
11096       break;
11097
11098       case RGR_PRD_CQI_MOD21:
11099       {
11100          if(cqiCb->isWb)
11101          {
11102              if(numTxAnt == 2)
11103              {
11104                 if (ri ==1)
11105                 {
11106                     pcqiSz = 6;
11107                 }
11108                 else
11109                 {
11110                     pcqiSz = 8;
11111                 }
11112              }
11113              else if(numTxAnt == 4)
11114              {
11115                 if (ri ==1)
11116                 {
11117                     pcqiSz = 8;
11118                 }
11119                 else
11120                 {
11121                     pcqiSz = 11;
11122                 }
11123              }
11124              else
11125              {
11126                 /* This might be number of antenna case 1.
11127                  * For mode 2-1 wideband case only antenna port 2 or 4 is supported.
11128                  * So setting invalid value.*/
11129                 pcqiSz = 0;
11130              }
11131           }
11132           else
11133           {
11134              if (ri ==1)
11135              {
11136                  pcqiSz = 4 + cqiCb->label;
11137              }
11138              else
11139              {
11140                  pcqiSz = 7 + cqiCb->label;
11141              }
11142           }
11143       }
11144       break;
11145
11146       default:
11147          pcqiSz = 0;
11148       break;
11149    }
11150    
11151    return (pcqiSz);
11152 }
11153 #endif
11154 #endif
11155 /**
11156  * @brief  Utility function to returns the number of subbands based on the 
11157  *         requested bytes.
11158  *
11159  * @details
11160  *
11161  *     Function : rgSchUtlGetNumSbs
11162  *
11163  *     Calculate the number of PRBs
11164  *     Update the subbandRequired based on the nPrbs and subband size
11165  *
11166  *  @param[in]  RgSchCellCb  *cell
11167  *  @param[in]  RgSchUeCb    *ue
11168  *  @param[in]  U32          *numSbs
11169  *  @return     U8
11170  **/
11171 #ifdef ANSI
11172 U8 rgSchUtlGetNumSbs
11173 (
11174 RgSchCellCb                  *cell,
11175 RgSchUeCb                    *ue,
11176 U32                          *numSbs
11177 )
11178 #else
11179 U8 rgSchUtlGetNumSbs (cell, ue, numSbs)
11180 RgSchCellCb                  *cell;
11181 RgSchUeCb                    *ue;
11182 U32                          *numSbs;
11183 #endif
11184 {
11185    U32                       nPrb;
11186    //Currently hardcoding MAX prb for each UE
11187    nPrb = ue->ue5gtfCb.maxPrb;
11188    (*numSbs) = RGSCH_CEIL(nPrb, MAX_5GTF_VRBG_SIZE);
11189    return ROK;
11190 }
11191
11192 /**
11193  * @brief  Utility function to insert the UE node into UE Lst based on the
11194  *         number of subbands allocated for the UE for the current TTI.
11195  *
11196  * @details
11197  *
11198  *     Function : rgSchUtlSortInsUeLst
11199  *
11200  *     If subbandRequired < Min, then insert at head
11201  *     Else If subbandRequired > Max, then insert at tail
11202  *     Else, traverse the list and place the node at the appropriate place
11203  *
11204  *  @param[in]  RgSchCellCb  *cell
11205  *  @param[in]  RgSchUeCb    *ue
11206  *  @return     U8
11207  **/
11208 #ifdef ANSI
11209 U8 rgSchUtlSortInsUeLst
11210 (
11211 RgSchCellCb  *cell,
11212 CmLListCp    *ueLst,
11213 CmLList      *node,
11214 U8           vrbgRequired
11215 )
11216 #else
11217 U8 rgSchUtlSortInsUeLst (cell, ueLst, node, vrbgRequired)
11218 RgSchCellCb  *cell;
11219 CmLListCp    *ueLst;
11220 CmLList      *node;
11221 U8           vrbgRequired;
11222 #endif
11223 {
11224    CmLList      *ueInLst;
11225    CmLList      *firstUeInLst;
11226    CmLList      *lastUeInLst;
11227    RgSchUeCb    *tempUe;
11228    RgSchCmnUlUe *ueUl;
11229
11230    //firstUeInLst = cmLListFirst(ueLst);
11231    CM_LLIST_FIRST_NODE(ueLst,firstUeInLst);
11232    if(NULLP == firstUeInLst)
11233    {
11234       /* first node to be added to the list */
11235       cmLListAdd2Tail(ueLst, node);
11236    }
11237    else
11238    {
11239       /* Sb Required for the UE is less than the first node in the list */
11240       tempUe      = (RgSchUeCb *)(firstUeInLst->node);
11241       ueUl = RG_SCH_CMN_GET_UL_UE(tempUe, cell);
11242
11243       if(vrbgRequired <= ueUl->vrbgRequired)
11244       {
11245          cmLListInsCrnt(ueLst, (node));
11246       }
11247       else
11248       {
11249          /* Sb Required for this UE is higher than the UEs in the list */
11250          lastUeInLst = cmLListLast(ueLst);
11251          tempUe      = (RgSchUeCb *)(lastUeInLst->node);
11252          if(vrbgRequired >= ueUl->vrbgRequired)
11253          {
11254             cmLListAdd2Tail(ueLst, (node));
11255          }
11256          else
11257          {
11258             /* This UE needs to be in the middle. Search and insert the UE */
11259             ueInLst = cmLListFirst(ueLst);
11260             do
11261             {
11262                tempUe = (RgSchUeCb *)(ueInLst->node);
11263
11264                if(vrbgRequired <= ueUl->vrbgRequired)
11265                {
11266                   cmLListInsCrnt(ueLst, (node));
11267                   break;
11268                }
11269
11270                ueInLst = cmLListNext(ueLst);
11271
11272             } while(NULLP != ueInLst && ueInLst != firstUeInLst);
11273          }
11274       }
11275    }
11276
11277    return ROK;
11278 }
11279
11280 /**
11281  * @brief Function to Send LCG GBR register to MAC
11282  *
11283  * @details
11284  *
11285  *     Function: rgSCHUtlBuildNSendLcgReg
11286  *
11287  *     Handler for sending LCG GBR registration 
11288  *
11289  *     Invoked by: 
11290  *         SCHD
11291  *
11292  *     Processing Steps:
11293  *           
11294  *  @param[in] RgSchCellCb       *cell
11295  *  @param[in] CmLteRnti         crnti
11296  *  @param[in] U8                lcgId
11297  *  @param[in] Bool              isGbr
11298  *  @return  S16
11299  *      -# ROK 
11300  **/
11301 #ifdef ANSI
11302 S16 rgSCHUtlBuildNSendLcgReg
11303 (
11304 RgSchCellCb    *cell,
11305 CmLteRnti      crnti,
11306 U8             lcgId,
11307 Bool           isGbr
11308 )
11309 #else
11310 S16 rgSCHUtlBuildNSendLcgReg(cell, crnti, lcgId, isGbr)
11311 RgSchCellCb    *cell;
11312 CmLteRnti      crnti;
11313 U8             lcgId;
11314 Bool           isGbr;
11315 #endif
11316 {
11317    Pst            pst;
11318    RgInfLcgRegReq lcgRegReq;
11319
11320    memset(&pst, 0, sizeof(Pst));
11321    lcgRegReq.isGbr  = isGbr;
11322    lcgRegReq.cellId = cell->cellId;
11323    lcgRegReq.crnti  = crnti;
11324    lcgRegReq.lcgId  = lcgId;
11325    rgSCHUtlGetPstToLyr(&pst, &rgSchCb[cell->instIdx], cell->macInst);
11326    /* code Coverage portion of the test case */ 
11327    RgSchMacLcgReg(&pst, &lcgRegReq);
11328
11329    return ROK;
11330 }
11331
11332 #ifdef TFU_UPGRADE
11333 #ifdef LTE_ADV
11334 #ifndef TFU_TDD
11335 /**
11336  * @brief Function to map RGR pucch type to TFU type
11337  *
11338  * @details
11339  *
11340  *     Function: rgSchUtlGetFdbkMode
11341  *
11342  *
11343  *     Invoked by: 
11344  *         SCHD
11345  *
11346  *     Processing Steps:
11347  *           
11348  *  @param[in] RgrSchFrmt1b3TypEnum
11349  *  @return  TfuAckNackMode
11350  *      -# ROK 
11351  **/
11352 #ifdef ANSI
11353 TfuAckNackMode rgSchUtlGetFdbkMode
11354 (
11355 RgrSchFrmt1b3TypEnum fdbkType
11356 )
11357 #else
11358 TfuAckNackMode rgSchUtlGetFdbkMode(fdbkType)
11359 RgrSchFrmt1b3TypEnum fdbkType;
11360 #endif
11361 {
11362
11363    TfuAckNackMode mode = TFU_UCI_FORMAT_1A_1B;
11364
11365    switch(fdbkType)
11366    {
11367      case RG_SCH_UCI_FORMAT_NON_CA:
11368      case RG_SCH_UCI_FORMAT1A_1B:
11369      {
11370         mode = TFU_UCI_FORMAT_1A_1B;
11371      }
11372      break;
11373      case RG_SCH_UCI_FORMAT1B_CS:
11374      {
11375         mode = TFU_UCI_FORMAT_1B_CS;
11376      }
11377      break;
11378      case RG_SCH_UCI_FORMAT3:
11379      {
11380         mode = TFU_UCI_FORMAT_3;
11381      }
11382      break;
11383    }
11384    return (mode);
11385 }
11386 #endif /* TFU_TDD */
11387 #endif /* LTE_ADV */
11388 #endif /*TFU_UPGRADE */
11389
11390 #ifdef LTE_ADV
11391 /**
11392  * @brief Send Ue SCell delete to SMAC.
11393  *
11394  * @details
11395  *
11396  *     Function : rgSCHUtlSndUeSCellDel2Mac 
11397  *       This function populates the struct RgInfRlsRnti and
11398  *       get the pst for SMac and mark field isUeSCellDel to TRUE which 
11399  *       indicates that it is a Ue SCell delete.
11400  *     
11401  *    
11402  *           
11403  *  @param[in]     RgSchCellCb    *cell
11404  *  @param[in]     CmLteRnti      rnti 
11405  *  @return  Void
11406  *      -# ROK 
11407  **/
11408 #ifdef ANSI
11409 Void rgSCHUtlSndUeSCellDel2Mac 
11410 (
11411 RgSchCellCb    *cell,
11412 CmLteRnti      rnti
11413 )
11414 #else
11415 Void rgSCHUtlSndUeSCellDel2Mac(cell, rnti)
11416 RgSchCellCb    *cell;
11417 CmLteRnti      rnti;
11418 #endif
11419 {
11420    Pst          pst;
11421    Inst         inst = cell->instIdx;
11422    RgInfRlsRnti rntiInfo;
11423
11424    RGSCHDBGINFONEW(inst,(rgSchPBuf(inst),"RNTI Release IND for UE(%d)\n", rnti));
11425    /* Copy the info to rntiInfo */
11426    rntiInfo.cellId = cell->cellId;
11427    rntiInfo.rnti   = rnti;
11428    /* Fix : syed ueId change as part of reestablishment.
11429     * Now SCH to trigger this. CRG ueRecfg for ueId change 
11430     * is dummy */          
11431    rntiInfo.ueIdChng = FALSE;
11432    rntiInfo.newRnti  = rnti;
11433    rntiInfo.isUeSCellDel = TRUE;
11434    /* Invoke MAC to release the rnti */
11435    rgSCHUtlGetPstToLyr(&pst, &rgSchCb[inst], cell->macInst);
11436    RgSchMacRlsRnti(&pst, &rntiInfo);
11437    RETVOID;
11438 }
11439
11440 /**
11441  * @brief Returns max TB supported by a given txMode
11442  *
11443  * @details
11444  *
11445  *     Function : rgSCHUtlGetMaxTbSupp
11446  *     Max TB supported for TM Modes (1,2,5,6 and 7) is 1
11447  *     and 2 for others
11448  *    
11449  *           
11450  *  @param[in]     RgrTxMode  txMode
11451  *  @return        U8 maxTbCount; 
11452  *      -# ROK 
11453  **/
11454 #ifdef ANSI
11455 U8 rgSCHUtlGetMaxTbSupp
11456 (
11457 RgrTxMode txMode
11458 )
11459 #else
11460 U8 rgSCHUtlGetMaxTbSupp(txMode)
11461 RgrTxMode txMode
11462 #endif
11463 {
11464    U8 maxTbCount;
11465
11466    /* Primary Cell */
11467
11468    switch(txMode)
11469    {
11470       case RGR_UE_TM_1:
11471       case RGR_UE_TM_2:
11472       case RGR_UE_TM_5:
11473       case RGR_UE_TM_6:
11474       case RGR_UE_TM_7:
11475          maxTbCount = 1;
11476          break;
11477       case RGR_UE_TM_3:
11478       case RGR_UE_TM_4:
11479       case RGR_UE_TM_8:
11480       case RGR_UE_TM_9:
11481          maxTbCount = 2;
11482          break;
11483       default:
11484          maxTbCount = 0;
11485          break;
11486    }
11487
11488    return (maxTbCount);
11489 }
11490
11491 /**
11492  * @brief Send Ue SCell delete to SMAC.
11493  *
11494  * @details
11495  *
11496  *     Function : rgSCHTomUtlGetTrigSet 
11497  *      This function gets the triggerset based on cqiReq 
11498  *     
11499  *  @param[in]     RgSchCellCb    *cell
11500  *  @param[in]     RgSchUeCb      ueCb 
11501  *  @param[in]     U8             cqiReq,
11502  *  @param[out]    U8             *triggerSet
11503  *
11504  *  @return  Void
11505  *      -# ROK 
11506  **/
11507 #ifdef ANSI
11508 Void rgSCHTomUtlGetTrigSet
11509 (
11510    RgSchCellCb       *cell,
11511    RgSchUeCb         *ueCb,
11512    U8                cqiReq,
11513    U8                *triggerSet
11514  )
11515 #else
11516 PRIVATE S16 rgSCHTomUtlGetTrigSet(cell, ueCb, cqiReq, triggerSet)
11517    RgSchCellCb       *cell;
11518    RgSchUeCb         *ueCb;
11519    U8                cqiReq;
11520    U8                *triggerSet;
11521 #endif
11522 {
11523    RgSchUeCellInfo *pCellInfo = RG_SCH_CMN_GET_PCELL_INFO(ueCb);
11524    switch(cqiReq)
11525    {
11526       case RG_SCH_APCQI_SERVING_CC:
11527          {
11528             /* APeriodic CQI request for Current Carrier.*/
11529             U8 sCellIdx = ueCb->cellIdToCellIdxMap[RG_SCH_CELLINDEX(cell)];
11530             *triggerSet = 1 << (7 - sCellIdx);
11531             break;
11532          }
11533       case RG_SCH_APCQI_1ST_SERVING_CCS_SET:
11534          {
11535             *triggerSet = pCellInfo->acqiCb.aCqiCfg.triggerSet1;
11536             break;
11537          }
11538       case RG_SCH_APCQI_2ND_SERVING_CCS_SET:
11539          {
11540             *triggerSet = pCellInfo->acqiCb.aCqiCfg.triggerSet2;
11541             break;
11542          }
11543       default:
11544          {
11545             /* BUG */
11546             break;
11547          }
11548    }
11549    RETVOID;
11550 }
11551 #endif
11552 /**
11553  * @brief This function updates the value of UE specific DCI sizes
11554  *
11555  * @details
11556  *
11557  *     Function: rgSCHUtlUpdUeDciSize
11558  *     Purpose:  This function calculates and updates DCI Sizes in bits.
11559  *
11560  *     Invoked by: Scheduler
11561  *
11562  *  @param[in]  RgSchCellCb       *cell
11563  *  @param[in]  RgSchUeCb         *ueCb
11564  *  @param[in]  isCsi2Bit         *isCsi2Bit: is 1 bit or 2 bit CSI
11565  *  @return     Void
11566  *
11567  **/
11568 #ifdef ANSI
11569 Void rgSCHUtlUpdUeDciSize
11570 (
11571 RgSchCellCb      *cell,
11572 RgSchUeCb        *ueCb,
11573 Bool             isCsi2Bit
11574 )
11575 #else
11576 Void rgSCHUtlUpdUeDciSize(cell, ueCb, isCsi2Bit)
11577 RgSchCellCb      *cell;
11578 RgSchUeCb        *ueCb;
11579 Bool             isCsi2Bit;
11580 #endif
11581 {
11582    U8 dci01aCmnSize = cell->dciSize.baseSize[TFU_DCI_FORMAT_0];
11583    U8 dci01aDedSize = cell->dciSize.baseSize[TFU_DCI_FORMAT_0];
11584    if ((ueCb->accessStratumRls >= RGR_REL_10) && (cell->bwCfg.dlTotalBw >= cell->bwCfg.ulTotalBw))
11585    {
11586       dci01aCmnSize += 1; /* Resource Allocation Type DCI 0 */
11587       dci01aDedSize += 1; /* Resource Allocation Type DCI 0 */
11588    }
11589    if (isCsi2Bit == TRUE)
11590    {
11591       dci01aDedSize += 2; /* 2 bit CSI DCI 0 */
11592    }
11593    else
11594    {
11595       dci01aDedSize += 1; /* 1 bit CSI DCI 0 */
11596    }
11597    
11598    /* Common CSI is always 1 bit DCI 0 */
11599    dci01aCmnSize += 1; /* 1 bit CSI DCI 0 */
11600
11601    /* Compare the sizes of DCI 0 with DCI 1A and consider the greater */
11602    if (dci01aCmnSize < cell->dciSize.baseSize[TFU_DCI_FORMAT_1A])
11603    {
11604       dci01aCmnSize = cell->dciSize.baseSize[TFU_DCI_FORMAT_1A];
11605    }
11606    if (dci01aDedSize < cell->dciSize.baseSize[TFU_DCI_FORMAT_1A])
11607    {
11608       dci01aDedSize = cell->dciSize.baseSize[TFU_DCI_FORMAT_1A];
11609    }
11610
11611    /* Remove the Ambiguous Sizes as mentioned in table Table 5.3.3.1.2-1 Spec 36.212-a80 Sec 5.3.3.1.3 */
11612    dci01aCmnSize += rgSchDciAmbigSizeTbl[dci01aCmnSize];
11613    dci01aDedSize += rgSchDciAmbigSizeTbl[dci01aDedSize];
11614
11615    ueCb->dciSize.cmnSize[TFU_DCI_FORMAT_0]  = dci01aCmnSize;
11616    ueCb->dciSize.cmnSize[TFU_DCI_FORMAT_1A] = dci01aCmnSize;
11617    
11618    ueCb->dciSize.dedSize[TFU_DCI_FORMAT_0]  = dci01aDedSize;
11619    ueCb->dciSize.dedSize[TFU_DCI_FORMAT_1A] = dci01aDedSize;
11620
11621    ueCb->dciSize.dedSize[TFU_DCI_FORMAT_1] = cell->dciSize.baseSize[TFU_DCI_FORMAT_1];
11622    do {
11623       /* Spec 36.212-a80 Sec 5.3.3.1.2: If the UE is configured to decode PDCCH with CRC scrambled 
11624        * by the C-RNTI and the number of information bits in format 1 is equal to that for format 0/1A 
11625        * for scheduling the same serving cell and mapped onto the UE specific search space given by the 
11626        * C-RNTI as defined in [3], one bit of value zero shall be appended to format 1. */
11627       if (ueCb->dciSize.dedSize[TFU_DCI_FORMAT_1] == ueCb->dciSize.dedSize[TFU_DCI_FORMAT_1A])
11628       {
11629          ueCb->dciSize.dedSize[TFU_DCI_FORMAT_1] += 1;
11630       }
11631
11632       /* Spec 36.212-a80 Sec 5.3.3.1.2: If the number of information bits in format 1 belongs 
11633        * to one of the sizes in Table 5.3.3.1.2-1, one or more zero bit(s) shall be appended 
11634        * to format 1 until the payload size of format 1 does not belong to one of the sizes in 
11635        * Table 5.3.3.1.2-1 and is not equal to that of format 0/1A mapped onto the same search space. */
11636       ueCb->dciSize.dedSize[TFU_DCI_FORMAT_1] += rgSchDciAmbigSizeTbl[ueCb->dciSize.dedSize[TFU_DCI_FORMAT_1]];
11637    } while (ueCb->dciSize.dedSize[TFU_DCI_FORMAT_1] == ueCb->dciSize.dedSize[TFU_DCI_FORMAT_1A]);
11638
11639    /* Just copying the value of 2/2A to avoid multiple checks at PDCCH allocations. This values never change.*/
11640    ueCb->dciSize.dedSize[TFU_DCI_FORMAT_2]  = cell->dciSize.size[TFU_DCI_FORMAT_2];
11641    ueCb->dciSize.dedSize[TFU_DCI_FORMAT_2A] = cell->dciSize.size[TFU_DCI_FORMAT_2A];
11642    ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_2]  = cell->dciSize.size[TFU_DCI_FORMAT_2];
11643    ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_2A] = cell->dciSize.size[TFU_DCI_FORMAT_2A];
11644
11645    /* Spec 36.212-a80 Sec 5.3.3.1.3: except when format 1A assigns downlink resource 
11646     * on a secondary cell without an uplink configuration associated with the secondary cell */
11647    ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1A] = cell->dciSize.baseSize[TFU_DCI_FORMAT_1A];
11648    ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1A] += rgSchDciAmbigSizeTbl[ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1A]];
11649    ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1] = cell->dciSize.baseSize[TFU_DCI_FORMAT_1];
11650    do {
11651       /* Spec 36.212-a80 Sec 5.3.3.1.2: If the UE is configured to decode PDCCH with CRC scrambled 
11652        * by the C-RNTI and the number of information bits in format 1 is equal to that for format 0/1A 
11653        * for scheduling the same serving cell and mapped onto the UE specific search space given by the 
11654        * C-RNTI as defined in [3], one bit of value zero shall be appended to format 1. */
11655       if (ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1] == ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1A])
11656       {
11657          ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1] += 1;
11658       }
11659
11660       /* Spec 36.212-a80 Sec 5.3.3.1.2: If the number of information bits in format 1 belongs 
11661        * to one of the sizes in Table 5.3.3.1.2-1, one or more zero bit(s) shall be appended 
11662        * to format 1 until the payload size of format 1 does not belong to one of the sizes in 
11663        * Table 5.3.3.1.2-1 and is not equal to that of format 0/1A mapped onto the same search space. */
11664       ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1] += rgSchDciAmbigSizeTbl[ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1]];
11665    } while (ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1] == ueCb->dciSize.noUlCcSize[TFU_DCI_FORMAT_1A]);
11666 #ifdef EMTC_ENABLE
11667    rgSCHEmtcUtlUpdUeDciSize(cell, ueCb); 
11668 #endif      
11669 }
11670
11671 /**
11672  * @brief This function initialises the DCI Size table
11673  *
11674  * @details
11675  *
11676  *     Function: rgSCHUtlCalcDciSizes
11677  *     Purpose:  This function calculates and initialises DCI Sizes in bits.
11678  *
11679  *     Invoked by: Scheduler
11680  *
11681  *  @param[in]  RgSchCellCb       *cell
11682  *  @return     Void
11683  *
11684  **/
11685 #ifdef ANSI
11686 Void rgSCHUtlCalcDciSizes
11687 (
11688 RgSchCellCb       *cell
11689 )
11690 #else
11691 Void rgSCHUtlCalcDciSizes(cell)
11692 RgSchCellCb       *cell;
11693 #endif
11694 {
11695    U8 dciSize = 0;
11696    U8 dci01aSize = 0;
11697    U32 bits = 0, idx = 0;
11698
11699    switch(TFU_DCI_FORMAT_0) /* Switch case for the purpose of readability */
11700    {
11701       case TFU_DCI_FORMAT_0:
11702          {
11703             /* DCI 0: Spec 36.212 Section 5.3.3.1.1 */
11704             dciSize = 0;
11705             /*-- Calculate resource block assignment bits need to be set
11706               Which is ln(N(N+1)/2) 36.212 5.3.3.1 --*/
11707             bits = (cell->bwCfg.ulTotalBw * (cell->bwCfg.ulTotalBw + 1) / 2);
11708             while ((bits & 0x8000) == 0)
11709             {
11710                bits <<= 1;
11711                idx++;
11712             }
11713             bits = 16 - idx;
11714
11715             dciSize = 1 /* DCI 0 bit indicator */ + \
11716                       1 /* Frequency hoping enable bit field */ + \
11717                       (U8)bits /* For frequency Hopping */ + \
11718                       5 /* MCS */ + \
11719                       1 /* NDI */ + \
11720                       2 /* TPC */ + \
11721                       3 /* DMRS */
11722 #ifdef TFU_TDD
11723                       + \
11724                       2 /* UL Index Config 0 or DAI Config 1-6 */
11725 #endif
11726                       ;
11727
11728             cell->dciSize.baseSize[TFU_DCI_FORMAT_0] = dciSize;
11729
11730             /* If hoping flag is enabled */
11731             if (cell->bwCfg.ulTotalBw <= 49) /* Spec 36.213 Table 8.4-1, N UL_hop, if hopping is enabled */
11732             {
11733                cell->dciSize.dci0HopSize = 1;
11734             }
11735             else
11736             {
11737                cell->dciSize.dci0HopSize = 2;
11738             }
11739
11740             /* Update common non-CRNTI scrambled DCI 0/1A flag */
11741             dci01aSize = cell->dciSize.baseSize[TFU_DCI_FORMAT_0] + 1; /* 1 bit CSI */
11742          }
11743       case TFU_DCI_FORMAT_1A:
11744          {
11745             /* DCI 1A: Spec 36.212 Section 5.3.3.1.3 */
11746             dciSize = 0;
11747             idx = 0;
11748             /* Calculate resource block assignment bits need to be set
11749               Which is ln(N(N+1)/2) */
11750             bits = (cell->bwCfg.dlTotalBw * (cell->bwCfg.dlTotalBw + 1) / 2);
11751             while ((bits & 0x8000) == 0)
11752             {
11753                bits <<= 1;
11754                idx++;
11755             }
11756             bits = 16 - idx;
11757
11758             dciSize += 1 /* Format 1A */ + \
11759                        1 /* Local or Distributed */ + \
11760                        (U8)bits /* Resource block Assignment */ + \
11761                        5 /* MCS */ + 
11762 #ifdef TFU_TDD
11763                        4 /* HARQ Proc Id */ + 
11764 #else
11765                        3 /* HARQ Proc Id */ + 
11766 #endif
11767                        1 /* NDI */ + \
11768                        2 /* RV */ + \
11769                        2 /* TPC CMD */
11770 #ifdef TFU_TDD
11771                        + \
11772                        2 /* DAI */
11773 #endif
11774                        ;
11775             cell->dciSize.baseSize[TFU_DCI_FORMAT_1A] = dciSize;
11776
11777             /* If the UE is not configured to decode PDCCH with CRC scrambled by the C-RNTI, 
11778              * and the number of information bits in format 1A is less than that of format 0, 
11779              * zeros shall be appended to format 1A until the payload size equals that of format 0. */
11780             /* Compare the size with DCI 1A  and DCI 0 and consider the greater one */
11781             if (dci01aSize < cell->dciSize.baseSize[TFU_DCI_FORMAT_1A])
11782             {
11783                dci01aSize = cell->dciSize.baseSize[TFU_DCI_FORMAT_1A];
11784             }
11785             /* If the number of information bits in format 1A belongs to one of the sizes in 
11786              * Table 5.3.3.1.2-1, one zero bit shall be appended to format 1A. */
11787             dci01aSize += rgSchDciAmbigSizeTbl[dci01aSize];
11788             cell->dciSize.size[TFU_DCI_FORMAT_1A] = cell->dciSize.size[TFU_DCI_FORMAT_0] = dci01aSize;
11789          }
11790       case TFU_DCI_FORMAT_1:
11791          {
11792             /* DCI 1: Spec 36.212 Section 5.3.3.1.2 */
11793             dciSize = 0;
11794             if (cell->bwCfg.dlTotalBw > 10)
11795             {
11796                dciSize = 1; /* Resource Allocation header bit */
11797             }
11798             
11799             /* Resouce allocation bits Type 0 and Type 1 */
11800             bits = (cell->bwCfg.dlTotalBw/cell->rbgSize);
11801             if ((cell->bwCfg.dlTotalBw % cell->rbgSize) != 0)
11802             {
11803                bits++;
11804             }
11805
11806             dciSize += (U8)bits /* Resource Allocation bits */ + \
11807                        5 /* MCS */ + 
11808 #ifdef TFU_TDD
11809                        4 /* HARQ TDD */ + 
11810 #else
11811                        3 /* HARQ FDD */ + 
11812 #endif
11813                        1 /* NDI */ + \
11814                        2 /* Redunancy Version */ + \
11815                        2 /* TPC Cmd */
11816 #ifdef TFU_TDD
11817                        + \
11818                        2 /* DAI */
11819 #endif
11820                        ;
11821
11822             
11823             cell->dciSize.baseSize[TFU_DCI_FORMAT_1] = dciSize;
11824
11825             cell->dciSize.size[TFU_DCI_FORMAT_1] = dciSize;
11826             
11827             do {
11828                /* If the UE is not configured to decode PDCCH with CRC 
11829                 * scrambled by the C-RNTI and the number of information bits in format 1 
11830                 * is equal to that for format 0/1A, one bit of value zero shall be appended 
11831                 * to format 1. */
11832                if (dci01aSize == cell->dciSize.size[TFU_DCI_FORMAT_1])
11833                {
11834                   cell->dciSize.size[TFU_DCI_FORMAT_1] += 1;
11835                }
11836
11837                /* If the number of information bits in format 1 belongs to one of the sizes in 
11838                 * Table 5.3.3.1.2-1, one or more zero bit(s) shall be appended to format 1 until 
11839                 * the payload size of format 1 does not belong to one of the sizes in Table 5.3.3.1.2-1 
11840                 * and is not equal to that of format 0/1A mapped onto the same search space. */
11841                cell->dciSize.size[TFU_DCI_FORMAT_1] += rgSchDciAmbigSizeTbl[cell->dciSize.size[TFU_DCI_FORMAT_1]];
11842             } while (cell->dciSize.size[TFU_DCI_FORMAT_1] == dci01aSize);
11843          }
11844       case TFU_DCI_FORMAT_2:
11845          {
11846             /* DCI 2: Spec 36.212 Section 5.3.3.1.5 */
11847             dciSize = 0;
11848             if (cell->bwCfg.dlTotalBw > 10)
11849             {
11850                dciSize = 1; /* Resource Allocation bit */
11851             }
11852
11853             dciSize += (U8)bits /* Resource Allocation bits */ + \
11854                        2 /* TPC */ + 
11855 #ifdef TFU_TDD
11856                        2 /* DAI */ + \
11857                        4 /* HARQ */ + 
11858 #else
11859                        3 /* HARQ */ +
11860 #endif
11861                        1 /* CW Swap Flag */ + \
11862                        5 /* MCS for TB1 */+ \
11863                        1 /* NDI for TB1 */+ \
11864                        2 /* RV for TB1 */ + \
11865                        5 /* MCS for TB2 */+ \
11866                        1 /* NDI for TB2 */+ \
11867                        2 /* RV for TB2 */;
11868             if (cell->numTxAntPorts == 2)
11869             {
11870                dciSize += 3;
11871             }
11872             else if (cell->numTxAntPorts == 4)
11873             {
11874                dciSize += 6;
11875             }
11876             cell->dciSize.size[TFU_DCI_FORMAT_2] = dciSize;
11877             cell->dciSize.size[TFU_DCI_FORMAT_2] += rgSchDciAmbigSizeTbl[cell->dciSize.size[TFU_DCI_FORMAT_2]];
11878          }
11879       case TFU_DCI_FORMAT_2A:
11880          {
11881             /* DCI 2A: Spec 36.212 Section 5.3.3.1.5A */
11882             dciSize = 0;
11883             if (cell->bwCfg.dlTotalBw > 10)
11884             {
11885                dciSize = 1; /* Resource Allocation bit */
11886             }
11887
11888             dciSize += (U8)bits /* Resource Allocation bits */ + \
11889                          2 /* TPC */ + 
11890 #ifdef TFU_TDD
11891                          2 /* DAI */ + \
11892                          4 /* HARQ */ + 
11893 #else
11894                          3 /* HARQ */ +
11895 #endif
11896                          1 /* CW Swap Flag */ + \
11897                          5 /* MCS for TB1 */+ \
11898                          1 /* NDI for TB1 */+ \
11899                          2 /* RV for TB1 */ + \
11900                          5 /* MCS for TB2 */+ \
11901                          1 /* NDI for TB2 */+ \
11902                          2 /* RV for TB2 */;
11903             if (cell->numTxAntPorts == 4)
11904             {
11905                dciSize += 2;
11906             }
11907             cell->dciSize.size[TFU_DCI_FORMAT_2A] = dciSize;
11908             cell->dciSize.size[TFU_DCI_FORMAT_2A] += \
11909                           rgSchDciAmbigSizeTbl[cell->dciSize.size[TFU_DCI_FORMAT_2A]]; /* Spec 39.212 Table 5.3.3.1.2-1 */
11910          }
11911       case TFU_DCI_FORMAT_3:
11912          {
11913             /* DCI 3: Spec 36.212 Section 5.3.3.1.6 */
11914             cell->dciSize.size[TFU_DCI_FORMAT_3] = cell->dciSize.size[TFU_DCI_FORMAT_1A] / 2;
11915             if (cell->dciSize.size[TFU_DCI_FORMAT_3] % 2)
11916             {
11917                cell->dciSize.size[TFU_DCI_FORMAT_3]++;
11918             }
11919          }
11920       case TFU_DCI_FORMAT_3A:
11921          {
11922             /* DCI 3A: Spec 36.212 Section 5.3.3.1.7 */
11923             cell->dciSize.size[TFU_DCI_FORMAT_3A] = cell->dciSize.size[TFU_DCI_FORMAT_1A];
11924          }
11925 #ifdef EMTC_ENABLE
11926       case TFU_DCI_FORMAT_6_0A:
11927          {
11928             rgSCHEmtcGetDciFrmt60ASize(cell);
11929          }
11930          case TFU_DCI_FORMAT_6_1A:
11931          {
11932             rgSCHEmtcGetDciFrmt61ASize(cell);
11933          }
11934 #endif                  
11935       default:
11936          {
11937             /* DCI format not supported */
11938             break;
11939          }
11940    }
11941 }
11942
11943 /**
11944  * @brief Handler for the CPU OvrLd related state adjustment.
11945  *
11946  * @details
11947  *
11948  *     Function : rgSCHUtlCpuOvrLdAdjItbsCap
11949  *
11950  *     Processing Steps:
11951  *      - Record dl/ulTpts 
11952  *      - Adjust maxItbs to acheive target throughputs
11953  *
11954  *  @param[in]  RgSchCellCb *cell
11955  *  @return  Void 
11956  **/
11957 #ifdef ANSI
11958 Void rgSCHUtlCpuOvrLdAdjItbsCap
11959 (
11960  RgSchCellCb *cell
11961 )
11962 #else
11963 Void rgSCHUtlCpuOvrLdAdjItbsCap(cell)
11964  RgSchCellCb *cell
11965 #endif
11966 {
11967    U32 tptDelta;
11968
11969    if ((cell->cpuOvrLdCntrl.cpuOvrLdIns) & (RGR_CPU_OVRLD_DL_TPT_UP | 
11970             RGR_CPU_OVRLD_DL_TPT_DOWN))
11971    {
11972       /* Regulate DL Tpt for CPU overload */
11973       if (cell->measurements.dlTpt > cell->cpuOvrLdCntrl.tgtDlTpt)
11974       {
11975          tptDelta = cell->measurements.dlTpt - cell->cpuOvrLdCntrl.tgtDlTpt;
11976          /* Upto 0.5% drift in measured vs target tpt is ignored */
11977          if (((tptDelta*1000)/cell->cpuOvrLdCntrl.tgtDlTpt) > 5)
11978          {
11979             cell->thresholds.maxDlItbs = RGSCH_MAX((cell->thresholds.maxDlItbs-1), 1);
11980          }
11981       }
11982       else
11983       {
11984          tptDelta = cell->cpuOvrLdCntrl.tgtDlTpt - cell->measurements.dlTpt;
11985          /* Upto 0.5% drift in measured vs target tpt is ignored */
11986          if (((tptDelta*1000)/cell->cpuOvrLdCntrl.tgtDlTpt) > 5)
11987          {
11988             cell->thresholds.maxDlItbs = RGSCH_MIN((cell->thresholds.maxDlItbs+1), RG_SCH_DL_MAX_ITBS);
11989          }
11990       }
11991 #ifdef CPU_OL_DBG_PRINTS
11992       printf("\n DL CPU OL ADJ = %lu, %lu, %d\n", cell->measurements.dlTpt, cell->cpuOvrLdCntrl.tgtDlTpt, 
11993             cell->thresholds.maxDlItbs);
11994 #endif
11995    }
11996
11997    if ((cell->cpuOvrLdCntrl.cpuOvrLdIns) & (RGR_CPU_OVRLD_UL_TPT_UP | 
11998             RGR_CPU_OVRLD_UL_TPT_DOWN))
11999    {
12000       /* Regualte DL Tpt for CPU overload */
12001       if (cell->measurements.ulTpt > cell->cpuOvrLdCntrl.tgtUlTpt)
12002       {
12003          tptDelta = cell->measurements.ulTpt - cell->cpuOvrLdCntrl.tgtUlTpt;
12004          /* Upto 1% drift in measured vs target tpt is ignored */
12005          if (((tptDelta*1000)/cell->cpuOvrLdCntrl.tgtUlTpt) > 10)
12006          {
12007             cell->thresholds.maxUlItbs = RGSCH_MAX((cell->thresholds.maxUlItbs-1), 1);
12008          }
12009       }
12010       else
12011       {
12012          tptDelta = cell->cpuOvrLdCntrl.tgtUlTpt - cell->measurements.ulTpt;
12013          /* Upto 1% drift in measured vs target tpt is ignored */
12014          if (((tptDelta*1000)/cell->cpuOvrLdCntrl.tgtUlTpt) > 10)
12015          {
12016             cell->thresholds.maxUlItbs = RGSCH_MIN((cell->thresholds.maxUlItbs+1), RG_SCH_UL_MAX_ITBS);
12017          }
12018       }
12019 #ifdef CPU_OL_DBG_PRINTS
12020       printf("\n UL CPU OL ADJ = %lu, %lu, %d\n", cell->measurements.ulTpt, cell->cpuOvrLdCntrl.tgtUlTpt, 
12021             cell->thresholds.maxUlItbs);
12022 #endif
12023    }
12024
12025    RETVOID;
12026 }
12027 /**
12028  * @brief Handler for the num UE per TTI based CPU OvrLd instr updating
12029  *
12030  * @details
12031  *
12032  *     Function : rgSCHUtlChkAndUpdNumUePerTtiCpuOvInstr
12033  *
12034  *     Processing Steps:
12035  *      - Validate the config params.
12036  *      - Update numUEperTTi CPU OL related information.
12037  *      - If successful, return ROK else RFAILED.
12038  *
12039  *  @param[in]  RgSchCellCb *cell
12040  *  @param[in]  U8          cnrtCpuOvrLdIns 
12041  *  @return     Void
12042  **/
12043 #ifdef ANSI
12044 PRIVATE Void rgSCHUtlChkAndUpdNumUePerTtiCpuOvInstr
12045 (
12046  RgSchCellCb *cell, 
12047  U8          crntCpuOvrLdIns
12048 )
12049 #else
12050 PRIVATE S16 rgSCHUtlChkAndUpdNumUePerTtiCpuOvInstr(cell, crntCpuOvrLdIns)
12051  RgSchCellCb *cell; 
12052  U8          crntCpuOvrLdIns;
12053 #endif
12054 {
12055    RgSchCpuOvrLdCntrlCb    *cpuInstr = &(cell->cpuOvrLdCntrl);
12056    RgSchCmnCell            *cellSch;
12057    U8                       maxUeNewDlTxPerTti;
12058    U8                       maxUeNewUlTxPerTti;
12059    U8                       tmpslot        = 0;
12060 #ifdef CPU_OL_DBG_PRINTS 
12061    U8                       idx = 0;
12062 #endif
12063    U8                       maxDlDecCnt;
12064    U8                       maxUlDecCnt;
12065
12066    cellSch = RG_SCH_CMN_GET_CELL(cell);
12067
12068    maxUeNewDlTxPerTti = cellSch->dl.maxUeNewTxPerTti; 
12069    maxUeNewUlTxPerTti = cellSch->ul.maxUeNewTxPerTti;
12070   
12071    /* Calculate Maximum Decremen */
12072    maxDlDecCnt =  (10*(maxUeNewDlTxPerTti - 1))-(10-RGR_MAX_PERC_NUM_UE_PER_TTI_RED);
12073    maxUlDecCnt =  (10*(maxUeNewUlTxPerTti - 1))-(10-RGR_MAX_PERC_NUM_UE_PER_TTI_RED);
12074
12075    /* Check for DL CPU Commands */
12076    if ( crntCpuOvrLdIns &  RGR_CPU_OVRLD_DL_DEC_NUM_UE_PER_TTI ) 
12077    {
12078       /* Decrement till 90% of maxUeNewDlTxPerTti */
12079       if ( cpuInstr->dlNxtIndxDecNumUeTti < maxDlDecCnt )
12080       {
12081          tmpslot = (cpuInstr->dlNxtIndxDecNumUeTti) % 10;
12082          cpuInstr->dlNxtIndxDecNumUeTti++;
12083          if ( cpuInstr->maxUeNewTxPerTti[tmpslot] > 1 )
12084          {
12085             cpuInstr->maxUeNewTxPerTti[tmpslot]--;
12086          }
12087          else
12088          {
12089 #ifdef CPU_OL_DBG_PRINTS
12090             printf("CPU_OL_TTI__ERROR\n");
12091 #endif
12092             RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Invalid CPU OL");
12093          }
12094       }
12095 #ifdef CPU_OL_DBG_PRINTS
12096       printf("dlNxtIndxDecNumUeTti = %d\n", cpuInstr->dlNxtIndxDecNumUeTti);
12097 #endif
12098       RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,"dlNxtIndxDecNumUeTti = %d",
12099          cpuInstr->dlNxtIndxDecNumUeTti);
12100    }
12101    else if ( crntCpuOvrLdIns &  RGR_CPU_OVRLD_DL_INC_NUM_UE_PER_TTI )
12102    {
12103       if ( cpuInstr->dlNxtIndxDecNumUeTti >  0) 
12104       {
12105          cpuInstr->dlNxtIndxDecNumUeTti--;
12106          tmpslot = (cpuInstr->dlNxtIndxDecNumUeTti) % 10;
12107          if ( cpuInstr->maxUeNewTxPerTti[tmpslot] < maxUeNewDlTxPerTti )
12108          {
12109             cpuInstr->maxUeNewTxPerTti[tmpslot]++;
12110          }
12111          else
12112          {
12113 #ifdef CPU_OL_DBG_PRINTS
12114             printf("CPU_OL_TTI__ERROR\n");
12115 #endif
12116             RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Invalid CPU OL");
12117          }
12118       }
12119 #ifdef CPU_OL_DBG_PRINTS
12120       printf("dlNxtIndxDecNumUeTti = %d\n", cpuInstr->dlNxtIndxDecNumUeTti);
12121 #endif
12122       RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,"dlNxtIndxDecNumUeTti = %d",
12123          cpuInstr->dlNxtIndxDecNumUeTti);
12124    }
12125    /* Check for UL CPU commands */
12126    if ( crntCpuOvrLdIns &  RGR_CPU_OVRLD_UL_DEC_NUM_UE_PER_TTI )
12127    {
12128       /* Decrement till 90% of maxUeNewDlTxPerTti */
12129       if ( cpuInstr->ulNxtIndxDecNumUeTti < maxUlDecCnt )
12130       {
12131          tmpslot = (cpuInstr->ulNxtIndxDecNumUeTti) % 10;
12132          cpuInstr->ulNxtIndxDecNumUeTti++;
12133          if ( cpuInstr->maxUeNewRxPerTti[tmpslot] > 1 )
12134          {
12135             cpuInstr->maxUeNewRxPerTti[tmpslot]--;
12136          }
12137          else
12138          {
12139 #ifdef CPU_OL_DBG_PRINTS
12140             printf("CPU_OL_TTI__ERROR\n");
12141 #endif
12142             RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Invalid CPU OL");
12143          }
12144       }
12145 #ifdef CPU_OL_DBG_PRINTS
12146       printf("ulNxtIndxDecNumUeTti = %d\n", cpuInstr->ulNxtIndxDecNumUeTti);
12147 #endif
12148       RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,"dlNxtIndxDecNumUeTti = %d",
12149          cpuInstr->dlNxtIndxDecNumUeTti);
12150    }
12151    else if ( crntCpuOvrLdIns &  RGR_CPU_OVRLD_UL_INC_NUM_UE_PER_TTI )
12152    {
12153       if ( cpuInstr->ulNxtIndxDecNumUeTti >  0) 
12154       {
12155          cpuInstr->ulNxtIndxDecNumUeTti--;
12156          tmpslot = (cpuInstr->ulNxtIndxDecNumUeTti) % 10;
12157          if ( cpuInstr->maxUeNewRxPerTti[tmpslot] < maxUeNewUlTxPerTti )
12158          {
12159             cpuInstr->maxUeNewRxPerTti[tmpslot]++;
12160          }
12161          else
12162          {
12163 #ifdef CPU_OL_DBG_PRINTS
12164             printf("CPU_OL_TTI__ERROR\n");
12165 #endif
12166             RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Invalid CPU OL");
12167          }
12168       }
12169 #ifdef CPU_OL_DBG_PRINTS
12170       printf("ulNxtIndxDecNumUeTti = %d\n", cpuInstr->ulNxtIndxDecNumUeTti);
12171 #endif
12172       RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,"dlNxtIndxDecNumUeTti = %d",
12173          cpuInstr->dlNxtIndxDecNumUeTti);
12174    }
12175 #ifdef CPU_OL_DBG_PRINTS 
12176  /* TODO: Debug Information - Shall be moved under CPU_OL_DBG_PRINTS */
12177    printf("maxUeNewDlTxPerTti = %d, maxUeNewUlTxPerTti = %d\n", maxUeNewDlTxPerTti, maxUeNewUlTxPerTti);
12178    printf("DL Sf numUePerTti:");
12179    for ( idx = 0; idx < 10 ; idx ++ )
12180    {
12181       printf("  %d", cpuInstr->maxUeNewTxPerTti[idx]);  
12182    }
12183    printf("\nUL Sf numUePerTti:");
12184    for ( idx = 0; idx < 10 ; idx ++ )
12185    {
12186       printf("  %d", cpuInstr->maxUeNewRxPerTti[idx]);  
12187    }
12188    printf("\n");
12189 #endif
12190
12191    RETVOID;
12192 } /* rgSCHUtlChkAndUpdNumUePerTtiCpuOvInstr */
12193
12194 /**
12195  * @brief Handler for the CPU OvrLd related cell Recfg.
12196  *
12197  * @details
12198  *
12199  *     Function : rgSCHUtlResetCpuOvrLdState
12200  *
12201  *     Processing Steps:
12202  *      - Validate the config params.
12203  *      - Update CPU OL related state information.
12204  *      - If successful, return ROK else RFAILED.
12205  *
12206  *  @param[in]  RgSchCellCb *cell
12207  *  @param[in]  U8          cnrtCpuOvrLdIns 
12208  *  @return  S16
12209  *      -# ROK
12210  *      -# RFAILED
12211  **/
12212 #ifdef ANSI
12213 S16 rgSCHUtlResetCpuOvrLdState
12214 (
12215  RgSchCellCb *cell, 
12216  U8          crntCpuOvrLdIns
12217 )
12218 #else
12219 S16 rgSCHUtlResetCpuOvrLdState(cell, crntCpuOvrLdIns)
12220  RgSchCellCb *cell; 
12221  U8          crntCpuOvrLdIns;
12222 #endif
12223 {
12224    U8              crntDlCpuOL=0;
12225    U8              crntUlCpuOL=0;
12226    RgSchCmnCell    *schCmnCell = (RgSchCmnCell *)(cell->sc.sch);
12227    U8 idx;
12228
12229 #ifdef CPU_OL_DBG_PRINTS
12230    printf("\n CPU OVR LD Ins Rcvd = %d\n", (int)crntCpuOvrLdIns);
12231 #endif
12232    RLOG_ARG0(L_INFO,DBG_CELLID,cell->cellId,"CPU OVR LD Ins Rcvd");
12233
12234    if ( RGR_CPU_OVRLD_RESET == crntCpuOvrLdIns )
12235    {
12236       /* The CPU OL instruction received with RESET (0), hence reset it */
12237 #ifdef CPU_OL_DBG_PRINTS
12238       printf("rgSCHUtlResetCpuOvrLdState: RESET CPU OL instr\n");
12239 #endif
12240       RLOG_ARG0(L_INFO,DBG_CELLID,cell->cellId,"RESET CPU OVR LD");
12241       cell->cpuOvrLdCntrl.cpuOvrLdIns = 0;
12242       /* Reset the max UL and DL itbs to 26 */
12243       cell->thresholds.maxUlItbs = RG_SCH_UL_MAX_ITBS;
12244       cell->thresholds.maxDlItbs = RG_SCH_DL_MAX_ITBS;
12245       /* Reset the num UE per TTI intructions */
12246       cell->cpuOvrLdCntrl.dlNxtIndxDecNumUeTti = 0;
12247       cell->cpuOvrLdCntrl.ulNxtIndxDecNumUeTti = 0;
12248       for ( idx = 0; idx < 10; idx++ )
12249       {
12250          cell->cpuOvrLdCntrl.maxUeNewTxPerTti[idx] = 
12251             schCmnCell->dl.maxUeNewTxPerTti;
12252          cell->cpuOvrLdCntrl.maxUeNewRxPerTti[idx] = 
12253             schCmnCell->ul.maxUeNewTxPerTti;
12254       }
12255
12256       return ROK;
12257    }
12258    /* Check and Update numUEPer TTI based CPU overload instruction before
12259     * going for TP based CPU OL  
12260     * TTI based intrcuctions shall be > 0xF */
12261    if ( crntCpuOvrLdIns >  0xF )  
12262    {
12263       rgSCHUtlChkAndUpdNumUePerTtiCpuOvInstr(cell, crntCpuOvrLdIns);
12264       /* If need to have both TP and numUePerTti instrcution together in
12265        * one command then dont return from here */
12266       return ROK;
12267    }
12268
12269    crntDlCpuOL = (crntCpuOvrLdIns & RGR_CPU_OVRLD_DL_TPT_UP) +\
12270                  (crntCpuOvrLdIns & RGR_CPU_OVRLD_DL_TPT_DOWN);
12271    if ((crntDlCpuOL) && (crntDlCpuOL != RGR_CPU_OVRLD_DL_TPT_UP) && 
12272        (crntDlCpuOL != RGR_CPU_OVRLD_DL_TPT_DOWN))
12273    {
12274       /* Cfg validation failed. Invalid Command. Either UP/DOWN is allowed */
12275       return RFAILED;
12276    }
12277    crntUlCpuOL = (crntCpuOvrLdIns & RGR_CPU_OVRLD_UL_TPT_UP) +\
12278                  (crntCpuOvrLdIns & RGR_CPU_OVRLD_UL_TPT_DOWN);
12279    if ((crntUlCpuOL) && (crntUlCpuOL != RGR_CPU_OVRLD_UL_TPT_UP) && 
12280        (crntUlCpuOL != RGR_CPU_OVRLD_UL_TPT_DOWN))
12281    {
12282       /* Cfg validation failed. Invalid Command. Either UP/DOWN is allowed */
12283       return RFAILED;
12284    }
12285    if ((crntDlCpuOL == 0) && (crntUlCpuOL == 0))
12286    {
12287       /* Cfg validation failed. Invalid Command. Either UP/DOWN is allowed */
12288       return RFAILED;
12289    }
12290
12291    cell->cpuOvrLdCntrl.cpuOvrLdIns = crntCpuOvrLdIns;
12292
12293    if (crntUlCpuOL)
12294    {
12295       if (crntUlCpuOL == RGR_CPU_OVRLD_UL_TPT_DOWN)
12296       {
12297          cell->cpuOvrLdCntrl.tgtUlTpt = cell->measurements.ulTpt - \
12298             (cell->measurements.ulTpt * 3 )/100;
12299       }
12300       else
12301       {
12302          cell->cpuOvrLdCntrl.tgtUlTpt = cell->measurements.ulTpt + \
12303             (cell->measurements.ulTpt * 2 )/100;
12304       }
12305       RLOG_ARG3(L_DEBUG,DBG_CELLID,cell->cellId,"CPU OVR LD UL Reset to "
12306             "%d, %lu, %lu", (int)crntUlCpuOL, cell->cpuOvrLdCntrl.tgtUlTpt,cell->measurements.ulTpt);
12307 #ifdef CPU_OL_DBG_PRINTS
12308       printf("\n CPU OVR LD UL Reset to= %d, %lu, %lu\n", (int)crntUlCpuOL, cell->cpuOvrLdCntrl.tgtUlTpt,
12309                               cell->measurements.ulTpt);
12310 #endif
12311    }
12312
12313    if (crntDlCpuOL)
12314    {
12315       if (crntDlCpuOL == RGR_CPU_OVRLD_DL_TPT_DOWN)
12316       {
12317          cell->cpuOvrLdCntrl.tgtDlTpt = cell->measurements.dlTpt - \
12318                                         (cell->measurements.dlTpt * 1 )/100;
12319       }
12320       else
12321       {
12322          cell->cpuOvrLdCntrl.tgtDlTpt = cell->measurements.dlTpt + \
12323             (cell->measurements.dlTpt * 1 )/100;
12324       }
12325       RLOG_ARG3(L_DEBUG,DBG_CELLID,cell->cellId,"CPU OVR LD DL Reset to "
12326             "%d, %lu, %lu", (int)crntDlCpuOL, cell->cpuOvrLdCntrl.tgtDlTpt,cell->measurements.dlTpt);
12327
12328 #ifdef CPU_OL_DBG_PRINTS
12329       printf("\n CPU OVR LD DL Reset to= %d, %lu, %lu\n", (int)crntDlCpuOL, cell->cpuOvrLdCntrl.tgtDlTpt,
12330                               cell->measurements.dlTpt);
12331 #endif
12332    }
12333    rgSCHUtlCpuOvrLdAdjItbsCap(cell);
12334    return ROK;
12335 }
12336 #ifdef EMTC_ENABLE
12337 S16 rgSCHUtlAddToResLst
12338 (
12339  CmLListCp   *cp,  
12340  RgSchIotRes *iotRes
12341  )
12342 {
12343    cmLListAdd2Tail(cp, &iotRes->resLnk);
12344    iotRes->resLnk.node = (PTR)iotRes;
12345    return ROK;
12346 }
12347 S16 rgSCHUtlDelFrmResLst
12348 (
12349 RgSchUeCb *ue,
12350 RgSchIotRes *iotRes
12351 )
12352 {
12353    CmLListCp  *cp = NULLP;
12354    RgSchEmtcUeInfo *emtcUe = NULLP;
12355    emtcUe = RG_GET_EMTC_UE_CB(ue);
12356    if(iotRes->resType == RG_SCH_EMTC_PUCCH_RES)
12357    {
12358       cp = &emtcUe->ulResLst;
12359    }else if(iotRes->resType == RG_SCH_EMTC_PDSCH_RES)
12360    {
12361       cp = &emtcUe->dlResLst;
12362    }else
12363    {
12364       RLOG0(L_INFO, "*****restype mismatch");
12365    }
12366    if(cp != NULLP )
12367    { 
12368       if(cp->count == 0)
12369       {
12370          RLOG0(L_INFO,"****error count*****\n");
12371          return ROK;
12372       }
12373    }
12374    cmLListDelFrm(cp, &iotRes->resLnk);
12375    iotRes->resLnk.node = NULLP;
12376    return ROK;
12377 }
12378 #endif
12379 /**********************************************************************
12380
12381          End of file
12382 **********************************************************************/