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