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