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