remove/replaced PRIVATE and EXTERN keywords
[o-du/l2.git] / src / 5gnrsch / rg_sch_scell.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 Round Robin functions
26
27      File:     rg_sch_scell.c
28
29 **********************************************************************/
30
31 /** @file rg_sch_rr.c
32 @brief This module handles the round robin scheduler functionality
33 */
34
35 /* header include files -- defines (.h) */
36 #include "common_def.h"
37 #include "lrg.h"
38 #include "rgr.h"
39 #include "rgm.h"
40 #include "tfu.h"
41 #include "rg_env.h"
42 #include "rg_sch_inf.h"
43 #include "rg_sch_err.h"
44 #include "rg_sch.h"
45 #include "rg_sch_cmn.h"
46
47 /* header/extern include files (.x) */
48 #include "tfu.x"           /* RGU types */
49 #include "lrg.x"           /* layer management typedefs for MAC */
50 #include "rgr.x"           /* layer management typedefs for MAC */
51 #include "rgm.x"           /* layer management typedefs for MAC */
52 #include "rg_sch_inf.x"    /* typedefs for Scheduler */
53 #include "rg_sch.x"        /* typedefs for Scheduler */
54 #include "rg_sch_cmn.x"
55
56 #ifdef LTE_ADV
57
58 Void rgSCHSCellActivation ARGS((
59 RgSchUeCellInfo  *sCell
60 ));
61
62 Void rgSCHSCellSchdActDeactCe ARGS((
63 RgSchUeCb         *ueCb,
64 RgSchDlHqTbCb     *tbInfo
65 ));
66 Void rgSCHSCellAddToActDeactLst ARGS((
67 RgSchCellCb                *cell,
68 RgSchUeCb                  *ue
69 ));
70
71 Void rgSCHSCellRmvFrmActLst ARGS((
72 RgSchCellCb                *cell,
73 RgSchUeCb                  *ue
74 ));
75 S16 rgSCHSCellIsActive ARGS((
76 RgSchCellCb                *cell,
77 RgSchUeCb                  *ue
78 ));
79
80 Void rgSCHSCellHndlFdbkInd ARGS((
81 RgSchDlHqProcCb   *hqP,
82 uint8_t                tbIdx,
83 uint8_t                fdbk,
84 Bool              maxHqRetxReached
85 ));
86
87 #ifdef LTE_ADV
88 Void rgSCHSCellDeactTmrExpry ARGS((
89 RgSchUeCellInfo *sCell
90 ));
91 #endif
92
93 Void rgSCHSCellDelUeSCell ARGS((
94 RgSchCellCb  *cellCb,
95 RgSchUeCb    *ueCb,
96 uint8_t            sCellIdx
97 ));
98
99 S16 rgSCHSCellDelUe ARGS((
100 RgSchCellCb  *cellCb,
101 RgSchUeCb    *ueCb
102 ));
103 #ifdef TFU_UPGRADE
104 S16 rgSCHSCellPCqiCfg ARGS((
105 RgSchCellCb  *priCellCb,
106 RgSchCellCb  *secCellCb,
107 RgSchUeCb    *ueCb,
108 RgrUePrdDlCqiCfg  *cqiCfg,
109 CmLteUeCategory   ueCat,
110 uint8_t            sCellIdx
111 ));
112 #endif
113 static S16 rgSCHSCellTrgMacHqEReset ARGS((
114 Inst          inst,
115 uint16_t           secCellId,
116 uint16_t           rnti
117 ));
118
119
120
121 /** * @brief Handler for scheduling Scell Activation CE.
122  *
123  * @details
124  *
125  *     Function : rgSCHDhmShcdSCellActCe
126  *     
127  *     This function is called by scheduler when resource allocation
128  *     for SCell Activation CE transmission is done.
129  *           
130  *  @param[in]  RgSchUeCb         *ue
131  *  @param[out] RgSchDlHqTbCb     *tbInfo
132  *  @return     Void
133  *      -# None.
134  **/
135 #ifdef ANSI
136 Void rgSCHSCellSchdActDeactCe
137 (
138 RgSchUeCb         *ueCb,
139 RgSchDlHqTbCb     *tbInfo
140 )
141 #else
142 Void rgSCHSCellSchdActDeactCe(ueCb, tbInfo)
143 RgSchUeCb         *ueCb;
144 RgSchDlHqTbCb     *tbInfo;
145 #endif
146 {
147
148    uint8_t   bitVal = 0;
149    uint8_t   sCellActDeactBitMask = 0;
150
151    /* Change the state of all Scells waiting for
152     * activation */
153
154    /* -------------------------
155     * | C7|C6|C5|C4|C3|C2|C1|R|
156     * -------------------------*/
157     /* 1 for activation
158      * 0 for deactivation
159      * */
160
161    for(uint8_t idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
162    {
163       if(ueCb->cellInfo[idx] != NULLP)
164       {
165          switch(ueCb->cellInfo[idx]->sCellState)
166          {
167             case RG_SCH_SCELL_TOBE_ACTIVATED:
168             case RG_SCH_SCELL_ACTVTN_IN_PROG:
169                {
170                   ueCb->cellInfo[idx]->sCellState = RG_SCH_SCELL_ACTVTN_IN_PROG; 
171                   bitVal = 1;
172                }
173                break;
174             case RG_SCH_SCELL_ACTIVE:
175                {
176                   bitVal = 1;
177                }
178                break;
179             case RG_SCH_SCELL_TOBE_DEACTIVATED:
180             case RG_SCH_SCELL_DEACTVTN_IN_PROG:
181                {
182                   ueCb->cellInfo[idx]->sCellState = RG_SCH_SCELL_DEACTVTN_IN_PROG; 
183                   bitVal = 0;
184                }
185                break;
186             case RG_SCH_SCELL_INACTIVE:
187             case RG_SCH_SCELL_READY:
188                {
189                   bitVal = 0;
190                }
191                break;
192          }
193       }
194       if(1 == bitVal)
195       {
196          sCellActDeactBitMask |= 1 << (idx);/* servCellIdx = idx + 1 */
197          bitVal = 0;
198       }
199    }
200    tbInfo->schdSCellActCe.pres    = PRSNT_NODEF;
201    tbInfo->schdSCellActCe.val     = sCellActDeactBitMask;
202
203    return;
204 } /* rgSCHSCellSchdActDeactCe */
205
206 \f
207 /**
208  * @brief Adds an UE to the Cell's SCell Activation list
209  *
210  * @details
211  *
212  *     Function: rgSCHSCellAddToActDeactLst
213  *     Purpose:  Adds an UE to Cell's SCEll Act list
214  *
215  *     Invoked by: Common Scheduler
216  *
217  *  @param[in]  RgSchCellCb*     cell
218  *  @param[in]  RgSchUeCb*       ue
219  *  @return  Void
220  *
221  **/
222 #ifdef ANSI
223 Void rgSCHSCellAddToActDeactLst
224 (
225 RgSchCellCb                *cell,
226 RgSchUeCb                  *ue
227 )
228 #else
229 Void rgSCHSCellAddToActDeactLst(cell, ue)
230 RgSchCellCb                *cell;
231 RgSchUeCb                  *ue;
232 #endif
233 {
234    RgSchCmnDlCell *cellCmnDl = RG_SCH_CMN_GET_DL_CELL(cell);
235
236    if(NULLP == ue->sCellActLnk.node)
237    {/* Ue is not present in the list */
238       cmLListAdd2Tail(&cellCmnDl->secCellActCeLst, &ue->sCellActLnk);
239       ue->sCellActLnk.node = (PTR)ue;
240    }
241    else
242    {
243       RGSCHDBGINFONEW(cell->instIdx,(rgSchPBuf(cell->instIdx),
244             "SCell is already added in the Act List: ueId(%u)\n", ue->ueId));
245    }
246    
247    return;
248 }
249
250 \f
251 /**
252  * @brief Removes an UE from Cell's SCell Activation list
253  *
254  * @details
255  *
256  *     Function: rgSCHSCellRmvFrmActLst
257  *     Purpose:  Removes an UE from Cell's SCEll Act list
258  *
259  *     Invoked by: Specific Scheduler
260  *
261  *  @param[in]  RgSchCellCb*     cell
262  *  @param[in]  RgSchUeCb*       ue
263  *  @return  Void
264  *
265  **/
266 #ifdef ANSI
267 Void rgSCHSCellRmvFrmActLst
268 (
269 RgSchCellCb                *cell,
270 RgSchUeCb                  *ue
271 )
272 #else
273 Void rgSCHSCellRmvFrmActLst(cell, ue)
274 RgSchCellCb                *cell;
275 RgSchUeCb                  *ue;
276 #endif
277 {
278    RgSchCmnDlCell *cellCmnDl = RG_SCH_CMN_GET_DL_CELL(cell);
279    if (NULLP != ue->sCellActLnk.node)
280    {
281       cmLListDelFrm(&cellCmnDl->secCellActCeLst, &ue->sCellActLnk);
282    }
283    ue->sCellActLnk.node = (PTR)NULLP;
284
285    return;
286 }
287 \f
288 /**
289  * @brief Handling of SCell Activation
290  *
291  * @details
292  *
293  *     Function: rgSCHSCellActivation
294  *     Purpose : Perform Activation of secondary cell
295  *             : Move the state to ACTIVE
296  *             : Start the procedure for PCQI/SRS for this scell
297  *
298  *     Invoked by:Cfg/Commn Scheduler 
299  *
300  *  @param[in]  RgSchUeCellInfo *sCellInfo
301  *
302  *  @return  ROK/RFAILED
303  *
304  **/
305 #ifdef ANSI
306 Void rgSCHSCellActivation
307 (
308 RgSchUeCellInfo  *sCellInfo
309 )
310 #else
311 Void rgSCHSCellActivation(sCellInfo)
312 RgSchUeCellInfo  *sCellInfo
313 #endif
314 {
315    RgSchCellCb  *sCell = sCellInfo->cell;
316    RgSchUeCb    *ueCb = sCellInfo->ue;
317    RgSchCmnCell *cellSch;
318 #ifdef TFU_UPGRADE
319 #ifdef DEBUGP
320    Inst   inst = ueCb->cell->instIdx;
321 #endif
322    uint16_t    tempIdx; 
323    RgrUePrdDlCqiCfg  *cqiCfg;
324    uint8_t     j;  /*Bandwidth Parts*/
325    uint16_t    riTrInsTime; 
326    uint16_t    periodicity; 
327    uint16_t    cqiTrInstTime; 
328    RgSchUePCqiCb *cqiCb = NULLP;
329    CmLteTimingInfo timingInfo;
330    uint16_t    crntTime;           
331 #endif
332
333
334    sCellInfo->sCellState = RG_SCH_SCELL_ACTIVE;
335 #ifdef TENB_STATS
336    ueCb->tenbStats->stats.persistent.numActivation++;
337 #endif
338
339 #ifdef CA_DBG 
340    printf("ueId is SCELL_ACTIVE\n ueCb->ueId = %d sCell->sCellIdx =%d, sCell->sCellId=%d, sCell->sCellState=%d \n", ueCb->ueId, sCellInfo->sCellIdx, sCellInfo->sCellId, sCellInfo->sCellState);
341 #endif
342    /* Start the sCellDeactivation timer if cfgd */
343    if(PRSNT_NODEF == ueCb->sCellDeactTmrVal.pres)
344    {
345       //rgSCHTmrStartTmr (sCell,sCellInfo ,RG_SCH_TMR_SCELL_DEACT,
346         //    ueCb->sCellDeactTmrVal.val);
347    }
348
349 #ifdef TFU_UPGRADE
350    /* Start receiving CQI for this SCell for this UE */
351    crntTime = (ueCb->cell->crntTime.sfn * RGSCH_NUM_SUB_FRAMES_5G)+
352                   (ueCb->cell->crntTime.slot);
353
354    cqiCb = &sCellInfo->cqiCb;
355    cqiCfg = &cqiCb->cqiCfg;
356    if (cqiCfg->type == RGR_SCH_PCQI_SETUP)
357    {
358       cqiTrInstTime = ((cqiCb->cqiPeri+crntTime) - cqiCb->cqiOffset)
359          %cqiCb->cqiPeri;
360       cqiCb->nCqiTrIdx = (crntTime + 
361             (cqiCb->cqiPeri - cqiTrInstTime));
362       /* Introduced timing delta for reception req
363        * in FDD*/
364       if(cqiCb->nCqiTrIdx  <= (crntTime + TFU_RECPREQ_DLDELTA))
365       {
366          cqiCb->nCqiTrIdx = cqiCb->nCqiTrIdx + cqiCb->cqiPeri;
367       }
368
369       timingInfo.sfn =  cqiCb->nCqiTrIdx/RGSCH_NUM_SUB_FRAMES_5G;
370       timingInfo.slot =  cqiCb->nCqiTrIdx%RGSCH_NUM_SUB_FRAMES_5G;
371       if(cqiCb->cqiCfg.cqiSetup.cqiRepType == RGR_UE_PCQI_SB_REP)
372       {
373          rgSCHTomUtlPcqiSbCalcBpIdx(timingInfo,ueCb,cqiCb); 
374       }
375
376       cqiCb->nCqiTrIdx = cqiCb->nCqiTrIdx
377          %RG_SCH_PCQI_SRS_SR_TRINS_SIZE;
378       RGSCHDBGINFONEW(inst, (rgSchPBuf(inst), "CQI Config: idx(%u) Periodicity %u"
379                "Offset %u uePosInQ (%u)\n", cqiCfg->cqiSetup.cqiPCfgIdx,
380                cqiCb->cqiPeri, cqiCb->cqiOffset,cqiCb->nCqiTrIdx));
381
382       cmLListAdd2Tail(&ueCb->cell->pCqiSrsSrLst[cqiCb->nCqiTrIdx].cqiLst,
383             &cqiCb->cqiLstEnt);  
384
385       rgSCHUtlSCellHndlCqiCollsn(cqiCb);
386
387       RGSCHDBGINFO(inst,(rgSchPBuf(inst), 
388                "\n rgSCHCfgPCqiUeCfg():"
389                "  CrntTime=%d  Next CqiTrInstTime=%d  Index Stored at=%d  ",
390                crntTime, cqiTrInstTime, cqiCb->nCqiTrIdx));
391
392       if(cqiCfg->cqiSetup.riEna)
393       {
394          cqiCb->perRiVal = 1;
395          cqiCb->invalidateCqi = FALSE;
396
397          if(RGR_UE_PCQI_WB_REP == cqiCfg->cqiSetup.cqiRepType)
398          {
399             /* 
400                1. wideband RI reporting is configured 
401                (Mode 1-0 or 1-1)
402                (10*sfn+floor(subframe)-Noffsetcqi-NoffsetRI )Mod(NCqiperiod
403              *MriPeriod)=0  
404              */ 
405             periodicity = cqiCb->cqiPeri * cqiCb->riPeri; 
406          }
407          else
408          {
409             /*
410              *  Where Widesband and Subband RI reporting is configured
411              *   (Mode 2-0 or 2-1 )
412              *   (10*sfn+floor(subframe)-Noffsetcqi-NoffsetRI )
413              *   Mod(H. NCqiperiod *MriPeriod )=0 
414              *   where H= J * K +1;  J=Number of bandwidth parts(BW/subsize). 
415              *   K is RGR interf input 
416              */
417
418             RG_SCH_GET_CQI_J_VAL(sCell->bwCfg.dlTotalBw, j);
419             cqiCb->h = (cqiCb->cqiCfg.cqiSetup.k *j )+1;  
420             periodicity = cqiCb->h * cqiCb->cqiPeri * 
421                cqiCb->riPeri; 
422
423          }
424
425          /* In case of SFN wraparound, the SB CQI reporting cycle breaks
426           * and RI->WB CQI->SBCQI.. should resume. RI is repositioned 
427           * accordingly. WBCQI handling is naturally accomplished */
428          if (periodicity >= RGSCH_MAX_SUBFRM_5G)
429          {
430             periodicity = cqiCb->cqiOffset - cqiCb->riOffset + 
431                RGSCH_MAX_SUBFRM_5G - (crntTime);
432             tempIdx = crntTime + periodicity;
433          }
434          else
435          {
436             riTrInsTime = ((periodicity +crntTime )- \
437                   cqiCb->cqiOffset + cqiCb->riOffset)\
438                           % periodicity;
439             tempIdx = (crntTime + (periodicity -riTrInsTime));
440          }
441          if (tempIdx <= (crntTime + TFU_RECPREQ_DLDELTA))
442          {
443             tempIdx = tempIdx + periodicity; 
444          }
445          cqiCb->nRiTrIdx = tempIdx 
446             % RG_SCH_PCQI_SRS_SR_TRINS_SIZE;
447          if(periodicity >= RG_SCH_PCQI_SRS_SR_TRINS_SIZE)
448          {  
449             cqiCb->riDist = rgSCHUtlFindDist((uint16_t)(crntTime + TFU_RECPREQ_DLDELTA),
450                   (uint16_t) tempIdx);
451          }
452          else
453          {
454             cqiCb->riDist =0; 
455          }
456
457
458          /* Start receiving RI for this SCell for this UE */
459          cmLListAdd2Tail(&ueCb->cell->pCqiSrsSrLst[cqiCb->nRiTrIdx].riLst,
460                &cqiCb->riLstEnt);  
461          RG_SCH_RECORD(&cqiCb->histElem,RGSCH_ACTION_ADD,
462             &ueCb->cell->pCqiSrsSrLst[cqiCb->nRiTrIdx].riLst);
463
464          rgSCHUtlSCellHndlRiCollsn(cqiCb);
465          /*werror*/
466 #ifndef BIT_64
467          RGSCHDBGINFONEW(inst,(rgSchPBuf(inst), "SCel RI cfg:"
468                   "idx %u period %u Offset %u posInQ(%u) riDist(%u)lst count"
469                   "%lu\n", cqiCfg->cqiSetup.riCfgIdx, cqiCb->riPeri,
470                   cqiCb->riOffset, cqiCb->nRiTrIdx, cqiCb->riDist, 
471                   ueCb->cell->pCqiSrsSrLst[cqiCb->nRiTrIdx].riLst.count));
472 #else
473          RGSCHDBGINFONEW(inst,(rgSchPBuf(inst), "SCel RI cfg:"
474                   "idx %u period %u Offset %u posInQ(%u) riDist(%u)lst count"
475                   "%u\n", cqiCfg->cqiSetup.riCfgIdx, cqiCb->riPeri,
476                   cqiCb->riOffset, cqiCb->nRiTrIdx, cqiCb->riDist, 
477                   ueCb->cell->pCqiSrsSrLst[cqiCb->nRiTrIdx].riLst.count));
478
479
480 #endif
481
482          RGSCHDBGINFO(inst,(rgSchPBuf(inst),
483                   "\n rgSCHSCellActivation(): CrntTime=%d Next RiTrInstTime=%d"
484                   "Index Stored at=%d riDis=%d ",
485                   crntTime, riTrInsTime, cqiCb->nRiTrIdx, cqiCb->riDist));
486       }
487    }
488 #endif
489
490    cellSch = RG_SCH_CMN_GET_CELL(sCellInfo->cell);
491    cellSch->apisDl->rgSCHDlSCellActv(sCellInfo->cell, sCellInfo->ue);
492
493    return;
494 }
495
496 #ifdef TFU_UPGRADE
497 \f
498 /**
499  * @brief Remove CQI from Scell Lst
500  *
501  * @details
502  *
503  *     Function: rgSCHCellClearScellLstOfCQI
504  *     Purpose : Remove CQI from Scell Lst
505  *              
506  *
507  *     Invoked by: Timer
508  *
509  *  @param[in]  RgSchUeCellInfo *sCellInfo
510  *  @return  Void
511  *
512  **/
513 #ifdef ANSI
514 static Void rgSCHCellClearScellLstOfCQI
515 (
516 RgSchUeCellInfo *sCellInfo
517 )
518 #else
519 static Void rgSCHCellClearScellLstOfCQI(sCellInfo)
520 RgSchUeCellInfo *sCellInfo;
521 #endif
522 {
523
524    RgSchUePCqiCb *cqiRiCb = NULLP;
525    RgSchUeCb    *ueCb;
526    ueCb = sCellInfo->ue;
527    /* Clear CQI/RI entry for this SCELL */
528    cqiRiCb = &sCellInfo->cqiCb;
529    /* Delete Periodic CQI/PMI  Transmission Instance  */
530    if (cqiRiCb->nCqiTrIdx != RG_SCH_INVALID_IDX)
531    {
532       cmLListDelFrm(&ueCb->cell->pCqiSrsSrLst[cqiRiCb->nCqiTrIdx].cqiLst, 
533             &cqiRiCb->cqiLstEnt); 
534       cqiRiCb->nCqiTrIdx = RG_SCH_INVALID_IDX;
535
536       if (ueCb->nPCqiCb == cqiRiCb)
537       {
538          rgSCHUtlSCellHndlCqiCollsn(&ueCb->cellInfo[RGSCH_PCELL_INDEX]->cqiCb);
539       }
540       /* Delete Periodic  RI  Transmission Instance  */
541
542       if (cqiRiCb->nRiTrIdx != RG_SCH_INVALID_IDX)
543       {
544          cmLListDelFrm(&ueCb->cell->pCqiSrsSrLst[cqiRiCb->nRiTrIdx].riLst, 
545                &cqiRiCb->riLstEnt); 
546          RG_SCH_RECORD(&cqiRiCb->histElem,RGSCH_ACTION_DEL,
547             &ueCb->cell->pCqiSrsSrLst[cqiRiCb->nRiTrIdx].riLst);
548          cqiRiCb->nRiTrIdx = RG_SCH_INVALID_IDX;
549          if (ueCb->nPRiCb == cqiRiCb)
550          {
551             rgSCHUtlSCellHndlRiCollsn(&ueCb->cellInfo[RGSCH_PCELL_INDEX]->cqiCb);
552          }
553       }
554    }
555
556    return;
557 }
558 #endif/*TFU_UPGRADE*/
559 \f
560 /**
561  * @brief Handling of SCell DeActivation
562  *
563  * @details
564  *
565  *     Function: rgSCHSCellDeActivation
566  *     Purpose : Perform Deactivation of secondary cell
567  *             : Move the state to IN_ACTIVE
568  *             : Flush the harqEntity
569  *             : Trigger harqEntity flushing to MAC
570  *             : Remove  PCQI/SRS for this scell
571  *             : Stop Deactivation timer if running
572  *
573  *     Invoked by:Cfg/Commn Scheduler 
574  *
575  *  @param[in]  RgSchUeCellInfo *sCellInfo
576  *
577  *  @return  ROK/RFAILED
578  *
579  **/
580 #ifdef ANSI
581 static S16 rgSCHSCellDeActivation
582 (
583 RgSchUeCellInfo *sCellInfo
584 )
585 #else
586 static S16 rgSCHSCellDeActivation(sCellInfo)
587 RgSchUeCellInfo *sCellInfo
588 #endif
589 {
590    return ROK;
591    RgSchCmnCell *cellSch;
592    Inst inst = sCellInfo->cell->instIdx;
593
594    /* Stop the timer if running */
595
596    if(sCellInfo->deactTmr.tmrEvnt != TMR_NONE)
597    {
598       rgSCHTmrStopTmr(sCellInfo->cell, RG_SCH_TMR_SCELL_DEACT, sCellInfo);
599    }
600
601    if (sCellInfo->actDelayTmr.tmrEvnt != TMR_NONE)
602    {
603       rgSCHTmrStopTmr(sCellInfo->cell, RG_SCH_TMR_SCELL_ACT_DELAY, sCellInfo);
604    }
605
606    cellSch = RG_SCH_CMN_GET_CELL(sCellInfo->cell);
607    cellSch->apisDl->rgSCHDlUeReset(sCellInfo->cell, sCellInfo->ue);
608
609    if(sCellInfo->ue->isDrxEnabled)
610    {   
611       rgSCHDrxUeHqReset(sCellInfo->ue->cell, sCellInfo->ue, 
612                         sCellInfo->hqEnt, sCellInfo->sCellIdx);
613    }
614
615    /* Flush the harqEntity at scheduler */
616    if(sCellInfo->hqEnt != NULLP) 
617    {
618       rgSCHDhmHqEntReset(sCellInfo->hqEnt);
619    }
620    /* Trigger harq flush req to MAC */
621
622
623    rgSCHSCellTrgMacHqEReset(inst,sCellInfo->sCellId,sCellInfo->ue->ueId);
624    
625    sCellInfo->sCellState = RG_SCH_SCELL_READY;
626 #ifdef TFU_UPGRADE
627    rgSCHCellClearScellLstOfCQI(sCellInfo);
628 #endif
629
630 #ifdef TENB_STATS
631    sCellInfo->ue->tenbStats->stats.persistent.numDeactivation++;
632 #endif
633
634    cellSch->apisDl->rgSCHDlSCellDeactv(sCellInfo->cell, sCellInfo->ue);
635
636 #ifdef CA_DBG 
637    printf("SCELL DEATIVATED  sCellInfo->ue->ueId =%d, sCellInfo->sCellId =%d\n", sCellInfo->ue->ueId, sCellInfo->sCellId);
638    //MSPD_DBG("SCELL DEATIVATED  sCellInfo->ue->ueId =%d, sCellInfo->sCellId =%d\n", sCellInfo->ue->ueId, sCellInfo->sCellId);
639 #endif
640    return ROK;
641 }
642
643 \f
644 /**
645  * @brief Triggering hqEntity reset to mac
646  *
647  * @details
648  *
649  *     Function: rgSCHSCellTrgMacHqEReset
650  *     Purpose: Frame the interface for mac to reset
651  *              the mac
652  *              Derive the macInstance corresponding
653  *              to the secondary cell going to be deactivated.
654  *              Triiger the msg to that macInstance
655  *
656  *     Invoked by: CommonScheduler
657  *
658  *  @param[in]  uint16_t        sCellId
659  *  @param[in]  uint16_t        rnti
660  *  @return  Void
661  *
662  **/
663 #ifdef ANSI
664 static S16 rgSCHSCellTrgMacHqEReset
665 (
666 Inst          inst,
667 uint16_t           secCellId,
668 uint16_t           rnti
669 )
670 #else
671 static S16 rgSCHSCellTrgMacHqEReset(inst,secCellId,rnti)
672 Inst          inst;
673 uint16_t           secCellId;
674 uint16_t           rnti;
675 #endif
676 {
677    Pst               pst;
678    RgSchCellCb      *secCellCb = NULLP;
679    RgInfResetHqEnt   hqEntRstInfo;
680
681    if((secCellCb = (RgSchCellCb *)rgSchUtlGetCellCb(inst, secCellId)) == NULLP)
682    {
683       RGSCHDBGERRNEW(inst, (rgSchPBuf(inst), "SCell doesnt exists"));
684       return RFAILED;
685    }
686
687    hqEntRstInfo.cellId = secCellId;
688    hqEntRstInfo.crnti  = rnti;
689
690    rgSCHUtlGetPstToLyr(&pst, &rgSchCb[inst], secCellCb->macInst);
691
692    RgSchMacRstHqEnt(&pst, &hqEntRstInfo);
693
694    return ROK;
695 }
696 /*removed endif*/
697
698
699 \f
700 /**
701  * @brief Handling of harq feeback for SCell act CE txion
702  *
703  * @details
704  *
705  *     Function: rgSCHSCellHndlFdbkInd
706  *     Purpose:  Handling the harq feedback for SCell ACT ce txion
707  *               ACK:: Set the state as active for the Scells for which
708  *                     CE was sent
709  *               HQ FAILURE/DTX/NACK:: Perform retxion. Add to Act CE list
710  *                                   Set the state to TOBE_SCHEDULED
711  *               
712  *
713  *     Invoked by: CommonScheduler
714  *
715  *  @param[in]  RgSchCellCb*     cell
716  *  @param[in]  RgSchUeCb*       ue
717  *  @return  Void
718  *
719  **/
720 #ifdef ANSI
721 Void rgSCHSCellHndlFdbkInd
722 (
723 RgSchDlHqProcCb   *hqP,
724 uint8_t                tbIdx,
725 uint8_t                fdbk,
726 Bool              maxHqRetxReached
727 )
728 #else
729 Void rgSCHSCellHndlFdbkInd(hqP, tbIdx, fdbk,maxHqRetxReached)
730 RgSchDlHqProcCb   *hqP;
731 uint8_t                tbIdx;
732 uint8_t                fdbk;
733 Bool              maxHqRetxReached;
734 #endif
735 {
736
737    RgSchUeCb      *ueCb;
738    RgSchCellCb    *cell;
739    RgSchUeCellInfo *sCellInfo;
740
741
742    ueCb  = hqP->hqE->ue;
743    cell  = ueCb->cell;
744    switch(fdbk)
745    {
746       case TFU_HQFDB_ACK:
747          {
748             hqP->tbInfo[tbIdx].schdSCellActCe.pres =  FALSE;
749
750             for(uint8_t idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
751             {
752                if(ueCb->cellInfo[idx] != NULLP) 
753                {
754                   if(ueCb->cellInfo[idx]->sCellState == RG_SCH_SCELL_ACTVTN_IN_PROG)
755                   {
756 #ifdef CA_DBG
757                      printf("\n starting delay timer...\n");
758 #endif                     
759                      rgSCHTmrStartTmr (cell,ueCb->cellInfo[idx] ,RG_SCH_TMR_SCELL_ACT_DELAY,
760                            RG_SCH_CMN_SCELL_ACT_DELAY_TMR);
761                   }
762                   else
763                   {
764                      if(ueCb->cellInfo[idx]->sCellState == RG_SCH_SCELL_DEACTVTN_IN_PROG)
765                      {
766                         sCellInfo = ueCb->cellInfo[idx];
767                         rgSCHSCellDeActivation(sCellInfo);
768                      }
769                   }
770                }
771             }
772          }
773          break;
774       case TFU_HQFDB_NACK:
775       case TFU_HQFDB_DTX:
776          {
777             if(TRUE == maxHqRetxReached)
778             {
779                hqP->tbInfo[tbIdx].schdSCellActCe.pres =  FALSE;
780                for(uint8_t idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
781                {
782                   if(ueCb->cellInfo[idx] != NULLP) 
783                   {
784                      if(ueCb->cellInfo[idx]->sCellState == RG_SCH_SCELL_ACTVTN_IN_PROG)
785                      {
786                         ueCb->cellInfo[idx]->sCellState = RG_SCH_SCELL_TOBE_ACTIVATED;
787                      }
788                      else
789                      {
790                         if(ueCb->cellInfo[idx]->sCellState == RG_SCH_SCELL_DEACTVTN_IN_PROG)
791                         {
792                            ueCb->cellInfo[idx]->sCellState = RG_SCH_SCELL_TOBE_DEACTIVATED;
793                         }
794                      }
795                   }
796                   /* Add to actDeactCe lst */
797                   rgSCHSCellAddToActDeactLst(cell,ueCb);
798                }
799             }
800          }
801          break;
802       default:
803          break;
804    }
805    return;
806 }
807
808 #ifdef LTE_ADV
809 /**
810  * @brief Handling of SCell Deactivation Tmr Expiry
811  *
812  * @details
813  *
814  *     Function: rgSCHSCellDeactTmrExpry
815  *     Purpose : Deactivating the SCell. a
816  *               Clear all the Harq Procs associated with this
817  *               scell.
818  *               Trigger Harq Reset to the respective MAC
819  *               Set the state of the cell to Inactive  
820  *              
821  *
822  *     Invoked by: Timer
823  *
824  *  @param[in]  RgSchUeCellInfo *sCellInfo
825  *  @return  Void
826  *
827  **/
828 #ifdef ANSI
829 Void rgSCHSCellDeactTmrExpry
830 (
831 RgSchUeCellInfo *sCellInfo
832 )
833 #else
834 Void rgSCHSCellDeactTmrExpry(sCellInfo)
835 RgSchUeCellInfo *sCellInfo;
836 #endif
837 {
838
839    if (sCellInfo->ue->isScellExplicitDeAct == TRUE)
840    {
841       /* Deactivation Timer is not configured (infinity), thus send deactivation CE explicitly */ 
842       /* No doing Deactivaiton of LAA Cell */
843       if (FALSE == rgSCHLaaSCellEnabled(sCellInfo->cell))
844       {
845          rgSCHSCellTrigActDeact(sCellInfo->ue->cell, sCellInfo->ue, sCellInfo->sCellIdx, RGR_SCELL_DEACT);
846       }
847       else
848       {
849          printf (" !!!!!! Avoiding DEACT for UE %d because of LAA Cell !!!!!!!!!!!!! \n",
850          sCellInfo->ue->ueId);
851       }
852
853    }
854    else
855    {
856       /* Deactivation Timer is configured, thus assume that UE has deactivated */ 
857       rgSCHSCellDeActivation(sCellInfo);
858    }
859    return;
860 }
861 #endif
862 \f
863 /**
864  * @brief This function handles the action of the SCell
865  *
866  * @details
867  *
868  *     Function: rgSCHSCellTrigActDeact
869  *     Purpose :  
870  *        1) Prepares SCELL ready for activation OR
871  *        2) Initiates activation of SCELL OR
872  *        3) Initiate deactivation of SCELL OR
873  *
874  *     Invoked by:Cfg/Commn Scheduler 
875  *
876  *  @param[in]  RgSchCellCb *cellCb
877  *  @param[in]  RgSchUeCb   *ueCb
878  *  @param[in]  uint8_t           sCellIdx
879  *  @param[in]  uint8_t           action
880  *
881  *  @return  ROK/RFAILED
882  *
883  **/
884 #ifdef ANSI
885 S16 rgSCHSCellTrigActDeact
886 (
887 RgSchCellCb  *cell,
888 RgSchUeCb    *ueCb,
889 uint8_t            sCellIdx,
890 uint8_t            action
891 )
892 #else
893 S16 rgSCHSCellTrigActDeact(cell,ueCb,sCellIdx,action)
894 RgSchCellCb  *cell,
895 RgSchUeCb    *ueCb;
896 uint8_t            sCellIdx;
897 uint8_t            action;
898 #endif
899 {
900    Inst inst = cell->instIdx;
901    S16 ret   = ROK;
902
903    if((sCellIdx < 1) ||
904       (sCellIdx > RGR_MAX_SCELL_PER_UE))
905    {
906       RGSCHDBGERRNEW(inst, (rgSchPBuf(inst),"Invalid Serv Cell Idx %d\n", \
907                sCellIdx));
908       return RFAILED;
909    }
910
911    if(ueCb->cellInfo[sCellIdx] == NULLP)
912    {
913       RGSCHDBGERRNEW(inst, (rgSchPBuf(inst),"Serv Cell not added to this Ue Scell Idx %d ueId %d\n", \
914               sCellIdx,ueCb->ueId));
915       return RFAILED;
916    }
917
918    switch (action)
919    {
920       case RGR_SCELL_READY:
921       {
922          if(ueCb->cellInfo[sCellIdx]->sCellState != RG_SCH_SCELL_INACTIVE)
923          {
924             RGSCHDBGERRNEW(inst, (rgSchPBuf(inst),"Invalid state %u for preparing SCell Idx %u for UE %u\n", \
925                      ueCb->cellInfo[sCellIdx]->sCellState, sCellIdx, ueCb->ueId));
926             ret = RFAILED;
927          }
928          else
929          {
930             ueCb->cellInfo[sCellIdx]->sCellState = RG_SCH_SCELL_READY;
931             //TODO_SID Activating the cell directly. Ignoring the ActCe procedure.
932             rgSCHSCellActivation(ueCb->cellInfo[sCellIdx]);
933             /* Setting allocCmnUlPdcch flag to FALSE, So that PDCCH allocation will be done 
934                from UE Searchspace */
935             ueCb->allocCmnUlPdcch = FALSE;
936             printf("\n***** SCellIdx=%d state Changed to %d State \n",sCellIdx, ueCb->cellInfo[sCellIdx]->sCellState);
937             printf("\n***** SCellInfo Addr=%p state Changed to RG_SCH_SCELL_READY\n",(void*)ueCb->cellInfo[sCellIdx]);
938          }
939          break;
940       }
941       case RGR_SCELL_ACT:
942       {
943          if(ueCb->cellInfo[sCellIdx]->sCellState != RG_SCH_SCELL_READY)
944          {
945             RGSCHDBGERRNEW(inst, (rgSchPBuf(inst),"Invalid state %u for activating SCell Idx %u for UE %u\n", \
946                      ueCb->cellInfo[sCellIdx]->sCellState, sCellIdx, ueCb->ueId));
947             ret = RFAILED;
948          }
949          else
950          {
951             ueCb->cellInfo[sCellIdx]->sCellState = RG_SCH_SCELL_TOBE_ACTIVATED;
952             if (NULLP == ueCb->sCellActLnk.node)
953             {
954                /* Add only if UE is not already present in the activation/deactivation list */
955                rgSCHSCellAddToActDeactLst(cell,ueCb);
956             }
957          }
958          break;
959       }
960       case RGR_SCELL_DEACT:
961       {
962          if(ueCb->cellInfo[sCellIdx]->sCellState != RG_SCH_SCELL_ACTIVE)
963          {
964             RGSCHDBGERRNEW(inst, (rgSchPBuf(inst),"Invalid state %u for deactivating SCell Idx %u for UE %u\n", \
965                      ueCb->cellInfo[sCellIdx]->sCellState, sCellIdx, ueCb->ueId));
966             ret = RFAILED;
967          }
968          else
969          {
970             ueCb->cellInfo[sCellIdx]->sCellState = RG_SCH_SCELL_TOBE_DEACTIVATED;
971             if (NULLP == ueCb->sCellActLnk.node)
972             {
973                /* Add only if UE is not already present in the activation/deactivation list */
974                rgSCHSCellAddToActDeactLst(cell,ueCb);
975             }
976          }
977          break;
978       }
979       default:
980       {
981          RGSCHDBGERRNEW(inst, (rgSchPBuf(inst),"Invalid action received for SCell Idx %u for UE %u\n", \
982                   sCellIdx, ueCb->ueId));
983          ret = RFAILED;
984          break;
985       }
986    }
987    return (ret);
988 }
989
990  \f
991 /**
992  * @brief SCell Activation of selected cell
993  *
994  * @details
995  *
996  *     Function: rgSCHSCellSelectForAct
997  *     Purpose :  Perform Selection of secondary cell for activation
998  *
999  *     Invoked by:Cfg/Commn Scheduler 
1000  *
1001  *  @param[in]  RgSchCellCb *cellCb
1002  *  @param[in]  RgSchUeCb   *ueCb
1003  *
1004  *  @return  ROK/RFAILED
1005  *
1006  **/
1007 #ifdef ANSI
1008 static S16 rgSCHSCellSelectForAct
1009 (
1010 RgSchCellCb  *cell,
1011 RgSchUeCb    *ueCb,
1012 uint8_t           *sCellIdx
1013 )
1014 #else
1015 static S16 rgSCHSCellSelectForAct(cell, ueCb)
1016 RgSchCellCb  *cell;
1017 RgSchUeCb    *ueCb;
1018 uint8_t           *sCellIdx;
1019 #endif
1020 {
1021
1022    for((*sCellIdx) = 1; (*sCellIdx) <= RG_SCH_MAX_SCELL; (*sCellIdx)++)
1023    {
1024       if((ueCb->cellInfo[(*sCellIdx)] != NULLP) &&
1025             (ueCb->cellInfo[(*sCellIdx)]->sCellState == RG_SCH_SCELL_READY))
1026       {
1027          return ROK;
1028       }
1029    }
1030    return RFAILED;
1031 }
1032
1033 /**
1034  * @brief SCell Activation of selected cell
1035  *
1036  * @details
1037  *
1038  *     Function: rgSCHSCellSelectAndActDeAct
1039  *     Purpose :  Perform Selection and Activation/Deactivation of secondary cell
1040  *
1041  *     Invoked by:Cfg/Commn Scheduler 
1042  *
1043  *  @param[in]  RgSchCellCb *cellCb
1044  *  @param[in]  RgSchUeCb   *ueCb
1045  *  @param[in]  uint8_t          action
1046  *
1047  *  @return  Void
1048  *
1049  **/
1050 #ifdef ANSI
1051 Void rgSCHSCellSelectAndActDeAct
1052 (
1053 RgSchCellCb  *pCell,
1054 RgSchUeCb    *ueCb,
1055 uint8_t           action
1056 )
1057 #else
1058 Void rgSCHSCellSelectAndActDeAct(pCell, ueCb, action)
1059 RgSchCellCb  *pCell;
1060 RgSchUeCb    *ueCb;
1061 uint8_t           action;
1062 #endif
1063 {
1064    uint8_t  sCellIdx = 0;
1065    S16 ret = ROK;
1066
1067    switch (action)
1068    {
1069       case RGR_SCELL_ACT:
1070          {
1071
1072             if(((ret = rgSCHSCellSelectForAct(pCell, ueCb, &sCellIdx)) == ROK)
1073                   && (sCellIdx == 0))
1074                return;
1075             break;
1076          }
1077          default:
1078          return;
1079    }
1080    if ((ret != ROK) || 
1081          (ROK != (rgSCHSCellTrigActDeact(pCell, ueCb, sCellIdx, action))))
1082    {
1083       RGSCHDBGERR(pCell->instIdx,(rgSchPBuf(pCell->instIdx), "SCell Actication failed"
1084                "for UE [%d] with SCellIdx [%d]\n", ueCb->ueId, sCellIdx));
1085    }
1086    return;
1087 }
1088
1089  \f
1090 /**
1091  * @brief Handling of Scell Deletion 
1092  *
1093  * @details
1094  *
1095  *     Function: rgSCHSCellDelUeSCell
1096  *     Purpose : Perform Scell Deletion for an UE
1097  *             : flush harqEnttiy of the given scell associated
1098  *               with this UE
1099  *              
1100  *
1101  *     Invoked by:Cfg module 
1102  *
1103  *  @param[in]  RgSchCellCb  *cellCb
1104  *  @param[in]  RgSchUeCb    *ueCb
1105  *  @param[in]  uint8_t            idx
1106  *  @return  ROK/RFAILED
1107  *
1108  **/
1109 #ifdef ANSI
1110 Void rgSCHSCellDelUeSCell
1111 (
1112 RgSchCellCb  *cellCb,
1113 RgSchUeCb    *ueCb,
1114 uint8_t            sCellIdx
1115 )
1116 #else
1117 Void rgSCHSCellDelUeSCell(cellCb,ueCb,sCellIdx)
1118 RgSchCellCb  *cellCb;
1119 RgSchUeCb    *ueCb;
1120 uint8_t            sCellIdx;
1121 #endif
1122 {
1123    RgUeUlHqCb       *ulHqEnt;
1124    Inst inst = cellCb->instIdx;
1125    RgSchUeCellInfo *sCellInfo;
1126    RgSchCmnUlUe *ueUl;
1127
1128    sCellInfo = ueCb->cellInfo[sCellIdx];
1129
1130
1131    if(sCellInfo == NULLP)
1132    {
1133       RGSCHDBGERRNEW(inst, (rgSchPBuf(inst),"Serv Cell not added to this Ue Scell Idx %d\
1134                ueId %d\n",
1135                sCellIdx,ueCb->ueId));
1136       return;
1137    }
1138
1139    rgSCHDbmDelUeCb(sCellInfo->cell, ueCb);
1140    ueUl = RG_SCH_CMN_GET_UL_UE(ueCb, sCellInfo->cell);
1141
1142    if (NULLP != sCellInfo->sCellLnk.node)
1143    {
1144       cmLListDelFrm(&sCellInfo->cell->sCellUeLst, &sCellInfo->sCellLnk);
1145    }
1146
1147    /* Clear Scheduler specific list for this UE from the 
1148     * corresponding CELL */
1149
1150    /*Updating 1BCS Value*/
1151    ueCb->f1bCsAVal = (ueCb->f1bCsAVal - 
1152          rgSCHUtlGetMaxTbSupp(sCellInfo->txMode.txModeEnum));
1153
1154 #ifdef LTE_TDD
1155    rgSCHUtlDelUeANFdbkInfo(ueCb,sCellIdx);
1156 #endif
1157
1158    rgSCHSCellDeActivation(sCellInfo);
1159    /* Release hqEnt mem */
1160    rgSCHDhmDelHqEnt(cellCb, &sCellInfo->hqEnt);
1161
1162    ulHqEnt = &(ueUl->hqEnt);
1163
1164    cellCb->sc.apis->rgSCHRgrSCellUeDel(sCellInfo, sCellInfo->ue);
1165
1166    rgSCHUhmFreeUe(sCellInfo->cell, ulHqEnt);
1167
1168    rgSCHUtlFreeSBuf(cellCb->instIdx,
1169          (Data**)(&(sCellInfo)), (sizeof(RgSchUeCellInfo)));
1170
1171    ueCb->cellInfo[sCellIdx] = NULLP;
1172    
1173    return;
1174 }
1175 \f
1176 /**
1177  * @brief Handling of UE Deletion
1178  *
1179  * @details
1180  *
1181  *     Function: rgSCHSCellDelUe
1182  *     Purpose : Perform UE Deletion
1183  *             : Delete all the SCells added for this UE
1184  *             : flush harqEnttiy of all scells associated
1185  *               with this UE
1186  *              
1187  *
1188  *     Invoked by:Cfg module 
1189  *
1190  *  @param[in]  RgSchCellCb  *cellCb
1191  *  @param[in]  RgSchUeCb    *ueCb
1192  *  @return  ROK/RFAILED
1193  *
1194  **/
1195 #ifdef ANSI
1196 S16 rgSCHSCellDelUe
1197 (
1198 RgSchCellCb  *cellCb,
1199 RgSchUeCb    *ueCb
1200 )
1201 #else
1202 S16 rgSCHSCellDelUe(cellCb,ueCb)
1203 RgSchCellCb  *cellCb;
1204 RgSchUeCb    *ueCb;
1205 #endif
1206 {
1207
1208
1209    for(uint8_t idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
1210    {
1211       rgSCHSCellDelUeSCell(cellCb,ueCb,idx);
1212    }
1213
1214    return ROK;
1215 }
1216
1217 #ifdef TFU_UPGRADE
1218 \f
1219 /**
1220  * @brief Handling of PCqi cfg fro a scell
1221  *
1222  * @details
1223  *
1224  *     Function: rgSCHSCellPCqiCfg
1225  *     Purpose : 
1226  *             : Delete all the SCells added for this UE
1227  *             : flush harqEnttiy of all scells associated
1228  *               with this UE
1229  *    Processing Steps:
1230  *             - For SCell-specific Periodic CQI  related configuration, 
1231  *             - If Periodic CQI/PMI is configured,
1232  *                   - Update SCell with the configured values.
1233  *                   - Update the CQI offset and CQI perodicity information
1234  *        
1235  *
1236  *     - For SCell-specific Periodic RI  related configuration, 
1237  *      - If Periodic RI is configured,
1238  *        - Update SCell with the configured values.
1239  *         - Update the  RI offset and RI perodicity information
1240  *      
1241  *
1242  *     Invoked by:Cfg module 
1243  *
1244  *  @param[in]  RgSchCellCb  *cellCb
1245  *  @param[in]  RgSchUeCb    *ueCb
1246  *  @return  ROK/RFAILED
1247  *
1248  **/
1249 #ifdef ANSI
1250 S16 rgSCHSCellPCqiCfg
1251 (
1252 RgSchCellCb  *priCellCb,
1253 RgSchCellCb  *secCellCb,
1254 RgSchUeCb    *ueCb,
1255 RgrUePrdDlCqiCfg  *cqiCfg,
1256 CmLteUeCategory   ueCat,
1257 uint8_t            sCellIdx
1258 )
1259 #else
1260 S16 rgSCHSCellPCqiCfg(priCellCb,secCellCb,ueCb,cqiCfg,ueCat,sCellIdx)
1261 RgSchCellCb       *priCellCb;
1262 RgSchCellCb       *secCellCb;
1263 RgSchUeCb         *ueCb;
1264 RgrUePrdDlCqiCfg  *cqiCfg;
1265 CmLteUeCategory    ueCat;
1266 uint8_t                sCellIdx;
1267 #endif
1268 {
1269    uint8_t     j;  /*Bandwidth Parts*/
1270    uint8_t     temp; 
1271 #ifdef DEBUGP
1272    Inst   inst = priCellCb->instIdx;
1273 #endif
1274    RgSchUeCellInfo *sCellInfo;
1275    RgSchUePCqiCb *cqiCb = NULLP;
1276
1277    RGSCHDBGINFO(priCellCb->instIdx, (rgSchPBuf(priCellCb->instIdx), 
1278             "rgSCHSCellPCqiCfg cellId =%d, ueId = %d, CfgType =%d\n",
1279             secCellCb->cellId,  ueCb->ueId, cqiCfg->type));
1280    
1281    if((sCellIdx < 1) ||
1282       (sCellIdx > RGR_MAX_SCELL_PER_UE))
1283    {
1284       RGSCHDBGERRNEW(inst, (rgSchPBuf(inst),"Invalid Serv Cell Idx %d\n",
1285                sCellIdx));
1286       return RFAILED;
1287    }
1288
1289    sCellInfo = ueCb->cellInfo[sCellIdx];
1290
1291    cqiCb = &ueCb->cellInfo[sCellIdx]->cqiCb;
1292    cqiCb->servCellInfo = sCellInfo;
1293
1294    /* Periodic CQI is setup  */
1295    if (cqiCfg->type == RGR_SCH_PCQI_SETUP)
1296    {   
1297       /*  1. Copy the Received CQI Cfg parameters to ueCb  */
1298       memcpy(&cqiCb->cqiCfg, cqiCfg, 
1299             sizeof(RgrUePrdDlCqiCfg));
1300
1301       /*  2. Compute Periodic CQI Periodicity and subframe offset   */
1302 #ifndef LTE_TDD           
1303       rgSCHUtlGetCfgPerOff(RG_SCH_FDD_PCQI_TBL, cqiCfg->cqiSetup.cqiPCfgIdx,
1304             &cqiCb->cqiPeri, &cqiCb->cqiOffset);      
1305 #else
1306       rgSCHUtlGetCfgPerOff( RG_SCH_TDD_PCQI_TBL, 
1307             cqiCfg->cqiSetup.cqiPCfgIdx,
1308             &cqiCb->cqiPeri, &cqiCb->cqiOffset);    
1309 #endif
1310
1311
1312       RGSCHDBGINFO(priCellCb->instIdx,(rgSchPBuf(priCellCb->instIdx), 
1313                "\n rgSCHSCellPCqiCfg(): CQI Peri=%d, CQI Offset=%d", 
1314                cqiCb->cqiPeri,cqiCb->cqiOffset));
1315
1316       if(RGR_UE_PCQI_SB_REP == cqiCfg->cqiSetup.cqiRepType)
1317       {
1318          uint8_t     k;  /*SubBand Size (RB) */
1319          RG_SCH_GET_CQI_J_VAL(secCellCb->bwCfg.dlTotalBw, j);
1320          RG_SCH_GET_CQI_K_VAL(secCellCb->bwCfg.dlTotalBw, k);
1321          cqiCb->J = j; /*Number of Bandwidth Parts*/
1322          /*h: reporting instances required for a complete CQI/PMI report */
1323          /*j:Number of bandwidth parts; k: Subband Size*/
1324          cqiCb->h = (cqiCb->cqiCfg.cqiSetup.k *j )+1; 
1325          /* ccpu00140905- L-size is coming as 3 for 100Rbs where it should be 2*/
1326          temp = RGSCH_CEIL(secCellCb->bwCfg.dlTotalBw, (j*k));
1327          cqiCb->label = (temp & (temp-1)) ?
1328             (1+ rgSCHUtlLog32bitNbase2(temp)) : rgSCHUtlLog32bitNbase2(temp);
1329       }
1330       else
1331       {
1332          /* Wideband Cqi Rep Type */
1333          cqiCb->prioLvl = RG_SCH_CQI_PRIO_LVL_1;
1334       }
1335       cqiCb->cqiLstEnt.node=(PTR)cqiCb;
1336       cqiCb->isCqiIgnoByCollsn = FALSE;
1337
1338
1339       /* 4. Rank Indicator Cfg handler */
1340       /* 1. Rank Indicator is enabled  */
1341       if(cqiCfg->cqiSetup.riEna)
1342       {
1343          rgSCHUtlGetCfgPerOff(RG_SCH_RI_TBL, 
1344                cqiCfg->cqiSetup.riCfgIdx,
1345                &cqiCb->riPeri, &cqiCb->riOffset);
1346
1347          RGSCHDBGINFO(priCellCb->instIdx,(rgSchPBuf(priCellCb->instIdx),
1348                   "\n rgSCHSCellPCqiCfg(): RI Peri=%d, RI Offset=%d", 
1349                   cqiCb->riPeri,cqiCb->riOffset));
1350
1351          if(ueCb->cellInfo[sCellIdx]->txMode.txModeEnum == RGR_UE_TM_3 
1352                || ueCb->cellInfo[sCellIdx]->txMode.txModeEnum == RGR_UE_TM_4)
1353          {
1354             if (secCellCb->numTxAntPorts ==2)
1355             {
1356                cqiCb->riNumBits = 1;
1357             }
1358             else if(secCellCb->numTxAntPorts ==4)
1359             {
1360                if(ueCat == CM_LTE_UE_CAT_8)
1361                {
1362                   cqiCb->riNumBits = 3;
1363                }
1364                else if((ueCat == CM_LTE_UE_CAT_5) || 
1365                      (ueCat == CM_LTE_UE_CAT_6) || CM_LTE_UE_CAT_7)
1366                {
1367                   cqiCb->riNumBits = 2;
1368                }
1369                else
1370                {
1371                   cqiCb->riNumBits = 1;
1372                }
1373             }
1374          }
1375          cqiCb->riLstEnt.node=(PTR) cqiCb;
1376          cqiCb->isRiIgnoByCollsn = FALSE;
1377
1378       }
1379    }
1380    else
1381    {
1382       sCellInfo->cqiCb.cqiCfg.type =  RGR_SCH_PCQI_REL;
1383    }
1384    /* Setting the indices to invalid during
1385       scell addition. These indices will be set during 
1386       activation */
1387    cqiCb->nRiTrIdx  = RG_SCH_INVALID_IDX;
1388    cqiCb->riDist    = RG_SCH_INVALID_IDX; 
1389    cqiCb->nCqiTrIdx = RG_SCH_INVALID_IDX;
1390  
1391    return ROK;
1392 }
1393 #endif
1394
1395 /**
1396  * @brief Handling of Ue Reset from common scheduler
1397  *
1398  * @details
1399  *
1400  *     Function: rgSCHSCellDlUeReset
1401  *     Purpose:  Call scheudler type spcefic UE RESET
1402  *               for all the secondary cells
1403  *
1404  *     Invoked by: CommonScheduler
1405  *
1406  *  @param[in]  RgSchCellCb*     cell
1407  *  @param[in]  RgSchUeCb*       ue
1408  *  @return  Void
1409  *
1410  **/
1411 #ifdef ANSI
1412 Void rgSCHSCellDlUeReset
1413 (
1414 RgSchCellCb                *cell,
1415 RgSchUeCb                  *ue
1416 )
1417 #else
1418 Void rgSCHSCellDlUeReset(cell, ue)
1419 RgSchCellCb                *cell;
1420 RgSchUeCb                  *ue;
1421 #endif
1422 {
1423    RgSchCmnCell *cellSch;
1424
1425    for(uint8_t idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
1426    {
1427       if(ue->cellInfo[idx] != NULLP) 
1428       {
1429          cellSch = RG_SCH_CMN_GET_CELL(ue->cellInfo[idx]->cell);
1430          cellSch->apisDl->rgSCHDlUeReset(ue->cellInfo[idx]->cell, ue);
1431          rgSCHSCellDeActivation(ue->cellInfo[idx]);
1432          ue->cellInfo[idx]->sCellState = RG_SCH_SCELL_INACTIVE;
1433       }
1434    }
1435    return;
1436 }
1437
1438
1439 /**
1440  * @brief Handling of LC Cfg from common scheduler
1441  *
1442  * @details
1443  *
1444  *     Function: rgSCHSCellDlLcCfg
1445  *     Purpose:  Call scheudler type spcefic LC config
1446  *               for all the secondary cells
1447  *
1448  *     Invoked by: CommonScheduler
1449  *
1450  *  @param[in]  RgSchCellCb*     cell
1451  *  @param[in]  RgSchUeCb*       ue
1452  *  @return  Void
1453  *
1454  **/
1455 #ifdef ANSI
1456 Void rgSCHSCellDlLcCfg
1457 (
1458 RgSchCellCb                *cell,
1459 RgSchUeCb                  *ue,
1460 RgSchDlLcCb                *svc
1461 )
1462 #else
1463 Void rgSCHSCellDlLcCfg(cell, ue, svc)
1464 RgSchCellCb                *cell;
1465 RgSchUeCb                  *ue;
1466 RgSchDlLcCb                *svc;
1467 #endif
1468 {
1469    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
1470    for(uint8_t idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
1471    {
1472       if(ue->cellInfo[idx] != NULLP) 
1473       {
1474          cellSch->apisDl->rgSCHRgrDlLcCfg(ue->cellInfo[idx]->cell, ue, svc,NULLP,NULLP);
1475       }
1476    }
1477    return;
1478 }
1479
1480 /**
1481  * @brief Handling of LC Delete from common scheduler
1482  *
1483  * @details
1484  *
1485  *     Function: rgSCHSCellDlLcDel
1486  *     Purpose:  Call scheudler type spcefic bo update handler
1487  *               for all the secondary cells
1488  *
1489  *     Invoked by: CommonScheduler
1490  *
1491  *  @param[in]  RgSchCellCb*     cell
1492  *  @param[in]  RgSchUeCb*       ue
1493  *  @return  Void
1494  *
1495  **/
1496 #ifdef ANSI
1497 Void rgSCHSCellDlLcDel
1498 (
1499 RgSchCellCb                *cell,
1500 RgSchUeCb                  *ue,
1501 RgSchDlLcCb                *svc
1502 )
1503 #else
1504 Void rgSCHSCellDlLcDel(cell, ue, svc)
1505 RgSchCellCb                *cell;
1506 RgSchUeCb                  *ue;
1507 RgSchDlLcCb                *svc;
1508 #endif
1509 {
1510    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
1511    for(uint8_t idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
1512    {
1513       if(ue->cellInfo[idx] != NULLP) 
1514       {
1515          cellSch->apisDl->rgSCHFreeDlLc(ue->cellInfo[idx]->cell, ue, svc);
1516       }
1517    }
1518    return;
1519 }
1520
1521 /**
1522  * @brief Handling of Bo update from common scheduler
1523  *
1524  * @details
1525  *
1526  *     Function: rgSCHSCellDlDedBoUpd
1527  *     Purpose:  Call scheudler type spcefic bo update handler
1528  *               for all the secondary cells
1529  *
1530  *     Invoked by: CommonScheduler
1531  *
1532  *  @param[in]  RgSchCellCb*     cell
1533  *  @param[in]  RgSchUeCb*       ue
1534  *  @return  Void
1535  *
1536  **/
1537 #ifdef ANSI
1538 Void rgSCHSCellDlDedBoUpd
1539 (
1540 RgSchCellCb                *cell,
1541 RgSchUeCb                  *ue,
1542 RgSchDlLcCb                *svc
1543 )
1544 #else
1545 Void rgSCHSCellDlDedBoUpd(cell, ue, svc)
1546 RgSchCellCb                *cell;
1547 RgSchUeCb                  *ue;
1548 RgSchDlLcCb                *svc;
1549 #endif
1550 {
1551    RgSchCmnCell *cellSch = RG_SCH_CMN_GET_CELL(cell);
1552
1553    /* If this is not invoked by PCell, then
1554       invoke the call to PCell handler 
1555       This happens during finalization if LC Bo becomes zero*/
1556    if (ue->cell != cell)
1557    {
1558       cellSch->apisDl->rgSCHDlDedBoUpd(ue->cell, ue, svc);
1559    }
1560    for(uint8_t idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
1561    {
1562       if((ue->cellInfo[idx] != NULLP) &&
1563             (ue->cellInfo[idx]->sCellState == RG_SCH_SCELL_ACTIVE) &&
1564            (ue->cellInfo[idx]->cell != cell))
1565       {
1566          cellSch->apisDl->rgSCHDlDedBoUpd(ue->cellInfo[idx]->cell, ue, svc);
1567       }
1568    }
1569    return;
1570 }
1571 #ifdef TFU_UPGRADE
1572 /**
1573  * @brief Compare two CQI CB configs are return the result
1574  *
1575  * @details
1576  *
1577  *     Function: rgSCHUtlSCellCmpCqiCfg
1578  *     Purpose : Compare priority levels of cqiCb1 and cqiCb2
1579  *               and set the isCqiIgnoByCollsn to TRUE for the 
1580  *               cqiCb which has lower priority 
1581  *     Invoked by:scell module 
1582  *
1583  *  @param[in] RgSchUePCqiCb *cqiCb1
1584  *  @param[in] RgSchUePCqiCb *cqiCb2
1585  *  @return uint8_t cqiCb cell idx which has the higher priority
1586  *
1587  **/
1588 #ifdef ANSI
1589 static uint8_t  rgSCHUtlSCellCmpCqiCfg
1590 (
1591 RgSchUePCqiCb *cqiCb1,
1592 RgSchUePCqiCb *cqiCb2
1593 )
1594 #else
1595 static uint8_t  rgSCHUtlSCellCmpCqiCfg(cqiCb1, cqiCb2)
1596 RgSchUePCqiCb     *cqiCb1;
1597 RgSchUePCqiCb     *cqiCb2;
1598 #endif
1599 {
1600    RgSchUePCqiCb     *retCqiCb;
1601    /* Collision rules are defined in TS 36.213,7.2.2 */
1602    /* RI, WB first PMI > WB CQI >  SB CQI */
1603    /* As of now only taking care of RI > WB CQI > SB CQI */
1604
1605    if (cqiCb1->prioLvl > cqiCb2->prioLvl)
1606    {
1607       cqiCb2->isCqiIgnoByCollsn = TRUE;
1608       cqiCb1->isCqiIgnoByCollsn = FALSE;
1609       retCqiCb = cqiCb1;
1610    }
1611    else if (cqiCb2->prioLvl > cqiCb1->prioLvl)
1612    {
1613       cqiCb1->isCqiIgnoByCollsn = TRUE;
1614       cqiCb2->isCqiIgnoByCollsn = FALSE;
1615       retCqiCb = cqiCb2;
1616    }
1617    else
1618    {
1619       if (cqiCb1->servCellInfo->sCellIdx > cqiCb2->servCellInfo->sCellIdx)
1620       {
1621          cqiCb1->isCqiIgnoByCollsn = TRUE;
1622          cqiCb2->isCqiIgnoByCollsn = FALSE;
1623          retCqiCb = cqiCb2;
1624       }
1625       else
1626       {
1627          cqiCb2->isCqiIgnoByCollsn = TRUE;
1628          cqiCb1->isCqiIgnoByCollsn = FALSE;
1629          retCqiCb = cqiCb1;
1630       }
1631    }
1632
1633    return (retCqiCb->servCellInfo->sCellIdx);
1634 }
1635
1636 /**
1637  * @brief Handling of collision of CQI types between serving cells
1638  *
1639  * @details
1640  *
1641  *     Function: rgSCHUtlSCellHndlCqiCollsn
1642  *     Purpose : Takes care of collision clauses specified in 36.213 7.2.2 Rel 10 
1643  *               and selects next nearest cqiCb 
1644  *     Invoked by:Cfg module 
1645  *
1646  *  @param[in]  RgSchCellCb  *cellCb
1647  *  @param[in]  RgSchUeCb    *ueCb
1648  *  @return  ROK/RFAILED
1649  *
1650  **/
1651 #ifdef ANSI
1652 S16 rgSCHUtlSCellHndlCqiCollsn
1653 (
1654 RgSchUePCqiCb *cqiCb
1655 )
1656 #else
1657 S16 rgSCHUtlSCellHndlCqiCollsn(cqiCb)
1658 RgSchUePCqiCb     *cqiCb;
1659 #endif
1660 {
1661    uint32_t nPCqiServCellIdx;
1662    uint32_t minPCqiTrIdx;
1663    uint32_t scellPCqiTrIdx;
1664    uint32_t pCqiTrIdx;
1665    RgSchCellCb       *priCellCb = cqiCb->servCellInfo->ue->cell;
1666    RgSchUeCb         *ueCb = cqiCb->servCellInfo->ue;
1667    uint16_t crntSfIdx;
1668    uint32_t cellIdx;
1669    uint32_t sCellCnt = 0;
1670    CmLteTimingInfo timingInfo;
1671    uint8_t idx = 0;
1672
1673 #ifdef xLTE_TDD
1674    RG_SCH_ADD_TO_CRNT_TIME(priCellCb->crntTime, timingInfo, TFU_DELTA);
1675 #else
1676    RG_SCH_ADD_TO_CRNT_TIME(priCellCb->crntTime, timingInfo,
1677          TFU_RECPREQ_DLDELTA);
1678 #endif
1679
1680    RG_SCH_GET_IDX_PCQISRSSR(timingInfo, crntSfIdx);
1681
1682    cqiCb->isCqiIgnoByCollsn = FALSE;
1683
1684    pCqiTrIdx = cqiCb->nCqiTrIdx;
1685    nPCqiServCellIdx = cqiCb->servCellInfo->sCellIdx;
1686    /* Handle wrap around case */
1687    if (pCqiTrIdx < crntSfIdx)
1688    {
1689       pCqiTrIdx += RG_SCH_PCQI_SRS_SR_TRINS_SIZE;
1690    }
1691    minPCqiTrIdx = pCqiTrIdx;
1692
1693    for (cellIdx =0; cellIdx <= RG_SCH_MAX_SCELL; cellIdx++)
1694    {
1695       /* If a serving cell is configured */
1696       if(ueCb->cellInfo[cellIdx] != NULLP)
1697       {
1698          /* If the serving cell is in ACTIVE state and 
1699             If it is not the same serving cell as cqiCb for which 
1700             collision is being checked */
1701          if ((ueCb->cellInfo[cellIdx]->sCellState == RG_SCH_SCELL_ACTIVE)&&
1702                (cellIdx != cqiCb->servCellInfo->sCellIdx))
1703          {
1704             scellPCqiTrIdx = ueCb->cellInfo[cellIdx]->cqiCb.nCqiTrIdx;
1705
1706             /* Handle wrap around case */
1707             if (scellPCqiTrIdx < crntSfIdx)
1708             {
1709                scellPCqiTrIdx += RG_SCH_PCQI_SRS_SR_TRINS_SIZE;
1710             }
1711             
1712             /* If cqiCb->isCqiIgnoByCollsn is TRUE then a higher prio cqiCb
1713                is already found so need to compare */
1714             if ((FALSE == ueCb->cellInfo[cellIdx]->cqiCb.isCqiIgnoByCollsn) &&
1715                   (FALSE == cqiCb->isCqiIgnoByCollsn) && 
1716                   (scellPCqiTrIdx == pCqiTrIdx))
1717             {
1718                /* Handle Collision */
1719                /* set isCqiIgnoByCollsn to TRUE for low prio CQI Rep type */
1720                nPCqiServCellIdx = rgSCHUtlSCellCmpCqiCfg(&ueCb->cellInfo[cellIdx]->cqiCb,cqiCb);
1721             }
1722             else if (scellPCqiTrIdx < minPCqiTrIdx)
1723             {
1724                minPCqiTrIdx = scellPCqiTrIdx;
1725                nPCqiServCellIdx = cellIdx;
1726             }
1727          }
1728
1729          /* If all of the num of configured scells are checked then break */
1730          if (sCellCnt == ueCb->numSCells)
1731          {
1732             break;
1733          }   
1734          sCellCnt++;
1735       }
1736    }
1737
1738    /* Set the next expected Cqi into nPCqiCb */
1739    idx = ((nPCqiServCellIdx)& (CM_LTE_MAX_CELLS -1));
1740    ueCb->nPCqiCb = &ueCb->cellInfo[idx]->cqiCb;
1741
1742    return ROK;
1743 }
1744
1745
1746 /**
1747  * @brief Handling of collision of RI types between serving cells
1748  *
1749  * @details
1750  *
1751  *     Function: rgSCHUtlSCellHndlRiCollsn
1752  *     Purpose : Takes care of collision clauses specified in 36.213 7.2.2 Rel 10 
1753  *               and selects next nearest cqiCb 
1754  *     Invoked by:Cfg module 
1755  *
1756  *  @param[in]  RgSchCellCb  *cellCb
1757  *  @param[in]  RgSchUeCb    *ueCb
1758  *  @return  ROK/RFAILED
1759  *
1760  **/
1761 #ifdef ANSI
1762 S16 rgSCHUtlSCellHndlRiCollsn
1763 (
1764 RgSchUePCqiCb *cqiCb
1765 )
1766 #else
1767 S16 rgSCHUtlSCellHndlRiCollsn(cqiCb)
1768 RgSchUePCqiCb     *cqiCb;
1769 #endif
1770 {
1771    uint32_t nPRiServCellIdx;
1772    uint32_t minPRiTrIdx;
1773    uint32_t scellPRiTrIdx;
1774    uint32_t pRiTrIdx;
1775    RgSchCellCb       *priCellCb = cqiCb->servCellInfo->ue->cell;
1776    RgSchUeCb         *ueCb = cqiCb->servCellInfo->ue;
1777    uint16_t crntSfIdx;
1778    uint32_t cellIdx;
1779    uint32_t sCellCnt = 0;
1780    CmLteTimingInfo timingInfo;
1781
1782 #ifdef xLTE_TDD
1783    RG_SCH_ADD_TO_CRNT_TIME(priCellCb->crntTime, timingInfo, TFU_DELTA);
1784 #else
1785    RG_SCH_ADD_TO_CRNT_TIME(priCellCb->crntTime, timingInfo,
1786          TFU_RECPREQ_DLDELTA);
1787 #endif
1788
1789    RG_SCH_GET_IDX_PCQISRSSR(timingInfo, crntSfIdx);
1790
1791    pRiTrIdx = cqiCb->nRiTrIdx + cqiCb->riDist * RG_SCH_PCQI_SRS_SR_TRINS_SIZE;
1792
1793    /* Handle wrap around case */
1794    if (pRiTrIdx < crntSfIdx)
1795    {
1796       pRiTrIdx += RG_SCH_PCQI_SRS_SR_TRINS_SIZE;
1797    }
1798
1799    cqiCb->isRiIgnoByCollsn = FALSE;
1800    nPRiServCellIdx = cqiCb->servCellInfo->sCellIdx;
1801    minPRiTrIdx = pRiTrIdx;
1802
1803    for (cellIdx =0; cellIdx <= RG_SCH_MAX_SCELL; cellIdx++)
1804    {
1805       /* If a serving cell is configured */
1806       if(ueCb->cellInfo[cellIdx] != NULLP)
1807       {
1808          /* If the serving cell is in ACTIVE state and 
1809             If it is not the same serving cell as cqiCb for which 
1810             collision is being checked */
1811          if ((ueCb->cellInfo[cellIdx]->sCellState == RG_SCH_SCELL_ACTIVE)&&
1812                (cellIdx != cqiCb->servCellInfo->sCellIdx))
1813          {
1814             scellPRiTrIdx = ueCb->cellInfo[cellIdx]->cqiCb.nRiTrIdx + 
1815                ueCb->cellInfo[cellIdx]->cqiCb.riDist * RG_SCH_PCQI_SRS_SR_TRINS_SIZE;
1816
1817             /* Handle wrap around case */
1818             if (scellPRiTrIdx < crntSfIdx)
1819             {
1820                scellPRiTrIdx += RG_SCH_PCQI_SRS_SR_TRINS_SIZE;
1821             }
1822             
1823             /* If cqiCb->isRiIgnoByCollsn is TRUE then a higher prio cqiCb
1824                is already found so need to compare */
1825             if ((FALSE == ueCb->cellInfo[cellIdx]->cqiCb.isRiIgnoByCollsn) &&
1826                   (FALSE == cqiCb->isRiIgnoByCollsn) && 
1827                   (scellPRiTrIdx == pRiTrIdx))
1828             {
1829                /* Handle Collision */
1830                /* set isRiIgnoByCollsn to TRUE for low prio CQI Rep type */
1831                if (cqiCb->servCellInfo->sCellIdx < (ueCb->cellInfo[cellIdx]->sCellIdx))
1832                {
1833                   ueCb->cellInfo[cellIdx]->cqiCb.isRiIgnoByCollsn = TRUE;
1834                }
1835                else
1836                {
1837                   cqiCb->isRiIgnoByCollsn = TRUE;
1838                }
1839             }
1840             else if (scellPRiTrIdx < minPRiTrIdx)
1841             {
1842                minPRiTrIdx = scellPRiTrIdx;
1843                nPRiServCellIdx = cellIdx;
1844             }
1845          }
1846
1847          /* If all of the num of configured scells are checked then break */
1848          if (sCellCnt == ueCb->numSCells)
1849          {
1850             break;
1851          }   
1852          sCellCnt++;
1853       }
1854    }
1855
1856    /* Set the next expected Cqi into nPCqiCb */
1857    ueCb->nPRiCb = &ueCb->cellInfo[nPRiServCellIdx]->cqiCb;
1858
1859    return ROK;
1860 }
1861 #endif/*TFU_UPGRADE*/
1862
1863 /**
1864  * @brief Checking whethter the scell is active or not
1865  *
1866  * @details
1867  *
1868  *     Function: rgSCHSCellIsActive
1869  *     Purpose: Check the Scell is in active state or not 
1870  *              
1871  *
1872  *     Invoked by: SpecificScheduler
1873  *
1874  *  @param[in]  RgSchCellCb*     cell
1875  *  @param[in]  RgSchUeCb*       ue
1876  *  @return  Void
1877  *
1878  **/
1879 #ifdef ANSI
1880 S16 rgSCHSCellIsActive
1881 (
1882 RgSchCellCb                *cell,
1883 RgSchUeCb                  *ue
1884 )
1885 #else
1886 S16 rgSCHSCellIsActive(cell, ue)
1887 RgSchCellCb                *cell;
1888 RgSchUeCb                  *ue;
1889 #endif
1890 {
1891    S16 retVal = RFAILED;
1892
1893    for(uint8_t idx = 1; idx <= RG_SCH_MAX_SCELL ; idx++)
1894    {
1895       if((ue->cellInfo[idx] != NULLP) &&
1896          (ue->cellInfo[idx]->cell->cellId == cell->cellId)&&
1897          (ue->cellInfo[idx]->sCellState == RG_SCH_SCELL_ACTIVE)) 
1898       {
1899          retVal = ROK;
1900          break;
1901       }
1902    }
1903    return (retVal);     
1904 }
1905
1906 /**
1907  * @brief Function to check for Acell Activation Trigered.
1908  *
1909  * @details
1910  *
1911  *     Function : rgSCHIsActvReqd
1912  *       This function will check for Secondary cell activation criteria
1913  *       If met this will return TRUE else FALSE
1914  *     
1915  *  @param[in]     RgSchCellCb    *cell
1916  *  @param[in]     RgSchUeCb      *ue
1917  *  @return  BOOL
1918  *      -#  TRUE
1919  **/
1920 #ifdef ANSI
1921 Bool rgSCHIsActvReqd 
1922 (
1923 RgSchCellCb    *cell,
1924 RgSchUeCb      *ue
1925 )
1926 #else
1927 Bool rgSCHIsActvReqd(cell, ue)
1928 RgSchCellCb    *cell;
1929 RgSchUeCb      *ue
1930 #endif
1931 {
1932    /* Check if remBoCnt in this UE is greater than ZERO for sufficient number of
1933     * Scheduling TTIs. If yes then We should activate a secondary cell to handle
1934     * outstanding BO */
1935    if(ue->remBoCnt == RG_SCH_ACTIVATION_COUNT)
1936    {
1937       return (TRUE);
1938    }
1939    return (FALSE);
1940 }
1941 #endif/*LTE_ADV*/
1942
1943
1944
1945 /**********************************************************************
1946
1947          End of file
1948 **********************************************************************/