Merge "replaced cmMemSet, cmMemcpy with memset and memcpy resp AND Removed TRC()...
[o-du/l2.git] / src / 5gnrsch / rg_sch_cmn.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_cmn.c
28
29 **********************************************************************/
30
31 /** @file rg_sch_cmn.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_FILE_ID=187;
37 static int RLOG_MODULE_ID=4096;
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 "rgm.h"
45 #include "rg_env.h"
46 #include "rg_sch_err.h"
47 #include "rg_sch_inf.h"
48 #include "rg_sch.h"
49 #include "rg_sch_cmn.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"           /* layer management typedefs for MAC */
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 MAC_SCH_STATS
62 #include "lrg.x"            /* Stats Structures */
63 #endif /* MAC_SCH_STATS */
64 #ifdef __cplusplus
65 extern "C" {
66 #endif /* __cplusplus */
67
68 #ifdef EMTC_ENABLE
69 EXTERN U32 emtcStatsUlTomSrInd;
70 EXTERN U32 emtcStatsUlBsrTmrTxp;
71 #endif
72
73 #define RG_ITBS_DIFF(_x, _y) ((_x) > (_y) ? (_x) - (_y) : (_y) - (_x))
74 EXTERN Void rgSCHSc1UlInit ARGS((RgUlSchdApis *apis));
75 #ifdef RG_PHASE2_SCHED
76 EXTERN Void rgSCHRrUlInit ARGS((RgUlSchdApis *apis));
77 #ifdef EMTC_ENABLE
78 EXTERN Void rgSCHEmtcHqInfoFree ARGS((RgSchCellCb *cell, RgSchDlHqProcCb *hqP));
79 EXTERN Void rgSCHEmtcRrUlInit ARGS((RgUlSchdApis *apis));
80 EXTERN Void rgSCHEmtcCmnDlInit ARGS((Void));
81 EXTERN Void rgSCHEmtcCmnUlInit ARGS((Void));
82 EXTERN Void rgSCHEmtcCmnUeNbReset ARGS((RgSchUeCb *ueCb));
83 EXTERN RgSchCmnCqiToTbs *rgSchEmtcCmnCqiToTbs[RGSCH_MAX_NUM_LYR_PERCW][RG_SCH_CMN_MAX_CP][RG_SCH_CMN_MAX_CFI];
84 #endif
85 EXTERN Void rgSCHMaxciUlInit ARGS((RgUlSchdApis *apis));
86 EXTERN Void rgSCHPfsUlInit ARGS((RgUlSchdApis *apis));
87 #endif
88 EXTERN Void rgSCHSc1DlInit ARGS((RgDlSchdApis *apis));
89 #ifdef RG_PHASE2_SCHED
90 EXTERN Void rgSCHRrDlInit ARGS((RgDlSchdApis *apis));
91 #ifdef EMTC_ENABLE
92 EXTERN Void rgSCHEmtcRrDlInit ARGS((RgDlEmtcSchdApis *apis));
93 #endif
94 EXTERN Void rgSCHMaxciDlInit ARGS((RgDlSchdApis *apis));
95 EXTERN Void rgSCHPfsDlInit ARGS((RgDlSchdApis *apis));
96 #ifdef TFU_UPGRADE
97 EXTERN Void rgSCHDlfsInit ARGS((RgDlfsSchdApis *apis));
98 #endif
99 #endif
100 #ifdef EMTC_ENABLE
101 EXTERN Void rgSCHCmnGetCqiEmtcDciFrmt2AggrLvl ARGS((RgSchCellCb *cell));
102 EXTERN Void rgSCHCmnGetEmtcDciFrmtSizes ARGS((RgSchCellCb *cell));
103 EXTERN Void rgSCHEmtcRrUlProcRmvFrmRetx ARGS((RgSchCellCb *cell, RgSchUlHqProcCb *proc));
104 EXTERN S16 rgSCHCmnPrecompEmtcMsg3Vars
105 ARGS((
106 RgSchCmnUlCell *cellUl,
107 U8           ccchCqi,
108 U16          msgSzA,
109 U8           sbSize,
110 Bool         isEcp
111 ));
112 Void rgSCHEmtcCmnUeCcchSduDel
113 (
114 RgSchCellCb  *cell,
115 RgSchUeCb    *ueCb
116 );
117 EXTERN Void rgSCHEmtcRmvFrmTaLst
118 (
119 RgSchCmnDlCell  *cellDl,
120 RgSchUeCb       *ue
121 );
122 EXTERN Void rgSCHEmtcInitTaLst
123 (
124 RgSchCmnDlCell  *cellDl
125 );
126 EXTERN Void rgSCHEmtcAddToTaLst
127 (
128 RgSchCmnDlCell  *cellDl,
129 RgSchUeCb       *ue
130 );
131
132 #endif
133
134 #ifdef RGR_SI_SCH
135 PRIVATE Void rgSCHDlSiSched ARGS((RgSchCellCb  *cell,
136                       RgSchCmnDlRbAllocInfo *allocInfo,
137                       RgInfSfAlloc  *subfrmAlloc));
138 PRIVATE Void rgSCHChkNUpdSiCfg ARGS((RgSchCellCb  *cell));
139 PRIVATE Void rgSCHSelectSi ARGS((RgSchCellCb *cell));
140 #endif /*RGR_SI_SCH*/
141 /* LTE_ADV_FLAG_REMOVED_START */
142 #ifdef UNUSED_FUNC
143 #ifndef LTE_TDD
144 PRIVATE S16 rgSCHCmnNonDlfsUpdDSFRTyp2Alloc
145 (
146 RgSchCellCb        *cell,
147 RgSchUeCb          *ue,
148 RgSchDlSf          *dlSf,
149 U8                 rbStrt,
150 U8                 numRb
151 );
152 PRIVATE S16 rgSCHCmnBuildRntpInfo (
153 RgSchCellCb        *cell,
154 U8                 *rntpPtr,
155 U8                  startRb,
156 U8                  nmbRb,
157 U16                 bw
158 );
159 #endif
160 PRIVATE Void rgSCHCmnNonDlfsType0Alloc
161 (
162 RgSchCellCb        *cell,
163 RgSchDlSf          *dlSf,
164 RgSchDlRbAlloc     *allocInfo,
165 RgSchUeCb          *ue
166 );
167 PRIVATE U8 rgSchCmnUlRvIdxToIMcsTbl[4] = {32, 30, 31, 29};
168 PRIVATE Void rgSCHCmnUlNonadapRetx ARGS((
169 RgSchCmnUlCell  *cellUl,
170 RgSchUlAlloc    *alloc,
171 U8               idx
172 ));
173 PRIVATE Void rgSCHCmnUlSfRlsRetxProcs ARGS((
174 RgSchCellCb *cell,
175 RgSchUlSf   *sf
176 ));
177
178 #ifdef TFU_UPGRADE
179 PRIVATE S16 rgSCHCmnUlMdfyGrntForCqi ARGS((
180 RgSchCellCb  *cell,
181 RgSchUeCb    *ue,
182 U32          maxRb,
183 U32          *numSb,
184 U8           *iTbs,
185 U32          hqSz,
186 U32          stepDownItbs,
187 U32          effTgt
188 ));
189 #endif
190 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt1 ARGS((
191 RgSchCellCb                *cell,
192 RgSchDlRbAlloc             *rbAllocInfo,
193 RgSchDlHqProcCb            *hqP,
194 RgSchPdcch                 *pdcch,
195 U8                         tpc
196 ));
197 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt1A ARGS((
198 RgSchCellCb                *cell,
199 RgSchDlRbAlloc             *rbAllocInfo,
200 RgSchDlHqProcCb            *hqP,
201 RgSchPdcch                 *pdcch,
202 U8                         tpc
203 ));
204 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt1B ARGS((
205 RgSchCellCb                *cell,
206 RgSchDlRbAlloc             *rbAllocInfo,
207 RgSchDlHqProcCb            *hqP,
208 RgSchPdcch                 *pdcch,
209 U8                         tpc
210 ));
211 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt2 ARGS((
212 RgSchCellCb                *cell,
213 RgSchDlRbAlloc             *rbAllocInfo,
214 RgSchDlHqProcCb            *hqP,
215 RgSchPdcch                 *pdcch,
216 U8                         tpc
217 ));
218 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt2A ARGS((
219 RgSchCellCb                *cell,
220 RgSchDlRbAlloc             *rbAllocInfo,
221 RgSchDlHqProcCb            *hqP,
222 RgSchPdcch                 *pdcch,
223 U8                         tpc
224 ));
225
226 #endif
227
228 Void rgSCHCmnDlSpsSch
229 (
230  RgSchCellCb        *cell
231 );
232 /* LTE_ADV_FLAG_REMOVED_END */
233
234 PRIVATE Void rgSCHCmnNonDlfsBcchPcchRbAlloc ARGS((
235 RgSchCellCb           *cell,
236 RgSchCmnDlRbAllocInfo *allocInfo
237 ));
238 PRIVATE Void rgSCHBcchPcchDlRbAlloc ARGS((
239 RgSchCellCb           *cell,
240 RgSchCmnDlRbAllocInfo *allocInfo
241 ));
242 PRIVATE Void rgSCHCmnDlBcchPcchAlloc ARGS((
243 RgSchCellCb  *cell
244 ));
245 #ifdef RGR_CQI_REPT
246 PRIVATE Void rgSCHCmnDlCqiOnPucchInd ARGS ((
247  RgSchCellCb        *cell,
248  RgSchUeCb          *ue,
249  TfuDlCqiPucch      *pucchCqi,
250  RgrUeCqiRept       *ueCqiRept,
251  Bool               *isCqiAvail,
252  Bool               *is2ndCwCqiAvail
253  ));
254 PRIVATE Void rgSCHCmnDlCqiOnPuschInd ARGS ((
255  RgSchCellCb        *cell,
256  RgSchUeCb          *ue,
257  TfuDlCqiPusch      *puschCqi,
258  RgrUeCqiRept       *ueCqiRept,
259  Bool               *isCqiAvail,
260  Bool               *is2ndCwCqiAvail
261  ));
262 #else
263 PRIVATE Void rgSCHCmnDlCqiOnPucchInd ARGS ((
264  RgSchCellCb        *cell,
265  RgSchUeCb          *ue,
266  TfuDlCqiPucch      *pucchCqi
267  ));
268 PRIVATE Void rgSCHCmnDlCqiOnPuschInd ARGS ((
269  RgSchCellCb        *cell,
270  RgSchUeCb          *ue,
271  TfuDlCqiPusch      *puschCqi
272  ));
273 #endif
274 /* ccpu00117452 - MOD - Changed macro name from
275    RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
276 #ifdef RGR_CQI_REPT
277 PRIVATE S16 rgSCHCmnUeDlPwrCtColltCqiRept ARGS((
278    RgSchCellCb        *cell,
279    RgSchUeCb          *ue,
280    RgrUeCqiRept        *ueCqiRept));
281 #endif /* End of RGR_CQI_REPT */
282 /* Fix: syed align multiple UEs to refresh at same time */
283 PRIVATE Void rgSCHCmnGetRefreshPer ARGS((
284    RgSchCellCb  *cell,
285    RgSchUeCb    *ue,
286    U32          *waitPer));
287 PRIVATE S16 rgSCHCmnApplyUeRefresh ARGS((
288 RgSchCellCb     *cell,
289 RgSchUeCb       *ue));
290 #ifdef DL_LA
291 Void rgSCHCmnDlSetUeAllocLmtLa ARGS
292 ((
293 RgSchCellCb   *cell,
294 RgSchUeCb     *ue
295 ));
296 PRIVATE Void rgSCHCheckAndSetTxScheme ARGS
297 ((
298 RgSchCellCb   *cell,
299 RgSchUeCb     *ue
300 ));
301 #endif
302
303 #ifdef LTE_TDD
304 PRIVATE U32 rgSCHCmnCalcDwPtsTbSz ARGS
305 ((
306 RgSchCellCb    *cell,
307 U32             bo,
308 U8             *rb,
309 U8             *iTbs,
310 U8              lyr,
311 U8              cfi
312 ));
313
314 PRIVATE Void rgSCHCmnCalcDwPtsTbSz2Cw ARGS
315 ((
316 RgSchCellCb    *cell,
317 U32             bo,
318 U8             *rb,
319 U8              maxRb,
320 U8             *iTbs1,
321 U8             *iTbs2,
322 U8              lyr1,
323 U8              lyr2,
324 U32            *tb1Sz, 
325 U32            *tb2Sz, 
326 U8              cfi
327 ));
328
329 #endif
330 PRIVATE Void  rgSCHCmnInitRbAlloc ARGS 
331 ((
332 RgSchCellCb        *cell
333 ));
334 #ifdef __cplusplus
335 }
336 #endif /* __cplusplus */
337
338
339 /* local defines */
340  RgSchdApis          rgSchCmnApis;
341 PRIVATE RgUlSchdApis        rgSchUlSchdTbl[RGSCH_NUM_SCHEDULERS];
342 PRIVATE RgDlSchdApis        rgSchDlSchdTbl[RGSCH_NUM_SCHEDULERS];
343 #ifdef EMTC_ENABLE
344 PRIVATE RgUlSchdApis        rgSchEmtcUlSchdTbl[RGSCH_NUM_EMTC_SCHEDULERS];
345 PRIVATE RgDlEmtcSchdApis        rgSchEmtcDlSchdTbl[RGSCH_NUM_EMTC_SCHEDULERS];
346 #endif
347 #ifdef RG_PHASE2_SCHED
348 PRIVATE RgDlfsSchdApis      rgSchDlfsSchdTbl[RGSCH_NUM_DLFS_SCHEDULERS];
349 #endif
350 PRIVATE RgUlSchdInits       rgSchUlSchdInits = RGSCH_ULSCHED_INITS;
351 PRIVATE RgDlSchdInits       rgSchDlSchdInits = RGSCH_DLSCHED_INITS;
352 #ifdef EMTC_ENABLE
353 PRIVATE RgEmtcUlSchdInits       rgSchEmtcUlSchdInits = RGSCH_EMTC_ULSCHED_INITS;
354 PRIVATE RgEmtcDlSchdInits       rgSchEmtcDlSchdInits = RGSCH_EMTC_DLSCHED_INITS;
355 #endif
356 #if (defined (RG_PHASE2_SCHED) && defined (TFU_UPGRADE))
357 PRIVATE RgDlfsSchdInits     rgSchDlfsSchdInits = RGSCH_DLFSSCHED_INITS;
358 #endif
359
360 typedef Void (*RgSchCmnDlAllocRbFunc) ARGS((RgSchCellCb *cell, RgSchDlSf *subFrm,
361 RgSchUeCb *ue, U32 bo, U32 *effBo, RgSchDlHqProcCb *proc,
362 RgSchCmnDlRbAllocInfo *cellWdAllocInfo));
363 typedef U8 (*RgSchCmnDlGetPrecInfFunc) ARGS((RgSchCellCb *cell, RgSchUeCb *ue, 
364       U8 numLyrs, Bool bothCwEnbld));
365 PRIVATE Void rgSCHCmnDlAllocTxRbTM1 ARGS((
366 RgSchCellCb                *cell,
367 RgSchDlSf                  *subFrm,
368 RgSchUeCb                  *ue,
369 U32                        bo,
370 U32                        *effBo,
371 RgSchDlHqProcCb            *proc,
372 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
373 ));
374 PRIVATE Void rgSCHCmnDlAllocTxRbTM2 ARGS((
375 RgSchCellCb                *cell,
376 RgSchDlSf                  *subFrm,
377 RgSchUeCb                  *ue,
378 U32                        bo,
379 U32                        *effBo,
380 RgSchDlHqProcCb            *proc,
381 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
382 ));
383 PRIVATE Void rgSCHCmnDlAllocTxRbTM3 ARGS((
384 RgSchCellCb                *cell,
385 RgSchDlSf                  *subFrm,
386 RgSchUeCb                  *ue,
387 U32                        bo,
388 U32                        *effBo,
389 RgSchDlHqProcCb            *proc,
390 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
391 ));
392 PRIVATE Void rgSCHCmnDlAllocTxRbTM4 ARGS((
393 RgSchCellCb                *cell,
394 RgSchDlSf                  *subFrm,
395 RgSchUeCb                  *ue,
396 U32                        bo,
397 U32                        *effBo,
398 RgSchDlHqProcCb            *proc,
399 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
400 ));
401 #ifdef RG_UNUSED
402 PRIVATE Void rgSCHCmnDlAllocTxRbTM5 ARGS((
403 RgSchCellCb                *cell,
404 RgSchDlSf                  *subFrm,
405 RgSchUeCb                  *ue,
406 U32                        bo,
407 U32                        *effBo,
408 RgSchDlHqProcCb            *proc,
409 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
410 ));
411 #endif
412 PRIVATE Void rgSCHCmnDlAllocTxRbTM6 ARGS((
413 RgSchCellCb                *cell,
414 RgSchDlSf                  *subFrm,
415 RgSchUeCb                  *ue,
416 U32                        bo,
417 U32                        *effBo,
418 RgSchDlHqProcCb            *proc,
419 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
420 ));
421 PRIVATE Void rgSCHCmnDlAllocTxRbTM7 ARGS((
422 RgSchCellCb                *cell,
423 RgSchDlSf                  *subFrm,
424 RgSchUeCb                  *ue,
425 U32                        bo,
426 U32                        *effBo,
427 RgSchDlHqProcCb            *proc,
428 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
429 ));
430 PRIVATE Void rgSCHCmnDlAllocRetxRbTM1 ARGS((
431 RgSchCellCb                *cell,
432 RgSchDlSf                  *subFrm,
433 RgSchUeCb                  *ue,
434 U32                        bo,
435 U32                        *effBo,
436 RgSchDlHqProcCb            *proc,
437 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
438 ));
439 PRIVATE Void rgSCHCmnDlAllocRetxRbTM2 ARGS((
440 RgSchCellCb                *cell,
441 RgSchDlSf                  *subFrm,
442 RgSchUeCb                  *ue,
443 U32                        bo,
444 U32                        *effBo,
445 RgSchDlHqProcCb            *proc,
446 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
447 ));
448 PRIVATE Void rgSCHCmnDlAllocRetxRbTM3 ARGS((
449 RgSchCellCb                *cell,
450 RgSchDlSf                  *subFrm,
451 RgSchUeCb                  *ue,
452 U32                        bo,
453 U32                        *effBo,
454 RgSchDlHqProcCb            *proc,
455 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
456 ));
457 PRIVATE Void rgSCHCmnDlAllocRetxRbTM4 ARGS((
458 RgSchCellCb                *cell,
459 RgSchDlSf                  *subFrm,
460 RgSchUeCb                  *ue,
461 U32                        bo,
462 U32                        *effBo,
463 RgSchDlHqProcCb            *proc,
464 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
465 ));
466 #ifdef RG_UNUSED
467 PRIVATE Void rgSCHCmnDlAllocRetxRbTM5 ARGS((
468 RgSchCellCb                *cell,
469 RgSchDlSf                  *subFrm,
470 RgSchUeCb                  *ue,
471 U32                        bo,
472 U32                        *effBo,
473 RgSchDlHqProcCb            *proc,
474 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
475 ));
476 #endif
477 PRIVATE Void rgSCHCmnDlAllocRetxRbTM6 ARGS((
478 RgSchCellCb                *cell,
479 RgSchDlSf                  *subFrm,
480 RgSchUeCb                  *ue,
481 U32                        bo,
482 U32                        *effBo,
483 RgSchDlHqProcCb            *proc,
484 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
485 ));
486 PRIVATE Void rgSCHCmnDlAllocRetxRbTM7 ARGS((
487 RgSchCellCb                *cell,
488 RgSchDlSf                  *subFrm,
489 RgSchUeCb                  *ue,
490 U32                        bo,
491 U32                        *effBo,
492 RgSchDlHqProcCb            *proc,
493 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
494 ));
495
496 #ifdef LTE_ADV 
497 PRIVATE U8 rgSchGetN1ResCount ARGS ((
498  RgSchUeCb *ue,
499  U16       servCellId 
500 ));
501 Bool rgSchCmnChkDataOnlyOnPcell 
502 (
503  RgSchUeCb         *ue,
504  RgSchDlSf         *dlSf
505 );
506 #endif /*LTE_ADV */
507 U8 rgSCHCmnCalcPcqiBitSz
508 (
509  RgSchUeCb    *ueCb, 
510  U8           numTxAnt
511 );
512
513 #ifndef LTE_ADV
514 /* Functions specific to each transmission mode for DL Tx RB Allocation*/
515 RgSchCmnDlAllocRbFunc  dlAllocTxRbFunc[7] = {rgSCHCmnDlAllocTxRbTM1,
516 rgSCHCmnDlAllocTxRbTM2, rgSCHCmnDlAllocTxRbTM3, rgSCHCmnDlAllocTxRbTM4,
517 NULLP, rgSCHCmnDlAllocTxRbTM6, rgSCHCmnDlAllocTxRbTM7};
518
519 /* Functions specific to each transmission mode for DL Retx RB Allocation*/
520 RgSchCmnDlAllocRbFunc  dlAllocRetxRbFunc[7] = {rgSCHCmnDlAllocRetxRbTM1,
521 rgSCHCmnDlAllocRetxRbTM2, rgSCHCmnDlAllocRetxRbTM3, rgSCHCmnDlAllocRetxRbTM4,
522 NULLP, rgSCHCmnDlAllocRetxRbTM6, rgSCHCmnDlAllocRetxRbTM7};
523 #else
524 /* Functions specific to each transmission mode for DL Tx RB Allocation*/
525 RgSchCmnDlAllocRbFunc  dlAllocTxRbFunc[9] = {rgSCHCmnDlAllocTxRbTM1,
526 rgSCHCmnDlAllocTxRbTM2, rgSCHCmnDlAllocTxRbTM3, rgSCHCmnDlAllocTxRbTM4,
527 NULLP, rgSCHCmnDlAllocTxRbTM6, rgSCHCmnDlAllocTxRbTM7, NULLP, NULLP};
528
529 /* Functions specific to each transmission mode for DL Retx RB Allocation*/
530 RgSchCmnDlAllocRbFunc  dlAllocRetxRbFunc[9] = {rgSCHCmnDlAllocRetxRbTM1,
531 rgSCHCmnDlAllocRetxRbTM2, rgSCHCmnDlAllocRetxRbTM3, rgSCHCmnDlAllocRetxRbTM4,
532 NULLP, rgSCHCmnDlAllocRetxRbTM6, rgSCHCmnDlAllocRetxRbTM7, NULLP, NULLP};
533
534 #endif
535
536
537 PRIVATE U8 rgSCHCmnDlTM3PrecInf2 ARGS((
538 RgSchCellCb                *cell,
539 RgSchUeCb                  *ue,
540 U8                         numTxLyrs,
541 Bool                       bothCwEnbld
542 ));
543 PRIVATE U8 rgSCHCmnDlTM3PrecInf4 ARGS((
544 RgSchCellCb                *cell,
545 RgSchUeCb                  *ue,
546 U8                         numTxLyrs,
547 Bool                       bothCwEnbld
548 ));
549 PRIVATE U8 rgSCHCmnDlTM4PrecInf2 ARGS((
550 RgSchCellCb                *cell,
551 RgSchUeCb                  *ue,
552 U8                         numTxLyrs,
553 Bool                       bothCwEnbld
554 ));
555 PRIVATE U8 rgSCHCmnDlTM4PrecInf4 ARGS((
556 RgSchCellCb                *cell,
557 RgSchUeCb                  *ue,
558 U8                         numTxLyrs,
559 Bool                       bothCwEnbld
560 ));
561 /* Functions specific to each transmission mode for DL RB Allocation*/
562 RgSchCmnDlGetPrecInfFunc getPrecInfoFunc[2][2] = {
563 {rgSCHCmnDlTM3PrecInf2, rgSCHCmnDlTM3PrecInf4},
564 {rgSCHCmnDlTM4PrecInf2, rgSCHCmnDlTM4PrecInf4}
565 };
566
567 PRIVATE S16 rgSCHCmnDlAlloc1CwRetxRb ARGS((
568 RgSchCellCb                *cell,
569 RgSchDlSf                  *subFrm,
570 RgSchUeCb                  *ue,
571 RgSchDlHqTbCb              *tbInfo,
572 U8                         noLyr,
573 U8                         *numRb,
574 U32                        *effBo
575 ));
576 PRIVATE S16 rgSCHCmnDlAlloc2CwRetxRb ARGS((
577 RgSchCellCb                *cell,
578 RgSchDlSf                  *subFrm,
579 RgSchUeCb                  *ue,
580 RgSchDlHqProcCb            *proc,
581 U8                         *numRb,
582 Bool                       *swpFlg,
583 U32                        *effBo
584 ));
585 PRIVATE Void rgSCHCmnDlTM3TxTx ARGS((
586 RgSchCellCb                *cell,
587 RgSchDlSf                  *subFrm,
588 RgSchUeCb                  *ue,
589 U32                        bo,
590 U32                        *effBo,
591 RgSchDlHqProcCb            *proc,
592 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
593 ));
594 PRIVATE Void rgSCHCmnDlTM3TxRetx ARGS((
595 RgSchCellCb                *cell,
596 RgSchDlSf                  *subFrm,
597 RgSchUeCb                  *ue,
598 U32                        bo,
599 U32                        *effBo,
600 RgSchDlHqProcCb            *proc,
601 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
602 ));
603 PRIVATE Void rgSCHCmnDlTM3RetxRetx ARGS((
604 RgSchCellCb                *cell,
605 RgSchDlSf                  *subFrm,
606 RgSchUeCb                  *ue,
607 U32                        bo,
608 U32                        *effBo,
609 RgSchDlHqProcCb            *proc,
610 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
611 ));
612
613 PRIVATE Void rgSCHCmnNonDlfsUpdTyp2Alloc ARGS((
614 RgSchCellCb        *cell,
615 RgSchDlSf          *dlSf,
616 U8                 rbStrt,
617 U8                 numRb
618 ));
619 /* LTE_ADV_FLAG_REMOVED_START */
620 #ifndef LTE_TDD
621 PRIVATE Void rgSCHCmnNonDlfsSFRCmnChannelUpdTyp2Alloc ARGS((
622 RgSchCellCb        *cell,
623 RgSchDlSf          *dlSf,
624 U8                 rbStrt,
625 U8                 numRb
626 ));
627 #endif
628 /* LTE_ADV_FLAG_REMOVED_END */
629 PRIVATE Void rgSCHCmnDlRbInfoAddUeTx ARGS((
630 RgSchCellCb        *cell,
631 RgSchCmnDlRbAllocInfo *allocInfo,
632 RgSchUeCb             *ue,
633 RgSchDlHqProcCb       *proc
634 ));
635 PRIVATE Void rgSCHCmnDlRbInfoAddUeRetx ARGS((
636 RgSchCellCb        *cell,
637 RgSchCmnDlRbAllocInfo *allocInfo,
638 RgSchUeCb             *ue,
639 RgSchDlHqProcCb       *hqP
640 ));
641 PRIVATE Void rgSCHCmnDlAdd2NonSchdRetxLst ARGS((
642 RgSchCmnDlRbAllocInfo *allocInfo,
643 RgSchUeCb             *ue,
644 RgSchDlHqProcCb       *proc
645 ));
646 PRIVATE S16 rgSCHCmnDlAlloc2CwTxRetxRb ARGS((
647 RgSchCellCb                *cell,
648 RgSchDlSf                  *subFrm,
649 RgSchUeCb                  *ue,
650 RgSchDlHqTbCb              *reTxTb,
651 RgSchDlHqTbCb              *txTb,
652 U8                         *numRb,
653 U32                        *effBo
654 ));
655 PRIVATE S16 rgSCHCmnDlAlloc2CwTxRb ARGS((
656 RgSchCellCb                *cell,
657 RgSchDlSf                  *subFrm,
658 RgSchUeCb                  *ue,
659 RgSchDlHqProcCb            *proc,
660 U32                        bo,
661 U8                         *numRb,
662 U32                        *effBo
663 ));
664 PRIVATE S16 rgSCHCmnDlAlloc1CwTxRb ARGS((
665 RgSchCellCb                *cell,
666 RgSchDlSf                  *subFrm,
667 RgSchUeCb                  *ue,
668 RgSchDlHqTbCb              *tbInfo,
669 U32                        bo,
670 U8                         *numRb,
671 U32                        *effBo
672 ));
673 #ifndef LTEMAC_SPS
674 PRIVATE Void rgSCHCmnFillHqPTb ARGS((
675 RgSchCellCb                *cell,
676 RgSchDlRbAlloc             *rbAllocInfo,
677 U8                         tbAllocIdx,
678 RgSchPdcch                 *pdcch
679 ));
680 #endif
681 #ifdef LTEMAC_SPS
682 PRIVATE Void rgSCHCmnDlGetBestFitHole ARGS((
683 U32         *allocMask,
684 U8          numMaskRbs,
685 U32         *crntAllocMask,
686 U8          rbsReq,
687 U8          *allocStart,
688 U8          *allocNumRbs,
689 Bool        isPartialAlloc
690 ));
691 #ifdef RGSCH_SPS_UNUSED
692 PRIVATE U32 rgSCHCmnGetRaType1Mask ARGS((
693 U8                rbIdx,
694 U8                rbgSize,
695 U8                *type1Subset
696 ));
697 #endif
698 PRIVATE U32 rgSCHCmnGetRaType0Mask ARGS((
699 U8                rbIdx,
700 U8                rbgSize
701 ));
702 PRIVATE U32 rgSCHCmnGetRaType2Mask ARGS((
703 U8                rbIdx,
704 U8                *maskIdx
705 ));
706 #endif
707
708 Bool rgSCHCmnRetxAllocAvoid ARGS(( 
709 RgSchDlSf                  *subFrm,
710 RgSchCellCb                *cell,
711 RgSchDlHqProcCb            *proc
712 ));
713
714 U16 rgSCHCmnGetSiSetId ARGS((
715 U16    sfn,
716 U8     sf,
717 U16    minPeriodicity
718 ));
719
720
721 #ifdef RG_5GTF
722 //TODO_SID: Currenly table is only for 100 Prbs. Need to modify wrt VRBG table 8.1.5.2.1-1 V5G_213
723 U32 rgSch5gtfTbSzTbl[MAX_5GTF_MCS] = 
724     {1864, 5256, 8776, 13176, 17576, 21976, 26376, 31656, 35176, 39576, 43976, 47496, 52776, 59376, 66392};
725 U32 g5gtfTtiCnt = 0;
726 U32 gUl5gtfSrRecv = 0;
727 U32 gUl5gtfBsrRecv = 0;
728 U32 gUl5gtfUeSchPick = 0;
729 U32 gUl5gtfPdcchSchd = 0;
730 U32 gUl5gtfAllocAllocated = 0;
731 U32 gUl5gtfUeRbAllocDone = 0;
732 U32 gUl5gtfUeRmvFnlzZeroBo = 0;
733 U32 gUl5gtfUeFnlzReAdd = 0;
734 U32 gUl5gtfPdcchSend = 0;
735 U32 gUl5gtfRbAllocFail = 0;
736 U32 ul5gtfsidUlMarkUl = 0;
737 U32 ul5gtfsidDlSchdPass = 0;
738 U32 ul5gtfsidDlAlreadyMarkUl = 0;
739 U32 ul5gtfTotSchdCnt = 0;
740 #endif
741
742 /* CQI Offset Index to Beta CQI Offset value mapping,
743  * stored as parts per 1000. Reserved is set to 0.
744  * Refer 36.213 sec 8.6.3 Tbl 8.6.3-3 */
745 U32 rgSchCmnBetaCqiOffstTbl[16] = {0, 0, 1125,
746    1250, 1375, 1625, 1750, 2000, 2250, 2500, 2875,
747    3125, 3500, 4000, 5000, 6250};
748 U32 rgSchCmnBetaHqOffstTbl[16] =  {2000, 2500, 3125, 
749    4000, 5000, 6250, 8000,10000, 12625, 15875, 20000, 
750    31000, 50000,80000,126000,0};
751 U32 rgSchCmnBetaRiOffstTbl[16] = {1250, 1625, 2000, 
752    2500, 3125, 4000, 5000, 6250, 8000, 10000,12625,
753    15875,20000,0,0,0};
754 S8 rgSchCmnDlCqiDiffOfst[8] = {0, 1, 2, 3, -4, -3, -2, -1};
755
756 /* Include CRS REs while calculating Efficiency */
757 CONSTANT PRIVATE U8 rgSchCmnAntIdx[5] = {0,0,1,0,2};
758 CONSTANT PRIVATE U8 rgSchCmnNumResForCrs[5] = {0,6,12,0,16};
759 U32 cfiSwitchCnt ;
760 U32 cfiIncr ;
761 U32 cfiDecr ;
762
763
764 #ifdef TFU_UPGRADE
765 S8 rgSchCmnApUeSelDiffCqi[4] = {1, 2, 3, 4};
766 S8 rgSchCmnApEnbConfDiffCqi[4] = {0, 1, 2, -1};
767 #endif
768
769 typedef struct rgSchCmnDlUeDciFrmtOptns
770 {
771   TfuDciFormat spfcDciFrmt;   /* TM(Transmission Mode) specific DCI format.
772                                * Search space : UE Specific by C-RNTI only. */
773   U8           spfcDciRAType; /* Resource Alloctn(RA) type for spfcDciFrmt */
774   TfuDciFormat prfrdDciFrmt;  /* Preferred DCI format among the available
775                                * options for TD (Transmit Diversity) */
776   U8           prfrdDciRAType; /* Resource Alloctn(RA) type for prfrdDciFrmt */
777 }RgSchCmnDlUeDciFrmtOptns;
778 #ifndef LTE_ADV
779
780 /* DCI Format options for each Transmission Mode */
781 RgSchCmnDlUeDciFrmtOptns rgSchCmnDciFrmtOptns[7] = {
782    {TFU_DCI_FORMAT_1, RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
783    {TFU_DCI_FORMAT_1, RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
784    {TFU_DCI_FORMAT_2A,RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
785    {TFU_DCI_FORMAT_2, RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
786    {TFU_DCI_FORMAT_1D,RG_SCH_CMN_RA_TYPE2, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
787    {TFU_DCI_FORMAT_1B,RG_SCH_CMN_RA_TYPE2, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
788    {TFU_DCI_FORMAT_1, RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2}
789 };
790
791 #else
792 /* DCI Format options for each Transmission Mode */
793 RgSchCmnDlUeDciFrmtOptns rgSchCmnDciFrmtOptns[9] = {
794    {TFU_DCI_FORMAT_1, RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
795    {TFU_DCI_FORMAT_1, RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
796    {TFU_DCI_FORMAT_2A,RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
797    {TFU_DCI_FORMAT_2, RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
798    {TFU_DCI_FORMAT_1D,RG_SCH_CMN_RA_TYPE2, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
799    {TFU_DCI_FORMAT_1B,RG_SCH_CMN_RA_TYPE2, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2},
800    {TFU_DCI_FORMAT_1, RG_SCH_CMN_RA_TYPE0, TFU_DCI_FORMAT_1A, RG_SCH_CMN_RA_TYPE2}
801 };
802 #endif
803
804
805 typedef struct rgSchCmnDlImcsTbl
806 {
807   U8   modOdr; /* Modulation Order */
808   U8   iTbs;   /* ITBS */
809 }RgSchCmnDlImcsTbl[29];
810
811 CONSTANT struct rgSchCmnMult235Info
812 {
813    U8   match;    /* Closest number satisfying 2^a.3^b.5^c, with a bias
814                   * towards the smaller number */
815    U8   prvMatch; /* Closest number not greater than array index
816                   * satisfying 2^a.3^b.5^c */
817 } rgSchCmnMult235Tbl[110+1] = {
818    {0, 0},  /* dummy */
819    {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {6, 6}, {8, 8},
820    {9, 9}, {10, 10}, {10, 10}, {12, 12}, {12, 12}, {15, 12}, {15, 15},
821    {16, 16}, {16, 16}, {18, 18}, {18, 18}, {20, 20}, {20, 20}, {20, 20},
822    {24, 20}, {24, 24}, {25, 25}, {25, 25}, {27, 27}, {27, 27}, {30, 27},
823    {30, 30}, {30, 30}, {32, 32}, {32, 32}, {32, 32}, {36, 32}, {36, 36},
824    {36, 36}, {36, 36}, {40, 36}, {40, 40}, {40, 40}, {40, 40}, {45, 40},
825    {45, 40}, {45, 45}, {45, 45}, {48, 45}, {48, 48}, {48, 48}, {50, 50},
826    {50, 50}, {50, 50}, {54, 50}, {54, 54}, {54, 54}, {54, 54}, {54, 54},
827    {60, 54}, {60, 54}, {60, 60}, {60, 60}, {60, 60}, {64, 60}, {64, 64},
828    {64, 64}, {64, 64}, {64, 64}, {64, 64}, {72, 64}, {72, 64}, {72, 64},
829    {72, 72}, {72, 72}, {75, 72}, {75, 75}, {75, 75}, {75, 75}, {80, 75},
830    {80, 75}, {80, 80}, {81, 81}, {81, 81}, {81, 81}, {81, 81}, {81, 81},
831    {90, 81}, {90, 81}, {90, 81}, {90, 81}, {90, 90}, {90, 90}, {90, 90},
832    {90, 90}, {96, 90}, {96, 90}, {96, 96}, {96, 96}, {96, 96}, {100, 96},
833    {100, 100}, {100, 100}, {100, 100}, {100, 100}, {100, 100}, {108, 100},
834    {108, 100}, {108, 100}, {108, 108}, {108, 108}, {108, 108}
835 };
836
837 /* R8 Upgrade */
838 /* BI table from 36.321 Table 7.2.1 */
839 CONSTANT PRIVATE S16 rgSchCmnBiTbl[RG_SCH_CMN_NUM_BI_VAL] = {
840       0, 10, 20, 30,40,60,80,120,160,240,320,480,960};
841 RgSchCmnUlCqiInfo rgSchCmnUlCqiTbl[RG_SCH_CMN_UL_NUM_CQI] = {
842  {     0,                0              },
843  {RGSCH_CMN_QM_CQI_1,RGSCH_CMN_UL_EFF_CQI_1 },
844  {RGSCH_CMN_QM_CQI_2,RGSCH_CMN_UL_EFF_CQI_2 },
845  {RGSCH_CMN_QM_CQI_3,RGSCH_CMN_UL_EFF_CQI_3 },
846  {RGSCH_CMN_QM_CQI_4,RGSCH_CMN_UL_EFF_CQI_4 },
847  {RGSCH_CMN_QM_CQI_5,RGSCH_CMN_UL_EFF_CQI_5 },
848  {RGSCH_CMN_QM_CQI_6,RGSCH_CMN_UL_EFF_CQI_6 },
849  {RGSCH_CMN_QM_CQI_7,RGSCH_CMN_UL_EFF_CQI_7 },
850  {RGSCH_CMN_QM_CQI_8,RGSCH_CMN_UL_EFF_CQI_8 },
851  {RGSCH_CMN_QM_CQI_9,RGSCH_CMN_UL_EFF_CQI_9 },
852  {RGSCH_CMN_QM_CQI_10,RGSCH_CMN_UL_EFF_CQI_10 },
853  {RGSCH_CMN_QM_CQI_11,RGSCH_CMN_UL_EFF_CQI_11 },
854  {RGSCH_CMN_QM_CQI_12,RGSCH_CMN_UL_EFF_CQI_12 },
855  {RGSCH_CMN_QM_CQI_13,RGSCH_CMN_UL_EFF_CQI_13 },
856  {RGSCH_CMN_QM_CQI_14,RGSCH_CMN_UL_EFF_CQI_14 },
857  {RGSCH_CMN_QM_CQI_15,RGSCH_CMN_UL_EFF_CQI_15 },
858 };
859
860 #ifdef RG_UNUSED
861 /* This table maps a (delta_offset * 2 + 2) to a (beta * 8)
862  * where beta is 10^-(delta_offset/10) rounded off to nearest 1/8
863  */
864 PRIVATE U16 rgSchCmnUlBeta8Tbl[29] = {
865    6, RG_SCH_CMN_UL_INVALID_BETA8, 8, 9, 10, 11, 13, 14, 16, 18, 20, 23,
866    25, 28, 32, RG_SCH_CMN_UL_INVALID_BETA8, 40, RG_SCH_CMN_UL_INVALID_BETA8,
867    50, RG_SCH_CMN_UL_INVALID_BETA8, 64, RG_SCH_CMN_UL_INVALID_BETA8, 80,
868    RG_SCH_CMN_UL_INVALID_BETA8, 101, RG_SCH_CMN_UL_INVALID_BETA8, 127,
869    RG_SCH_CMN_UL_INVALID_BETA8, 160
870 };
871 #endif
872
873 /* QCI to SVC priority mapping. Index specifies the Qci*/
874 PRIVATE U8 rgSchCmnDlQciPrio[RG_SCH_CMN_MAX_QCI] = RG_SCH_CMN_QCI_TO_PRIO;
875
876 /* The configuration is efficiency measured per 1024 REs.  */
877 /* The first element stands for when CQI is not known      */
878 /* This table is used to translate CQI to its corrospoding */
879 /* allocation parameters. These are currently from 36.213  */
880 /* Just this talbe needs to be edited for modifying the    */
881 /* the resource allocation behaviour                       */
882
883 /* ADD CQI to MCS mapping correction
884  * single dimensional array is replaced by 2 dimensions for different CFI*/
885 PRIVATE U16 rgSchCmnCqiPdschEff[4][16] = {RG_SCH_CMN_CQI_TO_PDSCH_EFF_CFI0 ,RG_SCH_CMN_CQI_TO_PDSCH_EFF_CFI1,
886     RG_SCH_CMN_CQI_TO_PDSCH_EFF_CFI2,RG_SCH_CMN_CQI_TO_PDSCH_EFF_CFI3};
887
888 PRIVATE U16 rgSchCmn2LyrCqiPdschEff[4][16] = {RG_SCH_CMN_2LYR_CQI_TO_PDSCH_EFF_CFI0 ,RG_SCH_CMN_2LYR_CQI_TO_PDSCH_EFF_CFI1,
889     RG_SCH_CMN_2LYR_CQI_TO_PDSCH_EFF_CFI2, RG_SCH_CMN_2LYR_CQI_TO_PDSCH_EFF_CFI3};
890
891 /* This configuration determines the transalation of a UEs CQI to its    */
892 /* PDCCH coding efficiency. This may be edited based on the installation */
893 PRIVATE U8 rgSchCmnDlRvTbl[4] = {0, 2, 3, 1}; /* RVIdx sequence is corrected*/
894
895 /* Indexed by [DciFrmt].
896  * Considering the following definition in determining the dciFrmt index.
897  * typedef enum
898 {
899    TFU_DCI_FORMAT_0,
900    TFU_DCI_FORMAT_1,
901    TFU_DCI_FORMAT_1A,
902    TFU_DCI_FORMAT_1B,
903    TFU_DCI_FORMAT_1C,
904    TFU_DCI_FORMAT_1D,
905    TFU_DCI_FORMAT_2,
906    TFU_DCI_FORMAT_2A,
907    TFU_DCI_FORMAT_3,
908    TFU_DCI_FORMAT_3A
909 } TfuDciFormat;
910 */
911 PRIVATE U16 rgSchCmnDciFrmtSizes[10];
912
913
914 PRIVATE U16 rgSchCmnCqiPdcchEff[16] = RG_SCH_CMN_CQI_TO_PDCCH_EFF;
915
916 #ifdef LTE_TDD
917
918 RgSchTddUlDlSubfrmTbl rgSchTddUlDlSubfrmTbl = {
919    {RG_SCH_TDD_DL_SUBFRAME, RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME},
920    {RG_SCH_TDD_DL_SUBFRAME, RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME},
921    {RG_SCH_TDD_DL_SUBFRAME, RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME},
922    {RG_SCH_TDD_DL_SUBFRAME, RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,   RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME},
923    {RG_SCH_TDD_DL_SUBFRAME, RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME, RG_SCH_TDD_DL_SUBFRAME,   RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME},
924    {RG_SCH_TDD_DL_SUBFRAME, RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME, RG_SCH_TDD_DL_SUBFRAME,   RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME},
925    {RG_SCH_TDD_DL_SUBFRAME, RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME,  RG_SCH_TDD_SPL_SUBFRAME, RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_UL_SUBFRAME,  RG_SCH_TDD_DL_SUBFRAME}
926 };
927
928 /* SPS_INTG_FIX */
929 #ifdef LTEMAC_SPS
930 U8 rgSchTddSpsDlMaxRetxTbl[RGSCH_MAX_TDD_UL_DL_CFG] = {
931    /* 0 */ 6,
932    /* 1 */ 7,
933    /* 2 */ 8,
934    /* 3 */ 11,
935    /* 4 */ 12,
936    /* 5 */ 13,
937    /* 6 */ 7};
938
939 #endif
940
941
942 /* Special Subframes in OFDM symbols */
943 /* ccpu00134197-MOD-Correct the number of symbols */
944 RgSchTddSplSubfrmInfoTbl rgSchTddSplSubfrmInfoTbl = {
945         {3,  1, 1, 3,   1, 1},
946         {9,  1, 1, 8,   1, 1},
947         {10, 1, 1, 9,   1, 1},
948         {11, 1, 1, 10,  1, 1},
949         {12, 1, 1, 3,   2, 2},
950         {3,  2, 2, 8,   2, 2},
951         {9,  2, 2, 9,   2, 2},
952         {10, 2, 2, 0,   0, 0},
953         {11, 2, 2, 0,   0, 0}
954 };
955
956 /* PHICH 'm' value Table */
957 RgSchTddPhichMValTbl rgSchTddPhichMValTbl = {
958         {2, 1, 0, 0, 0, 2, 1, 0, 0, 0},
959         {0, 1, 0, 0, 1, 0, 1, 0, 0, 1},
960         {0, 0, 0, 1, 0, 0, 0, 0, 1, 0},
961         {1, 0, 0, 0, 0, 0, 0, 0, 1, 1},
962         {0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
963         {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
964         {1, 1, 0, 0, 0, 1, 1, 0, 0, 1}
965 };
966
967 /* PHICH 'K' value Table */
968 RgSchTddKPhichTbl rgSchTddKPhichTbl = {
969         {0, 0, 4, 7, 6, 0, 0, 4, 7, 6},
970         {0, 0, 4, 6, 0, 0, 0, 4, 6, 0},
971         {0, 0, 6, 0, 0, 0, 0, 6, 0, 0},
972         {0, 0, 6, 6, 6, 0, 0, 0, 0, 0},
973         {0, 0, 6, 6, 0, 0, 0, 0, 0, 0},
974         {0, 0, 6, 0, 0, 0, 0, 0, 0, 0},
975         {0, 0, 4, 6, 6, 0, 0, 4, 7, 0}
976 };
977
978 /* Uplink association index 'K' value Table */
979 RgSchTddUlAscIdxKDashTbl rgSchTddUlAscIdxKDashTbl = {
980         {0, 0, 6, 4, 0, 0, 0, 6, 4, 0},
981         {0, 0, 4, 0, 0, 0, 0, 4, 0, 0},
982         {0, 0, 4, 4, 4, 0, 0, 0, 0, 0},
983         {0, 0, 4, 4, 0, 0, 0, 0, 0, 0},
984         {0, 0, 4, 0, 0, 0, 0, 0, 0, 0},
985         {0, 0, 7, 7, 5, 0, 0, 7, 7, 0}
986 };
987
988
989 /* PUSCH 'K' value Table */
990 RgSchTddPuschTxKTbl rgSchTddPuschTxKTbl = {
991         {4, 6, 0, 0, 0, 4, 6, 0, 0, 0},
992         {0, 6, 0, 0, 4, 0, 6, 0, 0, 4},
993         {0, 0, 0, 4, 0, 0, 0, 0, 4, 0},
994         {4, 0, 0, 0, 0, 0, 0, 0, 4, 4},
995         {0, 0, 0, 0, 0, 0, 0, 0, 4, 4},
996         {0, 0, 0, 0, 0, 0, 0, 0, 4, 0},
997         {7, 7, 0, 0, 0, 7, 7, 0, 0, 5}
998 };
999
1000 /* PDSCH to PUCCH Table for DL Harq Feed back. Based on the 
1001    Downlink association set index 'K' table */
1002 U8 rgSchTddPucchTxTbl[7][10] = {
1003         {4,  6,  0, 0, 0, 4, 6, 0, 0,  0},
1004         {7,  6,  0, 0, 4, 7, 6, 0, 0,  4},
1005         {7,  6,  0, 4, 8, 7, 6, 0, 4,  8},
1006         {4,  11, 0, 0, 0, 7, 6, 6, 5,  5},
1007         {12, 11, 0, 0, 8, 7, 7, 6, 5,  4},
1008         {12, 11, 0, 9, 8, 7, 6, 5, 4, 13},
1009         {7,  7,  0, 0, 0, 7, 7, 0, 0,  5}
1010 };
1011
1012 /* Table to fetch the next DL sf idx for applying the 
1013    new CFI. The next Dl sf Idx at which the new CFI 
1014    is applied is always the starting Sf of the next ACK/NACK
1015    Fdbk bundle. 
1016    
1017    Ex: In Cfg-2, sf4 and sf9 are the only subframes at which 
1018        a new ACK/NACK bundle of DL subframes can start
1019        
1020    D  S  U  D  D  D  S  U  D  D  D  S  U  D  D  D  S  U  D  D    
1021                4              9
1022    
1023    dlSf Array for Cfg-2:
1024    sfNum:  0  1  3  4  5  6  8  9  0  1   3  4  5  6  8  9 
1025    sfIdx:  0  1  2  3  4  5  6  7  8  9  10 11 12 12 14 15 
1026     
1027    If CFI changes at sf0,  nearest DL SF bundle >= 4 TTI is sf4
1028    So at sf4 the new CFI can be applied. To arrive at sf4 from
1029    sf0, the sfIdx has to be increased by 3 */  
1030                  
1031 U8 rgSchTddPdcchSfIncTbl[7][10] = {
1032  /* A/N Bundl: 0,1,5,6*/   {2,  1,  0, 0, 0, 2, 1,  0,  0,  0},
1033  /* A/N Bundl: 0,4,5,9*/   {2,  2,  0, 0, 3, 2, 2,  0,  0,  3},
1034  /* A/N Bundl: 4,9*/       {3,  6,  0, 5, 4, 3, 6,  0,  5,  4},
1035  /* A/N Bundl: 1,7,9*/     {4,  3,  0, 0, 0, 4, 5,  4,  6,  5},
1036  /* A/N Bundl: 0,6*/       {4,  3,  0, 0, 6, 5, 4,  7,  6,  5},
1037  /* A/N Bundl: 9*/         {8,  7,  0, 6, 5, 4, 12, 11, 10, 9},
1038  /* A/N Bundl: 0,1,5,6,9*/ {2,  1,  0, 0, 0, 2, 2,  0,  0,  3}
1039 };
1040    
1041
1042 /* combine compilation fixes */
1043 #ifdef LTEMAC_SPS
1044 /* subframe offset values to be used when twoIntervalsConfig is enabled in UL
1045  * SPS for a UE */
1046 RgSchTddSfOffTbl rgSchTddSfOffTbl = {
1047         {0, 0, 0,  0,  0, 0, 0,  0,  0, 0},
1048         {0, 0, 1, -1,  0, 0, 0,  1, -1, 0},
1049         {0, 0, 5,  0,  0, 0, 0, -5,  0, 0},
1050         {0, 0, 1,  1, -2, 0, 0,  0,  0, 0},
1051         {0, 0, 1, -1,  0, 0, 0,  0,  0, 0},
1052         {0, 0, 0,  0,  0, 0, 0,  0,  0, 0},
1053         {0, 0, 0,  0,  0, 0, 0,  0,  0, 0}
1054 };
1055
1056
1057 /* Table to determine when uplink SPS configured grants should
1058  * explicitly be reserved in a subframe. When enries are same
1059  * as that of Msg3SubfrmTbl, indicates competition with msg3.
1060  * As of now, this is same as Msg3SubfrmTbl (leaving out uldlcfg 2),
1061  * except that all 255s are now zeros. */
1062 RgSchTddSpsUlRsrvTbl rgSchTddSpsUlRsrvTbl = {
1063         {0,    0,  0,  6,  8,  0, 0,  0,  6,  8},
1064         {0,    0,  6,  9,  0,  0, 0,  6,  9,  0},
1065         {0,    0,  10,  0,  0,  0, 0,  10,  0,  0},
1066         {0,   0,  0,  0,  8,  0, 7,  7,  14,  0},
1067         {0,   0,  0,  9,  0,  0, 7,  15,  0, 0},
1068         {0,   0,  10,  0,  0,  0, 16,  0, 0, 0},
1069         {0,    0,  0,  0,  8,  0, 0,  0,  9,  0}
1070 };
1071
1072 /* Inverse DL Assoc Set index Table */
1073 RgSchTddInvDlAscSetIdxTbl rgSchTddInvDlAscSetIdxTbl = {
1074        {4,  6,  0, 0, 0, 4, 6, 0, 0,  0},
1075        {7,  6,  0, 0, 4, 7, 6, 0, 0,  4},
1076        {7,  6,  0, 4, 8, 7, 6, 0, 4,  8},
1077        {4,  11, 0, 0, 0, 7, 6, 6, 5,  5},
1078        {12, 11, 0, 0, 8, 7, 7, 6, 5,  4},
1079        {12, 11, 0, 9, 8, 7, 6, 5, 4, 13},
1080        {7,  7,  0, 0, 0, 7, 7, 0, 0,  5}
1081 };
1082
1083 #endif /* (LTEMAC_SPS ) */
1084
1085 /* Number of Uplink subframes Table */
1086 PRIVATE U8 rgSchTddNumUlSf[] = {6, 4, 2, 3, 2, 1, 5};
1087
1088 /* Downlink HARQ processes Table */
1089 RgSchTddUlNumHarqProcTbl rgSchTddUlNumHarqProcTbl = { 7, 4, 2, 3, 2, 1, 6};
1090
1091 /* Uplink HARQ processes Table */
1092 RgSchTddDlNumHarqProcTbl rgSchTddDlNumHarqProcTbl = { 4, 7, 10, 9, 12, 15, 6};
1093
1094 /* Downlink association index set 'K' value Table */
1095 RgSchTddDlAscSetIdxKTbl rgSchTddDlAscSetIdxKTbl = {
1096         { {0, {0}}, {0, {0}}, {1, {6}}, {0, {0}}, {1, {4}}, {0, {0}}, {0, {0}}, {1, {6}}, {0, {0}}, {1, {4}} },
1097
1098         { {0, {0}}, {0, {0}}, {2, {7, 6}}, {1, {4}}, {0, {0}}, {0, {0}}, {0, {0}}, {2, {7, 6}}, {1, {4}}, {0, {0}} },
1099
1100         { {0, {0}}, {0, {0}}, {4, {8, 7, 4, 6}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {4, {8, 7, 4, 6}}, {0, {0}}, {0, {0}} },
1101
1102         { {0, {0}}, {0, {0}}, {3, {7, 6, 11}}, {2, {6, 5}}, {2, {5, 4}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}} },
1103
1104         { {0, {0}}, {0, {0}}, {4, {12, 8, 7, 11}}, {4, {6, 5, 4, 7}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}} },
1105
1106         { {0, {0}}, {0, {0}}, {9, {13, 12, 9, 8, 7, 5, 4, 11, 6}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}} },
1107
1108         { {0, {0}}, {0, {0}}, {1, {7}}, {1, {7}}, {1, {5}}, {0, {0}}, {0, {0}}, {1, {7}}, {1, {7}}, {0, {0}} }
1109 };
1110
1111  /* ccpu132282-ADD-the table rgSchTddDlAscSetIdxKTbl is rearranged in 
1112   * decreasing order of Km, this is used to calculate the NCE used for 
1113   * calculating N1Pucch Resource for Harq*/
1114 RgSchTddDlAscSetIdxKTbl rgSchTddDlHqPucchResCalTbl = {
1115         { {0, {0}}, {0, {0}}, {1, {6}}, {0, {0}}, {1, {4}}, {0, {0}}, {0, {0}}, {1, {6}}, {0, {0}}, {1, {4}} },
1116
1117         { {0, {0}}, {0, {0}}, {2, {7, 6}}, {1, {4}}, {0, {0}}, {0, {0}}, {0, {0}}, {2, {7, 6}}, {1, {4}}, {0, {0}} },
1118
1119         { {0, {0}}, {0, {0}}, {4, {8, 7, 6, 4}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {4, {8, 7, 6, 4}}, {0, {0}}, {0, {0}} },
1120
1121         { {0, {0}}, {0, {0}}, {3, {11, 7, 6}}, {2, {6, 5}}, {2, {5, 4}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}} },
1122
1123         { {0, {0}}, {0, {0}}, {4, {12, 11, 8, 7}}, {4, {7, 6, 5, 4}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}} },
1124
1125         { {0, {0}}, {0, {0}}, {9, {13, 12, 11, 9, 8, 7, 6, 5, 4}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}} },
1126
1127         { {0, {0}}, {0, {0}}, {1, {7}}, {1, {7}}, {1, {5}}, {0, {0}}, {0, {0}}, {1, {7}}, {1, {7}}, {0, {0}} }
1128 };
1129
1130 /* Minimum number of Ack/Nack feeback information to be
1131    stored for each UL-DL configuration */
1132 RgSchTddANFdbkMapTbl rgSchTddANFdbkMapTbl = {4, 4, 2, 3, 2, 1, 5};
1133
1134 /* Uplink switch points and number of UL subframes Table */
1135 RgSchTddMaxUlSubfrmTbl rgSchTddMaxUlSubfrmTbl = {
1136      {2,3,3}, {2,2,2}, {2,1,1}, {1,3,0}, {1,2,0}, {1,1,0}, {2,3,2}
1137 };
1138
1139 /* Uplink switch points and number of DL subframes Table */
1140 RgSchTddMaxDlSubfrmTbl rgSchTddMaxDlSubfrmTbl = {
1141      {2,2,2}, {2,3,3}, {2,4,4}, {1,7,0}, {1,8,0}, {1,9,0}, {2,2,3}
1142 };
1143
1144 /* Number of UL subframes present before a particular subframe */
1145 RgSchTddNumUlSubfrmTbl rgSchTddNumUlSubfrmTbl = {
1146         {0, 0, 1, 2, 3, 3, 3, 4, 5, 6},
1147         {0, 0, 1, 2, 2, 2, 2, 3, 4, 4},
1148         {0, 0, 1, 1, 1, 1, 1, 2, 2, 2},
1149         {0, 0, 1, 2, 3, 3, 3, 3, 3, 3},
1150         {0, 0, 1, 2, 2, 2, 2, 2, 2, 2},
1151         {0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
1152         {0, 0, 1, 2, 3, 3, 3, 4, 5, 5}
1153 };
1154
1155 /* Number of DL subframes present till a particular subframe */
1156 RgSchTddNumDlSubfrmTbl rgSchTddNumDlSubfrmTbl = {
1157         {1, 2, 2, 2, 2, 3, 4, 4, 4, 4},
1158         {1, 2, 2, 2, 3, 4, 5, 5, 5, 6},
1159         {1, 2, 2, 3, 4, 5, 6, 6, 7, 8},
1160         {1, 2, 2, 2, 2, 3, 4, 5, 6, 7},
1161         {1, 2, 2, 2, 3, 4, 5, 6, 7, 8},
1162         {1, 2, 2, 3, 4, 5, 6, 7, 8, 9},
1163         {1, 2, 2, 2, 2, 3, 4, 4, 4, 5}
1164 };
1165
1166
1167 /* Nearest possible UL subframe Index from UL subframe
1168  * DL Index < UL Index */
1169 RgSchTddLowDlSubfrmIdxTbl rgSchTddLowDlSubfrmIdxTbl = {
1170         {0, 1, 1, 1, 1, 5, 6, 6, 6, 6},
1171         {0, 1, 1, 1, 4, 5, 6, 6, 6, 9},
1172         {0, 1, 1, 3, 4, 5, 6, 6, 8, 9},
1173         {0, 1, 1, 1, 1, 5, 6, 7, 8, 9},
1174         {0, 1, 1, 1, 4, 5, 6, 7, 8, 9},
1175         {0, 1, 1, 3, 4, 5, 6, 7, 8, 9},
1176         {0, 1, 1, 1, 1, 5, 6, 6, 6, 9}
1177 };
1178
1179 /* Nearest possible DL subframe Index from UL subframe
1180  * DL Index > UL Index
1181  * 10 represents Next SFN low DL Idx */
1182 RgSchTddHighDlSubfrmIdxTbl rgSchTddHighDlSubfrmIdxTbl = {
1183         {0, 1, 5, 5, 5, 5, 6, 10, 10, 10},
1184         {0, 1, 4, 4, 4, 5, 6,  9,  9,  9},
1185         {0, 1, 3, 3, 4, 5, 6,  8,  8,  9},
1186         {0, 1, 5, 5, 5, 5, 6,  7,  8,  9},
1187         {0, 1, 4, 4, 4, 5, 6,  7,  8,  9},
1188         {0, 1, 3, 3, 4, 5, 6,  7,  8,  9},
1189         {0, 1, 5, 5, 5, 5, 6,  9,  9,  9}
1190 };
1191
1192 /* RACH Message3 related information */
1193 RgSchTddMsg3SubfrmTbl rgSchTddMsg3SubfrmTbl = {
1194         {7,      6,  255,  255,  255,  7,   6,  255,  255,  255},
1195         {7,      6,  255,  255,    8,  7,   6,  255,  255,    8},
1196         {7,      6,  255,  9,      8,  7,   6,  255,    9,    8},
1197         {12,    11,  255,  255,  255,  7,   6,    6,    6,   13},
1198         {12,    11,  255,  255,    8,  7,   6,    6,   14,   13},
1199         {12,    11,  255,    9,    8,  7,   6,   15,   14,   13},
1200         {7,      6,  255,  255,  255,  7,   6,  255,  255,    8}
1201 };
1202
1203 /* ccpu00132341-DEL Removed rgSchTddRlsDlSubfrmTbl and used Kset table for 
1204  * releasing DL HARQs */
1205
1206 /* DwPTS Scheduling Changes Start */
1207 /* Provides the number of Cell Reference Signals in DwPTS
1208  * region per RB */
1209 PRIVATE U8  rgSchCmnDwptsCrs[2][3] = {/* [Spl Sf cfg][Ant Port] */
1210            {4, 8,  16}, /* Spl Sf cfg 1,2,3,6,7,8 */
1211            {6, 12, 20}, /* Spl Sf cfg 4 */
1212 };
1213
1214 PRIVATE S8  rgSchCmnSplSfDeltaItbs[9] = RG_SCH_DWPTS_ITBS_ADJ;
1215 /* DwPTS Scheduling Changes End */
1216 #endif
1217
1218
1219 PRIVATE U32 rgSchCmnBsrTbl[64] = {
1220    0, 10, 12, 14, 17, 19, 22, 26,
1221    31, 36, 42, 49, 57, 67, 78, 91,
1222    107, 125, 146, 171, 200, 234, 274, 321,
1223    376, 440, 515, 603, 706, 826, 967, 1132,
1224    1326, 1552, 1817, 2127, 2490, 2915, 3413, 3995,
1225    4677, 5476, 6411, 7505, 8787, 10287, 12043, 14099,
1226    16507, 19325, 22624, 26487, 31009, 36304, 42502, 49759,
1227    58255, 68201, 79846, 93479, 109439, 128125, 150000, 220000
1228 };
1229
1230 PRIVATE U32 rgSchCmnExtBsrTbl[64] = {
1231    0, 10, 13, 16, 19, 23, 29, 35,
1232    43, 53, 65, 80, 98, 120, 147, 181,
1233    223, 274, 337, 414, 509, 625, 769, 945,
1234    1162, 1429, 1757, 2161, 2657, 3267, 4017, 4940,
1235    6074, 7469, 9185, 11294, 13888, 17077, 20999, 25822,
1236    31752, 39045, 48012, 59039, 72598, 89272, 109774, 134986,
1237    165989, 204111, 250990, 308634, 379519, 466683, 573866, 705666,
1238    867737, 1067031, 1312097, 1613447, 1984009, 2439678, 3000000, 3100000
1239 };
1240
1241 U8 rgSchCmnUlCqiToTbsTbl[RG_SCH_CMN_MAX_CP][RG_SCH_CMN_UL_NUM_CQI];
1242
1243 RgSchTbSzTbl rgTbSzTbl = {
1244  {
1245    {16,    32,    56,    88,    120,   152,   176,   208,   224,   256,   288,   328,   344,   376,   392,   424,   456,   488,   504,   536,   568,   600,   616,   648,   680,   712,   744,   776,   776,   808,   840,   872,   904,   936,   968,   1000,  1032,  1032,  1064,  1096,  1128,  1160,  1192,  1224,  1256,  1256,  1288,  1320,  1352,  1384,  1416,  1416,  1480,  1480,  1544,  1544,  1608,  1608,  1608,  1672,  1672,  1736,  1736,  1800,  1800,  1800,  1864,  1864,  1928,  1928,  1992,  1992,  2024,  2088,  2088,  2088,  2152,  2152,  2216,  2216,  2280,  2280,  2280,  2344,  2344,  2408,  2408,  2472,  2472,  2536,  2536,  2536,  2600,  2600,  2664,  2664,  2728,  2728,  2728,  2792,  2792,  2856,  2856,  2856,  2984,  2984,  2984,  2984,  2984,  3112},
1246    {24,    56,    88,    144,   176,   208,   224,   256,   328,   344,   376,   424,   456,   488,   520,   568,   600,   632,   680,   712,   744,   776,   808,   872,   904,   936,   968,   1000,  1032,  1064,  1128,  1160,  1192,  1224,  1256,  1288,  1352,  1384,  1416,  1416,  1480,  1544,  1544,  1608,  1608,  1672,  1736,  1736,  1800,  1800,  1864,  1864,  1928,  1992,  1992,  2024,  2088,  2088,  2152,  2152,  2216,  2280,  2280,  2344,  2344,  2408,  2472,  2472,  2536,  2536,  2600,  2600,  2664,  2728,  2728,  2792,  2792,  2856,  2856,  2856,  2984,  2984,  2984,  3112,  3112,  3112,  3240,  3240,  3240,  3240,  3368,  3368,  3368,  3496,  3496,  3496,  3496,  3624,  3624,  3624,  3752,  3752,  3752,  3752,  3880,  3880,  3880,  4008,  4008,  4008},
1247    {32,    72,    144,   176,   208,   256,   296,   328,   376,   424,   472,   520,   568,   616,   648,   696,   744,   776,   840,   872,   936,   968,   1000,  1064,  1096,  1160,  1192,  1256,  1288,  1320,  1384,  1416,  1480,  1544,  1544,  1608,  1672,  1672,  1736,  1800,  1800,  1864,  1928,  1992,  2024,  2088,  2088,  2152,  2216,  2216,  2280,  2344,  2344,  2408,  2472,  2536,  2536,  2600,  2664,  2664,  2728,  2792,  2856,  2856,  2856,  2984,  2984,  3112,  3112,  3112,  3240,  3240,  3240,  3368,  3368,  3368,  3496,  3496,  3496,  3624,  3624,  3624,  3752,  3752,  3880,  3880,  3880,  4008,  4008,  4008,  4136,  4136,  4136,  4264,  4264,  4264,  4392,  4392,  4392,  4584,  4584,  4584,  4584,  4584,  4776,  4776,  4776,  4776,  4968,  4968},
1248    {40,    104,   176,   208,   256,   328,   392,   440,   504,   568,   616,   680,   744,   808,   872,   904,   968,   1032,  1096,  1160,  1224,  1256,  1320,  1384,  1416,  1480,  1544,  1608,  1672,  1736,  1800,  1864,  1928,  1992,  2024,  2088,  2152,  2216,  2280,  2344,  2408,  2472,  2536,  2536,  2600,  2664,  2728,  2792,  2856,  2856,  2984,  2984,  3112,  3112,  3240,  3240,  3368,  3368,  3496,  3496,  3624,  3624,  3624,  3752,  3752,  3880,  3880,  4008,  4008,  4136,  4136,  4264,  4264,  4392,  4392,  4392,  4584,  4584,  4584,  4776,  4776,  4776,  4776,  4968,  4968,  4968,  5160,  5160,  5160,  5352,  5352,  5352,  5352,  5544,  5544,  5544,  5736,  5736,  5736,  5736,  5992,  5992,  5992,  5992,  6200,  6200,  6200,  6200,  6456,  6456},
1249    {56,    120,   208,   256,   328,   408,   488,   552,   632,   696,   776,   840,   904,   1000,  1064,  1128,  1192,  1288,  1352,  1416,  1480,  1544,  1608,  1736,  1800,  1864,  1928,  1992,  2088,  2152,  2216,  2280,  2344,  2408,  2472,  2600,  2664,  2728,  2792,  2856,  2984,  2984,  3112,  3112,  3240,  3240,  3368,  3496,  3496,  3624,  3624,  3752,  3752,  3880,  4008,  4008,  4136,  4136,  4264,  4264,  4392,  4392,  4584,  4584,  4584,  4776,  4776,  4968,  4968,  4968,  5160,  5160,  5160,  5352,  5352,  5544,  5544,  5544,  5736,  5736,  5736,  5992,  5992,  5992,  5992,  6200,  6200,  6200,  6456,  6456,  6456,  6456,  6712,  6712,  6712,  6968,  6968,  6968,  6968,  7224,  7224,  7224,  7480,  7480,  7480,  7480,  7736,  7736,  7736,  7992},
1250    {72,    144,   224,   328,   424,   504,   600,   680,   776,   872,   968,   1032,  1128,  1224,  1320,  1384,  1480,  1544,  1672,  1736,  1864,  1928,  2024,  2088,  2216,  2280,  2344,  2472,  2536,  2664,  2728,  2792,  2856,  2984,  3112,  3112,  3240,  3368,  3496,  3496,  3624,  3752,  3752,  3880,  4008,  4008,  4136,  4264,  4392,  4392,  4584,  4584,  4776,  4776,  4776,  4968,  4968,  5160,  5160,  5352,  5352,  5544,  5544,  5736,  5736,  5736,  5992,  5992,  5992,  6200,  6200,  6200,  6456,  6456,  6712,  6712,  6712,  6968,  6968,  6968,  7224,  7224,  7224,  7480,  7480,  7480,  7736,  7736,  7736,  7992,  7992,  7992,  8248,  8248,  8248,  8504,  8504,  8760,  8760,  8760,  8760,  9144,  9144,  9144,  9144,  9528,  9528,  9528,  9528,  9528},
1251    {328,    176,   256,   392,   504,   600,   712,   808,   936,   1032,  1128,  1224,  1352,  1480,  1544,  1672,  1736,  1864,  1992,  2088,  2216,  2280,  2408,  2472,  2600,  2728,  2792,  2984,  2984,  3112,  3240,  3368,  3496,  3496,  3624,  3752,  3880,  4008,  4136,  4136,  4264,  4392,  4584,  4584,  4776,  4776,  4968,  4968,  5160,  5160,  5352,  5352,  5544,  5736,  5736,  5992,  5992,  5992,  6200,  6200,  6456,  6456,  6456,  6712,  6712,  6968,  6968,  6968,  7224,  7224,  7480,  7480,  7736,  7736,  7736,  7992,  7992,  8248,  8248,  8248,  8504,  8504,  8760,  8760,  8760,  9144,  9144,  9144,  9144,  9528,  9528,  9528,  9528,  9912,  9912,  9912,  10296, 10296, 10296, 10296, 10680, 10680, 10680, 10680, 11064, 11064, 11064, 11448, 11448, 11448},
1252    {104,   224,   328,   472,   584,   712,   840,   968,   1096,  1224,  1320,  1480,  1608,  1672,  1800,  1928,  2088,  2216,  2344,  2472,  2536,  2664,  2792,  2984,  3112,  3240,  3368,  3368,  3496,  3624,  3752,  3880,  4008,  4136,  4264,  4392,  4584,  4584,  4776,  4968,  4968,  5160,  5352,  5352,  5544,  5736,  5736,  5992,  5992,  6200,  6200,  6456,  6456,  6712,  6712,  6712,  6968,  6968,  7224,  7224,  7480,  7480,  7736,  7736,  7992,  7992,  8248,  8248,  8504,  8504,  8760,  8760,  8760,  9144,  9144,  9144,  9528,  9528,  9528,  9912,  9912,  9912,  10296, 10296, 10296, 10680, 10680, 10680, 11064, 11064, 11064, 11448, 11448, 11448, 11448, 11832, 11832, 11832, 12216, 12216, 12216, 12576, 12576, 12576, 12960, 12960, 12960, 12960, 13536, 13536},
1253    {120,   256,   392,   536,   680,   808,   968,   1096,  1256,  1384,  1544,  1672,  1800,  1928,  2088,  2216,  2344,  2536,  2664,  2792,  2984,  3112,  3240,  3368,  3496,  3624,  3752,  3880,  4008,  4264,  4392,  4584,  4584,  4776,  4968,  4968,  5160,  5352,  5544,  5544,  5736,  5992,  5992,  6200,  6200,  6456,  6456,  6712,  6968,  6968,  7224,  7224,  7480,  7480,  7736,  7736,  7992,  7992,  8248,  8504,  8504,  8760,  8760,  9144,  9144,  9144,  9528,  9528,  9528,  9912,  9912,  9912,  10296, 10296, 10680, 10680, 10680, 11064, 11064, 11064, 11448, 11448, 11448, 11832, 11832, 12216, 12216, 12216, 12576, 12576, 12576, 12960, 12960, 12960, 13536, 13536, 13536, 13536, 14112, 14112, 14112, 14112, 14688, 14688, 14688, 14688, 15264, 15264, 15264, 15264},
1254    {136,   296,   456,   616,   776,   936,   1096,  1256,  1416,  1544,  1736,  1864,  2024,  2216,  2344,  2536,  2664,  2856,  2984,  3112,  3368,  3496,  3624,  3752,  4008,  4136,  4264,  4392,  4584,  4776,  4968,  5160,  5160,  5352,  5544,  5736,  5736,  5992,  6200,  6200,  6456,  6712,  6712,  6968,  6968,  7224,  7480,  7480,  7736,  7992,  7992,  8248,  8248,  8504,  8760,  8760,  9144,  9144,  9144,  9528,  9528,  9912,  9912,  10296, 10296, 10296, 10680, 10680, 11064, 11064, 11064, 11448, 11448, 11832, 11832, 11832, 12216, 12216, 12576, 12576, 12960, 12960, 12960, 13536, 13536, 13536, 13536, 14112, 14112, 14112, 14112, 14688, 14688, 14688, 15264, 15264, 15264, 15264, 15840, 15840, 15840, 16416, 16416, 16416, 16416, 16992, 16992, 16992, 16992, 17568},
1255    {144,   328,   504,   680,   872,   1032,  1224,  1384,  1544,  1736,  1928,  2088,  2280,  2472,  2664,  2792,  2984,  3112,  3368,  3496,  3752,  3880,  4008,  4264,  4392,  4584,  4776,  4968,  5160,  5352,  5544,  5736,  5736,  5992,  6200,  6200,  6456,  6712,  6712,  6968,  7224,  7480,  7480,  7736,  7992,  7992,  8248,  8504,  8504,  8760,  9144,  9144,  9144,  9528,  9528,  9912,  9912,  10296, 10296, 10680, 10680, 11064, 11064, 11448, 11448, 11448, 11832, 11832, 12216, 12216, 12576, 12576, 12960, 12960, 12960, 13536, 13536, 13536, 14112, 14112, 14112, 14688, 14688, 14688, 14688, 15264, 15264, 15264, 15840, 15840, 15840, 16416, 16416, 16416, 16992, 16992, 16992, 16992, 17568, 17568, 17568, 18336, 18336, 18336, 18336, 18336, 19080, 19080, 19080, 19080},
1256    {176,   376,   584,   776,   1000,  1192,  1384,  1608,  1800,  2024,  2216,  2408,  2600,  2792,  2984,  3240,  3496,  3624,  3880,  4008,  4264,  4392,  4584,  4776,  4968,  5352,  5544,  5736,  5992,  5992,  6200,  6456,  6712,  6968,  6968,  7224,  7480,  7736,  7736,  7992,  8248,  8504,  8760,  8760,  9144,  9144,  9528,  9528,  9912,  9912,  10296, 10680, 10680, 11064, 11064, 11448, 11448, 11832, 11832, 12216, 12216, 12576, 12576, 12960, 12960, 13536, 13536, 13536, 14112, 14112, 14112, 14688, 14688, 14688, 15264, 15264, 15840, 15840, 15840, 16416, 16416, 16416, 16992, 16992, 16992, 17568, 17568, 17568, 18336, 18336, 18336, 18336, 19080, 19080, 19080, 19080, 19848, 19848, 19848, 19848, 20616, 20616, 20616, 21384, 21384, 21384, 21384, 22152, 22152, 22152},
1257    {208,   440,   680,   904,   1128,  1352,  1608,  1800,  2024,  2280,  2472,  2728,  2984,  3240,  3368,  3624,  3880,  4136,  4392,  4584,  4776,  4968,  5352,  5544,  5736,  5992,  6200,  6456,  6712,  6712,  6968,  7224,  7480,  7736,  7992,  8248,  8504,  8760,  8760,  9144,  9528,  9528,  9912,  9912,  10296, 10680, 10680, 11064, 11064, 11448, 11832, 11832, 12216, 12216, 12576, 12576, 12960, 12960, 13536, 13536, 14112, 14112, 14112, 14688, 14688, 15264, 15264, 15264, 15840, 15840, 16416, 16416, 16416, 16992, 16992, 17568, 17568, 17568, 18336, 18336, 18336, 19080, 19080, 19080, 19080, 19848, 19848, 19848, 20616, 20616, 20616, 21384, 21384, 21384, 21384, 22152, 22152, 22152, 22920, 22920, 22920, 23688, 23688, 23688, 23688, 24496, 24496, 24496, 24496, 25456},
1258    {224,   488,   744,   1000,  1256,  1544,  1800,  2024,  2280,  2536,  2856,  3112,  3368,  3624,  3880,  4136,  4392,  4584,  4968,  5160,  5352,  5736,  5992,  6200,  6456,  6712,  6968,  7224,  7480,  7736,  7992,  8248,  8504,  8760,  9144,  9144,  9528,  9912,  9912,  10296, 10680, 10680, 11064, 11448, 11448, 11832, 12216, 12216, 12576, 12960, 12960, 13536, 13536, 14112, 14112, 14688, 14688, 14688, 15264, 15264, 15840, 15840, 16416, 16416, 16992, 16992, 16992, 17568, 17568, 18336, 18336, 18336, 19080, 19080, 19080, 19848, 19848, 19848, 20616, 20616, 20616, 21384, 21384, 21384, 22152, 22152, 22152, 22920, 22920, 22920, 23688, 23688, 23688, 24496, 24496, 24496, 25456, 25456, 25456, 25456, 26416, 26416, 26416, 26416, 27376, 27376, 27376, 27376, 28336, 28336},
1259    {256,   552,   840,   1128,  1416,  1736,  1992,  2280,  2600,  2856,  3112,  3496,  3752,  4008,  4264,  4584,  4968,  5160,  5544,  5736,  5992,  6200,  6456,  6968,  7224,  7480,  7736,  7992,  8248,  8504,  8760,  9144,  9528,  9912,  9912,  10296, 10680, 11064, 11064, 11448, 11832, 12216, 12216, 12576, 12960, 12960, 13536, 13536, 14112, 14112, 14688, 14688, 15264, 15264, 15840, 15840, 16416, 16416, 16992, 16992, 17568, 17568, 18336, 18336, 18336, 19080, 19080, 19848, 19848, 19848, 20616, 20616, 20616, 21384, 21384, 22152, 22152, 22152, 22920, 22920, 22920, 23688, 23688, 24496, 24496, 24496, 25456, 25456, 25456, 25456, 26416, 26416, 26416, 27376, 27376, 27376, 28336, 28336, 28336, 28336, 29296, 29296, 29296, 29296, 30576, 30576, 30576, 30576, 31704, 31704},
1260    {280,   600,   904,   1224,  1544,  1800,  2152,  2472,  2728,  3112,  3368,  3624,  4008,  4264,  4584,  4968,  5160,  5544,  5736,  6200,  6456,  6712,  6968,  7224,  7736,  7992,  8248,  8504,  8760,  9144,  9528,  9912,  10296, 10296, 10680, 11064, 11448, 11832, 11832, 12216, 12576, 12960, 12960, 13536, 13536, 14112, 14688, 14688, 15264, 15264, 15840, 15840, 16416, 16416, 16992, 16992, 17568, 17568, 18336, 18336, 18336, 19080, 19080, 19848, 19848, 20616, 20616, 20616, 21384, 21384, 22152, 22152, 22152, 22920, 22920, 23688, 23688, 23688, 24496, 24496, 24496, 25456, 25456, 25456, 26416, 26416, 26416, 27376, 27376, 27376, 28336, 28336, 28336, 29296, 29296, 29296, 29296, 30576, 30576, 30576, 30576, 31704, 31704, 31704, 31704, 32856, 32856, 32856, 34008, 34008},
1261    {328,   632,   968,   1288,  1608,  1928,  2280,  2600,  2984,  3240,  3624,  3880,  4264,  4584,  4968,  5160,  5544,  5992,  6200,  6456,  6712,  7224,  7480,  7736,  7992,  8504,  8760,  9144,  9528,  9912,  9912,  10296, 10680, 11064, 11448, 11832, 12216, 12216, 12576, 12960, 13536, 13536, 14112, 14112, 14688, 14688, 15264, 15840, 15840, 16416, 16416, 16992, 16992, 17568, 17568, 18336, 18336, 19080, 19080, 19848, 19848, 19848, 20616, 20616, 21384, 21384, 22152, 22152, 22152, 22920, 22920, 23688, 23688, 24496, 24496, 24496, 25456, 25456, 25456, 26416, 26416, 26416, 27376, 27376, 27376, 28336, 28336, 28336, 29296, 29296, 29296, 30576, 30576, 30576, 30576, 31704, 31704, 31704, 31704, 32856, 32856, 32856, 34008, 34008, 34008, 34008, 35160, 35160, 35160, 35160},
1262    {336,   696,   1064,  1416,  1800,  2152,  2536,  2856,  3240,  3624,  4008,  4392,  4776,  5160,  5352,  5736,  6200,  6456,  6712,  7224,  7480,  7992,  8248,  8760,  9144,  9528,  9912,  10296, 10296, 10680, 11064, 11448, 11832, 12216, 12576, 12960, 13536, 13536, 14112, 14688, 14688, 15264, 15264, 15840, 16416, 16416, 16992, 17568, 17568, 18336, 18336, 19080, 19080, 19848, 19848, 20616, 20616, 20616, 21384, 21384, 22152, 22152, 22920, 22920, 23688, 23688, 24496, 24496, 24496, 25456, 25456, 26416, 26416, 26416, 27376, 27376, 27376, 28336, 28336, 29296, 29296, 29296, 30576, 30576, 30576, 30576, 31704, 31704, 31704, 32856, 32856, 32856, 34008, 34008, 34008, 35160, 35160, 35160, 35160, 36696, 36696, 36696, 36696, 37888, 37888, 37888, 39232, 39232, 39232, 39232},
1263    {376,   776,   1160,  1544,  1992,  2344,  2792,  3112,  3624,  4008,  4392,  4776,  5160,  5544,  5992,  6200,  6712,  7224,  7480,  7992,  8248,  8760,  9144,  9528,  9912,  10296, 10680, 11064, 11448, 11832, 12216, 12576, 12960, 13536, 14112, 14112, 14688, 15264, 15264, 15840, 16416, 16416, 16992, 17568, 17568, 18336, 18336, 19080, 19080, 19848, 19848, 20616, 21384, 21384, 22152, 22152, 22920, 22920, 23688, 23688, 24496, 24496, 24496, 25456, 25456, 26416, 26416, 27376, 27376, 27376, 28336, 28336, 29296, 29296, 29296, 30576, 30576, 30576, 31704, 31704, 31704, 32856, 32856, 32856, 34008, 34008, 34008, 35160, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 37888, 37888, 39232, 39232, 39232, 40576, 40576, 40576, 40576, 42368, 42368, 42368, 42368, 43816, 43816},
1264    {408,   840,   1288,  1736,  2152,  2600,  2984,  3496,  3880,  4264,  4776,  5160,  5544,  5992,  6456,  6968,  7224,  7736,  8248,  8504,  9144,  9528,  9912,  10296, 10680, 11064, 11448, 12216, 12576, 12960, 13536, 13536, 14112, 14688, 15264, 15264, 15840, 16416, 16992, 16992, 17568, 18336, 18336, 19080, 19080, 19848, 20616, 20616, 21384, 21384, 22152, 22152, 22920, 22920, 23688, 24496, 24496, 25456, 25456, 25456, 26416, 26416, 27376, 27376, 28336, 28336, 29296, 29296, 29296, 30576, 30576, 30576, 31704, 31704, 32856, 32856, 32856, 34008, 34008, 34008, 35160, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 37888, 39232, 39232, 39232, 40576, 40576, 40576, 40576, 42368, 42368, 42368, 43816, 43816, 43816, 43816, 45352, 45352, 45352, 46888, 46888, 46888, 46888},
1265    {440,   904,   1384,  1864,  2344,  2792,  3240,  3752,  4136,  4584,  5160,  5544,  5992,  6456,  6968,  7480,  7992,  8248,  8760,  9144,  9912,  10296, 10680, 11064, 11448, 12216, 12576, 12960, 13536, 14112, 14688, 14688, 15264, 15840, 16416, 16992, 16992, 17568, 18336, 18336, 19080, 19848, 19848, 20616, 20616, 21384, 22152, 22152, 22920, 22920, 23688, 24496, 24496, 25456, 25456, 26416, 26416, 27376, 27376, 28336, 28336, 29296, 29296, 29296, 30576, 30576, 31704, 31704, 31704, 32856, 32856, 34008, 34008, 34008, 35160, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 39232, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 45352, 46888, 46888, 46888, 46888, 48936, 48936, 48936, 48936, 48936, 51024, 51024, 51024},
1266    {488,   1000,  1480,  1992,  2472,  2984,  3496,  4008,  4584,  4968,  5544,  5992,  6456,  6968,  7480,  7992,  8504,  9144,  9528,  9912,  10680, 11064, 11448, 12216, 12576, 12960, 13536, 14112, 14688, 15264, 15840, 15840, 16416, 16992, 17568, 18336, 18336, 19080, 19848, 19848, 20616, 21384, 21384, 22152, 22920, 22920, 23688, 24496, 24496, 25456, 25456, 26416, 26416, 27376, 27376, 28336, 28336, 29296, 29296, 30576, 30576, 31704, 31704, 31704, 32856, 32856, 34008, 34008, 35160, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 39232, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 45352, 46888, 46888, 46888, 46888, 48936, 48936, 48936, 48936, 51024, 51024, 51024, 51024, 52752, 52752, 52752, 52752, 55056, 55056, 55056},
1267    {520,   1064,  1608,  2152,  2664,  3240,  3752,  4264,  4776,  5352,  5992,  6456,  6968,  7480,  7992,  8504,  9144,  9528,  10296, 10680, 11448, 11832, 12576, 12960, 13536, 14112, 14688, 15264, 15840, 16416, 16992, 16992, 17568, 18336, 19080, 19080, 19848, 20616, 21384, 21384, 22152, 22920, 22920, 23688, 24496, 24496, 25456, 25456, 26416, 27376, 27376, 28336, 28336, 29296, 29296, 30576, 30576, 31704, 31704, 32856, 32856, 34008, 34008, 34008, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 45352, 46888, 46888, 46888, 48936, 48936, 48936, 48936, 51024, 51024, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 55056, 57336, 57336, 57336, 57336, 59256, 59256, 59256},
1268    {552,   1128,  1736,  2280,  2856,  3496,  4008,  4584,  5160,  5736,  6200,  6968,  7480,  7992,  8504,  9144,  9912,  10296, 11064, 11448, 12216, 12576, 12960, 13536, 14112, 14688, 15264, 15840, 16416, 16992, 17568, 18336, 19080, 19848, 19848, 20616, 21384, 22152, 22152, 22920, 23688, 24496, 24496, 25456, 25456, 26416, 27376, 27376, 28336, 28336, 29296, 29296, 30576, 30576, 31704, 31704, 32856, 32856, 34008, 34008, 35160, 35160, 36696, 36696, 37888, 37888, 37888, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 45352, 46888, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 55056, 57336, 57336, 57336, 57336, 59256, 59256, 59256, 59256, 61664, 61664, 61664, 61664, 63776},
1269    {584,   1192,  1800,  2408,  2984,  3624,  4264,  4968,  5544,  5992,  6712,  7224,  7992,  8504,  9144,  9912,  10296, 11064, 11448, 12216, 12960, 13536, 14112, 14688, 15264, 15840, 16416, 16992, 17568, 18336, 19080, 19848, 19848, 20616, 21384, 22152, 22920, 22920, 23688, 24496, 25456, 25456, 26416, 26416, 27376, 28336, 28336, 29296, 29296, 30576, 31704, 31704, 32856, 32856, 34008, 34008, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 39232, 39232, 40576, 40576, 42368, 42368, 42368, 43816, 43816, 45352, 45352, 45352, 46888, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 51024, 52752, 52752, 52752, 52752, 55056, 55056, 55056, 57336, 57336, 57336, 57336, 59256, 59256, 59256, 61664, 61664, 61664, 61664, 63776, 63776, 63776, 63776, 66592, 66592, 66592, 66592},
1270    {616,   1256,  1864,  2536,  3112,  3752,  4392,  5160,  5736,  6200,  6968,  7480,  8248,  8760,  9528,  10296, 10680, 11448, 12216, 12576, 13536, 14112, 14688, 15264, 15840, 16416, 16992, 17568, 18336, 19080, 19848, 20616, 20616, 21384, 22152, 22920, 23688, 24496, 24496, 25456, 26416, 26416, 27376, 28336, 28336, 29296, 29296, 30576, 31704, 31704, 32856, 32856, 34008, 34008, 35160, 35160, 36696, 36696, 37888, 37888, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 46888, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 55056, 57336, 57336, 57336, 59256, 59256, 59256, 61664, 61664, 61664, 61664, 63776, 63776, 63776, 63776, 66592, 66592, 66592, 66592, 68808, 68808, 68808, 71112},
1271    {712,   1480,  2216,  2984,  3752,  4392,  5160,  5992,  6712,  7480,  8248,  8760,  9528,  10296, 11064, 11832, 12576, 13536, 14112, 14688, 15264, 16416, 16992, 17568, 18336, 19080, 19848, 20616, 21384, 22152, 22920, 23688, 24496, 25456, 25456, 26416, 27376, 28336, 29296, 29296, 30576, 30576, 31704, 32856, 32856, 34008, 35160, 35160, 36696, 36696, 37888, 37888, 39232, 40576, 40576, 40576, 42368, 42368, 43816, 43816, 45352, 45352, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 55056, 57336, 57336, 57336, 59256, 59256, 59256, 61664, 61664, 61664, 63776, 63776, 63776, 66592, 66592, 66592, 68808, 68808, 68808, 71112, 71112, 71112, 73712, 73712, 75376, 75376, 75376, 75376, 75376, 75376, 75376, 75376, 75376, 75376, 75376}
1272  },
1273  {
1274    {32,    88,    152,   208,   256,   328,   376,   424,   488,   536,   600,   648,   712,   776,   808,   872,   936,   1000,  1032,  1096,  1160,  1224,  1256,  1320,  1384,  1416,  1480,  1544,  1608,  1672,  1736,  1800,  1800,  1864,  1928,  1992,  2088,  2088,  2152,  2216,  2280,  2344,  2408,  2472,  2536,  2536,  2600,  2664,  2728,  2792,  2856,  2856,  2984,  2984,  3112,  3112,  3240,  3240,  3240,  3368,  3368,  3496,  3496,  3624,  3624,  3624,  3752,  3752,  3880,  3880,  4008,  4008,  4008,  4136,  4136,  4136,  4264,  4264,  4392,  4392,  4584,  4584,  4584,  4776,  4776,  4776,  4776,  4968,  4968,  5160,  5160,  5160,  5160,  5160,  5352,  5352,  5544,  5544,  5544,  5544,  5544,  5736,  5736,  5736,  5992,  5992,  5992,  5992,  5992,  6200},
1275    {56,    144,   208,   256,   344,   424,   488,   568,   632,   712,   776,   872,   936,   1000,  1064,  1160,  1224,  1288,  1384,  1416,  1544,  1608,  1672,  1736,  1800,  1864,  1992,  2024,  2088,  2152,  2280,  2344,  2408,  2472,  2536,  2600,  2728,  2792,  2856,  2856,  2984,  3112,  3112,  3240,  3240,  3368,  3496,  3496,  3624,  3624,  3752,  3752,  3880,  4008,  4008,  4008,  4136,  4136,  4264,  4264,  4392,  4584,  4584,  4776,  4776,  4776,  4968,  4968,  5160,  5160,  5160,  5160,  5352,  5544,  5544,  5544,  5544,  5736,  5736,  5736,  5992,  5992,  5992,  6200,  6200,  6200,  6456,  6456,  6456,  6456,  6712,  6712,  6712,  6968,  6968,  6968,  6968,  7224,  7224,  7224,  7480,  7480,  7480,  7480,  7736,  7736,  7736,  7992,  7992,  7992},
1276    {72,    176,   256,   328,   424,   520,   616,   696,   776,   872,   968,   1064,  1160,  1256,  1320,  1416,  1544,  1608,  1672,  1800,  1864,  1992,  2088,  2152,  2216,  2344,  2408,  2536,  2600,  2664,  2792,  2856,  2984,  3112,  3112,  3240,  3368,  3368,  3496,  3624,  3624,  3752,  3880,  4008,  4008,  4136,  4264,  4264,  4392,  4584,  4584,  4584,  4776,  4776,  4968,  5160,  5160,  5160,  5352,  5352,  5544,  5544,  5736,  5736,  5736,  5992,  5992,  6200,  6200,  6200,  6456,  6456,  6456,  6712,  6712,  6712,  6968,  6968,  6968,  7224,  7224,  7224,  7480,  7480,  7736,  7736,  7736,  7992,  7992,  7992,  8248,  8248,  8248,  8504,  8504,  8504,  8760,  8760,  8760,  9144,  9144,  9144,  9144,  9144,  9528,  9528,  9528,  9528,  9912,  9912},
1277    {104,   208,   328,   440,   568,   680,   808,   904,   1032,  1160,  1256,  1384,  1480,  1608,  1736,  1864,  1992,  2088,  2216,  2344,  2472,  2536,  2664,  2792,  2856,  2984,  3112,  3240,  3368,  3496,  3624,  3752,  3880,  4008,  4136,  4264,  4392,  4392,  4584,  4776,  4776,  4968,  4968,  5160,  5352,  5352,  5544,  5544,  5736,  5736,  5992,  5992,  6200,  6200,  6456,  6456,  6712,  6712,  6968,  6968,  7224,  7224,  7224,  7480,  7480,  7736,  7736,  7992,  7992,  8248,  8248,  8504,  8504,  8760,  8760,  8760,  9144,  9144,  9144,  9528,  9528,  9528,  9528,  9912,  9912,  9912,  10296, 10296, 10296, 10680, 10680, 10680, 10680, 11064, 11064, 11064, 11448, 11448, 11448, 11448, 11832, 11832, 11832, 11832, 12576, 12576, 12576, 12576, 12960, 12960},
1278    {120,   256,   408,   552,   696,   840,   1000,  1128,  1288,  1416,  1544,  1736,  1864,  1992,  2152,  2280,  2408,  2600,  2728,  2856,  2984,  3112,  3240,  3496,  3624,  3752,  3880,  4008,  4136,  4264,  4392,  4584,  4776,  4968,  4968,  5160,  5352,  5544,  5544,  5736,  5992,  5992,  6200,  6200,  6456,  6456,  6712,  6968,  6968,  7224,  7224,  7480,  7480,  7736,  7992,  7992,  8248,  8248,  8504,  8504,  8760,  8760,  9144,  9144,  9144,  9528,  9528,  9912,  9912,  9912,  10296, 10296, 10296, 10680, 10680, 11064, 11064, 11064, 11448, 11448, 11448, 11832, 11832, 11832, 11832, 12576, 12576, 12576, 12960, 12960, 12960, 12960, 13536, 13536, 13536, 14112, 14112, 14112, 14112, 14688, 14688, 14688, 14688, 14688, 14688, 14688, 15264, 15264, 15264, 15840},
1279    {144,   328,   504,   680,   872,   1032,  1224,  1384,  1544,  1736,  1928,  2088,  2280,  2472,  2664,  2792,  2984,  3112,  3368,  3496,  3752,  3880,  4008,  4264,  4392,  4584,  4776,  4968,  5160,  5352,  5544,  5736,  5736,  5992,  6200,  6200,  6456,  6712,  6968,  6968,  7224,  7480,  7480,  7736,  7992,  7992,  8248,  8504,  8760,  8760,  9144,  9144,  9528,  9528,  9528,  9912,  9912,  10296, 10296, 10680, 10680, 11064, 11064, 11448, 11448, 11448, 11832, 11832,  11832,  12576,  12576,  12576,  12960, 12960, 13536, 13536, 13536, 14112, 14112, 14112, 14688, 14688, 14688, 14688, 14688, 14688, 15264, 15264, 15264, 15840, 15840, 15840, 16416, 16416, 16416, 16992,  16992,  17568,  17568,  17568,  17568,  18336,  18336,  18336,  18336,  19080,  19080,  19080,  19080,  19080},
1280    {176,   392,   600,   808,   1032,  1224,  1480,  1672,  1864,  2088,  2280,  2472,  2728,  2984,  3112,  3368,  3496,  3752,  4008,  4136,  4392,  4584,  4776,  4968,  5160,  5352,  5736,  5992,  5992,  6200,  6456,  6712,  6968,  6968,  7224,  7480,  7736,  7992,  8248,  8248,  8504,  8760,  9144,  9144,  9528,  9528,  9912,  9912,  10296, 10296, 10680, 10680, 11064, 11448, 11448, 11832, 11832, 11832, 12576, 12576, 12960, 12960, 12960, 13536, 13536, 14112, 14112, 14112,  14688,  14688,  14688,  14688,  15264, 15264, 15264, 15840, 15840, 16416, 16416, 16416, 16992, 16992, 17568, 17568, 17568, 18336, 18336, 18336, 18336, 19080, 19080, 19080, 19080, 19848, 19848, 19848,  20616, 20616, 20616, 20616, 21384, 21384, 21384, 21384, 24264, 24264, 24264, 22920, 22920, 22920},
1281    {224,   472,   712,   968,   1224,  1480,  1672,  1928,  2216,  2472,  2664,  2984,  3240,  3368,  3624,  3880,  4136,  4392,  4584,  4968,  5160,  5352,  5736,  5992,  6200,  6456,  6712,  6712,  6968,  7224,  7480,  7736,  7992,  8248,  8504,  8760,  9144,  9144,  9528,  9912,  9912,  10296, 10680, 10680, 11064, 11448, 11448, 11832, 11832, 12216, 12576, 12576, 12960, 12960, 13536, 13536, 14112, 14112, 14688, 14688, 14688, 14688, 15264, 15264, 15840, 15840, 16416, 16416, 16992, 16992, 17568, 17568, 17568, 18336, 18336, 18336, 19080, 19080, 19080, 19848, 19848, 19848, 20616, 20616, 20616, 21384, 21384, 21384, 24264, 24264, 24264, 22920, 22920, 22920, 22920, 23688, 23688, 23688, 24496, 24496, 24496, 25456, 25456, 25456, 25456, 25456, 25456, 25456, 27376, 27376},
1282    {256,   536,   808,   1096,  1384,  1672,  1928,  2216,  2536,  2792,  3112,  3368,  3624,  3880,  4264,  4584,  4776,  4968,  5352,  5544,  5992,  6200,  6456,  6712,  6968,  7224,  7480,  7736,  7992,  8504,  8760,  9144,  9144,  9528,  9912,  9912,  10296, 10680, 11064, 11064, 11448, 11832, 12216, 12216, 12576, 12960, 12960, 13536, 13536, 14112, 14112, 14688, 14688, 15264, 15264, 15264, 15840, 15840, 16416, 16992, 16992, 17568, 17568, 18336, 18336, 18336, 19080, 19080, 19080, 19848, 19848, 19848, 20616, 20616, 21384, 21384, 21384, 24264, 24264, 24264, 22920, 22920, 22920, 23688, 23688, 24496, 24496, 24496, 25456, 25456, 25456, 25456, 25456, 25456, 27376, 27376, 27376, 27376, 28336, 28336, 28336, 28336, 29296, 29296, 29296, 29296, 30576, 30576, 30576, 30576},
1283    {296,   616,   936,   1256,  1544,  1864,  2216,  2536,  2856,  3112,  3496,  3752,  4136,  4392,  4776,  5160,  5352,  5736,  5992,  6200,  6712,  6968,  7224,  7480,  7992,  8248,  8504,  8760,  9144,  9528,  9912,  10296, 10296, 10680, 11064, 11448, 11832, 11832, 12216, 12576, 12960, 13536, 13536, 14112, 14112, 14688, 14688, 15264, 15264, 15840, 16416, 16416, 16992, 16992, 17568, 17568, 18336, 18336, 18336, 19080, 19080, 19848, 19848, 20616, 20616, 20616, 21384, 21384, 24264, 24264, 24264, 22920, 22920, 23688, 23688, 23688, 24496, 24496, 25456, 25456, 25456, 25456, 25456, 27376, 27376, 27376, 27376, 28336, 28336, 28336, 28336, 29296, 29296, 29296, 30576, 30576, 30576, 30576, 31704, 31704, 31704, 32856, 32856, 32856, 32856, 34008, 34008, 34008, 34008, 35160},
1284    {328,   680,   1032,  1384,  1736,  2088,  2472,  2792,  3112,  3496,  3880,  4264,  4584,  4968,  5352,  5736,  5992,  6200,  6712,  6968,  7480,  7736,  7992,  8504,  8760,  9144,  9528,  9912,  10296, 10680, 11064, 11448, 11448, 11832, 12216, 12576, 12960, 13536, 13536, 14112, 14688, 14688, 15264, 15264, 15840, 16416, 16416, 16992, 16992, 17568, 18336, 18336, 18336, 19080, 19080, 19848, 19848, 20616, 20616, 21384, 21384, 24264, 24264, 22920, 22920, 22920, 23688, 23688, 24496, 24496, 25456, 25456, 25456, 25456, 25456, 27376, 27376, 27376, 28336, 28336, 28336, 29296, 29296, 29296, 29296, 30576, 30576, 30576, 31704, 31704, 31704, 32856, 32856, 32856, 34008, 34008, 34008, 34008, 35160, 35160, 35160, 36696, 36696, 36696, 36696, 36696, 37888, 37888, 37888, 37888},
1285    {376,   776,   1192,  1608,  2024,  2408,  2792,  3240,  3624,  4008,  4392,  4776,  5352,  5736,  5992,  6456,  6968,  7224,  7736,  7992,  8504,  8760,  9144,  9528,  9912,  10680, 11064, 11448, 11832, 12216, 12576, 12960, 13536, 13536, 14112, 14688, 14688, 15264, 15840, 16416, 16416, 16992, 17568, 17568, 18336, 18336, 19080, 19080, 19848, 19848, 20616, 21384, 21384, 22152, 22152, 22920, 22920, 23688, 23688, 24496, 24496, 25456, 25456, 25456, 25456, 27376, 27376, 27376, 28336, 28336, 28336, 29296, 29296, 29296, 30576, 30576, 31704, 31704, 31704, 32856, 32856, 32856, 34008, 34008, 34008, 35160, 35160, 35160, 36696, 36696, 36696, 36696, 37888, 37888, 37888, 37888, 39232, 39232, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 42368, 42368, 43816, 43816, 43816},
1286    {440,   904,   1352,  1800,  2280,  2728,  3240,  3624,  4136,  4584,  4968,  5544,  5992,  6456,  6712,  7224,  7736,  8248,  8760,  9144,  9528,  9912,  10680, 11064, 11448, 11832, 12216, 12576, 12960, 13536, 14112, 14688, 15264, 15264, 15840, 16416, 16992, 17568, 17568, 18336, 19080, 19080, 19848, 19848, 20616, 21384, 21384, 22152, 22152, 22920, 23688, 23688, 24496, 24496, 25456, 25456, 25456, 25456, 27376, 27376, 28336, 28336, 28336, 29296, 29296, 30576, 30576, 30576, 31704, 31704, 32856, 32856, 32856, 34008, 34008, 35160, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 37888, 37888, 39232, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 45352, 46888, 46888, 46888, 46888, 48936, 48936, 48936, 48936, 51024},
1287    {488,   1000,  1544,  2024,  2536,  3112,  3624,  4136,  4584,  5160,  5736,  6200,  6712,  7224,  7736,  8248,  8760,  9144,  9912,  10296, 10680, 11448, 11832, 12216, 12960, 13536, 14112, 14688, 14688, 15264, 15840, 16416, 16992, 17568, 18336, 18336, 19080, 19848, 19848, 20616, 21384, 21384, 22152, 22920, 22920, 23688, 24496, 24496, 25456, 25456, 26416, 26416, 27376, 27376, 28336, 29296, 29296, 29296, 30576, 30576, 31704, 31704, 32856, 32856, 34008, 34008, 34008, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 37888, 39232, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 45352, 46888, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 51024, 51024, 52752, 52752, 52752, 52752, 55056, 55056, 55056, 55056, 57336, 57336},
1288    {552,   1128,  1736,  2280,  2856,  3496,  4008,  4584,  5160,  5736,  6200,  6968,  7480,  7992,  8504,  9144,  9912,  10296, 11064, 11448, 12216, 12576, 12960, 13536, 14112, 14688, 15264, 15840, 16416, 16992, 17568, 18336, 19080, 19848, 19848, 20616, 21384, 22152, 22152, 22920, 23688, 24496, 24496, 25456, 25456, 26416, 27376, 27376, 28336, 28336, 29296, 29296, 30576, 30576, 31704, 31704, 32856, 32856, 34008, 34008, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 39232, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 45352, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 57336, 57336, 57336, 57336, 59256, 59256, 59256, 59256, 61664, 61664, 61664, 61664, 63776, 63776},
1289    {600,   1224,  1800,  2472,  3112,  3624,  4264,  4968,  5544,  6200,  6712,  7224,  7992,  8504,  9144,  9912,  10296, 11064, 11832, 12216, 12960, 13536, 14112, 14688, 15264, 15840, 16416, 16992, 17568, 18336, 19080, 19848, 20616, 20616, 21384, 22152, 22920, 23688, 23688, 24496, 25456, 25456, 26416, 27376, 27376, 28336, 29296, 29296, 30576, 30576, 31704, 31704, 32856, 32856, 34008, 34008, 35160, 35160, 36696, 36696, 36696, 37888, 37888, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 46888, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 57336, 57336, 57336, 59256, 59256, 59256, 59256, 61664, 61664, 61664, 61664, 63776, 63776, 63776, 63776, 66592, 66592, 66592, 68808, 68808},
1290    {632,   1288,  1928,  2600,  3240,  3880,  4584,  5160,  5992,  6456,  7224,  7736,  8504,  9144,  9912,  10296, 11064, 11832, 12216, 12960, 13536, 14112, 14688, 15840, 16416, 16992, 17568, 18336, 19080, 19848, 19848, 20616, 21384, 22152, 22920, 23688, 24496, 24496, 25456, 26416, 26416, 27376, 28336, 28336, 29296, 30576, 30576, 31704, 31704, 32856, 32856, 34008, 34008, 35160, 35160, 36696, 36696, 37888, 37888, 39232, 39232, 39232, 40576, 40576, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 57336, 57336, 57336, 59256, 59256, 59256, 61664, 61664, 61664, 61664, 63776, 63776, 63776, 63776, 66592, 66592, 66592, 68808, 68808, 68808, 68808, 71112, 71112, 71112, 71112},
1291    {696,   1416,  2152,  2856,  3624,  4392,  5160,  5736,  6456,  7224,  7992,  8760,  9528,  10296, 10680, 11448, 12216, 12960, 13536, 14688, 15264, 15840, 16416, 17568, 18336, 19080, 19848, 20616, 20616, 21384, 22152, 22920, 23688, 24496, 25456, 26416, 26416, 27376, 28336, 29296, 29296, 30576, 30576, 31704, 32856, 32856, 34008, 35160, 35160, 36696, 36696, 37888, 37888, 39232, 39232, 40576, 40576, 40576, 42368, 42368, 43816, 43816, 45352, 45352, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 57336, 57336, 59256, 59256, 59256, 61664, 61664, 61664, 61664, 63776, 63776, 63776, 66592, 66592, 66592, 68808, 68808, 68808, 71112, 71112, 71112, 71112, 73712, 73712, 73712, 73712, 76208, 76208, 76208, 78704, 78704, 78704, 78704},
1292    {776,   1544,  2344,  3112,  4008,  4776,  5544,  6200,  7224,  7992,  8760,  9528,  10296, 11064, 11832, 12576, 13536, 14112, 15264, 15840, 16416, 17568, 18336, 19080, 19848, 20616, 21384, 22152, 22920, 23688, 24496, 25456, 26416, 27376, 27376, 28336, 29296, 30576, 30576, 31704, 32856, 32856, 34008, 35160, 35160, 36696, 37888, 37888, 39232, 39232, 40576, 40576, 42368, 42368, 43816, 43816, 45352, 45352, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 52752, 52752, 55056, 55056, 55056, 57336, 57336, 59256, 59256, 59256, 61664, 61664, 61664, 63776, 63776, 63776, 66592, 66592, 66592, 68808, 68808, 68808, 71112, 71112, 71112, 73712, 73712, 73712, 76208, 76208, 76208, 76208, 78704, 78704, 78704, 81176, 81176, 81176, 81176, 84760, 84760, 84760, 84760, 87936, 87936},
1293    {840,   1736,  2600,  3496,  4264,  5160,  5992,  6968,  7736,  8504,  9528,  10296, 11064, 12216, 12960, 13536, 14688, 15264, 16416, 16992, 18336, 19080, 19848, 20616, 21384, 22152, 22920, 24496, 25456, 25456, 26416, 27376, 28336, 29296, 30576, 30576, 31704, 32856, 34008, 34008, 35160, 36696, 36696, 37888, 39232, 39232, 40576, 40576, 42368, 43816, 43816, 45352, 45352, 46888, 46888, 48936, 48936, 51024, 51024, 51024, 52752, 52752, 55056, 55056, 57336, 57336, 59256, 59256, 59256, 61664, 61664, 61664, 63776, 63776, 66592, 66592, 66592, 68808, 68808, 68808, 71112, 71112, 71112, 73712, 73712, 73712, 76208, 76208, 76208, 78704, 78704, 78704, 81176, 81176, 81176, 81176, 84760, 84760, 84760, 87936, 87936, 87936, 87936, 90816, 90816, 90816, 93800, 93800, 93800, 93800},
1294    {904,   1864,  2792,  3752,  4584,  5544,  6456,  7480,  8248,  9144,  10296, 11064, 12216, 12960, 14112, 14688, 15840, 16992, 17568, 18336, 19848, 20616, 21384, 22152, 22920, 24496, 25456, 26416, 27376, 28336, 29296, 29296, 30576, 31704, 32856, 34008, 34008, 35160, 36696, 36696, 37888, 39232, 40576, 40576, 42368, 42368, 43816, 45352, 45352, 46888, 46888, 48936, 48936, 51024, 51024, 52752, 52752, 55056, 55056, 57336, 57336, 59256, 59256, 59256, 61664, 61664, 63776, 63776, 63776, 66592, 66592, 68808, 68808, 68808, 71112, 71112, 71112, 73712, 73712, 73712, 76208, 76208, 78704, 78704, 78704, 81176, 81176, 81176, 84760, 84760, 84760, 84760, 87936, 87936, 87936, 90816, 90816, 90816, 93800, 93800, 93800, 93800, 97896, 97896, 97896, 97896, 97896, 101840, 101840, 101840},
1295    {1000,  1992,  2984,  4008,  4968,  5992,  6968,  7992,  9144,  9912,  11064, 12216, 12960, 14112, 15264, 15840, 16992, 18336, 19080, 19848, 21384, 22152, 22920, 24496, 25456, 26416, 27376, 28336, 29296, 30576, 31704, 31704, 32856, 34008, 35160, 36696, 36696, 37888, 39232, 40576, 40576, 42368, 43816, 43816, 45352, 46888, 46888, 48936, 48936, 51024, 51024, 52752, 52752, 55056, 55056, 57336, 57336, 59256, 59256, 61664, 61664, 63776, 63776, 63776, 66592, 66592, 68808, 68808, 71112, 71112, 71112, 73712, 73712, 73712, 76208, 76208, 78704, 78704, 78704, 81176, 81176, 81176, 84760, 84760, 84760, 87936, 87936, 87936, 90816, 90816, 90816, 93800, 93800, 93800, 93800, 97896, 97896, 97896, 97896, 101840, 101840, 101840, 101840, 105528, 105528, 105528, 105528, 110136, 110136, 110136},
1296    {1064,  2152,  3240,  4264,  5352,  6456,  7480,  8504,  9528,  10680, 11832, 12960, 14112, 15264, 16416, 16992, 18336, 19080, 20616, 21384, 22920, 23688, 24496, 25456, 27376, 28336, 29296, 30576, 31704, 32856, 34008, 34008, 35160, 36696, 37888, 39232, 40576, 40576, 42368, 43816, 43816, 45352, 46888, 46888, 48936, 48936, 51024, 51024, 52752, 55056, 55056, 57336, 57336, 59256, 59256, 61664, 61664, 63776, 63776, 66592, 66592, 68808, 68808, 68808, 71112, 71112, 73712, 73712, 73712, 76208, 76208, 78704, 78704, 81176, 81176, 81176, 84760, 84760, 84760, 87936, 87936, 87936, 90816, 90816, 90816, 93800, 93800, 93800, 97896, 97896, 97896, 97896, 101840, 101840, 101840, 101840, 105528, 105528, 105528, 110136, 110136, 110136, 110136, 115040, 115040, 115040, 115040, 119816, 119816, 119816},
1297    {1128,  2280,  3496,  4584,  5736,  6968,  7992,  9144,  10296, 11448, 12576, 13536, 14688, 15840, 16992, 18336, 19848, 20616, 22152, 22920, 24496, 25456, 26416, 27376, 28336, 29296, 30576, 31704, 32856, 34008, 35160, 36696, 37888, 39232, 40576, 40576, 42368, 43816, 45352, 45352, 46888, 48936, 48936, 51024, 51024, 52752, 55056, 55056, 57336, 57336, 59256, 59256, 61664, 61664, 63776, 63776, 66592, 66592, 68808, 68808, 71112, 71112, 73712, 73712, 76208, 76208, 76208, 78704, 78704, 81176, 81176, 81176, 84760, 84760, 87936, 87936, 87936, 90816, 90816, 90816, 93800, 93800, 93800, 97896, 97896, 97896, 101840,101840,101840,101840,105528, 105528, 105528, 110136, 110136, 110136, 110136, 115040, 115040, 115040, 115040, 119816, 119816, 119816, 119816, 124464, 124464, 124464, 124464, 128496},
1298    {1192,  2408,  3624,  4968,  5992,  7224,  8504,  9912,  11064, 12216, 13536, 14688, 15840, 16992, 18336, 19848, 20616, 22152, 22920, 24496, 25456, 26416, 28336, 29296, 30576, 31704, 32856, 34008, 35160, 36696, 37888, 39232, 40576, 42368, 42368, 43816, 45352, 46888, 46888, 48936, 51024, 51024, 52752, 52752, 55056, 57336, 57336, 59256, 59256, 61664, 61664, 63776, 63776, 66592, 66592, 68808, 71112, 71112, 73712, 73712, 73712, 76208, 76208, 78704, 78704, 81176, 81176, 84760, 84760, 84760, 87936, 87936, 90816, 90816, 90816, 93800, 93800, 93800, 97896, 97896, 97896, 101840, 101840, 101840, 105528, 105528, 105528, 105528, 110136, 110136, 110136, 115040, 115040, 115040, 115040, 119816, 119816, 119816, 124464, 124464, 124464, 124464, 128496, 128496, 128496, 128496, 133208, 133208, 133208, 133208},
1299    {1256,  2536,  3752,  5160,  6200,  7480,  8760,  10296, 11448, 12576, 14112, 15264, 16416, 17568, 19080, 20616, 21384, 22920, 24496, 25456, 26416, 28336, 29296, 30576, 31704, 32856, 34008, 35160, 36696, 37888, 39232, 40576, 42368, 43816, 43816, 45352, 46888, 48936, 48936, 51024, 52752, 52752, 55056, 55056, 57336, 59256, 59256, 61664, 61664, 63776, 63776, 66592, 66592, 68808, 71112, 71112, 73712, 73712, 76208, 76208, 78704, 78704, 81176, 81176, 81176, 84760, 84760, 87936, 87936, 87936, 90816, 90816, 93800, 93800, 93800, 97896, 97896, 97896, 101840, 101840, 101840, 105528, 105528, 105528, 110136, 110136, 110136, 110136, 115040,115040, 115040, 119816, 119816, 119816, 124464, 124464, 124464, 124464, 128496, 128496, 128496, 128496, 133208, 133208, 133208, 133208, 137792, 137792, 137792, 142248},
1300    {1480,  2984,  4392,  5992,  7480,  8760,  10296, 11832, 13536, 14688, 16416, 17568, 19080, 20616, 22152, 23688, 25456, 26416, 28336, 29296, 30576, 32856, 34008, 35160, 36696, 37888, 40576, 40576, 42368, 43816, 45352, 46888, 48936, 51024, 52752, 52752, 55056, 55056, 57336, 59256, 59256, 61664, 63776, 63776, 66592, 68808, 68808, 71112, 73712, 75376, 75376, 75376, 75376, 75376, 75376, 81176, 84760, 84760, 87936, 87936, 90816, 90816, 93800, 93800, 97896, 97896, 97896, 101840, 101840, 105528, 105528, 105528, 110136, 110136, 110136, 110136, 115040, 115040, 115040, 119816, 119816, 119816, 124464, 124464, 124464, 128496, 128496, 128496, 133208, 133208, 133208, 137792, 137792, 137792, 142248, 142248, 142248, 146856, 146856,149776, 149776, 149776, 149776, 149776, 149776, 149776, 149776, 149776, 149776, 149776}
1301  }
1302 };
1303 RgSchUlIMcsTbl rgUlIMcsTbl = {
1304    {2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, 5},
1305    {2, 6}, {2, 7}, {2, 8}, {2, 9}, {2, 10},
1306    {4, 10}, {4, 11}, {4, 12}, {4, 13}, {4, 14},
1307    {4, 15}, {4, 16}, {4, 17}, {4, 18}, {4, 19},
1308    {6, 19}, {6, 20}, {6, 21}, {6, 22}, {6, 23},
1309    {6, 24}, {6, 25}, {6, 26}
1310 };
1311 RgSchUeCatTbl rgUeCatTbl = {
1312    /*Column1:Maximum number of bits of an UL-SCH 
1313              transport block transmitted within a TTI
1314              - maxUlBits
1315      Column2:Maximum number of bits of a DLSCH
1316              transport block received within a TTI 
1317              - maxDlBits
1318      Column3:Total number of soft channel bits 
1319              - maxSftChBits
1320      Column4:Support for 64QAM in UL 
1321              - ul64qamSup
1322      Column5:Maximum number of DL-SCH transport
1323              block bits received within a TTI
1324              - maxDlTbBits
1325      Column6:Maximum number of supported layers for 
1326              spatial multiplexing in DL 
1327              - maxTxLyrs*/
1328    {5160,  {10296,0},      250368,  FALSE, 10296,  1},
1329    {25456, {51024,0},      1237248, FALSE, 51024,  2},
1330    {51024, {75376,0},      1237248, FALSE, 102048, 2},
1331    {51024, {75376,0},      1827072, FALSE, 150752, 2},
1332    {75376, {149776,0},     3667200, TRUE,  299552, 4},
1333    {51024, {75376,149776}, 3654144, FALSE, 301504,  4},
1334    {51024, {75376,149776}, 3654144, FALSE, 301504,  4},
1335    {149776,{299856,0},     35982720,TRUE,  2998560, 8}
1336 };
1337
1338 /* [ccpu00138532]-ADD-The below table stores the min HARQ RTT time
1339    in Downlink for TDD and FDD. Indices 0 to 6 map to tdd UL DL config 0-6. 
1340    Index 7 map to FDD */    
1341 U8 rgSchCmnHarqRtt[8] = {4,7,10,9,12,15,6,8};
1342 /* Number of CFI Switchover Index is equals to 7 TDD Indexes + 1 FDD index */
1343 U8 rgSchCfiSwitchOvrWinLen[] = {7, 4, 2, 3, 2, 1, 6, 8};
1344
1345 /* EffTbl is calculated for single layer and two layers.
1346   * CqiToTbs is calculated for single layer and two layers */
1347 RgSchCmnTbSzEff rgSchCmnNorCfi1Eff[RGSCH_MAX_NUM_LYR_PERCW], rgSchCmnNorCfi2Eff[RGSCH_MAX_NUM_LYR_PERCW];
1348 RgSchCmnTbSzEff rgSchCmnNorCfi3Eff[RGSCH_MAX_NUM_LYR_PERCW], rgSchCmnNorCfi4Eff[RGSCH_MAX_NUM_LYR_PERCW];
1349 /* New variable to store UL effiency values for normal and extended CP*/
1350 RgSchCmnTbSzEff rgSchCmnNorUlEff[1],rgSchCmnExtUlEff[1];
1351 RgSchCmnCqiToTbs rgSchCmnNorCfi1CqiToTbs[RGSCH_MAX_NUM_LYR_PERCW], rgSchCmnNorCfi2CqiToTbs[RGSCH_MAX_NUM_LYR_PERCW];
1352 RgSchCmnCqiToTbs rgSchCmnNorCfi3CqiToTbs[RGSCH_MAX_NUM_LYR_PERCW], rgSchCmnNorCfi4CqiToTbs[RGSCH_MAX_NUM_LYR_PERCW];
1353 RgSchCmnCqiToTbs *rgSchCmnCqiToTbs[RGSCH_MAX_NUM_LYR_PERCW][RG_SCH_CMN_MAX_CP][RG_SCH_CMN_MAX_CFI];
1354 RgSchCmnTbSzEff rgSchCmnExtCfi1Eff[RGSCH_MAX_NUM_LYR_PERCW], rgSchCmnExtCfi2Eff[RGSCH_MAX_NUM_LYR_PERCW];
1355 RgSchCmnTbSzEff rgSchCmnExtCfi3Eff[RGSCH_MAX_NUM_LYR_PERCW], rgSchCmnExtCfi4Eff[RGSCH_MAX_NUM_LYR_PERCW];
1356 RgSchCmnCqiToTbs rgSchCmnExtCfi1CqiToTbs[RGSCH_MAX_NUM_LYR_PERCW], rgSchCmnExtCfi2CqiToTbs[RGSCH_MAX_NUM_LYR_PERCW];
1357 RgSchCmnCqiToTbs rgSchCmnExtCfi3CqiToTbs[RGSCH_MAX_NUM_LYR_PERCW], rgSchCmnExtCfi4CqiToTbs[RGSCH_MAX_NUM_LYR_PERCW];
1358 /* Include CRS REs while calculating Efficiency */
1359 RgSchCmnTbSzEff *rgSchCmnEffTbl[RGSCH_MAX_NUM_LYR_PERCW][RG_SCH_CMN_MAX_CP][RG_SCH_CMN_MAX_ANT_CONF][RG_SCH_CMN_MAX_CFI];
1360 RgSchCmnTbSzEff *rgSchCmnUlEffTbl[RG_SCH_CMN_MAX_CP];
1361 #ifdef LTE_TDD
1362 RgSchRaPrmblToRaFrmTbl rgRaPrmblToRaFrmTbl = {1, 2, 2, 3, 1};
1363 #else
1364 /* Added matrix 'rgRaPrmblToRaFrmTbl'for computation of RA sub-frames from RA preamble */
1365 RgSchRaPrmblToRaFrmTbl rgRaPrmblToRaFrmTbl = {1, 2, 2, 3};
1366 #endif
1367
1368 EXTERN  RgUlSchdInits        rgSchUlSchdInits;
1369 EXTERN  RgDlSchdInits        rgSchDlSchdInits;
1370 EXTERN  RgDlfsSchdInits      rgSchDlfsSchdInits;
1371 #ifdef EMTC_ENABLE
1372 EXTERN  RgEmtcUlSchdInits        rgSchEmtcUlSchdInits;
1373 EXTERN  RgEmtcDlSchdInits        rgSchEmtcDlSchdInits;
1374 #endif
1375
1376 /* RACHO : start */
1377 PRIVATE S16 rgSCHCmnUeIdleExdThrsld ARGS((
1378 RgSchCellCb     *cell,
1379 RgSchUeCb       *ue
1380 ));
1381 RgSchUeCb* rgSCHCmnGetHoUe ARGS((
1382 RgSchCellCb           *cell,
1383 U16                   rapId
1384 ));
1385 PRIVATE Void rgSCHCmnDelDedPreamble ARGS((
1386 RgSchCellCb           *cell,
1387 U8                    preambleId
1388 ));
1389 RgSchUeCb* rgSCHCmnGetPoUe ARGS((
1390 RgSchCellCb           *cell,
1391 U16                   rapId,
1392 CmLteTimingInfo       timingInfo
1393 ));
1394 PRIVATE Void rgSCHCmnDelRachInfo ARGS((
1395 RgSchCellCb  *cell,
1396 RgSchUeCb    *ue
1397 ));
1398 PRIVATE S16 rgSCHCmnUlRbAllocForPoHoUe ARGS((
1399 RgSchCellCb           *cell,
1400 RgSchUlSf             *sf,
1401 RgSchUeCb             *ue,
1402 U8                    maxRb
1403 ));
1404 PRIVATE Void rgSCHCmnHdlHoPo ARGS((
1405 RgSchCellCb           *cell,
1406 CmLListCp             *raRspLst,
1407 RgSchRaReqInfo        *raReq
1408 ));
1409 PRIVATE Void rgSCHCmnAllocPoHoGrnt ARGS((
1410 RgSchCellCb           *cell,
1411 CmLListCp             *raRspLst,
1412 RgSchUeCb             *ue,
1413 RgSchRaReqInfo        *raReq
1414 ));
1415 PRIVATE Void rgSCHCmnFillPdcchOdr2Sf ARGS((
1416 RgSchCellCb *cell,
1417 RgSchUeCb   *ue,
1418 RgSchPdcch  *pdcc,
1419 U8          rapId,
1420 U8          prachMskIdx
1421 ));
1422 PRIVATE Void rgSCHCmnDlAdd2PdcchOdrQ ARGS((
1423 RgSchCellCb                *cell,
1424 RgSchUeCb                  *ue
1425 ));
1426 PRIVATE Void rgSCHCmnDlRmvFrmPdcchOdrQ ARGS((
1427 RgSchCellCb                *cell,
1428 RgSchUeCb                  *ue
1429 ));
1430 PRIVATE Void rgSCHCmnUpdNxtPrchMskIdx ARGS((
1431 RgSchCellCb  *cell
1432 ));
1433 PRIVATE Void rgSCHCmnUpdRachParam ARGS((
1434 RgSchCellCb  *cell
1435 ));
1436 PRIVATE S16 rgSCHCmnAllocPOParam ARGS((
1437 RgSchCellCb  *cell,
1438 RgSchDlSf    *dlSf,
1439 RgSchUeCb    *ue,
1440 RgSchPdcch   **pdcch,
1441 U8           *rapId,
1442 U8           *prachMskIdx
1443 ));
1444 PRIVATE Void rgSCHCmnGenPdcchOrder ARGS((
1445 RgSchCellCb  *cell,
1446 RgSchDlSf    *dlSf
1447 ));
1448 PRIVATE Void rgSCHCmnCfgRachDedPrm ARGS((
1449 RgSchCellCb   *cell
1450 ));
1451 /* RACHO : end */
1452
1453 PRIVATE Void rgSCHCmnHdlUlInactUes ARGS((
1454 RgSchCellCb  *cell
1455 ));
1456 PRIVATE Void rgSCHCmnHdlDlInactUes ARGS((
1457 RgSchCellCb  *cell
1458 ));
1459 PRIVATE Void rgSCHCmnUlInit ARGS((Void
1460 ));
1461 PRIVATE Void rgSCHCmnDlInit ARGS((Void
1462 ));
1463 PRIVATE Void rgSCHCmnInitDlRbAllocInfo ARGS((
1464 RgSchCmnDlRbAllocInfo  *allocInfo
1465 ));
1466 PRIVATE Void rgSCHCmnUpdUlCompEffBsr ARGS((
1467 RgSchUeCb *ue
1468 ));
1469 #if RG_UNUSED
1470 PRIVATE Void rgSCHCmnUlSetAllUnSched  ARGS((
1471 RgSchCmnUlRbAllocInfo *allocInfo
1472 ));
1473 PRIVATE Void rgSCHCmnUlUpdSf ARGS((
1474          RgSchCellCb           *cell,
1475          RgSchCmnUlRbAllocInfo *allocInfo,
1476          RgSchUlSf     *sf
1477          ));
1478 PRIVATE Void rgSCHCmnUlHndlAllocRetx ARGS((
1479          RgSchCellCb           *cell,
1480          RgSchCmnUlRbAllocInfo *allocInfo,
1481          RgSchUlSf     *sf,
1482          RgSchUlAlloc  *alloc
1483          ));
1484 #endif
1485 PRIVATE Void rgSCHCmnGrpPwrCntrlPucch ARGS((
1486 RgSchCellCb  *cell,
1487 RgSchDlSf    *dlSf
1488 ));
1489 PRIVATE Void rgSCHCmnGrpPwrCntrlPusch ARGS((
1490 RgSchCellCb  *cell,
1491 RgSchUlSf    *ulSf
1492 ));
1493 PRIVATE Void rgSCHCmnDelUeFrmRefreshQ ARGS((
1494 RgSchCellCb     *cell,
1495 RgSchUeCb       *ue
1496 ));
1497 PRIVATE S16 rgSCHCmnTmrExpiry ARGS((
1498 PTR cb,               /* Pointer to timer control block */
1499 S16 tmrEvnt           /* Timer Event */
1500 ));
1501 PRIVATE S16 rgSCHCmnTmrProc ARGS((
1502 RgSchCellCb *cell
1503 ));
1504 PRIVATE Void rgSCHCmnAddUeToRefreshQ ARGS((
1505 RgSchCellCb     *cell,
1506 RgSchUeCb       *ue,
1507 U32             wait
1508 ));
1509 PRIVATE Void rgSCHCmnDlCcchRetx ARGS((
1510 RgSchCellCb             *cell,
1511 RgSchCmnDlRbAllocInfo   *allocInfo
1512 ));
1513 PRIVATE Void rgSCHCmnUpdUeMimoInfo ARGS((
1514 RgrUeCfg     *ueCfg,
1515 RgSchCmnDlUe *ueDl,
1516 RgSchCellCb  *cell,
1517 RgSchCmnCell *cellSchd
1518 ));
1519 PRIVATE Void rgSCHCmnUpdUeUlCqiInfo ARGS((
1520 RgSchCellCb   *cell,
1521 RgSchUeCb     *ue,
1522 RgSchCmnUlUe  *ueUl,
1523 RgSchCmnUe    *ueSchCmn,
1524 RgSchCmnCell  *cellSchd,
1525 Bool          isEcp 
1526 ));
1527 #ifdef RGR_V1
1528 PRIVATE Void rgSCHCmnDlCcchSduRetx ARGS((
1529 RgSchCellCb             *cell,
1530 RgSchCmnDlRbAllocInfo   *allocInfo
1531 ));
1532 PRIVATE Void rgSCHCmnDlCcchSduTx ARGS((
1533 RgSchCellCb             *cell,
1534 RgSchCmnDlRbAllocInfo   *allocInfo
1535 ));
1536 PRIVATE S16 rgSCHCmnCcchSduAlloc ARGS((
1537 RgSchCellCb                *cell,
1538 RgSchUeCb                  *ueCb,
1539 RgSchCmnDlRbAllocInfo      *allocInfo
1540 ));
1541 PRIVATE S16 rgSCHCmnCcchSduDedAlloc ARGS((
1542 RgSchCellCb                *cell,
1543 RgSchUeCb                  *ueCb
1544 ));
1545 PRIVATE S16 rgSCHCmnNonDlfsCcchSduRbAlloc ARGS((
1546 RgSchCellCb           *cell,
1547 RgSchUeCb             *ueCb,
1548 RgSchDlSf             *dlSf
1549 ));
1550 #endif
1551 PRIVATE Void rgSCHCmnInitVars ARGS((
1552          RgSchCellCb *cell
1553          ));
1554
1555 /*ccpu00117180 - DEL - Moved rgSCHCmnUpdVars to .x as its access is now */
1556 PRIVATE Void rgSCHCmnUlRbAllocForLst ARGS((
1557          RgSchCellCb           *cell,
1558          RgSchUlSf             *sf,
1559          U32                   count,
1560          CmLListCp             *reqLst,
1561          CmLListCp             *schdLst,
1562          CmLListCp             *nonSchdLst,
1563          Bool                  isNewTx
1564          ));
1565 PRIVATE S16 rgSCHCmnUlRbAllocForUe ARGS((
1566          RgSchCellCb           *cell,
1567          RgSchUlSf             *sf,
1568          RgSchUeCb             *ue,
1569          U8                    maxRb,
1570          RgSchUlHole           *hole
1571          ));
1572 PRIVATE Void rgSCHCmnMsg3GrntReq ARGS((
1573          RgSchCellCb     *cell,
1574          CmLteRnti       rnti,
1575          Bool            preamGrpA,
1576          RgSchUlHqProcCb *hqProc,
1577          RgSchUlAlloc    **ulAllocRef,
1578          U8              *hqProcIdRef
1579          ));
1580 PRIVATE Void rgSCHCmnDlCcchRarAlloc ARGS((
1581 RgSchCellCb             *cell
1582 ));
1583 PRIVATE Void rgSCHCmnDlCcchTx ARGS((
1584 RgSchCellCb             *cell,
1585 RgSchCmnDlRbAllocInfo   *allocInfo
1586 ));
1587 PRIVATE Void rgSCHCmnDlBcchPcch ARGS((
1588 RgSchCellCb             *cell,
1589 RgSchCmnDlRbAllocInfo   *allocInfo,
1590 RgInfSfAlloc            *subfrmAlloc
1591 ));
1592 Bool rgSCHCmnChkInWin ARGS((
1593 CmLteTimingInfo   frm,
1594 CmLteTimingInfo   start,
1595 CmLteTimingInfo   end
1596 ));
1597 Bool rgSCHCmnChkPastWin ARGS((
1598 CmLteTimingInfo   frm,
1599 CmLteTimingInfo   end
1600 ));
1601 PRIVATE Void rgSCHCmnClcAlloc ARGS((
1602 RgSchCellCb             *cell,
1603 RgSchDlSf               *sf,
1604 RgSchClcDlLcCb          *lch,
1605 U16                     rnti,
1606 RgSchCmnDlRbAllocInfo   *allocInfo
1607 ));
1608 #ifndef LTEMAC_SPS
1609 PRIVATE Void rgSCHCmnClcRbAlloc ARGS((
1610 RgSchCellCb             *cell,
1611 U32                     bo,
1612 U8                      cqi,
1613 U8                      *rb,
1614 U32                     *tbs,
1615 U8                      *mcs,
1616 RgSchDlSf               *sf 
1617 ));
1618 #endif
1619
1620 PRIVATE S16 rgSCHCmnMsg4Alloc ARGS((
1621 RgSchCellCb                *cell,
1622 RgSchRaCb                  *raCb,
1623 RgSchCmnDlRbAllocInfo      *allocInfo
1624 ));
1625 PRIVATE S16 rgSCHCmnMsg4DedAlloc ARGS((
1626 RgSchCellCb                *cell,
1627 RgSchRaCb                  *raCb
1628 ));
1629 PRIVATE Void rgSCHCmnDlRaRsp ARGS((
1630 RgSchCellCb                *cell,
1631 RgSchCmnDlRbAllocInfo      *allocInfo
1632 ));
1633 PRIVATE S16 rgSCHCmnRaRspAlloc ARGS((
1634 RgSchCellCb             *cell,
1635 RgSchDlSf               *subFrm,
1636 U16                     rntiIdx,
1637 U16                     rarnti,
1638 U8                      noRaRnti,
1639 RgSchCmnDlRbAllocInfo   *allocInfo
1640 ));
1641 PRIVATE Void rgSCHCmnUlUeDelAllocs ARGS((
1642 RgSchCellCb  *cell,
1643 RgSchUeCb   *ue
1644 ));
1645 PRIVATE Void rgSCHCmnDlSetUeAllocLmt ARGS((
1646 RgSchCellCb   *cell,
1647 RgSchCmnDlUe  *ueDl,
1648 Bool          isEmtcUe
1649 ));
1650 PRIVATE S16 rgSCHCmnDlRgrCellCfg ARGS((
1651 RgSchCellCb    *cell,
1652 RgrCellCfg     *cfg,
1653 RgSchErrInfo   *err
1654 ));
1655 PRIVATE Void rgSCHCmnUlAdapRetx ARGS((
1656 RgSchUlAlloc    *alloc,
1657 RgSchUlHqProcCb *proc
1658 ));
1659 PRIVATE Void rgSCHCmnUlUpdAllocRetx ARGS((
1660 RgSchCellCb    *cell,
1661 RgSchUlAlloc   *alloc
1662 ));
1663 PRIVATE Void rgSCHCmnUlSfReTxAllocs ARGS((
1664 RgSchCellCb *cell,
1665 RgSchUlSf   *sf
1666 ));
1667 /* Fix: syed Adaptive Msg3 Retx crash. */
1668 #ifdef TFU_UPGRADE
1669 PRIVATE Void rgSCHCmnDlHdlTxModeRecfg ARGS
1670 ((
1671 RgSchCellCb *cell,
1672 RgSchUeCb    *ue,
1673 RgrUeRecfg   *ueRecfg,
1674 U8 numTxPorts
1675 ));
1676 #else
1677 PRIVATE Void rgSCHCmnDlHdlTxModeRecfg ARGS
1678 ((
1679 RgSchCellCb *cell,
1680 RgSchUeCb    *ue,
1681 RgrUeRecfg   *ueRecfg
1682 ));
1683 #endif
1684
1685
1686 /*
1687  * DL RB allocation specific functions
1688  */
1689
1690 PRIVATE Void rgSCHCmnDlRbAlloc ARGS((
1691 RgSchCellCb           *cell,
1692 RgSchCmnDlRbAllocInfo *allocInfo
1693 ));
1694 PRIVATE Void rgSCHCmnNonDlfsRbAlloc ARGS((
1695 RgSchCellCb           *cell,
1696 RgSchCmnDlRbAllocInfo *allocInfo
1697 ));
1698 PRIVATE S16 rgSCHCmnNonDlfsCmnRbAlloc ARGS((
1699 RgSchCellCb           *cell,
1700 RgSchDlRbAlloc        *cmnAllocInfo));
1701
1702 #ifndef LTE_TDD
1703 PRIVATE Void rgSCHCmnNonDlfsPbchRbAllocAdj ARGS((
1704 RgSchCellCb           *cell,
1705 RgSchDlRbAlloc        *cmnAllocInfo,
1706 U8                    pbchSsRsSym,
1707 Bool                  isBcchPcch
1708 ));
1709 /* Added function to adjust TBSize*/
1710 PRIVATE Void rgSCHCmnNonDlfsPbchTbSizeAdj ARGS((
1711 RgSchDlRbAlloc        *allocInfo,
1712 U8                    numOvrlapgPbchRb,
1713 U8                    pbchSsRsSym,
1714 U8                    idx,
1715 U32                   bytesReq
1716 ));
1717
1718 /* Added function to find num of overlapping PBCH rb*/
1719 PRIVATE Void rgSCHCmnFindNumPbchOvrlapRbs ARGS((
1720 RgSchCellCb           *cell,
1721 RgSchDlSf             *dlSf,
1722 RgSchDlRbAlloc        *allocInfo,
1723 U8                    *numOvrlapgPbchRb
1724 ));
1725
1726 PRIVATE U8 rgSCHCmnFindNumAddtlRbsAvl ARGS((
1727 RgSchCellCb           *cell,
1728 RgSchDlSf             *dlSf,
1729 RgSchDlRbAlloc        *allocInfo
1730 ));
1731 #ifdef DEBUGP
1732 #ifdef UNUSED_FUNC
1733 PRIVATE Void rgSCHCmnFindCodeRate ARGS((
1734 RgSchCellCb           *cell,
1735 RgSchDlSf             *dlSf,
1736 RgSchDlRbAlloc        *allocInfo,
1737 U8                    idx
1738 ));
1739 #endif
1740 #endif
1741 #endif
1742 PRIVATE Void rgSCHCmnNonDlfsMsg4Alloc ARGS((
1743 RgSchCellCb           *cell,
1744 RgSchCmnMsg4RbAlloc   *msg4AllocInfo,
1745 U8                    isRetx
1746 ));
1747 PRIVATE S16 rgSCHCmnNonDlfsMsg4RbAlloc ARGS((
1748 RgSchCellCb           *cell,
1749 RgSchRaCb             *raCb,
1750 RgSchDlSf             *dlSf
1751 ));
1752
1753 PRIVATE S16 rgSCHCmnNonDlfsUeRbAlloc ARGS((
1754 RgSchCellCb           *cell,
1755 RgSchUeCb             *ue,
1756 RgSchDlSf             *dlSf,
1757 U8                    *isDlBwAvail
1758 ));
1759 #ifndef LTEMAC_SPS
1760 PRIVATE U32 rgSCHCmnCalcRiv ARGS(( U8 bw,
1761          U8           rbStart,
1762          U8           numRb));
1763 #endif
1764
1765 #ifdef LTE_TDD
1766 PRIVATE Void rgSCHCmnUpdHqAndDai ARGS((
1767 RgSchDlHqProcCb   *hqP,
1768 RgSchDlSf         *subFrm,
1769 RgSchDlHqTbCb     *tbCb,
1770 U8                tbAllocIdx
1771 ));
1772 PRIVATE S16 rgSCHCmnUlCalcAvailBw ARGS((
1773 RgSchCellCb *cell,
1774 RgrCellCfg  *cellCfg,
1775 U8          cfi,
1776 U8          *rbStartRef,
1777 U8          *bwAvailRef
1778 ));
1779 PRIVATE S16 rgSCHCmnDlKdashUlAscInit ARGS((
1780 RgSchCellCb *cell
1781 ));
1782 PRIVATE S16 rgSCHCmnDlANFdbkInit ARGS((
1783 RgSchCellCb *cell
1784 ));
1785 PRIVATE S16 rgSCHCmnDlNpValInit ARGS((
1786 RgSchCellCb *cell
1787 ));
1788 PRIVATE S16 rgSCHCmnDlCreateRachPrmLst ARGS((
1789 RgSchCellCb *cell
1790 ));
1791 PRIVATE S16 rgSCHCmnDlCpyRachInfo ARGS((
1792 RgSchCellCb        *cell,
1793 RgSchTddRachRspLst rachRspLst[][RGSCH_NUM_SUB_FRAMES],
1794 U8                 raArrSz
1795 ));
1796 PRIVATE S16 rgSCHCmnDlRachInfoInit ARGS((
1797 RgSchCellCb *cell
1798 ));
1799 PRIVATE S16 rgSCHCmnDlPhichOffsetInit ARGS((
1800 RgSchCellCb *cell
1801 ));
1802 #endif
1803 #ifdef TFU_UPGRADE
1804 PRIVATE Void rgSCHCmnFindUlCqiUlTxAnt ARGS
1805 ((
1806  RgSchCellCb          *cell,
1807  RgSchUeCb            *ue,
1808  U8                          wideCqi
1809  ));
1810  PRIVATE RgSchCmnRank rgSCHCmnComputeRank ARGS
1811 ((
1812  RgrTxMode    txMode,
1813  U32          *pmiBitMap,
1814  U8           numTxPorts
1815  ));
1816
1817  PRIVATE RgSchCmnRank rgSCHCmnComp2TxMode3 ARGS
1818 ((
1819  U32 *pmiBitMap
1820  ));
1821
1822   PRIVATE RgSchCmnRank rgSCHCmnComp4TxMode3 ARGS
1823 ((
1824  U32 *pmiBitMap
1825  ));
1826
1827   PRIVATE RgSchCmnRank rgSCHCmnComp2TxMode4 ARGS
1828 ((
1829  U32 *pmiBitMap
1830  ));
1831
1832   PRIVATE RgSchCmnRank rgSCHCmnComp4TxMode4 ARGS
1833 ((
1834  U32 *pmiBitMap
1835  ));
1836
1837  PRIVATE U8 rgSCHCmnCalcWcqiFrmSnr ARGS
1838 ((
1839  RgSchCellCb        *cell,
1840  TfuSrsRpt        *srsRpt
1841  ));
1842 #endif
1843
1844 /* comcodsepa : start */
1845 \f
1846 /**
1847  * @brief This function computes efficiency and stores in a table.
1848  *
1849  * @details
1850  *
1851  *     Function: rgSCHCmnCompEff
1852  *     Purpose:  this function computes the efficiency as number of
1853  *               bytes per 1024 symbols. The CFI table is also filled
1854  *               with the same information such that comparison is valid
1855  *
1856  *     Invoked by: Scheduler
1857  *
1858  *  @param[in]  U8            noPdcchSym
1859  *  @param[in]  U8            cpType
1860  *  @param[in]  U8            txAntIdx
1861  *  @param[in]  RgSchCmnTbSzEff* effTbl
1862  *  @return  Void
1863  *
1864  **/
1865 #ifdef ANSI
1866 PRIVATE Void rgSCHCmnCompEff
1867 (
1868 U8                    noPdcchSym,
1869 U8                    cpType,
1870 U8                    txAntIdx,
1871 RgSchCmnTbSzEff       *effTbl
1872 )
1873 #else
1874 PRIVATE Void rgSCHCmnCompEff(noPdcchSym, cpType, txAntIdx, effTbl)
1875 U8                    noPdcchSym;
1876 U8                    cpType;
1877 U8                    txAntIdx;
1878 RgSchCmnTbSzEff       *effTbl;
1879 #endif
1880 {
1881    U8               noResPerRb;
1882    U8               noSymPerRb;
1883    U8               resOfCrs; /* Effective REs occupied by CRS */
1884    U8               i, j;
1885
1886
1887    switch (cpType)
1888    {
1889       case RG_SCH_CMN_NOR_CP:
1890          noSymPerRb = 14;
1891          break;
1892       case RG_SCH_CMN_EXT_CP:
1893          noSymPerRb = 12;
1894          break;
1895       default:
1896          /* Generate a log error. This case should never be executed */
1897          RETVOID;
1898    }
1899
1900    /* Depending on the Tx Antenna Index, deduct the
1901     * Resource elements for the CRS */
1902    switch (txAntIdx)
1903    {
1904       case 0:
1905          resOfCrs = RG_SCH_CMN_EFF_CRS_ONE_ANT_PORT;
1906          break;
1907       case 1:
1908          resOfCrs = RG_SCH_CMN_EFF_CRS_TWO_ANT_PORT;
1909          break;
1910       case 2:
1911          resOfCrs = RG_SCH_CMN_EFF_CRS_FOUR_ANT_PORT;
1912          break;
1913       default:
1914          /* Generate a log error. This case should never be executed */
1915          RETVOID;
1916    }
1917    noResPerRb = ((noSymPerRb - noPdcchSym) * RB_SCH_CMN_NUM_SCS_PER_RB) - resOfCrs;
1918    for (i = 0; i < RG_SCH_CMN_NUM_TBS; i++)
1919    {
1920       (*effTbl)[i] = 0;
1921       for (j = 0; j < RG_SCH_CMN_NUM_RBS; j++)
1922       {
1923          /* This line computes the coding efficiency per 1024 REs */
1924          (*effTbl)[i] += (rgTbSzTbl[0][i][j] * 1024) / (noResPerRb * (j+1));
1925       }
1926       (*effTbl)[i] /= RG_SCH_CMN_NUM_RBS;
1927    }
1928    RETVOID;
1929 }
1930 /**
1931  * @brief This function computes efficiency and stores in a table.
1932  *
1933  * @details
1934  *
1935  *     Function: rgSCHCmnCompUlEff
1936  *     Purpose:  this function computes the efficiency as number of
1937  *               bytes per 1024 symbols. The CFI table is also filled
1938  *               with the same information such that comparison is valid
1939  *
1940  *     Invoked by: Scheduler
1941  *
1942  *  @param[in]  U8            noUlRsSym
1943  *  @param[in]  U8            cpType
1944  *  @param[in]  U8            txAntIdx
1945  *  @param[in]  RgSchCmnTbSzEff* effTbl
1946  *  @return  Void
1947  *
1948  **/
1949 #ifdef ANSI
1950 PRIVATE Void rgSCHCmnCompUlEff
1951 (
1952 U8                    noUlRsSym,
1953 U8                    cpType,
1954 RgSchCmnTbSzEff       *effTbl
1955 )
1956 #else
1957 PRIVATE Void rgSCHCmnCompUlEff(noUlRsSym, cpType, effTbl)
1958 U8                    noUlRsSym;
1959 U8                    cpType;
1960 RgSchCmnTbSzEff       *effTbl;
1961 #endif
1962 {
1963    U8               noResPerRb;
1964    U8               noSymPerRb;
1965    U8               i, j;
1966
1967
1968    switch (cpType)
1969    {
1970       case RG_SCH_CMN_NOR_CP:
1971          noSymPerRb = 14;
1972          break;
1973       case RG_SCH_CMN_EXT_CP:
1974          noSymPerRb = 12;
1975          break;
1976       default:
1977          /* Generate a log error. This case should never be executed */
1978          RETVOID;
1979    }
1980
1981    noResPerRb = ((noSymPerRb - noUlRsSym) * RB_SCH_CMN_NUM_SCS_PER_RB);
1982    for (i = 0; i < RG_SCH_CMN_NUM_TBS; i++)
1983    {
1984       (*effTbl)[i] = 0;
1985       for (j = 0; j < RG_SCH_CMN_NUM_RBS; j++)
1986       {
1987          /* This line computes the coding efficiency per 1024 REs */
1988          (*effTbl)[i] += (rgTbSzTbl[0][i][j] * 1024) / (noResPerRb * (j+1));
1989       }
1990       (*effTbl)[i] /= RG_SCH_CMN_NUM_RBS;
1991    }
1992    RETVOID;
1993 }
1994
1995 /**
1996  * @brief This function computes efficiency for 2 layers and stores in a table.
1997  *
1998  * @details
1999  *
2000  *     Function: rgSCHCmn2LyrCompEff
2001  *     Purpose:  this function computes the efficiency as number of
2002  *               bytes per 1024 symbols. The CFI table is also filled
2003  *               with the same information such that comparison is valid
2004  *
2005  *     Invoked by: Scheduler
2006  *
2007  *  @param[in]  U8            noPdcchSym
2008  *  @param[in]  U8            cpType
2009  *  @param[in]  U8            txAntIdx
2010  *  @param[in]  RgSchCmnTbSzEff* effTbl2Lyr
2011  *  @return  Void
2012  *
2013  **/
2014 #ifdef ANSI
2015 PRIVATE Void rgSCHCmn2LyrCompEff
2016 (
2017 U8                    noPdcchSym,
2018 U8                    cpType,
2019 U8                    txAntIdx,
2020 RgSchCmnTbSzEff       *effTbl2Lyr
2021 )
2022 #else
2023 PRIVATE Void rgSCHCmn2LyrCompEff(noPdcchSym, cpType, txAntIdx, effTbl2Lyr)
2024 U8                    noPdcchSym;
2025 U8                    cpType;
2026 U8                    txAntIdx;
2027 RgSchCmnTbSzEff       *effTbl2Lyr;
2028 #endif
2029 {
2030    U8               noResPerRb;
2031    U8               noSymPerRb;
2032    U8               resOfCrs; /* Effective REs occupied by CRS */
2033    U8               i, j;
2034
2035
2036    switch (cpType)
2037    {
2038       case RG_SCH_CMN_NOR_CP:
2039          noSymPerRb = 14;
2040          break;
2041       case RG_SCH_CMN_EXT_CP:
2042          noSymPerRb = 12;
2043          break;
2044       default:
2045          /* Generate a log error. This case should never be executed */
2046          RETVOID;
2047    }
2048
2049    /* Depending on the Tx Antenna Index, deduct the
2050     * Resource elements for the CRS */
2051    switch (txAntIdx)
2052    {
2053       case 0:
2054          resOfCrs = RG_SCH_CMN_EFF_CRS_ONE_ANT_PORT;
2055          break;
2056       case 1:
2057          resOfCrs = RG_SCH_CMN_EFF_CRS_TWO_ANT_PORT;
2058          break;
2059       case 2:
2060          resOfCrs = RG_SCH_CMN_EFF_CRS_FOUR_ANT_PORT;
2061          break;
2062       default:
2063          /* Generate a log error. This case should never be executed */
2064          RETVOID;
2065    }
2066
2067    noResPerRb = ((noSymPerRb - noPdcchSym) * RB_SCH_CMN_NUM_SCS_PER_RB) - resOfCrs;
2068    for (i = 0; i < RG_SCH_CMN_NUM_TBS; i++)
2069    {
2070       (*effTbl2Lyr)[i] = 0;
2071       for (j = 0; j < RG_SCH_CMN_NUM_RBS; j++)
2072       {
2073          /* This line computes the coding efficiency per 1024 REs */
2074          (*effTbl2Lyr)[i] += (rgTbSzTbl[1][i][j] * 1024) / (noResPerRb * (j+1));
2075       }
2076       (*effTbl2Lyr)[i] /= RG_SCH_CMN_NUM_RBS;
2077    }
2078    RETVOID;
2079 }
2080
2081 \f
2082 /**
2083  * @brief This function initializes the rgSchCmnDciFrmtSizes table.
2084  *
2085  * @details
2086  *
2087  *     Function: rgSCHCmnGetDciFrmtSizes
2088  *     Purpose:  This function determines the sizes of all
2089  *               the available DCI Formats. The order of
2090  *               bits addition for each format is inaccordance
2091  *               with the specs.
2092  *     Invoked by: rgSCHCmnRgrCellCfg
2093  *
2094  *  @return  Void
2095  *
2096  **/
2097 #ifdef ANSI
2098 PRIVATE Void rgSCHCmnGetDciFrmtSizes
2099 (
2100 RgSchCellCb *cell
2101 )
2102 #else
2103 PRIVATE Void rgSCHCmnGetDciFrmtSizes(cell)
2104 RgSchCellCb *cell;
2105 #endif
2106 {
2107
2108
2109    /* DCI Format 0 size determination */
2110    rgSchCmnDciFrmtSizes[0] = 1 +
2111                              1 +
2112                              rgSCHUtlLog32bitNbase2((cell->bwCfg.ulTotalBw * \
2113                              (cell->bwCfg.ulTotalBw + 1))/2) +
2114                              5 +
2115                              1 +
2116                              2 +
2117                              3 +
2118 #ifdef LTE_TDD
2119                              2 +
2120                              2 +
2121 #endif
2122                              1;
2123    /* DCI Format 1 size determination */
2124    rgSchCmnDciFrmtSizes[1] = 1 +
2125    RGSCH_CEIL(cell->bwCfg.dlTotalBw, cell->rbgSize) +
2126                              5 +
2127 #ifndef LTE_TDD
2128                              3 +
2129 #else
2130                              4 + 2 + /* HqProc Id and DAI */
2131 #endif
2132                              1 +
2133                              2 +
2134                              2;
2135
2136    /* DCI Format 1A size determination */
2137    rgSchCmnDciFrmtSizes[2] = 1 + /* Flag for format0/format1a differentiation */
2138                1 + /* Localized/distributed VRB assignment flag */
2139                5 + /* For mcs */
2140 #ifndef LTE_TDD
2141                3 + /* Harq process Id */
2142 #else
2143                4 + /* Harq process Id */
2144                2 + /* UL Index or DAI */
2145 #endif
2146                1 + /* New Data Indicator */
2147                2 + /* For RV */
2148                2 + /* For tpc */
2149                1 + rgSCHUtlLog32bitNbase2((cell->bwCfg.dlTotalBw * \
2150                    (cell->bwCfg.dlTotalBw + 1))/2);
2151                /* Resource block assignment ceil[log2(bw(bw+1)/2)] : \
2152                   Since VRB is local */
2153
2154    /* DCI Format 1B size determination */
2155    rgSchCmnDciFrmtSizes[3] = 1 +
2156                              rgSCHUtlLog32bitNbase2((cell->bwCfg.dlTotalBw * \
2157                              (cell->bwCfg.dlTotalBw + 1))/2) +
2158                              5 +
2159                              3 +
2160 #ifdef LTE_TDD
2161                              1 + /* HqP */
2162                              2 + /* Dai */
2163 #endif
2164                              1 +
2165                              2 +
2166                              2 +
2167                              ((cell->numTxAntPorts == 4)? 4:2) +
2168                              1;
2169
2170    /* DCI Format 1C size determination */
2171    /* Approximation: NDLVrbGap1 ~= Nprb for DL */
2172    rgSchCmnDciFrmtSizes[4] = (cell->bwCfg.dlTotalBw < 50)? 0:1 +
2173                              (cell->bwCfg.dlTotalBw < 50)?
2174                              (rgSCHUtlLog32bitNbase2((cell->bwCfg.dlTotalBw/2 * \
2175                                 (cell->bwCfg.dlTotalBw/2 + 1))/2)) :
2176                              (rgSCHUtlLog32bitNbase2((cell->bwCfg.dlTotalBw/4 * \
2177                                 (cell->bwCfg.dlTotalBw/4 + 1))/2)) +
2178                              5;
2179
2180    /* DCI Format 1D size determination */
2181    rgSchCmnDciFrmtSizes[5] = 1 +
2182                              rgSCHUtlLog32bitNbase2((cell->bwCfg.dlTotalBw * \
2183                              (cell->bwCfg.dlTotalBw + 1))/2) +
2184                              5 +
2185                              3 +
2186 #ifdef LTE_TDD
2187                              1 + 2 +
2188 #endif
2189                              1 +
2190                              2 +
2191                              2 +
2192                              ((cell->numTxAntPorts == 4)? 4:2) +
2193                              1;
2194
2195    /* DCI Format 2 size determination */
2196    rgSchCmnDciFrmtSizes[6] = ((cell->bwCfg.dlTotalBw < 10)?0:1) +
2197                              RGSCH_CEIL(cell->bwCfg.dlTotalBw, cell->rbgSize) +
2198                              2 +
2199 #ifdef LTE_TDD
2200                              2 + 1 +
2201 #endif
2202                              3 +
2203                              1 +
2204                              (5 + 1 + 2)*2 +
2205                              ((cell->numTxAntPorts == 4)? 6:3);
2206
2207    /* DCI Format 2A size determination */
2208    rgSchCmnDciFrmtSizes[7] = ((cell->bwCfg.dlTotalBw < 10)?0:1) +
2209                              RGSCH_CEIL(cell->bwCfg.dlTotalBw, cell->rbgSize) +
2210                              2 +
2211 #ifdef LTE_TDD
2212                              2 + 1 +
2213 #endif
2214                              3 +
2215                              1 +
2216                              (5 + 1 + 2)*2 +
2217                              ((cell->numTxAntPorts == 4)? 2:0);
2218
2219    /* DCI Format 3 size determination */
2220    rgSchCmnDciFrmtSizes[8] = rgSchCmnDciFrmtSizes[0];
2221
2222    /* DCI Format 3A size determination */
2223    rgSchCmnDciFrmtSizes[9] = rgSchCmnDciFrmtSizes[0];
2224
2225    RETVOID;
2226 }
2227
2228
2229 /**
2230  * @brief This function initializes the cmnCell->dciAggrLvl table.
2231  *
2232  * @details
2233  *
2234  *     Function: rgSCHCmnGetCqiDciFrmt2AggrLvl
2235  *     Purpose:  This function determines the Aggregation level
2236  *               for each CQI level against each DCI format.
2237  *     Invoked by: rgSCHCmnRgrCellCfg
2238  *
2239  *  @return  Void
2240  *
2241  **/
2242 #ifdef ANSI
2243 PRIVATE Void rgSCHCmnGetCqiDciFrmt2AggrLvl
2244 (
2245 RgSchCellCb *cell
2246 )
2247 #else
2248 PRIVATE Void rgSCHCmnGetCqiDciFrmt2AggrLvl(cell)
2249 RgSchCellCb *cell;
2250 #endif
2251 {
2252    RgSchCmnCell  *cellSch = RG_SCH_CMN_GET_CELL(cell);
2253    U8            i;
2254    U8            j;
2255
2256
2257    for (i = 0; i < RG_SCH_CMN_MAX_CQI; i++)
2258    {
2259       for (j = 0; j < 10; j++)
2260       {
2261          U32 pdcchBits; /* Actual number of phy bits needed for a given DCI Format
2262                * for a given CQI Level */
2263          pdcchBits = (rgSchCmnDciFrmtSizes[j] * 1024)/rgSchCmnCqiPdcchEff[i];
2264                         /* V5G_211 : 6.6 */
2265          if (pdcchBits < 192)
2266          {
2267              cellSch->dciAggrLvl[i][j] = CM_LTE_AGGR_LVL2;
2268              continue;
2269          }
2270          if (pdcchBits < 384)
2271          {
2272              cellSch->dciAggrLvl[i][j] = CM_LTE_AGGR_LVL4;
2273              continue;
2274          }
2275          if (pdcchBits < 768)
2276          {
2277              cellSch->dciAggrLvl[i][j] = CM_LTE_AGGR_LVL8;
2278              continue;
2279          }
2280          cellSch->dciAggrLvl[i][j] = CM_LTE_AGGR_LVL16;
2281       }
2282    }
2283    RETVOID;
2284 }
2285 \f
2286 /**
2287  * @brief This function initializes all the data for the scheduler.
2288  *
2289  * @details
2290  *
2291  *     Function: rgSCHCmnDlInit
2292  *     Purpose:  This function initializes the following information:
2293  *               1. Efficiency table
2294  *               2. CQI to table index - It is one row for upto 3 RBs
2295  *                  and another row for greater than 3 RBs
2296  *                  currently extended prefix is compiled out.
2297  *     Invoked by: MAC intialization code..may be ActvInit
2298  *
2299  *  @return  Void
2300  *
2301  **/
2302 #ifdef ANSI
2303 PRIVATE Void rgSCHCmnDlInit
2304 (
2305 )
2306 #else
2307 PRIVATE Void rgSCHCmnDlInit()
2308 #endif
2309 {
2310    U8                   i;
2311    S16                  j;
2312    S16                  k;
2313    U8                   idx;
2314    RgSchCmnTbSzEff      *effTbl;
2315    RgSchCmnCqiToTbs     *tbsTbl;
2316
2317
2318    /* 0 corresponds to Single layer case, 1 corresponds to 2 layers case*/
2319    /* Init Efficiency table for normal cyclic prefix */
2320    /*Initialize Efficiency table for Layer Index 0 */
2321    /*Initialize Efficiency table for Tx Antenna Port Index 0 */
2322    /*Initialize Efficiency table for each of the CFI indices. The
2323     * 4th Dimension of the rgSCHCmnEffTbl table refers to the CFI Index*/
2324    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][0][0] = &rgSchCmnNorCfi1Eff[0];
2325    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][0][1] = &rgSchCmnNorCfi2Eff[0];
2326    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][0][2] = &rgSchCmnNorCfi3Eff[0];
2327    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][0][3] = &rgSchCmnNorCfi4Eff[0];
2328    /*Initialize Efficency table for Tx Antenna Port Index 1 */
2329    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][1][0] = &rgSchCmnNorCfi1Eff[0];
2330    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][1][1] = &rgSchCmnNorCfi2Eff[0];
2331    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][1][2] = &rgSchCmnNorCfi3Eff[0];
2332    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][1][3] = &rgSchCmnNorCfi4Eff[0];
2333    /*Initialize Efficency table for Tx Antenna Port Index 2 */
2334    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][2][0] = &rgSchCmnNorCfi1Eff[0];
2335    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][2][1] = &rgSchCmnNorCfi2Eff[0];
2336    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][2][2] = &rgSchCmnNorCfi3Eff[0];
2337    rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][2][3] = &rgSchCmnNorCfi4Eff[0];
2338
2339    /*Initialize CQI to TBS table for Layer Index 0 for Normal CP */
2340    rgSchCmnCqiToTbs[0][RG_SCH_CMN_NOR_CP][0] = &rgSchCmnNorCfi1CqiToTbs[0];
2341    rgSchCmnCqiToTbs[0][RG_SCH_CMN_NOR_CP][1] = &rgSchCmnNorCfi2CqiToTbs[0];
2342    rgSchCmnCqiToTbs[0][RG_SCH_CMN_NOR_CP][2] = &rgSchCmnNorCfi3CqiToTbs[0];
2343    rgSchCmnCqiToTbs[0][RG_SCH_CMN_NOR_CP][3] = &rgSchCmnNorCfi4CqiToTbs[0];
2344
2345    /*Intialize Efficency table for Layer Index 1 */
2346    /*Initialize Efficiency table for Tx Antenna Port Index 0 */
2347    /*Initialize Efficiency table for each of the CFI indices. The
2348     * 4th Dimension of the rgSCHCmnEffTbl table refers to the CFI Index*/
2349    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][0][0] = &rgSchCmnNorCfi1Eff[1];
2350    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][0][1] = &rgSchCmnNorCfi2Eff[1];
2351    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][0][2] = &rgSchCmnNorCfi3Eff[1];
2352    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][0][3] = &rgSchCmnNorCfi4Eff[1];
2353    /*Initialize Efficiency table for Tx Antenna Port Index 1 */
2354    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][1][0] = &rgSchCmnNorCfi1Eff[1];
2355    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][1][1] = &rgSchCmnNorCfi2Eff[1];
2356    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][1][2] = &rgSchCmnNorCfi3Eff[1];
2357    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][1][3] = &rgSchCmnNorCfi4Eff[1];
2358    /*Initialize Efficiency table for Tx Antenna Port Index 2 */
2359    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][2][0] = &rgSchCmnNorCfi1Eff[1];
2360    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][2][1] = &rgSchCmnNorCfi2Eff[1];
2361    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][2][2] = &rgSchCmnNorCfi3Eff[1];
2362    rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][2][3] = &rgSchCmnNorCfi4Eff[1];
2363
2364    /*Initialize CQI to TBS table for Layer Index 1 for Normal CP */
2365    rgSchCmnCqiToTbs[1][RG_SCH_CMN_NOR_CP][0] = &rgSchCmnNorCfi1CqiToTbs[1];
2366    rgSchCmnCqiToTbs[1][RG_SCH_CMN_NOR_CP][1] = &rgSchCmnNorCfi2CqiToTbs[1];
2367    rgSchCmnCqiToTbs[1][RG_SCH_CMN_NOR_CP][2] = &rgSchCmnNorCfi3CqiToTbs[1];
2368    rgSchCmnCqiToTbs[1][RG_SCH_CMN_NOR_CP][3] = &rgSchCmnNorCfi4CqiToTbs[1];
2369
2370    for (idx = 0; idx < RG_SCH_CMN_MAX_ANT_CONF; idx++)
2371    {
2372       for (i = 0; i < RG_SCH_CMN_MAX_CFI; i++)
2373       {
2374          /* EfficiencyTbl calculation incase of 2 layers for normal CP  */
2375          rgSCHCmnCompEff((U8)(i + 1), RG_SCH_CMN_NOR_CP, idx,\
2376                rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][idx][i]);
2377          rgSCHCmn2LyrCompEff((U8)(i + 1), RG_SCH_CMN_NOR_CP, idx, \
2378                rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][idx][i]);
2379       }
2380    }
2381
2382    for (idx = 0; idx < RG_SCH_CMN_MAX_ANT_CONF; idx++)
2383    {
2384       for (i = 0; i < RG_SCH_CMN_MAX_CFI; i++)
2385       {
2386          effTbl = rgSchCmnEffTbl[0][RG_SCH_CMN_NOR_CP][idx][i];
2387          tbsTbl = rgSchCmnCqiToTbs[0][RG_SCH_CMN_NOR_CP][i];
2388          for (j = RG_SCH_CMN_NUM_TBS - 1, k = RG_SCH_CMN_MAX_CQI - 1;
2389                (j >= 0) && (k > 0); --j)
2390          {
2391             /* ADD CQI to MCS mapping correction
2392             * single dimensional array is replaced by 2 dimensions for different CFI*/
2393             if ((*effTbl)[j] <= rgSchCmnCqiPdschEff[i][k])
2394             {
2395                (*tbsTbl)[k--] = (U8)j;
2396             }
2397          }
2398          for (; k > 0; --k)
2399          {
2400             (*tbsTbl)[k] = 0;
2401          }
2402          /* effTbl,tbsTbl calculation incase of 2 layers for normal CP */
2403          effTbl = rgSchCmnEffTbl[1][RG_SCH_CMN_NOR_CP][idx][i];
2404          tbsTbl = rgSchCmnCqiToTbs[1][RG_SCH_CMN_NOR_CP][i];
2405          for (j = RG_SCH_CMN_NUM_TBS - 1, k = RG_SCH_CMN_MAX_CQI - 1;
2406                (j >= 0) && (k > 0); --j)
2407          {
2408             /* ADD CQI to MCS mapping correction
2409             * single dimensional array is replaced by 2 dimensions for different CFI*/
2410             if ((*effTbl)[j] <= rgSchCmn2LyrCqiPdschEff[i][k])
2411             {
2412                (*tbsTbl)[k--] = (U8)j;
2413             }
2414          }
2415          for (; k > 0; --k)
2416          {
2417             (*tbsTbl)[k] = 0;
2418          }
2419       }
2420    }
2421
2422    /* Efficiency Table for Extended CP */
2423    /*Initialize Efficiency table for Layer Index 0 */
2424    /*Initialize Efficiency table for Tx Antenna Port Index 0 */
2425    /*Initialize Efficiency table for each of the CFI indices. The
2426     * 4th Dimension of the rgSCHCmnEffTbl table refers to the CFI Index*/
2427    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][0][0] = &rgSchCmnExtCfi1Eff[0];
2428    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][0][1] = &rgSchCmnExtCfi2Eff[0];
2429    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][0][2] = &rgSchCmnExtCfi3Eff[0];
2430    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][0][3] = &rgSchCmnExtCfi4Eff[0];
2431    /*Initialize Efficency table for Tx Antenna Port Index 1 */
2432    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][1][0] = &rgSchCmnExtCfi1Eff[0];
2433    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][1][1] = &rgSchCmnExtCfi2Eff[0];
2434    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][1][2] = &rgSchCmnExtCfi3Eff[0];
2435    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][1][3] = &rgSchCmnExtCfi4Eff[0];
2436    /*Initialize Efficency table for Tx Antenna Port Index 2 */
2437    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][2][0] = &rgSchCmnExtCfi1Eff[0];
2438    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][2][1] = &rgSchCmnExtCfi2Eff[0];
2439    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][2][2] = &rgSchCmnExtCfi3Eff[0];
2440    rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][2][3] = &rgSchCmnExtCfi4Eff[0];
2441
2442    /*Initialize CQI to TBS table for Layer Index 0 for Extended CP */
2443    rgSchCmnCqiToTbs[0][RG_SCH_CMN_EXT_CP][0] = &rgSchCmnExtCfi1CqiToTbs[0];
2444    rgSchCmnCqiToTbs[0][RG_SCH_CMN_EXT_CP][1] = &rgSchCmnExtCfi2CqiToTbs[0];
2445    rgSchCmnCqiToTbs[0][RG_SCH_CMN_EXT_CP][2] = &rgSchCmnExtCfi3CqiToTbs[0];
2446    rgSchCmnCqiToTbs[0][RG_SCH_CMN_EXT_CP][3] = &rgSchCmnExtCfi4CqiToTbs[0];
2447
2448    /*Initialize Efficiency table for Layer Index 1 */
2449    /*Initialize Efficiency table for each of the CFI indices. The
2450     * 4th Dimension of the rgSCHCmnEffTbl table refers to the CFI Index*/
2451    /*Initialize Efficency table for Tx Antenna Port Index 0 */
2452    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][0][0] = &rgSchCmnExtCfi1Eff[1];
2453    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][0][1] = &rgSchCmnExtCfi2Eff[1];
2454    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][0][2] = &rgSchCmnExtCfi3Eff[1];
2455    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][0][3] = &rgSchCmnExtCfi4Eff[1];
2456    /*Initialize Efficency table for Tx Antenna Port Index 1 */
2457    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][1][0] = &rgSchCmnExtCfi1Eff[1];
2458    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][1][1] = &rgSchCmnExtCfi2Eff[1];
2459    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][1][2] = &rgSchCmnExtCfi3Eff[1];
2460    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][1][3] = &rgSchCmnExtCfi4Eff[1];
2461    /*Initialize Efficency table for Tx Antenna Port Index 2 */
2462    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][2][0] = &rgSchCmnExtCfi1Eff[1];
2463    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][2][1] = &rgSchCmnExtCfi2Eff[1];
2464    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][2][2] = &rgSchCmnExtCfi3Eff[1];
2465    rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][2][3] = &rgSchCmnExtCfi4Eff[1];
2466
2467    /*Initialize CQI to TBS table for Layer Index 1 for Extended CP */
2468    rgSchCmnCqiToTbs[1][RG_SCH_CMN_EXT_CP][0] = &rgSchCmnExtCfi1CqiToTbs[1];
2469    rgSchCmnCqiToTbs[1][RG_SCH_CMN_EXT_CP][1] = &rgSchCmnExtCfi2CqiToTbs[1];
2470    rgSchCmnCqiToTbs[1][RG_SCH_CMN_EXT_CP][2] = &rgSchCmnExtCfi3CqiToTbs[1];
2471    rgSchCmnCqiToTbs[1][RG_SCH_CMN_EXT_CP][3] = &rgSchCmnExtCfi4CqiToTbs[1];
2472    /* Activate this code when extended cp is supported */
2473    for (idx = 0; idx < RG_SCH_CMN_MAX_ANT_CONF; idx++)
2474    {
2475       for (i = 0; i < RG_SCH_CMN_MAX_CFI; i++)
2476       {
2477          /* EfficiencyTbl calculation incase of 2 layers for extendedl CP  */
2478          rgSCHCmnCompEff( (U8)(i + 1 ), (U8)RG_SCH_CMN_EXT_CP, idx,\
2479                rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][idx][i]);
2480          rgSCHCmn2LyrCompEff((U8)(i + 1), (U8) RG_SCH_CMN_EXT_CP,idx, \
2481                rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][idx][i]);
2482       }
2483    }
2484
2485    for (idx = 0; idx < RG_SCH_CMN_MAX_ANT_CONF; idx++)
2486    {
2487       for (i = 0; i < RG_SCH_CMN_MAX_CFI; i++)
2488       {
2489          effTbl = rgSchCmnEffTbl[0][RG_SCH_CMN_EXT_CP][idx][i];
2490          tbsTbl = rgSchCmnCqiToTbs[0][RG_SCH_CMN_EXT_CP][i];
2491          for (j = RG_SCH_CMN_NUM_TBS - 1, k = RG_SCH_CMN_MAX_CQI - 1;
2492                (j >= 0) && (k > 0); --j)
2493          {
2494             /* ADD CQI to MCS mapping correction
2495             * single dimensional array is replaced by 2 dimensions for different CFI*/
2496             if ((*effTbl)[j] <= rgSchCmnCqiPdschEff[i][k])
2497             {
2498                (*tbsTbl)[k--] = (U8)j;
2499             }
2500          }
2501          for (; k > 0; --k)
2502          {
2503             (*tbsTbl)[k] = 0;
2504          }
2505          /* effTbl,tbsTbl calculation incase of 2 layers for extended CP */
2506          effTbl = rgSchCmnEffTbl[1][RG_SCH_CMN_EXT_CP][idx][i];
2507          tbsTbl = rgSchCmnCqiToTbs[1][RG_SCH_CMN_EXT_CP][i];
2508          for (j = RG_SCH_CMN_NUM_TBS - 1, k = RG_SCH_CMN_MAX_CQI - 1;
2509                (j >= 0) && (k > 0); --j)
2510          {
2511            /* ADD CQI to MCS mapping correction
2512             * single dimensional array is replaced by 2 dimensions for different CFI*/
2513             if ((*effTbl)[j] <= rgSchCmn2LyrCqiPdschEff[i][k])
2514             {
2515                (*tbsTbl)[k--] = (U8)j;
2516             }
2517          }
2518          for (; k > 0; --k)
2519          {
2520             (*tbsTbl)[k] = 0;
2521          }
2522       }
2523    }
2524    RETVOID;
2525 }
2526 \f
2527 /**
2528  * @brief This function initializes all the data for the scheduler.
2529  *
2530  * @details
2531  *
2532  *     Function: rgSCHCmnUlInit
2533  *     Purpose:  This function initializes the following information:
2534  *               1. Efficiency table
2535  *               2. CQI to table index - It is one row for upto 3 RBs
2536  *                  and another row for greater than 3 RBs
2537  *                  currently extended prefix is compiled out.
2538  *     Invoked by: MAC intialization code..may be ActvInit
2539  *
2540  *  @return  Void
2541  *
2542  **/
2543 #ifdef ANSI
2544 PRIVATE Void rgSCHCmnUlInit
2545 (
2546 )
2547 #else
2548 PRIVATE Void rgSCHCmnUlInit()
2549 #endif
2550 {
2551    U8              *mapTbl = &rgSchCmnUlCqiToTbsTbl[RG_SCH_CMN_NOR_CP][0];
2552    RgSchCmnTbSzEff    *effTbl    = &rgSchCmnNorUlEff[0];
2553    CONSTANT RgSchCmnUlCqiInfo *cqiTbl = &rgSchCmnUlCqiTbl[0];
2554    S16              i;
2555    S16              j;
2556
2557    /* Initaializing new variable added for UL eff */
2558    rgSchCmnUlEffTbl[RG_SCH_CMN_NOR_CP] = &rgSchCmnNorUlEff[0];
2559    /* Reason behind using 3 as the number of symbols to rule out for
2560     * efficiency table computation would be that we are using 2 symbols for
2561     * DMRS(1 in each slot) and 1 symbol for SRS*/
2562    rgSCHCmnCompUlEff(RGSCH_UL_SYM_DMRS_SRS,RG_SCH_CMN_NOR_CP,rgSchCmnUlEffTbl[RG_SCH_CMN_NOR_CP]);
2563
2564    for (i = RGSCH_NUM_ITBS - 1, j = RG_SCH_CMN_UL_NUM_CQI - 1;
2565          i >= 0 && j > 0; --i)
2566    {
2567       if ((*effTbl)[i] <= cqiTbl[j].eff)
2568       {
2569          mapTbl[j--] = (U8)i;
2570       }
2571    }
2572    for (; j > 0; --j)
2573    {
2574       mapTbl[j] = 0;
2575    }
2576    effTbl    = &rgSchCmnExtUlEff[0];
2577    mapTbl    = &rgSchCmnUlCqiToTbsTbl[RG_SCH_CMN_EXT_CP][0];
2578
2579    /* Initaializing new variable added for UL eff */
2580    rgSchCmnUlEffTbl[RG_SCH_CMN_EXT_CP] = &rgSchCmnExtUlEff[0];
2581    /* Reason behind using 3 as the number of symbols to rule out for
2582     * efficiency table computation would be that we are using 2 symbols for
2583     * DMRS(1 in each slot) and 1 symbol for SRS*/
2584    rgSCHCmnCompUlEff(3,RG_SCH_CMN_EXT_CP,rgSchCmnUlEffTbl[RG_SCH_CMN_EXT_CP]);
2585
2586    for (i = RGSCH_NUM_ITBS - 1, j = RG_SCH_CMN_UL_NUM_CQI - 1;
2587          i >= 0 && j > 0; --i)
2588    {
2589       if ((*effTbl)[i] <= cqiTbl[j].eff)
2590       {
2591          mapTbl[j--] = (U8)i;
2592       }
2593    }
2594    for (; j > 0; --j)
2595    {
2596       mapTbl[j] = 0;
2597    }
2598    rgSCHPwrInit();
2599    RETVOID;
2600 }
2601
2602 /**
2603  * @brief This function initializes all the data for the scheduler.
2604  *
2605  * @details
2606  *
2607  *     Function: rgSCHCmnInit
2608  *     Purpose:  This function initializes the following information:
2609  *               1. Efficiency table
2610  *               2. CQI to table index - It is one row for upto 3 RBs
2611  *                  and another row for greater than 3 RBs
2612  *                  currently extended prefix is compiled out.
2613  *     Invoked by: MAC intialization code..may be ActvInit
2614  *
2615  *  @return  Void
2616  *
2617  **/
2618 #ifdef ANSI
2619 Void rgSCHCmnInit
2620 (
2621 )
2622 #else
2623 Void rgSCHCmnInit()
2624 #endif
2625 {
2626    U8   idx;
2627
2628    rgSCHCmnDlInit();
2629    rgSCHCmnUlInit();
2630 #ifdef EMTC_ENABLE
2631    rgSCHEmtcCmnDlInit();
2632    rgSCHEmtcCmnUlInit();
2633 #endif      
2634 #ifdef LTEMAC_SPS
2635    rgSCHCmnSpsInit();
2636 #endif
2637
2638    /* Init the function pointers */
2639    rgSchCmnApis.rgSCHRgrUeCfg         = rgSCHCmnRgrUeCfg;
2640    rgSchCmnApis.rgSCHRgrUeRecfg       = rgSCHCmnRgrUeRecfg;
2641    rgSchCmnApis.rgSCHFreeUe           = rgSCHCmnUeDel;
2642    rgSchCmnApis.rgSCHRgrCellCfg       = rgSCHCmnRgrCellCfg;
2643    rgSchCmnApis.rgSCHRgrCellRecfg     = rgSCHCmnRgrCellRecfg;
2644    rgSchCmnApis.rgSCHFreeCell         = rgSCHCmnCellDel;
2645    rgSchCmnApis.rgSCHRgrLchCfg        = rgSCHCmnRgrLchCfg;
2646    rgSchCmnApis.rgSCHRgrLcgCfg        = rgSCHCmnRgrLcgCfg;
2647    rgSchCmnApis.rgSCHRgrLchRecfg      = rgSCHCmnRgrLchRecfg;
2648    rgSchCmnApis.rgSCHRgrLcgRecfg      = rgSCHCmnRgrLcgRecfg;
2649    rgSchCmnApis.rgSCHFreeDlLc         = rgSCHCmnFreeDlLc;
2650    rgSchCmnApis.rgSCHFreeLcg          = rgSCHCmnLcgDel;
2651    rgSchCmnApis.rgSCHRgrLchDel        = rgSCHCmnRgrLchDel;
2652    rgSchCmnApis.rgSCHActvtUlUe        = rgSCHCmnActvtUlUe;
2653    rgSchCmnApis.rgSCHActvtDlUe        = rgSCHCmnActvtDlUe;
2654    rgSchCmnApis.rgSCHHdlUlTransInd    = rgSCHCmnHdlUlTransInd;
2655    rgSchCmnApis.rgSCHDlDedBoUpd       = rgSCHCmnDlDedBoUpd;
2656    rgSchCmnApis.rgSCHUlRecMsg3Alloc   = rgSCHCmnUlRecMsg3Alloc;
2657    rgSchCmnApis.rgSCHUlCqiInd         = rgSCHCmnUlCqiInd;
2658    rgSchCmnApis.rgSCHPucchDeltaPwrInd = rgSCHPwrPucchDeltaInd;
2659    rgSchCmnApis.rgSCHUlHqProcForUe    = rgSCHCmnUlHqProcForUe;
2660 #ifdef RG_UNUSED
2661    rgSchCmnApis.rgSCHUpdUlHqProc      = rgSCHCmnUpdUlHqProc;
2662 #endif
2663    rgSchCmnApis.rgSCHUpdBsrShort      = rgSCHCmnUpdBsrShort;
2664    rgSchCmnApis.rgSCHUpdBsrTrunc      = rgSCHCmnUpdBsrTrunc;
2665    rgSchCmnApis.rgSCHUpdBsrLong       = rgSCHCmnUpdBsrLong;
2666    rgSchCmnApis.rgSCHUpdPhr           = rgSCHCmnUpdPhr;
2667    rgSchCmnApis.rgSCHUpdExtPhr        = rgSCHCmnUpdExtPhr;
2668    rgSchCmnApis.rgSCHContResUlGrant   = rgSCHCmnContResUlGrant;
2669    rgSchCmnApis.rgSCHSrRcvd           = rgSCHCmnSrRcvd;
2670    rgSchCmnApis.rgSCHFirstRcptnReq    = rgSCHCmnFirstRcptnReq;
2671    rgSchCmnApis.rgSCHNextRcptnReq     = rgSCHCmnNextRcptnReq;
2672    rgSchCmnApis.rgSCHFirstHqFdbkAlloc = rgSCHCmnFirstHqFdbkAlloc;
2673    rgSchCmnApis.rgSCHNextHqFdbkAlloc  = rgSCHCmnNextHqFdbkAlloc;
2674    rgSchCmnApis.rgSCHDlProcAddToRetx  = rgSCHCmnDlProcAddToRetx;
2675    rgSchCmnApis.rgSCHDlCqiInd         = rgSCHCmnDlCqiInd;
2676 #ifdef EMTC_ENABLE
2677    rgSchCmnApis.rgSCHUlProcAddToRetx  = rgSCHCmnEmtcUlProcAddToRetx;
2678 #endif
2679 #ifdef TFU_UPGRADE
2680    rgSchCmnApis.rgSCHSrsInd           = rgSCHCmnSrsInd;
2681 #endif
2682    rgSchCmnApis.rgSCHDlTARpt          = rgSCHCmnDlTARpt;
2683    rgSchCmnApis.rgSCHDlRlsSubFrm      = rgSCHCmnDlRlsSubFrm;
2684    rgSchCmnApis.rgSCHUeReset          = rgSCHCmnUeReset;
2685 #ifdef LTEMAC_SPS
2686    rgSchCmnApis.rgSCHHdlCrntiCE         = rgSCHCmnHdlCrntiCE;
2687    rgSchCmnApis.rgSCHDlProcAck        = rgSCHCmnDlProcAck;
2688    rgSchCmnApis.rgSCHDlRelPdcchFbk    = rgSCHCmnDlRelPdcchFbk;
2689    rgSchCmnApis.rgSCHUlSpsRelInd      = rgSCHCmnUlSpsRelInd;
2690    rgSchCmnApis.rgSCHUlSpsActInd      = rgSCHCmnUlSpsActInd;
2691    rgSchCmnApis.rgSCHUlCrcFailInd     = rgSCHCmnUlCrcFailInd;
2692    rgSchCmnApis.rgSCHUlCrcInd     = rgSCHCmnUlCrcInd;
2693 #endif
2694    rgSchCmnApis.rgSCHDrxStrtInActvTmrInUl = rgSCHCmnDrxStrtInActvTmrInUl;
2695    rgSchCmnApis.rgSCHUpdUeDataIndLcg      = rgSCHCmnUpdUeDataIndLcg;
2696
2697    for (idx = 0; idx < RGSCH_NUM_SCHEDULERS; ++idx)
2698    {
2699       rgSchUlSchdInits[idx](&rgSchUlSchdTbl[idx]);
2700       rgSchDlSchdInits[idx](&rgSchDlSchdTbl[idx]);
2701    }
2702 #ifdef EMTC_ENABLE 
2703    for (idx = 0; idx < RGSCH_NUM_EMTC_SCHEDULERS; ++idx)
2704    {
2705       rgSchEmtcUlSchdInits[idx](&rgSchEmtcUlSchdTbl[idx]);
2706       rgSchEmtcDlSchdInits[idx](&rgSchEmtcDlSchdTbl[idx]);
2707    }
2708 #endif
2709 #if (defined (RG_PHASE2_SCHED) && defined(TFU_UPGRADE))
2710    for (idx = 0; idx < RGSCH_NUM_DLFS_SCHEDULERS; ++idx)
2711    {
2712       rgSchDlfsSchdInits[idx](&rgSchDlfsSchdTbl[idx]);
2713    }
2714 #endif
2715 #ifdef LTE_ADV
2716    rgSchCmnApis.rgSCHRgrSCellUeCfg         = rgSCHCmnRgrSCellUeCfg;
2717    rgSchCmnApis.rgSCHRgrSCellUeDel         = rgSCHCmnRgrSCellUeDel;
2718 #endif
2719    RETVOID;
2720 }
2721
2722 \f
2723 /**
2724  * @brief This function is a wrapper to call scheduler specific API.
2725  *
2726  * @details
2727  *
2728  *     Function: rgSCHCmnDlRlsSubFrm
2729  *     Purpose:  Releases scheduler Information from DL SubFrm.
2730  *
2731  *     Invoked by: DHM
2732  *
2733  *  @param[in]   RgSchCellCb     *cell
2734  *  @param[out]  CmLteTimingInfo frm
2735  *  @return  Void
2736  *
2737  **/
2738 #ifdef ANSI
2739 Void rgSCHCmnDlRlsSubFrm
2740 (
2741 RgSchCellCb        *cell,
2742 CmLteTimingInfo   frm
2743 )
2744 #else
2745 Void rgSCHCmnDlRlsSubFrm(cell, frm)
2746 RgSchCellCb        *cell;
2747 CmLteTimingInfo    frm;
2748 #endif
2749 {
2750    RgSchCmnCell        *cellSch = RG_SCH_CMN_GET_CELL(cell);
2751    RgSchDlSf           *sf;
2752
2753
2754    /* Get the pointer to the subframe */
2755    sf = rgSCHUtlSubFrmGet(cell, frm);
2756
2757    rgSCHUtlSubFrmPut(cell, sf);
2758    if (sf->dlfsSf)
2759    {
2760       /* Re-initialize DLFS specific information for the sub-frame */
2761       cellSch->apisDlfs->rgSCHDlfsReinitSf(cell, sf);
2762    }
2763    RETVOID;
2764 }
2765
2766
2767 \f
2768 /**
2769  * @brief This function is the starting function for DL allocation.
2770  *
2771  * @details
2772  *
2773  *     Function: rgSCHCmnDlCmnChAlloc
2774  *     Purpose:  Scheduling for downlink. It performs allocation in the order
2775  *               of priority wich BCCH/PCH first, CCCH, Random Access and TA.
2776  *
2777  *     Invoked by: Scheduler
2778  *
2779  *  @param[in]  RgSchCellCb*           cell
2780  *  @param[out] RgSchCmnDlRbAllocInfo* allocInfo
2781  *  @return  Void
2782  *
2783  **/
2784 #ifdef ANSI
2785 PRIVATE Void rgSCHCmnDlCcchRarAlloc
2786 (
2787 RgSchCellCb             *cell
2788 )
2789 #else
2790 PRIVATE Void rgSCHCmnDlCcchRarAlloc(cell)
2791 RgSchCellCb             *cell;
2792 #endif
2793 {
2794    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
2795
2796
2797    rgSCHCmnDlCcchRetx(cell, &cellSch->allocInfo);
2798    /* LTE_ADV_FLAG_REMOVED_START */
2799    if(RG_SCH_ABS_ENABLED_ABS_SF == cell->lteAdvCb.absDlSfInfo)
2800    {
2801       if(cell->lteAdvCb.absCfg.absPatternType & RGR_ABS_MUTE)
2802       {
2803          /*eNodeB need to blank the subframe */
2804       }
2805       else
2806       {
2807          rgSCHCmnDlCcchTx(cell, &cellSch->allocInfo);
2808       }
2809    }
2810    else
2811    {
2812       rgSCHCmnDlCcchTx(cell, &cellSch->allocInfo);
2813    }
2814    /* LTE_ADV_FLAG_REMOVED_END */
2815
2816 #ifdef RGR_V1
2817
2818    /*Added these function calls for processing CCCH SDU arriving
2819     * after guard timer expiry.Functions differ from above two functions
2820     * in using ueCb instead of raCb.*/
2821    rgSCHCmnDlCcchSduRetx(cell, &cellSch->allocInfo);
2822    /* LTE_ADV_FLAG_REMOVED_START */
2823    if(RG_SCH_ABS_ENABLED_ABS_SF == cell->lteAdvCb.absDlSfInfo)
2824    {
2825       if(cell->lteAdvCb.absCfg.absPatternType & RGR_ABS_MUTE)
2826       {
2827          /*eNodeB need to blank the subframe */
2828       }
2829       else
2830       {
2831          rgSCHCmnDlCcchSduTx(cell, &cellSch->allocInfo);
2832       }
2833    }
2834    else
2835    {
2836       rgSCHCmnDlCcchSduTx(cell, &cellSch->allocInfo);
2837    }
2838    /* LTE_ADV_FLAG_REMOVED_END */
2839 #endif
2840
2841 #ifdef LTE_TDD
2842    if(cellSch->ul.msg3SchdIdx != RGSCH_INVALID_INFO)
2843    {
2844       /* Do not schedule msg3 if there is a CFI change ongoing */
2845       if (cellSch->dl.currCfi == cellSch->dl.newCfi)
2846       {
2847          rgSCHCmnDlRaRsp(cell, &cellSch->allocInfo);
2848       }
2849    }
2850 #else
2851    /* LTE_ADV_FLAG_REMOVED_START */
2852    if(RG_SCH_ABS_ENABLED_ABS_SF == cell->lteAdvCb.absDlSfInfo)
2853    {
2854       if(cell->lteAdvCb.absCfg.absPatternType & RGR_ABS_MUTE)
2855       {
2856          /*eNodeB need to blank the subframe */
2857       }
2858       else
2859       {
2860          /* Do not schedule msg3 if there is a CFI change ongoing */
2861          if (cellSch->dl.currCfi == cellSch->dl.newCfi)
2862          {
2863             rgSCHCmnDlRaRsp(cell, &cellSch->allocInfo);
2864          }
2865       }
2866    }
2867    else
2868    {
2869       /* Do not schedule msg3 if there is a CFI change ongoing */
2870       if (cellSch->dl.currCfi == cellSch->dl.newCfi)
2871       {
2872          rgSCHCmnDlRaRsp(cell, &cellSch->allocInfo);
2873       }
2874    }
2875    /* LTE_ADV_FLAG_REMOVED_END */
2876 #endif
2877
2878    RETVOID;
2879 }
2880
2881 #ifdef RGR_V1
2882 /**
2883  * @brief Scheduling for CCCH SDU.
2884  *
2885  * @details
2886  *
2887  *     Function: rgSCHCmnCcchSduAlloc
2888  *     Purpose:  Scheduling for CCCH SDU
2889  *
2890  *     Invoked by: Scheduler
2891  *
2892  *  @param[in]  RgSchCellCb*          cell
2893  *  @param[in]  RgSchUeCb*            ueCb
2894  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
2895  *  @return  S16
2896  *
2897  **/
2898 #ifdef ANSI
2899 PRIVATE S16 rgSCHCmnCcchSduAlloc
2900 (
2901 RgSchCellCb                *cell,
2902 RgSchUeCb                  *ueCb,
2903 RgSchCmnDlRbAllocInfo      *allocInfo
2904 )
2905 #else
2906 PRIVATE S16 rgSCHCmnCcchSduAlloc(cell, ueCb, allocInfo)
2907 RgSchCellCb                *cell;
2908 RgSchUeCb                  *ueCb;
2909 RgSchCmnDlRbAllocInfo      *allocInfo;
2910 #endif
2911 {
2912    RgSchDlRbAlloc  *rbAllocInfo;
2913    RgSchCmnCell       *cellSch = RG_SCH_CMN_GET_CELL(cell);
2914    RgSchCmnDlUe       *ueDl = RG_SCH_CMN_GET_DL_UE(ueCb,cell);
2915
2916
2917    /* Return if subframe BW exhausted */
2918    if (allocInfo->ccchSduAlloc.ccchSduDlSf->bw <=
2919        allocInfo->ccchSduAlloc.ccchSduDlSf->bwAssigned)
2920    {
2921       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
2922          "bw<=bwAssigned for UEID:%d",ueCb->ueId);
2923       return RFAILED;
2924    }
2925
2926    if (rgSCHDhmGetCcchSduHqProc(ueCb, cellSch->dl.time, &(ueDl->proc)) != ROK)
2927    {
2928       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
2929          "rgSCHDhmGetCcchSduHqProc failed UEID:%d",ueCb->ueId);
2930       return RFAILED;
2931    }
2932
2933    rbAllocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ueCb, cell);
2934    rbAllocInfo->dlSf = allocInfo->ccchSduAlloc.ccchSduDlSf;
2935
2936    if (rgSCHCmnCcchSduDedAlloc(cell, ueCb) != ROK)
2937    {
2938       /* Fix : syed Minor failure handling, release hqP if Unsuccessful */    
2939       rgSCHDhmRlsHqpTb(ueDl->proc, 0, FALSE);
2940       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
2941          "rgSCHCmnCcchSduDedAlloc failed UEID:%d",ueCb->ueId);
2942       return RFAILED;
2943    }
2944    cmLListAdd2Tail(&allocInfo->ccchSduAlloc.ccchSduTxLst, &ueDl->proc->reqLnk);
2945    ueDl->proc->reqLnk.node = (PTR)ueDl->proc;
2946    allocInfo->ccchSduAlloc.ccchSduDlSf->schdCcchUe++;
2947
2948    return ROK;
2949 }
2950 /**
2951  * @brief This function scheduler for downlink CCCH messages.
2952  *
2953  * @details
2954  *
2955  *     Function: rgSCHCmnDlCcchSduTx
2956  *     Purpose:  Scheduling for downlink CCCH
2957  *
2958  *     Invoked by: Scheduler
2959  *
2960  *  @param[in]  RgSchCellCb           *cell
2961  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
2962  *  @return  Void
2963  *
2964  **/
2965 #ifdef ANSI
2966 PRIVATE Void rgSCHCmnDlCcchSduTx
2967 (
2968 RgSchCellCb             *cell,
2969 RgSchCmnDlRbAllocInfo   *allocInfo
2970 )
2971 #else
2972 PRIVATE Void rgSCHCmnDlCcchSduTx(cell, allocInfo)
2973 RgSchCellCb             *cell;
2974 RgSchCmnDlRbAllocInfo   *allocInfo;
2975 #endif
2976 {
2977    CmLList           *node;
2978    RgSchUeCb         *ueCb;
2979    RgSchCmnDlUe      *ueCmnDl;
2980    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
2981
2982    RgSchDlSf         *dlSf = allocInfo->ccchSduAlloc.ccchSduDlSf;
2983    
2984
2985    node = cell->ccchSduUeLst.first;
2986    while(node)
2987    {
2988       if(cellSch->dl.maxCcchPerDlSf &&
2989             dlSf->schdCcchUe == cellSch->dl.maxCcchPerDlSf)
2990       {
2991          break;
2992       }
2993       else
2994       {
2995          ueCb = (RgSchUeCb *)(node->node);
2996          ueCmnDl  = RG_SCH_CMN_GET_DL_UE(ueCb,cell);
2997          node = node->next;
2998          /* Fix : syed postpone scheduling for this
2999           * until msg4 is done */
3000          /* Fix : syed RLC can erroneously send CCCH SDU BO 
3001           * twice. Hence an extra guard to avoid if already 
3002           * scheduled for RETX */
3003          if ((!(ueCb->dl.dlInactvMask & RG_HQENT_INACTIVE)) &&
3004                (!ueCmnDl->proc))
3005          {
3006             if ((rgSCHCmnCcchSduAlloc(cell, ueCb, allocInfo)) != ROK)
3007             {
3008                break;
3009             }
3010          }
3011          else
3012          {
3013             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"ERROR!! THIS SHOULD "
3014                      "NEVER HAPPEN for UEID:%d", ueCb->ueId);
3015             continue;
3016          }
3017       }
3018    }
3019    RETVOID;
3020 }
3021 #endif
3022 \f
3023 /**
3024  * @brief This function scheduler for downlink CCCH messages.
3025  *
3026  * @details
3027  *
3028  *     Function: rgSCHCmnDlCcchTx
3029  *     Purpose:  Scheduling for downlink CCCH
3030  *
3031  *     Invoked by: Scheduler
3032  *
3033  *  @param[in]  RgSchCellCb           *cell
3034  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
3035  *  @return  Void
3036  *
3037  **/
3038 #ifdef ANSI
3039 PRIVATE Void rgSCHCmnDlCcchTx
3040 (
3041 RgSchCellCb             *cell,
3042 RgSchCmnDlRbAllocInfo   *allocInfo
3043 )
3044 #else
3045 PRIVATE Void rgSCHCmnDlCcchTx(cell, allocInfo)
3046 RgSchCellCb             *cell;
3047 RgSchCmnDlRbAllocInfo   *allocInfo;
3048 #endif
3049 {
3050    CmLList           *node;
3051    RgSchRaCb         *raCb;
3052    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
3053    RgSchDlSf         *dlSf = allocInfo->msg4Alloc.msg4DlSf;
3054    
3055
3056    node = cell->raInfo.toBeSchdLst.first;
3057    while(node)
3058    {
3059       if(cellSch->dl.maxCcchPerDlSf &&
3060             dlSf->schdCcchUe == cellSch->dl.maxCcchPerDlSf)
3061       {
3062          break;
3063       }
3064       else
3065       {
3066
3067          raCb = (RgSchRaCb *)(node->node);
3068          node = node->next;
3069          /* Address allocation for this UE for MSG 4 */
3070          /* Allocation for Msg4 */
3071          if ((rgSCHCmnMsg4Alloc(cell, raCb, allocInfo)) != ROK)
3072          {
3073             break;
3074          }
3075       }
3076    }
3077    RETVOID;
3078 }
3079
3080 #ifdef RGR_V1
3081 /**
3082  * @brief This function scheduler for downlink CCCH messages.
3083  *
3084  * @details
3085  *
3086  *     Function: rgSCHCmnDlCcchSduRetx
3087  *     Purpose:  Scheduling for downlink CCCH
3088  *
3089  *     Invoked by: Scheduler
3090  *
3091  *  @param[in]  RgSchCellCb           *cell
3092  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
3093  *  @return  Void
3094  *
3095  **/
3096 #ifdef ANSI
3097 PRIVATE Void rgSCHCmnDlCcchSduRetx
3098 (
3099 RgSchCellCb             *cell,
3100 RgSchCmnDlRbAllocInfo   *allocInfo
3101 )
3102 #else
3103 PRIVATE Void rgSCHCmnDlCcchSduRetx(cell, allocInfo)
3104 RgSchCellCb             *cell;
3105 RgSchCmnDlRbAllocInfo   *allocInfo;
3106 #endif
3107 {
3108    RgSchDlRbAlloc  *rbAllocInfo;
3109    CmLList           *node;
3110    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
3111    RgSchUeCb         *ueCb;
3112    RgSchDlHqProcCb   *hqP;
3113    U8                retxBw = 0;
3114    RgSchCmnDlUe      *ueDl;
3115    RgSchDlSf         *dlSf = allocInfo->ccchSduAlloc.ccchSduDlSf;
3116    
3117
3118    node = cellSch->dl.ccchSduRetxLst.first;
3119    while(node)
3120    {
3121       if(cellSch->dl.maxCcchPerDlSf &&
3122             dlSf->schdCcchUe == cellSch->dl.maxCcchPerDlSf)
3123       {
3124          break;
3125       }
3126       else
3127       {
3128
3129          hqP = (RgSchDlHqProcCb *)(node->node);
3130          node = node->next;
3131
3132          /* DwPts Scheduling Changes Start */      
3133 #ifdef LTE_TDD
3134          if (rgSCHCmnRetxAvoidTdd(allocInfo->ccchSduAlloc.ccchSduDlSf, 
3135                   cell, hqP) == TRUE)
3136          {
3137             continue;  
3138          }
3139 #endif
3140          /* DwPts Scheduling Changes End */     
3141
3142          if (hqP->tbInfo[0].dlGrnt.numRb > (dlSf->bw - dlSf->bwAssigned))
3143          {
3144             break;
3145          }
3146          ueCb = (RgSchUeCb*)(hqP->hqE->ue);
3147          ueDl = RG_SCH_CMN_GET_DL_UE(ueCb,cell);
3148
3149          rbAllocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ueCb, cell);
3150          /* Fill RB Alloc Info */
3151          rbAllocInfo->dlSf = dlSf;
3152          rbAllocInfo->tbInfo[0].bytesReq =  hqP->tbInfo[0].ccchSchdInfo.totBytes;
3153          rbAllocInfo->rbsReq = hqP->tbInfo[0].dlGrnt.numRb;
3154          /* Fix : syed iMcs setting did not correspond to RETX */
3155          RG_SCH_CMN_GET_MCS_FOR_RETX((&hqP->tbInfo[0]), 
3156                rbAllocInfo->tbInfo[0].imcs);
3157          rbAllocInfo->rnti = ueCb->ueId;
3158          rbAllocInfo->tbInfo[0].noLyr = hqP->tbInfo[0].numLyrs;
3159          /* Fix : syed Copying info in entirety without depending on stale TX information */
3160          rbAllocInfo->tbInfo[0].tbCb = &hqP->tbInfo[0];
3161          rbAllocInfo->tbInfo[0].schdlngForTb = TRUE;
3162          /* Fix : syed Assigning proc to scratchpad */ 
3163          ueDl->proc = hqP;
3164
3165          retxBw += rbAllocInfo->rbsReq;
3166
3167          cmLListAdd2Tail(&allocInfo->ccchSduAlloc.ccchSduRetxLst, \
3168                &hqP->reqLnk);
3169          hqP->reqLnk.node = (PTR)hqP;
3170          dlSf->schdCcchUe++;
3171       }
3172    }
3173    dlSf->bwAssigned += retxBw;
3174    RETVOID;
3175 }
3176 #endif
3177 \f
3178 /**
3179  * @brief This function scheduler for downlink CCCH messages.
3180  *
3181  * @details
3182  *
3183  *     Function: rgSCHCmnDlCcchRetx
3184  *     Purpose:  Scheduling for downlink CCCH
3185  *
3186  *     Invoked by: Scheduler
3187  *
3188  *  @param[in]  RgSchCellCb           *cell
3189  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
3190  *  @return  Void
3191  *
3192  **/
3193 #ifdef ANSI
3194 PRIVATE Void rgSCHCmnDlCcchRetx
3195 (
3196 RgSchCellCb             *cell,
3197 RgSchCmnDlRbAllocInfo   *allocInfo
3198 )
3199 #else
3200 PRIVATE Void rgSCHCmnDlCcchRetx(cell, allocInfo)
3201 RgSchCellCb             *cell;
3202 RgSchCmnDlRbAllocInfo   *allocInfo;
3203 #endif
3204 {
3205    CmLList           *node;
3206    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
3207    RgSchRaCb         *raCb;
3208    RgSchDlHqProcCb   *hqP;
3209    U8                retxBw = 0;
3210    RgSchDlSf         *dlSf = allocInfo->msg4Alloc.msg4DlSf;
3211         
3212
3213    node = cellSch->dl.msg4RetxLst.first;
3214    while(node)
3215    {
3216       if(cellSch->dl.maxCcchPerDlSf &&
3217             dlSf->schdCcchUe == cellSch->dl.maxCcchPerDlSf)
3218       {
3219          break;
3220       }
3221       else
3222       {
3223          hqP = (RgSchDlHqProcCb *)(node->node);
3224
3225          node = node->next;
3226
3227          /* DwPts Scheduling Changes Start */     
3228 #ifdef LTE_TDD      
3229          if (rgSCHCmnRetxAvoidTdd(allocInfo->msg4Alloc.msg4DlSf, 
3230                   cell, hqP) == TRUE)
3231          {
3232             continue;  
3233          }
3234 #endif      
3235          /* DwPts Scheduling Changes End */      
3236
3237          if (hqP->tbInfo[0].dlGrnt.numRb > (dlSf->bw - dlSf->bwAssigned))
3238          {
3239             break;
3240          }
3241          raCb = (RgSchRaCb*)(hqP->hqE->raCb);
3242          /* Fill RB Alloc Info */
3243          raCb->rbAllocInfo.dlSf = dlSf;
3244          raCb->rbAllocInfo.tbInfo[0].bytesReq =  hqP->tbInfo[0].ccchSchdInfo.totBytes;
3245          raCb->rbAllocInfo.rbsReq = hqP->tbInfo[0].dlGrnt.numRb;
3246          /* Fix : syed iMcs setting did not correspond to RETX */
3247          RG_SCH_CMN_GET_MCS_FOR_RETX((&hqP->tbInfo[0]), 
3248                raCb->rbAllocInfo.tbInfo[0].imcs);
3249          raCb->rbAllocInfo.rnti = raCb->tmpCrnti;
3250          raCb->rbAllocInfo.tbInfo[0].noLyr = hqP->tbInfo[0].numLyrs;
3251          /* Fix; syed Copying info in entirety without depending on stale TX information */
3252          raCb->rbAllocInfo.tbInfo[0].tbCb = &hqP->tbInfo[0];
3253          raCb->rbAllocInfo.tbInfo[0].schdlngForTb = TRUE;
3254
3255          retxBw += raCb->rbAllocInfo.rbsReq;
3256
3257          cmLListAdd2Tail(&allocInfo->msg4Alloc.msg4RetxLst, \
3258                &hqP->reqLnk);
3259          hqP->reqLnk.node = (PTR)hqP;
3260          dlSf->schdCcchUe++;
3261       }
3262    }
3263    dlSf->bwAssigned += retxBw;
3264    RETVOID;
3265 }
3266
3267 \f
3268 /**
3269  * @brief This function implements scheduler DL allocation for
3270  *        for broadcast (on PDSCH) and paging.
3271  *
3272  * @details
3273  *
3274  *     Function: rgSCHCmnDlBcchPcch
3275  *     Purpose:  This function implements scheduler for DL allocation
3276  *               for broadcast (on PDSCH) and paging.
3277  *
3278  *     Invoked by: Scheduler
3279  *
3280  *  @param[in]  RgSchCellCb*     cell
3281  *  @return  S16
3282  *      -# ROK
3283  *      -# RFAILED
3284  **/
3285 #ifdef ANSI
3286 PRIVATE Void rgSCHCmnDlBcchPcch
3287 (
3288 RgSchCellCb             *cell,
3289 RgSchCmnDlRbAllocInfo   *allocInfo,
3290 RgInfSfAlloc            *subfrmAlloc
3291 )
3292 #else
3293 PRIVATE Void rgSCHCmnDlBcchPcch(cell, allocInfo, subfrmAlloc)
3294 RgSchCellCb             *cell;
3295 RgSchCmnDlRbAllocInfo   *allocInfo;
3296 RgInfSfAlloc            *subfrmAlloc;
3297 #endif
3298 {
3299    CmLteTimingInfo   frm;
3300    RgSchDlSf         *sf;
3301    RgSchClcDlLcCb    *pcch;
3302    RgSchClcBoRpt     *bo;
3303 #ifndef RGR_SI_SCH
3304    Bool              valid;
3305    RgSchClcDlLcCb    *bcch, *bch;
3306 #endif/*RGR_SI_SCH*/
3307
3308
3309
3310    frm   = cell->crntTime;
3311 #ifdef LTEMAC_HDFDD
3312    /* For HDFDD we need scheduling information at least RG_SCH_CMN_DL_DELTA
3313       + RG_SCH_CMN_HARQ_INTERVAL (7) subframes ahead */
3314    RGSCH_INCR_SUB_FRAME(frm, RG_SCH_CMN_DL_DELTA + RG_SCH_CMN_HARQ_INTERVAL);
3315 #else
3316   // RGSCH_SUBFRAME_INDEX(frm);
3317    //RGSCH_INCR_SUB_FRAME(frm, RG_SCH_CMN_DL_DELTA);
3318 #endif
3319
3320    /* Compute the subframe for which allocation is being made        */
3321    /* essentially, we need pointer to the dl frame for this subframe */
3322    sf = rgSCHUtlSubFrmGet(cell, frm);
3323
3324
3325 #ifndef RGR_SI_SCH
3326    bch = rgSCHDbmGetBcchOnBch(cell);
3327 #if (ERRCLASS & ERRCLS_DEBUG)
3328    if (bch == NULLP)
3329    {
3330       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"BCCH on BCH is not configured");
3331       RETVOID;
3332    }
3333 #endif
3334    if (bch->boLst.first != NULLP)
3335    {
3336       bo = (RgSchClcBoRpt *)(bch->boLst.first->node);
3337       if (RGSCH_TIMEINFO_SAME(frm, bo->timeToTx))
3338       {
3339          sf->bch.tbSize = bo->bo;
3340          cmLListDelFrm(&bch->boLst, bch->boLst.first);
3341          /* ccpu00117052 - MOD - Passing double pointer
3342             for proper NULLP assignment*/
3343          rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&bo, sizeof(*bo));
3344          rgSCHUtlFillRgInfCmnLcInfo(sf, subfrmAlloc, bch->lcId,TRUE);
3345       }
3346    }
3347    else
3348    {
3349       if ((frm.sfn % 4 == 0) && (frm.subframe == 0))
3350       {
3351       }
3352    }
3353
3354    allocInfo->bcchAlloc.schdFirst = FALSE;
3355    bcch = rgSCHDbmGetFirstBcchOnDlsch(cell);
3356 #if (ERRCLASS & ERRCLS_DEBUG)
3357    if (bcch == NULLP)
3358    {
3359       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"BCCH on DLSCH is not configured");
3360       RETVOID;
3361    }
3362 #endif
3363    if (bcch->boLst.first != NULLP)
3364    {
3365       bo = (RgSchClcBoRpt *)(bcch->boLst.first->node);
3366
3367       if (RGSCH_TIMEINFO_SAME(frm, bo->timeToTx))
3368       {
3369          allocInfo->bcchAlloc.schdFirst = TRUE;
3370          /* Time to perform allocation for this BCCH transmission */
3371          rgSCHCmnClcAlloc(cell, sf, bcch, RGSCH_SI_RNTI, allocInfo);
3372       }
3373    }
3374
3375    if(!allocInfo->bcchAlloc.schdFirst)
3376    {
3377       CmLList   *lnk;
3378       bcch = rgSCHDbmGetSecondBcchOnDlsch(cell);
3379 #if (ERRCLASS & ERRCLS_DEBUG)
3380       if (bcch == NULLP)
3381       {
3382          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"BCCH on DLSCH is not configured");
3383          RETVOID;
3384       }
3385 #endif
3386       lnk = bcch->boLst.first;
3387       while (lnk != NULLP)
3388       {
3389          bo = (RgSchClcBoRpt *)(lnk->node);
3390          lnk = lnk->next;
3391          valid = rgSCHCmnChkInWin(frm, bo->timeToTx, bo->maxTimeToTx);
3392
3393          if(valid)
3394          {
3395             bo->i = RGSCH_CALC_SF_DIFF(frm, bo->timeToTx);
3396             /* Time to perform allocation for this BCCH transmission */
3397             rgSCHCmnClcAlloc(cell, sf, bcch, RGSCH_SI_RNTI, allocInfo);
3398             break;
3399          }
3400          else
3401          {
3402             valid = rgSCHCmnChkPastWin(frm, bo->maxTimeToTx);
3403             if(valid)
3404             {
3405                cmLListDelFrm(&bcch->boLst, &bo->boLstEnt);
3406                /* ccpu00117052 - MOD - Passing double pointer
3407                   for proper NULLP assignment*/
3408                rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&bo,
3409                      sizeof(RgSchClcBoRpt));
3410             }
3411          }
3412       }
3413    }
3414 #else
3415    rgSCHDlSiSched(cell, allocInfo, subfrmAlloc);
3416 #endif/*RGR_SI_SCH*/
3417
3418    pcch = rgSCHDbmGetPcch(cell);
3419 #ifdef ERRCLS_KW
3420    if (pcch == NULLP)
3421    {
3422       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"PCCH on DLSCH is not configured");
3423       RETVOID;
3424    }
3425 #endif
3426    if (pcch->boLst.first != NULLP)
3427    {
3428       bo = (RgSchClcBoRpt *)(pcch->boLst.first->node);
3429
3430       if (RGSCH_TIMEINFO_SAME(frm, bo->timeToTx))
3431       {
3432          /* Time to perform allocation for this PCCH transmission */
3433          rgSCHCmnClcAlloc(cell, sf, pcch, RGSCH_P_RNTI, allocInfo);
3434       }
3435    }
3436    RETVOID;
3437 }
3438
3439 /*
3440 *
3441 *       Fun:   rgSCHCmnChkInWin
3442 *
3443 *       Desc:  This function checks if frm occurs in window
3444 *
3445 *       Ret:   TRUE      - if in window
3446 *              FALSE     - otherwise
3447 *
3448 *       Notes: None
3449 *
3450 *       File:  rg_sch_cmn.c
3451 *
3452 */
3453 #ifdef ANSI
3454 Bool rgSCHCmnChkInWin
3455 (
3456 CmLteTimingInfo   frm,
3457 CmLteTimingInfo   start,
3458 CmLteTimingInfo   end
3459 )
3460 #else
3461 Bool rgSCHCmnChkInWin(frm, start, end)
3462 CmLteTimingInfo   frm;
3463 CmLteTimingInfo   start;
3464 CmLteTimingInfo   end;
3465 #endif
3466 {
3467    Bool    inWin = FALSE;
3468
3469
3470    if (end.sfn > start.sfn)
3471    {
3472       if (frm.sfn > start.sfn
3473             || (frm.sfn == start.sfn && frm.slot >= start.slot))
3474       {
3475          if (frm.sfn < end.sfn
3476 #ifdef EMTC_ENABLE
3477                || (frm.sfn == end.sfn && frm.slot <= end.slot))
3478 #else
3479                || (frm.sfn == end.sfn && frm.slot <= start.slot))
3480 #endif
3481          {
3482             inWin = TRUE;
3483          }
3484       }
3485    }
3486    /* Testing for wrap around, sfn wraparound check should be enough */
3487    else if (end.sfn < start.sfn)
3488    {
3489       if (frm.sfn > start.sfn
3490             || (frm.sfn == start.sfn && frm.slot >= start.slot))
3491       {
3492          inWin = TRUE;
3493       }
3494       else
3495       {
3496          if (frm.sfn < end.sfn
3497                || (frm.sfn == end.sfn && frm.slot <= end.slot))
3498          {
3499             inWin = TRUE;
3500          }
3501       }
3502    }
3503    else  /* start.sfn == end.sfn */
3504    {
3505       if (frm.sfn == start.sfn
3506             && (frm.slot >= start.slot
3507                && frm.slot <= end.slot))
3508       {
3509          inWin = TRUE;
3510       }
3511    }
3512
3513    return (inWin);
3514 } /* end of rgSCHCmnChkInWin*/
3515
3516 /*
3517 *
3518 *       Fun:   rgSCHCmnChkPastWin
3519 *
3520 *       Desc:  This function checks if frm has gone past window edge
3521 *
3522 *       Ret:   TRUE      - if past window edge
3523 *              FALSE     - otherwise
3524 *
3525 *       Notes: None
3526 *
3527 *       File:  rg_sch_cmn.c
3528 *
3529 */
3530 #ifdef ANSI
3531 Bool rgSCHCmnChkPastWin
3532 (
3533 CmLteTimingInfo   frm,
3534 CmLteTimingInfo   end
3535 )
3536 #else
3537 Bool rgSCHCmnChkPastWin(frm, end)
3538 CmLteTimingInfo   frm;
3539 CmLteTimingInfo   end;
3540 #endif
3541 {
3542    CmLteTimingInfo  refFrm = end;
3543    Bool             pastWin;
3544
3545
3546    RGSCH_INCR_FRAME(refFrm.sfn);
3547    RGSCH_INCR_SUB_FRAME(end, 1);
3548    pastWin = rgSCHCmnChkInWin(frm, end, refFrm);
3549
3550    return (pastWin);
3551 } /* end of rgSCHCmnChkPastWin*/
3552 \f
3553 /**
3554  * @brief This function implements allocation of the resources for common
3555  * channels BCCH, PCCH.
3556  *
3557  * @details
3558  *
3559  *     Function: rgSCHCmnClcAlloc
3560  *     Purpose:  This function implements selection of number of RBs based
3561  *               the allowed grant for the service. It is also responsible
3562  *               for selection of MCS for the transmission.
3563  *
3564  *     Invoked by: Scheduler
3565  *
3566  *  @param[in]  RgSchCellCb                *cell,
3567  *  @param[in]  RgSchDlSf                  *sf,
3568  *  @param[in]  RgSchClcDlLcCb             *lch,
3569  *  @param[in]  U16                        rnti,
3570  *  @param[out] RgSchCmnDlRbAllocInfo      *allocInfo
3571  *  @return     Void
3572  *
3573  **/
3574 #ifdef ANSI
3575 PRIVATE Void rgSCHCmnClcAlloc
3576 (
3577 RgSchCellCb             *cell,
3578 RgSchDlSf               *sf,
3579 RgSchClcDlLcCb          *lch,
3580 U16                     rnti,
3581 RgSchCmnDlRbAllocInfo   *allocInfo
3582 )
3583 #else
3584 PRIVATE Void rgSCHCmnClcAlloc(cell, sf, lch, rnti, allocInfo)
3585 RgSchCellCb             *cell;
3586 RgSchDlSf               *sf;
3587 RgSchClcDlLcCb          *lch;
3588 U16                     rnti;
3589 RgSchCmnDlRbAllocInfo   *allocInfo;
3590 #endif
3591 {
3592    RgSchCmnDlCell       *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
3593    RgSchClcBoRpt        *bo;
3594    U32                  rb=0;
3595    U8                   mcs;
3596    U32                  tbs;
3597 #ifdef LTE_TDD   
3598    U8                   lostRe;
3599    U8                   cfi = cellDl->currCfi;  
3600 #endif
3601
3602
3603    bo = (RgSchClcBoRpt *)(lch->boLst.first->node);
3604
3605    mcs = bo->mcs;
3606    tbs = bo->bo;
3607    /* rgSCHCmnClcRbAllocForFxdTb(cell, bo->bo, cellDl->ccchCqi, &rb);*/
3608    if(cellDl->bitsPerRb==0)
3609    {
3610       while ((rgTbSzTbl[0][0][rb]) < (tbs*8))
3611       {
3612          rb++;
3613       }
3614       rb = rb+1;
3615    }
3616    else
3617    {
3618       rb = RGSCH_CEIL((tbs*8), cellDl->bitsPerRb);
3619    }
3620    /* DwPTS Scheduling Changes Start */   
3621 #ifdef LTE_TDD
3622    if(sf->sfType == RG_SCH_SPL_SF_DATA) 
3623    {
3624       RGSCH_GET_SPS_SF_CFI(cell->bwCfg.dlTotalBw, cfi);
3625
3626       /* Calculate the less RE's because of DwPTS */
3627       lostRe = rb * (cellDl->noResPerRb[cfi] - cellDl->numReDwPts[cfi]);
3628
3629       /* Increase number of RBs in Spl SF to compensate for lost REs */
3630       rb += RGSCH_CEIL(lostRe, cellDl->numReDwPts[cfi]); 
3631    }
3632 #endif
3633    /* DwPTS Scheduling Changes End */   
3634    /*ccpu00115595- end*/
3635    /* additional check to see if required RBs
3636     * exceeds the available */
3637    if (rb > sf->bw - sf->bwAssigned)
3638    {
3639       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"BW allocation "
3640                 "failed for CRNTI:%d",rnti);
3641       RETVOID;
3642    }
3643
3644    /* Update the subframe Allocated BW field */
3645    sf->bwAssigned = sf->bwAssigned + rb;
3646    /* Fill in the BCCH/PCCH transmission info to the RBAllocInfo struct */
3647    if (rnti == RGSCH_SI_RNTI)
3648    {
3649       allocInfo->bcchAlloc.rnti = rnti;
3650       allocInfo->bcchAlloc.dlSf = sf;
3651       allocInfo->bcchAlloc.tbInfo[0].bytesReq = tbs;
3652       allocInfo->bcchAlloc.rbsReq = rb;
3653       allocInfo->bcchAlloc.tbInfo[0].imcs = mcs;
3654       allocInfo->bcchAlloc.tbInfo[0].noLyr = 1;
3655       /* Nprb indication at PHY for common Ch */
3656       allocInfo->bcchAlloc.nPrb = bo->nPrb;
3657    }
3658    else
3659    {
3660       allocInfo->pcchAlloc.rnti = rnti;
3661       allocInfo->pcchAlloc.dlSf = sf;
3662       allocInfo->pcchAlloc.tbInfo[0].bytesReq = tbs;
3663       allocInfo->pcchAlloc.rbsReq = rb;
3664       allocInfo->pcchAlloc.tbInfo[0].imcs = mcs;
3665       allocInfo->pcchAlloc.tbInfo[0].noLyr = 1;
3666       allocInfo->pcchAlloc.nPrb = bo->nPrb;
3667    }
3668    RETVOID;
3669 }
3670
3671 \f
3672 /**
3673  * @brief This function implements PDCCH allocation for common channels.
3674  *
3675  * @details
3676  *
3677  *     Function: rgSCHCmnCmnPdcchAlloc
3678  *     Purpose:  This function implements allocation of PDCCH for a UE.
3679  *               1. This uses index 0 of PDCCH table for efficiency.
3680  *               2. Uses he candidate PDCCH count for the aggr level.
3681  *               3. Look for availability for each candidate and choose
3682  *                  the first one available.
3683  *
3684  *     Invoked by: Scheduler
3685  *
3686  *  @param[in]  RgSchCellCb           *cell
3687  *  @param[in]  RgSchDlSf             *sf
3688  *  @return     RgSchPdcch *
3689  *               -# NULLP when unsuccessful
3690  *
3691  **/
3692 #ifdef ANSI
3693 RgSchPdcch *rgSCHCmnCmnPdcchAlloc
3694 (
3695 RgSchCellCb                *cell,
3696 RgSchDlSf                  *subFrm
3697 )
3698 #else
3699 RgSchPdcch *rgSCHCmnCmnPdcchAlloc(cell, subFrm)
3700 RgSchCellCb                *cell;
3701 RgSchDlSf                  *subFrm;
3702 #endif
3703 {
3704    CmLteAggrLvl         aggrLvl;
3705    RgSchPdcchInfo       *pdcchInfo;
3706    RgSchPdcch           *pdcch;
3707    RgSchCmnCell         *cellSch = RG_SCH_CMN_GET_CELL(cell);
3708    U8                   numCce;  /*store num CCEs based on 
3709                                   aggregation level */
3710
3711    aggrLvl   = cellSch->dl.cmnChAggrLvl;
3712
3713    pdcchInfo = &(subFrm->pdcchInfo);
3714
3715     /* Updating the no. of nCce in pdcchInfo, in case if CFI
3716     * was changed  */
3717 #ifdef LTE_TDD
3718    if(subFrm->nCce != pdcchInfo->nCce)
3719    {   
3720       rgSCHUtlPdcchInit(cell, subFrm, subFrm->nCce);
3721    }
3722 #else   
3723    if(cell->nCce != pdcchInfo->nCce)
3724    {
3725       rgSCHUtlPdcchInit(cell, subFrm, cell->nCce);
3726    }
3727 #endif  
3728
3729    switch (aggrLvl)
3730    {
3731       case CM_LTE_AGGR_LVL4:
3732         numCce = 4;
3733         break;
3734       case CM_LTE_AGGR_LVL8:
3735         numCce = 8;
3736         break;
3737                 case CM_LTE_AGGR_LVL16:
3738         numCce = 16;
3739         break;
3740       default:
3741         return (NULLP);
3742    }
3743
3744    if (rgSCHUtlPdcchAvail(cell, pdcchInfo, aggrLvl, &pdcch) == TRUE)
3745    {
3746 #ifdef LTEMAC_SPS
3747       pdcch->isSpsRnti = FALSE;
3748 #endif
3749       /* Increment the CCE used counter in the current subframe */
3750       subFrm->cceCnt += numCce;
3751       pdcch->pdcchSearchSpace = RG_SCH_CMN_SEARCH_SPACE;
3752
3753       return (pdcch);
3754    }
3755
3756    /* PDCCH Allocation Failed, Mark cceFailure flag as TRUE */
3757    subFrm->isCceFailure = TRUE;
3758
3759    RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,
3760             "PDCCH ERR: NO PDDCH AVAIL IN COMMON SEARCH SPACE aggr:%u", 
3761             aggrLvl);
3762    return (NULLP);
3763 }
3764
3765 \f
3766 /**
3767  * @brief This function implements bandwidth allocation for common channels.
3768  *
3769  * @details
3770  *
3771  *     Function: rgSCHCmnClcRbAlloc
3772  *     Purpose:  This function implements bandwith allocation logic
3773  *               for common control channels.
3774  *
3775  *     Invoked by: Scheduler
3776  *
3777  *  @param[in]  RgSchCellCb*  cell
3778  *  @param[in]  U32           bo
3779  *  @param[in]  U8            cqi
3780  *  @param[in]  U8            *rb
3781  *  @param[in]  U32           *tbs
3782  *  @param[in]  U8            *mcs
3783  *  @param[in]  RgSchDlSf     *sf
3784  *  @return  Void
3785  *
3786  **/
3787 #ifdef LTEMAC_SPS
3788 #ifdef ANSI
3789 Void rgSCHCmnClcRbAlloc
3790 (
3791 RgSchCellCb             *cell,
3792 U32                     bo,
3793 U8                      cqi,
3794 U8                      *rb,
3795 U32                     *tbs,
3796 U8                      *mcs,
3797 U8                      *iTbs,
3798 Bool                    isSpsBo,
3799 RgSchDlSf               *sf 
3800 )
3801 #else
3802 Void rgSCHCmnClcRbAlloc(cell, bo, cqi, rb, tbs, mcs, iTbs, isSpsBo)
3803 RgSchCellCb             *cell;
3804 U32                     bo;
3805 U8                      cqi;
3806 U8                      *rb;
3807 U32                     *tbs;
3808 U8                      *mcs;
3809 U8                      *iTbs;
3810 Bool                    isSpsBo;
3811 RgSchDlSf               *sf; 
3812 #endif
3813 #else
3814 #ifdef ANSI
3815 PRIVATE Void rgSCHCmnClcRbAlloc
3816 (
3817 RgSchCellCb             *cell,
3818 U32                     bo,
3819 U8                      cqi,
3820 U8                      *rb,
3821 U32                     *tbs,
3822 U8                      *mcs,
3823 RgSchDlSf               *sf 
3824 )
3825 #else
3826 PRIVATE Void rgSCHCmnClcRbAlloc(cell, bo, cqi, rb, tbs, mcs, sf)
3827 RgSchCellCb             *cell;
3828 U32                     bo;
3829 U8                      cqi;
3830 U8                      *rb;
3831 U32                     *tbs;
3832 U8                      *mcs;
3833 RgSchDlSf               *sf; 
3834 #endif
3835 #endif /* LTEMAC_SPS */
3836 {
3837    U8                   iTbsVal;
3838    RgSchCmnTbSzEff      *effTbl;
3839    U32                  eff;
3840    U32                  noRes;
3841    RgSchCmnCell         *cellSch = RG_SCH_CMN_GET_CELL(cell);
3842    U8                   cfi = cellSch->dl.currCfi;
3843    U32                  tmpRb=0;
3844
3845    /* first get the CQI to MCS table and determine the number of RBs */
3846    effTbl = (RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[0][cfi]);
3847    iTbsVal = (*(RgSchCmnCqiToTbs *)(cellSch->dl.cqiToTbsTbl[0][cfi]))[cqi];
3848    RG_SCH_CMN_DL_TBS_TO_MCS(iTbsVal, *mcs);
3849
3850    /* Efficiency is number of bits per 1024 REs */
3851    eff  = (*effTbl)[iTbsVal];
3852
3853    /* Get the number of REs needed for this bo  */
3854    noRes = ((bo * 8 * 1024) / eff );
3855
3856    /* Get the number of RBs needed for this transmission */
3857    /* Number of RBs = No of REs / No of REs per RB       */
3858    tmpRb = RGSCH_CEIL(noRes, cellSch->dl.noResPerRb[cfi]);
3859    /* KWORK_FIX: added check to see if rb has crossed maxRb*/
3860    RGSCH_ARRAY_BOUND_CHECK_WITH_POS_IDX(cell->instIdx, rgTbSzTbl[0][0], (tmpRb-1));
3861    if (tmpRb > cellSch->dl.maxDlBwPerUe)
3862    {
3863       tmpRb = cellSch->dl.maxDlBwPerUe;
3864    }
3865    while ((rgTbSzTbl[0][iTbsVal][tmpRb-1]/8) < bo && 
3866            (tmpRb < cellSch->dl.maxDlBwPerUe))
3867    {
3868       tmpRb++;
3869       RGSCH_ARRAY_BOUND_CHECK_WITH_POS_IDX(cell->instIdx, rgTbSzTbl[0][0], (tmpRb-1));
3870    }
3871    *tbs =  rgTbSzTbl[0][iTbsVal][tmpRb-1]/8;
3872    *rb = (U8)tmpRb;
3873    RG_SCH_CMN_DL_TBS_TO_MCS(iTbsVal, *mcs);
3874
3875    RETVOID;
3876 }
3877
3878 \f
3879
3880 /**
3881  * @brief Scheduling for MSG4.
3882  *
3883  * @details
3884  *
3885  *     Function: rgSCHCmnMsg4Alloc
3886  *     Purpose:  Scheduling for MSG4
3887  *
3888  *     Invoked by: Scheduler
3889  *
3890  *  @param[in]  RgSchCellCb*          cell
3891  *  @param[in]  RgSchRaCb*            raCb
3892  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
3893  *  @return  S16
3894  *
3895  **/
3896 #ifdef ANSI
3897 PRIVATE S16 rgSCHCmnMsg4Alloc
3898 (
3899 RgSchCellCb                *cell,
3900 RgSchRaCb                  *raCb,
3901 RgSchCmnDlRbAllocInfo      *allocInfo
3902 )
3903 #else
3904 PRIVATE S16 rgSCHCmnMsg4Alloc(cell, raCb, allocInfo)
3905 RgSchCellCb                *cell;
3906 RgSchRaCb                  *raCb;
3907 RgSchCmnDlRbAllocInfo      *allocInfo;
3908 #endif
3909 {
3910    RgSchCmnCell       *cellSch = RG_SCH_CMN_GET_CELL(cell);
3911
3912
3913  /* SR_RACH_STATS : MSG4 TO BE TXED */
3914    rgNumMsg4ToBeTx++;
3915    /* Return if subframe BW exhausted */
3916    if (allocInfo->msg4Alloc.msg4DlSf->bw <=
3917        allocInfo->msg4Alloc.msg4DlSf->bwAssigned)
3918    {
3919       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId ,
3920          "bw<=bwAssigned");
3921       return RFAILED;
3922    }
3923
3924    if (rgSCHDhmGetMsg4HqProc(raCb, cellSch->dl.time) != ROK)
3925    {
3926       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
3927          "rgSCHDhmGetMsg4HqProc failed");
3928       return RFAILED;
3929    }
3930
3931    raCb->rbAllocInfo.dlSf = allocInfo->msg4Alloc.msg4DlSf;
3932
3933    if (rgSCHCmnMsg4DedAlloc(cell, raCb) != ROK)
3934    {
3935       /* Fix : syed Minor failure handling, release hqP if Unsuccessful */    
3936       rgSCHDhmRlsHqpTb(raCb->dlHqE->msg4Proc, 0, FALSE);
3937       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
3938          "rgSCHCmnMsg4DedAlloc failed.");
3939       return RFAILED;
3940    }
3941    cmLListAdd2Tail(&allocInfo->msg4Alloc.msg4TxLst, &raCb->dlHqE->msg4Proc->reqLnk);
3942    raCb->dlHqE->msg4Proc->reqLnk.node = (PTR)raCb->dlHqE->msg4Proc;
3943    allocInfo->msg4Alloc.msg4DlSf->schdCcchUe++;
3944
3945    return ROK;
3946 }
3947
3948 \f
3949 /**
3950  * @brief This function implements PDCCH allocation for an UE.
3951  *
3952  * @details
3953  *
3954  *     Function: PdcchAlloc
3955  *     Purpose:  This function implements allocation of PDCCH for an UE.
3956  *               1. Get the aggregation level for the CQI of the UE.
3957  *               2. Get the candidate PDCCH count for the aggr level.
3958  *               3. Look for availability for each candidate and choose
3959  *                  the first one available.
3960  *
3961  *     Invoked by: Scheduler
3962  *
3963  *  @param[in]  cell
3964  *  @param[in]  subFrm
3965  *  @param[in]  cqi
3966  *  @param[in]  dciFrmt
3967  *  @return  RgSchPdcch *
3968  *         -# NULLP when unsuccessful
3969  *
3970  **/
3971 #ifdef ANSI
3972 RgSchPdcch *rgSCHCmnPdcchAlloc
3973 (
3974 RgSchCellCb             *cell,
3975 RgSchUeCb               *ue,
3976 RgSchDlSf               *subFrm,
3977 U8                      cqi,
3978 TfuDciFormat            dciFrmt,
3979 Bool                    isDtx
3980 )
3981 #else
3982 RgSchPdcch *rgSCHCmnPdcchAlloc(cell, subFrm, cqi, dciFrmt, isDtx)
3983 RgSchCellCb             *cell;
3984 RgSchUeCb               *ue;
3985 RgSchDlSf               *subFrm;
3986 U8                      cqi;
3987 TfuDciFormat            dciFrmt;
3988 Bool                    isDtx;
3989 #endif
3990 {
3991    CmLteAggrLvl     aggrLvl;
3992    RgSchPdcchInfo   *pdcchInfo;
3993    RgSchPdcch       *pdcch;
3994
3995
3996    /* 3.1 consider the selected DCI format size in determining the
3997     * aggregation level */
3998    //TODO_SID Need to update. Currently using 4 aggregation level
3999    aggrLvl   = CM_LTE_AGGR_LVL2;//cellSch->dciAggrLvl[cqi][dciFrmt];
4000
4001 #ifdef LTE_ADV
4002    if((dciFrmt == TFU_DCI_FORMAT_1A) &&
4003       ((ue) && (ue->allocCmnUlPdcch)) )
4004    {
4005       pdcch = rgSCHCmnCmnPdcchAlloc(cell, subFrm);
4006       /* Since CRNTI Scrambled */
4007       if(NULLP != pdcch)
4008       {
4009          pdcch->dciNumOfBits = ue->dciSize.cmnSize[dciFrmt];
4010         // prc_trace_format_string(PRC_TRACE_GROUP_PS, PRC_TRACE_INFO_LOW,"Forcing alloc in CMN search spc size %d fmt %d \n",
4011         // pdcch->dciNumOfBits, dciFrmt);
4012       }
4013       return (pdcch);
4014    }
4015 #endif
4016
4017    /* Incrementing aggrLvl by 1 if it not AGGR_LVL8(MAX SIZE)
4018     * inorder to increse the redudancy bits for better decoding of UE */
4019    if (isDtx)
4020    {
4021       if (aggrLvl != CM_LTE_AGGR_LVL16)
4022       {
4023          switch(aggrLvl)
4024          {
4025             case CM_LTE_AGGR_LVL2:
4026                aggrLvl = CM_LTE_AGGR_LVL4;
4027                 break;
4028             case CM_LTE_AGGR_LVL4:
4029                aggrLvl = CM_LTE_AGGR_LVL8;
4030                break;
4031             case CM_LTE_AGGR_LVL8:
4032                aggrLvl = CM_LTE_AGGR_LVL16;
4033                break;
4034             default:
4035                break;
4036          }
4037          /* aggrLvl   += 1; */
4038       }
4039    }
4040
4041    pdcchInfo = &subFrm->pdcchInfo;
4042
4043    /* Updating the no. of nCce in pdcchInfo, in case if CFI
4044     * was changed  */
4045 #ifdef LTE_TDD
4046    if(subFrm->nCce != pdcchInfo->nCce)
4047    {   
4048       rgSCHUtlPdcchInit(cell, subFrm, subFrm->nCce);
4049    }
4050 #else   
4051    if(cell->nCce != pdcchInfo->nCce)
4052    {
4053       rgSCHUtlPdcchInit(cell, subFrm, cell->nCce);
4054    }
4055 #endif       
4056
4057    if (pdcchInfo->nCce < (1 << (aggrLvl - 1)))
4058    {
4059       /* PDCCH Allocation Failed, Mark cceFailure flag as TRUE */
4060       subFrm->isCceFailure = TRUE;
4061       RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,
4062             "PDCCH ERR: NO PDDCH AVAIL IN UE SEARCH SPACE :aggr(%u)", 
4063             aggrLvl);
4064
4065       return (NULLP);
4066    }
4067
4068    if (rgSCHUtlPdcchAvail(cell, pdcchInfo, aggrLvl, &pdcch) == TRUE)
4069    {
4070       /* SR_RACH_STATS : Reset isTBMsg4 */
4071       pdcch->dci.u.format1aInfo.t.pdschInfo.isTBMsg4= FALSE;         
4072       pdcch->dci.u.format0Info.isSrGrant = FALSE;
4073 #ifdef LTEMAC_SPS
4074       pdcch->isSpsRnti = FALSE;
4075 #endif
4076       /* Increment the CCE used counter in the current subframe */
4077       subFrm->cceCnt += aggrLvl;
4078       pdcch->pdcchSearchSpace = RG_SCH_UE_SPECIFIC_SEARCH_SPACE;
4079       if (ue != NULLP)
4080                 {
4081 #ifdef LTE_ADV
4082                  if (ue->cell != cell)
4083                  {
4084                     /* Secondary Cell */
4085                     //pdcch->dciNumOfBits = ue->dciSize.noUlCcSize[dciFrmt];
4086                     pdcch->dciNumOfBits = MAX_5GTF_DCIA1B1_SIZE;
4087                  }
4088                  else
4089 #endif
4090                  {
4091                     //pdcch->dciNumOfBits = ue->dciSize.dedSize[dciFrmt];
4092                     //TODO_SID Need to update dci size.
4093                     pdcch->dciNumOfBits = MAX_5GTF_DCIA1B1_SIZE;
4094                  }
4095                 }
4096       else
4097       {
4098          /* MSG4 */
4099          pdcch->dciNumOfBits = cell->dciSize.size[dciFrmt];
4100       }
4101       return (pdcch);
4102    }
4103
4104    /* PDCCH Allocation Failed, Mark cceFailure flag as TRUE */
4105    subFrm->isCceFailure = TRUE;
4106
4107    RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,
4108          "PDCCH ERR: NO PDDCH AVAIL IN UE SEARCH SPACE :aggr(%u)",
4109          aggrLvl);
4110    return (NULLP);
4111 }
4112
4113 #ifdef RGR_V1
4114 /**
4115  * @brief This function implements BW allocation for CCCH SDU
4116  *
4117  * @details
4118  *
4119  *     Function: rgSCHCmnCcchSduDedAlloc
4120  *     Purpose:  Downlink bandwidth Allocation for CCCH SDU.
4121  *
4122  *     Invoked by: Scheduler
4123  *
4124  *  @param[in]  RgSchCellCb*     cell
4125  *  @param[out] RgSchUeCb        *ueCb
4126  *  @return S16
4127  *
4128  **/
4129 #ifdef ANSI
4130 PRIVATE S16 rgSCHCmnCcchSduDedAlloc
4131 (
4132 RgSchCellCb      *cell,
4133 RgSchUeCb        *ueCb
4134 )
4135 #else
4136 PRIVATE S16 rgSCHCmnCcchSduDedAlloc(cell, ueCb)
4137 RgSchCellCb      *cell;
4138 RgSchUeCb        *ueCb;
4139 #endif
4140 {
4141    RgSchDlHqEnt      *hqE = NULLP;
4142    U32                  effBo;
4143    RgSchDlRbAlloc       *rbAllocinfo = NULLP;
4144    RgSchCmnDlCell       *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
4145    U8                   iTbs;
4146    U8                   numRb;
4147 #ifdef LTE_TDD
4148    U8                   cfi     = cellDl->currCfi;
4149 #endif
4150
4151
4152    rbAllocinfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ueCb, cell);
4153
4154    effBo  =   ueCb->dlCcchInfo.bo + RGSCH_CCCH_SDU_HDRSIZE;
4155
4156 #ifndef LTEMAC_SPS
4157    rgSCHCmnClcRbAlloc(cell, effBo, cellDl->ccchCqi, &rbAllocinfo->rbsReq, \
4158                       &rbAllocinfo->tbInfo[0].bytesReq,
4159                       &rbAllocinfo->tbInfo[0].imcs, rbAllocinfo->dlSf);
4160 #else /* LTEMAC_SPS */
4161    rgSCHCmnClcRbAlloc(cell, effBo, cellDl->ccchCqi, &rbAllocinfo->rbsReq, \
4162                       &rbAllocinfo->tbInfo[0].bytesReq,\
4163                       &rbAllocinfo->tbInfo[0].imcs, &iTbs, FALSE, 
4164                       rbAllocinfo->dlSf);
4165 #endif /* LTEMAC_SPS */
4166
4167    iTbs = 0;
4168    /* Cannot exceed the total number of RBs in the cell */
4169    if ((S16)rbAllocinfo->rbsReq > ((S16)(rbAllocinfo->dlSf->bw - \
4170                                    rbAllocinfo->dlSf->bwAssigned)))
4171    {
4172       /* Check if atleast one allocation was possible.
4173          This may be the case where the Bw is very less and
4174          with the configured CCCH CQI, CCCH SDU exceeds the min Bw */
4175       if (rbAllocinfo->dlSf->bwAssigned == 0)
4176       {
4177          numRb   = rbAllocinfo->dlSf->bw;
4178          RG_SCH_CMN_DL_MCS_TO_TBS(rbAllocinfo->tbInfo[0].imcs, iTbs);
4179          while (rgTbSzTbl[0][++iTbs][numRb-1]/8 < effBo)
4180          {
4181             iTbs++;
4182          }
4183          rbAllocinfo->rbsReq = numRb;
4184          rbAllocinfo->tbInfo[0].bytesReq = rgTbSzTbl[0][iTbs][numRb-1]/8;
4185          /* DwPTS Scheduling Changes Start */
4186 #ifdef LTE_TDD
4187          if(rbAllocinfo->dlSf->sfType == RG_SCH_SPL_SF_DATA)
4188          {
4189             rbAllocinfo->tbInfo[0].bytesReq =
4190                rgSCHCmnCalcDwPtsTbSz(cell, effBo, &numRb, &iTbs, 1,cfi);
4191          }
4192 #endif
4193          /* DwPTS Scheduling Changes End */
4194          RG_SCH_CMN_DL_TBS_TO_MCS(iTbs, rbAllocinfo->tbInfo[0].imcs);
4195       }
4196       else
4197       {
4198          return RFAILED;
4199       }
4200    }
4201
4202    /* Update the subframe Allocated BW field */
4203    rbAllocinfo->dlSf->bwAssigned = rbAllocinfo->dlSf->bwAssigned + \
4204                                    rbAllocinfo->rbsReq;
4205    hqE = RG_SCH_CMN_GET_UE_HQE(ueCb, cell);
4206    rbAllocinfo->tbInfo[0].tbCb = &hqE->ccchSduProc->tbInfo[0];
4207    rbAllocinfo->rnti = ueCb->ueId;
4208    rbAllocinfo->tbInfo[0].noLyr = 1;
4209
4210    return ROK;
4211 }
4212 #endif
4213 \f
4214 /**
4215  * @brief This function implements BW allocation for MSG4
4216  *
4217  * @details
4218  *
4219  *     Function: rgSCHCmnMsg4DedAlloc
4220  *     Purpose:  Downlink bandwidth Allocation for MSG4.
4221  *
4222  *     Invoked by: Scheduler
4223  *
4224  *  @param[in]  RgSchCellCb*     cell
4225  *  @param[out] RgSchRaCb        *raCb
4226  *  @return S16
4227  *
4228  **/
4229 #ifdef ANSI
4230 PRIVATE S16 rgSCHCmnMsg4DedAlloc
4231 (
4232 RgSchCellCb      *cell,
4233 RgSchRaCb        *raCb
4234 )
4235 #else
4236 PRIVATE S16 rgSCHCmnMsg4DedAlloc(cell, raCb)
4237 RgSchCellCb      *cell;
4238 RgSchRaCb        *raCb;
4239 #endif
4240 {
4241    U32                  effBo;
4242    RgSchDlRbAlloc       *rbAllocinfo = &raCb->rbAllocInfo;
4243    U8                   iTbs;
4244    U8                   numRb;
4245 #ifdef LTE_TDD
4246    RgSchCmnDlCell       *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
4247    U8                   cfi     = cellDl->currCfi;
4248 #endif
4249
4250
4251    effBo  = raCb->dlCcchInfo.bo + RGSCH_MSG4_HDRSIZE + RGSCH_CONT_RESID_SIZE;
4252
4253 #ifndef LTEMAC_SPS
4254    rgSCHCmnClcRbAlloc(cell, effBo, raCb->ccchCqi, &rbAllocinfo->rbsReq, \
4255          &rbAllocinfo->tbInfo[0].bytesReq,\
4256          &rbAllocinfo->tbInfo[0].imcs, rbAllocinfo->dlSf);
4257 #else /* LTEMAC_SPS */
4258    rgSCHCmnClcRbAlloc(cell, effBo, raCb->ccchCqi, &rbAllocinfo->rbsReq, \
4259                       &rbAllocinfo->tbInfo[0].bytesReq,\
4260                       &rbAllocinfo->tbInfo[0].imcs, &iTbs, FALSE,
4261                       rbAllocinfo->dlSf);
4262 #endif /* LTEMAC_SPS */
4263
4264    iTbs = 0;
4265    /* Cannot exceed the total number of RBs in the cell */
4266    if ((S16)rbAllocinfo->rbsReq > ((S16)(rbAllocinfo->dlSf->bw - \
4267                rbAllocinfo->dlSf->bwAssigned)))
4268    {
4269       /* Check if atleast one allocation was possible.
4270          This may be the case where the Bw is very less and
4271          with the configured CCCH CQI, CCCH SDU exceeds the min Bw */
4272       if (rbAllocinfo->dlSf->bwAssigned == 0)
4273       {
4274          numRb   = rbAllocinfo->dlSf->bw;
4275          RG_SCH_CMN_DL_MCS_TO_TBS(rbAllocinfo->tbInfo[0].imcs, iTbs);
4276          while (rgTbSzTbl[0][++iTbs][numRb-1]/8 < effBo)
4277          {
4278             iTbs++;
4279          }
4280          rbAllocinfo->rbsReq = numRb;
4281          rbAllocinfo->tbInfo[0].bytesReq = rgTbSzTbl[0][iTbs][numRb-1]/8;
4282          /* DwPTS Scheduling Changes Start */
4283 #ifdef LTE_TDD
4284          if(rbAllocinfo->dlSf->sfType == RG_SCH_SPL_SF_DATA)
4285          {
4286             rbAllocinfo->tbInfo[0].bytesReq =
4287                rgSCHCmnCalcDwPtsTbSz(cell, effBo, &numRb, &iTbs, 1, cfi);
4288          }
4289 #endif
4290          /* DwPTS Scheduling Changes End */
4291          RG_SCH_CMN_DL_TBS_TO_MCS(iTbs, rbAllocinfo->tbInfo[0].imcs);
4292       }
4293       else
4294       {
4295          return RFAILED;
4296       }
4297    }
4298
4299    /* Update the subframe Allocated BW field */
4300    rbAllocinfo->dlSf->bwAssigned = rbAllocinfo->dlSf->bwAssigned + \
4301                                    rbAllocinfo->rbsReq;
4302    rbAllocinfo->rnti = raCb->tmpCrnti;
4303    rbAllocinfo->tbInfo[0].tbCb = &raCb->dlHqE->msg4Proc->tbInfo[0];
4304    rbAllocinfo->tbInfo[0].schdlngForTb = TRUE;
4305    rbAllocinfo->tbInfo[0].noLyr = 1;
4306
4307    return ROK;
4308 }
4309
4310 #ifdef LTE_TDD
4311 /**
4312  * @brief This function implements scheduling for RA Response.
4313  *
4314  * @details
4315  *
4316  *     Function: rgSCHCmnDlRaRsp
4317  *     Purpose:  Downlink scheduling for RA responses.
4318  *
4319  *     Invoked by: Scheduler
4320  *
4321  *  @param[in]  RgSchCellCb*     cell
4322  *  @return  Void
4323  *
4324  **/
4325 #ifdef ANSI
4326 PRIVATE Void rgSCHCmnDlRaRsp
4327 (
4328 RgSchCellCb                *cell,
4329 RgSchCmnDlRbAllocInfo      *allocInfo
4330 )
4331 #else
4332 PRIVATE Void rgSCHCmnDlRaRsp(cell, allocInfo)
4333 RgSchCellCb                *cell;
4334 RgSchCmnDlRbAllocInfo      *allocInfo;
4335 #endif
4336 {
4337    CmLteTimingInfo      frm;
4338    CmLteTimingInfo      schFrm;
4339    RgSchDlSf            *subFrm;
4340    U16                  rarnti;
4341    U8                   i;
4342    U8                   noRaRnti=0;
4343    U8                   raIdx;
4344    RgSchTddRachRspLst   *rachRsp;
4345    U8                   ulDlCfgIdx = cell->ulDlCfgIdx;
4346    U8                   sfnIdx;
4347    U8                   subfrmIdx;
4348    U16                  rntiIdx=0;
4349
4350    frm   = cell->crntTime;
4351    RGSCH_INCR_SUB_FRAME(frm, RG_SCH_CMN_DL_DELTA);
4352
4353    /* Compute the subframe for which allocation is being made        */
4354    /* essentially, we need pointer to the dl frame for this subframe */
4355    subFrm  = rgSCHUtlSubFrmGet(cell, frm);
4356
4357    /* Get the RACH Response scheduling related information
4358     * for the subframe with RA index */
4359    raIdx = rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][frm.subframe]-1;
4360
4361    rachRsp = &cell->rachRspLst[raIdx];
4362
4363    for(sfnIdx = 0; sfnIdx < rachRsp->numRadiofrms; sfnIdx++)
4364    {
4365       /* For all scheduled RACH Responses in SFNs */
4366       schFrm = frm;
4367       RG_SCH_CMN_DECR_FRAME(schFrm.sfn, rachRsp->rachRsp[sfnIdx].sfnOffset);
4368       /* For all scheduled RACH Responses in subframes */
4369       for(subfrmIdx = 0;
4370             subfrmIdx < rachRsp->rachRsp[sfnIdx].numSubfrms; subfrmIdx++)
4371       {
4372          schFrm.subframe = rachRsp->rachRsp[sfnIdx].subframe[subfrmIdx];
4373          /* compute the last RA RNTI used in the previous subframe */
4374          raIdx = (((schFrm.sfn % cell->raInfo.maxRaSize) * \
4375                   RGSCH_NUM_SUB_FRAMES * RGSCH_MAX_RA_RNTI_PER_SUBFRM) \
4376                                     + schFrm.subframe);
4377
4378          /* For all RA RNTIs within a subframe */
4379
4380          for(i=0; (i < RGSCH_MAX_RA_RNTI_PER_SUBFRM) && \
4381                (noRaRnti < RGSCH_MAX_TDD_RA_RSP_ALLOC); i++)
4382          {
4383             rarnti = (schFrm.subframe + RGSCH_NUM_SUB_FRAMES*i + 1);
4384             rntiIdx = (raIdx + RGSCH_NUM_SUB_FRAMES*i);
4385
4386             if (cell->raInfo.raReqLst[rntiIdx].first != NULLP)
4387             {
4388                /* compute the next RA RNTI */
4389                if (rgSCHCmnRaRspAlloc(cell, subFrm, rntiIdx,
4390                         rarnti, noRaRnti, allocInfo) != ROK)
4391                {
4392                   /* The resources are exhausted */
4393                   break;
4394                }
4395                noRaRnti++;
4396             }
4397          }
4398          noRaRnti=0;
4399       }
4400    }
4401
4402    RETVOID;
4403 }
4404 #else
4405 /**
4406  * @brief This function implements scheduling for RA Response.
4407  *
4408  * @details
4409  *
4410  *     Function: rgSCHCmnDlRaRsp
4411  *     Purpose:  Downlink scheduling for RA responses.
4412  *
4413  *     Invoked by: Scheduler
4414  *
4415  *  @param[in]  RgSchCellCb*          cell
4416  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
4417  *  @return  Void
4418  *
4419  **/
4420 #ifdef ANSI
4421 PRIVATE Void rgSCHCmnDlRaRsp  //FDD
4422 (
4423 RgSchCellCb                *cell,
4424 RgSchCmnDlRbAllocInfo      *allocInfo
4425 )
4426 #else
4427 PRIVATE Void rgSCHCmnDlRaRsp(cell, allocInfo)
4428 RgSchCellCb                *cell;
4429 RgSchCmnDlRbAllocInfo      *allocInfo;
4430 #endif
4431 {
4432    CmLteTimingInfo      frm;
4433    CmLteTimingInfo      winStartFrm;
4434    RgSchDlSf            *subFrm;
4435    U8                   winStartIdx;
4436    U8                   winGap;
4437    U8                   rarnti;
4438    U8                   raIdx;
4439    RgSchCmnCell         *sched;
4440    U8                   i,noRaRnti=0;
4441
4442    frm   = cell->crntTime;
4443    RGSCH_INCR_SUB_FRAME(frm, RG_SCH_CMN_DL_DELTA);
4444
4445    /* Compute the subframe for which allocation is being made        */
4446    /* essentially, we need pointer to the dl frame for this subframe */
4447    subFrm  = rgSCHUtlSubFrmGet(cell, frm);
4448    sched   = RG_SCH_CMN_GET_CELL(cell);
4449
4450    /* ccpu00132523 - Window Start calculated by considering RAR window size, 
4451     * RAR Wait period, Subframes occuppied for respective preamble format*/
4452    winGap = (sched->dl.numRaSubFrms-1) + (cell->rachCfg.raWinSize-1) 
4453              +RGSCH_RARSP_WAIT_PERIOD;
4454
4455    /* Window starting occassion is retrieved using the gap and tried to 
4456     * fit to the size of raReqLst array*/ 
4457    RGSCHDECRFRMCRNTTIME(frm, winStartFrm, winGap);
4458
4459         //5G_TODO TIMING update. Need to check
4460    winStartIdx = (winStartFrm.sfn & 1) * RGSCH_MAX_RA_RNTI+ winStartFrm.slot;
4461
4462    for(i = 0; ((i < cell->rachCfg.raWinSize) && (noRaRnti < RG_SCH_CMN_MAX_CMN_PDCCH)); i++)
4463    {
4464       raIdx = (winStartIdx + i) % RGSCH_RAREQ_ARRAY_SIZE;
4465
4466       if (cell->raInfo.raReqLst[raIdx].first != NULLP)
4467       {
4468          allocInfo->raRspAlloc[noRaRnti].biEstmt = \
4469                          (!i * RGSCH_ONE_BIHDR_SIZE);
4470          rarnti = raIdx % RGSCH_MAX_RA_RNTI+ 1;
4471          if (rgSCHCmnRaRspAlloc(cell, subFrm, raIdx,
4472                                  rarnti, noRaRnti, allocInfo) != ROK)
4473          {
4474             /* The resources are exhausted */
4475             break;
4476          }
4477          /* ccpu00132523- If all the RAP ids are not scheduled then need not 
4478           * proceed for next RA RNTIs*/
4479          if(allocInfo->raRspAlloc[noRaRnti].numRapids < cell->raInfo.raReqLst[raIdx].count)
4480          {
4481             break;
4482          }
4483          noRaRnti++; /* Max of RG_SCH_CMN_MAX_CMN_PDCCH RARNTIs
4484                         for response allocation */
4485       }
4486    }
4487    RETVOID;
4488 }
4489 #endif
4490
4491 \f
4492 /**
4493  * @brief This function allocates the resources for an RARNTI.
4494  *
4495  * @details
4496  *
4497  *     Function: rgSCHCmnRaRspAlloc
4498  *     Purpose:  Allocate resources to a RARNTI.
4499  *               0. Allocate PDCCH for sending the response.
4500  *               1. Locate the number of RA requests pending for the RARNTI.
4501  *               2. Compute the size of data to be built.
4502  *               3. Using common channel CQI, compute the number of RBs.
4503  *
4504  *     Invoked by: Scheduler
4505  *
4506  *  @param[in]  RgSchCellCb             *cell,
4507  *  @param[in]  RgSchDlSf               *subFrm,
4508  *  @param[in]  U16                     rarnti,
4509  *  @param[in]  U8                      noRaRnti
4510  *  @param[out] RgSchCmnDlRbAllocInfo   *allocInfo
4511  *  @return  S16
4512  *
4513  **/
4514 #ifdef ANSI
4515 PRIVATE S16 rgSCHCmnRaRspAlloc
4516 (
4517 RgSchCellCb             *cell,
4518 RgSchDlSf               *subFrm,
4519 U16                     raIndex,
4520 U16                     rarnti,
4521 U8                      noRaRnti,
4522 RgSchCmnDlRbAllocInfo   *allocInfo
4523 )
4524 #else
4525 PRIVATE S16 rgSCHCmnRaRspAlloc(cell,subFrm,raIndex,rarnti,noRaRnti,allocInfo)
4526 RgSchCellCb             *cell;
4527 RgSchDlSf               *subFrm;
4528 U16                     raIndex;
4529 U16                     rarnti;
4530 U8                      noRaRnti;
4531 RgSchCmnDlRbAllocInfo   *allocInfo;
4532 #endif
4533 {
4534    RgSchCmnDlCell       *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
4535    RgSchCmnUlCell       *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
4536    U16                  noBytes;
4537    U32                  rb = 0;
4538    U32                  tbs;
4539    /*ccpu00116700,ccpu00116708- Corrected the wrong type for mcs*/
4540    U8                   mcs;
4541    CmLListCp            *reqLst;
4542    /* RACH handling related changes */
4543    Bool                 isAlloc = FALSE;
4544    static U8            schdNumRapid = 0;
4545    U8                   remNumRapid = 0;
4546    U8                   nPrb = 0;
4547    S32                  allwdTbSz = 0;
4548 #ifdef LTE_TDD   
4549    U16                  lostRe;  
4550    U8                   cfi = cellDl->currCfi;  
4551 #endif   
4552
4553 #ifndef RGR_V1
4554    UNUSED(cellUl);
4555 #endif
4556
4557    /* ccpu00132523: Resetting the schdRap Id count in every scheduling subframe*/
4558    if(noRaRnti == 0)
4559    {
4560       schdNumRapid = 0;
4561    }
4562
4563
4564    if (subFrm->bw == subFrm->bwAssigned)
4565    {
4566       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
4567          "bw == bwAssigned RARNTI:%d",rarnti);
4568       return RFAILED;
4569    }
4570
4571    reqLst = &cell->raInfo.raReqLst[raIndex];
4572    if (reqLst->count == 0)
4573    {
4574       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
4575          "reqLst Count=0 RARNTI:%d",rarnti);
4576       return RFAILED;
4577    }
4578    remNumRapid = reqLst->count;
4579
4580 #ifdef RGR_V1
4581    /* Limit number of rach rsps to maxMsg3PerUlsf */
4582    if ( schdNumRapid+remNumRapid > cellUl->maxMsg3PerUlSf )
4583    {
4584       remNumRapid = cellUl->maxMsg3PerUlSf-schdNumRapid;
4585    }
4586 #endif
4587  
4588    while (remNumRapid)
4589    {
4590       /* Try allocating for as many RAPIDs as possible */
4591       /* BI sub-header size to the tbSize requirement */
4592       noBytes  = RGSCH_GET_RAR_BYTES(remNumRapid) +\
4593                  allocInfo->raRspAlloc[noRaRnti].biEstmt;
4594       if ((allwdTbSz = rgSCHUtlGetAllwdCchTbSz(noBytes*8, &nPrb, &mcs)) == -1)
4595       {
4596          remNumRapid--;
4597          continue;
4598       }
4599
4600       /* rgSCHCmnClcRbAllocForFxdTb(cell, allwdTbSz/8, cellDl->ccchCqi, &rb);*/
4601       if(cellDl->bitsPerRb==0)
4602       {
4603          while ((rgTbSzTbl[0][0][rb]) <(U32) allwdTbSz)
4604          {
4605             rb++;
4606          }
4607          rb = rb+1;
4608       }
4609       else
4610       {
4611          rb = RGSCH_CEIL(allwdTbSz, cellDl->bitsPerRb);
4612       }
4613       /* DwPTS Scheduling Changes Start */      
4614 #ifdef LTE_TDD      
4615       if (subFrm->sfType == RG_SCH_SPL_SF_DATA)
4616       {
4617          RGSCH_GET_SPS_SF_CFI(cell->bwCfg.dlTotalBw, cfi);
4618
4619          /* Calculate the less RE's because of DwPTS */
4620          lostRe = rb * (cellDl->noResPerRb[cfi] - 
4621                                   cellDl->numReDwPts[cfi]);
4622           
4623          /* Increase number of RBs in Spl SF to compensate for lost REs */
4624          rb += RGSCH_CEIL(lostRe, cellDl->numReDwPts[cfi]);
4625       }
4626 #endif      
4627       /* DwPTS Scheduling Changes End */
4628
4629       /*ccpu00115595- end*/
4630       if (rb > subFrm->bw - subFrm->bwAssigned)
4631       {
4632          remNumRapid--;
4633          continue;
4634       }
4635       /* Allocation succeeded for 'remNumRapid' */
4636       isAlloc = TRUE;
4637       tbs = allwdTbSz/8;
4638       printf("\n!!!RAR alloc noBytes:%u,allwdTbSz:%u,tbs:%u,rb:%u\n",
4639                                       noBytes,allwdTbSz,tbs,rb);
4640       break;
4641    }
4642    if (!isAlloc)
4643    {
4644       RLOG_ARG0(L_INFO,DBG_CELLID,cell->cellId,"BW alloc Failed");
4645       return RFAILED;
4646    }
4647
4648    subFrm->bwAssigned = subFrm->bwAssigned + rb;
4649
4650    /* Fill AllocInfo structure */
4651    allocInfo->raRspAlloc[noRaRnti].rnti = rarnti;
4652    allocInfo->raRspAlloc[noRaRnti].tbInfo[0].bytesReq = tbs;
4653    allocInfo->raRspAlloc[noRaRnti].rbsReq = rb;
4654    allocInfo->raRspAlloc[noRaRnti].dlSf = subFrm;
4655    allocInfo->raRspAlloc[noRaRnti].tbInfo[0].imcs = mcs;
4656    allocInfo->raRspAlloc[noRaRnti].raIndex = raIndex;
4657    /* RACH changes for multiple RAPID handling */
4658    allocInfo->raRspAlloc[noRaRnti].numRapids = remNumRapid;
4659    allocInfo->raRspAlloc[noRaRnti].nPrb = nPrb;
4660    allocInfo->raRspAlloc[noRaRnti].tbInfo[0].noLyr = 1;
4661    allocInfo->raRspAlloc[noRaRnti].vrbgReq = RGSCH_CEIL(nPrb,MAX_5GTF_VRBG_SIZE); 
4662    schdNumRapid += remNumRapid; 
4663    return ROK;
4664 }
4665
4666 /***********************************************************
4667  *
4668  *     Func : rgSCHCmnUlAllocFillRbInfo
4669  *
4670  *     Desc : Fills the start RB and the number of RBs for
4671  *            uplink allocation.
4672  *
4673  *     Ret  : void
4674  *
4675  *     Notes:
4676  *
4677  *     File :
4678  *
4679  **********************************************************/
4680 #ifdef ANSI
4681 Void rgSCHCmnUlAllocFillRbInfo
4682 (
4683 RgSchCellCb   *cell,
4684 RgSchUlSf      *sf,
4685 RgSchUlAlloc  *alloc
4686 )
4687 #else
4688 Void rgSCHCmnUlAllocFillRbInfo(cell, sf, alloc)
4689 RgSchCellCb    *cell;
4690 RgSchUlSf      *sf;
4691 RgSchUlAlloc   *alloc;
4692 #endif
4693 {
4694     RgSchCmnUlCell *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
4695     RgSchCmnDlCell *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
4696     U8             cfi = cellDl->currCfi;
4697
4698
4699    alloc->grnt.rbStart = (alloc->sbStart * cellUl->sbSize) + 
4700                                     cell->dynCfiCb.bwInfo[cfi].startRb;
4701
4702    /* Num RBs = numSbAllocated * sbSize - less RBs in the last SB */
4703    alloc->grnt.numRb = (alloc->numSb * cellUl->sbSize);
4704
4705    RETVOID;
4706 }
4707
4708 /**
4709  * @brief Grant request for Msg3.
4710  *
4711  * @details
4712  *
4713  *     Function : rgSCHCmnMsg3GrntReq
4714  *
4715  *     This is invoked by downlink scheduler to request allocation
4716  *     for msg3.
4717  *     Steps:
4718  *     - Attempt to allocate msg3 in the current msg3 subframe
4719  *       Allocation attempt based on whether preamble is from group A
4720  *       and the value of MESSAGE_SIZE_GROUP_A
4721  *     - Link allocation with passed RNTI and msg3 HARQ process
4722  *     - Set the HARQ process ID (*hqProcIdRef)
4723  *
4724  *  @param[in]  RgSchCellCb       *cell
4725  *  @param[in]  CmLteRnti         rnti
4726  *  @param[in]  Bool              preamGrpA
4727  *  @param[in]  RgSchUlHqProcCb   *hqProc
4728  *  @param[out] RgSchUlAlloc      **ulAllocRef
4729  *  @param[out] U8                *hqProcIdRef
4730  *  @return  Void
4731  **/
4732 #ifdef ANSI
4733 PRIVATE Void rgSCHCmnMsg3GrntReq
4734 (
4735 RgSchCellCb     *cell,
4736 CmLteRnti       rnti,
4737 Bool            preamGrpA,
4738 RgSchUlHqProcCb *hqProc,
4739 RgSchUlAlloc    **ulAllocRef,
4740 U8              *hqProcIdRef
4741 )
4742 #else
4743 PRIVATE Void rgSCHCmnMsg3GrntReq(cell, rnti, preamGrpA, hqProc,
4744                                  ulAllocRef, hqProcIdRef)
4745 RgSchCellCb     *cell;
4746 CmLteRnti       rnti;
4747 Bool            preamGrpA;
4748 RgSchUlHqProcCb *hqProc;
4749 RgSchUlAlloc    **ulAllocRef;
4750 U8              *hqProcIdRef;
4751 #endif
4752 {
4753    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
4754    RgSchUlSf       *sf = &cellUl->ulSfArr[cellUl->msg3SchdIdx];
4755    RgSchUlHole     *hole;
4756    RgSchUlAlloc    *alloc;
4757    U8              iMcs;
4758    U8              numSb;
4759
4760
4761    *ulAllocRef = NULLP;
4762
4763    /* Fix: ccpu00120610 Use remAllocs from subframe during msg3 allocation */
4764    if (*sf->allocCountRef >= cellUl->maxAllocPerUlSf)
4765    {
4766       RETVOID;
4767    }
4768    if (preamGrpA == FALSE)
4769    {
4770       numSb = cellUl->ra.prmblBNumSb;
4771       iMcs  = cellUl->ra.prmblBIMcs;
4772    }
4773    else
4774    {
4775       numSb = cellUl->ra.prmblANumSb;
4776       iMcs  = cellUl->ra.prmblAIMcs;
4777    }
4778
4779    if ((hole = rgSCHUtlUlHoleFirst(sf)) != NULLP)
4780    {
4781       if(*sf->allocCountRef == 0)
4782       {
4783          RgSchCmnDlCell  *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
4784          /* Reinitialize the hole */
4785          if (sf->holeDb->count == 1 && (hole->start == 0)) /* Sanity check of holeDb */
4786          {
4787             hole->num = cell->dynCfiCb.bwInfo[cellDl->currCfi].numSb;
4788             /* Re-Initialize available subbands because of CFI change*/
4789             hole->num = cell->dynCfiCb.bwInfo[cellDl->currCfi].numSb;   
4790          }
4791          else
4792          {
4793             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
4794                      "Error! holeDb sanity check failed RNTI:%d",rnti);
4795          } 
4796       }
4797       if (numSb <= hole->num)
4798       {
4799          U8 iTbs;
4800          alloc                = rgSCHUtlUlAllocGetHole(sf, numSb, hole);
4801          rgSCHCmnUlAllocFillRbInfo(cell, sf, alloc);
4802          alloc->grnt.iMcs     = iMcs;
4803          alloc->grnt.iMcsCrnt = iMcs;
4804          iTbs                 = rgSCHCmnUlGetITbsFrmIMcs(iMcs);
4805          RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgTbSzTbl[0], iTbs); 
4806          /* To include the length and ModOrder in DataRecp Req.*/
4807          alloc->grnt.datSz = rgTbSzTbl[0][iTbs][alloc->grnt.numRb-1] / 8;
4808          RG_SCH_UL_MCS_TO_MODODR(iMcs, alloc->grnt.modOdr);
4809          /* RACHO : setting nDmrs to 0 and UlDelaybit to 0*/
4810          alloc->grnt.nDmrs    = 0;
4811          alloc->grnt.hop      = 0;
4812          alloc->grnt.delayBit = 0;
4813          alloc->grnt.isRtx    = FALSE;
4814          *ulAllocRef          = alloc;
4815          *hqProcIdRef         = (cellUl->msg3SchdHqProcIdx);
4816          hqProc->procId       = *hqProcIdRef;
4817          hqProc->ulSfIdx      = (cellUl->msg3SchdIdx);
4818          alloc->rnti          = rnti;
4819          alloc->ue            = NULLP;
4820          alloc->pdcch         = FALSE;
4821          alloc->forMsg3       = TRUE;
4822          alloc->hqProc        = hqProc;
4823          rgSCHUhmNewTx(hqProc, (U8)(cell->rachCfg.maxMsg3Tx - 1), alloc);
4824          //RLOG_ARG4(L_DEBUG,DBG_CELLID,cell->cellId,
4825          printf(
4826                "\nRNTI:%d MSG3 ALLOC proc(%lu)procId(%d)schdIdx(%d)\n",
4827                alloc->rnti,
4828                ((PTR)alloc->hqProc),
4829                alloc->hqProc->procId,
4830                alloc->hqProc->ulSfIdx);
4831          RLOG_ARG2(L_DEBUG,DBG_CELLID,cell->cellId,
4832                "alloc(%p)maxMsg3Tx(%d)",
4833                ((PTR)alloc),
4834                cell->rachCfg.maxMsg3Tx);
4835       }
4836    }
4837
4838    RETVOID;
4839 }
4840
4841 \f
4842 /**
4843  * @brief This function determines the allocation limits and
4844  *        parameters that aid in DL scheduling.
4845  *
4846  * @details
4847  *
4848  *     Function: rgSCHCmnDlSetUeAllocLmt
4849  *     Purpose:  This function determines the Maximum RBs
4850  *               a UE is eligible to get based on softbuffer
4851  *               limitation and cell->>>maxDlBwPerUe. The Codeword
4852  *               specific parameters like iTbs, eff and noLyrs
4853  *               are also set in this function. This function
4854  *               is called while UE configuration and UeDlCqiInd.
4855  *
4856  *     Invoked by: Scheduler
4857  *
4858  *  @param[in]  RgSchCellCb   *cellCb
4859  *  @param[in]  RgSchCmnDlUe  *ueDl
4860  *  @return  Void
4861  *
4862  **/
4863 #ifdef ANSI
4864 PRIVATE Void rgSCHCmnDlSetUeAllocLmt
4865 (
4866 RgSchCellCb   *cell,
4867 RgSchCmnDlUe  *ueDl,
4868 Bool          isEmtcUe
4869 )
4870 #else
4871 PRIVATE Void rgSCHCmnDlSetUeAllocLmt(cell, ueDl, isEmtcUe)
4872 RgSchCellCb   *cell;
4873 RgSchCmnDlUe  *ueDl;
4874 Bool          isEmtcUe;
4875 #endif
4876 {
4877    U8            modOrder;
4878    U32           maxRb;
4879    RgSchCmnCell  *cellSch = RG_SCH_CMN_GET_CELL(cell);
4880    U8            cfi = cellSch->dl.currCfi;
4881
4882
4883 #ifdef EMTC_ENABLE
4884    if(TRUE == isEmtcUe)
4885    {
4886       /* ITbs for CW0 for 1 Layer Tx */
4887       ueDl->mimoInfo.cwInfo[0].iTbs[0] = (*(RgSchEmtcCmnCqiToTbs *)(cellSch->dl.emtcCqiToTbsTbl[0][cfi]))\
4888                                              [ueDl->mimoInfo.cwInfo[0].cqi];
4889       /* ITbs for CW0 for 2 Layer Tx */
4890       ueDl->mimoInfo.cwInfo[0].iTbs[1] = (*(RgSchEmtcCmnCqiToTbs *)(cellSch->dl.emtcCqiToTbsTbl[1][cfi]))\
4891                                              [ueDl->mimoInfo.cwInfo[0].cqi];
4892       /* Eff for CW0 for 1 Layer Tx */
4893       ueDl->mimoInfo.cwInfo[0].eff[0] = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[0][cfi]))\
4894                                             [ueDl->mimoInfo.cwInfo[0].iTbs[0]];
4895       /* Eff for CW0 for 2 Layer Tx */
4896       ueDl->mimoInfo.cwInfo[0].eff[1] = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[1][cfi]))\
4897                                             [ueDl->mimoInfo.cwInfo[0].iTbs[1]];
4898
4899       /* ITbs for CW1 for 1 Layer Tx */
4900       ueDl->mimoInfo.cwInfo[1].iTbs[0] = (*(RgSchEmtcCmnCqiToTbs *)(cellSch->dl.emtcCqiToTbsTbl[0][cfi]))\
4901                                              [ueDl->mimoInfo.cwInfo[1].cqi];
4902       /* ITbs for CW1 for 2 Layer Tx */
4903       ueDl->mimoInfo.cwInfo[1].iTbs[1] = (*(RgSchEmtcCmnCqiToTbs *)(cellSch->dl.emtcCqiToTbsTbl[1][cfi]))\
4904                                              [ueDl->mimoInfo.cwInfo[1].cqi];
4905       /* Eff for CW1 for 1 Layer Tx */
4906       ueDl->mimoInfo.cwInfo[1].eff[0] = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[0][cfi]))\
4907                                             [ueDl->mimoInfo.cwInfo[1].iTbs[0]];
4908       /* Eff for CW1 for 2 Layer Tx */
4909       ueDl->mimoInfo.cwInfo[1].eff[1] = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[1][cfi]))\
4910                                             [ueDl->mimoInfo.cwInfo[1].iTbs[1]];
4911    }
4912    else
4913 #endif 
4914    {
4915       /* ITbs for CW0 for 1 Layer Tx */
4916       ueDl->mimoInfo.cwInfo[0].iTbs[0] = (*(RgSchCmnCqiToTbs *)(cellSch->dl.cqiToTbsTbl[0][cfi]))\
4917                                          [ueDl->mimoInfo.cwInfo[0].cqi];
4918       /* ITbs for CW0 for 2 Layer Tx */
4919       ueDl->mimoInfo.cwInfo[0].iTbs[1] = (*(RgSchCmnCqiToTbs *)(cellSch->dl.cqiToTbsTbl[1][cfi]))\
4920                                          [ueDl->mimoInfo.cwInfo[0].cqi];
4921       /* Eff for CW0 for 1 Layer Tx */
4922       ueDl->mimoInfo.cwInfo[0].eff[0] = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[0][cfi]))\
4923                                         [ueDl->mimoInfo.cwInfo[0].iTbs[0]];
4924       /* Eff for CW0 for 2 Layer Tx */
4925       ueDl->mimoInfo.cwInfo[0].eff[1] = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[1][cfi]))\
4926                                         [ueDl->mimoInfo.cwInfo[0].iTbs[1]];
4927       
4928       /* ITbs for CW1 for 1 Layer Tx */
4929       ueDl->mimoInfo.cwInfo[1].iTbs[0] = (*(RgSchCmnCqiToTbs *)(cellSch->dl.cqiToTbsTbl[0][cfi]))\
4930                                          [ueDl->mimoInfo.cwInfo[1].cqi];
4931       /* ITbs for CW1 for 2 Layer Tx */
4932       ueDl->mimoInfo.cwInfo[1].iTbs[1] = (*(RgSchCmnCqiToTbs *)(cellSch->dl.cqiToTbsTbl[1][cfi]))\
4933                                          [ueDl->mimoInfo.cwInfo[1].cqi];
4934       /* Eff for CW1 for 1 Layer Tx */
4935       ueDl->mimoInfo.cwInfo[1].eff[0] = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[0][cfi]))\
4936                                         [ueDl->mimoInfo.cwInfo[1].iTbs[0]];
4937       /* Eff for CW1 for 2 Layer Tx */
4938       ueDl->mimoInfo.cwInfo[1].eff[1] = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[1][cfi]))\
4939                                         [ueDl->mimoInfo.cwInfo[1].iTbs[1]];
4940    }
4941
4942 //#ifdef DL_LA 
4943   // ueDl->laCb.cqiBasediTbs =  ueDl->mimoInfo.cwInfo[0].iTbs[0] * 100;
4944 //#endif
4945    /* Assigning noLyrs to each CW assuming optimal Spatial multiplexing
4946     * capability */
4947    (ueDl->mimoInfo.ri/2 == 0)? (ueDl->mimoInfo.cwInfo[0].noLyr = 1) : \
4948               (ueDl->mimoInfo.cwInfo[0].noLyr = ueDl->mimoInfo.ri/2);
4949    ueDl->mimoInfo.cwInfo[1].noLyr = ueDl->mimoInfo.ri - ueDl->mimoInfo.cwInfo[0].noLyr;
4950    /* rg002.101:ccpu00102106: correcting DL harq softbuffer limitation logic.
4951     * The maxTbSz is the maximum number of PHY bits a harq process can
4952     * hold. Hence we limit our allocation per harq process based on this.
4953     * Earlier implementation we misinterpreted the maxTbSz to be per UE
4954     * per TTI, but in fact it is per Harq per TTI. */
4955    /* rg002.101:ccpu00102106: cannot exceed the harq Tb Size
4956     * and harq Soft Bits limit.*/
4957
4958    /* Considering iTbs corresponding to 2 layer transmission for
4959     * codeword0(approximation) and the maxLayers supported by
4960     * this UE at this point of time. */
4961    RG_SCH_CMN_TBS_TO_MODODR(ueDl->mimoInfo.cwInfo[0].iTbs[1], modOrder);
4962
4963    /* Bits/modOrder gives #REs, #REs/noResPerRb gives #RBs */
4964    /* rg001.301 -MOD- [ccpu00119213] : avoiding wraparound */
4965    maxRb = ((ueDl->maxSbSz)/(cellSch->dl.noResPerRb[cfi] * modOrder *\
4966                    ueDl->mimoInfo.ri));
4967    if (cellSch->dl.isDlFreqSel)
4968    {
4969       /* Rounding off to left nearest multiple of RBG size */
4970       maxRb -= maxRb % cell->rbgSize;
4971    }
4972    ueDl->maxRb = RGSCH_MIN(maxRb, cellSch->dl.maxDlBwPerUe);
4973    if (cellSch->dl.isDlFreqSel)
4974    {
4975       /* Rounding off to right nearest multiple of RBG size */
4976       if (ueDl->maxRb % cell->rbgSize)
4977       {
4978          ueDl->maxRb += (cell->rbgSize - 
4979                          (ueDl->maxRb % cell->rbgSize));
4980       }
4981    }
4982
4983    /* Set the index of the cwInfo, which is better in terms of
4984     * efficiency. If RI<2, only 1 CW, hence btrCwIdx shall be 0 */
4985    if (ueDl->mimoInfo.ri < 2)
4986    {
4987       ueDl->mimoInfo.btrCwIdx = 0;
4988    }
4989    else
4990    {
4991       if (ueDl->mimoInfo.cwInfo[0].eff[ueDl->mimoInfo.cwInfo[0].noLyr-1] <\
4992           ueDl->mimoInfo.cwInfo[1].eff[ueDl->mimoInfo.cwInfo[1].noLyr-1])
4993       {
4994          ueDl->mimoInfo.btrCwIdx = 1;
4995       }
4996       else
4997       {
4998          ueDl->mimoInfo.btrCwIdx = 0;
4999       }
5000    }
5001
5002    RETVOID;
5003    }
5004
5005 #ifdef DL_LA
5006
5007 /**
5008  * @brief This function updates TX Scheme.
5009  *
5010  * @details
5011  *
5012  *     Function: rgSCHCheckAndSetTxScheme 
5013  *     Purpose:  This function determines the Maximum RBs
5014  *               a UE is eligible to get based on softbuffer
5015  *               limitation and cell->>>maxDlBwPerUe. The Codeword
5016  *               specific parameters like iTbs, eff and noLyrs
5017  *               are also set in this function. This function
5018  *               is called while UE configuration and UeDlCqiInd.
5019  *
5020  *     Invoked by: Scheduler
5021  *
5022  *  @param[in]  RgSchCellCb   *cell
5023  *  @param[in]  RgSchUeCb     *ue
5024  *  @return  Void
5025  *
5026  **/
5027 #ifdef ANSI
5028 PRIVATE Void rgSCHCheckAndSetTxScheme 
5029 (
5030 RgSchCellCb   *cell,
5031 RgSchUeCb     *ue
5032 )
5033 #else
5034 PRIVATE Void rgSCHCheckAndSetTxScheme(cell, ue)
5035 RgSchCellCb   *cell;
5036 RgSchUeCb     *ue;
5037 #endif
5038 {
5039    RgSchCmnCell  *cellSch = RG_SCH_CMN_GET_CELL(cell);
5040    RgSchCmnDlUe  *ueDl =  RG_SCH_CMN_GET_DL_UE(ue ,cell);
5041    U8            cfi = cellSch->dl.currCfi;
5042    U8            maxiTbs;
5043    U8            cqiBasediTbs;
5044    U8            actualiTbs;
5045
5046
5047    maxiTbs      = (*(RgSchCmnCqiToTbs*)(cellSch->dl.cqiToTbsTbl[0][cfi]))\
5048                 [RG_SCH_CMN_MAX_CQI - 1];
5049    cqiBasediTbs = (ueDl->laCb[0].cqiBasediTbs)/100;
5050    actualiTbs   = ueDl->mimoInfo.cwInfo[0].iTbs[0];
5051
5052    if((actualiTbs < RG_SCH_TXSCHEME_CHNG_ITBS_FACTOR) && (cqiBasediTbs >
5053      actualiTbs) && ((cqiBasediTbs - actualiTbs) > RG_SCH_TXSCHEME_CHNG_THRSHD)) 
5054    {
5055       RG_SCH_CMN_SET_FORCE_TD(ue,cell, RG_SCH_CMN_TD_TXSCHEME_CHNG);
5056    }
5057    
5058    if(actualiTbs >= maxiTbs)
5059    {
5060       RG_SCH_CMN_UNSET_FORCE_TD(ue,cell, RG_SCH_CMN_TD_TXSCHEME_CHNG);
5061    }
5062
5063    RETVOID;
5064 }
5065
5066 /**
5067  * @brief This function determines the allocation limits and
5068  *        parameters that aid in DL scheduling.
5069  *
5070  * @details
5071  *
5072  *     Function: rgSCHCmnDlSetUeAllocLmtLa
5073  *     Purpose:  This function determines the Maximum RBs
5074  *               a UE is eligible to get based on softbuffer
5075  *               limitation and cell->>>maxDlBwPerUe. The Codeword
5076  *               specific parameters like iTbs, eff and noLyrs
5077  *               are also set in this function. This function
5078  *               is called while UE configuration and UeDlCqiInd.
5079  *
5080  *     Invoked by: Scheduler
5081  *
5082  *  @param[in]  RgSchCellCb   *cell
5083  *  @param[in]  RgSchUeCb     *ue
5084  *  @return  Void
5085  *
5086  **/
5087 #ifdef ANSI
5088 Void rgSCHCmnDlSetUeAllocLmtLa
5089 (
5090 RgSchCellCb   *cell,
5091 RgSchUeCb     *ue
5092 )
5093 #else
5094 Void rgSCHCmnDlSetUeAllocLmtLa(cell, ue)
5095 RgSchCellCb   *cell;
5096 RgSchUeCb     *ue;
5097 #endif
5098 {
5099    U8            modOrder;
5100    U32           maxRb;
5101    U8            reportediTbs;
5102    RgSchCmnCell  *cellSch = RG_SCH_CMN_GET_CELL(cell);
5103    RgSchCmnDlUe  *ueDl =  RG_SCH_CMN_GET_DL_UE(ue,cell);
5104    U8            cfi = cellSch->dl.currCfi;
5105    U8            maxiTbs;
5106    U8            cwIdx = 0; 
5107
5108
5109    maxiTbs      = (*(RgSchCmnCqiToTbs *)(cellSch->dl.cqiToTbsTbl[0][cfi]))[RG_SCH_CMN_MAX_CQI - 1];
5110    if(ueDl->cqiFlag == TRUE)
5111    {
5112       for(cwIdx=0; cwIdx < RG_SCH_CMN_MAX_CW_PER_UE; cwIdx++)
5113       {
5114          S32 iTbsNew;
5115
5116          /* Calcluating the reported iTbs for code word 0 */
5117          reportediTbs = ue->ue5gtfCb.mcs; 
5118
5119          iTbsNew = (S32) reportediTbs;
5120
5121          if(!ueDl->laCb[cwIdx].notFirstCqi)
5122          {
5123             /* This is the first CQI report from UE */
5124             ueDl->laCb[cwIdx].cqiBasediTbs = (iTbsNew * 100);
5125             ueDl->laCb[cwIdx].notFirstCqi  =  TRUE;
5126          }
5127          else if ((RG_ITBS_DIFF(reportediTbs, ueDl->mimoInfo.cwInfo[cwIdx].iTbs[0])) > 5)
5128          {
5129             /* Ignore this iTBS report and mark that last iTBS report was */
5130             /* ignored so that subsequently we reset the LA algorithm     */
5131             ueDl->laCb[cwIdx].lastiTbsIgnored = TRUE;
5132             ueDl->laCb[cwIdx].numLastiTbsIgnored++;
5133             if( ueDl->laCb[cwIdx].numLastiTbsIgnored > 10)
5134             {
5135                /* CQI reported by UE is not catching up. Reset the LA algorithm */
5136                ueDl->laCb[cwIdx].cqiBasediTbs = (iTbsNew * 100);
5137                ueDl->laCb[cwIdx].deltaiTbs = 0;
5138                ueDl->laCb[cwIdx].lastiTbsIgnored = FALSE;
5139                ueDl->laCb[cwIdx].numLastiTbsIgnored = 0;
5140             }
5141          }
5142          else
5143          {
5144             if (ueDl->laCb[cwIdx].lastiTbsIgnored != TRUE)
5145             {
5146                ueDl->laCb[cwIdx].cqiBasediTbs = ((20 * iTbsNew * 100) +
5147                      (80 * ueDl->laCb[cwIdx].cqiBasediTbs))/100;
5148             }
5149             else
5150             {
5151                /* Reset the LA as iTbs in use caught up with the value   */
5152                /* reported by UE.                                        */
5153                ueDl->laCb[cwIdx].cqiBasediTbs = ((20 * iTbsNew * 100) +
5154                      (80 * ueDl->mimoInfo.cwInfo[cwIdx].iTbs[0] * 100))/100;
5155                ueDl->laCb[cwIdx].deltaiTbs = 0;
5156                ueDl->laCb[cwIdx].lastiTbsIgnored = FALSE;
5157             }
5158          }
5159
5160          iTbsNew = (ueDl->laCb[cwIdx].cqiBasediTbs + ueDl->laCb[cwIdx].deltaiTbs)/100;
5161
5162          RG_SCH_CHK_ITBS_RANGE(iTbsNew, maxiTbs);       
5163
5164          ueDl->mimoInfo.cwInfo[cwIdx].iTbs[0] = RGSCH_MIN(iTbsNew, cell->thresholds.maxDlItbs);
5165          //ueDl->mimoInfo.cwInfo[cwIdx].iTbs[1] = ueDl->mimoInfo.cwInfo[cwIdx].iTbs[0];
5166 #ifdef RG_5GTF
5167          ue->ue5gtfCb.mcs = ueDl->mimoInfo.cwInfo[cwIdx].iTbs[0];
5168          /*
5169          printf("reportediTbs[%d] cqiBasediTbs[%d] deltaiTbs[%d] iTbsNew[%d] mcs[%d] cwIdx[%d]\n", 
5170                  reportediTbs, ueDl->laCb[cwIdx].cqiBasediTbs, ueDl->laCb[cwIdx].deltaiTbs,
5171                  iTbsNew, ue->ue5gtfCb.mcs, cwIdx);
5172          */
5173 #endif
5174
5175          if((ue->mimoInfo.txMode != RGR_UE_TM_3) && (ue->mimoInfo.txMode != RGR_UE_TM_4))
5176          {
5177             break; 
5178          }
5179       }
5180       ueDl->cqiFlag = FALSE;
5181    } 
5182
5183
5184    RETVOID;
5185 }
5186 #endif
5187 /***********************************************************
5188  *
5189  *     Func : rgSCHCmnDlUeResetTemp
5190  *
5191  *     Desc : Reset whatever variables where temporarily used
5192  *            during UE scheduling.
5193  *
5194  *     Ret  : Void
5195  *
5196  *     Notes:
5197  *
5198  *     File :
5199  *
5200  **********************************************************/
5201 #ifdef ANSI
5202 Void rgSCHCmnDlHqPResetTemp 
5203 (
5204 RgSchDlHqProcCb         *hqP
5205 )
5206 #else
5207 Void rgSCHCmnDlHqPResetTemp(hqP)
5208 RgSchDlHqProcCb         *hqP;
5209 #endif
5210 {
5211
5212
5213    /* Fix: syed having a hqP added to Lists for RB assignment rather than
5214     * a UE, as adding UE was limiting handling some scenarios */ 
5215     hqP->reqLnk.node = (PTR)NULLP;
5216     hqP->schdLstLnk.node = (PTR)NULLP;
5217
5218    RETVOID;
5219 }  /* rgSCHCmnDlHqPResetTemp */
5220
5221 /***********************************************************
5222  *
5223  *     Func : rgSCHCmnDlUeResetTemp
5224  *
5225  *     Desc : Reset whatever variables where temporarily used
5226  *            during UE scheduling.
5227  *
5228  *     Ret  : Void
5229  *
5230  *     Notes:
5231  *
5232  *     File :
5233  *
5234  **********************************************************/
5235 #ifdef ANSI
5236 Void rgSCHCmnDlUeResetTemp
5237 (
5238 RgSchUeCb               *ue,
5239 RgSchDlHqProcCb         *hqP
5240 )
5241 #else
5242 Void rgSCHCmnDlUeResetTemp(ue, hqP)
5243 RgSchUeCb               *ue;
5244 RgSchDlHqProcCb         *hqP;
5245 #endif
5246 {
5247    RgSchDlRbAlloc  *allocInfo;
5248    RgSchCmnDlUe       *cmnUe = RG_SCH_CMN_GET_DL_UE(ue,hqP->hqE->cell);
5249 #ifdef LTE_ADV
5250    Void           *tmpCb;
5251 #endif
5252
5253
5254    /* Fix : syed check for UE's existence was useless.
5255     * Instead we need to check that reset is done only for the 
5256     * information of a scheduled harq proc, which is cmnUe->proc.
5257     * Reset should not be done for non-scheduled hqP */
5258    if((cmnUe->proc == hqP) || (cmnUe->proc == NULLP))
5259    {
5260       cmnUe->proc = NULLP;
5261       allocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue, hqP->hqE->cell);
5262 #ifdef LTE_ADV
5263       tmpCb = allocInfo->laaCb;
5264 #endif
5265       memset(allocInfo, 0, sizeof(RgSchDlRbAlloc));
5266       allocInfo->rnti = ue->ueId;
5267 #ifdef LTE_ADV
5268       allocInfo->laaCb = tmpCb;
5269 #endif
5270       /* Fix: syed moving this to a common function for both scheduled
5271        * and non-scheduled UEs */
5272       cmnUe->outStndAlloc = 0;
5273    }
5274    rgSCHCmnDlHqPResetTemp(hqP);
5275
5276    RETVOID;
5277 }  /* rgSCHCmnDlUeResetTemp */
5278
5279 /***********************************************************
5280  *
5281  *     Func : rgSCHCmnUlUeResetTemp
5282  *
5283  *     Desc : Reset whatever variables where temporarily used
5284  *            during UE scheduling.
5285  *
5286  *     Ret  : Void
5287  *
5288  *     Notes:
5289  *
5290  *     File :
5291  *
5292  **********************************************************/
5293 #ifdef ANSI
5294 Void rgSCHCmnUlUeResetTemp
5295 (
5296 RgSchCellCb             *cell,
5297 RgSchUeCb               *ue
5298 )
5299 #else
5300 Void rgSCHCmnUlUeResetTemp(cell, ue)
5301 RgSchCellCb             *cell;
5302 RgSchUeCb               *ue;
5303 #endif
5304 {
5305    RgSchCmnUlUe       *cmnUlUe = RG_SCH_CMN_GET_UL_UE(ue,cell);
5306
5307
5308    memset(&cmnUlUe->alloc, 0, sizeof(cmnUlUe->alloc));
5309
5310    RETVOID;
5311 }  /* rgSCHCmnUlUeResetTemp */
5312
5313
5314 \f
5315 /**
5316  * @brief This function fills the PDCCH information from dlProc.
5317  *
5318  * @details
5319  *
5320  *     Function: rgSCHCmnFillPdcch
5321  *     Purpose:  This function fills in the PDCCH information
5322  *               obtained from the RgSchDlRbAlloc
5323  *               during common channel scheduling(P, SI, RA - RNTI's).
5324  *
5325  *     Invoked by: Downlink Scheduler
5326  *
5327  *  @param[out] RgSchPdcch*       pdcch
5328  *  @param[in]  RgSchDlRbAlloc*   rbAllocInfo
5329  *  @return  Void
5330  *
5331  **/
5332 #ifdef ANSI
5333 Void rgSCHCmnFillPdcch
5334 (
5335 RgSchCellCb                *cell,
5336 RgSchPdcch                 *pdcch,
5337 RgSchDlRbAlloc             *rbAllocInfo
5338 )
5339 #else
5340 Void rgSCHCmnFillPdcch(cell, pdcch, rbAllocInfo)
5341 RgSchCellCb                *cell;
5342 RgSchPdcch                 *pdcch;
5343 RgSchDlRbAlloc             *rbAllocInfo;
5344 #endif
5345 {
5346
5347
5348    /* common channel pdcch filling,
5349     * only 1A and Local is supported */
5350    pdcch->rnti                       = rbAllocInfo->rnti;
5351    pdcch->dci.dciFormat              = rbAllocInfo->dciFormat;
5352    switch(rbAllocInfo->dciFormat)
5353    {
5354 #ifdef RG_5GTF  /* ANOOP: ToDo: DCI format B1/B2 filling */
5355       case TFU_DCI_FORMAT_B1:
5356          {
5357             /* ToDo: Anoop */
5358             pdcch->dci.u.formatB1Info.formatType = 0;
5359             pdcch->dci.u.formatB1Info.xPDSCHRange = rbAllocInfo->tbInfo[0].cmnGrnt.xPDSCHRange;
5360             pdcch->dci.u.formatB1Info.RBAssign = rbAllocInfo->tbInfo[0].cmnGrnt.rbAssign;
5361             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.hqProcId = 0;
5362             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.mcs = rbAllocInfo->tbInfo[0].imcs;
5363             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.ndi = 0;
5364             //pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.ndi = rbAllocInfo->tbInfo[0].ndi;
5365             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.RV = rbAllocInfo->tbInfo[0].cmnGrnt.rv;
5366             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.bmiHqAckNack = 0;
5367             pdcch->dci.u.formatB1Info.CSI_BSI_BRI_Req = 0;
5368             pdcch->dci.u.formatB1Info.CSIRS_BRRS_TxTiming = 0;
5369             pdcch->dci.u.formatB1Info.CSIRS_BRRS_SymbIdx = 0;
5370             pdcch->dci.u.formatB1Info.CSIRS_BRRS_ProcInd = 0;
5371             pdcch->dci.u.formatB1Info.xPUCCH_TxTiming = 0;
5372             //TODO_SID: Need to update
5373             pdcch->dci.u.formatB1Info.freqResIdx_xPUCCH = 0;
5374             pdcch->dci.u.formatB1Info.beamSwitch  = 0;
5375             pdcch->dci.u.formatB1Info.SRS_Config = 0;
5376             pdcch->dci.u.formatB1Info.SRS_Symbol = 0;
5377             //TODO_SID: Need to check.Currently setting 0(1 layer, ports(8) w/o OCC).
5378             pdcch->dci.u.formatB1Info.AntPorts_numLayers = 0;
5379             pdcch->dci.u.formatB1Info.SCID = rbAllocInfo->tbInfo[0].cmnGrnt.SCID;
5380             //TODO_SID: Hardcoding TPC command to 1 i.e. No change
5381             pdcch->dci.u.formatB1Info.tpcCmd = 1; //tpc;
5382             pdcch->dci.u.formatB1Info.DL_PCRS = 0;
5383
5384             break; /* case TFU_DCI_FORMAT_B1: */
5385          }
5386
5387       case TFU_DCI_FORMAT_B2:
5388          {
5389             //printf(" RG_5GTF:: Pdcch filling with DCI format B2\n");
5390             /* ToDo: Anoop */
5391             break; /* case TFU_DCI_FORMAT_B2: */
5392          }
5393 #endif
5394       case TFU_DCI_FORMAT_1A:
5395          pdcch->dci.u.format1aInfo.isPdcchOrder = FALSE;
5396
5397          /*Nprb indication at PHY for common Ch
5398           *setting least significant bit of tpc field to 1 if
5399           nPrb=3 and 0 otherwise. */
5400          if (rbAllocInfo->nPrb == 3)
5401          {
5402             pdcch->dci.u.format1aInfo.t.pdschInfo.tpcCmd  = 1;
5403          }
5404          else
5405          {
5406             pdcch->dci.u.format1aInfo.t.pdschInfo.tpcCmd  = 0;
5407          }
5408          pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.nGap2.pres = NOTPRSNT;
5409          pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.isLocal = TRUE;
5410          pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.mcs     = \
5411                                                                    rbAllocInfo->tbInfo[0].imcs;
5412          pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.ndi     = 0;
5413          pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.rv      = 0;
5414          /* Add RIV CALC */
5415          pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.alloc.type =
5416             TFU_ALLOC_TYPE_RIV;
5417          pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.alloc.u.riv =
5418             rgSCHCmnCalcRiv (cell->bwCfg.dlTotalBw,
5419                   rbAllocInfo->allocInfo.raType2.rbStart,
5420                   rbAllocInfo->allocInfo.raType2.numRb);
5421
5422 #ifdef LTE_TDD
5423          pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.harqProcId.pres = \
5424                                                                            FALSE;
5425 #ifdef TFU_TDD
5426          pdcch->dci.u.format1aInfo.t.pdschInfo.dai.pres = TRUE;
5427          pdcch->dci.u.format1aInfo.t.pdschInfo.dai.val = 1;
5428 #endif
5429 #endif
5430          break; /* case TFU_DCI_FORMAT_1A: */
5431       case TFU_DCI_FORMAT_1:
5432          pdcch->dci.u.format1Info.tpcCmd = 0;
5433          /* Avoiding this check,as we dont support Type1 RA */
5434 #ifdef RG_UNUSED
5435          if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE0)
5436          {
5437 #endif
5438             pdcch->dci.u.format1Info.allocInfo.isAllocType0 = TRUE;
5439             pdcch->dci.u.format1Info.allocInfo.resAllocMap[0] =
5440                ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 24)
5441                 & 0xff);
5442             pdcch->dci.u.format1Info.allocInfo.resAllocMap[1] =
5443                ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 16)
5444                 & 0x00ff);
5445             pdcch->dci.u.format1Info.allocInfo.resAllocMap[2] =
5446                ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 8)
5447                 & 0x0000ff);
5448             pdcch->dci.u.format1Info.allocInfo.resAllocMap[3] =
5449                ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask & 0x000000ff));
5450 #ifdef RG_UNUSED
5451          }
5452 #endif
5453          pdcch->dci.u.format1Info.allocInfo.harqProcId = 0;
5454          pdcch->dci.u.format1Info.allocInfo.ndi = 0;
5455          pdcch->dci.u.format1Info.allocInfo.mcs = rbAllocInfo->tbInfo[0].imcs;
5456          pdcch->dci.u.format1Info.allocInfo.rv = 0;
5457 #ifdef TFU_TDD
5458          pdcch->dci.u.format1Info.dai = 1;
5459 #endif
5460          break;
5461       default:
5462          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Allocator's icorrect "
5463             "dciForamt Fill RNTI:%d",rbAllocInfo->rnti);
5464          break;
5465    }
5466    RETVOID;
5467 }
5468
5469 #ifdef LTE_TDD
5470 /**
5471  * @brief This function finds whether the subframe is special subframe or not.
5472  *
5473  * @details
5474  *
5475  *     Function: rgSCHCmnIsSplSubfrm
5476  *     Purpose:  This function finds the subframe index of the special subframe
5477  *               and finds whether the current DL index matches it or not.
5478  *
5479  *     Invoked by: Scheduler
5480  *
5481  *  @param[in] U8                   splfrmCnt
5482  *  @param[in] U8                   curSubfrmIdx
5483  *  @param[in] U8                   periodicity
5484  *  @param[in] RgSchTddSubfrmInfo   *subfrmInfo
5485  *  @return  Bool
5486  *
5487  **/
5488 #ifdef ANSI
5489 PRIVATE Bool rgSCHCmnIsSplSubfrm
5490 (
5491 U8                   splfrmCnt,
5492 U8                   curSubfrmIdx,
5493 U8                   periodicity,
5494 RgSchTddSubfrmInfo   *subfrmInfo
5495 )
5496 #else
5497 PRIVATE Bool rgSCHCmnIsSplSubfrm(splfrmCnt, curSubfrmIdx, periodicity, subfrmInfo)
5498 U8                   splfrmCnt;
5499 U8                   curSubfrmIdx;
5500 U8                   periodicity;
5501 RgSchTddSubfrmInfo   *subfrmInfo;
5502 #endif
5503 {
5504    U8 dlSfCnt = 0;
5505    U8 splfrmIdx  = 0;
5506
5507
5508    if(splfrmCnt > 0)
5509    {
5510       if(periodicity == RG_SCH_CMN_5_MS_PRD)
5511       {
5512          if(splfrmCnt%2)
5513          {
5514             dlSfCnt = ((splfrmCnt-1)/2) *\
5515                       (subfrmInfo->numFrmHf1 + subfrmInfo->numFrmHf2);
5516             dlSfCnt = dlSfCnt + subfrmInfo->numFrmHf1;
5517          }
5518          else
5519          {
5520             dlSfCnt = (splfrmCnt/2) * \
5521                       (subfrmInfo->numFrmHf1 + subfrmInfo->numFrmHf2);
5522          }
5523       }
5524       else
5525       {
5526          dlSfCnt = splfrmCnt * subfrmInfo->numFrmHf1;
5527       }
5528       splfrmIdx = RG_SCH_CMN_SPL_SUBFRM_1 +\
5529                   (periodicity*splfrmCnt - dlSfCnt);
5530    }
5531    else
5532    {
5533       splfrmIdx = RG_SCH_CMN_SPL_SUBFRM_1;
5534    }
5535
5536    if(splfrmIdx == curSubfrmIdx)
5537    {
5538       return (TRUE);
5539    }
5540
5541    return (FALSE);
5542 }
5543
5544 /**
5545  * @brief This function updates DAI or UL index.
5546  *
5547  * @details
5548  *
5549  *     Function: rgSCHCmnUpdHqAndDai
5550  *     Purpose:  Updates the DAI based on UL-DL Configuration
5551  *               index and UE. It also updates the HARQ feedback
5552  *               time and 'm' index.
5553  *
5554  *     Invoked by: TOM
5555  *
5556  *  @param[in]  RgDlHqProcCb  *hqP
5557  *  @param[in]  RgSchDlSf     *subFrm
5558  *  @param[in]  RgSchDlHqTbCb *tbCb
5559  *  @param[in]  U8            tbAllocIdx
5560  *  @return  Void
5561  *
5562  **/
5563 #ifdef ANSI
5564 PRIVATE Void rgSCHCmnUpdHqAndDai
5565 (
5566 RgSchDlHqProcCb   *hqP,
5567 RgSchDlSf         *subFrm,
5568 RgSchDlHqTbCb     *tbCb,
5569 U8                tbAllocIdx
5570 )
5571 #else
5572 PRIVATE Void rgSCHCmnUpdHqAndDai(hqP, subFrm, tbCb,tbAllocIdx)
5573 RgSchDlHqProcCb   *hqP;
5574 RgSchDlSf         *subFrm;
5575 RgSchDlHqTbCb     *tbCb;
5576 U8                tbAllocIdx;
5577 #endif
5578 {
5579    RgSchUeCb      *ue = hqP->hqE->ue;
5580    
5581
5582    if(subFrm != NULLP)
5583    {
5584       /* set the time at which UE shall send the feedback
5585        * for this process */
5586       tbCb->fdbkTime.sfn = (tbCb->timingInfo.sfn + \
5587             subFrm->dlFdbkInfo.sfnOffset) % RGSCH_MAX_SFN;
5588       tbCb->fdbkTime.subframe = subFrm->dlFdbkInfo.subframe;
5589       tbCb->m = subFrm->dlFdbkInfo.m;
5590    }
5591    else
5592    {
5593       /* set the time at which UE shall send the feedback
5594        * for this process */
5595       tbCb->fdbkTime.sfn = (tbCb->timingInfo.sfn + \
5596             hqP->subFrm->dlFdbkInfo.sfnOffset) % RGSCH_MAX_SFN;
5597       tbCb->fdbkTime.subframe = hqP->subFrm->dlFdbkInfo.subframe;
5598       tbCb->m = hqP->subFrm->dlFdbkInfo.m;
5599    }
5600
5601    /* ccpu00132340-MOD- DAI need to be updated for first TB only*/
5602    if(ue && !tbAllocIdx)
5603    {
5604       Bool   havePdcch = (tbCb->hqP->pdcch ? TRUE : FALSE);
5605       U8     dlDai;
5606       
5607       dlDai = rgSCHCmnUpdDai(ue, &tbCb->fdbkTime, tbCb->m, havePdcch,tbCb->hqP,
5608             &tbCb->dai);
5609       if(havePdcch)
5610       {/* Non SPS occasions */
5611          tbCb->hqP->pdcch->dlDai = dlDai;
5612          /* hqP->ulDai is used for N1 resource filling
5613           * when SPS occaions present in a bundle */
5614          tbCb->hqP->ulDai = tbCb->dai;
5615          tbCb->hqP->dlDai = dlDai;
5616       }
5617    }
5618
5619    /* Updatijng pucchFdbkIdx for both PUCCH or PUSCH
5620       fdbk reception */
5621    tbCb->pucchFdbkIdx = tbCb->hqP->ulDai;
5622
5623    RETVOID;
5624 }
5625
5626
5627 /**
5628  * @brief This function updates DAI or UL index.
5629  *
5630  * @details
5631  *
5632  *     Function: rgSCHCmnUpdDai
5633  *     Purpose:  Updates the DAI in the ack-nack info, a valid
5634  *               ue should be passed
5635  *
5636  *     Invoked by: TOM
5637  *
5638  *  @param[in]  RgDlHqProcCb  *hqP
5639  *  @param[in]  RgSchDlSf     *subFrm
5640  *  @param[in]  RgSchDlHqTbCb *tbCb
5641  *  @return  U8 dlDai 
5642  *
5643  **/
5644 #ifdef ANSI
5645 U8 rgSCHCmnUpdDai
5646 (
5647 RgSchUeCb         *ue,
5648 CmLteTimingInfo   *fdbkTime,
5649 U8                 m,
5650 Bool               havePdcch,
5651 RgSchDlHqProcCb   *hqP,
5652 U8                *ulDai
5653 )
5654 #else
5655 U8 rgSCHCmnUpdDai(ue, fdbkTime, m, havePdcch,tbCb,servCellId,hqP,ulDai)
5656 RgSchUeCb         *ue;
5657 CmLteTimingInfo   *fdbkTime;
5658 U8                 m;
5659 Bool               havePdcch;
5660 RgSchDlHqProcCb   *hqP;
5661 U8                *ulDai;
5662 #endif
5663 {
5664    RgSchTddANInfo *anInfo;
5665    U8             servCellIdx;
5666    U8             ackNackFdbkArrSize;
5667   
5668
5669
5670    if(hqP != NULLP)
5671    {/* Non SPS */
5672 #ifdef LTE_ADV
5673       servCellIdx = rgSchUtlGetServCellIdx(hqP->hqE->cell->instIdx,
5674             hqP->hqE->cell->cellId,
5675             ue);
5676 #else
5677      servCellIdx = RGSCH_PCELL_INDEX;
5678 #endif
5679       ackNackFdbkArrSize = hqP->hqE->cell->ackNackFdbkArrSize;
5680    }else
5681    {/* SPS on primary cell */
5682       servCellIdx = RGSCH_PCELL_INDEX;
5683       ackNackFdbkArrSize = ue->cell->ackNackFdbkArrSize;
5684    }
5685
5686
5687    anInfo = rgSCHUtlGetUeANFdbkInfo(ue, fdbkTime,servCellIdx);
5688
5689    /* If no ACK/NACK feedback already present, create a new one */
5690    if(NULLP == anInfo)
5691    {
5692       anInfo = &ue->cellInfo[servCellIdx]->anInfo[ue->cellInfo[servCellIdx]->nextFreeANIdx];
5693       anInfo->sfn = fdbkTime->sfn;
5694       anInfo->subframe = fdbkTime->subframe;
5695       anInfo->latestMIdx = m;
5696       /* Fixing DAI value - ccpu00109162 */
5697       /* Handle TDD case as in MIMO definition of the function */
5698       anInfo->ulDai = 1;
5699       if (havePdcch)
5700       {
5701          anInfo->dlDai = 1;
5702       }
5703       anInfo->isSpsOccasion = FALSE;
5704       /* set the free Index to store  Ack/Nack Information*/
5705       ue->cellInfo[servCellIdx]->nextFreeANIdx = (ue->cellInfo[servCellIdx]->nextFreeANIdx + 1) %
5706          ackNackFdbkArrSize;
5707
5708    }
5709    else
5710    {
5711       anInfo->latestMIdx = m;
5712       /* Fixing DAI value - ccpu00109162 */
5713       /* Handle TDD case as in MIMO definition of the function */
5714       anInfo->ulDai = anInfo->ulDai + 1;
5715       if (havePdcch)
5716       {
5717          anInfo->dlDai = anInfo->dlDai + 1;
5718       }
5719    }
5720 #ifdef LTE_ADV
5721    /* ignoring the Scell check,
5722     * for primary cell this field is unused*/
5723    if(hqP != NULLP)
5724    {/* SPS*/
5725       anInfo->n1ResTpcIdx = hqP->tpc;
5726    }
5727
5728    if(ulDai)
5729    {/* As this not required for release pdcch */
5730       *ulDai = anInfo->ulDai;
5731    }
5732 #endif
5733    return (anInfo->dlDai);
5734
5735 }
5736 #endif /* ifdef LTE_TDD */
5737
5738 U32 rgHqRvRetxCnt[4][2];
5739 U32 rgUlrate_grant;
5740
5741 /**
5742  * @brief This function fills the HqP TB with rbAllocInfo.
5743  *
5744  * @details
5745  *
5746  *     Function: rgSCHCmnFillHqPTb
5747  *     Purpose:  This function fills in the HqP TB with rbAllocInfo.
5748  *
5749  *     Invoked by: rgSCHCmnFillHqPTb
5750  *
5751  *  @param[in]  RgSchCellCb*      cell
5752  *  @param[in]  RgSchDlRbAlloc    *rbAllocInfo,
5753  *  @param[in]  U8                tbAllocIdx
5754  *  @param[in]  RgSchPdcch        *pdcch
5755  *  @return  Void
5756  *
5757  **/
5758 #ifdef LTEMAC_SPS
5759 #ifdef ANSI
5760 Void rgSCHCmnFillHqPTb
5761 (
5762 RgSchCellCb                *cell,
5763 RgSchDlRbAlloc             *rbAllocInfo,
5764 U8                         tbAllocIdx,
5765 RgSchPdcch                 *pdcch
5766 )
5767 #else
5768 Void rgSCHCmnFillHqPTb(cell, rbAllocInfo, tbAllocIdx, pdcch)
5769 RgSchCellCb                *cell;
5770 RgSchDlRbAlloc             *rbAllocInfo;
5771 U8                         tbAllocIdx;
5772 RgSchPdcch                 *pdcch;
5773 #endif
5774 #else
5775 #ifdef ANSI
5776 PRIVATE Void rgSCHCmnFillHqPTb
5777 (
5778 RgSchCellCb                *cell,
5779 RgSchDlRbAlloc             *rbAllocInfo,
5780 U8                         tbAllocIdx,
5781 RgSchPdcch                 *pdcch
5782 )
5783 #else
5784 PRIVATE Void rgSCHCmnFillHqPTb(cell, rbAllocInfo, tbAllocIdx, pdcch)
5785 RgSchCellCb                *cell;
5786 RgSchDlRbAlloc             *rbAllocInfo;
5787 U8                         tbAllocIdx;
5788 RgSchPdcch                 *pdcch;
5789 #endif
5790 #endif /* LTEMAC_SPS */
5791 {
5792    RgSchCmnDlCell     *cmnCellDl = RG_SCH_CMN_GET_DL_CELL(cell);
5793    RgSchDlTbAllocInfo *tbAllocInfo = &rbAllocInfo->tbInfo[tbAllocIdx];
5794    RgSchDlHqTbCb      *tbInfo = tbAllocInfo->tbCb;
5795    RgSchDlHqProcCb    *hqP = tbInfo->hqP;
5796
5797
5798    /*ccpu00120365-ADD-if tb is disabled, set mcs=0,rv=1.
5799     * Relevant for DCI format 2 & 2A as per 36.213-7.1.7.2
5800     */
5801    if ( tbAllocInfo->isDisabled)
5802    {
5803
5804       tbInfo->dlGrnt.iMcs = 0;
5805       tbInfo->dlGrnt.rv   = 1;
5806    }
5807    /* Fill for TB retransmission */
5808    else if (tbInfo->txCntr > 0)
5809    {
5810
5811       tbInfo->timingInfo = cmnCellDl->time;
5812       /* Fix */
5813       if ((tbInfo->isAckNackDtx == TFU_HQFDB_DTX)) 
5814       {
5815          tbInfo->dlGrnt.iMcs = tbAllocInfo->imcs;         
5816          rgHqRvRetxCnt[tbInfo->dlGrnt.rv][tbInfo->tbIdx]++;
5817       }
5818       else
5819       {
5820          tbInfo->dlGrnt.rv = rgSchCmnDlRvTbl[++(tbInfo->ccchSchdInfo.rvIdx) & 0x03];
5821       }
5822
5823       /* fill the scheduler information of hqProc */
5824       tbInfo->ccchSchdInfo.totBytes = tbAllocInfo->bytesAlloc;
5825       RGSCH_ARRAY_BOUND_CHECK(cell->instIdx,hqP->tbInfo,tbInfo->tbIdx );
5826       rgSCHDhmHqTbRetx(hqP->hqE, tbInfo->timingInfo, hqP, tbInfo->tbIdx);
5827    }
5828    /* Fill for TB transmission */
5829    else
5830    {
5831       /* Fill the HqProc */
5832       tbInfo->dlGrnt.iMcs = tbAllocInfo->imcs;
5833       tbInfo->tbSz = tbAllocInfo->bytesAlloc;
5834       tbInfo->timingInfo = cmnCellDl->time;
5835
5836       tbInfo->dlGrnt.rv = rgSchCmnDlRvTbl[0];
5837       /* fill the scheduler information of hqProc */
5838       tbInfo->ccchSchdInfo.rvIdx = 0;
5839       tbInfo->ccchSchdInfo.totBytes = tbAllocInfo->bytesAlloc;
5840       /* DwPts Scheduling Changes Start */
5841       /* DwPts Scheduling Changes End */ 
5842       cell->measurements.dlBytesCnt += tbAllocInfo->bytesAlloc;
5843    }
5844
5845    /*ccpu00120365:-ADD-only add to subFrm list if tb is not disabled */
5846    if ( tbAllocInfo->isDisabled == FALSE )
5847    {
5848       /* Set the number of transmitting SM layers for this TB */
5849       tbInfo->numLyrs = tbAllocInfo->noLyr;
5850       /* Set the TB state as WAITING to indicate TB has been
5851        * considered for transmission */
5852       tbInfo->state  = HQ_TB_WAITING;
5853       hqP->subFrm = rbAllocInfo->dlSf;
5854       tbInfo->hqP->pdcch  = pdcch;
5855       //tbInfo->dlGrnt.numRb = rbAllocInfo->rbsAlloc;
5856       rgSCHUtlDlHqPTbAddToTx(hqP->subFrm, hqP, tbInfo->tbIdx);
5857    }
5858    RETVOID;
5859 }
5860
5861 /**
5862  * @brief This function fills the PDCCH DCI format 2 information from dlProc.
5863  *
5864  * @details
5865  *
5866  *     Function: rgSCHCmnFillHqPPdcchDciFrmt2
5867  *     Purpose:  This function fills in the PDCCH information
5868  *               obtained from the RgSchDlHqProcCb and RgSchDlRbAlloc
5869  *               for dedicated service scheduling. It also
5870  *               obtains TPC to be filled in from the power module.
5871  *               Assign the PDCCH to HQProc.
5872  *
5873  *     Invoked by: Downlink Scheduler
5874  *
5875  *  @param[in]  RgSchCellCb*      cell
5876  *  @param[in]  RgSchDlRbAlloc*   rbAllocInfo
5877  *  @param[in]  RgDlHqProc*       hqP
5878  *  @param[out]  RgSchPdcch        *pdcch
5879  *  @param[in]   U8               tpc
5880  *  @return  Void
5881  *
5882  **/
5883 #ifdef ANSI
5884 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmtB1B2
5885 (
5886 RgSchCellCb                *cell,
5887 RgSchDlRbAlloc             *rbAllocInfo,
5888 RgSchDlHqProcCb            *hqP,
5889 RgSchPdcch                 *pdcch,
5890 U8                         tpc
5891 )
5892 #else
5893 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmtB1B2(cell, rbAllocInfo, hqP, pdcch, tpc)
5894 RgSchCellCb                *cell;
5895 RgSchDlRbAlloc             *rbAllocInfo;
5896 RgSchDlHqProcCb            *hqP;
5897 RgSchPdcch                 *pdcch;
5898 U8                         tpc;
5899 #endif
5900 {
5901
5902
5903    rgSCHCmnFillHqPTb(cell, rbAllocInfo, 0, pdcch);   
5904    //Currently hardcoding values here.
5905    //printf("Filling 5GTF UL DCI for rnti %d \n",alloc->rnti);
5906    switch(rbAllocInfo->dciFormat)
5907    {
5908       case TFU_DCI_FORMAT_B1:
5909          {
5910             pdcch->dci.u.formatB1Info.formatType = 0;
5911             pdcch->dci.u.formatB1Info.xPDSCHRange = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.xPDSCHRange;
5912             pdcch->dci.u.formatB1Info.RBAssign = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.rbAssign;
5913             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.hqProcId = hqP->procId;
5914             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.mcs = rbAllocInfo->tbInfo[0].imcs;
5915             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.ndi = rbAllocInfo->tbInfo[0].tbCb->ndi;
5916             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.RV = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.rv;
5917             pdcch->dci.u.formatB1Info.u.rbAssignB1Val324.bmiHqAckNack = 0;
5918             pdcch->dci.u.formatB1Info.CSI_BSI_BRI_Req = 0;
5919             pdcch->dci.u.formatB1Info.CSIRS_BRRS_TxTiming = 0;
5920             pdcch->dci.u.formatB1Info.CSIRS_BRRS_SymbIdx = 0;
5921             pdcch->dci.u.formatB1Info.CSIRS_BRRS_ProcInd = 0;
5922             pdcch->dci.u.formatB1Info.xPUCCH_TxTiming = 0;
5923             //TODO_SID: Need to update
5924             pdcch->dci.u.formatB1Info.freqResIdx_xPUCCH = 0;
5925             pdcch->dci.u.formatB1Info.beamSwitch  = 0;
5926             pdcch->dci.u.formatB1Info.SRS_Config = 0;
5927             pdcch->dci.u.formatB1Info.SRS_Symbol = 0;
5928             //TODO_SID: Need to check.Currently setting 0(1 layer, ports(8) w/o OCC).
5929             pdcch->dci.u.formatB1Info.AntPorts_numLayers = 0;
5930             pdcch->dci.u.formatB1Info.SCID = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.SCID;
5931             //TODO_SID: Hardcoding TPC command to 1 i.e. No change
5932             pdcch->dci.u.formatB1Info.tpcCmd = 1; //tpc;
5933             pdcch->dci.u.formatB1Info.DL_PCRS = 0;
5934             break;
5935          }
5936       case TFU_DCI_FORMAT_B2:
5937          {
5938             pdcch->dci.u.formatB2Info.formatType = 1;
5939             pdcch->dci.u.formatB2Info.xPDSCHRange = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.xPDSCHRange;
5940             pdcch->dci.u.formatB2Info.RBAssign = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.rbAssign;
5941             pdcch->dci.u.formatB2Info.u.rbAssignB1Val324.hqProcId = hqP->procId;
5942             pdcch->dci.u.formatB2Info.u.rbAssignB1Val324.mcs = rbAllocInfo->tbInfo[0].imcs;
5943             pdcch->dci.u.formatB2Info.u.rbAssignB1Val324.ndi = rbAllocInfo->tbInfo[0].tbCb->ndi;
5944             pdcch->dci.u.formatB2Info.u.rbAssignB1Val324.RV = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.rv;
5945             pdcch->dci.u.formatB2Info.u.rbAssignB1Val324.bmiHqAckNack = 0;
5946             pdcch->dci.u.formatB2Info.CSI_BSI_BRI_Req = 0;
5947             pdcch->dci.u.formatB2Info.CSIRS_BRRS_TxTiming = 0;
5948             pdcch->dci.u.formatB2Info.CSIRS_BRRS_SymbIdx = 0;
5949             pdcch->dci.u.formatB2Info.CSIRS_BRRS_ProcInd = 0;
5950             pdcch->dci.u.formatB2Info.xPUCCH_TxTiming = 0;
5951             //TODO_SID: Need to update
5952             pdcch->dci.u.formatB2Info.freqResIdx_xPUCCH = 0;
5953             pdcch->dci.u.formatB2Info.beamSwitch  = 0;
5954             pdcch->dci.u.formatB2Info.SRS_Config = 0;
5955             pdcch->dci.u.formatB2Info.SRS_Symbol = 0;
5956             //TODO_SID: Need to check.Currently setting 4(2 layer, ports(8,9) w/o OCC).
5957             pdcch->dci.u.formatB2Info.AntPorts_numLayers = 4;
5958             pdcch->dci.u.formatB2Info.SCID = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.SCID;
5959             //TODO_SID: Hardcoding TPC command to 1 i.e. No change
5960             pdcch->dci.u.formatB2Info.tpcCmd = 1; //tpc;
5961             pdcch->dci.u.formatB2Info.DL_PCRS = 0;
5962             break;
5963          }
5964          default:
5965             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId," 5GTF_ERROR Allocator's icorrect "
5966                "dciForamt Fill RNTI:%d",rbAllocInfo->rnti);
5967             break;
5968    }
5969    
5970    RETVOID;
5971 }
5972
5973 extern U32 totPcellSCell;
5974 extern U32 addedForScell;
5975 extern U32 addedForScell1;
5976 extern U32 addedForScell2;
5977 /**
5978  * @brief This function fills the PDCCH information from dlProc.
5979  *
5980  * @details
5981  *
5982  *     Function: rgSCHCmnFillHqPPdcch
5983  *     Purpose:  This function fills in the PDCCH information
5984  *               obtained from the RgSchDlHqProcCb and RgSchDlRbAlloc
5985  *               for dedicated service scheduling. It also
5986  *               obtains TPC to be filled in from the power module.
5987  *               Assign the PDCCH to HQProc.
5988  *
5989  *     Invoked by: Downlink Scheduler
5990  *
5991  *  @param[in]  RgSchCellCb*      cell
5992  *  @param[in]  RgSchDlRbAlloc*   rbAllocInfo
5993  *  @param[in]  RgDlHqProc*       hqP
5994  *  @return  Void
5995  *
5996  **/
5997 #ifdef ANSI
5998 Void rgSCHCmnFillHqPPdcch
5999 (
6000 RgSchCellCb                *cell,
6001 RgSchDlRbAlloc             *rbAllocInfo,
6002 RgSchDlHqProcCb            *hqP
6003 )
6004 #else
6005 Void rgSCHCmnFillHqPPdcch(cell, rbAllocInfo, hqP)
6006 RgSchCellCb                *cell;
6007 RgSchDlRbAlloc             *rbAllocInfo;
6008 RgSchDlHqProcCb            *hqP;
6009 #endif
6010 {
6011    RgSchCmnDlCell     *cmnCell = RG_SCH_CMN_GET_DL_CELL(cell);
6012    RgSchPdcch         *pdcch = rbAllocInfo->pdcch;
6013    U8                 tpc = 1;
6014
6015
6016    if (hqP->hqE->ue)
6017    {
6018 #ifdef LTE_ADV
6019       if(RG_SCH_IS_CELL_SEC(hqP->hqE->ue, cell))
6020       {
6021          tpc = hqP->tpc;
6022       }
6023       else
6024 #endif
6025       {
6026          tpc = rgSCHPwrPucchTpcForUe(cell, hqP->hqE->ue);
6027       }
6028       /* Fix: syed moving this to a common function for both scheduled
6029        * and non-scheduled UEs */
6030
6031       pdcch->ue = hqP->hqE->ue;
6032       if (hqP->hqE->ue->csgMmbrSta == FALSE)
6033       {
6034          cmnCell->ncsgPrbCnt += rbAllocInfo->rbsAlloc;
6035       }
6036       cmnCell->totPrbCnt += rbAllocInfo->rbsAlloc;
6037 #ifdef TENB_STATS
6038       {
6039          hqP->hqE->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(hqP->hqE->cell)].dlPrbUsg += 
6040             rbAllocInfo->rbsAlloc;
6041          hqP->hqE->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(hqP->hqE->cell)].dlSumCw0iTbs += 
6042             rbAllocInfo->tbInfo[0].iTbs;
6043          hqP->hqE->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(hqP->hqE->cell)].dlNumCw0iTbs ++; 
6044          hqP->hqE->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(hqP->hqE->cell)].dlTpt +=
6045             (rbAllocInfo->tbInfo[0].bytesAlloc << 3);
6046
6047 #ifdef LTE_ADV
6048       totPcellSCell += (rbAllocInfo->tbInfo[0].bytesAlloc << 3);
6049       if(RG_SCH_IS_CELL_SEC(hqP->hqE->ue, cell))
6050       {
6051          addedForScell +=  (rbAllocInfo->tbInfo[0].bytesAlloc << 3);
6052          addedForScell1 += (rbAllocInfo->tbInfo[0].bytesAlloc << 3);
6053 /*
6054          printf (" Hqp %d cell %d addedForScell %lu addedForScell1 %lu sfn:sf %d:%d \n",
6055          hqP->procId,
6056          hqP->hqE->cell->cellId,
6057          addedForScell,
6058          addedForScell1,
6059          cell->crntTime.sfn,
6060          cell->crntTime.slot);
6061          */
6062       }
6063 #endif
6064          hqP->hqE->cell->tenbStats->sch.dlPrbUsage[0] += 
6065             rbAllocInfo->rbsAlloc;
6066          hqP->hqE->cell->tenbStats->sch.dlSumCw0iTbs += 
6067             rbAllocInfo->tbInfo[0].iTbs;
6068          hqP->hqE->cell->tenbStats->sch.dlNumCw0iTbs ++; 
6069          hqP->hqE->cell->tenbStats->sch.dlTtlTpt +=
6070             (rbAllocInfo->tbInfo[0].bytesAlloc << 3); 
6071          if (rbAllocInfo->tbInfo[1].schdlngForTb)
6072          {
6073             hqP->hqE->cell->tenbStats->sch.dlSumCw1iTbs += 
6074                rbAllocInfo->tbInfo[1].iTbs;
6075             hqP->hqE->cell->tenbStats->sch.dlNumCw1iTbs ++; 
6076             hqP->hqE->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(hqP->hqE->cell)].dlSumCw1iTbs += 
6077                rbAllocInfo->tbInfo[1].iTbs;
6078             hqP->hqE->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(hqP->hqE->cell)].dlNumCw1iTbs ++; 
6079             hqP->hqE->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(hqP->hqE->cell)].dlTpt +=
6080                (rbAllocInfo->tbInfo[1].bytesAlloc << 3);
6081
6082
6083 #ifdef LTE_ADV
6084             if(RG_SCH_IS_CELL_SEC(hqP->hqE->ue, cell))
6085             {
6086                addedForScell +=  (rbAllocInfo->tbInfo[1].bytesAlloc << 3);
6087                addedForScell2 += (rbAllocInfo->tbInfo[1].bytesAlloc << 3);
6088 /*
6089          printf (" Hqp %d cell %d addedForScell %lu addedForScell2 %lu \n",
6090          hqP->procId,
6091          hqP->hqE->cell->cellId,
6092          addedForScell,
6093          addedForScell2);
6094          */
6095             }
6096             totPcellSCell += (rbAllocInfo->tbInfo[1].bytesAlloc << 3);
6097 #endif
6098
6099
6100             hqP->hqE->cell->tenbStats->sch.dlTtlTpt +=
6101                (rbAllocInfo->tbInfo[1].bytesAlloc << 3);
6102          }
6103          /*
6104          printf ("add DL TPT is %lu  sfn:sf %d:%d \n", hqP->hqE->ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(hqP->hqE->cell)].dlTpt ,
6105          cell->crntTime.sfn,
6106          cell->crntTime.slot);
6107          */
6108       }
6109 #endif
6110    }
6111
6112    pdcch->rnti                       = rbAllocInfo->rnti;
6113    pdcch->dci.dciFormat              = rbAllocInfo->dciFormat;
6114    /* Update subframe and pdcch info in HqTb control block */
6115    switch(rbAllocInfo->dciFormat)
6116    {
6117 #ifdef RG_5GTF  
6118       case TFU_DCI_FORMAT_B1:
6119       case TFU_DCI_FORMAT_B2:
6120            {
6121         // printf(" RG_5GTF:: Pdcch filling with DCI format B1/B2\n");
6122               rgSCHCmnFillHqPPdcchDciFrmtB1B2(cell, rbAllocInfo, hqP, \
6123                     pdcch, tpc);
6124               break;
6125            }
6126 #endif
6127       default:
6128          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
6129             "Allocator's incorrect dciForamt Fill for RNTI:%d",rbAllocInfo->rnti);
6130          break;
6131    }
6132    RETVOID;
6133 }
6134 #ifdef UNUSED_FUNC
6135 /**
6136  * @brief This function fills the PDCCH DCI format 1 information from dlProc.
6137  *
6138  * @details
6139  *
6140  *     Function: rgSCHCmnFillHqPPdcchDciFrmt1
6141  *     Purpose:  This function fills in the PDCCH information
6142  *               obtained from the RgSchDlHqProcCb and RgSchDlRbAlloc
6143  *               for dedicated service scheduling. It also
6144  *               obtains TPC to be filled in from the power module.
6145  *               Assign the PDCCH to HQProc.
6146  *
6147  *     Invoked by: Downlink Scheduler
6148  *
6149  *  @param[in]  RgSchCellCb*      cell
6150  *  @param[in]  RgSchDlRbAlloc*   rbAllocInfo
6151  *  @param[in]  RgDlHqProc*       hqP
6152  *  @param[out]  RgSchPdcch        *pdcch
6153  *  @param[in]   U8               tpc
6154  *  @return  Void
6155  *
6156  **/
6157
6158 #ifdef ANSI
6159 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt1
6160 (
6161 RgSchCellCb                *cell,
6162 RgSchDlRbAlloc             *rbAllocInfo,
6163 RgSchDlHqProcCb            *hqP,
6164 RgSchPdcch                 *pdcch,
6165 U8                         tpc
6166 )
6167 #else
6168 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt1(cell, rbAllocInfo, hqP, pdcch, tpc)
6169 RgSchCellCb                *cell;
6170 RgSchDlRbAlloc             *rbAllocInfo;
6171 RgSchDlHqProcCb            *hqP;
6172 RgSchPdcch                 *pdcch;
6173 U8                         tpc;
6174 #endif
6175 {
6176
6177 #ifdef LTE_TDD
6178    RgSchTddANInfo     *anInfo;
6179 #endif
6180
6181 #ifdef LTEMAC_SPS
6182 /* For activation or reactivation,
6183  * Harq ProcId should be 0 */
6184    RgSchCmnDlHqProc *cmnHqDl = RG_SCH_CMN_GET_DL_HQP(hqP);
6185 #endif
6186
6187
6188     rgSCHCmnFillHqPTb(cell, rbAllocInfo, 0, pdcch);
6189     pdcch->dci.u.format1Info.tpcCmd = tpc;
6190      /* Avoiding this check,as we dont support Type1 RA */
6191 #ifdef RG_UNUSED
6192     if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE0)
6193     {
6194 #endif
6195        pdcch->dci.u.format1Info.allocInfo.isAllocType0 = TRUE;
6196        pdcch->dci.u.format1Info.allocInfo.resAllocMap[0] =
6197          ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 24)
6198                & 0xff);
6199        pdcch->dci.u.format1Info.allocInfo.resAllocMap[1] =
6200          ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 16)
6201                & 0x00ff);
6202        pdcch->dci.u.format1Info.allocInfo.resAllocMap[2] =
6203            ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 8)
6204                & 0x0000ff);
6205        pdcch->dci.u.format1Info.allocInfo.resAllocMap[3] =
6206            ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask & 0x000000ff));
6207 #ifdef RG_UNUSED
6208     }
6209 #endif
6210 #ifdef LTEMAC_SPS
6211     if ((!(hqP->tbInfo[0].txCntr)) &&
6212        (cmnHqDl != (RgSchCmnDlHqProc*)NULLP  &&
6213          ((cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_ACTV) ||
6214          (cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_REACTV)))
6215        )
6216     {
6217        pdcch->dci.u.format1Info.allocInfo.harqProcId = 0;
6218     }
6219     else
6220     {
6221       pdcch->dci.u.format1Info.allocInfo.harqProcId = hqP->procId;
6222     }
6223 #else
6224     pdcch->dci.u.format1Info.allocInfo.harqProcId = hqP->procId;
6225 #endif
6226
6227     pdcch->dci.u.format1Info.allocInfo.ndi = 
6228                         rbAllocInfo->tbInfo[0].tbCb->ndi;
6229     pdcch->dci.u.format1Info.allocInfo.mcs = 
6230                         rbAllocInfo->tbInfo[0].imcs;
6231     pdcch->dci.u.format1Info.allocInfo.rv = 
6232                         rbAllocInfo->tbInfo[0].tbCb->dlGrnt.rv;
6233 #ifdef LTE_TDD
6234        if(hqP->hqE->ue != NULLP)
6235        {
6236 #ifdef LTE_ADV
6237            U8 servCellIdx = rgSchUtlGetServCellIdx(hqP->hqE->cell->instIdx,
6238                                         hqP->hqE->cell->cellId,
6239                                         hqP->hqE->ue);
6240
6241            anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6242                             &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),servCellIdx);
6243 #else
6244            anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6245                             &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),0);
6246 #endif
6247 #ifdef TFU_TDD
6248           if(anInfo)
6249           {
6250              pdcch->dci.u.format1Info.dai = RG_SCH_GET_DAI_VALUE(anInfo->dlDai);
6251           }
6252           else
6253           {
6254                /* Fixing DAI value - ccpu00109162 */
6255              pdcch->dci.u.format1Info.dai = RG_SCH_MAX_DAI_IDX;
6256           }
6257 #endif
6258        }
6259        else
6260        {
6261             /* always 0 for RACH */
6262            pdcch->dci.u.format1Info.allocInfo.harqProcId = 0;
6263 #ifdef TFU_TDD
6264             /* Fixing DAI value - ccpu00109162 */
6265            pdcch->dci.u.format1Info.dai = 1;
6266 #endif
6267        }
6268 #endif
6269  
6270
6271        RETVOID;
6272 }
6273 /**
6274  * @brief This function fills the PDCCH DCI format 1A information from dlProc.
6275  *
6276  * @details
6277  *
6278  *     Function: rgSCHCmnFillHqPPdcchDciFrmt1A
6279  *     Purpose:  This function fills in the PDCCH information
6280  *               obtained from the RgSchDlHqProcCb and RgSchDlRbAlloc
6281  *               for dedicated service scheduling. It also
6282  *               obtains TPC to be filled in from the power module.
6283  *               Assign the PDCCH to HQProc.
6284  *
6285  *     Invoked by: Downlink Scheduler
6286  *
6287  *  @param[in]  RgSchCellCb*      cell
6288  *  @param[in]  RgSchDlRbAlloc*   rbAllocInfo
6289  *  @param[in]  RgDlHqProc*       hqP
6290  *  @param[out]  RgSchPdcch        *pdcch
6291  *  @param[in]   U8               tpc
6292  *  @return  Void
6293  *
6294  **/
6295 #ifdef ANSI
6296 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt1A
6297 (
6298 RgSchCellCb                *cell,
6299 RgSchDlRbAlloc             *rbAllocInfo,
6300 RgSchDlHqProcCb            *hqP,
6301 RgSchPdcch                 *pdcch,
6302 U8                         tpc
6303 )
6304 #else
6305 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt1A(cell, rbAllocInfo, hqP, pdcch, tpc)
6306 RgSchCellCb                *cell;
6307 RgSchDlRbAlloc             *rbAllocInfo;
6308 RgSchDlHqProcCb            *hqP;
6309 RgSchPdcch                 *pdcch;
6310 U8                         tpc;
6311 #endif
6312 {
6313
6314 #ifdef LTE_TDD
6315    RgSchTddANInfo     *anInfo;
6316 #endif
6317
6318 #ifdef LTEMAC_SPS
6319    RgSchCmnDlHqProc *cmnHqDl = RG_SCH_CMN_GET_DL_HQP(hqP);
6320 #endif
6321
6322
6323     rgSCHCmnFillHqPTb(cell, rbAllocInfo, 0, pdcch);
6324     pdcch->dci.u.format1aInfo.isPdcchOrder = FALSE;
6325     pdcch->dci.u.format1aInfo.t.pdschInfo.tpcCmd  = tpc;
6326     pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.mcs     = \
6327       rbAllocInfo->tbInfo[0].imcs;
6328     pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.harqProcId.pres = TRUE;
6329 #ifdef LTEMAC_SPS
6330     if ((!(hqP->tbInfo[0].txCntr)) &&
6331        ( cmnHqDl != (RgSchCmnDlHqProc*)NULLP  &&
6332          ((cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_ACTV) ||
6333          (cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_REACTV))
6334        ))
6335     {
6336        pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.harqProcId.val = 0;
6337     }
6338     else
6339     {
6340       pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.harqProcId.val
6341                                                 = hqP->procId;
6342     }
6343 #else
6344     pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.harqProcId.val =
6345                                               hqP->procId;
6346 #endif
6347     pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.ndi     = \
6348        rbAllocInfo->tbInfo[0].tbCb->ndi;
6349     pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.rv      = \
6350        rbAllocInfo->tbInfo[0].tbCb->dlGrnt.rv;
6351          /* As of now, we do not support Distributed allocations */
6352     pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.isLocal = TRUE;
6353     pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.nGap2.pres = NOTPRSNT;
6354     pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.alloc.type =
6355             TFU_ALLOC_TYPE_RIV;
6356     pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.alloc.u.riv =
6357     rgSCHCmnCalcRiv (cell->bwCfg.dlTotalBw,
6358                   rbAllocInfo->allocInfo.raType2.rbStart,
6359                   rbAllocInfo->allocInfo.raType2.numRb);
6360 #ifdef LTE_TDD
6361     if(hqP->hqE->ue != NULLP)
6362     {
6363 #ifdef LTE_ADV
6364        U8 servCellIdx = rgSchUtlGetServCellIdx(hqP->hqE->cell->instIdx,
6365                                         hqP->hqE->cell->cellId,
6366                                         hqP->hqE->ue);
6367        anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6368                               &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),servCellIdx);
6369 #else
6370        anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6371                               &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),0);
6372 #endif
6373 #ifdef TFU_TDD
6374        pdcch->dci.u.format1aInfo.t.pdschInfo.dai.pres = TRUE;
6375        if(anInfo)
6376        {
6377           pdcch->dci.u.format1aInfo.t.pdschInfo.dai.val = 
6378                               RG_SCH_GET_DAI_VALUE(anInfo->dlDai);
6379        }
6380        else
6381        {
6382           /* Fixing DAI value - ccpu00109162 */
6383           pdcch->dci.u.format1aInfo.t.pdschInfo.dai.val = RG_SCH_MAX_DAI_IDX;
6384           RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
6385                    "PDCCH is been scheduled without updating anInfo RNTI:%d",
6386                     rbAllocInfo->rnti);
6387        }
6388 #endif
6389     }
6390     else
6391     {
6392             /* always 0 for RACH */
6393        pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.harqProcId.pres
6394                                                                      = FALSE;
6395 #ifdef TFU_TDD
6396        pdcch->dci.u.format1aInfo.t.pdschInfo.dai.pres = TRUE;
6397             /* Fixing DAI value - ccpu00109162 */
6398        pdcch->dci.u.format1aInfo.t.pdschInfo.dai.val = 1;
6399 #endif
6400     }
6401 #endif
6402  
6403     RETVOID;
6404 }       
6405 /**
6406  * @brief This function fills the PDCCH DCI format 1B information from dlProc.
6407  *
6408  * @details
6409  *
6410  *     Function: rgSCHCmnFillHqPPdcchDciFrmt1B
6411  *     Purpose:  This function fills in the PDCCH information
6412  *               obtained from the RgSchDlHqProcCb and RgSchDlRbAlloc
6413  *               for dedicated service scheduling. It also
6414  *               obtains TPC to be filled in from the power module.
6415  *               Assign the PDCCH to HQProc.
6416  *
6417  *     Invoked by: Downlink Scheduler
6418  *
6419  *  @param[in]  RgSchCellCb*      cell
6420  *  @param[in]  RgSchDlRbAlloc*   rbAllocInfo
6421  *  @param[in]  RgDlHqProc*       hqP
6422  *  @param[out]  RgSchPdcch        *pdcch
6423  *  @param[in]   U8               tpc
6424  *  @return  Void
6425  *
6426  **/
6427 #ifdef ANSI
6428 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt1B
6429 (
6430 RgSchCellCb                *cell,
6431 RgSchDlRbAlloc             *rbAllocInfo,
6432 RgSchDlHqProcCb            *hqP,
6433 RgSchPdcch                 *pdcch,
6434 U8                         tpc
6435 )
6436 #else
6437 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt1B(cell, rbAllocInfo, hqP, pdcch, tpc)
6438 RgSchCellCb                *cell;
6439 RgSchDlRbAlloc             *rbAllocInfo;
6440 RgSchDlHqProcCb            *hqP;
6441 RgSchPdcch                 *pdcch;
6442 U8                         tpc;
6443 #endif
6444 {
6445
6446 #ifdef LTE_TDD
6447    RgSchTddANInfo     *anInfo;
6448 #endif
6449
6450 #ifdef LTEMAC_SPS
6451    RgSchCmnDlHqProc *cmnHqDl = RG_SCH_CMN_GET_DL_HQP(hqP);
6452 #endif
6453
6454
6455     rgSCHCmnFillHqPTb(cell, rbAllocInfo, 0, pdcch);
6456     pdcch->dci.u.format1bInfo.tpcCmd  = tpc;
6457     pdcch->dci.u.format1bInfo.allocInfo.mcs     = \
6458            rbAllocInfo->tbInfo[0].imcs;
6459 #ifdef LTEMAC_SPS
6460     if ((!(hqP->tbInfo[0].txCntr)) &&
6461        ( cmnHqDl != (RgSchCmnDlHqProc*)NULLP  &&
6462          ((cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_ACTV) ||
6463          (cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_REACTV))
6464        ))
6465     {
6466        pdcch->dci.u.format1bInfo.allocInfo.harqProcId = 0;
6467     }
6468     else
6469     {
6470       pdcch->dci.u.format1bInfo.allocInfo.harqProcId = hqP->procId;
6471     }
6472 #else
6473     pdcch->dci.u.format1bInfo.allocInfo.harqProcId = hqP->procId;
6474 #endif
6475     pdcch->dci.u.format1bInfo.allocInfo.ndi     = \
6476           rbAllocInfo->tbInfo[0].tbCb->ndi;
6477     pdcch->dci.u.format1bInfo.allocInfo.rv      = \
6478            rbAllocInfo->tbInfo[0].tbCb->dlGrnt.rv;
6479          /* As of now, we do not support Distributed allocations */
6480     pdcch->dci.u.format1bInfo.allocInfo.isLocal = TRUE;
6481     pdcch->dci.u.format1bInfo.allocInfo.nGap2.pres = NOTPRSNT;
6482     pdcch->dci.u.format1bInfo.allocInfo.alloc.type =
6483             TFU_ALLOC_TYPE_RIV;
6484     pdcch->dci.u.format1bInfo.allocInfo.alloc.u.riv =
6485     rgSCHCmnCalcRiv (cell->bwCfg.dlTotalBw,
6486                   rbAllocInfo->allocInfo.raType2.rbStart,
6487                   rbAllocInfo->allocInfo.raType2.numRb);
6488          /* Fill precoding Info */
6489     pdcch->dci.u.format1bInfo.allocInfo.pmiCfm = \
6490                rbAllocInfo->mimoAllocInfo.precIdxInfo >> 4;
6491     pdcch->dci.u.format1bInfo.allocInfo.tPmi   = \
6492                rbAllocInfo->mimoAllocInfo.precIdxInfo & 0x0F;
6493 #ifdef LTE_TDD
6494     if(hqP->hqE->ue != NULLP)
6495     {
6496 #ifdef LTE_ADV
6497        U8 servCellIdx = rgSchUtlGetServCellIdx(hqP->hqE->cell->instIdx,
6498                                         hqP->hqE->cell->cellId,
6499                                         hqP->hqE->ue);
6500        anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6501              &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),servCellIdx);
6502 #else
6503        anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6504              &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),0);
6505 #endif
6506 #ifdef TFU_TDD
6507        if(anInfo)
6508        {
6509           pdcch->dci.u.format1bInfo.dai = 
6510                          RG_SCH_GET_DAI_VALUE(anInfo->dlDai);
6511        }
6512        else
6513        {
6514           pdcch->dci.u.format1bInfo.dai = RG_SCH_MAX_DAI_IDX;
6515           RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
6516                    "PDCCH is been scheduled without updating anInfo RNTI:%d",
6517                    rbAllocInfo->rnti);
6518        }
6519 #endif
6520     }
6521 #endif
6522        
6523     RETVOID;
6524
6525 }
6526 /**
6527  * @brief This function fills the PDCCH DCI format 2 information from dlProc.
6528  *
6529  * @details
6530  *
6531  *     Function: rgSCHCmnFillHqPPdcchDciFrmt2
6532  *     Purpose:  This function fills in the PDCCH information
6533  *               obtained from the RgSchDlHqProcCb and RgSchDlRbAlloc
6534  *               for dedicated service scheduling. It also
6535  *               obtains TPC to be filled in from the power module.
6536  *               Assign the PDCCH to HQProc.
6537  *
6538  *     Invoked by: Downlink Scheduler
6539  *
6540  *  @param[in]  RgSchCellCb*      cell
6541  *  @param[in]  RgSchDlRbAlloc*   rbAllocInfo
6542  *  @param[in]  RgDlHqProc*       hqP
6543  *  @param[out]  RgSchPdcch        *pdcch
6544  *  @param[in]   U8               tpc
6545  *  @return  Void
6546  *
6547  **/
6548 #ifdef ANSI
6549 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt2
6550 (
6551 RgSchCellCb                *cell,
6552 RgSchDlRbAlloc             *rbAllocInfo,
6553 RgSchDlHqProcCb            *hqP,
6554 RgSchPdcch                 *pdcch,
6555 U8                         tpc
6556 )
6557 #else
6558 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt2(cell, rbAllocInfo, hqP, pdcch, tpc)
6559 RgSchCellCb                *cell;
6560 RgSchDlRbAlloc             *rbAllocInfo;
6561 RgSchDlHqProcCb            *hqP;
6562 RgSchPdcch                 *pdcch;
6563 U8                         tpc;
6564 #endif
6565 {
6566
6567 #ifdef LTE_TDD
6568    RgSchTddANInfo     *anInfo;
6569 #endif
6570
6571 #ifdef LTEMAC_SPS
6572 /* ccpu00119023-ADD-For activation or reactivation,
6573  * Harq ProcId should be 0 */
6574    RgSchCmnDlHqProc *cmnHqDl = RG_SCH_CMN_GET_DL_HQP(hqP);
6575 #endif
6576
6577
6578     rgSCHCmnFillHqPTb(cell, rbAllocInfo, 0, pdcch);
6579     /*ccpu00120365:-ADD-call also if tb is disabled */
6580     if (rbAllocInfo->tbInfo[1].schdlngForTb ||
6581         rbAllocInfo->tbInfo[1].isDisabled)
6582     {
6583         rgSCHCmnFillHqPTb(cell, rbAllocInfo, 1, pdcch);
6584     }
6585     pdcch->dci.u.format2Info.tpcCmd = tpc;
6586          /* Avoiding this check,as we dont support Type1 RA */
6587 #ifdef RG_UNUSED
6588     if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE0)
6589     {
6590 #endif
6591         pdcch->dci.u.format2Info.allocInfo.isAllocType0 = TRUE;
6592         pdcch->dci.u.format2Info.allocInfo.resAllocMap[0] =
6593           ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 24)
6594                & 0xff);
6595         pdcch->dci.u.format2Info.allocInfo.resAllocMap[1] =
6596            ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 16)
6597                & 0x00ff);
6598         pdcch->dci.u.format2Info.allocInfo.resAllocMap[2] =
6599                ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 8)
6600                 & 0x0000ff);
6601         pdcch->dci.u.format2Info.allocInfo.resAllocMap[3] =
6602                ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask & 0x000000ff));
6603 #ifdef RG_UNUSED
6604     }
6605 #endif
6606 #ifdef LTEMAC_SPS
6607     if ((!(hqP->tbInfo[0].txCntr)) &&
6608        ( cmnHqDl != (RgSchCmnDlHqProc*)NULLP  &&
6609          ((cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_ACTV) ||
6610          (cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_REACTV))
6611        ))
6612     {
6613        pdcch->dci.u.format2Info.allocInfo.harqProcId = 0;
6614     }
6615     else
6616     {
6617       pdcch->dci.u.format2Info.allocInfo.harqProcId = hqP->procId;
6618     }
6619 #else
6620      pdcch->dci.u.format2Info.allocInfo.harqProcId = hqP->procId;
6621 #endif
6622          /* Initialize the TB info for both the TBs */
6623      pdcch->dci.u.format2Info.allocInfo.tbInfo[0].mcs = 0;
6624      pdcch->dci.u.format2Info.allocInfo.tbInfo[0].rv  = 1;
6625      pdcch->dci.u.format2Info.allocInfo.tbInfo[1].mcs = 0;
6626      pdcch->dci.u.format2Info.allocInfo.tbInfo[1].rv  = 1;
6627          /* Fill tbInfo for scheduled TBs */
6628      pdcch->dci.u.format2Info.allocInfo.tbInfo[rbAllocInfo->tbInfo[0].\
6629         tbCb->tbIdx].ndi = rbAllocInfo->tbInfo[0].tbCb->ndi;
6630      pdcch->dci.u.format2Info.allocInfo.tbInfo[rbAllocInfo->tbInfo[0].\
6631         tbCb->tbIdx].mcs = rbAllocInfo->tbInfo[0].imcs;
6632      pdcch->dci.u.format2Info.allocInfo.tbInfo[rbAllocInfo->tbInfo[0].\
6633             tbCb->tbIdx].rv = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.rv;
6634           /* If we reach this function. It is safely assumed that
6635            *  rbAllocInfo->tbInfo[0] always has non default valid values.
6636            *  rbAllocInfo->tbInfo[1]'s scheduling is optional */
6637      if (rbAllocInfo->tbInfo[1].schdlngForTb == TRUE)
6638      {
6639             pdcch->dci.u.format2Info.allocInfo.tbInfo[rbAllocInfo->tbInfo[1].\
6640                 tbCb->tbIdx].ndi = rbAllocInfo->tbInfo[1].tbCb->ndi;
6641             pdcch->dci.u.format2Info.allocInfo.tbInfo[rbAllocInfo->tbInfo[1].\
6642                 tbCb->tbIdx].mcs = rbAllocInfo->tbInfo[1].imcs;
6643             pdcch->dci.u.format2Info.allocInfo.tbInfo[rbAllocInfo->tbInfo[1].\
6644                 tbCb->tbIdx].rv = rbAllocInfo->tbInfo[1].tbCb->dlGrnt.rv;
6645      }
6646      pdcch->dci.u.format2Info.allocInfo.transSwap =
6647              rbAllocInfo->mimoAllocInfo.swpFlg;
6648      pdcch->dci.u.format2Info.allocInfo.precoding =
6649              rbAllocInfo->mimoAllocInfo.precIdxInfo;
6650 #ifdef LTE_TDD
6651      if(hqP->hqE->ue != NULLP)
6652      {
6653
6654 #ifdef LTE_ADV
6655         U8 servCellIdx = rgSchUtlGetServCellIdx(hqP->hqE->cell->instIdx,
6656                                         hqP->hqE->cell->cellId,
6657                                         hqP->hqE->ue);
6658         anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6659                            &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),servCellIdx);
6660 #else
6661         anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6662                            &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),0);
6663 #endif
6664 #ifdef TFU_TDD
6665         if(anInfo)
6666         {
6667            pdcch->dci.u.format2Info.dai = RG_SCH_GET_DAI_VALUE(anInfo->dlDai);
6668         }
6669         else
6670         {
6671            pdcch->dci.u.format2Info.dai = RG_SCH_MAX_DAI_IDX;
6672            RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
6673                     "PDCCH is been scheduled without updating anInfo RNTI:%d",
6674                     rbAllocInfo->rnti);
6675         }
6676 #endif
6677      }
6678 #endif
6679
6680      RETVOID;
6681 }
6682 /**
6683  * @brief This function fills the PDCCH DCI format 2A information from dlProc.
6684  *
6685  * @details
6686  *
6687  *     Function: rgSCHCmnFillHqPPdcchDciFrmt2A
6688  *     Purpose:  This function fills in the PDCCH information
6689  *               obtained from the RgSchDlHqProcCb and RgSchDlRbAlloc
6690  *               for dedicated service scheduling. It also
6691  *               obtains TPC to be filled in from the power module.
6692  *               Assign the PDCCH to HQProc.
6693  *
6694  *     Invoked by: Downlink Scheduler
6695  *
6696  *  @param[in]  RgSchCellCb*      cell
6697  *  @param[in]  RgSchDlRbAlloc*   rbAllocInfo
6698  *  @param[in]  RgDlHqProc*       hqP
6699  *  @param[out]  RgSchPdcch        *pdcch
6700  *  @param[in]   U8               tpc
6701  *  @return  Void
6702  *
6703  **/
6704 #ifdef ANSI
6705 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt2A
6706 (
6707 RgSchCellCb                *cell,
6708 RgSchDlRbAlloc             *rbAllocInfo,
6709 RgSchDlHqProcCb            *hqP,
6710 RgSchPdcch                 *pdcch,
6711 U8                         tpc
6712 )
6713 #else
6714 PRIVATE Void rgSCHCmnFillHqPPdcchDciFrmt2A(cell, rbAllocInfo, hqP, pdcch, tpc)
6715 RgSchCellCb                *cell;
6716 RgSchDlRbAlloc             *rbAllocInfo;
6717 RgSchDlHqProcCb            *hqP;
6718 RgSchPdcch                 *pdcch;
6719 U8                         tpc;
6720 #endif
6721 {
6722 #ifdef LTE_TDD
6723    RgSchTddANInfo     *anInfo;
6724 #endif
6725
6726 #ifdef LTEMAC_SPS
6727    RgSchCmnDlHqProc *cmnHqDl = RG_SCH_CMN_GET_DL_HQP(hqP);
6728 #endif
6729
6730
6731     rgSCHCmnFillHqPTb(cell, rbAllocInfo, 0, pdcch);
6732     /*ccpu00120365:-ADD-call also if tb is disabled */
6733     if (rbAllocInfo->tbInfo[1].schdlngForTb ||
6734           rbAllocInfo->tbInfo[1].isDisabled)
6735     {
6736
6737         rgSCHCmnFillHqPTb(cell, rbAllocInfo, 1, pdcch);
6738     }
6739
6740     pdcch->dci.u.format2AInfo.tpcCmd = tpc;
6741          /* Avoiding this check,as we dont support Type1 RA */
6742 #ifdef RG_UNUSED
6743     if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE0)
6744     {
6745 #endif
6746         pdcch->dci.u.format2AInfo.allocInfo.isAllocType0 = TRUE;
6747         pdcch->dci.u.format2AInfo.allocInfo.resAllocMap[0] =
6748               ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 24)
6749                & 0xff);
6750         pdcch->dci.u.format2AInfo.allocInfo.resAllocMap[1] =
6751               ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 16)
6752                & 0x00ff);
6753         pdcch->dci.u.format2AInfo.allocInfo.resAllocMap[2] =
6754                ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask >> 8)
6755                 & 0x0000ff);
6756         pdcch->dci.u.format2AInfo.allocInfo.resAllocMap[3] =
6757                ((rbAllocInfo->allocInfo.raType0.dlAllocBitMask & 0x000000ff));
6758 #ifdef RG_UNUSED
6759     }
6760 #endif
6761 #ifdef LTEMAC_SPS
6762     if ((!(hqP->tbInfo[0].txCntr)) &&
6763        ( cmnHqDl != (RgSchCmnDlHqProc*)NULLP  &&
6764          ((cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_ACTV) ||
6765          (cmnHqDl->spsAction & RG_SCH_CMN_SPS_DL_REACTV))
6766        ))
6767     {
6768        pdcch->dci.u.format2AInfo.allocInfo.harqProcId = 0;
6769     }
6770     else
6771     {
6772       pdcch->dci.u.format2AInfo.allocInfo.harqProcId = hqP->procId;
6773     }
6774 #else
6775     pdcch->dci.u.format2AInfo.allocInfo.harqProcId = hqP->procId;
6776 #endif
6777          /* Initialize the TB info for both the TBs */
6778     pdcch->dci.u.format2AInfo.allocInfo.tbInfo[0].mcs = 0;
6779     pdcch->dci.u.format2AInfo.allocInfo.tbInfo[0].rv  = 1;
6780     pdcch->dci.u.format2AInfo.allocInfo.tbInfo[1].mcs = 0;
6781     pdcch->dci.u.format2AInfo.allocInfo.tbInfo[1].rv  = 1;
6782          /* Fill tbInfo for scheduled TBs */
6783     pdcch->dci.u.format2AInfo.allocInfo.tbInfo[rbAllocInfo->tbInfo[0].\
6784             tbCb->tbIdx].ndi = rbAllocInfo->tbInfo[0].tbCb->ndi;
6785     pdcch->dci.u.format2AInfo.allocInfo.tbInfo[rbAllocInfo->tbInfo[0].\
6786             tbCb->tbIdx].mcs = rbAllocInfo->tbInfo[0].imcs;
6787     pdcch->dci.u.format2AInfo.allocInfo.tbInfo[rbAllocInfo->tbInfo[0].\
6788             tbCb->tbIdx].rv = rbAllocInfo->tbInfo[0].tbCb->dlGrnt.rv;
6789          /* If we reach this function. It is safely assumed that
6790           *  rbAllocInfo->tbInfo[0] always has non default valid values.
6791           *  rbAllocInfo->tbInfo[1]'s scheduling is optional */
6792
6793     if (rbAllocInfo->tbInfo[1].schdlngForTb == TRUE)
6794     {
6795             pdcch->dci.u.format2AInfo.allocInfo.tbInfo[rbAllocInfo->tbInfo[1].\
6796                tbCb->tbIdx].ndi = rbAllocInfo->tbInfo[1].tbCb->ndi;
6797             pdcch->dci.u.format2AInfo.allocInfo.tbInfo[rbAllocInfo->tbInfo[1].\
6798                tbCb->tbIdx].mcs = rbAllocInfo->tbInfo[1].imcs;
6799             pdcch->dci.u.format2AInfo.allocInfo.tbInfo[rbAllocInfo->tbInfo[1].\
6800                tbCb->tbIdx].rv = rbAllocInfo->tbInfo[1].tbCb->dlGrnt.rv;
6801
6802     }
6803     pdcch->dci.u.format2AInfo.allocInfo.transSwap =
6804             rbAllocInfo->mimoAllocInfo.swpFlg;
6805     pdcch->dci.u.format2AInfo.allocInfo.precoding =
6806             rbAllocInfo->mimoAllocInfo.precIdxInfo;
6807 #ifdef LTE_TDD
6808     if(hqP->hqE->ue != NULLP)
6809     {
6810 #ifdef LTE_ADV
6811        U8 servCellIdx = rgSchUtlGetServCellIdx(hqP->hqE->cell->instIdx,
6812                                         hqP->hqE->cell->cellId,
6813                                         hqP->hqE->ue);
6814        anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6815                          &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),servCellIdx);
6816 #else
6817        anInfo = rgSCHUtlGetUeANFdbkInfo(hqP->hqE->ue,
6818                          &(rbAllocInfo->tbInfo[0].tbCb->fdbkTime),0);
6819 #endif
6820 #ifdef TFU_TDD
6821        if(anInfo)
6822        {
6823           pdcch->dci.u.format2AInfo.dai = RG_SCH_GET_DAI_VALUE(anInfo->dlDai);
6824        }
6825        else
6826        {
6827           pdcch->dci.u.format2AInfo.dai = RG_SCH_MAX_DAI_IDX;
6828           RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
6829                    "PDCCH is been scheduled without updating anInfo RNTI:%d",
6830                    rbAllocInfo->rnti);
6831        }
6832 #endif
6833      }
6834 #endif
6835
6836
6837     RETVOID;
6838 }
6839 #endif
6840 /**
6841  * @brief init of Sch vars.
6842  *
6843  * @details
6844  *
6845  *     Function: rgSCHCmnInitVars
6846        Purpose:  Initialization of various UL subframe indices
6847  *
6848  *  @param[in]  RgSchCellCb *cell
6849  *  @return  Void
6850  *
6851  **/
6852 #ifdef ANSI
6853 PRIVATE Void rgSCHCmnInitVars
6854 (
6855 RgSchCellCb *cell
6856 )
6857 #else
6858 PRIVATE Void rgSCHCmnInitVars(cell)
6859 RgSchCellCb *cell;
6860 #endif
6861 {
6862    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
6863
6864
6865    cellUl->idx         = RGSCH_INVALID_INFO;
6866    cellUl->schdIdx     = RGSCH_INVALID_INFO;
6867    cellUl->schdHqProcIdx = RGSCH_INVALID_INFO;
6868    cellUl->msg3SchdIdx = RGSCH_INVALID_INFO;
6869 #ifdef EMTC_ENBLE
6870    cellUl->emtcMsg3SchdIdx = RGSCH_INVALID_INFO;
6871 #endif
6872    cellUl->msg3SchdHqProcIdx = RGSCH_INVALID_INFO;
6873    cellUl->rcpReqIdx   = RGSCH_INVALID_INFO;
6874    cellUl->hqFdbkIdx[0] = RGSCH_INVALID_INFO;
6875    cellUl->hqFdbkIdx[1] = RGSCH_INVALID_INFO;
6876    cellUl->reTxIdx[0]   = RGSCH_INVALID_INFO;
6877    cellUl->reTxIdx[1]   = RGSCH_INVALID_INFO;
6878   /* Stack Crash problem for TRACE5 Changes. Added the return below */
6879   RETVOID;
6880
6881 }
6882
6883 #ifndef LTE_TDD
6884 /**
6885  * @brief Updation of Sch vars per TTI.
6886  *
6887  * @details
6888  *
6889  *     Function: rgSCHCmnUpdVars
6890  *     Purpose:  Updation of Sch vars per TTI.
6891  *
6892  *  @param[in]  RgSchCellCb *cell
6893  *  @return  Void
6894  *
6895  **/
6896 #ifdef ANSI
6897 Void rgSCHCmnUpdVars
6898 (
6899 RgSchCellCb *cell
6900 )
6901 #else
6902 Void rgSCHCmnUpdVars(cell)
6903 RgSchCellCb *cell;
6904 #endif
6905 {
6906    CmLteTimingInfo   timeInfo;
6907    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
6908    U16 idx;
6909
6910
6911    idx = (cell->crntTime.sfn * RGSCH_NUM_SUB_FRAMES_5G + cell->crntTime.slot);
6912    cellUl->idx     = ((idx) % (RG_SCH_CMN_UL_NUM_SF));
6913 #ifdef UL_ADPT_DBG     
6914    printf("idx %d cellUl->idx  %d RGSCH_NUM_SUB_FRAMES_5G %d  time(%d %d) \n",idx,cellUl->idx ,RGSCH_NUM_SUB_FRAMES_5G,cell->crntTime.sfn,cell->crntTime.slot);
6915 #endif    
6916    /* Need to scheduler for after SCHED_DELTA */
6917    /* UL allocation has been advanced by 1 subframe
6918     * so that we do not wrap around and send feedback
6919     * before the data is even received by the PHY */
6920    /* Introduced timing delta for UL control */
6921    idx = (cellUl->idx + TFU_ULCNTRL_DLDELTA + RGSCH_PDCCH_PUSCH_DELTA);
6922    cellUl->schdIdx     = ((idx) % (RG_SCH_CMN_UL_NUM_SF));
6923
6924    RGSCHCMNADDTOCRNTTIME(cell->crntTime,timeInfo,
6925             TFU_ULCNTRL_DLDELTA + RGSCH_PDCCH_PUSCH_DELTA)
6926    cellUl->schdHqProcIdx = rgSCHCmnGetUlHqProcIdx(&timeInfo, cell);
6927
6928    /* ccpu00127193 filling schdTime for logging and enhancement purpose*/
6929    cellUl->schdTime = timeInfo;
6930
6931    /* msg3 scheduling two subframes after general scheduling */
6932    idx = (cellUl->idx + RG_SCH_CMN_DL_DELTA + RGSCH_RARSP_MSG3_DELTA);
6933    cellUl->msg3SchdIdx = ((idx) % (RG_SCH_CMN_UL_NUM_SF));
6934
6935    RGSCHCMNADDTOCRNTTIME(cell->crntTime,timeInfo,
6936             RG_SCH_CMN_DL_DELTA+ RGSCH_RARSP_MSG3_DELTA)
6937    cellUl->msg3SchdHqProcIdx = rgSCHCmnGetUlHqProcIdx(&timeInfo, cell);
6938
6939    idx = (cellUl->idx + TFU_RECPREQ_DLDELTA);
6940
6941    cellUl->rcpReqIdx   = ((idx) % (RG_SCH_CMN_UL_NUM_SF));
6942
6943    /* Downlink harq feedback is sometime after data reception / harq failure */
6944    /* Since feedback happens prior to scheduling being called, we add 1 to   */
6945    /* take care of getting the correct subframe for feedback                 */
6946    idx = (cellUl->idx - TFU_CRCIND_ULDELTA + RG_SCH_CMN_UL_NUM_SF);
6947 #ifdef UL_ADPT_DBG     
6948    printf("Finally setting cellUl->hqFdbkIdx[0] = %d TFU_CRCIND_ULDELTA %d RG_SCH_CMN_UL_NUM_SF %d\n",idx,TFU_CRCIND_ULDELTA,RG_SCH_CMN_UL_NUM_SF);
6949 #endif
6950    cellUl->hqFdbkIdx[0]   = (idx % (RG_SCH_CMN_UL_NUM_SF));
6951
6952    idx = ((cellUl->schdIdx) % (RG_SCH_CMN_UL_NUM_SF));
6953
6954    cellUl->reTxIdx[0] = (U8) idx;
6955 #ifdef UL_ADPT_DBG     
6956    printf("cellUl->hqFdbkIdx[0] %d cellUl->reTxIdx[0] %d \n",cellUl->hqFdbkIdx[0], cellUl->reTxIdx[0] );
6957 #endif
6958    /* RACHO: update cmn sched specific RACH variables,
6959     * mainly the prachMaskIndex */
6960    rgSCHCmnUpdRachParam(cell);
6961
6962    RETVOID;
6963 }
6964 #endif
6965
6966 #ifdef LTE_TDD
6967
6968 /**
6969  * @brief To get uplink subframe index associated with current PHICH
6970  *        transmission.
6971  *
6972  * @details
6973  *
6974  *     Function: rgSCHCmnGetPhichUlSfIdx
6975  *     Purpose:  Gets uplink subframe index associated with current PHICH
6976  *               transmission based on SFN and subframe no
6977  *
6978  *  @param[in]  CmLteTimingInfo  *timeInfo
6979  *  @param[in]  RgSchCellCb              *cell
6980  *  @return U8
6981  *
6982  **/
6983 #ifdef ANSI
6984 U8  rgSCHCmnGetPhichUlSfIdx
6985 (
6986 CmLteTimingInfo *timeInfo,
6987 RgSchCellCb *cell
6988 )
6989 #else
6990 U8  rgSCHCmnGetPhichUlSfIdx(timeInfo, cell)
6991 CmLteTimingInfo *timeInfo;
6992 RgSchCellCb        *cell;
6993 #endif
6994 {
6995    RgSchCmnUlCell       *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
6996    RgSchDlSf            *dlsf;
6997    U8                   ulDlCfgIdx = cell->ulDlCfgIdx;
6998    U8                   idx;
6999    U16                  numUlSf;
7000    U16                  sfn;
7001    U8                   subframe;
7002
7003
7004    dlsf = rgSCHUtlSubFrmGet(cell, *timeInfo);
7005
7006    if(dlsf->phichOffInfo.sfnOffset == RGSCH_INVALID_INFO)
7007    {
7008       return (RGSCH_INVALID_INFO);
7009    }
7010    subframe = dlsf->phichOffInfo.subframe;
7011
7012    sfn = (RGSCH_MAX_SFN + timeInfo->sfn -
7013                    dlsf->phichOffInfo.sfnOffset) % RGSCH_MAX_SFN;
7014
7015    /* ccpu00130980: numUlSf(U16) parameter added to avoid integer
7016     * wrap case such that idx will be proper*/
7017    numUlSf = rgSchTddNumUlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
7018    numUlSf = ((numUlSf * sfn) + rgSchTddNumUlSubfrmTbl[ulDlCfgIdx][subframe]) - 1;
7019    idx = numUlSf % (cellUl->numUlSubfrms);
7020
7021    return (idx);
7022 }
7023
7024 /**
7025  * @brief To get uplink subframe index.
7026  *
7027  * @details
7028  *
7029  *
7030  *     Function: rgSCHCmnGetUlSfIdx
7031  *     Purpose:  Gets uplink subframe index based on SFN and subframe number.
7032  *
7033  *  @param[in]  CmLteTimingInfo  *timeInfo
7034  *  @param[in]  U8               ulDlCfgIdx
7035  *  @return U8
7036  *
7037  **/
7038 #ifdef ANSI
7039 U8  rgSCHCmnGetUlSfIdx
7040 (
7041 CmLteTimingInfo *timeInfo,
7042 RgSchCellCb *cell
7043 )
7044 #else
7045 U8  rgSCHCmnGetUlSfIdx(timeInfo, cell)
7046 CmLteTimingInfo *timeInfo;
7047 RgSchCellCb *cell;
7048 #endif
7049 {
7050    RgSchCmnUlCell    *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
7051    U8                ulDlCfgIdx = cell->ulDlCfgIdx;
7052    U8                idx = 0;
7053    U16               numUlSf;
7054
7055
7056    /* ccpu00130980: numUlSf(U16) parameter added to avoid integer
7057     * wrap case such that idx will be proper*/
7058    numUlSf = rgSchTddNumUlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
7059    numUlSf = ((numUlSf * timeInfo->sfn) + \
7060          rgSchTddNumUlSubfrmTbl[ulDlCfgIdx][timeInfo->subframe]) - 1;
7061    idx = numUlSf % (cellUl->numUlSubfrms);
7062
7063    return (idx);
7064 }
7065
7066 #endif
7067
7068 /**
7069  * @brief To get uplink hq index.
7070  *
7071  * @details
7072  *
7073  *
7074  *     Function: rgSCHCmnGetUlHqProcIdx
7075  *     Purpose:  Gets uplink subframe index based on SFN and subframe number.
7076  *
7077  *  @param[in]  CmLteTimingInfo  *timeInfo
7078  *  @param[in]  U8               ulDlCfgIdx
7079  *  @return U8
7080  *
7081  **/
7082 #ifdef ANSI
7083 U8  rgSCHCmnGetUlHqProcIdx
7084 (
7085 CmLteTimingInfo *timeInfo,
7086 RgSchCellCb *cell
7087 )
7088 #else
7089 U8  rgSCHCmnGetUlHqProcIdx(timeInfo, cell)
7090 CmLteTimingInfo *timeInfo;
7091 RgSchCellCb *cell;
7092 #endif
7093 {
7094    U8            procId;
7095    U32           numUlSf;
7096   
7097 #ifndef LTE_TDD
7098    numUlSf  = (timeInfo->sfn * RGSCH_NUM_SUB_FRAMES_5G + timeInfo->slot);
7099    procId   = numUlSf % RGSCH_NUM_UL_HQ_PROC;
7100 #else
7101    U8            ulDlCfgIdx = cell->ulDlCfgIdx;
7102    /*ccpu00130639 - MOD - To get correct UL HARQ Proc IDs for all UL/DL Configs*/
7103    U8            numUlSfInSfn;
7104    S8            sfnCycle = cell->tddHqSfnCycle;
7105    U8            numUlHarq = rgSchTddUlNumHarqProcTbl[ulDlCfgIdx]
7106
7107    /* TRACE 5 Changes */
7108
7109    /* Calculate the number of UL SF in one SFN */
7110    numUlSfInSfn = RGSCH_NUM_SUB_FRAMES -
7111                rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
7112
7113    /* Check for the SFN wrap around case */
7114    if(cell->crntTime.sfn == 1023 && timeInfo->sfn == 0)
7115    {
7116       sfnCycle++;
7117    }
7118    else if(cell->crntTime.sfn == 0 && timeInfo->sfn == 1023)
7119    {
7120       /* sfnCycle decremented by 1 */
7121       sfnCycle = (sfnCycle + numUlHarq-1) % numUlHarq;
7122    }
7123    /* Calculate the total number of UL sf */
7124    /*  -1 is done since uplink sf are counted from 0 */
7125    numUlSf = numUlSfInSfn *  (timeInfo->sfn + (sfnCycle*1024)) +
7126                   rgSchTddNumUlSubfrmTbl[ulDlCfgIdx][timeInfo->slot] - 1;
7127
7128    procId = numUlSf % numUlHarq;   
7129 #endif
7130    return (procId);
7131 }
7132
7133
7134 /* UL_ALLOC_CHANGES */
7135 /***********************************************************
7136  *
7137  *     Func : rgSCHCmnUlFreeAlloc
7138  *
7139  *     Desc : Free an allocation - invokes UHM and releases
7140  *            alloc for the scheduler
7141  *            Doest need subframe as argument
7142  *
7143  *     Ret  :
7144  *
7145  *     Notes:
7146  *
7147  *     File :
7148  *
7149  **********************************************************/
7150 #ifdef ANSI
7151 Void rgSCHCmnUlFreeAlloc
7152 (
7153 RgSchCellCb     *cell,
7154 RgSchUlAlloc    *alloc
7155 )
7156 #else
7157 Void rgSCHCmnUlFreeAlloc(cell, alloc)
7158 RgSchCellCb     *cell;
7159 RgSchUlAlloc    *alloc;
7160 #endif
7161 {
7162    RgSchUlHqProcCb *hqProc;
7163
7164    if (alloc->forMsg3)
7165    {
7166       /* Fix : Release RNTI upon MSG3 max TX failure for non-HO UEs */
7167       if ((alloc->hqProc->remTx == 0) &&
7168           (alloc->hqProc->rcvdCrcInd == FALSE) &&
7169           (alloc->raCb))
7170       {
7171          RgSchRaCb      *raCb = alloc->raCb;
7172          rgSCHUhmFreeProc(alloc->hqProc, cell);
7173          rgSCHUtlUlAllocRelease(alloc);
7174          rgSCHRamDelRaCb(cell, raCb, TRUE);
7175          RETVOID;
7176       }
7177    }
7178    
7179    hqProc = alloc->hqProc;
7180    rgSCHUtlUlAllocRelease(alloc);
7181    rgSCHUhmFreeProc(hqProc, cell);
7182    RETVOID;
7183 }
7184
7185
7186 /***********************************************************
7187  *
7188  *     Func : rgSCHCmnUlFreeAllocation
7189  *
7190  *     Desc : Free an allocation - invokes UHM and releases
7191  *            alloc for the scheduler
7192  *
7193  *     Ret  :
7194  *
7195  *     Notes:
7196  *
7197  *     File :
7198  *
7199  **********************************************************/
7200 #ifdef ANSI
7201 Void rgSCHCmnUlFreeAllocation
7202 (
7203 RgSchCellCb     *cell,
7204 RgSchUlSf       *sf,
7205 RgSchUlAlloc    *alloc
7206 )
7207 #else
7208 Void rgSCHCmnUlFreeAllocation(cell, sf, alloc)
7209 RgSchCellCb     *cell;
7210 RgSchUlSf       *sf;
7211 RgSchUlAlloc    *alloc;
7212 #endif
7213 {
7214    RgSchUlHqProcCb *hqProc;
7215
7216
7217    if (alloc->forMsg3)
7218    {
7219       /* Fix : Release RNTI upon MSG3 max TX failure for non-HO UEs */
7220       if ((alloc->hqProc->remTx == 0) &&
7221           (alloc->hqProc->rcvdCrcInd == FALSE) &&
7222           (alloc->raCb))
7223       {
7224          RgSchRaCb      *raCb = alloc->raCb;
7225          rgSCHUhmFreeProc(alloc->hqProc, cell);
7226          rgSCHUtlUlAllocRls(sf, alloc);
7227          rgSCHRamDelRaCb(cell, raCb, TRUE);
7228          RETVOID;
7229       }
7230    }
7231    
7232    hqProc = alloc->hqProc;
7233    rgSCHUhmFreeProc(hqProc, cell);
7234 #ifdef LTE_L2_MEAS
7235    /* re-setting the PRB count while freeing the allocations */
7236    sf->totPrb = 0;
7237 #endif
7238    rgSCHUtlUlAllocRls(sf, alloc);
7239
7240    RETVOID;
7241 }
7242
7243 /**
7244  * @brief This function implements PDCCH allocation for an UE
7245  *        in the currently running subframe.
7246  *
7247  * @details
7248  *
7249  *     Function: rgSCHCmnPdcchAllocCrntSf
7250  *     Purpose:  This function determines current DL subframe
7251  *               and UE DL CQI to call the actual pdcch allocator
7252  *               function.
7253  *               Note that this function is called only
7254  *               when PDCCH request needs to be made during
7255  *               uplink scheduling.
7256  *
7257  *     Invoked by: Scheduler
7258  *
7259  *  @param[in]  RgSchCellCb  *cell
7260  *  @param[in]  RgSchUeCb    *ue
7261  *  @return  RgSchPdcch *
7262  *         -# NULLP when unsuccessful
7263  **/
7264 #ifdef ANSI
7265 RgSchPdcch *rgSCHCmnPdcchAllocCrntSf
7266 (
7267 RgSchCellCb                *cell,
7268 RgSchUeCb                  *ue
7269 )
7270 #else
7271 RgSchPdcch *rgSCHCmnPdcchAllocCrntSf(cell, ue)
7272 RgSchCellCb                *cell;
7273 RgSchUeCb                  *ue;
7274 #endif
7275 {
7276    CmLteTimingInfo      frm = cell->crntTime;
7277    RgSchCmnDlUe         *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
7278    RgSchDlSf            *sf;
7279    RgSchPdcch           *pdcch = NULLP;
7280
7281    RGSCH_INCR_SUB_FRAME(frm, TFU_ULCNTRL_DLDELTA);
7282    sf = rgSCHUtlSubFrmGet(cell, frm);
7283
7284 #ifdef LTE_ADV
7285    if (ue->allocCmnUlPdcch)
7286    {
7287       pdcch = rgSCHCmnCmnPdcchAlloc(cell, sf);
7288       /* Since CRNTI Scrambled */
7289       if(NULLP != pdcch)
7290       {
7291          pdcch->dciNumOfBits = ue->dciSize.cmnSize[TFU_DCI_FORMAT_0];
7292       }
7293    }
7294    else
7295 #endif
7296    {
7297       //pdcch = rgSCHCmnPdcchAlloc(cell, ue, sf, y, ueDl->mimoInfo.cwInfo[0].cqi, TFU_DCI_FORMAT_0, FALSE);
7298                 pdcch = rgSCHCmnPdcchAlloc(cell, ue, sf, ueDl->mimoInfo.cwInfo[0].cqi, TFU_DCI_FORMAT_A1, FALSE);
7299    }
7300    return (pdcch);
7301 }
7302
7303 /***********************************************************
7304  *
7305  *     Func : rgSCHCmnUlAllocFillNdmrs
7306  *
7307  *     Desc : Determines and fills N_dmrs for a UE uplink
7308  *            allocation.
7309  *
7310  *     Ret  :
7311  *
7312  *     Notes: N_dmrs determination is straightforward, so
7313  *            it is configured per subband
7314  *
7315  *     File :
7316  *
7317  **********************************************************/
7318 #ifdef ANSI
7319 Void rgSCHCmnUlAllocFillNdmrs
7320 (
7321 RgSchCmnUlCell *cellUl,
7322 RgSchUlAlloc   *alloc
7323 )
7324 #else
7325 Void rgSCHCmnUlAllocFillNdmrs(cellUl, alloc)
7326 RgSchCmnUlCell *cellUl;
7327 RgSchUlAlloc   *alloc;
7328 #endif
7329 {
7330    alloc->grnt.nDmrs = cellUl->dmrsArr[alloc->sbStart];
7331    RETVOID;
7332 }
7333
7334 /***********************************************************
7335  *
7336  *     Func : rgSCHCmnUlAllocLnkHqProc
7337  *
7338  *     Desc : Links a new allocation for an UE with the
7339  *            appropriate HARQ process of the UE.
7340  *
7341  *     Ret  :
7342  *
7343  *     Notes:
7344  *
7345  *     File :
7346  *
7347  **********************************************************/
7348 #ifdef ANSI
7349 Void rgSCHCmnUlAllocLnkHqProc
7350 (
7351 RgSchUeCb       *ue,
7352 RgSchUlAlloc    *alloc,
7353 RgSchUlHqProcCb *proc,
7354 Bool            isRetx
7355 )
7356 #else
7357 Void rgSCHCmnUlAllocLnkHqProc(ue, alloc, proc, isRetx)
7358 RgSchUeCb       *ue;
7359 RgSchUlAlloc    *alloc;
7360 RgSchUlHqProcCb *proc;
7361 Bool            isRetx;
7362 #endif
7363 {
7364
7365    if(TRUE == isRetx)
7366    {
7367       rgSCHCmnUlAdapRetx(alloc, proc);
7368    }
7369    else
7370    {
7371 #ifdef LTE_L2_MEAS /* L2_COUNTERS */
7372       alloc->ue = ue;
7373 #endif
7374       rgSCHUhmNewTx(proc, (((RgUeUlHqCb*)proc->hqEnt)->maxHqRetx), alloc);
7375    }
7376    RETVOID;
7377 }
7378
7379 /**
7380  * @brief This function releases a PDCCH in the subframe that is
7381  *        currently being allocated for.
7382  *
7383  * @details
7384  *
7385  *     Function: rgSCHCmnPdcchRlsCrntSf
7386  *     Purpose:  This function determines current DL subframe
7387  *               which is considered for PDCCH allocation,
7388  *               and then calls the actual function that
7389  *               releases a PDCCH in a specific subframe.
7390  *               Note that this function is called only
7391  *               when PDCCH release needs to be made during
7392  *               uplink scheduling.
7393  *
7394  *     Invoked by: Scheduler
7395  *
7396  *  @param[in]  RgSchCellCb  *cell
7397  *  @param[in]  RgSchPdcch   *pdcch
7398  *  @return  Void
7399  **/
7400 #ifdef ANSI
7401 Void rgSCHCmnPdcchRlsCrntSf
7402 (
7403 RgSchCellCb                *cell,
7404 RgSchPdcch                 *pdcch
7405 )
7406 #else
7407 Void rgSCHCmnPdcchRlsCrntSf(cell, pdcch)
7408 RgSchCellCb                *cell;
7409 RgSchPdcch                 *pdcch;
7410 #endif
7411 {
7412    CmLteTimingInfo      frm = cell->crntTime;
7413    RgSchDlSf               *sf;
7414
7415
7416    RGSCH_INCR_SUB_FRAME(frm, TFU_ULCNTRL_DLDELTA);
7417    sf = rgSCHUtlSubFrmGet(cell, frm);
7418    rgSCHUtlPdcchPut(cell, &sf->pdcchInfo, pdcch);
7419    RETVOID;
7420 }
7421 /***********************************************************
7422  *
7423  *     Func : rgSCHCmnUlFillPdcchWithAlloc
7424  *
7425  *     Desc : Fills a PDCCH with format 0 information.
7426  *
7427  *     Ret  :
7428  *
7429  *     Notes:
7430  *
7431  *     File :
7432  *
7433  **********************************************************/
7434 #ifdef ANSI
7435 Void rgSCHCmnUlFillPdcchWithAlloc
7436 (
7437 RgSchPdcch      *pdcch,
7438 RgSchUlAlloc    *alloc,
7439 RgSchUeCb       *ue
7440 )
7441 #else
7442 Void rgSCHCmnUlFillPdcchWithAlloc(pdcch, alloc, ue)
7443 RgSchPdcch      *pdcch;
7444 RgSchUlAlloc    *alloc;
7445 RgSchUeCb       *ue;
7446 #endif
7447 {
7448
7449
7450    pdcch->ue = ue;
7451    pdcch->rnti = alloc->rnti;
7452    //pdcch->dci.dciFormat = TFU_DCI_FORMAT_A2;
7453    pdcch->dci.dciFormat = alloc->grnt.dciFrmt;
7454
7455    //Currently hardcoding values here.
7456    //printf("Filling 5GTF UL DCI for rnti %d \n",alloc->rnti);
7457    switch(pdcch->dci.dciFormat)
7458    {
7459       case TFU_DCI_FORMAT_A1:
7460                 {
7461                         pdcch->dci.u.formatA1Info.formatType = 0;
7462          pdcch->dci.u.formatA1Info.xPUSCHRange = alloc->grnt.xPUSCHRange;
7463          pdcch->dci.u.formatA1Info.xPUSCH_TxTiming = 0;
7464          pdcch->dci.u.formatA1Info.RBAssign = alloc->grnt.rbAssign;
7465          pdcch->dci.u.formatA1Info.u.rbAssignA1Val324.hqProcId = alloc->grnt.hqProcId;
7466          pdcch->dci.u.formatA1Info.u.rbAssignA1Val324.mcs = alloc->grnt.iMcsCrnt;
7467          pdcch->dci.u.formatA1Info.u.rbAssignA1Val324.ndi = alloc->hqProc->ndi;
7468          pdcch->dci.u.formatA1Info.CSI_BSI_BRI_Req = 0;
7469          pdcch->dci.u.formatA1Info.CSIRS_BRRS_TxTiming = 0;
7470          pdcch->dci.u.formatA1Info.CSIRS_BRRS_SymbIdx = 0;
7471          pdcch->dci.u.formatA1Info.CSIRS_BRRS_ProcInd = 0;
7472          pdcch->dci.u.formatA1Info.numBSI_Reports = 0;
7473          pdcch->dci.u.formatA1Info.uciOnxPUSCH = alloc->grnt.uciOnxPUSCH;
7474          pdcch->dci.u.formatA1Info.beamSwitch  = 0;
7475          pdcch->dci.u.formatA1Info.SRS_Config = 0;
7476          pdcch->dci.u.formatA1Info.SRS_Symbol = 0;
7477          pdcch->dci.u.formatA1Info.REMapIdx_DMRS_PCRS_numLayers = 0;
7478          pdcch->dci.u.formatA1Info.SCID = alloc->grnt.SCID;
7479          pdcch->dci.u.formatA1Info.PMI = alloc->grnt.PMI;
7480          pdcch->dci.u.formatA1Info.UL_PCRS = 0;
7481          pdcch->dci.u.formatA1Info.tpcCmd = alloc->grnt.tpc;
7482                         break;
7483       }
7484                 case TFU_DCI_FORMAT_A2:
7485                 {
7486                         pdcch->dci.u.formatA2Info.formatType = 1;
7487          pdcch->dci.u.formatA2Info.xPUSCHRange = alloc->grnt.xPUSCHRange;
7488          pdcch->dci.u.formatA2Info.xPUSCH_TxTiming = 0;
7489          pdcch->dci.u.formatA2Info.RBAssign = alloc->grnt.rbAssign;
7490          pdcch->dci.u.formatA2Info.u.rbAssignA1Val324.hqProcId = alloc->grnt.hqProcId;
7491          pdcch->dci.u.formatA2Info.u.rbAssignA1Val324.mcs = alloc->grnt.iMcsCrnt;
7492          pdcch->dci.u.formatA2Info.u.rbAssignA1Val324.ndi = alloc->hqProc->ndi;
7493          pdcch->dci.u.formatA2Info.CSI_BSI_BRI_Req = 0;
7494          pdcch->dci.u.formatA2Info.CSIRS_BRRS_TxTiming = 0;
7495          pdcch->dci.u.formatA2Info.CSIRS_BRRS_SymbIdx = 0;
7496          pdcch->dci.u.formatA2Info.CSIRS_BRRS_ProcInd = 0;
7497          pdcch->dci.u.formatA2Info.numBSI_Reports = 0;
7498          pdcch->dci.u.formatA2Info.uciOnxPUSCH = alloc->grnt.uciOnxPUSCH;
7499          pdcch->dci.u.formatA2Info.beamSwitch  = 0;
7500          pdcch->dci.u.formatA2Info.SRS_Config = 0;
7501          pdcch->dci.u.formatA2Info.SRS_Symbol = 0;
7502          pdcch->dci.u.formatA2Info.REMapIdx_DMRS_PCRS_numLayers = 0;
7503          pdcch->dci.u.formatA2Info.SCID = alloc->grnt.SCID;
7504          pdcch->dci.u.formatA2Info.PMI = alloc->grnt.PMI;
7505          pdcch->dci.u.formatA2Info.UL_PCRS = 0;
7506          pdcch->dci.u.formatA2Info.tpcCmd = alloc->grnt.tpc;
7507                         break;
7508                 }
7509       default:
7510          RLOG1(L_ERROR," 5GTF_ERROR UL Allocator's icorrect "
7511                "dciForamt Fill RNTI:%d",alloc->rnti);
7512          break;
7513    }    
7514    
7515
7516    RETVOID;
7517 }
7518
7519 /***********************************************************
7520  *
7521  *     Func : rgSCHCmnUlAllocFillTpc
7522  *
7523  *     Desc : Determines and fills TPC for an UE allocation.
7524  *
7525  *     Ret  :
7526  *
7527  *     Notes:
7528  *
7529  *     File :
7530  *
7531  **********************************************************/
7532 #ifdef ANSI
7533 Void rgSCHCmnUlAllocFillTpc
7534 (
7535 RgSchCellCb  *cell,
7536 RgSchUeCb    *ue,
7537 RgSchUlAlloc *alloc
7538 )
7539 #else
7540 Void rgSCHCmnUlAllocFillTpc(cell, ue, alloc)
7541 RgSchCellCb  *cell;
7542 RgSchUeCb    *ue;
7543 RgSchUlAlloc *alloc;
7544 #endif
7545 {
7546    alloc->grnt.tpc = rgSCHPwrPuschTpcForUe(cell, ue);
7547    RETVOID;
7548 }
7549
7550
7551 /***********************************************************
7552  *
7553  *     Func : rgSCHCmnAddUeToRefreshQ
7554  *
7555  *     Desc : Adds a UE to refresh queue, so that the UE is
7556  *            periodically triggered to refresh it's GBR and
7557  *            AMBR values.
7558  *
7559  *     Ret  :
7560  *
7561  *     Notes:
7562  *
7563  *     File :
7564  *
7565  **********************************************************/
7566 #ifdef ANSI
7567 PRIVATE Void rgSCHCmnAddUeToRefreshQ
7568 (
7569 RgSchCellCb     *cell,
7570 RgSchUeCb       *ue,
7571 U32             wait
7572 )
7573 #else
7574 PRIVATE Void rgSCHCmnAddUeToRefreshQ(cell, ue, wait)
7575 RgSchCellCb     *cell;
7576 RgSchUeCb       *ue;
7577 U32             wait;
7578 #endif
7579 {
7580    RgSchCmnCell   *sched  = RG_SCH_CMN_GET_CELL(cell);
7581    CmTmrArg       arg;
7582    RgSchCmnUeInfo *ueSchd = RG_SCH_CMN_GET_CMN_UE(ue);
7583
7584    UNUSED(cell);
7585
7586    memset(&arg, 0, sizeof(arg));
7587    arg.tqCp   = &sched->tmrTqCp;
7588    arg.tq     = sched->tmrTq;
7589    arg.timers = &ueSchd->tmr;
7590    arg.cb     = (PTR)ue;
7591    arg.tNum   = 0;
7592    arg.max    = 1;
7593    arg.evnt   = RG_SCH_CMN_EVNT_UE_REFRESH;
7594    arg.wait   = wait;
7595    cmPlcCbTq(&arg);
7596    RETVOID;
7597 }
7598
7599 /**
7600  * @brief Perform UE reset procedure.
7601  *
7602  * @details
7603  *
7604  *     Function : rgSCHCmnUlUeReset
7605  *
7606  *     This functions performs BSR resetting and
7607  *     triggers UL specific scheduler
7608  *     to Perform UE reset procedure.
7609  *
7610  *  @param[in]  RgSchCellCb  *cell
7611  *  @param[in]  RgSchUeCb    *ue
7612  *  @return  Void
7613  **/
7614 #ifdef ANSI
7615 PRIVATE Void rgSCHCmnUlUeReset
7616 (
7617 RgSchCellCb  *cell,
7618 RgSchUeCb    *ue
7619 )
7620 #else
7621 PRIVATE Void rgSCHCmnUlUeReset(cell, ue)
7622 RgSchCellCb  *cell;
7623 RgSchUeCb    *ue;
7624 #endif
7625 {
7626    RgSchCmnCell         *cellSchd = RG_SCH_CMN_GET_CELL(cell);
7627    RgSchCmnUlUe         *ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
7628    U8                   lcgCnt=0;
7629    RgSchCmnLcg          *lcgCmn;
7630    CmLList              *node;
7631    RgSchCmnAllocRecord  *allRcd;
7632
7633    ue->ul.minReqBytes = 0;
7634    ue->ul.totalBsr = 0;
7635    ue->ul.effBsr = 0;
7636    ue->ul.nonGbrLcgBs = 0;
7637    ue->ul.effAmbr = ue->ul.cfgdAmbr;
7638
7639    node = ueUl->ulAllocLst.first;
7640    while (node)
7641    {
7642       allRcd = (RgSchCmnAllocRecord *)node->node;
7643       allRcd->alloc = 0;
7644       node = node->next;
7645    }
7646    for(lcgCnt = 0; lcgCnt < RGSCH_MAX_LCG_PER_UE; lcgCnt++)
7647    {
7648       lcgCmn = RG_SCH_CMN_GET_UL_LCG(&ue->ul.lcgArr[lcgCnt]);
7649       lcgCmn->bs = 0;
7650       lcgCmn->reportedBs = 0;
7651       lcgCmn->effGbr = lcgCmn->cfgdGbr;
7652       lcgCmn->effDeltaMbr = lcgCmn->deltaMbr;
7653    }
7654    rgSCHCmnUlUeDelAllocs(cell, ue);
7655
7656    ue->isSrGrant = FALSE;
7657
7658    cellSchd->apisUl->rgSCHUlUeReset(cell, ue);
7659
7660    /* Stack Crash problem for TRACE5 changes. Added the return below */
7661    RETVOID;
7662
7663 }
7664
7665 /**
7666  * @brief RESET UL CQI and DL CQI&RI to conservative values
7667     * for a reestablishing UE.
7668  *
7669  * @details
7670  *
7671  *     Function : rgSCHCmnResetRiCqi 
7672  *     
7673  *     RESET UL CQI and DL CQI&RI to conservative values
7674  *     for a reestablishing UE
7675  *
7676  *  @param[in]  RgSchCellCb  *cell
7677  *  @param[in]  RgSchUeCb    *ue
7678  *  @return  Void
7679  **/
7680 #ifdef ANSI
7681 PRIVATE Void rgSCHCmnResetRiCqi 
7682 (
7683 RgSchCellCb  *cell,
7684 RgSchUeCb    *ue
7685 )
7686 #else
7687 PRIVATE Void rgSCHCmnResetRiCqi(cell, ue)
7688 RgSchCellCb  *cell;
7689 RgSchUeCb    *ue;
7690 #endif
7691 {
7692    RgSchCmnCell  *cellSchd = RG_SCH_CMN_GET_CELL(cell);
7693    RgSchCmnUe    *ueSchCmn = RG_SCH_CMN_GET_UE(ue,cell);
7694    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
7695    RgSchCmnUlUe  *ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
7696
7697
7698    rgSCHCmnUpdUeUlCqiInfo(cell, ue, ueUl, ueSchCmn, cellSchd, 
7699          cell->isCpUlExtend);
7700
7701    ueDl->mimoInfo.cwInfo[0].cqi = cellSchd->dl.ccchCqi;
7702    ueDl->mimoInfo.cwInfo[1].cqi = cellSchd->dl.ccchCqi;
7703    ueDl->mimoInfo.ri = 1;
7704    if ((ue->mimoInfo.txMode == RGR_UE_TM_4) ||
7705           (ue->mimoInfo.txMode == RGR_UE_TM_6))
7706    {
7707       RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_NO_PMI);
7708    }
7709    if (ue->mimoInfo.txMode == RGR_UE_TM_3)
7710    {
7711       RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_RI_1);
7712    }
7713 #ifdef EMTC_ENABLE   
7714    rgSCHCmnDlSetUeAllocLmt(cell, ueDl, ue->isEmtcUe);
7715 #else
7716    rgSCHCmnDlSetUeAllocLmt(cell, ueDl, FALSE);
7717 #endif      
7718
7719 #ifdef TFU_UPGRADE
7720    /* Request for an early Aper CQI in case of reest */
7721    RgSchUeACqiCb  *acqiCb = RG_SCH_CMN_GET_ACQICB(ue,cell); 
7722    if(acqiCb && acqiCb->aCqiCfg.pres)
7723    {
7724       acqiCb->aCqiTrigWt = 0;
7725    }
7726 #endif   
7727
7728    RETVOID;
7729 }
7730
7731 /**
7732  * @brief Perform UE reset procedure.
7733  *
7734  * @details
7735  *
7736  *     Function : rgSCHCmnDlUeReset
7737  *
7738  *     This functions performs BO resetting and
7739  *     triggers DL specific scheduler
7740  *     to Perform UE reset procedure.
7741  *
7742  *  @param[in]  RgSchCellCb  *cell
7743  *  @param[in]  RgSchUeCb    *ue
7744  *  @return  Void
7745  **/
7746 #ifdef ANSI
7747 PRIVATE Void rgSCHCmnDlUeReset
7748 (
7749 RgSchCellCb  *cell,
7750 RgSchUeCb    *ue
7751 )
7752 #else
7753 PRIVATE Void rgSCHCmnDlUeReset(cell, ue)
7754 RgSchCellCb  *cell;
7755 RgSchUeCb    *ue;
7756 #endif
7757 {
7758    RgSchCmnCell         *cellSchd = RG_SCH_CMN_GET_CELL(cell);
7759    RgSchCmnDlCell       *cellCmnDl = RG_SCH_CMN_GET_DL_CELL(cell);
7760    RgSchCmnDlUe         *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
7761
7762
7763    if (ueDl->rachInfo.poLnk.node != NULLP)
7764    {
7765       rgSCHCmnDlRmvFrmPdcchOdrQ(cell, ue);
7766    }
7767
7768    /* Fix: syed Remove from TA List if this UE is there.
7769     * If TA Timer is running. Stop it */
7770    if (ue->dlTaLnk.node)
7771    {
7772       cmLListDelFrm(&cellCmnDl->taLst, &ue->dlTaLnk);
7773       ue->dlTaLnk.node = (PTR)NULLP;
7774    }
7775    else if (ue->taTmr.tmrEvnt != TMR_NONE)
7776    {
7777       rgSCHTmrStopTmr(cell, ue->taTmr.tmrEvnt, ue);
7778    }
7779
7780    cellSchd->apisDl->rgSCHDlUeReset(cell, ue);
7781 #ifdef LTE_ADV
7782    if (ue->numSCells)
7783    {
7784       rgSCHSCellDlUeReset(cell,ue);
7785    }
7786 #endif
7787 }
7788
7789 /**
7790  * @brief Perform UE reset procedure.
7791  *
7792  * @details
7793  *
7794  *     Function : rgSCHCmnUeReset
7795  *
7796  *     This functions triggers specific scheduler
7797  *     to Perform UE reset procedure.
7798  *
7799  *  @param[in]  RgSchCellCb  *cell
7800  *  @param[in]  RgSchUeCb    *ue
7801  *  @return  S16
7802  *      -# ROK
7803  *      -# RFAILED
7804  **/
7805 #ifdef ANSI
7806 Void rgSCHCmnUeReset
7807 (
7808 RgSchCellCb  *cell,
7809 RgSchUeCb    *ue
7810 )
7811 #else
7812 Void rgSCHCmnUeReset(cell, ue)
7813 RgSchCellCb  *cell;
7814 RgSchUeCb    *ue;
7815 #endif
7816 {
7817    U8 idx;
7818    Pst               pst;
7819    RgInfResetHqEnt   hqEntRstInfo;
7820
7821    /* RACHO: remove UE from pdcch, handover and rapId assoc Qs */
7822    rgSCHCmnDelRachInfo(cell, ue);
7823
7824    rgSCHPwrUeReset(cell, ue);
7825
7826    rgSCHCmnUlUeReset(cell, ue);
7827    rgSCHCmnDlUeReset(cell, ue);
7828    
7829 #ifdef LTE_ADV
7830    /* Making allocCmnUlPdcch TRUE to allocate DCI0/1A from Common search space.
7831       As because multiple cells are added hence 2 bits CqiReq is there 
7832       This flag will be set to FALSE once we will get Scell READY */
7833    ue->allocCmnUlPdcch = TRUE;
7834 #endif
7835
7836    /* Fix : syed RESET UL CQI and DL CQI&RI to conservative values
7837     * for a reestablishing UE */
7838    /*Reset Cqi Config for all the configured cells*/
7839    for (idx = 0;idx < CM_LTE_MAX_CELLS; idx++)
7840    {
7841       if (ue->cellInfo[idx] != NULLP) 
7842       {   
7843          rgSCHCmnResetRiCqi(ue->cellInfo[idx]->cell, ue);
7844       }
7845    }
7846    /*After Reset Trigger APCQI for Pcell*/
7847    RgSchUeCellInfo *pCellInfo = RG_SCH_CMN_GET_PCELL_INFO(ue);
7848    if(pCellInfo->acqiCb.aCqiCfg.pres)
7849    {
7850       ue->dl.reqForCqi = RG_SCH_APCQI_SERVING_CC;
7851    }
7852
7853 /* sending HqEnt reset to MAC */
7854    hqEntRstInfo.cellId = cell->cellId;
7855    hqEntRstInfo.crnti  = ue->ueId;
7856
7857    rgSCHUtlGetPstToLyr(&pst, &rgSchCb[cell->instIdx], cell->macInst);
7858    RgSchMacRstHqEnt(&pst,&hqEntRstInfo);
7859
7860    RETVOID;
7861 }
7862
7863 /**
7864  * @brief UE out of MeasGap or AckNackReptn.
7865  *
7866  * @details
7867  *
7868  *     Function : rgSCHCmnActvtUlUe
7869  *
7870  *     This functions triggers specific scheduler
7871  *     to start considering it for scheduling.
7872  *
7873  *  @param[in]  RgSchCellCb  *cell
7874  *  @param[in]  RgSchUeCb    *ue
7875  *  @return  S16
7876  *      -# ROK
7877  *      -# RFAILED
7878  **/
7879 #ifdef ANSI
7880 Void rgSCHCmnActvtUlUe
7881 (
7882 RgSchCellCb  *cell,
7883 RgSchUeCb    *ue
7884 )
7885 #else
7886 Void rgSCHCmnActvtUlUe(cell, ue)
7887 RgSchCellCb  *cell;
7888 RgSchUeCb    *ue;
7889 #endif
7890 {
7891    RgSchCmnCell         *cellSchd = RG_SCH_CMN_GET_CELL(cell);
7892
7893    /* : take care of this in UL retransmission */
7894    cellSchd->apisUl->rgSCHUlActvtUe(cell, ue);
7895    RETVOID;
7896 }
7897
7898 /**
7899  * @brief UE out of MeasGap or AckNackReptn.
7900  *
7901  * @details
7902  *
7903  *     Function : rgSCHCmnActvtDlUe
7904  *
7905  *     This functions triggers specific scheduler
7906  *     to start considering it for scheduling.
7907  *
7908  *  @param[in]  RgSchCellCb  *cell
7909  *  @param[in]  RgSchUeCb    *ue
7910  *  @return  S16
7911  *      -# ROK
7912  *      -# RFAILED
7913  **/
7914 #ifdef ANSI
7915 Void rgSCHCmnActvtDlUe
7916 (
7917 RgSchCellCb  *cell,
7918 RgSchUeCb    *ue
7919 )
7920 #else
7921 Void rgSCHCmnActvtDlUe(cell, ue)
7922 RgSchCellCb  *cell;
7923 RgSchUeCb    *ue;
7924 #endif
7925 {
7926    RgSchCmnCell         *cellSchd = RG_SCH_CMN_GET_CELL(cell);
7927
7928    cellSchd->apisDl->rgSCHDlActvtUe(cell, ue);
7929    RETVOID;
7930 }
7931
7932 /**
7933  * @brief This API is invoked to indicate scheduler of a CRC indication.
7934  *
7935  * @details
7936  *
7937  *     Function : rgSCHCmnHdlUlTransInd
7938  *      This API is invoked to indicate scheduler of a CRC indication.
7939  *
7940  *  @param[in]  RgSchCellCb     *cell
7941  *  @param[in]  RgSchUeCb       *ue
7942  *  @param[in]  CmLteTimingInfo timingInfo
7943  *
7944  *  @return Void
7945  **/
7946 #ifdef ANSI
7947 Void rgSCHCmnHdlUlTransInd
7948 (
7949 RgSchCellCb     *cell,
7950 RgSchUeCb       *ue,
7951 CmLteTimingInfo timingInfo
7952 )
7953 #else
7954 Void rgSCHCmnHdlUlTransInd(cell, ue, timingInfo)
7955 RgSchCellCb     *cell;
7956 RgSchUeCb       *ue;
7957 CmLteTimingInfo timingInfo;
7958 #endif
7959 {
7960
7961    /* Update the latest UL dat/sig transmission time */
7962    RGSCHCPYTIMEINFO(timingInfo, ue->ul.ulTransTime);
7963    if (RG_SCH_CMN_IS_UE_PDCCHODR_INACTV(ue))
7964    {
7965       /* Some UL Transmission from this UE.
7966        * Activate this UE if it was inactive */
7967       RG_SCH_CMN_DL_UPDT_INACTV_MASK ( cell, ue, RG_PDCCHODR_INACTIVE);
7968       RG_SCH_CMN_UL_UPDT_INACTV_MASK ( cell, ue, RG_PDCCHODR_INACTIVE);
7969    }
7970    RETVOID;
7971 }
7972
7973 #ifdef TFU_UPGRADE
7974
7975 /**
7976  * @brief Compute the minimum Rank based on Codebook subset
7977  *        restriction configuration for 4 Tx Ports and Tx Mode 4.
7978  *
7979  * @details
7980  *
7981  *     Function : rgSCHCmnComp4TxMode4
7982  *
7983  *     Depending on BitMap set at CBSR during Configuration
7984  *      - return the least possible Rank
7985  *
7986  *
7987  *  @param[in]  U32 *pmiBitMap
7988  *  @return  RgSchCmnRank
7989  **/
7990 #ifdef ANSI
7991 PRIVATE RgSchCmnRank rgSCHCmnComp4TxMode4
7992 (
7993  U32    *pmiBitMap
7994  )
7995 #else
7996 PRIVATE RgSchCmnRank rgSCHCmnComp4TxMode4(pmiBitMap)
7997    U32  *pmiBitMap;
7998 #endif
7999 {
8000    U32 bitMap0, bitMap1;
8001    bitMap0 = pmiBitMap[0];
8002    bitMap1 = pmiBitMap[1];
8003    if((bitMap1) & 0xFFFF)
8004    {
8005       return  (RG_SCH_CMN_RANK_1);
8006    }
8007    else if((bitMap1>>16) & 0xFFFF)
8008    {
8009       return  (RG_SCH_CMN_RANK_2);
8010    }
8011    else if((bitMap0) & 0xFFFF)
8012    {
8013       return  (RG_SCH_CMN_RANK_3);
8014    }
8015    else if((bitMap0>>16) & 0xFFFF)
8016    {
8017       return  (RG_SCH_CMN_RANK_4);
8018    }
8019    else
8020    {
8021       return  (RG_SCH_CMN_RANK_1);
8022    }
8023 }
8024
8025
8026 /**
8027  * @brief Compute the minimum Rank based on Codebook subset
8028  *        restriction configuration for 2 Tx Ports and Tx Mode 4.
8029  *
8030  * @details
8031  *
8032  *     Function : rgSCHCmnComp2TxMode4
8033  *
8034  *     Depending on BitMap set at CBSR during Configuration
8035  *      - return the least possible Rank
8036  *
8037  *
8038  *  @param[in]  U32 *pmiBitMap
8039  *  @return  RgSchCmnRank
8040  **/
8041 #ifdef ANSI
8042 PRIVATE RgSchCmnRank rgSCHCmnComp2TxMode4
8043 (
8044  U32    *pmiBitMap
8045  )
8046 #else
8047 PRIVATE RgSchCmnRank rgSCHCmnComp2TxMode4(pmiBitMap)
8048    U32  *pmiBitMap;
8049 #endif
8050 {
8051    U32 bitMap0;
8052    bitMap0 = pmiBitMap[0];
8053    if((bitMap0>>26)& 0x0F)
8054    {
8055       return  (RG_SCH_CMN_RANK_1);
8056    }
8057    else if((bitMap0>>30) & 3)
8058    {
8059       return  (RG_SCH_CMN_RANK_2);
8060    }
8061    else
8062    {
8063       return  (RG_SCH_CMN_RANK_1);
8064    }
8065 }
8066
8067 /**
8068  * @brief Compute the minimum Rank based on Codebook subset
8069  *        restriction configuration for 4 Tx Ports and Tx Mode 3.
8070  *
8071  * @details
8072  *
8073  *     Function : rgSCHCmnComp4TxMode3
8074  *
8075  *     Depending on BitMap set at CBSR during Configuration
8076  *      - return the least possible Rank
8077  *
8078  *
8079  *  @param[in]  U32 *pmiBitMap
8080  *  @return  RgSchCmnRank
8081  **/
8082 #ifdef ANSI
8083 PRIVATE RgSchCmnRank rgSCHCmnComp4TxMode3
8084 (
8085  U32    *pmiBitMap
8086  )
8087 #else
8088 PRIVATE RgSchCmnRank rgSCHCmnComp4TxMode3(pmiBitMap)
8089    U32  *pmiBitMap;
8090 #endif
8091 {
8092    U32 bitMap0;
8093    bitMap0 = pmiBitMap[0];
8094    if((bitMap0>>28)& 1)
8095    {
8096       return  (RG_SCH_CMN_RANK_1);
8097    }
8098    else if((bitMap0>>29) &1)
8099    {
8100       return  (RG_SCH_CMN_RANK_2);
8101    }
8102    else if((bitMap0>>30) &1)
8103    {
8104       return  (RG_SCH_CMN_RANK_3);
8105    }
8106    else if((bitMap0>>31) &1)
8107    {
8108       return  (RG_SCH_CMN_RANK_4);
8109    }
8110    else
8111    {
8112       return  (RG_SCH_CMN_RANK_1);
8113    }
8114 }
8115
8116 /**
8117  * @brief Compute the minimum Rank based on Codebook subset
8118  *        restriction configuration for 2 Tx Ports and Tx Mode 3.
8119  *
8120  * @details
8121  *
8122  *     Function : rgSCHCmnComp2TxMode3
8123  *
8124  *     Depending on BitMap set at CBSR during Configuration
8125  *      - return the least possible Rank
8126  *
8127  *
8128  *  @param[in]  U32 *pmiBitMap
8129  *  @return  RgSchCmnRank
8130  **/
8131 #ifdef ANSI
8132 PRIVATE RgSchCmnRank rgSCHCmnComp2TxMode3
8133 (
8134  U32 *pmiBitMap
8135  )
8136 #else
8137 PRIVATE RgSchCmnRank rgSCHCmnComp2TxMode3(pmiBitMap)
8138    U32 *pmiBitMap;
8139 #endif
8140 {
8141    U32 bitMap0;
8142    bitMap0 = pmiBitMap[0];
8143    if((bitMap0>>30)& 1)
8144    {
8145       return  (RG_SCH_CMN_RANK_1);
8146    }
8147    else if((bitMap0>>31) &1)
8148    {
8149       return  (RG_SCH_CMN_RANK_2);
8150    }
8151    else
8152    {
8153       return  (RG_SCH_CMN_RANK_1);
8154    }
8155 }
8156
8157 /**
8158  * @brief Compute the minimum Rank based on Codebook subset
8159  *        restriction configuration.
8160  *
8161  * @details
8162  *
8163  *     Function : rgSCHCmnComputeRank
8164  *
8165  *     Depending on Num Tx Ports and Transmission mode
8166  *      - return the least possible Rank
8167  *
8168  *
8169  *  @param[in]  RgrTxMode txMode
8170  *  @param[in]  U32 *pmiBitMap
8171  *  @param[in]  U8 numTxPorts
8172  *  @return  RgSchCmnRank
8173  **/
8174 #ifdef ANSI
8175 PRIVATE RgSchCmnRank rgSCHCmnComputeRank
8176 (
8177  RgrTxMode    txMode,
8178  U32          *pmiBitMap,
8179  U8           numTxPorts
8180  )
8181 #else
8182 PRIVATE RgSchCmnRank rgSCHCmnComputeRank(txMode, pmiBitMap, numTxPorts)
8183    RgrTxMode    txMode;
8184    U32          *pmiBitMap;
8185    U8           numTxPorts;
8186 #endif
8187 {
8188
8189    if (numTxPorts ==2 && txMode == RGR_UE_TM_3)
8190    {
8191       return  (rgSCHCmnComp2TxMode3(pmiBitMap));
8192    }
8193    else if (numTxPorts ==4 && txMode == RGR_UE_TM_3)
8194    {
8195       return  (rgSCHCmnComp4TxMode3(pmiBitMap));
8196    }
8197    else if (numTxPorts ==2 && txMode == RGR_UE_TM_4)
8198    {
8199       return  (rgSCHCmnComp2TxMode4(pmiBitMap));
8200    }
8201    else if (numTxPorts ==4 && txMode == RGR_UE_TM_4)
8202    {
8203       return  (rgSCHCmnComp4TxMode4(pmiBitMap));
8204    }
8205    else
8206    {
8207       return  (RG_SCH_CMN_RANK_1);
8208    }
8209 }
8210
8211 #endif
8212
8213 /**
8214  * @brief Harq Entity Deinitialization for CMN SCH.
8215  *
8216  * @details
8217  *
8218  *     Function : rgSCHCmnDlDeInitHqEnt 
8219  *
8220  *     Harq Entity Deinitialization for CMN SCH 
8221  *
8222  *  @param[in]  RgSchCellCb  *cell
8223  *  @param[in]  RgSchDlHqEnt *hqE 
8224  *  @return  VOID
8225  **/
8226 /*KWORK_FIX:Changed function return type to void */
8227 #ifdef ANSI
8228 Void rgSCHCmnDlDeInitHqEnt 
8229 (
8230 RgSchCellCb  *cell,
8231 RgSchDlHqEnt *hqE
8232 )
8233 #else
8234 Void rgSCHCmnDlDeInitHqEnt(cell, hqE)
8235 RgSchCellCb  *cell;
8236 RgSchDlHqEnt *hqE;
8237 #endif
8238 {
8239    RgSchCmnCell         *cellSchd = RG_SCH_CMN_GET_CELL(cell);
8240    RgSchDlHqProcCb      *hqP;
8241    U8                   cnt;
8242    S16                  ret;
8243
8244
8245    ret = cellSchd->apisDl->rgSCHDlUeHqEntDeInit(cell, hqE);
8246    /* Free only If the Harq proc are created*/
8247    if(RFAILED == ret)
8248    {
8249    }
8250
8251    for(cnt = 0; cnt < hqE->numHqPrcs; cnt++)
8252    {
8253       hqP = &hqE->procs[cnt];
8254       if ((RG_SCH_CMN_GET_DL_HQP(hqP)))
8255       {
8256          rgSCHUtlFreeSBuf(cell->instIdx,
8257               (Data**)(&(hqP->sch)), (sizeof(RgSchCmnDlHqProc)));
8258       }
8259    }
8260 #ifdef LTE_ADV
8261    rgSCHLaaDeInitDlHqProcCb (cell, hqE);
8262 #endif
8263
8264    RETVOID;
8265 }
8266
8267 /**
8268  * @brief Harq Entity initialization for CMN SCH.
8269  *
8270  * @details
8271  *
8272  *     Function : rgSCHCmnDlInitHqEnt 
8273  *
8274  *     Harq Entity initialization for CMN SCH 
8275  *
8276  *  @param[in]  RgSchCellCb  *cell
8277  *  @param[in]  RgSchUeCb    *ue
8278  *  @return  S16
8279  *      -# ROK
8280  *      -# RFAILED
8281  **/
8282 #ifdef ANSI
8283 S16 rgSCHCmnDlInitHqEnt 
8284 (
8285 RgSchCellCb  *cell,
8286 RgSchDlHqEnt  *hqEnt
8287 )
8288 #else
8289 S16 rgSCHCmnDlInitHqEnt(cell, hqEnt)
8290 RgSchCellCb  *cell;
8291 RgSchDlHqEnt  *hqEnt;
8292 #endif
8293
8294 {
8295    RgSchDlHqProcCb      *hqP;
8296    U8                   cnt;
8297
8298    RgSchCmnCell         *cellSchd = RG_SCH_CMN_GET_CELL(cell);
8299
8300    for(cnt = 0; cnt < hqEnt->numHqPrcs; cnt++)
8301    {
8302       hqP = &hqEnt->procs[cnt];
8303       if (rgSCHUtlAllocSBuf(cell->instIdx,
8304                (Data**)&(hqP->sch), (sizeof(RgSchCmnDlHqProc))) != ROK)
8305       {
8306          return RFAILED;
8307       }
8308    }
8309 #ifdef EMTC_ENABLE
8310    if((cell->emtcEnable) &&(hqEnt->ue->isEmtcUe))
8311    {
8312       if(ROK != cellSchd->apisEmtcDl->rgSCHDlUeHqEntInit(cell, hqEnt))
8313       {
8314          return RFAILED;
8315       }
8316
8317    }
8318    else
8319 #endif
8320    {
8321       if(ROK != cellSchd->apisDl->rgSCHDlUeHqEntInit(cell, hqEnt))
8322       {
8323          return RFAILED;
8324       }
8325    }
8326
8327    return ROK;
8328 }  /* rgSCHCmnDlInitHqEnt */
8329
8330 /**
8331  * @brief This function computes distribution of refresh period
8332  *
8333  * @details
8334  *
8335  *     Function: rgSCHCmnGetRefreshDist 
8336  *     Purpose: This function computes distribution of refresh period
8337  *              This is required to align set of UEs refresh
8338  *              around the different consecutive subframe.
8339  *               
8340  *     Invoked by: rgSCHCmnGetRefreshPerDist
8341  *
8342  *  @param[in]  RgSchCellCb        *cell
8343  *  @param[in]  RgSchUeCb          *ue
8344  *  @return  Void
8345  *
8346  **/
8347 #ifdef ANSI
8348 PRIVATE U8 rgSCHCmnGetRefreshDist 
8349 (
8350 RgSchCellCb        *cell,
8351 RgSchUeCb          *ue
8352 )
8353 #else
8354 PRIVATE U8 rgSCHCmnGetRefreshDist(cell, ue)
8355 RgSchCellCb        *cell;
8356 RgSchUeCb          *ue;
8357 #endif
8358 {
8359    U8   refOffst;
8360 #ifdef DEBUGP
8361    Inst inst = cell->instIdx;
8362 #endif
8363
8364    for(refOffst = 0; refOffst < RGSCH_MAX_REFRESH_OFFSET; refOffst++)
8365    {
8366       if(cell->refreshUeCnt[refOffst] < RGSCH_MAX_REFRESH_GRPSZ)
8367       {
8368          cell->refreshUeCnt[refOffst]++;
8369          ue->refreshOffset = refOffst;
8370          /* printf("UE[%d] refresh offset[%d]. Cell refresh ue count[%d].\n", ue->ueId, refOffst,  cell->refreshUeCnt[refOffst]); */
8371          return (refOffst);
8372       }
8373    }
8374   
8375    RGSCHDBGERRNEW(inst, (rgSchPBuf(inst), "Allocation of refresh distribution failed\n"));
8376    /* We should not enter here  normally, but incase of failure, allocating from  last offset*/
8377    cell->refreshUeCnt[refOffst-1]++;
8378    ue->refreshOffset = refOffst-1;
8379
8380    return (refOffst-1);
8381 }
8382 /**
8383  * @brief This function computes initial Refresh Wait Period.
8384  *
8385  * @details
8386  *
8387  *     Function: rgSCHCmnGetRefreshPer 
8388  *     Purpose: This function computes initial Refresh Wait Period.
8389  *              This is required to align multiple UEs refresh
8390  *              around the same time.
8391  *               
8392  *     Invoked by: rgSCHCmnGetRefreshPer 
8393  *
8394  *  @param[in]  RgSchCellCb        *cell
8395  *  @param[in]  RgSchUeCb          *ue
8396  *  @param[in]  U32                *waitPer 
8397  *  @return  Void
8398  *
8399  **/
8400 #ifdef ANSI
8401 PRIVATE Void rgSCHCmnGetRefreshPer 
8402 (
8403 RgSchCellCb        *cell,
8404 RgSchUeCb          *ue,
8405 U32                *waitPer
8406 )
8407 #else
8408 PRIVATE Void rgSCHCmnGetRefreshPer(cell, ue, waitPer)
8409 RgSchCellCb        *cell;
8410 RgSchUeCb          *ue;
8411 U32                *waitPer;
8412 #endif
8413 {
8414    U32       refreshPer;           
8415    U32       crntSubFrm;
8416
8417
8418    refreshPer = RG_SCH_CMN_REFRESH_TIME * RG_SCH_CMN_REFRESH_TIMERES;
8419    crntSubFrm = cell->crntTime.sfn * RGSCH_NUM_SUB_FRAMES_5G + cell->crntTime.slot;
8420    /* Fix: syed align multiple UEs to refresh at same time */
8421    *waitPer = refreshPer - (crntSubFrm % refreshPer);
8422    *waitPer = RGSCH_CEIL(*waitPer, RG_SCH_CMN_REFRESH_TIMERES);
8423    *waitPer = *waitPer + rgSCHCmnGetRefreshDist(cell, ue);
8424
8425    RETVOID;
8426 }
8427
8428
8429 #ifdef LTE_ADV
8430 /**
8431  * @brief UE initialisation for scheduler.
8432  *
8433  * @details
8434  *
8435  *     Function : rgSCHCmnRgrSCellUeCfg
8436  *
8437  *     This functions intialises UE specific scheduler 
8438  *     information for SCELL
8439  *     0. Perform basic validations
8440  *     1. Allocate common sched UE cntrl blk
8441  *     2. Perform DL cfg (allocate Hq Procs Cmn sched cntrl blks)
8442  *     3. Perform UL cfg
8443  *     4. Perform DLFS cfg
8444  *
8445  *  @param[in]  RgSchCellCb  *cell
8446  *  @param[in]  RgSchUeCb    *ue
8447  *  @param[out] RgSchErrInfo *err
8448  *  @return  S16
8449  *      -# ROK
8450  *      -# RFAILED
8451  **/
8452 #ifdef ANSI
8453 S16 rgSCHCmnRgrSCellUeCfg
8454 (
8455 RgSchCellCb  *sCell,
8456 RgSchUeCb    *ue,
8457 RgrUeSecCellCfg  *sCellInfoCfg,
8458 RgSchErrInfo *err
8459 )
8460 #else
8461 S16 rgSCHCmnRgrSCellUeCfg(sCell, ue, sCellInfoCfg, err)
8462 RgSchCellCb  *sCell;
8463 RgSchUeCb    *ue;
8464 RgrUeSecCellCfg  *sCellInfoCfg;
8465 RgSchErrInfo *err;
8466 #endif
8467 {
8468    U8 i;
8469    S16                  ret;
8470    U8                   cnt;
8471    RgSchCmnAllocRecord  *allRcd;
8472    RgSchDlRbAlloc       *allocInfo;
8473    RgSchCmnCell         *cellSchd = RG_SCH_CMN_GET_CELL(ue->cell);
8474    RgSchCmnUlUe         *ueUl;
8475    RgSchCmnUlUe         *ueUlPcell;
8476    RgSchCmnUe           *pCellUeSchCmn;
8477    RgSchCmnUe           *ueSchCmn;
8478    RgSchCmnDlUe         *ueDl;
8479    RgSchCmnDlUe         *pCellUeDl;
8480 #ifdef DEBUGP
8481    Inst                 inst = ue->cell->instIdx;
8482 #endif
8483    U32 idx = (U8)((sCell->cellId - rgSchCb[sCell->instIdx].genCfg.startCellId)&(CM_LTE_MAX_CELLS-1));
8484
8485    pCellUeSchCmn = RG_SCH_CMN_GET_UE(ue,ue->cell);
8486    pCellUeDl = &pCellUeSchCmn->dl;
8487
8488    /* 1. Allocate Common sched control block */
8489    if((rgSCHUtlAllocSBuf(sCell->instIdx,
8490                (Data**)&(((ue->cellInfo[ue->cellIdToCellIdxMap[idx]])->sch)), (sizeof(RgSchCmnUe))) != ROK))
8491    {
8492       RGSCHDBGERRNEW(inst, (rgSchPBuf(inst), "Memory allocation FAILED\n"));
8493       err->errCause = RGSCHERR_SCH_CFG;
8494       return RFAILED;
8495    }
8496    ueSchCmn = RG_SCH_CMN_GET_UE(ue,sCell);
8497
8498    /*2.  Perform UEs downlink configuration */
8499    ueDl = &ueSchCmn->dl;
8500
8501    /*CA TODO*/
8502    ueDl->mimoInfo = pCellUeDl->mimoInfo;
8503
8504    if ((ue->mimoInfo.txMode == RGR_UE_TM_4) ||
8505          (ue->mimoInfo.txMode == RGR_UE_TM_6))
8506    {
8507       RG_SCH_CMN_SET_FORCE_TD(ue, sCell, RG_SCH_CMN_TD_NO_PMI);
8508    }
8509    if (ue->mimoInfo.txMode == RGR_UE_TM_3)
8510    {
8511       RG_SCH_CMN_SET_FORCE_TD(ue, sCell, RG_SCH_CMN_TD_RI_1);
8512    }
8513    RGSCH_ARRAY_BOUND_CHECK(sCell->instIdx, rgUeCatTbl, pCellUeSchCmn->cmn.ueCat);
8514    ueDl->maxTbBits = rgUeCatTbl[pCellUeSchCmn->cmn.ueCat].maxDlTbBits;
8515    /*CA dev-Start*/
8516    U8 ri = 0;
8517    ri = RGSCH_MIN(ri, sCell->numTxAntPorts);
8518    if(((CM_LTE_UE_CAT_6 == pCellUeSchCmn->cmn.ueCat )
8519             ||(CM_LTE_UE_CAT_7 == pCellUeSchCmn->cmn.ueCat)) 
8520          && (4 == ri))
8521    {
8522       ueDl->maxTbSz = rgUeCatTbl[pCellUeSchCmn->cmn.ueCat].maxDlBits[1];
8523    }
8524    else
8525    {
8526       ueDl->maxTbSz = rgUeCatTbl[pCellUeSchCmn->cmn.ueCat].maxDlBits[0];
8527    }
8528    /*CA dev-End*/
8529    /* Fix : syed Assign hqEnt to UE only if msg4 is done */
8530 #ifdef LTE_TDD
8531    ueDl->maxSbSz = (rgUeCatTbl[pCellUeSchCmn->cmn.ueCat].maxSftChBits/
8532          rgSchTddDlNumHarqProcTbl[sCell->ulDlCfgIdx]);
8533 #else
8534    ueDl->maxSbSz = (rgUeCatTbl[pCellUeSchCmn->cmn.ueCat].maxSftChBits/
8535          RGSCH_NUM_DL_HQ_PROC);
8536 #endif
8537 #ifdef EMTC_ENABLE   
8538    rgSCHCmnDlSetUeAllocLmt(sCell, ueDl, ue->isEmtcUe);
8539 #else
8540    rgSCHCmnDlSetUeAllocLmt(sCell, ueDl, FALSE);
8541 #endif      
8542
8543    /* DL ambr */
8544    /* ambrCfgd config moved to ueCb.dl, as it's not needed for per cell wise*/
8545
8546    allocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue, sCell);
8547    allocInfo->rnti = ue->ueId;
8548
8549    /* Initializing the lastCfi value to current cfi value */
8550    ueDl->lastCfi = cellSchd->dl.currCfi;
8551
8552    if ((cellSchd->apisDl->rgSCHRgrSCellDlUeCfg(sCell, ue, err)) != ROK)
8553    {
8554       RGSCHDBGERRNEW(inst, (rgSchPBuf(inst), "Spec Sched DL UE CFG FAILED\n"));
8555       return RFAILED;
8556    }
8557
8558    /* TODO: enhance for DLFS RB Allocation for SCELLs in future dev */
8559
8560    /* DLFS UE Config */
8561    if (cellSchd->dl.isDlFreqSel)
8562    {
8563       if ((cellSchd->apisDlfs->rgSCHDlfsSCellUeCfg(sCell, ue, sCellInfoCfg, err)) != ROK)
8564       {
8565          RGSCHDBGERRNEW(inst, (rgSchPBuf(inst), "DLFS UE config FAILED\n"));
8566          return RFAILED;
8567       }
8568    }
8569
8570    /* TODO: Do UL SCELL CFG during UL CA dev */
8571    {
8572       ueUl = RG_SCH_CMN_GET_UL_UE(ue, sCell);
8573
8574       /* TODO_ULCA: SRS for SCELL needs to be handled in the below function call */
8575       rgSCHCmnUpdUeUlCqiInfo(sCell, ue, ueUl, ueSchCmn, cellSchd,
8576             sCell->isCpUlExtend);
8577
8578       ret = rgSCHUhmHqEntInit(sCell, ue);
8579       if (ret != ROK)
8580       {
8581          RLOG_ARG1(L_ERROR,DBG_CELLID,sCell->cellId,"SCELL UHM HARQ Ent Init "
8582                "Failed for CRNTI:%d", ue->ueId);
8583          return RFAILED;
8584       }
8585
8586       ueUlPcell = RG_SCH_CMN_GET_UL_UE(ue, ue->cell);
8587       /* Initialize uplink HARQ related information for UE */
8588       ueUl->hqEnt.maxHqRetx = ueUlPcell->hqEnt.maxHqRetx;
8589       cmLListInit(&ueUl->hqEnt.free);
8590       cmLListInit(&ueUl->hqEnt.inUse);
8591       for(i=0; i < ueUl->hqEnt.numHqPrcs; i++)
8592       {
8593          ueUl->hqEnt.hqProcCb[i].hqEnt = (void*)(&ueUl->hqEnt);
8594          ueUl->hqEnt.hqProcCb[i].procId = i;
8595          ueUl->hqEnt.hqProcCb[i].ulSfIdx = RGSCH_INVALID_INFO;
8596          ueUl->hqEnt.hqProcCb[i].alloc = NULLP;
8597 #ifdef LTEMAC_SPS
8598          /* ccpu00139513- Initializing SPS flags*/
8599          ueUl->hqEnt.hqProcCb[i].isSpsActvnHqP = FALSE;
8600          ueUl->hqEnt.hqProcCb[i].isSpsOccnHqP = FALSE;
8601 #endif
8602          cmLListAdd2Tail(&ueUl->hqEnt.free, &ueUl->hqEnt.hqProcCb[i].lnk);
8603          ueUl->hqEnt.hqProcCb[i].lnk.node = (PTR)&ueUl->hqEnt.hqProcCb[i];
8604       }
8605
8606       /* Allocate UL BSR allocation tracking List */
8607       cmLListInit(&ueUl->ulAllocLst);
8608
8609       for (cnt = 0; cnt < RG_SCH_CMN_MAX_ALLOC_TRACK; cnt++)
8610       {
8611          if((rgSCHUtlAllocSBuf(sCell->instIdx,
8612                      (Data**)&(allRcd),sizeof(RgSchCmnAllocRecord)) != ROK))
8613          {
8614             RLOG_ARG1(L_ERROR,DBG_CELLID,sCell->cellId,"SCELL Memory allocation FAILED"
8615                   "for CRNTI:%d",ue->ueId);
8616             err->errCause = RGSCHERR_SCH_CFG;
8617             return RFAILED;
8618          }
8619          allRcd->allocTime = sCell->crntTime;
8620          cmLListAdd2Tail(&ueUl->ulAllocLst, &allRcd->lnk);
8621          allRcd->lnk.node = (PTR)allRcd;
8622       }
8623
8624       /* After initialising UL part, do power related init */
8625       ret = rgSCHPwrUeSCellCfg(sCell, ue, sCellInfoCfg);
8626       if (ret != ROK)
8627       {
8628          RLOG_ARG1(L_ERROR,DBG_CELLID,sCell->cellId, "Could not do "
8629                "power config for UE CRNTI:%d",ue->ueId);
8630          return RFAILED;
8631       }
8632
8633 #ifdef EMTC_ENABLE   
8634       if(TRUE == ue->isEmtcUe)
8635       {
8636          if ((cellSchd->apisEmtcUl->rgSCHRgrUlUeCfg(sCell, ue, NULL, err)) != ROK)
8637          {
8638             RLOG_ARG1(L_ERROR,DBG_CELLID,sCell->cellId, "Spec Sched UL UE CFG FAILED"
8639                   "for CRNTI:%d",ue->ueId);
8640             return RFAILED;
8641          }
8642       }
8643       else
8644 #endif
8645       {
8646       if ((cellSchd->apisUl->rgSCHRgrUlUeCfg(sCell, ue, NULL, err)) != ROK)
8647       {
8648          RLOG_ARG1(L_ERROR,DBG_CELLID,sCell->cellId, "Spec Sched UL UE CFG FAILED"
8649                "for CRNTI:%d",ue->ueId);
8650          return RFAILED;
8651       }
8652       }
8653    
8654       ue->ul.isUlCaEnabled = TRUE;
8655    }
8656
8657    return ROK;
8658 }  /* rgSCHCmnRgrSCellUeCfg */
8659
8660
8661 /**
8662  * @brief UE initialisation for scheduler.
8663  *
8664  * @details
8665  *
8666  *     Function : rgSCHCmnRgrSCellUeDel 
8667  *
8668  *     This functions Delete UE specific scheduler 
8669  *     information for SCELL
8670  *
8671  *  @param[in]  RgSchCellCb  *cell
8672  *  @param[in]  RgSchUeCb    *ue
8673  *  @return  S16
8674  *      -# ROK
8675  *      -# RFAILED
8676  **/
8677 #ifdef ANSI
8678 S16 rgSCHCmnRgrSCellUeDel
8679 (
8680 RgSchUeCellInfo *sCellInfo,
8681 RgSchUeCb    *ue
8682 )
8683 #else
8684 S16 rgSCHCmnRgrSCellUeDel(sCellInfo, ue)
8685 RgSchUeCellInfo *sCellInfo;
8686 RgSchUeCb    *ue;
8687 #endif
8688 {
8689    RgSchCmnCell         *cellSchd = RG_SCH_CMN_GET_CELL(ue->cell);
8690    Inst                 inst = ue->cell->instIdx;
8691
8692
8693    cellSchd->apisDl->rgSCHRgrSCellDlUeDel(sCellInfo, ue);
8694
8695    /* UL CA */
8696    rgSCHCmnUlUeDelAllocs(sCellInfo->cell, ue);
8697
8698 #ifdef EMTC_ENABLE   
8699    if(TRUE == ue->isEmtcUe)
8700    {
8701       cellSchd->apisEmtcUl->rgSCHFreeUlUe(sCellInfo->cell, ue);
8702    }
8703    else
8704 #endif
8705    {
8706    cellSchd->apisUl->rgSCHFreeUlUe(sCellInfo->cell, ue);
8707    }
8708
8709    /* DLFS UE Config */
8710    if (cellSchd->dl.isDlFreqSel)
8711    {
8712       if ((cellSchd->apisDlfs->rgSCHDlfsSCellUeDel(sCellInfo->cell, ue)) != ROK)
8713       {
8714          RGSCHDBGERRNEW(inst, (rgSchPBuf(inst), "DLFS Scell del FAILED\n"));
8715          return RFAILED;
8716       }
8717    }
8718
8719    rgSCHUtlFreeSBuf(sCellInfo->cell->instIdx,
8720          (Data**)(&(sCellInfo->sch)), (sizeof(RgSchCmnUe)));
8721
8722
8723    return ROK;
8724 }  /* rgSCHCmnRgrSCellUeDel */
8725  
8726 #endif
8727
8728 #ifdef RG_5GTF
8729 /**
8730  * @brief Handles 5gtf configuration for a UE
8731  *
8732  * @details
8733  *
8734  *     Function : rgSCHCmn5gtfUeCfg
8735  *
8736  *     Processing Steps:
8737  *
8738  *      - Return ROK
8739  *
8740  *  @param[in]  RgSchCellCb  *cell
8741  *  @param[in]  RgSchUeCb    *ue
8742  *  @param[in]  RgrUeCfg     *cfg
8743  *  @return  S16
8744  *      -# ROK
8745  *      -# RFAILED
8746  **/
8747 #ifdef ANSI
8748 S16 rgSCHCmn5gtfUeCfg
8749 (
8750 RgSchCellCb *cell,
8751 RgSchUeCb   *ue,
8752 RgrUeCfg    *cfg
8753 )
8754 #else
8755 S16 rgSCHCmn5gtfUeCfg(cell, ue, cfg)
8756 RgSchCellCb *cell;
8757 RgSchUeCb   *ue;
8758 RgrUeCfg    *cfg;
8759 #endif
8760 {
8761
8762    RgSchUeGrp *ue5gtfGrp;
8763    ue->ue5gtfCb.grpId = cfg->ue5gtfCfg.grpId;
8764    ue->ue5gtfCb.BeamId = cfg->ue5gtfCfg.BeamId;
8765    ue->ue5gtfCb.numCC = cfg->ue5gtfCfg.numCC;   
8766    ue->ue5gtfCb.mcs = cfg->ue5gtfCfg.mcs;
8767    ue->ue5gtfCb.maxPrb = cfg->ue5gtfCfg.maxPrb;
8768
8769    ue->ue5gtfCb.cqiRiPer = 100;
8770    /* 5gtf TODO: CQIs to start from (10,0)*/
8771    ue->ue5gtfCb.nxtCqiRiOccn.sfn = 10;
8772    ue->ue5gtfCb.nxtCqiRiOccn.slot = 0;
8773    ue->ue5gtfCb.rank = 1;
8774
8775    printf("\nschd cfg at mac,%u,%u,%u,%u,%u\n",ue->ue5gtfCb.grpId,ue->ue5gtfCb.BeamId,ue->ue5gtfCb.numCC,
8776          ue->ue5gtfCb.mcs,ue->ue5gtfCb.maxPrb); 
8777
8778    ue5gtfGrp = &(cell->cell5gtfCb.ueGrp5gConf[ue->ue5gtfCb.BeamId]);
8779
8780    /* TODO_5GTF: Currently handling 1 group only. Need to update when multi group 
8781       scheduling comes into picture */
8782    if(ue5gtfGrp->beamBitMask & (1 << ue->ue5gtfCb.BeamId))
8783    {
8784       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
8785             "5GTF_ERROR Invalid beam id CRNTI:%d",cfg->crnti);
8786       return RFAILED;
8787    }
8788    ue5gtfGrp->beamBitMask |= (1 << ue->ue5gtfCb.BeamId);
8789
8790    return ROK;
8791 }
8792 #endif
8793
8794 /**
8795  * @brief UE initialisation for scheduler.
8796  *
8797  * @details
8798  *
8799  *     Function : rgSCHCmnRgrUeCfg
8800  *
8801  *     This functions intialises UE specific scheduler
8802  *     information
8803  *     0. Perform basic validations
8804  *     1. Allocate common sched UE cntrl blk
8805  *     2. Perform DL cfg (allocate Hq Procs Cmn sched cntrl blks)
8806  *     3. Perform UL cfg
8807  *     4. Perform DLFS cfg
8808  *
8809  *  @param[in]  RgSchCellCb  *cell
8810  *  @param[in]  RgSchUeCb    *ue
8811  *  @param[int] RgrUeCfg     *ueCfg
8812  *  @param[out] RgSchErrInfo *err
8813  *  @return  S16
8814  *      -# ROK
8815  *      -# RFAILED
8816  **/
8817 #ifdef ANSI
8818 S16 rgSCHCmnRgrUeCfg
8819 (
8820 RgSchCellCb  *cell,
8821 RgSchUeCb    *ue,
8822 RgrUeCfg     *ueCfg,
8823 RgSchErrInfo *err
8824 )
8825 #else
8826 S16 rgSCHCmnRgrUeCfg(cell, ue, ueCfg, err)
8827 RgSchCellCb  *cell;
8828 RgSchUeCb    *ue;
8829 RgrUeCfg     *ueCfg;
8830 RgSchErrInfo *err;
8831 #endif
8832 {
8833    RgSchDlRbAlloc  *allocInfo;
8834    S16                  ret;
8835    RgSchCmnCell         *cellSchd = RG_SCH_CMN_GET_CELL(cell);
8836    RgSchCmnUe           *ueSchCmn;
8837    RgSchCmnUlUe         *ueUl;
8838    RgSchCmnDlUe         *ueDl;
8839    U8                   cnt;
8840    RgSchCmnAllocRecord  *allRcd;
8841    U32                  waitPer;
8842    U32                  idx = (U8)((cell->cellId - rgSchCb[cell->instIdx].genCfg.startCellId)&(CM_LTE_MAX_CELLS-1));
8843    RgSchUeCellInfo      *pCellInfo = RG_SCH_CMN_GET_PCELL_INFO(ue);
8844
8845
8846    /* 1. Allocate Common sched control block */
8847    if((rgSCHUtlAllocSBuf(cell->instIdx,
8848                (Data**)&(((ue->cellInfo[ue->cellIdToCellIdxMap[idx]])->sch)), (sizeof(RgSchCmnUe))) != ROK))
8849    {
8850       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
8851             "Memory allocation FAILED for CRNTI:%d",ueCfg->crnti);
8852       err->errCause = RGSCHERR_SCH_CFG;
8853       return RFAILED;
8854    }
8855    ueSchCmn   = RG_SCH_CMN_GET_UE(ue,cell);
8856    ue->dl.ueDlCqiCfg = ueCfg->ueDlCqiCfg;
8857    pCellInfo->acqiCb.aCqiCfg = ueCfg->ueDlCqiCfg.aprdCqiCfg;
8858    if(ueCfg->ueCatEnum > 0 )
8859    {
8860      /*KWORK_FIX removed NULL chk for ueSchCmn*/
8861       ueSchCmn->cmn.ueCat = ueCfg->ueCatEnum - 1; 
8862    }
8863    else
8864    {
8865       ueSchCmn->cmn.ueCat = 0; /* Assuming enum values correctly set */
8866    }
8867    cmInitTimers(&ueSchCmn->cmn.tmr, 1);
8868
8869    /*2.  Perform UEs downlink configuration */
8870    ueDl = &ueSchCmn->dl;
8871    /* RACHO : store the rapId assigned for HandOver UE.
8872     * Append UE to handover list of cmnCell */
8873    if (ueCfg->dedPreambleId.pres == PRSNT_NODEF)
8874    {
8875       rgSCHCmnDelDedPreamble(cell, ueCfg->dedPreambleId.val);
8876       ueDl->rachInfo.hoRapId = ueCfg->dedPreambleId.val;
8877       cmLListAdd2Tail(&cellSchd->rachCfg.hoUeLst, &ueDl->rachInfo.hoLnk);
8878       ueDl->rachInfo.hoLnk.node = (PTR)ue;
8879    }
8880
8881    rgSCHCmnUpdUeMimoInfo(ueCfg, ueDl, cell, cellSchd);
8882
8883    if (ueCfg->txMode.pres == TRUE)
8884    {
8885       if ((ueCfg->txMode.txModeEnum == RGR_UE_TM_4) ||
8886             (ueCfg->txMode.txModeEnum == RGR_UE_TM_6))
8887       {
8888          RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_NO_PMI);
8889       }
8890       if (ueCfg->txMode.txModeEnum == RGR_UE_TM_3)
8891       {
8892          RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_RI_1);
8893       }
8894    }
8895    RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgUeCatTbl, ueSchCmn->cmn.ueCat);
8896    ueDl->maxTbBits = rgUeCatTbl[ueSchCmn->cmn.ueCat].maxDlTbBits;
8897    /*CA dev-Start*/
8898    U8 ri = 0;
8899    ri = RGSCH_MIN(ri, cell->numTxAntPorts);
8900    if(((CM_LTE_UE_CAT_6 == ueSchCmn->cmn.ueCat )
8901             ||(CM_LTE_UE_CAT_7 == ueSchCmn->cmn.ueCat)) 
8902                   && (4 == ri))
8903    {
8904       ueDl->maxTbSz = rgUeCatTbl[ueSchCmn->cmn.ueCat].maxDlBits[1];
8905    }
8906    else
8907    {
8908       ueDl->maxTbSz = rgUeCatTbl[ueSchCmn->cmn.ueCat].maxDlBits[0];
8909    }
8910    /*CA dev-End*/
8911    /* Fix : syed Assign hqEnt to UE only if msg4 is done */
8912 #ifdef LTE_TDD
8913    ueDl->maxSbSz = (rgUeCatTbl[ueSchCmn->cmn.ueCat].maxSftChBits/
8914          rgSchTddDlNumHarqProcTbl[cell->ulDlCfgIdx]);
8915 #else
8916    ueDl->maxSbSz = (rgUeCatTbl[ueSchCmn->cmn.ueCat].maxSftChBits/
8917          RGSCH_NUM_DL_HQ_PROC);
8918 #endif
8919 #ifdef EMTC_ENABLE   
8920    rgSCHCmnDlSetUeAllocLmt(cell, ueDl, ue->isEmtcUe);
8921 #else
8922    rgSCHCmnDlSetUeAllocLmt(cell, ueDl, FALSE);
8923 #endif 
8924      /* if none of the DL and UL AMBR are configured then fail the configuration
8925     */     
8926    if((ueCfg->ueQosCfg.dlAmbr == 0) && (ueCfg->ueQosCfg.ueBr == 0))
8927    {
8928       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"UL Ambr and DL Ambr are"
8929          "configured as 0 for CRNTI:%d",ueCfg->crnti);
8930       err->errCause = RGSCHERR_SCH_CFG;
8931       return RFAILED;
8932    }
8933    /* DL ambr */
8934    ue->dl.ambrCfgd = (ueCfg->ueQosCfg.dlAmbr * RG_SCH_CMN_REFRESH_TIME)/100;
8935
8936    allocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue, cell);
8937    allocInfo->rnti = ue->ueId;
8938
8939    /* Initializing the lastCfi value to current cfi value */
8940    ueDl->lastCfi = cellSchd->dl.currCfi;
8941 #ifdef EMTC_ENABLE
8942    if(cell->emtcEnable && ue->isEmtcUe)
8943    {
8944       if ((cellSchd->apisEmtcDl->rgSCHRgrDlUeCfg(cell, ue, ueCfg, err)) != ROK)
8945       {
8946          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
8947                "Spec Sched DL UE CFG FAILED for CRNTI:%d",ueCfg->crnti);
8948          return RFAILED;
8949       }
8950
8951    }
8952    else
8953 #endif
8954    {
8955       if ((cellSchd->apisDl->rgSCHRgrDlUeCfg(cell, ue, ueCfg, err)) != ROK)
8956       {
8957          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
8958                "Spec Sched DL UE CFG FAILED for CRNTI:%d",ueCfg->crnti);
8959          return RFAILED;
8960       }
8961    }
8962
8963
8964
8965    /* 3. Initialize ul part */
8966    ueUl     = &ueSchCmn->ul;
8967
8968    rgSCHCmnUpdUeUlCqiInfo(cell, ue, ueUl, ueSchCmn, cellSchd,
8969             cell->isCpUlExtend);
8970
8971    ue->ul.maxBytesPerUePerTti = rgUeCatTbl[ueSchCmn->cmn.ueCat].maxUlBits * \
8972                                RG_SCH_CMN_MAX_BITS_RATIO / (RG_SCH_CMN_UL_COM_DENOM*8);
8973
8974    ue->ul.cfgdAmbr = (ueCfg->ueQosCfg.ueBr * RG_SCH_CMN_REFRESH_TIME)/100;
8975    ue->ul.effAmbr = ue->ul.cfgdAmbr;
8976    RGSCHCPYTIMEINFO(cell->crntTime, ue->ul.ulTransTime);
8977
8978    /* Allocate UL BSR allocation tracking List */
8979    cmLListInit(&ueUl->ulAllocLst);
8980
8981    for (cnt = 0; cnt < RG_SCH_CMN_MAX_ALLOC_TRACK; cnt++)
8982    {
8983       if((rgSCHUtlAllocSBuf(cell->instIdx,
8984                   (Data**)&(allRcd),sizeof(RgSchCmnAllocRecord)) != ROK))
8985       {
8986          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Memory allocation FAILED"
8987                    "for CRNTI:%d",ueCfg->crnti);
8988          err->errCause = RGSCHERR_SCH_CFG;
8989          return RFAILED;
8990       }
8991       allRcd->allocTime = cell->crntTime;
8992       cmLListAdd2Tail(&ueUl->ulAllocLst, &allRcd->lnk);
8993       allRcd->lnk.node = (PTR)allRcd;
8994    }
8995    /* Allocate common sch cntrl blocks for LCGs */
8996    for (cnt=0; cnt<RGSCH_MAX_LCG_PER_UE; cnt++)
8997    {
8998       ret = rgSCHUtlAllocSBuf(cell->instIdx,
8999             (Data**)&(ue->ul.lcgArr[cnt].sch), (sizeof(RgSchCmnLcg)));
9000       if (ret != ROK)
9001       {
9002          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
9003             "SCH struct alloc failed for CRNTI:%d",ueCfg->crnti);
9004          err->errCause = RGSCHERR_SCH_CFG;
9005          return (ret);
9006       }
9007    }
9008    /* After initialising UL part, do power related init */
9009    ret = rgSCHPwrUeCfg(cell, ue, ueCfg);
9010    if (ret != ROK)
9011    {
9012       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "Could not do "
9013          "power config for UE CRNTI:%d",ueCfg->crnti);
9014       return RFAILED;
9015    }
9016 #ifdef LTEMAC_SPS
9017    ret = rgSCHCmnSpsUeCfg(cell, ue, ueCfg, err);
9018    if (ret != ROK)
9019    {
9020       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "Could not do "
9021          "SPS config for CRNTI:%d",ueCfg->crnti);
9022       return RFAILED;
9023    }
9024 #endif /* LTEMAC_SPS */
9025
9026 #ifdef EMTC_ENABLE   
9027    if(TRUE == ue->isEmtcUe)
9028    {
9029       if ((cellSchd->apisEmtcUl->rgSCHRgrUlUeCfg(cell, ue, ueCfg, err)) != ROK)
9030       {
9031          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "Spec Sched UL UE CFG FAILED"
9032                   "for CRNTI:%d",ueCfg->crnti);
9033          return RFAILED;
9034       }
9035    }
9036    else
9037 #endif
9038    {
9039    if ((cellSchd->apisUl->rgSCHRgrUlUeCfg(cell, ue, ueCfg, err)) != ROK)
9040    {
9041       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "Spec Sched UL UE CFG FAILED"
9042                "for CRNTI:%d",ueCfg->crnti);
9043       return RFAILED;
9044    }
9045    }
9046
9047    /* DLFS UE Config */
9048    if (cellSchd->dl.isDlFreqSel)
9049    {
9050       if ((cellSchd->apisDlfs->rgSCHDlfsUeCfg(cell, ue, ueCfg, err)) != ROK)
9051       {
9052          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "DLFS UE config FAILED"
9053                    "for CRNTI:%d",ueCfg->crnti);
9054          return RFAILED;
9055       }
9056    }
9057
9058    /* Fix: syed align multiple UEs to refresh at same time */
9059    rgSCHCmnGetRefreshPer(cell, ue, &waitPer);
9060    /* Start UE Qos Refresh Timer */
9061    rgSCHCmnAddUeToRefreshQ(cell, ue, waitPer);
9062 #ifdef RG_5GTF
9063    rgSCHCmn5gtfUeCfg(cell, ue, ueCfg);
9064 #endif
9065
9066    return ROK;
9067 }  /* rgSCHCmnRgrUeCfg */
9068
9069 /**
9070  * @brief UE TX mode reconfiguration handler.
9071  *
9072  * @details
9073  *
9074  *     Function : rgSCHCmnDlHdlTxModeRecfg
9075  *
9076  *     This functions updates UE specific scheduler
9077  *     information upon UE reconfiguration.
9078  *
9079  *  @param[in]  RgSchUeCb    *ue
9080  *  @param[in] RgrUeRecfg   *ueRecfg
9081  *  @return  Void
9082  **/
9083 #ifdef TFU_UPGRADE
9084 #ifdef ANSI
9085 PRIVATE Void rgSCHCmnDlHdlTxModeRecfg
9086 (
9087 RgSchCellCb *cell,
9088 RgSchUeCb    *ue,
9089 RgrUeRecfg   *ueRecfg,
9090 U8 numTxPorts
9091 )
9092 #else
9093 PRIVATE Void rgSCHCmnDlHdlTxModeRecfg(cell, ue, ueRecfg, numTxPorts)
9094 RgSchCellCb *cell;
9095 RgSchUeCb    *ue;
9096 RgrUeRecfg   *ueRecfg;
9097 U8 numTxPorts;
9098 #endif
9099 #else
9100 #ifdef ANSI
9101 PRIVATE Void rgSCHCmnDlHdlTxModeRecfg
9102 (
9103 RgSchCellCb *cell,
9104 RgSchUeCb    *ue,
9105 RgrUeRecfg   *ueRecfg
9106 )
9107 #else
9108 PRIVATE Void rgSCHCmnDlHdlTxModeRecfg(cell, ue, ueRecfg)
9109 RgSchCellCb *cell;
9110 RgSchUeCb    *ue;
9111 RgrUeRecfg   *ueRecfg;
9112 #endif
9113 #endif
9114 {
9115    RgSchCmnDlUe *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
9116
9117    if (ueRecfg->txMode.pres != PRSNT_NODEF)
9118    {
9119       RETVOID;
9120    }
9121    /* ccpu00140894- Starting Timer for TxMode Transition Completion*/
9122    ue->txModeTransCmplt =FALSE;
9123    rgSCHTmrStartTmr (ue->cell, ue, RG_SCH_TMR_TXMODE_TRNSTN, RG_SCH_TXMODE_TRANS_TIMER);
9124    if (ueRecfg->txMode.tmTrnstnState == RGR_TXMODE_RECFG_CMPLT)
9125    {
9126       RG_SCH_CMN_UNSET_FORCE_TD(ue, cell,
9127                                 RG_SCH_CMN_TD_TXMODE_RECFG);
9128      /* MS_WORKAROUND for ccpu00123186 MIMO Fix Start: need to set FORCE TD bitmap based on TX mode */
9129      ueDl->mimoInfo.ri = 1;
9130      if ((ueRecfg->txMode.txModeEnum == RGR_UE_TM_4) ||
9131           (ueRecfg->txMode.txModeEnum == RGR_UE_TM_6))
9132       {
9133          RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_NO_PMI);
9134       }
9135       if (ueRecfg->txMode.txModeEnum == RGR_UE_TM_3)
9136       {
9137          RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_RI_1);
9138       }
9139       /* MIMO Fix End: need to set FORCE TD bitmap based on TX mode */
9140       RETVOID;
9141    }
9142    if (ueRecfg->txMode.tmTrnstnState == RGR_TXMODE_RECFG_START)
9143    {
9144       /* start afresh forceTD masking */
9145       RG_SCH_CMN_INIT_FORCE_TD(ue, cell, 0);
9146       RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_TXMODE_RECFG);
9147       /* Intialize MIMO related parameters of UE */
9148
9149 #ifdef TFU_UPGRADE
9150       if(ueRecfg->txMode.pres)
9151       {
9152          if((ueRecfg->txMode.txModeEnum ==RGR_UE_TM_3) ||
9153                (ueRecfg->txMode.txModeEnum ==RGR_UE_TM_4))
9154          {
9155             if(ueRecfg->ueCodeBookRstRecfg.pres)
9156             {
9157                ueDl->mimoInfo.ri =
9158                   rgSCHCmnComputeRank(ueRecfg->txMode.txModeEnum,
9159                     ueRecfg->ueCodeBookRstRecfg.pmiBitMap, numTxPorts);
9160             }
9161             else
9162             {
9163                ueDl->mimoInfo.ri = 1;
9164             }
9165          }
9166          else
9167          {
9168             ueDl->mimoInfo.ri = 1;
9169          }
9170       }
9171       else
9172       {
9173          ueDl->mimoInfo.ri = 1;
9174       }
9175 #else
9176       ueDl->mimoInfo.ri = 1;
9177 #endif /* TFU_UPGRADE */
9178       if ((ueRecfg->txMode.txModeEnum == RGR_UE_TM_4) ||
9179           (ueRecfg->txMode.txModeEnum == RGR_UE_TM_6))
9180       {
9181          RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_NO_PMI);
9182       }
9183       if (ueRecfg->txMode.txModeEnum == RGR_UE_TM_3)
9184       {
9185          RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_RI_1);
9186       }
9187       RETVOID;
9188    }
9189 }
9190 /***********************************************************
9191  *
9192  *     Func : rgSCHCmnUpdUeMimoInfo
9193  *
9194  *     Desc : Updates UL and DL Ue Information
9195  *
9196  *     Ret  :
9197  *
9198  *     Notes:
9199  *
9200  *     File :
9201  *
9202  **********************************************************/
9203 #ifdef ANSI
9204 PRIVATE Void rgSCHCmnUpdUeMimoInfo
9205 (
9206 RgrUeCfg     *ueCfg,
9207 RgSchCmnDlUe *ueDl,
9208 RgSchCellCb  *cell,
9209 RgSchCmnCell *cellSchd
9210 )
9211 #else
9212 PRIVATE Void rgSCHCmnUpdUeMimoInfo(ueCfg, ueDl, cell, cellSchd)
9213 RgrUeCfg     *ueCfg;
9214 RgSchCmnDlUe *ueDl;
9215 RgSchCellCb  *cell;
9216 RgSchCmnCell *cellSchd;
9217 #endif
9218 {
9219 #ifdef TFU_UPGRADE
9220    if(ueCfg->txMode.pres)
9221    {
9222       if((ueCfg->txMode.txModeEnum ==RGR_UE_TM_3) ||
9223             (ueCfg->txMode.txModeEnum ==RGR_UE_TM_4))
9224       {
9225          if(ueCfg->ueCodeBookRstCfg.pres)
9226          {
9227             ueDl->mimoInfo.ri =
9228                rgSCHCmnComputeRank(ueCfg->txMode.txModeEnum,
9229                  ueCfg->ueCodeBookRstCfg.pmiBitMap, cell->numTxAntPorts);
9230          }
9231          else
9232          {
9233             ueDl->mimoInfo.ri = 1;
9234          }
9235       }
9236       else
9237       {
9238          ueDl->mimoInfo.ri = 1;
9239       }
9240    }
9241    else
9242    {
9243       ueDl->mimoInfo.ri = 1;
9244    }
9245
9246 #else
9247    ueDl->mimoInfo.ri = 1;
9248 #endif /*TFU_UPGRADE */
9249    ueDl->mimoInfo.cwInfo[0].cqi = cellSchd->dl.ccchCqi;
9250    ueDl->mimoInfo.cwInfo[1].cqi = cellSchd->dl.ccchCqi;
9251
9252    RETVOID;
9253 }
9254 /***********************************************************
9255  *
9256  *     Func : rgSCHCmnUpdUeUlCqiInfo
9257  *
9258  *     Desc : Updates UL and DL Ue Information
9259  *
9260  *     Ret  :
9261  *
9262  *     Notes:
9263  *
9264  *     File :
9265  *
9266  **********************************************************/
9267 #ifdef ANSI
9268 PRIVATE Void rgSCHCmnUpdUeUlCqiInfo
9269 (
9270 RgSchCellCb   *cell,
9271 RgSchUeCb     *ue,
9272 RgSchCmnUlUe  *ueUl,
9273 RgSchCmnUe    *ueSchCmn,
9274 RgSchCmnCell  *cellSchd,
9275 Bool          isEcp
9276 )
9277 #else
9278 PRIVATE Void rgSCHCmnUpdUeUlCqiInfo(cell, ue, ueUl, ueSchCmn, cellSchd, isEcp)
9279 RgSchCellCb  *cell;
9280 RgSchUeCb    *ue;
9281 RgSchCmnUlUe *ueUl;
9282 RgSchCmnUe   *ueSchCmn;
9283 RgSchCmnCell *cellSchd;
9284 Bool          isEcp;
9285 #endif
9286 {
9287
9288
9289 #ifdef TFU_UPGRADE
9290    if(ue->srsCb.srsCfg.type  ==  RGR_SCH_SRS_SETUP)
9291    {
9292      if(ue->ul.ulTxAntSel.pres)
9293      {
9294        ueUl->crntUlCqi[ue->srsCb.selectedAnt] = cellSchd->ul.dfltUlCqi;
9295        ueUl->validUlCqi = ueUl->crntUlCqi[ue->srsCb.selectedAnt];
9296      }
9297      else
9298      {
9299        ueUl->crntUlCqi[0] = cellSchd->ul.dfltUlCqi;
9300        ueUl->validUlCqi =  ueUl->crntUlCqi[0];
9301      }
9302       ue->validTxAnt = ue->srsCb.selectedAnt;
9303    }
9304    else
9305    {
9306       ueUl->validUlCqi = cellSchd->ul.dfltUlCqi;
9307       ue->validTxAnt = 0;
9308    }
9309 #ifdef UL_LA
9310    ueUl->ulLaCb.cqiBasediTbs = rgSchCmnUlCqiToTbsTbl[isEcp]
9311                                                 [ueUl->validUlCqi] * 100;   
9312    ueUl->ulLaCb.deltaiTbs = 0;
9313 #endif
9314
9315 #else
9316    ueUl->crntUlCqi[0] = cellSchd->ul.dfltUlCqi;
9317 #endif /*TFU_UPGRADE */
9318    RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgUeCatTbl, ueSchCmn->cmn.ueCat);
9319    if (rgUeCatTbl[ueSchCmn->cmn.ueCat].ul64qamSup == FALSE)
9320    {
9321       ueUl->maxUlCqi = cellSchd->ul.max16qamCqi;
9322    }
9323    else
9324    {
9325       ueUl->maxUlCqi = RG_SCH_CMN_UL_NUM_CQI - 1;
9326    }
9327
9328    RETVOID;
9329 }
9330 /***********************************************************
9331  *
9332  *     Func : rgSCHCmnUpdUeCatCfg
9333  *
9334  *     Desc : Updates UL and DL Ue Information
9335  *
9336  *     Ret  :
9337  *
9338  *     Notes:
9339  *
9340  *     File :
9341  *
9342  **********************************************************/
9343 #ifdef ANSI
9344 PRIVATE Void rgSCHCmnUpdUeCatCfg
9345 (
9346 RgSchUeCb    *ue,
9347 RgSchCellCb  *cell
9348 )
9349 #else
9350 PRIVATE Void rgSCHCmnUpdUeCatCfg(ue, cell)
9351 RgSchUeCb    *ue;
9352 RgSchCellCb  *cell;
9353 #endif
9354 {
9355    RgSchDlHqEnt *hqE = NULLP;
9356    RgSchCmnUlUe *ueUl     = RG_SCH_CMN_GET_UL_UE(ue,cell);
9357    RgSchCmnDlUe *ueDl     = RG_SCH_CMN_GET_DL_UE(ue,cell);
9358    RgSchCmnUe   *ueSchCmn = RG_SCH_CMN_GET_UE(ue,cell);
9359    RgSchCmnCell *cellSchd = RG_SCH_CMN_GET_CELL(cell);
9360
9361
9362    ueDl->maxTbBits = rgUeCatTbl[ueSchCmn->cmn.ueCat].maxDlTbBits;
9363    
9364    hqE = RG_SCH_CMN_GET_UE_HQE(ue, cell);
9365    /*CA dev-Start*/
9366    U8 ri = 0;
9367    ri = RGSCH_MIN(ri, cell->numTxAntPorts);
9368    if(((CM_LTE_UE_CAT_6 == ueSchCmn->cmn.ueCat )
9369             ||(CM_LTE_UE_CAT_7 == ueSchCmn->cmn.ueCat)) 
9370          && (RG_SCH_MAX_TX_LYRS_4 == ri))
9371    {
9372       ueDl->maxTbSz = rgUeCatTbl[ueSchCmn->cmn.ueCat].maxDlBits[1];
9373    }
9374    else
9375    {
9376       ueDl->maxTbSz = rgUeCatTbl[ueSchCmn->cmn.ueCat].maxDlBits[0];
9377    }
9378    /*CA dev-End*/
9379    ueDl->maxSbSz = (rgUeCatTbl[ueSchCmn->cmn.ueCat].maxSftChBits/
9380                            hqE->numHqPrcs);
9381    if (rgUeCatTbl[ueSchCmn->cmn.ueCat].ul64qamSup == FALSE)
9382    {
9383       ueUl->maxUlCqi = cellSchd->ul.max16qamCqi;
9384    }
9385    else
9386    {
9387       ueUl->maxUlCqi = RG_SCH_CMN_UL_NUM_CQI - 1;
9388    }
9389    ue->ul.maxBytesPerUePerTti = rgUeCatTbl[ueSchCmn->cmn.ueCat].maxUlBits * \
9390                    RG_SCH_CMN_MAX_BITS_RATIO / (RG_SCH_CMN_UL_COM_DENOM*8);
9391    RETVOID;
9392 }
9393
9394 /**
9395  * @brief UE reconfiguration for scheduler.
9396  *
9397  * @details
9398  *
9399  *     Function : rgSChCmnRgrUeRecfg
9400  *
9401  *     This functions updates UE specific scheduler
9402  *     information upon UE reconfiguration.
9403  *
9404  *  @param[in]  RgSchCellCb  *cell
9405  *  @param[in]  RgSchUeCb    *ue
9406  *  @param[int] RgrUeRecfg   *ueRecfg
9407  *  @param[out] RgSchErrInfo *err
9408  *  @return  S16
9409  *      -# ROK
9410  *      -# RFAILED
9411  **/
9412 #ifdef ANSI
9413 S16 rgSCHCmnRgrUeRecfg
9414 (
9415 RgSchCellCb  *cell,
9416 RgSchUeCb    *ue,
9417 RgrUeRecfg   *ueRecfg,
9418 RgSchErrInfo *err
9419 )
9420 #else
9421 S16 rgSCHCmnRgrUeRecfg(cell, ue, ueRecfg, err)
9422 RgSchCellCb  *cell;
9423 RgSchUeCb    *ue;
9424 RgrUeRecfg   *ueRecfg;
9425 RgSchErrInfo *err;
9426 #endif
9427 {
9428    RgSchCmnCell *cellSchCmn = RG_SCH_CMN_GET_CELL(cell);
9429    U32          waitPer;
9430
9431    /* Basic validations */
9432    if (ueRecfg->ueRecfgTypes & RGR_UE_TXMODE_RECFG)
9433    {
9434 #ifdef TFU_UPGRADE
9435       rgSCHCmnDlHdlTxModeRecfg(cell, ue, ueRecfg, cell->numTxAntPorts);
9436 #else
9437       rgSCHCmnDlHdlTxModeRecfg(cell, ue, ueRecfg);
9438 #endif /* TFU_UPGRADE */
9439    }
9440    if(ueRecfg->ueRecfgTypes & RGR_UE_CSG_PARAM_RECFG)
9441    {
9442       ue->csgMmbrSta = ueRecfg->csgMmbrSta;
9443    }
9444    /* Changes for UE Category reconfiguration feature */
9445    if(ueRecfg->ueRecfgTypes & RGR_UE_UECAT_RECFG)
9446    {
9447        rgSCHCmnUpdUeCatCfg(ue, cell);
9448    }
9449    if (ueRecfg->ueRecfgTypes & RGR_UE_APRD_DLCQI_RECFG)
9450    {
9451       RgSchUeCellInfo *pCellInfo = RG_SCH_CMN_GET_PCELL_INFO(ue);
9452       pCellInfo->acqiCb.aCqiCfg = ueRecfg->aprdDlCqiRecfg;
9453    }
9454 #ifndef TFU_UPGRADE
9455    if (ueRecfg->ueRecfgTypes & RGR_UE_PRD_DLCQI_RECFG)
9456    {
9457       if ((ueRecfg->prdDlCqiRecfg.pres == TRUE)
9458             && (ueRecfg->prdDlCqiRecfg.prdModeEnum != RGR_PRD_CQI_MOD10)
9459             && (ueRecfg->prdDlCqiRecfg.prdModeEnum != RGR_PRD_CQI_MOD20))
9460       {
9461          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,"Unsupported periodic CQI "
9462             "reporting mode %d for old CRNIT:%d", 
9463             (int)ueRecfg->prdDlCqiRecfg.prdModeEnum,ueRecfg->oldCrnti);
9464          err->errCause = RGSCHERR_SCH_CFG;
9465          return RFAILED;
9466       }
9467      ue->dl.ueDlCqiCfg.prdCqiCfg = ueRecfg->prdDlCqiRecfg;
9468    }
9469 #endif
9470
9471    if (ueRecfg->ueRecfgTypes & RGR_UE_ULPWR_RECFG)
9472    {
9473       if (rgSCHPwrUeRecfg(cell, ue, ueRecfg) != ROK)
9474       {
9475          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
9476                "Power Reconfiguration Failed for OLD CRNTI:%d",ueRecfg->oldCrnti);
9477          return RFAILED;
9478       }
9479    }
9480
9481    if (ueRecfg->ueRecfgTypes & RGR_UE_QOS_RECFG)
9482    {
9483       /* Uplink Sched related Initialization */
9484       if ((ueRecfg->ueQosRecfg.dlAmbr == 0) && (ueRecfg->ueQosRecfg.ueBr == 0))
9485       {
9486          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Ul Ambr and DL Ambr "
9487             "configured as 0 for OLD CRNTI:%d",ueRecfg->oldCrnti);
9488          err->errCause = RGSCHERR_SCH_CFG;
9489          return RFAILED;
9490       }
9491       ue->ul.cfgdAmbr = (ueRecfg->ueQosRecfg.ueBr * \
9492       RG_SCH_CMN_REFRESH_TIME)/100;
9493       /* Downlink Sched related Initialization */
9494       ue->dl.ambrCfgd = (ueRecfg->ueQosRecfg.dlAmbr * \
9495       RG_SCH_CMN_REFRESH_TIME)/100;
9496       /* Fix: syed Update the effAmbr and effUeBR fields w.r.t the
9497        * new QOS configuration */
9498       rgSCHCmnDelUeFrmRefreshQ(cell, ue);
9499       /* Fix: syed align multiple UEs to refresh at same time */
9500       rgSCHCmnGetRefreshPer(cell, ue, &waitPer);
9501       rgSCHCmnApplyUeRefresh(cell, ue);
9502       rgSCHCmnAddUeToRefreshQ(cell, ue, waitPer);
9503    }
9504 #ifdef EMTC_ENABLE   
9505    if((cell->emtcEnable)&&(TRUE == ue->isEmtcUe))
9506    {
9507       if ((cellSchCmn->apisEmtcUl->rgSCHRgrUlUeRecfg(cell, ue, ueRecfg, err)) != ROK)
9508       {
9509          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
9510                "Spec Sched UL UE ReCFG FAILED for CRNTI:%d",ue->ueId);
9511          return RFAILED;
9512       }
9513       if ((cellSchCmn->apisEmtcDl->rgSCHRgrDlUeRecfg(cell, ue, ueRecfg, err)) != ROK)
9514       {
9515          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
9516                "Spec Sched DL UE ReCFG FAILED for CRNTI:%d",ue->ueId);
9517          return RFAILED;
9518       }
9519    }
9520    else
9521 #endif
9522    {
9523       if ((cellSchCmn->apisUl->rgSCHRgrUlUeRecfg(cell, ue, ueRecfg, err)) != ROK)
9524       {
9525          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
9526             "Spec Sched UL UE ReCFG FAILED for CRNTI:%d",ue->ueId);
9527          return RFAILED;
9528       }
9529       if ((cellSchCmn->apisDl->rgSCHRgrDlUeRecfg(cell, ue, ueRecfg, err)) != ROK)
9530       {
9531          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
9532             "Spec Sched DL UE ReCFG FAILED for CRNTI:%d",ue->ueId);
9533          return RFAILED;
9534       }
9535    }
9536    /* DLFS UE Config */
9537    if (cellSchCmn->dl.isDlFreqSel)
9538    {
9539       if ((cellSchCmn->apisDlfs->rgSCHDlfsUeRecfg(cell, ue, \
9540          ueRecfg, err)) != ROK)
9541       {
9542          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
9543                "DLFS UE re-config FAILED for CRNTI:%d",ue->ueId);
9544          return RFAILED;
9545       }
9546    }
9547
9548 #ifdef LTEMAC_SPS
9549    /* Invoke re-configuration on SPS module */
9550    if (rgSCHCmnSpsUeRecfg(cell, ue, ueRecfg, err) != ROK)
9551    {
9552       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
9553               "DL SPS ReCFG FAILED for UE CRNTI:%d", ue->ueId);
9554       return RFAILED;
9555    }
9556 #endif
9557
9558    return ROK;
9559 }  /* rgSCHCmnRgrUeRecfg*/
9560
9561 /***********************************************************
9562  *
9563  *     Func : rgSCHCmnUlUeDelAllocs
9564  *
9565  *     Desc : Deletion of all UE allocations.
9566  *
9567  *     Ret  :
9568  *
9569  *     Notes:
9570  *
9571  *     File :
9572  *
9573  **********************************************************/
9574 #ifdef ANSI
9575 PRIVATE Void rgSCHCmnUlUeDelAllocs
9576 (
9577 RgSchCellCb  *cell,
9578 RgSchUeCb   *ue
9579 )
9580 #else
9581 PRIVATE Void rgSCHCmnUlUeDelAllocs(cell, ue)
9582 RgSchCellCb  *cell;
9583 RgSchUeCb   *ue;
9584 #endif
9585 {
9586    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
9587    RgSchCmnUlUe *ueUl = RG_SCH_CMN_GET_UL_UE(ue, cell);
9588    U8 i;
9589 #ifdef LTEMAC_SPS
9590    RgSchCmnUlUeSpsInfo   *ulSpsUe   = RG_SCH_CMN_GET_UL_SPS_UE(ue,cell);
9591 #endif
9592
9593    for (i = 0; i < ueUl->hqEnt.numHqPrcs; ++i)
9594    {
9595       RgSchUlHqProcCb *proc = rgSCHUhmGetUlHqProc(cell, ue, i);
9596
9597 #ifdef ERRCLS_KW
9598       /* proc can't be NULL here */
9599       if (proc)
9600 #endif
9601       {
9602          /* R8 Upgrade */
9603          proc->ndi = 0;
9604          if (proc->alloc)
9605          {
9606             /* Added Insure Fixes Of reading Dangling memory.NULLed crntAlloc */
9607 #ifdef LTEMAC_SPS
9608             if(proc->alloc == ulSpsUe->ulSpsSchdInfo.crntAlloc)
9609             {
9610                ulSpsUe->ulSpsSchdInfo.crntAlloc = NULLP;
9611                ulSpsUe->ulSpsSchdInfo.crntAllocSf = NULLP;
9612             }
9613 #endif
9614 #ifdef EMTC_ENABLE
9615             rgSCHCmnUlFreeAllocation(cell, &cellUl->ulSfArr[proc->ulSfIdx],
9616                   proc->alloc,ue->isEmtcUe);
9617 #else
9618             rgSCHCmnUlFreeAllocation(cell, &cellUl->ulSfArr[proc->ulSfIdx],
9619                   proc->alloc);
9620 #endif
9621             /* PHY probably needn't be intimated since
9622              * whatever intimation it needs happens at the last minute
9623              */
9624          }
9625          /* Fix: syed Adaptive Msg3 Retx crash. Remove the harqProc
9626           * from adaptive retx List. */
9627          if (proc->reTxLnk.node)
9628          {
9629             {
9630                //TODO_SID: Need to take care
9631                cmLListDelFrm(&cellUl->reTxLst, &proc->reTxLnk); 
9632                proc->reTxLnk.node = (PTR)NULLP;
9633             }
9634          }
9635       }
9636    }
9637    RETVOID;
9638 }
9639
9640 /***********************************************************
9641  *
9642  *     Func : rgSCHCmnDelUeFrmRefreshQ
9643  *
9644  *     Desc : Adds a UE to refresh queue, so that the UE is
9645  *            periodically triggered to refresh it's GBR and
9646  *            AMBR values.
9647  *
9648  *     Ret  :
9649  *
9650  *     Notes:
9651  *
9652  *     File :
9653  *
9654  **********************************************************/
9655 #ifdef ANSI
9656 PRIVATE Void rgSCHCmnDelUeFrmRefreshQ
9657 (
9658 RgSchCellCb     *cell,
9659 RgSchUeCb       *ue
9660 )
9661 #else
9662 PRIVATE Void rgSCHCmnDelUeFrmRefreshQ(cell, ue)
9663 RgSchCellCb     *cell;
9664 RgSchUeCb       *ue;
9665 #endif
9666 {
9667    RgSchCmnCell   *sched  = RG_SCH_CMN_GET_CELL(cell);
9668    CmTmrArg       arg;
9669    RgSchCmnUeInfo *ueSchd = RG_SCH_CMN_GET_CMN_UE(ue);
9670
9671
9672 #ifdef RGL_SPECIFIC_CHANGES
9673    if(ue->refreshOffset < RGSCH_MAX_REFRESH_GRPSZ)
9674    {
9675       if(cell->refreshUeCnt[ue->refreshOffset])
9676       {
9677          cell->refreshUeCnt[ue->refreshOffset]--;
9678       }
9679    }
9680 #endif
9681
9682
9683    memset(&arg, 0, sizeof(arg));
9684    arg.tqCp   = &sched->tmrTqCp;
9685    arg.tq     = sched->tmrTq;
9686    arg.timers = &ueSchd->tmr;
9687    arg.cb     = (PTR)ue;
9688    arg.tNum   = 0;
9689    arg.max    = 1;
9690    arg.evnt   = RG_SCH_CMN_EVNT_UE_REFRESH;
9691
9692    cmRmvCbTq(&arg);
9693    RETVOID;
9694 }
9695
9696 /***********************************************************
9697  *
9698  *     Func : rgSCHCmnUeCcchSduDel
9699  *
9700  *     Desc : Clear CCCH SDU scheduling context.
9701  *
9702  *     Ret  :
9703  *
9704  *     Notes:
9705  *
9706  *     File :
9707  *
9708  **********************************************************/
9709 #ifdef ANSI
9710 PRIVATE Void rgSCHCmnUeCcchSduDel
9711 (
9712 RgSchCellCb  *cell,
9713 RgSchUeCb    *ueCb
9714 )
9715 #else
9716 PRIVATE Void rgSCHCmnUeCcchSduDel(cell, ueCb)
9717 RgSchCellCb  *cell;
9718 RgSchUeCb    *ueCb;
9719 #endif
9720 {
9721    RgSchDlHqEnt      *hqE = NULLP;
9722    RgSchDlHqProcCb   *ccchSduHqP = NULLP;
9723    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
9724
9725
9726    hqE = RG_SCH_CMN_GET_UE_HQE(ueCb, cell);
9727    if (hqE == NULLP)
9728    {
9729       RETVOID;
9730    }
9731    ccchSduHqP = hqE->ccchSduProc;
9732    if(ueCb->ccchSduLnk.node != NULLP)
9733    {
9734       /* Remove the ccchSduProc if it is in the Tx list */
9735       cmLListDelFrm(&(cell->ccchSduUeLst), &(ueCb->ccchSduLnk));
9736       ueCb->ccchSduLnk.node = NULLP;   
9737    }
9738    else if(ccchSduHqP != NULLP)
9739    {
9740       /* Fix for crash due to stale pdcch. Release ccch pdcch*/
9741       if(ccchSduHqP->pdcch)
9742       {
9743          cmLListDelFrm(&ccchSduHqP->subFrm->pdcchInfo.pdcchs,
9744                &ccchSduHqP->pdcch->lnk);
9745          cmLListAdd2Tail(&cell->pdcchLst, &ccchSduHqP->pdcch->lnk);
9746          ccchSduHqP->pdcch = NULLP;
9747       }
9748       if(ccchSduHqP->tbInfo[0].ccchSchdInfo.retxLnk.node != NULLP)
9749       {
9750          /* Remove the ccchSduProc if it is in the retx list */
9751          cmLListDelFrm(&cellSch->dl.ccchSduRetxLst,
9752           &ccchSduHqP->tbInfo[0].ccchSchdInfo.retxLnk);
9753          /* ccchSduHqP->tbInfo[0].ccchSchdInfo.retxLnk.node = NULLP; */
9754          rgSCHDhmRlsHqpTb(ccchSduHqP, 0, TRUE);
9755       }
9756       else if ((ccchSduHqP->subFrm != NULLP) &&
9757        (ccchSduHqP->hqPSfLnk.node != NULLP))
9758       {
9759          rgSCHUtlDlHqPTbRmvFrmTx(ccchSduHqP->subFrm, 
9760                ccchSduHqP, 0, FALSE);
9761          rgSCHDhmRlsHqpTb(ccchSduHqP, 0, TRUE);
9762       }
9763    }   
9764    RETVOID;
9765 }
9766
9767
9768
9769
9770 /**
9771  * @brief UE deletion for scheduler.
9772  *
9773  * @details
9774  *
9775  *     Function : rgSCHCmnUeDel
9776  *
9777  *     This functions deletes all scheduler information
9778  *     pertaining to an UE.
9779  *
9780  *  @param[in]  RgSchCellCb  *cell
9781  *  @param[in]  RgSchUeCb    *ue
9782  *  @return  Void
9783  **/
9784 #ifdef ANSI
9785 Void rgSCHCmnUeDel
9786 (
9787 RgSchCellCb  *cell,
9788 RgSchUeCb    *ue
9789 )
9790 #else
9791 Void rgSCHCmnUeDel(cell, ue)
9792 RgSchCellCb  *cell;
9793 RgSchUeCb    *ue;
9794 #endif
9795 {
9796    RgSchDlHqEnt         *hqE = NULLP;
9797    RgSchCmnUlUe         *ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
9798    CmLList              *node;
9799    RgSchCmnAllocRecord  *allRcd;
9800    U8                    cnt;
9801    RgSchCmnCell         *cellSchCmn = RG_SCH_CMN_GET_CELL(cell);
9802    U32                   idx = 0;
9803
9804    if (RG_SCH_CMN_GET_UE(ue,cell) == NULLP)
9805    {
9806       /* Common scheduler config has not happened yet */
9807       RETVOID;
9808    }
9809    hqE = RG_SCH_CMN_GET_UE_HQE(ue, cell);
9810    if(hqE)
9811    {
9812       /* UE Free can be triggered before MSG4 done when dlHqE is not updated */
9813 #ifdef EMTC_ENABLE
9814       if(ue->isEmtcUe)
9815       {
9816          rgSCHEmtcCmnUeCcchSduDel(cell, ue);
9817       }
9818       else
9819 #endif
9820      {    
9821          rgSCHCmnUeCcchSduDel(cell, ue);
9822      }
9823    }
9824    rgSCHCmnDelUeFrmRefreshQ(cell, ue);
9825
9826    rgSCHCmnUlUeDelAllocs(cell, ue);
9827
9828    rgSCHCmnDelRachInfo(cell, ue);
9829
9830 #ifdef EMTC_ENABLE   
9831    if(TRUE == ue->isEmtcUe)
9832    {
9833       cellSchCmn->apisEmtcUl->rgSCHFreeUlUe(cell, ue);
9834    }
9835    else
9836 #endif
9837    {
9838    cellSchCmn->apisUl->rgSCHFreeUlUe(cell, ue);
9839    }
9840 #ifdef LTE_ADV
9841    if (ue->numSCells)
9842    {
9843       for(idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
9844       {
9845          if(ue->cellInfo[idx] != NULLP) 
9846          {
9847             rgSCHSCellDelUeSCell(cell,ue,idx);
9848          }
9849       }
9850
9851    }
9852 #endif
9853 #ifdef EMTC_ENABLE
9854    if((cell->emtcEnable)&&(TRUE == ue->isEmtcUe))
9855    {
9856       cellSchCmn->apisEmtcDl->rgSCHFreeDlUe(cell, ue);
9857    }
9858    else
9859 #endif
9860    {
9861       cellSchCmn->apisDl->rgSCHFreeDlUe(cell, ue);
9862    }
9863    rgSCHPwrUeDel(cell, ue);
9864
9865 #ifdef LTEMAC_SPS
9866    rgSCHCmnSpsUeDel(cell, ue);
9867 #endif /* LTEMAC_SPS*/
9868
9869    /* CA Dev Start*/
9870    rgSchCmnDlSfHqDel(ue, cell);
9871    /* CA Dev End*/
9872    /* DLFS UE delete */
9873    if (cellSchCmn->dl.isDlFreqSel)
9874    {
9875       cellSchCmn->apisDlfs->rgSCHDlfsUeDel(cell, ue);
9876    }
9877    node = ueUl->ulAllocLst.first;
9878
9879 /* ccpu00117052 - MOD - Passing double pointer in all the places of
9880    rgSCHUtlFreeSBuf function call for proper NULLP assignment*/
9881    while(node)
9882    {
9883       allRcd = (RgSchCmnAllocRecord *)node->node;
9884       node = node->next;
9885       cmLListDelFrm(&ueUl->ulAllocLst, &allRcd->lnk);
9886       rgSCHUtlFreeSBuf(cell->instIdx,
9887          (Data**)(&allRcd), (sizeof(RgSchCmnAllocRecord)));
9888    }
9889
9890    for(cnt = 0; cnt < RGSCH_MAX_LCG_PER_UE; cnt++)
9891    {
9892       if (ue->ul.lcgArr[cnt].sch != NULLP)
9893       {
9894          rgSCHUtlFreeSBuf(cell->instIdx,
9895             (Data**)(&(ue->ul.lcgArr[cnt].sch)), (sizeof(RgSchCmnLcg)));
9896       }
9897    }
9898
9899    /* Fix : syed Moved hqEnt deinit to rgSCHCmnDlDeInitHqEnt */
9900    idx = (U8)((cell->cellId - rgSchCb[cell->instIdx].genCfg.startCellId) & (CM_LTE_MAX_CELLS - 1));
9901    rgSCHUtlFreeSBuf(cell->instIdx,
9902          (Data**)(&(((ue->cellInfo[ue->cellIdToCellIdxMap[idx]])->sch))), (sizeof(RgSchCmnUe)));
9903    RETVOID;
9904 }  /* rgSCHCmnUeDel */
9905
9906 \f
9907 /**
9908  * @brief This function handles the common code rate configurations
9909  *        done as part of RgrCellCfg/RgrCellRecfg.
9910  *
9911  * @details
9912  *
9913  *     Function: rgSCHCmnDlCnsdrCmnRt
9914  *     Purpose:  This function handles the common code rate configurations
9915  *        done as part of RgrCellCfg/RgrCellRecfg.
9916  *
9917  *     Invoked by: Scheduler
9918  *
9919  *  @param[in]  RgSchCellCb                *cell
9920  *  @param[in]  RgrDlCmnCodeRateCfg     *dlCmnCodeRate
9921  *  @return     S16
9922  *
9923  **/
9924 #ifdef ANSI
9925 PRIVATE S16 rgSCHCmnDlCnsdrCmnRt
9926 (
9927 RgSchCellCb             *cell,
9928 RgrDlCmnCodeRateCfg     *dlCmnCodeRate
9929 )
9930 #else
9931 PRIVATE S16 rgSCHCmnDlCnsdrCmnRt(cell, dlCmnCodeRate)
9932 RgSchCellCb             *cell;
9933 RgrDlCmnCodeRateCfg     *dlCmnCodeRate;
9934 #endif
9935 {
9936    RgSchCmnCell         *cellDl = RG_SCH_CMN_GET_CELL(cell);
9937    U32                  bitsPerRb;
9938    U32                  bitsPer2Rb;
9939    U32                  bitsPer3Rb;
9940    U8                   i, rbNum;
9941    U32                  pdcchBits;
9942
9943
9944    /* code rate is bits per 1024 phy bits, since modl'n scheme is 2. it is
9945     * bits per 1024/2 REs */
9946    if (dlCmnCodeRate->bcchPchRaCodeRate != 0)
9947    {
9948       bitsPerRb = ((dlCmnCodeRate->bcchPchRaCodeRate * 2) *
9949             cellDl->dl.noResPerRb[3])/1024;
9950    }
9951    else
9952    {
9953       bitsPerRb = ((RG_SCH_CMN_DEF_BCCHPCCH_CODERATE * 2) *
9954             cellDl->dl.noResPerRb[3])/1024;
9955    }
9956    /* Store bitsPerRb in cellDl->dl to use later to determine
9957     * Number of RBs for UEs with SI-RNTI, P-RNTI and RA-RNTI */
9958    cellDl->dl.bitsPerRb = bitsPerRb;
9959    /* ccpu00115595 end*/
9960    /* calculate the ITbs for 2 RBs. Initialize ITbs to MAX value */
9961    i = 0;
9962    rbNum = 2;
9963    bitsPer2Rb = bitsPerRb * rbNum;
9964    while ((i < 9) && (rgTbSzTbl[0][i][rbNum - 1] <= bitsPer2Rb))
9965       i++;
9966
9967    (i <= 1)? (cellDl->dl.cmnChITbs.iTbs2Rbs = 0) :
9968       (cellDl->dl.cmnChITbs.iTbs2Rbs = i-1);
9969
9970    /* calculate the ITbs for 3 RBs. Initialize ITbs to MAX value */
9971    i = 0;
9972    rbNum = 3;
9973    bitsPer3Rb = bitsPerRb * rbNum;
9974    while ((i < 9) && (rgTbSzTbl[0][i][rbNum - 1] <= bitsPer3Rb))
9975          i++;
9976
9977    (i <= 1)? (cellDl->dl.cmnChITbs.iTbs3Rbs = 0) :
9978       (cellDl->dl.cmnChITbs.iTbs3Rbs = i-1);
9979
9980
9981    pdcchBits = 1 + /* Flag for format0/format1a differentiation */
9982       1 + /* Localized/distributed VRB assignment flag */
9983       5 + /* For mcs */
9984 #ifndef LTE_TDD
9985       3 + /* Harq process Id */
9986 #else
9987       4 + /* Harq process Id */
9988       2 + /* UL Index or DAI */
9989 #endif
9990       1 + /* New Data Indicator */
9991       2 + /* For RV */
9992       2 + /* For tpc */
9993       1 + rgSCHUtlLog32bitNbase2((cell->bwCfg.dlTotalBw * \
9994                (cell->bwCfg.dlTotalBw + 1))/2);
9995    /* Resource block assignment ceil[log2(bw(bw+1)/2)] : \
9996       Since VRB is local */
9997    /* For TDD consider DAI */
9998
9999    /* Convert the pdcchBits to actual pdcchBits required for transmission */
10000    if (dlCmnCodeRate->pdcchCodeRate != 0)
10001    {
10002       pdcchBits = (pdcchBits * 1024)/dlCmnCodeRate->pdcchCodeRate;
10003       if (pdcchBits <= 288) /* 288 : Num of pdcch bits for aggrLvl=4 */
10004       {
10005          cellDl->dl.cmnChAggrLvl = CM_LTE_AGGR_LVL4;
10006       }
10007       else                  /* 576 : Num of pdcch bits for aggrLvl=8 */
10008       {
10009          cellDl->dl.cmnChAggrLvl = CM_LTE_AGGR_LVL8;
10010       }
10011    }
10012    else
10013    {
10014       cellDl->dl.cmnChAggrLvl = CM_LTE_AGGR_LVL4;
10015    }
10016    if (dlCmnCodeRate->ccchCqi == 0)
10017    {
10018       return RFAILED;
10019    }
10020    else
10021    {
10022       cellDl->dl.ccchCqi = dlCmnCodeRate->ccchCqi;
10023    }
10024    return ROK;
10025 }
10026
10027 #ifdef LTE_TDD
10028 /**
10029  * @brief This function handles the configuration of cell for the first
10030  *        time by the scheduler.
10031  *
10032  * @details
10033  *
10034  *     Function: rgSCHCmnDlRgrCellCfg
10035  *     Purpose:  Configuration received is stored into the data structures
10036  *               Also, update the scheduler with the number of frames of
10037  *               RACH preamble transmission.
10038  *
10039  *     Invoked by: BO and Scheduler
10040  *
10041  *  @param[in]  RgSchCellCb*     cell
10042  *  @param[in]  RgrCellCfg*      cfg
10043  *  @return     S16
10044  *
10045  **/
10046 #ifdef ANSI
10047 PRIVATE S16 rgSCHCmnDlRgrCellCfg
10048 (
10049 RgSchCellCb    *cell,
10050 RgrCellCfg     *cfg,
10051 RgSchErrInfo   *err
10052 )
10053 #else
10054 PRIVATE S16 rgSCHCmnDlRgrCellCfg(cell, cfg, err)
10055 RgSchCellCb    *cell;
10056 RgrCellCfg     *cfg;
10057 RgSchErrInfo   *err;
10058 #endif
10059 {
10060    RgSchCmnCell         *cellSch;
10061    U8                   cp;
10062    U8                   sfCount;
10063    U8                   numPdcchSym;
10064    U8                   noSymPerSlot;
10065    U8                   maxDlSubfrms = cell->numDlSubfrms;
10066    U8                   splSubfrmIdx = cfg->spclSfCfgIdx;
10067    U8                   swPtCnt = 0;
10068    Bool                 isSplfrm;
10069    RgSchTddSubfrmInfo   subfrmInfo = rgSchTddMaxUlSubfrmTbl[cell->ulDlCfgIdx];
10070    S16                  ret;
10071    U8                   splSfIdx;
10072    U8                   antPortIdx;
10073    U8                   numCrs;
10074    U8                   cfi;  
10075    U8                   cfiIdx;
10076    RgSchDlSf            *sf;
10077    U8                   splSfCfi;
10078    U8                   mPhich;
10079
10080    
10081
10082    cellSch = RG_SCH_CMN_GET_CELL(cell);
10083    cellSch->dl.numRaSubFrms = rgRaPrmblToRaFrmTbl[cell->\
10084                                                   rachCfg.preambleFormat];
10085    /*[ccpu00138532]-ADD-fill the Msg4 Harq data */
10086    cell->dlHqCfg.maxMsg4HqTx = cfg->dlHqCfg.maxMsg4HqTx;                                                
10087    
10088    /* Msg4 Tx Delay = (HARQ_RTT * MAX_MSG4_HARQ_RETX)  + 
10089                        3 TTI (MAX L1+L2 processing delay at the UE) */
10090    cellSch->dl.msg4TxDelay = (cfg->dlHqCfg.maxMsg4HqTx-1) *
10091                                  rgSchCmnHarqRtt[cell->ulDlCfgIdx] + 3; 
10092    cellSch->dl.maxUePerDlSf = cfg->maxUePerDlSf;
10093    cellSch->dl.maxUeNewTxPerTti = cfg->maxDlUeNewTxPerTti;
10094    if (cfg->maxUePerDlSf == 0)
10095    {
10096       cellSch->dl.maxUePerDlSf = RG_SCH_CMN_MAX_UE_PER_DL_SF;
10097    }
10098    if (cellSch->dl.maxUePerDlSf < cellSch->dl.maxUeNewTxPerTti)
10099    {
10100       return RFAILED;
10101    }
10102
10103
10104    if (cell->bwCfg.dlTotalBw <= 10)
10105    {
10106       cfiIdx = 1;
10107       numPdcchSym = 2;
10108    }
10109    else
10110    {
10111       cfiIdx = 0;
10112       numPdcchSym = 1;
10113    }
10114    /* DwPTS Scheduling Changes Start */
10115    cellSch->dl.splSfCfg  = splSubfrmIdx;
10116  
10117    if (cfg->isCpDlExtend == TRUE)
10118    {
10119       if((0 == splSubfrmIdx) || (4 == splSubfrmIdx) ||
10120          (7 == splSubfrmIdx) || (8 == splSubfrmIdx)
10121         )
10122       {
10123          cell->splSubfrmCfg.isDlDataAllowed = FALSE; 
10124       }
10125       else
10126       {
10127          cell->splSubfrmCfg.isDlDataAllowed = TRUE; 
10128       }
10129    }
10130    else
10131    {
10132       /* Refer to 36.213 Section 7.1.7 */
10133       if((0 == splSubfrmIdx) || (5 == splSubfrmIdx))
10134       {
10135          cell->splSubfrmCfg.isDlDataAllowed = FALSE; 
10136       }
10137       else
10138       {
10139          cell->splSubfrmCfg.isDlDataAllowed = TRUE; 
10140       }
10141    }
10142    /* DwPTS Scheduling Changes End */  
10143
10144    splSfCfi = RGSCH_MIN(cell->dynCfiCb.maxCfi, cellSch->cfiCfg.cfi);
10145    RGSCH_GET_SPS_SF_CFI(cell->bwCfg.dlTotalBw, splSfCfi);
10146    
10147    for (sfCount = 0; sfCount < maxDlSubfrms; sfCount++)
10148    {
10149       sf = cell->subFrms[sfCount];
10150       /* Sfcount matches the first special subframe occurs at Index 0
10151             * or subsequent special subframes */
10152       if(subfrmInfo.switchPoints == 1)
10153       {
10154          isSplfrm = rgSCHCmnIsSplSubfrm(swPtCnt, sfCount,
10155                                  RG_SCH_CMN_10_MS_PRD, &subfrmInfo);
10156       }
10157       else
10158       {
10159          isSplfrm = rgSCHCmnIsSplSubfrm(swPtCnt, sfCount,
10160                                  RG_SCH_CMN_5_MS_PRD, &subfrmInfo);
10161       }
10162       if(isSplfrm == TRUE)
10163       {
10164          swPtCnt++;
10165          /* DwPTS Scheduling Changes Start */        
10166          if (cell->splSubfrmCfg.isDlDataAllowed == TRUE)
10167          {
10168             sf->sfType = RG_SCH_SPL_SF_DATA;
10169          }
10170          else
10171          {
10172             sf->sfType = RG_SCH_SPL_SF_NO_DATA;
10173          }
10174          /* DwPTS Scheduling Changes End */
10175       }
10176       else
10177       {
10178          /* DwPTS Scheduling Changes Start */
10179          if (sf->sfNum != 0)
10180          {
10181             sf->sfType = RG_SCH_DL_SF;
10182          }
10183          else
10184          {
10185             sf->sfType = RG_SCH_DL_SF_0;
10186          }
10187          /* DwPTS Scheduling Changes End */
10188       }
10189       
10190       /* Calculate the number of CCEs per subframe in the cell */
10191       mPhich = rgSchTddPhichMValTbl[cell->ulDlCfgIdx][sf->sfNum];
10192       if(cell->dynCfiCb.isDynCfiEnb == TRUE)
10193       {   
10194          /* In case if Dynamic CFI feature is enabled, default CFI 
10195           * value 1 is used  */
10196          sf->nCce = cell->dynCfiCb.cfi2NCceTbl[mPhich][1];
10197       }
10198       else
10199       {
10200          if (sf->sfType == RG_SCH_SPL_SF_DATA)
10201          {
10202             sf->nCce = cell->dynCfiCb.cfi2NCceTbl[mPhich][splSfCfi];
10203          }
10204          else
10205          {
10206             sf->nCce = cell->dynCfiCb.cfi2NCceTbl[mPhich][RGSCH_MIN(cell->dynCfiCb.maxCfi, cellSch->cfiCfg.cfi)];
10207          }
10208       }   
10209    }
10210
10211    /* Intialize the RACH response scheduling related infromation */
10212    if(rgSCHCmnDlRachInfoInit(cell) != ROK)
10213    {
10214      return RFAILED;
10215    }
10216
10217    /* Allocate PRACH preamble list */
10218    rgSCHCmnDlCreateRachPrmLst(cell);
10219
10220    /* Initialize PHICH offset information */
10221    rgSCHCmnDlPhichOffsetInit(cell);
10222
10223    /* Update the size of HARQ ACK/NACK feedback table */
10224    /* The array size is increased by 2 to have enough free indices, where other
10225     * indices are busy waiting for HARQ feedback */
10226    cell->ackNackFdbkArrSize = rgSchTddANFdbkMapTbl[cell->ulDlCfgIdx] + 2; 
10227
10228    /* Initialize expected HARQ ACK/NACK feedback time */
10229    rgSCHCmnDlANFdbkInit(cell);
10230
10231    /* Initialize UL association set index */
10232    if(cell->ulDlCfgIdx != 0)
10233    {
10234       rgSCHCmnDlKdashUlAscInit(cell);
10235    }
10236
10237    if (cfg->isCpDlExtend == TRUE)
10238    {
10239       cp = RG_SCH_CMN_EXT_CP;
10240       noSymPerSlot = 6;
10241       cell->splSubfrmCfg.dwPts =
10242           rgSchTddSplSubfrmInfoTbl[splSubfrmIdx].extDlDwPts;
10243    
10244       if ( cell->splSubfrmCfg.dwPts == 0 )
10245       {
10246          cell->isDwPtsCnted = FALSE;
10247       }
10248       else
10249       {
10250          cell->isDwPtsCnted = TRUE;
10251       }
10252
10253       if(cfg->isCpUlExtend == TRUE)
10254       {
10255          cell->splSubfrmCfg.upPts =
10256             rgSchTddSplSubfrmInfoTbl[splSubfrmIdx].extDlExtUpPts;
10257       }
10258       else
10259       {
10260          cell->splSubfrmCfg.upPts =
10261             rgSchTddSplSubfrmInfoTbl[splSubfrmIdx].extDlNorUpPts;
10262       }
10263    }
10264    else
10265    {
10266       cp = RG_SCH_CMN_NOR_CP;
10267       noSymPerSlot = 7;
10268       cell->splSubfrmCfg.dwPts =
10269           rgSchTddSplSubfrmInfoTbl[splSubfrmIdx].norDlDwPts;
10270       cell->isDwPtsCnted = TRUE;
10271
10272       if(cfg->isCpUlExtend == TRUE)
10273       {
10274          cell->splSubfrmCfg.upPts =
10275             rgSchTddSplSubfrmInfoTbl[splSubfrmIdx].norDlExtUpPts;
10276       }
10277       else
10278       {
10279          cell->splSubfrmCfg.upPts =
10280             rgSchTddSplSubfrmInfoTbl[splSubfrmIdx].norDlNorUpPts;
10281       }
10282    }
10283
10284    /* Initializing the cqiToEffTbl and cqiToTbsTbl for every CFI value */
10285    for(cfi = 1; cfi < RG_SCH_CMN_MAX_CFI; cfi++,cfiIdx++)
10286    {   
10287       cellSch->dl.cqiToTbsTbl[0][cfi]   = rgSchCmnCqiToTbs[0][cp][cfiIdx];
10288       cellSch->dl.cqiToEffTbl[0][cfi]   = rgSchCmnEffTbl[0][cp][rgSchCmnAntIdx\
10289                                                  [cell->numTxAntPorts]][cfiIdx];
10290       cellSch->dl.cqiToTbsTbl[1][cfi]   = rgSchCmnCqiToTbs[1][cp][cfiIdx];
10291       cellSch->dl.cqiToEffTbl[1][cfi]   = rgSchCmnEffTbl[1][cp][rgSchCmnAntIdx\
10292                                                  [cell->numTxAntPorts]][cfiIdx];
10293    }
10294
10295    /* Initializing the values of CFI parameters */
10296    if(cell->dynCfiCb.isDynCfiEnb)
10297    {   
10298       /* If DCFI is enabled, current CFI value will start from 1 */
10299       cellSch->dl.currCfi = cellSch->dl.newCfi = 1;
10300    }
10301    else
10302    {
10303       /* If DCFI is disabled, current CFI value is set as default max allowed CFI value */
10304       cellSch->dl.currCfi = RGSCH_MIN(cell->dynCfiCb.maxCfi, cellSch->cfiCfg.cfi);
10305       cellSch->dl.newCfi = cellSch->dl.currCfi;
10306    }   
10307
10308    /* Include CRS REs while calculating Efficiency
10309     * The number of Resource Elements occupied by CRS depends on Number of
10310     * Antenna Ports. Please refer to Section 6.10.1 of 3GPP TS 36.211 V8.8.0.
10311     * Also, please refer to Figures 6.10.1.2-1 and 6.10.1.2-2 for diagrammatic
10312     * details of the same. Please note that PDCCH overlap symbols would not
10313     * considered in CRS REs deduction */
10314    for (cfi = 1; cfi < RG_SCH_CMN_MAX_CFI; cfi++, numPdcchSym++)
10315    {
10316       cellSch->dl.noResPerRb[cfi] = (((noSymPerSlot * RG_SCH_CMN_NUM_SLOTS_PER_SF)
10317             - numPdcchSym) *RB_SCH_CMN_NUM_SCS_PER_RB) - rgSchCmnNumResForCrs[cell->numTxAntPorts];
10318    }
10319
10320    /* DwPTS Scheduling Changes Start */
10321    antPortIdx = (cell->numTxAntPorts == 1)? 0: 
10322       ((cell->numTxAntPorts == 2)? 1: 2);     
10323
10324    if (cp == RG_SCH_CMN_NOR_CP)
10325    {
10326       splSfIdx = (splSubfrmIdx == 4)? 1: 0;   
10327    }
10328    else
10329    {
10330       splSfIdx = (splSubfrmIdx == 3)? 1: 0;
10331    }
10332
10333    numCrs = rgSchCmnDwptsCrs[splSfIdx][antPortIdx];
10334
10335    for (cfi = 1; cfi < RG_SCH_CMN_MAX_CFI-1; cfi++)
10336    { 
10337       /* If CFI is 2 and Ant Port is 4, don't consider the sym 1 CRS REs */  
10338       if (antPortIdx == 2 && cfi == 2)
10339       {
10340          numCrs -= 4;      
10341       }
10342       cellSch->dl.numReDwPts[cfi]  =  ((cell->splSubfrmCfg.dwPts - cfi)*
10343                                   RB_SCH_CMN_NUM_SCS_PER_RB) - numCrs;
10344    }
10345    /* DwPTS Scheduling Changes End */
10346
10347    if (cfg->maxDlBwPerUe == 0)
10348    {
10349       cellSch->dl.maxDlBwPerUe = RG_SCH_CMN_MAX_DL_BW_PERUE;
10350    }
10351    else
10352    {
10353       cellSch->dl.maxDlBwPerUe = cfg->maxDlBwPerUe;
10354    }
10355    if (cfg->maxDlRetxBw == 0)
10356    {
10357       cellSch->dl.maxDlRetxBw = RG_SCH_CMN_MAX_DL_RETX_BW;
10358    }
10359    else
10360    {
10361       cellSch->dl.maxDlRetxBw = cfg->maxDlRetxBw;
10362    }
10363    /* Fix: MUE_PERTTI_DL*/
10364    cellSch->dl.maxUePerDlSf = cfg->maxUePerDlSf;
10365    cellSch->dl.maxUeNewTxPerTti = cfg->maxDlUeNewTxPerTti;
10366    if (cfg->maxUePerDlSf == 0)
10367    {
10368       cellSch->dl.maxUePerDlSf = RG_SCH_CMN_MAX_UE_PER_DL_SF;
10369    }
10370    RG_SCH_RESET_HCSG_DL_PRB_CNTR(&cellSch->dl);
10371    /*[ccpu00138609]-ADD- Configure the Max CCCH Counter */
10372    if (cfg->maxCcchPerDlSf > cfg->maxUePerDlSf)
10373    {
10374       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId, 
10375                       "Invalid configuration !: "
10376                       "maxCcchPerDlSf %u > maxUePerDlSf %u",
10377                    cfg->maxCcchPerDlSf, cfg->maxUePerDlSf );
10378
10379       return RFAILED;
10380    }
10381    else if (!cfg->maxCcchPerDlSf)
10382    {
10383       /* ccpu00143032: maxCcchPerDlSf 0 means not configured by application
10384        * hence setting to maxUePerDlSf. If maxCcchPerDlSf is 0 then scheduler
10385        * does't consider CCCH allocation in MaxUePerTti cap. Hence more than
10386        * 4UEs getting schduled & SCH expects >16 Hq PDUs in a TTI which causes
10387        * FLE crash in PHY as PHY has limit of 16 max*/
10388       cellSch->dl.maxCcchPerDlSf = cfg->maxUePerDlSf;
10389    }
10390    else
10391    {
10392       cellSch->dl.maxCcchPerDlSf = cfg->maxCcchPerDlSf;
10393    }
10394    if (rgSCHCmnDlCnsdrCmnRt(cell, &cfg->dlCmnCodeRate) != ROK)
10395    {
10396       return RFAILED;
10397    }
10398
10399    /*ccpu00118273 - ADD - start */
10400    cmLListInit(&cellSch->dl.msg4RetxLst);
10401 #ifdef RGR_V1
10402    cmLListInit(&cellSch->dl.ccchSduRetxLst);
10403 #endif
10404
10405 #ifdef RG_PHASE2_SCHED
10406    if (cellSch->apisDlfs == NULLP) /* DFLS specific initialization */
10407    {
10408       cellSch->apisDlfs = &rgSchDlfsSchdTbl[cfg->dlfsSchdType];
10409    }
10410    if (cfg->dlfsCfg.isDlFreqSel)
10411    {
10412       ret = cellSch->apisDlfs->rgSCHDlfsCellCfg(cell, cfg, err);
10413       if (ret != ROK)
10414       {
10415          return RFAILED;
10416       }
10417    }
10418    cellSch->dl.isDlFreqSel = cfg->dlfsCfg.isDlFreqSel;
10419 #endif
10420
10421    /* Power related configuration */
10422    ret = rgSCHPwrCellCfg(cell, cfg);
10423    if (ret != ROK)
10424    {
10425       return RFAILED;
10426    }
10427
10428    cellSch->dl.bcchTxPwrOffset = cfg->bcchTxPwrOffset; 
10429    cellSch->dl.pcchTxPwrOffset = cfg->pcchTxPwrOffset; 
10430    cellSch->dl.rarTxPwrOffset  = cfg->rarTxPwrOffset; 
10431    cellSch->dl.phichTxPwrOffset  = cfg->phichTxPwrOffset; 
10432    cellSch->dl.msg4pAVal        = cfg->msg4pAVal;
10433    return ROK;
10434 }
10435 #else /* LTE_TDD */
10436 /**
10437  * @brief This function handles the configuration of cell for the first
10438  *        time by the scheduler.
10439  *
10440  * @details
10441  *
10442  *     Function: rgSCHCmnDlRgrCellCfg
10443  *     Purpose:  Configuration received is stored into the data structures
10444  *               Also, update the scheduler with the number of frames of
10445  *               RACH preamble transmission.
10446  *
10447  *     Invoked by: BO and Scheduler
10448  *
10449  *  @param[in]  RgSchCellCb*   cell
10450  *  @param[in]  RgrCellCfg*    cfg
10451  *  @param[in]  RgSchErrInfo*  err
10452  *  @return     S16
10453  *
10454  **/
10455 #ifdef ANSI
10456 PRIVATE S16 rgSCHCmnDlRgrCellCfg
10457 (
10458 RgSchCellCb             *cell,
10459 RgrCellCfg              *cfg,
10460 RgSchErrInfo            *err
10461 )
10462 #else
10463 PRIVATE S16 rgSCHCmnDlRgrCellCfg(cell, cfg, err)
10464 RgSchCellCb             *cell;
10465 RgrCellCfg              *cfg;
10466 RgSchErrInfo            *err;
10467 #endif
10468 {
10469    S16                 ret;
10470    RgSchCmnCell        *cellSch;
10471    U8                   cp;
10472    U8                   numPdcchSym;
10473    U8                   noSymPerSlot;
10474    U8                   cfi;  
10475    U8                   cfiIdx;
10476
10477
10478    cellSch = RG_SCH_CMN_GET_CELL(cell);
10479
10480    /* Initialize the parameters with the ones received in the */
10481    /* configuration.                                          */
10482
10483    /* Added matrix 'rgRaPrmblToRaFrmTbl' for computation of RA
10484     * sub-frames from preamble format */
10485    cellSch->dl.numRaSubFrms = rgRaPrmblToRaFrmTbl[cell->rachCfg.preambleFormat];
10486
10487    /*[ccpu00138532]-ADD-fill the Msg4 Harq data */
10488    cell->dlHqCfg.maxMsg4HqTx = cfg->dlHqCfg.maxMsg4HqTx;                                                
10489    
10490    /* Msg4 Tx Delay = (HARQ_RTT * MAX_MSG4_HARQ_RETX)  + 
10491                        3 TTI (MAX L1+L2 processing delay at the UE) */
10492    cellSch->dl.msg4TxDelay = (cfg->dlHqCfg.maxMsg4HqTx-1) *
10493                                  rgSchCmnHarqRtt[7] + 3; 
10494
10495    if (cell->bwCfg.dlTotalBw <= 10)
10496    {
10497       cfiIdx = 1;
10498       numPdcchSym = 2;
10499    }
10500    else
10501    {
10502       cfiIdx = 0;
10503       numPdcchSym = 1;
10504    }
10505
10506    if (cell->isCpDlExtend == TRUE)
10507    {
10508       cp = RG_SCH_CMN_EXT_CP;
10509       noSymPerSlot = 6;
10510    }
10511    else
10512    {
10513       cp = RG_SCH_CMN_NOR_CP;
10514       noSymPerSlot = 7;
10515    }
10516
10517    /* Initializing the cqiToEffTbl and cqiToTbsTbl for every CFI value */
10518    for(cfi = 1; cfi < RG_SCH_CMN_MAX_CFI; cfi++, cfiIdx++)
10519    {   
10520       cellSch->dl.cqiToTbsTbl[0][cfi]   = rgSchCmnCqiToTbs[0][cp][cfiIdx];
10521 #ifdef EMTC_ENABLE      
10522       cellSch->dl.emtcCqiToTbsTbl[0][cfi]   = rgSchEmtcCmnCqiToTbs[0][cp][cfiIdx];
10523 #endif      
10524       cellSch->dl.cqiToEffTbl[0][cfi]   = rgSchCmnEffTbl[0][cp][rgSchCmnAntIdx\
10525                                                  [cell->numTxAntPorts]][cfiIdx];
10526       cellSch->dl.cqiToTbsTbl[1][cfi]   = rgSchCmnCqiToTbs[1][cp][cfiIdx];
10527 #ifdef EMTC_ENABLE      
10528       cellSch->dl.emtcCqiToTbsTbl[1][cfi]   = rgSchEmtcCmnCqiToTbs[1][cp][cfiIdx];
10529 #endif      
10530       cellSch->dl.cqiToEffTbl[1][cfi]   = rgSchCmnEffTbl[1][cp][rgSchCmnAntIdx\
10531                                                  [cell->numTxAntPorts]][cfiIdx];
10532    }
10533
10534    /* Initializing the values of CFI parameters */
10535    if(cell->dynCfiCb.isDynCfiEnb)
10536    {   
10537       /* If DCFI is enabled, current CFI value will start from 1 */
10538       cellSch->dl.currCfi = cellSch->dl.newCfi = 1;
10539    }
10540    else
10541    {
10542       /* If DCFI is disabled, current CFI value is set as default CFI value */
10543       cellSch->dl.currCfi = cellSch->cfiCfg.cfi;
10544       cellSch->dl.newCfi = cellSch->dl.currCfi;
10545    }   
10546
10547    /* Include CRS REs while calculating Efficiency
10548     * The number of Resource Elements occupied by CRS depends on Number of
10549     * Antenna Ports. Please refer to Section 6.10.1 of 3GPP TS 36.211 V8.8.0.
10550     * Also, please refer to Figures 6.10.1.2-1 and 6.10.1.2-2 for diagrammatic
10551     * details of the same. Please note that PDCCH overlap symbols would not
10552     * considered in CRS REs deduction */
10553    for (cfi = 1; cfi < RG_SCH_CMN_MAX_CFI; cfi++, numPdcchSym++)
10554    {
10555        cellSch->dl.noResPerRb[cfi]    = (((noSymPerSlot * RG_SCH_CMN_NUM_SLOTS_PER_SF)
10556             - numPdcchSym) * RB_SCH_CMN_NUM_SCS_PER_RB) - rgSchCmnNumResForCrs[cell->numTxAntPorts];
10557    }           
10558
10559    if (cfg->maxDlBwPerUe == 0)
10560    {
10561       cellSch->dl.maxDlBwPerUe = RG_SCH_CMN_MAX_DL_BW_PERUE;
10562    }
10563    else
10564    {
10565       cellSch->dl.maxDlBwPerUe = cfg->maxDlBwPerUe;
10566    }
10567    if (cfg->maxDlRetxBw == 0)
10568    {
10569       cellSch->dl.maxDlRetxBw = RG_SCH_CMN_MAX_DL_RETX_BW;
10570    }
10571    else
10572    {
10573       cellSch->dl.maxDlRetxBw = cfg->maxDlRetxBw;
10574    }
10575    
10576    /* Fix: MUE_PERTTI_DL*/
10577    cellSch->dl.maxUePerDlSf = cfg->maxUePerDlSf;
10578    cellSch->dl.maxUeNewTxPerTti = cfg->maxDlUeNewTxPerTti;
10579    if (cfg->maxUePerDlSf == 0)
10580    {
10581       cellSch->dl.maxUePerDlSf = RG_SCH_CMN_MAX_UE_PER_DL_SF;
10582    }
10583    /* Fix: MUE_PERTTI_DL syed validating Cell Configuration */
10584    if (cellSch->dl.maxUePerDlSf < cellSch->dl.maxUeNewTxPerTti)
10585    {
10586       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,
10587             "FAILED MaxUePerDlSf(%u) < MaxDlUeNewTxPerTti(%u)",
10588             cellSch->dl.maxUePerDlSf,
10589             cellSch->dl.maxUeNewTxPerTti);
10590       return RFAILED;
10591    }
10592    /*[ccpu00138609]-ADD- Configure the Max CCCH Counter */
10593    if (cfg->maxCcchPerDlSf > cfg->maxUePerDlSf)
10594    {
10595       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,"Invalid configuration !: "
10596             "maxCcchPerDlSf %u > maxUePerDlSf %u",
10597             cfg->maxCcchPerDlSf, cfg->maxUePerDlSf );
10598
10599       return RFAILED;
10600    }
10601    else if (!cfg->maxCcchPerDlSf)
10602    {
10603       /* ccpu00143032: maxCcchPerDlSf 0 means not configured by application
10604        * hence setting to maxUePerDlSf. If maxCcchPerDlSf is 0 then scheduler
10605        * does't consider CCCH allocation in MaxUePerTti cap. Hence more than
10606        * 4UEs getting schduled & SCH expects >16 Hq PDUs in a TTI which causes
10607        * FLE crash in PHY as PHY has limit of 16 max*/
10608       cellSch->dl.maxCcchPerDlSf = cfg->maxUePerDlSf;
10609    }
10610    else
10611    {
10612       cellSch->dl.maxCcchPerDlSf = cfg->maxCcchPerDlSf;
10613    }
10614
10615
10616    if (rgSCHCmnDlCnsdrCmnRt(cell, &cfg->dlCmnCodeRate) != ROK)
10617    {
10618       return RFAILED;
10619    }
10620    cmLListInit(&cellSch->dl.msg4RetxLst);
10621 #ifdef RGR_V1
10622    cmLListInit(&cellSch->dl.ccchSduRetxLst);
10623 #endif
10624
10625 #ifdef RG_PHASE2_SCHED
10626    if (cellSch->apisDlfs == NULLP) /* DFLS specific initialization */
10627    {
10628       cellSch->apisDlfs = &rgSchDlfsSchdTbl[cfg->dlfsSchdType];
10629    }
10630    if (cfg->dlfsCfg.isDlFreqSel)
10631    {
10632       ret = cellSch->apisDlfs->rgSCHDlfsCellCfg(cell, cfg, err);
10633       if (ret != ROK)
10634       {
10635          return RFAILED;
10636       }
10637    }
10638    cellSch->dl.isDlFreqSel = cfg->dlfsCfg.isDlFreqSel;
10639 #endif
10640
10641    /* Power related configuration */
10642    ret = rgSCHPwrCellCfg(cell, cfg);
10643    if (ret != ROK)
10644    {
10645       return RFAILED;
10646    }
10647
10648    cellSch->dl.bcchTxPwrOffset = cfg->bcchTxPwrOffset; 
10649    cellSch->dl.pcchTxPwrOffset = cfg->pcchTxPwrOffset; 
10650    cellSch->dl.rarTxPwrOffset  = cfg->rarTxPwrOffset; 
10651    cellSch->dl.phichTxPwrOffset  = cfg->phichTxPwrOffset; 
10652    RG_SCH_RESET_HCSG_DL_PRB_CNTR(&cellSch->dl);
10653    return ROK;
10654 }
10655 #endif /* LTE_TDD */
10656
10657 /***********************************************************
10658  *
10659  *     Func : rgSCHCmnUlCalcReqRbCeil
10660  *
10661  *     Desc : Calculate RB required to satisfy 'bytes' for
10662  *            a given CQI.
10663  *            Returns number of RBs such that requirement
10664  *            is necessarily satisfied (does a 'ceiling'
10665  *            computation).
10666  *
10667  *     Ret  : Required RBs (U8)
10668  *
10669  *     Notes:
10670  *
10671  *     File :
10672  *
10673  **********************************************************/
10674 #ifdef ANSI
10675 U8 rgSCHCmnUlCalcReqRbCeil
10676 (
10677 U32            bytes,
10678 U8             cqi,
10679 RgSchCmnUlCell *cellUl
10680 )
10681 #else
10682 U8 rgSCHCmnUlCalcReqRbCeil(bytes, cqi, cellUl)
10683 U32            bytes;
10684 U8             cqi;
10685 RgSchCmnUlCell *cellUl;
10686 #endif
10687 {
10688    U32 numRe = RGSCH_CEIL((bytes * 8) * 1024, rgSchCmnUlCqiTbl[cqi].eff);
10689    return ((U8)RGSCH_CEIL(numRe, RG_SCH_CMN_UL_NUM_RE_PER_RB(cellUl)));
10690 }
10691
10692 /***********************************************************
10693  *
10694  *     Func : rgSCHCmnPrecompMsg3Vars
10695  *
10696  *     Desc : Precomputes the following for msg3 allocation:
10697  *            1. numSb and Imcs for msg size A
10698  *            2. numSb and Imcs otherwise
10699  *
10700  *     Ret  :
10701  *
10702  *     Notes: The corresponding vars in cellUl struct is filled
10703  *            up
10704  *
10705  *     File :
10706  *
10707  **********************************************************/
10708 #ifdef ANSI
10709 PRIVATE S16 rgSCHCmnPrecompMsg3Vars
10710 (
10711 RgSchCmnUlCell *cellUl,
10712 U8           ccchCqi,
10713 U16          msgSzA,
10714 U8           sbSize,
10715 Bool         isEcp
10716 )
10717 #else
10718 PRIVATE S16 rgSCHCmnPrecompMsg3Vars(cellUl, ccchCqi, msgSzA, sbSize, isEcp)
10719 RgSchCmnUlCell *cellUl;
10720 U8           ccchCqi;
10721 U16          msgSzA;
10722 U8           sbSize;
10723 Bool         isEcp;
10724 #endif
10725 {
10726    U8 numSb;
10727    U8 ccchTbs;
10728    U8 ccchMcs;
10729    U8   numRb = 0;
10730    U8   iTbs = 0;
10731    U16  msg3GrntSz = 0;
10732
10733
10734    if (ccchCqi > cellUl->max16qamCqi)
10735    {
10736       ccchCqi = cellUl->max16qamCqi;
10737    }
10738 /* #ifndef RG_SCH_CMN_EXP_CP_SUP For ECP Pick the index 1 */
10739    /* Fix */
10740    ccchTbs = rgSchCmnUlCqiToTbsTbl[(U8)isEcp][ccchCqi];
10741    ccchMcs = rgSCHCmnUlGetIMcsFrmITbs(ccchTbs, CM_LTE_UE_CAT_1);
10742    
10743    /* MCS should fit in 4 bits in RAR */
10744    if (ccchMcs >= 15)
10745    {
10746       ccchMcs = 15;
10747    }
10748    
10749    /* Limit the ccchMcs to 15 as it
10750     * can be inferred from 36.213, section 6.2 that msg3 imcs
10751     * field is 4 bits.
10752     * Since, UE doesn't exist right now, we use CAT_1 for ue
10753     * category*/
10754    while((ccchMcs = (rgSCHCmnUlGetIMcsFrmITbs(
10755                       rgSchCmnUlCqiToTbsTbl[(U8)isEcp][ccchCqi],CM_LTE_UE_CAT_1))
10756                     ) >
10757                  RG_SCH_CMN_MAX_MSG3_IMCS)
10758    {
10759       ccchCqi--;
10760    }
10761    
10762    iTbs = rgSchCmnUlCqiToTbsTbl[(U8)isEcp][ccchCqi];
10763    
10764    if (msgSzA < RGSCH_MIN_MSG3_GRNT_SZ)
10765    {
10766       return RFAILED;
10767    }
10768    numSb = RGSCH_CEIL(rgSCHCmnUlCalcReqRbCeil(msgSzA, ccchCqi, cellUl), sbSize);
10769    
10770    numRb   = numSb * sbSize;
10771    msg3GrntSz = 8 * msgSzA;
10772
10773    while( (rgTbSzTbl[0][iTbs][numRb - 1]) < msg3GrntSz)
10774    {
10775       ++numSb;
10776       numRb   = numSb * sbSize;
10777    }
10778    while (rgSchCmnMult235Tbl[numSb].match != numSb)
10779    {
10780       ++numSb;
10781    }
10782    /* Reversed(Corrected) the assignment for preamble-GrpA
10783     * Refer- TG36.321- section- 5.1.2*/
10784    cellUl->ra.prmblBNumSb = numSb;
10785    cellUl->ra.prmblBIMcs  = ccchMcs;
10786    numSb = RGSCH_CEIL(rgSCHCmnUlCalcReqRbCeil(RGSCH_MIN_MSG3_GRNT_SZ, \
10787                       ccchCqi, cellUl),
10788          sbSize);
10789
10790    numRb   = numSb * sbSize;
10791    msg3GrntSz = 8 * RGSCH_MIN_MSG3_GRNT_SZ;
10792    while( (rgTbSzTbl[0][iTbs][numRb - 1]) < msg3GrntSz)
10793    {
10794       ++numSb;
10795       numRb   = numSb * sbSize;
10796    }
10797    while (rgSchCmnMult235Tbl[numSb].match != numSb)
10798    {
10799       ++numSb;
10800    }
10801    /* Reversed(Corrected) the assignment for preamble-GrpA
10802     * Refer- TG36.321- section- 5.1.2*/
10803    cellUl->ra.prmblANumSb = numSb;
10804    cellUl->ra.prmblAIMcs  = ccchMcs;
10805    return ROK;
10806 }
10807
10808 U32 gPrntPucchDet=0;
10809
10810 #ifdef LTE_TDD
10811 /***********************************************************
10812  *
10813  *     Func : rgSCHCmnUlCalcAvailBw
10814  *
10815  *     Desc : Calculates bandwidth available for PUSCH scheduling.
10816  *
10817  *     Ret  : S16 (ROK/RFAILED)
10818  *
10819  *     Notes:
10820  *
10821  *     File :
10822  *
10823  **********************************************************/
10824 #ifdef ANSI
10825 PRIVATE S16 rgSCHCmnUlCalcAvailBw
10826 (
10827 RgSchCellCb    *cell,
10828 RgrCellCfg     *cellCfg,
10829 U8              cfi,
10830 U8             *rbStartRef,
10831 U8             *bwAvailRef
10832 )
10833 #else
10834 PRIVATE S16 rgSCHCmnUlCalcAvailBw(cell, cellCfg, cfi, rbStartRef, bwAvailRef)
10835 RgSchCellCb   *cell;
10836 RgrCellCfg    *cellCfg;
10837 U8             cfi;  
10838 U8            *rbStartRef;
10839 U8            *bwAvailRef;
10840 #endif
10841 {
10842    U8  c        = 3;
10843    U8  ulBw     = cell->bwCfg.ulTotalBw;
10844    U8  n2Rb     = cell->pucchCfg.resourceSize;
10845    U8  pucchDeltaShft = cell->pucchCfg.deltaShift;
10846    U16 n1Pucch  = cell->pucchCfg.n1PucchAn;
10847    U8  n1Cs     = cell->pucchCfg.cyclicShift;
10848
10849    U8  n1PerRb;
10850    U8  totalCce;
10851    U16 n1Max;
10852    U8  n1Rb;
10853    U32 mixedRb;
10854    U8  exclRb; /* RBs to exclude */
10855    U8  n1RbPart;
10856    U8  puschRbStart;
10857    /* To avoid PUCCH and PUSCH collision issue */
10858    U8  P;
10859    U8  n1PlusOne;
10860    U8  mi;
10861    /* Maximum value of M as per Table 10.1-1 */
10862    U8  M[RGSCH_MAX_TDD_UL_DL_CFG] = {1, 2, 4, 3, 4, 9, 1};
10863
10864
10865    if (cell->isCpUlExtend)
10866    {
10867       c = 2;
10868    }
10869
10870    n1PerRb  = c * 12 / pucchDeltaShft; /* 12/18/36 */
10871
10872    /* Considering the max no. of CCEs for PUSCH BW calculation 
10873     * based on min mi value */
10874    if (cell->ulDlCfgIdx == 0 || cell->ulDlCfgIdx == 6)
10875    {
10876       mi = 1;
10877    }
10878    else
10879    { 
10880       mi = 0;
10881    }
10882    
10883    totalCce = cell->dynCfiCb.cfi2NCceTbl[mi][cfi];
10884
10885    P        = rgSCHCmnGetPValFrmCCE(cell, totalCce-1);
10886    n1PlusOne = cell->rgSchTddNpValTbl[P + 1];
10887    n1Max    = (M[cell->ulDlCfgIdx] - 1)*n1PlusOne + (totalCce-1) + n1Pucch;
10888
10889    /* ccpu00129978- MOD- excluding RBs based on formula in section 5.4.3 in 
10890     * TS 36.211  */
10891    n1RbPart = (c*n1Cs)/pucchDeltaShft;
10892    n1Rb = (n1Max - n1RbPart)/ n1PerRb;
10893    mixedRb = RGSCH_CEIL(n1Cs, 8); /* same as 'mixedRb = n1Cs ? 1 : 0' */
10894
10895    /* get the total Number of RB's to be excluded for PUSCH */
10896    /* ccpu00137339 */
10897    if(n1Pucch < n1RbPart)
10898    {
10899       exclRb = n2Rb;
10900    }
10901    else
10902    {
10903       exclRb = n2Rb + mixedRb + n1Rb; /* RBs to exclude */
10904    }
10905    puschRbStart = exclRb/2 + 1; 
10906
10907    /* Num of PUCCH RBs = puschRbStart*2 */
10908    if (puschRbStart * 2 >= ulBw)
10909    {
10910       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"No bw available for PUSCH");
10911       return RFAILED;
10912    }
10913
10914    *rbStartRef = puschRbStart;
10915    *bwAvailRef = ulBw -  puschRbStart * 2;
10916  
10917    if(cell->pucchCfg.maxPucchRb !=0 && 
10918          (puschRbStart * 2 > cell->pucchCfg.maxPucchRb))
10919    {
10920       cell->dynCfiCb.maxCfi = RGSCH_MIN(cfi-1, cell->dynCfiCb.maxCfi);
10921    }
10922     
10923    return ROK;
10924 }
10925 #else
10926
10927 /***********************************************************
10928  *
10929  *     Func : rgSCHCmnUlCalcAvailBw
10930  *
10931  *     Desc : Calculates bandwidth available for PUSCH scheduling.
10932  *
10933  *     Ret  : S16 (ROK/RFAILED)
10934  *
10935  *     Notes:
10936  *
10937  *     File :
10938  *
10939  **********************************************************/
10940 #ifdef ANSI
10941 PRIVATE S16 rgSCHCmnUlCalcAvailBw
10942 (
10943 RgSchCellCb    *cell,
10944 RgrCellCfg     *cellCfg,
10945 U8              cfi,
10946 U8             *rbStartRef,
10947 U8             *bwAvailRef
10948 )
10949 #else
10950 PRIVATE S16 rgSCHCmnUlCalcAvailBw(cell, cellCfg, cfi, rbStartRef, bwAvailRef)
10951 RgSchCellCb   *cell;
10952 RgrCellCfg    *cellCfg;
10953 U8             cfi;
10954 U8            *rbStartRef;
10955 U8            *bwAvailRef;
10956 #endif
10957 {
10958    U8  c        = 3;
10959    U8  ulBw     = cell->bwCfg.ulTotalBw;
10960    U8  n2Rb     = cell->pucchCfg.resourceSize;
10961    U8  pucchDeltaShft = cell->pucchCfg.deltaShift;
10962    U16 n1Pucch  = cell->pucchCfg.n1PucchAn;
10963    U8  n1Cs     = cell->pucchCfg.cyclicShift;
10964    U8  n1PerRb;
10965    U8  totalCce;
10966    U16 n1Max;
10967    U8  n1Rb;
10968    U32 mixedRb;
10969    U8  exclRb; /* RBs to exclude */
10970    U8  n1RbPart;
10971    U8  puschRbStart;
10972 #ifdef LTE_ADV
10973    U16 numOfN3PucchRb;
10974    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);  
10975 #endif
10976    
10977
10978    if (cell->isCpUlExtend)
10979    {
10980       c = 2;
10981    }
10982
10983    n1PerRb  = c * 12 / pucchDeltaShft; /* 12/18/36 */
10984
10985    totalCce = cell->dynCfiCb.cfi2NCceTbl[0][cfi];
10986
10987    n1Max    = n1Pucch + totalCce-1;
10988
10989    /* ccpu00129978- MOD- excluding RBs based on formula in section 5.4.3 in 
10990     * TS 36.211  */
10991    n1RbPart = (c*n1Cs)/pucchDeltaShft;
10992    n1Rb = (U8)((n1Max - n1RbPart) / n1PerRb);
10993    mixedRb = RGSCH_CEIL(n1Cs, 8); /* same as 'mixedRb = n1Cs ? 1 : 0' */
10994
10995    /* get the total Number of RB's to be excluded for PUSCH */
10996    /* ccpu00137339 */
10997    if(n1Pucch < n1RbPart)
10998    {
10999       exclRb = n2Rb;
11000    }
11001    else
11002    {
11003       exclRb = n2Rb + mixedRb + n1Rb; /* RBs to exclude */
11004    }
11005    /*Support for PUCCH Format 3*/
11006 #ifdef LTE_ADV
11007    if (cell->isPucchFormat3Sptd)
11008    {
11009       numOfN3PucchRb = RGSCH_CEIL(cellSch->dl.maxUePerDlSf,5); 
11010       exclRb = exclRb + numOfN3PucchRb;
11011    }
11012 #endif
11013    puschRbStart = exclRb/2 + 1;
11014
11015    if(gPrntPucchDet)
11016    {
11017 #ifndef ALIGN_64BIT
11018            printf("CA_DBG:: puschRbStart:n1Rb:mixedRb:n1PerRb:totalCce:n1Max:n1RbPart:n2Rb::[%d:%d] [%d:%d:%ld:%d:%d:%d:%d:%d]\n",
11019         cell->crntTime.sfn, cell->crntTime.slot, puschRbStart, n1Rb, mixedRb,n1PerRb, totalCce, n1Max, n1RbPart, n2Rb);
11020 #else
11021            printf("CA_DBG:: puschRbStart:n1Rb:mixedRb:n1PerRb:totalCce:n1Max:n1RbPart:n2Rb::[%d:%d] [%d:%d:%d:%d:%d:%d:%d:%d]\n",
11022         cell->crntTime.sfn, cell->crntTime.slot, puschRbStart, n1Rb, mixedRb,n1PerRb, totalCce, n1Max, n1RbPart, n2Rb);
11023 #endif
11024    }
11025
11026    if (puschRbStart*2 >= ulBw)
11027    {
11028       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"No bw available for PUSCH");
11029       return RFAILED;
11030    }
11031
11032    *rbStartRef = puschRbStart;
11033    *bwAvailRef = ulBw - puschRbStart * 2;
11034
11035    if(cell->pucchCfg.maxPucchRb !=0 && 
11036       (puschRbStart * 2 > cell->pucchCfg.maxPucchRb))
11037    {
11038       cell->dynCfiCb.maxCfi = RGSCH_MIN(cfi-1, cell->dynCfiCb.maxCfi);
11039    }
11040    
11041    return ROK;
11042 }
11043 #endif
11044
11045
11046
11047 /***********************************************************
11048  *
11049  *     Func : rgSCHCmnUlCellInit
11050  *
11051  *     Desc : Uplink scheduler initialisation for cell.
11052  *
11053  *     Ret  : S16
11054  *
11055  *     Notes:
11056  *
11057  *     File :
11058  *
11059  **********************************************************/
11060 #ifdef ANSI
11061 PRIVATE S16 rgSCHCmnUlCellInit
11062 (
11063  RgSchCellCb  *cell,
11064  RgrCellCfg   *cellCfg
11065  )
11066 #else
11067 PRIVATE S16 rgSCHCmnUlCellInit(cell, cellCfg)
11068    RgSchCellCb *cell;
11069    RgrCellCfg  *cellCfg;
11070 #endif
11071 {
11072    S16            ret;
11073    RgSchCmnUlCell *cellUl      = RG_SCH_CMN_GET_UL_CELL(cell);
11074    U8             maxUePerUlSf = cellCfg->maxUePerUlSf;
11075 #ifdef RGR_V1
11076    /* Added configuration for maximum number of MSG3s */
11077    U8             maxMsg3PerUlSf = cellCfg->maxMsg3PerUlSf;
11078 #endif
11079    U8             maxUlBwPerUe = cellCfg->maxUlBwPerUe;
11080    U8             sbSize       = cellCfg->puschSubBand.size;
11081    U8             i;
11082    U8             rbStart;
11083    U8             bwAvail;
11084    U8             cfi;  
11085    U8             maxSbPerUe;
11086    U8             numSb;
11087 #ifdef LTE_TDD
11088    U16            ulDlCfgIdx = cell->ulDlCfgIdx;
11089    /* [ccpu00127294]-MOD-Change the max Ul subfrms size in TDD */
11090    U8             maxSubfrms = 2 * rgSchTddNumUlSf[ulDlCfgIdx]; 
11091    U8             ulToDlMap[12] = {0}; /* maximum 6 Subframes in UL  * 2 */
11092    U8             maxUlsubfrms = rgSchTddNumUlSubfrmTbl[ulDlCfgIdx]\
11093                                            [RGSCH_NUM_SUB_FRAMES-1];
11094    U16             subfrm;
11095    S8             dlIdx;
11096 #else
11097    U8             maxSubfrms = RG_SCH_CMN_UL_NUM_SF;
11098 #endif
11099 #ifdef LTE_L2_MEAS
11100    U8             idx;
11101 #endif
11102    U8  iTbs;
11103 #if (defined(LTE_L2_MEAS) )
11104    Inst           inst         = cell->instIdx;
11105 #endif /* #if (defined(LTE_L2_MEAS) || defined(DEBUGP) */
11106    RgSchCmnCell      *cellSch =  (RgSchCmnCell *)(cell->sc.sch);
11107    
11108
11109    cellUl->maxUeNewTxPerTti = cellCfg->maxUlUeNewTxPerTti;
11110    if (maxUePerUlSf == 0)
11111    {
11112       maxUePerUlSf = RG_SCH_CMN_MAX_UE_PER_UL_SF;
11113    }
11114 #ifdef RGR_V1
11115    if (maxMsg3PerUlSf == 0)
11116    {
11117       maxMsg3PerUlSf = RG_SCH_CMN_MAX_MSG3_PER_UL_SF;
11118    }
11119    /*  fixed the problem while sending raRsp 
11120     * if maxMsg3PerUlSf is greater than 
11121     * RGSCH_MAX_RNTI_PER_RARNTI 
11122     * */
11123    if(maxMsg3PerUlSf > RGSCH_MAX_RNTI_PER_RARNTI)
11124    {
11125       maxMsg3PerUlSf = RGSCH_MAX_RNTI_PER_RARNTI; 
11126    } 
11127
11128    if(maxMsg3PerUlSf > maxUePerUlSf)
11129    {
11130       maxMsg3PerUlSf =  maxUePerUlSf;   
11131    }
11132    
11133    /*cellUl->maxAllocPerUlSf = maxUePerUlSf + maxMsg3PerUlSf;*/
11134    /*Max MSG3 should be a subset of Max UEs*/
11135    cellUl->maxAllocPerUlSf = maxUePerUlSf;
11136    cellUl->maxMsg3PerUlSf = maxMsg3PerUlSf;
11137 #else
11138    cellUl->maxAllocPerUlSf = maxUePerUlSf;
11139 #endif
11140    /* Fix: MUE_PERTTI_UL syed validating Cell Configuration */
11141    if (cellUl->maxAllocPerUlSf < cellUl->maxUeNewTxPerTti)
11142    {
11143       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,
11144             "FAILED: MaxUePerUlSf(%u) < MaxUlUeNewTxPerTti(%u)",
11145             cellUl->maxAllocPerUlSf,
11146             cellUl->maxUeNewTxPerTti);
11147       return RFAILED;
11148    }
11149
11150 #ifdef LTE_L2_MEAS
11151 #ifdef LTE_TDD
11152    for(idx = 0; idx < RGSCH_SF_ALLOC_SIZE; idx++)
11153 #else
11154    for(idx = 0; idx < RGSCH_NUM_SUB_FRAMES; idx++)
11155 #endif
11156    {
11157
11158       ret = rgSCHUtlAllocSBuf(inst,  (Data **)&(cell->sfAllocArr[idx].
11159               ulUeInfo.ulAllocInfo), (cellUl->maxAllocPerUlSf * sizeof(RgInfUeUlAlloc)));
11160       if (ret != ROK)
11161       {
11162             RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Memory allocation failed ");
11163             return (ret);
11164       }
11165    }
11166 #endif
11167    if (maxUlBwPerUe == 0)
11168    {
11169       /* ccpu00139362- Setting to configured UL BW instead of MAX BW(100)*/
11170       maxUlBwPerUe = cell->bwCfg.ulTotalBw;
11171    }
11172    cellUl->maxUlBwPerUe = maxUlBwPerUe;
11173
11174    /* FOR RG_SCH_CMN_EXT_CP_SUP */
11175    if (!cellCfg->isCpUlExtend)
11176    {
11177       cellUl->ulNumRePerRb = 12 * (14 - RGSCH_UL_SYM_DMRS_SRS);
11178    }
11179    else
11180    {
11181       cellUl->ulNumRePerRb = 12 * (12 - RGSCH_UL_SYM_DMRS_SRS);
11182    }
11183
11184    if (sbSize != rgSchCmnMult235Tbl[sbSize].match)
11185    {
11186       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Invalid subband size %d", sbSize);
11187       return RFAILED;
11188    }
11189         //Setting the subband size to 4 which is size of VRBG in 5GTF
11190 #ifdef RG_5GTF
11191         sbSize = MAX_5GTF_VRBG_SIZE;
11192 #endif
11193         
11194    maxSbPerUe = maxUlBwPerUe / sbSize;
11195    if (maxSbPerUe == 0)
11196    {
11197       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId, "rgSCHCmnUlCellInit(): "
11198          "maxUlBwPerUe/sbSize is zero");
11199       return RFAILED;
11200    }
11201    cellUl->maxSbPerUe = rgSchCmnMult235Tbl[maxSbPerUe].prvMatch;
11202
11203    /* CQI related updations */
11204    if ((!RG_SCH_CMN_UL_IS_CQI_VALID(cellCfg->ulCmnCodeRate.ccchCqi))
11205          || (!RG_SCH_CMN_UL_IS_CQI_VALID(cellCfg->trgUlCqi.trgCqi)))
11206    {
11207       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHCmnUlCellInit(): "
11208          "Invalid cqi");
11209       return RFAILED;
11210    }
11211    cellUl->dfltUlCqi = cellCfg->ulCmnCodeRate.ccchCqi;
11212
11213    /* Changed the logic to determine maxUlCqi.
11214     * For a 16qam UE, maxUlCqi is the CQI Index at which
11215     * efficiency is as close as possible to RG_SCH_MAX_CODE_RATE_16QAM
11216     * Refer to 36.213-8.6.1 */
11217     for (i = RG_SCH_CMN_UL_NUM_CQI - 1;i > 0; --i)
11218    {
11219       RLOG_ARG2(L_INFO,DBG_CELLID,cell->cellId,
11220             "CQI %u:iTbs %u",
11221             i, 
11222             rgSchCmnUlCqiToTbsTbl[cell->isCpUlExtend][i]);
11223 #ifdef MAC_SCH_STATS
11224       /* ccpu00128489 ADD Update mcs in hqFailStats here instead of at CRC 
11225        * since CQI to MCS mapping does not change. The only exception is for 
11226        * ITBS = 19 where the MCS can be 20 or 21 based on the UE cat. We 
11227        * choose 20, instead of 21, ie UE_CAT_3 */
11228       iTbs = rgSchCmnUlCqiToTbsTbl[cell->isCpUlExtend][i];
11229       RG_SCH_CMN_UL_TBS_TO_MCS(iTbs, hqFailStats.ulCqiStat[i - 1].mcs);
11230 #endif
11231    }
11232    for (i = RG_SCH_CMN_UL_NUM_CQI - 1; i != 0; --i)
11233    {
11234       /* Fix for ccpu00123912*/
11235       iTbs = rgSchCmnUlCqiToTbsTbl[cell->isCpUlExtend][i];
11236       if (iTbs <= RGSCH_UL_16QAM_MAX_ITBS) /* corresponds to 16QAM */
11237       {
11238          RLOG_ARG1(L_INFO,DBG_CELLID,cell->cellId,
11239                          "16 QAM CQI %u", i);
11240          cellUl->max16qamCqi = i;
11241          break;
11242       }
11243    }
11244
11245 #ifdef EMTC_ENABLE
11246    /* Precompute useful values for RA msg3 */
11247    ret = rgSCHCmnPrecompEmtcMsg3Vars(cellUl, cellCfg->ulCmnCodeRate.ccchCqi,
11248          cell->rachCfg.msgSizeGrpA, sbSize, cell->isCpUlExtend);
11249    if (ret != ROK)
11250    {
11251       return (ret);
11252    }
11253 #endif   
11254
11255    /* Precompute useful values for RA msg3 */
11256    ret = rgSCHCmnPrecompMsg3Vars(cellUl, cellCfg->ulCmnCodeRate.ccchCqi,
11257          cell->rachCfg.msgSizeGrpA, sbSize, cell->isCpUlExtend);
11258    if (ret != ROK)
11259    {
11260       return (ret);
11261    }
11262
11263    cellUl->sbSize  = sbSize;
11264    
11265 #ifdef LTE_TDD  
11266    cellUl->numUlSubfrms = maxSubfrms;
11267
11268    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&cellUl->ulSfArr,
11269             cellUl->numUlSubfrms * sizeof(RgSchUlSf));
11270
11271    if (ret != ROK)
11272    {
11273       cellUl->numUlSubfrms = 0;
11274       return (ret);
11275    }
11276
11277    /* store the DL subframe corresponding to the PUSCH offset
11278     * in their respective UL subframe */
11279    for(i=0; i < RGSCH_NUM_SUB_FRAMES; i++)
11280    {
11281       if(rgSchTddPuschTxKTbl[ulDlCfgIdx][i] != 0)
11282       {
11283          subfrm = (i + rgSchTddPuschTxKTbl[ulDlCfgIdx][i]) % \
11284                                  RGSCH_NUM_SUB_FRAMES;
11285          subfrm = rgSchTddNumUlSubfrmTbl[ulDlCfgIdx][subfrm]-1;
11286          dlIdx = rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][i]-1;
11287          RGSCH_ARRAY_BOUND_CHECK( cell->instIdx, ulToDlMap, subfrm);
11288          ulToDlMap[subfrm] = dlIdx;
11289       }
11290    }
11291    /* Copy the information in the remaining UL subframes based
11292     * on number of HARQ processes */
11293    for(i=maxUlsubfrms; i < maxSubfrms; i++)
11294    {
11295       subfrm = i-maxUlsubfrms;
11296       RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, ulToDlMap, i);
11297       RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, ulToDlMap, subfrm)
11298       ulToDlMap[i] = ulToDlMap[subfrm];
11299    }
11300 #endif
11301
11302    for (cfi = 1; cfi < RG_SCH_CMN_MAX_CFI; cfi++)
11303    {
11304 #ifdef LTE_TDD        
11305       ret = rgSCHCmnUlCalcAvailBw(cell, cellCfg, cfi, &rbStart, &bwAvail); 
11306 #else
11307       ret = rgSCHCmnUlCalcAvailBw(cell, cellCfg, cfi, &rbStart, &bwAvail); 
11308 #endif
11309       if (ret != ROK)
11310       {
11311          return (ret);
11312       }
11313
11314       if (cfi == 1)
11315       {
11316          cell->ulAvailBw = bwAvail;
11317       }
11318
11319       numSb = bwAvail/sbSize; 
11320
11321       cell->dynCfiCb.bwInfo[cfi].startRb  = rbStart;
11322       cell->dynCfiCb.bwInfo[cfi].numSb    = numSb;
11323    }
11324
11325    if(0 == cell->dynCfiCb.maxCfi)
11326    {
11327       RLOG_ARG3(L_ERROR,DBG_CELLID,cell->cellId, 
11328                "Incorrect Default CFI(%u), maxCfi(%u), maxPucchRb(%d)",
11329                cellSch->cfiCfg.cfi, cell->dynCfiCb.maxCfi, 
11330                cell->pucchCfg.maxPucchRb);
11331             
11332       return RFAILED;
11333    }
11334
11335    /* DMRS values */
11336    cellUl->dmrsArrSize = cell->dynCfiCb.bwInfo[1].numSb;
11337    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&cellUl->dmrsArr,
11338          cellUl->dmrsArrSize * sizeof(*cellUl->dmrsArr));
11339    if (ret != ROK)
11340    {
11341       return (ret);
11342    }
11343    for (i = 0; i < cellUl->dmrsArrSize; ++i)
11344    {
11345       cellUl->dmrsArr[i] = cellCfg->puschSubBand.dmrs[i];
11346    }
11347  
11348    /* Init subframes */
11349    for (i = 0; i < maxSubfrms; ++i)
11350    {
11351       ret = rgSCHUtlUlSfInit(cell, &cellUl->ulSfArr[i], i,
11352                              cellUl->maxAllocPerUlSf);
11353       if (ret != ROK)
11354       {
11355          for (; i != 0; --i)
11356          {
11357             rgSCHUtlUlSfDeinit(cell, &cellUl->ulSfArr[i-1]);
11358          }
11359          /* ccpu00117052 - MOD - Passing double pointer
11360             for proper NULLP assignment*/
11361          rgSCHUtlFreeSBuf(cell->instIdx, (Data **)(&(cellUl->dmrsArr)),
11362                cellUl->dmrsArrSize * sizeof(*cellUl->dmrsArr));
11363 #ifdef LTE_TDD
11364          /* ccpu00117052 - MOD - Passing double pointer
11365             for proper NULLP assignment*/
11366          rgSCHUtlFreeSBuf(cell->instIdx,
11367             (Data **)(&(cellUl->ulSfArr)), maxSubfrms * sizeof(RgSchUlSf));
11368 #endif
11369          return (ret);
11370       }
11371    }
11372    RG_SCH_RESET_HCSG_UL_PRB_CNTR(cellUl);
11373    return ROK;
11374 }
11375
11376 /**
11377  * @brief Scheduler processing on cell configuration.
11378  *
11379  * @details
11380  *
11381  *     Function : rgSCHCmnRgrCellCfg
11382  *
11383  *     This function does requisite initialisation
11384  *     and setup for scheduler1 when a cell is
11385  *     configured.
11386  *
11387  *  @param[in]  RgSchCellCb   *cell
11388  *  @param[in]  RgrCellCfg    *cellCfg
11389  *  @param[out] RgSchErrInfo  *err
11390  *  @return  S16
11391  *      -# ROK
11392  *      -# RFAILED
11393  **/
11394 #ifdef ANSI
11395 S16 rgSCHCmnRgrCellCfg
11396 (
11397 RgSchCellCb   *cell,
11398 RgrCellCfg    *cellCfg,
11399 RgSchErrInfo  *err
11400 )
11401 #else
11402 S16 rgSCHCmnRgrCellCfg(cell, cellCfg, err)
11403 RgSchCellCb   *cell;
11404 RgrCellCfg    *cellCfg;
11405 RgSchErrInfo  *err;
11406 #endif
11407 {
11408    S16       ret;
11409    RgSchCmnCell *cellSch;
11410
11411    /* As part of RGR cell configuration, validate the CRGCellCfg
11412     * There is no trigger for crgCellCfg from SC1 */
11413    /* Removed failure check for Extended CP */
11414
11415    if (((ret = rgSCHUtlAllocSBuf(cell->instIdx,
11416       (Data**)&(cell->sc.sch), (sizeof(RgSchCmnCell)))) != ROK))
11417    {
11418       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,  
11419          "Memory allocation FAILED");
11420       err->errCause = RGSCHERR_SCH_CFG;
11421       return (ret);
11422    }
11423    cellSch = (RgSchCmnCell *)(cell->sc.sch);
11424    cellSch->cfiCfg = cellCfg->cfiCfg;
11425    cellSch->trgUlCqi.trgCqi = cellCfg->trgUlCqi.trgCqi;
11426    /* Initialize the scheduler refresh timer queues */
11427    cellSch->tmrTqCp.nxtEnt = 0;
11428    cellSch->tmrTqCp.tmrLen = RG_SCH_CMN_NUM_REFRESH_Q;
11429
11430    /* RACHO Intialize the RACH ded Preamble Information */
11431    rgSCHCmnCfgRachDedPrm(cell);
11432 #ifdef LTE_TDD
11433    /* Initialize 'Np' value for each 'p' used for
11434     * HARQ ACK/NACK reception */
11435    rgSCHCmnDlNpValInit(cell);
11436 #endif
11437
11438    /* Initialize 'Np' value for each 'p' used for
11439     * HARQ ACK/NACK reception */
11440 #ifdef LTE_TDD
11441    rgSCHCmnDlNpValInit(cell);
11442 #endif
11443
11444    /* Now perform uplink related initializations  */
11445    ret = rgSCHCmnUlCellInit(cell, cellCfg);
11446    if (ret != ROK)
11447    {
11448       /* There is no downlink deinit to be performed */
11449       err->errCause = RGSCHERR_SCH_CFG;
11450       return (ret);
11451    }
11452    ret = rgSCHCmnDlRgrCellCfg(cell, cellCfg, err);
11453    if (ret != ROK)
11454    {
11455       err->errCause = RGSCHERR_SCH_CFG;
11456       return (ret);
11457    }
11458    /* DL scheduler has no initializations to make */
11459    /* As of now DL scheduler always returns ROK   */
11460
11461    rgSCHCmnGetDciFrmtSizes(cell);
11462    rgSCHCmnGetCqiDciFrmt2AggrLvl(cell);
11463 #ifdef EMTC_ENABLE 
11464    rgSCHCmnGetEmtcDciFrmtSizes(cell);
11465    rgSCHCmnGetCqiEmtcDciFrmt2AggrLvl(cell);
11466 #endif /* EMTC_ENABLE  */
11467
11468 #ifdef EMTC_ENABLE   
11469    if(TRUE == cellCfg->emtcEnable)
11470    {
11471       cellSch->apisEmtcUl = &rgSchEmtcUlSchdTbl[0];
11472       ret = cellSch->apisEmtcUl->rgSCHRgrUlCellCfg(cell, cellCfg, err);
11473       if (ret != ROK)
11474       {
11475          return (ret);
11476       }
11477    }
11478 #endif
11479    cellSch->apisUl = &rgSchUlSchdTbl[RG_SCH_CMN_GET_UL_SCHED_TYPE(cell)];
11480    ret = cellSch->apisUl->rgSCHRgrUlCellCfg(cell, cellCfg, err);
11481    if (ret != ROK)
11482    {
11483       return (ret);
11484    }
11485 #ifdef EMTC_ENABLE   
11486    if(TRUE == cellCfg->emtcEnable)
11487    {
11488       cellSch->apisEmtcDl = &rgSchEmtcDlSchdTbl[0];
11489       ret = cellSch->apisEmtcDl->rgSCHRgrDlCellCfg(cell, cellCfg, err);
11490       if (ret != ROK)
11491       {
11492          return (ret);
11493       }
11494    }
11495 #endif
11496    cellSch->apisDl = &rgSchDlSchdTbl[RG_SCH_CMN_GET_DL_SCHED_TYPE(cell)];
11497 #ifdef LTEMAC_SPS
11498    /* Perform SPS specific initialization for the cell */
11499    ret = rgSCHCmnSpsCellCfg(cell, cellCfg, err);
11500    if (ret != ROK)
11501    {
11502       return (ret);
11503    }
11504 #endif
11505    ret = cellSch->apisDl->rgSCHRgrDlCellCfg(cell, cellCfg, err);
11506    if (ret != ROK)
11507    {
11508       return (ret);
11509    }
11510    rgSCHCmnInitVars(cell);
11511
11512    return ROK;
11513 }  /* rgSCHCmnRgrCellCfg*/
11514
11515 \f
11516 /**
11517  * @brief This function handles the reconfiguration of cell.
11518  *
11519  * @details
11520  *
11521  *     Function: rgSCHCmnRgrCellRecfg
11522  *     Purpose:  Update the reconfiguration parameters.
11523  *
11524  *     Invoked by: Scheduler
11525  *
11526  *  @param[in]  RgSchCellCb*  cell
11527  *  @return  Void
11528  *
11529  **/
11530 #ifdef ANSI
11531 S16 rgSCHCmnRgrCellRecfg
11532 (
11533 RgSchCellCb             *cell,
11534 RgrCellRecfg            *recfg,
11535 RgSchErrInfo            *err
11536 )
11537 #else
11538 S16 rgSCHCmnRgrCellRecfg(cell, recfg, err)
11539 RgSchCellCb             *cell;
11540 RgrCellRecfg            *recfg;
11541 RgSchErrInfo            *err;
11542 #endif
11543 {
11544    S16                  ret;
11545    RgSchCmnCell         *cellSch = RG_SCH_CMN_GET_CELL(cell);
11546    RgSchCmnUlCell       *cellUl  = RG_SCH_CMN_GET_UL_CELL(cell);
11547
11548
11549    if (recfg->recfgTypes & RGR_CELL_UL_CMNRATE_RECFG)
11550    {
11551       U8   oldCqi = cellUl->dfltUlCqi;
11552       if (!RG_SCH_CMN_UL_IS_CQI_VALID(recfg->ulCmnCodeRate.ccchCqi))
11553       {
11554          err->errCause = RGSCHERR_SCH_CFG;
11555          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId, "rgSCHCmnRgrCellRecfg(): "
11556             "Invalid cqi");
11557          return RFAILED;
11558       }
11559       cellUl->dfltUlCqi = recfg->ulCmnCodeRate.ccchCqi;
11560       ret = rgSCHCmnPrecompMsg3Vars(cellUl, recfg->ulCmnCodeRate.ccchCqi,
11561             cell->rachCfg.msgSizeGrpA, cellUl->sbSize, cell->isCpUlExtend);
11562       if (ret != ROK)
11563       {
11564          cellUl->dfltUlCqi = oldCqi;
11565          rgSCHCmnPrecompMsg3Vars(cellUl, recfg->ulCmnCodeRate.ccchCqi,
11566                cell->rachCfg.msgSizeGrpA, cellUl->sbSize, cell->isCpUlExtend);
11567          return (ret);
11568       }
11569    }
11570
11571    if (recfg->recfgTypes & RGR_CELL_DL_CMNRATE_RECFG)
11572    {
11573       if (rgSCHCmnDlCnsdrCmnRt(cell, &recfg->dlCmnCodeRate) != ROK)
11574       {
11575          err->errCause = RGSCHERR_SCH_CFG;
11576          return RFAILED;
11577       }
11578    }
11579  
11580 #ifdef EMTC_ENABLE  
11581    if(TRUE == cell->emtcEnable) 
11582    {
11583       /* Invoke UL sched for cell Recfg */
11584       ret = cellSch->apisEmtcUl->rgSCHRgrUlCellRecfg(cell, recfg, err);
11585       if (ret != ROK)
11586       {
11587          return RFAILED;
11588       }
11589
11590       /* Invoke DL sched for cell Recfg */
11591       ret = cellSch->apisEmtcDl->rgSCHRgrDlCellRecfg(cell, recfg, err);
11592       if (ret != ROK)
11593       {
11594          return RFAILED;
11595       }
11596    }
11597    else
11598 #endif
11599    {
11600    /* Invoke UL sched for cell Recfg */
11601    ret = cellSch->apisUl->rgSCHRgrUlCellRecfg(cell, recfg, err);
11602    if (ret != ROK)
11603    {
11604       return RFAILED;
11605    }
11606
11607    /* Invoke DL sched for cell Recfg */
11608    ret = cellSch->apisDl->rgSCHRgrDlCellRecfg(cell, recfg, err);
11609    if (ret != ROK)
11610    {
11611       return RFAILED;
11612    }
11613    }
11614
11615    if (recfg->recfgTypes & RGR_CELL_DLFS_RECFG)
11616    {
11617       ret = cellSch->apisDlfs->rgSCHDlfsCellRecfg(cell, recfg, err);
11618       if (ret != ROK)
11619       {
11620          return RFAILED;
11621       }
11622       cellSch->dl.isDlFreqSel = recfg->dlfsRecfg.isDlFreqSel;
11623    }
11624
11625    if (recfg->recfgTypes & RGR_CELL_PWR_RECFG)
11626    {
11627       ret = rgSCHPwrCellRecfg(cell, recfg);
11628       if (ret != ROK)
11629       {
11630          return RFAILED;
11631       }
11632    }
11633
11634    return ROK;
11635 }
11636
11637 /***********************************************************
11638  *
11639  *     Func : rgSCHCmnUlCellDeinit
11640  *
11641  *     Desc : Uplink scheduler de-initialisation for cell.
11642  *
11643  *     Ret  : S16
11644  *
11645  *     Notes:
11646  *
11647  *     File :
11648  *
11649  **********************************************************/
11650 #ifdef ANSI
11651 PRIVATE Void rgSCHCmnUlCellDeinit
11652 (
11653 RgSchCellCb *cell
11654 )
11655 #else
11656 PRIVATE Void rgSCHCmnUlCellDeinit(cell)
11657 RgSchCellCb *cell;
11658 #endif
11659 {
11660    RgSchCmnUlCell   *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
11661    U8               ulSfIdx;
11662 #ifdef LTE_TDD
11663    U8        maxSubfrms = cellUl->numUlSubfrms;
11664 #endif
11665 #ifdef LTE_L2_MEAS
11666    CmLList       *lnk = NULLP;
11667    RgSchL2MeasCb *measCb;
11668 #endif
11669 #ifdef LTE_L2_MEAS
11670 #ifdef LTE_TDD
11671    for(ulSfIdx = 0; ulSfIdx < RGSCH_SF_ALLOC_SIZE; ulSfIdx++)
11672 #else
11673    for(ulSfIdx = 0; ulSfIdx < RGSCH_NUM_SUB_FRAMES; ulSfIdx++)
11674 #endif
11675    {
11676       if(cell->sfAllocArr[ulSfIdx].ulUeInfo.ulAllocInfo != NULLP)
11677       {
11678          /* ccpu00117052 - MOD - Passing double pointer
11679             for proper NULLP assignment*/
11680          rgSCHUtlFreeSBuf(cell->instIdx,
11681          (Data **)(&(cell->sfAllocArr[ulSfIdx].ulUeInfo.ulAllocInfo)),
11682          cellUl->maxAllocPerUlSf * sizeof(RgInfUeUlAlloc));
11683
11684          /* ccpu00117052 - DEL - removed explicit NULLP assignment
11685             as it is done in above utility function */
11686       }
11687    }
11688    /* Free the memory allocated to measCb */
11689    lnk = cell->l2mList.first;
11690    while(lnk != NULLP)
11691    {
11692       measCb = (RgSchL2MeasCb *)lnk->node;
11693       cmLListDelFrm(&cell->l2mList, lnk);
11694       lnk = lnk->next;
11695    /* ccpu00117052 - MOD - Passing double pointer
11696    for proper NULLP assignment*/
11697       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&measCb,\
11698                           sizeof(RgSchL2MeasCb));
11699    }
11700 #endif
11701    if (cellUl->dmrsArr != NULLP)
11702    {
11703       /* ccpu00117052 - MOD - Passing double pointer
11704       for proper NULLP assignment*/
11705       rgSCHUtlFreeSBuf(cell->instIdx,(Data **)(&(cellUl->dmrsArr)),
11706                cellUl->dmrsArrSize * sizeof(*cellUl->dmrsArr));
11707    }
11708    /* De-init subframes */
11709 #ifdef LTE_TDD
11710    for (ulSfIdx = 0; ulSfIdx < maxSubfrms; ++ulSfIdx)
11711 #else
11712    for (ulSfIdx = 0; ulSfIdx < RG_SCH_CMN_UL_NUM_SF; ++ulSfIdx)
11713 #endif
11714    {
11715       rgSCHUtlUlSfDeinit(cell, &cellUl->ulSfArr[ulSfIdx]);
11716    }
11717
11718 #ifdef LTE_TDD
11719    if (cellUl->ulSfArr != NULLP)
11720    {
11721       /* ccpu00117052 - MOD - Passing double pointer
11722       for proper NULLP assignment*/
11723       rgSCHUtlFreeSBuf(cell->instIdx,
11724          (Data **)(&(cellUl->ulSfArr)), maxSubfrms * sizeof(RgSchUlSf));
11725    }
11726 #endif
11727
11728    RETVOID;
11729 }
11730
11731 /**
11732  * @brief Scheduler processing for cell delete.
11733  *
11734  * @details
11735  *
11736  *     Function : rgSCHCmnCellDel
11737  *
11738  *     This functions de-initialises and frees memory
11739  *     taken up by scheduler1 for the entire cell.
11740  *
11741  *  @param[in]  RgSchCellCb  *cell
11742  *  @return  Void
11743  **/
11744 #ifdef ANSI
11745 Void rgSCHCmnCellDel
11746 (
11747 RgSchCellCb  *cell
11748 )
11749 #else
11750 Void rgSCHCmnCellDel(cell)
11751 RgSchCellCb  *cell;
11752 #endif
11753 {
11754    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
11755
11756 #ifdef LTE_L2_MEAS
11757    glblTtiCnt = 0;
11758 #endif
11759    if (cellSch == NULLP)
11760    {
11761       RETVOID;
11762    }
11763    /* Perform the deinit for the UL scheduler */
11764    rgSCHCmnUlCellDeinit(cell);
11765 #ifdef EMTC_ENABLE
11766    if(TRUE == cell->emtcEnable)
11767    {
11768       if (cellSch->apisEmtcUl)
11769       {
11770          cellSch->apisEmtcUl->rgSCHFreeUlCell(cell);
11771       }
11772    }
11773 #endif 
11774    if (cellSch->apisUl)
11775    {
11776       /* api pointer checks added (here and below in
11777        * this function). pl check. - antriksh */
11778       cellSch->apisUl->rgSCHFreeUlCell(cell);
11779    }
11780
11781    /* Perform the deinit for the DL scheduler */
11782    cmLListInit(&cellSch->dl.taLst);
11783    if (cellSch->apisDl)
11784    {
11785       cellSch->apisDl->rgSCHFreeDlCell(cell);
11786    }
11787 #ifdef EMTC_ENABLE
11788    if (cellSch->apisEmtcDl)
11789    {
11790       rgSCHEmtcInitTaLst(&cellSch->dl);
11791
11792       cellSch->apisEmtcDl->rgSCHFreeDlCell(cell);
11793    }
11794 #endif
11795
11796    /* DLFS de-initialization */
11797    if (cellSch->dl.isDlFreqSel && cellSch->apisDlfs)
11798    {
11799       cellSch->apisDlfs->rgSCHDlfsCellDel(cell);
11800    }
11801
11802    rgSCHPwrCellDel(cell);
11803 #ifdef LTEMAC_SPS
11804    rgSCHCmnSpsCellDel(cell);
11805 #endif
11806
11807    /* ccpu00117052 - MOD - Passing double pointer
11808    for proper NULLP assignment*/
11809    rgSCHUtlFreeSBuf(cell->instIdx,
11810       (Data**)(&(cell->sc.sch)), (sizeof(RgSchCmnCell)));
11811    RETVOID;
11812 }  /* rgSCHCmnCellDel */
11813
11814 \f
11815 /**
11816  * @brief This function validates QOS parameters for DL.
11817  *
11818  * @details
11819  *
11820  *     Function: rgSCHCmnValidateDlQos
11821  *     Purpose:  This function validates QOS parameters for DL.
11822  *
11823  *     Invoked by: Scheduler
11824  *
11825  *  @param[in] CrgLchQosCfg    *dlQos
11826  *  @return                    S16
11827  *
11828  **/
11829 #ifdef ANSI
11830 PRIVATE S16 rgSCHCmnValidateDlQos
11831 (
11832 RgrLchQosCfg            *dlQos
11833 )
11834 #else
11835 PRIVATE S16 rgSCHCmnValidateDlQos(dlQos)
11836 RgrLchQosCfg            *dlQos;
11837 #endif
11838 {
11839    U8 qci = dlQos->qci;
11840
11841
11842    if ( qci < RG_SCH_CMN_MIN_QCI || qci > RG_SCH_CMN_MAX_QCI )
11843    {
11844       return RFAILED;
11845    }
11846
11847    if ((qci >= RG_SCH_CMN_GBR_QCI_START) &&
11848        (qci <= RG_SCH_CMN_GBR_QCI_END))
11849    {
11850       if ((dlQos->mbr == 0) || (dlQos->mbr < dlQos->gbr))
11851       {
11852          return RFAILED;
11853       }
11854    }
11855    return ROK;
11856 }
11857
11858 /**
11859  * @brief Scheduler invocation on logical channel addition.
11860  *
11861  * @details
11862  *
11863  *     Function : rgSCHCmnRgrLchCfg
11864  *
11865  *     This functions does required processing when a new
11866  *     (dedicated) logical channel is added. Assumes lcg
11867  *     pointer in ulLc is set.
11868  *
11869  *  @param[in]  RgSchCellCb  *cell
11870  *  @param[in]  RgSchUeCb    *ue
11871  *  @param[in]  RgSchDlLcCb  *dlLc
11872  *  @param[int] RgrLchCfg    *lcCfg
11873  *  @param[out] RgSchErrInfo *err
11874  *  @return  S16
11875  *      -# ROK
11876  *      -# RFAILED
11877  **/
11878 #ifdef ANSI
11879 S16 rgSCHCmnRgrLchCfg
11880 (
11881 RgSchCellCb  *cell,
11882 RgSchUeCb    *ue,
11883 RgSchDlLcCb  *dlLc,
11884 RgrLchCfg *lcCfg,
11885 RgSchErrInfo *err
11886 )
11887 #else
11888 S16 rgSCHCmnRgrLchCfg(cell, ue, dlLc, lcCfg, err)
11889 RgSchCellCb  *cell;
11890 RgSchUeCb    *ue;
11891 RgSchDlLcCb  *dlLc;
11892 RgrLchCfg *lcCfg;
11893 RgSchErrInfo *err;
11894 #endif
11895 {
11896    S16 ret;
11897
11898    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
11899
11900
11901    ret = rgSCHUtlAllocSBuf(cell->instIdx,
11902       (Data**)&((dlLc)->sch), (sizeof(RgSchCmnDlSvc)));
11903    if (ret != ROK)
11904    {
11905       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHCmnRgrLchCfg(): "
11906          "SCH struct alloc failed for CRNTI:%d LCID:%d",ue->ueId,lcCfg->lcId);
11907       err->errCause = RGSCHERR_SCH_CFG;
11908       return (ret);
11909    }
11910    if(lcCfg->lcType != CM_LTE_LCH_DCCH)
11911    {
11912       ret = rgSCHCmnValidateDlQos(&lcCfg->dlInfo.dlQos);
11913       if (ret != ROK)
11914       {
11915          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,"rgSchCmnCrgLcCfg(): "
11916             "DlQos validation failed for CRNTI:%d LCID:%d",ue->ueId,lcCfg->lcId);
11917          err->errCause = RGSCHERR_SCH_CFG;
11918          return (ret);
11919       }
11920       /* Perform DL service activation in the scheduler */
11921       ((RgSchCmnDlSvc *)(dlLc->sch))->qci = lcCfg->dlInfo.dlQos.qci;
11922       ((RgSchCmnDlSvc *)(dlLc->sch))->prio = rgSchCmnDlQciPrio[lcCfg->dlInfo.dlQos.qci - 1];
11923       ((RgSchCmnDlSvc *)(dlLc->sch))->gbr = (lcCfg->dlInfo.dlQos.gbr * \
11924       RG_SCH_CMN_REFRESH_TIME)/100;
11925       ((RgSchCmnDlSvc *)(dlLc->sch))->mbr = (lcCfg->dlInfo.dlQos.mbr * \
11926       RG_SCH_CMN_REFRESH_TIME)/100;
11927    }
11928    else
11929    {
11930      /*assigning highest priority to DCCH */
11931     ((RgSchCmnDlSvc *)(dlLc->sch))->prio=RG_SCH_CMN_DCCH_PRIO; 
11932    }   
11933    dlLc->ue = ue;
11934    dlLc->lcType=lcCfg->lcType;
11935
11936 #ifdef EMTC_ENABLE
11937    if((cell->emtcEnable)&&(TRUE == ue->isEmtcUe))
11938    {
11939       ret = cellSch->apisEmtcDl->rgSCHRgrDlLcCfg(cell, ue,dlLc ,lcCfg, err);
11940       if (ret != ROK)
11941       {
11942          return RFAILED;
11943       }
11944    }
11945    else
11946 #endif 
11947    {
11948       ret = cellSch->apisDl->rgSCHRgrDlLcCfg(cell, ue, dlLc, lcCfg, err);
11949       if (ret != ROK)
11950       {
11951          return RFAILED;
11952       }
11953    }
11954    
11955 #ifdef EMTC_ENABLE
11956    if(TRUE == ue->isEmtcUe)
11957    {
11958       ret = cellSch->apisEmtcUl->rgSCHRgrUlLcCfg(cell, ue, lcCfg, err);
11959       if (ret != ROK)
11960       {
11961          return RFAILED;
11962       }
11963    }
11964    else
11965 #endif 
11966    {
11967    ret = cellSch->apisUl->rgSCHRgrUlLcCfg(cell, ue, lcCfg, err);
11968    if (ret != ROK)
11969    {
11970       return RFAILED;
11971    }
11972    }
11973    
11974 #ifdef LTE_ADV
11975    if (ue->numSCells)
11976    {
11977       rgSCHSCellDlLcCfg(cell, ue, dlLc);
11978    }
11979 #endif
11980
11981
11982 #ifdef LTEMAC_SPS
11983    if(lcCfg->dlInfo.dlSpsCfg.isSpsEnabled)
11984    {
11985       /* Invoke SPS module if SPS is enabled for the service */
11986       ret = rgSCHCmnSpsDlLcCfg(cell, ue, dlLc, lcCfg, err);
11987       if (ret != ROK)
11988       {
11989          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,  "rgSchCmnRgrLchCfg(): "
11990             "SPS configuration failed for DL LC for CRNTI:%d LCID:%d",ue->ueId,lcCfg->lcId);
11991          err->errCause = RGSCHERR_SCH_CFG;
11992          return RFAILED;
11993       }
11994    }
11995 #endif
11996
11997    return ROK;
11998 }
11999
12000 /**
12001  * @brief Scheduler invocation on logical channel addition.
12002  *
12003  * @details
12004  *
12005  *     Function : rgSCHCmnRgrLchRecfg
12006  *
12007  *     This functions does required processing when an existing
12008  *     (dedicated) logical channel is reconfigured. Assumes lcg
12009  *     pointer in ulLc is set to the old value.
12010  *     Independent of whether new LCG is meant to be configured,
12011  *     the new LCG scheduler information is accessed and possibly modified.
12012  *
12013  *  @param[in]  RgSchCellCb  *cell
12014  *  @param[in]  RgSchUeCb    *ue
12015  *  @param[in]  RgSchDlLcCb  *dlLc
12016  *  @param[int] RgrLchRecfg  *lcRecfg
12017  *  @param[out] RgSchErrInfo *err
12018  *  @return  S16
12019  *      -# ROK
12020  *      -# RFAILED
12021  **/
12022 #ifdef ANSI
12023 S16 rgSCHCmnRgrLchRecfg
12024 (
12025 RgSchCellCb  *cell,
12026 RgSchUeCb    *ue,
12027 RgSchDlLcCb  *dlLc,
12028 RgrLchRecfg  *lcRecfg,
12029 RgSchErrInfo *err
12030 )
12031 #else
12032 S16 rgSCHCmnRgrLchRecfg(cell, ue, dlLc, lcRecfg, err)
12033 RgSchCellCb  *cell;
12034 RgSchUeCb    *ue;
12035 RgSchDlLcCb  *dlLc;
12036 RgrLchRecfg  *lcRecfg;
12037 RgSchErrInfo *err;
12038 #endif
12039 {
12040    S16   ret;
12041    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
12042
12043
12044    if(dlLc->lcType != CM_LTE_LCH_DCCH)
12045    {
12046       ret = rgSCHCmnValidateDlQos(&lcRecfg->dlRecfg.dlQos);
12047    
12048       if (ret != ROK)
12049       {
12050          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,
12051                "DlQos validation failed for CRNTI:%d LCID:%d",ue->ueId,lcRecfg->lcId);
12052          err->errCause = RGSCHERR_SCH_CFG;
12053          return (ret);
12054       }
12055       if (((RgSchCmnDlSvc *)(dlLc->sch))->qci != lcRecfg->dlRecfg.dlQos.qci)
12056       {
12057          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId, "Qci, hence lc Priority change "
12058             "not supported for CRNTI:%d LCID:%d",ue->ueId,lcRecfg->lcId);
12059          err->errCause = RGSCHERR_SCH_CFG;
12060          return (ret);
12061       }
12062       ((RgSchCmnDlSvc *)(dlLc->sch))->gbr = (lcRecfg->dlRecfg.dlQos.gbr * \
12063       RG_SCH_CMN_REFRESH_TIME)/100;
12064       ((RgSchCmnDlSvc *)(dlLc->sch))->mbr = (lcRecfg->dlRecfg.dlQos.mbr * \
12065       RG_SCH_CMN_REFRESH_TIME)/100;
12066    }
12067    else
12068    {
12069       /*assigning highest priority to DCCH */
12070       ((RgSchCmnDlSvc *)(dlLc->sch))->prio = RG_SCH_CMN_DCCH_PRIO; 
12071    }
12072    
12073 #ifdef EMTC_ENABLE
12074    if((cell->emtcEnable)&&(TRUE == ue->isEmtcUe))
12075    {
12076       ret = cellSch->apisEmtcDl->rgSCHRgrDlLcRecfg(cell, ue, dlLc, lcRecfg, err);
12077       if (ret != ROK)
12078       {
12079          return RFAILED;
12080       }
12081       ret = cellSch->apisEmtcUl->rgSCHRgrUlLcRecfg(cell, ue, lcRecfg, err);
12082       if (ret != ROK)
12083       {
12084          return RFAILED;
12085       }
12086    }
12087    else
12088 #endif 
12089    {
12090    ret = cellSch->apisDl->rgSCHRgrDlLcRecfg(cell, ue, dlLc, lcRecfg, err);
12091    if (ret != ROK)
12092    {
12093       return RFAILED;
12094    }
12095    ret = cellSch->apisUl->rgSCHRgrUlLcRecfg(cell, ue, lcRecfg, err);
12096    if (ret != ROK)
12097    {
12098       return RFAILED;
12099    }
12100    }
12101     
12102 #ifdef LTEMAC_SPS
12103    if (lcRecfg->recfgTypes & RGR_DL_LC_SPS_RECFG)
12104    {
12105       /* Invoke SPS module if SPS is enabled for the service */
12106       if(lcRecfg->dlRecfg.dlSpsRecfg.isSpsEnabled)
12107       {
12108          ret = rgSCHCmnSpsDlLcRecfg(cell, ue, dlLc, lcRecfg, err);
12109          if (ret != ROK)
12110          {
12111             RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,"SPS re-configuration not "
12112                   "supported for dlLC Ignore this CRNTI:%d LCID:%d",ue->ueId,lcRecfg->lcId);
12113          }
12114       }
12115       return ROK;
12116    }
12117 #endif
12118
12119    return ROK;
12120 }
12121
12122 /**
12123  * @brief Scheduler invocation on logical channel addition.
12124  *
12125  * @details
12126  *
12127  *     Function : rgSCHCmnRgrLcgCfg
12128  *
12129  *     This functions does required processing when a new
12130  *     (dedicated) logical channel is added. Assumes lcg
12131  *     pointer in ulLc is set.
12132  *
12133  *  @param[in]  RgSchCellCb  *cell,
12134  *  @param[in]  RgSchUeCb    *ue,
12135  *  @param[in]  RgSchLcgCb   *lcg,
12136  *  @param[in]  RgrLcgCfg    *lcgCfg,
12137  *  @param[out] RgSchErrInfo *err
12138  *  @return  S16
12139  *      -# ROK
12140  *      -# RFAILED
12141  **/
12142 #ifdef ANSI
12143 S16 rgSCHCmnRgrLcgCfg
12144 (
12145 RgSchCellCb  *cell,
12146 RgSchUeCb    *ue,
12147 RgSchLcgCb   *lcg,
12148 RgrLcgCfg    *lcgCfg,
12149 RgSchErrInfo *err
12150 )
12151 #else
12152 S16 rgSCHCmnRgrLcgCfg(cell, ue, lcg, lcgCfg, err)
12153 RgSchCellCb  *cell;
12154 RgSchUeCb    *ue;
12155 RgSchLcgCb   *lcg;
12156 RgrLcgCfg    *lcgCfg;
12157 RgSchErrInfo *err;
12158 #endif
12159 {
12160    S16 ret;
12161    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
12162    RgSchCmnLcg  *ulLcg = ((RgSchCmnLcg *)(ue->ul.lcgArr[lcgCfg->ulInfo.lcgId].sch));
12163
12164
12165    ulLcg->cfgdGbr = (lcgCfg->ulInfo.gbr * RG_SCH_CMN_REFRESH_TIME)/100;
12166    ulLcg->effGbr  = ulLcg->cfgdGbr;
12167    ulLcg->deltaMbr = ((lcgCfg->ulInfo.mbr - lcgCfg->ulInfo.gbr) * RG_SCH_CMN_REFRESH_TIME)/100;
12168    ulLcg->effDeltaMbr = ulLcg->deltaMbr;
12169
12170 #ifdef EMTC_ENABLE
12171    if(TRUE == ue->isEmtcUe)
12172    {
12173       ret = cellSch->apisEmtcUl->rgSCHRgrUlLcgCfg(cell, ue, lcg, lcgCfg, err);
12174       if (ret != ROK)
12175       {
12176          return RFAILED;
12177       }
12178    }
12179    else
12180 #endif
12181    {
12182    ret = cellSch->apisUl->rgSCHRgrUlLcgCfg(cell, ue, lcg, lcgCfg, err);
12183    if (ret != ROK)
12184    {
12185       return RFAILED;
12186    }
12187    }
12188    if (RGSCH_IS_GBR_BEARER(ulLcg->cfgdGbr))
12189    {
12190       /* Indicate MAC that this LCG is GBR LCG */
12191       rgSCHUtlBuildNSendLcgReg(cell, ue->ueId, lcgCfg->ulInfo.lcgId, TRUE);
12192    }
12193    return ROK;
12194 }
12195
12196 /**
12197  * @brief Scheduler invocation on logical channel addition.
12198  *
12199  * @details
12200  *
12201  *     Function : rgSCHCmnRgrLcgRecfg
12202  *
12203  *     This functions does required processing when a new
12204  *     (dedicated) logical channel is added. Assumes lcg
12205  *     pointer in ulLc is set.
12206  *
12207  *  @param[in]  RgSchCellCb  *cell,
12208  *  @param[in]  RgSchUeCb    *ue,
12209  *  @param[in]  RgSchLcgCb   *lcg,
12210  *  @param[in]  RgrLcgRecfg  *reCfg,
12211  *  @param[out] RgSchErrInfo *err
12212  *  @return  S16
12213  *      -# ROK
12214  *      -# RFAILED
12215  **/
12216 #ifdef ANSI
12217 S16 rgSCHCmnRgrLcgRecfg
12218 (
12219 RgSchCellCb  *cell,
12220 RgSchUeCb    *ue,
12221 RgSchLcgCb   *lcg,
12222 RgrLcgRecfg  *reCfg,
12223 RgSchErrInfo *err
12224 )
12225 #else
12226 S16 rgSCHCmnRgrLcgRecfg(cell, ue, lcg, reCfg, err)
12227 RgSchCellCb  *cell;
12228 RgSchUeCb    *ue;
12229 RgSchLcgCb   *lcg;
12230 RgrLcgRecfg  *reCfg;
12231 RgSchErrInfo *err;
12232 #endif
12233 {
12234    S16 ret;
12235    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
12236    RgSchCmnLcg  *ulLcg = ((RgSchCmnLcg *)(ue->ul.lcgArr[reCfg->ulRecfg.lcgId].sch));
12237    
12238
12239    ulLcg->cfgdGbr = (reCfg->ulRecfg.gbr * RG_SCH_CMN_REFRESH_TIME)/100;
12240    ulLcg->effGbr  = ulLcg->cfgdGbr;
12241    ulLcg->deltaMbr = ((reCfg->ulRecfg.mbr - reCfg->ulRecfg.gbr) * RG_SCH_CMN_REFRESH_TIME)/100;
12242    ulLcg->effDeltaMbr = ulLcg->deltaMbr;
12243  
12244 #ifdef EMTC_ENABLE
12245    if(TRUE == ue->isEmtcUe)
12246    {
12247       ret = cellSch->apisEmtcUl->rgSCHRgrUlLcgRecfg(cell, ue, lcg, reCfg, err);
12248       if (ret != ROK)
12249       {
12250          return RFAILED;
12251       }
12252    }
12253    else
12254 #endif
12255    {
12256    ret = cellSch->apisUl->rgSCHRgrUlLcgRecfg(cell, ue, lcg, reCfg, err);
12257    if (ret != ROK)
12258    {
12259       return RFAILED;
12260    }
12261    }
12262    if (RGSCH_IS_GBR_BEARER(ulLcg->cfgdGbr))
12263    {
12264       /* Indicate MAC that this LCG is GBR LCG */
12265       rgSCHUtlBuildNSendLcgReg(cell, ue->ueId, reCfg->ulRecfg.lcgId, TRUE);
12266    }
12267    else
12268    {
12269       /* In case of RAB modification */
12270       rgSCHUtlBuildNSendLcgReg(cell, ue->ueId, reCfg->ulRecfg.lcgId, FALSE);
12271    }
12272    return ROK;
12273 }
12274
12275 /***********************************************************
12276  *
12277  *     Func : rgSCHCmnRgrLchDel
12278  *
12279  *     Desc : Scheduler handling for a (dedicated)
12280  *             uplink logical channel being deleted.
12281  *
12282  *     Ret  :
12283  *
12284  *     Notes:
12285  *
12286  *     File :
12287  **********************************************************/
12288 #ifdef ANSI
12289 S16 rgSCHCmnRgrLchDel 
12290 (
12291 RgSchCellCb   *cell,
12292 RgSchUeCb     *ue,
12293 CmLteLcId     lcId,
12294 U8            lcgId
12295 )
12296 #else
12297 S16 rgSCHCmnRgrLchDel(cell, ue, lcId, lcgId)
12298 RgSchCellCb   *cell;
12299 RgSchUeCb     *ue;
12300 CmLteLcId     lcId;
12301 U8            lcgId;
12302 #endif
12303 {
12304    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
12305 #ifdef EMTC_ENABLE
12306    if(TRUE == ue->isEmtcUe)
12307    {
12308       cellSch->apisEmtcUl->rgSCHRgrUlLchDel(cell, ue, lcId, lcgId);
12309    }
12310    else
12311 #endif
12312    {
12313    cellSch->apisUl->rgSCHRgrUlLchDel(cell, ue, lcId, lcgId);
12314    }
12315    return ROK;
12316 }
12317
12318 /***********************************************************
12319  *
12320  *     Func : rgSCHCmnLcgDel
12321  *
12322  *     Desc : Scheduler handling for a (dedicated)
12323  *             uplink logical channel being deleted.
12324  *
12325  *     Ret  :
12326  *
12327  *     Notes:
12328  *
12329  *     File :
12330  *
12331  **********************************************************/
12332 #ifdef ANSI
12333 Void rgSCHCmnLcgDel
12334 (
12335 RgSchCellCb   *cell,
12336 RgSchUeCb     *ue,
12337 RgSchLcgCb    *lcg
12338 )
12339 #else
12340 Void rgSCHCmnLcgDel(cell, ue, lcg)
12341 RgSchCellCb   *cell;
12342 RgSchUeCb     *ue;
12343 RgSchLcgCb    *lcg;
12344 #endif
12345 {
12346    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
12347    RgSchCmnLcg  *lcgCmn = RG_SCH_CMN_GET_UL_LCG(lcg);
12348
12349    if (lcgCmn == NULLP)
12350    {
12351       RETVOID;
12352    }
12353
12354    if (RGSCH_IS_GBR_BEARER(lcgCmn->cfgdGbr))
12355    {
12356       /* Indicate MAC that this LCG is GBR LCG */
12357       rgSCHUtlBuildNSendLcgReg(cell, ue->ueId, lcg->lcgId, FALSE);
12358    }
12359
12360 #ifdef LTEMAC_SPS
12361    if (ue->ul.ulSpsCfg.isUlSpsEnabled == TRUE)
12362    {
12363       rgSCHCmnSpsUlLcgDel(cell, ue, lcg);
12364    }
12365 #endif /* LTEMAC_SPS */
12366
12367    lcgCmn->effGbr     = 0;
12368    lcgCmn->reportedBs = 0;
12369    lcgCmn->cfgdGbr    = 0;
12370    /* set lcg bs to 0. Deletion of control block happens
12371     * at the time of UE deletion. */
12372    lcgCmn->bs = 0;
12373 #ifdef EMTC_ENABLE
12374    if(TRUE == ue->isEmtcUe)
12375    {
12376       cellSch->apisEmtcUl->rgSCHFreeUlLcg(cell, ue, lcg);
12377    }
12378    else
12379 #endif
12380    {
12381    cellSch->apisUl->rgSCHFreeUlLcg(cell, ue, lcg);
12382    }
12383    RETVOID;
12384 }
12385
12386 \f
12387 /**
12388  * @brief This function deletes a service from scheduler.
12389  *
12390  * @details
12391  *
12392  *     Function: rgSCHCmnFreeDlLc
12393  *     Purpose:  This function is made available through a FP for
12394  *               making scheduler aware of a service being deleted from UE.
12395  *
12396  *     Invoked by: BO and Scheduler
12397  *
12398  *  @param[in]  RgSchCellCb*  cell
12399  *  @param[in]  RgSchUeCb*    ue
12400  *  @param[in]  RgSchDlLcCb*  svc
12401  *  @return  Void
12402  *
12403  **/
12404 #ifdef ANSI
12405 Void rgSCHCmnFreeDlLc
12406 (
12407 RgSchCellCb                *cell,
12408 RgSchUeCb                  *ue,
12409 RgSchDlLcCb                *svc
12410 )
12411 #else
12412 Void rgSCHCmnFreeDlLc(cell, ue, svc)
12413 RgSchCellCb                *cell;
12414 RgSchUeCb                  *ue;
12415 RgSchDlLcCb                *svc;
12416 #endif
12417 {
12418    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
12419    if (svc->sch == NULLP)
12420    {
12421       RETVOID;
12422    }
12423 #ifdef EMTC_ENABLE
12424     if((cell->emtcEnable)&&(TRUE == ue->isEmtcUe))
12425     {
12426       cellSch->apisEmtcDl->rgSCHFreeDlLc(cell, ue, svc);
12427     }
12428     else
12429 #endif
12430    {
12431       cellSch->apisDl->rgSCHFreeDlLc(cell, ue, svc);
12432    }
12433
12434 #ifdef LTE_ADV
12435    if (ue->numSCells)
12436    {
12437       rgSCHSCellDlLcDel(cell, ue, svc);
12438    }
12439 #endif
12440
12441 #ifdef LTEMAC_SPS
12442    /* If SPS service, invoke SPS module */
12443    if (svc->dlLcSpsCfg.isSpsEnabled)
12444    {
12445       rgSCHCmnSpsDlLcDel(cell, ue, svc);
12446    }
12447 #endif
12448
12449    /* ccpu00117052 - MOD - Passing double pointer
12450    for proper NULLP assignment*/
12451    rgSCHUtlFreeSBuf(cell->instIdx,
12452          (Data**)(&(svc->sch)), (sizeof(RgSchCmnDlSvc)));
12453
12454 #ifdef LTE_ADV
12455    rgSCHLaaDeInitDlLchCb(cell, svc);
12456 #endif
12457
12458    RETVOID;
12459 }
12460
12461 #ifdef RGR_V1
12462
12463 /**
12464  * @brief This function Processes the Final Allocations
12465  *        made by the RB Allocator against the requested
12466  *        CCCH SDURetx Allocations.
12467  *
12468  * @details
12469  *
12470  *     Function: rgSCHCmnDlCcchSduRetxFnlz
12471  *     Purpose:  This function Processes the Final Allocations
12472  *               made by the RB Allocator against the requested
12473  *               CCCH Retx Allocations.
12474  *               Scans through the scheduled list of ccchSdu retrans
12475  *               fills the corresponding pdcch, adds the hqProc to
12476  *               the corresponding SubFrm and removes the hqP from
12477  *               cells retx List.
12478  *
12479  *     Invoked by: Common Scheduler
12480  *
12481  *  @param[in]  RgSchCellCb           *cell
12482  *  @param[in]  RgSchCmnDlRbAllocInfo *allocInfo
12483  *  @return  Void
12484  *
12485  **/
12486 #ifdef ANSI
12487 PRIVATE Void rgSCHCmnDlCcchSduRetxFnlz
12488 (
12489 RgSchCellCb           *cell,
12490 RgSchCmnDlRbAllocInfo *allocInfo
12491 )
12492 #else
12493 PRIVATE Void rgSCHCmnDlCcchSduRetxFnlz(cell, allocInfo)
12494 RgSchCellCb           *cell;
12495 RgSchCmnDlRbAllocInfo *allocInfo;
12496 #endif
12497 {
12498    CmLList           *node;
12499    RgSchCmnDlCell    *cmnCellDl = RG_SCH_CMN_GET_DL_CELL(cell);
12500    RgSchDlRbAlloc    *rbAllocInfo;
12501    RgSchDlHqProcCb   *hqP;
12502    RgSchUeCb         *ue;
12503
12504    /* Traverse through the Scheduled Retx List */
12505    node = allocInfo->ccchSduAlloc.schdCcchSduRetxLst.first;
12506    while (node)
12507    {
12508       hqP = (RgSchDlHqProcCb *)(node->node);
12509       ue = hqP->hqE->ue;
12510       rbAllocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue, cell);
12511       node = node->next;
12512       rgSCHCmnFillHqPPdcch(cell, rbAllocInfo, hqP);
12513
12514       /* Remove the HqP from cell's ccchSduRetxLst */
12515       cmLListDelFrm(&cmnCellDl->ccchSduRetxLst, &hqP->tbInfo[0].ccchSchdInfo.retxLnk);
12516       hqP->tbInfo[0].ccchSchdInfo.retxLnk.node = (PTR)NULLP;
12517
12518       /* Fix: syed dlAllocCb reset should be performed.
12519        * zombie info in dlAllocCb leading to crash rbNum wraparound */ 
12520       rgSCHCmnDlUeResetTemp(ue, hqP);
12521    }
12522    /* Fix: syed dlAllocCb reset should be performed.
12523     * zombie info in dlAllocCb leading to crash rbNum wraparound */ 
12524    node = allocInfo->ccchSduAlloc.nonSchdCcchSduRetxLst.first;
12525    while(node)
12526    {
12527       hqP = (RgSchDlHqProcCb *)(node->node);
12528       ue = hqP->hqE->ue;
12529       node = node->next;
12530       /* reset the UE allocation Information */
12531       rgSCHCmnDlUeResetTemp(ue, hqP);
12532    }
12533    RETVOID;
12534 }
12535 #endif
12536 /**
12537  * @brief This function Processes the Final Allocations
12538  *        made by the RB Allocator against the requested
12539  *        CCCH Retx Allocations.
12540  *
12541  * @details
12542  *
12543  *     Function: rgSCHCmnDlCcchRetxFnlz
12544  *     Purpose:  This function Processes the Final Allocations
12545  *               made by the RB Allocator against the requested
12546  *               CCCH Retx Allocations.
12547  *               Scans through the scheduled list of msg4 retrans
12548  *               fills the corresponding pdcch, adds the hqProc to
12549  *               the corresponding SubFrm and removes the hqP from
12550  *               cells retx List.
12551  *
12552  *     Invoked by: Common Scheduler
12553  *
12554  *  @param[in]  RgSchCellCb           *cell
12555  *  @param[in]  RgSchCmnDlRbAllocInfo *allocInfo
12556  *  @return  Void
12557  *
12558  **/
12559 #ifdef ANSI
12560 PRIVATE Void rgSCHCmnDlCcchRetxFnlz
12561 (
12562 RgSchCellCb           *cell,
12563 RgSchCmnDlRbAllocInfo *allocInfo
12564 )
12565 #else
12566 PRIVATE Void rgSCHCmnDlCcchRetxFnlz(cell, allocInfo)
12567 RgSchCellCb           *cell;
12568 RgSchCmnDlRbAllocInfo *allocInfo;
12569 #endif
12570 {
12571    CmLList           *node;
12572    RgSchCmnDlCell    *cmnCellDl = RG_SCH_CMN_GET_DL_CELL(cell);
12573    RgSchDlRbAlloc    *rbAllocInfo;
12574    RgSchDlHqProcCb   *hqP;
12575    RgSchRaCb         *raCb;
12576
12577    /* Traverse through the Scheduled Retx List */
12578    node = allocInfo->msg4Alloc.schdMsg4RetxLst.first;
12579    while (node)
12580    {
12581       hqP = (RgSchDlHqProcCb *)(node->node);
12582       raCb = hqP->hqE->raCb;
12583       rbAllocInfo = &raCb->rbAllocInfo;
12584       node = node->next;
12585       rgSCHCmnFillHqPPdcch(cell, rbAllocInfo, hqP);
12586
12587       /* Remove the HqP from cell's msg4RetxLst */
12588       cmLListDelFrm(&cmnCellDl->msg4RetxLst, &hqP->tbInfo[0].ccchSchdInfo.retxLnk);
12589       hqP->tbInfo[0].ccchSchdInfo.retxLnk.node = (PTR)NULLP;
12590       /* Fix: syed dlAllocCb reset should be performed.
12591        * zombie info in dlAllocCb leading to crash rbNum wraparound */ 
12592       memset(rbAllocInfo, 0, sizeof(*rbAllocInfo));
12593       rgSCHCmnDlHqPResetTemp(hqP);
12594    }
12595    /* Fix: syed dlAllocCb reset should be performed.
12596     * zombie info in dlAllocCb leading to crash rbNum wraparound */ 
12597    node = allocInfo->msg4Alloc.nonSchdMsg4RetxLst.first;
12598    while(node)
12599    {
12600       hqP = (RgSchDlHqProcCb *)(node->node);
12601       raCb = hqP->hqE->raCb;
12602       node = node->next;
12603       memset(&raCb->rbAllocInfo, 0, sizeof(raCb->rbAllocInfo));
12604       rgSCHCmnDlHqPResetTemp(hqP);
12605    }
12606    RETVOID;
12607 }
12608
12609 #ifdef RGR_V1
12610 /**
12611  * @brief This function Processes the Final Allocations
12612  *        made by the RB Allocator against the requested
12613  *        CCCH SDU tx Allocations.
12614  *
12615  * @details
12616  *
12617  *     Function: rgSCHCmnDlCcchSduTxFnlz
12618  *     Purpose:  This function Processes the Final Allocations
12619  *               made by the RB Allocator against the requested
12620  *               CCCH tx Allocations.
12621  *               Scans through the scheduled list of CCCH SDU trans
12622  *               fills the corresponding pdcch, adds the hqProc to
12623  *               the corresponding SubFrm and removes the hqP from
12624  *               cells tx List.
12625  *
12626  *     Invoked by: Common Scheduler
12627  *
12628  *  @param[in]  RgSchCellCb           *cell
12629  *  @param[in]  RgSchCmnDlRbAllocInfo *allocInfo
12630  *  @return  Void
12631  *
12632  **/
12633 #ifdef ANSI
12634 PRIVATE Void rgSCHCmnDlCcchSduTxFnlz
12635 (
12636 RgSchCellCb           *cell,
12637 RgSchCmnDlRbAllocInfo *allocInfo
12638 )
12639 #else
12640 PRIVATE Void rgSCHCmnDlCcchSduTxFnlz(cell, allocInfo)
12641 RgSchCellCb           *cell;
12642 RgSchCmnDlRbAllocInfo *allocInfo;
12643 #endif
12644 {
12645    CmLList           *node;
12646    RgSchUeCb         *ueCb;
12647    RgSchDlRbAlloc    *rbAllocInfo;
12648    RgSchDlHqProcCb   *hqP;
12649    RgSchLchAllocInfo  lchSchdData;
12650
12651    /* Traverse through the Scheduled Retx List */
12652    node = allocInfo->ccchSduAlloc.schdCcchSduTxLst.first;
12653    while (node)
12654    {
12655       hqP = (RgSchDlHqProcCb *)(node->node);
12656       ueCb = hqP->hqE->ue;
12657       node = node->next;
12658       rbAllocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ueCb, cell);
12659
12660       /* fill the pdcch and HqProc */
12661       rgSCHCmnFillHqPPdcch(cell, rbAllocInfo, hqP);
12662
12663       /* Remove the raCb from cell's toBeSchdLst */
12664       cmLListDelFrm(&cell->ccchSduUeLst, &ueCb->ccchSduLnk);
12665       ueCb->ccchSduLnk.node = (PTR)NULLP;
12666
12667       /* Fix : Resetting this required to avoid complication
12668        * in reestablishment case */
12669       ueCb->dlCcchInfo.bo = 0;
12670
12671       /* Indicate DHM of the CCCH LC scheduling */
12672       hqP->tbInfo[0].contResCe = NOTPRSNT;
12673       lchSchdData.lcId     = 0;
12674       lchSchdData.schdData = hqP->tbInfo[0].ccchSchdInfo.totBytes -
12675                              (RGSCH_MSG4_HDRSIZE);
12676       rgSCHDhmAddLcData(cell->instIdx, &lchSchdData, &hqP->tbInfo[0]);
12677
12678       /* Fix: syed dlAllocCb reset should be performed.
12679        * zombie info in dlAllocCb leading to crash rbNum wraparound */ 
12680       rgSCHCmnDlUeResetTemp(ueCb, hqP);
12681    }
12682    /* Fix: syed dlAllocCb reset should be performed.
12683     * zombie info in dlAllocCb leading to crash rbNum wraparound */ 
12684    node = allocInfo->ccchSduAlloc.nonSchdCcchSduTxLst.first;
12685    while(node)
12686    {
12687       hqP = (RgSchDlHqProcCb *)(node->node);
12688       ueCb = hqP->hqE->ue;
12689       node = node->next;
12690       /* Release HqProc */
12691       rgSCHDhmRlsHqpTb(hqP, 0, FALSE);
12692       /*Fix: Removing releasing of TB1 as it will not exist for CCCH SDU and hence caused a crash*/
12693       /*rgSCHDhmRlsHqpTb(hqP, 1, FALSE);*/
12694       /* reset the UE allocation Information */
12695       rgSCHCmnDlUeResetTemp(ueCb, hqP);
12696    }
12697    RETVOID;
12698 }
12699
12700 #endif
12701 /**
12702  * @brief This function Processes the Final Allocations
12703  *        made by the RB Allocator against the requested
12704  *        CCCH tx Allocations.
12705  *
12706  * @details
12707  *
12708  *     Function: rgSCHCmnDlCcchTxFnlz
12709  *     Purpose:  This function Processes the Final Allocations
12710  *               made by the RB Allocator against the requested
12711  *               CCCH tx Allocations.
12712  *               Scans through the scheduled list of msg4 trans
12713  *               fills the corresponding pdcch, adds the hqProc to
12714  *               the corresponding SubFrm and removes the hqP from
12715  *               cells tx List.
12716  *
12717  *     Invoked by: Common Scheduler
12718  *
12719  *  @param[in]  RgSchCellCb           *cell
12720  *  @param[in]  RgSchCmnDlRbAllocInfo *allocInfo
12721  *  @return  Void
12722  *
12723  **/
12724 #ifdef ANSI
12725 PRIVATE Void rgSCHCmnDlCcchTxFnlz
12726 (
12727 RgSchCellCb           *cell,
12728 RgSchCmnDlRbAllocInfo *allocInfo
12729 )
12730 #else
12731 PRIVATE Void rgSCHCmnDlCcchTxFnlz(cell, allocInfo)
12732 RgSchCellCb           *cell;
12733 RgSchCmnDlRbAllocInfo *allocInfo;
12734 #endif
12735 {
12736    CmLList           *node;
12737    RgSchRaCb         *raCb;
12738    RgSchDlRbAlloc    *rbAllocInfo;
12739    RgSchDlHqProcCb   *hqP;
12740    RgSchLchAllocInfo  lchSchdData;
12741
12742    /* Traverse through the Scheduled Retx List */
12743    node = allocInfo->msg4Alloc.schdMsg4TxLst.first;
12744    while (node)
12745    {
12746       hqP = (RgSchDlHqProcCb *)(node->node);
12747       raCb = hqP->hqE->raCb;
12748       node = node->next;
12749       rbAllocInfo = &raCb->rbAllocInfo;
12750
12751       /* fill the pdcch and HqProc */
12752       rgSCHCmnFillHqPPdcch(cell, rbAllocInfo, hqP);
12753       /* MSG4 Fix Start */
12754      
12755       rgSCHRamRmvFrmRaInfoSchdLst(cell, raCb);
12756       /* MSG4 Fix End */     
12757
12758       /* Indicate DHM of the CCCH LC scheduling */
12759       lchSchdData.lcId     = 0;
12760       lchSchdData.schdData = hqP->tbInfo[0].ccchSchdInfo.totBytes -
12761          (RGSCH_MSG4_HDRSIZE + RGSCH_CONT_RESID_SIZE);
12762       /* TRansmitting presence of cont Res CE across MAC-SCH interface to
12763        * identify CCCH SDU transmissions which need to be done
12764        * without the
12765        * contention resolution CE*/
12766       hqP->tbInfo[0].contResCe = PRSNT_NODEF;
12767       /*Dont add lc if only cont res CE is being transmitted*/
12768       if(raCb->dlCcchInfo.bo)
12769       {
12770          rgSCHDhmAddLcData(cell->instIdx, &lchSchdData, &hqP->tbInfo[0]);
12771       }
12772       else
12773       {
12774       }
12775       /* Fix: syed dlAllocCb reset should be performed.
12776        * zombie info in dlAllocCb leading to crash rbNum wraparound */ 
12777       memset(&raCb->rbAllocInfo, 0, sizeof(raCb->rbAllocInfo));
12778       rgSCHCmnDlHqPResetTemp(hqP);
12779    }
12780    node = allocInfo->msg4Alloc.nonSchdMsg4TxLst.first;
12781    while(node)
12782    {
12783       hqP = (RgSchDlHqProcCb *)(node->node);
12784       raCb = hqP->hqE->raCb;
12785       node = node->next;
12786       rbAllocInfo = &raCb->rbAllocInfo;
12787       /* Release HqProc */
12788       rgSCHDhmRlsHqpTb(hqP, 0, FALSE);
12789       /*Fix: Removing releasing of TB1 as it will not exist for MSG4 and hence caused a crash*/
12790       /*      rgSCHDhmRlsHqpTb(hqP, 1, FALSE);*/
12791       /* reset the UE allocation Information */
12792       memset(rbAllocInfo, 0, sizeof(*rbAllocInfo));
12793       rgSCHCmnDlHqPResetTemp(hqP);
12794    }
12795
12796    RETVOID;
12797 }
12798 /* R8 Upgrade */
12799 /**
12800  * @brief This function calculates the BI Index to be sent in the Bi header
12801  * field.
12802  *
12803  * @details
12804  *     Function: rgSCHCmnGetBiIndex
12805  *     Purpose:  This function Processes utilizes the previous BI time value
12806  *     calculated and the difference last BI sent time and current time. To
12807  *     calculate the latest BI Index. It also considers the how many UE's
12808  *     Unserved in this subframe.
12809  *
12810  *     Invoked by: Common Scheduler
12811  *
12812  *  @param[in]  RgSchCellCb           *cell
12813  *  @param[in]  U32                   ueCount
12814  *  @return  U8
12815  *
12816  **/
12817 #ifdef ANSI
12818 U8 rgSCHCmnGetBiIndex
12819 (
12820 RgSchCellCb   *cell,
12821 U32           ueCount
12822 )
12823 #else
12824 U8 rgSCHCmnGetBiIndex(cell, ueCount)
12825 RgSchCellCb   *cell;
12826 U32           ueCount;
12827 #endif
12828 {
12829    S16  prevVal = 0;      /* To Store Intermediate Value */
12830    U16  newBiVal = 0;     /* To store Bi Value in millisecond */
12831    U8   idx = 0;
12832    U16  timeDiff = 0;
12833
12834
12835    if (cell->biInfo.prevBiTime != 0)
12836    {
12837 #ifdef EMTC_ENABLE
12838       if(cell->emtcEnable == TRUE)
12839       {
12840          timeDiff =(RGSCH_CALC_SF_DIFF_EMTC(cell->crntTime, cell->biInfo.biTime));
12841       }
12842       else
12843 #endif
12844       {
12845          timeDiff =(RGSCH_CALC_SF_DIFF(cell->crntTime, cell->biInfo.biTime));
12846       }
12847
12848       prevVal = cell->biInfo.prevBiTime - timeDiff;
12849    }
12850    if (prevVal < 0)
12851    {
12852       prevVal = 0;
12853    }
12854    newBiVal = RG_SCH_CMN_GET_BI_VAL(prevVal,ueCount);
12855    /* To be used next time when BI is calculated */
12856 #ifdef EMTC_ENABLE
12857    if(cell->emtcEnable == TRUE)
12858    {
12859       RGSCHCPYTIMEINFO_EMTC(cell->crntTime, cell->biInfo.biTime)
12860    }
12861    else
12862 #endif
12863    {
12864       RGSCHCPYTIMEINFO(cell->crntTime, cell->biInfo.biTime)
12865    }
12866
12867   /* Search the actual BI Index from table Backoff Parameters Value  and
12868    * return that Index */
12869    do
12870    {
12871       if (rgSchCmnBiTbl[idx] > newBiVal)
12872       {
12873          break;
12874       }
12875       idx++;
12876    }while(idx < RG_SCH_CMN_NUM_BI_VAL-1);
12877    cell->biInfo.prevBiTime = rgSchCmnBiTbl[idx];
12878    /* For 16 Entries in Table 7.2.1 36.321.880 - 3 reserved so total 13 Entries */
12879    return (idx); /* Returning reserved value from table UE treats it has 960 ms */
12880 } /* rgSCHCmnGetBiIndex */
12881
12882
12883 /**
12884  * @brief This function Processes the Final Allocations
12885  *        made by the RB Allocator against the requested
12886  *        RAR allocations. Assumption: The reuqested
12887  *        allocations are always satisfied completely.
12888  *        Hence no roll back.
12889  *
12890  * @details
12891  *
12892  *     Function: rgSCHCmnDlRaRspFnlz
12893  *     Purpose:  This function Processes the Final Allocations
12894  *               made by the RB Allocator against the requested.
12895  *               Takes care of PDCCH filling.
12896  *
12897  *     Invoked by: Common Scheduler
12898  *
12899  *  @param[in]  RgSchCellCb           *cell
12900  *  @param[in]  RgSchCmnDlRbAllocInfo *allocInfo
12901  *  @return  Void
12902  *
12903  **/
12904 #ifdef ANSI
12905 PRIVATE Void rgSCHCmnDlRaRspFnlz
12906 (
12907 RgSchCellCb           *cell,
12908 RgSchCmnDlRbAllocInfo *allocInfo
12909 )
12910 #else
12911 PRIVATE Void rgSCHCmnDlRaRspFnlz(cell, allocInfo)
12912 RgSchCellCb           *cell;
12913 RgSchCmnDlRbAllocInfo *allocInfo;
12914 #endif
12915 {
12916    U32            rarCnt = 0;
12917    RgSchDlRbAlloc *raRspAlloc;
12918    RgSchDlSf      *subFrm = NULLP;
12919    RgSchRaCb      *raCb;
12920    RgSchErrInfo   err;
12921    CmLListCp      *reqLst;
12922    RgSchRaReqInfo *raReq;
12923    Bool           preamGrpA;
12924    RgSchUlAlloc   *ulAllocRef=NULLP;
12925    RgSchCmnDlCell *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
12926    U8              allocRapidCnt = 0;
12927 #ifdef LTE_TDD
12928    U32            msg3SchdIdx = 0;
12929    U8             ulDlCfgIdx = cell->ulDlCfgIdx;
12930    U8             msg3Subfrm;
12931 #endif
12932
12933
12934    for (rarCnt=0; rarCnt<RG_SCH_CMN_MAX_CMN_PDCCH; rarCnt++)
12935    {
12936       raRspAlloc = &allocInfo->raRspAlloc[rarCnt];
12937       /* Having likely condition first for optimization */
12938       if (!raRspAlloc->pdcch)
12939       {
12940          continue;
12941       }
12942       else
12943       {
12944          subFrm = raRspAlloc->dlSf;
12945          reqLst = &cell->raInfo.raReqLst[raRspAlloc->raIndex];
12946          /* Corrected RACH handling for multiple RAPIDs per RARNTI */
12947          allocRapidCnt = raRspAlloc->numRapids;
12948          while (allocRapidCnt)
12949          {
12950             raReq = (RgSchRaReqInfo *)(reqLst->first->node);
12951             /* RACHO: If dedicated preamble, then allocate UL Grant
12952              * (consequence of handover/pdcchOrder) and continue */
12953             if (RGSCH_IS_DEDPRM(cell, raReq->raReq.rapId))
12954             {
12955                rgSCHCmnHdlHoPo(cell, &subFrm->raRsp[rarCnt].contFreeUeLst,
12956                      raReq);
12957                cmLListDelFrm(reqLst, reqLst->first);
12958                allocRapidCnt--;
12959                /* ccpu00117052 - MOD - Passing double pointer
12960                for proper NULLP assignment*/
12961                rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&raReq,
12962                      sizeof(RgSchRaReqInfo));
12963                continue;
12964             }
12965             /* ccpu00139815 */
12966             if(cell->overLoadBackOffEnab)
12967             {/* rach Overlaod conrol is triggerd, Skipping this rach */
12968                cmLListDelFrm(reqLst, reqLst->first);
12969                allocRapidCnt--;
12970                rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&raReq,
12971                      sizeof(RgSchRaReqInfo));
12972                continue;
12973             }
12974             /* Attempt to include each RA request into the RSP */
12975             /* Any failure in the procedure is considered to   */
12976             /* affect futher allocations in the same TTI. When */
12977             /* a failure happens, we break out and complete    */
12978             /* the processing for random access                */
12979             if (rgSCHRamCreateRaCb(cell, &raCb, &err) != ROK)
12980             {
12981                break;
12982             }
12983             /* Msg3 allocation request to USM */
12984             if (raReq->raReq.rapId < cell->rachCfg.sizeRaPreambleGrpA)
12985                preamGrpA = TRUE;
12986             else
12987                preamGrpA = FALSE;
12988             /*ccpu00128820 - MOD - Msg3 alloc double delete issue*/
12989             rgSCHCmnMsg3GrntReq(cell, raCb->tmpCrnti, preamGrpA, \
12990                   &(raCb->msg3HqProc), &ulAllocRef, &raCb->msg3HqProcId);
12991             if (ulAllocRef == NULLP)
12992             {
12993                rgSCHRamDelRaCb(cell, raCb, TRUE);
12994                break;
12995             }
12996             if (raReq->raReq.cqiPres)
12997             {
12998                raCb->ccchCqi = raReq->raReq.cqiIdx;
12999             }
13000             else
13001             {
13002                raCb->ccchCqi = cellDl->ccchCqi;
13003             }
13004             raCb->rapId = raReq->raReq.rapId;
13005             raCb->ta.pres    = TRUE;
13006             raCb->ta.val = raReq->raReq.ta;
13007             raCb->msg3Grnt = ulAllocRef->grnt;
13008             /* Populating the tpc value received */
13009             raCb->msg3Grnt.tpc = raReq->raReq.tpc;
13010             /* PHR handling for MSG3 */
13011             ulAllocRef->raCb = raCb;
13012 #ifndef LTE_TDD
13013             /* To the crntTime, add the MIN time at which UE will
13014              * actually send MSG3 i.e DL_DELTA+6 */
13015             raCb->msg3AllocTime = cell->crntTime;
13016             RGSCH_INCR_SUB_FRAME(raCb->msg3AllocTime, RG_SCH_CMN_MIN_MSG3_RECP_INTRVL);
13017 #else
13018             msg3SchdIdx = (cell->crntTime.slot+RG_SCH_CMN_DL_DELTA) % 
13019                                  RGSCH_NUM_SUB_FRAMES;
13020             /*[ccpu00134666]-MOD-Modify the check to schedule the RAR in
13021               special subframe */                       
13022             if(rgSchTddUlDlSubfrmTbl[ulDlCfgIdx][msg3SchdIdx] != 
13023                         RG_SCH_TDD_UL_SUBFRAME)
13024             {
13025                RGSCHCMNADDTOCRNTTIME(cell->crntTime,raCb->msg3AllocTime,
13026                                        RG_SCH_CMN_DL_DELTA)
13027                msg3Subfrm = rgSchTddMsg3SubfrmTbl[ulDlCfgIdx][
13028                                        raCb->msg3AllocTime.slot];
13029                RGSCHCMNADDTOCRNTTIME(raCb->msg3AllocTime, raCb->msg3AllocTime, 
13030                                  msg3Subfrm);
13031             }
13032 #endif
13033             cmLListAdd2Tail(&subFrm->raRsp[rarCnt].raRspLst, &raCb->rspLnk);
13034             raCb->rspLnk.node = (PTR)raCb;
13035             cmLListDelFrm(reqLst, reqLst->first);
13036             allocRapidCnt--;
13037             /* ccpu00117052 - MOD - Passing double pointer
13038             for proper NULLP assignment*/
13039             rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&raReq,
13040                   sizeof(RgSchRaReqInfo));
13041
13042             /* SR_RACH_STATS : RAR scheduled */
13043             rgNumRarSched++;
13044
13045          }
13046          /* R8 Upgrade */
13047          /* Fill subframe data members */
13048          subFrm->raRsp[rarCnt].raRnti = raRspAlloc->rnti;
13049          subFrm->raRsp[rarCnt].pdcch  = raRspAlloc->pdcch;
13050          subFrm->raRsp[rarCnt].tbSz   = raRspAlloc->tbInfo[0].bytesAlloc;
13051          /* Fill PDCCH data members */
13052          rgSCHCmnFillPdcch(cell, subFrm->raRsp[rarCnt].pdcch, raRspAlloc);
13053
13054          /* ccpu00139815 */
13055          if(cell->overLoadBackOffEnab)
13056          {/* rach Overlaod conrol is triggerd, Skipping this rach */
13057             subFrm->raRsp[rarCnt].backOffInd.pres = PRSNT_NODEF;
13058             subFrm->raRsp[rarCnt].backOffInd.val  = cell->overLoadBackOffval;
13059             continue;
13060          }
13061          else
13062          {
13063             subFrm->raRsp[rarCnt].backOffInd.pres = NOTPRSNT;
13064          }
13065
13066          /*[ccpu00125212] Avoiding sending of empty RAR in case of RAR window
13067            is short and UE is sending unauthorised preamble.*/
13068          reqLst = &cell->raInfo.raReqLst[raRspAlloc->raIndex];
13069          if ((raRspAlloc->biEstmt) && (reqLst->count))
13070          {
13071             subFrm->raRsp[0].backOffInd.pres = PRSNT_NODEF;
13072             /* Added as part of Upgrade */
13073             subFrm->raRsp[0].backOffInd.val =
13074             rgSCHCmnGetBiIndex(cell, reqLst->count);
13075
13076             /* SR_RACH_STATS : Back Off Inds */
13077             rgNumBI++;
13078
13079          }
13080          else if ((subFrm->raRsp[rarCnt].raRspLst.first == NULLP) &&
13081                (subFrm->raRsp[rarCnt].contFreeUeLst.first == NULLP))
13082          {
13083             /* Return the grabbed PDCCH */
13084             rgSCHUtlPdcchPut(cell, &subFrm->pdcchInfo, raRspAlloc->pdcch);
13085             subFrm->raRsp[rarCnt].pdcch = NULLP;
13086             RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHCmnRaRspAlloc(): "
13087                   "Not even one RaReq.");
13088             RETVOID;
13089          }
13090       }
13091       RLOG_ARG3(L_DEBUG,DBG_CELLID,cell->cellId, 
13092             "RNTI:%d Scheduled RAR @ (%u,%u) ",
13093             raRspAlloc->rnti, 
13094             cell->crntTime.sfn,
13095             cell->crntTime.slot);
13096    }
13097    RETVOID;
13098 }
13099
13100 /**
13101  * @brief This function computes rv.
13102  *
13103  * @details
13104  *
13105  *     Function: rgSCHCmnDlCalcRvForBcch
13106  *     Purpose:  This function computes rv.
13107  *
13108  *     Invoked by: Common Scheduler
13109  *
13110  *  @param[in]   RgSchCellCb     *cell
13111  *  @param[in]   Bool            si
13112  *  @param[in]   U16             i
13113  *  @return  U8
13114  *
13115  **/
13116 #ifdef ANSI
13117 PRIVATE U8 rgSCHCmnDlCalcRvForBcch
13118 (
13119 RgSchCellCb          *cell,
13120 Bool                 si,
13121 U16                  i
13122 )
13123 #else
13124 PRIVATE U8 rgSCHCmnDlCalcRvForBcch(cell, si, i)
13125 RgSchCellCb          *cell;
13126 Bool                 si;
13127 U16                  i;
13128 #endif
13129 {
13130    U8 k, rv;
13131    CmLteTimingInfo   frm;
13132
13133    frm   = cell->crntTime;
13134    RGSCH_INCR_SUB_FRAME(frm, RG_SCH_CMN_DL_DELTA);
13135
13136    if(si)
13137    {
13138       k = i % 4;
13139    }
13140    else
13141    {
13142       k = (frm.sfn/2) % 4;
13143    }
13144    rv = RGSCH_CEIL(3*k, 2) % 4;
13145    return (rv);
13146 }
13147
13148 /**
13149  * @brief This function Processes the Final Allocations
13150  *        made by the RB Allocator against the requested
13151  *        BCCH/PCCH allocations. Assumption: The reuqested
13152  *        allocations are always satisfied completely.
13153  *        Hence no roll back.
13154  *
13155  * @details
13156  *
13157  *     Function: rgSCHCmnDlBcchPcchFnlz
13158  *     Purpose:  This function Processes the Final Allocations
13159  *               made by the RB Allocator against the requested.
13160  *               Takes care of PDCCH filling.
13161  *
13162  *     Invoked by: Common Scheduler
13163  *
13164  *  @param[in]  RgSchCellCb           *cell
13165  *  @param[in]  RgSchCmnDlRbAllocInfo *allocInfo
13166  *  @return  Void
13167  *
13168  **/
13169 #ifdef ANSI
13170 PRIVATE Void rgSCHCmnDlBcchPcchFnlz
13171 (
13172 RgSchCellCb           *cell,
13173 RgSchCmnDlRbAllocInfo *allocInfo
13174 )
13175 #else
13176 PRIVATE Void rgSCHCmnDlBcchPcchFnlz(cell, allocInfo)
13177 RgSchCellCb           *cell;
13178 RgSchCmnDlRbAllocInfo *allocInfo;
13179 #endif
13180 {
13181    RgSchDlRbAlloc *rbAllocInfo;
13182    RgSchDlSf      *subFrm;
13183
13184 #ifdef LTE_TDD
13185    U8             nextSfIdx = (cell->crntSfIdx) % RGSCH_SF_ALLOC_SIZE;
13186 #else
13187 #ifdef LTEMAC_HDFDD
13188    U8             nextSfIdx = (cell->crntSfIdx + RG_SCH_CMN_HARQ_INTERVAL) % RGSCH_NUM_SUB_FRAMES;
13189 #else
13190    U8             nextSfIdx = (cell->crntSfIdx) % RGSCH_NUM_SUB_FRAMES;
13191 #endif
13192 #endif
13193
13194    /*  Moving variables to available scope for optimization */
13195    RgSchClcDlLcCb *pcch;
13196    RgSchClcBoRpt  *bo;
13197 #ifndef RGR_SI_SCH
13198    RgSchClcDlLcCb  *bcch;
13199    Bool           sendInd=TRUE;
13200 #endif
13201    RgSchCmnDlCell       *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
13202
13203
13204    /* handle PCCH */
13205    rbAllocInfo = &allocInfo->pcchAlloc;
13206    if (rbAllocInfo->pdcch)
13207    {
13208       RgInfSfAlloc   *subfrmAlloc = &(cell->sfAllocArr[nextSfIdx]);
13209
13210       /* Added sfIdx calculation for TDD as well */
13211 #ifndef LTE_TDD
13212 #ifdef LTEMAC_HDFDD
13213       nextSfIdx = (cell->crntSfIdx + RG_SCH_CMN_HARQ_INTERVAL) % RGSCH_NUM_SUB_FRAMES;
13214 #else
13215       nextSfIdx = (cell->crntSfIdx) % RGSCH_NUM_SUB_FRAMES;
13216 #endif
13217 #endif
13218       subFrm = rbAllocInfo->dlSf;
13219       pcch = rgSCHDbmGetPcch(cell);
13220       if(pcch == NULLP)
13221       {
13222          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHCmnDlBcchPcchFnlz( ): "
13223                "No Pcch Present");
13224          RETVOID;
13225       }
13226
13227       /* Added Dl TB count for paging message transmission*/
13228 #ifdef LTE_L2_MEAS
13229       cell->dlUlTbCnt.tbTransDlTotalCnt++;
13230 #endif      
13231       bo = (RgSchClcBoRpt *)pcch->boLst.first->node;
13232       cmLListDelFrm(&pcch->boLst, &bo->boLstEnt);
13233       /* ccpu00117052 - MOD - Passing double pointer
13234          for proper NULLP assignment*/
13235       rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&bo, sizeof(RgSchClcBoRpt));
13236       /* Fill subframe data members */
13237       subFrm->pcch.tbSize = rbAllocInfo->tbInfo[0].bytesAlloc;
13238       subFrm->pcch.pdcch  = rbAllocInfo->pdcch;
13239       /* Fill PDCCH data members */
13240       rgSCHCmnFillPdcch(cell, subFrm->pcch.pdcch, rbAllocInfo);
13241       rgSCHUtlFillRgInfCmnLcInfo(subFrm, subfrmAlloc, pcch->lcId, TRUE);
13242       /* ccpu00132314-ADD-Update the tx power allocation info  
13243          TODO-Need to add a check for max tx power per symbol */ 
13244       subfrmAlloc->cmnLcInfo.pcchInfo.txPwrOffset = cellDl->pcchTxPwrOffset;   
13245    }
13246
13247    /* handle BCCH */
13248    rbAllocInfo = &allocInfo->bcchAlloc;
13249    if (rbAllocInfo->pdcch)
13250    {
13251       RgInfSfAlloc   *subfrmAlloc = &(cell->sfAllocArr[nextSfIdx]);
13252 #ifndef LTE_TDD
13253 #ifdef LTEMAC_HDFDD
13254       nextSfIdx = (cell->crntSfIdx + RG_SCH_CMN_HARQ_INTERVAL) % RGSCH_NUM_SUB_FRAMES;
13255 #else
13256       nextSfIdx = (cell->crntSfIdx) % RGSCH_NUM_SUB_FRAMES;
13257 #endif
13258 #endif
13259       subFrm = rbAllocInfo->dlSf;
13260
13261       /* Fill subframe data members */
13262       subFrm->bcch.tbSize = rbAllocInfo->tbInfo[0].bytesAlloc;
13263       subFrm->bcch.pdcch  = rbAllocInfo->pdcch;
13264       /* Fill PDCCH data members */
13265       rgSCHCmnFillPdcch(cell, subFrm->bcch.pdcch, rbAllocInfo);
13266
13267       if(rbAllocInfo->schdFirst)
13268       {
13269 #ifndef RGR_SI_SCH
13270          bcch = rgSCHDbmGetFirstBcchOnDlsch(cell);
13271          bo = (RgSchClcBoRpt *)bcch->boLst.first->node;
13272 #else
13273          /*Copy the SIB1 msg buff into interface buffer */
13274          SCpyMsgMsg(cell->siCb.crntSiInfo.sib1Info.sib1,
13275                rgSchCb[cell->instIdx].rgSchInit.region,
13276                rgSchCb[cell->instIdx].rgSchInit.pool,
13277                &subfrmAlloc->cmnLcInfo.bcchInfo.pdu);
13278 #endif/*RGR_SI_SCH*/
13279          subFrm->bcch.pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.rv =
13280             rgSCHCmnDlCalcRvForBcch(cell, FALSE, 0);
13281       }
13282       else
13283       {
13284          U16   i;
13285 #ifdef RGR_SI_SCH
13286          Buffer    *pdu;
13287
13288          i = cell->siCb.siCtx.i;
13289          /*Decrement the retransmission count */
13290          cell->siCb.siCtx.retxCntRem--;
13291
13292          /*Copy the SI msg buff into interface buffer */
13293          if(cell->siCb.siCtx.warningSiFlag == FALSE)
13294          {
13295             SCpyMsgMsg(cell->siCb.siArray[cell->siCb.siCtx.siId-1].si,
13296                   rgSchCb[cell->instIdx].rgSchInit.region,
13297                   rgSchCb[cell->instIdx].rgSchInit.pool,
13298                   &subfrmAlloc->cmnLcInfo.bcchInfo.pdu);
13299          }
13300          else
13301          {
13302             pdu = rgSCHUtlGetWarningSiPdu(cell);
13303             RGSCH_NULL_CHECK(cell->instIdx, pdu);
13304             SCpyMsgMsg(pdu,
13305                   rgSchCb[cell->instIdx].rgSchInit.region,
13306                   rgSchCb[cell->instIdx].rgSchInit.pool,
13307                   &subfrmAlloc->cmnLcInfo.bcchInfo.pdu);
13308             if(cell->siCb.siCtx.retxCntRem == 0)
13309             {  
13310                rgSCHUtlFreeWarningSiPdu(cell);
13311                cell->siCb.siCtx.warningSiFlag  = FALSE;
13312
13313             }
13314          }
13315 #else
13316          bcch = rgSCHDbmGetSecondBcchOnDlsch(cell);
13317          bo = (RgSchClcBoRpt *)bcch->boLst.first->node;
13318          bo->retxCnt--;
13319          if(bo->retxCnt != cell->siCfg.retxCnt-1)
13320          {
13321             sendInd=FALSE;
13322          }
13323          i = bo->i;
13324 #endif/*RGR_SI_SCH*/
13325          subFrm->bcch.pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.rv =
13326             rgSCHCmnDlCalcRvForBcch(cell, TRUE, i);
13327       }
13328
13329       /* Added Dl TB count for SIB1 and SI messages transmission.
13330        * This counter will be incremented only for the first transmission
13331        * (with RV 0) of these messages*/
13332 #ifdef LTE_L2_MEAS
13333       if(subFrm->bcch.pdcch->dci.u.format1aInfo.t.pdschInfo.allocInfo.rv == 0)
13334       {   
13335          cell->dlUlTbCnt.tbTransDlTotalCnt++;
13336       }
13337 #endif      
13338 #ifndef RGR_SI_SCH
13339       if(bo->retxCnt == 0)
13340       {
13341          cmLListDelFrm(&bcch->boLst, &bo->boLstEnt);
13342          /* ccpu00117052 - MOD - Passing double pointer
13343             for proper NULLP assignment*/
13344          rgSCHUtlFreeSBuf(cell->instIdx, (Data **)&bo, sizeof(RgSchClcBoRpt));
13345       }
13346       rgSCHUtlFillRgInfCmnLcInfo(subFrm, subfrmAlloc, bcch->lcId, sendInd);
13347 #else
13348       /*Fill the interface info */
13349       rgSCHUtlFillRgInfCmnLcInfo(subFrm, subfrmAlloc, NULLD, NULLD);
13350
13351       /* ccpu00132314-ADD-Update the tx power allocation info  
13352          TODO-Need to add a check for max tx power per symbol */ 
13353       subfrmAlloc->cmnLcInfo.bcchInfo.txPwrOffset = cellDl->bcchTxPwrOffset;   
13354
13355       /*mBuf has been already copied above */
13356 #endif/*RGR_SI_SCH*/
13357    }
13358
13359    RETVOID;
13360 }
13361
13362
13363 #if RG_UNUSED
13364 /**
13365  * @brief
13366  *
13367  * @details
13368  *
13369  *     Function: rgSCHCmnUlSetAllUnSched
13370  *     Purpose:
13371  *
13372  *     Invoked by: Common Scheduler
13373  *
13374  *  @param[out] RgSchCmnUlRbAllocInfo *allocInfo
13375  *  @return  Void
13376  *
13377  **/
13378 #ifdef ANSI
13379 PRIVATE Void rgSCHCmnUlSetAllUnSched
13380 (
13381 RgSchCmnUlRbAllocInfo *allocInfo
13382 )
13383 #else
13384 PRIVATE Void rgSCHCmnUlSetAllUnSched(allocInfo)
13385 RgSchCmnUlRbAllocInfo *allocInfo;
13386 #endif
13387 {
13388    CmLList            *node;
13389
13390
13391    node = allocInfo->contResLst.first;
13392    while (node)
13393    {
13394       rgSCHCmnUlMov2NonSchdCntResLst(allocInfo, (RgSchUeCb *)node->node);
13395       node = allocInfo->contResLst.first;
13396    }
13397
13398    node = allocInfo->retxUeLst.first;
13399    while (node)
13400    {
13401       rgSCHCmnUlMov2NonSchdRetxUeLst(allocInfo, (RgSchUeCb *)node->node);
13402       node = allocInfo->retxUeLst.first;
13403    }
13404
13405    node = allocInfo->ueLst.first;
13406    while (node)
13407    {
13408       rgSCHCmnUlMov2NonSchdUeLst(allocInfo, (RgSchUeCb *)node->node);
13409       node = allocInfo->ueLst.first;
13410    }
13411
13412    RETVOID;
13413 }
13414 #endif
13415
13416 /**
13417  * @brief
13418  *
13419  * @details
13420  *
13421  *     Function: rgSCHCmnUlAdd2CntResLst
13422  *     Purpose:
13423  *
13424  *     Invoked by: Common Scheduler
13425  *
13426  *  @param[out] RgSchCmnUlRbAllocInfo *allocInfo
13427  *  @param[in]  RgSchUeCb             *ue
13428  *  @return  Void
13429  *
13430  **/
13431 #ifdef ANSI
13432 Void rgSCHCmnUlAdd2CntResLst
13433 (
13434 RgSchCmnUlRbAllocInfo *allocInfo,
13435 RgSchUeCb             *ue
13436 )
13437 #else
13438 Void rgSCHCmnUlAdd2CntResLst(allocInfo, ue)
13439 RgSchCmnUlRbAllocInfo *allocInfo;
13440 RgSchUeCb             *ue;
13441 #endif
13442 {
13443    RgSchCmnUeUlAlloc  *ulAllocInfo = &((RG_SCH_CMN_GET_UL_UE(ue,ue->cell))->alloc);
13444    cmLListAdd2Tail(&allocInfo->contResLst, &ulAllocInfo->reqLnk);
13445    ulAllocInfo->reqLnk.node = (PTR)ue;
13446    RETVOID;
13447 }
13448
13449 /**
13450  * @brief
13451  *
13452  * @details
13453  *
13454  *     Function: rgSCHCmnUlAdd2UeLst
13455  *     Purpose:
13456  *
13457  *     Invoked by: Common Scheduler
13458  *
13459  *  @param[out] RgSchCmnUlRbAllocInfo *allocInfo
13460  *  @param[in]  RgSchUeCb             *ue
13461  *  @return  Void
13462  *
13463  **/
13464 #ifdef ANSI
13465 Void rgSCHCmnUlAdd2UeLst
13466 (
13467 RgSchCellCb           *cell,
13468 RgSchCmnUlRbAllocInfo *allocInfo,
13469 RgSchUeCb             *ue
13470 )
13471 #else
13472 Void rgSCHCmnUlAdd2UeLst(cell, allocInfo, ue)
13473 RgSchCellCb           *cell;
13474 RgSchCmnUlRbAllocInfo *allocInfo;
13475 RgSchUeCb             *ue;
13476 #endif
13477 {
13478    RgSchCmnUeUlAlloc  *ulAllocInfo = &((RG_SCH_CMN_GET_UL_UE(ue,cell))->alloc);
13479    if (ulAllocInfo->reqLnk.node == NULLP)
13480    {
13481       cmLListAdd2Tail(&allocInfo->ueLst, &ulAllocInfo->reqLnk);
13482       ulAllocInfo->reqLnk.node = (PTR)ue;
13483    }
13484    RETVOID;
13485 }
13486
13487 /**
13488  * @brief
13489  *
13490  * @details
13491  *
13492  *     Function: rgSCHCmnAllocUlRb
13493  *     Purpose:  To do RB allocations for uplink
13494  *
13495  *     Invoked by: Common Scheduler
13496  *
13497  *  @param[in]  RgSchCellCb           *cell
13498  *  @param[in]  RgSchCmnUlRbAllocInfo *allocInfo
13499  *  @return  Void
13500  **/
13501 #ifdef ANSI
13502 Void rgSCHCmnAllocUlRb
13503 (
13504 RgSchCellCb           *cell,
13505 RgSchCmnUlRbAllocInfo *allocInfo
13506 )
13507 #else
13508 Void rgSCHCmnAllocUlRb(cell, allocInfo)
13509 RgSchCellCb           *cell;
13510 RgSchCmnUlRbAllocInfo *allocInfo;
13511 #endif
13512 {
13513    RgSchUlSf         *sf = allocInfo->sf;
13514
13515    /* Schedule for new transmissions */
13516    rgSCHCmnUlRbAllocForLst(cell, sf, allocInfo->ueLst.count,
13517          &allocInfo->ueLst, &allocInfo->schdUeLst,
13518          &allocInfo->nonSchdUeLst, (Bool)TRUE);
13519    RETVOID;
13520 }
13521
13522 /***********************************************************
13523  *
13524  *     Func : rgSCHCmnUlRbAllocForLst
13525  *
13526  *     Desc : Allocate for a list in cmn rb alloc information passed
13527  *            in a subframe.
13528  *
13529  *     Ret  :
13530  *
13531  *     Notes:
13532  *
13533  *     File :
13534  *
13535  **********************************************************/
13536 #ifdef ANSI
13537 PRIVATE Void rgSCHCmnUlRbAllocForLst
13538 (
13539 RgSchCellCb           *cell,
13540 RgSchUlSf             *sf,
13541 U32                   count,
13542 CmLListCp             *reqLst,
13543 CmLListCp             *schdLst,
13544 CmLListCp             *nonSchdLst,
13545 Bool                  isNewTx
13546 )
13547 #else
13548 PRIVATE Void rgSCHCmnUlRbAllocForLst(cell, sf, count, reqLst, schdLst,
13549                                      nonSchdLst, isNewTx)
13550 RgSchCellCb           *cell;
13551 RgSchUlSf             *sf;
13552 U32                   count;
13553 CmLListCp             *reqLst;
13554 CmLListCp             *schdLst;
13555 CmLListCp             *nonSchdLst;
13556 Bool                  isNewTx;
13557 #endif
13558 {
13559    CmLList          *lnk;
13560    RgSchUlHole      *hole;
13561 #ifdef LTE_L2_MEAS
13562 #ifdef LTE_TDD
13563    U8               k;
13564    CmLteTimingInfo  timeInfo;
13565 #endif    
13566 #endif    
13567
13568    if(schdLst->count == 0)
13569    {
13570       cmLListInit(schdLst);
13571    }
13572
13573    cmLListInit(nonSchdLst);
13574 #ifdef LTE_L2_MEAS
13575    if(isNewTx == TRUE)
13576    {
13577       cell->sfAllocArr[cell->crntSfIdx].ulUeInfo.numUes = (U8) count;
13578 #ifdef LTE_TDD
13579       RG_SCH_ADD_TO_CRNT_TIME(cell->crntTime, timeInfo, TFU_ULCNTRL_DLDELTA);
13580       k = rgSchTddPuschTxKTbl[cell->ulDlCfgIdx][timeInfo.subframe];
13581       RG_SCH_ADD_TO_CRNT_TIME(timeInfo,
13582           cell->sfAllocArr[cell->crntSfIdx].ulUeInfo.timingInfo, k);
13583 #else
13584       RG_SCH_ADD_TO_CRNT_TIME(cell->crntTime,cell->sfAllocArr[cell->crntSfIdx].ulUeInfo.timingInfo,
13585                             (TFU_ULCNTRL_DLDELTA + RGSCH_PDCCH_PUSCH_DELTA));
13586 #endif
13587    }
13588 #endif
13589
13590    for (lnk = reqLst->first; count; lnk = lnk->next, --count)
13591    {
13592       RgSchUeCb             *ue = (RgSchUeCb *)lnk->node;
13593       RgSchCmnUlUe          *ueUl = RG_SCH_CMN_GET_UL_UE(ue, cell);
13594       S16                   ret;
13595       U8                    maxRb;
13596
13597
13598       if ((hole = rgSCHUtlUlHoleFirst(sf)) == NULLP)
13599       {
13600          break;
13601       }
13602
13603       ueUl->subbandShare = ueUl->subbandRequired;
13604       if(isNewTx == TRUE)
13605       {
13606          maxRb = RGSCH_MIN((ueUl->subbandRequired * MAX_5GTF_VRBG_SIZE), ue->ue5gtfCb.maxPrb);
13607       } 
13608       ret = rgSCHCmnUlRbAllocForUe(cell, sf, ue, maxRb, hole);
13609       if (ret == ROK)
13610       {
13611          rgSCHCmnUlRbAllocAddUeToLst(cell, ue, schdLst);
13612          rgSCHCmnUlUeFillAllocInfo(cell, ue);
13613       }
13614       else
13615       {
13616          gUl5gtfRbAllocFail++;
13617 #if defined (TENB_STATS) && defined (RG_5GTF)
13618          cell->tenbStats->sch.ul5gtfRbAllocFail++;
13619 #endif
13620          rgSCHCmnUlRbAllocAddUeToLst(cell, ue, nonSchdLst);
13621          ue->isMsg4PdcchWithCrnti = FALSE;
13622          ue->isSrGrant = FALSE;
13623       }
13624 #ifdef LTE_L2_MEAS
13625       if(isNewTx == TRUE)
13626       {
13627          cell->sfAllocArr[cell->crntSfIdx].ulUeInfo.
13628          ulAllocInfo[count - 1].rnti   = ue->ueId;
13629          cell->sfAllocArr[cell->crntSfIdx].ulUeInfo.
13630          ulAllocInfo[count - 1].numPrb = ue->ul.nPrb;
13631       }
13632 #endif
13633       ueUl->subbandShare = 0; /* This reset will take care of
13634                                   * all scheduler types */
13635    }
13636    for (; count; lnk = lnk->next, --count)
13637    {
13638       RgSchUeCb             *ue = (RgSchUeCb *)lnk->node;
13639       rgSCHCmnUlRbAllocAddUeToLst(cell, ue, nonSchdLst);
13640       ue->isMsg4PdcchWithCrnti = FALSE;
13641    }
13642    RETVOID;
13643 }
13644
13645 #ifdef UNUSED_FUNC
13646 #ifdef TFU_UPGRADE
13647 /***********************************************************
13648  *
13649  *     Func : rgSCHCmnUlMdfyGrntForCqi
13650  *
13651  *     Desc : Modify UL Grant to consider presence of 
13652  *            CQI along with PUSCH Data.
13653  *
13654  *     Ret  :
13655  *
13656  *     Notes: 
13657  *          -  Scale down iTbs based on betaOffset and
13658  *             size of Acqi Size.
13659  *          -  Optionally attempt to increase numSb by 1
13660  *             if input payload size does not fit in due 
13661  *             to reduced tbSz as a result of iTbsNew.
13662  *
13663  *     File :
13664  *
13665  **********************************************************/
13666 #ifdef ANSI
13667 PRIVATE S16 rgSCHCmnUlMdfyGrntForCqi
13668 (
13669 RgSchCellCb  *cell,
13670 RgSchUeCb    *ue,
13671 U32          maxRb,
13672 U32          *numSb,
13673 U8           *iTbs,
13674 U32          hqSz,
13675 U32          stepDownItbs,
13676 U32          effTgt
13677 )
13678 #else
13679 PRIVATE S16 rgSCHCmnUlMdfyGrntForCqi(cell, ue, maxRb, numSb, iTbs, hqSz, stepDownItbs, effTgt)
13680 RgSchCellCb  *cell;
13681 RgSchUeCb    *ue;
13682 U32          maxRb;
13683 U32          *numSb;
13684 U8           *iTbs;
13685 U32          hqSz;
13686 U32          stepDownItbs;
13687 U32          effTgt;
13688 #endif
13689 {
13690    RgSchCmnUlCell *cellUl = RG_SCH_CMN_GET_UL_CELL(ue->cell);
13691    U32  nPrb;
13692    U32  totREs;
13693    U32  cqiRiREs;
13694    U32  hqREs;
13695    U32  remREsForPusch;
13696    U32  bitsPerRe;
13697    U32  tbSz;
13698    U32  betaOffVal = ue->ul.betaOffstVal;
13699    U32  cqiRiRptSz = ue->ul.cqiRiSz;
13700    U32  betaOffHqVal = rgSchCmnBetaHqOffstTbl[ue->ul.betaHqOffst];
13701    U32  resNumSb = *numSb;
13702    U32  puschEff = 1000;
13703    U8   modOdr;
13704    U8   iMcs;
13705    Bool mdfyiTbsFlg = FALSE;
13706    U8   resiTbs = *iTbs;
13707
13708
13709    
13710    do
13711    {
13712       iMcs  = rgSCHCmnUlGetIMcsFrmITbs(resiTbs, RG_SCH_CMN_GET_UE_CTGY(ue));
13713       RG_SCH_UL_MCS_TO_MODODR(iMcs, modOdr);
13714       if (RG_SCH_CMN_GET_UE_CTGY(ue) != CM_LTE_UE_CAT_5)
13715       {
13716          modOdr = RGSCH_MIN(RGSCH_QM_QPSK, modOdr);
13717       }
13718       else
13719       {
13720          modOdr = RGSCH_MIN(RGSCH_QM_64QAM, modOdr);
13721       }
13722       nPrb = resNumSb * cellUl->sbSize;
13723       /* Restricting the minumum iTbs requried to modify to 10 */
13724       if ((nPrb >= maxRb) && (resiTbs <= 10))
13725       {
13726          /* Could not accomodate ACQI */
13727          return RFAILED;
13728       }
13729       totREs = nPrb * RG_SCH_CMN_UL_NUM_RE_PER_RB(cellUl);
13730       tbSz = rgTbSzTbl[0][resiTbs][nPrb-1];
13731       /*  totalREs/tbSz = num of bits perRE.  */
13732       cqiRiREs = (totREs * betaOffVal * cqiRiRptSz)/(1000 * tbSz); /* betaOffVal is represented 
13733                                                                    as parts per 1000 */
13734       hqREs = (totREs * betaOffHqVal * hqSz)/(1000 * tbSz);
13735       if ((cqiRiREs + hqREs) < totREs)
13736       {
13737          remREsForPusch = totREs - cqiRiREs - hqREs;
13738          bitsPerRe = (tbSz * 1000)/remREsForPusch; /* Multiplying by 1000 for Interger Oper */
13739          puschEff = bitsPerRe/modOdr;
13740       }
13741       if (puschEff < effTgt)
13742       {
13743           /* ensure resultant efficiency for PUSCH Data is within 0.93*/
13744           break;
13745       }
13746       else
13747       {
13748          /* Alternate between increasing SB or decreasing iTbs until eff is met */
13749          if (mdfyiTbsFlg == FALSE)
13750          {
13751             if (nPrb < maxRb)
13752             {
13753               resNumSb = resNumSb + 1;
13754             }
13755             mdfyiTbsFlg = TRUE;
13756          }
13757          else
13758          {
13759             if (resiTbs > 10)
13760             {
13761                resiTbs-= stepDownItbs;
13762             }
13763             mdfyiTbsFlg = FALSE;
13764          }
13765       }
13766    }while (1); /* Loop breaks if efficency is met 
13767                   or returns RFAILED if not able to meet the efficiency */
13768               
13769    *numSb = resNumSb;
13770    *iTbs = resiTbs;
13771
13772    return ROK;
13773 }
13774 #endif
13775 #endif
13776 /***********************************************************
13777  *
13778  *     Func : rgSCHCmnUlRbAllocForUe
13779  *
13780  *     Desc : Do uplink RB allocation for an UE.
13781  *
13782  *     Ret  :
13783  *
13784  *     Notes: Note that as of now, for retx, maxRb
13785  *            is not considered. Alternatives, such
13786  *            as dropping retx if it crosses maxRb
13787  *            could be considered.
13788  *
13789  *     File :
13790  *
13791  **********************************************************/
13792 #ifdef ANSI
13793 PRIVATE S16 rgSCHCmnUlRbAllocForUe
13794 (
13795 RgSchCellCb           *cell,
13796 RgSchUlSf             *sf,
13797 RgSchUeCb             *ue,
13798 U8                    maxRb,
13799 RgSchUlHole           *hole
13800 )
13801 #else
13802 PRIVATE S16 rgSCHCmnUlRbAllocForUe(cell, sf, ue, maxRb, hole)
13803 RgSchCellCb           *cell;
13804 RgSchUlSf             *sf;
13805 RgSchUeCb             *ue;
13806 U8                    maxRb;
13807 RgSchUlHole           *hole;
13808 #endif
13809 {
13810    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
13811    RgSchCmnUlUe    *ueUl    = RG_SCH_CMN_GET_UL_UE(ue, cell);
13812    RgSchUlAlloc     *alloc = NULLP;
13813    U32              nPrb = 0;
13814    U8               numVrbg;
13815    U8               iMcs;
13816    U8               iMcsCrnt;
13817 #ifndef RG_5GTF
13818    RgSchUlHqProcCb  *proc = &ueUl->hqEnt.hqProcCb[cellUl->schdHqProcIdx];
13819 #else
13820    RgSchUlHqProcCb  *proc = NULLP;
13821 #endif
13822    RgSchPdcch       *pdcch;
13823    U32              reqVrbg;
13824    U8               numVrbgTemp;
13825 #ifdef RG_5GTF
13826    TfuDciFormat     dciFrmt;
13827    U8               numLyr;
13828 #endif
13829
13830 #ifdef RG_5GTF
13831    rgSCHUhmGetAvlHqProc(cell, ue, &proc);
13832    if (proc == NULLP)
13833    {
13834       //printf("UE [%d] HQ Proc unavailable\n", ue->ueId);
13835       return RFAILED;
13836    }
13837 #endif
13838
13839    if (ue->ue5gtfCb.rank == 2)
13840    {
13841       dciFrmt = TFU_DCI_FORMAT_A2;
13842       numLyr = 2;
13843    }
13844    else
13845    {
13846       dciFrmt = TFU_DCI_FORMAT_A1;
13847       numLyr = 1;
13848    }
13849    /* 5gtf TODO : To pass dci frmt to this function */
13850    pdcch = rgSCHCmnPdcchAllocCrntSf(cell, ue);
13851    if(pdcch == NULLP)
13852    {
13853       RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId, 
13854          "rgSCHCmnUlRbAllocForUe(): Could not get PDCCH for CRNTI:%d",ue->ueId);
13855       return RFAILED;
13856    }
13857         gUl5gtfPdcchSchd++;
13858 #if defined (TENB_STATS) && defined (RG_5GTF)
13859    cell->tenbStats->sch.ul5gtfPdcchSchd++;
13860 #endif
13861
13862    //TODO_SID using configured prb as of now
13863    nPrb = ue->ue5gtfCb.maxPrb;
13864    reqVrbg = nPrb/MAX_5GTF_VRBG_SIZE;
13865    iMcs  = ue->ue5gtfCb.mcs; //gSCHCmnUlGetIMcsFrmITbs(iTbs,ueCtg);
13866    iMcsCrnt = iMcs;
13867    numVrbg = reqVrbg;
13868
13869    if((sf->sfBeamInfo[ue->ue5gtfCb.BeamId].vrbgStart > MAX_5GTF_VRBG)
13870          || (sf->sfBeamInfo[ue->ue5gtfCb.BeamId].totVrbgAllocated > MAX_5GTF_VRBG))
13871    {
13872       printf("5GTF_ERROR vrbg > 25 valstart = %d valalloc %d\n", sf->sfBeamInfo[ue->ue5gtfCb.BeamId].vrbgStart
13873             , sf->sfBeamInfo[ue->ue5gtfCb.BeamId].totVrbgAllocated);
13874       int *p=NULLP;
13875       *p = 10;
13876    }
13877
13878    /*TODO_SID: Workaround for alloc. Currently alloc is ulsf based. To handle multiple beams, we need a different
13879      design. Now alloc are formed based on MAX_5GTF_UE_SCH macro. */
13880    numVrbgTemp = MAX_5GTF_VRBG/MAX_5GTF_UE_SCH;
13881    if(numVrbg)
13882    {
13883       alloc = rgSCHCmnUlSbAlloc(sf, numVrbgTemp,\
13884                                 hole);
13885    }
13886    if (alloc == NULLP)
13887    {
13888       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId, 
13889          "rgSCHCmnUlRbAllocForUe(): Could not get UlAlloc %d CRNTI:%d",numVrbg,ue->ueId);
13890       rgSCHCmnPdcchRlsCrntSf(cell, pdcch);
13891       return RFAILED;
13892    }
13893    gUl5gtfAllocAllocated++;
13894 #if defined (TENB_STATS) && defined (RG_5GTF)
13895    cell->tenbStats->sch.ul5gtfAllocAllocated++;
13896 #endif
13897    alloc->grnt.vrbgStart = sf->sfBeamInfo[ue->ue5gtfCb.BeamId].vrbgStart;
13898    alloc->grnt.numVrbg = numVrbg;
13899    alloc->grnt.numLyr = numLyr;
13900    alloc->grnt.dciFrmt = dciFrmt;
13901
13902    sf->sfBeamInfo[ue->ue5gtfCb.BeamId].vrbgStart += numVrbg;
13903    sf->sfBeamInfo[ue->ue5gtfCb.BeamId].totVrbgAllocated += numVrbg;
13904
13905    //rgSCHCmnUlAllocFillRbInfo(cell, sf, alloc);
13906 #ifdef LTE_L2_MEAS
13907    sf->totPrb  += alloc->grnt.numRb;
13908    ue->ul.nPrb = alloc->grnt.numRb;
13909 #endif
13910    if (ue->csgMmbrSta != TRUE)
13911    {
13912       cellUl->ncsgPrbCnt += alloc->grnt.numRb;
13913    }
13914    cellUl->totPrbCnt += (alloc->grnt.numVrbg * MAX_5GTF_VRBG_SIZE);
13915    alloc->pdcch = pdcch;
13916    alloc->grnt.iMcs = iMcs;
13917    alloc->grnt.iMcsCrnt = iMcsCrnt;
13918    alloc->grnt.hop = 0;
13919    /* Initial Num RBs support for UCI on PUSCH */
13920 #ifdef TFU_UPGRADE
13921    ue->initNumRbs = (alloc->grnt.numVrbg * MAX_5GTF_VRBG_SIZE);
13922 #endif
13923    alloc->forMsg3 = FALSE;
13924    //RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgTb5gtfSzTbl[0], (iTbs)); 
13925
13926    //ueUl->alloc.allocdBytes = rgTbSzTbl[0][iTbs][alloc->grnt.numRb-1] / 8;
13927    /* TODO_SID Allocating based on configured MCS as of now.
13928          Currently for format A2. When doing multi grp per tti, need to update this. */
13929    ueUl->alloc.allocdBytes = (rgSch5gtfTbSzTbl[iMcs]/8) * ue->ue5gtfCb.rank;
13930
13931    alloc->grnt.datSz = ueUl->alloc.allocdBytes;
13932    //TODO_SID Need to check mod order.
13933    RG_SCH_CMN_TBS_TO_MODODR(iMcs, alloc->grnt.modOdr);
13934         //alloc->grnt.modOdr = 6;
13935    alloc->grnt.isRtx = FALSE;
13936
13937    alloc->grnt.rbAssign = rgSCHCmnCalcRiv(MAX_5GTF_VRBG, alloc->grnt.vrbgStart, alloc->grnt.numVrbg);
13938    alloc->grnt.SCID = 0;
13939    alloc->grnt.xPUSCHRange = MAX_5GTF_XPUSCH_RANGE;
13940    alloc->grnt.PMI = 0;
13941    alloc->grnt.uciOnxPUSCH = 0;
13942    alloc->grnt.hqProcId = proc->procId;
13943
13944    alloc->hqProc = proc;
13945    alloc->hqProc->ulSfIdx = cellUl->schdIdx;
13946    alloc->ue = ue;
13947    /*commenting to retain the rnti used for transmission SPS/c-rnti */
13948    alloc->rnti = ue->ueId;
13949    ueUl->alloc.alloc = alloc;
13950    /*rntiwari-Adding the debug for generating the graph.*/
13951    /* No grant attr recorded now */
13952    return ROK;
13953 }
13954
13955 /***********************************************************
13956  *
13957  *     Func : rgSCHCmnUlRbAllocAddUeToLst
13958  *
13959  *     Desc : Add UE to list (scheduled/non-scheduled list)
13960  *            for UL RB allocation information.
13961  *
13962  *     Ret  :
13963  *
13964  *     Notes:
13965  *
13966  *     File :
13967  *
13968  **********************************************************/
13969 #ifdef ANSI
13970 Void rgSCHCmnUlRbAllocAddUeToLst
13971 (
13972 RgSchCellCb           *cell,
13973 RgSchUeCb             *ue,
13974 CmLListCp             *lst
13975 )
13976 #else
13977 Void rgSCHCmnUlRbAllocAddUeToLst(cell, ue, lst)
13978 RgSchCellCb           *cell;
13979 RgSchUeCb             *ue;
13980 CmLListCp             *lst;
13981 #endif
13982 {
13983    RgSchCmnUlUe   *ueUl   = RG_SCH_CMN_GET_UL_UE(ue,cell);
13984    UNUSED(cell);
13985
13986    gUl5gtfUeRbAllocDone++;
13987 #if defined (TENB_STATS) && defined (RG_5GTF)
13988    cell->tenbStats->sch.ul5gtfUeRbAllocDone++;
13989 #endif
13990    cmLListAdd2Tail(lst, &ueUl->alloc.schdLstLnk);
13991    ueUl->alloc.schdLstLnk.node = (PTR)ue;
13992 }
13993
13994
13995 /**
13996  * @brief This function Processes the Final Allocations
13997  *        made by the RB Allocator against the requested.
13998  *
13999  * @details
14000  *
14001  *     Function: rgSCHCmnUlAllocFnlz
14002  *     Purpose:  This function Processes the Final Allocations
14003  *               made by the RB Allocator against the requested.
14004  *
14005  *     Invoked by: Common Scheduler
14006  *
14007  *  @param[in]  RgSchCellCb           *cell
14008  *  @param[in]  RgSchCmnUlRbAllocInfo *allocInfo
14009  *  @return  Void
14010  *
14011  **/
14012 #ifdef ANSI
14013 PRIVATE Void rgSCHCmnUlAllocFnlz
14014 (
14015 RgSchCellCb           *cell,
14016 RgSchCmnUlRbAllocInfo *allocInfo
14017 )
14018 #else
14019 PRIVATE Void rgSCHCmnUlAllocFnlz(cell, allocInfo)
14020 RgSchCellCb           *cell;
14021 RgSchCmnUlRbAllocInfo *allocInfo;
14022 #endif
14023 {
14024    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
14025
14026    /* call scheduler specific Finalization */
14027    cellSch->apisUl->rgSCHUlAllocFnlz(cell, allocInfo);
14028
14029    RETVOID;
14030 }
14031
14032 /**
14033  * @brief This function Processes the Final Allocations
14034  *        made by the RB Allocator against the requested.
14035  *
14036  * @details
14037  *
14038  *     Function: rgSCHCmnDlAllocFnlz
14039  *     Purpose:  This function Processes the Final Allocations
14040  *               made by the RB Allocator against the requested.
14041  *
14042  *     Invoked by: Common Scheduler
14043  *
14044  *  @param[in]  RgSchCellCb           *cell
14045  *  @return  Void
14046  *
14047  **/
14048 #ifdef ANSI
14049 Void rgSCHCmnDlAllocFnlz
14050 (
14051 RgSchCellCb           *cell
14052 )
14053 #else
14054 Void rgSCHCmnDlAllocFnlz(cell)
14055 RgSchCellCb           *cell;
14056 #endif
14057 {
14058    RgSchCmnCell           *cellSch = RG_SCH_CMN_GET_CELL(cell);
14059    RgSchCmnDlRbAllocInfo  *allocInfo = &cellSch->allocInfo; 
14060
14061
14062    rgSCHCmnDlCcchRetxFnlz(cell, allocInfo);
14063    rgSCHCmnDlCcchTxFnlz(cell, allocInfo);
14064 #ifdef RGR_V1
14065    /* Added below functions for handling CCCH SDU transmission received
14066     * after
14067     *     * guard timer expiry*/
14068    rgSCHCmnDlCcchSduRetxFnlz(cell, allocInfo);
14069    rgSCHCmnDlCcchSduTxFnlz(cell, allocInfo);
14070 #endif
14071    rgSCHCmnDlRaRspFnlz(cell, allocInfo);
14072       /* call scheduler specific Finalization */
14073    cellSch->apisDl->rgSCHDlAllocFnlz(cell, allocInfo);
14074
14075    /* Stack Crash problem for TRACE5 Changes. Added the return below */
14076    RETVOID;
14077
14078 }
14079
14080 #ifdef RG_UNUSED
14081 /**
14082  * @brief Update an uplink subframe.
14083  *
14084  * @details
14085  *
14086  *     Function : rgSCHCmnUlUpdSf
14087  *
14088  *     For each allocation
14089  *      - if no more tx needed
14090  *         - Release allocation
14091  *      - else
14092  *         - Perform retransmission
14093  *
14094  *  @param[in]  RgSchUlSf *sf
14095  *  @return  Void
14096  **/
14097 #ifdef ANSI
14098 PRIVATE Void rgSCHCmnUlUpdSf
14099 (
14100 RgSchCellCb           *cell,
14101 RgSchCmnUlRbAllocInfo *allocInfo,
14102 RgSchUlSf *sf
14103 )
14104 #else
14105 PRIVATE Void rgSCHCmnUlUpdSf(cell, allocInfo, sf)
14106 RgSchCellCb           *cell;
14107 RgSchCmnUlRbAllocInfo *allocInfo;
14108 RgSchUlSf *sf;
14109 #endif
14110 {
14111    CmLList        *lnk;
14112
14113    while ((lnk = sf->allocs.first))
14114    {
14115       RgSchUlAlloc  *alloc = (RgSchUlAlloc *)lnk->node;
14116       lnk = lnk->next;
14117
14118       if ((alloc->hqProc->rcvdCrcInd) || (alloc->hqProc->remTx == 0))
14119       {
14120       }
14121       else
14122       {
14123          /* If need to handle all retx together, run another loop separately */
14124          rgSCHCmnUlHndlAllocRetx(cell, allocInfo, sf, alloc);
14125       }
14126       rgSCHCmnUlRlsUlAlloc(cell, sf, alloc);
14127    }
14128
14129    /* By this time, all allocs would have been cleared and
14130     * SF is reset to be made ready for new allocations. */
14131    rgSCHCmnUlSfReset(cell, sf);
14132    /* In case there are timing problems due to msg3
14133     * allocations being done in advance, (which will
14134     * probably happen with the current FDD code that
14135     * handles 8 subframes) one solution
14136     * could be to hold the (recent) msg3 allocs in a separate
14137     * list, and then possibly add that to the actual
14138     * list later. So at this time while allocations are
14139     * traversed, the recent msg3 ones are not seen. Anytime after
14140     * this (a good time is when the usual allocations
14141     * are made), msg3 allocations could be transferred to the
14142     * normal list. Not doing this now as it is assumed
14143     * that incorporation of TDD shall take care of this.
14144     */
14145
14146
14147    RETVOID;
14148 }
14149
14150 /**
14151  * @brief Handle uplink allocation for retransmission.
14152  *
14153  * @details
14154  *
14155  *     Function : rgSCHCmnUlHndlAllocRetx
14156  *
14157  *     Processing Steps:
14158  *     - Add to queue for retx.
14159  *     - Do not release here, release happends as part
14160  *       of the loop that calls this function.
14161  *
14162  *  @param[in]  RgSchCellCb           *cell
14163  *  @param[in]  RgSchCmnUlRbAllocInfo *allocInfo
14164  *  @param[in]  RgSchUlSf *sf
14165  *  @param[in]  RgSchUlAlloc  *alloc
14166  *  @return  Void
14167  **/
14168 #ifdef ANSI
14169 PRIVATE Void rgSCHCmnUlHndlAllocRetx
14170 (
14171 RgSchCellCb           *cell,
14172 RgSchCmnUlRbAllocInfo *allocInfo,
14173 RgSchUlSf     *sf,
14174 RgSchUlAlloc  *alloc
14175 )
14176 #else
14177 PRIVATE Void rgSCHCmnUlHndlAllocRetx(cell, allocInfo, sf, alloc)
14178 RgSchCellCb           *cell;
14179 RgSchCmnUlRbAllocInfo *allocInfo;
14180 RgSchUlSf     *sf;
14181 RgSchUlAlloc  *alloc;
14182 #endif
14183 {
14184    U32            bytes;
14185    RgSchCmnUlUe   *ueUl;
14186    bytes = \
14187       rgTbSzTbl[0][rgSCHCmnUlGetITbsFrmIMcs(alloc->grnt.iMcs)]\
14188                                      [alloc->grnt.numRb-1]/8;
14189    if (!alloc->forMsg3)
14190    {
14191       ueUl = RG_SCH_CMN_GET_UL_UE(alloc->ue);
14192       ueUl->alloc.reqBytes = bytes;
14193       rgSCHUhmRetx(alloc->hqProc);
14194       rgSCHCmnUlAdd2RetxUeLst(allocInfo, alloc->ue);
14195    }
14196    else
14197    {
14198       /* RACHO msg3 retx handling. Part of RACH procedure changes. */
14199       retxAlloc = rgSCHCmnUlGetUlAlloc(cell, sf, alloc->numSb);
14200       if (retxAlloc == NULLP)
14201       {
14202          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
14203                "rgSCHCmnUlRbAllocForUe():Could not get UlAlloc for msg3Retx RNTI:%d",
14204                alloc->rnti);
14205          RETVOID;
14206       }
14207       retxAlloc->grnt.iMcs = alloc->grnt.iMcs;
14208       retxAlloc->grnt.iMcsCrnt = rgSchCmnUlRvIdxToIMcsTbl\
14209                                  [alloc->hqProc->rvIdx];
14210       retxAlloc->grnt.nDmrs    = 0;
14211       retxAlloc->grnt.hop      = 0;
14212       retxAlloc->grnt.delayBit = 0;
14213       retxAlloc->rnti          = alloc->rnti;
14214       retxAlloc->ue            = NULLP;
14215       retxAlloc->pdcch         = FALSE;
14216       retxAlloc->forMsg3       = TRUE;
14217       retxAlloc->raCb          = alloc->raCb;
14218       retxAlloc->hqProc        = alloc->hqProc;
14219       rgSCHUhmRetx(retxAlloc->hqProc);
14220    }
14221    RETVOID;
14222 }
14223 #endif
14224
14225 /**
14226  * @brief Uplink Scheduling Handler.
14227  *
14228  * @details
14229  *
14230  *     Function: rgSCHCmnUlAlloc
14231  *     Purpose:  This function Handles Uplink Scheduling.
14232  *
14233  *     Invoked by: Common Scheduler
14234  *
14235  *  @param[in]  RgSchCellCb *cell
14236  *  @return  Void
14237  **/
14238 /* ccpu00132653- The definition of this function made common for TDD and FDD*/
14239 #ifdef ANSI
14240 PRIVATE Void rgSCHCmnUlAlloc
14241 (
14242 RgSchCellCb  *cell
14243 )
14244 #else
14245 PRIVATE Void rgSCHCmnUlAlloc(cell)
14246 RgSchCellCb  *cell;
14247 #endif
14248 {
14249    RgSchCmnCell           *cellSch = RG_SCH_CMN_GET_CELL(cell);
14250    RgSchCmnUlCell         *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
14251    RgSchCmnDlCell         *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
14252    RgSchCmnUlRbAllocInfo  allocInfo;
14253    RgSchCmnUlRbAllocInfo  *allocInfoRef = &allocInfo;
14254 #ifdef RG_5GTF
14255    U8 idx;
14256
14257 #endif
14258
14259
14260    /* Initializing RgSchCmnUlRbAllocInfo structure */
14261    rgSCHCmnInitUlRbAllocInfo(allocInfoRef);
14262
14263    /* Get Uplink Subframe */
14264    allocInfoRef->sf = &cellUl->ulSfArr[cellUl->schdIdx];
14265 #ifdef LTE_L2_MEAS
14266    /* initializing the UL PRB count */
14267    allocInfoRef->sf->totPrb = 0;
14268 #endif
14269
14270 #ifdef LTEMAC_SPS
14271    rgSCHCmnSpsUlTti(cell, allocInfoRef);
14272 #endif
14273
14274    if(*allocInfoRef->sf->allocCountRef == 0)
14275    {            
14276       RgSchUlHole     *hole;
14277
14278       if ((hole = rgSCHUtlUlHoleFirst(allocInfoRef->sf)) != NULLP)
14279       {
14280          /* Sanity check of holeDb */
14281          if (allocInfoRef->sf->holeDb->count == 1 && hole->start == 0) 
14282          {
14283             hole->num = cell->dynCfiCb.bwInfo[cellDl->currCfi].numSb;   
14284             /* Re-Initialize available subbands because of CFI change*/
14285             allocInfoRef->sf->availSubbands = cell->dynCfiCb.\
14286                                               bwInfo[cellDl->currCfi].numSb;
14287             /*Currently initializing 5gtf ulsf specific initialization here.
14288               need to do at proper place */
14289 #ifdef RG_5GTF
14290        allocInfoRef->sf->numGrpPerTti = cell->cell5gtfCb.ueGrpPerTti;
14291        allocInfoRef->sf->numUePerGrp = cell->cell5gtfCb.uePerGrpPerTti;
14292             for(idx = 0; idx < MAX_5GTF_BEAMS; idx++)
14293             {
14294                allocInfoRef->sf->sfBeamInfo[idx].totVrbgAllocated = 0;
14295                allocInfoRef->sf->sfBeamInfo[idx].totVrbgRequired = 0;
14296                allocInfoRef->sf->sfBeamInfo[idx].vrbgStart = 0;
14297             }    
14298 #endif
14299          }
14300          else
14301          {
14302             RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
14303                   "Error! holeDb sanity check failed");
14304          }
14305       }
14306    }
14307
14308    /* Fix: Adaptive re-transmissions prioritised over other transmissions */
14309    /* perform adaptive retransmissions */
14310    rgSCHCmnUlSfReTxAllocs(cell, allocInfoRef->sf);
14311
14312         g5gtfTtiCnt++;
14313
14314    /* Fix: syed Adaptive Msg3 Retx crash. Release all
14315     Harq processes for which adap Retx failed, to avoid 
14316     blocking. This step should be done before New TX 
14317     scheduling to make hqProc available. Right now we
14318     dont check if proc is in adap Retx list for considering
14319     it to be available. But now with this release that 
14320     functionality would be correct. */
14321 #ifndef RG_5GTF
14322    rgSCHCmnUlSfRlsRetxProcs(cell, allocInfoRef->sf);  
14323 #endif
14324
14325    /* Specific UL scheduler to perform UE scheduling */
14326    cellSch->apisUl->rgSCHUlSched(cell, allocInfoRef);
14327
14328    /* Call UL RB allocator module */
14329    rgSCHCmnAllocUlRb(cell, allocInfoRef);
14330
14331    /* Do group power control for PUSCH */
14332    rgSCHCmnGrpPwrCntrlPusch(cell, allocInfoRef->sf);
14333
14334    cell->sc.apis->rgSCHDrxStrtInActvTmrInUl(cell);
14335
14336    rgSCHCmnUlAllocFnlz(cell, allocInfoRef);
14337         if(5000 == g5gtfTtiCnt)
14338         {
14339       ul5gtfsidDlAlreadyMarkUl = 0;
14340                 ul5gtfsidDlSchdPass = 0;
14341                 ul5gtfsidUlMarkUl = 0;
14342       ul5gtfTotSchdCnt = 0;
14343                 g5gtfTtiCnt = 0;
14344         }
14345
14346    RETVOID;
14347 }
14348
14349 /**
14350  * @brief send Subframe Allocations.
14351  *
14352  * @details
14353  *
14354  *     Function: rgSCHCmnSndCnsldtInfo
14355  *     Purpose:  Send the scheduled
14356  *     allocations to MAC for StaInd generation to Higher layers and
14357  *     for MUXing. PST's RgInfSfAlloc to MAC instance.
14358  *
14359  *     Invoked by: Common Scheduler
14360  *
14361  *  @param[in]  RgSchCellCb *cell
14362  *  @return  Void
14363  **/
14364 #ifdef ANSI
14365 Void rgSCHCmnSndCnsldtInfo
14366 (
14367 RgSchCellCb  *cell
14368 )
14369 #else
14370 Void rgSCHCmnSndCnsldtInfo(cell)
14371 RgSchCellCb  *cell;
14372 #endif
14373 {
14374    RgInfSfAlloc           *subfrmAlloc;
14375    Pst                    pst;
14376    RgSchCmnCell           *cellSch = RG_SCH_CMN_GET_CELL(cell);
14377
14378
14379    subfrmAlloc = &(cell->sfAllocArr[cell->crntSfIdx]);
14380
14381    /* Send the allocations to MAC for MUXing */
14382    rgSCHUtlGetPstToLyr(&pst, &rgSchCb[cell->instIdx], cell->macInst);
14383    subfrmAlloc->cellId = cell->cellId;
14384    /* Populate the List of UEs needing PDB-based Flow control */
14385    cellSch->apisDl->rgSCHDlFillFlwCtrlInfo(cell, subfrmAlloc);
14386 #ifdef LTE_L2_MEAS
14387    if((subfrmAlloc->rarInfo.numRaRntis) ||
14388 #ifdef EMTC_ENABLE
14389       (subfrmAlloc->emtcInfo.rarInfo.numRaRntis) ||
14390       (subfrmAlloc->emtcInfo.cmnLcInfo.bitMask)  ||
14391       (subfrmAlloc->emtcInfo.ueInfo.numUes) ||
14392 #endif
14393       (subfrmAlloc->ueInfo.numUes)      ||
14394       (subfrmAlloc->cmnLcInfo.bitMask)  ||
14395          (subfrmAlloc->ulUeInfo.numUes)    ||
14396          (subfrmAlloc->flowCntrlInfo.numUes))
14397 #else
14398    if((subfrmAlloc->rarInfo.numRaRntis) ||
14399 #ifdef EMTC_ENABLE
14400       (subfrmAlloc->emtcInfo.rarInfo.numRaRntis) ||
14401       (subfrmAlloc->emtcInfo.cmnLcInfo.bitMask)  ||
14402       (subfrmAlloc->emtcInfo.ueInfo.numUes) ||
14403 #endif
14404       (subfrmAlloc->ueInfo.numUes)      ||
14405             (subfrmAlloc->cmnLcInfo.bitMask)  ||
14406             (subfrmAlloc->flowCntrlInfo.numUes))
14407 #endif
14408    {
14409       RgSchMacSfAlloc(&pst, subfrmAlloc);
14410    }
14411 #ifndef LTE_TDD
14412    cell->crntSfIdx  = (cell->crntSfIdx + 1) % RGSCH_NUM_SUB_FRAMES;
14413 #else
14414    cell->crntSfIdx  = (cell->crntSfIdx + 1) % RGSCH_SF_ALLOC_SIZE;
14415 #endif
14416    
14417    RETVOID;
14418 }
14419 /**
14420  * @brief Consolidate Subframe Allocations.
14421  *
14422  * @details
14423  *
14424  *     Function: rgSCHCmnCnsldtSfAlloc
14425  *     Purpose:  Consolidate Subframe Allocations.
14426  *
14427  *     Invoked by: Common Scheduler
14428  *
14429  *  @param[in]  RgSchCellCb *cell
14430  *  @return  Void
14431  **/
14432 #ifdef ANSI
14433 Void rgSCHCmnCnsldtSfAlloc
14434 (
14435 RgSchCellCb  *cell
14436 )
14437 #else
14438 Void rgSCHCmnCnsldtSfAlloc(cell)
14439 RgSchCellCb  *cell;
14440 #endif
14441 {
14442    RgInfSfAlloc           *subfrmAlloc;
14443    CmLteTimingInfo        frm;
14444    RgSchDlSf              *dlSf;
14445    CmLListCp              dlDrxInactvTmrLst;
14446    CmLListCp              dlInActvLst;
14447    CmLListCp              ulInActvLst;
14448    RgSchCmnCell           *cellSch = NULLP;
14449
14450
14451    cmLListInit(&dlDrxInactvTmrLst);
14452    cmLListInit(&dlInActvLst);
14453    cmLListInit(&ulInActvLst);
14454
14455    subfrmAlloc = &(cell->sfAllocArr[cell->crntSfIdx]);
14456
14457    /* Get Downlink Subframe */
14458    frm   = cell->crntTime;
14459    RGSCH_INCR_SUB_FRAME(frm, RG_SCH_CMN_DL_DELTA);
14460    dlSf = rgSCHUtlSubFrmGet(cell, frm);
14461
14462    /* Fill the allocation Info */
14463    rgSCHUtlFillRgInfRarInfo(dlSf, subfrmAlloc, cell);
14464
14465   /* CA dev Start */
14466    rgSCHUtlFillRgInfUeInfo(dlSf, cell, &dlDrxInactvTmrLst, 
14467                            &dlInActvLst, &ulInActvLst);
14468 #ifdef RG_PFS_STATS
14469    cell->totalPrb += dlSf->bwAssigned;
14470 #endif
14471    /* Mark the following Ues inactive for UL*/
14472    cellSch = RG_SCH_CMN_GET_CELL(cell);
14473
14474    /* Calling Scheduler specific function with DRX inactive UE list*/
14475    cellSch->apisUl->rgSCHUlInactvtUes(cell, &ulInActvLst);
14476    cellSch->apisDl->rgSCHDlInactvtUes(cell, &dlInActvLst);
14477     
14478   /* CA dev End */
14479    /*re/start DRX inactivity timer for the UEs*/
14480    (Void)rgSCHDrxStrtInActvTmr(cell,&dlDrxInactvTmrLst,RG_SCH_DRX_DL);
14481
14482    RETVOID;
14483 }
14484
14485 /**
14486  * @brief Initialize the DL Allocation Information Structure.
14487  *
14488  * @details
14489  *
14490  *     Function: rgSCHCmnInitDlRbAllocInfo
14491  *     Purpose:  Initialize the DL Allocation Information Structure.
14492  *
14493  *     Invoked by: Common Scheduler
14494  *
14495  *  @param[out]  RgSchCmnDlRbAllocInfo  *allocInfo
14496  *  @return  Void
14497  **/
14498 #ifdef ANSI
14499 PRIVATE Void rgSCHCmnInitDlRbAllocInfo
14500 (
14501 RgSchCmnDlRbAllocInfo  *allocInfo
14502 )
14503 #else
14504 PRIVATE Void rgSCHCmnInitDlRbAllocInfo(allocInfo)
14505 RgSchCmnDlRbAllocInfo  *allocInfo;
14506 #endif
14507 {
14508    memset(&allocInfo->pcchAlloc, 0, sizeof(RgSchDlRbAlloc));
14509    memset(&allocInfo->bcchAlloc, 0, sizeof(RgSchDlRbAlloc));
14510    memset(allocInfo->raRspAlloc, 0,
14511          RG_SCH_CMN_MAX_CMN_PDCCH*sizeof(RgSchDlRbAlloc));
14512
14513    allocInfo->msg4Alloc.msg4DlSf = NULLP;
14514    cmLListInit(&allocInfo->msg4Alloc.msg4TxLst);
14515    cmLListInit(&allocInfo->msg4Alloc.msg4RetxLst);
14516    cmLListInit(&allocInfo->msg4Alloc.schdMsg4TxLst);
14517    cmLListInit(&allocInfo->msg4Alloc.schdMsg4RetxLst);
14518    cmLListInit(&allocInfo->msg4Alloc.nonSchdMsg4TxLst);
14519    cmLListInit(&allocInfo->msg4Alloc.nonSchdMsg4RetxLst);
14520 #ifdef RGR_V1
14521    allocInfo->ccchSduAlloc.ccchSduDlSf = NULLP;
14522    cmLListInit(&allocInfo->ccchSduAlloc.ccchSduTxLst);
14523    cmLListInit(&allocInfo->ccchSduAlloc.ccchSduRetxLst);
14524    cmLListInit(&allocInfo->ccchSduAlloc.schdCcchSduTxLst);
14525    cmLListInit(&allocInfo->ccchSduAlloc.schdCcchSduRetxLst);
14526    cmLListInit(&allocInfo->ccchSduAlloc.nonSchdCcchSduTxLst);
14527    cmLListInit(&allocInfo->ccchSduAlloc.nonSchdCcchSduRetxLst);
14528 #endif
14529
14530    allocInfo->dedAlloc.dedDlSf = NULLP;
14531    cmLListInit(&allocInfo->dedAlloc.txHqPLst);
14532    cmLListInit(&allocInfo->dedAlloc.retxHqPLst);
14533    cmLListInit(&allocInfo->dedAlloc.schdTxHqPLst);
14534    cmLListInit(&allocInfo->dedAlloc.schdRetxHqPLst);
14535    cmLListInit(&allocInfo->dedAlloc.nonSchdTxHqPLst);
14536    cmLListInit(&allocInfo->dedAlloc.nonSchdRetxHqPLst);
14537
14538    cmLListInit(&allocInfo->dedAlloc.txRetxHqPLst);
14539    cmLListInit(&allocInfo->dedAlloc.schdTxRetxHqPLst);
14540    cmLListInit(&allocInfo->dedAlloc.nonSchdTxRetxHqPLst);
14541 #ifdef LTEMAC_SPS
14542    cmLListInit(&allocInfo->dedAlloc.txSpsHqPLst);
14543    cmLListInit(&allocInfo->dedAlloc.retxSpsHqPLst);
14544    cmLListInit(&allocInfo->dedAlloc.schdTxSpsHqPLst);
14545    cmLListInit(&allocInfo->dedAlloc.schdRetxSpsHqPLst);
14546    cmLListInit(&allocInfo->dedAlloc.nonSchdTxSpsHqPLst);
14547    cmLListInit(&allocInfo->dedAlloc.nonSchdRetxSpsHqPLst);
14548 #endif
14549
14550 #ifdef LTE_ADV
14551    rgSCHLaaCmnInitDlRbAllocInfo (allocInfo);
14552 #endif
14553
14554    cmLListInit(&allocInfo->dedAlloc.errIndTxHqPLst);
14555    cmLListInit(&allocInfo->dedAlloc.schdErrIndTxHqPLst);
14556    cmLListInit(&allocInfo->dedAlloc.nonSchdErrIndTxHqPLst);
14557    RETVOID;
14558 }
14559
14560 /**
14561  * @brief Initialize the UL Allocation Information Structure.
14562  *
14563  * @details
14564  *
14565  *     Function: rgSCHCmnInitUlRbAllocInfo
14566  *     Purpose:  Initialize the UL Allocation Information Structure.
14567  *
14568  *     Invoked by: Common Scheduler
14569  *
14570  *  @param[out]  RgSchCmnUlRbAllocInfo  *allocInfo
14571  *  @return  Void
14572  **/
14573 #ifdef ANSI
14574 Void rgSCHCmnInitUlRbAllocInfo
14575 (
14576 RgSchCmnUlRbAllocInfo  *allocInfo
14577 )
14578 #else
14579 Void rgSCHCmnInitUlRbAllocInfo(allocInfo)
14580 RgSchCmnUlRbAllocInfo  *allocInfo;
14581 #endif
14582 {
14583    allocInfo->sf = NULLP;
14584    cmLListInit(&allocInfo->contResLst);
14585    cmLListInit(&allocInfo->schdContResLst);
14586    cmLListInit(&allocInfo->nonSchdContResLst);
14587    cmLListInit(&allocInfo->ueLst);
14588    cmLListInit(&allocInfo->schdUeLst);
14589    cmLListInit(&allocInfo->nonSchdUeLst);
14590
14591    RETVOID;
14592 }
14593
14594 /**
14595  * @brief Scheduling for PUCCH group power control.
14596  *
14597  * @details
14598  *
14599  *     Function: rgSCHCmnGrpPwrCntrlPucch
14600  *     Purpose: This function does group power control for PUCCH
14601  *     corresponding to the subframe for which DL UE allocations
14602  *     have happended.
14603  *
14604  *     Invoked by: Common Scheduler
14605  *
14606  *  @param[in]  RgSchCellCb *cell
14607  *  @return  Void
14608  **/
14609 #ifdef ANSI
14610 PRIVATE Void rgSCHCmnGrpPwrCntrlPucch
14611 (
14612 RgSchCellCb            *cell,
14613 RgSchDlSf              *dlSf
14614 )
14615 #else
14616 PRIVATE Void rgSCHCmnGrpPwrCntrlPucch(cell, dlSf)
14617 RgSchCellCb            *cell;
14618 RgSchDlSf              *dlSf;
14619 #endif
14620 {
14621
14622    rgSCHPwrGrpCntrlPucch(cell, dlSf);
14623
14624    RETVOID;
14625 }
14626
14627 /**
14628  * @brief Scheduling for PUSCH group power control.
14629  *
14630  * @details
14631  *
14632  *     Function: rgSCHCmnGrpPwrCntrlPusch
14633  *     Purpose: This function does group power control, for
14634  *     the subframe for which UL allocation has (just) happened.
14635  *
14636  *     Invoked by: Common Scheduler
14637  *
14638  *  @param[in]  RgSchCellCb *cell
14639  *  @param[in]  RgSchUlSf   *ulSf
14640  *  @return  Void
14641  **/
14642 #ifdef ANSI
14643 PRIVATE Void rgSCHCmnGrpPwrCntrlPusch
14644 (
14645 RgSchCellCb            *cell,
14646 RgSchUlSf              *ulSf
14647 )
14648 #else
14649 PRIVATE Void rgSCHCmnGrpPwrCntrlPusch(cell, ulSf)
14650 RgSchCellCb            *cell;
14651 RgSchUlSf              *ulSf;
14652 #endif
14653 {
14654    /*removed unused variable *cellSch*/
14655    CmLteTimingInfo        frm;
14656    RgSchDlSf              *dlSf;
14657
14658
14659    /* Got to pass DL SF corresponding to UL SF, so get that first.
14660     * There is no easy way of getting dlSf by having the RgSchUlSf*,
14661     * so use the UL delta from current time to get the DL SF. */
14662    frm   = cell->crntTime;
14663
14664 #ifdef EMTC_ENABLE
14665    if(cell->emtcEnable == TRUE)
14666    {
14667       RGSCH_INCR_SUB_FRAME_EMTC(frm, TFU_DLCNTRL_DLDELTA);
14668    }
14669    else
14670 #endif
14671    {
14672       RGSCH_INCR_SUB_FRAME(frm, TFU_DLCNTRL_DLDELTA);
14673    }
14674    /* Del filling of dl.time */
14675    dlSf = rgSCHUtlSubFrmGet(cell, frm);
14676
14677    rgSCHPwrGrpCntrlPusch(cell, dlSf, ulSf);
14678
14679    RETVOID;
14680 }
14681
14682 /* Fix: syed align multiple UEs to refresh at same time */
14683 /***********************************************************
14684  *
14685  *     Func : rgSCHCmnApplyUeRefresh 
14686  *
14687  *     Desc : Apply UE refresh in CMN and Specific 
14688  *     schedulers. Data rates and corresponding 
14689  *     scratchpad variables are updated.
14690  *
14691  *     Ret  :
14692  *
14693  *     Notes:
14694  *
14695  *     File :
14696  *
14697  **********************************************************/
14698 #ifdef ANSI
14699 PRIVATE S16 rgSCHCmnApplyUeRefresh 
14700 (
14701 RgSchCellCb     *cell,
14702 RgSchUeCb       *ue
14703 )
14704 #else
14705 PRIVATE S16 rgSCHCmnApplyUeRefresh(cell, ue)
14706 RgSchCellCb     *cell;
14707 RgSchUeCb       *ue;
14708 #endif
14709 {
14710    RgSchCmnCell    *cellSch     = RG_SCH_CMN_GET_CELL(cell);
14711    U32             effGbrBsr    = 0;
14712    U32             effNonGbrBsr = 0;
14713    U32             lcgId;
14714
14715
14716    /* Reset the refresh cycle variableCAP */
14717    ue->ul.effAmbr = ue->ul.cfgdAmbr;
14718
14719    for (lcgId = 1; lcgId < RGSCH_MAX_LCG_PER_UE; lcgId++)
14720    {
14721       if (RGSCH_LCG_ISCFGD(&ue->ul.lcgArr[lcgId]))
14722       {
14723          RgSchCmnLcg *cmnLcg = ((RgSchCmnLcg *)(ue->ul.lcgArr[lcgId].sch));
14724
14725          if (RGSCH_IS_GBR_BEARER(cmnLcg->cfgdGbr))
14726          {
14727             cmnLcg->effGbr = cmnLcg->cfgdGbr;
14728             cmnLcg->effDeltaMbr = cmnLcg->deltaMbr;
14729             cmnLcg->bs = RGSCH_MIN(cmnLcg->reportedBs, cmnLcg->effGbr + cmnLcg->effDeltaMbr);
14730             /* Considering GBR LCG will be prioritised by UE */
14731             effGbrBsr += cmnLcg->bs;
14732          }/* Else no remaing BS so nonLcg0 will be updated when BSR will be received */
14733          else
14734          {
14735             effNonGbrBsr += cmnLcg->reportedBs;
14736             cmnLcg->bs = RGSCH_MIN(cmnLcg->reportedBs, ue->ul.effAmbr);
14737          }
14738       }
14739    }
14740    effNonGbrBsr = RGSCH_MIN(effNonGbrBsr,ue->ul.effAmbr);
14741    ue->ul.nonGbrLcgBs = effNonGbrBsr;
14742
14743    ue->ul.nonLcg0Bs = effGbrBsr + effNonGbrBsr;
14744    ue->ul.effBsr = ue->ul.nonLcg0Bs +\
14745                   ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->bs;
14746
14747
14748    /* call scheduler specific event handlers
14749     * for refresh timer expiry */
14750    cellSch->apisUl->rgSCHUlUeRefresh(cell, ue);
14751    cellSch->apisDl->rgSCHDlUeRefresh(cell, ue);
14752
14753    return ROK;
14754 }
14755
14756 /***********************************************************
14757  *
14758  *     Func : rgSCHCmnTmrExpiry
14759  *
14760  *     Desc : Adds an UE to refresh queue, so that the UE is
14761  *            periodically triggered to refresh it's GBR and
14762  *            AMBR values.
14763  *
14764  *     Ret  :
14765  *
14766  *     Notes:
14767  *
14768  *     File :
14769  *
14770  **********************************************************/
14771 #ifdef ANSI
14772 PRIVATE S16 rgSCHCmnTmrExpiry
14773 (
14774 PTR cb,               /* Pointer to timer control block */
14775 S16 tmrEvnt           /* Timer Event */
14776 )
14777 #else
14778 PRIVATE S16 rgSCHCmnTmrExpiry(cb, tmrEvnt)
14779 PTR cb;               /* Pointer to timer control block */
14780 S16 tmrEvnt;           /* Timer Event */
14781 #endif
14782 {
14783    RgSchUeCb       *ue = (RgSchUeCb *)cb;
14784    RgSchCellCb     *cell = ue->cell;
14785 #if (ERRCLASS & ERRCLS_DEBUG)
14786 #endif
14787
14788
14789 #if (ERRCLASS & ERRCLS_DEBUG)
14790    if (tmrEvnt != RG_SCH_CMN_EVNT_UE_REFRESH)
14791    {
14792       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHCmnTmrExpiry(): Invalid "
14793          "timer event CRNTI:%d",ue->ueId);
14794       return RFAILED;
14795    }
14796 #else
14797    UNUSED(tmrEvnt);
14798 #endif
14799
14800    rgSCHCmnApplyUeRefresh(cell, ue);
14801
14802    rgSCHCmnAddUeToRefreshQ(cell, ue, RG_SCH_CMN_REFRESH_TIME);
14803
14804    return ROK;
14805 }
14806
14807 /***********************************************************
14808  *
14809  *     Func : rgSCHCmnTmrProc
14810  *
14811  *     Desc : Timer entry point per cell. Timer
14812  *            processing is triggered at every frame boundary
14813  *            (every 10 ms).
14814  *
14815  *     Ret  :
14816  *
14817  *     Notes:
14818  *
14819  *     File :
14820  *
14821  **********************************************************/
14822 #ifdef ANSI
14823 PRIVATE S16 rgSCHCmnTmrProc
14824 (
14825 RgSchCellCb *cell
14826 )
14827 #else
14828 PRIVATE S16 rgSCHCmnTmrProc(cell)
14829 RgSchCellCb *cell;
14830 #endif
14831 {
14832    RgSchCmnDlCell *cmnDlCell = RG_SCH_CMN_GET_DL_CELL(cell);
14833    RgSchCmnUlCell *cmnUlCell = RG_SCH_CMN_GET_UL_CELL(cell);
14834    /* Moving the assignment of scheduler pointer
14835      to available scope for optimization */
14836
14837    if ((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES_5G) == 0)
14838    {
14839       /* Reset the counters periodically */
14840       if ((cell->crntTime.sfn % RG_SCH_CMN_CSG_REFRESH_TIME) == 0)
14841       {
14842          RG_SCH_RESET_HCSG_DL_PRB_CNTR(cmnDlCell);
14843          RG_SCH_RESET_HCSG_UL_PRB_CNTR(cmnUlCell);
14844       }
14845       if ((cell->crntTime.sfn % RG_SCH_CMN_OVRLDCTRL_REFRESH_TIME) == 0)
14846       {
14847
14848          cell->measurements.ulTpt =  ((cell->measurements.ulTpt * 95) + ( cell->measurements.ulBytesCnt * 5))/100;
14849          cell->measurements.dlTpt =  ((cell->measurements.dlTpt * 95) + ( cell->measurements.dlBytesCnt * 5))/100;
14850
14851          rgSCHUtlCpuOvrLdAdjItbsCap(cell);
14852          /* reset cell level tpt measurements for next cycle */
14853          cell->measurements.ulBytesCnt = 0;
14854          cell->measurements.dlBytesCnt = 0;
14855       }
14856       /* Comparing with Zero instead of % is being done for efficiency.
14857        * If Timer resolution changes then accordingly update the
14858        * macro RG_SCH_CMN_REFRESH_TIMERES */    
14859       RgSchCmnCell   *sched  = RG_SCH_CMN_GET_CELL(cell);
14860       cmPrcTmr(&sched->tmrTqCp, sched->tmrTq, (PFV)rgSCHCmnTmrExpiry);
14861    }
14862
14863    return ROK;
14864 }
14865
14866
14867 /***********************************************************
14868  *
14869  *     Func : rgSchCmnUpdCfiVal 
14870  *
14871  *     Desc : Update the CFI value if CFI switch was done 
14872  *
14873  *     Ret  :
14874  *
14875  *     Notes:
14876  *
14877  *     File :
14878  *
14879  **********************************************************/
14880 #ifdef ANSI
14881 PRIVATE Void rgSchCmnUpdCfiVal
14882 (
14883 RgSchCellCb     *cell,
14884 U8              delta
14885 )
14886 #else
14887 PRIVATE Void rgSchCmnUpdCfiVal(cell, delta)
14888 RgSchCellCb     *cell;
14889 U8              delta;
14890 #endif  
14891 {
14892    RgSchDlSf        *dlSf;
14893    CmLteTimingInfo  pdsch;
14894    RgSchCmnDlCell  *cellCmnDl = RG_SCH_CMN_GET_DL_CELL(cell); 
14895    U8               dlIdx;
14896 #ifdef LTE_TDD
14897    U8               mPhich;
14898    RgSchDlSf        *tddSf;
14899    U8               idx;
14900    U8               splSfCfi = 0;
14901 #endif    
14902
14903
14904    pdsch  = cell->crntTime;
14905    RGSCH_INCR_SUB_FRAME(pdsch, delta);
14906    dlSf = rgSCHUtlSubFrmGet(cell, pdsch);
14907    /* Fix for DCFI FLE issue: when DL delta is 1 and UL delta is 0 and CFI
14908     *change happens in that SF then UL PDCCH allocation happens with old CFI
14909     *but CFI in control Req goes updated one since it was stored in the CELL
14910     */
14911    dlSf->pdcchInfo.currCfi = cellCmnDl->currCfi;
14912    if(cell->dynCfiCb.pdcchSfIdx != 0xFF) 
14913    {
14914 #ifdef LTE_TDD
14915       dlIdx = rgSCHUtlGetDlSfIdx(cell, &pdsch);
14916 #else
14917       dlIdx = (((pdsch.sfn & 1) * RGSCH_NUM_SUB_FRAMES) + (pdsch.slot % RGSCH_NUM_SUB_FRAMES));
14918       RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, cell->subFrms, dlIdx);
14919 #endif  
14920       /* If current downlink subframe index is same as pdcch SF index,
14921        * perform the switching of CFI in this subframe */
14922       if(cell->dynCfiCb.pdcchSfIdx == dlIdx)
14923       {
14924          cellCmnDl->currCfi  = cellCmnDl->newCfi;
14925          cell->dynCfiCb.pdcchSfIdx = 0xFF;
14926
14927          /* Updating the nCce value based on the new CFI */
14928 #ifdef LTE_TDD
14929          splSfCfi = cellCmnDl->newCfi;
14930          for(idx = 0; idx < cell->numDlSubfrms; idx++)
14931          {   
14932             tddSf = cell->subFrms[idx];
14933
14934             mPhich = rgSchTddPhichMValTbl[cell->ulDlCfgIdx][tddSf->sfNum];
14935
14936             if(tddSf->sfType == RG_SCH_SPL_SF_DATA)
14937             {
14938                RGSCH_GET_SPS_SF_CFI(cell->bwCfg.dlTotalBw, splSfCfi);
14939
14940                tddSf->nCce = cell->dynCfiCb.cfi2NCceTbl[mPhich][splSfCfi];
14941             }
14942             else
14943             {   
14944                tddSf->nCce = cell->dynCfiCb.cfi2NCceTbl[mPhich][cellCmnDl->currCfi];
14945             }
14946          }
14947          /* Setting the switch over window length based on config index.
14948           * During switch over period all the UL trnsmissions are Acked 
14949           * to UEs */
14950          cell->dynCfiCb.switchOvrWinLen = 
14951                rgSchCfiSwitchOvrWinLen[cell->ulDlCfgIdx];
14952 #else
14953          cell->nCce = cell->dynCfiCb.cfi2NCceTbl[0][cellCmnDl->currCfi];
14954          /* Fix for DCFI FLE issue: when DL delta is 1 and UL delta is 0 and CFI
14955           *change happens in that SF then UL PDCCH allocation happens with old CFI
14956           *but CFI in control Req goes updated one since it was stored in the CELL
14957           */
14958          dlSf->pdcchInfo.currCfi = cellCmnDl->currCfi;
14959          cell->dynCfiCb.switchOvrWinLen = rgSchCfiSwitchOvrWinLen[7];
14960 #endif
14961       }   
14962    }   
14963
14964    RETVOID;
14965 }
14966
14967 /***********************************************************
14968  *
14969  *     Func : rgSchCmnUpdtPdcchSfIdx 
14970  *
14971  *     Desc : Update the switch over window length
14972  *
14973  *     Ret  : void
14974  *
14975  *     Notes:
14976  *
14977  *     File :
14978  *
14979  **********************************************************/
14980 #ifdef LTE_TDD
14981 #ifdef ANSI
14982 PRIVATE Void rgSchCmnUpdtPdcchSfIdx 
14983 (
14984 RgSchCellCb     *cell,
14985 U8              dlIdx,
14986 U8              sfNum
14987 )
14988 #else
14989 PRIVATE Void rgSchCmnUpdtPdcchSfIdx(cell, dlIdx, sfNum)
14990 RgSchCellCb     *cell;
14991 U8              dlIdx;
14992 U8              sfNum;
14993 #endif   
14994 #else
14995 #ifdef ANSI
14996 PRIVATE Void rgSchCmnUpdtPdcchSfIdx 
14997 (
14998 RgSchCellCb     *cell,
14999 U8              dlIdx
15000 )
15001 #else
15002 PRIVATE Void rgSchCmnUpdtPdcchSfIdx(cell, dlIdx)
15003 RgSchCellCb     *cell;
15004 U8              dlIdx;
15005 #endif    
15006 #endif
15007 {
15008    U8         idx;
15009
15010
15011    /* Resetting the parameters on CFI switching */
15012    cell->dynCfiCb.cceUsed = 0;
15013    cell->dynCfiCb.lowCceCnt = 0;
15014
15015    cell->dynCfiCb.cceFailSum = 0;
15016    cell->dynCfiCb.cceFailCnt = 0;
15017    cell->dynCfiCb.prevCceFailIdx = 0;
15018
15019    cell->dynCfiCb.switchOvrInProgress = TRUE;
15020
15021    for(idx = 0; idx < cell->dynCfiCb.numFailSamples; idx++)
15022    {
15023       cell->dynCfiCb.cceFailSamples[idx] = 0;
15024    }   
15025
15026    cell->dynCfiCb.ttiCnt = 0;
15027
15028    cell->dynCfiCb.cfiSwitches++;
15029    cfiSwitchCnt = cell->dynCfiCb.cfiSwitches;
15030
15031 #ifdef LTE_TDD 
15032    cell->dynCfiCb.pdcchSfIdx = (dlIdx + 
15033       rgSchTddPdcchSfIncTbl[cell->ulDlCfgIdx][sfNum]) % cell->numDlSubfrms;
15034 #else
15035    cell->dynCfiCb.pdcchSfIdx = (dlIdx + RG_SCH_CFI_APPLY_DELTA) % \
15036         RGSCH_NUM_DL_slotS;
15037 #endif
15038 }
15039
15040 /***********************************************************
15041  *
15042  *     Func : rgSchCmnUpdCfiDb 
15043  *
15044  *     Desc : Update the counters related to dynamic
15045  *            CFI feature in cellCb. 
15046  *
15047  *     Ret  :
15048  *
15049  *     Notes:
15050  *
15051  *     File :
15052  *
15053  **********************************************************/
15054 #ifdef ANSI
15055 Void rgSchCmnUpdCfiDb 
15056 (
15057 RgSchCellCb     *cell,
15058 U8              delta 
15059 )
15060 #else
15061 Void rgSchCmnUpdCfiDb(cell, delta)
15062 RgSchCellCb     *cell;
15063 U8              delta;
15064 #endif 
15065 {
15066    CmLteTimingInfo        frm;
15067    RgSchDlSf              *dlSf;
15068 #ifdef LTE_TDD
15069    U8                     mPhich;
15070    Bool                   isHiDci0; 
15071 #endif      
15072    RgSchCmnCell           *cellSch = RG_SCH_CMN_GET_CELL(cell); 
15073    U8                     nCceLowerCfi = 0;
15074    U8                     currCfi;
15075    U8                     cceFailIdx;
15076    U32                    totalCce;
15077    U8                     dlIdx;
15078    U16                    ttiMod;
15079
15080
15081    /* Get Downlink Subframe */   
15082    frm   = cell->crntTime;
15083    RGSCH_INCR_SUB_FRAME(frm, delta);
15084
15085 #ifdef LTE_TDD
15086    dlIdx = rgSCHUtlGetDlSfIdx(cell, &frm);
15087    dlSf = cell->subFrms[dlIdx];
15088    isHiDci0 = rgSchTddPuschTxKTbl[cell->ulDlCfgIdx][dlSf->sfNum];
15089 #else
15090    /* Changing the idexing
15091       so that proper subframe is selected */
15092    dlIdx = (((frm.sfn & 1) * RGSCH_NUM_SUB_FRAMES) + (frm.slot % RGSCH_NUM_SUB_FRAMES));
15093    RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, cell->subFrms, dlIdx);
15094    dlSf = cell->subFrms[dlIdx];
15095 #endif 
15096
15097    currCfi = cellSch->dl.currCfi;
15098
15099    if(!cell->dynCfiCb.switchOvrInProgress)
15100    {   
15101       do{
15102          if(!cell->dynCfiCb.isDynCfiEnb)
15103          {
15104             if(currCfi != cellSch->cfiCfg.cfi)
15105             {
15106                if(currCfi < cellSch->cfiCfg.cfi)
15107                {
15108                   RG_SCH_CFI_STEP_UP(cell, cellSch, currCfi)
15109                   cfiIncr = cell->dynCfiCb.cfiIncr;   
15110                }
15111                else
15112                {
15113                   RG_SCH_CFI_STEP_DOWN(cell, cellSch, currCfi)
15114                   cfiDecr = cell->dynCfiCb.cfiDecr;
15115                }
15116             }
15117             break;
15118          }
15119
15120 #ifdef LTE_TDD         
15121          /* Setting ttiMod to 0 for ttiCnt > 1000 in case if this 
15122           * function was not called in UL subframe*/
15123          if(cell->dynCfiCb.ttiCnt > RGSCH_CFI_TTI_MON_INTRVL)
15124          {   
15125             ttiMod = 0;
15126          }
15127          else
15128 #endif
15129          {   
15130             ttiMod = cell->dynCfiCb.ttiCnt % RGSCH_CFI_TTI_MON_INTRVL;
15131          }
15132
15133          dlSf->dlUlBothCmplt++;
15134 #ifdef LTE_TDD      
15135          if((dlSf->dlUlBothCmplt == 2) || (!isHiDci0))
15136 #else
15137          if(dlSf->dlUlBothCmplt == 2)
15138 #endif         
15139          {
15140             /********************STEP UP CRITERIA********************/
15141             /* Updating the CCE failure count parameter */
15142             cell->dynCfiCb.cceFailCnt += dlSf->isCceFailure;
15143             cell->dynCfiCb.cceFailSum += dlSf->isCceFailure;
15144
15145             /* Check if cfi step up can be performed */
15146             if(currCfi < cell->dynCfiCb.maxCfi)
15147             {
15148                if(cell->dynCfiCb.cceFailSum >= cell->dynCfiCb.cfiStepUpTtiCnt) 
15149                {
15150                   RG_SCH_CFI_STEP_UP(cell, cellSch, currCfi)
15151                   cfiIncr = cell->dynCfiCb.cfiIncr;   
15152                   break;
15153                }
15154             } 
15155
15156             /********************STEP DOWN CRITERIA********************/
15157
15158             /* Updating the no. of CCE used in this dl subframe */
15159             cell->dynCfiCb.cceUsed += dlSf->cceCnt;
15160
15161             if(currCfi > RGSCH_MIN_CFI_VAL)
15162             {   
15163                /* calculating the number of CCE for next lower CFI */
15164 #ifdef LTE_TDD      
15165                mPhich = rgSchTddPhichMValTbl[cell->ulDlCfgIdx][dlSf->sfNum];
15166                nCceLowerCfi = cell->dynCfiCb.cfi2NCceTbl[mPhich][currCfi-1];
15167 #else
15168                nCceLowerCfi = cell->dynCfiCb.cfi2NCceTbl[0][currCfi-1];
15169 #endif     
15170                if(dlSf->cceCnt < nCceLowerCfi)
15171                {
15172                   /* Updating the count of TTIs in which no. of CCEs
15173                    * used were less than the CCEs of next lower CFI */
15174                   cell->dynCfiCb.lowCceCnt++;
15175                }   
15176
15177                if(ttiMod == 0)
15178                {
15179                   totalCce = (nCceLowerCfi * cell->dynCfiCb.cfiStepDownTtiCnt * 
15180                         RGSCH_CFI_CCE_PERCNTG)/100;
15181
15182                   if((!cell->dynCfiCb.cceFailSum) && 
15183                         (cell->dynCfiCb.lowCceCnt >= 
15184                          cell->dynCfiCb.cfiStepDownTtiCnt) && 
15185                         (cell->dynCfiCb.cceUsed < totalCce))  
15186                   {
15187                      RG_SCH_CFI_STEP_DOWN(cell, cellSch, currCfi)
15188                      cfiDecr = cell->dynCfiCb.cfiDecr; 
15189                      break;
15190                   }
15191                }   
15192             }
15193
15194             cceFailIdx = ttiMod/cell->dynCfiCb.failSamplePrd;
15195
15196             if(cceFailIdx != cell->dynCfiCb.prevCceFailIdx)
15197             {   
15198                /* New sample period has started. Subtract the old count  
15199                 * from the new sample period */
15200                cell->dynCfiCb.cceFailSum -= cell->dynCfiCb.cceFailSamples[cceFailIdx];
15201
15202                /* Store the previous sample period data */
15203                cell->dynCfiCb.cceFailSamples[cell->dynCfiCb.prevCceFailIdx]
15204                   = cell->dynCfiCb.cceFailCnt;
15205
15206                cell->dynCfiCb.prevCceFailIdx = cceFailIdx;
15207
15208                /* Resetting the CCE failure count as zero for next sample period */
15209                cell->dynCfiCb.cceFailCnt = 0;  
15210             }
15211
15212             if(ttiMod == 0)
15213             {   
15214                /* Restting the parametrs after Monitoring Interval expired */
15215                cell->dynCfiCb.cceUsed = 0;
15216                cell->dynCfiCb.lowCceCnt = 0;
15217                cell->dynCfiCb.ttiCnt = 0;
15218             }
15219
15220             cell->dynCfiCb.ttiCnt++;
15221          }
15222       }while(0);
15223
15224       if(cellSch->dl.newCfi != cellSch->dl.currCfi)
15225       {
15226 #ifdef LTE_TDD      
15227          rgSchCmnUpdtPdcchSfIdx(cell, dlIdx, dlSf->sfNum);
15228 #else
15229          rgSchCmnUpdtPdcchSfIdx(cell, dlIdx);
15230 #endif      
15231       }  
15232    }
15233 }   
15234
15235 /**
15236  * @brief Dl Scheduler for Broadcast and Common channel scheduling.
15237  *
15238  * @details
15239  *
15240  *     Function: rgSCHCmnDlCommonChSch
15241  *     Purpose:  This function schedules DL Common channels for LTE. 
15242  *               Invoked by TTI processing in TOM. Scheduling is done for 
15243  *               BCCH, PCCH, Msg4, CCCH SDU, RAR in that order 
15244  *
15245  *     Invoked by: TOM (TTI processing)
15246  *
15247  *  @param[in]  RgSchCellCb *cell
15248  *  @return  Void
15249  **/
15250 #ifdef ANSI
15251 Void rgSCHCmnDlCommonChSch
15252 (
15253 RgSchCellCb  *cell
15254 )
15255 #else
15256 Void rgSCHCmnDlCommonChSch(cell)
15257 RgSchCellCb  *cell;
15258 #endif
15259 {
15260    RgSchCmnCell           *cellSch = RG_SCH_CMN_GET_CELL(cell);
15261
15262
15263    cellSch->apisDl->rgSCHDlTickForPdbTrkng(cell);
15264    rgSchCmnUpdCfiVal(cell, RG_SCH_CMN_DL_DELTA);
15265
15266    /* handle Inactive UEs for DL */
15267    rgSCHCmnHdlDlInactUes(cell);
15268
15269    /* Send a Tick to Refresh Timer */
15270    rgSCHCmnTmrProc(cell);
15271
15272    if (cell->isDlDataAllwd && (cell->stopSiSch == FALSE)) 
15273    {
15274       rgSCHCmnInitRbAlloc(cell); 
15275       /* Perform DL scheduling of BCCH, PCCH */
15276       rgSCHCmnDlBcchPcchAlloc(cell);
15277    }
15278    else
15279    {
15280       if(cell->siCb.inWindow != 0)
15281       {
15282          cell->siCb.inWindow--;
15283       }
15284    }
15285    if (cell->isDlDataAllwd && (cell->stopDlSch == FALSE))
15286    {
15287       rgSCHCmnDlCcchRarAlloc(cell);
15288    }
15289    RETVOID;
15290 }
15291
15292 /**
15293  * @brief Scheduler invocation per TTI.
15294  *
15295  * @details
15296  *
15297  *     Function: rgSCHCmnUlSch
15298  *     Purpose:  This function implements UL scheduler alone. This is to
15299  *               be able to perform scheduling with more flexibility.
15300  *
15301  *     Invoked by: TOM (TTI processing)
15302  *
15303  *  @param[in]  RgSchCellCb *cell
15304  *  @return  Void
15305  **/
15306 #ifdef ANSI
15307 Void rgSCHCmnUlSch
15308 (
15309 RgSchCellCb  *cell
15310 )
15311 #else
15312 Void  rgSCHCmnUlSch(cell)
15313 RgSchCellCb  *cell;
15314 #endif
15315 {
15316    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
15317    
15318
15319 #ifdef LTE_ADV
15320    /* LAA_SCELL: */
15321    if(TRUE == rgSCHLaaSCellEnabled(cell))
15322    {
15323       RETVOID;   
15324    }
15325 #endif
15326    
15327    if(cellSch->ul.schdIdx != RGSCH_INVALID_INFO)
15328    {   
15329       rgSchCmnUpdCfiVal(cell, TFU_ULCNTRL_DLDELTA);
15330
15331       /* Handle Inactive UEs for UL */
15332       rgSCHCmnHdlUlInactUes(cell);
15333       /* Perform UL Scheduling EVERY TTI */
15334       rgSCHCmnUlAlloc(cell);
15335
15336       /* Calling function to update CFI parameters*/
15337       rgSchCmnUpdCfiDb(cell, TFU_ULCNTRL_DLDELTA);   
15338
15339       if(cell->dynCfiCb.switchOvrWinLen > 0)
15340       {
15341          /* Decrementing the switchover window length */
15342          cell->dynCfiCb.switchOvrWinLen--;
15343
15344          if(!cell->dynCfiCb.switchOvrWinLen)
15345          {   
15346             if(cell->dynCfiCb.dynCfiRecfgPend)
15347             {  
15348                /* Toggling the Dynamic CFI enabling */
15349                cell->dynCfiCb.isDynCfiEnb ^= 1;
15350                rgSCHDynCfiReCfg(cell, cell->dynCfiCb.isDynCfiEnb); 
15351                cell->dynCfiCb.dynCfiRecfgPend = FALSE;
15352             }   
15353             cell->dynCfiCb.switchOvrInProgress = FALSE;
15354          }
15355       }
15356    }
15357 #ifdef LTE_TDD
15358 #ifdef LTEMAC_SPS
15359    else
15360    {
15361       rgSCHCmnSpsUlTti(cell, NULLP); 
15362    }
15363 #endif
15364 #endif
15365
15366    RETVOID;
15367 }
15368
15369 \f
15370 /**
15371  * @brief This function updates the scheduler with service for an UE.
15372  *
15373  * @details
15374  *
15375  *     Function: rgSCHCmnDlDedBoUpd
15376  *     Purpose:  This function should be called whenever there is a
15377  *               change BO for a service.
15378  *
15379  *     Invoked by: BO and Scheduler
15380  *
15381  *  @param[in]  RgSchCellCb*  cell
15382  *  @param[in]  RgSchUeCb*    ue
15383  *  @param[in]  RgSchDlLcCb*  svc
15384  *  @return  Void
15385  *
15386  **/
15387 #ifdef ANSI
15388 Void rgSCHCmnDlDedBoUpd
15389 (
15390 RgSchCellCb                *cell,
15391 RgSchUeCb                  *ue,
15392 RgSchDlLcCb                *svc
15393 )
15394 #else
15395 Void rgSCHCmnDlDedBoUpd(cell, ue, svc)
15396 RgSchCellCb                *cell;
15397 RgSchUeCb                  *ue;
15398 RgSchDlLcCb                *svc;
15399 #endif
15400 {
15401    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
15402
15403    /* RACHO : if UEs idle time exceeded and a BO update
15404     * is received, then add UE to the pdcch Order Q */
15405    if (RG_SCH_CMN_IS_UE_PDCCHODR_INACTV(ue))
15406    {
15407       RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue, cell);
15408       /* If PDCCH order is already triggered and we are waiting for
15409        * RACH from UE then do not add to PdcchOdrQ. */
15410       if (ueDl->rachInfo.rapIdLnk.node == NULLP)
15411       {
15412          rgSCHCmnDlAdd2PdcchOdrQ(cell, ue);
15413       }
15414    }
15415
15416 #ifdef LTEMAC_SPS
15417
15418    /* If SPS service, invoke SPS module */
15419    if (svc->dlLcSpsCfg.isSpsEnabled)
15420    {
15421       rgSCHCmnSpsDlDedBoUpd(cell, ue, svc);
15422       /* Note: Retrun from here, no update needed in other schedulers */
15423       RETVOID;
15424    }
15425 #endif
15426 #ifdef EMTC_ENABLE
15427    if((cell->emtcEnable)&&(TRUE == ue->isEmtcUe))
15428    {
15429       cellSch->apisEmtcDl->rgSCHDlDedBoUpd(cell, ue, svc);
15430       //printf("rgSCHEMTCDlDedBoUpd\n");
15431    }
15432    else
15433 #endif
15434    {
15435       cellSch->apisDl->rgSCHDlDedBoUpd(cell, ue, svc);
15436    }
15437 #ifdef LTE_ADV
15438    if (ue->numSCells)
15439    {
15440       rgSCHSCellDlDedBoUpd(cell, ue, svc);
15441    }
15442 #endif
15443    RETVOID;
15444 }
15445
15446 \f
15447 /**
15448  * @brief Removes an UE from Cell's TA List.
15449  *
15450  * @details
15451  *
15452  *     Function: rgSCHCmnRmvFrmTaLst
15453  *     Purpose:  Removes an UE from Cell's TA List.
15454  *
15455  *     Invoked by: Specific Scheduler
15456  *
15457  *  @param[in]  RgSchCellCb*     cell
15458  *  @param[in]  RgSchUeCb*       ue
15459  *  @return  Void
15460  *
15461  **/
15462 #ifdef ANSI
15463 Void rgSCHCmnRmvFrmTaLst
15464 (
15465 RgSchCellCb                *cell,
15466 RgSchUeCb                  *ue
15467 )
15468 #else
15469 Void rgSCHCmnRmvFrmTaLst(cell, ue)
15470 RgSchCellCb                *cell;
15471 RgSchUeCb                  *ue;
15472 #endif
15473 {
15474    RgSchCmnDlCell *cellCmnDl = RG_SCH_CMN_GET_DL_CELL(cell);
15475
15476 #ifdef EMTC_ENABLE
15477    if(cell->emtcEnable && ue->isEmtcUe)
15478    {
15479       rgSCHEmtcRmvFrmTaLst(cellCmnDl,ue);
15480    }
15481    else
15482 #endif
15483    {
15484       cmLListDelFrm(&cellCmnDl->taLst, &ue->dlTaLnk);
15485       ue->dlTaLnk.node = (PTR)NULLP;
15486    }
15487    RETVOID;
15488 }
15489
15490 /* Fix: syed Remove the msg4Proc from cell
15491  * msg4Retx Queue. I have used CMN scheduler function
15492  * directly. Please define a new API and call this
15493  * function through that. */        
15494 \f
15495 /**
15496  * @brief This function removes MSG4 HARQ process from cell RETX Queues.
15497  *
15498  * @details
15499  *
15500  *     Function: rgSCHCmnDlMsg4ProcRmvFrmRetx
15501  *     Purpose:  This function removes MSG4 HARQ process from cell RETX Queues.
15502  *
15503  *     Invoked by: UE/RACB deletion. 
15504  *
15505  *  @param[in]  RgSchCellCb*     cell
15506  *  @param[in]  RgSchDlHqProc*   hqP
15507  *  @return  Void
15508  *
15509  **/
15510 #ifdef ANSI
15511 Void rgSCHCmnDlMsg4ProcRmvFrmRetx 
15512 (
15513 RgSchCellCb                *cell,
15514 RgSchDlHqProcCb            *hqP
15515 )
15516 #else
15517 Void rgSCHCmnDlMsg4ProcRmvFrmRetx(cell, hqP)
15518 RgSchCellCb                *cell;
15519 RgSchDlHqProcCb            *hqP;
15520 #endif
15521 {
15522    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
15523
15524    if (hqP->tbInfo[0].ccchSchdInfo.retxLnk.node)
15525    {
15526       if (hqP->hqE->msg4Proc == hqP)
15527       {
15528          cmLListDelFrm(&cellSch->dl.msg4RetxLst, \
15529                &hqP->tbInfo[0].ccchSchdInfo.retxLnk);
15530          hqP->tbInfo[0].ccchSchdInfo.retxLnk.node = (PTR)NULLP;
15531       }
15532 #ifdef RGR_V1
15533       else if(hqP->hqE->ccchSduProc == hqP)
15534       {
15535          cmLListDelFrm(&cellSch->dl.ccchSduRetxLst,
15536                &hqP->tbInfo[0].ccchSchdInfo.retxLnk);
15537          hqP->tbInfo[0].ccchSchdInfo.retxLnk.node = (PTR)NULLP;
15538       }
15539 #endif
15540    }
15541    RETVOID;
15542 }
15543
15544 \f
15545 /**
15546  * @brief This function adds a HARQ process for retx.
15547  *
15548  * @details
15549  *
15550  *     Function: rgSCHCmnDlProcAddToRetx
15551  *     Purpose:  This function adds a HARQ process to retransmission
15552  *               queue. This may be performed when a HARQ ack is
15553  *               unsuccessful.
15554  *
15555  *     Invoked by: HARQ feedback processing
15556  *
15557  *  @param[in]  RgSchCellCb*     cell
15558  *  @param[in]  RgSchDlHqProc*   hqP
15559  *  @return  Void
15560  *
15561  **/
15562 #ifdef ANSI
15563 Void rgSCHCmnDlProcAddToRetx
15564 (
15565 RgSchCellCb                *cell,
15566 RgSchDlHqProcCb            *hqP
15567 )
15568 #else
15569 Void rgSCHCmnDlProcAddToRetx(cell, hqP)
15570 RgSchCellCb                *cell;
15571 RgSchDlHqProcCb            *hqP;
15572 #endif
15573 {
15574    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
15575
15576    if (hqP->hqE->msg4Proc == hqP) /* indicating msg4 transmission */
15577    {
15578       cmLListAdd2Tail(&cellSch->dl.msg4RetxLst, \
15579             &hqP->tbInfo[0].ccchSchdInfo.retxLnk);
15580       hqP->tbInfo[0].ccchSchdInfo.retxLnk.node = (PTR)hqP;
15581    }
15582 #ifdef RGR_V1
15583    else if(hqP->hqE->ccchSduProc == hqP)
15584    {
15585       /*If CCCH SDU being transmitted without cont res CE*/
15586       cmLListAdd2Tail(&cellSch->dl.ccchSduRetxLst,
15587             &hqP->tbInfo[0].ccchSchdInfo.retxLnk);
15588       hqP->tbInfo[0].ccchSchdInfo.retxLnk.node = (PTR)hqP;
15589    }
15590 #endif
15591    else
15592    {
15593 #ifdef LTEMAC_SPS
15594       if (RG_SCH_CMN_SPS_DL_IS_SPS_HQP(hqP))
15595       {
15596          /* Invoke SPS module for SPS HARQ proc re-transmission handling */
15597          rgSCHCmnSpsDlProcAddToRetx(cell, hqP);
15598          RETVOID;
15599       }
15600 #endif /* LTEMAC_SPS */
15601 #ifdef EMTC_ENABLE      
15602       if((TRUE == cell->emtcEnable)
15603          && (TRUE == hqP->hqE->ue->isEmtcUe))
15604       {
15605          cellSch->apisEmtcDl->rgSCHDlProcAddToRetx(cell, hqP);
15606       }
15607       else
15608 #endif         
15609       {
15610          cellSch->apisDl->rgSCHDlProcAddToRetx(cell, hqP);
15611       }
15612    }
15613    RETVOID;
15614 }
15615
15616 \f
15617 /**
15618  * @brief This function performs RI validation and
15619  *        updates it to the ueCb.
15620  *
15621  * @details
15622  *
15623  *     Function: rgSCHCmnDlSetUeRi
15624  *     Purpose:  This function performs RI validation and
15625  *        updates it to the ueCb.
15626  *
15627  *     Invoked by: rgSCHCmnDlCqiInd
15628  *
15629  *  @param[in]  RgSchCellCb        *cell
15630  *  @param[in]  RgSchUeCb          *ue
15631  *  @param[in]  U8                 ri
15632  *  @param[in]  Bool               isPeriodic
15633  *  @return  Void
15634  *
15635  **/
15636 #ifdef ANSI
15637 PRIVATE Void rgSCHCmnDlSetUeRi
15638 (
15639 RgSchCellCb        *cell,
15640 RgSchUeCb          *ue,
15641 U8                 ri,
15642 Bool               isPer
15643 )
15644 #else
15645 PRIVATE Void rgSCHCmnDlSetUeRi(cell, ue, ri, isPer)
15646 RgSchCellCb        *cell;
15647 RgSchUeCb          *ue;
15648 U8                 ri;
15649 Bool               isPer;
15650 #endif
15651 {
15652    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
15653    RgSchCmnUeInfo    *ueSchCmn = RG_SCH_CMN_GET_CMN_UE(ue);
15654    
15655 #ifdef TFU_UPGRADE
15656    RgSchUePCqiCb *cqiCb = RG_SCH_GET_UE_CELL_CQI_CB(ue,cell);
15657    UNUSED(isPer);
15658 #endif
15659
15660
15661    /* FIX for RRC Reconfiguration issue */
15662    /* ccpu00140894- During Tx Mode transition RI report will not entertained for 
15663     * specific during which SCH expecting UE can complete TX mode transition*/
15664    if (ue->txModeTransCmplt == FALSE)
15665    {
15666       RETVOID;
15667    }
15668
15669    /* Restrict the Number of TX layers to cell->numTxAntPorts.
15670     * Protection from invalid RI values. */
15671    ri = RGSCH_MIN(ri, cell->numTxAntPorts);
15672    
15673    /* Special case of converting PMI to sane value when
15674     * there is a switch in RI from 1 to 2 and PMI reported 
15675     * for RI=1 is invalid for RI=2 */
15676    if ((cell->numTxAntPorts == 2) && (ue->mimoInfo.txMode == RGR_UE_TM_4))
15677    {
15678       if ((ri == 2) && ( ueDl->mimoInfo.ri == 1))
15679       {
15680          ueDl->mimoInfo.pmi = (ueDl->mimoInfo.pmi < 2)? 1:2;
15681       }
15682    }
15683
15684    /* Restrict the Number of TX layers according to the UE Category */
15685    ueDl->mimoInfo.ri = RGSCH_MIN(ri, rgUeCatTbl[ueSchCmn->ueCat].maxTxLyrs);
15686 #ifdef TENB_STATS
15687    ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(cell)].riCnt[ueDl->mimoInfo.ri-1]++;
15688    cell->tenbStats->sch.riCnt[ueDl->mimoInfo.ri-1]++;
15689 #endif
15690
15691 #ifdef TENB_STATS
15692    ue->tenbStats->stats.nonPersistent.sch[0].riCnt[ueDl->mimoInfo.ri-1]++;
15693    cell->tenbStats->sch.riCnt[ueDl->mimoInfo.ri-1]++;
15694 #endif
15695
15696 #ifdef TFU_UPGRADE
15697    if (isPer)
15698    {
15699       /* If RI is from Periodic CQI report */
15700       cqiCb->perRiVal = ueDl->mimoInfo.ri;
15701       /* Reset at every Periodic RI Reception */ 
15702       cqiCb->invalidateCqi = FALSE;
15703    }
15704    else
15705    {
15706       /* If RI is from Aperiodic CQI report */
15707       if (cqiCb->perRiVal != ueDl->mimoInfo.ri)
15708       {
15709          /* if this aperRI is different from last reported
15710           * perRI then invalidate all CQI reports till next
15711           * perRI */
15712          cqiCb->invalidateCqi = TRUE;
15713       }
15714       else
15715       {
15716          cqiCb->invalidateCqi = FALSE;
15717       }
15718    }
15719 #endif   
15720
15721    if (ueDl->mimoInfo.ri > 1)
15722    {
15723       RG_SCH_CMN_UNSET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_RI_1);
15724    }
15725    else if (ue->mimoInfo.txMode == RGR_UE_TM_3) /* ri == 1 */
15726    {
15727       RG_SCH_CMN_SET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_RI_1);
15728    }
15729
15730    RETVOID;
15731 }
15732
15733 \f
15734 /**
15735  * @brief This function performs PMI validation and
15736  *        updates it to the ueCb.
15737  *
15738  * @details
15739  *
15740  *     Function: rgSCHCmnDlSetUePmi
15741  *     Purpose:  This function performs PMI validation and
15742  *        updates it to the ueCb.
15743  *
15744  *     Invoked by: rgSCHCmnDlCqiInd
15745  *
15746  *  @param[in]  RgSchCellCb        *cell
15747  *  @param[in]  RgSchUeCb          *ue
15748  *  @param[in]  U8                 pmi
15749  *  @return  Void
15750  *
15751  **/
15752 #ifdef ANSI
15753 PRIVATE S16 rgSCHCmnDlSetUePmi
15754 (
15755 RgSchCellCb        *cell,
15756 RgSchUeCb          *ue,
15757 U8                 pmi
15758 )
15759 #else
15760 PRIVATE S16 rgSCHCmnDlSetUePmi(cell, ue, pmi)
15761 RgSchCellCb        *cell;
15762 RgSchUeCb          *ue;
15763 U8                 pmi;
15764 #endif
15765 {
15766    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
15767
15768    if (ue->txModeTransCmplt == FALSE)
15769    {
15770        return RFAILED;
15771    }
15772  
15773    if (cell->numTxAntPorts == 2)
15774    {
15775       if (pmi > 3)
15776       {
15777          return RFAILED;
15778       }
15779       if (ueDl->mimoInfo.ri == 2)
15780       {
15781          /*ccpu00118150 - MOD - changed pmi value validation from 0 to 2*/
15782          /* PMI 2 and 3 are invalid incase of 2 TxAnt and 2 Layered SM */
15783          if (pmi == 2 || pmi == 3)
15784          {
15785             return RFAILED;
15786          }
15787          ueDl->mimoInfo.pmi = pmi+1;
15788       }
15789       else
15790       {
15791          ueDl->mimoInfo.pmi = pmi;
15792       }
15793    }
15794    else if (cell->numTxAntPorts == 4)
15795    {
15796       if (pmi > 15)
15797       {
15798          return RFAILED;
15799       }
15800       ueDl->mimoInfo.pmi = pmi;
15801    }
15802    /* Reset the No PMI Flag in forceTD */
15803    RG_SCH_CMN_UNSET_FORCE_TD(ue, cell, RG_SCH_CMN_TD_NO_PMI);
15804    return ROK;
15805 }
15806
15807 /**
15808  * @brief This function Updates the DL CQI on PUCCH for the UE.
15809  *
15810  * @details
15811  *
15812  *     Function: rgSCHCmnDlProcCqiMode10
15813  *
15814  *     This function updates the DL CQI on PUCCH for the UE.
15815  *
15816  *     Invoked by: rgSCHCmnDlCqiOnPucchInd
15817  *
15818  *     Processing Steps:
15819  *
15820  *  @param[in] RgSchCellCb     *cell
15821  *  @param[in] RgSchUeCb       *ue
15822  *  @param[in] TfuDlCqiRpt     *dlCqiRpt
15823  *  @return  S16
15824  *      -# ROK
15825  *      -# RFAILED
15826  **/
15827 #ifdef RGR_CQI_REPT
15828 #ifdef ANSI
15829 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode10
15830 (
15831  RgSchCellCb        *cell,
15832  RgSchUeCb          *ue,
15833  TfuDlCqiPucch      *pucchCqi,
15834  Bool               *isCqiAvail
15835  )
15836 #else
15837 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode10(cell, ue, pucchCqi, isCqiAvail)
15838  RgSchCellCb        *cell;
15839  RgSchUeCb          *ue;
15840  TfuDlCqiPucch      *pucchCqi;
15841  Bool               *isCqiAvail;
15842 #endif
15843 #else
15844 #ifdef ANSI
15845 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode10
15846 (
15847  RgSchCellCb        *cell,
15848  RgSchUeCb          *ue,
15849  TfuDlCqiPucch      *pucchCqi
15850  )
15851 #else
15852 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode10(cell, ue, pucchCqi)
15853  RgSchCellCb        *cell;
15854  RgSchUeCb          *ue;
15855  TfuDlCqiPucch      *pucchCqi;
15856 #endif
15857 #endif
15858 {
15859    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
15860
15861    if (pucchCqi->u.mode10Info.type == TFU_RPT_CQI)
15862    {
15863       /*ccpu00109787 - ADD - Check for non-zero CQI*/
15864       /* Checking whether the decoded CQI is a value between 1 and 15*/
15865       if((pucchCqi->u.mode10Info.u.cqi) && (pucchCqi->u.mode10Info.u.cqi
15866                < RG_SCH_CMN_MAX_CQI))
15867       {
15868          ueDl->cqiFlag = TRUE;
15869          ueDl->mimoInfo.cwInfo[0].cqi = pucchCqi->u.mode10Info.u.cqi;
15870          ueDl->mimoInfo.cwInfo[1].cqi = ueDl->mimoInfo.cwInfo[0].cqi;
15871          /* ccpu00117452 - MOD - Changed macro name from
15872             RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
15873 #ifdef RGR_CQI_REPT
15874          *isCqiAvail = TRUE;
15875 #endif
15876       }
15877       else
15878       {
15879          RETVOID;
15880       }
15881    }
15882    else if (pucchCqi->u.mode10Info.type == TFU_RPT_RI)
15883    {
15884       if ( RG_SCH_CMN_IS_RI_VALID(pucchCqi->u.mode10Info.u.ri) )
15885       {
15886          rgSCHCmnDlSetUeRi(cell, ue, pucchCqi->u.mode10Info.u.ri,
15887                            TRUE);
15888       }
15889       else
15890       {
15891          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,"Invalid RI value(%x) CRNTI:%d",
15892             pucchCqi->u.mode10Info.u.ri,ue->ueId);
15893          RETVOID;
15894       }
15895    }
15896 }
15897
15898 /**
15899  * @brief This function Updates the DL CQI on PUCCH for the UE.
15900  *
15901  * @details
15902  *
15903  *     Function: rgSCHCmnDlProcCqiMode11
15904  *
15905  *     This function updates the DL CQI on PUCCH for the UE.
15906  *
15907  *     Invoked by: rgSCHCmnDlCqiOnPucchInd
15908  *
15909  *     Processing Steps:
15910  *       Process CQI MODE 11
15911  *  @param[in] RgSchCellCb     *cell
15912  *  @param[in] RgSchUeCb       *ue
15913  *  @param[in] TfuDlCqiRpt     *dlCqiRpt
15914  *  @return  S16
15915  *      -# ROK
15916  *      -# RFAILED
15917  **/
15918 #ifdef RGR_CQI_REPT
15919 #ifdef ANSI
15920 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode11
15921 (
15922  RgSchCellCb        *cell,
15923  RgSchUeCb          *ue,
15924  TfuDlCqiPucch      *pucchCqi,
15925  Bool               *isCqiAvail,
15926  Bool               *is2ndCwCqiAvail
15927  )
15928 #else
15929 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode11(cell, ue, pucchCqi, isCqiAvail, is2ndCwCqiAvail)
15930  RgSchCellCb        *cell;
15931  RgSchUeCb          *ue;
15932  TfuDlCqiPucch      *pucchCqi;
15933  Bool               *isCqiAvail;
15934  Bool               *is2ndCwCqiAvail;
15935 #endif
15936 #else
15937 #ifdef ANSI
15938 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode11
15939 (
15940  RgSchCellCb        *cell,
15941  RgSchUeCb          *ue,
15942  TfuDlCqiPucch      *pucchCqi
15943  )
15944 #else
15945 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode11(cell, ue, pucchCqi)
15946  RgSchCellCb        *cell;
15947  RgSchUeCb          *ue;
15948  TfuDlCqiPucch      *pucchCqi;
15949 #endif
15950 #endif
15951 {
15952    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
15953
15954    if (pucchCqi->u.mode11Info.type == TFU_RPT_CQI)
15955    {
15956       ue->mimoInfo.puschFdbkVld  = FALSE;
15957       /*ccpu00109787 - ADD - Check for non-zero CQI*/
15958       if((pucchCqi->u.mode11Info.u.cqi.cqi) &&
15959             (pucchCqi->u.mode11Info.u.cqi.cqi < RG_SCH_CMN_MAX_CQI))
15960       {
15961          ueDl->cqiFlag = TRUE;
15962          /* ccpu00117452 - MOD - Changed macro name from
15963             RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
15964 #ifdef RGR_CQI_REPT
15965          *isCqiAvail = TRUE;
15966 #endif
15967          ueDl->mimoInfo.cwInfo[0].cqi = pucchCqi->u.mode11Info.u.cqi.cqi;
15968          if (pucchCqi->u.mode11Info.u.cqi.wideDiffCqi.pres)
15969          {
15970             RG_SCH_UPDT_CW2_CQI(ueDl->mimoInfo.cwInfo[0].cqi, \
15971                                      ueDl->mimoInfo.cwInfo[1].cqi, \
15972                                      pucchCqi->u.mode11Info.u.cqi.wideDiffCqi.val);
15973 #ifdef RGR_CQI_REPT
15974             /* ccpu00117259 - ADD - Considering second codeword CQI info
15975                incase of MIMO for CQI Reporting */
15976             *is2ndCwCqiAvail = TRUE;
15977 #endif
15978          }
15979       }
15980       else
15981       {
15982          RETVOID;
15983       }
15984       rgSCHCmnDlSetUePmi(cell, ue, \
15985             pucchCqi->u.mode11Info.u.cqi.pmi);
15986    }
15987    else if (pucchCqi->u.mode11Info.type == TFU_RPT_RI)
15988    {
15989       if( RG_SCH_CMN_IS_RI_VALID(pucchCqi->u.mode11Info.u.ri))
15990       {
15991          rgSCHCmnDlSetUeRi(cell, ue,  pucchCqi->u.mode11Info.u.ri,
15992                            TRUE);
15993       }
15994       else
15995       {
15996          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,  "Invalid RI value(%x) CRNTI:%d",
15997             pucchCqi->u.mode11Info.u.ri,ue->ueId);
15998          RETVOID;
15999       }
16000    }
16001 }
16002
16003 /**
16004  * @brief This function Updates the DL CQI on PUCCH for the UE.
16005  *
16006  * @details
16007  *
16008  *     Function: rgSCHCmnDlProcCqiMode20
16009  *
16010  *     This function updates the DL CQI on PUCCH for the UE.
16011  *
16012  *     Invoked by: rgSCHCmnDlCqiOnPucchInd
16013  *
16014  *     Processing Steps:
16015  *       Process CQI MODE 20
16016  *  @param[in] RgSchCellCb     *cell
16017  *  @param[in] RgSchUeCb       *ue
16018  *  @param[in] TfuDlCqiRpt     *dlCqiRpt
16019  *  @return  S16
16020  *      -# ROK
16021  *      -# RFAILED
16022  **/
16023 #ifdef RGR_CQI_REPT
16024 #ifdef ANSI
16025 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode20
16026 (
16027  RgSchCellCb        *cell,
16028  RgSchUeCb          *ue,
16029  TfuDlCqiPucch      *pucchCqi,
16030  Bool               *isCqiAvail
16031  )
16032 #else
16033 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode20(cell, ue, pucchCqi, isCqiAvail )
16034  RgSchCellCb        *cell;
16035  RgSchUeCb          *ue;
16036  TfuDlCqiPucch      *pucchCqi;
16037  Bool               *isCqiAvail;
16038 #endif
16039 #else
16040 #ifdef ANSI
16041 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode20
16042 (
16043  RgSchCellCb        *cell,
16044  RgSchUeCb          *ue,
16045  TfuDlCqiPucch      *pucchCqi
16046  )
16047 #else
16048 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode20(cell, ue, pucchCqi)
16049  RgSchCellCb        *cell;
16050  RgSchUeCb          *ue;
16051  TfuDlCqiPucch      *pucchCqi;
16052 #endif
16053 #endif
16054 {
16055    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
16056
16057    if (pucchCqi->u.mode20Info.type == TFU_RPT_CQI)
16058    {
16059       if (pucchCqi->u.mode20Info.u.cqi.isWideband)
16060       {
16061          /*ccpu00109787 - ADD - Check for non-zero CQI*/
16062          if((pucchCqi->u.mode20Info.u.cqi.u.wideCqi) &&
16063                (pucchCqi->u.mode20Info.u.cqi.u.wideCqi < RG_SCH_CMN_MAX_CQI))
16064          {
16065             ueDl->cqiFlag = TRUE;
16066             ueDl->mimoInfo.cwInfo[0].cqi = pucchCqi->u.mode20Info.u.cqi.\
16067                                            u.wideCqi;
16068             ueDl->mimoInfo.cwInfo[1].cqi = ueDl->mimoInfo.cwInfo[0].cqi;
16069             /* ccpu00117452 - MOD - Changed macro name from
16070                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16071 #ifdef RGR_CQI_REPT
16072             *isCqiAvail = TRUE;
16073 #endif
16074          }
16075          else
16076          {
16077             RETVOID;
16078          }
16079       }
16080    }
16081    else if (pucchCqi->u.mode20Info.type == TFU_RPT_RI)
16082    {
16083       if(RG_SCH_CMN_IS_RI_VALID(pucchCqi->u.mode20Info.u.ri))
16084       {
16085          rgSCHCmnDlSetUeRi(cell, ue, pucchCqi->u.mode20Info.u.ri, 
16086                            TRUE);
16087       }
16088       else
16089       {
16090          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,"Invalid RI value(%x) CRNTI:%d",
16091             pucchCqi->u.mode20Info.u.ri,ue->ueId);
16092          RETVOID;
16093       }
16094    }
16095 }
16096
16097
16098 /**
16099  * @brief This function Updates the DL CQI on PUCCH for the UE.
16100  *
16101  * @details
16102  *
16103  *     Function: rgSCHCmnDlProcCqiMode21
16104  *
16105  *     This function updates the DL CQI on PUCCH for the UE.
16106  *
16107  *     Invoked by: rgSCHCmnDlCqiOnPucchInd
16108  *
16109  *     Processing Steps:
16110  *       Process CQI MODE 21
16111  *  @param[in] RgSchCellCb     *cell
16112  *  @param[in] RgSchUeCb       *ue
16113  *  @param[in] TfuDlCqiRpt     *dlCqiRpt
16114  *  @return  S16
16115  *      -# ROK
16116  *      -# RFAILED
16117  **/
16118 #ifdef RGR_CQI_REPT
16119 #ifdef ANSI
16120 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode21
16121 (
16122  RgSchCellCb        *cell,
16123  RgSchUeCb          *ue,
16124  TfuDlCqiPucch      *pucchCqi,
16125  Bool               *isCqiAvail,
16126  Bool               *is2ndCwCqiAvail
16127  )
16128 #else
16129 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode21(cell, ue, pucchCqi, isCqiAvail, is2ndCwCqiAvail)
16130    RgSchCellCb        *cell;
16131    RgSchUeCb          *ue;
16132  TfuDlCqiPucch        *pucchCqi;
16133    TfuDlCqiRpt        *dlCqiRpt;
16134    Bool               *isCqiAvail;
16135    Bool               *is2ndCwCqiAvail;
16136 #endif
16137 #else
16138 #ifdef ANSI
16139 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode21
16140 (
16141  RgSchCellCb        *cell,
16142  RgSchUeCb          *ue,
16143  TfuDlCqiPucch      *pucchCqi
16144  )
16145 #else
16146 PRIVATE INLINE Void rgSCHCmnDlProcCqiMode21(cell, ue, pucchCqi)
16147  RgSchCellCb        *cell;
16148  RgSchUeCb          *ue;
16149  TfuDlCqiPucch      *pucchCqi;
16150 #endif
16151 #endif
16152 {
16153    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
16154
16155    if (pucchCqi->u.mode21Info.type == TFU_RPT_CQI)
16156    {
16157       ue->mimoInfo.puschFdbkVld  = FALSE;
16158       if (pucchCqi->u.mode21Info.u.cqi.isWideband)
16159       {
16160          /*ccpu00109787 - ADD - Check for non-zero CQI*/
16161          if((pucchCqi->u.mode21Info.u.cqi.u.wideCqi.cqi) &&
16162                (pucchCqi->u.mode21Info.u.cqi.u.wideCqi.cqi < RG_SCH_CMN_MAX_CQI))
16163          {
16164             ueDl->cqiFlag = TRUE;
16165             ueDl->mimoInfo.cwInfo[0].cqi = pucchCqi->u.mode21Info.u.cqi.\
16166                                            u.wideCqi.cqi;
16167             if (pucchCqi->u.mode21Info.u.cqi.u.wideCqi.diffCqi.pres)
16168             {
16169                RG_SCH_UPDT_CW2_CQI(ueDl->mimoInfo.cwInfo[0].cqi, \
16170                                      ueDl->mimoInfo.cwInfo[1].cqi, \
16171                                      pucchCqi->u.mode21Info.u.cqi.u.wideCqi.diffCqi.val);
16172 #ifdef RGR_CQI_REPT
16173                /* ccpu00117259 - ADD - Considering second codeword CQI info
16174                   incase of MIMO for CQI Reporting */
16175                *is2ndCwCqiAvail = TRUE;
16176 #endif
16177             }
16178             /* ccpu00117452 - MOD - Changed macro name from
16179                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16180 #ifdef RGR_CQI_REPT
16181             *isCqiAvail = TRUE;
16182 #endif
16183          }
16184          else
16185          {
16186             RETVOID;
16187          }
16188          rgSCHCmnDlSetUePmi(cell, ue, \
16189                pucchCqi->u.mode21Info.u.cqi.u.wideCqi.pmi);
16190       }
16191    }
16192    else if (pucchCqi->u.mode21Info.type == TFU_RPT_RI)
16193    {
16194       if(RG_SCH_CMN_IS_RI_VALID(pucchCqi->u.mode21Info.u.ri))
16195       {
16196          rgSCHCmnDlSetUeRi(cell, ue, pucchCqi->u.mode21Info.u.ri,
16197                            TRUE);
16198       }
16199       else
16200       {
16201          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,  "Invalid RI value(%x) CRNTI:%d",
16202             pucchCqi->u.mode21Info.u.ri,ue->ueId);
16203          RETVOID;
16204       }
16205    }
16206 }
16207
16208
16209 /**
16210  * @brief This function Updates the DL CQI on PUCCH for the UE.
16211  *
16212  * @details
16213  *
16214  *     Function: rgSCHCmnDlCqiOnPucchInd
16215  *
16216  *     This function updates the DL CQI on PUCCH for the UE.
16217  *
16218  *     Invoked by: rgSCHCmnDlCqiInd
16219  *
16220  *     Processing Steps:
16221  *     - Depending on the reporting mode of the PUCCH, the CQI/PMI/RI values
16222  *       are updated and stored for each UE
16223  *
16224  *  @param[in] RgSchCellCb     *cell
16225  *  @param[in] RgSchUeCb       *ue
16226  *  @param[in] TfuDlCqiRpt     *dlCqiRpt
16227  *  @return  S16
16228  *      -# ROK
16229  *      -# RFAILED
16230  **/
16231 #ifdef RGR_CQI_REPT
16232 #ifdef ANSI
16233 PRIVATE Void rgSCHCmnDlCqiOnPucchInd
16234 (
16235  RgSchCellCb        *cell,
16236  RgSchUeCb          *ue,
16237  TfuDlCqiPucch      *pucchCqi,
16238  RgrUeCqiRept       *ueCqiRept,
16239  Bool               *isCqiAvail,
16240  Bool               *is2ndCwCqiAvail
16241  )
16242 #else
16243 PRIVATE Void rgSCHCmnDlCqiOnPucchInd(cell, ue, pucchCqi, ueCqiRept, isCqiAvail, is2ndCwCqiAvail)
16244  RgSchCellCb        *cell;
16245  RgSchUeCb          *ue;
16246  TfuDlCqiPucch      *pucchCqi;
16247  RgrUeCqiRept       *ueCqiRept;
16248  Bool               *isCqiAvail;
16249  Bool               *is2ndCwCqiAvail;
16250 #endif
16251 #else
16252 #ifdef ANSI
16253 PRIVATE Void rgSCHCmnDlCqiOnPucchInd
16254 (
16255  RgSchCellCb        *cell,
16256  RgSchUeCb          *ue,
16257  TfuDlCqiPucch      *pucchCqi
16258  )
16259 #else
16260 PRIVATE Void rgSCHCmnDlCqiOnPucchInd(cell, ue, pucchCqi)
16261  RgSchCellCb        *cell;
16262  RgSchUeCb          *ue;
16263  TfuDlCqiPucch      *pucchCqi;
16264 #endif
16265 #endif
16266 {
16267    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
16268
16269    /* ccpu00117452 - MOD - Changed
16270       RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16271 #ifdef RGR_CQI_REPT
16272    /* Save CQI mode information in the report */
16273    ueCqiRept->cqiMode = pucchCqi->mode;
16274 #endif
16275
16276    switch(pucchCqi->mode)
16277    {
16278       case TFU_PUCCH_CQI_MODE10:
16279 #ifdef RGR_CQI_REPT
16280          rgSCHCmnDlProcCqiMode10(cell, ue, pucchCqi, isCqiAvail);
16281 #else
16282          rgSCHCmnDlProcCqiMode10(cell, ue, pucchCqi);
16283 #endif
16284          ueDl->cqiFlag = TRUE;
16285          break;
16286       case TFU_PUCCH_CQI_MODE11:
16287 #ifdef RGR_CQI_REPT
16288          rgSCHCmnDlProcCqiMode11(cell, ue, pucchCqi, isCqiAvail,
16289                 is2ndCwCqiAvail);
16290 #else
16291          rgSCHCmnDlProcCqiMode11(cell, ue, pucchCqi);
16292 #endif
16293          ueDl->cqiFlag = TRUE;
16294          break;
16295       case TFU_PUCCH_CQI_MODE20:
16296 #ifdef RGR_CQI_REPT
16297          rgSCHCmnDlProcCqiMode20(cell, ue, pucchCqi, isCqiAvail);
16298 #else
16299          rgSCHCmnDlProcCqiMode20(cell, ue, pucchCqi);
16300 #endif
16301          ueDl->cqiFlag = TRUE;
16302          break;
16303       case TFU_PUCCH_CQI_MODE21:
16304 #ifdef RGR_CQI_REPT
16305          rgSCHCmnDlProcCqiMode21(cell, ue, pucchCqi, isCqiAvail,
16306                 is2ndCwCqiAvail);
16307 #else
16308          rgSCHCmnDlProcCqiMode21(cell, ue, pucchCqi);
16309 #endif
16310          ueDl->cqiFlag = TRUE;
16311          break;
16312       default:
16313          {
16314             RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,"Unknown CQI Mode %d",
16315                pucchCqi->mode,ue->ueId);
16316             /* ccpu00117452 - MOD - Changed macro name from
16317                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16318 #ifdef RGR_CQI_REPT
16319             *isCqiAvail = FALSE;
16320 #endif
16321          }
16322          break;
16323    }
16324
16325   RETVOID;
16326 }  /* rgSCHCmnDlCqiOnPucchInd */
16327
16328
16329 /**
16330  * @brief This function Updates the DL CQI on PUSCH for the UE.
16331  *
16332  * @details
16333  *
16334  *     Function: rgSCHCmnDlCqiOnPuschInd
16335  *
16336  *     This function updates the DL CQI on PUSCH for the UE.
16337  *
16338  *     Invoked by: rgSCHCmnDlCqiInd
16339  *
16340  *     Processing Steps:
16341  *     - Depending on the reporting mode of the PUSCH, the CQI/PMI/RI values
16342  *       are updated and stored for each UE
16343  *
16344  *  @param[in] RgSchCellCb     *cell
16345  *  @param[in] RgSchUeCb       *ue
16346  *  @param[in] TfuDlCqiRpt     *dlCqiRpt
16347  *  @return  S16
16348  *      -# ROK
16349  *      -# RFAILED
16350  **/
16351 #ifdef RGR_CQI_REPT
16352 #ifdef ANSI
16353 PRIVATE Void rgSCHCmnDlCqiOnPuschInd
16354 (
16355  RgSchCellCb        *cell,
16356  RgSchUeCb          *ue,
16357  TfuDlCqiPusch      *puschCqi,
16358  RgrUeCqiRept       *ueCqiRept,
16359  Bool               *isCqiAvail,
16360  Bool               *is2ndCwCqiAvail
16361  )
16362 #else
16363 PRIVATE Void rgSCHCmnDlCqiOnPuschInd(cell, ue, puschCqi, ueCqiRept, isCqiAvail, is2ndCwCqiAvail)
16364  RgSchCellCb        *cell;
16365  RgSchUeCb          *ue;
16366  TfuDlCqiPusch      *puschCqi;
16367  RgrUeCqiRept       *ueCqiRept;
16368  Bool               *isCqiAvail;
16369  Bool               *is2ndCwCqiAvail;
16370 #endif
16371 #else
16372 #ifdef ANSI
16373 PRIVATE Void rgSCHCmnDlCqiOnPuschInd
16374 (
16375  RgSchCellCb        *cell,
16376  RgSchUeCb          *ue,
16377  TfuDlCqiPusch      *puschCqi
16378  )
16379 #else
16380 PRIVATE Void rgSCHCmnDlCqiOnPuschInd(cell, ue, puschCqi)
16381    RgSchCellCb        *cell;
16382    RgSchUeCb          *ue;
16383    TfuDlCqiPusch      *puschCqi;
16384 #endif
16385 #endif
16386 {
16387    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
16388    U32 prevRiVal = 0; 
16389    if (puschCqi->ri.pres == PRSNT_NODEF)
16390    {
16391       if (RG_SCH_CMN_IS_RI_VALID(puschCqi->ri.val))
16392       {
16393          /* Saving the previous ri value to revert back
16394             in  case PMI update failed */
16395          if (RGR_UE_TM_4 == ue->mimoInfo.txMode ) /* Cheking for TM4. TM8 check later */
16396          {
16397             prevRiVal = ueDl->mimoInfo.ri;
16398          }
16399          rgSCHCmnDlSetUeRi(cell, ue, puschCqi->ri.val, FALSE);
16400       }
16401       else
16402       {
16403          RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,"Invalid RI value(%x) CRNTI:%d",
16404             puschCqi->ri.val,ue->ueId);
16405          RETVOID;
16406       }
16407    }
16408    ue->mimoInfo.puschFdbkVld  = FALSE;
16409    /* ccpu00117452 - MOD - Changed macro name from
16410       RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16411 #ifdef RGR_CQI_REPT
16412    /* Save CQI mode information in the report */
16413    ueCqiRept->cqiMode = puschCqi->mode;
16414    /* ccpu00117259 - DEL - removed default setting of isCqiAvail to TRUE */
16415 #endif
16416
16417    switch(puschCqi->mode)
16418    {
16419       case TFU_PUSCH_CQI_MODE_20:
16420          /*ccpu00109787 - ADD - Check for non-zero CQI*/
16421          /* Checking whether the decoded CQI is a value between 1 and 15*/
16422          if((puschCqi->u.mode20Info.wideBandCqi) &&
16423                (puschCqi->u.mode20Info.wideBandCqi < RG_SCH_CMN_MAX_CQI))
16424          {
16425             ueDl->mimoInfo.cwInfo[0].cqi = puschCqi->u.mode20Info.wideBandCqi;
16426             ueDl->mimoInfo.cwInfo[1].cqi = ueDl->mimoInfo.cwInfo[0].cqi;
16427             /* ccpu00117452 - MOD - Changed macro name from
16428                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16429 #ifdef RGR_CQI_REPT
16430            *isCqiAvail = TRUE;
16431 #endif
16432          }
16433          else
16434          {
16435             RETVOID;
16436          }
16437          break;
16438       case TFU_PUSCH_CQI_MODE_30:
16439          /*ccpu00109787 - ADD - Check for non-zero CQI*/
16440          if((puschCqi->u.mode30Info.wideBandCqi) &&
16441                (puschCqi->u.mode30Info.wideBandCqi < RG_SCH_CMN_MAX_CQI))
16442          {
16443             ueDl->mimoInfo.cwInfo[0].cqi = puschCqi->u.mode30Info.wideBandCqi;
16444             ueDl->mimoInfo.cwInfo[1].cqi = ueDl->mimoInfo.cwInfo[0].cqi;
16445             /* ccpu00117452 - MOD - Changed macro name from
16446                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16447 #ifdef RGR_CQI_REPT
16448             *isCqiAvail = TRUE;
16449 #endif
16450 #ifdef CA_DBG
16451             {
16452                extern U32 gACqiRcvdCount;
16453                gACqiRcvdCount++;
16454             
16455             }
16456 #endif
16457          }
16458          else
16459          {
16460             RETVOID;
16461          }
16462          break;
16463       case TFU_PUSCH_CQI_MODE_12:
16464          /*ccpu00109787 - ADD - Check for non-zero CQI*/
16465          if((puschCqi->u.mode12Info.cqiIdx[0]) &&
16466                (puschCqi->u.mode12Info.cqiIdx[0] < RG_SCH_CMN_MAX_CQI))
16467          {
16468             ueDl->mimoInfo.cwInfo[0].cqi = puschCqi->u.mode12Info.cqiIdx[0];
16469             /* ccpu00117452 - MOD - Changed macro name from
16470                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16471 #ifdef RGR_CQI_REPT
16472             *isCqiAvail = TRUE;
16473 #endif
16474          }
16475          else
16476          {
16477             RETVOID;
16478          }
16479          if((puschCqi->u.mode12Info.cqiIdx[1]) &&
16480                (puschCqi->u.mode12Info.cqiIdx[1] < RG_SCH_CMN_MAX_CQI))
16481          {
16482             ueDl->mimoInfo.cwInfo[1].cqi = puschCqi->u.mode12Info.cqiIdx[1];
16483             /* ccpu00117452 - MOD - Changed macro name from
16484                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16485 #ifdef RGR_CQI_REPT
16486             /* ccpu00117259 - ADD - Considering second codeword CQI info
16487                incase of MIMO for CQI Reporting */
16488             *is2ndCwCqiAvail = TRUE;
16489 #endif
16490          }
16491          else
16492          {
16493             RETVOID;
16494          }
16495          ue->mimoInfo.puschFdbkVld  = TRUE;
16496          ue->mimoInfo.puschPmiInfo.mode = TFU_PUSCH_CQI_MODE_12;
16497          ue->mimoInfo.puschPmiInfo.u.mode12Info = puschCqi->u.mode12Info;
16498          /*  : resetting this is time based. Make use of CQI reporting
16499           * periodicity, DELTA's in determining the exact time at which this
16500           * need to be reset. */
16501          break;
16502       case TFU_PUSCH_CQI_MODE_22:
16503          /*ccpu00109787 - ADD - Check for non-zero CQI*/
16504          if((puschCqi->u.mode22Info.wideBandCqi[0]) &&
16505                (puschCqi->u.mode22Info.wideBandCqi[0] < RG_SCH_CMN_MAX_CQI))
16506          {
16507             ueDl->mimoInfo.cwInfo[0].cqi = puschCqi->u.mode22Info.wideBandCqi[0];
16508             /* ccpu00117452 - MOD - Changed macro name from
16509                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16510 #ifdef RGR_CQI_REPT
16511             *isCqiAvail = TRUE;
16512 #endif
16513          }
16514          else
16515          {
16516             RETVOID;
16517          }
16518          if((puschCqi->u.mode22Info.wideBandCqi[1]) &&
16519                (puschCqi->u.mode22Info.wideBandCqi[1] < RG_SCH_CMN_MAX_CQI))
16520          {
16521             ueDl->mimoInfo.cwInfo[1].cqi = puschCqi->u.mode22Info.wideBandCqi[1];
16522             /* ccpu00117452 - MOD - Changed macro name from
16523                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16524 #ifdef RGR_CQI_REPT
16525             /* ccpu00117259 - ADD - Considering second codeword CQI info
16526                incase of MIMO for CQI Reporting */
16527             *is2ndCwCqiAvail = TRUE;
16528 #endif
16529          }
16530          else
16531          {
16532             RETVOID;
16533          }
16534          rgSCHCmnDlSetUePmi(cell, ue, puschCqi->u.mode22Info.wideBandPmi);
16535          ue->mimoInfo.puschFdbkVld  = TRUE;
16536          ue->mimoInfo.puschPmiInfo.mode = TFU_PUSCH_CQI_MODE_22;
16537          ue->mimoInfo.puschPmiInfo.u.mode22Info = puschCqi->u.mode22Info;
16538          break;
16539       case TFU_PUSCH_CQI_MODE_31:
16540          /*ccpu00109787 - ADD - Check for non-zero CQI*/
16541          if((puschCqi->u.mode31Info.wideBandCqi[0]) &&
16542                (puschCqi->u.mode31Info.wideBandCqi[0] < RG_SCH_CMN_MAX_CQI))
16543          {
16544             ueDl->mimoInfo.cwInfo[0].cqi = puschCqi->u.mode31Info.wideBandCqi[0];
16545             /* ccpu00117452 - MOD - Changed macro name from
16546                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16547 #ifdef RGR_CQI_REPT
16548             *isCqiAvail = TRUE;
16549 #endif
16550          }
16551          if (ueDl->mimoInfo.ri > 1)
16552          {
16553            if((puschCqi->u.mode31Info.wideBandCqi[1]) &&
16554                (puschCqi->u.mode31Info.wideBandCqi[1] < RG_SCH_CMN_MAX_CQI))
16555            {
16556              ueDl->mimoInfo.cwInfo[1].cqi = puschCqi->u.mode31Info.wideBandCqi[1];
16557             /* ccpu00117452 - MOD - Changed macro name from
16558                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16559 #ifdef RGR_CQI_REPT
16560             /* ccpu00117259 - ADD - Considering second codeword CQI info
16561                incase of MIMO for CQI Reporting */
16562              *is2ndCwCqiAvail = TRUE;
16563 #endif
16564            }
16565          }
16566          if (rgSCHCmnDlSetUePmi(cell, ue, puschCqi->u.mode31Info.pmi) != ROK)
16567          {
16568             /* To avoid Rank and PMI inconsistency */
16569             if ((puschCqi->ri.pres == PRSNT_NODEF) &&
16570                 (RGR_UE_TM_4 == ue->mimoInfo.txMode)) /* checking for TM4. TM8 check later */
16571             {
16572                ueDl->mimoInfo.ri = prevRiVal;
16573             }
16574          }
16575          ue->mimoInfo.puschPmiInfo.mode = TFU_PUSCH_CQI_MODE_31;
16576          ue->mimoInfo.puschPmiInfo.u.mode31Info = puschCqi->u.mode31Info;
16577          break;
16578       default:
16579          {
16580             RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,  "Unknown CQI Mode %d CRNTI:%d",
16581                puschCqi->mode,ue->ueId);
16582             /*  CQI decoding failed revert the RI to previous value */
16583             if ((puschCqi->ri.pres == PRSNT_NODEF) &&
16584                 (RGR_UE_TM_4 == ue->mimoInfo.txMode)) /* checking for TM4. TM8 check later */
16585             {
16586                ueDl->mimoInfo.ri = prevRiVal;
16587             }
16588             /* ccpu00117452 - MOD - Changed macro name from
16589                RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16590 #ifdef RGR_CQI_REPT
16591            *isCqiAvail = FALSE;
16592             /* ccpu00117259 - ADD - Considering second codeword CQI info
16593                incase of MIMO for CQI Reporting */
16594             *is2ndCwCqiAvail = FALSE;
16595 #endif
16596          }
16597          break;
16598    }
16599
16600    RETVOID;
16601 }  /* rgSCHCmnDlCqiOnPuschInd */
16602
16603 \f
16604 /**
16605  * @brief This function Updates the DL CQI for the UE.
16606  *
16607  * @details
16608  *
16609  *     Function: rgSCHCmnDlCqiInd
16610  *     Purpose:  Updates the DL CQI for the UE
16611  *
16612  *     Invoked by: TOM
16613  *
16614  *  @param[in]  RgSchCellCb        *cell
16615  *  @param[in]  RgSchUeCb          *ue
16616  *  @param[in]  TfuDlCqiRpt        *dlCqi
16617  *  @return  Void
16618  *
16619  **/
16620 #ifdef ANSI
16621 Void rgSCHCmnDlCqiInd
16622 (
16623 RgSchCellCb        *cell,
16624 RgSchUeCb          *ue,
16625 Bool               isPucchInfo,
16626 Void               *dlCqi,
16627 CmLteTimingInfo    timingInfo
16628 )
16629 #else
16630 Void rgSCHCmnDlCqiInd(cell, ue, isPucchInfo, dlCqi, timingInfo)
16631 RgSchCellCb        *cell;
16632 RgSchUeCb          *ue;
16633 Bool               isPucchInfo;
16634 Void               *dlCqi;
16635 CmLteTimingInfo    timingInfo;
16636 #endif
16637 {
16638    RgSchCmnCell  *cellSch = RG_SCH_CMN_GET_CELL(cell);
16639 /* ccpu00117452 - MOD - Changed macro name from
16640    RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16641 #ifdef RGR_CQI_REPT
16642    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
16643    RgrUeCqiRept   ueCqiRept = {{0}};
16644    Bool           isCqiAvail = FALSE;
16645    /* ccpu00117259 - ADD - Considering second codeword CQI info
16646       incase of MIMO for CQI Reporting */
16647    Bool           is2ndCwCqiAvail = FALSE;
16648 #endif
16649
16650
16651 #ifdef RGR_CQI_REPT
16652    if (isPucchInfo)
16653    {
16654       rgSCHCmnDlCqiOnPucchInd(cell, ue, (TfuDlCqiPucch *)dlCqi, &ueCqiRept, &isCqiAvail, &is2ndCwCqiAvail);
16655    }
16656    else
16657    {
16658       rgSCHCmnDlCqiOnPuschInd(cell, ue, (TfuDlCqiPusch *)dlCqi, &ueCqiRept,  &isCqiAvail, &is2ndCwCqiAvail);
16659    }
16660 #else
16661    if (isPucchInfo)
16662    {
16663       rgSCHCmnDlCqiOnPucchInd(cell, ue, (TfuDlCqiPucch *)dlCqi);
16664    }
16665    else
16666    {
16667       rgSCHCmnDlCqiOnPuschInd(cell, ue, (TfuDlCqiPusch *)dlCqi);
16668    }
16669 #endif
16670
16671 #ifdef CQI_CONFBITMASK_DROP
16672    if(!ue->cqiConfBitMask)
16673    {
16674       if (ueDl->mimoInfo.cwInfo[0].cqi >15)
16675       {
16676          ueDl->mimoInfo.cwInfo[0].cqi = ue->prevCqi;
16677          ueDl->mimoInfo.cwInfo[1].cqi = ue->prevCqi;
16678       }
16679       else if ( ueDl->mimoInfo.cwInfo[0].cqi >= ue->prevCqi)
16680       {
16681          ue->prevCqi = ueDl->mimoInfo.cwInfo[0].cqi;
16682       }
16683       else
16684       {
16685          U8 dlCqiDeltaPrev = 0;
16686          dlCqiDeltaPrev = ue->prevCqi - ueDl->mimoInfo.cwInfo[0].cqi;
16687          if (dlCqiDeltaPrev > 3)
16688             dlCqiDeltaPrev = 3;
16689          if ((ue->prevCqi - dlCqiDeltaPrev) < 6)
16690          {
16691             ue->prevCqi = 6;
16692          }
16693          else 
16694          {
16695             ue->prevCqi = ue->prevCqi - dlCqiDeltaPrev;
16696          }
16697          ueDl->mimoInfo.cwInfo[0].cqi = ue->prevCqi;
16698          ueDl->mimoInfo.cwInfo[1].cqi = ue->prevCqi;
16699
16700       }
16701    }
16702 #endif
16703
16704 /* ccpu00117452 - MOD - Changed macro name from
16705    RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
16706 #ifdef RGR_CQI_REPT
16707    /* ccpu00117259 - ADD - Considering second codeword CQI info
16708       incase of MIMO for CQI Reporting - added is2ndCwCqiAvail\
16709       in 'if' condition*/
16710    if (RG_SCH_CQIR_IS_PUSHNCQI_ENBLE(ue) && (isCqiAvail || is2ndCwCqiAvail))
16711    {
16712       ueCqiRept.cqi[0] = ueDl->mimoInfo.cwInfo[0].cqi;
16713
16714    /* ccpu00117259 - ADD - Considering second codeword CQI info
16715       incase of MIMO for CQI Reporting - added is2ndCwCqiAvail
16716       in 'if' condition*/
16717       ueCqiRept.cqi[1] = 0;
16718       if(is2ndCwCqiAvail)
16719       {
16720          ueCqiRept.cqi[1] = ueDl->mimoInfo.cwInfo[1].cqi;
16721       }
16722       rgSCHCmnUeDlPwrCtColltCqiRept(cell, ue, &ueCqiRept);
16723
16724    }
16725 #endif
16726 #ifdef DL_LA
16727    rgSCHCmnDlSetUeAllocLmtLa(cell, ue);
16728    rgSCHCheckAndSetTxScheme(cell, ue);
16729 #else
16730 #ifdef EMTC_ENABLE   
16731    rgSCHCmnDlSetUeAllocLmt(cell, RG_SCH_CMN_GET_DL_UE(ue,cell), ue->isEmtcUe);
16732 #else 
16733    rgSCHCmnDlSetUeAllocLmt(cell, RG_SCH_CMN_GET_DL_UE(ue,cell), FALSE);
16734 #endif   
16735 #endif
16736
16737    if (cellSch->dl.isDlFreqSel)
16738    {
16739       cellSch->apisDlfs->rgSCHDlfsDlCqiInd(cell, ue, isPucchInfo, dlCqi, timingInfo);
16740    }
16741 #ifdef LTEMAC_SPS
16742    /* Call SPS module to update CQI indication */
16743    rgSCHCmnSpsDlCqiIndHndlr(cell, ue, timingInfo);
16744 #endif
16745    /* Call Specific scheduler to process on dlCqiInd */
16746 #ifdef EMTC_ENABLE
16747    if((TRUE == cell->emtcEnable) && (TRUE == ue->isEmtcUe))
16748    {
16749       cellSch->apisEmtcDl->rgSCHDlCqiInd(cell, ue, isPucchInfo, dlCqi);
16750    }
16751    else
16752 #endif
16753    {
16754       cellSch->apisDl->rgSCHDlCqiInd(cell, ue, isPucchInfo, dlCqi);
16755    }
16756
16757 #ifdef RG_PFS_STATS
16758    ue->pfsStats.cqiStats[(RG_SCH_GET_SCELL_INDEX(ue, cell))].avgCqi += 
16759       ueDl->mimoInfo.cwInfo[0].cqi;
16760    ue->pfsStats.cqiStats[(RG_SCH_GET_SCELL_INDEX(ue, cell))].totalCqiOcc++; 
16761 #endif
16762
16763 #ifdef SCH_STATS
16764    ueDl->avgCqi +=  ueDl->mimoInfo.cwInfo[0].cqi;
16765    ueDl->numCqiOccns++;
16766    if (ueDl->mimoInfo.ri == 1)
16767    {
16768       ueDl->numRi1++;
16769    }
16770    else
16771    {
16772       ueDl->numRi2++;
16773    }
16774 #endif
16775
16776 #ifdef TENB_STATS
16777    ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(cell)].dlSumCw0Cqi +=  ueDl->mimoInfo.cwInfo[0].cqi;
16778    ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(cell)].dlSumCw1Cqi +=  ueDl->mimoInfo.cwInfo[1].cqi;
16779    ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(cell)].dlNumCw0Cqi ++;
16780    ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(cell)].dlNumCw1Cqi ++;
16781    cell->tenbStats->sch.dlSumCw0Cqi +=  ueDl->mimoInfo.cwInfo[0].cqi;
16782    cell->tenbStats->sch.dlSumCw1Cqi +=  ueDl->mimoInfo.cwInfo[1].cqi;
16783    cell->tenbStats->sch.dlNumCw0Cqi ++;
16784    cell->tenbStats->sch.dlNumCw1Cqi ++;
16785 #endif
16786    RETVOID;
16787 }
16788
16789 #ifdef TFU_UPGRADE
16790 /**
16791  * @brief This function calculates the wideband CQI from SNR
16792  *            reported for each RB.
16793  *
16794  * @details
16795  *
16796  *     Function: rgSCHCmnCalcWcqiFrmSnr
16797  *     Purpose:  Wideband CQI calculation from SNR
16798  *
16799  *     Invoked by: RG SCH
16800  *
16801  *  @param[in]  RgSchCellCb        *cell
16802  *  @param[in]  TfuSrsRpt        *srsRpt,
16803  *  @return  Wideband CQI
16804  *
16805  **/
16806 #ifdef ANSI
16807 PRIVATE U8 rgSCHCmnCalcWcqiFrmSnr
16808 (
16809  RgSchCellCb        *cell,
16810  TfuSrsRpt        *srsRpt
16811  )
16812 #else
16813 PRIVATE U8 rgSCHCmnCalcWcqiFrmSnr(cell,srsRpt)
16814    RgSchCellCb        *cell;
16815    TfuSrsRpt            *srsRpt;
16816 #endif
16817 {
16818    U8 wideCqi=1; /*Calculated value from SNR*/
16819    /*Need to map a certain SNR with a WideCQI value.
16820     * The CQI calculation is still primitive. Further, need to
16821     * use a improvized method for calculating WideCQI from SNR*/
16822        if (srsRpt->snr[0] <=50)
16823        {
16824            wideCqi=3;
16825        }
16826        else if (srsRpt->snr[0]>=51 && srsRpt->snr[0] <=100)
16827        {
16828            wideCqi=6;
16829        }
16830        else if (srsRpt->snr[0]>=101 && srsRpt->snr[0] <=150)
16831        {
16832            wideCqi=9;
16833        }
16834        else if (srsRpt->snr[0]>=151 && srsRpt->snr[0] <=200)
16835        {
16836            wideCqi=12;
16837        }
16838        else if (srsRpt->snr[0]>=201 && srsRpt->snr[0] <=250)
16839        {
16840            wideCqi=14;
16841        }
16842        else
16843        {
16844            wideCqi=15;
16845        }
16846    return (wideCqi);
16847 }/*rgSCHCmnCalcWcqiFrmSnr*/
16848
16849
16850 /**
16851  * @brief This function Updates the SRS for the UE.
16852  *
16853  * @details
16854  *
16855  *     Function: rgSCHCmnSrsInd
16856  *     Purpose:  Updates the UL SRS for the UE
16857  *
16858  *     Invoked by: TOM
16859  *
16860  *  @param[in]  RgSchCellCb        *cell
16861  *  @param[in]  RgSchUeCb          *ue
16862  *  @param[in]  TfuSrsRpt        *srsRpt,
16863  *  @return  Void
16864  *
16865  **/
16866 #ifdef ANSI
16867 Void rgSCHCmnSrsInd
16868 (
16869  RgSchCellCb        *cell,
16870  RgSchUeCb          *ue,
16871  TfuSrsRpt        *srsRpt,
16872  CmLteTimingInfo    timingInfo
16873  )
16874 #else
16875 Void rgSCHCmnSrsInd(cell, ue, srsRpt, timingInfo)
16876     RgSchCellCb        *cell;
16877     RgSchUeCb          *ue;
16878     TfuSrsRpt            *srsRpt;
16879     CmLteTimingInfo    timingInfo;
16880 #endif
16881 {
16882     U8 wideCqi; /*Calculated value from SNR*/
16883     U32 recReqTime; /*Received Time in TTI*/
16884
16885     recReqTime = (timingInfo.sfn * RGSCH_NUM_SUB_FRAMES_5G) + timingInfo.slot;
16886     ue->srsCb.selectedAnt = (recReqTime/ue->srsCb.peri)%2;
16887     if(srsRpt->wideCqiPres)
16888     {
16889         wideCqi = srsRpt->wideCqi;
16890     }
16891     else
16892     {
16893         wideCqi = rgSCHCmnCalcWcqiFrmSnr(cell, srsRpt);
16894     }
16895     rgSCHCmnFindUlCqiUlTxAnt(cell, ue, wideCqi);
16896     RETVOID;
16897 }/*rgSCHCmnSrsInd*/
16898 #endif
16899
16900 \f
16901 /**
16902  * @brief This function is a handler for TA report for an UE.
16903  *
16904  * @details
16905  *
16906  *     Function: rgSCHCmnDlTARpt
16907  *     Purpose:  Determine based on UE_IDLE_TIME threshold,
16908  *     whether UE needs to be Linked to the scheduler's TA list OR
16909  *     if it needs a PDCCH Order.
16910  *
16911  *
16912  *     Invoked by: TOM
16913  *
16914  *  @param[in]  RgSchCellCb        *cell
16915  *  @param[in]  RgSchUeCb          *ue
16916  *  @return  Void
16917  *
16918  **/
16919 #ifdef ANSI
16920 Void rgSCHCmnDlTARpt
16921 (
16922 RgSchCellCb        *cell,
16923 RgSchUeCb          *ue
16924 )
16925 #else
16926 Void rgSCHCmnDlTARpt(cell, ue)
16927 RgSchCellCb        *cell;
16928 RgSchUeCb          *ue;
16929 #endif
16930 {
16931    RgSchCmnCell    *cellSch = RG_SCH_CMN_GET_CELL(cell);
16932    RgSchCmnDlCell  *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
16933    RgSchCmnDlUe    *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
16934    CmLListCp       poInactvLst;
16935
16936
16937    /* RACHO: If UE idle time is more than threshold, then
16938     * set its poInactv pdcch order inactivity  */
16939    /* Fix : syed Ignore if TaTmr is not configured */
16940    if ((ue->dl.taCb.cfgTaTmr) && (rgSCHCmnUeIdleExdThrsld(cell, ue) == ROK))
16941    {
16942       U32 prevDlMsk = ue->dl.dlInactvMask;
16943       U32 prevUlMsk = ue->ul.ulInactvMask;
16944       ue->dl.dlInactvMask |= RG_PDCCHODR_INACTIVE;
16945       ue->ul.ulInactvMask |= RG_PDCCHODR_INACTIVE;
16946       /* Indicate Specific scheduler for this UEs inactivity */
16947       cmLListInit(&poInactvLst);
16948       cmLListAdd2Tail(&poInactvLst, &ueDl->rachInfo.inActUeLnk);
16949       ueDl->rachInfo.inActUeLnk.node = (PTR)ue;
16950       /* Send inactivate ind only if not already sent */
16951       if (prevDlMsk == 0)
16952       {
16953          cellSch->apisDl->rgSCHDlInactvtUes(cell, &poInactvLst);
16954       }
16955       if (prevUlMsk == 0)
16956       {
16957          cellSch->apisUl->rgSCHUlInactvtUes(cell, &poInactvLst);
16958       }
16959    }
16960    else
16961    {
16962       /* Fix: ccpu00124009 Fix for loop in the linked list "cellDl->taLst" */
16963       if (!ue->dlTaLnk.node)
16964       {
16965 #ifdef EMTC_ENABLE
16966          if(cell->emtcEnable)
16967          {
16968             if(ue->isEmtcUe)
16969             {
16970                rgSCHEmtcAddToTaLst(cellDl,ue);
16971             }
16972          }
16973          else
16974 #endif
16975          {
16976
16977             cmLListAdd2Tail(&cellDl->taLst, &ue->dlTaLnk);
16978             ue->dlTaLnk.node = (PTR)ue;
16979          }
16980       }
16981       else
16982       {
16983          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
16984                "<TA>TA duplicate entry attempt failed: UEID:%u", 
16985                ue->ueId);
16986       }
16987    }
16988    RETVOID;
16989 }
16990
16991 #ifdef TFU_UPGRADE
16992 /**
16993  * @brief Indication of UL CQI.
16994  *
16995  * @details
16996  *
16997  *     Function : rgSCHCmnFindUlCqiUlTxAnt
16998  *
16999  *     - Finds the Best Tx Antenna amongst the CQIs received
17000  *         from Two Tx Antennas.
17001  *
17002  *  @param[in]  RgSchCellCb         *cell
17003  *  @param[in]  RgSchUeCb           *ue
17004  *  @param[in]   U8                 wideCqi
17005  *  @return  Void
17006  **/
17007 #ifdef ANSI
17008 PRIVATE Void rgSCHCmnFindUlCqiUlTxAnt
17009 (
17010 RgSchCellCb     *cell,
17011 RgSchUeCb       *ue,
17012 U8              wideCqi
17013 )
17014 #else
17015 PRIVATE Void rgSCHCmnFindUlCqiUlTxAnt(cell, ue, wideCqi)
17016 RgSchCellCb     *cell;
17017 RgSchUeCb       *ue;
17018 U8              wideCqi;
17019 #endif
17020 {
17021    ue->validTxAnt = 1;
17022    RETVOID;
17023 }  /* rgSCHCmnFindUlCqiUlTxAnt */
17024 #endif
17025
17026 /**
17027  * @brief Indication of UL CQI.
17028  *
17029  * @details
17030  *
17031  *     Function : rgSCHCmnUlCqiInd
17032  *
17033  *     - Updates uplink CQI information for the UE. Computes and
17034  *       stores the lowest CQI of CQIs reported in all subbands.
17035  *
17036  *  @param[in]  RgSchCellCb         *cell
17037  *  @param[in]  RgSchUeCb           *ue
17038  *  @param[in]  TfuUlCqiRpt         *ulCqiInfo
17039  *  @return  Void
17040  **/
17041 #ifdef ANSI
17042 Void rgSCHCmnUlCqiInd
17043 (
17044 RgSchCellCb          *cell,
17045 RgSchUeCb            *ue,
17046 TfuUlCqiRpt          *ulCqiInfo
17047 )
17048 #else
17049 Void rgSCHCmnUlCqiInd(cell, ue, ulCqiInfo)
17050 RgSchCellCb          *cell;
17051 RgSchUeCb            *ue;
17052 TfuUlCqiRpt          *ulCqiInfo;
17053 #endif
17054 {
17055    RgSchCmnUlUe  *ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
17056    RgSchCmnCell  *cellSch = RG_SCH_CMN_GET_CELL(cell);
17057 #ifdef UL_LA
17058    U8            iTbsNew;
17059    S32           previTbs;
17060 #endif
17061 #if (defined(SCH_STATS) || defined(TENB_STATS))
17062      CmLteUeCategory ueCtg = (CmLteUeCategory)(RG_SCH_CMN_GET_UE_CTGY(ue));
17063 #endif   
17064                   
17065    /*  consider inputs from SRS handlers about SRS occassions
17066     * in determining the UL TX Antenna selection */
17067    ueUl->crntUlCqi[0] = ulCqiInfo->wideCqi;
17068 #ifdef TFU_UPGRADE
17069    ueUl->validUlCqi = ueUl->crntUlCqi[0];
17070    ue->validTxAnt = 0;
17071 #ifdef UL_LA
17072    iTbsNew  =  rgSchCmnUlCqiToTbsTbl[cell->isCpUlExtend][ueUl->validUlCqi];
17073    previTbs =  (ueUl->ulLaCb.cqiBasediTbs + ueUl->ulLaCb.deltaiTbs)/100;
17074
17075    if (RG_ITBS_DIFF(iTbsNew, previTbs) > 5)
17076    {
17077       /* Ignore this iTBS report and mark that last iTBS report was */
17078       /* ignored so that subsequently we reset the LA algorithm     */
17079       ueUl->ulLaCb.lastiTbsIgnored = TRUE;
17080    }
17081    else
17082    {
17083       if (ueUl->ulLaCb.lastiTbsIgnored != TRUE)
17084       {
17085          ueUl->ulLaCb.cqiBasediTbs = ((20 * iTbsNew * 100) +
17086                                        (80 * ueUl->ulLaCb.cqiBasediTbs))/100;
17087       }
17088       else
17089       {
17090          /* Reset the LA as iTbs in use caught up with the value   */
17091          /* reported by UE.                                        */
17092          ueUl->ulLaCb.cqiBasediTbs = ((20 * iTbsNew * 100) +
17093                                         (80 * previTbs * 100))/100;
17094          ueUl->ulLaCb.deltaiTbs = 0;
17095          ueUl->ulLaCb.lastiTbsIgnored = FALSE;
17096       }
17097    }
17098 #endif 
17099 #endif
17100    rgSCHPwrUlCqiInd(cell, ue);
17101 #ifdef LTEMAC_SPS
17102    if (ue->ul.ulSpsCfg.isUlSpsEnabled == TRUE)
17103    {
17104       rgSCHCmnSpsUlCqiInd(cell, ue);
17105    }
17106 #endif
17107    /* Applicable to only some schedulers */
17108 #ifdef EMTC_ENABLE
17109    if((TRUE == cell->emtcEnable) && (TRUE == ue->isEmtcUe))
17110    {
17111       cellSch->apisEmtcUl->rgSCHUlCqiInd(cell, ue, ulCqiInfo);
17112    }
17113    else
17114 #endif
17115    {
17116       cellSch->apisUl->rgSCHUlCqiInd(cell, ue, ulCqiInfo);
17117    }
17118
17119 #ifdef SCH_STATS
17120    ueUl->numCqiOccns++;
17121    ueUl->avgCqi += rgSCHCmnUlGetCqi(cell, ue, ueCtg);
17122 #endif
17123
17124 #ifdef TENB_STATS
17125    {
17126       ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(cell)].ulSumCqi += rgSCHCmnUlGetCqi(cell, ue, ueCtg);
17127       ue->tenbStats->stats.nonPersistent.sch[RG_SCH_CELLINDEX(cell)].ulNumCqi ++;
17128       cell->tenbStats->sch.ulSumCqi += rgSCHCmnUlGetCqi(cell, ue, ueCtg);
17129       cell->tenbStats->sch.ulNumCqi ++;
17130    }
17131 #endif
17132
17133    RETVOID;
17134 }  /* rgSCHCmnUlCqiInd */
17135
17136 /**
17137  * @brief Returns HARQ proc for which data expected now.
17138  *
17139  * @details
17140  *
17141  *     Function: rgSCHCmnUlHqProcForUe
17142  *     Purpose:  This function returns the harq process for
17143  *               which data is expected in the current subframe.
17144  *               It does not validate that the HARQ process
17145  *               has an allocation.
17146  *
17147  *     Invoked by: TOM
17148  *
17149  *  @param[in]  RgSchCellCb        *cell
17150  *  @param[in]  CmLteTimingInfo    frm
17151  *  @param[in]  RgSchUeCb          *ue
17152  *  @param[out] RgSchUlHqProcCb    **procRef
17153  *  @return  Void
17154  **/
17155 #ifdef ANSI
17156 Void rgSCHCmnUlHqProcForUe
17157 (
17158 RgSchCellCb         *cell,
17159 CmLteTimingInfo     frm,
17160 RgSchUeCb           *ue,
17161 RgSchUlHqProcCb     **procRef
17162 )
17163 #else
17164 Void rgSCHCmnUlHqProcForUe(cell, frm, ue, procRef)
17165 RgSchCellCb         *cell;
17166 CmLteTimingInfo     frm;
17167 RgSchUeCb           *ue;
17168 RgSchUlHqProcCb     **procRef;
17169 #endif
17170 {
17171 #ifndef RG_5GTF
17172    U8 procId = rgSCHCmnGetUlHqProcIdx(&frm, cell);
17173 #endif
17174 #ifndef RG_5GTF
17175    *procRef = rgSCHUhmGetUlHqProc(cell, ue, procId);
17176 #else
17177    *procRef = rgSCHUhmGetUlProcByTime(cell, ue, frm);
17178 #endif
17179    RETVOID;
17180 }
17181
17182 #ifdef RG_UNUSED
17183 /**
17184  * @brief Update harq process for allocation.
17185  *
17186  * @details
17187  *
17188  *     Function : rgSCHCmnUpdUlHqProc
17189  *
17190  *     This function is invoked when harq process
17191  *     control block is now in a new memory location
17192  *     thus requiring a pointer/reference update.
17193  *
17194  *  @param[in] RgSchCellCb      *cell
17195  *  @param[in] RgSchUlHqProcCb  *curProc
17196  *  @param[in] RgSchUlHqProcCb  *oldProc
17197  *  @return  S16
17198  *      -# ROK
17199  *      -# RFAILED
17200  **/
17201 #ifdef ANSI
17202 S16 rgSCHCmnUpdUlHqProc
17203 (
17204 RgSchCellCb      *cell,
17205 RgSchUlHqProcCb  *curProc,
17206 RgSchUlHqProcCb  *oldProc
17207 )
17208 #else
17209 S16 rgSCHCmnUpdUlHqProc(cell, curProc, oldProc)
17210 RgSchCellCb      *cell;
17211 RgSchUlHqProcCb  *curProc;
17212 RgSchUlHqProcCb  *oldProc;
17213 #endif
17214 {
17215
17216    UNUSED(cell);
17217    UNUSED(oldProc);
17218 #if (ERRCLASS & ERRCLS_DEBUG)
17219    if (curProc->alloc == NULLP)
17220    {
17221       return RFAILED;
17222    }
17223 #endif
17224    curProc->alloc->hqProc = curProc;
17225    return ROK;
17226 }  /* rgSCHCmnUpdUlHqProc */
17227 #endif
17228
17229 /*MS_WORKAROUND for CR FIXME */
17230 /**
17231  * @brief Hsndles BSR timer expiry
17232  *
17233  * @details
17234  *
17235  *     Function : rgSCHCmnBsrTmrExpry
17236  *
17237  *     This function is invoked when periodic BSR timer expires for a UE.
17238  *
17239  *  @param[in] RgSchUeCb        *ue
17240  *  @return  S16
17241  *      -# ROK
17242  *      -# RFAILED
17243  **/
17244 #ifdef ANSI
17245 S16 rgSCHCmnBsrTmrExpry
17246 (
17247 RgSchUeCb  *ueCb
17248 )
17249 #else
17250 S16 rgSCHCmnBsrTmrExpry(ueCb)
17251 RgSchUeCb  *ueCb;
17252 #endif
17253 {
17254    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(ueCb->cell);
17255
17256
17257    ueCb->isSrGrant = TRUE;
17258
17259 #ifdef EMTC_ENABLE
17260    emtcStatsUlBsrTmrTxp++;
17261 #endif
17262
17263 #ifdef EMTC_ENABLE
17264    if(ueCb->cell->emtcEnable)
17265    {
17266       if(ueCb->isEmtcUe)
17267       {
17268          cellSch->apisEmtcUl->rgSCHSrRcvd(ueCb->cell, ueCb);
17269          return ROK;
17270       }
17271    }
17272    else
17273 #endif
17274    {
17275       cellSch->apisUl->rgSCHSrRcvd(ueCb->cell, ueCb);
17276    }
17277
17278    return  (ROK);
17279 }
17280
17281 /**
17282  * @brief Short BSR update.
17283  *
17284  * @details
17285  *
17286  *     Function : rgSCHCmnUpdBsrShort
17287  *
17288  *     This functions does requisite updates to handle short BSR reporting.
17289  *
17290  *  @param[in]  RgSchCellCb  *cell
17291  *  @param[in]  RgSchUeCb    *ue
17292  *  @param[in]  RgSchLcgCb *ulLcg
17293  *  @param[in]  U8           bsr
17294  *  @param[out] RgSchErrInfo *err
17295  *  @return  S16
17296  *      -# ROK
17297  *      -# RFAILED
17298  **/
17299 #ifdef ANSI
17300 S16 rgSCHCmnUpdBsrShort
17301 (
17302 RgSchCellCb  *cell,
17303 RgSchUeCb    *ue,
17304 RgSchLcgCb *ulLcg,
17305 U8           bsr,
17306 RgSchErrInfo *err
17307 )
17308 #else
17309 S16 rgSCHCmnUpdBsrShort(cell, ue, ulLcg, bsr, err)
17310 RgSchCellCb  *cell;
17311 RgSchUeCb    *ue;
17312 RgSchLcgCb *ulLcg;
17313 U8           bsr;
17314 RgSchErrInfo *err;
17315 #endif
17316 {
17317    U8  lcgCnt;
17318 #ifdef LTE_L2_MEAS
17319    RgSchCmnUlUe *ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
17320 #endif
17321    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
17322    RgSchCmnLcg  *cmnLcg  = NULLP;
17323
17324 #ifdef LTE_L2_MEAS
17325    U8             idx;
17326 #endif
17327
17328    if (!RGSCH_LCG_ISCFGD(ulLcg))
17329    {
17330       err->errCause = RGSCHERR_SCH_LCG_NOT_CFGD;
17331       return RFAILED;
17332    }
17333    for (lcgCnt=0; lcgCnt<4; lcgCnt++)
17334    {
17335 #ifdef LTE_L2_MEAS
17336       /* Set BS of all other LCGs to Zero.
17337          If Zero BSR is reported in Short BSR include this LCG too */
17338       if ((lcgCnt != ulLcg->lcgId) ||
17339             (!bsr && !ueUl->hqEnt.numBusyHqProcs))
17340       {
17341          /* If old BO is zero do nothing */
17342          if(((RgSchCmnLcg *)(ue->ul.lcgArr[lcgCnt].sch))->bs != 0)
17343          {
17344             for(idx = 0; idx < ue->ul.lcgArr[lcgCnt].numLch; idx++)
17345             {
17346                if((ue->ul.lcgArr[lcgCnt].lcArray[idx]->qciCb->ulUeCount) &&
17347                  (ue->ulActiveLCs & (1 << 
17348                   (ue->ul.lcgArr[lcgCnt].lcArray[idx]->qciCb->qci -1))))
17349                {
17350           /* L2_COUNTER */
17351                  ue->ul.lcgArr[lcgCnt].lcArray[idx]->qciCb->ulUeCount--;
17352                  ue->ulActiveLCs &= ~(1 << 
17353                   (ue->ul.lcgArr[lcgCnt].lcArray[idx]->qciCb->qci -1));
17354                }
17355             }
17356          }
17357       }
17358 #endif
17359       if (RGSCH_LCG_ISCFGD(&ue->ul.lcgArr[lcgCnt]))
17360       {
17361          ((RgSchCmnLcg *)(ue->ul.lcgArr[lcgCnt].sch))->bs = 0;
17362          ((RgSchCmnLcg *)(ue->ul.lcgArr[lcgCnt].sch))->reportedBs = 0;
17363       }
17364    }
17365
17366 #ifdef LTE_L2_MEAS
17367    if(ulLcg->lcgId && bsr && (((RgSchCmnLcg *)(ulLcg->sch))->bs == 0))
17368    {
17369       for(idx = 0; idx < ulLcg->numLch; idx++)
17370       {
17371           /* L2_COUNTER */
17372           if (!(ue->ulActiveLCs & (1 << (ulLcg->lcArray[idx]->qciCb->qci -1))))
17373           {
17374              ulLcg->lcArray[idx]->qciCb->ulUeCount++;
17375              ue->ulActiveLCs |= (1 << (ulLcg->lcArray[idx]->qciCb->qci -1));
17376           }
17377       }
17378    }
17379 #endif
17380    /* Resetting the nonGbrLcgBs info here */
17381    ue->ul.nonGbrLcgBs = 0;
17382    ue->ul.nonLcg0Bs = 0;
17383
17384    cmnLcg = ((RgSchCmnLcg *)(ulLcg->sch));
17385    
17386    if (TRUE == ue->ul.useExtBSRSizes)
17387    {
17388       cmnLcg->reportedBs = rgSchCmnExtBsrTbl[bsr];
17389    }
17390    else
17391    {
17392       cmnLcg->reportedBs = rgSchCmnBsrTbl[bsr];
17393    }
17394    if (RGSCH_IS_GBR_BEARER(cmnLcg->cfgdGbr))
17395    {
17396       /* TBD check for effGbr != 0 */    
17397       cmnLcg->bs = RGSCH_MIN(cmnLcg->reportedBs, cmnLcg->effGbr + cmnLcg->effDeltaMbr);
17398    }
17399    else if (0 == ulLcg->lcgId) 
17400    {
17401       /* This is added for handling LCG0 */
17402       cmnLcg->bs = cmnLcg->reportedBs;
17403    }
17404    else 
17405    {
17406       /* Update non GBR LCG's BS*/
17407       ue->ul.nonGbrLcgBs = RGSCH_MIN(cmnLcg->reportedBs,ue->ul.effAmbr);
17408       cmnLcg->bs     = ue->ul.nonGbrLcgBs;
17409    }
17410    ue->ul.totalBsr = cmnLcg->bs;
17411
17412 #ifdef RGR_V1
17413    if ((ue->bsrTmr.tmrEvnt != TMR_NONE) && (bsr == 0))
17414    {
17415       rgSCHTmrStopTmr(cell, ue->bsrTmr.tmrEvnt, ue);
17416    }
17417 #endif
17418 #ifdef LTEMAC_SPS
17419    if (ue->ul.ulSpsCfg.isUlSpsEnabled == TRUE)
17420    {
17421       rgSCHCmnSpsBsrRpt(cell, ue, ulLcg);
17422    }
17423 #endif
17424    rgSCHCmnUpdUlCompEffBsr(ue);
17425
17426 #ifdef EMTC_ENABLE
17427    if(cell->emtcEnable)
17428    {
17429       if(ue->isEmtcUe)
17430       {
17431          cellSch->apisEmtcUl->rgSCHUpdBsrShort(cell, ue, ulLcg, bsr);
17432          return ROK;
17433       }
17434    }
17435    else
17436 #endif
17437    {
17438    cellSch->apisUl->rgSCHUpdBsrShort(cell, ue, ulLcg, bsr);
17439    }
17440
17441 #ifdef LTE_ADV
17442    if (ue->ul.isUlCaEnabled  && ue->numSCells)
17443    {
17444       for(U8 sCellIdx = 1; sCellIdx <= RG_SCH_MAX_SCELL ; sCellIdx++)
17445       {
17446 #ifndef PAL_ENABLE_UL_CA
17447          if((ue->cellInfo[sCellIdx] != NULLP) &&
17448                (ue->cellInfo[sCellIdx]->sCellState == RG_SCH_SCELL_ACTIVE))
17449 #else
17450          if(ue->cellInfo[sCellIdx] != NULLP)
17451 #endif
17452          {
17453             cellSch->apisUl->rgSCHUpdBsrShort(ue->cellInfo[sCellIdx]->cell, 
17454                   ue, ulLcg, bsr);
17455          }
17456       }
17457    }
17458 #endif 
17459
17460    return ROK;
17461 }
17462
17463 /**
17464  * @brief Truncated BSR update.
17465  *
17466  * @details
17467  *
17468  *     Function : rgSCHCmnUpdBsrTrunc
17469  *
17470  *     This functions does required updates to handle truncated BSR report.
17471  *
17472  *
17473  *  @param[in]  RgSchCellCb  *cell
17474  *  @param[in]  RgSchUeCb    *ue
17475  *  @param[in]  RgSchLcgCb *ulLcg
17476  *  @param[in]  U8           bsr
17477  *  @param[out] RgSchErrInfo *err
17478  *  @return  S16
17479  *      -# ROK
17480  *      -# RFAILED
17481  **/
17482 #ifdef ANSI
17483 S16 rgSCHCmnUpdBsrTrunc
17484 (
17485 RgSchCellCb  *cell,
17486 RgSchUeCb    *ue,
17487 RgSchLcgCb *ulLcg,
17488 U8           bsr,
17489 RgSchErrInfo *err
17490 )
17491 #else
17492 S16 rgSCHCmnUpdBsrTrunc(cell, ue, ulLcg, bsr, err)
17493 RgSchCellCb  *cell;
17494 RgSchUeCb    *ue;
17495 RgSchLcgCb *ulLcg;
17496 U8           bsr;
17497 RgSchErrInfo *err;
17498 #endif
17499 {
17500    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
17501    RgSchCmnLcg  *cmnLcg = NULLP;
17502    S32          cnt;
17503 #ifdef LTE_L2_MEAS
17504    U8     idx;
17505 #endif
17506
17507
17508    if (!RGSCH_LCG_ISCFGD(ulLcg))
17509    {
17510       err->errCause = RGSCHERR_SCH_LCG_NOT_CFGD;
17511       return RFAILED;
17512    }
17513    /* set all higher prio lcgs bs to 0 and update this lcgs bs and
17514       total bsr= sumofall lcgs bs */
17515    if (ulLcg->lcgId)
17516    {
17517       for (cnt = ulLcg->lcgId-1; cnt >= 0; cnt--)
17518       {
17519 #ifdef LTE_L2_MEAS
17520          /* If Existing BO is zero the don't do anything */
17521          if(((RgSchCmnLcg *)(ue->ul.lcgArr[cnt].sch))->bs != 0)
17522          {
17523             for(idx = 0; idx < ue->ul.lcgArr[cnt].numLch; idx++)
17524             {
17525                /* L2_COUNTERS */
17526                if((ue->ul.lcgArr[cnt].lcArray[idx]->qciCb->ulUeCount) &&
17527                      (ue->ulActiveLCs & (1 << 
17528                                          (ue->ul.lcgArr[cnt].lcArray[idx]->qciCb->qci -1))))
17529                {
17530                   ue->ul.lcgArr[cnt].lcArray[idx]->qciCb->ulUeCount--;
17531                   ue->ulActiveLCs &= ~(1 << 
17532                         (ue->ul.lcgArr[cnt].lcArray[idx]->qciCb->qci -1));
17533                }
17534             }
17535          }
17536 #endif
17537          ((RgSchCmnLcg *)(ue->ul.lcgArr[cnt].sch))->bs = 0;
17538          ((RgSchCmnLcg *)(ue->ul.lcgArr[cnt].sch))->reportedBs = 0;
17539       }
17540    }
17541
17542 #ifdef LTE_L2_MEAS
17543    for (cnt = ulLcg->lcgId; cnt < RGSCH_MAX_LCG_PER_UE; cnt++)
17544    {
17545       if (ulLcg->lcgId == 0)
17546       {
17547          continue;
17548       }
17549       /* If Existing BO is zero the don't do anything */
17550       if(((RgSchCmnLcg *)(ue->ul.lcgArr[cnt].sch))->bs == 0)
17551       {
17552          for(idx = 0; idx < ue->ul.lcgArr[cnt].numLch; idx++)
17553          {
17554             /* L2_COUNTERS */
17555             if (!(ue->ulActiveLCs & (1 << 
17556                (ue->ul.lcgArr[cnt].lcArray[idx]->qciCb->qci -1))))
17557             {
17558                ue->ul.lcgArr[cnt].lcArray[idx]->qciCb->ulUeCount++;
17559                ue->ulActiveLCs |= (1 << 
17560                      (ue->ul.lcgArr[cnt].lcArray[idx]->qciCb->qci -1));
17561             }
17562          }
17563       }
17564    }
17565 #endif
17566    ue->ul.nonGbrLcgBs = 0;
17567    ue->ul.nonLcg0Bs = 0;
17568    cmnLcg = ((RgSchCmnLcg *)(ulLcg->sch));
17569    if (TRUE == ue->ul.useExtBSRSizes)
17570    {
17571       cmnLcg->reportedBs = rgSchCmnExtBsrTbl[bsr];
17572    }
17573    else
17574    {
17575       cmnLcg->reportedBs = rgSchCmnBsrTbl[bsr];
17576    }
17577    if (RGSCH_IS_GBR_BEARER(cmnLcg->cfgdGbr))
17578    {
17579       cmnLcg->bs = RGSCH_MIN(cmnLcg->reportedBs, cmnLcg->effGbr + cmnLcg->effDeltaMbr);
17580    }
17581    else if(ulLcg->lcgId == 0)
17582    {
17583       /* This is for handeling LCG0 */
17584       cmnLcg->bs = cmnLcg->reportedBs;
17585    }
17586    else
17587    {
17588       ue->ul.nonGbrLcgBs = RGSCH_MIN(cmnLcg->reportedBs, ue->ul.effAmbr);
17589       cmnLcg->bs = ue->ul.nonGbrLcgBs;
17590    }
17591    ue->ul.totalBsr = cmnLcg->bs;
17592
17593    for (cnt = ulLcg->lcgId+1; cnt < RGSCH_MAX_LCG_PER_UE; cnt++)
17594    {
17595       /* TODO: The bs for the other LCGs may be stale because some or all of
17596        * the part of bs may have been already scheduled/data received. Please 
17597        * consider this when truncated BSR is tested/implemented */
17598       ue->ul.totalBsr += ((RgSchCmnLcg *)(ue->ul.lcgArr[cnt].sch))->bs;
17599    }
17600
17601    rgSCHCmnUpdUlCompEffBsr(ue);
17602
17603 #ifdef EMTC_ENABLE
17604    if(cell->emtcEnable)
17605    {
17606       if(ue->isEmtcUe)
17607       {
17608          cellSch->apisEmtcUl->rgSCHUpdBsrTrunc(cell, ue, ulLcg, bsr);
17609          return ROK;
17610       }
17611    }
17612    else
17613 #endif
17614    {
17615       cellSch->apisUl->rgSCHUpdBsrTrunc(cell, ue, ulLcg, bsr);
17616    }
17617
17618 #ifdef LTE_ADV
17619    if (ue->ul.isUlCaEnabled  && ue->numSCells)
17620    {
17621       for(U8 sCellIdx = 1; sCellIdx <= RG_SCH_MAX_SCELL ; sCellIdx++)
17622       {
17623 #ifndef PAL_ENABLE_UL_CA
17624          if((ue->cellInfo[sCellIdx] != NULLP) &&
17625                (ue->cellInfo[sCellIdx]->sCellState == RG_SCH_SCELL_ACTIVE))
17626 #else
17627          if(ue->cellInfo[sCellIdx] != NULLP)
17628 #endif
17629          {
17630             cellSch->apisUl->rgSCHUpdBsrTrunc(ue->cellInfo[sCellIdx]->cell, ue, ulLcg, bsr);
17631          }
17632       }
17633    }
17634 #endif 
17635
17636    return ROK;
17637 }
17638
17639 /**
17640  * @brief Long BSR update.
17641  *
17642  * @details
17643  *
17644  *     Function : rgSCHCmnUpdBsrLong
17645  *
17646  *     - Update BSRs for all configured LCGs.
17647  *     - Update priority of LCGs if needed.
17648  *     - Update UE's position within/across uplink scheduling queues.
17649  *
17650  *
17651  *  @param[in]  RgSchCellCb  *cell
17652  *  @param[in]  RgSchUeCb    *ue
17653  *  @param[in]  U8 bsArr[]
17654  *  @param[out] RgSchErrInfo *err
17655  *  @return  S16
17656  *      -# ROK
17657  *      -# RFAILED
17658  **/
17659 #ifdef ANSI
17660 S16 rgSCHCmnUpdBsrLong
17661 (
17662 RgSchCellCb  *cell,
17663 RgSchUeCb    *ue,
17664 U8           *bsArr,
17665 RgSchErrInfo *err
17666 )
17667 #else
17668 S16 rgSCHCmnUpdBsrLong(cell, ue, bsArr, err)
17669 RgSchCellCb  *cell;
17670 RgSchUeCb    *ue;
17671 U8           *bsArr;
17672 RgSchErrInfo *err;
17673 #endif
17674 {
17675    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
17676    U32           tmpBsArr[4] = {0, 0, 0, 0};
17677    U32           nonGbrBs = 0;
17678 #ifdef LTE_L2_MEAS
17679    U8            idx1;
17680    U8            idx2;
17681 #endif
17682    U32           lcgId;
17683
17684
17685 #ifdef LTE_L2_MEAS
17686    for(idx1 = 1; idx1 < RGSCH_MAX_LCG_PER_UE; idx1++)
17687    {
17688      /* If Old BO is non zero then do nothing */
17689      if ((((RgSchCmnLcg *)(ue->ul.lcgArr[idx1].sch))->bs == 0)
17690         && bsArr[idx1] )
17691      {
17692        for(idx2 = 0; idx2 < ue->ul.lcgArr[idx1].numLch; idx2++)
17693        {
17694           /* L2_COUNTERS */
17695           if (!(ue->ulActiveLCs & (1 << 
17696              (ue->ul.lcgArr[idx1].lcArray[idx2]->qciCb->qci -1))))
17697           {
17698              ue->ul.lcgArr[idx1].lcArray[idx2]->qciCb->ulUeCount++;
17699              ue->ulActiveLCs |= (1 << 
17700                (ue->ul.lcgArr[idx1].lcArray[idx2]->qciCb->qci -1));
17701           }
17702        }
17703      }
17704    }
17705 #endif
17706    ue->ul.nonGbrLcgBs = 0;
17707    ue->ul.nonLcg0Bs = 0;
17708
17709    if (RGSCH_LCG_ISCFGD(&ue->ul.lcgArr[0]))
17710    {
17711       if (TRUE == ue->ul.useExtBSRSizes)
17712       {
17713          ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->bs = rgSchCmnExtBsrTbl[bsArr[0]];
17714          ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->reportedBs = rgSchCmnExtBsrTbl[bsArr[0]];
17715          tmpBsArr[0] = rgSchCmnExtBsrTbl[bsArr[0]];
17716       }
17717       else
17718       {
17719          ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->bs = rgSchCmnBsrTbl[bsArr[0]];
17720          ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->reportedBs = rgSchCmnBsrTbl[bsArr[0]];
17721          tmpBsArr[0] = rgSchCmnBsrTbl[bsArr[0]];
17722       }
17723    }
17724    for (lcgId = 1; lcgId < RGSCH_MAX_LCG_PER_UE; lcgId++)
17725    {
17726       if (RGSCH_LCG_ISCFGD(&ue->ul.lcgArr[lcgId]))
17727       {
17728          RgSchCmnLcg *cmnLcg = ((RgSchCmnLcg *)(ue->ul.lcgArr[lcgId].sch));
17729
17730          if (TRUE == ue->ul.useExtBSRSizes)
17731          {
17732             cmnLcg->reportedBs = rgSchCmnExtBsrTbl[bsArr[lcgId]];
17733          }
17734          else
17735          {
17736             cmnLcg->reportedBs = rgSchCmnBsrTbl[bsArr[lcgId]];
17737          }
17738          if (RGSCH_IS_GBR_BEARER(cmnLcg->cfgdGbr))
17739          {
17740             cmnLcg->bs = RGSCH_MIN(cmnLcg->reportedBs, cmnLcg->effGbr + cmnLcg->effDeltaMbr);
17741             tmpBsArr[lcgId] = cmnLcg->bs;
17742          }
17743          else
17744          {
17745             nonGbrBs += cmnLcg->reportedBs;
17746             tmpBsArr[lcgId] = cmnLcg->reportedBs;
17747             cmnLcg->bs = RGSCH_MIN(cmnLcg->reportedBs,ue->ul.effAmbr);
17748          }
17749       }
17750    }
17751    ue->ul.nonGbrLcgBs = RGSCH_MIN(nonGbrBs,ue->ul.effAmbr);
17752
17753    ue->ul.totalBsr = tmpBsArr[0] + tmpBsArr[1] + tmpBsArr[2] + tmpBsArr[3];
17754 #ifdef RGR_V1
17755    if ((ue->bsrTmr.tmrEvnt != TMR_NONE) && (ue->ul.totalBsr == 0))
17756    {
17757       rgSCHTmrStopTmr(cell, ue->bsrTmr.tmrEvnt, ue);
17758    }
17759 #endif
17760
17761 #ifdef LTEMAC_SPS
17762    if (ue->ul.ulSpsCfg.isUlSpsEnabled == TRUE) /* SPS_FIX */
17763    {
17764      if(ue->ul.totalBsr - tmpBsArr[1] == 0)
17765      {/* Updaing the BSR to SPS only if LCG1 BS is present in sps active state */
17766         rgSCHCmnSpsBsrRpt(cell, ue, &ue->ul.lcgArr[1]);
17767      }
17768    }
17769 #endif
17770    rgSCHCmnUpdUlCompEffBsr(ue);
17771
17772 #ifdef EMTC_ENABLE
17773    if(cell->emtcEnable)
17774    {
17775       if(ue->isEmtcUe)
17776       {
17777          cellSch->apisEmtcUl->rgSCHUpdBsrLong(cell, ue, bsArr);
17778          return ROK;
17779       }
17780    }
17781    else
17782 #endif
17783    {
17784    cellSch->apisUl->rgSCHUpdBsrLong(cell, ue, bsArr);
17785    }
17786
17787 #ifdef LTE_ADV
17788    if (ue->ul.isUlCaEnabled  && ue->numSCells)
17789    {
17790       for(U8 idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
17791       {
17792 #ifndef PAL_ENABLE_UL_CA
17793          if((ue->cellInfo[idx] != NULLP) &&
17794                (ue->cellInfo[idx]->sCellState == RG_SCH_SCELL_ACTIVE))
17795 #else
17796          if(ue->cellInfo[idx] != NULLP)
17797 #endif
17798          {
17799             cellSch->apisUl->rgSCHUpdBsrLong(ue->cellInfo[idx]->cell, ue, bsArr);
17800          }
17801       }
17802    }
17803 #endif 
17804
17805    return ROK;
17806 }
17807
17808 /**
17809  * @brief PHR update.
17810  *
17811  * @details
17812  *
17813  *     Function : rgSCHCmnUpdExtPhr
17814  *
17815  *     Updates extended power headroom information for an UE.
17816  *
17817  *  @param[in]  RgSchCellCb  *cell
17818  *  @param[in]  RgSchUeCb    *ue
17819  *  @param[in]  U8           phr
17820  *  @param[out] RgSchErrInfo *err
17821  *  @return  S16
17822  *      -# ROK
17823  *      -# RFAILED
17824  **/
17825 #ifdef ANSI
17826 S16 rgSCHCmnUpdExtPhr
17827 (
17828 RgSchCellCb    *cell,
17829 RgSchUeCb      *ue,
17830 RgInfExtPhrCEInfo *extPhr,
17831 RgSchErrInfo   *err
17832 )
17833 #else
17834 S16 rgSCHCmnUpdExtPhr(cell, ue, extPhr, err)
17835 RgSchCellCb    *cell;
17836 RgSchUeCb      *ue;
17837 RgInfExtPhrCEInfo *extPhr;
17838 RgSchErrInfo   *err;
17839 #endif
17840 {
17841    RgSchCmnUlUe        *ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
17842    RgSchCmnAllocRecord *allRcd;
17843    CmLList             *node = ueUl->ulAllocLst.last;
17844
17845 #ifdef LTEMAC_SPS
17846    RgSchCmnUlUeSpsInfo   *ulSpsUe = RG_SCH_CMN_GET_UL_SPS_UE(ue,cell);
17847 #endif
17848
17849    UNUSED(err);
17850
17851    while (node)
17852    {
17853       allRcd = (RgSchCmnAllocRecord *)node->node;
17854       node = node->prev;
17855       if (RGSCH_TIMEINFO_SAME(ue->macCeRptTime, allRcd->allocTime))
17856       {
17857          rgSCHPwrUpdExtPhr(cell, ue, extPhr, allRcd);
17858          break;
17859       }
17860    }
17861 #ifdef LTEMAC_SPS
17862    if(ulSpsUe->isUlSpsActv)
17863    {
17864       rgSCHCmnSpsPhrInd(cell,ue);
17865    }
17866 #endif
17867
17868    return ROK;
17869 }  /* rgSCHCmnUpdExtPhr */
17870
17871
17872
17873
17874 /**
17875  * @brief PHR update.
17876  *
17877  * @details
17878  *
17879  *     Function : rgSCHCmnUpdPhr
17880  *
17881  *     Updates power headroom information for an UE.
17882  *
17883  *  @param[in]  RgSchCellCb  *cell
17884  *  @param[in]  RgSchUeCb    *ue
17885  *  @param[in]  U8           phr
17886  *  @param[out] RgSchErrInfo *err
17887  *  @return  S16
17888  *      -# ROK
17889  *      -# RFAILED
17890  **/
17891 #ifdef ANSI
17892 S16 rgSCHCmnUpdPhr
17893 (
17894 RgSchCellCb    *cell,
17895 RgSchUeCb      *ue,
17896 U8             phr,
17897 RgSchErrInfo   *err
17898 )
17899 #else
17900 S16 rgSCHCmnUpdPhr(cell, ue, phr, err)
17901 RgSchCellCb    *cell;
17902 RgSchUeCb      *ue;
17903 U8             phr;
17904 RgSchErrInfo   *err;
17905 #endif
17906 {
17907    RgSchCmnUlUe        *ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
17908    RgSchCmnAllocRecord *allRcd;
17909    CmLList             *node = ueUl->ulAllocLst.last;
17910
17911 #ifdef LTEMAC_SPS
17912    RgSchCmnUlUeSpsInfo   *ulSpsUe = RG_SCH_CMN_GET_UL_SPS_UE(ue,cell);
17913 #endif
17914
17915    UNUSED(err);
17916
17917    while (node)
17918    {
17919       allRcd = (RgSchCmnAllocRecord *)node->node;
17920       node = node->prev;
17921       if (RGSCH_TIMEINFO_SAME(ue->macCeRptTime, allRcd->allocTime))
17922       {
17923          rgSCHPwrUpdPhr(cell, ue, phr, allRcd, RG_SCH_CMN_PWR_USE_CFG_MAX_PWR);
17924          break;
17925       }
17926    }
17927 #ifdef LTEMAC_SPS
17928    if(ulSpsUe->isUlSpsActv)
17929    {
17930       rgSCHCmnSpsPhrInd(cell,ue);
17931    }
17932 #endif
17933
17934    return ROK;
17935 }  /* rgSCHCmnUpdPhr */
17936
17937 /**
17938  * @brief UL grant for contention resolution.
17939  *
17940  * @details
17941  *
17942  *     Function : rgSCHCmnContResUlGrant
17943  *
17944  *     Add UE to another queue specifically for CRNTI based contention
17945  *     resolution.
17946  *
17947  *
17948  *  @param[in]  RgSchUeCb    *ue
17949  *  @param[out] RgSchErrInfo *err
17950  *  @return  S16
17951  *      -# ROK
17952  *      -# RFAILED
17953  **/
17954 #ifdef ANSI
17955 S16 rgSCHCmnContResUlGrant
17956 (
17957 RgSchCellCb  *cell,
17958 RgSchUeCb    *ue,
17959 RgSchErrInfo *err
17960 )
17961 #else
17962 S16 rgSCHCmnContResUlGrant(cell, ue, err)
17963 RgSchCellCb  *cell;
17964 RgSchUeCb    *ue;
17965 RgSchErrInfo *err;
17966 #endif
17967 {
17968    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
17969
17970    #ifdef EMTC_ENABLE
17971    if(cell->emtcEnable)
17972    {
17973       if(ue->isEmtcUe)
17974       {
17975          cellSch->apisEmtcUl->rgSCHContResUlGrant(cell, ue);
17976          return ROK;
17977       }
17978    }
17979    else
17980 #endif
17981    {
17982       cellSch->apisUl->rgSCHContResUlGrant(cell, ue);
17983    }
17984    return ROK;
17985 }
17986
17987 /**
17988  * @brief SR reception handling.
17989  *
17990  * @details
17991  *
17992  *     Function : rgSCHCmnSrRcvd
17993  *
17994  *     - Update UE's position within/across uplink scheduling queues
17995  *     - Update priority of LCGs if needed.
17996  *
17997  *  @param[in]  RgSchCellCb  *cell
17998  *  @param[in]  RgSchUeCb    *ue
17999  *  @param[in]  CmLteTimingInfo frm
18000  *  @param[out] RgSchErrInfo *err
18001  *  @return  S16
18002  *      -# ROK
18003  *      -# RFAILED
18004  **/
18005 #ifdef ANSI
18006 S16 rgSCHCmnSrRcvd
18007 (
18008 RgSchCellCb  *cell,
18009 RgSchUeCb    *ue,
18010 CmLteTimingInfo frm,
18011 RgSchErrInfo *err
18012 )
18013 #else
18014 S16 rgSCHCmnSrRcvd(cell, ue, frm, err)
18015 RgSchCellCb  *cell;
18016 RgSchUeCb    *ue;
18017 CmLteTimingInfo frm;
18018 RgSchErrInfo *err;
18019 #endif
18020 {
18021    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
18022    RgSchCmnUlUe *ueUl    = RG_SCH_CMN_GET_UL_UE(ue,cell);
18023    CmLList      *node    = ueUl->ulAllocLst.last;
18024
18025
18026 #ifdef EMTC_ENABLE
18027    emtcStatsUlTomSrInd++;
18028 #endif
18029
18030    RGSCH_INCR_SUB_FRAME(frm, 1); /* 1 TTI after the time SR was sent */
18031    while (node)
18032    {
18033       RgSchCmnAllocRecord *allRcd = (RgSchCmnAllocRecord *)node->node;
18034       if (RGSCH_TIMEINFO_SAME(frm, allRcd->allocTime))
18035       {
18036          break;
18037       }
18038       node = node->prev;
18039    }
18040    //TODO_SID Need to check when it is getting triggered
18041    ue->isSrGrant = TRUE;
18042 #ifdef EMTC_ENABLE
18043    if(cell->emtcEnable)
18044    {
18045       if(ue->isEmtcUe)
18046       {
18047          cellSch->apisEmtcUl->rgSCHSrRcvd(cell, ue);
18048          return ROK;
18049       }
18050    }
18051    else
18052 #endif
18053    {
18054       cellSch->apisUl->rgSCHSrRcvd(cell, ue);
18055    }
18056    return ROK;
18057 }
18058
18059 /**
18060  * @brief Returns first uplink allocation to send reception
18061  *        request to PHY.
18062  *
18063  * @details
18064  *
18065  *     Function: rgSCHCmnFirstRcptnReq(cell)
18066  *     Purpose:  This function returns the first uplink allocation
18067  *               (or NULLP if there is none) in the subframe
18068  *               in which is expected to prepare and send reception
18069  *               request to PHY.
18070  *
18071  *     Invoked by: TOM
18072  *
18073  *  @param[in]  RgSchCellCb      *cell
18074  *  @return  RgSchUlAlloc*
18075  **/
18076 #ifdef ANSI
18077 RgSchUlAlloc *rgSCHCmnFirstRcptnReq
18078 (
18079 RgSchCellCb      *cell
18080 )
18081 #else
18082 RgSchUlAlloc *rgSCHCmnFirstRcptnReq(cell)
18083 RgSchCellCb      *cell;
18084 #endif
18085 {
18086    RgSchCmnUlCell *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
18087 /* ACC_TDD */
18088    RgSchUlAlloc* alloc = NULLP;
18089
18090
18091    if (cellUl->rcpReqIdx != RGSCH_INVALID_INFO)
18092    {
18093            RgSchUlSf* sf = &cellUl->ulSfArr[cellUl->rcpReqIdx];
18094            alloc = rgSCHUtlUlAllocFirst(sf);
18095
18096            if (alloc && alloc->hqProc == NULLP)
18097            {
18098                    alloc = rgSCHUtlUlAllocNxt(sf, alloc);
18099            }
18100    }
18101
18102    return (alloc);
18103 }
18104
18105 /**
18106  * @brief Returns first uplink allocation to send reception
18107  *        request to PHY.
18108  *
18109  * @details
18110  *
18111  *     Function: rgSCHCmnNextRcptnReq(cell)
18112  *     Purpose:  This function returns the next uplink allocation
18113  *               (or NULLP if there is none) in the subframe
18114  *               in which is expected to prepare and send reception
18115  *               request to PHY.
18116  *
18117  *     Invoked by: TOM
18118  *
18119  *  @param[in]  RgSchCellCb      *cell
18120  *  @return  RgSchUlAlloc*
18121  **/
18122 #ifdef ANSI
18123 RgSchUlAlloc *rgSCHCmnNextRcptnReq
18124 (
18125 RgSchCellCb      *cell,
18126 RgSchUlAlloc     *alloc
18127 )
18128 #else
18129 RgSchUlAlloc *rgSCHCmnNextRcptnReq(cell, alloc)
18130 RgSchCellCb      *cell;
18131 RgSchUlAlloc     *alloc;
18132 #endif
18133 {
18134    RgSchCmnUlCell *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
18135 /* ACC-TDD */
18136    //RgSchUlSf      *sf   = &cellUl->ulSfArr[cellUl->rcpReqIdx];
18137
18138 /* ACC-TDD */
18139    if (cellUl->rcpReqIdx != RGSCH_INVALID_INFO)
18140    {
18141            RgSchUlSf *sf = &cellUl->ulSfArr[cellUl->rcpReqIdx];
18142
18143            alloc = rgSCHUtlUlAllocNxt(sf, alloc);
18144            if (alloc && alloc->hqProc == NULLP)
18145            {
18146                    alloc = rgSCHUtlUlAllocNxt(sf, alloc);
18147            }
18148    }
18149    else
18150    {
18151            alloc = NULLP;
18152    }
18153
18154    return (alloc);
18155 }
18156 /**
18157  * @brief Collates DRX enabled UE's scheduled in this SF
18158  *
18159  * @details
18160  *
18161  *     Function: rgSCHCmnDrxStrtInActvTmrInUl(cell)
18162  *     Purpose:  This function collates the link
18163  *               of UE's scheduled in this SF who
18164  *               have drx enabled. It then calls
18165  *               DRX specific function to start/restart
18166  *               inactivity timer in Ul
18167  *
18168  *     Invoked by: TOM
18169  *
18170  *  @param[in]  RgSchCellCb      *cell
18171  *  @return Void
18172  **/
18173 #ifdef ANSI
18174 Void rgSCHCmnDrxStrtInActvTmrInUl
18175 (
18176 RgSchCellCb      *cell
18177 )
18178 #else
18179 Void rgSCHCmnDrxStrtInActvTmrInUl(cell)
18180 RgSchCellCb      *cell;
18181 #endif
18182 {
18183    RgSchCmnUlCell *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
18184    RgSchUlSf      *sf     = &(cellUl->ulSfArr[cellUl->schdIdx]);
18185    RgSchUlAlloc   *alloc  = rgSCHUtlUlAllocFirst(sf);
18186    CmLListCp       ulUeLst;
18187    RgSchUeCb       *ueCb;
18188
18189
18190    cmLListInit(&ulUeLst);
18191
18192    while(alloc)
18193    {
18194       ueCb = alloc->ue;
18195
18196       if (ueCb)
18197       {
18198          if (!(alloc->grnt.isRtx) && ueCb->isDrxEnabled && !(ueCb->isSrGrant)
18199 #ifdef LTEMAC_SPS
18200              /* ccpu00139513- DRX inactivity timer should not be started for 
18201               * UL SPS occasions */
18202              && (alloc->hqProc->isSpsOccnHqP == FALSE) 
18203 #endif
18204              )
18205          {
18206             cmLListAdd2Tail(&ulUeLst,&(ueCb->ulDrxInactvTmrLnk));
18207             ueCb->ulDrxInactvTmrLnk.node = (PTR)ueCb;
18208          }
18209       }
18210
18211       alloc = rgSCHUtlUlAllocNxt(sf, alloc);
18212    }/*while(alloc)*/
18213
18214    (Void)rgSCHDrxStrtInActvTmr(cell,&ulUeLst,RG_SCH_DRX_UL);
18215
18216    RETVOID;
18217 }
18218
18219
18220 /**
18221  * @brief Returns first uplink allocation to send HARQ feedback
18222  *        request to PHY.
18223  *
18224  * @details
18225  *
18226  *     Function: rgSCHCmnFirstHqFdbkAlloc
18227  *     Purpose:  This function returns the first uplink allocation
18228  *               (or NULLP if there is none) in the subframe
18229  *               for which it is expected to prepare and send HARQ
18230  *               feedback to PHY.
18231  *
18232  *     Invoked by: TOM
18233  *
18234  *  @param[in]  RgSchCellCb      *cell
18235  *  @param[in]  U8               idx
18236  *  @return  RgSchUlAlloc*
18237  **/
18238 #ifdef ANSI
18239 RgSchUlAlloc *rgSCHCmnFirstHqFdbkAlloc
18240 (
18241 RgSchCellCb      *cell,
18242 U8               idx 
18243 )
18244 #else
18245 RgSchUlAlloc *rgSCHCmnFirstHqFdbkAlloc(cell, idx)
18246 RgSchCellCb      *cell;
18247 U8               idx;
18248 #endif
18249 {
18250    RgSchCmnUlCell *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
18251 /* ACC-TDD */
18252    RgSchUlAlloc  *alloc = NULLP;
18253
18254
18255    if (cellUl->hqFdbkIdx[idx] != RGSCH_INVALID_INFO)
18256    {
18257           RgSchUlSf *sf = &cellUl->ulSfArr[cellUl->hqFdbkIdx[idx]];
18258           alloc    = rgSCHUtlUlAllocFirst(sf);
18259
18260           while (alloc && (alloc->hqProc == NULLP))
18261           {
18262                   alloc = rgSCHUtlUlAllocNxt(sf, alloc);
18263           }
18264    }
18265
18266    return (alloc);
18267 }
18268
18269 /**
18270  * @brief Returns next allocation to send HARQ feedback for.
18271  *
18272  * @details
18273  *
18274  *     Function: rgSCHCmnNextHqFdbkAlloc(cell)
18275  *     Purpose:  This function returns the next uplink allocation
18276  *               (or NULLP if there is none) in the subframe
18277  *               for which HARQ feedback needs to be sent.
18278  *
18279  *     Invoked by: TOM
18280  *
18281  *  @param[in]  RgSchCellCb      *cell
18282  *  @return  RgSchUlAlloc*
18283  **/
18284 #ifdef ANSI
18285 RgSchUlAlloc *rgSCHCmnNextHqFdbkAlloc
18286 (
18287 RgSchCellCb      *cell,
18288 RgSchUlAlloc     *alloc,
18289 U8               idx 
18290 )
18291 #else
18292 RgSchUlAlloc *rgSCHCmnNextHqFdbkAlloc(cell, alloc, idx)
18293 RgSchCellCb      *cell;
18294 RgSchUlAlloc     *alloc;
18295 U8               idx; 
18296 #endif
18297 {
18298    RgSchCmnUlCell *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
18299
18300    if (cellUl->hqFdbkIdx[idx] != RGSCH_INVALID_INFO)
18301    {
18302       RgSchUlSf *sf = &cellUl->ulSfArr[cellUl->hqFdbkIdx[idx]];
18303
18304       alloc = rgSCHUtlUlAllocNxt(sf, alloc);
18305       while (alloc && (alloc->hqProc == NULLP))
18306       {
18307          alloc = rgSCHUtlUlAllocNxt(sf, alloc);
18308       }
18309    }
18310    else
18311    {
18312           alloc = NULLP;
18313    }
18314    return (alloc);
18315 }
18316
18317 /***********************************************************
18318  *
18319  *     Func : rgSCHCmnUlGetITbsFrmIMcs
18320  *
18321  *     Desc : Returns the Itbs that is mapped to an Imcs
18322  *            for the case of uplink.
18323  *
18324  *     Ret  :
18325  *
18326  *     Notes:
18327  *
18328  *     File :
18329  *
18330  **********************************************************/
18331 #ifdef ANSI
18332 U8 rgSCHCmnUlGetITbsFrmIMcs
18333 (
18334 U8          iMcs
18335 )
18336 #else
18337 U8 rgSCHCmnUlGetITbsFrmIMcs(iMcs)
18338 U8          iMcs;
18339 #endif
18340 {
18341
18342    return (rgUlIMcsTbl[iMcs].iTbs);
18343 }
18344
18345 /***********************************************************
18346  *
18347  *     Func : rgSCHCmnUlGetIMcsFrmITbs
18348  *
18349  *     Desc : Returns the Imcs that is mapped to an Itbs
18350  *            for the case of uplink.
18351  *
18352  *     Ret  :
18353  *
18354  *     Notes: For iTbs 19, iMcs is dependant on modulation order.
18355  *            Refer to 36.213, Table 8.6.1-1 and 36.306 Table 4.1-2
18356  *            for UE capability information
18357  *
18358  *     File :
18359  *
18360  **********************************************************/
18361 #ifdef ANSI
18362 U8 rgSCHCmnUlGetIMcsFrmITbs
18363 (
18364 U8                iTbs,
18365 CmLteUeCategory   ueCtg
18366 )
18367 #else
18368 U8 rgSCHCmnUlGetIMcsFrmITbs(iTbs, ueCtg)
18369 U8                iTbs;
18370 CmLteUeCategory   ueCtg;
18371 #endif
18372 {
18373    U8 iMcs;
18374
18375    if (iTbs <= 10)
18376    {
18377       iMcs = iTbs;
18378    }
18379    /*a higher layer can force a 64QAM UE to transmit at 16QAM.
18380     * We currently do not support this. Once the support for such
18381     * is added, ueCtg should be replaced by current transmit
18382     * modulation configuration.Refer to 36.213 -8.6.1
18383     */
18384    else if ( iTbs < 19 )
18385    {
18386       iMcs = iTbs + 1;
18387    }
18388    else if ((iTbs == 19) && (ueCtg != CM_LTE_UE_CAT_5))
18389    {
18390       iMcs = iTbs + 1;
18391    }
18392    else
18393    {
18394       iMcs = iTbs + 2;
18395    }
18396
18397 #ifdef LTE_TDD
18398    /* This is a Temp fix, done for TENBPLUS-3898, ULSCH SDU corruption
18399       was seen when IMCS exceeds 20  on T2k TDD*/
18400    if (iMcs > 20)
18401    {
18402       iMcs = 20;
18403    }
18404 #endif
18405
18406    return (iMcs);
18407 }
18408
18409 /***********************************************************
18410  *
18411  *     Func : rgSCHCmnUlMinTbBitsForITbs
18412  *
18413  *     Desc : Returns the minimum number of bits that can
18414  *            be given as grant for a specific CQI.
18415  *
18416  *     Ret  :
18417  *
18418  *     Notes:
18419  *
18420  *     File :
18421  *
18422  **********************************************************/
18423 #ifdef ANSI
18424 U32 rgSCHCmnUlMinTbBitsForITbs
18425 (
18426 RgSchCmnUlCell     *cellUl,
18427 U8                 iTbs
18428 )
18429 #else
18430 U32 rgSCHCmnUlMinTbBitsForITbs(cellUl, iTbs)
18431 RgSchCmnUlCell   *cellUl;
18432 U8               iTbs;
18433 #endif
18434 {
18435
18436    RGSCH_ARRAY_BOUND_CHECK(0, rgTbSzTbl[0], iTbs); 
18437
18438    return (rgTbSzTbl[0][iTbs][cellUl->sbSize-1]);
18439 }
18440
18441 /***********************************************************
18442  *
18443  *     Func : rgSCHCmnUlSbAlloc
18444  *
18445  *     Desc : Given a required 'number of subbands' and a hole,
18446  *            returns a suitable alloc such that the subband
18447  *            allocation size is valid
18448  *
18449  *     Ret  :
18450  *
18451  *     Notes: Does not assume either passed numSb or hole size
18452  *            to be valid for allocation, and hence arrives at
18453  *            an acceptable value.
18454  *     File :
18455  *
18456  **********************************************************/
18457 #ifdef ANSI
18458 RgSchUlAlloc *rgSCHCmnUlSbAlloc
18459 (
18460 RgSchUlSf       *sf,
18461 U8              numSb,
18462 RgSchUlHole     *hole
18463 )
18464 #else
18465 RgSchUlAlloc *rgSCHCmnUlSbAlloc(sf, numSb, hole)
18466 RgSchUlSf       *sf;
18467 U8              numSb;
18468 RgSchUlHole     *hole;
18469 #endif
18470 {
18471    U8           holeSz; /* valid hole size */
18472    RgSchUlAlloc *alloc;
18473
18474    if ((holeSz = rgSchCmnMult235Tbl[hole->num].prvMatch) == hole->num)
18475    {
18476       numSb = rgSchCmnMult235Tbl[numSb].match;
18477       if (numSb >= holeSz)
18478       {
18479          alloc = rgSCHUtlUlAllocGetCompHole(sf, hole);
18480       }
18481       else
18482       {
18483          alloc = rgSCHUtlUlAllocGetPartHole(sf, numSb, hole);
18484       }
18485    }
18486    else
18487    {
18488       if (numSb < holeSz)
18489       {
18490          numSb = rgSchCmnMult235Tbl[numSb].match;
18491       }
18492       else
18493       {
18494          numSb = rgSchCmnMult235Tbl[numSb].prvMatch;
18495       }
18496
18497       if ( numSb >= holeSz )
18498       {
18499          numSb = holeSz;
18500       }
18501       alloc = rgSCHUtlUlAllocGetPartHole(sf, numSb, hole);
18502    }
18503    return (alloc);
18504 }
18505
18506 /**
18507  * @brief To fill the RgSchCmnUeUlAlloc structure of UeCb.
18508  *
18509  * @details
18510  *
18511  *     Function: rgSCHCmnUlUeFillAllocInfo
18512  *     Purpose:  Specific scheduler to call this API to fill the alloc
18513  *               information.
18514  *
18515  *     Invoked by: Scheduler
18516  *
18517  *  @param[in]  RgSchCellCb      *cell
18518  *  @param[out] RgSchUeCb        *ue
18519  *  @return   Void
18520  **/
18521 #ifdef ANSI
18522 Void rgSCHCmnUlUeFillAllocInfo
18523 (
18524 RgSchCellCb      *cell,
18525 RgSchUeCb        *ue
18526 )
18527 #else
18528 Void rgSCHCmnUlUeFillAllocInfo(cell, ue)
18529 RgSchCellCb      *cell;
18530 RgSchUeCb        *ue;
18531 #endif
18532 {
18533    RgSchCmnUlCell     *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
18534    RgSchCmnUeUlAlloc  *ulAllocInfo;
18535    RgSchCmnUlUe       *ueUl;
18536
18537
18538    ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
18539    ulAllocInfo = &ueUl->alloc;
18540
18541    /* Fill alloc structure */
18542    rgSCHCmnUlAllocFillTpc(cell, ue, ulAllocInfo->alloc);
18543    rgSCHCmnUlAllocFillNdmrs(cellUl, ulAllocInfo->alloc);
18544    rgSCHCmnUlAllocLnkHqProc(ue, ulAllocInfo->alloc, ulAllocInfo->alloc->hqProc,
18545                      ulAllocInfo->alloc->hqProc->isRetx);
18546    /* Fill PDCCH */
18547    rgSCHCmnUlFillPdcchWithAlloc(ulAllocInfo->alloc->pdcch,
18548          ulAllocInfo->alloc, ue);
18549    /* Recording information about this allocation */
18550    rgSCHCmnUlRecordUeAlloc(cell, ue);
18551
18552    /* Update the UE's outstanding allocation */
18553    if (!ulAllocInfo->alloc->hqProc->isRetx)
18554    {
18555       rgSCHCmnUlUpdOutStndAlloc(cell, ue, ulAllocInfo->allocdBytes);
18556    }
18557
18558    RETVOID;
18559 }
18560
18561 /**
18562  * @brief Update the UEs outstanding alloc based on the BSR report's timing.
18563  *
18564  *
18565  * @details
18566  *
18567  *     Function: rgSCHCmnUpdUlCompEffBsr
18568  *     Purpose:  Clear off all the allocations from outstanding allocation that
18569  *     are later than or equal to BSR timing information (stored in UEs datIndTime).
18570  *
18571  *     Invoked by: Scheduler
18572  *
18573  *  @param[in]  RgSchUeCb *ue
18574  *  @return  Void
18575  **/
18576 #ifdef ANSI
18577 PRIVATE Void rgSCHCmnUpdUlCompEffBsr
18578 (
18579 RgSchUeCb *ue
18580 )
18581 #else
18582 PRIVATE Void rgSCHCmnUpdUlCompEffBsr(ue)
18583 RgSchUeCb *ue;
18584 #endif
18585 {
18586    RgSchCmnUlUe *ueUl = RG_SCH_CMN_GET_UL_UE(ue,ue->cell);
18587    CmLList   *node = ueUl->ulAllocLst.last;
18588    RgSchCmnAllocRecord *allRcd;
18589    U32 outStndAlloc=0;
18590    U32 nonLcg0OutStndAllocBs=0;
18591    U32 nonLcg0Bsr=0;
18592    U8  lcgId;
18593    RgSchCmnLcg *cmnLcg = NULLP;
18594
18595    while (node)
18596    {
18597       allRcd = (RgSchCmnAllocRecord *)node->node;
18598       if (RGSCH_TIMEINFO_SAME(ue->macCeRptTime, allRcd->allocTime))
18599       {
18600          node = node->next;
18601          break;
18602       }
18603       node = node->prev;
18604    }
18605    while (node)
18606    {
18607       allRcd = (RgSchCmnAllocRecord *)node->node;
18608       node = node->next;
18609       outStndAlloc += allRcd->alloc;
18610    }
18611  
18612    cmnLcg = (RgSchCmnLcg *)(ue->ul.lcgArr[0].sch);
18613    /* Update UEs LCG0's bs according to the total outstanding BSR allocation.*/
18614    if (cmnLcg->bs > outStndAlloc)
18615    {
18616       cmnLcg->bs -= outStndAlloc;
18617       ue->ul.minReqBytes = cmnLcg->bs;
18618       outStndAlloc = 0;
18619    }
18620    else
18621    {
18622       nonLcg0OutStndAllocBs = outStndAlloc - cmnLcg->bs;
18623       cmnLcg->bs = 0;
18624    }
18625
18626    for(lcgId = 1;lcgId < RGSCH_MAX_LCG_PER_UE; lcgId++)
18627    {
18628       if(RGSCH_LCG_ISCFGD(&ue->ul.lcgArr[lcgId]))
18629       {
18630          cmnLcg = ((RgSchCmnLcg *) (ue->ul.lcgArr[lcgId].sch));
18631          if (RGSCH_IS_GBR_BEARER(cmnLcg->cfgdGbr))
18632          {
18633             nonLcg0Bsr += cmnLcg->bs;
18634          }
18635       }
18636    }
18637    nonLcg0Bsr += ue->ul.nonGbrLcgBs;  
18638    if (nonLcg0OutStndAllocBs > nonLcg0Bsr)
18639    {
18640       nonLcg0Bsr = 0;
18641    }
18642    else
18643    {
18644       nonLcg0Bsr -= nonLcg0OutStndAllocBs;
18645    }
18646    ue->ul.nonLcg0Bs = nonLcg0Bsr;
18647    /* Cap effBsr with nonLcg0Bsr and append lcg0 bs.
18648     * nonLcg0Bsr limit applies only to lcg1,2,3 */
18649    /* better be handled in individual scheduler */
18650    ue->ul.effBsr = nonLcg0Bsr +\
18651                   ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->bs;
18652    RETVOID;
18653 }
18654
18655 /**
18656  * @brief  Records information about the current allocation.
18657  *
18658  * @details
18659  *
18660  *     Function: rgSCHCmnUlRecordUeAlloc
18661  *     Purpose:  Records information about the curent allocation.
18662  *               This includes the allocated bytes, as well
18663  *               as some power information.
18664  *
18665  *     Invoked by: Scheduler
18666  *
18667  *  @param[in]  RgSchCellCb *cell
18668  *  @param[in]  RgSchUeCb   *ue
18669  *  @return  Void
18670  **/
18671 #ifdef ANSI
18672 Void rgSCHCmnUlRecordUeAlloc
18673 (
18674 RgSchCellCb *cell,
18675 RgSchUeCb   *ue
18676 )
18677 #else
18678 Void rgSCHCmnUlRecordUeAlloc(cell, ue)
18679 RgSchCellCb *cell;
18680 RgSchUeCb   *ue;
18681 #endif
18682 {
18683 #ifdef LTE_TDD
18684    RgSchCmnUlCell     *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
18685 #endif
18686    RgSchCmnUlUe        *ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
18687    CmLListCp           *lst = &ueUl->ulAllocLst;
18688    CmLList             *node = ueUl->ulAllocLst.first;
18689    RgSchCmnAllocRecord *allRcd = (RgSchCmnAllocRecord *)(node->node);
18690    RgSchCmnUeUlAlloc  *ulAllocInfo = &ueUl->alloc;
18691    CmLteUeCategory ueCtg = (CmLteUeCategory)(RG_SCH_CMN_GET_UE_CTGY(ue));
18692
18693    cmLListDelFrm(lst, &allRcd->lnk);
18694 #ifndef LTE_TDD
18695    /* To the crntTime, add the MIN time at which UE will
18696     * actually send the BSR i.e DELTA+4 */
18697    allRcd->allocTime = cell->crntTime;
18698    /*ccpu00116293 - Correcting relation between UL subframe and DL subframe based on RG_UL_DELTA*/
18699 #ifdef EMTC_ENABLE
18700    if(ue->isEmtcUe == TRUE)
18701    {
18702       RGSCH_INCR_SUB_FRAME_EMTC(allRcd->allocTime,
18703                            (TFU_ULCNTRL_DLDELTA + RGSCH_PDCCH_PUSCH_DELTA));
18704    }
18705    else
18706 #endif
18707    {
18708       RGSCH_INCR_SUB_FRAME(allRcd->allocTime,
18709                            (TFU_ULCNTRL_DLDELTA + RGSCH_PDCCH_PUSCH_DELTA));
18710    }
18711 #else
18712    allRcd->allocTime = cellUl->schdTime;
18713 #endif
18714    cmLListAdd2Tail(lst, &allRcd->lnk);
18715
18716    /* Filling in the parameters to be recorded */
18717    allRcd->alloc = ulAllocInfo->allocdBytes;
18718    //allRcd->numRb = ulAllocInfo->alloc->grnt.numRb;
18719    allRcd->numRb = (ulAllocInfo->alloc->grnt.numVrbg * MAX_5GTF_VRBG_SIZE);
18720    /*Recording the UL CQI derived from the maxUlCqi */
18721    allRcd->cqi   = rgSCHCmnUlGetCqi(cell, ue, ueCtg);
18722    allRcd->tpc   = ulAllocInfo->alloc->grnt.tpc;
18723
18724    rgSCHPwrRecordRbAlloc(cell, ue, allRcd->numRb);
18725
18726    cell->measurements.ulBytesCnt += ulAllocInfo->allocdBytes;
18727
18728    RETVOID;
18729 }
18730
18731 /** PHR handling for MSG3
18732  * @brief  Records allocation information of msg3 in the the UE.
18733  *
18734  * @details
18735  *
18736  *     Function: rgSCHCmnUlRecMsg3Alloc
18737  *     Purpose:  Records information about msg3 allocation.
18738  *               This includes the allocated bytes, as well
18739  *               as some power information.
18740  *
18741  *     Invoked by: Scheduler
18742  *
18743  *  @param[in]  RgSchCellCb *cell
18744  *  @param[in]  RgSchUeCb   *ue
18745  *  @param[in]  RgSchRaCb   *raCb
18746  *  @return  Void
18747  **/
18748 #ifdef ANSI
18749 Void rgSCHCmnUlRecMsg3Alloc
18750 (
18751 RgSchCellCb *cell,
18752 RgSchUeCb   *ue,
18753 RgSchRaCb   *raCb
18754 )
18755 #else
18756 Void rgSCHCmnUlRecMsg3Alloc(cell, ue, raCb)
18757 RgSchCellCb *cell;
18758 RgSchUeCb   *ue;
18759 RgSchRaCb   *raCb;
18760 #endif
18761 {
18762    RgSchCmnUlUe        *ueUl = RG_SCH_CMN_GET_UL_UE(ue,cell);
18763    CmLListCp           *lst = &ueUl->ulAllocLst;
18764    CmLList             *node = ueUl->ulAllocLst.first;
18765    RgSchCmnAllocRecord *allRcd = (RgSchCmnAllocRecord *)(node->node);
18766
18767    /* Stack Crash problem for TRACE5 changes */
18768
18769    cmLListDelFrm(lst, node);
18770    allRcd->allocTime = raCb->msg3AllocTime;
18771    cmLListAdd2Tail(lst, node);
18772
18773    /* Filling in the parameters to be recorded */
18774    allRcd->alloc = raCb->msg3Grnt.datSz;
18775    allRcd->numRb = raCb->msg3Grnt.numRb;
18776    allRcd->cqi   = raCb->ccchCqi;
18777    allRcd->tpc   = raCb->msg3Grnt.tpc;
18778
18779    rgSCHPwrRecordRbAlloc(cell, ue, allRcd->numRb);
18780
18781    RETVOID;
18782 }
18783 /**
18784  * @brief Keeps track of the most recent RG_SCH_CMN_MAX_ALLOC_TRACK
18785  * allocations to track. Adds this allocation to the ueUl's ulAllocLst.
18786  *
18787  *
18788  * @details
18789  *
18790  *     Function: rgSCHCmnUlUpdOutStndAlloc
18791  *     Purpose:  Recent Allocation shall be at First Pos'n.
18792  *               Remove the last node, update the fields
18793  *                with the new allocation and add at front.
18794  *
18795  *     Invoked by: Scheduler
18796  *
18797  *  @param[in]  RgSchCellCb *cell
18798  *  @param[in]  RgSchUeCb   *ue
18799  *  @param[in]  U32 alloc
18800  *  @return  Void
18801  **/
18802 #ifdef ANSI
18803 Void rgSCHCmnUlUpdOutStndAlloc
18804 (
18805 RgSchCellCb *cell,
18806 RgSchUeCb   *ue,
18807 U32 alloc
18808 )
18809 #else
18810 Void rgSCHCmnUlUpdOutStndAlloc(cell, ue, alloc)
18811 RgSchCellCb *cell;
18812 RgSchUeCb   *ue;
18813 U32 alloc;
18814 #endif
18815 {
18816    U32                 nonLcg0Alloc=0;
18817
18818    /* Update UEs LCG0's bs according to the total outstanding BSR allocation.*/
18819    if (((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->bs > alloc)
18820    {
18821       ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->bs -= alloc;
18822    }
18823    else
18824    {
18825       nonLcg0Alloc = alloc - ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->bs;
18826       ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->bs = 0;
18827    }
18828
18829    if (nonLcg0Alloc >= ue->ul.nonLcg0Bs)
18830    {
18831       ue->ul.nonLcg0Bs  = 0;
18832    }
18833    else
18834    {
18835       ue->ul.nonLcg0Bs  -= nonLcg0Alloc;
18836    }
18837    /* Cap effBsr with effAmbr and append lcg0 bs.
18838     * effAmbr limit applies only to lcg1,2,3 non GBR LCG's*/
18839    /* better be handled in individual scheduler */
18840    ue->ul.effBsr = ue->ul.nonLcg0Bs +\
18841                   ((RgSchCmnLcg *)(ue->ul.lcgArr[0].sch))->bs;
18842 #ifdef RGR_V1
18843    if (ue->ul.effBsr == 0)
18844    {
18845       if (ue->bsrTmr.tmrEvnt != TMR_NONE)
18846       {
18847          rgSCHTmrStopTmr(cell, ue->bsrTmr.tmrEvnt, ue);
18848       }
18849       /* ccpu00133008 */
18850       if (FALSE == ue->isSrGrant)
18851       {
18852          if (ue->ul.bsrTmrCfg.isPrdBsrTmrPres)
18853          {
18854             /*
18855             rgSCHTmrStartTmr(cell, ue, RG_SCH_TMR_BSR,
18856                   ue->ul.bsrTmrCfg.prdBsrTmr);
18857             */
18858          }
18859       }
18860    }
18861 #endif
18862    /* Resetting UEs lower Cap */
18863    ue->ul.minReqBytes = 0;
18864
18865    RETVOID;
18866 }
18867
18868
18869 /**
18870  * @brief Returns the "Itbs" for a given UE.
18871  *
18872  * @details
18873  *
18874  *     Function: rgSCHCmnUlGetITbs
18875  *     Purpose:  This function returns the "Itbs" for a given UE.
18876  *
18877  *     Invoked by: Scheduler
18878  *
18879  *  @param[in]  RgSchUeCb        *ue
18880  *  @return     U8
18881  **/
18882 #ifdef ANSI
18883 U8 rgSCHCmnUlGetITbs
18884 (
18885 RgSchCellCb      *cell,
18886 RgSchUeCb        *ue,
18887 Bool             isEcp
18888 )
18889 #else
18890 U8 rgSCHCmnUlGetITbs(cell, ue, isEcp)
18891 RgSchCellCb      *cell;
18892 RgSchUeCb        *ue;
18893 Bool             isEcp;
18894 #endif
18895 {
18896    RgSchCmnUlUe *ueUl    = RG_SCH_CMN_GET_UL_UE(ue,cell);
18897    /* CQI will be capped to maxUlCqi for 16qam UEs */
18898    CmLteUeCategory  ueCtgy = (CmLteUeCategory)(RG_SCH_CMN_GET_UE_CTGY(ue));
18899    U8            cqi;
18900 #ifdef UL_LA
18901    S32            iTbs;
18902    U8            maxiTbs = rgSchCmnUlCqiToTbsTbl[(U8)isEcp][ueUl->maxUlCqi]; 
18903 #endif
18904
18905
18906    /* #ifdef RG_SCH_CMN_EXT_CP_SUP For ECP pick index 1 */
18907 #ifdef TFU_UPGRADE
18908    if ( (ueCtgy != CM_LTE_UE_CAT_5) &&
18909         (ueUl->validUlCqi > ueUl->maxUlCqi)
18910       )
18911    {
18912       cqi = ueUl->maxUlCqi;
18913    }
18914    else
18915    {
18916       cqi = ueUl->validUlCqi;
18917    }
18918
18919 #ifdef UL_LA
18920    iTbs = (ueUl->ulLaCb.cqiBasediTbs + ueUl->ulLaCb.deltaiTbs)/100;
18921
18922    RG_SCH_CHK_ITBS_RANGE(iTbs, maxiTbs); 
18923
18924    iTbs = RGSCH_MIN(iTbs,  ue->cell->thresholds.maxUlItbs);
18925
18926 #ifdef LTE_TDD
18927    /* This is a Temp fix, done for TENBPLUS-3898, ULSCH SDU corruption
18928       was seen when IMCS exceeds 20 on T2k TDD */
18929    if (iTbs > 19)
18930    {
18931       iTbs = 19;
18932    }
18933 #endif
18934    return (iTbs);
18935 #endif 
18936 #else
18937    if ( (ueCtgy != CM_LTE_UE_CAT_5) && (ueUl->crntUlCqi[0] > ueUl->maxUlCqi ))
18938    {
18939       cqi = ueUl->maxUlCqi;
18940    }
18941    else
18942    {
18943       cqi = ueUl->crntUlCqi[0];
18944    }
18945 #endif
18946    return (rgSchCmnUlCqiToTbsTbl[(U8)isEcp][cqi]);
18947 }
18948
18949 /**
18950  * @brief This function adds the UE to DLRbAllocInfo TX lst.
18951  *
18952  * @details
18953  *
18954  *     Function: rgSCHCmnDlRbInfoAddUeTx
18955  *     Purpose:  This function adds the UE to DLRbAllocInfo TX lst.
18956  *
18957  *     Invoked by: Common Scheduler
18958  *
18959  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
18960  *  @param[in]  RgSchUeCb             *ue
18961  *  @param[in]  RgSchDlHqProcCb       *hqP
18962  *  @return  Void
18963  *
18964  **/
18965 #ifdef ANSI
18966 PRIVATE Void rgSCHCmnDlRbInfoAddUeTx
18967 (
18968 RgSchCellCb        *cell,
18969 RgSchCmnDlRbAllocInfo *allocInfo,
18970 RgSchUeCb             *ue,
18971 RgSchDlHqProcCb       *hqP
18972 )
18973 #else
18974 PRIVATE Void rgSCHCmnDlRbInfoAddUeTx(cell, allocInfo, ue, hqP)
18975 RgSchCellCb        *cell;
18976 RgSchCmnDlRbAllocInfo *allocInfo;
18977 RgSchUeCb             *ue;
18978 RgSchDlHqProcCb       *hqP;
18979 #endif
18980 {
18981    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
18982
18983
18984    if (hqP->reqLnk.node == NULLP)
18985    {
18986       if (cellSch->dl.isDlFreqSel)
18987       {
18988          cellSch->apisDlfs->rgSCHDlfsAddUeToLst(cell,
18989            &allocInfo->dedAlloc.txHqPLst, hqP);
18990       }
18991       else
18992       {
18993          {
18994             cmLListAdd2Tail(&allocInfo->dedAlloc.txHqPLst, &hqP->reqLnk);
18995          }
18996          hqP->reqLnk.node = (PTR)hqP;
18997       }
18998    }
18999    RETVOID;
19000 }
19001
19002 /**
19003  * @brief This function adds the UE to DLRbAllocInfo RETX lst.
19004  *
19005  * @details
19006  *
19007  *     Function: rgSCHCmnDlRbInfoAddUeRetx
19008  *     Purpose:  This function adds the UE to DLRbAllocInfo RETX lst.
19009  *
19010  *     Invoked by: Common Scheduler
19011  *
19012  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
19013  *  @param[in]  RgSchUeCb             *ue
19014  *  @param[in]  RgSchDlHqProcCb       *hqP
19015  *  @return  Void
19016  *
19017  **/
19018 #ifdef ANSI
19019 PRIVATE Void rgSCHCmnDlRbInfoAddUeRetx
19020 (
19021 RgSchCellCb        *cell,
19022 RgSchCmnDlRbAllocInfo *allocInfo,
19023 RgSchUeCb             *ue,
19024 RgSchDlHqProcCb       *hqP
19025 )
19026 #else
19027 PRIVATE Void rgSCHCmnDlRbInfoAddUeRetx(cell, allocInfo, ue, hqP)
19028 RgSchCellCb        *cell;
19029 RgSchCmnDlRbAllocInfo *allocInfo;
19030 RgSchUeCb             *ue;
19031 RgSchDlHqProcCb       *hqP;
19032 #endif
19033 {
19034    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(ue->cell);
19035
19036
19037    if (cellSch->dl.isDlFreqSel)
19038    {
19039       cellSch->apisDlfs->rgSCHDlfsAddUeToLst(cell,
19040         &allocInfo->dedAlloc.retxHqPLst, hqP);
19041    }
19042    else
19043    {
19044       /* checking UE's presence in this lst is unnecessary */
19045       cmLListAdd2Tail(&allocInfo->dedAlloc.retxHqPLst, &hqP->reqLnk);
19046       hqP->reqLnk.node = (PTR)hqP;
19047    }
19048    RETVOID;
19049 }
19050
19051 /**
19052  * @brief This function adds the UE to DLRbAllocInfo TX-RETX lst.
19053  *
19054  * @details
19055  *
19056  *     Function: rgSCHCmnDlRbInfoAddUeRetxTx
19057  *     Purpose:  This adds the UE to DLRbAllocInfo TX-RETX lst.
19058  *
19059  *     Invoked by: Common Scheduler
19060  *
19061  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
19062  *  @param[in]  RgSchUeCb             *ue
19063  *  @param[in]  RgSchDlHqProcCb       *hqP
19064  *  @return  Void
19065  *
19066  **/
19067 #ifdef ANSI
19068 PRIVATE Void rgSCHCmnDlRbInfoAddUeRetxTx
19069 (
19070 RgSchCellCb        *cell,
19071 RgSchCmnDlRbAllocInfo *allocInfo,
19072 RgSchUeCb             *ue,
19073 RgSchDlHqProcCb       *hqP
19074 )
19075 #else
19076 PRIVATE Void rgSCHCmnDlRbInfoAddUeRetxTx(allocInfo, ue, hqP)
19077 RgSchCellCb        *cell;
19078 RgSchCmnDlRbAllocInfo *allocInfo;
19079 RgSchUeCb             *ue;
19080 RgSchDlHqProcCb       *hqP;
19081 #endif
19082 {
19083    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(ue->cell);
19084
19085
19086    if (cellSch->dl.isDlFreqSel)
19087    {
19088       cellSch->apisDlfs->rgSCHDlfsAddUeToLst(cell,
19089         &allocInfo->dedAlloc.txRetxHqPLst, hqP);
19090    }
19091    else
19092    {
19093       cmLListAdd2Tail(&allocInfo->dedAlloc.txRetxHqPLst, &hqP->reqLnk);
19094       hqP->reqLnk.node = (PTR)hqP;
19095    }
19096    RETVOID;
19097 }
19098
19099 /**
19100  * @brief This function adds the UE to DLRbAllocInfo NonSchdRetxLst.
19101  *
19102  * @details
19103  *
19104  *     Function: rgSCHCmnDlAdd2NonSchdRetxLst 
19105  *     Purpose:  During RB estimation for RETX, if allocation fails
19106  *               then appending it to NonSchdRetxLst, the further
19107  *               action is taken as part of Finalization in
19108  *               respective schedulers.
19109  *
19110  *     Invoked by: Common Scheduler
19111  *
19112  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
19113  *  @param[in]  RgSchUeCb             *ue
19114  *  @param[in]  RgSchDlHqProcCb       *hqP
19115  *  @return  Void
19116  *
19117  **/
19118 #ifdef ANSI
19119 PRIVATE Void rgSCHCmnDlAdd2NonSchdRetxLst 
19120 (
19121 RgSchCmnDlRbAllocInfo *allocInfo,
19122 RgSchUeCb             *ue,
19123 RgSchDlHqProcCb       *hqP
19124 )
19125 #else
19126 PRIVATE Void rgSCHCmnDlAdd2NonSchdRetxLst(allocInfo, ue, hqP)
19127 RgSchCmnDlRbAllocInfo *allocInfo;
19128 RgSchUeCb             *ue;
19129 RgSchDlHqProcCb       *hqP;
19130 #endif
19131 {
19132    CmLList         *schdLnkNode;
19133
19134
19135 #ifdef LTEMAC_SPS
19136    if ( (hqP->sch != (RgSchCmnDlHqProc *)NULLP) && 
19137          (RG_SCH_CMN_SPS_DL_IS_SPS_HQP(hqP)))
19138    {
19139       RETVOID;
19140    }
19141 #endif
19142
19143    schdLnkNode = &hqP->schdLstLnk;
19144    RG_SCH_CMN_INIT_SCHD_LNK(schdLnkNode, hqP);
19145    cmLListAdd2Tail(&allocInfo->dedAlloc.nonSchdRetxHqPLst, schdLnkNode);
19146
19147    RETVOID;
19148 }
19149
19150
19151
19152 /**
19153  * @brief This function adds the UE to DLRbAllocInfo NonSchdTxRetxLst.
19154  *
19155  * @details
19156  *
19157  *     Function: rgSCHCmnDlAdd2NonSchdTxRetxLst 
19158  *     Purpose:  During RB estimation for TXRETX, if allocation fails
19159  *               then appending it to NonSchdTxRetxLst, the further
19160  *               action is taken as part of Finalization in
19161  *               respective schedulers.
19162  *
19163  *     Invoked by: Common Scheduler
19164  *
19165  *  @param[out] RgSchCmnDlRbAllocInfo *allocInfo
19166  *  @param[in]  RgSchUeCb             *ue
19167  *  @param[in]  RgSchDlHqProcCb       *hqP
19168  *  @return  Void
19169  *
19170  **/
19171 #ifdef LTE_TDD
19172 /**
19173  * @brief This function handles the initialisation of DL HARQ/ACK feedback
19174  *        timing information for eaach DL subframe.
19175  *
19176  * @details
19177  *
19178  *     Function: rgSCHCmnDlANFdbkInit
19179  *     Purpose:  Each DL subframe stores the sfn and subframe
19180  *               information of UL subframe in which it expects
19181  *               HARQ ACK/NACK feedback for this subframe.It
19182  *               generates the information based on Downlink
19183  *               Association Set Index table.
19184  *
19185  *     Invoked by: Scheduler
19186  *
19187  *  @param[in]  RgSchCellCb*     cell
19188  *  @return     S16
19189  *
19190  **/
19191 #ifdef ANSI
19192 PRIVATE S16 rgSCHCmnDlANFdbkInit
19193 (
19194 RgSchCellCb                *cell
19195 )
19196 #else
19197 PRIVATE S16 rgSCHCmnDlANFdbkInit(cell)
19198 RgSchCellCb                *cell;
19199 #endif
19200 {
19201  U8                   sfCount;
19202  U8                   ulDlCfgIdx = cell->ulDlCfgIdx;
19203  U8                   maxDlSubfrms = cell->numDlSubfrms;
19204  U8                   sfNum;
19205  U8                   idx;
19206  U8                   dlIdx;
19207  U8                   calcSfnOffset;
19208  S8                   calcSfNum;
19209  U8                   ulSfCnt =0;
19210  RgSchTddSubfrmInfo   ulSubfrmInfo;
19211  U8                   maxUlSubfrms;
19212
19213
19214    ulSubfrmInfo = rgSchTddMaxUlSubfrmTbl[ulDlCfgIdx];
19215    maxUlSubfrms = rgSchTddNumUlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
19216
19217    /* Generate HARQ ACK/NACK feedback information for each DL sf in a radio frame
19218     * Calculate this information based on DL Association set Index table */
19219    for (sfCount = 0, sfNum = 0; sfCount < maxUlSubfrms; sfCount++)
19220    {
19221       while(rgSchTddUlDlSubfrmTbl[ulDlCfgIdx][sfNum] !=
19222             RG_SCH_TDD_UL_SUBFRAME)
19223       {
19224          sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
19225       }
19226       ulSfCnt++;
19227
19228       for(idx=0; idx < rgSchTddDlAscSetIdxKTbl[ulDlCfgIdx][sfNum].\
19229             numFdbkSubfrms; idx++)
19230       {
19231          calcSfNum = sfNum - rgSchTddDlAscSetIdxKTbl[ulDlCfgIdx][sfNum].\
19232                      subfrmNum[idx];
19233          if(calcSfNum < 0)
19234          {
19235             calcSfnOffset = RGSCH_CEIL(-calcSfNum, RGSCH_NUM_SUB_FRAMES);
19236          }
19237          else
19238          {
19239             calcSfnOffset = 0;
19240          }
19241
19242          calcSfNum = ((RGSCH_NUM_SUB_FRAMES * calcSfnOffset) + calcSfNum)\
19243                      % RGSCH_NUM_SUB_FRAMES;
19244
19245          if(calcSfNum <= RG_SCH_CMN_SPL_SUBFRM_1)
19246          {
19247             dlIdx = calcSfNum;
19248          }
19249          else if((ulSubfrmInfo.switchPoints == 2) && (calcSfNum <= \
19250                   RG_SCH_CMN_SPL_SUBFRM_6))
19251          {
19252             dlIdx = calcSfNum - ulSubfrmInfo.numFrmHf1;
19253          }
19254          else
19255          {
19256             dlIdx = calcSfNum - maxUlSubfrms;
19257          }
19258
19259          cell->subFrms[dlIdx]->dlFdbkInfo.subframe = sfNum;
19260          cell->subFrms[dlIdx]->dlFdbkInfo.sfnOffset = calcSfnOffset;
19261          cell->subFrms[dlIdx]->dlFdbkInfo.m = idx;
19262       }
19263       sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
19264    }
19265
19266    /* DL subframes in the subsequent radio frames are initialized
19267     * with the previous radio frames  */
19268    for(dlIdx = RGSCH_NUM_SUB_FRAMES - maxUlSubfrms; dlIdx < maxDlSubfrms;\
19269          dlIdx++)
19270    {
19271       sfNum = dlIdx - rgSchTddNumDlSubfrmTbl[ulDlCfgIdx]\
19272               [RGSCH_NUM_SUB_FRAMES-1];
19273       cell->subFrms[dlIdx]->dlFdbkInfo.subframe = \
19274                                                   cell->subFrms[sfNum]->dlFdbkInfo.subframe;
19275       cell->subFrms[dlIdx]->dlFdbkInfo.sfnOffset = \
19276                                                    cell->subFrms[sfNum]->dlFdbkInfo.sfnOffset;
19277       cell->subFrms[dlIdx]->dlFdbkInfo.m = cell->subFrms[sfNum]->dlFdbkInfo.m;
19278    }
19279    return ROK;
19280 }
19281
19282 /**
19283  * @brief This function handles the initialization of uplink association
19284  *        set information for each DL subframe.
19285  *
19286  *
19287  * @details
19288  *
19289  *     Function: rgSCHCmnDlKdashUlAscInit
19290  *     Purpose:  Each DL sf stores the sfn and sf information of UL sf
19291  *               in which it expects HQ ACK/NACK trans. It generates the information
19292  *               based on k` in UL association set index table.
19293  *
19294  *     Invoked by: Scheduler
19295  *
19296  *  @param[in]  RgSchCellCb*     cell
19297  *  @return     S16
19298  *
19299  **/
19300 #ifdef ANSI
19301 PRIVATE S16 rgSCHCmnDlKdashUlAscInit
19302 (
19303 RgSchCellCb                *cell
19304 )
19305 #else
19306 PRIVATE S16 rgSCHCmnDlKdashUlAscInit(cell)
19307 RgSchCellCb                *cell;
19308 #endif
19309 {
19310  U8                   sfCount;
19311  U8                   ulDlCfgIdx = cell->ulDlCfgIdx;
19312  U8                   maxDlSubfrms = cell->numDlSubfrms;
19313  U8                   sfNum;
19314  U8                   dlIdx;
19315  S8                   calcSfnOffset;
19316  S8                   calcSfNum;
19317  U8                   ulSfCnt =0;
19318  RgSchTddSubfrmInfo   ulSubfrmInfo = rgSchTddMaxUlSubfrmTbl[ulDlCfgIdx];
19319  U8                   maxUlSubfrms = rgSchTddNumUlSubfrmTbl[ulDlCfgIdx]\
19320                                      [RGSCH_NUM_SUB_FRAMES-1];
19321  U8                   dlPres = 0;
19322
19323
19324    /* Generate ACK/NACK offset information for each DL subframe in a radio frame
19325     * Calculate this information based on K` in UL Association Set table */
19326    for (sfCount = 0, sfNum = 0; sfCount < maxUlSubfrms; sfCount++)
19327    {
19328       while(rgSchTddUlDlSubfrmTbl[ulDlCfgIdx][sfNum] !=
19329             RG_SCH_TDD_UL_SUBFRAME)
19330       {
19331          sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
19332       }
19333       ulSfCnt++;
19334
19335       calcSfNum = (sfNum - rgSchTddUlAscIdxKDashTbl[ulDlCfgIdx-1][sfNum] + \
19336             RGSCH_NUM_SUB_FRAMES) % RGSCH_NUM_SUB_FRAMES;
19337       calcSfnOffset = sfNum - rgSchTddUlAscIdxKDashTbl[ulDlCfgIdx-1][sfNum];
19338       if(calcSfnOffset < 0)
19339       {
19340          calcSfnOffset = RGSCH_CEIL(-calcSfnOffset, RGSCH_NUM_SUB_FRAMES);
19341       }
19342       else
19343       {
19344          calcSfnOffset = 0;
19345       }
19346
19347       if(calcSfNum <= RG_SCH_CMN_SPL_SUBFRM_1)
19348       {
19349          dlIdx = calcSfNum;
19350       }
19351       else if((ulSubfrmInfo.switchPoints == 2) &&
19352             (calcSfNum <= RG_SCH_CMN_SPL_SUBFRM_6))
19353       {
19354          dlIdx = calcSfNum - ulSubfrmInfo.numFrmHf1;
19355       }
19356       else
19357       {
19358          dlIdx = calcSfNum - maxUlSubfrms;
19359       }
19360
19361       cell->subFrms[dlIdx]->ulAscInfo.subframe = sfNum;
19362       cell->subFrms[dlIdx]->ulAscInfo.sfnOffset = calcSfnOffset;
19363
19364       /* set dlIdx for which ulAscInfo is updated */
19365       dlPres = dlPres | (1 << dlIdx);
19366       sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
19367    }
19368
19369    /* Set Invalid information for which ulAscInfo is not present */
19370    for (sfCount = 0;
19371          sfCount < rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
19372          sfCount++)
19373    {
19374       /* If dlPres is 0, ulAscInfo is not present in that DL index */
19375       if(! ((dlPres >> sfCount)&0x01))
19376       {
19377          cell->subFrms[sfCount]->ulAscInfo.sfnOffset =
19378             RGSCH_INVALID_INFO;
19379          cell->subFrms[sfCount]->ulAscInfo.subframe =
19380             RGSCH_INVALID_INFO;
19381       }
19382    }
19383
19384    /* DL subframes in the subsequent radio frames are initialized
19385     * with the previous radio frames  */
19386    for(dlIdx = RGSCH_NUM_SUB_FRAMES - maxUlSubfrms; dlIdx < maxDlSubfrms;
19387          dlIdx++)
19388    {
19389       sfNum = dlIdx - \
19390               rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
19391       cell->subFrms[dlIdx]->ulAscInfo.subframe =
19392          cell->subFrms[sfNum]->ulAscInfo.subframe;
19393       cell->subFrms[dlIdx]->ulAscInfo.sfnOffset =
19394          cell->subFrms[sfNum]->ulAscInfo.sfnOffset;
19395    }
19396    return ROK;
19397 }
19398
19399
19400 /**
19401  * @brief This function initialises the 'Np' value for 'p'
19402  *
19403  * @details
19404  *
19405  *     Function: rgSCHCmnDlNpValInit
19406  *     Purpose:  To initialise the 'Np' value for each 'p'. It is used
19407  *               to find the mapping between nCCE and 'p' and used in
19408  *               HARQ ACK/NACK reception.
19409  *
19410  *     Invoked by: Scheduler
19411  *
19412  *  @param[in]  RgSchCellCb*     cell
19413  *  @return     S16
19414  *
19415  **/
19416 #ifdef ANSI
19417 PRIVATE S16 rgSCHCmnDlNpValInit
19418 (
19419 RgSchCellCb                *cell
19420 )
19421 #else
19422 PRIVATE S16 rgSCHCmnDlNpValInit(cell)
19423 RgSchCellCb                *cell;
19424 #endif
19425 {
19426    U8    idx;
19427    U16   np;
19428
19429    /* Always Np is 0 for p=0 */
19430    cell->rgSchTddNpValTbl[0] = 0;
19431
19432    for(idx=1; idx < RGSCH_TDD_MAX_P_PLUS_ONE_VAL; idx++)
19433    {
19434       np = cell->bwCfg.dlTotalBw * (idx * RG_SCH_CMN_NUM_SUBCAR - 4);
19435       cell->rgSchTddNpValTbl[idx] = (U8) (np/36);
19436    }
19437
19438    return ROK;
19439 }
19440
19441 /**
19442  * @brief This function handles the creation of RACH preamble
19443  *        list to queue the preambles and process at the scheduled
19444  *        time.
19445  *
19446  * @details
19447  *
19448  *     Function: rgSCHCmnDlCreateRachPrmLst
19449  *     Purpose:  To create RACH preamble list based on RA window size.
19450  *               It is used to queue the preambles and process it at the
19451  *               scheduled time.
19452  *
19453  *     Invoked by: Scheduler
19454  *
19455  *  @param[in]  RgSchCellCb*     cell
19456  *  @return     S16
19457  *
19458  **/
19459 #ifdef ANSI
19460 PRIVATE S16 rgSCHCmnDlCreateRachPrmLst
19461 (
19462 RgSchCellCb                *cell
19463 )
19464 #else
19465 PRIVATE S16 rgSCHCmnDlCreateRachPrmLst(cell)
19466 RgSchCellCb                *cell;
19467 #endif
19468 {
19469  U8       raArrSz;
19470  S16       ret;
19471  U8       lstSize;
19472
19473
19474    RG_SCH_CMN_CALC_RARSPLST_SIZE(cell, raArrSz);
19475
19476    lstSize = raArrSz * RGSCH_MAX_RA_RNTI_PER_SUBFRM * RGSCH_NUM_SUB_FRAMES;
19477
19478    cell->raInfo.maxRaSize = raArrSz;
19479    ret = rgSCHUtlAllocSBuf(cell->instIdx,
19480          (Data **)(&cell->raInfo.raReqLst), (Size)(lstSize * sizeof(CmLListCp)));
19481    if (ret != ROK)
19482    {
19483       return (ret);
19484    }
19485
19486    cell->raInfo.lstSize = lstSize;
19487
19488    return ROK;
19489 }
19490
19491
19492 /**
19493  * @brief This function handles the initialization of RACH Response
19494  *        information at each DL subframe.
19495  *
19496  * @details
19497  *
19498  *     Function: rgSCHCmnDlRachInfoInit
19499  *     Purpose:  Each DL subframe stores the sfn and subframe information of
19500  *               possible RACH response allowed for UL subframes. It generates
19501  *               the information based on PRACH configuration.
19502  *
19503  *     Invoked by: Scheduler
19504  *
19505  *  @param[in]  RgSchCellCb*     cell
19506  *  @return     S16
19507  *
19508  **/
19509 #ifdef ANSI
19510 PRIVATE S16 rgSCHCmnDlRachInfoInit
19511 (
19512 RgSchCellCb                *cell
19513 )
19514 #else
19515 PRIVATE S16 rgSCHCmnDlRachInfoInit(cell)
19516 RgSchCellCb                *cell;
19517 #endif
19518 {
19519    U8                   sfCount;
19520    U8                   ulDlCfgIdx = cell->ulDlCfgIdx;
19521    U8                   sfNum;
19522    U8                   ulSfCnt =0;
19523    U8                   maxUlSubfrms = rgSchTddNumUlSubfrmTbl[ulDlCfgIdx]\
19524                                        [RGSCH_NUM_SUB_FRAMES-1];
19525    U8                   raArrSz;
19526    RgSchTddRachRspLst   rachRspLst[3][RGSCH_NUM_SUB_FRAMES];
19527    U8                   startWin;
19528    U8                   endWin;
19529    U8                   sfnIdx;
19530    U8                   subfrmIdx;
19531    U8                   endSubfrmIdx;
19532    U8                   startSubfrmIdx;
19533    S16                   ret;
19534    RgSchTddRachDelInfo  *delInfo;
19535    S8                   sfnOffset;
19536    U8                   numSubfrms;
19537
19538
19539    memset(rachRspLst, 0, sizeof(rachRspLst));
19540
19541    RG_SCH_CMN_CALC_RARSPLST_SIZE(cell, raArrSz);
19542
19543    /* Include Special subframes */
19544    maxUlSubfrms = maxUlSubfrms + \
19545                   rgSchTddMaxUlSubfrmTbl[ulDlCfgIdx].switchPoints;
19546    for (sfCount = 0, sfNum = 0; sfCount < maxUlSubfrms; sfCount++)
19547    {
19548       while(rgSchTddUlDlSubfrmTbl[ulDlCfgIdx][sfNum] ==
19549             RG_SCH_TDD_DL_SUBFRAME)
19550       {
19551          sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
19552       }
19553       ulSfCnt++;
19554
19555       startWin = (sfNum + RG_SCH_CMN_RARSP_WAIT_PRD + \
19556             ((RgSchCmnCell *)cell->sc.sch)->dl.numRaSubFrms);
19557       endWin = (startWin + cell->rachCfg.raWinSize - 1);
19558       startSubfrmIdx =
19559          rgSchTddHighDlSubfrmIdxTbl[ulDlCfgIdx][startWin%RGSCH_NUM_SUB_FRAMES];
19560       /* Find the next DL subframe starting from Subframe 0 */
19561       if((startSubfrmIdx % RGSCH_NUM_SUB_FRAMES) == 0)
19562       {
19563          startWin = RGSCH_CEIL(startWin, RGSCH_NUM_SUB_FRAMES);
19564          startWin = startWin * RGSCH_NUM_SUB_FRAMES;
19565       }
19566
19567       endSubfrmIdx =
19568          rgSchTddLowDlSubfrmIdxTbl[ulDlCfgIdx][endWin%RGSCH_NUM_SUB_FRAMES];
19569       endWin = (endWin/RGSCH_NUM_SUB_FRAMES) * RGSCH_NUM_SUB_FRAMES \
19570                + endSubfrmIdx;
19571       if(startWin > endWin)
19572       {
19573          continue;
19574       }
19575       /* Find all the possible RACH Response transmission
19576        * time within the RA window size */
19577       startSubfrmIdx = startWin%RGSCH_NUM_SUB_FRAMES;
19578       for(sfnIdx = startWin/RGSCH_NUM_SUB_FRAMES;
19579             sfnIdx <= endWin/RGSCH_NUM_SUB_FRAMES; sfnIdx++)
19580       {
19581          if(sfnIdx == endWin/RGSCH_NUM_SUB_FRAMES)
19582          {
19583             endSubfrmIdx = endWin%RGSCH_NUM_SUB_FRAMES;
19584          }
19585          else
19586          {
19587             endSubfrmIdx = RGSCH_NUM_SUB_FRAMES-1;
19588          }
19589
19590          /* Find all the possible RACH Response transmission
19591           * time within radio frame */
19592          for(subfrmIdx = startSubfrmIdx;
19593                subfrmIdx <= endSubfrmIdx; subfrmIdx++)
19594          {
19595             if(rgSchTddUlDlSubfrmTbl[ulDlCfgIdx][subfrmIdx] ==
19596                   RG_SCH_TDD_UL_SUBFRAME)
19597             {
19598                continue;
19599             }
19600             subfrmIdx = rgSchTddHighDlSubfrmIdxTbl[ulDlCfgIdx][subfrmIdx];
19601             /* Find the next DL subframe starting from Subframe 0 */
19602             if(subfrmIdx == RGSCH_NUM_SUB_FRAMES)
19603             {
19604                break;
19605             }
19606             RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rachRspLst[sfnIdx], subfrmIdx);
19607             numSubfrms =
19608                rachRspLst[sfnIdx][subfrmIdx].rachRsp[0].numSubfrms;
19609             rachRspLst[sfnIdx][subfrmIdx].rachRsp[0].sfnOffset = sfnIdx;
19610             rachRspLst[sfnIdx][subfrmIdx].rachRsp[0].subframe[numSubfrms]
19611                = sfNum;
19612             rachRspLst[sfnIdx][subfrmIdx].rachRsp[0].numSubfrms++;
19613          }
19614          startSubfrmIdx = RG_SCH_CMN_SUBFRM_0;
19615       }
19616       /* Update the subframes to be deleted at this subframe */
19617       /* Get the subframe after the end of RA window size */
19618       endWin++;
19619       endSubfrmIdx++;
19620       sfnOffset = endWin/RGSCH_NUM_SUB_FRAMES;
19621       if(sfnOffset < 0)
19622       {
19623          sfnOffset += raArrSz;
19624       }
19625       sfnIdx = (endWin/RGSCH_NUM_SUB_FRAMES) % raArrSz;
19626
19627       RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgSchTddHighDlSubfrmIdxTbl[ulDlCfgIdx],endSubfrmIdx-1);
19628       if((endSubfrmIdx == RGSCH_NUM_SUB_FRAMES) ||
19629             (rgSchTddHighDlSubfrmIdxTbl[ulDlCfgIdx][endSubfrmIdx] ==
19630              RGSCH_NUM_SUB_FRAMES))
19631       {
19632          subfrmIdx =
19633             rgSchTddHighDlSubfrmIdxTbl[ulDlCfgIdx][RG_SCH_CMN_SUBFRM_0];
19634       }
19635       else
19636       {
19637          subfrmIdx = rgSchTddHighDlSubfrmIdxTbl[ulDlCfgIdx][endSubfrmIdx];
19638       }
19639
19640       delInfo = &rachRspLst[sfnIdx][subfrmIdx].delInfo;
19641       delInfo->sfnOffset = sfnOffset;
19642       delInfo->subframe[delInfo->numSubfrms] = sfNum;
19643       delInfo->numSubfrms++;
19644
19645       sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
19646    }
19647
19648    ret = rgSCHCmnDlCpyRachInfo(cell, rachRspLst, raArrSz);
19649    if (ret != ROK)
19650    {
19651       return (ret);
19652    }
19653
19654    return ROK;
19655 }
19656
19657 /**
19658  * @brief This function handles the initialization of PHICH information
19659  *        for each DL subframe based on PHICH table.
19660  *
19661  * @details
19662  *
19663  *     Function: rgSCHCmnDlPhichOffsetInit
19664  *     Purpose:  Each DL subf stores the sfn and subf information of UL subframe
19665  *               for which it trnsmts PHICH in this subframe. It generates the information
19666  *               based on PHICH table.
19667  *
19668  *     Invoked by: Scheduler
19669  *
19670  *  @param[in]  RgSchCellCb*     cell
19671  *  @return     S16
19672  *
19673  **/
19674 #ifdef ANSI
19675 PRIVATE S16 rgSCHCmnDlPhichOffsetInit
19676 (
19677 RgSchCellCb                *cell
19678 )
19679 #else
19680 PRIVATE S16 rgSCHCmnDlPhichOffsetInit(cell)
19681 RgSchCellCb                *cell;
19682 #endif
19683 {
19684    U8                   sfCount;
19685    U8                   ulDlCfgIdx = cell->ulDlCfgIdx;
19686    U8                   maxDlSubfrms = cell->numDlSubfrms;
19687    U8                   sfNum;
19688    U8                   dlIdx;
19689    U8                   dlPres = 0;
19690    U8                   calcSfnOffset;
19691    U8                   calcSfNum;
19692    U8                   ulSfCnt =0;
19693    RgSchTddSubfrmInfo   ulSubfrmInfo = rgSchTddMaxUlSubfrmTbl[ulDlCfgIdx];
19694    U8                   maxUlSubfrms = rgSchTddNumUlSubfrmTbl[ulDlCfgIdx]\
19695                                        [RGSCH_NUM_SUB_FRAMES-1];
19696
19697
19698    /* Generate PHICH offset information for each DL subframe in a radio frame
19699     * Calculate this information based on K in PHICH table */
19700    for (sfCount = 0, sfNum = 0; sfCount < maxUlSubfrms; sfCount++)
19701    {
19702       while(rgSchTddUlDlSubfrmTbl[ulDlCfgIdx][sfNum] !=
19703             RG_SCH_TDD_UL_SUBFRAME)
19704       {
19705          sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
19706       }
19707       ulSfCnt++;
19708
19709       calcSfNum = (rgSchTddKPhichTbl[ulDlCfgIdx][sfNum] + sfNum) % \
19710                   RGSCH_NUM_SUB_FRAMES;
19711       calcSfnOffset = (rgSchTddKPhichTbl[ulDlCfgIdx][sfNum] + sfNum) / \
19712                       RGSCH_NUM_SUB_FRAMES;
19713
19714       if(calcSfNum <= RG_SCH_CMN_SPL_SUBFRM_1)
19715       {
19716          dlIdx = calcSfNum;
19717       }
19718       else if((ulSubfrmInfo.switchPoints == 2) &&
19719             (calcSfNum <= RG_SCH_CMN_SPL_SUBFRM_6))
19720       {
19721          dlIdx = calcSfNum - ulSubfrmInfo.numFrmHf1;
19722       }
19723       else
19724       {
19725          dlIdx = calcSfNum - maxUlSubfrms;
19726       }
19727
19728       cell->subFrms[dlIdx]->phichOffInfo.subframe = sfNum;
19729       cell->subFrms[dlIdx]->phichOffInfo.numSubfrms = 1;
19730
19731       cell->subFrms[dlIdx]->phichOffInfo.sfnOffset = calcSfnOffset;
19732
19733       /* set dlIdx for which phich offset is updated */
19734       dlPres = dlPres | (1 << dlIdx);
19735       sfNum = (sfNum+1) % RGSCH_NUM_SUB_FRAMES;
19736    }
19737
19738    /* Set Invalid information for which phich offset is not present */
19739    for (sfCount = 0;
19740          sfCount < rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
19741          sfCount++)
19742    {
19743       /* If dlPres is 0, phich offset is not present in that DL index */
19744       if(! ((dlPres >> sfCount)&0x01))
19745       {
19746          cell->subFrms[sfCount]->phichOffInfo.sfnOffset =
19747             RGSCH_INVALID_INFO;
19748          cell->subFrms[sfCount]->phichOffInfo.subframe =
19749             RGSCH_INVALID_INFO;
19750          cell->subFrms[sfCount]->phichOffInfo.numSubfrms = 0;
19751       }
19752    }
19753
19754    /* DL subframes in the subsequent radio frames are
19755     * initialized with the previous radio frames  */
19756    for(dlIdx = RGSCH_NUM_SUB_FRAMES - maxUlSubfrms;
19757          dlIdx < maxDlSubfrms; dlIdx++)
19758    {
19759       sfNum = dlIdx - \
19760               rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1];
19761
19762       cell->subFrms[dlIdx]->phichOffInfo.subframe =
19763          cell->subFrms[sfNum]->phichOffInfo.subframe;
19764
19765       cell->subFrms[dlIdx]->phichOffInfo.sfnOffset =
19766          cell->subFrms[sfNum]->phichOffInfo.sfnOffset;
19767    }
19768    return ROK;
19769 }
19770
19771
19772 /**
19773  * @brief Updation of Sch vars per TTI.
19774  *
19775  * @details
19776  *
19777  *     Function: rgSCHCmnUpdVars
19778  *     Purpose:  Updation of Sch vars per TTI.
19779  *
19780  *  @param[in]  RgSchCellCb *cell
19781  *  @return  Void
19782  *
19783  **/
19784 #ifdef ANSI
19785 Void rgSCHCmnUpdVars
19786 (
19787 RgSchCellCb *cell
19788 )
19789 #else
19790 Void rgSCHCmnUpdVars(cell)
19791 RgSchCellCb *cell;
19792 #endif
19793 {
19794    RgSchCmnUlCell    *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
19795    CmLteTimingInfo   timeInfo;
19796    U8                idx;
19797    U8                ulSubframe;
19798    U8                ulDlCfgIdx = cell->ulDlCfgIdx;
19799    U8                msg3Subfrm;
19800    U8                Mval;
19801  
19802    /* ccpu00132654-ADD- Initializing all the indices in every subframe*/ 
19803    rgSCHCmnInitVars(cell);
19804
19805    idx = (cell->crntTime.slot + TFU_ULCNTRL_DLDELTA) % RGSCH_NUM_SUB_FRAMES;
19806    /* Calculate the UL scheduling subframe idx based on the 
19807       Pusch k table */
19808    if(rgSchTddPuschTxKTbl[ulDlCfgIdx][idx] != 0)
19809    {
19810       /* PUSCH transmission is based on offset from DL
19811        * PDCCH scheduling */
19812       RGSCHCMNADDTOCRNTTIME(cell->crntTime,timeInfo, TFU_ULCNTRL_DLDELTA); 
19813       ulSubframe = rgSchTddPuschTxKTbl[ulDlCfgIdx][timeInfo.subframe];
19814       /* Add the DCI-0 to PUSCH time to get the time of UL subframe */
19815       RGSCHCMNADDTOCRNTTIME(timeInfo, timeInfo, ulSubframe);
19816 #ifdef LTEMAC_SPS
19817       cellUl->schdTti = timeInfo.sfn * 10 + timeInfo.subframe;
19818 #endif
19819       /* Fetch the corresponding  UL subframe Idx in UL sf array */ 
19820       cellUl->schdIdx = rgSCHCmnGetUlSfIdx(&timeInfo, cell);
19821       /* Fetch the corresponding  UL Harq Proc ID */ 
19822       cellUl->schdHqProcIdx = rgSCHCmnGetUlHqProcIdx(&timeInfo, cell);
19823       cellUl->schdTime = timeInfo;
19824    }
19825    Mval = rgSchTddPhichMValTbl[ulDlCfgIdx][idx]; 
19826    if(Mval)
19827    {
19828       /* Fetch the tx time for DL HIDCI-0 */
19829       RGSCHCMNADDTOCRNTTIME(cell->crntTime,timeInfo, TFU_ULCNTRL_DLDELTA);
19830       /* Fetch the corresponding n-k tx time of PUSCH */
19831       cellUl->hqFdbkIdx[0] = rgSCHCmnGetPhichUlSfIdx(&timeInfo, cell);
19832       /* Retx will happen according to the Pusch k table */
19833       cellUl->reTxIdx[0] = cellUl->schdIdx;
19834       
19835       if(ulDlCfgIdx == 0) 
19836       {
19837          /* Calculate the ReTxIdx corresponding to hqFdbkIdx[0] */
19838          cellUl->reTxIdx[0] = rgSchUtlCfg0ReTxIdx(cell,timeInfo,
19839                                                 cellUl->hqFdbkIdx[0]);
19840          if(Mval == 2)
19841          {
19842             /* At Idx 1 store the UL SF adjacent(left) to the UL SF
19843                given at idx 0 */  
19844             cellUl->hqFdbkIdx[1] = (cellUl->hqFdbkIdx[0]-1 + 
19845                                    cellUl->numUlSubfrms) % cellUl->numUlSubfrms;
19846             /* Calculate the ReTxIdx corresponding to hqFdbkIdx[1] */
19847             cellUl->reTxIdx[1] = rgSchUtlCfg0ReTxIdx(cell,timeInfo,
19848                                                 cellUl->hqFdbkIdx[1]);
19849          }                               
19850       }
19851    }
19852
19853    idx = (cell->crntTime.slot + TFU_RECPREQ_DLDELTA) % RGSCH_NUM_SUB_FRAMES;
19854    if (rgSchTddUlDlSubfrmTbl[ulDlCfgIdx][idx] == RG_SCH_TDD_UL_SUBFRAME)
19855    {
19856       RGSCHCMNADDTOCRNTTIME(cell->crntTime, timeInfo, TFU_RECPREQ_DLDELTA)
19857       cellUl->rcpReqIdx   = rgSCHCmnGetUlSfIdx(&timeInfo, cell);
19858    }
19859    idx = (cell->crntTime.slot+RG_SCH_CMN_DL_DELTA) % RGSCH_NUM_SUB_FRAMES;
19860    
19861    /*[ccpu00134666]-MOD-Modify the check to schedule the RAR in
19862      special subframe */                       
19863    if(rgSchTddUlDlSubfrmTbl[ulDlCfgIdx][idx] != RG_SCH_TDD_UL_SUBFRAME)
19864    {
19865       RGSCHCMNADDTOCRNTTIME(cell->crntTime,timeInfo,RG_SCH_CMN_DL_DELTA)
19866       msg3Subfrm = rgSchTddMsg3SubfrmTbl[ulDlCfgIdx][timeInfo.subframe];
19867       RGSCHCMNADDTOCRNTTIME(timeInfo, timeInfo, msg3Subfrm);
19868       cellUl->msg3SchdIdx     = rgSCHCmnGetUlSfIdx(&timeInfo, cell);
19869       cellUl->msg3SchdHqProcIdx = rgSCHCmnGetUlHqProcIdx(&timeInfo, cell);
19870    }
19871 #ifdef LTEMAC_SPS
19872    if(!rgSchTddSpsUlRsrvTbl[ulDlCfgIdx][idx])
19873    {
19874       cellUl->spsUlRsrvIdx = RGSCH_INVALID_INFO;
19875    }
19876    else
19877    {
19878       /* introduce some reuse with above code? */
19879       U8    offst;
19880       RGSCHCMNADDTOCRNTTIME(cell->crntTime,timeInfo,RG_SCH_CMN_DL_DELTA)
19881       //offst = rgSchTddMsg3SubfrmTbl[ulDlCfgIdx][timeInfo.subframe];
19882       offst = rgSchTddSpsUlRsrvTbl[ulDlCfgIdx][timeInfo.subframe];
19883       RGSCHCMNADDTOCRNTTIME(timeInfo, timeInfo, offst);
19884       cellUl->spsUlRsrvIdx     = rgSCHCmnGetUlSfIdx(&timeInfo, cell);
19885       /* The harq proc continues to be accessed and used the same delta before
19886        * actual data occurance, and hence use the same idx */
19887       cellUl->spsUlRsrvHqProcIdx = cellUl->schdHqProcIdx;
19888    }
19889 #endif
19890
19891    /* RACHO: update cmn sched specific RACH variables,
19892     * mainly the prachMaskIndex */
19893    rgSCHCmnUpdRachParam(cell);
19894
19895    RETVOID;
19896 }
19897
19898 /**
19899  * @brief To get 'p' value from nCCE.
19900  *
19901  * @details
19902  *
19903  *     Function: rgSCHCmnGetPValFrmCCE
19904  *     Purpose:  Gets 'p' value for HARQ ACK/NACK reception from CCE.
19905  *
19906  *  @param[in]  RgSchCellCb   *cell
19907  *  @param[in]  U8            cce
19908  *  @return U8
19909  *
19910  **/
19911 #ifdef ANSI
19912 U8  rgSCHCmnGetPValFrmCCE
19913 (
19914 RgSchCellCb *cell,
19915 U8          cce
19916 )
19917 #else
19918 U8  rgSCHCmnGetPValFrmCCE(cell, cce)
19919 RgSchCellCb *cell;
19920 U8          cce;
19921 #endif
19922 {
19923    U8 i;
19924
19925    for(i=1; i < RGSCH_TDD_MAX_P_PLUS_ONE_VAL; i++)
19926    {
19927       if(cce < cell->rgSchTddNpValTbl[i])
19928       {
19929          return (i-1);
19930       }
19931    }
19932    return (0);
19933 }
19934 #endif
19935
19936 /***********************************************************
19937  *
19938  *     Func : rgSCHCmnUlAdapRetx
19939  *
19940  *     Desc : Adaptive retransmission for an allocation.
19941  *
19942  *     Ret  :
19943  *
19944  *     Notes:
19945  *
19946  *     File :
19947  *
19948  **********************************************************/
19949 #ifdef ANSI
19950 PRIVATE Void rgSCHCmnUlAdapRetx
19951 (
19952 RgSchUlAlloc    *alloc,
19953 RgSchUlHqProcCb *proc
19954 )
19955 #else
19956 PRIVATE Void rgSCHCmnUlAdapRetx(alloc, proc)
19957 RgSchUlAlloc    *alloc;
19958 RgSchUlHqProcCb *proc;
19959 #endif
19960 {
19961
19962    rgSCHUhmRetx(proc, alloc);
19963 #ifndef RG_5GTF
19964    if (proc->rvIdx != 0)
19965    {
19966       alloc->grnt.iMcsCrnt = rgSchCmnUlRvIdxToIMcsTbl[proc->rvIdx];
19967    }
19968    else
19969 #endif
19970    {
19971       alloc->grnt.iMcsCrnt = alloc->grnt.iMcs;
19972    }
19973    RETVOID;
19974 }
19975
19976 /**
19977  * @brief Scheduler invocation per TTI.
19978  *
19979  * @details
19980  *
19981  *     Function: rgSCHCmnHdlUlInactUes
19982  *     Purpose:
19983  *
19984  *     Invoked by: Common Scheduler
19985  *
19986  *  @param[in]  RgSchCellCb *cell
19987  *  @return  Void
19988  **/
19989 #ifdef ANSI
19990 PRIVATE Void rgSCHCmnHdlUlInactUes
19991 (
19992 RgSchCellCb  *cell
19993 )
19994 #else
19995 PRIVATE Void rgSCHCmnHdlUlInactUes(cell)
19996 RgSchCellCb  *cell;
19997 #endif
19998 {
19999    RgSchCmnCell  *cellSch  = RG_SCH_CMN_GET_CELL(cell);
20000    CmLListCp     ulInactvLst;
20001    /* Get a List of Inactv UEs for UL*/
20002    cmLListInit(&ulInactvLst);
20003
20004    /* Trigger Spfc Schedulers with Inactive UEs */
20005    rgSCHMeasGapANRepGetUlInactvUe (cell, &ulInactvLst);
20006    /* take care of this in UL retransmission */
20007    cellSch->apisUl->rgSCHUlInactvtUes(cell, &ulInactvLst);
20008
20009    RETVOID;
20010 }
20011
20012 /**
20013  * @brief Scheduler invocation per TTI.
20014  *
20015  * @details
20016  *
20017  *     Function: rgSCHCmnHdlDlInactUes
20018  *     Purpose:
20019  *
20020  *     Invoked by: Common Scheduler
20021  *
20022  *  @param[in]  RgSchCellCb *cell
20023  *  @return  Void
20024  **/
20025 #ifdef ANSI
20026 PRIVATE Void rgSCHCmnHdlDlInactUes
20027 (
20028 RgSchCellCb  *cell
20029 )
20030 #else
20031 PRIVATE Void rgSCHCmnHdlDlInactUes(cell)
20032 RgSchCellCb  *cell;
20033 #endif
20034 {
20035    RgSchCmnCell *cellSch  = RG_SCH_CMN_GET_CELL(cell);
20036    CmLListCp    dlInactvLst;
20037    /* Get a List of Inactv UEs for DL */
20038    cmLListInit(&dlInactvLst);
20039
20040    /* Trigger Spfc Schedulers with Inactive UEs */
20041    rgSCHMeasGapANRepGetDlInactvUe (cell, &dlInactvLst);
20042
20043    cellSch->apisDl->rgSCHDlInactvtUes(cell, &dlInactvLst);
20044    RETVOID;
20045 }
20046
20047 /* RACHO: Rach handover functions start here */
20048 /***********************************************************
20049  *
20050  *     Func : rgSCHCmnUeIdleExdThrsld
20051  *
20052  *     Desc : RETURN ROK if UE has been idle more
20053  *            than threshold.
20054  *
20055  *     Ret  :
20056  *
20057  *     Notes:
20058  *
20059  *     File :
20060  *
20061  **********************************************************/
20062 #ifdef ANSI
20063 PRIVATE S16 rgSCHCmnUeIdleExdThrsld
20064 (
20065 RgSchCellCb     *cell,
20066 RgSchUeCb       *ue
20067 )
20068 #else
20069 PRIVATE S16 rgSCHCmnUeIdleExdThrsld(cell, ue)
20070 RgSchCellCb     *cell;
20071 RgSchUeCb       *ue;
20072 #endif
20073 {
20074    /* Time difference in subframes */
20075    U32 sfDiff = RGSCH_CALC_SF_DIFF(cell->crntTime, ue->ul.ulTransTime);
20076
20077
20078    if (sfDiff > (U32)RG_SCH_CMN_UE_IDLE_THRSLD(ue))
20079    {
20080       return ROK;
20081    }
20082    else
20083    {
20084       return RFAILED;
20085    }
20086 }
20087
20088 \f
20089 /**
20090  * @brief Scheduler processing for Ded Preambles on cell configuration.
20091  *
20092  * @details
20093  *
20094  *     Function : rgSCHCmnCfgRachDedPrm
20095  *
20096  *     This function does requisite initialisation
20097  *     for RACH Ded Preambles.
20098  *
20099  *
20100  *  @param[in]  RgSchCellCb   *cell
20101  *  @return  Void
20102  **/
20103 #ifdef ANSI
20104 PRIVATE Void rgSCHCmnCfgRachDedPrm
20105 (
20106 RgSchCellCb   *cell
20107 )
20108 #else
20109 PRIVATE Void rgSCHCmnCfgRachDedPrm(cell)
20110 RgSchCellCb   *cell;
20111 #endif
20112 {
20113    RgSchCmnCell *cellSch = (RgSchCmnCell *)(cell->sc.sch);
20114    U32          gap = RG_SCH_CMN_MIN_PRACH_OPPR_GAP;
20115    U32          sfDiff;
20116    U8           cnt;
20117
20118    if (cell->macPreambleSet.pres == NOTPRSNT)
20119    {
20120       RETVOID;
20121    }
20122    cellSch->rachCfg.numDedPrm = cell->macPreambleSet.size;
20123    cellSch->rachCfg.dedPrmStart = cell->macPreambleSet.start;
20124    /* Initialize handover List */
20125    cmLListInit(&cellSch->rachCfg.hoUeLst);
20126    /* Initialize pdcch Order List */
20127    cmLListInit(&cellSch->rachCfg.pdcchOdrLst);
20128
20129    /* Intialize the rapId to UE mapping structure */
20130    for (cnt = 0; cnt<cellSch->rachCfg.numDedPrm; cnt++)
20131    {
20132       cellSch->rachCfg.rapIdMap[cnt].rapId = cellSch->rachCfg.dedPrmStart + \
20133                                              cnt;
20134       cmLListInit(&cellSch->rachCfg.rapIdMap[cnt].assgndUes);
20135    }
20136    /* Perform Prach Mask Idx, remDedPrm, applFrm initializations */
20137    /* Set remDedPrm as numDedPrm */
20138    cellSch->rachCfg.remDedPrm = cellSch->rachCfg.numDedPrm;
20139    /* Initialize applFrm */
20140    cellSch->rachCfg.prachMskIndx = 0;
20141    if (cell->rachCfg.raOccasion.sfnEnum == RGR_SFN_EVEN)
20142    {
20143       cellSch->rachCfg.applFrm.sfn = (cell->crntTime.sfn + \
20144             (cell->crntTime.sfn % 2)) % RGSCH_MAX_SFN;
20145    }
20146 #ifdef LTE_TDD
20147    else if (cell->rachCfg.raOccasion.sfnEnum == RGR_SFN_ODD)
20148    {
20149       if((cell->crntTime.sfn%2) == 0)
20150       {
20151          cellSch->rachCfg.applFrm.sfn = (cell->crntTime.sfn + 1)\
20152                                         % RGSCH_MAX_SFN;
20153       }
20154    }
20155 #endif
20156    else /* ANY sfn */
20157    {
20158       cellSch->rachCfg.applFrm.sfn = cell->crntTime.sfn;
20159    }
20160    /* Initialize cellSch->rachCfg.applFrm as >= crntTime.
20161     * This is because of RGSCH_CALC_SF_DIFF logic */
20162    if (cellSch->rachCfg.applFrm.sfn == cell->crntTime.sfn)
20163    {
20164       while (cellSch->rachCfg.prachMskIndx < cell->rachCfg.raOccasion.size)
20165       {
20166          if (cell->crntTime.slot <\
20167                cell->rachCfg.raOccasion.subFrameNum[cellSch->rachCfg.prachMskIndx])
20168          {
20169             break;
20170          }
20171          cellSch->rachCfg.prachMskIndx++;
20172       }
20173       if (cellSch->rachCfg.prachMskIndx == cell->rachCfg.raOccasion.size)
20174       {
20175          if (cell->rachCfg.raOccasion.sfnEnum == RGR_SFN_ANY)
20176          {
20177             cellSch->rachCfg.applFrm.sfn = (cellSch->rachCfg.applFrm.sfn+1) %\
20178                                            RGSCH_MAX_SFN;
20179          }
20180          else
20181          {
20182             cellSch->rachCfg.applFrm.sfn = (cellSch->rachCfg.applFrm.sfn+2) %\
20183                                            RGSCH_MAX_SFN;
20184          }
20185          cellSch->rachCfg.prachMskIndx = 0;
20186       }
20187       cellSch->rachCfg.applFrm.slot = \
20188                                           cell->rachCfg.raOccasion.subFrameNum[cellSch->rachCfg.prachMskIndx];
20189    }
20190    else
20191    {
20192       cellSch->rachCfg.applFrm.slot = \
20193                                           cell->rachCfg.raOccasion.subFrameNum[cellSch->rachCfg.prachMskIndx];
20194    }
20195
20196    /* Note first param to this macro should always be the latest in time */
20197    sfDiff = RGSCH_CALC_SF_DIFF(cellSch->rachCfg.applFrm, cell->crntTime);
20198    while (sfDiff <= gap)
20199    {
20200       rgSCHCmnUpdNxtPrchMskIdx(cell);
20201       sfDiff = RGSCH_CALC_SF_DIFF(cellSch->rachCfg.applFrm, cell->crntTime);
20202    }
20203
20204    RETVOID;
20205 }
20206
20207 /**
20208  * @brief Updates the PRACH MASK INDEX.
20209  *
20210  * @details
20211  *
20212  *     Function: rgSCHCmnUpdNxtPrchMskIdx
20213  *     Purpose:  Ensures the "applFrm" field of Cmn Sched RACH
20214  *     CFG is always >= "n"+"DELTA", where "n" is the crntTime
20215  *     of the cell. If not, applFrm is updated to the next avl
20216  *     PRACH oppurtunity as per the PRACH Cfg Index configuration.
20217  *
20218  *
20219  *     Invoked by: Common Scheduler
20220  *
20221  *  @param[in]  RgSchCellCb *cell
20222  *  @return  Void
20223  **/
20224 #ifdef ANSI
20225 PRIVATE Void rgSCHCmnUpdNxtPrchMskIdx
20226 (
20227 RgSchCellCb  *cell
20228 )
20229 #else
20230 PRIVATE Void rgSCHCmnUpdNxtPrchMskIdx(cell)
20231 RgSchCellCb  *cell;
20232 #endif
20233 {
20234    RgSchCmnCell    *cellSch = (RgSchCmnCell *)(cell->sc.sch);
20235
20236    /* Determine the next prach mask Index */
20237    if (cellSch->rachCfg.prachMskIndx == cell->rachCfg.raOccasion.size - 1)
20238    {
20239       /* PRACH within applFrm.sfn are done, go to next AVL sfn */
20240       cellSch->rachCfg.prachMskIndx = 0;
20241       if (cell->rachCfg.raOccasion.sfnEnum == RGR_SFN_ANY)
20242       {
20243          cellSch->rachCfg.applFrm.sfn = (cellSch->rachCfg.applFrm.sfn+1) % \
20244                                         RGSCH_MAX_SFN;
20245       }
20246       else/* RGR_SFN_EVEN or RGR_SFN_ODD */
20247       {
20248          cellSch->rachCfg.applFrm.sfn = (cellSch->rachCfg.applFrm.sfn+2) % \
20249                                         RGSCH_MAX_SFN;
20250       }
20251       cellSch->rachCfg.applFrm.slot = cell->rachCfg.raOccasion.\
20252                                           subFrameNum[0];
20253    }
20254    else /* applFrm.sfn is still valid */
20255    {
20256       cellSch->rachCfg.prachMskIndx += 1;
20257       if ( cellSch->rachCfg.prachMskIndx < RGR_MAX_SUBFRAME_NUM )
20258       {
20259          cellSch->rachCfg.applFrm.slot = \
20260                                           cell->rachCfg.raOccasion.subFrameNum[cellSch->rachCfg.prachMskIndx];
20261       }
20262    }
20263    RETVOID;
20264 }
20265
20266 /**
20267  * @brief Updates the Ded preamble RACH parameters
20268  *        every TTI.
20269  *
20270  * @details
20271  *
20272  *     Function: rgSCHCmnUpdRachParam
20273  *     Purpose:  Ensures the "applFrm" field of Cmn Sched RACH
20274  *     CFG is always >= "n"+"6"+"DELTA", where "n" is the crntTime
20275  *     of the cell. If not, applFrm is updated to the next avl
20276  *     PRACH oppurtunity as per the PRACH Cfg Index configuration,
20277  *     accordingly the "remDedPrm" is reset to "numDedPrm" and
20278  *     "prachMskIdx" field is updated as per "applFrm".
20279  *
20280  *
20281  *     Invoked by: Common Scheduler
20282  *
20283  *  @param[in]  RgSchCellCb *cell
20284  *  @return  Void
20285  **/
20286 #ifdef ANSI
20287 PRIVATE Void rgSCHCmnUpdRachParam
20288 (
20289 RgSchCellCb  *cell
20290 )
20291 #else
20292 PRIVATE Void rgSCHCmnUpdRachParam(cell)
20293 RgSchCellCb  *cell;
20294 #endif
20295 {
20296
20297    RgSchCmnCell    *cellSch = (RgSchCmnCell *)(cell->sc.sch);
20298    U32             gap = RG_SCH_CMN_MIN_PRACH_OPPR_GAP;
20299    U32             sfDiff;
20300
20301    if (cell->macPreambleSet.pres == NOTPRSNT)
20302    {
20303       RETVOID;
20304    }
20305    sfDiff = RGSCH_CALC_SF_DIFF(cellSch->rachCfg.applFrm, \
20306          cell->crntTime);
20307    if (sfDiff > gap)
20308    {
20309       /* applFrm is still a valid next Prach Oppurtunity */
20310       RETVOID;
20311    }
20312    rgSCHCmnUpdNxtPrchMskIdx(cell);
20313    /* Reset remDedPrm as numDedPrm */
20314    cellSch->rachCfg.remDedPrm = cellSch->rachCfg.numDedPrm;
20315
20316    RETVOID;
20317 }
20318
20319 /**
20320  * @brief Dedicated Preamble allocation function.
20321  *
20322  * @details
20323  *
20324  *     Function: rgSCHCmnAllocPOParam
20325  *     Purpose:  Allocate pdcch, rapId and PrachMskIdx.
20326  *     Set mapping of UE with the allocated rapId.
20327  *
20328  *     Invoked by: Common Scheduler
20329  *
20330  *  @param[in]   RgSchCellCb *cell
20331  *  @param[in]   RgSchDlSf   *dlSf
20332  *  @param[in]   RgSchUeCb   *ue
20333  *  @param[out]  RgSchPdcch  **pdcch
20334  *  @param[out]  U8          *rapId
20335  *  @param[out]  U8          *prachMskIdx
20336  *  @return  Void
20337  **/
20338 #ifdef ANSI
20339 PRIVATE S16 rgSCHCmnAllocPOParam
20340 (
20341 RgSchCellCb  *cell,
20342 RgSchDlSf    *dlSf,
20343 RgSchUeCb    *ue,
20344 RgSchPdcch   **pdcch,
20345 U8           *rapId,
20346 U8           *prachMskIdx
20347 )
20348 #else
20349 PRIVATE S16 rgSCHCmnAllocPOParam(cell, dlSf, ue, pdcch, rapId, prachMskIdx)
20350 RgSchCellCb  *cell;
20351 RgSchDlSf    *dlSf;
20352 RgSchUeCb    *ue;
20353 RgSchPdcch   **pdcch;
20354 U8           *rapId;
20355 U8           *prachMskIdx;
20356 #endif
20357 {
20358
20359    RgSchCmnCell    *cellSch = (RgSchCmnCell *)(cell->sc.sch);
20360    RgSchCmnDlUe    *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
20361
20362
20363    if (cell->macPreambleSet.pres == PRSNT_NODEF)
20364    {
20365       if (cellSch->rachCfg.remDedPrm == 0)
20366       {
20367          return RFAILED;
20368       }
20369       /* DTX Changes: One Variable is passed to check whether it is DTX or Not */
20370       if ((*pdcch = rgSCHCmnPdcchAlloc(cell, ue, dlSf, ueDl->mimoInfo.cwInfo[0].cqi, TFU_DCI_FORMAT_1A, FALSE)) == NULLP)
20371       {
20372          return RFAILED;
20373       }
20374       /* The stored prachMskIdx is the index of PRACH Oppurtunities in
20375        * raOccasions.subframes[].
20376        * Converting the same to the actual PRACHMskIdx to be transmitted. */
20377       *prachMskIdx = cellSch->rachCfg.prachMskIndx + 1;
20378       /* Distribution starts from dedPrmStart till dedPrmStart + numDedPrm */
20379       *rapId =  cellSch->rachCfg.dedPrmStart +
20380          cellSch->rachCfg.numDedPrm - cellSch->rachCfg.remDedPrm;
20381       cellSch->rachCfg.remDedPrm--;
20382       /* Map UE with the allocated RapId */
20383       ueDl->rachInfo.asgnOppr = cellSch->rachCfg.applFrm;
20384       RGSCH_ARRAY_BOUND_CHECK_WITH_POS_IDX(cell->instIdx, cellSch->rachCfg.rapIdMap, (*rapId - cellSch->rachCfg.dedPrmStart));
20385       cmLListAdd2Tail(&cellSch->rachCfg.rapIdMap[*rapId - cellSch->rachCfg.dedPrmStart].assgndUes, 
20386              &ueDl->rachInfo.rapIdLnk);
20387       ueDl->rachInfo.rapIdLnk.node = (PTR)ue;
20388       ueDl->rachInfo.poRapId = *rapId;
20389    }
20390    else /* if dedicated preambles not configured */
20391    {
20392       /* DTX Changes: One Variable is passed to check whether it is DTX or Not */
20393       if ((*pdcch = rgSCHCmnPdcchAlloc(cell, ue, dlSf, ueDl->mimoInfo.cwInfo[0].cqi, TFU_DCI_FORMAT_1A, FALSE)) == NULLP)
20394       {
20395          return RFAILED;
20396       }
20397       *prachMskIdx = 0;
20398       *rapId       = 0;
20399    }
20400
20401    return ROK;
20402 }
20403
20404 /**
20405  * @brief Dowlink Scheduling Handler.
20406  *
20407  * @details
20408  *
20409  *     Function: rgSCHCmnGenPdcchOrder
20410  *     Purpose:  For each UE in PO Q, grab a PDCCH,
20411  *     get an available ded RapId and fill PDCCH
20412  *     with PO information.
20413  *
20414  *     Invoked by: Common Scheduler
20415  *
20416  *  @param[in]  RgSchCellCb *cell
20417  *  @param[in]  RgSchDlSf   *dlSf
20418  *  @return  Void
20419  **/
20420 #ifdef ANSI
20421 PRIVATE Void rgSCHCmnGenPdcchOrder
20422 (
20423 RgSchCellCb  *cell,
20424 RgSchDlSf    *dlSf
20425 )
20426 #else
20427 PRIVATE Void rgSCHCmnGenPdcchOrder(cell, dlSf)
20428 RgSchCellCb  *cell;
20429 RgSchDlSf    *dlSf;
20430 #endif
20431 {
20432    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
20433    CmLList           *node = cellSch->rachCfg.pdcchOdrLst.first;
20434    RgSchUeCb         *ue;
20435    U8                rapId;
20436    U8                prachMskIdx;
20437    RgSchPdcch        *pdcch = NULLP;
20438
20439
20440    while (node)
20441    {
20442       ue = (RgSchUeCb *)node->node;
20443       node = node->next;
20444       /* Skip sending for this subframe is Measuring or inActive in UL due
20445        * to MeasGap or inactie due to DRX
20446        */
20447       if  ((ue->measGapCb.isMeasuring == TRUE) ||
20448            (ue->ul.ulInactvMask & RG_MEASGAP_INACTIVE) ||
20449            (ue->isDrxEnabled &&
20450              ue->dl.dlInactvMask & RG_DRX_INACTIVE)
20451            )
20452       {
20453          continue;
20454       }
20455       if (rgSCHCmnAllocPOParam(cell, dlSf, ue, &pdcch, &rapId,\
20456                &prachMskIdx) != ROK)
20457       {
20458          /* No More rapIds left for the valid next avl Oppurtunity.
20459           * Unsatisfied UEs here would be given a chance, when the
20460           * prach Mask Index changes as per rachUpd every TTI */
20461
20462          /* PDDCH can also be ordered with rapId=0, prachMskIdx=0
20463           * so that UE triggers a RACH procedure with non-dedicated preamble.
20464           * But the implementation here does not do this. Instead, the "break"
20465           * here implies, that PDCCH Odr always given with valid rapId!=0,
20466           * prachMskIdx!=0 if dedicated preambles are configured.
20467           * If not configured, then trigger a PO with rapId=0,prchMskIdx=0*/
20468          break;
20469       }
20470       /* Fill pdcch with pdcch odr information */
20471       rgSCHCmnFillPdcchOdr2Sf(cell, ue, pdcch, rapId, prachMskIdx);
20472       /* Remove this UE from the PDCCH ORDER QUEUE */
20473       rgSCHCmnDlRmvFrmPdcchOdrQ(cell, ue);
20474       /* Reset UE's power state */
20475       rgSCHPwrUeReset(cell, ue);
20476    }
20477    RETVOID;
20478 }
20479
20480 \f
20481 /**
20482  * @brief This function add UE to PdcchOdr Q if not already present.
20483  *
20484  * @details
20485  *
20486  *     Function: rgSCHCmnDlAdd2PdcchOdrQ
20487  *     Purpose:
20488  *
20489  *     Invoked by: CMN Scheduler
20490  *
20491  *  @param[in]  RgSchCellCb*  cell
20492  *  @param[in]  RgSchUeCb*    ue
20493  *  @return  Void
20494  *
20495  **/
20496 #ifdef ANSI
20497 PRIVATE Void rgSCHCmnDlAdd2PdcchOdrQ
20498 (
20499 RgSchCellCb                *cell,
20500 RgSchUeCb                  *ue
20501 )
20502 #else
20503 PRIVATE Void rgSCHCmnDlAdd2PdcchOdrQ(cell, ue)
20504 RgSchCellCb                *cell;
20505 RgSchUeCb                  *ue;
20506 #endif
20507 {
20508    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
20509    RgSchCmnDlUe *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
20510
20511
20512    if (ueDl->rachInfo.poLnk.node == NULLP)
20513    {
20514       cmLListAdd2Tail(&cellSch->rachCfg.pdcchOdrLst, &ueDl->rachInfo.poLnk);
20515       ueDl->rachInfo.poLnk.node = (PTR)ue;
20516    }
20517    RETVOID;
20518 }
20519
20520 \f
20521 /**
20522  * @brief This function rmvs UE to PdcchOdr Q if not already present.
20523  *
20524  * @details
20525  *
20526  *     Function: rgSCHCmnDlRmvFrmPdcchOdrQ
20527  *     Purpose:
20528  *
20529  *     Invoked by: CMN Scheduler
20530  *
20531  *  @param[in]  RgSchCellCb*  cell
20532  *  @param[in]  RgSchUeCb*    ue
20533  *  @return  Void
20534  *
20535  **/
20536 #ifdef ANSI
20537 PRIVATE Void rgSCHCmnDlRmvFrmPdcchOdrQ
20538 (
20539 RgSchCellCb                *cell,
20540 RgSchUeCb                  *ue
20541 )
20542 #else
20543 PRIVATE Void rgSCHCmnDlRmvFrmPdcchOdrQ(cell, ue)
20544 RgSchCellCb                *cell;
20545 RgSchUeCb                  *ue;
20546 #endif
20547 {
20548    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
20549    RgSchCmnDlUe *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
20550
20551
20552    cmLListDelFrm(&cellSch->rachCfg.pdcchOdrLst, &ueDl->rachInfo.poLnk);
20553    ueDl->rachInfo.poLnk.node = NULLP;
20554    RETVOID;
20555 }
20556
20557 /**
20558  * @brief Fill pdcch with PDCCH order information.
20559  *
20560  * @details
20561  *
20562  *     Function: rgSCHCmnFillPdcchOdr2Sf
20563  *     Purpose:  Fill PDCCH with PDCCH order information,
20564  *
20565  *     Invoked by: Common Scheduler
20566  *
20567  *  @param[in]  RgSchUeCb   *ue
20568  *  @param[in]  RgSchPdcch  *pdcch
20569  *  @param[in]  U8          rapId
20570  *  @param[in]  U8          prachMskIdx
20571  *  @return  Void
20572  **/
20573 #ifdef ANSI
20574 PRIVATE Void rgSCHCmnFillPdcchOdr2Sf
20575 (
20576 RgSchCellCb *cell,
20577 RgSchUeCb   *ue,
20578 RgSchPdcch  *pdcch,
20579 U8          rapId,
20580 U8          prachMskIdx
20581 )
20582 #else
20583 PRIVATE Void rgSCHCmnFillPdcchOdr2Sf(ue, pdcch, rapId, prachMskIdx)
20584 RgSchCellCb *cell;
20585 RgSchUeCb   *ue;
20586 RgSchPdcch  *pdcch;
20587 U8          rapId;
20588 U8          prachMskIdx;
20589 #endif
20590 {
20591    RgSchUeACqiCb  *acqiCb = RG_SCH_CMN_GET_ACQICB(ue,cell); 
20592
20593
20594    pdcch->rnti                                         = ue->ueId;
20595    pdcch->dci.dciFormat                                = TFU_DCI_FORMAT_1A;
20596    pdcch->dci.u.format1aInfo.isPdcchOrder = TRUE;
20597    pdcch->dci.u.format1aInfo.t.pdcchOrder.preambleIdx  = rapId;
20598    pdcch->dci.u.format1aInfo.t.pdcchOrder.prachMaskIdx = prachMskIdx;
20599
20600    /* Request for APer CQI immediately after PDCCH Order */
20601    /* CR ccpu00144525 */
20602 #ifdef TFU_UPGRADE
20603    if(ue->dl.ueDlCqiCfg.aprdCqiCfg.pres)
20604    {
20605       ue->dl.reqForCqi = RG_SCH_APCQI_SERVING_CC;
20606       acqiCb->aCqiTrigWt = 0;
20607    }
20608 #endif   
20609
20610    RETVOID;
20611 }
20612
20613 \f
20614 /**
20615  * @brief UE deletion for scheduler.
20616  *
20617  * @details
20618  *
20619  *     Function : rgSCHCmnDelRachInfo
20620  *
20621  *     This functions deletes all scheduler information
20622  *     pertaining to an UE.
20623  *
20624  *  @param[in]  RgSchCellCb  *cell
20625  *  @param[in]  RgSchUeCb    *ue
20626  *  @return  Void
20627  **/
20628 #ifdef ANSI
20629 PRIVATE Void rgSCHCmnDelRachInfo
20630 (
20631 RgSchCellCb  *cell,
20632 RgSchUeCb    *ue
20633 )
20634 #else
20635 PRIVATE Void rgSCHCmnDelRachInfo(cell, ue)
20636 RgSchCellCb  *cell;
20637 RgSchUeCb    *ue;
20638 #endif
20639 {
20640    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
20641    RgSchCmnDlUe *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
20642    U8            rapIdIdx;
20643
20644
20645    if (ueDl->rachInfo.poLnk.node)
20646    {
20647       rgSCHCmnDlRmvFrmPdcchOdrQ(cell, ue);
20648    }
20649    if (ueDl->rachInfo.hoLnk.node)
20650    {
20651       cmLListDelFrm(&cellSch->rachCfg.hoUeLst, &ueDl->rachInfo.hoLnk);
20652       ueDl->rachInfo.hoLnk.node = NULLP;
20653    }
20654    if (ueDl->rachInfo.rapIdLnk.node)
20655    {
20656       rapIdIdx = ueDl->rachInfo.poRapId - cellSch->rachCfg.dedPrmStart;
20657       cmLListDelFrm(&cellSch->rachCfg.rapIdMap[rapIdIdx].assgndUes, 
20658           &ueDl->rachInfo.rapIdLnk);
20659       ueDl->rachInfo.rapIdLnk.node = NULLP;
20660    }
20661    RETVOID;
20662 }
20663
20664 /**
20665  * @brief This function retrieves the ue which has sent this raReq
20666  * and it allocates grant for UEs undergoing (for which RAR
20667  * is being generated) HandOver/PdcchOrder.
20668  *
20669  *
20670  * @details
20671  *
20672  *     Function: rgSCHCmnHdlHoPo
20673  *     Purpose:  This function  retrieves the ue which has sent this raReq
20674  *               and it allocates grant for UEs undergoing (for which RAR
20675  *               is being generated) HandOver/PdcchOrder.
20676  *
20677  *     Invoked by: Common Scheduler
20678  *
20679  *  @param[in]  RgSchCellCb           *cell
20680  *  @param[out] CmLListCp             *raRspLst
20681  *  @param[in]  RgSchRaReqInfo        *raReq
20682  *  @return  Void
20683  *
20684  **/
20685 #ifdef ANSI
20686 PRIVATE Void rgSCHCmnHdlHoPo
20687 (
20688 RgSchCellCb           *cell,
20689 CmLListCp             *raRspLst,
20690 RgSchRaReqInfo        *raReq
20691 )
20692 #else
20693 PRIVATE Void rgSCHCmnHdlHoPo(cell, raRspLst, raReq)
20694 RgSchCellCb           *cell;
20695 CmLListCp             *raRspLst;
20696 RgSchRaReqInfo        *raReq;
20697 #endif
20698 {
20699    RgSchUeCb             *ue = raReq->ue;
20700
20701    if ( ue->isDrxEnabled )
20702    {
20703       rgSCHDrxDedRa(cell,ue);
20704    }
20705    rgSCHCmnAllocPoHoGrnt(cell, raRspLst, ue, raReq);
20706    RETVOID;
20707 }
20708
20709 /**
20710  * @brief This function retrieves the UE which has sent this raReq
20711  * for handover case.
20712  *
20713  *
20714  * @details
20715  *
20716  *     Function: rgSCHCmnGetHoUe
20717  *     Purpose:  This function retrieves the UE which has sent this raReq
20718  *     for handover case.
20719  *
20720  *     Invoked by: Common Scheduler
20721  *
20722  *  @param[in]  RgSchCellCb           *cell
20723  *  @param[in]  RgSchRaReqInfo        *raReq
20724  *  @return  RgSchUeCb*
20725  *
20726  **/
20727 #ifdef ANSI
20728 RgSchUeCb* rgSCHCmnGetHoUe
20729 (
20730 RgSchCellCb           *cell,
20731 U16                   rapId
20732 )
20733 #else
20734 RgSchUeCb* rgSCHCmnGetHoUe(cell, rapId)
20735 RgSchCellCb           *cell;
20736 U16                   rapId
20737 #endif
20738 {
20739    RgSchCmnCell          *cellSch = (RgSchCmnCell *)(cell->sc.sch);
20740    CmLList               *node;
20741    CmLListCp             *ueLst;
20742    RgSchUeCb             *ue;
20743    RgSchCmnDlUe          *ueDl;
20744
20745    ueLst = &cellSch->rachCfg.hoUeLst;
20746    node = ueLst->first;
20747    while (node)
20748    {
20749       ue = (RgSchUeCb *)node->node;
20750       node = node->next;
20751       ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
20752       if (ueDl->rachInfo.hoRapId == rapId)
20753       {
20754          return (ue);
20755       }
20756    }
20757    return (NULLP);
20758 }
20759
20760 #ifdef ANSI
20761 PRIVATE Void rgSCHCmnDelDedPreamble
20762 (
20763 RgSchCellCb           *cell,
20764 U8                    preambleId
20765 )
20766 #else
20767 PRIVATE rgSCHCmnDelDedPreamble(cell, preambleId)
20768 RgSchCellCb           *cell;
20769 U8                    preambleId;
20770 #endif
20771 {
20772    RgSchCmnCell          *cellSch = (RgSchCmnCell *)(cell->sc.sch);
20773    CmLList               *node;
20774    CmLListCp             *ueLst;
20775    RgSchUeCb             *ue;
20776    RgSchCmnDlUe          *ueDl;
20777
20778    ueLst = &cellSch->rachCfg.hoUeLst;
20779    node = ueLst->first;
20780    while (node)
20781    {
20782       ue = (RgSchUeCb *)node->node;
20783       node = node->next;
20784       ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
20785       if (ueDl->rachInfo.hoRapId == preambleId)
20786       {
20787          cmLListDelFrm(ueLst, &ueDl->rachInfo.hoLnk);
20788          ueDl->rachInfo.hoLnk.node = (PTR)NULLP;
20789       }
20790    }
20791 }
20792
20793 /**
20794  * @brief This function retrieves the UE which has sent this raReq
20795  * for PDCCh Order case.
20796  *
20797  *
20798  * @details
20799  *
20800  *     Function: rgSCHCmnGetPoUe
20801  *     Purpose:  This function retrieves the UE which has sent this raReq
20802  *     for PDCCH Order case.
20803  *
20804  *     Invoked by: Common Scheduler
20805  *
20806  *  @param[in]  RgSchCellCb           *cell
20807  *  @param[in]  RgSchRaReqInfo        *raReq
20808  *  @return  RgSchUeCb*
20809  *
20810  **/
20811 #ifdef ANSI
20812 RgSchUeCb* rgSCHCmnGetPoUe
20813 (
20814 RgSchCellCb           *cell,
20815 U16                   rapId,
20816 CmLteTimingInfo       timingInfo
20817 )
20818 #else
20819 RgSchUeCb* rgSCHCmnGetPoUe(cell, rapId, timingInfo)
20820 RgSchCellCb           *cell;
20821 U16                   rapId;
20822 CmLteTimingInfo       timingInfo;
20823 #endif
20824 {
20825    RgSchCmnCell          *cellSch = (RgSchCmnCell *)(cell->sc.sch);
20826    CmLList               *node;
20827    CmLListCp             *ueLst;
20828    RgSchUeCb             *ue;
20829    RgSchCmnDlUe          *ueDl;
20830    U8                    rapIdIdx;
20831
20832    rapIdIdx = rapId -cellSch->rachCfg.dedPrmStart;
20833    ueLst = &cellSch->rachCfg.rapIdMap[rapIdIdx].assgndUes;
20834    node = ueLst->first;
20835    while (node)
20836    {
20837       ue = (RgSchUeCb *)node->node;
20838       node = node->next;
20839       ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
20840       /* Remove UEs irrespective.
20841        * Old UE associations are removed.*/
20842       cmLListDelFrm(ueLst, &ueDl->rachInfo.rapIdLnk);
20843       ueDl->rachInfo.rapIdLnk.node = (PTR)NULLP;
20844       if (RGSCH_TIMEINFO_SAME(ueDl->rachInfo.asgnOppr, timingInfo))
20845       {
20846          return (ue);
20847       }
20848    }
20849
20850    return (NULLP);
20851 }
20852
20853
20854 /**
20855  * @brief This function returns the valid UL cqi for a given UE.
20856  *
20857  * @details
20858  *
20859  *     Function: rgSCHCmnUlGetCqi
20860  *     Purpose:  This function returns the "valid UL cqi" for a given UE
20861  *               based on UE category
20862  *
20863  *     Invoked by: Scheduler
20864  *     
20865  *  @param[in]  RgSchUeCb        *ue
20866  *  @param[in]  U8               ueCtgy
20867  *  @return     U8 
20868  **/
20869 #ifdef ANSI
20870 U8 rgSCHCmnUlGetCqi
20871 (
20872 RgSchCellCb      *cell,
20873 RgSchUeCb        *ue,
20874 CmLteUeCategory  ueCtgy
20875 )
20876 #else
20877 U8 rgSCHCmnUlGetCqi(cell, ue, ueCtgy)
20878 RgSchCellCb      *cell;
20879 RgSchUeCb        *ue;
20880 CmLteUeCategory  ueCtgy;
20881 #endif
20882 {
20883    RgSchCmnUlUe *ueUl    = RG_SCH_CMN_GET_UL_UE(ue,cell);
20884    U8            cqi;
20885
20886    
20887    cqi = ueUl->maxUlCqi;
20888 #ifdef TFU_UPGRADE
20889    if (!((ueCtgy != CM_LTE_UE_CAT_5) && 
20890         (ueUl->validUlCqi > ueUl->maxUlCqi)))
20891    {
20892       cqi = ueUl->validUlCqi;
20893    }
20894 #else   
20895    if (!((ueCtgy != CM_LTE_UE_CAT_5) && 
20896          (ueUl->crntUlCqi[0] > ueUl->maxUlCqi )))
20897    {
20898       cqi = ueUl->crntUlCqi[0];
20899    }
20900 #endif    
20901    return (cqi);
20902 }/* End of rgSCHCmnUlGetCqi */
20903
20904 /***********************************************************
20905  *
20906  *     Func : rgSCHCmnUlRbAllocForPoHoUe
20907  *
20908  *     Desc : Do uplink RB allocation for a HO/PO UE.
20909  *
20910  *     Ret  :
20911  *
20912  *     Notes: Note that as of now, for retx, maxRb
20913  *            is not considered. Alternatives, such
20914  *            as dropping retx if it crosses maxRb
20915  *            could be considered.
20916  *
20917  *     File :
20918  *
20919  **********************************************************/
20920 #ifdef ANSI
20921 PRIVATE S16 rgSCHCmnUlRbAllocForPoHoUe
20922 (
20923 RgSchCellCb           *cell,
20924 RgSchUlSf             *sf,
20925 RgSchUeCb             *ue,
20926 U8                    maxRb
20927 )
20928 #else
20929 PRIVATE S16 rgSCHCmnUlRbAllocForPoHoUe(cell, sf, ue, maxRb)
20930 RgSchCellCb           *cell;
20931 RgSchUlSf             *sf;
20932 RgSchUeCb             *ue;
20933 U8                    maxRb;
20934 #endif
20935 {
20936    RgSchCmnUlCell *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
20937    RgSchCmnUlUe *ueUl    = RG_SCH_CMN_GET_UL_UE(ue,cell);
20938    U8           sbSize  = cellUl->sbSize;
20939    U32          maxBits = ue->ul.maxBytesPerUePerTti*8;
20940    U32          bits;
20941    RgSchUlAlloc *alloc;
20942    U32          nPrb;
20943    U8           iTbs;
20944    U32          eff;
20945    U32          numSb;
20946    U8           iMcs;
20947    U8           iMcsCrnt;
20948    U8           cqi;
20949    U8           modOdr;
20950    RgSchUlHole      *hole;
20951    RgSchUlHqProcCb  *proc = &ueUl->hqEnt.hqProcCb[cellUl->msg3SchdHqProcIdx];
20952    CmLteUeCategory ueCtg = (CmLteUeCategory)(RG_SCH_CMN_GET_UE_CTGY(ue));
20953
20954    if ((hole = rgSCHUtlUlHoleFirst(sf)) == NULLP)
20955    {
20956       return RFAILED;
20957    }
20958    /*MS_WORKAROUND for HO ccpu00121116*/
20959    cqi   = rgSCHCmnUlGetCqi(cell, ue, ueCtg);
20960    RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgSchCmnUlCqiToTbsTbl[(U8)cell->isCpUlExtend], cqi);
20961    iTbs  = rgSchCmnUlCqiToTbsTbl[(U8)cell->isCpUlExtend][cqi];
20962    iMcs  = rgSCHCmnUlGetIMcsFrmITbs(iTbs,ueCtg);
20963    while(iMcs > RG_SCH_CMN_MAX_MSG3_IMCS)
20964    {
20965        cqi--;
20966        iTbs  = rgSchCmnUlCqiToTbsTbl[(U8)cell->isCpUlExtend][cqi];
20967        iMcs  = rgSCHCmnUlGetIMcsFrmITbs(iTbs, ueCtg);
20968    }
20969    /* Filling the modorder in the grant structure*/
20970    RG_SCH_UL_MCS_TO_MODODR(iMcs,modOdr);
20971    if (!cell->isCpUlExtend)
20972    {
20973       eff   = rgSchCmnNorUlEff[0][iTbs];
20974    }
20975    else
20976    {
20977       eff   = rgSchCmnExtUlEff[0][iTbs];
20978    }
20979
20980    bits = ueUl->alloc.reqBytes * 8;
20981
20982 #if (ERRCLASS & ERRCLS_DEBUG)
20983    if (!bits)
20984    {
20985       return RFAILED;
20986    }
20987 #endif
20988
20989    if (bits < rgSCHCmnUlMinTbBitsForITbs(cellUl, iTbs))
20990    {
20991       numSb = 1;
20992       nPrb = numSb * sbSize;
20993    }
20994    else
20995    {
20996       if (bits > maxBits)
20997       {
20998          bits  = maxBits;
20999          nPrb  = bits * 1024 / eff / RG_SCH_CMN_UL_NUM_RE_PER_RB(cellUl);
21000          if (nPrb > maxRb)
21001          {
21002             nPrb = maxRb;
21003          }
21004          numSb = nPrb / sbSize;
21005       }
21006       else
21007       {
21008          /*ccpu00128775:MOD-Change to get upper threshold nPrb*/
21009          nPrb = RGSCH_CEIL((RGSCH_CEIL(bits * 1024, eff)),
21010                   RG_SCH_CMN_UL_NUM_RE_PER_RB(cellUl));
21011          if (nPrb > maxRb)
21012          {
21013             nPrb = maxRb;
21014          }
21015          numSb = RGSCH_DIV_ROUND(nPrb, sbSize);
21016       }
21017    }
21018    iMcsCrnt = iMcs;
21019
21020    alloc = rgSCHCmnUlSbAlloc(sf, (U8)RGSCH_MIN(numSb, cellUl->maxSbPerUe),\
21021                              hole);
21022    if (alloc == NULLP)
21023    {
21024       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
21025          "rgSCHCmnUlRbAllocForPoHoUe(): Could not get UlAlloc");
21026       return RFAILED;
21027    }
21028    rgSCHCmnUlAllocFillRbInfo(cell, sf, alloc);
21029    
21030    /* Filling the modorder in the grant structure start*/
21031    alloc->grnt.modOdr = (TfuModScheme) modOdr;
21032    alloc->grnt.iMcs = iMcs;
21033    alloc->grnt.iMcsCrnt = iMcsCrnt;
21034    alloc->grnt.hop = 0;
21035    /* Fix for ccpu00123915*/
21036    alloc->forMsg3 = TRUE;
21037    alloc->hqProc = proc;
21038    alloc->hqProc->ulSfIdx = cellUl->msg3SchdIdx;
21039    alloc->ue = ue;
21040    alloc->rnti = ue->ueId;
21041    /* updating initNumRbs in case of HO */
21042 #ifdef TFU_UPGRADE
21043    ue->initNumRbs = alloc->grnt.numRb;
21044 #endif
21045    ueUl->alloc.alloc = alloc;
21046    iTbs = rgSCHCmnUlGetITbsFrmIMcs(iMcs);
21047    RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgTbSzTbl[0], iTbs);
21048    alloc->grnt.datSz    = rgTbSzTbl[0][iTbs][alloc->grnt.numRb-1] / 8;
21049    /* MS_WORKAROUND for HO ccpu00121124*/
21050    /*[Adi temp change] Need to fil modOdr */
21051    RG_SCH_UL_MCS_TO_MODODR(alloc->grnt.iMcsCrnt,alloc->grnt.modOdr);
21052    rgSCHUhmNewTx(proc, ueUl->hqEnt.maxHqRetx, alloc);
21053    /* No grant attr recorded now */
21054    return ROK;
21055 }
21056
21057 /**
21058  * @brief This function allocates grant for UEs undergoing (for which RAR
21059  * is being generated) HandOver/PdcchOrder.
21060  *
21061  *
21062  * @details
21063  *
21064  *     Function: rgSCHCmnAllocPoHoGrnt
21065  *     Purpose:  This function allocates grant for UEs undergoing (for which RAR
21066  *               is being generated) HandOver/PdcchOrder.
21067  *
21068  *     Invoked by: Common Scheduler
21069  *
21070  *  @param[in]  RgSchCellCb           *cell
21071  *  @param[out] CmLListCp             *raRspLst,
21072  *  @param[in]  RgSchUeCb             *ue
21073  *  @param[in]  RgSchRaReqInfo        *raReq
21074  *  @return  Void
21075  *
21076  **/
21077 #ifdef ANSI
21078 PRIVATE Void rgSCHCmnAllocPoHoGrnt
21079 (
21080 RgSchCellCb           *cell,
21081 CmLListCp             *raRspLst,
21082 RgSchUeCb             *ue,
21083 RgSchRaReqInfo        *raReq
21084 )
21085 #else
21086 PRIVATE Void rgSCHCmnAllocPoHoGrnt(cell, raRspLst, ue, raReq)
21087 RgSchCellCb           *cell;
21088 CmLListCp             *raRspLst;
21089 RgSchUeCb             *ue;
21090 RgSchRaReqInfo        *raReq;
21091 #endif
21092 {
21093    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
21094    RgSchCmnUlUe    *ueUl   = RG_SCH_CMN_GET_UL_UE(ue,cell);
21095    RgSchUlGrnt     *grnt;
21096    RgSchUlSf       *sf = &cellUl->ulSfArr[cellUl->msg3SchdIdx];
21097
21098
21099    /* Clearing previous allocs if any*/
21100    rgSCHCmnUlUeDelAllocs(cell, ue);
21101    /* Fix : syed allocs are limited */
21102    if (*sf->allocCountRef >= cellUl->maxAllocPerUlSf)
21103    {
21104       RETVOID;
21105    }
21106    ueUl->alloc.reqBytes = RG_SCH_MIN_GRNT_HOPO;
21107    if (rgSCHCmnUlRbAllocForPoHoUe(cell, sf, ue, RGSCH_MAX_UL_RB) != ROK)
21108    {
21109       RETVOID;
21110    }
21111
21112    /* Fill grant information */
21113    grnt = &ueUl->alloc.alloc->grnt;
21114
21115    /* KWork fix */
21116    if (grnt == NULLP)
21117    {
21118       RLOG_ARG1(L_ERROR,DBG_INSTID,cell->instIdx,  "Failed to get"
21119         "the grant for HO/PDCCH Order. CRNTI:%d",ue->ueId);
21120       RETVOID;
21121    }
21122    ue->ul.rarGrnt.rapId = raReq->raReq.rapId;
21123    ue->ul.rarGrnt.hop = grnt->hop;
21124    ue->ul.rarGrnt.rbStart = grnt->rbStart;
21125    ue->ul.rarGrnt.numRb = grnt->numRb;
21126    ue->ul.rarGrnt.tpc = grnt->tpc;
21127    ue->ul.rarGrnt.iMcsCrnt = grnt->iMcsCrnt;
21128    ue->ul.rarGrnt.ta.pres = TRUE;
21129    ue->ul.rarGrnt.ta.val = raReq->raReq.ta;
21130    ue->ul.rarGrnt.datSz = grnt->datSz;
21131    if((sf->numACqiCount < RG_SCH_MAX_ACQI_PER_ULSF) && (RG_SCH_APCQI_NO != ue->dl.reqForCqi)) 
21132    {
21133 #ifdef LTE_ADV
21134       U8    idx = 0; 
21135       /* Send two bits cqireq field if more than one cells are configured else one*/
21136       for (idx = 1;idx < CM_LTE_MAX_CELLS;idx++)
21137       {
21138          if (ue->cellInfo[idx] != NULLP)
21139          {
21140             ue->ul.rarGrnt.cqiReqBit = ue->dl.reqForCqi;
21141             break;
21142          }
21143       }
21144       if (idx == CM_LTE_MAX_CELLS)
21145 #endif
21146       {
21147          ue->ul.rarGrnt.cqiReqBit = ue->dl.reqForCqi;
21148       }
21149       ue->dl.reqForCqi = RG_SCH_APCQI_NO;
21150       sf->numACqiCount++;
21151    }
21152    else
21153    {
21154       ue->ul.rarGrnt.cqiReqBit = 0;
21155    }
21156    /* Attach Ho/Po allocation to RAR Rsp cont free Lst */
21157    cmLListAdd2Tail(raRspLst, &ue->ul.rarGrnt.raRspLnk);
21158    ue->ul.rarGrnt.raRspLnk.node = (PTR)ue;
21159
21160    RETVOID;
21161 }
21162
21163 /**
21164  * @brief This is a utility function to set the fields in
21165  * an UL harq proc which is identified for non-adaptive retx
21166  *
21167  * @details
21168  *
21169  *     Function: rgSCHCmnUlNonadapRetx 
21170  *     Purpose:  Sets the fields in UL Harq  proc for non-adaptive retx 
21171  *
21172  * @param[in]  RgSchCmnUlCell  *cellUl 
21173  * @param[out] RgSchUlAlloc    *alloc
21174  * @param[in]  U8              idx 
21175  * @return  Void
21176  *
21177  **/
21178 #ifdef UNUSED_FUNC
21179 #ifdef ANSI
21180 PRIVATE Void rgSCHCmnUlNonadapRetx
21181 (
21182 RgSchCmnUlCell  *cellUl,
21183 RgSchUlAlloc    *alloc,
21184 U8              idx
21185 )
21186 #else
21187 PRIVATE Void rgSCHCmnUlNonadapRetx(cellUl, alloc, idx)
21188 RgSchCmnUlCell  *cellUl;
21189 RgSchUlAlloc    *alloc;
21190 U8              idx;
21191 #endif
21192 {
21193    rgSCHUhmRetx(alloc->hqProc, alloc);
21194
21195    /* Update alloc to retx */
21196    alloc->hqProc->isRetx = TRUE;
21197    alloc->hqProc->ulSfIdx = cellUl->reTxIdx[idx];
21198
21199    if (alloc->hqProc->rvIdx != 0)
21200    {
21201       alloc->grnt.iMcsCrnt = rgSchCmnUlRvIdxToIMcsTbl[alloc->hqProc->rvIdx];
21202    }
21203    else
21204    {
21205       alloc->grnt.iMcsCrnt = alloc->grnt.iMcs;
21206    }
21207    alloc->grnt.isRtx = TRUE;
21208    alloc->pdcch = NULLP;
21209    RETVOID;
21210 }
21211 /**
21212  * @brief Check if 2 allocs overlap
21213  *
21214  * @details
21215  *
21216  *     Function : rgSCHCmnUlAllocsOvrLap
21217  *
21218  *      - Return TRUE if alloc1 and alloc2 overlap.
21219  *
21220  *  @param[in]  RgSchUlAlloc  *alloc1
21221  *  @param[in]  RgSchUlAlloc  *alloc2
21222  *  @return  Bool
21223  **/
21224 #ifdef ANSI
21225 PRIVATE Bool rgSCHCmnUlAllocsOvrLap
21226 (
21227 RgSchUlAlloc    *alloc1,
21228 RgSchUlAlloc    *alloc2
21229 )
21230 #else
21231 PRIVATE Bool rgSCHCmnUlAllocsOvrLap(alloc1, alloc2)
21232 RgSchUlAlloc    *alloc1;
21233 RgSchUlAlloc    *alloc2;
21234 #endif
21235 {
21236
21237
21238    if (((alloc1->sbStart >= alloc2->sbStart) &&
21239          (alloc1->sbStart <= alloc2->sbStart + alloc2->numSb-1)) ||
21240         ((alloc2->sbStart >= alloc1->sbStart) &&
21241          (alloc2->sbStart <= alloc1->sbStart + alloc1->numSb-1)))
21242    {
21243       return (TRUE);
21244    }
21245    return (FALSE);
21246 }
21247 /**
21248  * @brief Copy allocation Info from src to dst.
21249  *
21250  * @details
21251  *
21252  *     Function : rgSCHCmnUlCpyAllocInfo
21253  *
21254  *      - Copy allocation Info from src to dst.
21255  *
21256  *  @param[in]  RgSchUlAlloc  *srcAlloc
21257  *  @param[in]  RgSchUlAlloc  *dstAlloc
21258  *  @return  Void
21259  **/
21260 #ifdef ANSI
21261 PRIVATE Void rgSCHCmnUlCpyAllocInfo
21262 (
21263 RgSchCellCb     *cell,
21264 RgSchUlAlloc    *srcAlloc,
21265 RgSchUlAlloc    *dstAlloc
21266 )
21267 #else
21268 PRIVATE Void rgSCHCmnUlCpyAllocInfo(cell, srcAlloc, dstAlloc)
21269 RgSchCellCb     *cell;
21270 RgSchUlAlloc    *srcAlloc;
21271 RgSchUlAlloc    *dstAlloc;
21272 #endif
21273 {
21274    RgSchCmnUlUe *ueUl;
21275
21276    dstAlloc->grnt = srcAlloc->grnt;
21277    dstAlloc->hqProc = srcAlloc->hqProc;
21278    /* Fix : syed During UE context release, hqProc->alloc
21279     * was pointing to srcAlloc instead of dstAlloc and
21280     * freeing from incorrect sf->allocDb was
21281     * corrupting the list. */
21282     /* In case of SPS Occasion Allocation is done in advance and 
21283        at a later time Hq Proc is linked. Hence HqProc
21284        pointer in alloc shall be NULL */
21285 #ifdef LTEMAC_SPS
21286    if (dstAlloc->hqProc)
21287 #endif
21288    {
21289       dstAlloc->hqProc->alloc = dstAlloc;
21290    }
21291    dstAlloc->ue = srcAlloc->ue;
21292    dstAlloc->rnti = srcAlloc->rnti;
21293    dstAlloc->forMsg3 = srcAlloc->forMsg3;
21294    dstAlloc->raCb  = srcAlloc->raCb;
21295    dstAlloc->pdcch = srcAlloc->pdcch;
21296    /* Fix : syed HandIn Ue has forMsg3 and ue Set, but no RaCb */
21297    if (dstAlloc->ue)
21298    {
21299       ueUl = RG_SCH_CMN_GET_UL_UE(dstAlloc->ue,cell);
21300       ueUl->alloc.alloc = dstAlloc;
21301 #ifdef LTEMAC_SPS
21302       if (dstAlloc->ue->ul.ulSpsCfg.isUlSpsEnabled == TRUE)
21303       {
21304          if((dstAlloc->ue->ul.ulSpsInfo.ulSpsSchdInfo.crntAlloc != NULLP)
21305                && (dstAlloc->ue->ul.ulSpsInfo.ulSpsSchdInfo.crntAlloc == srcAlloc))
21306          {
21307             dstAlloc->ue->ul.ulSpsInfo.ulSpsSchdInfo.crntAlloc = dstAlloc;
21308          }
21309       }
21310 #endif
21311    }
21312
21313    RETVOID;
21314 }
21315 /**
21316  * @brief Update TX and RETX subframe's allocation
21317  *        markings.
21318  *
21319  * @details
21320  *
21321  *     Function : rgSCHCmnUlInsAllocFrmNewSf2OldSf
21322  *
21323  *      - Release all preassigned allocations of newSf and merge
21324  *        them to oldSf.
21325  *      - If alloc of newSf collide with one or more allocs of oldSf
21326  *        - mark all such allocs of oldSf for Adaptive Retx.
21327  *      - Swap the alloc and hole DB references of oldSf and newSf.
21328  *
21329  *  @param[in]  RgSchCellCb   *cell
21330  *  @param[in]  RgSchUlSf     *newSf
21331  *  @param[in]  RgSchUlSf     *oldSf
21332  *  @param[in]  RgSchUlAlloc  *srcAlloc
21333  *  @return  Void
21334  **/
21335 #ifdef ANSI
21336 PRIVATE Void rgSCHCmnUlInsAllocFrmNewSf2OldSf
21337 (
21338 RgSchCellCb     *cell,
21339 RgSchUlSf       *newSf,
21340 RgSchUlSf       *oldSf,
21341 RgSchUlAlloc    *srcAlloc
21342 )
21343 #else
21344 PRIVATE Void rgSCHCmnUlInsAllocFrmNewSf2OldSf(cell, newSf, oldSf, srcAlloc)
21345 RgSchCellCb     *cell;
21346 RgSchUlSf       *newSf;
21347 RgSchUlSf       *oldSf;
21348 RgSchUlAlloc    *srcAlloc;
21349 #endif
21350 {
21351    RgSchUlAlloc   *alloc, *dstAlloc, *nxtAlloc;
21352
21353    /* MS_WORKAROUND ccpu00120827 */
21354    RgSchCmnCell *schCmnCell = (RgSchCmnCell *)(cell->sc.sch);
21355    U8 remAllocs;
21356
21357    if ((alloc = rgSCHUtlUlAllocFirst(oldSf)) != NULLP)
21358    {
21359       do
21360       {
21361          nxtAlloc = rgSCHUtlUlAllocNxt(oldSf, alloc);
21362          /* If there is an overlap between alloc and srcAlloc
21363           * then alloc is marked for Adaptive retx and it is released
21364           * from txSf */
21365          if (rgSCHCmnUlAllocsOvrLap(alloc, srcAlloc) == TRUE)
21366          {
21367             rgSCHCmnUlUpdAllocRetx(cell, alloc);
21368             rgSCHUtlUlAllocRls(oldSf, alloc);
21369          }
21370          /* No further allocs spanning the srcAlloc subbands */
21371          if (srcAlloc->sbStart + srcAlloc->numSb - 1  <= alloc->sbStart)
21372          {
21373             break;
21374          }
21375       } while ((alloc = nxtAlloc) != NULLP);
21376    }
21377
21378    /* After freeing all the colliding allocs, request for an allocation
21379     * specifying the start and numSb with in txSf. This function should
21380     * always return positively with a nonNULL dstAlloc */
21381     /* MS_WORKAROUND ccpu00120827 */
21382    remAllocs = schCmnCell->ul.maxAllocPerUlSf - *oldSf->allocCountRef;
21383    if (!remAllocs)
21384    {
21385       /* Fix : If oldSf already has max Allocs then release the
21386        * old RETX alloc to make space for new alloc of newSf.
21387        * newSf allocs(i.e new Msg3s) are given higher priority
21388        * over retx allocs. */      
21389       if ((alloc = rgSCHUtlUlAllocFirst(oldSf)) != NULLP)
21390       {
21391          do
21392          {
21393             nxtAlloc = rgSCHUtlUlAllocNxt(oldSf, alloc);           
21394             if (!alloc->mrgdNewTxAlloc)
21395             {
21396                /* If alloc is for RETX */                   
21397                /* TODO: Incase of this ad also in case of choosing
21398                 * and alloc for ADAP RETX, we need to send ACK for
21399                 * the corresponding alloc in PHICH */               
21400 #ifndef EMTC_ENABLE
21401                rgSCHCmnUlFreeAllocation(cell, oldSf, alloc);
21402 #else
21403                rgSCHCmnUlFreeAllocation(cell, oldSf, alloc,FALSE);
21404 #endif
21405                break;
21406             }               
21407          }while((alloc = nxtAlloc) != NULLP);
21408       }
21409    }
21410    dstAlloc = rgSCHUtlUlGetSpfcAlloc(oldSf, srcAlloc->sbStart, srcAlloc->numSb);
21411 #ifdef ERRCLS_KW
21412    /* This should never happen */
21413    if (dstAlloc == NULLP)
21414    {
21415       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"CRNTI:%d "
21416          "rgSCHUtlUlGetSpfcAlloc failed in rgSCHCmnUlInsAllocFrmNewSf2OldSf",
21417          srcAlloc->rnti);
21418       RETVOID;
21419    }
21420 #endif
21421    /* Copy the srcAlloc's state information in to dstAlloc */
21422    rgSCHCmnUlCpyAllocInfo(cell, srcAlloc, dstAlloc);
21423    /* Set new Tx merged Alloc Flag to TRUE, indicating that this
21424     * alloc shall not be processed for non-adaptive retransmission */
21425    dstAlloc->mrgdNewTxAlloc = TRUE;
21426    RETVOID;
21427 }
21428 /**
21429  * @brief Merge all allocations of newSf to oldSf.
21430  *
21431  * @details
21432  *
21433  *     Function : rgSCHCmnUlMergeSfAllocs
21434  *
21435  *      - Merge all allocations of newSf to oldSf.
21436  *      - If newSf's alloc collides with oldSf's alloc
21437  *        then oldSf's alloc is marked for adaptive Retx
21438  *        and is released from oldSf to create space for
21439  *        newSf's alloc.
21440  *
21441  *  @param[in]  RgSchCellCb  *cell
21442  *  @param[in]  RgSchUlSf    *oldSf
21443  *  @param[in]  RgSchUlSf    *newSf
21444  *  @return  Void
21445  **/
21446 #ifdef ANSI
21447 PRIVATE Void rgSCHCmnUlMergeSfAllocs
21448 (
21449 RgSchCellCb  *cell,
21450 RgSchUlSf    *oldSf,
21451 RgSchUlSf    *newSf
21452 )
21453 #else
21454 PRIVATE Void rgSCHCmnUlMergeSfAllocs(cell, oldSf, newSf)
21455 RgSchCellCb  *cell;
21456 RgSchUlSf    *oldSf;
21457 RgSchUlSf    *newSf;
21458 #endif
21459 {
21460    RgSchUlAlloc    *alloc, *nxtAlloc;
21461    UNUSED(cell);
21462
21463    /* Merge each alloc of newSf in to oldSf
21464     * and release it from newSf */
21465    if ((alloc = rgSCHUtlUlAllocFirst(newSf)) != NULLP)
21466    {
21467       do
21468       {
21469          nxtAlloc = rgSCHUtlUlAllocNxt(newSf, alloc);
21470          rgSCHCmnUlInsAllocFrmNewSf2OldSf(cell, newSf, oldSf, alloc);
21471          rgSCHUtlUlAllocRls(newSf, alloc);
21472       } while((alloc = nxtAlloc) != NULLP);
21473    }
21474    RETVOID;
21475 }
21476 /**
21477  * @brief Swap Hole/Alloc DB context of newSf and oldSf.
21478  *
21479  * @details
21480  *
21481  *     Function : rgSCHCmnUlSwapSfAllocs
21482  *
21483  *      - Swap Hole/Alloc DB context of newSf and oldSf.
21484  *
21485  *  @param[in]  RgSchCellCb  *cell
21486  *  @param[in]  RgSchUlSf    *oldSf
21487  *  @param[in]  RgSchUlSf    *newSf
21488  *  @return  Void
21489  **/
21490 #ifdef ANSI
21491 PRIVATE Void rgSCHCmnUlSwapSfAllocs
21492 (
21493 RgSchCellCb  *cell,
21494 RgSchUlSf    *oldSf,
21495 RgSchUlSf    *newSf
21496 )
21497 #else
21498 PRIVATE Void rgSCHCmnUlSwapSfAllocs(cell, oldSf, newSf)
21499 RgSchCellCb  *cell;
21500 RgSchUlSf    *oldSf;
21501 RgSchUlSf    *newSf;
21502 #endif
21503 {
21504    RgSchUlAllocDb *tempAllocDb  = newSf->allocDb;
21505    RgSchUlHoleDb  *tempHoleDb   = newSf->holeDb;
21506    U8              tempAvailSbs = newSf->availSubbands;
21507
21508    UNUSED(cell);
21509
21510    newSf->allocDb       = oldSf->allocDb;
21511    newSf->holeDb        = oldSf->holeDb;
21512    newSf->availSubbands = oldSf->availSubbands;
21513
21514    oldSf->allocDb = tempAllocDb;
21515    oldSf->holeDb  = tempHoleDb;
21516    oldSf->availSubbands = tempAvailSbs;
21517       
21518    /* Fix ccpu00120610*/
21519    newSf->allocCountRef = &newSf->allocDb->count;
21520    oldSf->allocCountRef = &oldSf->allocDb->count;
21521    RETVOID;
21522 }
21523 /**
21524  * @brief Perform non-adaptive RETX for non-colliding allocs.
21525  *
21526  * @details
21527  *
21528  *     Function : rgSCHCmnUlPrcNonAdptRetx
21529  *
21530  *      - Perform non-adaptive RETX for non-colliding allocs.
21531  *
21532  *  @param[in]  RgSchCellCb  *cell
21533  *  @param[in]  RgSchUlSf    *newSf
21534  *  @param[in]  U8           idx
21535  *  @return  Void
21536  **/
21537 #ifdef ANSI
21538 PRIVATE Void rgSCHCmnUlPrcNonAdptRetx
21539 (
21540 RgSchCellCb  *cell,
21541 RgSchUlSf    *newSf,
21542 U8           idx
21543 )
21544 #else
21545 PRIVATE Void rgSCHCmnUlPrcNonAdptRetx(cell, newSf, idx)
21546 RgSchCellCb  *cell;
21547 RgSchUlSf    *newSf;
21548 U8           idx;
21549 #endif
21550 {
21551    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
21552    RgSchUlAlloc    *alloc, *nxtAlloc;
21553
21554    /* perform non-adaptive retx allocation(adjustment) */
21555    if ((alloc = rgSCHUtlUlAllocFirst(newSf)) != NULLP)
21556    {
21557       do
21558       {
21559          nxtAlloc = rgSCHUtlUlAllocNxt(newSf, alloc);
21560          /* A merged new TX alloc, reset the state and skip */
21561          if (alloc->mrgdNewTxAlloc)
21562          {
21563             alloc->mrgdNewTxAlloc = FALSE;
21564             continue;
21565          }
21566          
21567
21568          rgSCHCmnUlNonadapRetx(cellUl, alloc, idx);
21569
21570       } while((alloc = nxtAlloc) != NULLP);
21571    }
21572    RETVOID;
21573 }
21574
21575 /**
21576  * @brief Update TX and RETX subframe's allocation
21577  *        markings.
21578  *
21579  * @details
21580  *
21581  *     Function : rgSCHCmnUlPrfmSfMerge
21582  *
21583  *      - Release all preassigned allocations of newSf and merge
21584  *        them to oldSf.
21585  *      - If alloc of newSf collide with one or more allocs of oldSf
21586  *        - mark all such allocs of oldSf for Adaptive Retx.
21587  *      - Swap the alloc and hole DB references of oldSf and newSf.
21588  *      - The allocs which did not collide with pre-assigned msg3
21589  *        allocs are marked for non-adaptive RETX.
21590  *
21591  *  @param[in]  RgSchCellCb  *cell
21592  *  @param[in]  RgSchUlSf    *oldSf
21593  *  @param[in]  RgSchUlSf    *newSf
21594  *  @param[in]  U8           idx 
21595  *  @return  Void
21596  **/
21597 #ifdef ANSI
21598 PRIVATE Void rgSCHCmnUlPrfmSfMerge
21599 (
21600 RgSchCellCb  *cell,
21601 RgSchUlSf    *oldSf,
21602 RgSchUlSf    *newSf,
21603 U8           idx
21604 )
21605 #else
21606 PRIVATE Void rgSCHCmnUlPrfmSfMerge(cell, oldSf, newSf, idx)
21607 RgSchCellCb  *cell;
21608 RgSchUlSf    *oldSf;
21609 RgSchUlSf    *newSf;
21610 U8           idx;
21611 #endif
21612 {
21613    /* Preassigned resources for msg3 in newSf.
21614     * Hence do adaptive retx for all NACKED TXs */
21615    rgSCHCmnUlMergeSfAllocs(cell, oldSf, newSf);
21616    /* swap alloc and hole DBs of oldSf and newSf. */
21617    rgSCHCmnUlSwapSfAllocs(cell, oldSf, newSf);
21618    /* Here newSf has the resultant merged allocs context */
21619    /* Perform non-adaptive RETX for non-colliding allocs */
21620    rgSCHCmnUlPrcNonAdptRetx(cell, newSf, idx);
21621    
21622    RETVOID;
21623 }
21624 #endif
21625 /**
21626  * @brief Update TX and RETX subframe's allocation
21627  *        markings.
21628  *
21629  * @details
21630  *
21631  *     Function : rgSCHCmnUlRmvCmpltdAllocs
21632  *
21633  *      - Free all Transmission which are ACKED
21634  *        OR for which MAX retransmission have
21635  *        occurred.
21636  *
21637  *
21638  *  @param[in]  RgSchCellCb    *cell,
21639  *  @param[in]  RgSchUlSf      *sf
21640  *  @return  Void
21641  **/
21642 #ifdef ANSI
21643 PRIVATE Void rgSCHCmnUlRmvCmpltdAllocs
21644 (
21645 RgSchCellCb    *cell,
21646 RgSchUlSf      *sf
21647 )
21648 #else
21649 PRIVATE Void rgSCHCmnUlRmvCmpltdAllocs(cell, sf)
21650 RgSchCellCb    *cell;
21651 RgSchUlSf      *sf;
21652 #endif
21653 {
21654    RgSchUlAlloc    *alloc, *nxtAlloc;
21655
21656    if ((alloc = rgSCHUtlUlAllocFirst(sf)) == NULLP)
21657    {
21658       RETVOID;
21659    }
21660    do
21661    {
21662       nxtAlloc = rgSCHUtlUlAllocNxt(sf, alloc);
21663 #ifdef UL_ADPT_DBG      
21664       printf("rgSCHCmnUlRmvCmpltdAllocs:time(%d %d) alloc->hqProc->remTx %d hqProcId(%d) \n",cell->crntTime.sfn,cell->crntTime.slot,alloc->hqProc->remTx, alloc->grnt.hqProcId);
21665 #endif
21666       alloc->hqProc->rcvdCrcInd = TRUE;
21667       if ((alloc->hqProc->rcvdCrcInd) || (alloc->hqProc->remTx == 0))
21668       {
21669
21670         /* SR_RACH_STATS : MSG 3 MAX RETX FAIL*/
21671          if ((alloc->forMsg3 == TRUE) && (alloc->hqProc->remTx == 0))
21672          {
21673             rgNumMsg3FailMaxRetx++;
21674 #ifdef TENB_STATS
21675             cell->tenbStats->sch.msg3Fail++;
21676 #endif
21677          }
21678
21679 #ifdef MAC_SCH_STATS
21680     if(alloc->ue != NULLP)
21681     {
21682        /* access from ulHarqProc*/
21683        RgSchUeCb       *ueCb  = alloc->ue;
21684        RgSchCmnUe      *cmnUe = (RgSchCmnUe*)ueCb->sch;
21685        RgSchCmnUlUe    *ulUe  = &(cmnUe->ul);
21686        U8              cqi    = ulUe->crntUlCqi[0];  
21687        U16             numUlRetx = ueCb->ul.hqEnt.maxHqRetx - alloc->hqProc->remTx;
21688
21689        hqRetxStats.ulCqiStat[(cqi - 1)].mcs = alloc->grnt.iMcs;
21690
21691        switch (numUlRetx)
21692        {
21693           case 1:
21694              hqRetxStats.ulCqiStat[(cqi - 1)].numOfHQ_1++;
21695              break;
21696           case 2:
21697              hqRetxStats.ulCqiStat[(cqi - 1)].numOfHQ_2++;
21698              break;
21699          case 3:
21700             hqRetxStats.ulCqiStat[(cqi - 1)].numOfHQ_3++;
21701             break;
21702          case 4:
21703             hqRetxStats.ulCqiStat[(cqi - 1)].numOfHQ_4++;
21704             break;
21705       }
21706       hqRetxStats.ulCqiStat[(cqi - 1)].totalTx = \
21707              hqRetxStats.ulCqiStat[(cqi - 1)].numOfHQ_1 + \
21708             (hqRetxStats.ulCqiStat[(cqi - 1)].numOfHQ_2 * 2) + \
21709             (hqRetxStats.ulCqiStat[(cqi - 1)].numOfHQ_3 * 3) + \
21710             (hqRetxStats.ulCqiStat[(cqi - 1)].numOfHQ_4 * 4);
21711    }
21712
21713 #endif /*MAC_SCH_STATS*/
21714          rgSCHCmnUlFreeAllocation(cell, sf, alloc);
21715       }
21716       /*ccpu00106104 MOD added check for AckNackRep */
21717       /*added check for acknack so that adaptive retx considers ue
21718        inactivity due to ack nack repetition*/
21719       else if((alloc->ue != NULLP) && (TRUE != alloc->forMsg3))
21720       {
21721         rgSCHCmnUlUpdAllocRetx(cell, alloc);
21722         rgSCHUtlUlAllocRls(sf, alloc);
21723       }
21724    } while ((alloc = nxtAlloc) != NULLP);
21725
21726    RETVOID;
21727 }
21728
21729 /**
21730  * @brief Update an uplink subframe.
21731  *
21732  * @details
21733  *
21734  *     Function : rgSCHCmnRlsUlSf
21735  *
21736  *     For each allocation
21737  *      - if no more tx needed
21738  *         - Release allocation
21739  *      - else
21740  *         - Perform retransmission
21741  *
21742  *  @param[in]  RgSchUlSf *sf
21743  *  @param[in]  U8        idx 
21744  *  @return  Void
21745  **/
21746 #ifdef ANSI
21747 Void rgSCHCmnRlsUlSf
21748 (
21749 RgSchCellCb    *cell,
21750 U8              idx
21751 )
21752 #else
21753 Void rgSCHCmnRlsUlSf(cell, idx)
21754 RgSchCellCb    *cell;
21755 U8              idx;
21756 #endif
21757 {
21758
21759    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
21760    
21761    if (cellUl->hqFdbkIdx[idx] != RGSCH_INVALID_INFO) 
21762    {
21763       RgSchUlSf   *oldSf  = &cellUl->ulSfArr[cellUl->hqFdbkIdx[idx]];
21764
21765       /* Initialize the reTxLst of UL HqProcs for RETX subframe */
21766       if (rgSCHUtlUlAllocFirst(oldSf) == NULLP)
21767       {
21768          RETVOID;
21769       }
21770       /* Release all completed TX allocs from sf */
21771       rgSCHCmnUlRmvCmpltdAllocs(cell, oldSf);
21772
21773       oldSf->numACqiCount = 0;
21774    }
21775    RETVOID;
21776 }
21777
21778 /**
21779  * @brief Handle uplink allocation for retransmission.
21780  *
21781  * @details
21782  *
21783  *     Function : rgSCHCmnUlUpdAllocRetx
21784  *
21785  *     - Perform adaptive retransmission
21786  *
21787  *  @param[in]  RgSchUlSf *sf
21788  *  @param[in]  RgSchUlAlloc  *alloc
21789  *  @return  Void
21790  **/
21791 #ifdef ANSI
21792 PRIVATE Void rgSCHCmnUlUpdAllocRetx
21793 (
21794 RgSchCellCb    *cell,
21795 RgSchUlAlloc   *alloc
21796 )
21797 #else
21798 PRIVATE Void rgSCHCmnUlUpdAllocRetx(cell, alloc)
21799 RgSchCellCb    *cell;
21800 RgSchUlAlloc   *alloc;
21801 #endif
21802 {
21803    RgSchCmnUlCell *cmnUlCell = RG_SCH_CMN_GET_UL_CELL(cell);
21804
21805
21806    alloc->hqProc->reTxAlloc.rnti    =  alloc->rnti;
21807    alloc->hqProc->reTxAlloc.numSb   =  alloc->numSb;
21808    alloc->hqProc->reTxAlloc.iMcs   =  alloc->grnt.iMcs;
21809 #ifdef RG_5GTF
21810    alloc->hqProc->reTxAlloc.dciFrmt =  alloc->grnt.dciFrmt;
21811    alloc->hqProc->reTxAlloc.numLyr   =  alloc->grnt.numLyr;
21812    alloc->hqProc->reTxAlloc.vrbgStart =  alloc->grnt.vrbgStart;
21813    alloc->hqProc->reTxAlloc.numVrbg   =  alloc->grnt.numVrbg;
21814    alloc->hqProc->reTxAlloc.modOdr   =  alloc->grnt.modOdr;
21815 #endif
21816    //iTbs = rgSCHCmnUlGetITbsFrmIMcs(alloc->grnt.iMcs);
21817    //iTbs = alloc->grnt.iMcs;
21818    //RGSCH_ARRAY_BOUND_CHECK( 0, rgTbSzTbl[0], iTbs);
21819    alloc->hqProc->reTxAlloc.tbSz = alloc->grnt.datSz;
21820       //rgTbSzTbl[0][iTbs][alloc->grnt.numRb-1]/8;
21821    alloc->hqProc->reTxAlloc.ue      = alloc->ue;
21822    alloc->hqProc->reTxAlloc.forMsg3 = alloc->forMsg3;
21823    alloc->hqProc->reTxAlloc.raCb = alloc->raCb;
21824
21825    /* Set as retransmission is pending */
21826    alloc->hqProc->isRetx = TRUE;
21827    alloc->hqProc->alloc = NULLP;
21828    alloc->hqProc->ulSfIdx = RGSCH_INVALID_INFO;
21829 #ifdef UL_ADPT_DBG  
21830    printf("Adding Harq Proc Id in the retx list  hqProcId %d \n",alloc->grnt.hqProcId); 
21831 #endif
21832    cmLListAdd2Tail(&cmnUlCell->reTxLst, &alloc->hqProc->reTxLnk);
21833    alloc->hqProc->reTxLnk.node = (PTR)alloc->hqProc;
21834    RETVOID;
21835 }
21836
21837 /**
21838  * @brief Attempts allocation for msg3s for which ADAP retransmissions
21839  *     are required.
21840  *
21841  * @details
21842  *
21843  *     Function : rgSCHCmnUlAdapRetxAlloc
21844  *
21845  *     Attempts allocation for msg3s for which ADAP retransmissions
21846  *     are required.
21847  *
21848  *  @param[in]  RgSchCellCb       *cell
21849  *  @param[in]  RgSchUlSf         *sf
21850  *  @param[in]  RgSchUlHqProcCb   *proc;
21851  *  @param[in]  RgSchUlHole       *hole;
21852  *  @return  U8
21853  **/
21854 #ifdef ANSI
21855 PRIVATE Bool rgSCHCmnUlAdapRetxAlloc
21856 (
21857 RgSchCellCb       *cell,
21858 RgSchUlSf         *sf,
21859 RgSchUlHqProcCb   *proc,
21860 RgSchUlHole       *hole
21861 )
21862 #else
21863 PRIVATE Bool rgSCHCmnUlAdapRetxAlloc(cell, sf, proc, hole)
21864 RgSchCellCb       *cell;
21865 RgSchUlSf         *sf;
21866 RgSchUlHqProcCb   *proc;
21867 RgSchUlHole       *hole;
21868 #endif
21869 {
21870    U8              numSb = proc->reTxAlloc.numSb;
21871    U8              iMcs  = proc->reTxAlloc.iMcs;
21872    CmLteTimingInfo frm = cell->crntTime;
21873    RgSchCmnUlCell  *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
21874    RgSchDlSf       *dlSf;
21875    RgSchPdcch      *pdcch;
21876    RgSchUlAlloc    *alloc;
21877
21878    /* Fetch PDCCH for msg3 */
21879    /* ccpu00116293 - Correcting relation between UL subframe and DL subframe based on RG_UL_DELTA*/
21880    /* Introduced timing delta for UL control */
21881    RGSCH_INCR_SUB_FRAME(frm, TFU_ULCNTRL_DLDELTA);
21882    dlSf = rgSCHUtlSubFrmGet(cell, frm);
21883    pdcch = rgSCHCmnCmnPdcchAlloc(cell, dlSf);
21884    if (pdcch == NULLP)
21885    {
21886       return (FALSE);
21887    }
21888
21889    /* Fetch UL Alloc for msg3 */
21890    if (numSb <= hole->num)
21891    {
21892       alloc                = rgSCHUtlUlAllocGetHole(sf, numSb, hole);
21893       
21894       /* KWork fix */
21895          if(alloc == NULLP)
21896          {
21897             rgSCHUtlPdcchPut(cell, &dlSf->pdcchInfo, pdcch);
21898             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
21899                   "UL Alloc fail for msg3 retx for rnti: %d\n", 
21900                   proc->reTxAlloc.rnti);
21901             return (FALSE);
21902          }
21903
21904       rgSCHCmnUlAllocFillRbInfo(cell, sf, alloc);
21905       alloc->grnt.iMcs     = iMcs;
21906       alloc->grnt.datSz    = proc->reTxAlloc.tbSz;
21907 #ifdef RG_5GTF
21908 #else
21909       //RG_SCH_UL_MCS_TO_MODODR(iMcs, alloc->grnt.modOdr);
21910 #endif
21911       /* Fill UL Alloc for msg3 */
21912       /* RACHO : setting nDmrs to 0 and UlDelaybit to 0*/
21913       alloc->grnt.nDmrs    = 0;
21914       alloc->grnt.hop      = 0;
21915       alloc->grnt.delayBit = 0;
21916       alloc->grnt.isRtx    = TRUE;
21917       proc->ulSfIdx        = cellUl->schdIdx;
21918 #ifdef RG_5GTF
21919       proc->schdTime = cellUl->schdTime;
21920       alloc->grnt.hqProcId = proc->procId;
21921       alloc->grnt.dciFrmt = proc->reTxAlloc.dciFrmt;
21922       alloc->grnt.numLyr = proc->reTxAlloc.numLyr;
21923       alloc->grnt.vrbgStart = proc->reTxAlloc.vrbgStart;
21924       alloc->grnt.numVrbg = proc->reTxAlloc.numVrbg;
21925       alloc->grnt.rbAssign = rgSCHCmnCalcRiv(MAX_5GTF_VRBG, alloc->grnt.vrbgStart, alloc->grnt.numVrbg);
21926       alloc->grnt.modOdr = proc->reTxAlloc.modOdr;
21927
21928       /* TODO : Hardcoding these as of now */
21929       alloc->grnt.hop = 0;
21930       alloc->grnt.SCID = 0;
21931       alloc->grnt.xPUSCHRange = MAX_5GTF_XPUSCH_RANGE;
21932       alloc->grnt.PMI = 0;
21933       alloc->grnt.uciOnxPUSCH = 0;
21934 #endif
21935       alloc->rnti          = proc->reTxAlloc.rnti;
21936       /* Fix : syed HandIn Ue has forMsg3 and ue Set, but no RaCb */
21937       alloc->ue            = proc->reTxAlloc.ue;
21938       alloc->pdcch         = pdcch;
21939       alloc->forMsg3       = proc->reTxAlloc.forMsg3;
21940       alloc->raCb          = proc->reTxAlloc.raCb;
21941       alloc->hqProc        = proc;
21942       alloc->isAdaptive    = TRUE;
21943 #ifdef LTE_L2_MEAS
21944       sf->totPrb  += alloc->grnt.numRb;
21945 #endif
21946       /* FIX : syed HandIn Ue has forMsg3 and ue Set, but no RaCb */
21947       if (alloc->raCb)
21948       {
21949          alloc->raCb->msg3Grnt= alloc->grnt;
21950 #ifndef LTE_TDD
21951          /* To the crntTime, add the time at which UE will
21952           * actually send MSG3 */
21953          alloc->raCb->msg3AllocTime = cell->crntTime;
21954          RGSCH_INCR_SUB_FRAME(alloc->raCb->msg3AllocTime, RG_SCH_CMN_MIN_RETXMSG3_RECP_INTRVL);
21955 #else
21956          alloc->raCb->msg3AllocTime =  cellUl->schdTime;
21957 #endif
21958          rgSCHCmnUlAdapRetx(alloc, proc);
21959          /* Fill PDCCH with alloc info */
21960          pdcch->rnti                           = alloc->rnti;
21961          pdcch->dci.dciFormat                  = TFU_DCI_FORMAT_0;
21962          pdcch->dci.u.format0Info.hoppingEnbld = alloc->grnt.hop;
21963          pdcch->dci.u.format0Info.rbStart      = alloc->grnt.rbStart;
21964          pdcch->dci.u.format0Info.numRb        = alloc->grnt.numRb;
21965          pdcch->dci.u.format0Info.mcs          = alloc->grnt.iMcsCrnt;
21966          pdcch->dci.u.format0Info.ndi          = alloc->hqProc->ndi;
21967          pdcch->dci.u.format0Info.nDmrs        = alloc->grnt.nDmrs;
21968          pdcch->dci.u.format0Info.tpcCmd       = alloc->grnt.tpc;
21969
21970 #ifdef LTE_TDD
21971 #ifdef TFU_TDD
21972          /* ulIdx setting for cfg 0 shall be appropriately fixed thru ccpu00109015 */
21973          pdcch->dci.u.format0Info.ulIdx = RG_SCH_ULIDX_MSB;
21974          pdcch->dci.u.format0Info.dai = RG_SCH_MAX_DAI_IDX;
21975 #endif
21976 #endif
21977          pdcch->dciNumOfBits = cell->dciSize.size[TFU_DCI_FORMAT_0];
21978       }
21979       else
21980       {
21981          RgSchCmnUlUe *ueUl    = RG_SCH_CMN_GET_UL_UE(alloc->ue,cell);
21982 #ifdef TFU_UPGRADE
21983          alloc->ue->initNumRbs = (alloc->grnt.numVrbg * MAX_5GTF_VRBG_SIZE);
21984 #endif
21985 #ifdef LTE_L2_MEAS
21986          ue->ul.nPrb = alloc->grnt.numRb;
21987 #endif
21988          ueUl->alloc.alloc = alloc;
21989          /* FIx: Removed the call to rgSCHCmnUlAdapRetx */
21990          rgSCHCmnUlUeFillAllocInfo(cell, alloc->ue);
21991          /* Setting csireq as false for Adaptive Retx*/
21992          ueUl->alloc.alloc->pdcch->dci.u.format0Info.cqiReq = RG_SCH_APCQI_NO;
21993          pdcch->dciNumOfBits = alloc->ue->dciSize.cmnSize[TFU_DCI_FORMAT_0];
21994       }
21995       /* Reset as retransmission is done */
21996       proc->isRetx = FALSE;
21997    }
21998    else /* Intg fix */
21999    {
22000       rgSCHUtlPdcchPut(cell, &dlSf->pdcchInfo, pdcch);
22001       RLOG_ARG1(L_DEBUG,DBG_CELLID,cell->cellId,
22002                "Num SB not suffiecient for adap retx for rnti: %d", 
22003                proc->reTxAlloc.rnti);
22004       return (FALSE);
22005    }
22006    return (TRUE);
22007 }
22008
22009 /* Fix: syed Adaptive Msg3 Retx crash. */
22010 /**
22011  * @brief Releases all Adaptive Retx HqProcs which failed for
22012  *        allocations in this scheduling occassion.
22013  *
22014  * @details
22015  *
22016  *     Function : rgSCHCmnUlSfRlsRetxProcs
22017  *
22018  *
22019  *  @param[in]  RgSchCellCb *cell
22020  *  @param[in]  RgSchUlSf   *sf
22021  *  @return  U8
22022  **/
22023 #ifdef UNUSED_FUNC
22024 #ifdef ANSI
22025 PRIVATE Void rgSCHCmnUlSfRlsRetxProcs
22026 (
22027 RgSchCellCb *cell,
22028 RgSchUlSf   *sf
22029 )
22030 #else
22031 PRIVATE Void rgSCHCmnUlSfRlsRetxProcs(cell, sf)
22032 RgSchCellCb *cell;
22033 RgSchUlSf   *sf;
22034 #endif
22035 {
22036    CmLListCp         *cp;
22037    CmLList           *node;
22038    RgSchUlHqProcCb   *proc;
22039    RgSchCmnUlCell    *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
22040
22041
22042    cp = &(cellUl->reTxLst);
22043    node = cp->first;
22044    while (node)
22045    {
22046       proc  = (RgSchUlHqProcCb *)node->node;
22047       node = node->next;
22048       /* ccpu00137834 : Deleting reTxLnk from the respective reTxLst */
22049       cmLListDelFrm(&cellUl->reTxLst, &proc->reTxLnk);
22050       proc->reTxLnk.node = (PTR)NULLP;
22051    }
22052    RETVOID;
22053 }
22054 #endif   
22055
22056 /**
22057  * @brief Attempts allocation for UEs for which retransmissions
22058  *     are required.
22059  *
22060  * @details
22061  *
22062  *     Function : rgSCHCmnUlSfReTxAllocs
22063  *
22064  *     Attempts allocation for UEs for which retransmissions
22065  *     are required.
22066  *
22067  *  @param[in]  RgSchCellCb *cell
22068  *  @param[in]  RgSchUlSf   *sf
22069  *  @return  U8
22070  **/
22071 #ifdef ANSI
22072 PRIVATE Void rgSCHCmnUlSfReTxAllocs
22073 (
22074 RgSchCellCb *cell,
22075 RgSchUlSf   *sf
22076 )
22077 #else
22078 PRIVATE Void rgSCHCmnUlSfReTxAllocs(cell, sf)
22079 RgSchCellCb *cell;
22080 RgSchUlSf   *sf;
22081 #endif
22082 {
22083    CmLListCp         *cp;
22084    CmLList           *node;
22085    RgSchUlHqProcCb   *proc;
22086    RgSchUlHole       *hole;
22087    RgSchUeCb         *ue;
22088    RgSchCmnCell      *schCmnCell = (RgSchCmnCell *)(cell->sc.sch);
22089    RgSchCmnUlCell    *cellUl = RG_SCH_CMN_GET_UL_CELL(cell);
22090
22091    cp = &(cellUl->reTxLst);
22092    node = cp->first;
22093    while ((node))
22094    {
22095       proc  = (RgSchUlHqProcCb *)node->node;
22096       ue = proc->reTxAlloc.ue;
22097       node = node->next;
22098       /*ccpu00106104 MOD added check for AckNackRep */
22099       /*added check for acknack so that adaptive retx considers ue
22100        inactivity due to ack nack repetition*/
22101       if((ue != NULLP) &&
22102             ((ue->measGapCb.isMeasuring == TRUE)||
22103                (ue->ackNakRepCb.isAckNakRep == TRUE)))
22104       {
22105          continue;
22106       }
22107       /* Fix for ccpu00123917: Check if maximum allocs per UL sf have been exhausted */
22108       if (((hole = rgSCHUtlUlHoleFirst(sf)) == NULLP)
22109             || (sf->allocDb->count == schCmnCell->ul.maxAllocPerUlSf))
22110       {
22111          /* No more UL BW then return */
22112          break;
22113       }
22114       /* perform adaptive retx for UE's */
22115       if (rgSCHCmnUlAdapRetxAlloc(cell, sf, proc, hole) == FALSE)
22116       {
22117          continue;
22118       }
22119       /* ccpu00137834 : Deleting reTxLnk from the respective reTxLst */
22120       cmLListDelFrm(&cellUl->reTxLst, &proc->reTxLnk);
22121       /* Fix: syed Adaptive Msg3 Retx crash. */
22122       proc->reTxLnk.node = (PTR)NULLP;
22123    }
22124    RETVOID;
22125 }
22126
22127 /**
22128  * @brief Handles RB allocation for downlink.
22129  *
22130  * @details
22131  *
22132  *     Function : rgSCHCmnDlRbAlloc
22133  *
22134  *     Invoking Module Processing:
22135  *     - This function is invoked for DL RB allocation
22136  *
22137  *     Processing Steps:
22138  *     - If cell is frequency selecive,
22139  *       - Call rgSCHDlfsAllocRb().
22140  *     - else,
22141  *       - Call rgSCHCmnNonDlfsRbAlloc().
22142  *
22143  *  @param[in]  RgSchCellCb        *cell
22144  *  @param[in]  RgSchDlRbAllocInfo *allocInfo
22145  *  @return  Void
22146  **/
22147
22148 #ifdef ANSI
22149 PRIVATE Void rgSCHCmnDlRbAlloc
22150 (
22151 RgSchCellCb           *cell,
22152 RgSchCmnDlRbAllocInfo *allocInfo
22153 )
22154 #else
22155 PRIVATE Void rgSCHCmnDlRbAlloc(cell, allocInfo)
22156 RgSchCellCb           *cell;
22157 RgSchCmnDlRbAllocInfo *allocInfo;
22158 #endif
22159 {
22160    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
22161
22162    if (cellSch->dl.isDlFreqSel)
22163    {
22164       printf("5GTF_ERROR DLFS SCH Enabled\n");
22165       cellSch->apisDlfs->rgSCHDlfsAllocRb(cell, allocInfo);
22166    }
22167    else
22168    {
22169       rgSCHCmnNonDlfsRbAlloc(cell, allocInfo);
22170    }
22171    RETVOID;
22172 }
22173
22174 #ifdef LTEMAC_SPS
22175
22176 /**
22177  * @brief Determines number of RBGs and RBG subset sizes for the given DL
22178  * bandwidth and rbgSize
22179  *
22180  * @details
22181  *     Function : rgSCHCmnDlGetRbgInfo
22182  *
22183  *
22184  *     Processing Steps:
22185  *     - Fill-up rbgInfo data structure for given DL bandwidth and rbgSize
22186  *
22187  *   @param[in]  U8             dlTotalBw
22188  *   @param[in]  U8             dlSubsetBw
22189  *   @param[in]  U8             maxRaType1SubsetBw
22190  *   @param[in]  U8             rbgSize
22191  *   @param[out] RgSchBwRbgInfo *rbgInfo
22192  *  @return Void
22193  **/
22194 #ifdef ANSI
22195 Void rgSCHCmnDlGetRbgInfo
22196 (
22197 U8             dlTotalBw,
22198 U8             dlSubsetBw,
22199 U8             maxRaType1SubsetBw,
22200 U8             rbgSize,
22201 RgSchBwRbgInfo *rbgInfo
22202 )
22203 #else
22204 Void rgSCHCmnDlGetRbgInfo(dlTotalBw, dlSubsetBw, maxRaType1SubsetBw,
22205       rbgSize, rbgInfo)
22206 U8             dlTotalBw;
22207 U8             dlSubsetBw;
22208 U8             maxRaType1SubsetBw;
22209 U8             rbgSize;
22210 RgSchBwRbgInfo *rbgInfo;
22211 #endif
22212 {
22213 #ifdef RGSCH_SPS_UNUSED
22214    U8    idx           = 0;
22215    U8    lastRbgIdx    = ((dlTotalBw + rbgSize - 1)/rbgSize) - 1;
22216    U8    currRbgSize   = rbgSize;
22217    U8    subsetSizeIdx = 0;
22218    U8    subsetSize[RG_SCH_NUM_RATYPE1_SUBSETS] = {0};
22219    U8    lastRbgSize = rbgSize - (dlTotalBw - ((dlTotalBw/rbgSize) * rbgSize));
22220    U8    numRaType1Rbgs = (maxRaType1SubsetBw + rbgSize - 1)/rbgSize;
22221 #endif
22222
22223    /* Compute maximum number of SPS RBGs for the cell */
22224    rbgInfo->numRbgs =  ((dlSubsetBw + rbgSize - 1)/rbgSize);
22225
22226 #ifdef RGSCH_SPS_UNUSED
22227    /* Distribute RBGs across subsets except last RBG */
22228    for (;idx < numRaType1Rbgs - 1; ++idx)
22229    {
22230       subsetSize[subsetSizeIdx] += currRbgSize;
22231       subsetSizeIdx = (subsetSizeIdx + 1) % rbgSize;
22232    }
22233
22234    /* Computation for last RBG */
22235    if (idx == lastRbgIdx)
22236    {
22237       currRbgSize = lastRbgSize;
22238    }
22239    subsetSize[subsetSizeIdx] += currRbgSize;
22240    subsetSizeIdx = (subsetSizeIdx + 1) % rbgSize;
22241 #endif
22242
22243    /* Update the computed sizes */
22244 #ifdef RGSCH_SPS_UNUSED
22245    rbgInfo->lastRbgSize = currRbgSize;
22246 #endif
22247    rbgInfo->lastRbgSize = rbgSize - 
22248             (dlSubsetBw - ((dlSubsetBw/rbgSize) * rbgSize));
22249 #ifdef RGSCH_SPS_UNUSED
22250    memcpy(rbgInfo->rbgSubsetSize, subsetSize, 4 * sizeof(U8));
22251 #endif
22252    rbgInfo->numRbs = (rbgInfo->numRbgs * rbgSize > dlTotalBw) ?
22253       dlTotalBw:(rbgInfo->numRbgs * rbgSize);
22254    rbgInfo->rbgSize = rbgSize;
22255 }
22256
22257 /**
22258  * @brief Handles RB allocation for Resource allocation type 0
22259  *
22260  * @details
22261  *
22262  *     Function : rgSCHCmnDlRaType0Alloc
22263  *
22264  *     Invoking Module Processing:
22265  *     - This function is invoked for DL RB allocation for resource allocation
22266  *     type 0
22267  *
22268  *     Processing Steps:
22269  *     - Determine the available positions in the rbgMask.
22270  *     - Allocate RBGs in the available positions.
22271  *     - Update RA Type 0, RA Type 1 and RA type 2 masks.
22272  *
22273  *  @param[in]   RgSchDlSfAllocInfo *allocedInfo
22274  *  @param[in]   U8             rbsReq
22275  *  @param[in]   RgSchBwRbgInfo *rbgInfo
22276  *  @param[out]  U8             *numAllocRbs
22277  *  @param[out]  RgSchDlSfAllocInfo *resAllocInfo
22278  *  @param[in]   Bool           isPartialAlloc
22279  *
22280  *  @return  Void
22281  **/
22282
22283 #ifdef ANSI
22284 U8 rgSCHCmnDlRaType0Alloc
22285 (
22286 RgSchDlSfAllocInfo *allocedInfo,
22287 U8                 rbsReq,
22288 RgSchBwRbgInfo     *rbgInfo,
22289 U8                 *numAllocRbs,
22290 RgSchDlSfAllocInfo *resAllocInfo,
22291 Bool               isPartialAlloc
22292 )
22293 #else
22294 U8 rgSCHCmnDlRaType0Alloc(allocedInfo, rbsReq, rbgInfo,
22295       numAllocRbs, resAllocInfo, isPartialAlloc)
22296 RgSchDlSfAllocInfo *allocedInfo;
22297 U8                 rbsReq;
22298 RgSchBwRbgInfo     *rbgInfo;
22299 U8                 *numAllocRbs;
22300 RgSchDlSfAllocInfo *resAllocInfo;
22301 Bool               isPartialAlloc;
22302 #endif
22303 {
22304    /* Note: This function atttempts allocation only full allocation */
22305    U32      remNumRbs, rbgPosInRbgMask, ueRaType2Mask;
22306    U8       type2MaskIdx, cnt, rbIdx;
22307    U8       maskSize, rbg;
22308    U8       bestNumAvailRbs = 0;
22309    U8       usedRbs = 0;
22310    U8       numAllocRbgs = 0;
22311    U8       rbgSize = rbgInfo->rbgSize;
22312    U32      *rbgMask = &(resAllocInfo->raType0Mask);
22313 #ifdef RGSCH_SPS_UNUSED
22314    U8       rbgSubset;
22315    U32      ueRaType1Mask;
22316    U32      *raType1Mask = resAllocInfo->raType1Mask;
22317    U32      *raType1UsedRbs = resAllocInfo->raType1UsedRbs;
22318 #endif
22319    U32      *raType2Mask = resAllocInfo->raType2Mask;
22320
22321    U32      allocedMask = allocedInfo->raType0Mask;
22322
22323    maskSize = rbgInfo->numRbgs;
22324
22325    *numAllocRbs = 0;
22326    RG_SCH_CMN_DL_COUNT_ONES(allocedMask, maskSize, &usedRbs);
22327    if (maskSize == usedRbs)
22328    {
22329       /* All RBGs are allocated, including the last one */
22330       remNumRbs = 0;
22331    }
22332    else
22333    {
22334       remNumRbs = (maskSize - usedRbs - 1) * rbgSize; /* vamsee: removed minus 1 */
22335
22336       /* If last RBG is available, add last RBG size */
22337       if (!(allocedMask & (1 << RG_SCH_CMN_DL_GET_POS_FRM_LSB(maskSize - 1))))
22338       {
22339          remNumRbs += rbgInfo->lastRbgSize;
22340       }
22341    }
22342
22343    /* If complete allocation is needed, check if total requested RBs are available else
22344     * check the best available RBs */
22345    if (!isPartialAlloc)
22346    {
22347       if (remNumRbs >= rbsReq)
22348       {
22349          bestNumAvailRbs = rbsReq;
22350       }
22351    }
22352    else
22353    {
22354       bestNumAvailRbs = remNumRbs > rbsReq ? rbsReq : remNumRbs;
22355    }
22356
22357    /* Allocate for bestNumAvailRbs */
22358    if (bestNumAvailRbs)
22359    {
22360       for (rbg = 0; rbg < maskSize - 1; ++rbg)
22361       {
22362          rbgPosInRbgMask = 1 << RG_SCH_CMN_DL_GET_POS_FRM_LSB(rbg);
22363          if (!(allocedMask & rbgPosInRbgMask))
22364          {
22365             /* Update RBG mask */
22366             *rbgMask |= rbgPosInRbgMask;
22367
22368             /* Compute RB index of the first RB of the RBG allocated */
22369             rbIdx = rbg * rbgSize;
22370
22371             for (cnt = 0; cnt < rbgSize; ++cnt)
22372             {
22373 #ifdef RGSCH_SPS_UNUSED
22374                ueRaType1Mask = rgSCHCmnGetRaType1Mask(rbIdx, rbgSize, &rbgSubset);
22375 #endif
22376                ueRaType2Mask = rgSCHCmnGetRaType2Mask(rbIdx, &type2MaskIdx);
22377 #ifdef RGSCH_SPS_UNUSED
22378                /* Update RBG mask for RA type 1 */
22379                raType1Mask[rbgSubset] |= ueRaType1Mask;
22380                raType1UsedRbs[rbgSubset]++;
22381 #endif
22382                /* Update RA type 2 mask */
22383                raType2Mask[type2MaskIdx] |= ueRaType2Mask;
22384                rbIdx++;
22385             }
22386             *numAllocRbs += rbgSize;
22387             remNumRbs -= rbgSize;
22388             ++numAllocRbgs;
22389             if (*numAllocRbs >= bestNumAvailRbs)
22390             {
22391                break;
22392             }
22393          }
22394       }
22395       /* If last RBG available and allocation is not completed, allocate
22396        * last RBG */
22397       if (*numAllocRbs < bestNumAvailRbs)
22398       {
22399          rbgPosInRbgMask =  1 << RG_SCH_CMN_DL_GET_POS_FRM_LSB(rbg);
22400          *rbgMask |= rbgPosInRbgMask;
22401          *numAllocRbs += rbgInfo->lastRbgSize;
22402
22403          /* Compute RB index of the first RB of the last RBG */
22404          rbIdx = ((rbgInfo->numRbgs - 1 ) * rbgSize ); /* removed minus 1  vamsee */
22405
22406          for (cnt = 0; cnt < rbgInfo->lastRbgSize; ++cnt)
22407          {
22408 #ifdef RGSCH_SPS_UNUSED
22409             ueRaType1Mask = rgSCHCmnGetRaType1Mask(rbIdx, rbgSize, &rbgSubset);
22410 #endif
22411             ueRaType2Mask = rgSCHCmnGetRaType2Mask(rbIdx, &type2MaskIdx);
22412 #ifdef RGSCH_SPS_UNUSED
22413             /* Update RBG mask for RA type 1 */
22414             raType1Mask[rbgSubset] |=  ueRaType1Mask;
22415             raType1UsedRbs[rbgSubset]++;
22416 #endif
22417             /* Update RA type 2 mask */
22418             raType2Mask[type2MaskIdx] |= ueRaType2Mask;
22419             rbIdx++;
22420          }
22421          remNumRbs -= rbgInfo->lastRbgSize;
22422          ++numAllocRbgs;
22423       }
22424       /* Note: this should complete allocation, not checking for the
22425        * same */
22426    }
22427
22428    return (numAllocRbgs);
22429 }
22430
22431 #ifdef RGSCH_SPS_UNUSED
22432 /**
22433  * @brief Handles RB allocation for Resource allocation type 1
22434  *
22435  * @details
22436  *
22437  *     Function : rgSCHCmnDlRaType1Alloc
22438  *
22439  *     Invoking Module Processing:
22440  *     - This function is invoked for DL RB allocation for resource allocation
22441  *     type 1
22442  *
22443  *     Processing Steps:
22444  *     - Determine the available positions in the subsets.
22445  *     - Allocate RB in the available subset.
22446  *     - Update RA Type1, RA type 0 and RA type 2 masks.
22447  *
22448  *  @param[in]   RgSchDlSfAllocInfo *allocedInfo
22449  *  @param[in]   U8                 rbsReq
22450  *  @param[in]   RgSchBwRbgInfo     *rbgInfo
22451  *  @param[in]   U8                 startRbgSubset
22452  *  @param[in]   U8                 *allocRbgSubset
22453  *  @param[out]  rgSchDlSfAllocInfo *resAllocInfo
22454  *  @param[in]   Bool               isPartialAlloc
22455  *
22456  *  @return  U8
22457  *  Number of allocated RBs
22458  **/
22459
22460 #ifdef ANSI
22461 U8 rgSCHCmnDlRaType1Alloc
22462 (
22463 RgSchDlSfAllocInfo *allocedInfo,
22464 U8                 rbsReq,
22465 RgSchBwRbgInfo     *rbgInfo,
22466 U8                 startRbgSubset,
22467 U8                 *allocRbgSubset,
22468 RgSchDlSfAllocInfo *resAllocInfo,
22469 Bool               isPartialAlloc
22470 )
22471 #else
22472 U8 rgSCHCmnDlRaType1Alloc(allocedInfo, rbsReq,rbgInfo,startRbgSubset,
22473       allocRbgSubset, resAllocInfo, isPartialAlloc)
22474 RgSchDlSfAllocInfo *allocedInfo;
22475 U8                 rbsReq;
22476 RgSchBwRbgInfo     *rbgInfo;
22477 U8                 startRbgSubset;
22478 U8                 *allocRbgSubset;
22479 RgSchDlSfAllocInfo *resAllocInfo;
22480 Bool               isPartialAlloc;
22481 #endif
22482 {
22483    /* Note: This function atttempts only full allocation */
22484    U8          *rbgSubsetSzArr;
22485    U8          type2MaskIdx, subsetIdx, rbIdx, rbInSubset, rbgInSubset;
22486    U8          offset, rbg, maskSize, bestSubsetIdx;
22487    U8          startPos = 0;
22488    U8          bestNumAvailRbs = 0;
22489    U8          numAllocRbs = 0;
22490    U32         ueRaType2Mask, ueRaType0Mask, rbPosInSubset;
22491    U32         remNumRbs, allocedMask;
22492    U8          usedRbs = 0;
22493    U8          rbgSize = rbgInfo->rbgSize;
22494    U8          rbgSubset = startRbgSubset;
22495    U32         *rbgMask = &resAllocInfo->raType0Mask;
22496    U32         *raType1Mask = resAllocInfo->raType1Mask;
22497    U32         *raType2Mask = resAllocInfo->raType2Mask;
22498    U32         *raType1UsedRbs = resAllocInfo->raType1UsedRbs;
22499    U32         *allocMask = allocedInfo->raType1Mask;
22500
22501    /* Initialize the subset size Array */
22502    rbgSubsetSzArr = rbgInfo->rbgSubsetSize;
22503
22504    /* Perform allocation for RA type 1 */
22505    for (subsetIdx = 0;subsetIdx < rbgSize; ++subsetIdx)
22506    {
22507       allocedMask = allocMask[rbgSubset];
22508       maskSize = rbgSubsetSzArr[rbgSubset];
22509
22510       /* Determine number of available RBs in the subset */
22511       usedRbs = allocedInfo->raType1UsedRbs[subsetIdx];
22512       remNumRbs = maskSize - usedRbs;
22513
22514       if (remNumRbs >= rbsReq)
22515       {
22516          bestNumAvailRbs = rbsReq;
22517          bestSubsetIdx = rbgSubset;
22518          break;
22519       }
22520       else if (isPartialAlloc && (remNumRbs > bestNumAvailRbs))
22521       {
22522          bestNumAvailRbs = remNumRbs;
22523          bestSubsetIdx = rbgSubset;
22524       }
22525
22526       rbgSubset = (rbgSubset + 1) % rbgSize;
22527    } /* End of for (each rbgsubset) */
22528
22529    if (bestNumAvailRbs)
22530    {
22531       /* Initialize alloced mask and subsetSize depending on the RBG
22532        * subset of allocation */
22533       U8        startIdx = 0;
22534       maskSize = rbgSubsetSzArr[bestSubsetIdx];
22535       allocedMask = allocMask[bestSubsetIdx];
22536       RG_SCH_CMN_DL_GET_START_POS(allocedMask, maskSize,
22537             &startPos);
22538       for (; startIdx < rbgSize; ++startIdx, ++startPos)
22539       {
22540          for (rbInSubset = startPos; rbInSubset < maskSize;
22541                rbInSubset = rbInSubset + rbgSize)
22542          {
22543             rbPosInSubset =  1 << RG_SCH_CMN_DL_GET_POS_FRM_LSB(rbInSubset);
22544             if (!(allocedMask & rbPosInSubset))
22545             {
22546                raType1Mask[bestSubsetIdx] |= rbPosInSubset;
22547                raType1UsedRbs[bestSubsetIdx]++;
22548
22549                /* Compute RB index value for the RB being allocated */
22550                rbgInSubset = rbInSubset /rbgSize;
22551                offset = rbInSubset % rbgSize;
22552                rbg = (rbgInSubset * rbgSize) + bestSubsetIdx;
22553                rbIdx = (rbg * rbgSize) + offset;
22554
22555                /* Update RBG mask for RA type 0 allocation */
22556                ueRaType0Mask = rgSCHCmnGetRaType0Mask(rbIdx, rbgSize);
22557                *rbgMask |= ueRaType0Mask;
22558
22559                /* Update RA type 2 mask */
22560                ueRaType2Mask = rgSCHCmnGetRaType2Mask(rbIdx, &type2MaskIdx);
22561                raType2Mask[type2MaskIdx] |= ueRaType2Mask;
22562
22563                /* Update the counters */
22564                numAllocRbs++;
22565                remNumRbs--;
22566                if (numAllocRbs == bestNumAvailRbs)
22567                {
22568                   break;
22569                }
22570             }
22571          } /* End of for (each position in the subset mask) */
22572          if (numAllocRbs == bestNumAvailRbs)
22573          {
22574             break;
22575          }
22576       } /* End of for startIdx = 0 to rbgSize */
22577
22578       *allocRbgSubset = bestSubsetIdx;
22579    } /* End of if (bestNumAvailRbs) */
22580
22581    return (numAllocRbs);
22582 }
22583 #endif
22584 /**
22585  * @brief Handles RB allocation for Resource allocation type 2
22586  *
22587  * @details
22588  *
22589  *     Function : rgSCHCmnDlRaType2Alloc
22590  *
22591  *     Invoking Module Processing:
22592  *     - This function is invoked for DL RB allocation for resource allocation
22593  *     type 2
22594  *
22595  *     Processing Steps:
22596  *     - Determine the available positions in the mask
22597  *     - Allocate best fit cosecutive RBs.
22598  *     - Update RA Type2, RA type 1 and RA type 0 masks.
22599  *
22600  *  @param[in]   RgSchDlSfAllocInfo *allocedInfo
22601  *  @param[in]   U8             rbsReq
22602  *  @param[in]   RgSchBwRbgInfo *rbgInfo
22603  *  @param[out]  U8             *rbStart
22604  *  @param[out]  rgSchDlSfAllocInfo *resAllocInfo
22605  *  @param[in]   Bool           isPartialAlloc
22606  *
22607  *  @return  U8
22608  *  Number of allocated RBs
22609  **/
22610
22611 #ifdef ANSI
22612 U8 rgSCHCmnDlRaType2Alloc
22613 (
22614 RgSchDlSfAllocInfo *allocedInfo,
22615 U8                 rbsReq,
22616 RgSchBwRbgInfo     *rbgInfo,
22617 U8                 *rbStart,
22618 RgSchDlSfAllocInfo *resAllocInfo,
22619 Bool               isPartialAlloc
22620 )
22621 #else
22622 U8 rgSCHCmnDlRaType2Alloc(allocedInfo, rbsReq, rbgInfo, rbStart,
22623       resAllocInfo, isPartialAlloc)
22624 RgSchDlSfAllocInfo *allocedInfo;
22625 U8                 rbsReq;
22626 RgSchBwRbgInfo     *rbgInfo;
22627 U8                 *rbStart;
22628 RgSchDlSfAllocInfo *resAllocInfo;
22629 Bool               isPartialAlloc;
22630 #endif
22631 {
22632    U8          numAllocRbs = 0;
22633    U8          rbIdx;
22634    U8          rbgSize = rbgInfo->rbgSize;
22635    U32         *rbgMask = &resAllocInfo->raType0Mask;
22636 #ifdef RGSCH_SPS_UNUSED
22637    U32         *raType1Mask = resAllocInfo->raType1Mask;
22638 #endif
22639    U32         *raType2Mask = resAllocInfo->raType2Mask;
22640 #ifdef RGSCH_SPS_UNUSED
22641    U32         *raType1UsedRbs = resAllocInfo->raType1UsedRbs;
22642 #endif
22643    U32         *allocedMask = allocedInfo->raType2Mask;
22644
22645    /* Note: This function atttempts only full allocation */
22646    rgSCHCmnDlGetBestFitHole(allocedMask, rbgInfo->numRbs,
22647          raType2Mask, rbsReq, rbStart, &numAllocRbs, isPartialAlloc);
22648    if (numAllocRbs)
22649    {
22650       /* Update the allocation in RA type 0 and RA type 1 masks */
22651       U8 rbCnt = numAllocRbs;
22652 #ifdef RGSCH_SPS_UNUSED
22653       U8 rbgSubset;
22654       U32 ueRaType1Mask;
22655 #endif
22656       U32 ueRaType0Mask;
22657       rbIdx = *rbStart;
22658
22659       while(rbCnt)
22660       {
22661          /* Update RBG mask for RA type 0 allocation */
22662          ueRaType0Mask = rgSCHCmnGetRaType0Mask(rbIdx, rbgSize);
22663          *rbgMask |= ueRaType0Mask;
22664
22665 #ifdef RGSCH_SPS_UNUSED
22666          /* Update RBG mask for RA type 1 */
22667          ueRaType1Mask = rgSCHCmnGetRaType1Mask(rbIdx, rbgSize, &rbgSubset);
22668          raType1Mask[rbgSubset] |= ueRaType1Mask;
22669          raType1UsedRbs[rbgSubset]++;
22670 #endif
22671          /* Update the counters */
22672          --rbCnt;
22673          rbIdx++;
22674       }
22675    }
22676
22677    return (numAllocRbs);
22678 }
22679
22680 /**
22681  * @brief Determines RA type 0 mask from given RB index.
22682  *
22683  * @details
22684  *
22685  *     Function : rgSCHCmnGetRaType0Mask
22686  *
22687  *
22688  *     Processing Steps:
22689  *     - Determine RA Type 0 mask for given rbIdex and rbg size.
22690  *
22691  *  @param[in]  U8          rbIdx
22692  *  @param[in]  U8          rbgSize
22693  *  @return  U32 RA type 0 mask
22694  **/
22695 #ifdef ANSI
22696 PRIVATE U32 rgSCHCmnGetRaType0Mask
22697 (
22698 U8                rbIdx,
22699 U8                rbgSize
22700 )
22701 #else
22702 PRIVATE U32 rgSCHCmnGetRaType0Mask(rbIdx, rbgSize)
22703 U8                rbIdx;
22704 U8                rbgSize;
22705 #endif
22706 {
22707    U8 rbg;
22708    U32 rbgPosInRbgMask = 0;
22709
22710    rbg = rbIdx/rbgSize;
22711    rbgPosInRbgMask = 1 << RG_SCH_CMN_DL_GET_POS_FRM_LSB(rbg);
22712
22713    return (rbgPosInRbgMask);
22714 }
22715
22716 #ifdef RGSCH_SPS_UNUSED
22717 /**
22718  * @brief Determines RA type 1 mask from given RB index.
22719  *
22720  * @details
22721  *
22722  *     Function : rgSCHCmnGetRaType1Mask
22723  *
22724  *
22725  *     Processing Steps:
22726  *     - Determine RA Type 1 mask for given rbIdex and rbg size.
22727  *
22728  *  @param[in]  U8          rbIdx
22729  *  @param[in]  U8          rbgSize
22730  *  @param[out] U8          *type1Subset
22731  *  @return  U32 RA type 1 mask
22732  **/
22733 #ifdef ANSI
22734 PRIVATE U32 rgSCHCmnGetRaType1Mask
22735 (
22736 U8                rbIdx,
22737 U8                rbgSize,
22738 U8                *type1Subset
22739 )
22740 #else
22741 PRIVATE U32 rgSCHCmnGetRaType1Mask(rbIdx, rbgSize, type1Subset)
22742 U8                rbIdx;
22743 U8                rbgSize;
22744 U8                *type1Subset;
22745 #endif
22746 {
22747    U8 rbg, rbgSubset, rbgInSubset, offset, rbInSubset;
22748    U32 rbPosInSubset;
22749
22750    rbg = rbIdx/rbgSize;
22751    rbgSubset = rbg % rbgSize;
22752    rbgInSubset = rbg/rbgSize;
22753    offset = rbIdx % rbgSize;
22754    rbInSubset = rbgInSubset * rbgSize + offset;
22755    rbPosInSubset =  1 << RG_SCH_CMN_DL_GET_POS_FRM_LSB(rbInSubset);
22756
22757    *type1Subset = rbgSubset;
22758    return (rbPosInSubset);
22759
22760 #endif /* RGSCH_SPS_UNUSED */
22761 /**
22762  * @brief Determines RA type 2 mask from given RB index.
22763  *
22764  * @details
22765  *
22766  *     Function : rgSCHCmnGetRaType2Mask
22767  *
22768  *
22769  *     Processing Steps:
22770  *     - Determine RA Type 2 mask for given rbIdx and rbg size.
22771  *
22772  *  @param[in]  U8          rbIdx
22773  *  @param[out] U8          *maskIdx
22774  *  @return  U32 RA type 2 mask
22775  **/
22776 #ifdef ANSI
22777 PRIVATE U32 rgSCHCmnGetRaType2Mask
22778 (
22779 U8                rbIdx,
22780 U8                *maskIdx
22781 )
22782 #else
22783 PRIVATE U32 rgSCHCmnGetRaType2Mask(rbIdx, maskIdx)
22784 U8                rbIdx;
22785 U8                *maskIdx;
22786 #endif
22787 {
22788    U32 rbPosInType2;
22789
22790    *maskIdx = rbIdx / 32;
22791    rbPosInType2 =  1 << RG_SCH_CMN_DL_GET_POS_FRM_LSB(rbIdx % 32);
22792
22793    return (rbPosInType2);
22794 }
22795
22796 /**
22797  * @brief Performs resource allocation for a non-SPS UE in SPS bandwidth
22798  *
22799  * @details
22800  *
22801  *     Function : rgSCHCmnAllocUeInSpsBw
22802  *
22803  *
22804  *     Processing Steps:
22805  *       - Determine allocation for the UE.
22806  *       - Use resource allocation type 0, 1 and 2 for allocation
22807  *         within maximum SPS bandwidth.
22808  *
22809  *  @param[in]  RgSchDlSf       *dlSf
22810  *  @param[in]  RgSchCellCb     *cell
22811  *  @param[in]  RgSchUeCb       *ue
22812  *  @param[in]  RgSchDlRbAlloc  *rbAllocInfo
22813  *  @param[in]  Bool            isPartialAlloc
22814  *  @return  Bool
22815  *             ROK      success
22816  *             RFAILED  failed
22817  **/
22818 #ifdef ANSI
22819 Bool rgSCHCmnAllocUeInSpsBw
22820 (
22821 RgSchDlSf           *dlSf,
22822 RgSchCellCb         *cell,
22823 RgSchUeCb           *ue,
22824 RgSchDlRbAlloc      *rbAllocInfo,
22825 Bool                isPartialAlloc
22826 )
22827 #else
22828 Bool rgSCHCmnAllocUeInSpsBw(dlSf, cell, ue, rbAllocInfo, isPartialAlloc)
22829 RgSchDlSf           *dlSf;
22830 RgSchCellCb         *cell;
22831 RgSchUeCb           *ue;
22832 RgSchDlRbAlloc      *rbAllocInfo;
22833 Bool                isPartialAlloc;
22834 #endif
22835 {
22836    U8                  rbgSize = cell->rbgSize;
22837    U8                  numAllocRbs = 0;
22838    U8                  numAllocRbgs = 0;
22839    U8                  rbStart = 0;
22840    U8                  idx, noLyr, iTbs;
22841    RgSchCmnDlUe        *dlUe = RG_SCH_CMN_GET_DL_UE(ue,cell);
22842    RgSchDlSfAllocInfo  *dlSfAlloc = &rbAllocInfo->dlSf->dlSfAllocInfo;
22843    RgSchBwRbgInfo      *spsRbgInfo = &cell->spsBwRbgInfo;
22844
22845    /* SPS_FIX : Check if this Hq proc is scheduled */
22846    if ((0 == rbAllocInfo->tbInfo[0].schdlngForTb) &&
22847          (0 == rbAllocInfo->tbInfo[1].schdlngForTb))
22848    {
22849       return (TRUE);
22850    }
22851
22852    /* Check if the requirement can be accomodated in SPS BW */
22853    if (dlSf->spsAllocdBw == spsRbgInfo->numRbs)
22854    {
22855       /* SPS Bandwidth has been exhausted: no further allocations possible */
22856       return (FALSE);
22857    }
22858    if (!isPartialAlloc)
22859    {
22860       if((dlSf->spsAllocdBw + rbAllocInfo->rbsReq) > spsRbgInfo->numRbs)
22861       {
22862          return (TRUE);
22863       }
22864    }
22865
22866    /* Perform allocation for RA type 0 if rbsReq is multiple of RBG size (also
22867     * if RBG size = 1) */
22868    if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE0)
22869    {
22870       rbAllocInfo->rbsReq += (rbgSize - rbAllocInfo->rbsReq % rbgSize);
22871       numAllocRbgs = rgSCHCmnDlRaType0Alloc(dlSfAlloc,
22872             rbAllocInfo->rbsReq, spsRbgInfo, &numAllocRbs,
22873             &rbAllocInfo->resAllocInfo, isPartialAlloc);
22874    }
22875 #ifdef RGSCH_SPS_UNUSED
22876    else if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE1)
22877    {
22878       /* If no RBS could be allocated, attempt RA TYPE 1 */
22879
22880       numAllocRbs = rgSCHCmnDlRaType1Alloc(dlSfAlloc,
22881             rbAllocInfo->rbsReq, spsRbgInfo, (U8)dlSfAlloc->nxtRbgSubset,
22882             &rbAllocInfo->allocInfo.raType1.rbgSubset,
22883             &rbAllocInfo->resAllocInfo, isPartialAlloc);
22884
22885       if(numAllocRbs)
22886       {
22887          dlSfAlloc->nxtRbgSubset =
22888             (rbAllocInfo->allocInfo.raType1.rbgSubset + 1 ) % rbgSize;
22889       }
22890    }
22891 #endif
22892    else if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE2)
22893    {
22894       numAllocRbs = rgSCHCmnDlRaType2Alloc(dlSfAlloc,
22895             rbAllocInfo->rbsReq, spsRbgInfo,
22896             &rbStart, &rbAllocInfo->resAllocInfo, isPartialAlloc);
22897    }
22898    if (!numAllocRbs)
22899    {
22900       return (TRUE);
22901    }
22902
22903    if (!(rbAllocInfo->pdcch =
22904             rgSCHCmnPdcchAlloc(cell, ue, dlSf, dlUe->mimoInfo.cwInfo[0].cqi,\
22905                rbAllocInfo->dciFormat, FALSE)))
22906    {
22907       /* Note: Returning TRUE since PDCCH might be available for another UE */
22908       return (TRUE);
22909    }
22910
22911    /* Update Tb info for each scheduled TB */
22912    iTbs = rbAllocInfo->tbInfo[0].iTbs;
22913    noLyr = rbAllocInfo->tbInfo[0].noLyr;
22914    rbAllocInfo->tbInfo[0].bytesAlloc =
22915       rgTbSzTbl[noLyr - 1][iTbs][numAllocRbs - 1]/8;
22916
22917    if (rbAllocInfo->tbInfo[1].schdlngForTb)
22918    {
22919       iTbs = rbAllocInfo->tbInfo[1].iTbs;
22920       noLyr = rbAllocInfo->tbInfo[1].noLyr;
22921       rbAllocInfo->tbInfo[1].bytesAlloc =
22922          rgTbSzTbl[noLyr - 1][iTbs][numAllocRbs - 1]/8;;
22923    }
22924
22925    /* Update rbAllocInfo with the allocation information */
22926    if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE0)
22927    {
22928       rbAllocInfo->allocInfo.raType0.dlAllocBitMask =
22929          rbAllocInfo->resAllocInfo.raType0Mask;
22930       rbAllocInfo->allocInfo.raType0.numDlAlloc = numAllocRbgs;
22931    }
22932 #ifdef RGSCH_SPS_UNUSED
22933    else if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE1)
22934    {
22935       rbAllocInfo->allocInfo.raType1.dlAllocBitMask =
22936          rbAllocInfo->resAllocInfo.raType1Mask[rbAllocInfo->allocInfo.raType1.rbgSubset];
22937       rbAllocInfo->allocInfo.raType1.numDlAlloc = numAllocRbs;
22938       rbAllocInfo->allocInfo.raType1.shift = 0;
22939    }
22940 #endif
22941    else if (rbAllocInfo->raType == RG_SCH_CMN_RA_TYPE2)
22942    {
22943       rbAllocInfo->allocInfo.raType2.isLocal = TRUE;
22944       rbAllocInfo->allocInfo.raType2.rbStart = rbStart;
22945       rbAllocInfo->allocInfo.raType2.numRb = numAllocRbs;
22946    }
22947
22948    rbAllocInfo->rbsAlloc = numAllocRbs;
22949    rbAllocInfo->tbInfo[0].schdlngForTb = TRUE;
22950
22951    /* Update allocation masks for RA types 0, 1 and 2 in DL SF */
22952
22953    /* Update type 0 allocation mask */
22954    dlSfAlloc->raType0Mask |= rbAllocInfo->resAllocInfo.raType0Mask;
22955 #ifdef RGSCH_SPS_UNUSED
22956    /* Update type 1 allocation masks */
22957    for (idx = 0; idx < RG_SCH_NUM_RATYPE1_32BIT_MASK; ++idx)
22958    {
22959       dlSfAlloc->raType1Mask[idx] |= rbAllocInfo->resAllocInfo.raType1Mask[idx];
22960       dlSfAlloc->raType1UsedRbs[idx] +=
22961          rbAllocInfo->resAllocInfo.raType1UsedRbs[idx];
22962    }
22963 #endif
22964    /* Update type 2 allocation masks */
22965    for (idx = 0; idx < RG_SCH_NUM_RATYPE2_32BIT_MASK; ++idx)
22966    {
22967       dlSfAlloc->raType2Mask[idx] |= rbAllocInfo->resAllocInfo.raType2Mask[idx];
22968    }
22969
22970    dlSf->spsAllocdBw += numAllocRbs;
22971    return (TRUE);
22972 }
22973
22974 /***********************************************************
22975  *
22976  *     Func : rgSCHCmnDlGetBestFitHole
22977  *
22978  *
22979  *     Desc : Converts the best fit hole into allocation and returns the
22980  *     allocation information.
22981  *
22982  *
22983  *     Ret  : Void
22984  *
22985  *
22986  *     Notes:
22987  *
22988  *     File :
22989  *
22990  **********************************************************/
22991 #ifdef ANSI
22992 PRIVATE Void rgSCHCmnDlGetBestFitHole
22993 (
22994 U32         *allocMask,
22995 U8          numMaskRbs,
22996 U32         *crntAllocMask,
22997 U8          rbsReq,
22998 U8          *allocStart,
22999 U8          *allocNumRbs,
23000 Bool        isPartialAlloc
23001 )
23002 #else
23003 PRIVATE  Void rgSCHCmnDlGetBestFitHole (allocMask, numMaskRbs,
23004         crntAllocMask, rbsReq, allocStart, allocNumRbs, isPartialAlloc)
23005 U32         *allocMask;
23006 U8          numMaskRbs;
23007 U32         *crntAllocMask;
23008 U8          rbsReq;
23009 U8          *allocStart;
23010 U8          *allocNumRbs;
23011 Bool        isPartialAlloc;
23012 #endif
23013 {
23014    U8 maskSz = (numMaskRbs + 31)/32;
23015    U8 maxMaskPos = (numMaskRbs % 32);
23016    U8 maskIdx, maskPos;
23017    U8 numAvailRbs = 0;
23018    U8 bestAvailNumRbs = 0;
23019    S8 bestStartPos = -1;
23020    S8 startPos = -1;
23021    U32 tmpMask[RG_SCH_NUM_RATYPE2_32BIT_MASK] = {0};
23022    U32 bestMask[RG_SCH_NUM_RATYPE2_32BIT_MASK] = {0};
23023
23024    *allocNumRbs = numAvailRbs;
23025    *allocStart = 0;
23026
23027    for (maskIdx = 0; maskIdx < maskSz; ++maskIdx)
23028    {
23029       maxMaskPos = 31;
23030       if (maskIdx == (maskSz - 1))
23031       {
23032          if (numMaskRbs % 32)
23033          {
23034             maxMaskPos = numMaskRbs % 32;
23035          }
23036       }
23037       for (maskPos = 0; maskPos < maxMaskPos; ++maskPos)
23038       {
23039          if (!(allocMask[maskIdx] & (1 << (31 - maskPos))))
23040          {
23041             tmpMask[maskIdx] |= (1 << (31 - maskPos));
23042             if (startPos == -1)
23043             {
23044                startPos = maskIdx * 32 + maskPos;
23045             }
23046             ++numAvailRbs;
23047             if (numAvailRbs == rbsReq)
23048             {
23049                *allocStart = (U8)startPos;
23050                *allocNumRbs = rbsReq;
23051                break;
23052             }
23053          }
23054          else
23055          {
23056             if (numAvailRbs > bestAvailNumRbs)
23057             {
23058                bestAvailNumRbs = numAvailRbs;
23059                bestStartPos = startPos;
23060                memcpy(bestMask, tmpMask, 4 * sizeof(U32));
23061             }
23062             numAvailRbs = 0;
23063             startPos = -1;
23064             memset(tmpMask, 0, 4 * sizeof(U32));
23065          }
23066       }
23067       if (*allocNumRbs == rbsReq)
23068       {
23069          break;
23070       }
23071    }
23072
23073    if (*allocNumRbs == rbsReq)
23074    {
23075       /* Convert the hole into allocation */
23076       memcpy(crntAllocMask, tmpMask, 4 * sizeof(U32));
23077       RETVOID;
23078    }
23079    else
23080    {
23081       if (bestAvailNumRbs && isPartialAlloc)
23082       {
23083          /* Partial allocation could have been done */
23084          *allocStart = (U8)bestStartPos;
23085          *allocNumRbs = bestAvailNumRbs;
23086          /* Convert the hole into allocation */
23087          memcpy(crntAllocMask, bestMask, 4 * sizeof(U32));
23088       }
23089    }
23090
23091    RETVOID;
23092 }
23093 #endif /* LTEMAC_SPS */
23094
23095 /***************************************************************************
23096  *
23097  * NON-DLFS Allocation functions
23098  *
23099  * *************************************************************************/
23100 #ifndef LTE_TDD
23101 #ifdef DEBUGP
23102 /**
23103  * @brief Function to find out code rate
23104  *
23105  * @details
23106  *
23107  *     Function : rgSCHCmnFindCodeRate
23108  *
23109  *     Processing Steps:
23110  *
23111  *  @param[in]      RgSchCellCb     *cell
23112  *  @param[in]      RgSchDlSf       *dlSf
23113  *  @param[in,out]  RgSchDlRbAlloc  *allocInfo
23114  *  @return  void
23115  **/
23116 #ifdef UNUSED_FUNC
23117 #ifdef ANSI
23118 PRIVATE Void rgSCHCmnFindCodeRate
23119 (
23120 RgSchCellCb           *cell,
23121 RgSchDlSf             *dlSf,
23122 RgSchDlRbAlloc        *allocInfo,
23123 U8                    idx
23124 )
23125 #else
23126 PRIVATE Void rgSCHCmnFindCodeRate(cell,dlSf,allocInfo,idx)
23127 RgSchCellCb           *cell;
23128 RgSchDlSf             *dlSf;
23129 RgSchDlRbAlloc        *allocInfo;
23130 U8                    idx;
23131 #endif
23132 {
23133     RETVOID;
23134
23135 }
23136 #endif
23137
23138 /* Adjust the Imcs and bytes allocated also with respect to the adjusted
23139    RBs - Here we will find out the Imcs by identifying first Highest
23140    number of bits compared to the original bytes allocated.  */
23141 /**
23142  * @brief Adjust IMCS according to tbSize and ITBS
23143  *
23144  * @details
23145  *
23146  *     Function : rgSCHCmnNonDlfsPbchTbImcsAdj
23147  *
23148  *     Processing Steps:
23149  *      - Adjust Imcs according to tbSize and ITBS.
23150  *
23151  *  @param[in,out]  RgSchDlRbAlloc  *allocInfo
23152  *  @param[in]      U8              *idx
23153  *  @return  void
23154  **/
23155 #ifdef ANSI
23156 PRIVATE Void rgSCHCmnNonDlfsPbchTbImcsAdj
23157 (
23158 RgSchCellCb      *cell,
23159 RgSchDlRbAlloc   *allocInfo,
23160 U8               idx,
23161 U8               rbsReq
23162 )
23163 #else
23164 PRIVATE Void rgSCHCmnNonDlfsPbchTbImcsAdj(cell,allocInfo, idx, rbsReq)
23165 RgSchCellCb      *cell;
23166 RgSchDlRbAlloc   *allocInfo;
23167 U8               idx;
23168 U8               rbsReq;
23169 #endif
23170 {
23171    U8             noLyrs = 0;
23172    U8             tbs = 0;
23173    U32            origBytesReq;
23174    U8             noRbgs = 0;
23175    U8             noRbs = 0;
23176    RgSchDlSf     *dlSf = allocInfo->dlSf;
23177
23178    RG_SCH_CMN_DL_MCS_TO_TBS(allocInfo->tbInfo[idx].imcs, tbs);
23179    noLyrs = allocInfo->tbInfo[idx].noLyr;
23180
23181    if((allocInfo->raType == RG_SCH_CMN_RA_TYPE0))
23182    {
23183       noRbgs = RGSCH_CEIL((allocInfo->rbsReq + dlSf->lstRbgDfct), cell->rbgSize);
23184       noRbs = (noRbgs * cell->rbgSize) - dlSf->lstRbgDfct;
23185    }
23186    else
23187    {
23188        noRbs = allocInfo->rbsReq;
23189    }
23190
23191    /* This line will help in case if tbs is zero and reduction in MCS is not possible */
23192    if (allocInfo->rbsReq == 0 )
23193    {
23194       RETVOID;
23195    }
23196    origBytesReq = rgTbSzTbl[noLyrs - 1][tbs][rbsReq - 1]/8;
23197
23198    /* Find out the ITbs & Imcs by identifying first Highest
23199       number of bits compared to the original bytes allocated.*/
23200    if(tbs > 0)
23201    {
23202       if(((rgTbSzTbl[noLyrs - 1][0][noRbs - 1])/8) < origBytesReq)
23203       {
23204           RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgTbSzTbl[noLyrs - 1], tbs);
23205           while(((rgTbSzTbl[noLyrs - 1][tbs][noRbs - 1])/8) > origBytesReq)
23206           {
23207               tbs--;
23208           }
23209       }
23210       else
23211       {
23212           tbs = 0;
23213       }
23214       allocInfo->tbInfo[idx].bytesReq = rgTbSzTbl[noLyrs - 1][tbs][noRbs - 1]/8;
23215       allocInfo->tbInfo[idx].iTbs = tbs;
23216       RG_SCH_CMN_DL_TBS_TO_MCS(tbs,allocInfo->tbInfo[idx].imcs);
23217    }
23218
23219    RETVOID;
23220 }
23221 /* Added funcion to adjust TBSize*/
23222 /**
23223  * @brief Function to adjust the tbsize in case of subframe 0 & 5 when
23224  * we were not able to do RB alloc adjustment by adding extra required Rbs
23225  *
23226  * @details
23227  *
23228  *     Function : rgSCHCmnNonDlfsPbchTbSizeAdj
23229  *
23230  *     Processing Steps:
23231  *
23232  *  @param[in,out]  RgSchDlRbAlloc  *allocInfo
23233  *  @param[in]      U8            numOvrlapgPbchRb
23234  *  @param[in]      U8            idx
23235  *  @param[in]      U8            pbchSsRsSym
23236  *  @return  void
23237  **/
23238 #ifdef ANSI
23239 PRIVATE Void rgSCHCmnNonDlfsPbchTbSizeAdj
23240 (
23241 RgSchDlRbAlloc        *allocInfo,
23242 U8                    numOvrlapgPbchRb,
23243 U8                    pbchSsRsSym,
23244 U8                    idx,
23245 U32                   bytesReq
23246 )
23247 #else
23248 PRIVATE Void rgSCHCmnNonDlfsPbchTbSizeAdj(allocInfo,numOvrlapgPbchRb,pbchSsRsSym,idx,bytesReq)
23249 RgSchDlRbAlloc        *allocInfo;
23250 U8                    numOvrlapgPbchRb;
23251 U8                    pbchSsRsSym;
23252 U8                    idx;
23253 U32                   bytesReq;
23254 #endif
23255 {
23256    U32             reducedTbs = 0;
23257    U8              noLyrs = 0;
23258    U8              tbs = 0;
23259
23260    noLyrs = allocInfo->tbInfo[idx].noLyr;
23261
23262    RG_SCH_CMN_DL_MCS_TO_TBS(allocInfo->tbInfo[idx].imcs, tbs);
23263
23264    reducedTbs = bytesReq - (((U32)numOvrlapgPbchRb * (U32)pbchSsRsSym * 6)/8);
23265
23266    /* find out the ITbs & Imcs by identifying first Highest
23267     number of bits compared with reduced bits considering the bits that are
23268     reserved for PBCH/PSS/SSS */
23269    if(((rgTbSzTbl[noLyrs - 1][0][allocInfo->rbsReq - 1])/8) < reducedTbs)
23270    {
23271        while(((rgTbSzTbl[noLyrs - 1][tbs][allocInfo->rbsReq - 1])/8) > reducedTbs)
23272        {
23273            tbs--;
23274        }
23275    }
23276    else
23277    {
23278        tbs = 0;
23279    }
23280    allocInfo->tbInfo[idx].bytesReq = rgTbSzTbl[noLyrs - 1][tbs][allocInfo->rbsReq - 1]/8;
23281    allocInfo->tbInfo[idx].iTbs = tbs;
23282    RG_SCH_CMN_DL_TBS_TO_MCS(tbs,allocInfo->tbInfo[idx].imcs);
23283
23284    RETVOID;
23285 }
23286
23287 /* Added this function to find num of ovrlapping PBCH rb*/
23288 /**
23289  * @brief Function to find out how many additional rbs are available
23290  *    in the entire bw which can be allocated to a UE
23291  * @details
23292  *
23293  *     Function : rgSCHCmnFindNumAddtlRbsAvl
23294  *
23295  *     Processing Steps:
23296  *      - Calculates number of additinal rbs available
23297  *
23298  *  @param[in]      RgSchCellCb     *cell
23299  *  @param[in]      RgSchDlSf       *dlSf
23300  *  @param[in,out]  RgSchDlRbAlloc  *allocInfo
23301  *  @param[out]      U8            addtlRbsAvl
23302  *  @return  void
23303  **/
23304 #ifdef ANSI
23305 PRIVATE U8 rgSCHCmnFindNumAddtlRbsAvl
23306 (
23307 RgSchCellCb           *cell,
23308 RgSchDlSf             *dlSf,
23309 RgSchDlRbAlloc        *allocInfo
23310 )
23311 #else
23312 PRIVATE U8 rgSCHCmnFindNumAddtlRbsAvl(cell,dlSf,allocInfo)
23313 RgSchCellCb           *cell;
23314 RgSchDlSf             *dlSf;
23315 RgSchDlRbAlloc        *allocInfo;
23316 #endif
23317 {
23318     U8 addtlRbsAvl = 0;
23319
23320
23321     if (allocInfo->raType == RG_SCH_CMN_RA_TYPE0)
23322     {
23323          addtlRbsAvl = (((dlSf->type0End - dlSf->type2End + 1)*\
23324                         cell->rbgSize) - dlSf->lstRbgDfct) - allocInfo->rbsReq;
23325     }
23326     else if (allocInfo->raType == RG_SCH_CMN_RA_TYPE2)
23327     {
23328        addtlRbsAvl = (dlSf->bw - dlSf->bwAlloced) - allocInfo->rbsReq;
23329     }
23330
23331     return (addtlRbsAvl);
23332
23333 }
23334 /* Added this function to find num of ovrlapping PBCH rb*/
23335 /**
23336  * @brief Function to find out how many of the requested RBs are
23337  *        falling in the center 6 RBs of the downlink bandwidth.
23338  * @details
23339  *
23340  *     Function : rgSCHCmnFindNumPbchOvrlapRbs
23341  *
23342  *     Processing Steps:
23343  *      - Calculates number of overlapping rbs
23344  *
23345  *  @param[in]      RgSchCellCb     *cell
23346  *  @param[in]      RgSchDlSf       *dlSf
23347  *  @param[in,out]  RgSchDlRbAlloc  *allocInfo
23348  *  @param[out]      U8*            numOvrlapgPbchRb
23349  *  @return  void
23350  **/
23351 #ifdef ANSI
23352 PRIVATE Void rgSCHCmnFindNumPbchOvrlapRbs
23353 (
23354 RgSchCellCb           *cell,
23355 RgSchDlSf             *dlSf,
23356 RgSchDlRbAlloc        *allocInfo,
23357 U8                    *numOvrlapgPbchRb
23358 )
23359 #else
23360 PRIVATE Void rgSCHCmnFindNumPbchOvrlapRbs(cell,dlSf,allocInfo,numOvrlapgPbchRb)
23361 RgSchCellCb           *cell;
23362 RgSchDlSf             *dlSf;
23363 RgSchDlRbAlloc        *allocInfo;
23364 U8                    *numOvrlapgPbchRb;
23365 #endif
23366 {
23367     *numOvrlapgPbchRb = 0;
23368    /*Find if we have already crossed the start boundary for PBCH 6 RBs,
23369     * if yes then lets find the number of RBs which are getting overlapped
23370     * with this allocation.*/
23371    if(dlSf->bwAlloced <= (cell->pbchRbStart))
23372    {
23373       /*We have not crossed the start boundary of PBCH RBs. Now we need
23374        * to know that if take this allocation then how much PBCH RBs
23375        * are overlapping with this allocation.*/
23376       /* Find out the overlapping RBs in the centre 6 RBs */
23377        if((dlSf->bwAlloced + allocInfo->rbsReq) > cell->pbchRbStart)
23378        {
23379            *numOvrlapgPbchRb = (dlSf->bwAlloced + allocInfo->rbsReq) - (cell->pbchRbStart);
23380            if(*numOvrlapgPbchRb > 6)
23381                 *numOvrlapgPbchRb = 6;
23382        }
23383    }
23384    else if ((dlSf->bwAlloced > (cell->pbchRbStart)) &&
23385          (dlSf->bwAlloced < (cell->pbchRbEnd)))
23386    {
23387       /*We have already crossed the start boundary of PBCH RBs.We need to
23388        * find that if we take this allocation then how much of the RBs for
23389        * this allocation will overlap with PBCH RBs.*/
23390       /* Find out the overlapping RBs in the centre 6 RBs */
23391       if(dlSf->bwAlloced + allocInfo->rbsReq < (cell->pbchRbEnd))
23392       {
23393          /*If we take this allocation then also we are not crossing the
23394           * end boundary of PBCH 6 RBs.*/
23395          *numOvrlapgPbchRb = allocInfo->rbsReq;
23396       }
23397       else
23398       {
23399          /*If we take this allocation then we are crossing the
23400           * end boundary of PBCH 6 RBs.*/
23401          *numOvrlapgPbchRb = (cell->pbchRbEnd) - dlSf->bwAlloced;
23402       }
23403    }
23404     RETVOID;
23405
23406 }
23407 /**
23408  * @brief Performs RB allocation adjustment if the requested RBs are
23409  *        falling in the center 6 RBs of the downlink bandwidth.
23410  * @details
23411  *
23412  *     Function : rgSCHCmnNonDlfsPbchRbAllocAdj
23413  *
23414  *     Processing Steps:
23415  *      - Allocate consecutively available RBs.
23416  *
23417  *  @param[in]      RgSchCellCb     *cell
23418  *  @param[in,out]  RgSchDlRbAlloc  *allocInfo
23419  *  @param[in]      U8               pbchSsRsSym
23420  *  @return  void
23421  **/
23422 #ifdef ANSI
23423 PRIVATE Void rgSCHCmnNonDlfsPbchRbAllocAdj
23424 (
23425 RgSchCellCb      *cell,
23426 RgSchDlRbAlloc   *allocInfo,
23427 U8               pbchSsRsSym,
23428 Bool             isBcchPcch
23429 )
23430 #else
23431 PRIVATE Void rgSCHCmnNonDlfsPbchRbAllocAdj(cell, allocInfo,pbchSsRsSym)
23432 RgSchCellCb      *cell;
23433 RgSchDlRbAlloc   *allocInfo;
23434 U8               pbchSsRsSym;
23435 Bool             isBcchPcch;
23436 #endif
23437 {
23438    RgSchDlSf     *dlSf = allocInfo->dlSf;
23439    U8             numOvrlapgPbchRb = 0;
23440    U8             numOvrlapgAdtlPbchRb = 0;
23441    U8             totSym;
23442    U8             addtlRbsReq = 0;
23443    U8             moreAddtlRbsReq = 0;
23444    U8             addtlRbsAdd = 0;
23445    U8             moreAddtlRbsAdd = 0;
23446    U8             tbs;
23447    U8             origRbsReq = 0;
23448    U32            bytesReq;
23449    U8             noLyr;
23450    U8             divResult;
23451
23452
23453
23454
23455    origRbsReq = allocInfo->rbsReq;
23456    rgSCHCmnFindNumPbchOvrlapRbs(cell,dlSf,allocInfo,&numOvrlapgPbchRb);
23457
23458   totSym =  (cell->isCpDlExtend) ? RGSCH_TOT_NUM_SYM_EXTCP : RGSCH_TOT_NUM_SYM_NORCP;
23459
23460    /* Additional RBs are allocated by considering the loss due to
23461       the reserved symbols for CFICH, PBCH, PSS, SSS and cell specific RS */
23462
23463    divResult = (numOvrlapgPbchRb * pbchSsRsSym)/totSym;
23464    if((numOvrlapgPbchRb * pbchSsRsSym) % totSym)
23465    {
23466       divResult++;
23467    }
23468    addtlRbsReq = divResult;
23469
23470    RG_SCH_CMN_UPD_RBS_TO_ADD(cell, dlSf, allocInfo, addtlRbsReq, addtlRbsAdd)
23471
23472    /*Now RBs requires is original requested RBs + these additional RBs to make
23473     * up for PSS/SSS/BCCH.*/
23474    allocInfo->rbsReq = allocInfo->rbsReq + addtlRbsAdd;
23475
23476    /*Check if with these additional RBs we have taken up, these are also falling
23477     * under PBCH RBs range, if yes then we would need to account for
23478     * PSS/BSS/BCCH for these additional RBs too.*/
23479    if(addtlRbsAdd && ((dlSf->bwAlloced + allocInfo->rbsReq - addtlRbsAdd) < (cell->pbchRbEnd)))
23480    {
23481       if((dlSf->bwAlloced + allocInfo->rbsReq) <= (cell->pbchRbEnd))
23482       {
23483       /*With additional RBs taken into account, we are not crossing the
23484        * PBCH RB end boundary.Thus here we need to account just for
23485        * overlapping PBCH RBs for these additonal RBs.*/
23486           divResult = (addtlRbsAdd * pbchSsRsSym)/totSym;
23487           if((addtlRbsAdd * pbchSsRsSym) % totSym)
23488           {
23489             divResult++;
23490           }
23491
23492           moreAddtlRbsReq = divResult;
23493
23494           RG_SCH_CMN_UPD_RBS_TO_ADD(cell, dlSf, allocInfo, moreAddtlRbsReq, moreAddtlRbsAdd)
23495
23496           allocInfo->rbsReq = allocInfo->rbsReq + moreAddtlRbsAdd;
23497       }
23498       else
23499       {
23500
23501          /*Here we have crossed the PBCH RB end boundary, thus we need to take
23502           * into account the overlapping RBs for additional RBs which will be
23503           * subset of addtlRbs.*/
23504           numOvrlapgAdtlPbchRb = (cell->pbchRbEnd) - ((dlSf->bwAlloced + allocInfo->rbsReq) -  addtlRbsAdd);
23505
23506           divResult = (numOvrlapgAdtlPbchRb * pbchSsRsSym)/totSym;
23507           if((numOvrlapgAdtlPbchRb * pbchSsRsSym) % totSym)
23508           {
23509              divResult++;
23510           }
23511
23512           moreAddtlRbsReq =  divResult;
23513
23514           RG_SCH_CMN_UPD_RBS_TO_ADD(cell, dlSf, allocInfo, moreAddtlRbsReq, moreAddtlRbsAdd)
23515
23516           allocInfo->rbsReq = allocInfo->rbsReq + moreAddtlRbsAdd;
23517       }
23518    }
23519    if (isBcchPcch == TRUE)
23520    {
23521       RETVOID;
23522    }
23523
23524    RG_SCH_CMN_DL_MCS_TO_TBS(allocInfo->tbInfo[0].imcs, tbs);
23525    if(tbs == 6)
23526    {
23527       /* This case might be for Imcs value 6 and NPrb = 1 case  - Not
23528          Adjusting either RBs or Imcs or Bytes Allocated */
23529       allocInfo->rbsReq = allocInfo->rbsReq - addtlRbsAdd - moreAddtlRbsAdd;
23530    }
23531    else if(tbs && ((0 == addtlRbsAdd) && (moreAddtlRbsAdd == 0)))
23532    {
23533        /*In case of a situation where we the entire bandwidth is already occupied
23534         * and we dont have room to add additional Rbs then in order to decrease the
23535         * code rate we reduce the tbsize such that we reduce the present calculated
23536         * tbsize by number of bytes that would be occupied by PBCH/PSS/SSS in overlapping
23537         * rbs and find the nearest tbsize which would be less than this deduced value*/
23538
23539       rgSCHCmnFindNumPbchOvrlapRbs(cell,dlSf,allocInfo,&numOvrlapgPbchRb);
23540
23541       noLyr = allocInfo->tbInfo[0].noLyr;
23542       RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgTbSzTbl[noLyr - 1], tbs);
23543       bytesReq = rgTbSzTbl[noLyr - 1][tbs][allocInfo->rbsReq - 1]/8;
23544
23545       rgSCHCmnNonDlfsPbchTbSizeAdj(allocInfo,numOvrlapgPbchRb,pbchSsRsSym,0,bytesReq);
23546
23547       if(allocInfo->tbInfo[1].schdlngForTb == TRUE)
23548       {
23549           noLyr = allocInfo->tbInfo[1].noLyr;
23550           bytesReq = rgTbSzTbl[noLyr - 1][tbs][allocInfo->rbsReq - 1]/8;
23551           rgSCHCmnNonDlfsPbchTbSizeAdj(allocInfo,numOvrlapgPbchRb,pbchSsRsSym,1,bytesReq);
23552       }
23553
23554    }
23555    else if(tbs && ((addtlRbsAdd != addtlRbsReq) ||
23556           (addtlRbsAdd && (moreAddtlRbsReq != moreAddtlRbsAdd))))
23557    {
23558        /*In case of a situation where we were not able to add required number of
23559         * additional RBs then we adjust the Imcs based on original RBs requested.
23560         * Doing this would comensate for the few extra Rbs we have added but inorder
23561         * to comensate for number of RBS we couldnt add we again do the TBSize adjustment*/
23562
23563       rgSCHCmnNonDlfsPbchTbImcsAdj(cell, allocInfo, 0 , origRbsReq);
23564
23565       if(allocInfo->tbInfo[1].schdlngForTb == TRUE)
23566       {
23567           rgSCHCmnNonDlfsPbchTbImcsAdj(cell, allocInfo, 1 , origRbsReq);
23568       }
23569
23570       rgSCHCmnFindNumPbchOvrlapRbs(cell,dlSf,allocInfo,&numOvrlapgPbchRb);
23571       numOvrlapgPbchRb = numOvrlapgPbchRb - (addtlRbsAdd + moreAddtlRbsAdd);
23572
23573       rgSCHCmnNonDlfsPbchTbSizeAdj(allocInfo,numOvrlapgPbchRb,pbchSsRsSym,0,allocInfo->tbInfo[0].bytesReq);
23574
23575       if(allocInfo->tbInfo[1].schdlngForTb == TRUE)
23576       {
23577           rgSCHCmnNonDlfsPbchTbSizeAdj(allocInfo,numOvrlapgPbchRb,pbchSsRsSym,1,allocInfo->tbInfo[1].bytesReq);
23578       }
23579
23580    }
23581    else
23582    {
23583        /*We hit this code when we were able to add the required additional RBS
23584         * hence we should adjust the IMcs based on orignals RBs requested*/
23585
23586       rgSCHCmnNonDlfsPbchTbImcsAdj(cell, allocInfo, 0 , origRbsReq);
23587
23588       if(allocInfo->tbInfo[1].schdlngForTb == TRUE)
23589       {
23590           rgSCHCmnNonDlfsPbchTbImcsAdj(cell, allocInfo, 1 , origRbsReq);
23591       }
23592    }
23593
23594    RETVOID;
23595 } /* end of rgSCHCmnNonDlfsPbchRbAllocAdj */
23596 #endif
23597 #endif
23598 /**
23599  * @brief Performs RB allocation for frequency non-selective cell.
23600  *
23601  * @details
23602  *
23603  *     Function : rgSCHCmnNonDlfsCmnRbAlloc
23604  *
23605  *     Processing Steps:
23606  *      - Allocate consecutively available RBs for BCCH/PCCH/RAR.
23607  *
23608  *  @param[in]      RgSchCellCb     *cell
23609  *  @param[in, out] RgSchDlRbAlloc  *allocInfo
23610  *  @return  S16
23611  *      -# ROK
23612  *      -# RFAILED
23613  **/
23614 #ifdef ANSI
23615 PRIVATE S16 rgSCHCmnNonDlfsCmnRbAlloc
23616 (
23617 RgSchCellCb      *cell,
23618 RgSchDlRbAlloc   *allocInfo
23619 )
23620 #else
23621 PRIVATE S16 rgSCHCmnNonDlfsCmnRbAlloc(cell, allocInfo)
23622 RgSchCellCb      *cell;
23623 RgSchDlRbAlloc   *allocInfo;
23624 #endif
23625 {
23626 #ifndef LTE_TDD
23627 #ifdef LTEMAC_SPS
23628 #endif
23629    U8 pbchSsRsSym = 0;
23630    U8 pbchFrame = 0;
23631    U8  tbs = 0;
23632    RgSchCmnDlCell   *cellDl    = RG_SCH_CMN_GET_DL_CELL(cell); 
23633 #endif
23634    RgSchDlSf     *dlSf   = allocInfo->dlSf;
23635 #ifdef LTEMAC_SPS
23636    U8                  rbStart = 0;
23637    U8                  spsRbsAlloc = 0;
23638    RgSchDlSfAllocInfo  *dlSfAlloc = &allocInfo->dlSf->dlSfAllocInfo;
23639 #endif
23640
23641    allocInfo->tbInfo[0].noLyr = 1;
23642
23643 #ifdef LTEMAC_SPS
23644    /* Note: Initialize the masks to 0, this might not be needed since alloInfo
23645     * is initialized to 0 at the beginning of allcoation */
23646    allocInfo->resAllocInfo.raType0Mask = 0;
23647    memset(allocInfo->resAllocInfo.raType1Mask, 0,
23648          RG_SCH_NUM_RATYPE1_32BIT_MASK * sizeof (U32));
23649    memset(allocInfo->resAllocInfo.raType2Mask, 0,
23650          RG_SCH_NUM_RATYPE2_32BIT_MASK * sizeof (U32));
23651
23652    if ((dlSf->spsAllocdBw >= cell->spsBwRbgInfo.numRbs) &&
23653          (dlSf->bwAlloced == dlSf->bw))
23654 #else
23655    if(dlSf->bwAlloced == dlSf->bw)
23656 #endif
23657    {
23658       return RFAILED;
23659    }
23660 #ifndef LTE_TDD
23661    if (allocInfo->rbsReq > (dlSf->bw - dlSf->bwAlloced))
23662    {
23663 #ifdef LTEMAC_SPS
23664       if ((allocInfo->tbInfo[0].imcs < 29) && (dlSf->bwAlloced < dlSf->bw))
23665 #else
23666       if(allocInfo->tbInfo[0].imcs < 29)
23667 #endif
23668       {
23669          /* set the remaining RBs for the requested UE */
23670          allocInfo->rbsReq = dlSf->bw - dlSf->bwAlloced;
23671          RG_SCH_CMN_DL_MCS_TO_TBS(allocInfo->tbInfo[0].imcs, tbs);
23672          allocInfo->tbInfo[0].bytesReq = rgTbSzTbl[0][tbs][allocInfo->rbsReq - 1]/8;
23673       }
23674       else
23675       {
23676 #ifdef LTEMAC_SPS
23677          /* Attempt RA Type 2 allocation in SPS Bandwidth */
23678          if (dlSf->spsAllocdBw < cell->spsBwRbgInfo.numRbs) 
23679          {
23680             spsRbsAlloc =
23681                rgSCHCmnDlRaType2Alloc(dlSfAlloc,
23682                      allocInfo->rbsReq, &cell->spsBwRbgInfo, &rbStart,
23683                      &allocInfo->resAllocInfo, FALSE);
23684             /* rbsAlloc assignment moved from line 16671 to here to avoid
23685              * compilation error. Recheck */
23686             dlSf->spsAllocdBw += spsRbsAlloc;
23687          }
23688          if (!spsRbsAlloc)
23689 #endif /* LTEMAC_SPS */
23690          {
23691             return RFAILED;
23692          }
23693       }
23694    }
23695 #endif
23696
23697    /* Update allocation information */
23698    allocInfo->pdcch = rgSCHCmnCmnPdcchAlloc(cell, dlSf);
23699    if (allocInfo->pdcch == NULLP)
23700    {
23701       return RFAILED;
23702    }
23703    allocInfo->dciFormat = TFU_DCI_FORMAT_1A;
23704    allocInfo->pdcch->dciNumOfBits = cell->dciSize.size[TFU_DCI_FORMAT_1A];
23705    allocInfo->raType = RG_SCH_CMN_RA_TYPE2;
23706    allocInfo->allocInfo.raType2.isLocal = TRUE;
23707 #ifdef LTEMAC_SPS
23708    if (spsRbsAlloc) 
23709    {
23710       allocInfo->allocInfo.raType2.rbStart = rbStart;
23711       allocInfo->allocInfo.raType2.numRb = allocInfo->rbsReq;
23712       allocInfo->rbsAlloc = allocInfo->rbsReq;
23713    }
23714 #endif
23715
23716 #ifdef LTEMAC_SPS
23717    if (!spsRbsAlloc)
23718    {
23719 #endif
23720 #ifndef LTE_TDD
23721       if(dlSf->sfNum)
23722       {
23723          if(!(dlSf->sfNum == 5))
23724          {
23725             /* case for subframes 1 to 9 except 5 */
23726 #ifdef LTEMAC_SPS
23727             allocInfo->allocInfo.raType2.rbStart = rbStart;
23728 #else
23729             /*Fix for ccpu00123918*/
23730             allocInfo->allocInfo.raType2.rbStart = (U8)dlSf->type2Start;
23731 #endif
23732          }
23733          else
23734          {
23735             pbchFrame = 1; /* case for subframe 5 */
23736             /* In subframe 5, symbols are reserved for PSS and SSS and CFICH
23737                and Cell Specific Reference Signals */
23738             pbchSsRsSym = (((cellDl->currCfi) + RGSCH_NUM_PSS_SSS_SYM) *
23739                   RGSCH_NUM_SC_IN_RB + cell->numCellRSPerSf);
23740          }
23741       }
23742       else
23743       {
23744          pbchFrame = 1;
23745          /* In subframe 0, symbols are reserved for PSS, SSS, PBCH, CFICH and
23746             and Cell Specific Reference signals */
23747          pbchSsRsSym = (((cellDl->currCfi) + RGSCH_NUM_PBCH_SYM +
23748                   RGSCH_NUM_PSS_SSS_SYM) * RGSCH_NUM_SC_IN_RB +
23749                cell->numCellRSPerSf);
23750       } /* end of outer else */
23751
23752       if((pbchFrame) &&
23753             (((dlSf->bwAlloced + allocInfo->rbsReq) - cell->pbchRbStart) > 0)&&
23754             (dlSf->bwAlloced < cell->pbchRbEnd))
23755       {
23756          if(allocInfo->tbInfo[0].imcs < 29)
23757          {
23758             rgSCHCmnNonDlfsPbchRbAllocAdj(cell, allocInfo, pbchSsRsSym, TRUE);
23759          }
23760       }
23761 #endif
23762 #ifdef LTEMAC_SPS
23763    }
23764 #endif
23765
23766 #ifdef LTEMAC_SPS
23767    if (!spsRbsAlloc)
23768    {  
23769 #endif
23770       /*Fix for ccpu00123918*/
23771       allocInfo->allocInfo.raType2.rbStart = (U8)dlSf->type2Start;
23772       allocInfo->allocInfo.raType2.numRb = allocInfo->rbsReq;
23773       allocInfo->rbsAlloc = allocInfo->rbsReq;
23774
23775       /* LTE_ADV_FLAG_REMOVED_START */
23776 #ifndef LTE_TDD
23777       if (cell->lteAdvCb.sfrCfg.status == RGR_ENABLE)
23778       {
23779          rgSCHCmnNonDlfsSFRCmnChannelUpdTyp2Alloc(cell, dlSf, \
23780                allocInfo->allocInfo.raType2.rbStart, \
23781                allocInfo->allocInfo.raType2.numRb);
23782       }
23783       else
23784 #endif
23785       {
23786          rgSCHCmnNonDlfsUpdTyp2Alloc(cell, dlSf, \
23787                allocInfo->allocInfo.raType2.rbStart, \
23788                allocInfo->allocInfo.raType2.numRb);
23789       }
23790
23791 #ifdef LTEMAC_SPS
23792    }
23793 #endif
23794    /* LTE_ADV_FLAG_REMOVED_END */
23795    allocInfo->tbInfo[0].bytesAlloc = allocInfo->tbInfo[0].bytesReq;
23796
23797
23798 #ifdef LTEMAC_SPS
23799    if (spsRbsAlloc)
23800    {
23801       U8    idx;
23802       /* Update type 0, 1 and 2 masks */
23803       dlSfAlloc->raType0Mask    |= allocInfo->resAllocInfo.raType0Mask;
23804 #ifdef RGSCH_SPS_UNUSED
23805       for (idx = 0; idx < RG_SCH_NUM_RATYPE1_32BIT_MASK; ++idx)
23806       {
23807          dlSfAlloc->raType1Mask[idx] |=
23808             allocInfo->resAllocInfo.raType1Mask[idx];
23809          dlSfAlloc->raType1UsedRbs[idx] +=
23810             allocInfo->resAllocInfo.raType1UsedRbs[idx];
23811       }
23812 #endif
23813       for (idx = 0; idx < RG_SCH_NUM_RATYPE2_32BIT_MASK; ++idx)
23814       {
23815          dlSfAlloc->raType2Mask[idx] |=
23816             allocInfo->resAllocInfo.raType2Mask[idx];
23817       }
23818    }
23819 #endif
23820
23821    return ROK;
23822 }
23823
23824
23825 /**
23826  * @brief Performs RB allocation for frequency non-selective cell.
23827  *
23828  * @details
23829  *
23830  *     Function : rgSCHCmnNonDlfsCmnRbAllocRar
23831  *
23832  *     Processing Steps:
23833  *      - Allocate consecutively available RBs for BCCH/PCCH/RAR.
23834  *
23835  *  @param[in]      RgSchCellCb     *cell
23836  *  @param[in, out] RgSchDlRbAlloc  *allocInfo
23837  *  @return  S16
23838  *      -# ROK
23839  *      -# RFAILED
23840  **/
23841 #ifdef ANSI
23842 PRIVATE S16 rgSCHCmnNonDlfsCmnRbAllocRar
23843 (
23844  RgSchCellCb      *cell,
23845  RgSchDlRbAlloc   *allocInfo
23846  )
23847 #else
23848 PRIVATE S16 rgSCHCmnNonDlfsCmnRbAlloc(cell, allocInfo)
23849    RgSchCellCb      *cell;
23850    RgSchDlRbAlloc   *allocInfo;
23851 #endif
23852 {
23853    RgSchDlSf     *dlSf   = allocInfo->dlSf;
23854
23855
23856    if(dlSf->bwAlloced == dlSf->bw)
23857    {
23858       return RFAILED;
23859    }
23860
23861    allocInfo->tbInfo[0].noLyr = 1;
23862 #ifndef RG_5GTF
23863    /* Update allocation information */
23864    allocInfo->pdcch = rgSCHCmnCmnPdcchAlloc(cell, dlSf);
23865    if (allocInfo->pdcch == NULLP)
23866    {
23867       return RFAILED;
23868    }
23869    allocInfo->dciFormat = TFU_DCI_FORMAT_1A;
23870    allocInfo->pdcch->dciNumOfBits = cell->dciSize.size[TFU_DCI_FORMAT_1A];
23871    allocInfo->raType = RG_SCH_CMN_RA_TYPE2;
23872    allocInfo->allocInfo.raType2.isLocal = TRUE;
23873
23874    /*Fix for ccpu00123918*/
23875    allocInfo->allocInfo.raType2.rbStart = (U8)dlSf->type2Start;
23876    allocInfo->allocInfo.raType2.numRb = allocInfo->rbsReq;
23877    allocInfo->rbsAlloc = allocInfo->rbsReq;
23878
23879    /* LTE_ADV_FLAG_REMOVED_END */
23880    allocInfo->tbInfo[0].bytesAlloc = allocInfo->tbInfo[0].bytesReq;
23881
23882 #else
23883    allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, NULLP, dlSf, 13, TFU_DCI_FORMAT_B1, FALSE);
23884    if (allocInfo->pdcch == NULLP)
23885    {
23886       return RFAILED;
23887    }
23888    RgSchSfBeamInfo  *beamInfo = &(dlSf->sfBeamInfo[0]);
23889    if(beamInfo->totVrbgAllocated > MAX_5GTF_VRBG)
23890    {
23891       printf("5GTF_ERROR vrbg allocated > 25\n");
23892       return RFAILED;
23893    }
23894
23895    allocInfo->tbInfo[0].cmnGrnt.vrbgStart = beamInfo->vrbgStart;
23896    allocInfo->tbInfo[0].cmnGrnt.numVrbg = allocInfo->vrbgReq;
23897
23898    /* Update allocation information */
23899    allocInfo->dciFormat = TFU_DCI_FORMAT_B1;
23900
23901    allocInfo->tbInfo[0].cmnGrnt.xPDSCHRange = 1;  
23902    allocInfo->tbInfo[0].cmnGrnt.rbAssign = rgSCHCmnCalcRiv(MAX_5GTF_VRBG, 
23903          allocInfo->tbInfo[0].cmnGrnt.vrbgStart, allocInfo->tbInfo[0].cmnGrnt.numVrbg);
23904
23905    allocInfo->tbInfo[0].cmnGrnt.rbStrt = (allocInfo->tbInfo[0].cmnGrnt.vrbgStart * MAX_5GTF_VRBG_SIZE);
23906    allocInfo->tbInfo[0].cmnGrnt.numRb = (allocInfo->tbInfo[0].cmnGrnt.numVrbg * MAX_5GTF_VRBG_SIZE);
23907
23908    beamInfo->vrbgStart += allocInfo->tbInfo[0].cmnGrnt.numVrbg;
23909    beamInfo->totVrbgAllocated += allocInfo->tbInfo[0].cmnGrnt.numVrbg;
23910    allocInfo->tbInfo[0].cmnGrnt.rv = 0;
23911    allocInfo->tbInfo[0].bytesAlloc = allocInfo->tbInfo[0].bytesReq;
23912
23913 #endif
23914    printf("\n[%s],allocInfo->tbInfo[0].bytesAlloc:%u,vrbgReq:%u\n",
23915          __func__,allocInfo->tbInfo[0].bytesAlloc,allocInfo->vrbgReq);
23916
23917    return ROK;
23918 }
23919
23920
23921 /* LTE_ADV_FLAG_REMOVED_START */
23922 #ifndef LTE_TDD
23923 /**
23924  * @brief To check if DL BW available for non-DLFS allocation.
23925  *
23926  * @details
23927  *
23928  *     Function : rgSCHCmnNonDlfsBwAvlbl
23929  *
23930  *     Processing Steps:
23931  *      - Determine availability based on RA Type.
23932  *
23933  *  @param[in]  RgSchCellCb     *cell
23934  *  @param[in]  RgSchDlSf       *dlSf
23935  *  @param[in]  RgSchDlRbAlloc  *allocInfo
23936  *
23937  *  @return Bool
23938  *      -# TRUE
23939  *      -# FALSE
23940  **/
23941 #ifdef UNUSED_FUNC
23942 #ifdef ANSI
23943 PRIVATE Bool rgSCHCmnNonDlfsSFRBwAvlbl
23944 (
23945 RgSchCellCb        *cell,
23946 RgSchSFRPoolInfo   **sfrpoolInfo,
23947 RgSchDlSf          *dlSf,
23948 RgSchDlRbAlloc     *allocInfo,
23949 Bool               isUeCellEdge
23950 )
23951 #else
23952 PRIVATE Bool rgSCHCmnNonDlfsSFRBwAvlbl(cell, sfrpoolInfo, dlSf, allocInfo, isUeCellEdge)
23953 RgSchCellCb        *cell;
23954 RgSchSFRPoolInfo   **sfrpoolInfo;
23955 RgSchDlSf          *dlSf;
23956 RgSchDlRbAlloc     *allocInfo;
23957 Bool               isUeCellEdge;
23958 #endif
23959 {
23960    CmLListCp   *l;
23961    CmLListCp   *l1;
23962    CmLList     *n;
23963    CmLList     *n1;
23964    RgSchSFRPoolInfo  *sfrPool;
23965    RgSchSFRPoolInfo  *sfrCEPool;
23966
23967    U8 tbs;
23968    U8 noLyrs;
23969    RgSchSFRPoolInfo *poolWithMaxAvlblBw = NULLP;
23970    U32 bwAvlbl = 0;
23971    U32 addtnlPRBs = 0;
23972
23973    if (dlSf->bw <= dlSf->bwAlloced)
23974    {
23975       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId, 
23976             "BW is fully allocated for subframe (%d) CRNTI:%d", dlSf->sfNum,allocInfo->rnti);
23977       return FALSE;
23978    }
23979
23980    if (dlSf->sfrTotalPoolInfo.ccBwFull == TRUE)
23981    {
23982       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
23983             "BW is fully allocated for CC Pool CRNTI:%d",allocInfo->rnti);
23984       return FALSE;
23985    }
23986
23987    if ((dlSf->sfrTotalPoolInfo.ceBwFull == TRUE) && (isUeCellEdge))
23988    {
23989       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, 
23990             "BW is fully allocated for CE Pool CRNTI:%d",allocInfo->rnti);
23991       return FALSE;
23992    }  
23993
23994    /* We first check if the ue scheduled is a cell edge or cell centre and accordingly check the avaialble
23995       memory in their pool. If the cell centre UE doesnt have Bw available in its pool, then it will check
23996       Bw availability in cell edge pool but the other way around is NOT possible.   */
23997    if(isUeCellEdge)
23998    {   
23999       l = &dlSf->sfrTotalPoolInfo.cePool;
24000    }
24001    else
24002    {
24003       l = &dlSf->sfrTotalPoolInfo.ccPool; 
24004    }     
24005
24006    n = cmLListFirst(l);
24007
24008    while(n)       
24009    {
24010       if (allocInfo->raType == RG_SCH_CMN_RA_TYPE0)
24011       {
24012          sfrPool = (RgSchSFRPoolInfo*)(n->node);
24013
24014          /* MS_FIX for ccpu00123919 : Number of RBs in case of RETX should be same as that of initial transmission. */
24015          if(allocInfo->tbInfo[0].tbCb->txCntr)
24016          {
24017             /* If RB assignment is being done for RETX. Then if reqRbs are   a multiple of rbgSize then ignore lstRbgDfct. If reqRbs is 
24018              * not a multiple of rbgSize then check if lsgRbgDfct exists */
24019             if (allocInfo->rbsReq % cell->rbgSize == 0)
24020             {
24021                if ((sfrPool->type2End == dlSf->type2End) && dlSf->lstRbgDfct)
24022                {
24023                   /* In this scenario we are wasting the last RBG for this dlSf */
24024                   sfrPool->type0End--;
24025                   sfrPool->bwAlloced += (cell->rbgSize - dlSf->lstRbgDfct);
24026
24027                   dlSf->lstRbgDfct = 0;
24028
24029                   /*ABHINAV To check if these variables need to be taken care of*/
24030                   dlSf->type0End--;
24031                   dlSf->bwAlloced += (cell->rbgSize - dlSf->lstRbgDfct);
24032                }
24033             }
24034             else
24035             {
24036                if (dlSf->lstRbgDfct)
24037                {
24038                   /* Check if type0 allocation can cater to this RETX requirement */
24039                   if ((allocInfo->rbsReq % cell->rbgSize) != (cell->rbgSize - dlSf->lstRbgDfct))
24040                   {
24041                      return (FALSE);
24042                   }
24043                   else
24044                   {
24045                      if (sfrPool->type2End != dlSf->type2End)   /*Search again for some pool which has the END RBG of the BandWidth*/
24046                      {
24047                         continue;                                       
24048                      }  
24049                   }
24050                }
24051                else
24052                {
24053                   /* cannot allocate same number of required RBs */
24054                   return (FALSE);                    
24055                }
24056             }
24057          }
24058
24059          /*rg002.301 ccpu00120391 MOD condition is modified approprialtely to find if rbsReq is less than available RBS*/
24060          if(allocInfo->rbsReq <= (((sfrPool->type0End - sfrPool->type2End + 1)*\
24061                      cell->rbgSize) - dlSf->lstRbgDfct))
24062          {
24063             *sfrpoolInfo = sfrPool;
24064             return (TRUE);
24065          }
24066          else
24067          {
24068             if (sfrPool->bw <= sfrPool->bwAlloced + cell->rbgSize)
24069             {
24070                n = cmLListNext(l);
24071                /* If the ue is cell centre then it will simply check the memory available in next pool.
24072                   But if there are no more memory pools available, then cell centre Ue will try to look for memory in cell edge pool */
24073
24074                if((!isUeCellEdge) && (!n->node))
24075                {
24076                   l = &dlSf->sfrTotalPoolInfo.cePool;
24077                   n = cmLListFirst(l);
24078                }
24079
24080                continue; 
24081             }    
24082
24083             /* MS_FIX: Number of RBs in case of RETX should be same as that of initial transmission */
24084             if(allocInfo->tbInfo[0].tbCb->txCntr == 0)
24085             {
24086                /*rg002.301 ccpu00120391 MOD setting the remaining RBs  for the requested UE*/
24087                allocInfo->rbsReq = (((sfrPool->type0End - sfrPool->type2End + 1)*\
24088                         cell->rbgSize) - dlSf->lstRbgDfct);
24089                RG_SCH_CMN_DL_MCS_TO_TBS(allocInfo->tbInfo[0].imcs, tbs);
24090                noLyrs = allocInfo->tbInfo[0].noLyr;
24091                allocInfo->tbInfo[0].bytesReq = rgTbSzTbl[noLyrs-1][tbs][allocInfo->rbsReq - 1]/8;
24092                *sfrpoolInfo = sfrPool;
24093                return (TRUE);
24094             }
24095             else
24096             {
24097                n = cmLListNext(l);
24098
24099                /* If the ue is cell centre then it will simply check the memory available in next pool.
24100                   But if there are no more memory pools available, then cell centre Ue will try to look for memory in cell edge pool */
24101                if((!isUeCellEdge) && (!n->node))
24102                {
24103                   l = &dlSf->sfrTotalPoolInfo.cePool;
24104                   n = cmLListFirst(l);
24105                }
24106
24107                continue;
24108             }
24109
24110          //   return (FALSE);
24111          }
24112       }
24113       else if (allocInfo->raType == RG_SCH_CMN_RA_TYPE2)
24114       {
24115          sfrPool = (RgSchSFRPoolInfo*)(n->node);
24116          /* This is a Case where a UE was CC and had more RBs allocated than present in CE pool.
24117             In case this UE whn become CE with retx going on, then BW is not sufficient for Retx */
24118          if ((isUeCellEdge) &&
24119             (allocInfo->tbInfo[0].tbCb->txCntr != 0))
24120          {
24121             if(allocInfo->rbsReq > (sfrPool->bw - sfrPool->bwAlloced))
24122             {
24123                /* Adjust CE BW such that Retx alloc is successful */
24124                /* Check if merging CE with adjacent CC pool will be sufficient to process Retx */
24125
24126                /* If no Type 0 allocations are made from this pool */
24127                if (sfrPool->type0End == (((sfrPool->poolendRB + 1) / cell->rbgSize) - 1))
24128                {
24129                   if (sfrPool->adjCCPool &&
24130                         (sfrPool->adjCCPool->type2Start == sfrPool->poolendRB + 1) &&
24131                         (allocInfo->rbsReq <= ((sfrPool->bw - sfrPool->bwAlloced) + 
24132                                                ((sfrPool->adjCCPool->bw - sfrPool->adjCCPool->bwAlloced)))))
24133                   {
24134                      addtnlPRBs = allocInfo->rbsReq - (sfrPool->bw - sfrPool->bwAlloced);
24135
24136                      /* Adjusting CE Pool Info */
24137                      sfrPool->bw += addtnlPRBs;
24138                      sfrPool->type0End = ((sfrPool->poolendRB + addtnlPRBs + 1) /
24139                            cell->rbgSize) - 1;
24140
24141                      /* Adjusting CC Pool Info */
24142                      sfrPool->adjCCPool->type2Start += addtnlPRBs;
24143                      sfrPool->adjCCPool->type2End = RGSCH_CEIL(sfrPool->adjCCPool->type2Start, 
24144                            cell->rbgSize);
24145                      sfrPool->adjCCPool->bw -= addtnlPRBs;
24146                      *sfrpoolInfo = sfrPool;
24147                      return (TRUE);
24148                   }
24149                }
24150             }
24151          }
24152
24153          /* Check if CC pool is one of the following:
24154           * 1. |CE| + |CC "CCPool2Exists" = TRUE|
24155           * 2. |CC "CCPool2Exists" = FALSE| + |CE| + |CC "CCPool2Exists" = TRUE|
24156           */ 
24157          if(TRUE == sfrPool->CCPool2Exists)
24158          {
24159             l1 = &dlSf->sfrTotalPoolInfo.cePool;
24160             n1 = cmLListFirst(l1); 
24161             sfrCEPool = (RgSchSFRPoolInfo*)(n1->node);
24162             if(allocInfo->rbsReq <= (sfrCEPool->bw - sfrCEPool->bwAlloced))
24163             {
24164                *sfrpoolInfo = sfrCEPool;
24165                return (TRUE);
24166             }
24167             else if(allocInfo->rbsReq <= (sfrPool->bw - sfrPool->bwAlloced))  
24168             {
24169                *sfrpoolInfo = sfrPool;
24170                return (TRUE);
24171             }
24172             /* Check if CE and CC boundary has unallocated prbs */
24173             else if ((sfrPool->poolstartRB == sfrPool->type2Start) &&
24174                   (sfrCEPool->type0End  == ((sfrCEPool->poolendRB + 1) / cell->rbgSize) - 1))
24175             {
24176                if(allocInfo->rbsReq <= (sfrCEPool->bw - sfrCEPool->bwAlloced) + 
24177                      (sfrPool->bw - sfrPool->bwAlloced))
24178                {
24179                   /* Checking if BW can be allocated partly from CE pool and partly
24180                    * from CC pool
24181                    */
24182                   addtnlPRBs = allocInfo->rbsReq - (sfrPool->bw - sfrPool->bwAlloced);
24183                   /* Updating CE and CC  type2 parametrs based on the RBs allocated
24184                    * from these pools*/
24185                   sfrPool->type2Start -= addtnlPRBs;
24186                   sfrPool->type2End = RGSCH_CEIL(sfrPool->type2Start, cell->rbgSize);
24187                   sfrPool->bw += addtnlPRBs;
24188                   if (addtnlPRBs == (sfrCEPool->bw - sfrCEPool->bwAlloced))
24189                   {
24190                      sfrCEPool->bwAlloced  = sfrCEPool->bw; 
24191                      dlSf->sfrTotalPoolInfo.ceBwFull = TRUE;
24192                   }
24193                   else
24194                   {
24195                      sfrCEPool->bw -= addtnlPRBs;
24196                      sfrCEPool->type0End = ((sfrCEPool->poolendRB + 1 - addtnlPRBs) / cell->rbgSize) - 1;
24197                   }
24198                   *sfrpoolInfo = sfrPool;
24199                   return (TRUE);
24200                }
24201                else if ( bwAvlbl < 
24202                      ((sfrCEPool->bw - sfrCEPool->bwAlloced) +
24203                       (sfrPool->bw - sfrPool->bwAlloced)))
24204                {
24205                   /* All the Prbs from CE BW shall be allocated */
24206                   if(allocInfo->tbInfo[0].tbCb->txCntr == 0)
24207                   {
24208                      sfrPool->type2Start   = sfrCEPool->type2Start;
24209                      sfrPool->bw          += sfrCEPool->bw - sfrCEPool->bwAlloced;
24210                      sfrCEPool->type2Start = sfrCEPool->poolendRB + 1;
24211                      sfrCEPool->bwAlloced  = sfrCEPool->bw; 
24212                      dlSf->sfrTotalPoolInfo.ceBwFull = TRUE;
24213
24214                      /* set the remaining RBs for the requested UE */
24215                      allocInfo->rbsReq = (sfrPool->bw - sfrPool->bwAlloced);
24216                      RG_SCH_CMN_DL_MCS_TO_TBS(allocInfo->tbInfo[0].imcs, tbs);
24217                      noLyrs = allocInfo->tbInfo[0].noLyr;
24218                      allocInfo->tbInfo[0].bytesReq = 
24219                         rgTbSzTbl[noLyrs-1][tbs][allocInfo->rbsReq - 1]/8;
24220                      *sfrpoolInfo = sfrPool;               
24221                      return (TRUE);
24222                   }
24223                   else
24224                   {
24225                      return (FALSE);
24226                   }
24227                }
24228             }
24229          } 
24230
24231          /* Checking if no. of RBs required can be allocated from
24232           * SFR pool. 
24233           * 1. If available return the SFR pool.
24234           * 2. Else update the RBs required parameter based on the 
24235           *    BW available in the pool 
24236           * 3. Return FALSE if no B/W is available. 
24237           */
24238          if (allocInfo->rbsReq <= (sfrPool->bw - sfrPool->bwAlloced))
24239          {
24240             *sfrpoolInfo = sfrPool;
24241             return (TRUE);
24242          }
24243          else
24244          {
24245             if(allocInfo->tbInfo[0].tbCb->txCntr == 0)
24246             {
24247                if (bwAvlbl < sfrPool->bw - sfrPool->bwAlloced)
24248                {
24249                   if (isUeCellEdge)
24250                   {
24251                      dlSf->sfrTotalPoolInfo.ceBwFull = TRUE; 
24252                   }
24253                   bwAvlbl = sfrPool->bw - sfrPool->bwAlloced;
24254                   poolWithMaxAvlblBw = sfrPool;
24255                }
24256                n = cmLListNext(l);
24257
24258                if ((isUeCellEdge == FALSE) && (n == NULLP))
24259                {
24260                   if(l != &dlSf->sfrTotalPoolInfo.cePool)
24261                   {
24262                      l = &dlSf->sfrTotalPoolInfo.cePool;
24263                      n = cmLListFirst(l);                          
24264                   }
24265                }
24266
24267                if (n == NULLP)
24268                {
24269                   if (bwAvlbl == 0)
24270                   {                                                             
24271                      if (isUeCellEdge)
24272                      {
24273                         dlSf->sfrTotalPoolInfo.ceBwFull = TRUE; 
24274                      }
24275                      else
24276                      {
24277                         dlSf->sfrTotalPoolInfo.ccBwFull = TRUE;  
24278                      }
24279                      return (FALSE);
24280                   }
24281                   else
24282                   {
24283                      /* set the remaining RBs for the requested UE */
24284                      allocInfo->rbsReq = poolWithMaxAvlblBw->bw - 
24285                         poolWithMaxAvlblBw->bwAlloced;
24286                      RG_SCH_CMN_DL_MCS_TO_TBS(allocInfo->tbInfo[0].imcs, tbs);
24287                      noLyrs = allocInfo->tbInfo[0].noLyr;
24288                      allocInfo->tbInfo[0].bytesReq = 
24289                         rgTbSzTbl[noLyrs-1][tbs][allocInfo->rbsReq - 1]/8;
24290                      *sfrpoolInfo = poolWithMaxAvlblBw;            
24291                      return (TRUE);
24292                   }
24293                }                          
24294             }
24295             else
24296             {                   
24297                n = cmLListNext(l);
24298
24299                if ((isUeCellEdge == FALSE) && (n == NULLP))
24300                {
24301                   if(l != &dlSf->sfrTotalPoolInfo.cePool)
24302                   {
24303                      l = &dlSf->sfrTotalPoolInfo.cePool;
24304                      n = cmLListFirst(l);                          
24305                   }
24306                }
24307
24308                if (n == NULLP)
24309                {
24310                   return (FALSE);
24311                }
24312             }
24313
24314          }
24315       }   
24316    } 
24317    return (FALSE);
24318 }
24319 #endif
24320 #endif /* end of ifndef LTE_TDD*/
24321 /* LTE_ADV_FLAG_REMOVED_END */
24322
24323 /**
24324  * @brief To check if DL BW available for non-DLFS allocation.
24325  *
24326  * @details
24327  *
24328  *     Function : rgSCHCmnNonDlfsUeRbAlloc
24329  *
24330  *     Processing Steps:
24331  *      - Determine availability based on RA Type.
24332  *
24333  *  @param[in]  RgSchCellCb     *cell
24334  *  @param[in]  RgSchDlSf       *dlSf
24335  *  @param[in]  RgSchDlRbAlloc  *allocInfo
24336  *
24337  *  @return Bool
24338  *      -# TRUE
24339  *      -# FALSE
24340  **/
24341 #ifdef UNUSED_FUNC
24342 #ifdef ANSI
24343 PRIVATE Bool rgSCHCmnNonDlfsBwAvlbl
24344 (
24345 RgSchCellCb        *cell,
24346 RgSchDlSf          *dlSf,
24347 RgSchDlRbAlloc     *allocInfo
24348 )
24349 #else
24350 PRIVATE Bool rgSCHCmnNonDlfsBwAvlbl(cell, dlSf, allocInfo)
24351 RgSchCellCb        *cell;
24352 RgSchDlSf          *dlSf;
24353 RgSchDlRbAlloc     *allocInfo;
24354 #endif
24355 {
24356    U8 tbs;
24357    U8 noLyrs;
24358    U8 ignoredDfctRbg = FALSE;
24359
24360    if (dlSf->bw <= dlSf->bwAlloced)
24361    {
24362       RLOG_ARG3(L_DEBUG,DBG_CELLID,cell->cellId, "(%d:%d)FAILED CRNTI:%d",
24363          dlSf->bw, dlSf->bwAlloced,allocInfo->rnti);
24364       return (FALSE);
24365    }
24366    if (allocInfo->raType == RG_SCH_CMN_RA_TYPE0)
24367    {
24368        /* Fix for ccpu00123919 : Number of RBs in case of RETX should be same as 
24369         * that of initial transmission. */
24370        if(allocInfo->tbInfo[0].tbCb->txCntr)
24371        {
24372           /* If RB assignment is being done for RETX. Then if reqRbs are 
24373            * a multiple of rbgSize then ignore lstRbgDfct. If reqRbs is 
24374            * not a multiple of rbgSize then check if lsgRbgDfct exists */
24375           if (allocInfo->rbsReq % cell->rbgSize == 0)
24376           {
24377              if (dlSf->lstRbgDfct)
24378              {
24379                 /* In this scenario we are wasting the last RBG for this dlSf */
24380                 
24381                 dlSf->type0End--;
24382                 dlSf->bwAlloced += (cell->rbgSize - dlSf->lstRbgDfct);
24383                 /* Fix: MUE_PERTTI_DL */
24384                 dlSf->lstRbgDfct = 0;
24385                 ignoredDfctRbg = TRUE;
24386                 
24387              }
24388           }
24389           else
24390           {
24391              if (dlSf->lstRbgDfct)
24392              {
24393                 /* Check if type0 allocation can cater to this RETX requirement */
24394                 if ((allocInfo->rbsReq % cell->rbgSize) != (cell->rbgSize - dlSf->lstRbgDfct))
24395                 {
24396                    return (FALSE);
24397                 }
24398              }
24399              else
24400              {
24401                 /* cannot allocate same number of required RBs */
24402                 return (FALSE);              
24403              }
24404           }
24405        }
24406
24407        /* Condition is modified approprialtely to find
24408         * if rbsReq is less than available RBS*/
24409       if(allocInfo->rbsReq <= (((dlSf->type0End - dlSf->type2End + 1)*\
24410                cell->rbgSize) - dlSf->lstRbgDfct))
24411       {
24412          return (TRUE);
24413       }
24414       /* ccpu00132358:MOD- Removing "ifndef LTE_TDD" for unblocking the RB 
24415        * allocation in TDD when requested RBs are more than available RBs*/
24416       else
24417       {
24418           /* MS_WORKAROUND for ccpu00122022 */
24419          if (dlSf->bw < dlSf->bwAlloced + cell->rbgSize)
24420          {
24421             /* ccpu00132358- Re-assigning the values which were updated above 
24422              * if it is RETX and Last  RBG available*/
24423             if(ignoredDfctRbg == TRUE)
24424             {
24425                dlSf->type0End++;
24426                dlSf->bwAlloced -= (cell->rbgSize - dlSf->lstRbgDfct);
24427                dlSf->lstRbgDfct = 1;
24428             }
24429
24430
24431             return (FALSE);
24432          }
24433          /* Fix: Number of RBs in case of RETX should be same as 
24434           * that of initial transmission. */
24435          if(allocInfo->tbInfo[0].tbCb->txCntr == 0 
24436 #ifdef LTE_ADV
24437             && (FALSE == rgSCHLaaIsLaaTB(allocInfo))
24438 #endif
24439             )
24440          {
24441             /* Setting the remaining RBs for the requested UE*/
24442             allocInfo->rbsReq = (((dlSf->type0End - dlSf->type2End + 1)*\
24443                         cell->rbgSize) - dlSf->lstRbgDfct);
24444             RG_SCH_CMN_DL_MCS_TO_TBS(allocInfo->tbInfo[0].imcs, tbs);
24445             noLyrs = allocInfo->tbInfo[0].noLyr;
24446             allocInfo->tbInfo[0].bytesReq = rgTbSzTbl[noLyrs-1][tbs][allocInfo->rbsReq - 1]/8;
24447             /* DwPts Scheduling Changes Start */
24448 #if LTE_TDD
24449             if (dlSf->sfType == RG_SCH_SPL_SF_DATA)
24450             {   
24451                allocInfo->tbInfo[0].bytesReq = 
24452                         rgTbSzTbl[noLyrs-1][tbs][RGSCH_MAX(allocInfo->rbsReq*3/4,1) - 1]/8; 
24453             }
24454 #endif            
24455             /* DwPts Scheduling Changes End */
24456          }
24457          else
24458          {
24459                     /* ccpu00132358- Re-assigning the values which were updated above 
24460              * if it is RETX and Last  RBG available*/
24461             if(ignoredDfctRbg == TRUE)
24462             {
24463                dlSf->type0End++;
24464                dlSf->bwAlloced -= (cell->rbgSize - dlSf->lstRbgDfct);
24465                dlSf->lstRbgDfct = 1;
24466             }
24467
24468             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "FAILED for CRNTI:%d",
24469                   allocInfo->rnti);
24470             printf ("RB Alloc failed for LAA TB type 0\n");
24471             return (FALSE);
24472          }
24473          return (TRUE);
24474       }
24475    }
24476    else if (allocInfo->raType == RG_SCH_CMN_RA_TYPE2)
24477    {
24478       if (allocInfo->rbsReq <= (dlSf->bw - dlSf->bwAlloced))
24479       {
24480          return (TRUE);
24481       }
24482       /* ccpu00132358:MOD- Removing "ifndef LTE_TDD" for unblocking the RB 
24483        * allocation in TDD when requested RBs are more than available RBs*/
24484       else
24485       {
24486          /* Fix: Number of RBs in case of RETX should be same as 
24487           * that of initial transmission. */
24488          if((allocInfo->tbInfo[0].tbCb->txCntr == 0) 
24489 #ifdef LTE_ADV
24490             && (FALSE == rgSCHLaaIsLaaTB(allocInfo))
24491 #endif
24492             )
24493          {
24494             /* set the remaining RBs for the requested UE */
24495             allocInfo->rbsReq = dlSf->bw - dlSf->bwAlloced;
24496             RG_SCH_CMN_DL_MCS_TO_TBS(allocInfo->tbInfo[0].imcs, tbs);
24497             noLyrs = allocInfo->tbInfo[0].noLyr;
24498             allocInfo->tbInfo[0].bytesReq = rgTbSzTbl[noLyrs-1][tbs][allocInfo->rbsReq - 1]/8;
24499             /* DwPts Scheduling Changes Start */
24500 #ifdef LTE_TDD
24501             if (dlSf->sfType == RG_SCH_SPL_SF_DATA)
24502             {   
24503                allocInfo->tbInfo[0].bytesReq = 
24504                         rgTbSzTbl[noLyrs-1][tbs][RGSCH_MAX(allocInfo->rbsReq*3/4,1) - 1]/8; 
24505             }
24506 #endif            
24507             /* DwPts Scheduling Changes End */
24508          }
24509          else
24510          {
24511             printf ("RB Alloc failed for LAA TB type 2\n");
24512             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"FAILED for CRNTI:%d",allocInfo->rnti);
24513             return (FALSE);
24514          }
24515          /* Fix: Number of RBs in case of RETX should be same as 
24516           * that of initial transmission. */
24517          return (TRUE);
24518       }
24519    }
24520    RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"FAILED for CRNTI:%d",allocInfo->rnti);
24521    return (FALSE);
24522 }
24523 #endif
24524 /* LTE_ADV_FLAG_REMOVED_START */
24525 #ifndef LTE_TDD
24526 /**
24527  * @brief To update non-DLFS alloc'n parameters after TYPE2 Allocation.
24528  *
24529  * @details
24530  *
24531  *     Function : rgSCHCmnNonDlfsSFRCmnChannelUpdTyp2Alloc
24532  *
24533  *     Processing Steps:
24534  *
24535  *  @param[in]  RgSchCellCb     *cell
24536  *  @param[in]  RgSchDlSf       *dlSf
24537  *  @param[in]  U8              rbStrt
24538  *  @param[in]  U8              numRb
24539  *
24540  *  @return Void
24541  **/
24542 #ifdef ANSI
24543 Void rgSCHCmnNonDlfsSFRCmnChannelUpdTyp2Alloc
24544 (
24545 RgSchCellCb        *cell,
24546 RgSchDlSf          *dlSf,
24547 U8                 rbStrt,
24548 U8                 numRb
24549 )
24550 #else
24551 Void rgSCHCmnNonDlfsSFRCmnChannelUpdTyp2Alloc(cell, dlSf, rbStrt, numRb)
24552 RgSchCellCb        *cell;
24553 RgSchDlSf          *dlSf;
24554 U8                 rbStrt;
24555 U8                 numRb;
24556 #endif
24557
24558    CmLListCp   *l;
24559    CmLList     *n;
24560    RgSchSFRPoolInfo  *sfrPool;
24561    
24562    l = &dlSf->sfrTotalPoolInfo.ccPool;
24563      
24564    dlSf->type2End = RGSCH_CEIL((rbStrt+numRb), cell->rbgSize);
24565    dlSf->bwAlloced += numRb;
24566    dlSf->type2Start += numRb;
24567    n = cmLListFirst(l);
24568         
24569    while(n->node)
24570    {
24571         sfrPool = (RgSchSFRPoolInfo*)(n->node);
24572         n = cmLListNext(l);
24573          
24574          /* If the pool contains some RBs allocated in this allocation, e.g: Pool is [30.50]. Pool->type2Start is 40 , dlSf->type2Start is 45. then update the variables in pool   */
24575         if((sfrPool->poolendRB >= dlSf->type2Start) && (sfrPool->type2Start < dlSf->type2Start))
24576         {
24577                 sfrPool->type2End   =  dlSf->type2End;
24578                 sfrPool->bwAlloced  =  dlSf->type2Start - sfrPool->poolstartRB; 
24579                 sfrPool->type2Start =  dlSf->type2Start;
24580         }          
24581         else 
24582         { 
24583                 /* If the pool contains all RBs allocated in this allocation*/
24584                 if(dlSf->type2Start > sfrPool->poolendRB)
24585                 {                
24586                         sfrPool->type2End   =  sfrPool->type0End + 1;
24587                         sfrPool->bwAlloced  =  sfrPool->bw; 
24588                         sfrPool->type2Start =  sfrPool->poolendRB + 1;             
24589                 }  
24590         }
24591       if (!n)
24592       { 
24593          if (l != &dlSf->sfrTotalPoolInfo.cePool)
24594          {
24595             l = &dlSf->sfrTotalPoolInfo.cePool;   
24596             n = cmLListFirst(l);
24597          }
24598          else
24599             RETVOID;
24600       }
24601    }
24602    RETVOID;
24603 }
24604
24605 /**
24606  * @brief To update non-DLFS alloc'n parameters after TYPE2 Allocation.
24607  *
24608  * @details
24609  *
24610  *     Function : rgSCHCmnNonDlfsUpdDSFRTyp2Alloc
24611  *
24612  *     Processing Steps:
24613  *
24614  *  @param[in]  RgSchCellCb     *cell
24615  *  @param[in]  RgSchDlSf       *dlSf
24616  *  @param[in]  U8              rbStrt
24617  *  @param[in]  U8              numRb
24618  *
24619  *  @return Void
24620  **/
24621 #ifdef UNUSED_FUNC
24622 #ifdef ANSI
24623 PRIVATE S16 rgSCHCmnNonDlfsUpdDSFRTyp2Alloc
24624 (
24625 RgSchCellCb        *cell,
24626 RgSchUeCb          *ue,
24627 RgSchDlSf          *dlSf,
24628 U8                 rbStrt,
24629 U8                 numRb
24630 )
24631 #else
24632 PRIVATE S16 rgSCHCmnNonDlfsUpdDSFRTyp2Alloc(cell, ue, dlSf, rbStrt, numRb)
24633 RgSchCellCb        *cell;
24634 RgSchUeCb          *ue;
24635 RgSchDlSf          *dlSf;
24636 U8                 rbStrt;
24637 U8                 numRb;
24638 #endif
24639 {
24640    CmLListCp   *l;
24641    CmLList     *n;
24642    RgSchSFRPoolInfo  *sfrCCPool1 = NULL;
24643    RgSchSFRPoolInfo  *sfrCCPool2 = NULL;
24644    S16 ret = RFAILED;
24645
24646    /* Move the type2End pivot forward */
24647    
24648    
24649    l = &dlSf->sfrTotalPoolInfo.ccPool;
24650    n = cmLListFirst(l);
24651    while(n)
24652    {
24653       sfrCCPool1 = (RgSchSFRPoolInfo*)(n->node);
24654       /* KWork fix */
24655       if (sfrCCPool1 ==  NULLP)
24656             {
24657                RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,  "rgSCHCmnNonDlfsUpdDSFRTyp2Alloc():"
24658                         "sfrCCPool1 is NULL for CRNTI:%d",ue->ueId);
24659                return RFAILED;
24660             }
24661       n = cmLListNext(l);
24662       if(n)
24663       {
24664           sfrCCPool2 = (RgSchSFRPoolInfo*)(n->node);
24665           n = cmLListNext(l);
24666       }
24667       if((sfrCCPool1) && (sfrCCPool2))
24668       { 
24669           /* Based on RNTP info, the CC user is assigned high power per subframe basis */
24670           if(((dlSf->type2Start >= sfrCCPool1->pwrHiCCRange.startRb) &&
24671               (dlSf->type2Start + numRb < sfrCCPool1->pwrHiCCRange.endRb)) || 
24672              ((dlSf->type2Start >= sfrCCPool2->pwrHiCCRange.startRb) &&
24673               (dlSf->type2Start + numRb < sfrCCPool2->pwrHiCCRange.endRb)))
24674           {
24675                ue->lteAdvUeCb.isCCUePHigh = TRUE;
24676
24677                /* Calling rgSCHCmnBuildRntpInfo function to update RNTP BitMap */
24678                ret = rgSCHCmnBuildRntpInfo(cell, dlSf->rntpInfo.val, dlSf->type2Start, numRb, dlSf->bw);
24679                if (ret != ROK)
24680                {
24681                     RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "rgSCHCmnNonDlfsUpdDSFRTyp2Alloc():"
24682                       "rgSCHCmnBuildRntpInfo() function returned RFAILED for CRNTI:%d",ue->ueId);
24683                     return RFAILED;
24684                }
24685            }
24686       }
24687       else
24688       {
24689          if((dlSf->type2Start >= sfrCCPool1->pwrHiCCRange.startRb) &&
24690                (dlSf->type2Start + numRb < sfrCCPool1->pwrHiCCRange.endRb))
24691          {
24692             ue->lteAdvUeCb.isCCUePHigh = TRUE;
24693
24694             /* Calling rgSCHCmnBuildRntpInfo function to update RNTP BitMap */
24695             ret = rgSCHCmnBuildRntpInfo(cell, dlSf->rntpInfo.val, dlSf->type2Start, numRb, dlSf->bw);
24696             if (ret != ROK)
24697             {
24698                RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,   "rgSCHCmnNonDlfsUpdDSFRTyp2Alloc():" 
24699                         "rgSCHCmnBuildRntpInfo() function returned RFAILED CRNTI:%d",ue->ueId);
24700                return RFAILED;
24701             }
24702          }
24703       }
24704    }
24705    dlSf->type2End = RGSCH_CEIL((rbStrt+numRb), cell->rbgSize);
24706 #ifndef LTEMAC_SPS
24707    dlSf->bwAlloced += numRb;
24708    /*MS_FIX for ccpu00123918*/
24709    dlSf->type2Start += numRb;
24710 #endif
24711    return ROK;
24712
24713 }
24714 #endif
24715 #endif /* end of ifndef LTE_TDD*/
24716 /* LTE_ADV_FLAG_REMOVED_END */
24717 /**
24718  * @brief To update non-DLFS alloc'n parameters after TYPE2 Allocation.
24719  *
24720  * @details
24721  *
24722  *     Function : rgSCHCmnNonDlfsUpdTyp2Alloc
24723  *
24724  *     Processing Steps:
24725  *
24726  *  @param[in]  RgSchCellCb     *cell
24727  *  @param[in]  RgSchDlSf       *dlSf
24728  *  @param[in]  U8              rbStrt
24729  *  @param[in]  U8              numRb
24730  *
24731  *  @return Void
24732  **/
24733 #ifdef ANSI
24734 PRIVATE Void rgSCHCmnNonDlfsUpdTyp2Alloc
24735 (
24736 RgSchCellCb        *cell,
24737 RgSchDlSf          *dlSf,
24738 U8                 rbStrt,
24739 U8                 numRb
24740 )
24741 #else
24742 PRIVATE Void rgSCHCmnNonDlfsUpdTyp2Alloc(cell, dlSf, rbStrt, numRb)
24743 RgSchCellCb        *cell;
24744 RgSchDlSf          *dlSf;
24745 U8                 rbStrt;
24746 U8                 numRb;
24747 #endif
24748 {
24749    /* Move the type2End pivot forward */
24750    dlSf->type2End = RGSCH_CEIL((rbStrt+numRb), cell->rbgSize);
24751 //#ifndef LTEMAC_SPS
24752    dlSf->bwAlloced += numRb;
24753    /*Fix for ccpu00123918*/
24754    dlSf->type2Start += numRb;
24755 //#endif
24756    RETVOID;
24757 }
24758
24759 /**
24760  * @brief To do DL allocation using TYPE0 RA.
24761  *
24762  * @details
24763  *
24764  *     Function : rgSCHCmnNonDlfsType0Alloc
24765  *
24766  *     Processing Steps:
24767  *      - Perform TYPE0 allocation using the RBGs between
24768  *        type0End and type2End.
24769  *      - Build the allocation mask as per RBG positioning.
24770  *      - Update the allocation parameters.
24771  *
24772  *  @param[in]  RgSchCellCb     *cell
24773  *  @param[in]  RgSchDlSf       *dlSf
24774  *  @param[in]  RgSchDlRbAlloc  *allocInfo
24775  *
24776  *  @return Void
24777  **/
24778 #ifdef UNUSED_FUNC
24779 #ifdef ANSI
24780 PRIVATE Void rgSCHCmnNonDlfsType0Alloc
24781 (
24782 RgSchCellCb        *cell,
24783 RgSchDlSf          *dlSf,
24784 RgSchDlRbAlloc     *allocInfo,
24785 RgSchUeCb          *ue
24786 )
24787 #else
24788 PRIVATE Void rgSCHCmnNonDlfsType0Alloc(cell, dlSf, allocInfo, dlUe)
24789 RgSchCellCb        *cell;
24790 RgSchDlSf          *dlSf;
24791 RgSchDlRbAlloc     *allocInfo;
24792 RgSchUeCb          *ue;
24793 #endif
24794 {
24795    U32 dlAllocMsk = 0;
24796    U8  rbgFiller = dlSf->lstRbgDfct;
24797    U8  noRbgs = RGSCH_CEIL((allocInfo->rbsReq + rbgFiller), cell->rbgSize);
24798    //U8  noRbgs = (allocInfo->rbsReq + rbgFiller)/ cell->rbgSize;
24799    U8  noRbs;
24800    U8  noLyr;
24801    U8  iTbs;
24802    U32          tb1BytesAlloc = 0;
24803    U32          tb2BytesAlloc = 0;
24804    RgSchCmnDlUe *dlUe         = RG_SCH_CMN_GET_DL_UE(ue,cell);
24805
24806    //if(noRbgs == 0) noRbgs = 1; /* Not required as ceilling is used above*/
24807
24808    /* Fix for ccpu00123919*/
24809    noRbs = (noRbgs * cell->rbgSize) - rbgFiller;
24810    if (dlSf->bwAlloced + noRbs > dlSf->bw)
24811    {
24812       if (--noRbgs == 0)
24813       {
24814          RETVOID;
24815       }
24816       noRbs = (noRbgs * cell->rbgSize) - rbgFiller;
24817    }
24818
24819    /* Fix for ccpu00138701: Ceilling is using to derive num of RBGs, Therefore, 
24820    *  after this operation,checking Max TB size and Max RBs are not crossed
24821    * if it is crossed then decrement num of RBGs. */
24822    //if((noRbs + rbgFiller) % cell->rbgSize)
24823    if((noRbs > allocInfo->rbsReq) &&
24824          (allocInfo->rbsReq + rbgFiller) % cell->rbgSize)
24825    {/* considering ue category limitation
24826      * due to ceiling */
24827
24828 #ifdef LTE_ADV
24829       if (rgSCHLaaIsLaaTB(allocInfo)== FALSE)
24830 #endif
24831       {
24832          if ((allocInfo->tbInfo[0].schdlngForTb) && (!allocInfo->tbInfo[0].tbCb->txCntr))
24833          {
24834             iTbs = allocInfo->tbInfo[0].iTbs;
24835             noLyr = allocInfo->tbInfo[0].noLyr;
24836             tb1BytesAlloc = rgTbSzTbl[noLyr - 1][iTbs][noRbs - 1]/8;
24837          }
24838
24839          if ((allocInfo->tbInfo[1].schdlngForTb) && (!allocInfo->tbInfo[1].tbCb->txCntr))
24840          {
24841             iTbs = allocInfo->tbInfo[1].iTbs;
24842             noLyr = allocInfo->tbInfo[1].noLyr;
24843             tb2BytesAlloc = rgTbSzTbl[noLyr - 1][iTbs][noRbs - 1]/8;
24844          }
24845       }
24846       
24847       /* Only Check for New Tx No need for Retx */
24848       if (tb1BytesAlloc || tb2BytesAlloc)
24849       {
24850          if (( ue->dl.aggTbBits >= dlUe->maxTbBits) ||
24851                (tb1BytesAlloc >= dlUe->maxTbSz/8) ||
24852                (tb2BytesAlloc >= dlUe->maxTbSz/8) ||
24853                (noRbs >= dlUe->maxRb))
24854          {
24855             if (--noRbgs == 0)
24856             {
24857                RETVOID;
24858             }
24859             noRbs = (noRbgs * cell->rbgSize) - rbgFiller;
24860          }
24861       }
24862    }
24863    /* type0End would have been initially (during subfrm Init) at the bit position
24864     * (cell->noOfRbgs - 1), 0 being the most significant.
24865     * Getting DlAllocMsk for noRbgs and at the appropriate position */
24866    dlAllocMsk |= (((1 << noRbgs) - 1) << (31 - dlSf->type0End));
24867    /* Move backwards the type0End pivot */
24868    dlSf->type0End -= noRbgs;
24869    /*Fix for ccpu00123919*/
24870    /*noRbs = (noRbgs * cell->rbgSize) - rbgFiller;*/
24871    /* Update the bwAlloced field accordingly */
24872 //#ifndef LTEMAC_SPS    /* ccpu00129474*/
24873    dlSf->bwAlloced += noRbs;
24874 //#endif
24875    /* Update Type0 Alloc Info */
24876    allocInfo->allocInfo.raType0.numDlAlloc = noRbgs;
24877    allocInfo->allocInfo.raType0.dlAllocBitMask |= dlAllocMsk;
24878    allocInfo->rbsAlloc = noRbs;
24879
24880    /* Update Tb info for each scheduled TB */
24881    iTbs = allocInfo->tbInfo[0].iTbs;
24882    noLyr = allocInfo->tbInfo[0].noLyr;
24883    /* Fix for ccpu00123919: For a RETX TB the iTbs is irrelevant.
24884     * RETX TB Size is same as Init TX TB Size */
24885    if (allocInfo->tbInfo[0].tbCb->txCntr)
24886    {
24887       allocInfo->tbInfo[0].bytesAlloc =
24888          allocInfo->tbInfo[0].bytesReq;
24889    }
24890    else
24891    {
24892       allocInfo->tbInfo[0].bytesAlloc =
24893          rgTbSzTbl[noLyr - 1][iTbs][noRbs - 1]/8;
24894       /* DwPts Scheduling Changes Start */
24895 #ifdef LTE_TDD
24896       if (dlSf->sfType == RG_SCH_SPL_SF_DATA)
24897       {
24898          allocInfo->tbInfo[0].bytesAlloc =
24899             rgTbSzTbl[noLyr - 1][iTbs][RGSCH_MAX(noRbs*3/4,1) - 1]/8;
24900       }
24901 #endif      
24902       /* DwPts Scheduling Changes End */
24903    }
24904
24905    if (allocInfo->tbInfo[1].schdlngForTb)
24906    {
24907       iTbs = allocInfo->tbInfo[1].iTbs;
24908       noLyr = allocInfo->tbInfo[1].noLyr;
24909       /* Fix for ccpu00123919: For a RETX TB the iTbs is irrelevant
24910        * RETX TB Size is same as Init TX TB Size */
24911       if (allocInfo->tbInfo[1].tbCb->txCntr)
24912       {
24913          allocInfo->tbInfo[1].bytesAlloc =
24914             allocInfo->tbInfo[1].bytesReq;
24915       }
24916       else
24917       {
24918          allocInfo->tbInfo[1].bytesAlloc =
24919             rgTbSzTbl[noLyr - 1][iTbs][noRbs - 1]/8;;
24920          /* DwPts Scheduling Changes Start */
24921 #ifdef LTE_TDD
24922          if (dlSf->sfType == RG_SCH_SPL_SF_DATA)
24923          {
24924             allocInfo->tbInfo[1].bytesAlloc =
24925                rgTbSzTbl[noLyr - 1][iTbs][RGSCH_MAX(noRbs*3/4,1) - 1]/8;
24926          }
24927 #endif      
24928          /* DwPts Scheduling Changes End */
24929       }
24930    }
24931
24932    /* The last RBG which can be smaller than the RBG size is consedered
24933     * only for the first time allocation of TYPE0 UE */
24934    dlSf->lstRbgDfct = 0;
24935    RETVOID;
24936 }
24937 #endif
24938 #ifndef LTE_TDD
24939
24940 /**
24941  * @brief To prepare RNTP value from the PRB allocation (P-High -> 1 and P-Low -> 0)
24942  *
24943  * @details
24944  *
24945  *     Function : rgSCHCmnBuildRntpInfo
24946  *
24947  *     Processing Steps:
24948  *
24949  *  @param[in]  U8                 *rntpPtr
24950  *  @param[in]  U8                 startRb
24951  *  @param[in]  U8                 numRb
24952  *
24953  *  @return Void
24954  **/
24955 #ifdef UNUSED_FUNC
24956 #ifdef ANSI
24957 PRIVATE S16 rgSCHCmnBuildRntpInfo
24958 (
24959 RgSchCellCb        *cell,
24960 U8                 *rntpPtr,
24961 U8                            startRb,
24962 U8                  nmbRb,
24963 U16                 bw
24964 )
24965 #else
24966 PRIVATE S16 rgSCHCmnBuildRntpInfo(cell, rntpPtr, startRb, nmbRb, bw)
24967 RgSchCellCb        *cell;
24968 U8                 *rntpPtr;
24969 U8                            startRb;
24970 U8                  nmbRb;
24971 U16                 bw;
24972 #endif
24973 {
24974    U16 rbPtrStartIdx;              /* Start Index of Octete Buffer to be filled */
24975    U16 rbPtrEndIdx;                /* End Index of Octete Buffer to be filled */
24976    U16 rbBitLoc;                   /* Bit Location to be set as 1 in the current Byte */
24977    U16 nmbRbPerByte;               /* PRB's to be set in the current Byte (in case of multiple Bytes) */
24978
24979
24980    rbPtrStartIdx = (startRb)/8;
24981    rbPtrEndIdx   = (startRb + nmbRb)/8;
24982
24983    if (rntpPtr == NULLP)
24984    {
24985       RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
24986                "rgSCHCmnBuildRntpInfo():"
24987                "rntpPtr can't be NULLP (Memory Allocation Failed)");
24988       return RFAILED;
24989    }
24990
24991    while(rbPtrStartIdx <= rbPtrEndIdx)
24992    {
24993       rbBitLoc = (startRb)%8;
24994
24995       /* case 1: startRb and endRb lies in same Byte */
24996       if (rbPtrStartIdx == rbPtrEndIdx)
24997       {
24998          rntpPtr[rbPtrStartIdx] = rntpPtr[rbPtrStartIdx]
24999                                      | (((1<<nmbRb)-1)<<rbBitLoc);
25000       }
25001
25002       /* case 2: startRb and endRb lies in different Byte */
25003       if (rbPtrStartIdx != rbPtrEndIdx)
25004       {
25005          nmbRbPerByte = 8 - rbBitLoc;
25006          nmbRb        = nmbRb - nmbRbPerByte;
25007          rntpPtr[rbPtrStartIdx] = rntpPtr[rbPtrStartIdx]
25008                                      | (((1<<nmbRbPerByte)-1)<<rbBitLoc);
25009          startRb = startRb + nmbRbPerByte;
25010       }
25011
25012       rbPtrStartIdx++;
25013    }
25014
25015    /* dsfr_pal_fixes ** 21-March-2013 ** SKS ** Adding Debug logs */
25016
25017    /* dsfr_pal_fixes ** 25-March-2013 ** SKS ** Adding Debug logs to print RNTP */
25018
25019    return ROK;
25020 }
25021
25022 /**
25023  * @brief To update non-DLFS alloc'n parameters after TYPE2 Allocation.
25024  *
25025  * @details
25026  *
25027  *     Function : rgSCHCmnNonDlfsUpdSFRPoolTyp2Alloc
25028  *
25029  *     Processing Steps:
25030  *
25031  *  @param[in]  RgSchCellCb     *cell
25032  *  @param[in]  RgSchDlSf       *dlSf
25033  *  @param[in]  U8              rbStrt
25034  *  @param[in]  U8              numRb
25035  *
25036  *  @return Void
25037  **/
25038 #ifdef ANSI
25039 PRIVATE S16 rgSCHCmnNonDlfsUpdSFRPoolTyp2Alloc
25040 (
25041 RgSchCellCb        *cell,
25042 RgSchUeCb                  *ue,
25043 RgSchDlSf          *dlSf,
25044 RgSchSFRPoolInfo   *sfrPool,
25045 U8                 rbStrt,
25046 U8                 numRb
25047 )
25048 #else
25049 PRIVATE S16 rgSCHCmnNonDlfsUpdSFRPoolTyp2Alloc(cell, ue, dlSf, sfrPool, rbStrt, numRb)
25050 RgSchCellCb        *cell;
25051 RgSchUeCb          *ue;
25052 RgSchDlSf          *dlSf;
25053 RgSchSFRPoolInfo   *sfrPool;
25054 U8                 rbStrt;
25055 U8                 numRb;
25056 #endif
25057 {
25058 #ifndef LTEMAC_SPS
25059    S16 ret;
25060 #endif
25061
25062    dlSf->type2End = RGSCH_CEIL((rbStrt+numRb), cell->rbgSize);
25063    sfrPool->type2End = RGSCH_CEIL((rbStrt+numRb), cell->rbgSize);
25064    
25065 #ifndef LTEMAC_SPS
25066    dlSf->type2Start += numRb;
25067    dlSf->bwAlloced += numRb;
25068    
25069    if(cell->lteAdvCb.dsfrCfg.status == RGR_ENABLE)
25070    {
25071       /* Based on RNTP info, the CC user is assigned high power per subframe basis */
25072       if(FALSE == ue->lteAdvUeCb.rgrLteAdvUeCfg.isUeCellEdge)
25073       {
25074          if((sfrPool->type2Start >= sfrPool->pwrHiCCRange.startRb) &&
25075                (sfrPool->type2Start + numRb < sfrPool->pwrHiCCRange.endRb))
25076          {
25077             ue->lteAdvUeCb.isCCUePHigh = TRUE;
25078
25079             /* Calling rgSCHCmnBuildRntpInfo function to update RNTP BitMap */
25080             ret = rgSCHCmnBuildRntpInfo(cell, dlSf->rntpInfo.val, sfrPool->type2Start, numRb, dlSf->bw);
25081             if (ret != ROK)
25082             {
25083                RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"rgSCHCmnNonDlfsUpdSFRPoolTyp2Alloc():"
25084                         "rgSCHCmnBuildRntpInfo() function returned RFAILED for CRNTI:%d",ue->ueId);
25085                return RFAILED;
25086             }
25087          }
25088       }
25089       else
25090       {
25091          /* Calling rgSCHCmnBuildRntpInfo function to update RNTP BitMap */
25092          ret = rgSCHCmnBuildRntpInfo(cell, dlSf->rntpInfo.val, sfrPool->type2Start, numRb, dlSf->bw);
25093          if (ret != ROK)
25094          {
25095             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "rgSCHCmnNonDlfsUpdSFRPoolTyp2Alloc():"
25096                      "rgSCHCmnBuildRntpInfo() function returned RFAILED for CRNTI:%d",ue->ueId);
25097             return RFAILED;
25098          }
25099       }
25100    }
25101    sfrPool->type2Start += numRb;
25102    sfrPool->bwAlloced += numRb;
25103 #endif 
25104
25105    return ROK;
25106 }
25107
25108 /**
25109  * @brief To do DL allocation using TYPE0 RA.
25110  *
25111  * @details
25112  *
25113  *     Function : rgSCHCmnNonDlfsSFRPoolType0Alloc
25114  *
25115  *     Processing Steps:
25116  *      - Perform TYPE0 allocation using the RBGs between type0End and type2End.
25117  *      - Build the allocation mask as per RBG positioning.
25118  *      - Update the allocation parameters.
25119  *
25120  *  @param[in]  RgSchCellCb     *cell
25121  *  @param[in]  RgSchDlSf       *dlSf
25122  *  @param[in]  RgSchDlRbAlloc  *allocInfo
25123  *
25124  *  @return Void
25125  **/
25126 #ifdef ANSI
25127 PRIVATE Void rgSCHCmnNonDlfsSFRPoolType0Alloc
25128 (
25129 RgSchCellCb        *cell,
25130 RgSchDlSf          *dlSf,
25131 RgSchSFRPoolInfo   *poolInfo,
25132 RgSchDlRbAlloc     *allocInfo
25133 )
25134 #else
25135 PRIVATE Void rgSCHCmnNonDlfsSFRPoolType0Alloc(cell, dlSf, poolInfo, allocInfo)
25136 RgSchCellCb        *cell;
25137 RgSchDlSf          *dlSf;
25138 RgSchSFRPoolInfo   *poolInfo;
25139 RgSchDlRbAlloc     *allocInfo;
25140 #endif
25141 {
25142    U32 dlAllocMsk = 0;
25143    U8  rbgFiller = 0;
25144    U8  noRbgs = 0;
25145    U8  noRbs;
25146    U8  noLyr;
25147    U8  iTbs;
25148
25149
25150    if (poolInfo->poolstartRB + poolInfo->bw == dlSf->bw)
25151    {
25152                 if (poolInfo->type0End == dlSf->bw/4)
25153                 {
25154                         rbgFiller = dlSf->lstRbgDfct;
25155                         /* The last RBG which can be smaller than the RBG size is consedered
25156                         * only for the first time allocation of TYPE0 UE */
25157                         dlSf->lstRbgDfct = 0;
25158                 }
25159    }
25160
25161    noRbgs = RGSCH_CEIL((allocInfo->rbsReq + rbgFiller), cell->rbgSize);
25162
25163    /* Abhinav to-do start */
25164    /* MS_FIX for ccpu00123919*/
25165    noRbs = (noRbgs * cell->rbgSize) - rbgFiller;
25166    if (dlSf->bwAlloced + noRbs > dlSf->bw)
25167    {
25168       if (--noRbgs == 0)
25169       {
25170          RETVOID;
25171       }
25172       noRbs = (noRbgs * cell->rbgSize) - rbgFiller;
25173    }
25174    /* Abhinav to-do end */
25175
25176
25177    
25178    /* type0End would have been initially (during subfrm Init) at the bit position
25179     * (cell->noOfRbgs - 1), 0 being the most significant.
25180     * Getting DlAllocMsk for noRbgs and at the appropriate position */
25181    dlAllocMsk |= (((1 << noRbgs) - 1) << (31 - poolInfo->type0End));
25182    /* Move backwards the type0End pivot */
25183    poolInfo->type0End -= noRbgs;
25184    /*MS_FIX for ccpu00123919*/
25185    /*noRbs = (noRbgs * cell->rbgSize) - rbgFiller;*/
25186    /* Update the bwAlloced field accordingly */
25187    poolInfo->bwAlloced += noRbs + dlSf->lstRbgDfct;
25188    dlSf->bwAlloced += noRbs + dlSf->lstRbgDfct;
25189    
25190    /* Update Type0 Alloc Info */
25191    allocInfo->allocInfo.raType0.numDlAlloc = noRbgs;
25192    allocInfo->allocInfo.raType0.dlAllocBitMask |= dlAllocMsk;
25193    allocInfo->rbsAlloc = noRbs;
25194
25195    /* Update Tb info for each scheduled TB */
25196    iTbs = allocInfo->tbInfo[0].iTbs;
25197    noLyr = allocInfo->tbInfo[0].noLyr;
25198    /* Fix for ccpu00123919: For a RETX TB the iTbs is irrelevant.
25199     * RETX TB Size is same as Init TX TB Size */
25200    if (allocInfo->tbInfo[0].tbCb->txCntr)
25201    {
25202       allocInfo->tbInfo[0].bytesAlloc =
25203          allocInfo->tbInfo[0].bytesReq;
25204    }
25205    else
25206    {
25207       allocInfo->tbInfo[0].bytesAlloc =
25208          rgTbSzTbl[noLyr - 1][iTbs][noRbs - 1]/8;
25209    }
25210
25211    if (allocInfo->tbInfo[1].schdlngForTb)
25212    {
25213       iTbs = allocInfo->tbInfo[1].iTbs;
25214       noLyr = allocInfo->tbInfo[1].noLyr;
25215       /* Fix for ccpu00123919: For a RETX TB the iTbs is irrelevant
25216        * RETX TB Size is same as Init TX TB Size */
25217       if (allocInfo->tbInfo[1].tbCb->txCntr)
25218       {
25219          allocInfo->tbInfo[1].bytesAlloc =
25220             allocInfo->tbInfo[1].bytesReq;
25221       }
25222       else
25223       {
25224          allocInfo->tbInfo[1].bytesAlloc =
25225             rgTbSzTbl[noLyr - 1][iTbs][noRbs - 1]/8;;
25226       }
25227    }
25228
25229    /* The last RBG which can be smaller than the RBG size is consedered
25230     * only for the first time allocation of TYPE0 UE */
25231    dlSf->lstRbgDfct = 0;
25232    RETVOID;
25233 }
25234 #endif
25235 /**
25236  * @brief Computes RNTP Info for a subframe.
25237  *
25238  * @details
25239  *
25240  *     Function :  rgSCHCmnNonDlfsDsfrRntpComp 
25241  *
25242  *     Processing Steps:
25243  *      - Computes RNTP info from individual pools.
25244  *
25245  *  @param[in]  RgSchDlSf       *dlSf
25246  *
25247  *  @return  void
25248  
25249  **/
25250 #ifdef ANSI
25251 PRIVATE void rgSCHCmnNonDlfsDsfrRntpComp
25252 (
25253 RgSchCellCb         *cell,
25254 RgSchDlSf          *dlSf
25255 )
25256 #else
25257 PRIVATE void rgSCHCmnNonDlfsDsfrRntpComp(cell, dlSf)
25258 RgSchCellCb         *cell;
25259 RgSchDlSf          *dlSf;
25260 #endif
25261 {
25262    PRIVATE U16 samples = 0;
25263    U16 i;
25264    U16 bwBytes = (dlSf->bw-1)/8;
25265    RgrLoadInfIndInfo *rgrLoadInf;
25266    U16 len;
25267    U16 ret     = ROK;
25268
25269
25270    len = (dlSf->bw % 8 == 0) ? dlSf->bw/8 : dlSf->bw/8 + 1;
25271
25272    /* RNTP info is ORed every TTI and the sample is stored in cell control block */ 
25273    for(i = 0; i <= bwBytes; i++)
25274    {
25275      cell->rntpAggrInfo.val[i] |= dlSf->rntpInfo.val[i];
25276    }
25277    samples = samples + 1;
25278    /* After every 1000 ms, the RNTP info will be sent to application to be further sent to all neighbouring eNB
25279          informing them about the load indication for cell edge users */
25280    if(RG_SCH_MAX_RNTP_SAMPLES == samples)
25281    {
25282       /* ccpu00134492 */
25283       ret = rgSCHUtlAllocSBuf (cell->instIdx,(Data**)&rgrLoadInf,
25284                sizeof(RgrLoadInfIndInfo));
25285       if (ret != ROK)
25286       {
25287          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId, "Could not "
25288             "allocate memory for sending LoadInfo");
25289          RETVOID;  
25290       }
25291      
25292       rgrLoadInf->u.rntpInfo.pres = cell->rntpAggrInfo.pres;
25293       /* dsfr_pal_fixes ** 21-March-2013 ** SKS */
25294       rgrLoadInf->u.rntpInfo.len  = len;
25295
25296       /* dsfr_pal_fixes ** 21-March-2013 ** SKS */
25297       rgrLoadInf->u.rntpInfo.val = cell->rntpAggrInfo.val; 
25298       rgrLoadInf->cellId = cell->cellId;
25299
25300       /* dsfr_pal_fixes ** 22-March-2013 ** SKS */
25301       rgrLoadInf->bw = dlSf->bw;
25302       rgrLoadInf->type = RGR_SFR;
25303
25304       ret = rgSCHUtlRgrLoadInfInd(cell, rgrLoadInf);
25305       if(ret == RFAILED)
25306       {
25307          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId, "rgSCHCmnNonDlfsDsfrRntpComp():"
25308                   "rgSCHUtlRgrLoadInfInd() returned RFAILED");
25309       }
25310
25311       memset(cell->rntpAggrInfo.val,0,len);
25312       samples = 0;
25313    }
25314  } 
25315 /* LTE_ADV_FLAG_REMOVED_END */
25316
25317 /* LTE_ADV_FLAG_REMOVED_START */
25318 /**
25319  * @brief Performs RB allocation per UE from a pool.
25320  *
25321  * @details
25322  *
25323  *     Function : rgSCHCmnSFRNonDlfsUeRbAlloc
25324  *
25325  *     Processing Steps:
25326  *      - Allocate consecutively available RBs.
25327  *
25328  *  @param[in]  RgSchCellCb     *cell
25329  *  @param[in]  RgSchUeCb       *ue
25330  *  @param[in]  RgSchDlSf       *dlSf
25331  *  @param[out] U8              *isDlBwAvail
25332  *
25333  *  @return  S16
25334  *      -# ROK
25335  *      -# RFAILED
25336  **/
25337 #ifdef UNUSED_FUNC
25338 #ifdef ANSI
25339 PRIVATE S16 rgSCHCmnSFRNonDlfsUeRbAlloc
25340 (
25341 RgSchCellCb        *cell,
25342 RgSchUeCb          *ue,
25343 RgSchDlSf          *dlSf,
25344 U8                 *isDlBwAvail
25345 )
25346 #else
25347 PRIVATE S16 rgSCHCmnSFRNonDlfsUeRbAlloc(cell, ue, dlSf, isDlBwAvail)
25348 RgSchCellCb        *cell;
25349 RgSchUeCb          *ue;
25350 RgSchDlSf          *dlSf;
25351 U8                 *isDlBwAvail;
25352 #endif
25353 {
25354    RgSchDlRbAlloc  *allocInfo;
25355    RgSchCmnDlUe    *dlUe;
25356    Bool isUECellEdge;
25357    RgSchSFRPoolInfo *sfrpoolInfo = NULLP;
25358
25359
25360    isUECellEdge = RG_SCH_CMN_IS_UE_CELL_EDGE(ue);
25361
25362    dlUe = RG_SCH_CMN_GET_DL_UE(ue,cell);
25363    allocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
25364    *isDlBwAvail = TRUE;
25365
25366    /*Find which pool is available for this UE*/
25367    if (rgSCHCmnNonDlfsSFRBwAvlbl(cell,  &sfrpoolInfo, dlSf, allocInfo, isUECellEdge) != TRUE)
25368    {
25369       /* SFR_FIX - If this is CE UE there may be BW available in CC Pool
25370          So CC UEs will be scheduled */
25371       if (isUECellEdge)
25372       {
25373          *isDlBwAvail = TRUE;
25374       }
25375       else
25376       {
25377          *isDlBwAvail = FALSE;
25378       }
25379       return RFAILED;
25380    }
25381
25382    if (dlUe->proc->tbInfo[0].isAckNackDtx == TFU_HQFDB_DTX || dlUe->proc->tbInfo[1].isAckNackDtx)
25383    {
25384       allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, ue, dlSf, dlUe->mimoInfo.cwInfo[0].cqi, allocInfo->dciFormat, TRUE);
25385    }
25386    else
25387    {
25388       allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, ue, dlSf, dlUe->mimoInfo.cwInfo[0].cqi, allocInfo->dciFormat,FALSE);
25389    }
25390    
25391    if (!(allocInfo->pdcch))
25392    {
25393       /* Returning ROK since PDCCH might be available for another UE and further allocations could be done */
25394       return RFAILED;
25395    }
25396    
25397 #ifdef LTEMAC_SPS
25398    allocInfo->rnti = ue->ueId;
25399 #endif
25400
25401    if (allocInfo->raType == RG_SCH_CMN_RA_TYPE2)
25402    {
25403       allocInfo->allocInfo.raType2.isLocal = TRUE;
25404       /* rg004.201 patch - ccpu00109921 fix end */
25405       /* MS_FIX for ccpu00123918*/
25406       allocInfo->allocInfo.raType2.rbStart = (U8)sfrpoolInfo->type2Start;
25407       allocInfo->allocInfo.raType2.numRb = allocInfo->rbsReq;
25408       /* rg007.201 - Changes for MIMO feature addition */
25409       /* rg008.201 - Removed dependency on MIMO compile-time flag */
25410       rgSCHCmnNonDlfsUpdSFRPoolTyp2Alloc(cell, ue, dlSf, sfrpoolInfo, \
25411             allocInfo->allocInfo.raType2.rbStart, \
25412             allocInfo->allocInfo.raType2.numRb);
25413       allocInfo->rbsAlloc = allocInfo->rbsReq;
25414       allocInfo->tbInfo[0].bytesAlloc = allocInfo->tbInfo[0].bytesReq;
25415    }
25416    else if (allocInfo->raType == RG_SCH_CMN_RA_TYPE0)
25417    {
25418       rgSCHCmnNonDlfsSFRPoolType0Alloc(cell, dlSf, sfrpoolInfo, allocInfo);
25419    }
25420 #ifndef LTE_TDD
25421 #ifdef DEBUGP
25422    rgSCHCmnFindCodeRate(cell,dlSf,allocInfo,0);
25423    if(allocInfo->tbInfo[1].schdlngForTb == TRUE)
25424    {
25425       rgSCHCmnFindCodeRate(cell,dlSf,allocInfo,1);
25426    }
25427 #endif
25428 #endif
25429
25430 #if defined(LTEMAC_SPS)
25431    /* Update the sub-frame with new allocation */
25432    dlSf->bwAlloced += allocInfo->rbsReq;
25433 #endif
25434
25435    return ROK;
25436 }
25437 #endif
25438 /* LTE_ADV_FLAG_REMOVED_END */
25439 #endif /* LTE_TDD */
25440
25441 /**
25442  * @brief Performs RB allocation per UE for frequency non-selective cell.
25443  *
25444  * @details
25445  *
25446  *     Function : rgSCHCmnNonDlfsUeRbAlloc
25447  *
25448  *     Processing Steps:
25449  *      - Allocate consecutively available RBs.
25450  *
25451  *  @param[in]  RgSchCellCb     *cell
25452  *  @param[in]  RgSchUeCb       *ue
25453  *  @param[in]  RgSchDlSf       *dlSf
25454  *  @param[out] U8              *isDlBwAvail
25455  *
25456  *  @return  S16
25457  *      -# ROK
25458  *      -# RFAILED
25459  **/
25460 #ifdef ANSI
25461 PRIVATE S16 rgSCHCmnNonDlfsUeRbAlloc
25462 (
25463 RgSchCellCb        *cell,
25464 RgSchUeCb          *ue,
25465 RgSchDlSf          *dlSf,
25466 U8                 *isDlBwAvail
25467 )
25468 #else
25469 PRIVATE S16 rgSCHCmnNonDlfsUeRbAlloc(cell, ue, dlSf, isDlBwAvail)
25470 RgSchCellCb        *cell;
25471 RgSchUeCb          *ue;
25472 RgSchDlSf          *dlSf;
25473 U8                 *isDlBwAvail;
25474 #endif
25475 {
25476    RgSchDlRbAlloc  *allocInfo;
25477    RgSchCmnDlUe    *dlUe;
25478 #ifdef LAA_DBG
25479    U32            dbgRbsReq = 0;
25480 #endif
25481
25482 #ifdef RG_5GTF
25483    RgSch5gtfUeCb  *ue5gtfCb = &(ue->ue5gtfCb);
25484         RgSchSfBeamInfo  *beamInfo = &(dlSf->sfBeamInfo[ue5gtfCb->BeamId]);
25485 #endif
25486    dlUe = RG_SCH_CMN_GET_DL_UE(ue,cell);
25487    allocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
25488    *isDlBwAvail = TRUE;
25489
25490         if(beamInfo->totVrbgAllocated > MAX_5GTF_VRBG)
25491         {
25492            RLOG_ARG1(L_ERROR ,DBG_CELLID,cell->cellId,
25493          "5GTF_ERROR : vrbg allocated > 25 :ue (%u)",
25494          ue->ueId);
25495            printf("5GTF_ERROR vrbg allocated > 25\n");
25496                 return RFAILED;
25497         }
25498
25499    if (dlUe->proc->tbInfo[0].isAckNackDtx == TFU_HQFDB_DTX 
25500        || dlUe->proc->tbInfo[1].isAckNackDtx)
25501    {
25502       allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, ue, dlSf, dlUe->mimoInfo.cwInfo[0].cqi, allocInfo->dciFormat, TRUE);
25503    }
25504    else
25505    {
25506       allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, ue, dlSf, dlUe->mimoInfo.cwInfo[0].cqi, allocInfo->dciFormat,FALSE);
25507    }
25508    if (!(allocInfo->pdcch))
25509    {
25510       /* Returning ROK since PDCCH might be available for another UE and
25511        * further allocations could be done */
25512       RLOG_ARG1(L_ERROR ,DBG_CELLID,cell->cellId,
25513          "5GTF_ERROR : PDCCH allocation failed :ue (%u)",
25514          ue->ueId);
25515            printf("5GTF_ERROR PDCCH allocation failed\n");
25516       return RFAILED;
25517    }
25518 #ifdef RG_5GTF
25519         //maxPrb = RGSCH_MIN((allocInfo->vrbgReq * MAX_5GTF_VRBG_SIZE), ue5gtfCb->maxPrb);
25520    //maxPrb = RGSCH_MIN(maxPrb, 
25521                 //((beamInfo->totVrbgAvail - beamInfo->vrbgStart)* MAX_5GTF_VRBG_SIZE)));
25522         //TODO_SID Need to check for vrbg available after scheduling for same beam.
25523         allocInfo->tbInfo[0].tbCb->dlGrnt.vrbgStart = beamInfo->vrbgStart;
25524         allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg = allocInfo->vrbgReq;
25525         //TODO_SID: Setting for max TP
25526         allocInfo->tbInfo[0].tbCb->dlGrnt.xPDSCHRange = 1;      
25527         allocInfo->tbInfo[0].tbCb->dlGrnt.rbAssign = rgSCHCmnCalcRiv(MAX_5GTF_VRBG, 
25528          allocInfo->tbInfo[0].tbCb->dlGrnt.vrbgStart, allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg);
25529         allocInfo->tbInfo[0].tbCb->dlGrnt.SCID = 0;
25530         allocInfo->tbInfo[0].tbCb->dlGrnt.dciFormat = allocInfo->dciFormat;
25531    //Filling temporarily
25532    allocInfo->tbInfo[0].tbCb->dlGrnt.rbStrt = (allocInfo->tbInfo[0].tbCb->dlGrnt.vrbgStart * MAX_5GTF_VRBG_SIZE);
25533    allocInfo->tbInfo[0].tbCb->dlGrnt.numRb = (allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg * MAX_5GTF_VRBG_SIZE);
25534
25535         beamInfo->vrbgStart += allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg;
25536         beamInfo->totVrbgAllocated += allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg; 
25537         allocInfo->tbInfo[0].bytesAlloc = allocInfo->tbInfo[0].bytesReq;
25538 #endif
25539
25540    return ROK;
25541 }
25542
25543 #ifdef RGR_V1
25544 /**
25545  * @brief Performs RB allocation for Msg4 for frequency non-selective cell.
25546  *
25547  * @details
25548  *
25549  *     Function : rgSCHCmnNonDlfsCcchSduAlloc
25550  *
25551  *     Processing Steps:
25552  *     - For each element in the list, Call rgSCHCmnNonDlfsCcchSduRbAlloc().
25553  *        - If allocation is successful, add the ueCb to scheduled list of CCCH
25554  *        SDU.
25555  *        - else, add UeCb to non-scheduled list.
25556  *
25557  *  @param[in]      RgSchCellCb         *cell
25558  *  @param[in, out] RgSchCmnCcchSduRbAlloc *allocInfo
25559  *  @param[in]      U8                  isRetx
25560  *
25561  *  @return  Void
25562  **/
25563 #ifdef ANSI
25564 PRIVATE Void rgSCHCmnNonDlfsCcchSduAlloc
25565 (
25566 RgSchCellCb         *cell,
25567 RgSchCmnCcchSduRbAlloc *allocInfo,
25568 U8                  isRetx
25569 )
25570 #else
25571 PRIVATE Void rgSCHCmnNonDlfsCcchSduAlloc(cell, allocInfo, isRetx)
25572 RgSchCellCb         *cell;
25573 RgSchCmnCcchSduRbAlloc *allocInfo;
25574 U8                  isRetx;
25575 #endif
25576 {
25577    S16             ret;
25578    CmLListCp       *ccchSduLst        = NULLP;
25579    CmLListCp       *schdCcchSduLst    = NULLP;
25580    CmLListCp       *nonSchdCcchSduLst = NULLP;
25581    CmLList         *schdLnkNode    = NULLP;
25582    CmLList         *toBeSchdLnk    = NULLP;
25583    RgSchDlSf       *dlSf           = allocInfo->ccchSduDlSf;
25584    RgSchUeCb       *ueCb           = NULLP;
25585    RgSchDlHqProcCb *hqP            = NULLP;
25586
25587    if (isRetx)
25588    {
25589       /* Initialize re-transmitting lists */
25590       ccchSduLst = &(allocInfo->ccchSduRetxLst);
25591       schdCcchSduLst = &(allocInfo->schdCcchSduRetxLst);
25592       nonSchdCcchSduLst = &(allocInfo->nonSchdCcchSduRetxLst);
25593    }
25594    else
25595    {
25596       /* Initialize transmitting lists */
25597       ccchSduLst = &(allocInfo->ccchSduTxLst);
25598       schdCcchSduLst = &(allocInfo->schdCcchSduTxLst);
25599       nonSchdCcchSduLst = &(allocInfo->nonSchdCcchSduTxLst);
25600    }
25601
25602    /* Perform allocaations  for the list */
25603    toBeSchdLnk = cmLListFirst(ccchSduLst);
25604    for (; toBeSchdLnk; toBeSchdLnk = toBeSchdLnk->next)
25605    {
25606       hqP = (RgSchDlHqProcCb *)(toBeSchdLnk->node);
25607       ueCb = hqP->hqE->ue;
25608       schdLnkNode = &hqP->schdLstLnk;
25609       RG_SCH_CMN_INIT_SCHD_LNK(schdLnkNode, hqP);
25610       ret = rgSCHCmnNonDlfsCcchSduRbAlloc(cell, ueCb, dlSf);
25611       if (ret != ROK)
25612       {
25613          /* Allocation failed: Add remaining MSG4 nodes to non-scheduled
25614           * list and return */
25615          do
25616          {
25617             hqP = (RgSchDlHqProcCb *)(toBeSchdLnk->node);
25618             ueCb = hqP->hqE->ue;
25619             schdLnkNode = &hqP->schdLstLnk;
25620             RG_SCH_CMN_INIT_SCHD_LNK(schdLnkNode, hqP);
25621             cmLListAdd2Tail(nonSchdCcchSduLst, schdLnkNode);
25622             toBeSchdLnk = toBeSchdLnk->next;
25623          } while(toBeSchdLnk);
25624          RETVOID;
25625       }
25626
25627       /* Allocation successful: Add UE to the scheduled list */
25628       cmLListAdd2Tail(schdCcchSduLst, schdLnkNode);
25629    }
25630
25631
25632    RETVOID;
25633 }
25634
25635 /**
25636  * @brief Performs RB allocation for CcchSdu for frequency non-selective cell.
25637  *
25638  * @details
25639  *
25640  *     Function : rgSCHCmnNonDlfsCcchSduRbAlloc
25641  *
25642  *     Processing Steps:
25643  *     - Fetch PDCCH
25644  *     - Allocate consecutively available RBs
25645  *
25646  *  @param[in] RgSchCellCb     *cell
25647  *  @param[in] RgSchUeCb       *ueCb
25648  *  @param[in] RgSchDlSf       *dlSf
25649  *  @return  S16
25650  *      -# ROK
25651  *      -# RFAILED
25652  **/
25653 #ifdef ANSI
25654 PRIVATE S16 rgSCHCmnNonDlfsCcchSduRbAlloc
25655 (
25656 RgSchCellCb        *cell,
25657 RgSchUeCb          *ueCb,
25658 RgSchDlSf          *dlSf
25659 )
25660 #else
25661 PRIVATE S16 rgSCHCmnNonDlfsCcchSduRbAlloc(cell, ueCb, dlSf)
25662 RgSchCellCb        *cell;
25663 RgSchUeCb          *ueCb;
25664 RgSchDlSf          *dlSf;
25665 #endif
25666 {
25667    RgSchDlRbAlloc  *allocInfo;
25668    RgSchCmnDlUe         *ueDl = RG_SCH_CMN_GET_DL_UE(ueCb,cell);
25669
25670
25671
25672    allocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ueCb,cell);
25673
25674    /* [ccpu00138802]-MOD-If Bw is less than required, return fail
25675       It will be allocated in next TTI */
25676 #ifdef LTEMAC_SPS
25677    if ((dlSf->spsAllocdBw >= cell->spsBwRbgInfo.numRbs) &&
25678          (dlSf->bwAlloced == dlSf->bw))
25679 #else
25680    if((dlSf->bwAlloced == dlSf->bw) ||
25681       (allocInfo->rbsReq > (dlSf->bw - dlSf->bwAlloced)))
25682 #endif
25683    {
25684       return RFAILED;
25685    }
25686    /* Retrieve PDCCH */
25687    /* DTX Changes: One Variable is passed to check whether it is DTX or Not */
25688    if (ueDl->proc->tbInfo[0].isAckNackDtx == TFU_HQFDB_DTX)
25689    {
25690       /*      allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, dlSf, y, ueDl->cqi,
25691        *      TFU_DCI_FORMAT_1A, TRUE);*/
25692       allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, ueCb, dlSf, ueDl->mimoInfo.cwInfo[0].cqi, TFU_DCI_FORMAT_1A, TRUE);
25693    }
25694    else
25695    {
25696       allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, ueCb, dlSf, ueDl->mimoInfo.cwInfo[0].cqi, TFU_DCI_FORMAT_1A, FALSE);
25697    }
25698    if (!(allocInfo->pdcch))
25699    {
25700       /* Returning RFAILED since PDCCH not available for any CCCH allocations */
25701       return RFAILED;
25702    }
25703
25704    /* Update allocation information */
25705    allocInfo->dciFormat = TFU_DCI_FORMAT_1A;
25706    allocInfo->raType = RG_SCH_CMN_RA_TYPE2;
25707    allocInfo->allocInfo.raType2.isLocal = TRUE;
25708
25709       /*Fix for ccpu00123918*/
25710       /* Push this harq process back to the free queue */
25711       allocInfo->allocInfo.raType2.rbStart = (U8)dlSf->type2Start;
25712       allocInfo->allocInfo.raType2.numRb = allocInfo->rbsReq;
25713       allocInfo->rbsAlloc = allocInfo->rbsReq;
25714       allocInfo->tbInfo[0].bytesAlloc = allocInfo->tbInfo[0].bytesReq;
25715       /* Update the sub-frame with new allocation */
25716       /* ccpu00129469 */
25717       /* LTE_ADV_FLAG_REMOVED_START */
25718 #ifndef LTE_TDD
25719       if (cell->lteAdvCb.sfrCfg.status == RGR_ENABLE)
25720       {
25721          rgSCHCmnNonDlfsSFRCmnChannelUpdTyp2Alloc(cell, dlSf,
25722                allocInfo->allocInfo.raType2.rbStart,
25723                allocInfo->allocInfo.raType2.numRb);
25724       }
25725       else
25726 #endif /* end of ifndef LTE_TDD*/
25727       {
25728          rgSCHCmnNonDlfsUpdTyp2Alloc(cell, dlSf, 
25729                allocInfo->allocInfo.raType2.rbStart, 
25730                allocInfo->allocInfo.raType2.numRb);
25731       }
25732
25733    /* LTE_ADV_FLAG_REMOVED_END */
25734    /* ccpu00131941 - bwAlloced is updated from SPS bandwidth */  
25735
25736
25737    return ROK;
25738 }
25739 #endif
25740
25741 /**
25742  * @brief Performs RB allocation for Msg4 for frequency non-selective cell.
25743  *
25744  * @details
25745  *
25746  *     Function : rgSCHCmnNonDlfsMsg4RbAlloc
25747  *
25748  *     Processing Steps:
25749  *     - Fetch PDCCH
25750  *     - Allocate consecutively available RBs
25751  *
25752  *  @param[in] RgSchCellCb     *cell
25753  *  @param[in] RgSchRaCb       *raCb
25754  *  @param[in] RgSchDlSf       *dlSf
25755  *  @return  S16
25756  *      -# ROK
25757  *      -# RFAILED
25758  **/
25759 #ifdef ANSI
25760 PRIVATE S16 rgSCHCmnNonDlfsMsg4RbAlloc
25761 (
25762 RgSchCellCb        *cell,
25763 RgSchRaCb          *raCb,
25764 RgSchDlSf          *dlSf
25765 )
25766 #else
25767 PRIVATE S16 rgSCHCmnNonDlfsMsg4RbAlloc(cell, raCb, dlSf)
25768 RgSchCellCb        *cell;
25769 RgSchRaCb          *raCb;
25770 RgSchDlSf          *dlSf;
25771 #endif
25772 {
25773    RgSchDlRbAlloc  *allocInfo;
25774
25775
25776    allocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_RACB(raCb);
25777
25778 #ifdef RG_5GTF
25779         RgSchSfBeamInfo  *beamInfo = &(dlSf->sfBeamInfo[0]);
25780         if(beamInfo->totVrbgAllocated > MAX_5GTF_VRBG)
25781         {
25782            RLOG_ARG1(L_ERROR ,DBG_CELLID,cell->cellId,
25783          "5GTF_ERROR : vrbg allocated > 25 :ue (%u)",
25784          raCb->ue->ueId);
25785            printf("5GTF_ERROR vrbg allocated > 25\n");
25786                 return RFAILED;
25787         }
25788 #endif
25789 #ifdef LTEMAC_SPS
25790    if ((dlSf->spsAllocdBw >= cell->spsBwRbgInfo.numRbs) &&
25791          (dlSf->bwAlloced == dlSf->bw))
25792 #else
25793    if((dlSf->bwAlloced == dlSf->bw) ||
25794             (allocInfo->rbsReq > (dlSf->bw - dlSf->bwAlloced)))
25795 #endif
25796    {
25797
25798       return RFAILED;
25799    }
25800
25801    /* DTX Changes: One Variable is passed to check whether it is DTX or Not */
25802    if (raCb->dlHqE->msg4Proc->tbInfo[0].isAckNackDtx == TFU_HQFDB_DTX)
25803    {
25804       allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, raCb->ue, dlSf, raCb->ccchCqi, TFU_DCI_FORMAT_B1, TRUE);
25805    }
25806    else
25807    {
25808       allocInfo->pdcch = rgSCHCmnPdcchAlloc(cell, raCb->ue, dlSf, raCb->ccchCqi, TFU_DCI_FORMAT_B1, FALSE);
25809    }
25810    if (!(allocInfo->pdcch))
25811    {
25812       /* Returning RFAILED since PDCCH not available for any CCCH allocations */
25813       return RFAILED;
25814    }
25815    
25816 #ifndef RG_5GTF
25817  /* SR_RACH_STATS : MSG4 TX Failed */
25818    allocInfo->pdcch->dci.u.format1aInfo.t.pdschInfo.isTBMsg4 = TRUE;
25819
25820    /* Update allocation information */
25821    allocInfo->dciFormat = TFU_DCI_FORMAT_1A;
25822    allocInfo->raType = RG_SCH_CMN_RA_TYPE2;
25823    allocInfo->allocInfo.raType2.isLocal = TRUE;
25824
25825
25826         /*Fix for ccpu00123918*/
25827         allocInfo->allocInfo.raType2.rbStart = (U8)dlSf->type2Start;
25828         allocInfo->allocInfo.raType2.numRb = allocInfo->rbsReq;
25829         /* LTE_ADV_FLAG_REMOVED_START */
25830 #ifndef LTE_TDD
25831         if (cell->lteAdvCb.sfrCfg.status == RGR_ENABLE)
25832         {
25833           rgSCHCmnNonDlfsSFRCmnChannelUpdTyp2Alloc(cell, dlSf, \
25834                 allocInfo->allocInfo.raType2.rbStart, \
25835                 allocInfo->allocInfo.raType2.numRb);
25836         }
25837         else
25838 #endif /* end of ifndef LTE_TDD */
25839         {
25840           rgSCHCmnNonDlfsUpdTyp2Alloc(cell, dlSf, \
25841                 allocInfo->allocInfo.raType2.rbStart, \
25842                 allocInfo->allocInfo.raType2.numRb);
25843         }
25844         /* LTE_ADV_FLAG_REMOVED_END */
25845
25846    allocInfo->rbsAlloc = allocInfo->rbsReq;
25847    allocInfo->tbInfo[0].bytesAlloc = allocInfo->tbInfo[0].bytesReq;
25848
25849 #else
25850
25851   allocInfo->pdcch->dci.u.format1aInfo.t.pdschInfo.isTBMsg4 = TRUE;
25852
25853         allocInfo->tbInfo[0].tbCb->dlGrnt.vrbgStart = beamInfo->vrbgStart;
25854         allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg = allocInfo->vrbgReq;
25855
25856    /* Update allocation information */
25857    allocInfo->dciFormat = TFU_DCI_FORMAT_B1;
25858
25859         allocInfo->tbInfo[0].tbCb->dlGrnt.xPDSCHRange = 1;      
25860         allocInfo->tbInfo[0].tbCb->dlGrnt.rbAssign = rgSCHCmnCalcRiv(MAX_5GTF_VRBG, 
25861          allocInfo->tbInfo[0].tbCb->dlGrnt.vrbgStart, allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg);
25862
25863    allocInfo->tbInfo[0].tbCb->dlGrnt.rbStrt = (allocInfo->tbInfo[0].tbCb->dlGrnt.vrbgStart * MAX_5GTF_VRBG_SIZE);
25864    allocInfo->tbInfo[0].tbCb->dlGrnt.numRb = (allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg * MAX_5GTF_VRBG_SIZE);
25865
25866
25867         beamInfo->vrbgStart += allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg;
25868         beamInfo->totVrbgAllocated += allocInfo->tbInfo[0].tbCb->dlGrnt.numVrbg; 
25869         allocInfo->tbInfo[0].bytesAlloc = allocInfo->tbInfo[0].bytesReq;
25870
25871 #endif
25872
25873    return ROK;
25874 }
25875
25876 /**
25877  * @brief Performs RB allocation for Msg4 lists of frequency non-selective cell.
25878  *
25879  * @details
25880  *
25881  *     Function : rgSCHCmnNonDlfsMsg4Alloc
25882  *
25883  *     Processing Steps:
25884  *     - For each element in the list, Call rgSCHCmnNonDlfsMsg4RbAlloc().
25885  *        - If allocation is successful, add the raCb to scheduled list of MSG4.
25886  *        - else, add RaCb to non-scheduled list.
25887  *
25888  *  @param[in]      RgSchCellCb         *cell
25889  *  @param[in, out] RgSchCmnMsg4RbAlloc *allocInfo
25890  *  @param[in]      U8                  isRetx
25891  *
25892  *  @return  Void
25893  **/
25894 #ifdef ANSI
25895 PRIVATE Void rgSCHCmnNonDlfsMsg4Alloc
25896 (
25897 RgSchCellCb         *cell,
25898 RgSchCmnMsg4RbAlloc *allocInfo,
25899 U8                  isRetx
25900 )
25901 #else
25902 PRIVATE Void rgSCHCmnNonDlfsMsg4Alloc(cell, allocInfo, isRetx)
25903 RgSchCellCb         *cell;
25904 RgSchCmnMsg4RbAlloc *allocInfo;
25905 U8                  isRetx;
25906 #endif
25907 {
25908    S16             ret;
25909    CmLListCp       *msg4Lst        = NULLP;
25910    CmLListCp       *schdMsg4Lst    = NULLP;
25911    CmLListCp       *nonSchdMsg4Lst = NULLP;
25912    CmLList         *schdLnkNode    = NULLP;
25913    CmLList         *toBeSchdLnk    = NULLP;
25914    RgSchDlSf       *dlSf           = allocInfo->msg4DlSf;
25915    RgSchRaCb       *raCb           = NULLP;
25916    RgSchDlHqProcCb *hqP            = NULLP;
25917
25918    if (isRetx)
25919    {
25920       /* Initialize re-transmitting lists */
25921       msg4Lst = &(allocInfo->msg4RetxLst);
25922       schdMsg4Lst = &(allocInfo->schdMsg4RetxLst);
25923       nonSchdMsg4Lst = &(allocInfo->nonSchdMsg4RetxLst);
25924    }
25925    else
25926    {
25927       /* Initialize transmitting lists */
25928       msg4Lst = &(allocInfo->msg4TxLst);
25929       schdMsg4Lst = &(allocInfo->schdMsg4TxLst);
25930       nonSchdMsg4Lst = &(allocInfo->nonSchdMsg4TxLst);
25931    }
25932
25933    /* Perform allocaations  for the list */
25934    toBeSchdLnk = cmLListFirst(msg4Lst);
25935    for (; toBeSchdLnk; toBeSchdLnk = toBeSchdLnk->next)
25936    {
25937       hqP = (RgSchDlHqProcCb *)(toBeSchdLnk->node);
25938       raCb = hqP->hqE->raCb;
25939       schdLnkNode = &hqP->schdLstLnk;
25940       RG_SCH_CMN_INIT_SCHD_LNK(schdLnkNode, hqP);
25941       ret = rgSCHCmnNonDlfsMsg4RbAlloc(cell, raCb, dlSf);
25942       if (ret != ROK)
25943       {
25944          /* Allocation failed: Add remaining MSG4 nodes to non-scheduled
25945           * list and return */
25946          do
25947          {
25948             hqP = (RgSchDlHqProcCb *)(toBeSchdLnk->node);
25949             raCb = hqP->hqE->raCb;
25950             schdLnkNode = &hqP->schdLstLnk;
25951             RG_SCH_CMN_INIT_SCHD_LNK(schdLnkNode, hqP);
25952             cmLListAdd2Tail(nonSchdMsg4Lst, schdLnkNode);
25953             toBeSchdLnk = toBeSchdLnk->next;
25954          } while(toBeSchdLnk);
25955          RETVOID;
25956       }
25957
25958       /* Allocation successful: Add UE to the scheduled list */
25959       cmLListAdd2Tail(schdMsg4Lst, schdLnkNode);
25960       if (isRetx)
25961       {
25962       }
25963    }
25964
25965
25966    RETVOID;
25967 }
25968
25969 /**
25970  * @brief Performs RB allocation for the list of UEs of a frequency
25971  * non-selective cell.
25972  *
25973  * @details
25974  *
25975  *     Function : rgSCHCmnNonDlfsDedRbAlloc
25976  *
25977  *     Processing Steps:
25978  *     - For each element in the list, Call rgSCHCmnNonDlfsUeRbAlloc().
25979  *        - If allocation is successful, add the ueCb to scheduled list of UEs.
25980  *        - else, add ueCb to non-scheduled list of UEs.
25981  *
25982  *  @param[in]      RgSchCellCb        *cell
25983  *  @param[in, out] RgSchCmnUeRbAlloc  *allocInfo
25984  *  @param[in]      CmLListCp          *ueLst,
25985  *  @param[in, out] CmLListCp          *schdHqPLst,
25986  *  @param[in, out] CmLListCp          *nonSchdHqPLst
25987  *
25988  *  @return  Void
25989  **/
25990 #ifdef ANSI
25991 Void rgSCHCmnNonDlfsDedRbAlloc
25992 (
25993 RgSchCellCb        *cell,
25994 RgSchCmnUeRbAlloc  *allocInfo,
25995 CmLListCp          *ueLst,
25996 CmLListCp          *schdHqPLst,
25997 CmLListCp          *nonSchdHqPLst
25998 )
25999 #else
26000 Void rgSCHCmnNonDlfsDedRbAlloc(cell, allocInfo, ueLst,
26001         schdHqPLst, nonSchdHqPLst)
26002 RgSchCellCb        *cell;
26003 RgSchCmnUeRbAlloc  *allocInfo;
26004 CmLListCp          *ueLst;
26005 CmLListCp          *schdHqPLst;
26006 CmLListCp          *nonSchdHqPLst;
26007 #endif
26008 {
26009    S16             ret;
26010    CmLList         *schdLnkNode  = NULLP;
26011    CmLList         *toBeSchdLnk  = NULLP;
26012    RgSchDlSf       *dlSf         = allocInfo->dedDlSf;
26013    RgSchUeCb       *ue           = NULLP;
26014    RgSchDlHqProcCb *hqP          = NULLP;
26015    U8              isDlBwAvail;
26016
26017
26018    /* Perform allocaations  for the list */
26019    toBeSchdLnk = cmLListFirst(ueLst);
26020    for (; toBeSchdLnk; toBeSchdLnk = toBeSchdLnk->next)
26021    {
26022       hqP = (RgSchDlHqProcCb *)(toBeSchdLnk->node);
26023       ue = hqP->hqE->ue;
26024       schdLnkNode = &hqP->schdLstLnk;
26025       RG_SCH_CMN_INIT_SCHD_LNK(schdLnkNode, hqP);
26026
26027       ret = rgSCHCmnNonDlfsUeRbAlloc(cell, ue, dlSf, &isDlBwAvail);
26028       if (!isDlBwAvail)
26029       {
26030          /* Allocation failed: Add remaining UEs to non-scheduled
26031           * list and return */
26032          do
26033          {
26034             hqP = (RgSchDlHqProcCb *)(toBeSchdLnk->node);
26035             ue = hqP->hqE->ue;
26036             schdLnkNode = &hqP->schdLstLnk;
26037             RG_SCH_CMN_INIT_SCHD_LNK(schdLnkNode, hqP);
26038             cmLListAdd2Tail(nonSchdHqPLst, schdLnkNode);
26039             toBeSchdLnk = toBeSchdLnk->next;
26040          } while(toBeSchdLnk);
26041          break; 
26042       }
26043
26044       if (ret == ROK)
26045       {
26046 #if defined (TENB_STATS) && defined (RG_5GTF)
26047          cell->tenbStats->sch.dl5gtfRbAllocPass++;
26048 #endif
26049          /* Allocation successful: Add UE to the scheduled list */
26050          cmLListAdd2Tail(schdHqPLst, schdLnkNode);
26051       }
26052       else
26053       {
26054 #if defined (TENB_STATS) && defined (RG_5GTF)
26055          cell->tenbStats->sch.dl5gtfRbAllocFail++;
26056 #endif
26057          /* Allocation failed : Add UE to the non-scheduled list */
26058                         printf("5GTF_ERROR Dl rb alloc failed adding nonSchdHqPLst\n");
26059          cmLListAdd2Tail(nonSchdHqPLst, schdLnkNode);
26060       }
26061    }
26062
26063    RETVOID;
26064 }
26065
26066 /**
26067  * @brief Handles RB allocation for frequency non-selective cell.
26068  *
26069  * @details
26070  *
26071  *     Function : rgSCHCmnNonDlfsRbAlloc
26072  *
26073  *     Invoking Module Processing:
26074  *      - SCH shall invoke this if downlink frequency selective is disabled for
26075  *        the cell for RB allocation.
26076  *      - MAX C/I/PFS/RR shall provide the requiredBytes, required RBs
26077  *        estimate and subframe for each allocation to be made to SCH.
26078  *
26079  *     Processing Steps:
26080  *     - Allocate sequentially for common channels.
26081  *     - For transmitting and re-transmitting UE list.
26082  *      - For each UE:
26083  *       - Perform wide-band allocations for UE in increasing order of
26084  *         frequency.
26085  *       - Determine Imcs for the allocation.
26086  *       - Determine RA type.
26087  *       - Determine DCI format.
26088  *
26089  *  @param[in]  RgSchCellCb        *cell
26090  *  @param[in]  RgSchCmnDlRbAllocInfo *allocInfo
26091  *  @return  Void
26092  **/
26093
26094 #ifdef ANSI
26095 Void rgSCHCmnNonDlfsRbAlloc
26096 (
26097 RgSchCellCb           *cell,
26098 RgSchCmnDlRbAllocInfo *allocInfo
26099 )
26100 #else
26101 Void rgSCHCmnNonDlfsRbAlloc(cell, allocInfo)
26102 RgSchCellCb           *cell;
26103 RgSchCmnDlRbAllocInfo *allocInfo;
26104 #endif
26105 {
26106    U8                 raRspCnt = 0;
26107    RgSchDlRbAlloc     *reqAllocInfo;
26108
26109    /* Allocate for MSG4 retransmissions */
26110    if (allocInfo->msg4Alloc.msg4RetxLst.count)
26111    {
26112       printf("5GTF_ERROR rgSCHCmnNonDlfsMsg4Alloc RetxLst\n");
26113       rgSCHCmnNonDlfsMsg4Alloc(cell, &(allocInfo->msg4Alloc), TRUE);
26114    }
26115
26116    /* Allocate for MSG4 transmissions */
26117    /* Assuming all the nodes in the list need allocations: rbsReq is valid */
26118    if (allocInfo->msg4Alloc.msg4TxLst.count)
26119    {
26120       printf("5GTF_ERROR rgSCHCmnNonDlfsMsg4Alloc txLst\n");
26121       rgSCHCmnNonDlfsMsg4Alloc(cell, &(allocInfo->msg4Alloc), FALSE);
26122    }
26123 #ifdef RGR_V1
26124    /* Allocate for CCCH SDU (received after guard timer expiry)
26125     * retransmissions */
26126    if (allocInfo->ccchSduAlloc.ccchSduRetxLst.count)
26127    {
26128       printf("5GTF_ERROR rgSCHCmnNonDlfsCcchSduAlloc\n");
26129       rgSCHCmnNonDlfsCcchSduAlloc(cell, &(allocInfo->ccchSduAlloc), TRUE);
26130    }
26131
26132    /* Allocate for CCCD SDU transmissions */
26133    /* Allocate for CCCH SDU (received after guard timer expiry) transmissions */
26134    if (allocInfo->ccchSduAlloc.ccchSduTxLst.count)
26135    {
26136       printf("5GTF_ERROR rgSCHCmnNonDlfsCcchSduAlloc\n");
26137       rgSCHCmnNonDlfsCcchSduAlloc(cell, &(allocInfo->ccchSduAlloc), FALSE);
26138    }
26139 #endif
26140
26141    /* Allocate for Random access response */
26142    for (raRspCnt = 0; raRspCnt < RG_SCH_CMN_MAX_CMN_PDCCH; ++raRspCnt)
26143    {
26144       /* Assuming that the requests will be filled in sequentially */
26145       reqAllocInfo = &(allocInfo->raRspAlloc[raRspCnt]);
26146       if (!reqAllocInfo->rbsReq)
26147       {
26148          break;
26149       }
26150       printf("5GTF_ERROR calling RAR rgSCHCmnNonDlfsCmnRbAlloc\n");
26151    //   if ((rgSCHCmnNonDlfsCmnRbAlloc(cell, reqAllocInfo)) != ROK)
26152       if ((rgSCHCmnNonDlfsCmnRbAllocRar(cell, reqAllocInfo)) != ROK)
26153       {
26154          break;
26155       }
26156    }
26157
26158    /* Allocate for RETX+TX UEs */
26159    if(allocInfo->dedAlloc.txRetxHqPLst.count)
26160    {
26161       printf("5GTF_ERROR TX RETX rgSCHCmnNonDlfsDedRbAlloc\n");
26162       rgSCHCmnNonDlfsDedRbAlloc(cell, &(allocInfo->dedAlloc),
26163             &(allocInfo->dedAlloc.txRetxHqPLst),
26164             &(allocInfo->dedAlloc.schdTxRetxHqPLst),
26165             &(allocInfo->dedAlloc.nonSchdTxRetxHqPLst));
26166    }
26167
26168    if((allocInfo->dedAlloc.retxHqPLst.count))
26169    {
26170       rgSCHCmnNonDlfsDedRbAlloc(cell, &(allocInfo->dedAlloc),
26171             &(allocInfo->dedAlloc.retxHqPLst),
26172             &(allocInfo->dedAlloc.schdRetxHqPLst),
26173             &(allocInfo->dedAlloc.nonSchdRetxHqPLst));
26174    }
26175
26176    /* Allocate for transmitting UEs */
26177    if((allocInfo->dedAlloc.txHqPLst.count))
26178    {
26179       rgSCHCmnNonDlfsDedRbAlloc(cell, &(allocInfo->dedAlloc),
26180             &(allocInfo->dedAlloc.txHqPLst),
26181             &(allocInfo->dedAlloc.schdTxHqPLst),
26182             &(allocInfo->dedAlloc.nonSchdTxHqPLst));
26183    }
26184    {
26185       RgSchCmnCell  *cmnCell = RG_SCH_CMN_GET_CELL(cell);
26186       if ((allocInfo->dedAlloc.txRetxHqPLst.count + 
26187                allocInfo->dedAlloc.retxHqPLst.count + 
26188                allocInfo->dedAlloc.txHqPLst.count) > 
26189             cmnCell->dl.maxUePerDlSf)
26190       {
26191 #ifndef ALIGN_64BIT
26192          RGSCHDBGERRNEW(cell->instIdx,(rgSchPBuf(cell->instIdx),"UEs selected by"
26193                   " scheduler exceed maximumUePerDlSf(%u)tx-retx %ld retx %ld tx %ld\n",
26194                   cmnCell->dl.maxUePerDlSf, allocInfo->dedAlloc.txRetxHqPLst.count,
26195                   allocInfo->dedAlloc.retxHqPLst.count,
26196                   allocInfo->dedAlloc.txHqPLst.count));
26197 #else
26198          RGSCHDBGERRNEW(cell->instIdx,(rgSchPBuf(cell->instIdx),"UEs selected by"
26199                   " scheduler exceed maximumUePerDlSf(%u)tx-retx %d retx %d tx %d\n",
26200                   cmnCell->dl.maxUePerDlSf, allocInfo->dedAlloc.txRetxHqPLst.count,
26201                   allocInfo->dedAlloc.retxHqPLst.count,
26202                   allocInfo->dedAlloc.txHqPLst.count));
26203 #endif
26204       }
26205    }
26206 #ifndef LTE_TDD
26207    /* LTE_ADV_FLAG_REMOVED_START */
26208    if(cell->lteAdvCb.dsfrCfg.status == RGR_ENABLE)
26209    {    
26210       printf("5GTF_ERROR RETX rgSCHCmnNonDlfsDsfrRntpComp\n");
26211       rgSCHCmnNonDlfsDsfrRntpComp(cell, allocInfo->dedAlloc.dedDlSf); 
26212    }  
26213    /* LTE_ADV_FLAG_REMOVED_END */
26214 #endif /* LTE_TDD */
26215    RETVOID;
26216 }
26217
26218 /***********************************************************
26219  *
26220  *     Func : rgSCHCmnCalcRiv
26221  *
26222  *     Desc : This function calculates RIV.
26223  *
26224  *     Ret  : None.
26225  *
26226  *     Notes: None.
26227  *
26228  *     File : rg_sch_utl.c
26229  *
26230  **********************************************************/
26231 #ifdef LTEMAC_SPS
26232 #ifdef ANSI
26233 U32 rgSCHCmnCalcRiv
26234 (
26235 U8           bw,
26236 U8           rbStart,
26237 U8           numRb
26238 )
26239 #else
26240 U32 rgSCHCmnCalcRiv(bw, rbStart, numRb)
26241 U8           bw;
26242 U8           rbStart;
26243 U8           numRb;
26244 #endif
26245 #else
26246 #ifdef ANSI
26247 U32 rgSCHCmnCalcRiv
26248 (
26249 U8           bw,
26250 U8           rbStart,
26251 U8           numRb
26252 )
26253 #else
26254 U32 rgSCHCmnCalcRiv(bw, rbStart, numRb)
26255 U8           bw;
26256 U8           rbStart;
26257 U8           numRb;
26258 #endif
26259 #endif
26260 {
26261    U8           numRbMinus1 = numRb - 1;
26262    U32          riv;
26263
26264
26265    if (numRbMinus1 <= bw/2)
26266    {
26267       riv = bw * numRbMinus1 + rbStart;
26268    }
26269    else
26270    {
26271       riv = bw * (bw - numRbMinus1) + (bw - rbStart - 1);
26272    }
26273    return (riv);
26274 } /* rgSCHCmnCalcRiv */
26275
26276 #ifdef LTE_TDD
26277 /**
26278  * @brief This function allocates and copies the RACH response scheduling
26279  *        related information into cell control block.
26280  *
26281  * @details
26282  *
26283  *     Function: rgSCHCmnDlCpyRachInfo
26284  *     Purpose:  This function allocates and copies the RACH response
26285  *               scheduling related information into cell control block
26286  *               for each DL subframe.
26287  *
26288  *
26289  *     Invoked by: Scheduler
26290  *
26291  *  @param[in]  RgSchCellCb*           cell
26292  *  @param[in]  RgSchTddRachRspLst     rachRspLst[][RGSCH_NUM_SUB_FRAMES]
26293  *  @param[in]  U8                     raArrSz
26294  *  @return     S16
26295  *
26296  **/
26297 #ifdef ANSI
26298 PRIVATE S16 rgSCHCmnDlCpyRachInfo
26299 (
26300 RgSchCellCb                *cell,
26301 RgSchTddRachRspLst         rachRspLst[][RGSCH_NUM_SUB_FRAMES],
26302 U8                         raArrSz
26303 )
26304 #else
26305 PRIVATE S16 rgSCHCmnDlCpyRachInfo(cell, rachRspLst, raArrSz)
26306 RgSchCellCb                *cell;
26307 RgSchTddRachRspLst         rachRspLst[][RGSCH_NUM_SUB_FRAMES];
26308 U8                         raArrSz;
26309 #endif
26310 {
26311    U8                   ulDlCfgIdx = cell->ulDlCfgIdx;
26312    U8                   sfNum;
26313    S16                  sfnIdx;
26314    U16                  subfrmIdx;
26315    U8                   numRfs;
26316    U8                   numSubfrms;
26317    U8                   sfcount;
26318    S16                   ret;
26319
26320
26321    /* Allocate RACH response information for each DL
26322     * subframe in a radio frame */
26323    ret = rgSCHUtlAllocSBuf(cell->instIdx, (Data **)&cell->rachRspLst,
26324          rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][RGSCH_NUM_SUB_FRAMES-1] *
26325          sizeof(RgSchTddRachRspLst));
26326    if (ret != ROK)
26327    {
26328       return (ret);
26329    }
26330
26331    for(sfnIdx=raArrSz-1; sfnIdx>=0; sfnIdx--)
26332    {
26333       for(subfrmIdx=0; subfrmIdx < RGSCH_NUM_SUB_FRAMES; subfrmIdx++)
26334       {
26335          subfrmIdx = rgSchTddHighDlSubfrmIdxTbl[ulDlCfgIdx][subfrmIdx];
26336          if(subfrmIdx == RGSCH_NUM_SUB_FRAMES)
26337          {
26338             break;
26339          }
26340
26341          RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rachRspLst[sfnIdx],subfrmIdx);
26342          numSubfrms =
26343             rachRspLst[sfnIdx][subfrmIdx].rachRsp[0].numSubfrms;
26344
26345          RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, rgSchTddNumDlSubfrmTbl[ulDlCfgIdx],subfrmIdx);
26346          sfNum = rgSchTddNumDlSubfrmTbl[ulDlCfgIdx][subfrmIdx]-1;
26347          numRfs = cell->rachRspLst[sfNum].numRadiofrms;
26348          /* For each DL subframe in which RACH response can
26349           * be sent is updated */
26350          if(numSubfrms > 0)
26351          {
26352             cell->rachRspLst[sfNum].rachRsp[numRfs].sfnOffset =
26353                rachRspLst[sfnIdx][subfrmIdx].rachRsp[0].sfnOffset;
26354             for(sfcount=0; sfcount < numSubfrms; sfcount++)
26355             {
26356                cell->rachRspLst[sfNum].rachRsp[numRfs].\
26357                   subframe[sfcount] =
26358                   rachRspLst[sfnIdx][subfrmIdx].rachRsp[0].\
26359                   subframe[sfcount];
26360             }
26361             cell->rachRspLst[sfNum].rachRsp[numRfs].numSubfrms =
26362                rachRspLst[sfnIdx][subfrmIdx].rachRsp[0].numSubfrms;
26363             cell->rachRspLst[sfNum].numRadiofrms++;
26364          }
26365
26366          /* Copy the subframes to be deleted at ths subframe */
26367          numSubfrms =
26368             rachRspLst[sfnIdx][subfrmIdx].delInfo.numSubfrms;
26369          if(numSubfrms > 0)
26370          {
26371             cell->rachRspLst[sfNum].delInfo.sfnOffset =
26372                rachRspLst[sfnIdx][subfrmIdx].delInfo.sfnOffset;
26373             for(sfcount=0; sfcount < numSubfrms; sfcount++)
26374             {
26375                cell->rachRspLst[sfNum].delInfo.subframe[sfcount] =
26376                   rachRspLst[sfnIdx][subfrmIdx].delInfo.subframe[sfcount];
26377             }
26378             cell->rachRspLst[sfNum].delInfo.numSubfrms =
26379                rachRspLst[sfnIdx][subfrmIdx].delInfo.numSubfrms;
26380          }
26381       }
26382    }
26383    return ROK;
26384 }
26385 #endif
26386 /**
26387  * @brief This function determines the iTbs based on the new CFI, 
26388  *        CQI and BLER based delta iTbs 
26389  *
26390  * @details
26391  *
26392  *     Function: rgSchCmnFetchItbs
26393  *     Purpose:  Fetch the new iTbs when CFI changes.
26394  *
26395  *  @param[in]  RgSchCellCb           *cell
26396  *  @param[in]  RgSchCmnDlUe          *ueDl
26397  *  @param[in]  U8                    cqi
26398  *
26399  *  @return S32 iTbs
26400  *
26401  **/
26402 #ifdef LTE_TDD
26403 #ifdef ANSI
26404 PRIVATE S32 rgSchCmnFetchItbs 
26405 (
26406 RgSchCellCb        *cell,
26407 RgSchCmnDlUe       *ueDl,
26408 RgSchDlSf          *subFrm,
26409 U8                 cqi,
26410 U8                 cfi,
26411 U8                 cwIdx,
26412 U8                 noLyr
26413 )
26414 #else
26415 PRIVATE S32 rgSchCmnFetchItbs (cell, ueDl, subFrm, cqi, cfi, cwIdx, noLyr)
26416 RgSchCellCb        *cell;
26417 RgSchCmnDlUe       *ueDl; 
26418 RgSchDlSf          *subFrm;
26419 U8                 cqi;
26420 U8                 cfi;
26421 U8                 cwIdx;
26422 U8                 noLyr;
26423 #endif
26424 #else
26425 #ifdef ANSI
26426 PRIVATE S32 rgSchCmnFetchItbs 
26427 (
26428 RgSchCellCb        *cell,
26429 RgSchCmnDlUe       *ueDl,
26430 U8                 cqi,
26431 U8                 cfi,
26432 U8                 cwIdx,
26433 U8                 noLyr
26434 )
26435 #else
26436 PRIVATE S32 rgSchCmnFetchItbs (cell, ueDl, cqi, cfi, cwIdx, noLyr)
26437 RgSchCellCb        *cell;
26438 RgSchCmnDlUe       *ueDl; 
26439 U8                 cqi;
26440 U8                 cfi;
26441 U8                 cwIdx;
26442 U8                 noLyr;
26443 #endif 
26444 #endif
26445 {
26446
26447    RgSchCmnDlCell *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
26448    S32 iTbs = 0;
26449
26450
26451 #ifdef LTE_TDD      
26452    /* Special Handling for Spl Sf when CFI is 3 as 
26453     * CFI in Spl Sf will be max 2 */
26454    if(subFrm->sfType == RG_SCH_SPL_SF_DATA) 
26455    {
26456       if((cellDl->currCfi == 3) || 
26457             ((cell->bwCfg.dlTotalBw <= 10) && (cellDl->currCfi == 1)))
26458       {    
26459          /* Use CFI 2 in this case */
26460          iTbs = (ueDl->laCb[cwIdx].deltaiTbs + 
26461                ((*(RgSchCmnCqiToTbs *)(cellDl->cqiToTbsTbl[0][2]))[cqi])* 100)/100;
26462
26463          RG_SCH_CHK_ITBS_RANGE(iTbs, RGSCH_NUM_ITBS - 1);
26464       }
26465       else
26466       {
26467          iTbs = ueDl->mimoInfo.cwInfo[cwIdx].iTbs[noLyr - 1];
26468       }
26469       iTbs = RGSCH_MIN(iTbs, cell->thresholds.maxDlItbs);
26470    }   
26471    else /* CFI Changed. Update with new iTbs Reset the BLER*/
26472 #endif         
26473    {
26474       S32 tmpiTbs  = (*(RgSchCmnCqiToTbs *)(cellDl->cqiToTbsTbl[0][cfi]))[cqi];
26475       
26476       iTbs = (ueDl->laCb[cwIdx].deltaiTbs + tmpiTbs*100)/100;
26477
26478       RG_SCH_CHK_ITBS_RANGE(iTbs, tmpiTbs);     
26479
26480       iTbs = RGSCH_MIN(iTbs, cell->thresholds.maxDlItbs);
26481
26482       ueDl->mimoInfo.cwInfo[cwIdx].iTbs[noLyr - 1] = iTbs;
26483
26484       ueDl->lastCfi = cfi;
26485       ueDl->laCb[cwIdx].deltaiTbs = 0;
26486    }
26487
26488    return (iTbs);
26489
26490 \f
26491 /**
26492  * @brief This function determines the RBs and Bytes required for BO
26493  *        transmission for UEs configured with TM 1/2/6/7.
26494  *
26495  * @details
26496  *
26497  *     Function: rgSCHCmnDlAllocTxRb1Tb1Cw
26498  *     Purpose:  Allocate TB1 on CW1.
26499  *
26500  *               Reference Parameter effBo is filled with alloced bytes.
26501  *               Returns RFAILED if BO not satisfied at all.
26502  *
26503  *     Invoked by: rgSCHCmnDlAllocTxRbTM1/2/6/7
26504  *
26505  *  @param[in]  RgSchCellCb           *cell
26506  *  @param[in]  RgSchDlSf             *subFrm
26507  *  @param[in]  RgSchUeCb             *ue
26508  *  @param[in]  U32                   bo
26509  *  @param[out] U32                   *effBo
26510  *  @param[in]  RgSchDlHqProcCb       *proc
26511  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
26512  *  @return  Void
26513  *
26514  **/
26515 #ifdef ANSI
26516 PRIVATE Void rgSCHCmnDlAllocTxRb1Tb1Cw
26517 (
26518 RgSchCellCb                *cell,
26519 RgSchDlSf                  *subFrm,
26520 RgSchUeCb                  *ue,
26521 U32                        bo,
26522 U32                        *effBo,
26523 RgSchDlHqProcCb            *proc,
26524 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
26525 )
26526 #else
26527 PRIVATE Void rgSCHCmnDlAllocTxRb1Tb1Cw(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
26528 RgSchCellCb                *cell;
26529 RgSchDlSf                  *subFrm;
26530 RgSchUeCb                  *ue;
26531 U32                        bo;
26532 U32                        *effBo;
26533 RgSchDlHqProcCb            *proc;
26534 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
26535 #endif
26536 {
26537    RgSchDlRbAlloc   *allocInfo;
26538    S16              ret;
26539    U8               numRb;
26540
26541    ret = ROK;
26542    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
26543 #ifdef RG_5GTF
26544    if (ue->ue5gtfCb.rank == 2)
26545    {
26546       allocInfo->dciFormat = TFU_DCI_FORMAT_B2;
26547    }
26548    else
26549    {
26550       allocInfo->dciFormat = TFU_DCI_FORMAT_B1;
26551    }
26552 #else
26553    allocInfo->dciFormat = rgSCHCmnSlctPdcchFrmt(cell, ue, \
26554          allocInfo->raType);
26555 #endif
26556    ret = rgSCHCmnDlAlloc1CwTxRb(cell, subFrm, ue, &proc->tbInfo[0],\
26557          bo, &numRb, effBo);
26558    if (ret == RFAILED)
26559    {
26560       /* If allocation couldn't be made then return */
26561       RETVOID;
26562    }
26563    /* Adding UE to RbAllocInfo TX Lst */
26564    rgSCHCmnDlRbInfoAddUeTx(cell, cellWdAllocInfo, ue, proc);
26565    /* Fill UE alloc Info */
26566    allocInfo->rbsReq = numRb;
26567    allocInfo->dlSf   = subFrm;
26568 #ifdef RG_5GTF
26569    allocInfo->vrbgReq = numRb/MAX_5GTF_VRBG_SIZE;
26570 #endif
26571
26572    RETVOID;
26573 }
26574
26575 \f
26576 /**
26577  * @brief This function determines the RBs and Bytes required for BO
26578  *        retransmission for UEs configured with TM 1/2/6/7.
26579  *
26580  * @details
26581  *
26582  *     Function: rgSCHCmnDlAllocRetxRb1Tb1Cw
26583  *     Purpose:  Allocate TB1 on CW1.
26584  *
26585  *               Reference Parameter effBo is filled with alloced bytes.
26586  *               Returns RFAILED if BO not satisfied at all.
26587  *
26588  *     Invoked by: rgSCHCmnDlAllocRetxRbTM1/2/6/7
26589  *
26590  *  @param[in]  RgSchCellCb           *cell
26591  *  @param[in]  RgSchDlSf             *subFrm
26592  *  @param[in]  RgSchUeCb             *ue
26593  *  @param[in]  U32                   bo
26594  *  @param[out] U32                   *effBo
26595  *  @param[in]  RgSchDlHqProcCb       *proc
26596  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
26597  *  @return  Void
26598  *
26599  **/
26600 #ifdef ANSI
26601 PRIVATE Void rgSCHCmnDlAllocRetxRb1Tb1Cw
26602 (
26603 RgSchCellCb                *cell,
26604 RgSchDlSf                  *subFrm,
26605 RgSchUeCb                  *ue,
26606 U32                        bo,
26607 U32                        *effBo,
26608 RgSchDlHqProcCb            *proc,
26609 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
26610 )
26611 #else
26612 PRIVATE Void rgSCHCmnDlAllocRetxRb1Tb1Cw(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
26613 RgSchCellCb                *cell;
26614 RgSchDlSf                  *subFrm;
26615 RgSchUeCb                  *ue;
26616 U32                        bo;
26617 U32                        *effBo;
26618 RgSchDlHqProcCb            *proc;
26619 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
26620 #endif
26621 {
26622    RgSchDlRbAlloc   *allocInfo;
26623    S16              ret;
26624    U8               numRb;
26625
26626    ret = ROK;
26627    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
26628
26629 #ifndef RG_5GTF
26630    /* 5GTF: RETX DCI format same as TX */
26631    allocInfo->dciFormat = rgSCHCmnSlctPdcchFrmt(cell, ue, \
26632       &allocInfo->raType);
26633 #endif
26634
26635    /* Get the Allocation in terms of RBs that are required for
26636     * this retx of TB1 */
26637    ret = rgSCHCmnDlAlloc1CwRetxRb(cell, subFrm, ue, &proc->tbInfo[0],
26638          1, &numRb, effBo);
26639    if (ret == RFAILED)
26640    {
26641       /* Allocation couldn't be made for Retx */
26642       /* Fix : syed If TxRetx allocation failed then add the UE along with the proc
26643        * to the nonSchdTxRetxUeLst and let spfc scheduler take care of it during
26644        * finalization. */        
26645       rgSCHCmnDlAdd2NonSchdRetxLst(cellWdAllocInfo, ue, proc);
26646       RETVOID;
26647    }
26648    rgSCHCmnDlRbInfoAddUeRetx(cell, cellWdAllocInfo, ue, proc);
26649    /* Fill UE alloc Info */
26650    allocInfo->rbsReq = numRb;
26651    allocInfo->dlSf   = subFrm;
26652 #ifdef RG_5GTF
26653    allocInfo->vrbgReq = numRb/MAX_5GTF_VRBG_SIZE;
26654 #endif
26655
26656    RETVOID;
26657 }
26658
26659 \f
26660 /**
26661  * @brief This function determines the RBs and Bytes required for BO
26662  *        transmission for UEs configured with TM 2.
26663  *
26664  * @details
26665  *
26666  *     Function: rgSCHCmnDlAllocTxRbTM1
26667  *     Purpose:
26668  *
26669  *               Reference Parameter effBo is filled with alloced bytes.
26670  *               Returns RFAILED if BO not satisfied at all.
26671  *
26672  *     Invoked by: rgSCHCmnDlAllocTxRb
26673  *
26674  *  @param[in]  RgSchCellCb           *cell
26675  *  @param[in]  RgSchDlSf             *subFrm
26676  *  @param[in]  RgSchUeCb             *ue
26677  *  @param[in]  U32                   bo
26678  *  @param[out] U32                   *effBo
26679  *  @param[in]  RgSchDlHqProcCb       *proc
26680  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
26681  *  @return Void
26682  *
26683  **/
26684 #ifdef ANSI
26685 PRIVATE Void rgSCHCmnDlAllocTxRbTM1
26686 (
26687 RgSchCellCb                *cell,
26688 RgSchDlSf                  *subFrm,
26689 RgSchUeCb                  *ue,
26690 U32                        bo,
26691 U32                        *effBo,
26692 RgSchDlHqProcCb            *proc,
26693 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
26694 )
26695 #else
26696 PRIVATE Void rgSCHCmnDlAllocTxRbTM1(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
26697 RgSchCellCb                *cell;
26698 RgSchDlSf                  *subFrm;
26699 RgSchUeCb                  *ue;
26700 U32                        bo;
26701 U32                        *effBo;
26702 RgSchDlHqProcCb            *proc;
26703 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
26704 #endif
26705 {
26706    rgSCHCmnDlAllocTxRb1Tb1Cw(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo);
26707    RETVOID;
26708 }
26709
26710 \f
26711 /**
26712  * @brief This function determines the RBs and Bytes required for BO
26713  *        retransmission for UEs configured with TM 2.
26714  *
26715  * @details
26716  *
26717  *     Function: rgSCHCmnDlAllocRetxRbTM1
26718  *     Purpose:
26719  *
26720  *               Reference Parameter effBo is filled with alloced bytes.
26721  *               Returns RFAILED if BO not satisfied at all.
26722  *
26723  *     Invoked by: rgSCHCmnDlAllocRetxRb
26724  *
26725  *  @param[in]  RgSchCellCb           *cell
26726  *  @param[in]  RgSchDlSf             *subFrm
26727  *  @param[in]  RgSchUeCb             *ue
26728  *  @param[in]  U32                   bo
26729  *  @param[out] U32                   *effBo
26730  *  @param[in]  RgSchDlHqProcCb       *proc
26731  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
26732  *  @return Void
26733  *
26734  **/
26735 #ifdef ANSI
26736 PRIVATE Void rgSCHCmnDlAllocRetxRbTM1
26737 (
26738 RgSchCellCb                *cell,
26739 RgSchDlSf                  *subFrm,
26740 RgSchUeCb                  *ue,
26741 U32                        bo,
26742 U32                        *effBo,
26743 RgSchDlHqProcCb            *proc,
26744 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
26745 )
26746 #else
26747 PRIVATE Void rgSCHCmnDlAllocRetxRbTM1(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
26748 RgSchCellCb                *cell;
26749 RgSchDlSf                  *subFrm;
26750 RgSchUeCb                  *ue;
26751 U32                        bo;
26752 U32                        *effBo;
26753 RgSchDlHqProcCb            *proc;
26754 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
26755 #endif
26756 {
26757    rgSCHCmnDlAllocRetxRb1Tb1Cw(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo);
26758    RETVOID;
26759 }
26760
26761 \f
26762 /**
26763  * @brief This function determines the RBs and Bytes required for BO
26764  *        transmission for UEs configured with TM 2.
26765  *
26766  * @details
26767  *
26768  *     Function: rgSCHCmnDlAllocTxRbTM2
26769  *     Purpose:
26770  *
26771  *               Reference Parameter effBo is filled with alloced bytes.
26772  *               Returns RFAILED if BO not satisfied at all.
26773  *
26774  *     Invoked by: rgSCHCmnDlAllocTxRb
26775  *
26776  *  @param[in]  RgSchCellCb           *cell
26777  *  @param[in]  RgSchDlSf             *subFrm
26778  *  @param[in]  RgSchUeCb             *ue
26779  *  @param[in]  U32                   bo
26780  *  @param[out] U32                   *effBo
26781  *  @param[in]  RgSchDlHqProcCb       *proc
26782  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
26783  *  @return Void
26784  *
26785  **/
26786 #ifdef ANSI
26787 PRIVATE Void rgSCHCmnDlAllocTxRbTM2
26788 (
26789 RgSchCellCb                *cell,
26790 RgSchDlSf                  *subFrm,
26791 RgSchUeCb                  *ue,
26792 U32                        bo,
26793 U32                        *effBo,
26794 RgSchDlHqProcCb            *proc,
26795 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
26796 )
26797 #else
26798 PRIVATE Void rgSCHCmnDlAllocTxRbTM2(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
26799 RgSchCellCb                *cell;
26800 RgSchDlSf                  *subFrm;
26801 RgSchUeCb                  *ue;
26802 U32                        bo;
26803 U32                        *effBo;
26804 RgSchDlHqProcCb            *proc;
26805 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
26806 #endif
26807 {
26808    rgSCHCmnDlAllocTxRb1Tb1Cw(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo);
26809    RETVOID;
26810 }
26811
26812 \f
26813 /**
26814  * @brief This function determines the RBs and Bytes required for BO
26815  *        retransmission for UEs configured with TM 2.
26816  *
26817  * @details
26818  *
26819  *     Function: rgSCHCmnDlAllocRetxRbTM2
26820  *     Purpose:
26821  *
26822  *               Reference Parameter effBo is filled with alloced bytes.
26823  *               Returns RFAILED if BO not satisfied at all.
26824  *
26825  *     Invoked by: rgSCHCmnDlAllocRetxRb
26826  *
26827  *  @param[in]  RgSchCellCb           *cell
26828  *  @param[in]  RgSchDlSf             *subFrm
26829  *  @param[in]  RgSchUeCb             *ue
26830  *  @param[in]  U32                   bo
26831  *  @param[out] U32                   *effBo
26832  *  @param[in]  RgSchDlHqProcCb       *proc
26833  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
26834  *  @return Void
26835  *
26836  **/
26837 #ifdef ANSI
26838 PRIVATE Void rgSCHCmnDlAllocRetxRbTM2
26839 (
26840 RgSchCellCb                *cell,
26841 RgSchDlSf                  *subFrm,
26842 RgSchUeCb                  *ue,
26843 U32                        bo,
26844 U32                        *effBo,
26845 RgSchDlHqProcCb            *proc,
26846 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
26847 )
26848 #else
26849 PRIVATE Void rgSCHCmnDlAllocRetxRbTM2(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
26850 RgSchCellCb                *cell;
26851 RgSchDlSf                  *subFrm;
26852 RgSchUeCb                  *ue;
26853 U32                        bo;
26854 U32                        *effBo;
26855 RgSchDlHqProcCb            *proc;
26856 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
26857 #endif
26858 {
26859    rgSCHCmnDlAllocRetxRb1Tb1Cw(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo);
26860    RETVOID;
26861 }
26862
26863 \f
26864 /**
26865  * @brief This function determines the RBs and Bytes required for BO
26866  *        transmission for UEs configured with TM 3.
26867  *
26868  * @details
26869  *
26870  *     Function: rgSCHCmnDlAllocTxRbTM3
26871  *     Purpose:
26872  *
26873  *               Reference Parameter effBo is filled with alloced bytes.
26874  *               Returns RFAILED if BO not satisfied at all.
26875  *
26876  *     Invoked by: rgSCHCmnDlAllocTxRb
26877  *
26878  *  @param[in]  RgSchCellCb           *cell
26879  *  @param[in]  RgSchDlSf             *subFrm
26880  *  @param[in]  RgSchUeCb             *ue
26881  *  @param[in]  U32                   bo
26882  *  @param[out] U32                   *effBo
26883  *  @param[in]  RgSchDlHqProcCb       *proc
26884  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
26885  *  @return Void
26886  *
26887  **/
26888 #ifdef ANSI
26889 PRIVATE Void rgSCHCmnDlAllocTxRbTM3
26890 (
26891 RgSchCellCb                *cell,
26892 RgSchDlSf                  *subFrm,
26893 RgSchUeCb                  *ue,
26894 U32                        bo,
26895 U32                        *effBo,
26896 RgSchDlHqProcCb            *proc,
26897 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
26898 )
26899 #else
26900 PRIVATE Void rgSCHCmnDlAllocTxRbTM3(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
26901 RgSchCellCb                *cell;
26902 RgSchDlSf                  *subFrm;
26903 RgSchUeCb                  *ue;
26904 U32                        bo;
26905 U32                        *effBo;
26906 RgSchDlHqProcCb            *proc;
26907 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
26908 #endif
26909 {
26910
26911
26912    /* Both TBs free for TX allocation */
26913    rgSCHCmnDlTM3TxTx(cell, subFrm, ue, bo, effBo,\
26914          proc, cellWdAllocInfo);
26915
26916    RETVOID;
26917 }
26918
26919 \f
26920 /**
26921  * @brief This function determines the RBs and Bytes required for BO
26922  *        retransmission for UEs configured with TM 3.
26923  *
26924  * @details
26925  *
26926  *     Function: rgSCHCmnDlAllocRetxRbTM3
26927  *     Purpose:
26928  *
26929  *               Reference Parameter effBo is filled with alloced bytes.
26930  *               Returns RFAILED if BO not satisfied at all.
26931  *
26932  *     Invoked by: rgSCHCmnDlAllocRetxRb
26933  *
26934  *  @param[in]  RgSchCellCb           *cell
26935  *  @param[in]  RgSchDlSf             *subFrm
26936  *  @param[in]  RgSchUeCb             *ue
26937  *  @param[in]  U32                   bo
26938  *  @param[out] U32                   *effBo
26939  *  @param[in]  RgSchDlHqProcCb       *proc
26940  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
26941  *  @return Void
26942  *
26943  **/
26944 #ifdef ANSI
26945 PRIVATE Void rgSCHCmnDlAllocRetxRbTM3
26946 (
26947 RgSchCellCb                *cell,
26948 RgSchDlSf                  *subFrm,
26949 RgSchUeCb                  *ue,
26950 U32                        bo,
26951 U32                        *effBo,
26952 RgSchDlHqProcCb            *proc,
26953 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
26954 )
26955 #else
26956 PRIVATE Void rgSCHCmnDlAllocRetxRbTM3(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
26957 RgSchCellCb                *cell;
26958 RgSchDlSf                  *subFrm;
26959 RgSchUeCb                  *ue;
26960 U32                        bo;
26961 U32                        *effBo;
26962 RgSchDlHqProcCb            *proc;
26963 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
26964 #endif
26965 {
26966
26967
26968    if ((proc->tbInfo[0].state == HQ_TB_NACKED) &&
26969          (proc->tbInfo[1].state == HQ_TB_NACKED))
26970    {
26971 #ifdef LAA_DBG_LOG
26972       printf ("RETX RB TM3 nack for both hqp %d cell %d \n", proc->procId, proc->hqE->cell->cellId);
26973 #endif
26974       /* Both TBs require RETX allocation */
26975       rgSCHCmnDlTM3RetxRetx(cell, subFrm, ue, bo, effBo,\
26976             proc, cellWdAllocInfo);
26977    }
26978    else
26979    {
26980       /* One of the TBs need RETX allocation. Other TB may/maynot
26981        * be available for new TX allocation. */
26982       rgSCHCmnDlTM3TxRetx(cell, subFrm, ue, bo, effBo,\
26983             proc, cellWdAllocInfo);
26984    }
26985
26986    RETVOID;
26987 }
26988
26989 \f
26990 /**
26991  * @brief This function performs the DCI format selection in case of
26992  *        Transmit Diversity scheme where there can be more
26993  *        than 1 option for DCI format selection.
26994  *
26995  * @details
26996  *
26997  *     Function: rgSCHCmnSlctPdcchFrmt
26998  *     Purpose:  1. If DLFS is enabled, then choose TM specific
26999  *                  DCI format for Transmit diversity. All the
27000  *                  TM Specific DCI Formats support Type0 and/or
27001  *                  Type1 resource allocation scheme. DLFS
27002  *                  supports only Type-0&1 Resource allocation.
27003  *               2. If DLFS is not enabled, select a DCI format
27004  *                  which is of smaller size. Since Non-DLFS
27005  *                  scheduler supports all Resource allocation
27006  *                  schemes, selection is based on efficiency.
27007  *
27008  *     Invoked by: DL UE Allocation by Common Scheduler.
27009  *
27010  *  @param[in]  RgSchCellCb      *cell
27011  *  @param[in]  RgSchUeCb        *ue
27012  *  @param[out] U8               *raType
27013  *  @return  TfuDciFormat
27014  *
27015  **/
27016 #ifdef ANSI
27017 TfuDciFormat rgSCHCmnSlctPdcchFrmt
27018 (
27019 RgSchCellCb                *cell,
27020 RgSchUeCb                  *ue,
27021 U8                         *raType
27022 )
27023 #else
27024 TfuDciFormat rgSCHCmnSlctPdcchFrmt(cell, ue, raType)
27025 RgSchCellCb                *cell;
27026 RgSchUeCb                  *ue;
27027 U8                         *raType;
27028 #endif
27029 {
27030    RgSchCmnCell   *cellSch = RG_SCH_CMN_GET_CELL(cell);
27031
27032
27033    /* ccpu00140894- Selective DCI Format and RA type should be selected only 
27034     * after TX Mode transition is completed*/
27035    if ((cellSch->dl.isDlFreqSel) && (ue->txModeTransCmplt))
27036    {
27037       *raType = rgSchCmnDciFrmtOptns[ue->mimoInfo.txMode-1].spfcDciRAType;
27038       return (rgSchCmnDciFrmtOptns[ue->mimoInfo.txMode-1].spfcDciFrmt);
27039    }
27040    else
27041    {
27042       *raType = rgSchCmnDciFrmtOptns[ue->mimoInfo.txMode-1].prfrdDciRAType;
27043       return (rgSchCmnDciFrmtOptns[ue->mimoInfo.txMode-1].prfrdDciFrmt);
27044    }
27045 }
27046
27047 \f
27048 /**
27049  * @brief This function handles Retx allocation in case of TM3 UEs
27050  *        where both the TBs were NACKED previously.
27051  *
27052  * @details
27053  *
27054  *     Function: rgSCHCmnDlTM3RetxRetx
27055  *     Purpose:  If forceTD flag enabled
27056  *                  TD for TB1 on CW1.
27057  *               Else
27058  *                  DCI Frmt 2A and RA Type 0
27059  *                  RI layered SM of both TBs on 2 CWs
27060  *               Add UE to cell Alloc Info.
27061  *               Fill UE alloc Info.
27062  *
27063  *
27064  *               Successful allocation is indicated by non-zero effBo value.
27065  *
27066  *     Invoked by: rgSCHCmnDlAllocRbTM3
27067  *
27068  *  @param[in]  RgSchCellCb           *cell
27069  *  @param[in]  RgSchDlSf             *subFrm
27070  *  @param[in]  RgSchUeCb             *ue
27071  *  @param[in]  U32                   bo
27072  *  @param[out] U32                   *effBo
27073  *  @param[in]  RgSchDlHqProcCb       *proc
27074  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
27075  *  @return  Void
27076  *
27077  **/
27078 #ifdef ANSI
27079 PRIVATE Void rgSCHCmnDlTM3RetxRetx
27080 (
27081 RgSchCellCb                *cell,
27082 RgSchDlSf                  *subFrm,
27083 RgSchUeCb                  *ue,
27084 U32                        bo,
27085 U32                        *effBo,
27086 RgSchDlHqProcCb            *proc,
27087 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
27088 )
27089 #else
27090 PRIVATE Void rgSCHCmnDlTM3RetxRetx(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
27091 RgSchCellCb                *cell;
27092 RgSchDlSf                  *subFrm;
27093 RgSchUeCb                  *ue;
27094 U32                        bo;
27095 U32                        *effBo;
27096 RgSchDlHqProcCb            *proc;
27097 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
27098 #endif
27099 {
27100    S16           ret;
27101    RgSchDlRbAlloc *allocInfo;
27102    U8            numRb;
27103    Bool          swpFlg;
27104    U8            precInfo;
27105    U8            noTxLyrs;
27106    U8            precInfoAntIdx;
27107
27108
27109    ret = ROK;
27110    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
27111    swpFlg = FALSE;
27112 /* Fix for ccpu00123927: Retransmit 2 codewords irrespective of current rank */
27113    {
27114       allocInfo->dciFormat = TFU_DCI_FORMAT_2A;
27115       allocInfo->raType    = RG_SCH_CMN_RA_TYPE0;
27116
27117       ret = rgSCHCmnDlAlloc2CwRetxRb(cell, subFrm, ue, proc, &numRb, &swpFlg,\
27118             effBo);
27119       if (ret == RFAILED)
27120       {
27121          /* Allocation couldn't be made for Retx */
27122          rgSCHCmnDlAdd2NonSchdRetxLst(cellWdAllocInfo, ue, proc);
27123          RETVOID;
27124       }
27125       /* Fix for ccpu00123927: Retransmit 2 codewords irrespective of current rank */
27126       noTxLyrs = proc->tbInfo[0].numLyrs + proc->tbInfo[1].numLyrs;
27127 #ifdef FOUR_TX_ANTENNA
27128       /*Chandra: For 4X4 MIM RETX with noTxLyrs=3, CW0 should be 1-LyrTB and CW1 should
27129        * have 2-LyrTB as per Table 6.3.3.2-1 of 36.211  */
27130       if(noTxLyrs == 3 &&  proc->tbInfo[0].numLyrs==2)
27131       {
27132          swpFlg = TRUE;
27133          proc->cwSwpEnabled = TRUE;
27134       }
27135 #endif
27136       precInfoAntIdx = cell->numTxAntPorts/2 - 1;
27137       precInfo = (getPrecInfoFunc[0][precInfoAntIdx])(cell, ue, noTxLyrs, TRUE);
27138    }
27139
27140 #ifdef LTEMAC_SPS
27141    if (!RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc))
27142 #endif
27143    {
27144       /* Adding UE to allocInfo RETX Lst */
27145       rgSCHCmnDlRbInfoAddUeRetx(cell, cellWdAllocInfo, ue, proc);
27146    }
27147    /* Fill UE alloc Info scratch pad */
27148    RG_SCH_CMN_FILL_DL_TXINFO(allocInfo, numRb, swpFlg, \
27149          precInfo, noTxLyrs, subFrm);
27150
27151    RETVOID;
27152 }
27153
27154 \f
27155 /**
27156  * @brief This function handles Retx allocation in case of TM4 UEs
27157  *        where both the TBs were NACKED previously.
27158  *
27159  * @details
27160  *
27161  *     Function: rgSCHCmnDlTM4RetxRetx
27162  *     Purpose:  If forceTD flag enabled
27163  *                  TD for TB1 on CW1.
27164  *               Else
27165  *                  DCI Frmt 2 and RA Type 0
27166  *                  If RI == 1
27167  *                     1 layer SM of TB1 on CW1.
27168  *                  Else
27169  *                     RI layered SM of both TBs on 2 CWs
27170  *               Add UE to cell Alloc Info.
27171  *               Fill UE alloc Info.
27172  *
27173  *
27174  *               Successful allocation is indicated by non-zero effBo value.
27175  *
27176  *     Invoked by: rgSCHCmnDlAllocRbTM4
27177  *
27178  *  @param[in]  RgSchCellCb           *cell
27179  *  @param[in]  RgSchDlSf             *subFrm
27180  *  @param[in]  RgSchUeCb             *ue
27181  *  @param[in]  U32                   bo
27182  *  @param[out] U32                   *effBo
27183  *  @param[in]  RgSchDlHqProcCb       *proc
27184  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
27185  *  @return  Void
27186  *
27187  **/
27188 #ifdef ANSI
27189 PRIVATE Void rgSCHCmnDlTM4RetxRetx
27190 (
27191 RgSchCellCb                *cell,
27192 RgSchDlSf                  *subFrm,
27193 RgSchUeCb                  *ue,
27194 U32                        bo,
27195 U32                        *effBo,
27196 RgSchDlHqProcCb            *proc,
27197 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
27198 )
27199 #else
27200 PRIVATE Void rgSCHCmnDlTM4RetxRetx(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
27201 RgSchCellCb                *cell;
27202 RgSchDlSf                  *subFrm;
27203 RgSchUeCb                  *ue;
27204 U32                        bo;
27205 U32                        *effBo;
27206 RgSchDlHqProcCb            *proc;
27207 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
27208 #endif
27209 {
27210    S16            ret;
27211    RgSchDlRbAlloc *allocInfo;
27212    U8             numRb;
27213    Bool           swpFlg = FALSE;
27214    U8             precInfo;
27215 #ifdef FOUR_TX_ANTENNA
27216    U8             precInfoAntIdx;
27217 #endif
27218    U8             noTxLyrs;
27219
27220
27221    ret = ROK;
27222    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
27223                        
27224    /* Irrespective of RI Schedule both CWs */
27225    allocInfo->dciFormat = TFU_DCI_FORMAT_2;
27226    allocInfo->raType    = RG_SCH_CMN_RA_TYPE0;
27227
27228    ret = rgSCHCmnDlAlloc2CwRetxRb(cell, subFrm, ue, proc, &numRb, &swpFlg,\
27229          effBo);
27230    if (ret == RFAILED)
27231    {
27232       /* Allocation couldn't be made for Retx */
27233       rgSCHCmnDlAdd2NonSchdRetxLst(cellWdAllocInfo, ue, proc);
27234       RETVOID;
27235    }
27236    noTxLyrs = proc->tbInfo[0].numLyrs + proc->tbInfo[1].numLyrs;
27237    precInfo = 0; 
27238 #ifdef FOUR_TX_ANTENNA
27239    /*Chandra: For 4X4 MIM RETX with noTxLyrs=3, CW0 should be 1-LyrTB and CW1
27240     * should have 2-LyrTB as per Table 6.3.3.2-1 of 36.211  */
27241    if(noTxLyrs == 3 &&  proc->tbInfo[0].numLyrs==2)
27242    {
27243       swpFlg = TRUE;
27244       proc->cwSwpEnabled = TRUE;
27245 }
27246 precInfoAntIdx = cell->numTxAntPorts/2 - 1;
27247 precInfo = (getPrecInfoFunc[1][precInfoAntIdx])(cell, ue, noTxLyrs, TRUE);
27248 #endif
27249
27250 #ifdef LTEMAC_SPS
27251    if (!RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc))
27252 #endif
27253    {
27254       /* Adding UE to allocInfo RETX Lst */
27255       rgSCHCmnDlRbInfoAddUeRetx(cell, cellWdAllocInfo, ue, proc);
27256    }
27257    /* Fill UE alloc Info scratch pad */
27258    RG_SCH_CMN_FILL_DL_TXINFO(allocInfo, numRb, swpFlg, \
27259          precInfo, noTxLyrs, subFrm);
27260
27261    RETVOID;
27262 }
27263
27264
27265 \f
27266 /**
27267  * @brief This function determines Transmission attributes
27268  *        incase of Spatial multiplexing for TX and RETX TBs.
27269  *
27270  * @details
27271  *
27272  *     Function: rgSCHCmnDlSMGetAttrForTxRetx
27273  *     Purpose:  1. Reached here for a TM3/4 UE's HqP whose one of the TBs is
27274  *                  NACKED and the other TB is either NACKED or WAITING.
27275  *               2. Select the NACKED TB for RETX allocation.
27276  *               3. Allocation preference for RETX TB by mapping it to a better
27277  *                  CW (better in terms of efficiency).
27278  *               4. Determine the state of the other TB.
27279  *                  Determine if swapFlag were to be set.
27280  *                  Swap flag would be set if Retx TB is cross
27281  *                  mapped to a CW.
27282  *               5. If UE has new data available for TX and if the other TB's state
27283  *                  is ACKED then set furtherScope as TRUE.
27284  *
27285  *     Invoked by: rgSCHCmnDlTM3[4]TxRetx
27286  *
27287  *  @param[in]  RgSchUeCb        *ue
27288  *  @param[in]  RgSchDlHqProcCb  *proc
27289  *  @param[out] RgSchDlHqTbCb    **retxTb
27290  *  @param[out] RgSchDlHqTbCb    **txTb
27291  *  @param[out] Bool             *frthrScp
27292  *  @param[out] Bool             *swpFlg
27293  *  @return  Void
27294  *
27295  **/
27296 #ifdef ANSI
27297 PRIVATE Void rgSCHCmnDlSMGetAttrForTxRetx
27298 (
27299 RgSchUeCb                  *ue,
27300 RgSchDlHqProcCb            *proc,
27301 RgSchDlHqTbCb              **retxTb,
27302 RgSchDlHqTbCb              **txTb,
27303 Bool                       *frthrScp,
27304 Bool                       *swpFlg
27305 )
27306 #else
27307 PRIVATE Void rgSCHCmnDlSMGetAttrForTxRetx(ue, proc, retxTb, txTb, frthrScp,\
27308         swpFlg)
27309 RgSchUeCb                  *ue;
27310 RgSchDlHqProcCb            *proc;
27311 RgSchDlHqTbCb              **retxTb;
27312 RgSchDlHqTbCb              **txTb;
27313 Bool                       *frthrScp;
27314 Bool                       *swpFlg;
27315 #endif
27316 {
27317    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,proc->hqE->cell);
27318    RgSchDlRbAlloc  *allocInfo;
27319
27320
27321    if (proc->tbInfo[0].state == HQ_TB_NACKED)
27322    {
27323       *retxTb = &proc->tbInfo[0];
27324       *txTb = &proc->tbInfo[1];
27325       /* TENB_BRDCM_TM4- Currently disabling swapflag for TM3/TM4, since 
27326        * HqFeedback processing does not consider a swapped hq feedback */
27327       if ((ue->mimoInfo.txMode == RGR_UE_TM_4) && (ueDl->mimoInfo.btrCwIdx == 1))
27328       {
27329          *swpFlg = TRUE;
27330          proc->cwSwpEnabled = TRUE;
27331       }
27332       if (proc->tbInfo[1].state == HQ_TB_ACKED)
27333       {
27334          allocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue, proc->hqE->cell);
27335          *frthrScp = allocInfo->mimoAllocInfo.hasNewTxData;
27336       }
27337    }
27338    else
27339    {
27340       *retxTb = &proc->tbInfo[1];
27341       *txTb = &proc->tbInfo[0];
27342       /* TENB_BRDCM_TM4 - Currently disabling swapflag for TM3/TM4, since 
27343        * HqFeedback processing does not consider a swapped hq feedback */
27344       if ((ue->mimoInfo.txMode == RGR_UE_TM_4) && (ueDl->mimoInfo.btrCwIdx == 0))
27345       {
27346          *swpFlg = TRUE;
27347          proc->cwSwpEnabled = TRUE;
27348       }
27349       if (proc->tbInfo[0].state == HQ_TB_ACKED)
27350       {
27351          allocInfo =  RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue, proc->hqE->cell);
27352          *frthrScp = allocInfo->mimoAllocInfo.hasNewTxData;
27353       }
27354    }
27355    RETVOID;
27356 }
27357
27358 \f
27359 /**
27360  * @brief Determine Precoding information for TM3 2 TX Antenna.
27361  *
27362  * @details
27363  *
27364  *     Function: rgSCHCmnDlTM3PrecInf2
27365  *     Purpose:
27366  *
27367  *     Invoked by: rgSCHCmnDlGetAttrForTM3
27368  *
27369  *  @param[in]  RgSchUeCb        *ue
27370  *  @param[in]  U8               numTxLyrs
27371  *  @param[in]  Bool             bothCwEnbld
27372  *  @return  U8
27373  *
27374  **/
27375 #ifdef ANSI
27376 PRIVATE U8 rgSCHCmnDlTM3PrecInf2
27377 (
27378 RgSchCellCb                *cell,
27379 RgSchUeCb                  *ue,
27380 U8                         numTxLyrs,
27381 Bool                       bothCwEnbld
27382 )
27383 #else
27384 PRIVATE U8 rgSCHCmnDlTM3PrecInf2(ue, numTxLyrs, bothCwEnbld)
27385 RgSchCellCb                *cell;
27386 RgSchUeCb                  *ue;
27387 U8                         numTxLyrs;
27388 Bool                       bothCwEnbld;
27389 #endif
27390 {
27391
27392    return (0);
27393 }
27394
27395 \f
27396 /**
27397  * @brief Determine Precoding information for TM4 2 TX Antenna.
27398  *
27399  * @details
27400  *
27401  *     Function: rgSCHCmnDlTM4PrecInf2
27402  *     Purpose:  To determine a logic of deriving precoding index
27403  *               information from 36.212 table 5.3.3.1.5-4
27404  *
27405  *     Invoked by: rgSCHCmnDlGetAttrForTM4
27406  *
27407  *  @param[in]  RgSchUeCb        *ue
27408  *  @param[in]  U8               numTxLyrs
27409  *  @param[in]  Bool             bothCwEnbld
27410  *  @return  U8
27411  *
27412  **/
27413 #ifdef ANSI
27414 PRIVATE U8 rgSCHCmnDlTM4PrecInf2
27415 (
27416 RgSchCellCb                *cell,
27417 RgSchUeCb                  *ue,
27418 U8                         numTxLyrs,
27419 Bool                       bothCwEnbld
27420 )
27421 #else
27422 PRIVATE U8 rgSCHCmnDlTM4PrecInf2(ue, numTxLyrs, bothCwEnbld)
27423 RgSchCellCb                *cell;
27424 RgSchUeCb                  *ue;
27425 U8                         numTxLyrs;
27426 Bool                       bothCwEnbld;
27427 #endif
27428 {
27429    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
27430    U8            precIdx;
27431
27432
27433    if (ueDl->mimoInfo.ri == numTxLyrs)
27434    {
27435       if (ueDl->mimoInfo.ri == 2)
27436       {
27437          /* PrecInfo corresponding to 2 CW
27438            Transmission */
27439          if (ue->mimoInfo.puschFdbkVld)
27440          {
27441             precIdx = 2;
27442          }
27443          else 
27444          {
27445             precIdx = ueDl->mimoInfo.pmi - 1;
27446          }
27447       }
27448       else
27449       {
27450          /* PrecInfo corresponding to 1 CW
27451           * Transmission */
27452          if (ue->mimoInfo.puschFdbkVld)
27453          {
27454             precIdx =  5;
27455          }
27456          else
27457          {
27458             precIdx =  ueDl->mimoInfo.pmi + 1;
27459          }
27460       }
27461    }
27462    else if (ueDl->mimoInfo.ri > numTxLyrs)
27463    {
27464       /* In case of choosing among the columns of a
27465        * precoding matrix, choose the column corresponding
27466        * to the MAX-CQI */
27467       if (ue->mimoInfo.puschFdbkVld)
27468       {
27469          precIdx = 5;
27470       }
27471       else
27472       {
27473          precIdx = (ueDl->mimoInfo.pmi- 1)* 2  + 1;
27474       }
27475    }
27476    else /* if RI < numTxLyrs */
27477    {
27478       precIdx = (ueDl->mimoInfo.pmi < 2)? 0:1;
27479    }
27480    return (precIdx);
27481 }
27482
27483 \f
27484 /**
27485  * @brief Determine Precoding information for TM3 4 TX Antenna.
27486  *
27487  * @details
27488  *
27489  *     Function: rgSCHCmnDlTM3PrecInf4
27490  *     Purpose:  To determine a logic of deriving precoding index
27491  *               information from 36.212 table 5.3.3.1.5A-2
27492  *
27493  *     Invoked by: rgSCHCmnDlGetAttrForTM3
27494  *
27495  *  @param[in]  RgSchUeCb        *ue
27496  *  @param[in]  U8               numTxLyrs
27497  *  @param[in]  Bool             bothCwEnbld
27498  *  @return  U8
27499  *
27500  **/
27501 #ifdef ANSI
27502 PRIVATE U8 rgSCHCmnDlTM3PrecInf4
27503 (
27504 RgSchCellCb                *cell,
27505 RgSchUeCb                  *ue,
27506 U8                         numTxLyrs,
27507 Bool                       bothCwEnbld
27508 )
27509 #else
27510 PRIVATE U8 rgSCHCmnDlTM3PrecInf4(ue, numTxLyrs, bothCwEnbld)
27511 RgSchCellCb                *cell;
27512 RgSchUeCb                  *ue;
27513 U8                         numTxLyrs;
27514 Bool                       bothCwEnbld;
27515 #endif
27516 {
27517    U8            precIdx;
27518
27519
27520    if (bothCwEnbld)
27521    {
27522       precIdx = numTxLyrs - 2;
27523    }
27524    else /* one 1 CW transmission */
27525    {
27526       precIdx = 1;
27527    }
27528    return (precIdx);
27529 }
27530
27531 \f
27532 /**
27533  * @brief Determine Precoding information for TM4 4 TX Antenna.
27534  *
27535  * @details
27536  *
27537  *     Function: rgSCHCmnDlTM4PrecInf4
27538  *     Purpose:  To determine a logic of deriving precoding index
27539  *               information from 36.212 table 5.3.3.1.5-5
27540  *
27541  *     Invoked by: rgSCHCmnDlGetAttrForTM4
27542  *
27543  *  @param[in]  RgSchUeCb        *ue
27544  *  @param[in]  U8               numTxLyrs
27545  *  @param[in]  Bool             bothCwEnbld
27546  *  @return  U8
27547  *
27548  **/
27549 #ifdef ANSI
27550 PRIVATE U8 rgSCHCmnDlTM4PrecInf4
27551 (
27552 RgSchCellCb                *cell,
27553 RgSchUeCb                  *ue,
27554 U8                         numTxLyrs,
27555 Bool                       bothCwEnbld
27556 )
27557 #else
27558 PRIVATE U8 rgSCHCmnDlTM4PrecInf4(cell, ue, numTxLyrs, bothCwEnbld)
27559 RgSchCellCb                *cell;
27560 RgSchUeCb                  *ue;
27561 U8                         numTxLyrs;
27562 Bool                       bothCwEnbld;
27563 #endif
27564 {
27565    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
27566    U8            precInfoBaseIdx, precIdx;
27567
27568
27569    precInfoBaseIdx  = (ue->mimoInfo.puschFdbkVld)? (16):
27570       (ueDl->mimoInfo.pmi);
27571    if (bothCwEnbld)
27572    {
27573       precIdx = precInfoBaseIdx + (numTxLyrs-2)*17;
27574    }
27575    else /* one 1 CW transmission */
27576    {
27577       precInfoBaseIdx += 1;
27578       precIdx = precInfoBaseIdx + (numTxLyrs-1)*17;
27579    }
27580    return (precIdx);
27581 }
27582
27583 \f
27584 /**
27585  * @brief This function determines Transmission attributes
27586  *        incase of TM3 scheduling.
27587  *
27588  * @details
27589  *
27590  *     Function: rgSCHCmnDlGetAttrForTM3
27591  *     Purpose:  Determine retx TB and tx TB based on TB states.
27592  *               If forceTD enabled
27593  *                  perform only retx TB allocation.
27594  *                  If retxTB == TB2 then DCI Frmt = 2A, RA Type = 0.
27595  *                  Else DCI Frmt and RA Type based on cell->isDlfsEnbld
27596  *               If RI == 1
27597  *                  perform retxTB allocation on CW1.
27598  *               Else if RI > 1
27599  *                  Determine further Scope and Swap Flag attributes
27600  *                  assuming a 2 CW transmission of RetxTB and new Tx TB.
27601  *                  If no further scope for new TX allocation
27602  *                     Allocate only retx TB using 2 layers if
27603  *                     this TB was previously transmitted using 2 layers AND
27604  *                     number of Tx antenna ports == 4.
27605  *                     otherwise do single layer precoding.
27606  *
27607  *     Invoked by: rgSCHCmnDlTM3TxRetx
27608  *
27609  *  @param[in]  RgSchUeCb        *ue
27610  *  @param[in]  RgSchDlHqProcCb  *proc
27611  *  @param[out] U8               *numTxLyrs
27612  *  @param[out] Bool             *isTraDiv
27613  *  @param[out] U8               *prcdngInf
27614  *  @param[out] U8               *raType
27615  *  @return  Void
27616  *
27617  **/
27618 #ifdef ANSI
27619 PRIVATE Void rgSCHCmnDlGetAttrForTM3
27620 (
27621 RgSchCellCb                *cell,
27622 RgSchUeCb                  *ue,
27623 RgSchDlHqProcCb            *proc,
27624 U8                         *numTxLyrs,
27625 TfuDciFormat               *dciFrmt,
27626 U8                         *prcdngInf,
27627 RgSchDlHqTbCb              **retxTb,
27628 RgSchDlHqTbCb              **txTb,
27629 Bool                       *frthrScp,
27630 Bool                       *swpFlg,
27631 U8                         *raType
27632 )
27633 #else
27634 PRIVATE Void rgSCHCmnDlGetAttrForTM3(cell, ue, proc, numTxLyrs, dciFrmt,\
27635         prcdngInf, retxTb, txTb, frthrScp, swpFlg, raType)
27636 RgSchCellCb                *cell;
27637 RgSchUeCb                  *ue;
27638 RgSchDlHqProcCb            *proc;
27639 U8                         *numTxLyrs;
27640 TfuDciFormat               *dciFrmt;
27641 U8                         *prcdngInf;
27642 RgSchDlHqTbCb              **retxTb;
27643 RgSchDlHqTbCb              **txTb;
27644 Bool                       *frthrScp;
27645 Bool                       *swpFlg;
27646 U8                         *raType;
27647 #endif
27648 {
27649    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
27650    U8            precInfoAntIdx;
27651
27652
27653    /* Avoiding Tx-Retx for LAA cell as firstSchedTime is associated with 
27654       HQP */
27655    /* Integration_fix: SPS Proc shall always have only one Cw */
27656 #ifdef LTEMAC_SPS
27657    if (((RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc)) ||
27658          (ueDl->mimoInfo.forceTD)) 
27659 #ifdef LTE_ADV
27660      ||(TRUE == rgSCHLaaSCellEnabled(cell))
27661 #endif
27662       )
27663 #else
27664    if ((ueDl->mimoInfo.forceTD) 
27665 #ifdef LTE_ADV
27666        || (TRUE == rgSCHLaaSCellEnabled(cell))
27667 #endif
27668       )
27669 #endif
27670    {
27671       /* Transmit Diversity. Format based on dlfsEnabled
27672        * No further scope */
27673       if (proc->tbInfo[0].state == HQ_TB_NACKED)
27674       {
27675          *retxTb = &proc->tbInfo[0];
27676          *dciFrmt = rgSCHCmnSlctPdcchFrmt(cell, ue, raType);
27677       }
27678       else
27679       {
27680          *retxTb = &proc->tbInfo[1];
27681          *dciFrmt = TFU_DCI_FORMAT_2A;
27682          *raType = RG_SCH_CMN_RA_TYPE0;
27683       }
27684       *numTxLyrs = 1;
27685       *frthrScp = FALSE;
27686       *prcdngInf = 0;
27687       RETVOID;
27688    }
27689
27690    /* Determine the 2 TB transmission attributes */
27691    rgSCHCmnDlSMGetAttrForTxRetx(ue, proc, retxTb, txTb, \
27692          frthrScp, swpFlg);
27693    if (*frthrScp)
27694    {
27695       /* Prefer allocation of RETX TB over 2 layers rather than combining
27696        * it with a new TX. */
27697       if ((ueDl->mimoInfo.ri == 2)
27698             && ((*retxTb)->numLyrs == 2) && (cell->numTxAntPorts == 4))
27699       {
27700          /* Allocate TB on CW1, using 2 Lyrs,
27701           * Format 2, precoding accordingly */
27702          *numTxLyrs = 2;
27703          *frthrScp = FALSE;
27704       }
27705       else
27706       {
27707          *numTxLyrs=  ((*retxTb)->numLyrs + ueDl->mimoInfo.cwInfo[!(ueDl->mimoInfo.btrCwIdx)].noLyr);
27708
27709          if((*retxTb)->tbIdx == 0 && ((*retxTb)->numLyrs == 2 ) && *numTxLyrs ==3)
27710          {
27711             *swpFlg = TRUE;
27712             proc->cwSwpEnabled = TRUE;
27713          }
27714          else if((*retxTb)->tbIdx == 1 && ((*retxTb)->numLyrs == 1) && *numTxLyrs ==3)
27715          {
27716             *swpFlg = TRUE;
27717             proc->cwSwpEnabled = TRUE;
27718          }
27719       }
27720
27721       precInfoAntIdx = cell->numTxAntPorts/2 - 1; 
27722       *prcdngInf = (getPrecInfoFunc[0][precInfoAntIdx])\
27723                    (cell, ue, ueDl->mimoInfo.ri, *frthrScp);
27724       *dciFrmt = TFU_DCI_FORMAT_2A;
27725       *raType = RG_SCH_CMN_RA_TYPE0;
27726    }
27727    else /* frthrScp == FALSE */
27728    {
27729       if (cell->numTxAntPorts == 2)
27730       {
27731          /*  Transmit Diversity  */
27732          *numTxLyrs = 1;
27733          if ((*retxTb)->tbIdx == 0)
27734          {
27735             *dciFrmt = rgSCHCmnSlctPdcchFrmt(cell, ue, raType);
27736          }
27737          else
27738          {
27739             /* If retxTB is TB2 then use format 2A */
27740             *dciFrmt = TFU_DCI_FORMAT_2A;
27741             *raType = RG_SCH_CMN_RA_TYPE0;
27742          }
27743          *prcdngInf = 0;
27744          RETVOID;
27745       }
27746       else /* NumAntPorts == 4 */
27747       {
27748          if ((*retxTb)->numLyrs == 2)
27749          {
27750             /* Allocate TB on CW1, using 2 Lyrs,
27751              * Format 2A, precoding accordingly */
27752             *numTxLyrs = 2;
27753             *dciFrmt = TFU_DCI_FORMAT_2A;
27754             *raType = RG_SCH_CMN_RA_TYPE0;
27755             precInfoAntIdx = cell->numTxAntPorts/2 - 1;
27756             *prcdngInf = (getPrecInfoFunc[0][precInfoAntIdx])(cell, ue, *numTxLyrs, *frthrScp);
27757             RETVOID;
27758          }
27759          else
27760          {
27761             /*  Transmit Diversity  */
27762             *numTxLyrs = 1;
27763             if ((*retxTb)->tbIdx == 0)
27764             {
27765                *dciFrmt = rgSCHCmnSlctPdcchFrmt(cell, ue, raType);
27766             }
27767             else
27768             {
27769                /* If retxTB is TB2 then use format 2A */
27770                *dciFrmt = TFU_DCI_FORMAT_2A;
27771                *raType = RG_SCH_CMN_RA_TYPE0;
27772             }
27773             *prcdngInf = 0;
27774             RETVOID;
27775          }
27776       }
27777    }
27778
27779    RETVOID;
27780 }
27781
27782
27783 \f
27784 /**
27785  * @brief This function determines Transmission attributes
27786  *        incase of TM4 scheduling.
27787  *
27788  * @details
27789  *
27790  *     Function: rgSCHCmnDlGetAttrForTM4
27791  *     Purpose:  Determine retx TB and tx TB based on TB states.
27792  *               If forceTD enabled
27793  *                  perform only retx TB allocation.
27794  *                  If retxTB == TB2 then DCI Frmt = 2, RA Type = 0.
27795  *                  Else DCI Frmt and RA Type based on cell->isDlfsEnbld
27796  *               If RI == 1
27797  *                  perform retxTB allocation on CW1.
27798  *               Else if RI > 1
27799  *                  Determine further Scope and Swap Flag attributes
27800  *                  assuming a 2 CW transmission of RetxTB and new Tx TB.
27801  *                  If no further scope for new TX allocation
27802  *                     Allocate only retx TB using 2 layers if
27803  *                     this TB was previously transmitted using 2 layers AND
27804  *                     number of Tx antenna ports == 4.
27805  *                     otherwise do single layer precoding.
27806  *
27807  *     Invoked by: rgSCHCmnDlTM4TxRetx
27808  *
27809  *  @param[in]  RgSchUeCb        *ue
27810  *  @param[in]  RgSchDlHqProcCb  *proc
27811  *  @param[out] U8               *numTxLyrs
27812  *  @param[out] Bool             *isTraDiv
27813  *  @param[out] U8               *prcdngInf
27814  *  @param[out] U8               *raType
27815  *  @return  Void
27816  *
27817  **/
27818 #ifdef ANSI
27819 PRIVATE Void rgSCHCmnDlGetAttrForTM4
27820 (
27821 RgSchCellCb                *cell,
27822 RgSchUeCb                  *ue,
27823 RgSchDlHqProcCb            *proc,
27824 U8                         *numTxLyrs,
27825 TfuDciFormat               *dciFrmt,
27826 U8                         *prcdngInf,
27827 RgSchDlHqTbCb              **retxTb,
27828 RgSchDlHqTbCb              **txTb,
27829 Bool                       *frthrScp,
27830 Bool                       *swpFlg,
27831 U8                         *raType
27832 )
27833 #else
27834 PRIVATE Void rgSCHCmnDlGetAttrForTM4(cell, ue, proc, numTxLyrs, dciFrmt,\
27835         prcdngInf, retxTb, txTb, frthrScp, swpFlg, raType)
27836 RgSchCellCb                *cell;
27837 RgSchUeCb                  *ue;
27838 RgSchDlHqProcCb            *proc;
27839 U8                         *numTxLyrs;
27840 TfuDciFormat               *dciFrmt;
27841 U8                         *prcdngInf;
27842 RgSchDlHqTbCb              **retxTb;
27843 RgSchDlHqTbCb              **txTb;
27844 Bool                       *frthrScp;
27845 Bool                       *swpFlg;
27846 U8                         *raType;
27847 #endif
27848 {
27849    RgSchCmnDlUe  *ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
27850    U8 precInfoAntIdx;
27851
27852
27853    *frthrScp = FALSE;
27854    /* Integration_fix: SPS Proc shall always have only one Cw */
27855 #ifdef LTEMAC_SPS
27856    if (((RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc)) ||
27857          (ueDl->mimoInfo.forceTD)) 
27858 #ifdef LTE_ADV
27859      ||(TRUE == rgSCHLaaSCellEnabled(cell))
27860 #endif
27861       )
27862 #else
27863    if ((ueDl->mimoInfo.forceTD) 
27864 #ifdef LTE_ADV
27865        || (TRUE == rgSCHLaaSCellEnabled(cell))
27866 #endif
27867       )
27868 #endif
27869    {
27870       /* Transmit Diversity. Format based on dlfsEnabled
27871        * No further scope */
27872       if (proc->tbInfo[0].state == HQ_TB_NACKED)
27873       {
27874          *retxTb = &proc->tbInfo[0];
27875          *dciFrmt = rgSCHCmnSlctPdcchFrmt(cell, ue, raType);
27876       }
27877       else
27878       {
27879          *retxTb = &proc->tbInfo[1];
27880          *dciFrmt = TFU_DCI_FORMAT_2;
27881          *raType = RG_SCH_CMN_RA_TYPE0;
27882       }
27883       *numTxLyrs = 1;
27884       *frthrScp = FALSE;
27885       *prcdngInf = 0;
27886       RETVOID;
27887    }
27888
27889    if (ueDl->mimoInfo.ri == 1)
27890    {
27891       /* single layer precoding. Format 2.
27892        * No further scope */
27893       if (proc->tbInfo[0].state == HQ_TB_NACKED)
27894       {
27895          *retxTb = &proc->tbInfo[0];
27896       }
27897       else
27898       {
27899          *retxTb = &proc->tbInfo[1];
27900       }
27901       *numTxLyrs = 1;
27902       *dciFrmt = TFU_DCI_FORMAT_2;
27903       *raType = RG_SCH_CMN_RA_TYPE0;
27904       *frthrScp = FALSE;
27905       *prcdngInf = 0; /*When RI= 1*/
27906       RETVOID;
27907    }
27908
27909    /* Determine the 2 TB transmission attributes */
27910    rgSCHCmnDlSMGetAttrForTxRetx(ue, proc, retxTb, txTb, \
27911          frthrScp, swpFlg);
27912    *dciFrmt = TFU_DCI_FORMAT_2;
27913    *raType = RG_SCH_CMN_RA_TYPE0;
27914    if (*frthrScp)
27915    {
27916       /* Prefer allocation of RETX TB over 2 layers rather than combining
27917        * it with a new TX. */
27918       if ((ueDl->mimoInfo.ri == 2)
27919             && ((*retxTb)->numLyrs == 2) && (cell->numTxAntPorts == 4))
27920       {
27921          /* Allocate TB on CW1, using 2 Lyrs,
27922           * Format 2, precoding accordingly */
27923          *numTxLyrs = 2;
27924          *frthrScp = FALSE;
27925       }
27926       precInfoAntIdx = cell->numTxAntPorts/2 - 1;
27927       *prcdngInf = (getPrecInfoFunc[1][precInfoAntIdx])
27928                    (cell, ue, ueDl->mimoInfo.ri, *frthrScp);
27929    }
27930    else /* frthrScp == FALSE */
27931    {
27932       if (cell->numTxAntPorts == 2)
27933       {
27934          /* single layer precoding. Format 2. */
27935          *numTxLyrs = 1;
27936          *prcdngInf = (getPrecInfoFunc[1][cell->numTxAntPorts/2 - 1])\
27937                       (cell, ue, *numTxLyrs, *frthrScp);
27938          RETVOID;
27939       }
27940       else /* NumAntPorts == 4 */
27941       {
27942          if ((*retxTb)->numLyrs == 2)
27943          {
27944             /* Allocate TB on CW1, using 2 Lyrs,
27945              * Format 2, precoding accordingly */
27946             *numTxLyrs = 2;
27947             precInfoAntIdx = cell->numTxAntPorts/2 - 1;
27948             *prcdngInf = (getPrecInfoFunc[1][precInfoAntIdx])\
27949                          (cell, ue, *numTxLyrs, *frthrScp);
27950             RETVOID;
27951          }
27952          else
27953          {
27954             /* Allocate TB with 1 lyr precoding,
27955              * Format 2, precoding info accordingly */
27956             *numTxLyrs = 1;
27957             precInfoAntIdx = cell->numTxAntPorts/2 - 1;
27958             *prcdngInf = (getPrecInfoFunc[1][precInfoAntIdx])\
27959                          (cell, ue, *numTxLyrs, *frthrScp);
27960             RETVOID;
27961          }
27962       }
27963    }
27964
27965    RETVOID;
27966 }
27967
27968 \f
27969 /**
27970  * @brief This function handles Retx allocation in case of TM3 UEs
27971  *        where previously one of the TBs was NACKED and the other
27972  *        TB is either ACKED/WAITING.
27973  *
27974  * @details
27975  *
27976  *     Function: rgSCHCmnDlTM3TxRetx
27977  *     Purpose:  Determine the TX attributes for TM3 TxRetx Allocation.
27978  *               If futher Scope for New Tx Allocation on other TB
27979  *                  Perform RETX alloc'n on 1 CW and TX alloc'n on other.
27980  *                  Add UE to cell wide RetxTx List.
27981  *               Else
27982  *                  Perform only RETX alloc'n on CW1.
27983  *                  Add UE to cell wide Retx List.
27984  *
27985  *               effBo is set to a non-zero value if allocation is
27986  *               successful.
27987  *
27988  *     Invoked by: rgSCHCmnDlAllocRbTM3
27989  *
27990  *  @param[in]  RgSchCellCb           *cell
27991  *  @param[in]  RgSchDlSf             *subFrm
27992  *  @param[in]  RgSchUeCb             *ue
27993  *  @param[in]  U32                   bo
27994  *  @param[out] U32                   *effBo
27995  *  @param[in]  RgSchDlHqProcCb       *proc
27996  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
27997  *  @return  Void
27998  *
27999  **/
28000 #ifdef ANSI
28001 PRIVATE Void rgSCHCmnDlTM3TxRetx
28002 (
28003 RgSchCellCb                *cell,
28004 RgSchDlSf                  *subFrm,
28005 RgSchUeCb                  *ue,
28006 U32                        bo,
28007 U32                        *effBo,
28008 RgSchDlHqProcCb            *proc,
28009 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28010 )
28011 #else
28012 PRIVATE Void rgSCHCmnDlTM3TxRetx(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28013 RgSchCellCb                *cell;
28014 RgSchDlSf                  *subFrm;
28015 RgSchUeCb                  *ue;
28016 U32                        bo;
28017 U32                        *effBo;
28018 RgSchDlHqProcCb            *proc;
28019 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28020 #endif
28021 {
28022    S16              ret;
28023    RgSchDlRbAlloc   *allocInfo;
28024    U8               numRb;
28025    RgSchDlHqTbCb    *retxTb, *txTb;
28026    Bool             frthrScp;
28027    Bool             swpFlg;
28028    U8               prcdngInf;
28029    U8               numTxLyrs;
28030
28031    frthrScp = FALSE;
28032
28033    ret = ROK;
28034    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
28035    swpFlg = FALSE;
28036
28037    /* Determine the transmission attributes */
28038    rgSCHCmnDlGetAttrForTM3(cell, ue, proc, &numTxLyrs, &allocInfo->dciFormat,\
28039          &prcdngInf, &retxTb, &txTb, &frthrScp, &swpFlg,\
28040          &allocInfo->raType);
28041
28042    if (frthrScp)
28043    {
28044 #ifdef LAA_DBG_LOG
28045       printf ("TX RETX called from proc %d cell %d \n",proc->procId, cell->cellId);
28046 #endif
28047       ret = rgSCHCmnDlAlloc2CwTxRetxRb(cell, subFrm, ue, retxTb, txTb,\
28048             &numRb, effBo);
28049       if (ret == RFAILED)
28050       {
28051          /* Allocation couldn't be made for Retx */
28052          rgSCHCmnDlAdd2NonSchdRetxLst(cellWdAllocInfo, ue, proc);
28053          RETVOID;
28054       }
28055       /* Adding UE to RbAllocInfo RETX-TX Lst */
28056       rgSCHCmnDlRbInfoAddUeRetxTx(cell, cellWdAllocInfo, ue, proc);
28057    }
28058    else
28059    {
28060       ret = rgSCHCmnDlAlloc1CwRetxRb(cell, subFrm, ue, retxTb,
28061             numTxLyrs, &numRb, effBo);
28062       if (ret == RFAILED)
28063       {
28064          /* Allocation couldn't be made for Retx */
28065          rgSCHCmnDlAdd2NonSchdRetxLst(cellWdAllocInfo, ue, proc);
28066          RETVOID;
28067       }
28068 #ifdef LTEMAC_SPS
28069       if (!RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc))
28070 #endif
28071       {
28072          /* Adding UE to allocInfo RETX Lst */
28073          rgSCHCmnDlRbInfoAddUeRetx(cell, cellWdAllocInfo, ue, proc);
28074       }
28075    }
28076    RG_SCH_CMN_FILL_DL_TXINFO(allocInfo, numRb, swpFlg, \
28077          prcdngInf, numTxLyrs, subFrm);
28078
28079    RETVOID;
28080 }
28081
28082 \f
28083 /**
28084  * @brief This function handles Retx allocation in case of TM4 UEs
28085  *        where previously one of the TBs was NACKED and the other
28086  *        TB is either ACKED/WAITING.
28087  *
28088  * @details
28089  *
28090  *     Function: rgSCHCmnDlTM4TxRetx
28091  *     Purpose:  Determine the TX attributes for TM4 TxRetx Allocation.
28092  *               If futher Scope for New Tx Allocation on other TB
28093  *                  Perform RETX alloc'n on 1 CW and TX alloc'n on other.
28094  *                  Add UE to cell wide RetxTx List.
28095  *               Else
28096  *                  Perform only RETX alloc'n on CW1.
28097  *                  Add UE to cell wide Retx List.
28098  *
28099  *               effBo is set to a non-zero value if allocation is
28100  *               successful.
28101  *
28102  *     Invoked by: rgSCHCmnDlAllocRbTM4
28103  *
28104  *  @param[in]  RgSchCellCb           *cell
28105  *  @param[in]  RgSchDlSf             *subFrm
28106  *  @param[in]  RgSchUeCb             *ue
28107  *  @param[in]  U32                   bo
28108  *  @param[out] U32                   *effBo
28109  *  @param[in]  RgSchDlHqProcCb       *proc
28110  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28111  *  @return  Void
28112  *
28113  **/
28114 #ifdef ANSI
28115 PRIVATE Void rgSCHCmnDlTM4TxRetx
28116 (
28117 RgSchCellCb                *cell,
28118 RgSchDlSf                  *subFrm,
28119 RgSchUeCb                  *ue,
28120 U32                        bo,
28121 U32                        *effBo,
28122 RgSchDlHqProcCb            *proc,
28123 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28124 )
28125 #else
28126 PRIVATE Void rgSCHCmnDlTM4TxRetx(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28127 RgSchCellCb                *cell;
28128 RgSchDlSf                  *subFrm;
28129 RgSchUeCb                  *ue;
28130 U32                        bo;
28131 U32                        *effBo;
28132 RgSchDlHqProcCb            *proc;
28133 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28134 #endif
28135 {
28136    S16              ret;
28137    RgSchDlRbAlloc   *allocInfo;
28138    U8               numRb;
28139    RgSchDlHqTbCb    *retxTb, *txTb;
28140    Bool             frthrScp;
28141    Bool             swpFlg;
28142    U8               prcdngInf;
28143    U8               numTxLyrs;
28144
28145
28146    ret = ROK;
28147    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
28148    swpFlg = FALSE;
28149
28150    /* Determine the transmission attributes */
28151    rgSCHCmnDlGetAttrForTM4(cell, ue, proc, &numTxLyrs, &allocInfo->dciFormat,\
28152          &prcdngInf, &retxTb, &txTb, &frthrScp, &swpFlg,\
28153          &allocInfo->raType);
28154
28155    if (frthrScp)
28156    {
28157       ret = rgSCHCmnDlAlloc2CwTxRetxRb(cell, subFrm, ue, retxTb, txTb,\
28158             &numRb, effBo);
28159       if (ret == RFAILED)
28160       {
28161          /* Fix : syed If TxRetx allocation failed then add the UE along 
28162           * with the proc to the nonSchdTxRetxUeLst and let spfc scheduler
28163           *  take care of it during finalization. */       
28164          rgSCHCmnDlAdd2NonSchdRetxLst(cellWdAllocInfo, ue, proc);
28165          RETVOID;
28166       }
28167       /* Adding UE to RbAllocInfo RETX-TX Lst */
28168       rgSCHCmnDlRbInfoAddUeRetxTx(cell, cellWdAllocInfo, ue, proc);
28169    }
28170    else
28171    {
28172       ret = rgSCHCmnDlAlloc1CwRetxRb(cell, subFrm, ue, retxTb,
28173             numTxLyrs, &numRb, effBo);
28174       if (ret == RFAILED)
28175       {
28176          /* Allocation couldn't be made for Retx */
28177          rgSCHCmnDlAdd2NonSchdRetxLst(cellWdAllocInfo, ue, proc);
28178          RETVOID;
28179       }
28180 #ifdef LTEMAC_SPS
28181       if (!RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc))
28182 #endif
28183       {
28184          /* Adding UE to allocInfo RETX Lst */
28185          rgSCHCmnDlRbInfoAddUeRetx(cell, cellWdAllocInfo, ue, proc);
28186       }
28187    }
28188    RG_SCH_CMN_FILL_DL_TXINFO(allocInfo, numRb, swpFlg, \
28189          prcdngInf, numTxLyrs, subFrm)
28190
28191       RETVOID;
28192 }
28193
28194 \f
28195 /**
28196  * @brief This function handles Retx allocation in case of TM4 UEs
28197  *        where previously both the TBs were ACKED and ACKED
28198  *        respectively.
28199  *
28200  * @details
28201  *
28202  *     Function: rgSCHCmnDlTM3TxTx
28203  *     Purpose:  Reached here for a TM3 UE's HqP's fresh allocation
28204  *                  where both the TBs are free for TX scheduling.
28205  *               If forceTD flag is set
28206  *                  perform TD on CW1 with TB1.
28207  *                  precInfo = 0
28208  *               else
28209  *                  DCI Format = 2A.
28210  *                  RA Type = Type0.
28211  *                  RI layered precoding 2 TB on 2 CW.
28212  *                  Set precoding info.
28213  *               Add UE to cellAllocInfo.
28214  *               Fill ueAllocInfo.
28215  *
28216  *              effBo is set to a non-zero value if allocation is
28217  *              successful.
28218  *
28219  *     Invoked by: rgSCHCmnDlAllocRbTM3
28220  *
28221  *  @param[in]  RgSchCellCb           *cell
28222  *  @param[in]  RgSchDlSf             *subFrm
28223  *  @param[in]  RgSchUeCb             *ue
28224  *  @param[in]  U32                   bo
28225  *  @param[out] U32                   *effBo
28226  *  @param[in]  RgSchDlHqProcCb       *proc
28227  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28228  *  @return  Void
28229  *
28230  **/
28231 #ifdef ANSI
28232 PRIVATE Void rgSCHCmnDlTM3TxTx
28233 (
28234 RgSchCellCb                *cell,
28235 RgSchDlSf                  *subFrm,
28236 RgSchUeCb                  *ue,
28237 U32                        bo,
28238 U32                        *effBo,
28239 RgSchDlHqProcCb            *proc,
28240 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28241 )
28242 #else
28243 PRIVATE Void rgSCHCmnDlTM3TxTx(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28244 RgSchCellCb                *cell;
28245 RgSchDlSf                  *subFrm;
28246 RgSchUeCb                  *ue;
28247 U32                        bo;
28248 U32                        *effBo;
28249 RgSchDlHqProcCb            *proc;
28250 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28251 #endif
28252 {
28253    RgSchCmnDlUe     *ueDl;
28254    RgSchDlRbAlloc   *allocInfo;
28255    U8               numRb;
28256    U8               noTxLyrs;
28257    U8               precInfo;
28258    S16              ret;
28259    U8               precInfoAntIdx;
28260
28261
28262    ret = ROK;
28263    ueDl = RG_SCH_CMN_GET_DL_UE(ue,cell);
28264    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
28265
28266    /* Integration_fix: SPS Proc shall always have only one Cw */
28267 #ifdef LTEMAC_SPS
28268 #ifdef FOUR_TX_ANTENNA
28269       if ((RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc)) ||
28270                      (ueDl->mimoInfo.forceTD) || proc->hasDcch) /*Chandra Avoid DCCH to be SM */
28271 #else
28272    if ((RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc)) ||
28273          (ueDl->mimoInfo.forceTD))
28274 #endif
28275 #else
28276    if (ueDl->mimoInfo.forceTD) /* Transmit Diversity (TD) */
28277 #endif
28278    {
28279       allocInfo->dciFormat = rgSCHCmnSlctPdcchFrmt(cell, ue, \
28280             &allocInfo->raType);
28281       ret = rgSCHCmnDlAlloc1CwTxRb(cell, subFrm, ue, &proc->tbInfo[0],\
28282             bo, &numRb, effBo);
28283       if (ret == RFAILED)
28284       {
28285          /* If allocation couldn't be made then return */
28286          RETVOID;
28287       }
28288       noTxLyrs = 1;
28289       precInfo = 0; /* TD */
28290    }
28291    else /* Precoding */
28292    {
28293       allocInfo->dciFormat = TFU_DCI_FORMAT_2A;
28294       allocInfo->raType    = RG_SCH_CMN_RA_TYPE0;
28295
28296       /* Spatial Multiplexing using 2 CWs */
28297       ret = rgSCHCmnDlAlloc2CwTxRb(cell, subFrm, ue, proc, bo, &numRb, effBo);
28298       if (ret == RFAILED)
28299       {
28300          /* If allocation couldn't be made then return */
28301          RETVOID;
28302       }
28303       noTxLyrs = ueDl->mimoInfo.ri;
28304       precInfoAntIdx = cell->numTxAntPorts/2 - 1;
28305       RGSCH_ARRAY_BOUND_CHECK(cell->instIdx, getPrecInfoFunc[0], precInfoAntIdx);
28306       precInfo = (getPrecInfoFunc[0][precInfoAntIdx])(cell, ue, noTxLyrs, TRUE);
28307    }
28308
28309 #ifdef LTEMAC_SPS
28310    if (!RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc))
28311 #endif
28312    {
28313       /* Adding UE to RbAllocInfo TX Lst */
28314       rgSCHCmnDlRbInfoAddUeTx(cell, cellWdAllocInfo, ue, proc);
28315    }
28316    /* Fill UE allocInfo scrath pad */
28317    RG_SCH_CMN_FILL_DL_TXINFO(allocInfo, numRb, FALSE, \
28318          precInfo, noTxLyrs, subFrm);
28319
28320    RETVOID;
28321 }
28322
28323 \f
28324 /**
28325  * @brief This function handles Retx allocation in case of TM4 UEs
28326  *        where previously both the TBs were ACKED and ACKED
28327  *        respectively.
28328  *
28329  * @details
28330  *
28331  *     Function: rgSCHCmnDlTM4TxTx
28332  *     Purpose:  Reached here for a TM4 UE's HqP's fresh allocation
28333  *                  where both the TBs are free for TX scheduling.
28334  *               If forceTD flag is set
28335  *                  perform TD on CW1 with TB1.
28336  *                  precInfo = 0
28337  *               else
28338  *                  DCI Format = 2.
28339  *                  RA Type = Type0.
28340  *                  If Rank == 1
28341  *                     Single layer precoding of TB1 on CW1.
28342  *                     Set precoding info.
28343  *                  else
28344  *                     RI layered precoding 2 TB on 2 CW.
28345  *                     Set precoding info.
28346  *               Add UE to cellAllocInfo.
28347  *               Fill ueAllocInfo.
28348  *
28349  *              effBo is set to a non-zero value if allocation is
28350  *              successful.
28351  *
28352  *     Invoked by: rgSCHCmnDlAllocRbTM4
28353  *
28354  *  @param[in]  RgSchCellCb           *cell
28355  *  @param[in]  RgSchDlSf             *subFrm
28356  *  @param[in]  RgSchUeCb             *ue
28357  *  @param[in]  U32                   bo
28358  *  @param[out] U32                   *effBo
28359  *  @param[in]  RgSchDlHqProcCb       *proc
28360  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28361  *  @return  Void
28362  *
28363  **/
28364 #ifdef ANSI
28365 PRIVATE Void rgSCHCmnDlTM4TxTx
28366 (
28367 RgSchCellCb                *cell,
28368 RgSchDlSf                  *subFrm,
28369 RgSchUeCb                  *ue,
28370 U32                        bo,
28371 U32                        *effBo,
28372 RgSchDlHqProcCb            *proc,
28373 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28374 )
28375 #else
28376 PRIVATE Void rgSCHCmnDlTM4TxTx(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28377 RgSchCellCb                *cell;
28378 RgSchDlSf                  *subFrm;
28379 RgSchUeCb                  *ue;
28380 U32                        bo;
28381 U32                        *effBo;
28382 RgSchDlHqProcCb            *proc;
28383 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28384 #endif
28385 {
28386    RgSchCmnDlUe     *ueDl;
28387    RgSchDlRbAlloc   *allocInfo;
28388    U8               numRb;
28389    U8               precInfo;
28390    U8               noTxLyrs;
28391    U8               precInfoAntIdx;
28392    S16              ret;
28393
28394
28395    ret       = ROK;
28396    ueDl      = RG_SCH_CMN_GET_DL_UE(ue,cell);
28397    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
28398
28399    /* Integration_fix: SPS Proc shall always have only one Cw */
28400 #ifdef LTEMAC_SPS
28401 #ifdef FOUR_TX_ANTENNA
28402    if ((RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc)) ||
28403                   (ueDl->mimoInfo.forceTD) || proc->hasDcch) /*Chandra Avoid DCCH to be SM */
28404 #else
28405    if ((RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc)) ||
28406          (ueDl->mimoInfo.forceTD))
28407 #endif
28408 #else
28409    if (ueDl->mimoInfo.forceTD) /* Transmit Diversity (TD) */
28410 #endif
28411    {
28412       allocInfo->dciFormat = rgSCHCmnSlctPdcchFrmt(cell, ue, \
28413             &allocInfo->raType);
28414
28415       ret = rgSCHCmnDlAlloc1CwTxRb(cell, subFrm, ue, &proc->tbInfo[0],\
28416             bo, &numRb, effBo);
28417       if (ret == RFAILED)
28418       {
28419          /* If allocation couldn't be made then return */
28420          RETVOID;
28421       }
28422       noTxLyrs = 1;
28423       precInfo = 0; /* TD */
28424    }
28425    else /* Precoding */
28426    {
28427       allocInfo->dciFormat = TFU_DCI_FORMAT_2;
28428       allocInfo->raType    = RG_SCH_CMN_RA_TYPE0;
28429
28430       if (ueDl->mimoInfo.ri == 1)
28431       {
28432          /* Single Layer SM using FORMAT 2 */
28433          ret = rgSCHCmnDlAlloc1CwTxRb(cell, subFrm, ue, &proc->tbInfo[0],\
28434                bo, &numRb, effBo);
28435          if (ret == RFAILED)
28436          {
28437             /* If allocation couldn't be made then return */
28438             RETVOID;
28439          }
28440          noTxLyrs = 1;
28441          precInfo = 0; /* PrecInfo as 0 for RI=1*/
28442       }
28443       else
28444       {
28445          /* Spatial Multiplexing using 2 CWs */
28446          ret = rgSCHCmnDlAlloc2CwTxRb(cell, subFrm, ue, proc, bo, &numRb, effBo);
28447          if (ret == RFAILED)
28448          {
28449             /* If allocation couldn't be made then return */
28450             RETVOID;
28451          }
28452          noTxLyrs = ueDl->mimoInfo.ri;
28453          precInfoAntIdx = cell->numTxAntPorts/2 - 1; 
28454          precInfo = (getPrecInfoFunc[1][precInfoAntIdx])(cell, ue, noTxLyrs, TRUE);
28455       }
28456    }
28457
28458    
28459 #ifdef LTEMAC_SPS
28460    if (!RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc))
28461 #endif
28462    {
28463       /* Adding UE to RbAllocInfo TX Lst */
28464       rgSCHCmnDlRbInfoAddUeTx(cell, cellWdAllocInfo, ue, proc);
28465    }
28466
28467    /* Fill UE allocInfo scrath pad */
28468    RG_SCH_CMN_FILL_DL_TXINFO(allocInfo, numRb, FALSE, \
28469          precInfo, noTxLyrs, subFrm);
28470
28471    RETVOID;
28472 }
28473
28474 \f
28475 /**
28476  * @brief This function determines the RBs and Bytes required for BO
28477  *        transmission for UEs configured with TM 4.
28478  *
28479  * @details
28480  *
28481  *     Function: rgSCHCmnDlAllocTxRbTM4
28482  *     Purpose:  Invokes the functionality particular to the
28483  *               current state of the TBs of the "proc".
28484  *
28485  *               Reference Parameter effBo is filled with alloced bytes.
28486  *               Returns RFAILED if BO not satisfied at all.
28487  *
28488  *     Invoked by: rgSCHCmnDlAllocTxRb
28489  *
28490  *  @param[in]  RgSchCellCb           *cell
28491  *  @param[in]  RgSchDlSf             *subFrm
28492  *  @param[in]  RgSchUeCb             *ue
28493  *  @param[in]  U32                   bo
28494  *  @param[out] U32                   *effBo
28495  *  @param[in]  RgSchDlHqProcCb       *proc
28496  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28497  *  @return  Void
28498  *
28499  **/
28500 #ifdef ANSI
28501 PRIVATE Void rgSCHCmnDlAllocTxRbTM4
28502 (
28503 RgSchCellCb                *cell,
28504 RgSchDlSf                  *subFrm,
28505 RgSchUeCb                  *ue,
28506 U32                        bo,
28507 U32                        *effBo,
28508 RgSchDlHqProcCb            *proc,
28509 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28510 )
28511 #else
28512 PRIVATE Void rgSCHCmnDlAllocTxRbTM4(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28513 RgSchCellCb                *cell;
28514 RgSchDlSf                  *subFrm;
28515 RgSchUeCb                  *ue;
28516 U32                        bo;
28517 U32                        *effBo;
28518 RgSchDlHqProcCb            *proc;
28519 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28520 #endif
28521 {
28522
28523    /* Both TBs free for TX allocation */
28524    rgSCHCmnDlTM4TxTx(cell, subFrm, ue, bo, effBo,\
28525          proc, cellWdAllocInfo);
28526
28527    RETVOID;
28528 }
28529
28530 \f
28531 /**
28532  * @brief This function determines the RBs and Bytes required for BO
28533  *        retransmission for UEs configured with TM 4.
28534  *
28535  * @details
28536  *
28537  *     Function: rgSCHCmnDlAllocRetxRbTM4
28538  *     Purpose:  Invokes the functionality particular to the
28539  *               current state of the TBs of the "proc".
28540  *
28541  *               Reference Parameter effBo is filled with alloced bytes.
28542  *               Returns RFAILED if BO not satisfied at all.
28543  *
28544  *     Invoked by: rgSCHCmnDlAllocRetxRb
28545  *
28546  *  @param[in]  RgSchCellCb           *cell
28547  *  @param[in]  RgSchDlSf             *subFrm
28548  *  @param[in]  RgSchUeCb             *ue
28549  *  @param[in]  U32                   bo
28550  *  @param[out] U32                   *effBo
28551  *  @param[in]  RgSchDlHqProcCb       *proc
28552  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28553  *  @return  Void
28554  *
28555  **/
28556 #ifdef ANSI
28557 PRIVATE Void rgSCHCmnDlAllocRetxRbTM4
28558 (
28559 RgSchCellCb                *cell,
28560 RgSchDlSf                  *subFrm,
28561 RgSchUeCb                  *ue,
28562 U32                        bo,
28563 U32                        *effBo,
28564 RgSchDlHqProcCb            *proc,
28565 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28566 )
28567 #else
28568 PRIVATE Void rgSCHCmnDlAllocRetxRbTM4(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28569 RgSchCellCb                *cell;
28570 RgSchDlSf                  *subFrm;
28571 RgSchUeCb                  *ue;
28572 U32                        bo;
28573 U32                        *effBo;
28574 RgSchDlHqProcCb            *proc;
28575 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28576 #endif
28577 {
28578
28579    if ((proc->tbInfo[0].state == HQ_TB_NACKED) &&
28580          (proc->tbInfo[1].state == HQ_TB_NACKED))
28581    {
28582       /* Both TBs require RETX allocation */
28583       rgSCHCmnDlTM4RetxRetx(cell, subFrm, ue, bo, effBo,\
28584             proc, cellWdAllocInfo);
28585    }
28586    else
28587    {
28588       /* One of the TBs need RETX allocation. Other TB may/maynot
28589        * be available for new TX allocation. */
28590       rgSCHCmnDlTM4TxRetx(cell, subFrm, ue, bo, effBo,\
28591             proc, cellWdAllocInfo);
28592    }
28593
28594    RETVOID;
28595 }
28596
28597 #ifdef RG_UNUSED
28598 \f
28599 /**
28600  * @brief This function determines the RBs and Bytes required for BO
28601  *        transmission for UEs configured with TM 5.
28602  *
28603  * @details
28604  *
28605  *     Function: rgSCHCmnDlAllocTxRbTM5
28606  *     Purpose:
28607  *
28608  *               Reference Parameter effBo is filled with alloced bytes.
28609  *               Returns RFAILED if BO not satisfied at all.
28610  *
28611  *     Invoked by: rgSCHCmnDlAllocTxRb
28612  *
28613  *  @param[in]  RgSchCellCb           *cell
28614  *  @param[in]  RgSchDlSf             *subFrm
28615  *  @param[in]  RgSchUeCb             *ue
28616  *  @param[in]  U32                   bo
28617  *  @param[out] U32                   *effBo
28618  *  @param[in]  RgSchDlHqProcCb       *proc
28619  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28620  *  @return Void
28621  *
28622  **/
28623 #ifdef ANSI
28624 PRIVATE Void rgSCHCmnDlAllocTxRbTM5
28625 (
28626 RgSchCellCb                *cell,
28627 RgSchDlSf                  *subFrm,
28628 RgSchUeCb                  *ue,
28629 U32                        bo,
28630 U32                        *effBo,
28631 RgSchDlHqProcCb            *proc,
28632 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28633 )
28634 #else
28635 PRIVATE Void rgSCHCmnDlAllocTxRbTM5(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28636 RgSchCellCb                *cell;
28637 RgSchDlSf                  *subFrm;
28638 RgSchUeCb                  *ue;
28639 U32                        bo;
28640 U32                        *effBo;
28641 RgSchDlHqProcCb            *proc;
28642 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28643 #endif
28644 {
28645 #if (ERRCLASS & ERRCLS_DEBUG)
28646    RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "Invalid TM 5 for CRNTI:%d",ue->ueId);
28647 #endif
28648    RETVOID;
28649 }
28650
28651 \f
28652 /**
28653  * @brief This function determines the RBs and Bytes required for BO
28654  *        retransmission for UEs configured with TM 5.
28655  *
28656  * @details
28657  *
28658  *     Function: rgSCHCmnDlAllocRetxRbTM5
28659  *     Purpose:
28660  *
28661  *               Reference Parameter effBo is filled with alloced bytes.
28662  *               Returns RFAILED if BO not satisfied at all.
28663  *
28664  *     Invoked by: rgSCHCmnDlAllocRetxRb
28665  *
28666  *  @param[in]  RgSchCellCb           *cell
28667  *  @param[in]  RgSchDlSf             *subFrm
28668  *  @param[in]  RgSchUeCb             *ue
28669  *  @param[in]  U32                   bo
28670  *  @param[out] U32                   *effBo
28671  *  @param[in]  RgSchDlHqProcCb       *proc
28672  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28673  *  @return Void
28674  *
28675  **/
28676 #ifdef ANSI
28677 PRIVATE Void rgSCHCmnDlAllocRetxRbTM5
28678 (
28679 RgSchCellCb                *cell,
28680 RgSchDlSf                  *subFrm,
28681 RgSchUeCb                  *ue,
28682 U32                        bo,
28683 U32                        *effBo,
28684 RgSchDlHqProcCb            *proc,
28685 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28686 )
28687 #else
28688 PRIVATE Void rgSCHCmnDlAllocRetxRbTM5(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28689 RgSchCellCb                *cell;
28690 RgSchDlSf                  *subFrm;
28691 RgSchUeCb                  *ue;
28692 U32                        bo;
28693 U32                        *effBo;
28694 RgSchDlHqProcCb            *proc;
28695 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28696 #endif
28697 {
28698 #if (ERRCLASS & ERRCLS_DEBUG)
28699    RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "Invalid TM 5 for CRNTI:%d",ue->ueId);
28700 #endif
28701    RETVOID;
28702 }
28703 #endif
28704
28705 \f
28706 /**
28707  * @brief This function determines the RBs and Bytes required for BO
28708  *        transmission for UEs configured with TM 6.
28709  *
28710  * @details
28711  *
28712  *     Function: rgSCHCmnDlAllocTxRbTM6
28713  *     Purpose:
28714  *
28715  *               Reference Parameter effBo is filled with alloced bytes.
28716  *               Returns RFAILED if BO not satisfied at all.
28717  *
28718  *     Invoked by: rgSCHCmnDlAllocTxRb
28719  *
28720  *  @param[in]  RgSchCellCb           *cell
28721  *  @param[in]  RgSchDlSf             *subFrm
28722  *  @param[in]  RgSchUeCb             *ue
28723  *  @param[in]  U32                   bo
28724  *  @param[out] U32                   *effBo
28725  *  @param[in]  RgSchDlHqProcCb       *proc
28726  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28727  *  @return Void
28728  *
28729  **/
28730 #ifdef ANSI
28731 PRIVATE Void rgSCHCmnDlAllocTxRbTM6
28732 (
28733 RgSchCellCb                *cell,
28734 RgSchDlSf                  *subFrm,
28735 RgSchUeCb                  *ue,
28736 U32                        bo,
28737 U32                        *effBo,
28738 RgSchDlHqProcCb            *proc,
28739 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28740 )
28741 #else
28742 PRIVATE Void rgSCHCmnDlAllocTxRbTM6(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28743 RgSchCellCb                *cell;
28744 RgSchDlSf                  *subFrm;
28745 RgSchUeCb                  *ue;
28746 U32                        bo;
28747 U32                        *effBo;
28748 RgSchDlHqProcCb            *proc;
28749 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28750 #endif
28751 {
28752    RgSchDlRbAlloc *allocInfo;
28753    RgSchCmnDlUe   *ueDl;
28754    S16            ret;
28755    U8             numRb;
28756
28757
28758    ret       = ROK;
28759    ueDl      = RG_SCH_CMN_GET_DL_UE(ue,cell);
28760    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
28761
28762    if (ueDl->mimoInfo.forceTD)
28763    {
28764       allocInfo->dciFormat = TFU_DCI_FORMAT_1A;
28765       allocInfo->raType    = RG_SCH_CMN_RA_TYPE2;
28766    }
28767    else
28768    {
28769       allocInfo->dciFormat = TFU_DCI_FORMAT_1B;
28770       allocInfo->raType    = RG_SCH_CMN_RA_TYPE2;
28771       /* Fill precoding information for FORMAT 1B */
28772       /* First 4 least significant bits to indicate PMI.
28773        * 4th most significant corresponds to pmi Confirmation.
28774        */
28775       allocInfo->mimoAllocInfo.precIdxInfo |= ue->mimoInfo.puschFdbkVld << 4;
28776       allocInfo->mimoAllocInfo.precIdxInfo |= ueDl->mimoInfo.pmi;
28777    }
28778    ret = rgSCHCmnDlAlloc1CwTxRb(cell, subFrm, ue, &proc->tbInfo[0],\
28779          bo, &numRb, effBo);
28780    if (ret == RFAILED)
28781    {
28782       /* If allocation couldn't be made then return */
28783       RETVOID;
28784    }
28785    
28786 #ifdef LTEMAC_SPS
28787    if (!RG_SCH_CMN_SPS_DL_IS_SPS_HQP(proc))
28788 #endif
28789    {
28790       /* Adding UE to RbAllocInfo TX Lst */
28791       rgSCHCmnDlRbInfoAddUeTx(cell, cellWdAllocInfo, ue, proc);
28792    }
28793    /* Fill UE alloc Info */
28794    allocInfo->rbsReq = numRb;
28795    allocInfo->dlSf   = subFrm;
28796    RETVOID;
28797 }
28798
28799 \f
28800 /**
28801  * @brief This function determines the RBs and Bytes required for BO
28802  *        retransmission for UEs configured with TM 6.
28803  *
28804  * @details
28805  *
28806  *     Function: rgSCHCmnDlAllocRetxRbTM6
28807  *     Purpose:
28808  *
28809  *               Reference Parameter effBo is filled with alloced bytes.
28810  *               Returns RFAILED if BO not satisfied at all.
28811  *
28812  *     Invoked by: rgSCHCmnDlAllocRetxRb
28813  *
28814  *  @param[in]  RgSchCellCb           *cell
28815  *  @param[in]  RgSchDlSf             *subFrm
28816  *  @param[in]  RgSchUeCb             *ue
28817  *  @param[in]  U32                   bo
28818  *  @param[out] U32                   *effBo
28819  *  @param[in]  RgSchDlHqProcCb       *proc
28820  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28821  *  @return Void
28822  *
28823  **/
28824 #ifdef ANSI
28825 PRIVATE Void rgSCHCmnDlAllocRetxRbTM6
28826 (
28827 RgSchCellCb                *cell,
28828 RgSchDlSf                  *subFrm,
28829 RgSchUeCb                  *ue,
28830 U32                        bo,
28831 U32                        *effBo,
28832 RgSchDlHqProcCb            *proc,
28833 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28834 )
28835 #else
28836 PRIVATE Void rgSCHCmnDlAllocRetxRbTM6(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28837 RgSchCellCb                *cell;
28838 RgSchDlSf                  *subFrm;
28839 RgSchUeCb                  *ue;
28840 U32                        bo;
28841 U32                        *effBo;
28842 RgSchDlHqProcCb            *proc;
28843 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28844 #endif
28845 {
28846    RgSchDlRbAlloc *allocInfo;
28847    RgSchCmnDlUe   *ueDl;
28848    S16            ret;
28849    U8             numRb;
28850
28851
28852    ret       = ROK;
28853    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
28854    ueDl      = RG_SCH_CMN_GET_DL_UE(ue,cell);
28855
28856    if (ueDl->mimoInfo.forceTD)
28857    {
28858       allocInfo->dciFormat = TFU_DCI_FORMAT_1A;
28859       allocInfo->raType    = RG_SCH_CMN_RA_TYPE2;
28860    }
28861    else
28862    {
28863       allocInfo->dciFormat = TFU_DCI_FORMAT_1B;
28864       allocInfo->raType    = RG_SCH_CMN_RA_TYPE2;
28865       /* Fill precoding information for FORMAT 1B */
28866       /* First 4 least significant bits to indicate PMI.
28867        * 4th most significant corresponds to pmi Confirmation.
28868        */
28869       allocInfo->mimoAllocInfo.precIdxInfo |= ue->mimoInfo.puschFdbkVld << 4;
28870       allocInfo->mimoAllocInfo.precIdxInfo |= ueDl->mimoInfo.pmi;
28871    }
28872
28873    /* Get the Allocation in terms of RBs that are required for
28874     * this retx of TB1 */
28875    ret = rgSCHCmnDlAlloc1CwRetxRb(cell, subFrm, ue, &proc->tbInfo[0],
28876          1, &numRb, effBo);
28877    if (ret == RFAILED)
28878    {
28879       /* Allocation couldn't be made for Retx */
28880       rgSCHCmnDlAdd2NonSchdRetxLst(cellWdAllocInfo, ue, proc);
28881       RETVOID;
28882    }
28883    /* Adding UE to allocInfo RETX Lst */
28884    rgSCHCmnDlRbInfoAddUeRetx(cell, cellWdAllocInfo, ue, proc);
28885    /* Fill UE alloc Info */
28886    allocInfo->rbsReq = numRb;
28887    allocInfo->dlSf   = subFrm;
28888    RETVOID;
28889 }
28890
28891 \f
28892 /**
28893  * @brief This function determines the RBs and Bytes required for BO
28894  *        transmission for UEs configured with TM 7.
28895  *
28896  * @details
28897  *
28898  *     Function: rgSCHCmnDlAllocTxRbTM7
28899  *     Purpose:
28900  *
28901  *               Reference Parameter effBo is filled with alloced bytes.
28902  *               Returns RFAILED if BO not satisfied at all.
28903  *
28904  *     Invoked by: rgSCHCmnDlAllocTxRb
28905  *
28906  *  @param[in]  RgSchCellCb           *cell
28907  *  @param[in]  RgSchDlSf             *subFrm
28908  *  @param[in]  RgSchUeCb             *ue
28909  *  @param[in]  U32                   bo
28910  *  @param[out] U32                   *effBo
28911  *  @param[in]  RgSchDlHqProcCb       *proc
28912  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28913  *  @return Void
28914  *
28915  **/
28916 #ifdef ANSI
28917 PRIVATE Void rgSCHCmnDlAllocTxRbTM7
28918 (
28919 RgSchCellCb                *cell,
28920 RgSchDlSf                  *subFrm,
28921 RgSchUeCb                  *ue,
28922 U32                        bo,
28923 U32                        *effBo,
28924 RgSchDlHqProcCb            *proc,
28925 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28926 )
28927 #else
28928 PRIVATE Void rgSCHCmnDlAllocTxRbTM7(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28929 RgSchCellCb                *cell;
28930 RgSchDlSf                  *subFrm;
28931 RgSchUeCb                  *ue;
28932 U32                        bo;
28933 U32                        *effBo;
28934 RgSchDlHqProcCb            *proc;
28935 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28936 #endif
28937 {
28938    rgSCHCmnDlAllocTxRb1Tb1Cw(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo);
28939    RETVOID;
28940 }
28941
28942 \f
28943 /**
28944  * @brief This function determines the RBs and Bytes required for BO
28945  *        retransmission for UEs configured with TM 7.
28946  *
28947  * @details
28948  *
28949  *     Function: rgSCHCmnDlAllocRetxRbTM7
28950  *     Purpose:
28951  *
28952  *               Reference Parameter effBo is filled with alloced bytes.
28953  *               Returns RFAILED if BO not satisfied at all.
28954  *
28955  *     Invoked by: rgSCHCmnDlAllocRetxRb
28956  *
28957  *  @param[in]  RgSchCellCb           *cell
28958  *  @param[in]  RgSchDlSf             *subFrm
28959  *  @param[in]  RgSchUeCb             *ue
28960  *  @param[in]  U32                   bo
28961  *  @param[out] U32                   *effBo
28962  *  @param[in]  RgSchDlHqProcCb       *proc
28963  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
28964  *  @return Void
28965  *
28966  **/
28967 #ifdef ANSI
28968 PRIVATE Void rgSCHCmnDlAllocRetxRbTM7
28969 (
28970 RgSchCellCb                *cell,
28971 RgSchDlSf                  *subFrm,
28972 RgSchUeCb                  *ue,
28973 U32                        bo,
28974 U32                        *effBo,
28975 RgSchDlHqProcCb            *proc,
28976 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
28977 )
28978 #else
28979 PRIVATE Void rgSCHCmnDlAllocRetxRbTM7(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
28980 RgSchCellCb                *cell;
28981 RgSchDlSf                  *subFrm;
28982 RgSchUeCb                  *ue;
28983 U32                        bo;
28984 U32                        *effBo;
28985 RgSchDlHqProcCb            *proc;
28986 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
28987 #endif
28988 {
28989    rgSCHCmnDlAllocRetxRb1Tb1Cw(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo);
28990    RETVOID;
28991 }
28992
28993 \f
28994 /**
28995  * @brief This function invokes the TM specific DL TX RB Allocation routine.
28996  *
28997  * @details
28998  *
28999  *     Function: rgSCHCmnDlAllocTxRb
29000  *     Purpose:  This function invokes the TM specific
29001  *               DL TX RB Allocation routine.
29002  *
29003  *     Invoked by: Specific Schedulers
29004  *
29005  *  @param[in]  RgSchCellCb           *cell
29006  *  @param[in]  RgSchDlSf             *subFrm
29007  *  @param[in]  RgSchUeCb             *ue
29008  *  @param[in]  U32                   bo
29009  *  @param[out] U32                   *effBo
29010  *  @param[in]  RgSchDlHqProcCb       *proc
29011  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
29012  *  @return  S16
29013  *
29014  **/
29015 #ifdef ANSI
29016 S16 rgSCHCmnDlAllocTxRb
29017 (
29018 RgSchCellCb                *cell,
29019 RgSchDlSf                  *subFrm,
29020 RgSchUeCb                  *ue,
29021 U32                        bo,
29022 U32                        *effBo,
29023 RgSchDlHqProcCb            *proc,
29024 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
29025 )
29026 #else
29027 S16 rgSCHCmnDlAllocTxRb(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
29028 RgSchCellCb                *cell;
29029 RgSchDlSf                  *subFrm;
29030 RgSchUeCb                  *ue;
29031 U32                        bo;
29032 U32                        *effBo;
29033 RgSchDlHqProcCb            *proc;
29034 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
29035 #endif
29036 {
29037    U32                     newSchBits = 0;
29038    U32                     prevSchBits = 0;
29039    RgSchDlRbAlloc          *allocInfo;
29040
29041
29042    if ( !RGSCH_TIMEINFO_SAME((cell->crntTime),(ue->dl.lstSchTime) ))
29043    {
29044       ue->dl.aggTbBits = 0;
29045    }
29046    *effBo = 0;
29047
29048    /* Calculate totals bits previously allocated */
29049    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
29050    if (allocInfo->tbInfo[0].schdlngForTb)
29051    {
29052       prevSchBits += allocInfo->tbInfo[0].bytesReq;
29053    }
29054    if (allocInfo->tbInfo[1].schdlngForTb)
29055    {
29056       prevSchBits += allocInfo->tbInfo[1].bytesReq;
29057    }
29058
29059    /* Call TM specific RB allocation routine */
29060    (dlAllocTxRbFunc[ue->mimoInfo.txMode - 1])(cell, subFrm, ue, bo, effBo, \
29061          proc, cellWdAllocInfo);
29062
29063    if (*effBo)
29064    {
29065       /* Calculate totals bits newly allocated */
29066       if (allocInfo->tbInfo[0].schdlngForTb)
29067       {
29068          newSchBits += allocInfo->tbInfo[0].bytesReq;
29069       }
29070       if (allocInfo->tbInfo[1].schdlngForTb)
29071       {
29072          newSchBits += allocInfo->tbInfo[1].bytesReq;
29073       }
29074       if (newSchBits > prevSchBits)
29075       {
29076          ue->dl.aggTbBits += ((newSchBits - prevSchBits) * 8);
29077          RGSCHCPYTIMEINFO((cell->crntTime),(ue->dl.lstSchTime))
29078       }
29079    }
29080
29081    return ROK;
29082 }
29083
29084 /* DwPTS Scheduling Changes Start */
29085 #ifdef LTE_TDD
29086 /**
29087  * @brief Retransmit decision for TDD. Retx is avoided in below cases
29088  *        1) DL Sf       -> Spl Sf
29089  *        2) DL SF       -> DL SF 0 
29090  *
29091  * @details
29092  *
29093  *     Function: rgSCHCmnRetxAvoidTdd 
29094  *     Purpose: Avoid allocating RETX for cases 1, 2 
29095  * 
29096  *     Invoked by: rgSCHCmnRetxAvoidTdd 
29097  *
29098  *  @param[in]  RgSchDlSf             *curSf
29099  *  @param[in]  RgSchCellCb           *cell
29100  *  @param[in]  RgSchDlHqProcCb       *proc
29101  *  @return  Bool 
29102  *
29103  **/
29104 #ifdef ANSI
29105 Bool rgSCHCmnRetxAvoidTdd 
29106 (
29107 RgSchDlSf                  *curSf,
29108 RgSchCellCb                *cell,
29109 RgSchDlHqProcCb            *proc
29110 )
29111 #else
29112 Bool rgSCHCmnRetxAvoidTdd(curSf, cell, proc)
29113 RgSchDlSf                  *curSf;
29114 RgSchCellCb                *cell;
29115 RgSchDlHqProcCb            *proc;
29116 #endif
29117 {
29118    RgSchTddSfType   txSfType = 0;
29119
29120
29121    /* Get the RBs of TB that will be retransmitted */
29122    if (proc->tbInfo[0].state == HQ_TB_NACKED)
29123    {
29124       txSfType = proc->tbInfo[0].sfType;
29125
29126 #ifdef XEON_SPECIFIC_CHANGES
29127 #ifndef XEON_TDD_SPCL
29128       /* Avoid re-transmission on Normal SF when the corresponding TB wss transmitted on SPCL SF */
29129       if(txSfType <= RG_SCH_SPL_SF_DATA && curSf->sfType >= RG_SCH_DL_SF_0)
29130       {
29131          return (TRUE);
29132       }
29133 #endif
29134 #endif
29135    }
29136    if (proc->tbInfo[1].state == HQ_TB_NACKED) 
29137    {
29138       /* Select the TxSf with the highest num of possible REs 
29139        * In ascending order -> 1) SPL SF 2) DL_SF_0 3) DL_SF */
29140       txSfType = RGSCH_MAX(txSfType, proc->tbInfo[1].sfType);
29141
29142 #ifdef XEON_SPECIFIC_CHANGES
29143 #ifndef XEON_TDD_SPCL
29144       /* Avoid re-transmission on Normal SF when the corresponding TB wss tranmitted on SPCL SF */
29145       if(txSfType <= RG_SCH_SPL_SF_DATA && curSf->sfType >= RG_SCH_DL_SF_0)
29146       {
29147          return (TRUE);
29148       }
29149 #endif
29150 #endif
29151    }
29152
29153    if (txSfType > curSf->sfType)
29154    {
29155       /* Avoid retx */
29156       return (TRUE);
29157    }
29158    
29159    /* Allow Retx */
29160    return (FALSE);
29161 }
29162
29163 #else
29164 /* DwPTS Scheduling Changes End */
29165 \f
29166 /**
29167  * @brief Avoid allocating RETX incase of collision
29168  * with reserved resources for BCH/PSS/SSS occassions.
29169  *
29170  * @details
29171  *
29172  *     Function: rgSCHCmnRetxAllocAvoid 
29173  *     Purpose: Avoid allocating RETX incase of collision
29174  * with reserved resources for BCH/PSS/SSS occassions 
29175  *
29176  *     Invoked by: rgSCHCmnDlAllocRetxRb 
29177  *
29178  *  @param[in]  RgSchDlSf             *subFrm
29179  *  @param[in]  RgSchUeCb             *ue
29180  *  @param[in]  RgSchDlHqProcCb       *proc
29181  *  @return  Bool 
29182  *
29183  **/
29184 #ifdef ANSI
29185 Bool rgSCHCmnRetxAllocAvoid 
29186 (
29187 RgSchDlSf                  *subFrm,
29188 RgSchCellCb                *cell,
29189 RgSchDlHqProcCb            *proc
29190 )
29191 #else
29192 Bool rgSCHCmnRetxAllocAvoid(subFrm, cell, proc)
29193 RgSchDlSf                  *subFrm;
29194 RgSchCellCb                *cell;
29195 RgSchDlHqProcCb            *proc;
29196 #endif
29197 {
29198    U8          reqRbs;
29199
29200
29201    if (proc->tbInfo[0].state == HQ_TB_NACKED)
29202    {
29203       reqRbs = proc->tbInfo[0].dlGrnt.numRb;    
29204    }
29205    else
29206    {
29207       reqRbs = proc->tbInfo[1].dlGrnt.numRb;    
29208    }
29209    /* Consider the dlGrnt.numRb of the Retransmitting proc->tbInfo
29210     * and current available RBs to determine if this RETX TB
29211     * will collide with the BCH/PSS/SSS occassion */
29212    if (subFrm->sfNum % 5 == 0)
29213    {
29214       if ((subFrm->bwAssigned < cell->pbchRbEnd) &&
29215           (((subFrm->bwAssigned + reqRbs) - cell->pbchRbStart) > 0))
29216       {
29217          return (TRUE);
29218       }
29219    }
29220    return (FALSE);
29221 }
29222
29223 #endif
29224
29225 \f
29226 /**
29227  * @brief This function invokes the TM specific DL RETX RB Allocation routine.
29228  *
29229  * @details
29230  *
29231  *     Function: rgSCHCmnDlAllocRetxRb
29232  *     Purpose:  This function invokes the TM specific
29233  *               DL RETX RB Allocation routine.
29234  *
29235  *     Invoked by: Specific Schedulers
29236  *
29237  *  @param[in]  RgSchCellCb           *cell
29238  *  @param[in]  RgSchDlSf             *subFrm
29239  *  @param[in]  RgSchUeCb             *ue
29240  *  @param[in]  U32                   bo
29241  *  @param[out] U32                   *effBo
29242  *  @param[in]  RgSchDlHqProcCb       *proc
29243  *  @param[out] RgSchCmnDlRbAllocInfo *cellWdAllocInfo
29244  *  @return  S16
29245  *
29246  **/
29247 #ifdef ANSI
29248 S16 rgSCHCmnDlAllocRetxRb
29249 (
29250 RgSchCellCb                *cell,
29251 RgSchDlSf                  *subFrm,
29252 RgSchUeCb                  *ue,
29253 U32                        bo,
29254 U32                        *effBo,
29255 RgSchDlHqProcCb            *proc,
29256 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo
29257 )
29258 #else
29259 S16 rgSCHCmnDlAllocRetxRb(cell, subFrm, ue, bo, effBo, proc, cellWdAllocInfo)
29260 RgSchCellCb                *cell;
29261 RgSchDlSf                  *subFrm;
29262 RgSchUeCb                  *ue;
29263 U32                        bo;
29264 U32                        *effBo;
29265 RgSchDlHqProcCb            *proc;
29266 RgSchCmnDlRbAllocInfo      *cellWdAllocInfo;
29267 #endif
29268 {
29269    U32                     newSchBits = 0;
29270    RgSchDlRbAlloc          *allocInfo;
29271
29272
29273    if ( !RGSCH_TIMEINFO_SAME((cell->crntTime),(ue->dl.lstSchTime) ))
29274    {
29275       ue->dl.aggTbBits = 0;
29276    }
29277  
29278    *effBo = 0;
29279    /* Check for DL BW exhaustion */
29280    if (subFrm->bw <= subFrm->bwAssigned)
29281    {
29282       return RFAILED;
29283    }
29284    /* Call TM specific RB allocation routine */
29285    (dlAllocRetxRbFunc[ue->mimoInfo.txMode - 1])(cell, subFrm, ue, bo, effBo, \
29286          proc, cellWdAllocInfo);
29287
29288    if (*effBo)
29289    {
29290       allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
29291       /* Calculate totals bits newly allocated */
29292       if (allocInfo->tbInfo[0].schdlngForTb)
29293       {
29294          newSchBits += allocInfo->tbInfo[0].bytesReq;
29295       }
29296       if (allocInfo->tbInfo[1].schdlngForTb)
29297       {
29298          newSchBits += allocInfo->tbInfo[1].bytesReq;
29299       }
29300       ue->dl.aggTbBits += (newSchBits * 8);
29301       RGSCHCPYTIMEINFO((cell->crntTime),(ue->dl.lstSchTime))
29302    }
29303    
29304    return ROK;
29305 }
29306
29307 \f
29308 /**
29309  * @brief This function determines the RBs and Bytes required for
29310  *        Transmission on 1 CW.
29311  *
29312  * @details
29313  *
29314  *     Function: rgSCHCmnDlAlloc1CwTxRb
29315  *     Purpose:  This function determines the RBs and Bytes required
29316  *               for Transmission of DL SVC BO on 1 CW.
29317  *               Also, takes care of SVC by SVC allocation by tracking
29318  *               previous SVCs allocations.
29319  *               Returns RFAILED if BO not satisfied at all.
29320  *
29321  *     Invoked by: DL UE Allocation
29322  *
29323  *  @param[in]  RgSchCellCb      *cell
29324  *  @param[in]  RgSchDlSf        *subFrm
29325  *  @param[in]  RgSchUeCb        *ue
29326  *  @param[in]  RgSchDlHqTbCb    *tbInfo
29327  *  @param[in]  U32              bo
29328  *  @param[out] U8               *numRb
29329  *  @param[out] U32              *effBo
29330  *  @return  S16
29331  *
29332  **/
29333 #ifdef ANSI
29334 PRIVATE S16 rgSCHCmnDlAlloc1CwTxRb
29335 (
29336 RgSchCellCb                *cell,
29337 RgSchDlSf                  *subFrm,
29338 RgSchUeCb                  *ue,
29339 RgSchDlHqTbCb              *tbInfo,
29340 U32                        bo,
29341 U8                         *numRb,
29342 U32                        *effBo
29343 )
29344 #else
29345 PRIVATE S16 rgSCHCmnDlAlloc1CwTxRb(cell, subFrm, ue, tbInfo, bo, numRb, effBo)
29346 RgSchCellCb                *cell;
29347 RgSchDlSf                  *subFrm;
29348 RgSchUeCb                  *ue;
29349 RgSchDlHqTbCb              *tbInfo;
29350 U32                        bo;
29351 U8                         *numRb;
29352 U32                        *effBo;
29353 #endif
29354 {
29355    U32                tbSz;
29356    U8                 imcs;
29357    U8                 iTbs;
29358    RgSchCmnDlUe       *ueDl;
29359    RgSchDlRbAlloc     *allocInfo;
29360    U32                oldReq;
29361    U32                reqBytes;
29362    /* Correcting wrap around issue.
29363     * This change has been done at mutliple places in this function.*/
29364    U32                tempNumRb;
29365
29366    reqBytes  = bo;
29367    ueDl      = RG_SCH_CMN_GET_DL_UE(ue,cell);
29368    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
29369    oldReq    = ueDl->outStndAlloc;
29370
29371 #ifdef RG_5GTF
29372    //TODO_SID: Currently setting max Tb size wrt to 5GTF TM3
29373    iTbs = ue->ue5gtfCb.mcs;
29374    ueDl->maxTbSz = MAX_5GTF_TB_SIZE * ue->ue5gtfCb.rank;
29375    ueDl->maxRb = MAX_5GTF_PRBS;
29376 #endif
29377    ueDl->outStndAlloc += bo;
29378    /* consider Cumulative amount of this BO and bytes so far allocated */
29379    bo = RGSCH_MIN(ueDl->outStndAlloc, ueDl->maxTbSz/8);
29380    /* Get the number of REs needed for this bo. */
29381    //noRes = ((bo * 8 * 1024) / eff);
29382
29383    /* Get the number of RBs needed for this transmission */
29384    /* Number of RBs = No of REs / No of REs per RB       */
29385    //tempNumRb = RGSCH_CEIL(noRes, cellDl->noResPerRb[cfi]);
29386    tempNumRb = MAX_5GTF_PRBS;
29387    tbSz = RGSCH_MIN(bo, (rgSch5gtfTbSzTbl[iTbs]/8) * ue->ue5gtfCb.rank);
29388
29389    /* DwPts Scheduling Changes End */
29390    *effBo = RGSCH_MIN(tbSz - oldReq, reqBytes);
29391
29392 #ifdef RG_5GTF
29393    //RG_SCH_CMN_DL_TBS_TO_MCS(iTbs, imcs);
29394    imcs = iTbs;
29395 #endif
29396
29397
29398    RG_SCH_CMN_FILL_DL_TBINFO(&allocInfo->tbInfo[0], tbSz, \
29399          iTbs, imcs, tbInfo, ue->ue5gtfCb.rank);
29400    *numRb = (U8) tempNumRb;
29401    
29402    /* Update the subframe Allocated BW field */
29403    subFrm->bwAssigned = subFrm->bwAssigned + tempNumRb - allocInfo->rbsReq;
29404    
29405    return ROK;
29406 }
29407
29408 \f
29409 /**
29410  * @brief This function is invoked in the event of any TB's allocation
29411  *  being underutilized by the specific scheduler. Here we reduce iMcs
29412  *  to increase redundancy and hence increase reception quality at UE.
29413  *
29414  * @details
29415  *
29416  *     Function: rgSCHCmnRdcImcsTxTb
29417  *     Purpose:  This function shall reduce the iMcs in accordance with
29418  *               the total consumed bytes by the UE at allocation
29419  *               finalization.
29420  *
29421  *     Invoked by: UE DL Allocation finalization routine
29422  *                 of specific scheduler.
29423  *
29424  *  @param[in]  RgSchDlRbAlloc   *allocInfo
29425  *  @param[in]  U8               tbInfoIdx
29426  *  @param[in]  U32              cnsmdBytes
29427  *  @return  Void
29428  *
29429  **/
29430 #ifdef ANSI
29431 Void rgSCHCmnRdcImcsTxTb
29432 (
29433 RgSchDlRbAlloc   *allocInfo,
29434 U8               tbInfoIdx,
29435 U32              cnsmdBytes
29436 )
29437 #else
29438 Void rgSCHCmnRdcImcsTxTb(allocInfo, tbInfoIdx, cnsmdBytes)
29439 RgSchDlRbAlloc   *allocInfo;
29440 U8               tbInfoIdx;
29441 U32              cnsmdBytes;
29442 #endif
29443 {
29444    RETVOID;
29445    /*The below functionality is not needed.*/
29446    U8                 noLyr;
29447    U8                 iTbs;
29448    U16                numRb;
29449
29450
29451    iTbs = allocInfo->tbInfo[tbInfoIdx].iTbs;
29452    noLyr = allocInfo->tbInfo[tbInfoIdx].noLyr;
29453    numRb = allocInfo->rbsAlloc;
29454    if ( numRb > 0)
29455    {
29456       if ((rgTbSzTbl[noLyr-1][iTbs][numRb-1]/8) == cnsmdBytes)
29457       {
29458          RETVOID;
29459       }
29460    }
29461    /* Get iTbs as suitable for the consumed bytes */
29462    while((rgTbSzTbl[noLyr-1][iTbs][numRb-1]/8) > cnsmdBytes)
29463    {
29464       if (iTbs == 0)
29465       {
29466          RG_SCH_CMN_DL_TBS_TO_MCS(iTbs, allocInfo->tbInfo[tbInfoIdx].\
29467                tbCb->dlGrnt.iMcs);
29468          RETVOID;
29469       }
29470       iTbs--;
29471    }
29472    iTbs++;
29473    RG_SCH_CMN_DL_TBS_TO_MCS(iTbs, allocInfo->tbInfo[tbInfoIdx].tbCb->dlGrnt.iMcs);
29474
29475    RETVOID;
29476 }
29477
29478 \f
29479 /**
29480  * @brief This function determines the RBs and Bytes required for
29481  *        Transmission on 2 CWs.
29482  *
29483  * @details
29484  *
29485  *     Function: rgSCHCmnDlAlloc2CwTxRb
29486  *     Purpose:  This function determines the RBs and Bytes required
29487  *               for Transmission of DL SVC BO on 2 CWs.
29488  *               Also, takes care of SVC by SVC allocation by tracking
29489  *               previous SVCs allocations.
29490  *               Returns RFAILED if BO not satisfied at all.
29491  *
29492  *     Invoked by: TM3 and TM4 DL UE Allocation
29493  *
29494  *  @param[in]  RgSchCellCb      *cell
29495  *  @param[in]  RgSchDlSf        *subFrm
29496  *  @param[in]  RgSchUeCb        *ue
29497  *  @param[in]  RgSchDlHqProcCb  *proc
29498  *  @param[in]  RgSchDlHqProcCb  bo
29499  *  @param[out] U8               *numRb
29500  *  @param[out] U32              *effBo
29501  *  @return  Void
29502  *
29503  **/
29504 #ifdef ANSI
29505 PRIVATE S16 rgSCHCmnDlAlloc2CwTxRb
29506 (
29507 RgSchCellCb                *cell,
29508 RgSchDlSf                  *subFrm,
29509 RgSchUeCb                  *ue,
29510 RgSchDlHqProcCb            *proc,
29511 U32                        bo,
29512 U8                         *numRbRef,
29513 U32                        *effBo
29514 )
29515 #else
29516 PRIVATE S16 rgSCHCmnDlAlloc2CwTxRb(cell, subFrm, ue, proc, bo, numRbRef, effBo)
29517 RgSchCellCb                *cell;
29518 RgSchDlSf                  *subFrm;
29519 RgSchUeCb                  *ue;
29520 RgSchDlHqProcCb            *proc;
29521 U32                        bo;
29522 U8                         *numRbRef;
29523 U32                        *effBo;
29524 #endif
29525 {
29526    U32                noRes;
29527    U32                eff1, eff2;
29528    U32                tb1Sz, tb2Sz;
29529    U8                 imcs1, imcs2;
29530    U8                 noLyr1, noLyr2;
29531    U8                 iTbs1, iTbs2;
29532    RgSchCmnDlCell     *cellDl;
29533    RgSchCmnDlUe       *ueDl;
29534    RgSchDlRbAlloc     *allocInfo;
29535    U32                oldReq;
29536    U32                reqBytes;
29537    /* Fix: MUE_PERTTI_DL */
29538    U32                numRb;
29539    RgSchCmnCell       *cellSch = RG_SCH_CMN_GET_CELL(cell);
29540    U8                 cfi = cellSch->dl.currCfi;
29541    S16                availBw; 
29542    U32                availBits = 0;
29543 #ifdef LTE_ADV
29544    U32                boTmp = bo;
29545 #endif
29546
29547
29548    reqBytes  = bo;
29549    cellDl    = RG_SCH_CMN_GET_DL_CELL(cell);
29550    ueDl      = RG_SCH_CMN_GET_DL_UE(ue,cell);
29551    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
29552    oldReq    = ueDl->outStndAlloc;
29553
29554    
29555    if (ueDl->maxTbBits > ue->dl.aggTbBits)
29556    {
29557       availBits = ueDl->maxTbBits - ue->dl.aggTbBits;
29558    }
29559    /* check if we can further allocate to this UE */
29560    if ((ue->dl.aggTbBits >= ueDl->maxTbBits) ||
29561          (allocInfo->tbInfo[0].bytesReq >= ueDl->maxTbSz/8) ||
29562          (allocInfo->tbInfo[1].bytesReq >= ueDl->maxTbSz/8) ||
29563          (allocInfo->rbsReq >= ueDl->maxRb))
29564    {
29565       RLOG_ARG0(L_DEBUG,DBG_CELLID,cell->cellId,
29566             "rgSCHCmnDlAllocRb(): UEs max allocation exceed");
29567       return RFAILED;
29568    }
29569
29570    noLyr1 = ueDl->mimoInfo.cwInfo[0].noLyr;
29571    noLyr2 = ueDl->mimoInfo.cwInfo[1].noLyr;
29572
29573    /* If there is no CFI change, continue to use the BLER based
29574     * iTBS value */
29575    if (ueDl->lastCfi == cfi)
29576    {   
29577       iTbs1  = ueDl->mimoInfo.cwInfo[0].iTbs[noLyr1 - 1];
29578       iTbs2  = ueDl->mimoInfo.cwInfo[1].iTbs[noLyr2 - 1];
29579    }
29580    else
29581    {  
29582       U8 cqi = ueDl->mimoInfo.cwInfo[0].cqi;
29583 #ifdef LTE_TDD      
29584       iTbs1 = (U8) rgSchCmnFetchItbs(cell, ueDl, subFrm, cqi, cfi, 0, noLyr1);
29585 #else      
29586       iTbs1 = (U8) rgSchCmnFetchItbs(cell, ueDl, cqi, cfi, 0, noLyr1);
29587 #endif         
29588
29589       cqi = ueDl->mimoInfo.cwInfo[1].cqi;
29590 #ifdef LTE_TDD      
29591       iTbs2 = (U8) rgSchCmnFetchItbs(cell, ueDl, subFrm, cqi, cfi, 1, noLyr2);
29592 #else      
29593       iTbs2 = (U8) rgSchCmnFetchItbs(cell, ueDl, cqi, cfi, 1, noLyr2);
29594 #endif         
29595    } 
29596
29597    /*ccpu00131191 and ccpu00131317 - Fix for RRC Reconfig failure
29598     * issue for VoLTE call */
29599    //if ((proc->hasDcch)  || (TRUE == rgSCHLaaSCellEnabled(cell)))
29600    if (proc->hasDcch)
29601    {
29602       if (iTbs1 > 5)
29603       {
29604          iTbs1  = iTbs1 - 5;
29605       }
29606       else
29607       {
29608          iTbs1  = 0; 
29609       }
29610       if (iTbs2 > 5)
29611       {
29612          iTbs2  = iTbs2 - 5;
29613       }
29614       else
29615       {
29616          iTbs2  = 0; 
29617       }
29618    }
29619    else if(!cellSch->dl.isDlFreqSel)
29620    {
29621 #ifdef LTE_TDD
29622       /* for Tdd reduce iTbs only for SF0. SF5 contains only 
29623        * SSS and can be ignored */
29624       if (subFrm->sfNum == 0)
29625       {
29626          (iTbs1 > 1)? (iTbs1 -= 1) : (iTbs1 = 0);
29627          (iTbs2 > 1)? (iTbs2 -= 1) : (iTbs2 = 0);
29628       }
29629       /* For SF 3 and 8 CRC is getting failed in DL.
29630          Need to do proper fix after the replay from 
29631          BRCM PHY team*/
29632 #ifdef CA_PHY_BRDCM_61765      
29633       if ((subFrm->sfNum == 3) || (subFrm->sfNum == 8))
29634       {
29635          (iTbs1 > 2)? (iTbs1 -= 2) : (iTbs1 = 0);
29636          (iTbs2 > 2)? (iTbs2 -= 2) : (iTbs2 = 0);
29637       }
29638 #endif
29639 #else
29640 #endif
29641    }
29642
29643 #ifdef LTE_TDD
29644    if(subFrm->sfType == RG_SCH_SPL_SF_DATA)
29645    {
29646       RGSCH_GET_SPS_SF_CFI(cell->bwCfg.dlTotalBw, cfi);
29647    }
29648 #endif 
29649
29650    eff1 = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[noLyr1 - 1][cfi]))[iTbs1];
29651    eff2 = (*(RgSchCmnTbSzEff *)(cellSch->dl.cqiToEffTbl[noLyr2 - 1][cfi]))[iTbs2];
29652
29653
29654    bo = RGSCH_MIN(bo,availBits/8);
29655    ueDl->outStndAlloc += bo;
29656    /* consider Cumulative amount of this BO and bytes so far allocated */
29657    bo = RGSCH_MIN(ueDl->outStndAlloc, ueDl->maxTbBits/8);
29658    bo = RGSCH_MIN(RGSCH_MAX(RGSCH_CMN_MIN_GRNT_HDR, (bo*eff1)/(eff1+eff2)), 
29659                   ueDl->maxTbSz/8) +
29660         RGSCH_MIN(RGSCH_MAX(RGSCH_CMN_MIN_GRNT_HDR, (bo*eff2)/(eff1+eff2)), 
29661                   (ueDl->maxTbSz)/8) +
29662         1; /* Add 1 to adjust the truncation at weighted averaging */
29663    /* Get the number of REs needed for this bo. */
29664    noRes = ((bo * 8 * 1024) / (eff1 + eff2));
29665
29666    /* Get the number of RBs needed for this transmission */
29667    /* Number of RBs = No of REs / No of REs per RB       */
29668    numRb = RGSCH_CEIL(noRes, cellDl->noResPerRb[cfi]);
29669    /* Cannot exceed the maximum number of RBs per UE */
29670    if (numRb > ueDl->maxRb)
29671    {
29672       numRb = ueDl->maxRb;
29673    }
29674    else
29675    {
29676 #ifdef LTE_ADV
29677       if(RFAILED == rgSCHLaaCmn2CwAdjustPrb(allocInfo,  boTmp, &numRb, ueDl, noLyr1, noLyr2, iTbs1, iTbs2))
29678 #endif
29679       {
29680          while ((numRb <= ueDl->maxRb) &&
29681                (rgTbSzTbl[noLyr1 - 1][iTbs1][numRb-1] <= ueDl->maxTbSz) &&
29682                (rgTbSzTbl[noLyr2 - 1][iTbs2][numRb-1] <= ueDl->maxTbSz) &&
29683                ((rgTbSzTbl[noLyr1 - 1][iTbs1][numRb-1]/8 +
29684                  rgTbSzTbl[noLyr2 - 1][iTbs2][numRb-1]/8) <= bo))
29685          {
29686             (numRb)++;
29687          }
29688       }
29689    }
29690    availBw = subFrm->bw - subFrm->bwAssigned;
29691    /* Cannot exceed the total number of RBs in the cell */
29692    if ((S16)(numRb - allocInfo->rbsReq) > availBw)
29693    {
29694       numRb = availBw + allocInfo->rbsReq;
29695    }
29696    tb1Sz = rgTbSzTbl[noLyr1 - 1][iTbs1][numRb-1]/8;
29697    tb2Sz = rgTbSzTbl[noLyr2 - 1][iTbs2][numRb-1]/8;
29698    /* DwPts Scheduling Changes Start */
29699 #ifdef LTE_TDD
29700    if(subFrm->sfType == RG_SCH_SPL_SF_DATA)
29701    { 
29702       /* Max Rb for Special Sf is approximated as 4/3 of maxRb */
29703       rgSCHCmnCalcDwPtsTbSz2Cw(cell, bo, (U8*)&numRb,  ueDl->maxRb*4/3, 
29704                                 &iTbs1, &iTbs2, noLyr1, 
29705                                 noLyr2, &tb1Sz, &tb2Sz, cfi);   
29706       /* Check for available Bw */
29707       if ((S16)numRb - allocInfo->rbsReq > availBw)
29708       {
29709          numRb = availBw + allocInfo->rbsReq;
29710          tb1Sz = rgTbSzTbl[noLyr1-1][iTbs1][RGSCH_MAX(numRb*3/4,1)-1]/8;
29711          tb2Sz = rgTbSzTbl[noLyr2-1][iTbs2][RGSCH_MAX(numRb*3/4,1)-1]/8;
29712       }
29713    }
29714 #endif
29715    /* DwPts Scheduling Changes End */
29716    /* Update the subframe Allocated BW field */
29717    subFrm->bwAssigned = subFrm->bwAssigned + numRb - \
29718                         allocInfo->rbsReq;
29719
29720    *effBo = RGSCH_MIN((tb1Sz + tb2Sz) - oldReq, reqBytes);
29721
29722 #ifdef LTE_ADV
29723    if (ROK != rgSCHLaaCmn2TBPrbCheck(allocInfo, tb1Sz, tb2Sz, boTmp, effBo, iTbs1, iTbs2, numRb, proc))
29724    {
29725       return RFAILED;
29726    }
29727 #endif
29728
29729    RG_SCH_CMN_DL_TBS_TO_MCS(iTbs1, imcs1);
29730    RG_SCH_CMN_DL_TBS_TO_MCS(iTbs2, imcs2);
29731    RG_SCH_CMN_FILL_DL_TBINFO(&allocInfo->tbInfo[0], tb1Sz, \
29732          iTbs1, imcs1, &proc->tbInfo[0], noLyr1);
29733    RG_SCH_CMN_FILL_DL_TBINFO(&allocInfo->tbInfo[1], tb2Sz, \
29734          iTbs2, imcs2, &proc->tbInfo[1], noLyr2);
29735    *numRbRef = (U8)numRb;
29736
29737
29738    return ROK;
29739 }
29740
29741 \f
29742 /**
29743  * @brief This function determines the RBs and Bytes required for
29744  *        Transmission & Retransmission on 2 CWs.
29745  *
29746  * @details
29747  *
29748  *     Function: rgSCHCmnDlAlloc2CwTxRetxRb
29749  *     Purpose:  This function determines the RBs and Bytes required
29750  *               for Transmission & Retransmission on 2 CWs. Allocate
29751  *               RETX TB on a better CW and restrict new TX TB by
29752  *               RETX allocation.
29753  *               Returns RFAILED if BO not satisfied at all.
29754  *
29755  *     Invoked by: TM3 and TM4 DL UE Allocation
29756  *
29757  *  @param[in]  RgSchCellCb      *cell
29758  *  @param[in]  RgSchDlSf        *subFrm
29759  *  @param[in]  RgSchUeCb        *ue
29760  *  @param[in]  RgSchDlHqTbCb    *reTxTb
29761  *  @param[in]  RgSchDlHqTbCb    *txTb
29762  *  @param[out] U8               *numRb
29763  *  @param[out] U32              *effBo
29764  *  @return  Void
29765  *
29766  **/
29767 #ifdef ANSI
29768 PRIVATE S16 rgSCHCmnDlAlloc2CwTxRetxRb
29769 (
29770 RgSchCellCb                *cell,
29771 RgSchDlSf                  *subFrm,
29772 RgSchUeCb                  *ue,
29773 RgSchDlHqTbCb              *reTxTb,
29774 RgSchDlHqTbCb              *txTb,
29775 U8                         *numRb,
29776 U32                        *effBo
29777 )
29778 #else
29779 PRIVATE S16 rgSCHCmnDlAlloc2CwTxRetxRb(cell, subFrm, ue, reTxTb, txTb, numRb,\
29780         effBo)
29781 RgSchCellCb                *cell;
29782 RgSchDlSf                  *subFrm;
29783 RgSchUeCb                  *ue;
29784 RgSchDlHqTbCb              *reTxTb;
29785 RgSchDlHqTbCb              *txTb;
29786 U8                         *numRb;
29787 U32                        *effBo;
29788 #endif
29789 {
29790    RgSchCmnDlUe       *ueDl;
29791    RgSchDlRbAlloc     *allocInfo;
29792    U8                 imcs1, imcs2;
29793    U8                  noLyr2;
29794    U16                 tb2Sz;
29795    RgSchCmnDlUeCwInfo *otherCw;
29796    S16                 availBw;
29797    RgSchCmnDlCell     *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
29798    U8                 cfi = cellDl->currCfi; 
29799    U8                 iTbs;
29800
29801
29802    ueDl      = RG_SCH_CMN_GET_DL_UE(ue,cell);
29803    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
29804    otherCw   = &ueDl->mimoInfo.cwInfo[!(ueDl->mimoInfo.btrCwIdx)];
29805
29806
29807    /* Fix for ccpu00123919: In case of RETX TB scheduling avoiding recomputation of RB
29808     * and Tbs. Set all parameters same as Init TX except RV(only for NACKED) and
29809     * MCS.  */
29810    availBw = subFrm->bw - subFrm->bwAssigned; 
29811    *numRb = reTxTb->dlGrnt.numRb;
29812
29813 #ifdef XEON_TDD_SPCL
29814    *numRb = (reTxTb->initTxNumRbs);
29815    if(reTxTb->sfType == RG_SCH_SPL_SF_DATA && subFrm->sfType != RG_SCH_SPL_SF_DATA)
29816    {
29817       *numRb = (reTxTb->initTxNumRbs*3/4);
29818
29819       if(*numRb <= 3)
29820       {
29821          RLOG1(L_ERROR," Number of RBs [%d] are less than or equal to 3",*numRb);
29822          return RFAILED;
29823       }
29824    }
29825 #endif
29826
29827    if ((S16)*numRb > availBw)
29828    {
29829       return RFAILED;
29830    }
29831    /* Update the subframe Allocated BW field */
29832    subFrm->bwAssigned += *numRb;
29833    noLyr2 = otherCw->noLyr;
29834    RG_SCH_CMN_GET_MCS_FOR_RETX(reTxTb, imcs1);
29835
29836    /* If there is no CFI change, continue to use the BLER based
29837     * iTBS value */
29838    if (ueDl->lastCfi == cfi)
29839    {   
29840       iTbs = otherCw->iTbs[noLyr2-1];
29841    }
29842    else
29843    {  
29844 #ifdef LTE_TDD      
29845       iTbs = (U8) rgSchCmnFetchItbs(cell, ueDl, subFrm, otherCw->cqi, cfi, 
29846                                       !(ueDl->mimoInfo.btrCwIdx), noLyr2);
29847 #else      
29848       iTbs = (U8) rgSchCmnFetchItbs(cell, ueDl, otherCw->cqi, cfi, 
29849                                       !(ueDl->mimoInfo.btrCwIdx), noLyr2);
29850 #endif 
29851    } 
29852    tb2Sz = rgTbSzTbl[noLyr2-1][iTbs][*numRb-1]/8;
29853    /* DwPts Scheduling Changes Start */
29854 #ifdef LTE_TDD
29855 #endif
29856    /* DwPts Scheduling Changes End */
29857    RG_SCH_CMN_DL_TBS_TO_MCS(iTbs, imcs2);
29858    
29859    RG_SCH_CMN_FILL_DL_TBINFO(&allocInfo->tbInfo[0], reTxTb->tbSz, \
29860                               0, imcs1, reTxTb, reTxTb->numLyrs);
29861    
29862    RG_SCH_CMN_FILL_DL_TBINFO(&allocInfo->tbInfo[1], tb2Sz, \
29863                               iTbs, imcs2, txTb, noLyr2);
29864    
29865    *effBo = reTxTb->tbSz + tb2Sz;
29866
29867    return ROK;
29868 }
29869
29870 \f
29871 /**
29872  * @brief This function determines the RBs and Bytes required for BO
29873  *        Retransmission on 2 CWs.
29874  *
29875  * @details
29876  *
29877  *     Function: rgSCHCmnDlAlloc2CwRetxRb
29878  *     Purpose:  This function determines the RBs and Bytes required
29879  *               for BO Retransmission on 2 CWs. Allocate larger TB
29880  *               on a better CW and check if the smaller TB can be
29881  *               accomodated on the other CW.
29882  *               Returns RFAILED if BO not satisfied at all.
29883  *
29884  *     Invoked by: Common Scheduler
29885  *
29886  *  @param[in]  RgSchCellCb      *cell
29887  *  @param[in]  RgSchDlSf        *subFrm
29888  *  @param[in]  RgSchUeCb        *ue
29889  *  @param[in]  RgSchDlHqProcCb  *proc
29890  *  @param[out] U8               *numRb
29891  *  @param[out] Bool             *swpFlg
29892  *  @param[out] U32              *effBo
29893  *  @return  Void
29894  *
29895  **/
29896 #ifdef ANSI
29897 PRIVATE S16 rgSCHCmnDlAlloc2CwRetxRb
29898 (
29899 RgSchCellCb                *cell,
29900 RgSchDlSf                  *subFrm,
29901 RgSchUeCb                  *ue,
29902 RgSchDlHqProcCb            *proc,
29903 U8                         *numRb,
29904 Bool                       *swpFlg,
29905 U32                        *effBo
29906 )
29907 #else
29908 PRIVATE S16 rgSCHCmnDlAlloc2CwRetxRb(cell, subFrm, ue, proc,\
29909         numRb, swpFlg, effBo)
29910 RgSchCellCb                *cell;
29911 RgSchDlSf                  *subFrm;
29912 RgSchUeCb                  *ue;
29913 RgSchDlHqProcCb            *proc;
29914 U8                         *numRb;
29915 Bool                       *swpFlg;
29916 U32                        *effBo;
29917 #endif
29918 {
29919    RgSchDlRbAlloc     *allocInfo;
29920    U8                 imcs1;
29921    U8                 imcs2;
29922    RgSchDlHqTbCb      *lrgTbInfo, *othrTbInfo;
29923
29924
29925    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
29926
29927
29928    /* Fix for ccpu00123919: In case of RETX TB scheduling avoiding recomputation of RB
29929     * and Tbs. Set all parameters same as Init TX except RV(only for NACKED) and
29930     * MCS.  */
29931    lrgTbInfo  = &proc->tbInfo[0];
29932    othrTbInfo = &proc->tbInfo[1];
29933    *numRb = lrgTbInfo->dlGrnt.numRb;
29934 #ifdef XEON_TDD_SPCL
29935    if((lrgTbInfo->sfType == RG_SCH_SPL_SF_DATA || othrTbInfo->sfType == RG_SCH_SPL_SF_DATA))
29936    {
29937       if(lrgTbInfo->sfType == RG_SCH_SPL_SF_DATA)
29938       {       
29939           *numRb = (lrgTbInfo->initTxNumRbs);
29940       }
29941       else
29942       {
29943           *numRb = (othrTbInfo->initTxNumRbs);
29944       }
29945
29946       if(subFrm->sfType != RG_SCH_SPL_SF_DATA)
29947       {
29948          *numRb = (*numRb)*3/4;
29949       }
29950        
29951       if(*numRb <= 3)
29952       {
29953          RLOG1(L_ERROR," Number of RBs [%d] are less than or equal to 3",*numRb);
29954          return RFAILED;
29955       }
29956    }
29957 #endif
29958    if ((S16)*numRb > (S16)(subFrm->bw - subFrm->bwAssigned))
29959    {
29960       return RFAILED;
29961    }
29962    /* Update the subframe Allocated BW field */
29963    subFrm->bwAssigned += *numRb;
29964    RG_SCH_CMN_GET_MCS_FOR_RETX(lrgTbInfo, imcs1);
29965    RG_SCH_CMN_GET_MCS_FOR_RETX(othrTbInfo, imcs2);
29966    RG_SCH_CMN_FILL_DL_TBINFO(&allocInfo->tbInfo[0], lrgTbInfo->tbSz, \
29967          0, imcs1, lrgTbInfo, lrgTbInfo->numLyrs);
29968    RG_SCH_CMN_FILL_DL_TBINFO(&allocInfo->tbInfo[1], othrTbInfo->tbSz, \
29969          0, imcs2, othrTbInfo, othrTbInfo->numLyrs);
29970    *effBo = lrgTbInfo->tbSz + othrTbInfo->tbSz;
29971
29972
29973
29974    return ROK;
29975 }
29976
29977 \f
29978 /**
29979  * @brief This function determines the RBs and Bytes required for BO
29980  *        Retransmission on 1 CW.
29981  *
29982  * @details
29983  *
29984  *     Function: rgSCHCmnDlAlloc1CwRetxRb
29985  *     Purpose:  This function determines the RBs and Bytes required
29986  *               for BO Retransmission on 1 CW, the first CW.
29987  *               Returns RFAILED if BO not satisfied at all.
29988  *
29989  *     Invoked by: Common Scheduler
29990  *
29991  *  @param[in]  RgSchCellCb      *cell
29992  *  @param[in]  RgSchDlSf        *subFrm
29993  *  @param[in]  RgSchUeCb        *ue
29994  *  @param[in]  RgSchDlHqTbCb    *tbInfo
29995  *  @param[in]  U8               noLyr
29996  *  @param[out] U8               *numRb
29997  *  @param[out] U32              *effBo
29998  *  @return  S16
29999  *
30000  **/
30001 #ifdef ANSI
30002 PRIVATE S16 rgSCHCmnDlAlloc1CwRetxRb
30003 (
30004 RgSchCellCb                *cell,
30005 RgSchDlSf                  *subFrm,
30006 RgSchUeCb                  *ue,
30007 RgSchDlHqTbCb              *tbInfo,
30008 U8                         noLyr,
30009 U8                         *numRb,
30010 U32                        *effBo
30011 )
30012 #else
30013 PRIVATE S16 rgSCHCmnDlAlloc1CwRetxRb(cell, subFrm, ue, tbInfo, noLyr,\
30014         numRb, effBo)
30015 RgSchCellCb                *cell;
30016 RgSchDlSf                  *subFrm;
30017 RgSchUeCb                  *ue;
30018 RgSchDlHqTbCb              *tbInfo;
30019 U8                         noLyr;
30020 U8                         *numRb;
30021 U32                        *effBo;
30022 #endif
30023 {
30024    RgSchDlRbAlloc  *allocInfo;
30025    U8              imcs;
30026
30027
30028    allocInfo = RG_SCH_CMN_GET_ALLOCCB_FRM_UE(ue,cell);
30029
30030
30031    /* Fix for ccpu00123919: In case of RETX TB scheduling avoiding recomputation of RB
30032     * and Tbs. Set all parameters same as Init TX except RV(only for NACKED) and
30033     * MCS.  */
30034    *numRb = tbInfo->dlGrnt.numRb;
30035    if ((S16)*numRb > (S16)(subFrm->bw - subFrm->bwAssigned))
30036    {
30037       return RFAILED;
30038    }
30039    /* Update the subframe Allocated BW field */
30040    subFrm->bwAssigned += *numRb;
30041    imcs = tbInfo->dlGrnt.iMcs;
30042    allocInfo->dciFormat = tbInfo->dlGrnt.dciFormat; 
30043    /* Fix: For a RETX TB the iTbs is irrelevant, hence setting 0 */
30044    RG_SCH_CMN_FILL_DL_TBINFO(&allocInfo->tbInfo[0], tbInfo->tbSz, \
30045          0, imcs, tbInfo, tbInfo->numLyrs);
30046    *effBo = tbInfo->tbSz;
30047
30048    return ROK;
30049 }
30050
30051 #ifdef LTEMAC_SPS
30052
30053 /**
30054  * @brief This function is called to handle Release PDCCH feedback for SPS UE
30055  *
30056  * @details
30057  *
30058  *     Function: rgSCHCmnDlRelPdcchFbk
30059  *     Purpose:  Invokes SPS module to handle release PDCCH feedback
30060  *
30061  *     Invoked by: DHM
30062  *
30063  *  @param[in]   RgSchCellCb     *cell
30064  *  @param[in]   RgSchUeCb       *ue
30065  *  @param[in]   Bool            isAck
30066  *  @return  Void
30067  *
30068  **/
30069 #ifdef ANSI
30070 Void rgSCHCmnDlRelPdcchFbk
30071 (
30072 RgSchCellCb        *cell,
30073 RgSchUeCb          *ue,
30074 Bool               isAck
30075 )
30076 #else
30077 Void rgSCHCmnDlRelPdcchFbk(cell, ue, isAck)
30078 RgSchCellCb        *cell;
30079 RgSchUeCb          *ue;
30080 Bool               isAck;
30081 #endif
30082 {
30083
30084    rgSCHCmnSpsDlRelPdcchFbk(cell, ue, isAck);
30085    RETVOID;
30086
30087 }
30088
30089
30090 /**
30091  * @brief This function is invoked to handle Ack processing for a HARQ proc.
30092  *
30093  * @details
30094  *
30095  *     Function: rgSCHCmnDlProcAck
30096  *     Purpose:  DTX processing for HARQ proc
30097  *
30098  *     Invoked by: DHM
30099  *
30100  *  @param[in]   RgSchCellCb     *cell
30101  *  @param[in]   RgSchDlHqProcCb *hqP
30102  *  @return  Void
30103  *
30104  **/
30105 #ifdef ANSI
30106 Void rgSCHCmnDlProcAck
30107 (
30108 RgSchCellCb        *cell,
30109 RgSchDlHqProcCb    *hqP
30110 )
30111 #else
30112 Void rgSCHCmnDlProcAck(cell, hqP)
30113 RgSchCellCb        *cell;
30114 RgSchDlHqProcCb    *hqP;
30115 #endif
30116 {
30117
30118
30119    if (RG_SCH_CMN_SPS_DL_IS_SPS_HQP(hqP))
30120    {
30121       /* Invoke SPS module if SPS service was scheduled for this HARQ proc */
30122       rgSCHCmnSpsDlProcAck(cell, hqP);
30123    }
30124    RETVOID;
30125 }
30126 #ifdef RGSCH_SPS_STATS
30127 extern U32 rgSchStatCrntiCeRcvCnt;
30128 #endif
30129 /**
30130  * @brief This function is invoked to handle CRNTI CE reception for an UE
30131  *
30132  * @details
30133  *
30134  *     Function: rgSCHCmnHdlCrntiCE
30135  *     Purpose:  Handle CRNTI CE reception
30136  *
30137  *     Invoked by: DHM
30138  *
30139  *  @param[in]   RgSchCellCb     *cell
30140  *  @param[in]   RgSchDlHqProcCb *hqP
30141  *  @return  Void
30142  *
30143  **/
30144 #ifdef ANSI
30145 Void rgSCHCmnHdlCrntiCE
30146 (
30147 RgSchCellCb        *cell,
30148 RgSchUeCb          *ue
30149 )
30150 #else
30151 Void rgSCHCmnHdlCrntiCE(cell, ue)
30152 RgSchCellCb        *cell;
30153 RgSchUeCb          *ue;
30154 #endif
30155 {
30156
30157 #ifdef RGSCH_SPS_STATS   
30158    rgSchStatCrntiCeRcvCnt++;
30159 #endif
30160
30161    /* When UL sync lost happened due to TA timer expiry UE is being moved to 
30162       PDCCH order inactivity list.But when CRNTI CE received in msg3 from UE
30163       we are not moving UE into active state due to that RRC Reconfiguration is
30164       not happening.
30165       So here we are moving UE to active list whenever we receive the CRNTI CE and
30166       UE is inactive */
30167    /* CR ccpu00144525 */      
30168    if (RG_SCH_CMN_IS_UE_PDCCHODR_INACTV(ue))
30169    {
30170        /* Activate this UE if it was inactive */
30171        RG_SCH_CMN_DL_UPDT_INACTV_MASK ( cell, ue, RG_PDCCHODR_INACTIVE);
30172        RG_SCH_CMN_UL_UPDT_INACTV_MASK ( cell, ue, RG_PDCCHODR_INACTIVE);
30173    }
30174
30175    /* Handling is same as reception of UE RESET for both DL and UL */
30176    if (ue->dl.dlSpsCfg.isDlSpsEnabled)
30177    {
30178       rgSCHCmnSpsDlUeReset(cell, ue);
30179    }
30180    if (ue->ul.ulSpsCfg.isUlSpsEnabled == TRUE)
30181    {
30182       rgSCHCmnSpsUlUeReset(cell, ue);
30183    }
30184    
30185    RETVOID;
30186 }
30187
30188
30189 /**
30190  * @brief This function is called to handle relInd from MAC for a UE
30191  *
30192  * @details
30193  *
30194  *     Function: rgSCHCmnUlSpsRelInd
30195  *     Purpose:  Invokes SPS module to handle UL SPS release for a UE
30196  *
30197  *     Invoked by: SCH_UTL
30198  *
30199  *  @param[in]   RgSchCellCb        *cell
30200  *  @param[in]   RgSchUeCb          *ue
30201  *  @param[in]   Bool               isExplRel
30202  *  @return  Void
30203  *
30204  **/
30205 #ifdef ANSI
30206 Void rgSCHCmnUlSpsRelInd
30207 (
30208 RgSchCellCb        *cell,
30209 RgSchUeCb          *ue,
30210 Bool               isExplRel
30211 )
30212 #else
30213 Void rgSCHCmnUlSpsRelInd(cell, ue, isExplRel)
30214 RgSchCellCb        *cell;
30215 RgSchUeCb          *ue;
30216 Bool               isExplRel;
30217 #endif
30218 {
30219
30220    rgSCHCmnSpsUlProcRelInd(cell, ue, isExplRel);
30221    RETVOID;
30222
30223 } /* end of rgSCHCmnUlSpsRelInd */
30224
30225 /**
30226  * @brief This function is called to handle SPS Activate Ind from MAC for a UE
30227  *
30228  * @details
30229  *
30230  *     Function: rgSCHCmnUlSpsActInd
30231  *     Purpose:  Invokes SPS module to handle UL SPS activate for a UE
30232  *
30233  *     Invoked by: SCH_UTL
30234  *
30235  *  @param[in]   RgSchCellCb        *cell
30236  *  @param[in]   RgSchUeCb          *ue
30237  *  @return  Void
30238  *
30239  **/
30240 #ifdef ANSI
30241 Void rgSCHCmnUlSpsActInd
30242 (
30243 RgSchCellCb        *cell,
30244 RgSchUeCb          *ue,
30245 U16                spsSduSize
30246 )
30247 #else
30248 Void rgSCHCmnUlSpsActInd(cell, ue,spsSduSize)
30249 RgSchCellCb        *cell;
30250 RgSchUeCb          *ue;
30251 U16                spsSduSize;
30252 #endif
30253 {
30254
30255
30256    if (ue->ul.ulSpsCfg.isUlSpsEnabled == TRUE)
30257    {
30258       rgSCHCmnSpsUlProcActInd(cell, ue,spsSduSize);
30259    }
30260    RETVOID;
30261
30262 } /* end of rgSCHCmnUlSpsActInd */
30263
30264 /**
30265  * @brief This function is called to handle CRC in UL for UEs
30266  * undergoing SPS release
30267  *
30268  * @details
30269  *
30270  *     Function: rgSCHCmnUlCrcInd
30271  *     Purpose:  Invokes SPS module to handle CRC in UL for SPS UE
30272  *
30273  *     Invoked by: SCH_UTL
30274  *
30275  *  @param[in]   RgSchCellCb        *cell
30276  *  @param[in]   RgSchUeCb          *ue
30277  *  @param[in]   CmLteTimingInfo    crcTime
30278  *  @return  Void
30279  *
30280  **/
30281 #ifdef ANSI
30282 Void rgSCHCmnUlCrcInd
30283 (
30284 RgSchCellCb        *cell,
30285 RgSchUeCb          *ue,
30286 CmLteTimingInfo    crcTime
30287 )
30288 #else
30289 Void rgSCHCmnUlCrcInd(cell, ue, crcTime)
30290 RgSchCellCb        *cell;
30291 RgSchUeCb          *ue;
30292 CmLteTimingInfo    crcTime;
30293 #endif
30294 {
30295
30296    if (ue->ul.ulSpsCfg.isUlSpsEnabled == TRUE)
30297    {
30298       rgSCHCmnSpsUlProcCrcInd(cell, ue, crcTime);
30299    }
30300    RETVOID;
30301
30302 } /* end of rgSCHCmnUlCrcFailInd */
30303
30304 /**
30305  * @brief This function is called to handle CRC failure in UL
30306  *
30307  * @details
30308  *
30309  *     Function: rgSCHCmnUlCrcFailInd
30310  *     Purpose:  Invokes SPS module to handle CRC failure in UL for SPS UE
30311  *
30312  *     Invoked by: SCH_UTL
30313  *
30314  *  @param[in]   RgSchCellCb        *cell
30315  *  @param[in]   RgSchUeCb          *ue
30316  *  @param[in]   CmLteTimingInfo    crcTime
30317  *  @return  Void
30318  *
30319  **/
30320 #ifdef ANSI
30321 Void rgSCHCmnUlCrcFailInd
30322 (
30323 RgSchCellCb        *cell,
30324 RgSchUeCb          *ue,
30325 CmLteTimingInfo    crcTime
30326 )
30327 #else
30328 Void rgSCHCmnUlCrcFailInd(cell, ue, crcTime)
30329 RgSchCellCb        *cell;
30330 RgSchUeCb          *ue;
30331 CmLteTimingInfo    crcTime;
30332 #endif
30333 {
30334
30335    if (ue->ul.ulSpsCfg.isUlSpsEnabled == TRUE)
30336    {
30337       rgSCHCmnSpsUlProcDtxInd(cell, ue, crcTime);
30338    }
30339    RETVOID;
30340
30341 } /* end of rgSCHCmnUlCrcFailInd */
30342
30343 #endif /* LTEMAC_SPS */
30344
30345 /**
30346  * @brief BCH,BCCH,PCCH Dowlink Scheduling Handler.
30347  *
30348  * @details
30349  *
30350  *     Function: rgSCHCmnDlBcchPcchAlloc
30351  *     Purpose:  This function calls common scheduler APIs to
30352  *     schedule for BCCH/PCCH.
30353  *     It then invokes Allocator for actual RB
30354  *     allocations. It processes on the actual resources allocated
30355  *     against requested to the allocator module.
30356  *
30357  *     Invoked by: Common Scheduler
30358  *
30359  *  @param[in]  RgSchCellCb *cell
30360  *  @return  Void
30361  **/
30362 #ifdef ANSI
30363 PRIVATE Void rgSCHCmnDlBcchPcchAlloc
30364 (
30365 RgSchCellCb  *cell
30366 )
30367 #else
30368 PRIVATE Void rgSCHCmnDlBcchPcchAlloc(cell)
30369 RgSchCellCb  *cell;
30370 #endif
30371 {
30372 #ifdef LTE_TDD
30373    U8           nextSfIdx = (cell->crntSfIdx) % RGSCH_SF_ALLOC_SIZE;
30374 #else
30375 #ifdef LTEMAC_HDFDD
30376    U8           nextSfIdx = (cell->crntSfIdx + RG_SCH_CMN_HARQ_INTERVAL) % RGSCH_NUM_SUB_FRAMES;
30377 #else
30378    U8           nextSfIdx = (cell->crntSfIdx) % RGSCH_NUM_SUB_FRAMES;
30379 #endif
30380 #endif
30381    RgInfSfAlloc *nextsfAlloc = &(cell->sfAllocArr[nextSfIdx]);
30382    RgSchCmnCell           *cellSch   = RG_SCH_CMN_GET_CELL(cell);
30383    RgSchCmnDlRbAllocInfo  *allocInfo = &cellSch->allocInfo;  
30384    
30385
30386
30387    /*Reset the bitmask for BCCH/PCCH*/
30388    rgSCHUtlResetSfAlloc(nextsfAlloc,TRUE,FALSE);
30389 #ifndef DISABLE_MIB_SIB /* Not sending MIB and SIB to CL */
30390 #ifdef RGR_SI_SCH
30391    rgSCHChkNUpdSiCfg(cell);
30392    rgSCHSelectSi(cell);
30393 #endif
30394
30395    /*Perform the scheduling for BCCH,PCCH*/
30396    rgSCHCmnDlBcchPcch(cell, allocInfo, nextsfAlloc);
30397
30398    /* Call common allocator for RB Allocation */
30399    rgSCHBcchPcchDlRbAlloc(cell, allocInfo);
30400
30401    /* Finalize the Allocations for reqested Against alloced */
30402    rgSCHCmnDlBcchPcchFnlz(cell, allocInfo);
30403 #endif /* DISABLE_MIB_SIB */
30404    RETVOID;
30405 }
30406
30407 /**
30408  * @brief Handles RB allocation for BCCH/PCCH for downlink.
30409  *
30410  * @details
30411  *
30412  *     Function : rgSCHBcchPcchDlRbAlloc
30413  *
30414  *     Invoking Module Processing:
30415  *     - This function is invoked for DL RB allocation of BCCH/PCCH
30416  *
30417  *     Processing Steps:
30418  *     - If cell is frequency selecive,
30419  *       - Call rgSCHDlfsBcchPcchAllocRb().
30420  *     - else,
30421  *       - Do the processing
30422  *
30423  *  @param[in]  RgSchCellCb        *cell
30424  *  @param[in]  RgSchDlRbAllocInfo *allocInfo
30425  *  @return  Void
30426  **/
30427
30428 #ifdef ANSI
30429 PRIVATE Void rgSCHBcchPcchDlRbAlloc
30430 (
30431 RgSchCellCb           *cell,
30432 RgSchCmnDlRbAllocInfo *allocInfo
30433 )
30434 #else
30435 PRIVATE Void rgSCHBcchPcchDlRbAlloc(cell, allocInfo)
30436 RgSchCellCb           *cell;
30437 RgSchCmnDlRbAllocInfo *allocInfo;
30438 #endif
30439 {
30440    RgSchCmnCell      *cellSch = RG_SCH_CMN_GET_CELL(cell);
30441
30442
30443
30444    if (cellSch->dl.isDlFreqSel)
30445    {
30446       cellSch->apisDlfs->rgSCHDlfsBcchPcchAllocRb(cell, allocInfo);
30447    }
30448    else
30449    {
30450       rgSCHCmnNonDlfsBcchPcchRbAlloc(cell, allocInfo);
30451    }
30452
30453    RETVOID;
30454 }
30455
30456 /**
30457  * @brief Handles RB allocation for BCCH,PCCH for frequency
30458  *  non-selective cell.
30459  *
30460  * @details
30461  *
30462  *     Function : rgSCHCmnNonDlfsBcchPcchRbAlloc
30463  *
30464  *     Invoking Module Processing:
30465  *      - SCH shall invoke this if downlink frequency selective is disabled for
30466  *        the cell for RB allocation.
30467  *      - MAX C/I/PFS/RR shall provide the requiredBytes, required RBs
30468  *        estimate and subframe for each allocation to be made to SCH.
30469  *
30470  *     Processing Steps:
30471  *     - Allocate sequentially for BCCH,PCCH common channels.
30472  *
30473  *  @param[in]  RgSchCellCb        *cell
30474  *  @param[in]  RgSchCmnDlRbAllocInfo *allocInfo
30475  *  @return  Void
30476  **/
30477
30478 #ifdef ANSI
30479 PRIVATE Void rgSCHCmnNonDlfsBcchPcchRbAlloc
30480 (
30481 RgSchCellCb           *cell,
30482 RgSchCmnDlRbAllocInfo *allocInfo
30483 )
30484 #else
30485 PRIVATE Void rgSCHCmnNonDlfsBcchPcchRbAlloc(cell, allocInfo)
30486 RgSchCellCb           *cell;
30487 RgSchCmnDlRbAllocInfo *allocInfo;
30488 #endif
30489 {
30490    RgSchDlRbAlloc     *reqAllocInfo;
30491
30492
30493    /* 143473 */
30494    /* Allocate for PCCH */
30495    reqAllocInfo = &(allocInfo->pcchAlloc);
30496    if (reqAllocInfo->rbsReq)
30497    {
30498       rgSCHCmnNonDlfsCmnRbAlloc(cell, reqAllocInfo);
30499    }
30500    /* Allocate for BCCH on DLSCH */
30501    reqAllocInfo = &(allocInfo->bcchAlloc);
30502    if (reqAllocInfo->rbsReq)
30503    {
30504       rgSCHCmnNonDlfsCmnRbAlloc(cell, reqAllocInfo);
30505    }
30506    RETVOID;
30507 }
30508
30509
30510 #ifdef RGR_SI_SCH
30511 /**
30512  * @brief This function implements the handling to check and
30513  *        update the SI cfg at the start of the modificiation period.
30514  *
30515  * @details
30516  *
30517  *     Function: rgSCHChkNUpdSiCfg
30518  *     Purpose:  This function implements handling for update of SI Cfg
30519  *               at the start of modification period.
30520  *
30521  *     Invoked by: Scheduler
30522  *
30523  *  @param[in]  RgSchCellCb*     cell
30524  *  @return  S16
30525  *      -# ROK
30526  *      -# RFAILED
30527  **/
30528 #ifdef ANSI
30529 PRIVATE Void rgSCHChkNUpdSiCfg
30530 (
30531 RgSchCellCb             *cell
30532 )
30533 #else
30534 PRIVATE Void rgSCHChkNUpdSiCfg(cell)
30535 RgSchCellCb             *cell;
30536 #endif
30537 {
30538    CmLteTimingInfo   pdSchTmInfo;
30539
30540
30541
30542    pdSchTmInfo   = cell->crntTime;
30543 #ifdef LTEMAC_HDFDD
30544    /* For HDFDD we need scheduling information at least RG_SCH_CMN_DL_DELTA
30545       + RG_SCH_CMN_HARQ_INTERVAL (7) subframes ahead */
30546    RGSCH_INCR_SUB_FRAME(pdSchTmInfo, RG_SCH_CMN_DL_DELTA + RG_SCH_CMN_HARQ_INTERVAL);
30547 #else
30548    RGSCH_INCR_SUB_FRAME(pdSchTmInfo, RG_SCH_CMN_DL_DELTA);
30549 #endif
30550
30551
30552    /* Updating the SIB1 for Warning SI message immediately after it is received 
30553     * from application. No need to wait for next modification period.
30554     */
30555    if((pdSchTmInfo.sfn % RGSCH_SIB1_RPT_PERIODICITY == 0)
30556          && (RGSCH_SIB1_TX_SF_NUM == (pdSchTmInfo.slot % RGSCH_NUM_SUB_FRAMES)))
30557    {   
30558       /*Check whether SIB1 with PWS has been updated*/
30559       if(cell->siCb.siBitMask & RGSCH_SI_SIB1_PWS_UPD)
30560       {
30561          RGSCH_SET_SI_INFO(cell->siCb.crntSiInfo.sib1Info.sib1,
30562                cell->siCb.newSiInfo.sib1Info.sib1);
30563          cell->siCb.crntSiInfo.sib1Info.mcs = 
30564             cell->siCb.newSiInfo.sib1Info.mcs;
30565          cell->siCb.crntSiInfo.sib1Info.nPrb = 
30566              cell->siCb.newSiInfo.sib1Info.nPrb;
30567          cell->siCb.crntSiInfo.sib1Info.msgLen = 
30568             cell->siCb.newSiInfo.sib1Info.msgLen;
30569          cell->siCb.siBitMask &= ~RGSCH_SI_SIB1_PWS_UPD;
30570       }
30571    }
30572
30573    /*Check if this SFN and SF No marks the start of next modification
30574      period. If current SFN,SF No doesn't marks the start of next
30575      modification period, then return. */
30576    if(!((pdSchTmInfo.sfn % cell->siCfg.modPrd == 0)
30577             && (0 == pdSchTmInfo.slot)))
30578    /*if(!((((pdSchTmInfo.hSfn * 1024) + pdSchTmInfo.sfn) % cell->siCfg.modPrd == 0)
30579             && (0 == pdSchTmInfo.slot)))*/
30580    {
30581       RETVOID;
30582    }
30583
30584    /*Check whether MIB has been updated*/
30585    if(cell->siCb.siBitMask & RGSCH_SI_MIB_UPD)
30586    {
30587       RGSCH_SET_SI_INFO(cell->siCb.crntSiInfo.mib,
30588             cell->siCb.newSiInfo.mib);
30589       cell->siCb.siBitMask &= ~RGSCH_SI_MIB_UPD;
30590    }
30591
30592    /*Check whether SIB1 has been updated*/
30593    if(cell->siCb.siBitMask & RGSCH_SI_SIB1_UPD)
30594    {
30595       RGSCH_SET_SI_INFO(cell->siCb.crntSiInfo.sib1Info.sib1,
30596             cell->siCb.newSiInfo.sib1Info.sib1);
30597       cell->siCb.crntSiInfo.sib1Info.mcs = cell->siCb.newSiInfo.sib1Info.mcs;
30598       cell->siCb.crntSiInfo.sib1Info.nPrb = cell->siCb.newSiInfo.sib1Info.nPrb;
30599       cell->siCb.crntSiInfo.sib1Info.msgLen = 
30600          cell->siCb.newSiInfo.sib1Info.msgLen;
30601       cell->siCb.siBitMask &= ~RGSCH_SI_SIB1_UPD;
30602    }
30603
30604    /*Check whether SIs have been updated*/
30605    if(cell->siCb.siBitMask & RGSCH_SI_SI_UPD)
30606    {
30607       U8  idx;
30608
30609       /*Check if SI cfg have been modified And Check if numSi have
30610         been changed, if yes then we would need to update the
30611         pointers for all the SIs */
30612       if((cell->siCb.siBitMask & RGSCH_SI_SICFG_UPD) &&
30613             (cell->siCfg.numSi != cell->siCb.newSiCfg.numSi))
30614       {
30615          for(idx = 0;idx < cell->siCb.newSiCfg.numSi;idx++)
30616          {
30617             RGSCH_SET_SI_INFO(cell->siCb.crntSiInfo.siInfo[idx].si,
30618                   cell->siCb.newSiInfo.siInfo[idx].si);
30619             cell->siCb.siArray[idx].si = cell->siCb.crntSiInfo.siInfo[idx].si;
30620             cell->siCb.siArray[idx].isWarningSi = FALSE;
30621
30622             cell->siCb.crntSiInfo.siInfo[idx].mcs = cell->siCb.newSiInfo.siInfo[idx].mcs;
30623             cell->siCb.crntSiInfo.siInfo[idx].nPrb = cell->siCb.newSiInfo.siInfo[idx].nPrb;
30624             cell->siCb.crntSiInfo.siInfo[idx].msgLen = cell->siCb.newSiInfo.siInfo[idx].msgLen;
30625          }
30626
30627          /*If numSi have been reduced then we need to free the
30628            pointers at the indexes in crntSiInfo which haven't
30629            been exercised. If numSi has increased then nothing
30630            additional is requires as above handling has taken
30631            care.*/
30632          if(cell->siCfg.numSi > cell->siCb.newSiCfg.numSi)
30633          {
30634             for(idx = cell->siCb.newSiCfg.numSi;
30635                   idx < cell->siCfg.numSi;idx++)
30636             {
30637                RGSCH_FREE_MSG(cell->siCb.crntSiInfo.siInfo[idx].si);
30638                cell->siCb.siArray[idx].si = NULLP;
30639             }
30640          }
30641       }
30642       else
30643       {
30644          /*numSi has not been updated, we just need to update the
30645            pointers for the SIs which are set to NON NULLP */
30646          /*ccpu00118260 - Correct Update of SIB2 */
30647          for(idx = 0;idx < cell->siCfg.numSi;idx++)
30648          {
30649             if(NULLP != cell->siCb.newSiInfo.siInfo[idx].si)
30650             {
30651                RGSCH_SET_SI_INFO(cell->siCb.crntSiInfo.siInfo[idx].si,
30652                      cell->siCb.newSiInfo.siInfo[idx].si);
30653
30654                cell->siCb.siArray[idx].si = cell->siCb.crntSiInfo.siInfo[idx].si;
30655                cell->siCb.siArray[idx].isWarningSi = FALSE;
30656                cell->siCb.crntSiInfo.siInfo[idx].mcs = cell->siCb.newSiInfo.siInfo[idx].mcs;
30657                cell->siCb.crntSiInfo.siInfo[idx].nPrb = cell->siCb.newSiInfo.siInfo[idx].nPrb;
30658                cell->siCb.crntSiInfo.siInfo[idx].msgLen = cell->siCb.newSiInfo.siInfo[idx].msgLen;
30659             }
30660          }
30661       }
30662       cell->siCb.siBitMask &= ~RGSCH_SI_SI_UPD;
30663    }
30664
30665    /*Check whether SI cfg have been updated*/
30666    if(cell->siCb.siBitMask & RGSCH_SI_SICFG_UPD)
30667    {
30668       cell->siCfg = cell->siCb.newSiCfg;
30669       cell->siCb.siBitMask &= ~RGSCH_SI_SICFG_UPD;
30670    }
30671
30672    RETVOID;
30673 }
30674
30675
30676 /**
30677  * @brief This function implements the selection of the SI
30678  *        that is to be scheduled.
30679  *
30680  * @details
30681  *
30682  *     Function: rgSCHSelectSi
30683  *     Purpose:  This function implements the selection of SI
30684  *               that is to be scheduled.
30685  *
30686  *     Invoked by: Scheduler
30687  *
30688  *  @param[in]  RgSchCellCb*     cell
30689  *  @return  S16
30690  *      -# ROK
30691  *      -# RFAILED
30692  **/
30693 #ifdef ANSI
30694 PRIVATE Void rgSCHSelectSi
30695 (
30696 RgSchCellCb             *cell
30697 )
30698 #else
30699 PRIVATE Void rgSCHSelectSi(cell)
30700 RgSchCellCb             *cell;
30701 #endif
30702 {
30703    CmLteTimingInfo        crntTmInfo;
30704    U8                     siWinSize;
30705    U16                    x; 
30706    U16                    windowId; 
30707
30708
30709
30710    crntTmInfo  = cell->crntTime;
30711 #ifdef LTEMAC_HDFDD
30712    /* For HDFDD we need scheduling information at least RG_SCH_CMN_DL_DELTA
30713       + RG_SCH_CMN_HARQ_INTERVAL (7) subframes ahead */
30714    RGSCH_INCR_SUB_FRAME(crntTmInfo, RG_SCH_CMN_DL_DELTA + RG_SCH_CMN_HARQ_INTERVAL);
30715 #else
30716    RGSCH_INCR_SUB_FRAME(crntTmInfo, RG_SCH_CMN_DL_DELTA);
30717 #endif
30718
30719    siWinSize    = cell->siCfg.siWinSize;
30720
30721    /* Select SI only once at the starting of the new window */
30722    if(cell->siCb.inWindow)
30723    {
30724       if ((crntTmInfo.sfn % cell->siCfg.minPeriodicity) == 0 && 
30725           crntTmInfo.slot == 0)
30726       {
30727          /* Reinit inWindow at the beginning of every SI window */
30728          cell->siCb.inWindow = siWinSize - 1;
30729       }
30730       else
30731       {
30732          cell->siCb.inWindow--;
30733          RETVOID;
30734       }
30735    }
30736    else /* New window. Re-init the winSize counter with the window length */
30737    {
30738       if((cell->siCb.siArray[cell->siCb.siCtx.siId - 1].isWarningSi == TRUE)&&
30739             (cell->siCb.siCtx.retxCntRem != 0))   
30740       {
30741          rgSCHUtlFreeWarningSiPdu(cell);
30742          cell->siCb.siCtx.warningSiFlag  = FALSE;
30743       }
30744
30745       cell->siCb.inWindow = siWinSize - 1;
30746    }
30747
30748    x = rgSCHCmnGetSiSetId(crntTmInfo.sfn, crntTmInfo.slot, 
30749                                   cell->siCfg.minPeriodicity); 
30750
30751    /* Window Id within a SI set. This window Id directly maps to a
30752     * unique SI Id */
30753    windowId = (((crntTmInfo.sfn * RGSCH_NUM_SUB_FRAMES_5G) + 
30754             crntTmInfo.slot) - (x * (cell->siCfg.minPeriodicity * 10))) 
30755                                                                / siWinSize;
30756
30757    if(windowId >= RGR_MAX_NUM_SI)
30758       RETVOID;
30759
30760    /* Update the siCtx if there is a valid SI and its periodicity
30761     * has occurred */
30762    if (NULLP != cell->siCb.siArray[windowId].si)
30763    {
30764       /* Warning SI Periodicity is same as SIB2 Periodicity */
30765       if(((cell->siCb.siArray[windowId].isWarningSi == FALSE) && 
30766                (x % (cell->siCfg.siPeriodicity[windowId]
30767                      /cell->siCfg.minPeriodicity) == 0)) || 
30768             ((cell->siCb.siArray[windowId].isWarningSi == TRUE) &&
30769              (x % (cell->siCfg.siPeriodicity[0]
30770                    /cell->siCfg.minPeriodicity) == 0)))
30771       {
30772          cell->siCb.siCtx.siId = windowId+1;
30773          cell->siCb.siCtx.retxCntRem = cell->siCfg.retxCnt;
30774          cell->siCb.siCtx.warningSiFlag = cell->siCb.siArray[windowId].
30775                                                            isWarningSi;
30776          cell->siCb.siCtx.timeToTx.sfn = crntTmInfo.sfn;
30777          cell->siCb.siCtx.timeToTx.slot = crntTmInfo.slot;
30778
30779          RG_SCH_ADD_TO_CRNT_TIME(cell->siCb.siCtx.timeToTx,
30780                cell->siCb.siCtx.maxTimeToTx, (siWinSize - 1))
30781       }
30782    }
30783    else
30784    {/* Update the siCtx with invalid si Id */
30785       cell->siCb.siCtx.siId = 0;
30786    }
30787
30788    RETVOID;
30789 }
30790
30791
30792 /**
30793  * @brief This function implements scheduler DL allocation for
30794  *        SI.
30795  *
30796  * @details
30797  *
30798  *     Function: rgSCHDlSiSched
30799  *     Purpose:  This function implements scheduler for DL allocation
30800  *               for SI.
30801  *
30802  *     Invoked by: Scheduler
30803  *
30804  *  @param[in]  RgSchCellCb*     cell
30805  *  @return  S16
30806  *      -# ROK
30807  *      -# RFAILED
30808  **/
30809 #ifdef ANSI
30810 PRIVATE Void rgSCHDlSiSched
30811 (
30812 RgSchCellCb             *cell,
30813 RgSchCmnDlRbAllocInfo   *allocInfo,
30814 RgInfSfAlloc            *subfrmAlloc
30815 )
30816 #else
30817 PRIVATE Void rgSCHDlSiSched(cell, allocInfo, subfrmAlloc)
30818 RgSchCellCb             *cell;
30819 RgSchCmnDlRbAllocInfo   *allocInfo;
30820 RgInfSfAlloc            *subfrmAlloc;
30821 #endif
30822 {
30823    CmLteTimingInfo   crntTimInfo;
30824    RgSchDlSf         *sf;
30825    U8                nPrb = 0;
30826    U8                mcs  = 0;
30827    MsgLen            msgLen = 0;
30828    U32               rb=0;
30829    RgSchCmnDlCell    *cellDl = RG_SCH_CMN_GET_DL_CELL(cell);
30830    /* DwPTS Scheduling Changes Start */
30831 #ifdef LTE_TDD   
30832    U16                lostRe;  
30833    U8                 cfi = cellDl->currCfi;      
30834 #endif
30835    /* DwPTS Scheduling Changes End */
30836
30837
30838
30839    crntTimInfo   = cell->crntTime;
30840 #ifdef LTEMAC_HDFDD
30841    /* For HDFDD we need scheduling information at least RG_SCH_CMN_DL_DELTA
30842       + RG_SCH_CMN_HARQ_INTERVAL (7) subframes ahead */
30843    RGSCH_INCR_SUB_FRAME(crntTimInfo, RG_SCH_CMN_DL_DELTA + RG_SCH_CMN_HARQ_INTERVAL);
30844 #else
30845    RGSCH_INCR_SUB_FRAME(crntTimInfo, RG_SCH_CMN_DL_DELTA);
30846 #endif
30847
30848    /* Compute the subframe for which allocation is being made.
30849       Essentially, we need pointer to the dl frame for this subframe */
30850    sf = rgSCHUtlSubFrmGet(cell, crntTimInfo);
30851
30852    /*Check if scheduling of MIB is required */
30853 #ifdef EMTC_ENABLE
30854    /* since we are adding the MIB repetition logic for EMTC UEs, checking if
30855     * emtcEnabled or not,  If enabled MIB would be repeted at as part of EMTC
30856     * feature, otherwise scheduling at (n,0) */
30857    if(0 == cell->emtcEnable)
30858    {
30859 #endif
30860    if((crntTimInfo.sfn % RGSCH_MIB_PERIODICITY == 0)
30861          && (RGSCH_MIB_TX_SF_NUM == crntTimInfo.slot))
30862    {
30863       MsgLen  mibLen = 0;
30864       U8      sfnOctet, mibOct2 = 0;
30865       U8      mibOct1 = 0;
30866       /*If MIB has not been yet setup by Application, return*/
30867       if(NULLP == cell->siCb.crntSiInfo.mib)
30868          RETVOID;
30869
30870       SFndLenMsg(cell->siCb.crntSiInfo.mib, &mibLen);
30871       sf->bch.tbSize = mibLen;
30872       /*Fill the interface information */
30873       rgSCHUtlFillRgInfCmnLcInfo(sf, subfrmAlloc, NULLD, NULLD);
30874
30875       /*Set the bits of MIB to reflect SFN */
30876       /*First get the Most signficant 8 bits of SFN */
30877       sfnOctet = (U8)(crntTimInfo.sfn >> 2);
30878       /*Get the first two octets of MIB, and then update them
30879         using the SFN octet value obtained above.*/
30880       if(ROK != SExamMsg((Data *)(&mibOct1),
30881                cell->siCb.crntSiInfo.mib, 0))
30882          RETVOID;
30883
30884       if(ROK != SExamMsg((Data *)(&mibOct2),
30885                cell->siCb.crntSiInfo.mib, 1))
30886          RETVOID;
30887
30888       /* ccpu00114572- Fix for improper way of MIB Octet setting for SFN */
30889       mibOct1 = (mibOct1 & 0xFC) | (sfnOctet >> 6);
30890       mibOct2 = (mibOct2 & 0x03) | (sfnOctet << 2);
30891       /* ccpu00114572- Fix ends*/
30892
30893       /*Now, replace the two octets in MIB */
30894       if(ROK != SRepMsg((Data)(mibOct1),
30895                cell->siCb.crntSiInfo.mib, 0))
30896          RETVOID;
30897
30898       if(ROK != SRepMsg((Data)(mibOct2),
30899                cell->siCb.crntSiInfo.mib, 1))
30900          RETVOID;
30901
30902       /*Copy the MIB msg buff into interface buffer */
30903       SCpyMsgMsg(cell->siCb.crntSiInfo.mib,
30904             rgSchCb[cell->instIdx].rgSchInit.region,
30905             rgSchCb[cell->instIdx].rgSchInit.pool,
30906             &subfrmAlloc->cmnLcInfo.bchInfo.pdu);
30907       /* Added Dl TB count for MIB message transmission
30908        * This counter is incremented 4 times to consider 
30909        * the retransmission at the PHY level on PBCH channel*/
30910 #ifdef LTE_L2_MEAS
30911       cell->dlUlTbCnt.tbTransDlTotalCnt += RG_SCH_MIB_CNT;
30912 #endif      
30913    }
30914 #ifdef EMTC_ENABLE
30915    }
30916 #endif
30917
30918    allocInfo->bcchAlloc.schdFirst = FALSE;
30919    /*Check if scheduling of SIB1 is required.
30920      Check of (crntTimInfo.sfn % RGSCH_SIB1_PERIODICITY == 0)
30921      is not required here since the below check takes care
30922      of SFNs applicable for this one too.*/
30923    if((crntTimInfo.sfn % RGSCH_SIB1_RPT_PERIODICITY == 0)
30924          && (RGSCH_SIB1_TX_SF_NUM == crntTimInfo.slot))
30925    {
30926       /*If SIB1 has not been yet setup by Application, return*/
30927       if(NULLP == (cell->siCb.crntSiInfo.sib1Info.sib1))
30928       {
30929          RETVOID;
30930       }
30931
30932       allocInfo->bcchAlloc.schdFirst = TRUE;
30933       mcs =  cell->siCb.crntSiInfo.sib1Info.mcs;
30934       nPrb =  cell->siCb.crntSiInfo.sib1Info.nPrb;
30935       msgLen =  cell->siCb.crntSiInfo.sib1Info.msgLen;
30936    }
30937    else
30938    {
30939       /*Check if scheduling of SI can be performed.*/
30940       Bool    invalid = FALSE;
30941
30942       if(cell->siCb.siCtx.siId == 0)
30943          RETVOID;
30944
30945       /*Check if the Si-Window for the current Si-Context is completed*/
30946       invalid = rgSCHCmnChkPastWin(crntTimInfo, cell->siCb.siCtx.maxTimeToTx);
30947       if(invalid)
30948       {
30949          /* LTE_ADV_FLAG_REMOVED_START */
30950          if(cell->siCb.siCtx.retxCntRem)
30951          { 
30952             RGSCHLOGERROR(cell->instIdx,ERRCLS_INT_PAR,ERG011,(ErrVal)cell->siCb.siCtx.siId,
30953                                 "rgSCHDlSiSched(): SI not scheduled and window expired");
30954          }
30955          /* LTE_ADV_FLAG_REMOVED_END */
30956          if(cell->siCb.siCtx.warningSiFlag == TRUE)
30957          {
30958             rgSCHUtlFreeWarningSiPdu(cell);
30959             cell->siCb.siCtx.warningSiFlag  = FALSE;
30960          }
30961          RETVOID;
30962       }
30963
30964       /*Check the timinginfo of the current SI-Context to see if its
30965         transmission can be scheduled. */
30966       if(FALSE == (rgSCHCmnChkInWin(crntTimInfo,
30967                   cell->siCb.siCtx.timeToTx,
30968                   cell->siCb.siCtx.maxTimeToTx)))
30969       {
30970          RETVOID;
30971
30972       }
30973       /*Check if retransmission count has become 0*/
30974       if(0 == cell->siCb.siCtx.retxCntRem)
30975       {
30976          RETVOID;
30977       }
30978
30979       /* LTE_ADV_FLAG_REMOVED_START */
30980       /* Check if ABS is enabled/configured  */
30981       if(RGR_ENABLE == cell->lteAdvCb.absCfg.status)
30982       {
30983          /* The pattern type is RGR_ABS_MUTE, then eNB need to blank the subframe */
30984          if(cell->lteAdvCb.absCfg.absPatternType & RGR_ABS_MUTE)
30985          {
30986             /* Determine next scheduling subframe is ABS or not */
30987             if(RG_SCH_ABS_ENABLED_ABS_SF == (RgSchAbsSfEnum)(cell->lteAdvCb.absCfg.absPattern
30988                   [((crntTimInfo.sfn*RGSCH_NUM_SUB_FRAMES) + crntTimInfo.slot) % RGR_ABS_PATTERN_LEN]))
30989             {
30990                /* Skip the SI scheduling to next tti */
30991                RETVOID;
30992             }
30993          }
30994       }
30995       /* LTE_ADV_FLAG_REMOVED_END */
30996
30997       /*Schedule the transmission of the current SI-Context */
30998       /*Find out the messg length for the SI message */
30999       /* warningSiFlag is to differentiate between Warning SI
31000        * and Other SI */
31001         if((rgSCHUtlGetMcsAndNPrb(cell, &nPrb, &mcs, &msgLen)) != ROK)
31002         {
31003            RETVOID; 
31004         }
31005
31006       cell->siCb.siCtx.i = RGSCH_CALC_SF_DIFF(crntTimInfo,
31007             cell->siCb.siCtx.timeToTx);
31008    } 
31009
31010
31011    /*Get the number of rb required */
31012    /*rgSCHCmnClcRbAllocForFxdTb(cell, msgLen, cellDl->ccchCqi, &rb);*/
31013    if(cellDl->bitsPerRb==0)
31014    {
31015       while ((rgTbSzTbl[0][0][rb]) < (U32) (msgLen*8))
31016       {
31017          rb++;
31018       }
31019       rb = rb+1;
31020    }
31021    else
31022    {
31023       rb = RGSCH_CEIL((msgLen*8), cellDl->bitsPerRb);
31024    }
31025    /* DwPTS Scheduling Changes Start */   
31026 #ifdef LTE_TDD
31027    if (sf->sfType == RG_SCH_SPL_SF_DATA) 
31028    {
31029       RGSCH_GET_SPS_SF_CFI(cell->bwCfg.dlTotalBw, cfi);
31030
31031       /* Calculate the less RE's because of DwPTS */
31032        lostRe = rb * (cellDl->noResPerRb[cfi] - cellDl->numReDwPts[cfi]);
31033
31034        /* Increase number of RBs in Spl SF to compensate for lost REs */
31035        rb += RGSCH_CEIL(lostRe, cellDl->numReDwPts[cfi]); 
31036    }
31037 #endif
31038    /* DwPTS Scheduling Changes End */   
31039    /*ccpu00115595- end*/
31040    /* Additional check to see if required RBs
31041     * exceeds the available */
31042    if (rb > sf->bw - sf->bwAssigned)
31043    {
31044       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,  "rgSCHDlSiSched(): "
31045          "BW allocation failed CRNTI:%d",RGSCH_SI_RNTI);
31046       RETVOID;
31047    }
31048
31049    /* Update the subframe Allocated BW field */
31050    sf->bwAssigned = sf->bwAssigned + rb;
31051
31052    /*Fill the parameters in allocInfo */
31053    allocInfo->bcchAlloc.rnti = RGSCH_SI_RNTI;
31054    allocInfo->bcchAlloc.dlSf = sf;
31055    allocInfo->bcchAlloc.rbsReq = rb;
31056    /*ccpu00116710- MCS is not getting assigned */
31057    allocInfo->bcchAlloc.tbInfo[0].imcs = mcs;
31058
31059    /* ccpu00117510 - ADD - Assignment of nPrb and other information */
31060    allocInfo->bcchAlloc.nPrb = nPrb;
31061    allocInfo->bcchAlloc.tbInfo[0].bytesReq = msgLen;
31062    allocInfo->bcchAlloc.tbInfo[0].noLyr = 1;
31063    RETVOID;
31064 }
31065 #endif /*RGR_SI_SCH*/
31066
31067 \f
31068 /* ccpu00117452 - MOD - Changed macro name from
31069    RGR_RRM_DLPWR_CNTRL to RGR_CQI_REPT */
31070 #ifdef RGR_CQI_REPT
31071 /**
31072  * @brief This function Updates the DL CQI for the UE.
31073  *
31074  * @details
31075  *
31076  *     Function: rgSCHCmnUeDlPwrCtColltCqiRept
31077  *     Purpose:  Manages PUSH N CQI reporting
31078  *         Step 1: Store the CQI in collation array
31079  *         Step 2: Increament the tracking count
31080  *         Step 3: Check is it time to to send the report
31081  *         Step 4: if yes, Send StaInd to RRM
31082  *         Step 4.1: Fill StaInd for sending collated N CQI rpeorts
31083  *         Step 4.2: Call utility function (rgSCHUtlRgrStaInd) to send rpts to RRM
31084  *         Step 4.2.1: If sending was not sucessful, return RFAILED
31085  *         Step 4.2.2: If sending was sucessful, return ROK
31086  *         Step 5: If no, return
31087  *     Invoked by: rgSCHCmnDlCqiInd
31088  *
31089  *  @param[in]  RgSchCellCb        *cell
31090  *  @param[in]  RgSchUeCb          *ue
31091  *  @param[in]  RgrUeCqiRept        *ueCqiRpt
31092  *  @return  Void
31093  *
31094  **/
31095 #ifdef ANSI
31096 PRIVATE S16 rgSCHCmnUeDlPwrCtColltCqiRept
31097 (
31098 RgSchCellCb        *cell,
31099 RgSchUeCb          *ue,
31100 RgrUeCqiRept        *ueCqiRpt
31101 )
31102 #else
31103 PRIVATE S16 rgSCHCmnUeDlPwrCtColltCqiRept(cell, ue, ueCqiRpt)
31104 RgSchCellCb        *cell;
31105 RgSchUeCb          *ue;
31106 RgrUeCqiRept        *ueCqiRpt;
31107 #endif
31108 {
31109    U8    *cqiCount = NULLP;
31110    S16   retVal;
31111    RgrStaIndInfo *staInfo = NULLP;
31112
31113
31114    /* Step 1: Store the CQI in collation array */
31115    /* Step 2: Increament the tracking count */
31116    cqiCount = &(ue->schCqiInfo.cqiCount);
31117    ue->schCqiInfo.cqiRept[(*cqiCount)++] =
31118                   *ueCqiRpt;
31119
31120
31121    /* Step 3: Check is it time to to send the report */
31122    if(RG_SCH_CQIR_IS_TIMTOSEND_CQIREPT(ue))
31123    {
31124    /* Step 4: if yes, Send StaInd to RRM */
31125       retVal = rgSCHUtlAllocSBuf (cell->instIdx,(Data**)&staInfo,
31126                sizeof(RgrStaIndInfo));
31127       if (retVal != ROK)
31128       {
31129          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId, "Could not "
31130             "allocate memory for sending StaInd CRNTI:%d",ue->ueId);
31131          return (retVal);
31132       }
31133
31134    /* Step 4.1: Fill StaInd for sending collated N CQI rpeorts */
31135 #ifdef CA_DBG
31136       {
31137          extern U32 gCqiReptToAppCount;
31138          gCqiReptToAppCount++;
31139       
31140       }
31141
31142 #endif
31143       retVal = rgSCHUtlFillSndStaInd(cell, ue, staInfo,
31144             ue->cqiReptCfgInfo.numColltdCqiRept);
31145       return (retVal);
31146
31147    }
31148
31149    return ROK;
31150 } /* End of rgSCHCmnUeDlPwrCtColltCqiRept */
31151
31152 #endif /* End of RGR_CQI_REPT */
31153
31154 /**
31155  * @brief This function checks for the retransmisson
31156  *        for a DTX scenario.
31157  * @details
31158  *
31159  *     Function:
31160  *     Purpose:
31161  *     Invoked by:
31162  *
31163  *  @param[in]  RgSchCellCb        *cell
31164  *  @param[in]  RgSchUeCb          *ue
31165  *  @param[in]
31166  *  @return  Void
31167  *
31168  **/
31169 #ifdef ANSI
31170 Void rgSCHCmnChkRetxAllowDtx
31171 (
31172 RgSchCellCb        *cell,
31173 RgSchUeCb          *ueCb,
31174 RgSchDlHqProcCb    *proc,
31175 Bool               *reTxAllwd
31176 )
31177 #else
31178 Void rgSCHCmnChkRetxAllowDtx(cell, ueCb, proc, reTxAllwd)
31179 RgSchCellCb        *cell;
31180 RgSchUeCb          *ueCb;
31181 RgSchDlHqProcCb    *proc;
31182 Bool               *reTxAllwd;
31183 #endif
31184 {
31185
31186
31187    *reTxAllwd = TRUE;
31188    /* Fix */
31189    if ((proc->tbInfo[0].isAckNackDtx == TFU_HQFDB_DTX))
31190    {
31191        *reTxAllwd = FALSE;
31192    }
31193
31194    RETVOID;
31195 }
31196
31197 /**
31198  * @brief API for calculating the SI Set Id 
31199  *
31200  * @details
31201  *
31202  *     Function: rgSCHCmnGetSiSetId
31203  *
31204  *     This API is used for calculating the SI Set Id, as shown below
31205  *     
31206  *          siSetId = 0        siSetId = 1
31207  *     |******************|******************|---------------->
31208  *   (0,0)              (8,0)              (16,0)          (SFN, SF)
31209  *    
31210  *
31211  *  @param[in]  U16     sfn                   
31212  *  @param[in]  U8      sf
31213  *  @return     U16     siSetId
31214  **/
31215 #ifdef ANSI
31216 U16 rgSCHCmnGetSiSetId
31217 (
31218 U16    sfn,
31219 U8     sf,
31220 U16    minPeriodicity
31221 )
31222 #else
31223 U16 rgSCHCmnGetSiSetId(sfn, sf, minPeriodicity)
31224 U16    sfn;
31225 U8     sf
31226 U16    minPeriodicity;
31227 #endif
31228 {
31229    /* 80 is the minimum SI periodicity in sf. Also
31230     * all other SI periodicities are multiples of 80 */
31231     return  (((sfn * RGSCH_NUM_SUB_FRAMES_5G) + sf) / (minPeriodicity * 10));
31232 }
31233 #ifdef LTE_TDD
31234 /**
31235  * @brief API for calculating the DwPts Rb, Itbs and  tbSz 
31236  *
31237  * @details
31238  *
31239  *     Function: rgSCHCmnCalcDwPtsTbSz
31240  *
31241  *  @param[in]     RgSchCellCb    *cell                   
31242  *  @param[in]     U32             bo
31243  *  @param[in/out] U8             *rb
31244  *  @param[in/out] U8             *iTbs
31245  *  @param[in]     U8              lyr
31246  *  @param[in]     U8              cfi
31247  *  @return        U32             tbSz
31248  **/
31249 #ifdef ANSI
31250 PRIVATE U32 rgSCHCmnCalcDwPtsTbSz
31251 (
31252 RgSchCellCb    *cell,
31253 U32             bo,
31254 U8             *rb,
31255 U8             *iTbs,
31256 U8              lyr,
31257 U8              cfi
31258 )
31259 #else
31260 PRIVATE U32 rgSCHCmnCalcDwPtsTbSz(cell, bo, rb, iTbs, lyr, cfi)
31261 RgSchCellCb    *cell;
31262 U32             bo;
31263 U8             *rb;
31264 U8             *iTbs;
31265 U8              lyr;
31266 U8              cfi;
31267 #endif
31268 {
31269     U32             tbSz;
31270     RgSchCmnDlCell *cellDl     = RG_SCH_CMN_GET_DL_CELL(cell);
31271     U32             numRE      = *rb * cellDl->noResPerRb[cfi];
31272     U32             numDwPtsRb = RGSCH_CEIL(numRE, cellDl->numReDwPts[cfi]);   
31273
31274
31275     /* DwPts Rb cannot exceed the cell Bw */
31276     numDwPtsRb = RGSCH_MIN(numDwPtsRb, cellDl->maxDlBwPerUe);
31277     
31278     /* Adjust the iTbs for optimum usage of the DwPts region. 
31279      * Using the same iTbs adjustment will not work for all 
31280      * special subframe configurations and iTbs levels. Hence use the 
31281      * static iTbs Delta table for adjusting the iTbs  */
31282     RG_SCH_CMN_ADJ_DWPTS_ITBS(cellDl, *iTbs);
31283     
31284     if (bo)
31285     {
31286        while(rgTbSzTbl[lyr-1][*iTbs][RGSCH_MAX(numDwPtsRb*3/4,1)-1] < bo*8 &&
31287              numDwPtsRb < cellDl->maxDlBwPerUe) 
31288        {
31289           (numDwPtsRb)++;
31290        }
31291
31292        tbSz = rgTbSzTbl[lyr-1][*iTbs][RGSCH_MAX(numDwPtsRb*3/4,1)-1];
31293     }
31294     else
31295     {
31296        tbSz = rgTbSzTbl[lyr-1][*iTbs][RGSCH_MAX(numDwPtsRb*3/4,1)-1];
31297     }
31298     *rb = numDwPtsRb;
31299
31300     return (tbSz/8);
31301 }
31302
31303 /**
31304  * @brief API for calculating the DwPts Rb, Itbs and  tbSz 
31305  *
31306  * @details
31307  *
31308  *     Function: rgSCHCmnCalcDwPtsTbSz2Cw
31309  *
31310  *  @param[in]      RgSchCellCb    *cell                   
31311  *  @param[in]      U32             bo
31312  *  @param[in/out]  U8             *rb
31313  *  @param[in]      U8              maxRb
31314  *  @param[in/out]  U8             *iTbs1
31315  *  @param[in/out]  U8             *iTbs2
31316  *  @param[in]      U8              lyr1
31317  *  @param[in]      U8              lyr2
31318  *  @return[in/out] U32            *tb1Sz
31319  *  @return[in/out] U32            *tb2Sz
31320  *  @param[in]      U8              cfi 
31321  **/
31322 #ifdef ANSI
31323 PRIVATE Void rgSCHCmnCalcDwPtsTbSz2Cw
31324 (
31325 RgSchCellCb    *cell,
31326 U32             bo,
31327 U8             *rb,
31328 U8              maxRb,
31329 U8             *iTbs1,
31330 U8             *iTbs2,
31331 U8              lyr1,
31332 U8              lyr2,
31333 U32            *tb1Sz, 
31334 U32            *tb2Sz,
31335 U8              cfi
31336 )
31337 #else
31338 PRIVATE Void rgSCHCmnCalcDwPtsTbSz2Cw(cell, bo, rb, maxRb, iTbs1, iTbs2, 
31339       lyr1, lyr2, tb1Sz, tb2Sz, cfi)
31340 RgSchCellCb    *cell;
31341 U32             bo;
31342 U8             *rb;
31343 U8              maxRb;
31344 U8             *iTbs1;
31345 U8             *iTbs2;
31346 U8              lyr1;
31347 U8              lyr2;
31348 U32            *tb1Sz; 
31349 U32            *tb2Sz;
31350 U8              cfi;
31351 #endif
31352 {
31353     RgSchCmnDlCell *cellDl     = RG_SCH_CMN_GET_DL_CELL(cell);
31354     U32             numRE      = *rb * cellDl->noResPerRb[cfi];
31355     U32             numDwPtsRb = RGSCH_CEIL(numRE, cellDl->numReDwPts[cfi]);   
31356
31357
31358     /* DwPts Rb cannot exceed the cell Bw */
31359     numDwPtsRb = RGSCH_MIN(numDwPtsRb, maxRb);
31360     
31361     /* Adjust the iTbs for optimum usage of the DwPts region. 
31362      * Using the same iTbs adjustment will not work for all 
31363      * special subframe configurations and iTbs levels. Hence use the 
31364      * static iTbs Delta table for adjusting the iTbs  */
31365     RG_SCH_CMN_ADJ_DWPTS_ITBS(cellDl, *iTbs1);
31366     RG_SCH_CMN_ADJ_DWPTS_ITBS(cellDl, *iTbs2);
31367     
31368     while((rgTbSzTbl[lyr1-1][*iTbs1][RGSCH_MAX(numDwPtsRb*3/4,1)-1] +
31369            rgTbSzTbl[lyr2-1][*iTbs2][RGSCH_MAX(numDwPtsRb*3/4,1)-1])< bo*8 &&
31370           numDwPtsRb < maxRb) 
31371     {
31372        (numDwPtsRb)++;
31373     }
31374
31375     *tb1Sz = rgTbSzTbl[lyr1-1][*iTbs1][RGSCH_MAX(numDwPtsRb*3/4,1)-1]/8;
31376     *tb2Sz = rgTbSzTbl[lyr2-1][*iTbs2][RGSCH_MAX(numDwPtsRb*3/4,1)-1]/8;
31377
31378     *rb = numDwPtsRb;
31379
31380     RETVOID;    
31381 }
31382
31383 #endif
31384
31385 /**
31386  * @brief Updates the GBR LCGs when datInd is received from MAC
31387  * 
31388  * @details
31389  *
31390  *     Function: rgSCHCmnUpdUeDataIndLcg(cell, ue, datInd)
31391  *     Purpose:  This function updates the GBR LCGs 
31392  *               when datInd is received from MAC.
31393  *
31394  *     Invoked by: TOM
31395  *
31396  *  @param[in]  RgSchCellCb      *cell
31397  *  @param[in]  RgSchUeCb        *ue
31398  *  @param[in]  RgInfUeDatInd    *datInd
31399  *  @return Void
31400  **/
31401 #ifdef ANSI
31402 Void rgSCHCmnUpdUeDataIndLcg 
31403 (
31404 RgSchCellCb    *cell,
31405 RgSchUeCb      *ue,
31406 RgInfUeDatInd  *datInd
31407 )
31408 #else
31409 Void rgSCHCmnUpdUeDataIndLcg(cell, ue, datInd)
31410 RgSchCellCb    *cell;
31411 RgSchUeCb      *ue;
31412 RgInfUeDatInd  *datInd;
31413 #endif
31414 {
31415    U32 idx = 0;
31416    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
31417 #ifdef DEBUGP
31418    Inst                inst = cell->instIdx;
31419 #endif
31420
31421
31422    for (idx = 0; (idx < RGINF_MAX_LCG_PER_UE - 1); idx++)
31423    {
31424       if (datInd->lcgInfo[idx].bytesRcvd != 0)
31425       {
31426          U8  lcgId     = datInd->lcgInfo[idx].lcgId;
31427          U32 bytesRcvd = datInd->lcgInfo[idx].bytesRcvd;
31428
31429          if (RGSCH_LCG_ISCFGD(&ue->ul.lcgArr[lcgId]))
31430          {
31431             RgSchCmnLcg *cmnLcg = ((RgSchCmnLcg *)(ue->ul.lcgArr[lcgId].sch));
31432             if (RGSCH_IS_GBR_BEARER(cmnLcg->cfgdGbr))
31433             {
31434                if(bytesRcvd > cmnLcg->effGbr)
31435                {
31436                   bytesRcvd -= cmnLcg->effGbr;
31437                   cmnLcg->effDeltaMbr = (cmnLcg->effDeltaMbr > bytesRcvd) ? \
31438                                         (cmnLcg->effDeltaMbr - bytesRcvd) : (0);
31439                   cmnLcg->effGbr = 0;
31440                }
31441                else
31442                {
31443                   cmnLcg->effGbr -= bytesRcvd;
31444                }
31445                /* To keep BS updated with the amount of data received for the GBR */
31446                cmnLcg->reportedBs = (cmnLcg->reportedBs > datInd->lcgInfo[idx].bytesRcvd) ? \
31447                                     (cmnLcg->reportedBs - datInd->lcgInfo[idx].bytesRcvd) : (0);
31448                cmnLcg->bs = RGSCH_MIN(cmnLcg->reportedBs, cmnLcg->effGbr+cmnLcg->effDeltaMbr);
31449             }
31450             else if(lcgId != 0)
31451             {
31452                ue->ul.effAmbr = (ue->ul.effAmbr > datInd->lcgInfo[idx].bytesRcvd) ? \
31453                                (ue->ul.effAmbr - datInd->lcgInfo[idx].bytesRcvd) : (0);
31454                cmnLcg->reportedBs = (cmnLcg->reportedBs > datInd->lcgInfo[idx].bytesRcvd) ? \
31455                                     (cmnLcg->reportedBs - datInd->lcgInfo[idx].bytesRcvd) : (0);
31456                cmnLcg->bs = RGSCH_MIN(cmnLcg->reportedBs, ue->ul.effAmbr);
31457                ue->ul.nonGbrLcgBs = (ue->ul.nonGbrLcgBs > datInd->lcgInfo[idx].bytesRcvd) ? \
31458                                    (ue->ul.nonGbrLcgBs - datInd->lcgInfo[idx].bytesRcvd) : (0);
31459             }
31460             ue->ul.nonLcg0Bs = (ue->ul.nonLcg0Bs > datInd->lcgInfo[idx].bytesRcvd) ? \
31461                               (ue->ul.nonLcg0Bs - datInd->lcgInfo[idx].bytesRcvd) : (0);
31462          }
31463       }
31464       else
31465       {
31466          break;
31467       }
31468    }
31469 #ifdef EMTC_ENABLE
31470    if(TRUE == ue->isEmtcUe)
31471    {
31472       if (cellSch->apisEmtcUl->rgSCHRgrUlLcgUpd(cell, ue, datInd) != ROK)
31473       {
31474          RGSCHDBGERRNEW(inst, (rgSchPBuf(inst), "\n rgSCHCmnUpdUeDataIndLcg(): rgSCHRgrUlLcgUpd returned failure"));
31475       }
31476
31477    }
31478    else
31479 #endif
31480    {
31481       if (cellSch->apisUl->rgSCHRgrUlLcgUpd(cell, ue, datInd) != ROK)
31482       {
31483          RGSCHDBGERRNEW(inst, (rgSchPBuf(inst), "\n rgSCHCmnUpdUeDataIndLcg(): rgSCHRgrUlLcgUpd returned failure"));
31484       }
31485    }
31486 }
31487
31488
31489 /** @brief This function initializes DL allocation lists and prepares
31490  *         for scheduling  
31491  *
31492  * @details
31493  *
31494  *     Function: rgSCHCmnInitRbAlloc
31495  *
31496  * @param  [in] RgSchCellCb    *cell
31497  *
31498  * Returns: Void
31499  *
31500  */
31501 #ifdef ANSI
31502 PRIVATE Void  rgSCHCmnInitRbAlloc 
31503 (
31504 RgSchCellCb        *cell
31505 )
31506 #else
31507 PRIVATE Void  rgSCHCmnInitRbAlloc (cell)
31508 RgSchCellCb        *cell;
31509 #endif
31510 {
31511    RgSchCmnCell           *cellSch = RG_SCH_CMN_GET_CELL(cell);
31512    CmLteTimingInfo        frm;
31513    RgSchDlSf              *dlSf;
31514         U8                     idx;
31515    
31516
31517 /* Initializing RgSchCmnUlRbAllocInfo structure.*/
31518    rgSCHCmnInitDlRbAllocInfo(&cellSch->allocInfo);
31519
31520    frm = cellSch->dl.time;
31521
31522    dlSf = rgSCHUtlSubFrmGet(cell, frm);
31523 #ifdef RG_5GTF
31524    dlSf->numGrpPerTti = cell->cell5gtfCb.ueGrpPerTti;
31525    dlSf->numUePerGrp = cell->cell5gtfCb.uePerGrpPerTti;
31526         for(idx = 0; idx < MAX_5GTF_BEAMS; idx++)
31527    {
31528       dlSf->sfBeamInfo[idx].totVrbgAllocated = 0;
31529       dlSf->sfBeamInfo[idx].totVrbgRequired = 0;
31530       dlSf->sfBeamInfo[idx].vrbgStart = 0;
31531    }
31532 #endif
31533    dlSf->remUeCnt = cellSch->dl.maxUePerDlSf;
31534    /* Updating the Subframe information in RBAllocInfo */
31535    cellSch->allocInfo.dedAlloc.dedDlSf   = dlSf;
31536    cellSch->allocInfo.msg4Alloc.msg4DlSf = dlSf;
31537
31538    /* LTE_ADV_FLAG_REMOVED_START */
31539    /* Determine next scheduling subframe is ABS or not */
31540    if(RGR_ENABLE == cell->lteAdvCb.absCfg.status)
31541    {
31542       cell->lteAdvCb.absPatternDlIdx = 
31543          ((frm.sfn*RGSCH_NUM_SUB_FRAMES_5G) + frm.slot) % RGR_ABS_PATTERN_LEN;
31544       cell->lteAdvCb.absDlSfInfo = (RgSchAbsSfEnum)(cell->lteAdvCb.absCfg.absPattern[
31545             cell->lteAdvCb.absPatternDlIdx]);
31546
31547    }
31548    else
31549    {
31550       cell->lteAdvCb.absDlSfInfo = RG_SCH_ABS_DISABLED;
31551    }
31552    /* LTE_ADV_FLAG_REMOVED_END */
31553
31554 #ifdef RGR_V1
31555    cellSch->allocInfo.ccchSduAlloc.ccchSduDlSf = dlSf;
31556 #endif
31557 #ifdef LTEMAC_SPS
31558    /* Update subframe-wide allocation information with SPS allocation */
31559    rgSCHCmnSpsDlUpdDlSfAllocWithSps(cell, frm, dlSf);
31560 #endif
31561    RETVOID;
31562 }
31563
31564
31565
31566 #ifdef DL_LA
31567 /**
31568  * @brief Check & Updates the TM Mode chnage threashold based on cqiiTbs and
31569  * actual iTbs
31570  * 
31571  * @details
31572  *
31573  *     Function: rgSCHCmnSendTxModeInd(cell, ueUl, newTxMode)
31574  *     Purpose:  This function sends the TX mode Change 
31575  *               indication to RRM
31576  *     change
31577  *
31578  *     Invoked by: CMN
31579  *
31580  *  @param[in]  RgSchCellCb      *cell
31581  *  @param[in]  RgSchUeCb        *ue
31582  *  @param[in]  U8               newTxMode
31583  *  @return Void
31584  **/
31585 #ifdef ANSI
31586 PRIVATE Void rgSCHCmnSendTxModeInd 
31587 (
31588 RgSchCellCb    *cell,
31589 RgSchUeCb      *ue,
31590 U8             newTxMode
31591 )
31592 #else
31593 PRIVATE Void rgSCHCmnSendTxModeInd(cell, ue, newTxMode)
31594 RgSchCellCb    *cell;
31595 RgSchUeCb      *ue;
31596 U8             newTxMode;
31597 #endif
31598
31599    RgmTransModeInd   *txModeChgInd;
31600    RgSchCmnDlUe      *ueDl =  RG_SCH_CMN_GET_DL_UE(ue,cell);
31601
31602
31603    if(!(ueDl->mimoInfo.forceTD & RG_SCH_CMN_TD_TXMODE_RECFG))
31604    {
31605       /* Mem Alloc */
31606       if(SGetSBuf(cell->rgmSap->sapCfg.sapPst.region,
31607                cell->rgmSap->sapCfg.sapPst.pool, (Data**)&txModeChgInd,
31608                sizeof(RgmTransModeInd)) != ROK)
31609       {
31610          RETVOID;
31611       }
31612       RG_SCH_FILL_RGM_TRANSMODE_IND(ue->ueId, cell->cellId, newTxMode, txModeChgInd);
31613       RgUiRgmChangeTransModeInd(&(cell->rgmSap->sapCfg.sapPst),
31614             cell->rgmSap->sapCfg.suId, txModeChgInd);
31615    }
31616
31617    ue->mimoInfo.txModUpChgFactor = 0;
31618    ue->mimoInfo.txModDownChgFactor = 0;
31619    ueDl->laCb[0].deltaiTbs = 0;
31620
31621    RETVOID;
31622 }
31623
31624 /**
31625  * @brief Check & Updates the TM Mode chnage threashold based on cqiiTbs and
31626  * actual iTbs
31627  * 
31628  * @details
31629  *
31630  *     Function: rgSchCheckAndTriggerModeChange(cell, ueUl, iTbsNew)
31631  *     Purpose:  This function update and check for threashold for TM mode
31632  *     change
31633  *
31634  *     Invoked by: CMN
31635  *
31636  *  @param[in]  RgSchCellCb      *cell
31637  *  @param[in]  RgSchUeCb        *ue
31638  *  @param[in]  U8               iTbs
31639  *  @return Void
31640  **/
31641 #ifdef ANSI
31642 Void rgSchCheckAndTriggerModeChange
31643 (
31644 RgSchCellCb    *cell,
31645 RgSchUeCb      *ue,
31646 U8             reportediTbs,
31647 U8             previTbs,
31648 U8             maxiTbs
31649 )
31650 #else
31651 Void rgSchCheckAndTriggerModeChange(cell, ue, reportediTbs, previTbs, maxiTbs)
31652 RgSchCellCb    *cell;
31653 RgSchUeCb      *ue;
31654 U8             reportediTbs;
31655 U8             previTbs;
31656 U8             maxiTbs;
31657 #endif
31658 {
31659    RgrTxMode          txMode;       /*!< UE's Transmission Mode */
31660    RgrTxMode          modTxMode;       /*!< UE's Transmission Mode */
31661
31662
31663    txMode = ue->mimoInfo.txMode;
31664
31665    /* Check for Step down */
31666    /* Step down only when TM4 is configured. */
31667    if(RGR_UE_TM_4 == txMode)
31668    {
31669       if((previTbs <= reportediTbs) && ((reportediTbs - previTbs) >= RG_SCH_MODE_CHNG_STEPDOWN_CHECK_FACTOR))
31670       {
31671          ue->mimoInfo.txModDownChgFactor += RG_SCH_MODE_CHNG_STEPUP_FACTOR;
31672       }
31673       else
31674       {
31675          ue->mimoInfo.txModDownChgFactor -= RG_SCH_MODE_CHNG_STEPDOWN_FACTOR;
31676       }
31677
31678       ue->mimoInfo.txModDownChgFactor =  
31679          RGSCH_MAX(ue->mimoInfo.txModDownChgFactor, -(RG_SCH_MODE_CHNG_STEPDOWN_THRSHD));
31680
31681       if(ue->mimoInfo.txModDownChgFactor >= RG_SCH_MODE_CHNG_STEPDOWN_THRSHD)
31682       {
31683          /* Trigger Mode step down */
31684          modTxMode = RGR_UE_TM_3;
31685          rgSCHCmnSendTxModeInd(cell, ue, modTxMode);
31686       }
31687    }
31688
31689    /* Check for Setup up */
31690    /* Step Up only when TM3 is configured, Max possible Mode is TM4*/
31691    if(RGR_UE_TM_3 == txMode)
31692    {
31693       if((previTbs > reportediTbs) || (maxiTbs == previTbs))
31694       {
31695          ue->mimoInfo.txModUpChgFactor += RG_SCH_MODE_CHNG_STEPUP_FACTOR;
31696       }
31697       else
31698       {
31699          ue->mimoInfo.txModUpChgFactor -= RG_SCH_MODE_CHNG_STEPDOWN_FACTOR;
31700       }
31701
31702       ue->mimoInfo.txModUpChgFactor = 
31703          RGSCH_MAX(ue->mimoInfo.txModUpChgFactor, -(RG_SCH_MODE_CHNG_STEPUP_THRSHD));
31704
31705       /* Check if TM step up need to be triggered */
31706       if(ue->mimoInfo.txModUpChgFactor >= RG_SCH_MODE_CHNG_STEPUP_THRSHD)
31707       {
31708          /* Trigger mode chnage */
31709          modTxMode =  RGR_UE_TM_4;
31710          rgSCHCmnSendTxModeInd(cell, ue, modTxMode);
31711       }
31712    }
31713
31714    RETVOID;
31715 }
31716 #endif
31717
31718 /**
31719 * @brief Updates the GBR LCGs when datInd is received from MAC
31720  * 
31721  * @details
31722  *
31723  *     Function: rgSCHCmnIsDlCsgPrio (cell)
31724  *     Purpose:  This function returns if csg UEs are
31725  *               having priority at current time
31726  *
31727  *     Invoked by: Scheduler
31728  *
31729  *  @param[in]  RgSchCellCb      *cell
31730  *  @param[in]  RgSchUeCb        *ue
31731  *  @param[in]  RgInfUeDatInd    *datInd
31732  *  @return Void
31733  **/
31734 #ifdef ANSI
31735 Bool rgSCHCmnIsDlCsgPrio
31736 (
31737 RgSchCellCb    *cell
31738 )
31739 #else
31740 Bool rgSCHCmnIsDlCsgPrio(cell)
31741 RgSchCellCb    *cell;
31742 #endif
31743 {
31744   
31745    RgSchCmnDlCell *cmnDlCell = RG_SCH_CMN_GET_DL_CELL(cell);
31746  
31747    /* Calculating the percentage resource allocated */
31748    if(RGR_CELL_ACCS_HYBRID != rgSchCb[cell->instIdx].rgrSchedEnbCfg.accsMode)
31749    {
31750       return (FALSE);
31751    }
31752    else
31753    {
31754       if(((cmnDlCell->ncsgPrbCnt * 100) / cmnDlCell->totPrbCnt) < cell->minDlResNonCsg)
31755       {
31756          return (FALSE);
31757       }
31758       else
31759       {
31760          return (TRUE);
31761       }
31762    }
31763 }
31764
31765 /**
31766 * @brief Updates the GBR LCGs when datInd is received from MAC
31767  * 
31768  * @details
31769  *
31770  *     Function: rgSCHCmnIsUlCsgPrio (cell)
31771  *     Purpose:  This function returns if csg UEs are
31772  *               having priority at current time
31773  *
31774  *     Invoked by: Scheduler
31775  *
31776  *  @param[in]  RgSchCellCb      *cell
31777  *  @param[in]  RgSchUeCb        *ue
31778  *  @param[in]  RgInfUeDatInd    *datInd
31779  *  @return Void
31780  **/
31781 #ifdef ANSI
31782 Bool rgSCHCmnIsUlCsgPrio
31783 (
31784 RgSchCellCb    *cell
31785 )
31786 #else
31787 Bool rgSCHCmnIsUlCsgPrio(cell)
31788 RgSchCellCb    *cell;
31789 #endif
31790 {
31791    RgSchCmnUlCell *cmnUlCell = RG_SCH_CMN_GET_UL_CELL(cell);
31792  
31793
31794    /* Calculating the percentage resource allocated */
31795    if(RGR_CELL_ACCS_HYBRID != rgSchCb[cell->instIdx].rgrSchedEnbCfg.accsMode)
31796    {
31797       return (FALSE);
31798    }
31799    else
31800    {
31801       if (((cmnUlCell->ncsgPrbCnt * 100) /cmnUlCell->totPrbCnt) < cell->minUlResNonCsg)
31802       {
31803          return (FALSE);
31804       }
31805       else
31806       {
31807          return (TRUE);
31808       }
31809    }
31810 }
31811
31812 /** @brief DL scheduler for SPS, and all other downlink data
31813  *
31814  * @details
31815  *
31816  *      Function: rgSchCmnPreDlSch
31817  *
31818  *  @param  [in] Inst               schInst;
31819  *   Returns: Void
31820  *
31821  */
31822 #ifdef ANSI
31823    Void rgSchCmnPreDlSch
31824 (
31825  RgSchCellCb        **cell,
31826  U8                 nCell,
31827  RgSchCellCb        **cellLst
31828  )
31829 #else
31830 Void rgSchCmnPreDlSch(cell, nCell, cellLst)
31831    RgSchCellCb        **cell;
31832    U8                 nCell;
31833    RgSchCellCb        **cellLst;
31834 #endif
31835 {
31836    RgSchCmnCell  *cellSch = RG_SCH_CMN_GET_CELL(cell[0]);
31837    RgSchDlSf     *sf;
31838    U8            idx;
31839
31840
31841    if(nCell > CM_LTE_MAX_CELLS)
31842    {
31843       RETVOID;
31844    }
31845
31846    if (cell[0]->isDlDataAllwd && (cell[0]->stopDlSch == FALSE))
31847    {
31848       /* Specific DL scheduler to perform UE scheduling */
31849       cellSch->apisDl->rgSCHDlPreSched(cell[0]);
31850
31851       /* Rearranging the cell entries based on their remueCnt in SF.
31852        * cells will be processed in the order of number of ue scheduled
31853        * in that cell */
31854       for (idx = 0; idx < nCell; idx++)
31855       {
31856          U8    j;
31857          cellSch = RG_SCH_CMN_GET_CELL(cell[idx]);
31858          sf = cellSch->allocInfo.dedAlloc.dedDlSf;
31859
31860          if(idx == 0)
31861          {
31862             cellLst[idx] = cell[idx];
31863             continue;
31864          }
31865
31866          for(j = 0; j < idx; j++)
31867          {
31868             RgSchCmnCell *cmnCell = RG_SCH_CMN_GET_CELL(cellLst[j]);
31869             RgSchDlSf    *subfrm = cmnCell->allocInfo.dedAlloc.dedDlSf;
31870
31871             if(sf->remUeCnt < subfrm->remUeCnt)
31872             {
31873                U8  k;
31874                for(k = idx; k > j; k--)
31875                {
31876                   cellLst[k] = cellLst[k-1];
31877                }
31878                break;
31879             }
31880          }
31881          cellLst[j] = cell[idx];
31882       }
31883    }
31884    else
31885    {
31886       for (idx = 0; idx < nCell; idx++)
31887       {
31888          cellLst[idx] = cell[idx];
31889       }
31890    }
31891    RETVOID;
31892 }
31893
31894 /** @brief DL scheduler for SPS, and all other downlink data
31895  *  @details
31896  *
31897  *       Function: rgSchCmnPstDlSch
31898  *
31899  *        @param  [in] Inst               schInst;
31900  *        Returns: Void
31901  *
31902  */
31903 #ifdef ANSI
31904 Void rgSchCmnPstDlSch
31905 (
31906  RgSchCellCb       *cell
31907 )
31908 #else
31909 Void rgSchCmnPstDlSch(cell)
31910    RgSchCellCb        *cell
31911 #endif
31912 {
31913    RgSchCmnCell  *cellSch = RG_SCH_CMN_GET_CELL(cell);
31914
31915
31916    if (cell->isDlDataAllwd && (cell->stopDlSch == FALSE))
31917    {
31918       cellSch->apisDl->rgSCHDlPstSched(cell->instIdx);
31919    }
31920 }
31921
31922 #ifdef ANSI
31923 U8 rgSCHCmnCalcPcqiBitSz
31924 (
31925  RgSchUeCb    *ueCb, 
31926  U8           numTxAnt
31927 )
31928 #else
31929 U8 rgSCHCmnCalcPcqiBitSz(ueCb, numTxAnt)
31930    RgSchUeCb     *ueCb;
31931    U8            numTxAnt;
31932 #endif
31933 {
31934    U8 confRepMode;
31935    U8 pcqiSz;
31936    U8 ri;
31937    RgSchUePCqiCb *cqiCb = ueCb->nPCqiCb;
31938
31939
31940    confRepMode = cqiCb->cqiCfg.cqiSetup.prdModeEnum;
31941    if((ueCb->mimoInfo.txMode != RGR_UE_TM_3) && 
31942          (ueCb->mimoInfo.txMode != RGR_UE_TM_4))
31943    {
31944       ri =1;
31945    }
31946    else
31947    {
31948       ri = cqiCb->perRiVal;
31949    }
31950    switch(confRepMode)
31951    {
31952       case RGR_PRD_CQI_MOD10:
31953          {
31954             pcqiSz = 4;
31955          }
31956          break;
31957
31958       case RGR_PRD_CQI_MOD11:
31959          {
31960             if(numTxAnt == 2)
31961             {
31962                if (ri ==1)
31963                {
31964                   pcqiSz = 6;
31965                }
31966                else
31967                {
31968                   pcqiSz = 8;
31969                }
31970             }
31971             else if(numTxAnt == 4)
31972             {
31973                if (ri ==1)
31974                {
31975                   pcqiSz = 8;
31976                }
31977                else
31978                {
31979                   pcqiSz = 11;
31980                }
31981             }
31982             else
31983             {
31984                /* This is number of antenna case 1.
31985                 * This is not applicable for Mode 1-1. 
31986                 * So setting it to invalid value */
31987                pcqiSz = 0;
31988             }
31989          }
31990          break;
31991
31992       case RGR_PRD_CQI_MOD20:
31993          {
31994             if(cqiCb->isWb)
31995             {
31996                pcqiSz = 4;
31997             }
31998             else
31999             {
32000                pcqiSz = 4 + cqiCb->label;
32001             }
32002          }
32003          break;
32004
32005       case RGR_PRD_CQI_MOD21:
32006          {
32007             if(cqiCb->isWb)
32008             {
32009                if(numTxAnt == 2)
32010                {
32011                   if (ri ==1)
32012                   {
32013                      pcqiSz = 6;
32014                   }
32015                   else
32016                   {
32017                      pcqiSz = 8;
32018                   }
32019                }
32020                else if(numTxAnt == 4)
32021                {
32022                   if (ri ==1)
32023                   {
32024                      pcqiSz = 8;
32025                   }
32026                   else
32027                   {
32028                      pcqiSz = 11;
32029                   }
32030                }
32031                else
32032                {
32033                   /* This might be number of antenna case 1.
32034                    * For mode 2-1 wideband case only antenna port 2 or 4 is supported.
32035                    * So setting invalid value.*/
32036                   pcqiSz = 0;
32037                }
32038             }
32039             else
32040             {
32041                if (ri ==1)
32042                {
32043                   pcqiSz = 4 + cqiCb->label;
32044                }
32045                else
32046                {
32047                   pcqiSz = 7 + cqiCb->label;
32048                }
32049             }
32050          }
32051          break;
32052       default:
32053           pcqiSz = 0;
32054           break;
32055    }
32056    
32057    return (pcqiSz);
32058 }
32059
32060 /** @brief DL scheduler for SPS, and all other downlink data
32061  *
32062  * @details
32063  *
32064  *     Function: rgSCHCmnDlSch
32065  *
32066  * @param  [in] RgSchCellCb    *cell
32067  *
32068  * Returns: Void
32069  *
32070  */
32071 #ifdef ANSI
32072 Void rgSCHCmnDlSch
32073 (
32074  RgSchCellCb        *cell
32075  )
32076 #else
32077 Void rgSCHCmnDlSch (cell)
32078    RgSchCellCb        *cell;
32079 #endif
32080 {
32081    RgSchDlSf *dlSf;
32082    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
32083 #ifdef RG_5GTF
32084    RgSchDynTddCb  *rgSchDynTddInfo = &(rgSchCb[cell->instIdx].rgSchDynTdd);
32085    U16 dlCntrlSfIdx;
32086 #endif
32087
32088
32089    dlSf = rgSCHUtlSubFrmGet(cell, cellSch->dl.time);
32090 #ifdef RG_5GTF
32091         if (rgSchDynTddInfo->isDynTddEnbld)
32092    {
32093       RG_SCH_DYN_TDD_GET_SFIDX(dlCntrlSfIdx, rgSchDynTddInfo->crntDTddSfIdx, 
32094                                             RG_SCH_CMN_DL_DELTA);
32095                 if(RG_SCH_DYNTDD_DLC_ULD == rgSchDynTddInfo->sfInfo[dlCntrlSfIdx].sfType)
32096                 {
32097                    if(1 == cell->cellId)
32098          {
32099                       ul5gtfsidDlAlreadyMarkUl++;
32100             /*
32101                       printf("ul5gtfsidDlAlreadyMarkUl: %d, [sfn:sf] [%04d:%02d]\n", 
32102                     ul5gtfsidDlAlreadyMarkUl, cellSch->dl.time.sfn, 
32103                     cellSch->dl.time.slot);
32104             */
32105          }
32106                    RETVOID;
32107                 }
32108    }
32109 #endif
32110
32111    /* Specific DL scheduler to perform UE scheduling */
32112    cellSch->apisDl->rgSCHDlNewSched(cell, &cellSch->allocInfo);      
32113    /* LTE_ADV_FLAG_REMOVED_END */
32114
32115    /* call common allocator for RB Allocation */
32116    rgSCHCmnDlRbAlloc(cell, &cellSch->allocInfo);
32117
32118    /* Finalize the Allocations for reqested Against alloced */
32119    rgSCHCmnDlAllocFnlz(cell);
32120
32121    /* Perform Pdcch allocations for PDCCH Order Q.
32122     * As of now, giving this the least preference.
32123     * This func call could be moved above other allocations
32124     * as per need */
32125    rgSCHCmnGenPdcchOrder(cell, dlSf);
32126
32127    /* Do group power control for PUCCH */
32128    rgSCHCmnGrpPwrCntrlPucch(cell, dlSf);
32129
32130    RETVOID;
32131 }
32132
32133 /**********************************************************************
32134
32135   End of file
32136 **********************************************************************/