Moving all common header file into common_def.h file
[o-du/l2.git] / src / 5gnrmac / rg_tom.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /************************************************************************
20  
21      Name:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code for Entry point fucntions
26   
27      File:     rg_tom.c 
28   
29 **********************************************************************/
30
31 static const char* RLOG_MODULE_NAME="MAC";
32 static int RLOG_FILE_ID=237;
33 static int RLOG_MODULE_ID=4096;
34 /** @file rg_tom.c 
35 @brief This module does processing related to handling of lower interface APIs 
36 invoked by PHY towards MAC
37 */
38 /* header include files -- defines (.h) */
39 #include "common_def.h"
40 #include "du_app_mac_inf.h"
41 #include "rgu.h"           /* RGU defines */
42 #include "tfu.h"           /* RGU defines */
43 #include "lrg.h"           /* layer management defines for LTE-MAC */
44 #include "crg.h"           /* layer management defines for LTE-MAC */
45 #include "rg_sch_inf.h"           /* layer management defines for LTE-MAC */
46 #include "rg.h"            /* defines and macros for MAC */
47 #include "rg_env.h"            /* defines and macros for MAC */
48 #include "rg_err.h"            /* defines and macros for MAC */
49 #include "rgm.h"           /* layer management typedefs for MAC */
50
51 /* header/extern include files (.x) */
52 #include "crg.x"           /* CRG interface typedefs */
53 #include "rgu.x"           /* RGU types */
54 #include "tfu.x"           /* RGU types */
55 #include "lrg.x"           /* layer management typedefs for MAC */
56 #include "rg_sch_inf.x"    /* SCH interface typedefs */
57 #include "rg_prg.x"        /* PRG interface typedefs */
58 #include "rgm.x"           /* layer management typedefs for MAC */
59 #include "rg.x"            /* typedefs for MAC */
60 #include "mac.h"
61 #include "lwr_mac_fsm.h"
62 #ifdef MAC_RLC_UL_RBUF
63 #include "ss_rbuf.h"
64 #include "ss_rbuf.x"
65 #endif
66
67 uint16_t handleDlTtiReq(SlotIndInfo currTimingInfo);
68 uint16_t handleUlTtiReq(SlotIndInfo currTimingInfo);
69
70 /* ADD Changes for Downlink UE Timing Optimization */
71 #ifndef LTEMAC_DLUE_TMGOPTMZ 
72 PRIVATE S16 rgTOMUtlProcDlSf ARGS(( RgDlSf *dlSf, RgCellCb   *cellCb,
73                                     RgErrInfo  *err));
74 #else
75 PUBLIC S16 rgTOMUtlProcDlSf ARGS((RgDlSf *dlSf, RgCellCb *cellCb,
76                                   RgErrInfo  *err));
77 #endif
78 PRIVATE S16 rgTOMProcCrntiCEInDatInd ARGS((
79 RgMacPdu          *pdu,
80 RgUeCb            *prevUeCb,
81 RgCellCb          *cellCb,
82 TfuDatInfo        *datInfo,
83 RgInfCeInfo       *ceInfo,
84 U16               slot
85 ));
86
87 PRIVATE S16 rgTOMProcCCCHSduInDatInd ARGS((
88 RgMacPdu          *pdu,
89 RgUeCb            *prevUeCb,
90 RgCellCb          *cellCb,
91 TfuDatInfo        *datInfo,
92 RgInfCeInfo       *ceInfo,
93 U16               slot
94 ));
95
96 PUBLIC S16 rgHndlFlowCntrl
97 (
98 RgCellCb       *cell,
99 RgInfSfAlloc        *sfInfo
100 );
101
102 EXTERN S16 RgUiRguFlowCntrlInd(Pst* pst, SuId suId, RguFlowCntrlInd *flowCntrlInd);
103 #ifdef EMTC_ENABLE
104 EXTERN S16 rgEmtcHndl(RgCellCb *cell,RgInfSfAlloc  *sfInfo);  
105 EXTERN S16 rgTOMEmtcUtlFillDatReqPdus(TfuDatReqInfo *datInfo, RgDlSf *dlSf, RgCellCb *cell, RgErrInfo *err);  
106 EXTERN Void rgTOMEmtcRlsSf(RgDlSf *dlSf);  
107 #endif
108 #ifdef LTE_L2_MEAS
109 PRIVATE Void rgTOML2MCompileActiveLCs ARGS
110 ((
111  RgCellCb      *cellCb, 
112  RgUeCb        *ueCb,
113  RgMacPdu      *pdu,
114  RgInfCeInfo   *ceInfo 
115  ));
116 PRIVATE S16 rgTOMUtlL2MStoreBufSz ARGS
117 ((
118  RgUeCb      *ueCb,
119  RgInfCeInfo *ceInfo
120  ));
121
122 PRIVATE S16 rgTomUtlPrepareL2MUlThrpInfo ARGS
123 ((
124    RgCellCb *cellCb,
125    RgUeCb  *ueCb,
126    RgRguDedDatInd  *dDatInd
127 ));
128
129
130 /* The below table takes lower values of BSR Range for a BSR value
131      This is to ensure that outstanding can be decrease to zero upon reception of
132      TB, which is not guaranteed if higher Range values are used */
133    /* Note: taking value 10 for BSR index 1 */
134 #ifndef MAC_5GTF_UPDATE
135 PRIVATE U32 rgLwrBsrTbl[64] = {
136    0, 10, 10, 12, 14, 17, 19, 22, 26,
137    31, 36, 42, 49, 57, 67, 78, 91,
138    107, 125, 146, 171, 200, 234, 274, 321,
139    376, 440, 515, 603, 706, 826, 967, 1132,
140    1326, 1552, 1817, 2127, 2490, 2915, 3413, 3995,
141    4677, 5476, 6411, 7505, 8787, 10287, 12043, 14099,
142    16507, 19325, 22624, 26487, 31009, 36304, 42502, 49759,
143    58255, 68201, 79846, 93479, 109439, 128125, 150000
144 };
145 #else
146
147 PRIVATE U32 rgLwrBsrTbl[64] = {
148 0,10,13,16,19,23,29,35,43,53,65,80,98,120,147,181,223,274,337,414,
149 509,625,769,945,1162,1429,1757,2161,2657,3267,4017,4940,6074,7469,
150 9185,11294,13888,17077,20999,25822,31752,39045,48012,59039,72598,
151 89272,109774,134986,165989,204111,250990,308634,379519,466683,
152 573866,705666,867737,1067031,1312097,1613447,1984009,2439678,
153 3000000};
154
155 #endif
156
157 #endif
158
159 /* local defines */
160 #define RG_TOM_INF_ALLOC(_pdu, _size, _dataPtr, _ret) {\
161    _ret = cmGetMem((Ptr)&_pdu->memCp, _size, (Ptr *)&_dataPtr); \
162 }
163
164 /* global variables */
165 PUBLIC U32 rgUlrate_tfu;
166 #ifdef EMTC_ENABLE
167 EXTERN U32 grgUlrate_tfu;
168 #endif
169
170 /** @brief This function fills the PDSCH data of a downlink subframe 
171  *
172  * @details
173  *
174  *     Function: rgTOMUtlFillDatReqPdus 
175  *
176  *         Processing steps:
177  *         - Fill BCCH on DLSCH data using datInfo
178  *         - Fill PCCH on DLSCH data using datInfo
179  *         - Fill Dedicated data on DLSCH data using datInfo
180  *         - Fill RA RSP data using datInfo
181  *
182  * @param  [out] TfuDatReqInfo *datInfo 
183  * @param  [in]  RgDlSf     *dlSf
184  * @param  [in]  RgCellCb   *cellCb
185  * @param  [out] RgErrInfo *err
186  * @return  S16
187  *      -# ROK 
188  *      -# RFAILED 
189  */
190 #ifdef ANSI
191 PRIVATE S16 rgTOMUtlFillDatReqPdus 
192 (
193  TfuDatReqInfo *datInfo,
194  RgDlSf        *dlSf,
195  RgCellCb      *cellCb,
196  RgErrInfo     *err
197  )
198 #else
199 PRIVATE S16 rgTOMUtlFillDatReqPdus(datInfo, dlSf, cellCb, err)
200  TfuDatReqInfo *datInfo;
201  RgDlSf        *dlSf;
202  RgCellCb      *cellCb;
203  RgErrInfo     *err;
204 #endif
205 {
206    S16              ret;
207    TfuDatReqPduInfo *datReq=NULLP;
208  /* Moving node declaration to limited scope for optimization */
209    RgDlHqProcCb     *hqCb;
210    U8               idx;
211    Inst             inst = cellCb->macInst - RG_INST_START;
212
213    TRC2(rgTOMUtlFillDatReqPdus)
214
215       /* first lets send the BCCH data down to PHY */
216    if (dlSf->bcch.tb != NULLP)
217    {
218       if ((ret = rgGetEventMem(inst,(Ptr *)&datReq, sizeof(TfuDatReqPduInfo),
219                                 &(datInfo->memCp))) != ROK)
220       {
221          err->errCause = RGERR_TOM_MEM_EXHAUST;
222          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Memory Exhaustion ");
223          RETVALUE(ret);
224       }
225 #ifdef TFU_ALLOC_EVENT_NO_INIT
226 #ifndef L2_OPTMZ      
227       datReq->mBuf[1] = 0;
228 #else 
229      datReq->tbInfo[0].lchInfo[0].mBuf[0]=NULLP;
230 #endif
231 #endif
232       datReq->rnti                   =  RG_SI_RNTI;
233       datReq->dciInfo                =  dlSf->bcch.pdcch.dci;
234       /* Note: SCpyMsgMsg is not done since free of unsent buffer 
235        * has been taken care through cell delete by invoking rgTomRlsSf
236        * during shutdown */
237       datReq->nmbOfTBs               =  1;
238 #ifndef L2_OPTMZ
239       datReq->mBuf[0]                =  dlSf->bcch.tb;
240 #else
241       SFndLenMsg((Buffer *)dlSf->bcch.tb, &(datReq->tbInfo[0].tbSize));
242       datReq->tbInfo[0].tbPres             = TRUE;
243       datReq->tbInfo[0].lchInfo[0].mBuf[0] = dlSf->bcch.tb;
244       datReq->tbInfo[0].numLch             = 1;
245       datReq->tbInfo[0].lchInfo[0].numPdu  = 1;
246
247 #ifdef TFU_ALLOC_EVENT_NO_INIT
248       datReq->tbInfo[1].tbPres             = FALSE;
249       datReq->tbInfo[1].lchInfo[0].mBuf[0] = NULLP;
250 #endif
251 #endif
252       cmLListAdd2Tail(&datInfo->pdus, &(datReq->lnk));
253       datReq->lnk.node = (PTR)datReq;
254 #ifdef TFU_UPGRADE      
255       /* ccpu00132314-ADD- Adding txPower offset for the PDSCH transmission */
256       datReq->txPwrOffset            = dlSf->bcch.txPwrOffset;
257 #endif      
258       /* Setting the pointer to NULL post transmission */
259       dlSf->bcch.tb = NULLP;
260    }
261    /* Fill PCCH data */
262    if (dlSf->pcch.tb != NULLP)
263    {
264       if ((ret = rgGetEventMem(inst,(Ptr *)&datReq, sizeof(TfuDatReqPduInfo),
265                                 &(datInfo->memCp))) != ROK)
266       {
267          err->errCause = RGERR_TOM_MEM_EXHAUST;
268          RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"Memory Exhaustion CRNTI:%d",datReq->rnti);
269          RETVALUE(ret);
270       }
271 #ifdef TFU_ALLOC_EVENT_NO_INIT
272 #ifndef L2_OPTMZ      
273       datReq->mBuf[1] = 0;
274 #endif     
275 #endif     
276       datReq->rnti                   =  RG_P_RNTI;
277       datReq->dciInfo                = dlSf->pcch.pdcch.dci;
278       datReq->nmbOfTBs               =  1;
279 #ifndef L2_OPTMZ
280       datReq->mBuf[0]                =  dlSf->pcch.tb;
281 #else
282       SFndLenMsg((Buffer *)dlSf->pcch.tb, &datReq->tbInfo[0].tbSize);
283       datReq->tbInfo[0].tbPres             = TRUE;
284       datReq->tbInfo[0].lchInfo[0].mBuf[0] =  dlSf->pcch.tb;
285 #ifdef TFU_ALLOC_EVENT_NO_INIT
286       datReq->tbInfo[1].tbPres             = FALSE;
287       datReq->tbInfo[1].lchInfo[0].mBuf[0] = NULLP;
288 #endif
289       datReq->tbInfo[0].numLch             = 1;
290       datReq->tbInfo[0].lchInfo[0].numPdu  = 1;
291 #endif
292       cmLListAdd2Tail(&datInfo->pdus, &(datReq->lnk));
293       datReq->lnk.node = (PTR)datReq;
294 #ifdef TFU_UPGRADE      
295       /* ccpu00132314-ADD- Adding txPower offset for the PDSCH transmission */
296       datReq->txPwrOffset            = dlSf->pcch.txPwrOffset;
297 #endif      
298       dlSf->pcch.tb = NULLP;
299    }
300
301    for(idx=0; idx < dlSf->numRaRsp; idx++)
302    {
303       if ((ret = rgGetEventMem(inst,(Ptr *)&datReq, sizeof(TfuDatReqPduInfo),
304                                 &(datInfo->memCp))) != ROK)
305       {
306          err->errCause = RGERR_TOM_MEM_EXHAUST;
307          RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"Memory Exhaustion CRNTI:%d",
308                          datReq->rnti);
309          RETVALUE(ret);
310       }
311 #ifdef TFU_ALLOC_EVENT_NO_INIT
312 #ifndef L2_OPTMZ      
313       datReq->mBuf[1] = 0;
314 #endif    
315 #endif    
316       datReq->rnti                   =  dlSf->raRsp[idx].pdcch.rnti;
317       datReq->dciInfo                = dlSf->raRsp[idx].pdcch.dci;
318       datReq->nmbOfTBs               =  1;
319 #ifndef L2_OPTMZ
320       datReq->mBuf[0]                =  dlSf->raRsp[idx].rar;
321 #else
322       SFndLenMsg((Buffer *)dlSf->raRsp[idx].rar, &datReq->tbInfo[0].tbSize);
323       datReq->tbInfo[0].tbPres             = TRUE;
324       datReq->tbInfo[0].lchInfo[0].mBuf[0] =  dlSf->raRsp[idx].rar;
325 #ifdef TFU_ALLOC_EVENT_NO_INIT
326       datReq->tbInfo[1].lchInfo[0].mBuf[0] = NULLP;
327       datReq->tbInfo[1].tbPres             = FALSE;
328 #endif
329       datReq->tbInfo[0].numLch             = 1;
330       datReq->tbInfo[0].lchInfo[0].numPdu  = 1;
331    //   prc_trace_format_string(0x40,3,"UE Id=(%d) tbSz=(%d)",datReq->rnti, datReq->tbInfo[0].tbSize);
332 #endif
333       cmLListAdd2Tail(&datInfo->pdus, &(datReq->lnk));
334       datReq->lnk.node = (PTR)datReq;
335 #ifdef TFU_UPGRADE      
336       /* ccpu00132314-ADD- Adding txPower offset for the PDSCH transmission */
337       datReq->txPwrOffset            = dlSf->raRsp[idx].txPwrOffset;
338 #endif
339       dlSf->raRsp[idx].rar = NULLP;
340    }
341
342    /* Fill Dedicated UE data */
343    if (dlSf->tbs.count != 0) 
344    {
345       CmLList          *node;
346       while (dlSf->tbs.first)
347       {
348          node = dlSf->tbs.first;
349          hqCb = (RgDlHqProcCb*)node->node;
350          if ((ret = rgDHMSndDatReq (cellCb, dlSf, datInfo, hqCb, err)) != ROK)
351          {
352             RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
353                             "DHM unable to fill DATA request");
354             err->errType = RGERR_TOM_TTIIND;
355             continue;
356          }
357       } /* end of while */
358    } 
359
360    RETVALUE(ROK);
361 } /* end of rgTOMUtlFillDatReqPdus*/ 
362
363 /** @brief This function does all the processing related to a single downlink
364  * subframe.
365  *
366  * @details 
367  *
368  *     Function: rgTOMUtlProcDlSf
369  *
370  *         Processing steps:
371  *         - collate control data for all UEs and send to PHY 
372  *         - collate data buffers for all UEs and send to PHY 
373  *
374  * @param  [in] RgDlSf     *dlSf
375  * @param  [in] RgCellCb   *cellCb
376  * @param  [out] RgErrInfo *err
377  * @return S16
378  */
379 /* ADD Changes for Downlink UE Timing Optimization */
380 #ifndef LTEMAC_DLUE_TMGOPTMZ 
381 #ifdef ANSI
382 PRIVATE S16 rgTOMUtlProcDlSf
383 (
384  RgDlSf     *dlSf,
385  RgCellCb   *cellCb,
386  RgErrInfo  *err
387  )
388 #else
389 PRIVATE S16 rgTOMUtlProcDlSf (dlSf, cellCb, err)
390  RgDlSf     *dlSf;
391  RgCellCb   *cellCb;
392  RgErrInfo  *err;
393 #endif
394 #else
395 #ifdef ANSI
396 PUBLIC S16 rgTOMUtlProcDlSf
397 (
398  RgDlSf     *dlSf,
399  RgCellCb   *cellCb,
400  RgErrInfo  *err
401  )
402 #else
403 PUBLIC S16 rgTOMUtlProcDlSf (dlSf, cellCb, err)
404  RgDlSf     *dlSf;
405  RgCellCb   *cellCb;
406  RgErrInfo  *err;
407 #endif
408 #endif
409 {
410    S16               ret;
411    TfuDatReqInfo     *datInfo;
412    Inst              inst = cellCb->macInst - RG_INST_START;
413
414    TRC2(rgTOMUtlProcDlSf);
415
416    /* Fill Data Request Info from scheduler to PHY */   
417    if ((ret = rgAllocEventMem(inst,(Ptr *)&datInfo, 
418                             sizeof(TfuDatReqInfo))) != ROK)
419    {
420       RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Unable to Allocate TfuDatReqInfo");
421       RETVALUE(ret);
422    }
423    else
424    {
425       cmLListInit(&datInfo->pdus);
426 #ifdef LTE_TDD
427       RGADDTOCRNTTIME(dlSf->schdTime, datInfo->timingInfo, TFU_DELTA);
428 #else
429       RGADDTOCRNTTIME(dlSf->schdTime, datInfo->timingInfo, TFU_DLDATA_DLDELTA);
430 #endif
431       datInfo->cellId = cellCb->cellId;
432       if((0 == (datInfo->timingInfo.sfn % 30)) && (0 == datInfo->timingInfo.slot))
433       {
434          //printf("5GTF_CHECK rgTOMUtlProcDlSf dat (%d : %d)\n", datInfo->timingInfo.sfn, datInfo->timingInfo.slot);
435       }
436 #ifdef TFU_ALLOC_EVENT_NO_INIT
437       datInfo->bchDat.pres = 0;
438 #endif
439
440       /* Fill BCH data */
441       if (dlSf->bch.tb != NULLP)
442       {
443          datInfo->bchDat.pres = PRSNT_NODEF;
444          datInfo->bchDat.val  = dlSf->bch.tb;
445          dlSf->bch.tb = NULLP;
446       }
447 #ifdef EMTC_ENABLE
448       /* Fill the DLSCH PDUs of BCCH, PCCH and Dedicated Channels */
449       if ((ret = rgTOMEmtcUtlFillDatReqPdus(datInfo, dlSf, cellCb, err)) != ROK)
450       {
451          RG_FREE_MEM(datInfo);
452          RETVALUE(ret);
453       }
454 #endif 
455       /* Fill the DLSCH PDUs of BCCH, PCCH and Dedicated Channels */
456       if ((ret = rgTOMUtlFillDatReqPdus(datInfo, dlSf, cellCb, err)) != ROK)
457       {
458          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Unable to send data for cell");
459          RG_FREE_MEM(datInfo);
460          RETVALUE(ret);
461       }
462       if((datInfo->pdus.count) || (datInfo->bchDat.pres == TRUE))
463       {
464          /* sending the data to Phy */
465          if (rgLIMTfuDatReq(inst,datInfo) != ROK)
466          {
467             RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Unable to send data info for cell");               
468          }
469       }
470       else
471       {
472          /* Nothing to send: free the allocated datInfo */
473          RG_FREE_MEM(datInfo);
474       }
475    }
476    RETVALUE(ROK);
477 } /* end of */
478
479 U32  rgMacGT;
480
481 /**
482  * @brief Handler for processing TTI indication recieved from 
483  * PHY for a cell.
484  *
485  * @details
486  *
487  *     Function: macProcessSlotInd
488  *
489  *     Handler for processing slot indication recieved from PHY
490  *     for a cell.
491  *
492  *     Invoked by: macProcessSlotInd
493  *
494  *     Processing Steps:
495  *     - Get cell and update the cell's current time with the timing value given
496  *     by PHY
497  *     - Invoke the cmPrcTmr to process the timing queue.
498  *     - Append the PHICH information to the downlink subframe that needs to go
499  *       out to PHY in this subframe.
500  *     - Invoke DHM to release the downlink subframe that occured earlier
501  *     rgDHMRlsDlsfHqProc.
502  *     - Invoke the TTI handler of scheduler. 
503  *     - Invoke the TTI handler of RAM module. 
504  *     - Get the downlink subframe that has to go out to PHY in this subframe
505  *     rgSCHSubFrmGet.
506  *     - Invoke rgTOMUtlProcTA to perform and timing advance processing. 
507  *     - Invoke rgTOMUtlProcDlSf to do further processing on the downlink
508  *     subframe.
509  *     - Get the downlink subframe that would occur after RG_DL_DELTA and 
510  *     invoke rgTOMUtlProcDlSfStaInd to send status indications to the higher
511  *     layer.
512  *     - Invoke GOM's TTI handler rgGOMTtiHndlr
513  *     - Invoke COM's TTI handler rgCOMTtiHndlr
514  *           
515  *  @param[in]  Inst        inst
516  *  @param[in] SlotIndInfo slotInd
517  *  @return  S16
518  *      -# ROK 
519  *      -# RFAILED 
520  **/
521 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
522 pthread_t gMacTId = 0;
523 #endif
524 PUBLIC S16 macProcessSlotInd
525 (
526 Inst          inst,
527 SlotIndInfo slotInd
528 )
529 {
530    RgCellCb             *cellCb;
531    RgErrInfo            err;
532    RgDlSf               *dlSf;
533 /* ADD Changes for Downlink UE Timing Optimization */
534 #ifdef LTEMAC_DLUE_TMGOPTMZ
535    RgDlSf               *prevDlSf;
536    CmLteTimingInfo       prevTmInfo;  
537 #endif
538    //SlotIndInfo *slotInd = &ttiInfo->cells[0];
539
540    TRC2(macProcessSlotInd);
541
542 #ifdef MAC_FREE_RING_BUF
543    gMacTId = pthread_self();
544 #endif
545
546    cellCb = rgCb[inst].cell;
547    if (cellCb == NULLP)
548    {
549       err.errType = RGERR_TOM_TTIIND;
550       err.errCause = RGERR_TOM_INV_CELL_ID;
551       RETVALUE(RFAILED);
552    }
553
554    RGCPYTIMEINFO(slotInd, cellCb->crntTime);
555
556    rgMacGT = (slotInd.sfn * RG_NUM_SUB_FRAMES_5G) + slotInd.slot;
557 #ifdef LTE_L2_MEAS
558    rgL2Meas(cellCb);
559    /*Included to track the number of 10240 cycles completed */
560
561   if((cellCb->crntTime.sfn == 0) && (cellCb->crntTime.slot==0))
562   {
563      cellCb->ttiCycle += 1;
564   }
565
566 #endif
567
568    /*Check if we have transmitted the previous DL SF, it could be the
569      case that we haven't received all the DATA from RLC as yet
570      and thus we would not have transmitted previous DL SF yet.*/
571 /* ADD Changes for Downlink UE Timing Optimization */
572 #ifdef LTEMAC_DLUE_TMGOPTMZ
573    RGSUBFRMCRNTTIME(slotInd, prevTmInfo, 1);
574    prevDlSf = &cellCb->subFrms[(prevTmInfo.slot % RG_NUM_SUB_FRAMES)];
575    if(FALSE == prevDlSf->txDone)
576    {
577       if (ROK != rgTOMUtlProcDlSf (prevDlSf, cellCb, &err))
578       {
579          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Unable to process "
580                 "previous downlink subframe for cell");
581          err.errType = RGERR_TOM_TTIIND;
582       }
583
584       /* Mark this frame as sent */
585       prevDlSf->txDone = TRUE;
586
587       if(prevDlSf->remDatReqCnt)
588       {
589          /*We have not received 1 or more data requests from RLC, this is
590            error scenario. MAC & SCH need to discard the allocations for
591            which data request hasn't been received as yet. And MAC
592            needs to inform SCH about the list of UEs for which 
593            allocation need to be discarded. */
594          prevDlSf->remDatReqCnt = 0;
595       }
596    }
597 #endif
598
599
600    /* Trigger for DL TTI REQ */
601    handleDlTtiReq(slotInd);
602
603    /* Trigger for UL TTI REQ */
604    handleUlTtiReq(slotInd);
605
606    dlSf = &cellCb->subFrms[(slotInd.slot % RG_NUM_SUB_FRAMES)];
607
608    if((dlSf->txDone == TRUE) ||
609       (!RG_TIMEINFO_SAME(slotInd,dlSf->schdTime)))
610    {
611    /* MS_WORKAROUND */
612 #ifndef LTEMAC_DLUE_TMGOPTMZ
613       TfuDatReqInfo     *datInfo;
614      CmLteTimingInfo   timingInfo;
615 #ifdef TFU_DL_DELTA_CHANGE
616          RGADDTOCRNTTIME(cellCb->crntTime, timingInfo, TFU_DLDATA_DLDELTA);
617 #else
618          RGADDTOCRNTTIME(cellCb->crntTime, timingInfo, TFU_DELTA);
619 #endif
620      /* Fill Data Request from MAC for BCH  */
621      if ((timingInfo.sfn % 4 == 0) && (timingInfo.slot == 0))
622      {
623          if (ROK != rgAllocEventMem(inst,(Ptr *)&datInfo, 
624                             sizeof(TfuDatReqInfo)))
625          {
626             RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
627                 "rgTOMUtlProcDlSf() Unable to Allocate TfuDatReqInfo for cell");
628             RETVALUE(RFAILED);
629          }
630          else
631          {
632             cmLListInit(&datInfo->pdus);
633             datInfo->cellId = cellCb->cellId;
634             datInfo->bchDat.pres = NOTPRSNT;
635             datInfo->timingInfo = timingInfo;
636             
637                                    
638           /* sending the dummy data req to Phy */
639             if (rgLIMTfuDatReq(inst,datInfo) != ROK)
640             {
641                RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
642                          "rgTOMUtlProcDlSf() Unable to send data info for cell");
643             }
644          
645          }
646      }      
647 #endif
648       /* Freeing as the part of CL Non RT Indication */
649       /* TDOD : Generalize for all SOCs */
650 #if !(defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD))
651       rgDHMFreeTbBufs(inst);
652 #endif
653       RETVALUE(ROK);
654    }
655
656    /*Return if there is still some data to be received
657      from RLC for this DL SF. */
658 /* ADD Changes for Downlink UE Timing Optimization */
659 #ifdef LTEMAC_DLUE_TMGOPTMZ
660    if(0 != dlSf->remDatReqCnt) 
661    {
662       /* Freeing as the part of CL Non RT Indication */
663       /* TODO : Generalize for all SOCs and remove this flag */
664 #if !(defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD))
665       rgDHMFreeTbBufs(inst);
666 #endif
667       RETVALUE(ROK);
668    }
669 #endif
670
671 #ifdef XEON_SPECIFIC_CHANGES
672    CM_MEAS_TIME((slotInd.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_DL_BR_PRC);
673 #endif
674
675    if (ROK != rgTOMUtlProcDlSf (dlSf, cellCb, &err))
676    {
677       //RLOG_ARG0(L_ERROR,DBG_CELLID,slotInd->cellId,
678       //              "Unable to process downlink subframe for cell");
679       err.errType = RGERR_TOM_TTIIND;
680    }
681 #ifdef XEON_SPECIFIC_CHANGES
682    CM_MEAS_TIME((slotInd->slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_DL_AFTER_PRC);
683 #endif
684
685    /* Mark this frame as sent */
686    dlSf->txDone = TRUE;
687
688    /* Freeing as the part of CL Non RT Indication */
689    /* TODO : Generalize for all SOCs and remove this flag */
690 #if !(defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD))
691    rgDHMFreeTbBufs(inst);
692 #endif 
693    RETVALUE(ROK);
694 }  /* macProcessSlotInd */
695
696 /** @brief This function allocates the RgMacPdu that will be populated by DEMUX
697  * with the SubHeaders list and the values of the Control elements.
698  *
699  * @details
700  *
701  *     Function: rgTOMUtlAllocPduEvnt
702  *
703  *         Processing steps:
704  *  @param[in]  Inst        inst
705  * @param  [out] RgMacPdu   **pdu
706  *
707  *  @return  S16
708  *      -# ROK 
709  *      -# RFAILED 
710  */
711 #ifdef ANSI
712 PRIVATE S16 rgTOMUtlAllocPduEvnt 
713 (
714 Inst             inst,
715  RgMacPdu         **pdu
716  )
717 #else
718 PRIVATE S16 rgTOMUtlAllocPduEvnt (inst,pdu)
719 Inst             inst;
720    RgMacPdu         **pdu;
721 #endif
722 {
723
724    Mem               evntMem;
725    RgUstaDgn         dgn;      /* Alarm diagnostics structure */
726    VOLATILE U32      startTime=0;
727
728    TRC2(rgTOMUtlAllocPduEvnt);
729
730    evntMem.region = rgCb[inst].rgInit.region;
731    evntMem.pool   = rgCb[inst].rgInit.pool;
732
733    /*starting Task*/
734    SStartTask(&startTime, PID_TOMUTL_CMALLCEVT);
735
736 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
737    MS_BUF_ADD_ALLOC_CALLER();
738 #endif /* */
739
740    if (cmAllocEvnt (sizeof (RgMacPdu), RG_BLKSZ, &evntMem, (Ptr*)pdu) != ROK)
741    {
742       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
743       rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
744                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
745       RLOG0(L_ERROR,"Allocation of DUX event failed");
746       RETVALUE(RFAILED);
747    }
748
749    /*stoping Task*/
750    SStopTask(startTime, PID_TOMUTL_CMALLCEVT);
751
752    RETVALUE(ROK);
753 } /* end of */ 
754
755 /** @brief This function frees up the RgMacPdu structure that has been
756  * populated by demux.
757  *
758  * @details
759  *
760  *     Function: rgTOMUtlFreePduEvnt
761  *       - Function frees up the RgMacPdu structure, in case of error it shall
762  *       free up the buffer's present in the different sdu.
763  *
764  *         Processing steps:
765  * @param  [in]  Inst        inst
766  * @param  [in] RgMacPdu   *pdu
767  * @param  [in] Bool       *error
768  * @return 
769  */
770 #ifdef ANSI
771 PRIVATE Void rgTOMUtlFreePduEvnt
772 (
773  RgMacPdu *pdu,
774  Bool      error
775  )
776 #else
777 PRIVATE Void rgTOMUtlFreePduEvnt (pdu, error)
778    RgMacPdu *pdu;
779    Bool      error;
780 #endif
781 {
782
783    RgMacSdu       *sdu;
784    CmLList        *node;
785
786    TRC2(rgTOMUtlFreePduEvnt);
787    /* Steps of freeing up the PDU.
788     * 1. loop through the subHdrLst and free up all the buffers.
789     * 2. free up the whole event
790     */
791    if ((error == TRUE) && (pdu->sduLst.count > 0))
792    {
793       node =  pdu->sduLst.first;
794       while (node)
795       {
796          sdu = (RgMacSdu*)node->node;
797          RG_FREE_MSG(sdu->mBuf);
798          node = node->next;
799       }
800    }
801    RG_FREE_MEM(pdu);
802    RETVOID;
803 } /* end of rgTOMUtlFreePduEvnt */ 
804
805 /** @brief This function allocates the RgMacPdu that will be populated by DEMUX
806  * with the SubHeaders list and the values of the Control elements.
807  *
808  * @details
809  *
810  *     Function: rgTOMInfAllocPduEvnt
811  *
812  *         Processing steps:
813  * @param  [in] Inst        inst
814  * @param  [out] RgMacPdu   **pdu
815  *
816  *  @return  S16
817  *      -# ROK 
818  *      -# RFAILED 
819  */
820 #ifdef ANSI
821 PRIVATE S16 rgTOMInfAllocPduEvnt 
822 (
823 Inst           inst,
824 RgInfSfDatInd **sfInfo
825  )
826 #else
827 PRIVATE S16 rgTOMInfAllocPduEvnt (inst,sfInfo)
828 Inst             inst;
829 RgInfSfDatInd **sfInfo;
830 #endif
831 {
832
833    Mem               evntMem;
834    RgUstaDgn         dgn;      /* Alarm diagnostics structure */
835    VOLATILE U32      startTime=0;
836
837    TRC2(rgTOMInfAllocPduEvnt);
838
839    evntMem.region = rgCb[inst].rgInit.region;
840    evntMem.pool   = rgCb[inst].rgInit.pool;
841
842    /*starting Task*/
843    SStartTask(&startTime, PID_TOMINF_CMALLCEVT);
844
845 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
846    MS_BUF_ADD_ALLOC_CALLER();
847 #endif /* */
848    if (cmAllocEvnt (sizeof (RgInfSfDatInd), RG_BLKSZ, &evntMem, (Ptr*)sfInfo) != ROK)
849    {
850       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
851       rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
852                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
853       RLOG0(L_ERROR,"Allocation failed");
854       RETVALUE(RFAILED);
855    }
856
857    /*stoping Task*/
858    SStopTask(startTime, PID_TOMINF_CMALLCEVT);
859
860    RETVALUE(ROK);
861 } /* end of */ 
862
863 /** @brief This function frees up the RgMacPdu structure that has been
864  * populated by demux.
865  *
866  * @details
867  *
868  *     Function: rgTOMInfFreePduEvnt
869  *       - Function frees up the RgMacPdu structure, in case of error it shall
870  *       free up the buffer's present in the different sdu.
871  *
872  *         Processing steps:
873  * @param  [in] RgMacPdu   *pdu
874  * @param  [in] Bool       *error
875  * @return 
876  */
877 #ifdef ANSI
878 PRIVATE Void rgTOMInfFreePduEvnt
879 (
880 RgInfSfDatInd *sfInfo
881  )
882 #else
883 PRIVATE Void rgTOMInfFreePduEvnt (sfInfo)
884 RgInfSfDatInd *sfInfo;
885 #endif
886 {
887    TRC2(rgTOMInfFreePduEvnt);
888
889    RG_FREE_MEM(sfInfo);
890    RETVOID;
891 } /* end of rgTOMUtlFreePduEvnt */
892
893 #ifdef LTE_L2_MEAS
894
895 /** @brief This function performs the preparation of information needed to set
896  * L2M Scheduled UL Throughput Information for a particular UE.
897  *
898  * @details
899  *
900  *     Function: rgTomUtlPrepareL2MUlThrpInfo
901  *      This function performs the preparation of information needed to set
902  *       L2M Scheduled UL Throughput Information for a particular UE.
903  *
904  *
905  *         Processing steps:
906  * @param  [in] RgCellCb   *cellCb
907  * @param  [in] RgUeCb       *ueCb
908  * @param  [out] RgRguDedDatInd *dDatInd
909  * @return 
910  */
911 #ifdef ANSI
912 PRIVATE S16 rgTomUtlPrepareL2MUlThrpInfo
913 (
914    RgCellCb *cellCb,
915    RgUeCb  *ueCb,
916    RgRguDedDatInd  *dDatInd
917  )
918 #else
919 PRIVATE S16 rgTomUtlPrepareL2MUlThrpInfo(cellCb,ueCb,dDatInd)
920    RgCellCb *cellCb;
921    RgUeCb *ueCb;
922    RgRguDedDatInd    *dDatInd;
923 #endif
924 {
925    U8 lcId;
926    U8 lcgId;
927    U8 loop;
928    TRC2(rgTomUtlPrepareL2MUlThrpInfo);
929
930    dDatInd->burstInd = RGU_L2M_UL_BURST_END;
931    for(loop=0;loop<dDatInd->numLch;loop++)
932    {
933       lcId=dDatInd->lchData[loop].lcId;
934       if (lcId)
935       {
936          lcgId = ueCb->ul.lcCb[lcId - 1].lcgId;
937          if(ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs > 0)
938          {
939             dDatInd->burstInd = RGU_L2M_UL_BURST_START;
940             break;
941                   }
942                }
943    }
944
945    RETVALUE(ROK);
946 }
947
948 #endif
949
950 /** @brief This function is called by rgTOMDatInd. This function invokes the
951  * scheduler with the information of the received Data and any Control Elements
952  * if present. Also it generates Data indications towards the higher layers.
953  *
954  * @details
955  *
956  *     Function: 
957  *
958  *         Processing steps:
959  *         - Retrieves the RaCb with the rnti provided, if it doesnt exist
960  *         return failure. 
961  *         - If UE exists then update the Schduler with any MAC CEs if present. 
962  *         - Invoke RAM module to do Msg3 related processing rgRAMProcMsg3
963  *         - Loop through the SDU subheaders and invoke either a common data
964  *         indication (rgUIMSndCmnDatInd) or dedicated data indication
965  *         (rgUIMSndDedDatInd) towards the higher layers. 
966  *
967  * @param  [in] RgCellCb   *cellCb
968  * @param  [in] RgUeCb     *ueCb
969  * @param  [in] CmLteRnti  rnti
970  * @param  [in] RgMacPdu   *pdu
971  * @param  [out] U32       *lcgBytes
972  *  
973  *  @return  S16
974  *      -# ROK 
975  *      -# RFAILED 
976  */
977  RgUeCb  *glblueCb4;
978  RgUeCb  *glblueCb5;
979
980 #ifdef LTEMAC_SPS
981 #ifdef ANSI
982 PRIVATE S16 rgTOMUtlProcMsg
983 (
984  RgCellCb      *cellCb, 
985  RgUeCb        *ueCb,
986  RgMacPdu      *pdu,
987  Bool          isSpsRnti,
988  Bool          *spsToBeActvtd,
989  U16           *sduSize,
990  U16           slot,
991  U32           *lcgBytes
992  )
993 #else
994 PRIVATE S16 rgTOMUtlProcMsg(cellCb, ueCb, pdu, isSpsRnti,spsToBeActvtd,sduSize, slot, lcgBytes)
995    RgCellCb      *cellCb; 
996    RgUeCb        *ueCb;
997    RgMacPdu      *pdu;
998    Bool          isSpsRnti;
999    Bool          *spsToBeActvtd;
1000    U16           *sduSize;
1001    U16           slot;
1002    U32           *lcgBytes;
1003 #endif   
1004 #else /* LTEMAC_SPS */
1005 #ifdef ANSI
1006 PRIVATE S16 rgTOMUtlProcMsg
1007 (
1008  RgCellCb      *cellCb, 
1009  RgUeCb        *ueCb,
1010  RgMacPdu      *pdu,
1011  U16           slot,
1012  U32           *lcgBytes
1013  )
1014 #else
1015 PRIVATE S16 rgTOMUtlProcMsg(cellCb, ueCb, pdu, slot, lcgBytes)
1016    RgCellCb      *cellCb; 
1017    RgUeCb        *ueCb;
1018    RgMacPdu      *pdu;
1019    U16           slot;
1020    U32           *lcgByes;
1021 #endif  
1022 #endif
1023 {
1024    Inst              inst = cellCb->macInst - RG_INST_START;
1025    S16               ret;
1026    RgRguCmnDatInd    *cDatInd;
1027    RgRguDedDatInd    *dDatInd;
1028    CmLList           *node;
1029    RgMacSdu          *sdu;
1030    MsgLen            ccchSz;
1031    MsgLen            cpySz;
1032 #ifdef LTEMAC_SPS
1033    Pst               schPst1;  
1034 //   RgInfSpsRelInfo   relInfo;
1035 #endif
1036
1037 #ifdef LTE_L2_MEAS
1038    U8                idx1;
1039    U8                idx2;
1040    RgUlSf            *ulSf;
1041    U16               totalBytesRcvd = 0;
1042    U16               sduLen[RGU_MAX_LC] = {0};
1043    U8                qciVal[RGU_MAX_LC] = {0};
1044    U8                numPrb = 0;
1045
1046 #endif
1047    U8                lcgId;
1048    MsgLen            bufSz;
1049
1050   /* Moved outside of LTE_L2_MEAS
1051     *          scope as this pointer will now be used to 
1052     *          check for valid Logical Channel ID
1053    */
1054    RgUlLcCb          *ulLcCb;
1055    
1056    cDatInd  = NULLP;
1057    dDatInd  = NULLP;
1058 #ifdef LTE_L2_MEAS
1059    ulSf   = NULLP;
1060    idx1   = 0;
1061    idx2   = 0;
1062 #endif
1063 #ifdef SS_RBUF 
1064    Void *elem = NULLP;
1065 #endif
1066   
1067    ulLcCb = NULLP;
1068    
1069    TRC2(rgTOMUtlProcMsg)
1070
1071 #ifndef LTE_L2_MEAS      
1072       UNUSED(slot);
1073 #endif
1074
1075    if(pdu->sduLst.first)
1076    {
1077       sdu = (RgMacSdu*)(pdu->sduLst.first->node);
1078                         glblueCb4 = ueCb;
1079       if ((sdu->lcId == RG_CCCH_LCID))
1080       {
1081          /* code for common channel dat indications */
1082          if ((ret = rgAllocShrablSBuf (inst,(Data**)&cDatInd, sizeof(RgRguCmnDatInd))) != ROK)
1083          {
1084             RETVALUE(RFAILED);
1085          }
1086          cDatInd->cellId   = cellCb->cellId;
1087          cDatInd->rnti     = ueCb->ueId;
1088          /* rg001.101: Corrected lcId value for common data indication */
1089          cDatInd->lcId     = cellCb->ulCcchId;
1090          cDatInd->pdu      = sdu->mBuf;
1091          SFndLenMsg (sdu->mBuf, &ccchSz);
1092          /* Fix : syed Contention resolution ID copy should consider only
1093           * 6 bytes of information from sdu->mBuf. Incase of CCCH sdu for reest
1094           * message/psuedo reest message, ccchSz can go beyond 6 and can corrupt 
1095           * other fields of ueCb. */
1096          if (ccchSz >= RG_CRES_LEN)
1097          {
1098             SCpyMsgFix (sdu->mBuf, (MsgLen)0, RG_CRES_LEN, ueCb->contResId.resId,
1099                         &cpySz);
1100          }
1101 #ifdef XEON_SPECIFIC_CHANGES
1102          CM_LOG_DEBUG(CM_LOG_ID_MAC, "CCCH SDU of size(%d) received for UE(%d) CRES[0x%x 0x%x 0x%x 0x%x 0x%x 0x%x] Time[%d %d]\n",  ((S16)ccchSz), ueCb->ueId,ueCb->contResId.resId[0], ueCb->contResId.resId[1], ueCb->contResId.resId[2], ueCb->contResId.resId[3], ueCb->contResId.resId[4], ueCb->contResId.resId[5], cellCb->crntTime.sfn,  cellCb->crntTime.slot);
1103 #endif
1104          sdu->mBuf = NULLP;
1105          rgUIMSndCmnDatInd(inst,cellCb->rguUlSap,cDatInd);
1106          RETVALUE(ROK);
1107       } /* end of common channel processing */
1108 #ifndef SS_RBUF 
1109       if ((ret = rgAllocShrablSBuf (inst,(Data**)&dDatInd, sizeof(RgRguDedDatInd))) != ROK)
1110       {
1111          RETVALUE(RFAILED);
1112       }
1113 #else
1114                         glblueCb5 = ueCb;
1115       elem = SRngGetWIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
1116       if (NULLP == elem)
1117       { 
1118          RETVALUE(RFAILED);
1119       }
1120       dDatInd = (RgRguDedDatInd *)elem;
1121       cmMemset((U8 *)dDatInd, 0x00, sizeof(RgRguDedDatInd));
1122 #endif
1123       dDatInd->cellId   = cellCb->cellId;
1124       dDatInd->rnti     = ueCb->ueId;
1125       dDatInd->numLch   = 0;
1126    }
1127 #ifdef LTE_L2_MEAS
1128    ulSf = &cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)];
1129    if(ulSf->ueUlAllocInfo != NULLP)
1130    {
1131      for(idx1 = 0; idx1 < ulSf->numUe; idx1++)
1132      {
1133         if(ulSf->ueUlAllocInfo[idx1].rnti == ueCb->ueId)
1134         {
1135            numPrb = ulSf->ueUlAllocInfo[idx1].numPrb;
1136            break;
1137         }
1138      }
1139    }
1140 #endif
1141    node =  pdu->sduLst.first;
1142    while (node)
1143    {
1144       sdu = (RgMacSdu*)node->node;
1145       
1146       ulLcCb = rgDBMGetUlDedLcCb (ueCb, sdu->lcId);
1147       
1148       if(ulLcCb == NULLP)
1149       {
1150          RLOG_ARG2(L_ERROR,DBG_CELLID,cellCb->cellId,"Unconfigured LCID:%d CRNTI:%d"
1151                          ,sdu->lcId,ueCb->ueId);
1152          /* ccpu00128443: Fix for memory leak */
1153          /* Fix : syed Neccessary to set sdu->mBuf = NULLP */
1154          RG_FREE_MSG(sdu->mBuf);         
1155          node = node->next;
1156          continue;
1157       }
1158 #ifdef RLC_STA_PROC_IN_MAC/* RLC Status PDU Processing */
1159       {
1160          extern S16 kwProcDlStatusPdu(Pst       *udxPst,SuId      suId,
1161                CmLteCellId cellId,CmLteRnti rnti,CmLteLcId lcId,Buffer *rlcSdu);
1162
1163          if(ROK == kwProcDlStatusPdu(&(cellCb->rguDlSap->sapCfg.sapPst),
1164                   cellCb->rguDlSap->sapCfg.suId,
1165                   cellCb->cellId,ueCb->ueId,sdu->lcId,sdu->mBuf))
1166          {
1167             RG_FREE_MSG(sdu->mBuf);           
1168             node = node->next;
1169             continue;
1170          }
1171       }
1172 #endif
1173
1174       /* ccpu00116477- Fixed the rgUIMSndDedDatInd condition when we receive 11 sdus in the 
1175        * list we are losing 11th sdu and sending the first 10 sdus again which
1176        * is causing the duplicate packets and eNB crashing due to access
1177        * of the freed memory */
1178       if (dDatInd->numLch >= RGU_MAX_LC)
1179       {
1180          if ((ret = rgUIMSndDedDatInd(inst,ueCb->rguUlSap,dDatInd)) != ROK)
1181          {
1182             RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
1183                 "Failed to send datIndication to RGU CRNTI:%d",ueCb->ueId);
1184             RETVALUE(ret);
1185          }
1186 #ifndef SS_RBUF
1187          if ((ret = rgAllocShrablSBuf (inst,(Data**)&dDatInd, sizeof(RgRguDedDatInd))) != ROK)
1188          {
1189             RETVALUE(RFAILED);
1190          }
1191 #else
1192       elem = SRngGetWIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
1193       if (NULLP == elem)
1194       { 
1195          RETVALUE(RFAILED);
1196       }
1197       dDatInd = (RgRguDedDatInd *)elem;
1198       cmMemset((U8 *)dDatInd, 0x00, sizeof(RgRguDedDatInd));
1199 #endif
1200          dDatInd->cellId   = cellCb->cellId;
1201          dDatInd->rnti     = ueCb->ueId;
1202          dDatInd->numLch   = 0;
1203       }
1204       dDatInd->lchData[dDatInd->numLch].lcId = sdu->lcId;
1205       dDatInd->lchData[dDatInd->numLch].pdu.mBuf[dDatInd->lchData[dDatInd->numLch].pdu.numPdu] = sdu->mBuf;
1206       dDatInd->lchData[dDatInd->numLch].pdu.numPdu++;
1207       lcgId = ulLcCb->lcgId;
1208       SFndLenMsg(sdu->mBuf, &bufSz);
1209 #ifdef LTE_L2_MEAS
1210       if(ulLcCb->measOn)
1211       {
1212          ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs -= bufSz; 
1213       }
1214 #endif
1215       //if ((lcgBytes != NULLP) && (ueCb->ul.lcgArr[lcgId].isGbr == TRUE))
1216       if (lcgBytes != NULLP)
1217       {
1218          lcgBytes[lcgId] += bufSz;
1219       }
1220       sdu->mBuf = NULLP;
1221       dDatInd->numLch++;
1222 #ifdef LTEMAC_SPS
1223       /* Check if data has come on SPS LC */
1224       /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
1225       if (ueCb->ul.spsLcId[sdu->lcId-1] == TRUE)
1226       {
1227          ueCb->ul.spsDatRcvd++;
1228       }
1229             
1230       if(isSpsRnti)
1231       {
1232          /* Data rcvd on CRNTI*/
1233          /* Retrieve the LCG ID of the LCID*/
1234          /* SPS LCG has data whose size > SID Size */
1235          /* Activate SPS if data recvd on SPS LCID and size > SID Packet Size */
1236          if((ueCb->ul.spsLcId[sdu->lcId-1] == TRUE) &&
1237             (sdu->len > RG_SPS_SID_PACKET_SIZE))
1238          {
1239              *spsToBeActvtd = TRUE;
1240              *sduSize = sdu->len;
1241          }
1242       }
1243       
1244 #endif  
1245
1246 #ifdef LTE_L2_MEAS
1247       if(cellCb->qciArray[ulLcCb->qci].mask == TRUE)
1248       {
1249            sduLen[ulLcCb->qci] = sdu->len;
1250            totalBytesRcvd += sdu->len;
1251            qciVal[ulLcCb->qci] = ulLcCb->qci;
1252       }
1253 #endif
1254       node = node->next;
1255    } /* end of while for SubHeaders */
1256 #ifdef LTE_L2_MEAS
1257    for(idx2 = 0; idx2 < RGU_MAX_LC; idx2++)
1258    {
1259       if((cellCb->qciArray[qciVal[idx2]].mask == TRUE) &&
1260           totalBytesRcvd > 0)
1261       {
1262          cellCb->qciArray[qciVal[idx2]].prbCount += 
1263          ((numPrb * sduLen[idx2]) / totalBytesRcvd);
1264       }
1265       
1266       /* RRM_RBC_X */
1267       if(totalBytesRcvd > 0 && qciVal[idx2] > 0)
1268       {
1269          RG_UPD_GBR_PRB(cellCb, qciVal[idx2], ((numPrb * sduLen[idx2])/totalBytesRcvd));
1270       }
1271       /* RRM_RBC_Y */
1272    }
1273 #endif
1274 /*Added for explicit release - start*/
1275 #ifdef LTEMAC_SPS
1276
1277    if(isSpsRnti && dDatInd && dDatInd->numLch)
1278    {
1279       if(ueCb->ul.spsDatRcvd != 0)
1280       {
1281          ueCb->ul.explRelCntr = 0;
1282          ueCb->ul.spsDatRcvd = 0;
1283       }
1284       else
1285       {
1286          ueCb->ul.explRelCntr++;
1287          if (ueCb->ul.explRelCntr == ueCb->ul.explRelCnt)
1288          {
1289             ueCb->ul.explRelCntr = 0;
1290             /* Indicate scheduler for explicit release */
1291             cmMemset((U8*)&schPst1, (U8)0, sizeof(Pst));
1292             rgGetPstToInst(&schPst1,inst, cellCb->schInstMap.schInst);
1293            //TODO: commented for compilation without SCH 
1294 #if 0
1295             relInfo.cellSapId = cellCb->schInstMap.cellSapId;
1296             relInfo.cRnti = ueCb->ueId;
1297             relInfo.isExplRel = TRUE;
1298             /* Release indicator is called now through the matrix in the function below */
1299             //TODO: commented for compilation without SCH RgMacSchSpsRel( &schPst1, &relInfo );
1300 #endif
1301             ueCb->ul.implRelCntr = 0;
1302          }
1303       }
1304    } 
1305    else
1306    {
1307       /* SPS_FIX */
1308       if(ueCb->ul.spsDatRcvd != 0)
1309       {
1310          //ueCb->ul.implRelCntr = 0;
1311          ueCb->ul.explRelCntr = 0;
1312          ueCb->ul.spsDatRcvd = 0;
1313       }
1314    }
1315 #endif
1316    /*Added for explicit release - end */
1317
1318    if((dDatInd) && (dDatInd->numLch))
1319    {
1320 #ifdef LTE_L2_MEAS
1321       rgTomUtlPrepareL2MUlThrpInfo(cellCb, ueCb,dDatInd);
1322
1323       RG_CALC_TTI_CNT(cellCb, dDatInd->ttiCnt); 
1324 #endif
1325       if ((ret = rgUIMSndDedDatInd(inst,ueCb->rguUlSap,dDatInd)) != ROK)
1326       {
1327          RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
1328                 "Failed to send datIndication to RGU CRNTI:%d",ueCb->ueId);
1329          RETVALUE(ret);
1330       }
1331    }
1332 #ifndef SS_RBUF
1333    else if((dDatInd) && (0 == dDatInd->numLch))
1334    {
1335       /* Free the memory allocated for dDatInd if we 
1336        * have no valid LCH PDU to send to RLC.*/
1337       rgFreeSharableSBuf(inst,(Data **)&dDatInd,sizeof(RgRguDedDatInd)); 
1338    }
1339 #endif
1340    RETVALUE(ROK);
1341 } /* end of */ 
1342
1343 /** @brief This function frees up the RgMacPdu structure that has been
1344  * populated by demux.
1345  *
1346  * @details
1347  *
1348  *     Function: rgTOMUtlInsSchInfo
1349  *       - Function frees up the RgMacPdu structure, in case of error it shall
1350  *       free up the buffer's present in the different sdu.
1351  *
1352  *         Processing steps:
1353  * @param  [in] RgMacPdu   *pdu
1354  * @param  [in] Bool       *error
1355  * @return 
1356  */
1357 #ifdef LTEMAC_SPS
1358 #ifdef ANSI
1359 PRIVATE S16 rgTOMUtlInsSchInfo
1360 (
1361 RgMacPdu *pdu,
1362 RgInfSfDatInd *sfInfo,
1363 RgInfCeInfo *ceInfo,
1364 CmLteRnti   rnti,
1365 Bool        spsToBeActvtd,
1366 U16         sduSize,
1367 U32         *lcgBytes
1368 )
1369 #else
1370 PRIVATE S16 rgTOMUtlInsSchInfo (pdu, sfInfo, ceInfo, rnti,spsToBeActvtd,sduSize, lcgBytes)
1371 RgMacPdu *pdu;
1372 RgInfSfDatInd *sfInfo;
1373 RgInfCeInfo *ceInfo;
1374 CmLteRnti   rnti;
1375 Bool        spsToBeActvtd;
1376 U16         sduSize;
1377 U32         *lcgBytes;
1378 #endif
1379
1380 #else
1381 #ifdef ANSI
1382 PRIVATE S16 rgTOMUtlInsSchInfo
1383 (
1384 RgMacPdu *pdu,
1385 RgInfSfDatInd *sfInfo,
1386 RgInfCeInfo *ceInfo,
1387 CmLteRnti   rnti,
1388 U32         *lcgBytes
1389 )
1390 #else
1391 PRIVATE S16 rgTOMUtlInsSchInfo (pdu, sfInfo, ceInfo, rnti, lcgBytes)
1392 RgMacPdu *pdu;
1393 RgInfSfDatInd *sfInfo;
1394 RgInfCeInfo *ceInfo;
1395 CmLteRnti   rnti;
1396 U32         *lcgBytes;
1397 #endif
1398 #endif
1399 {
1400    S16            ret;
1401    RgInfUeDatInd *ueInfo;
1402    U32           lcgId = 0;
1403    U32           idx = 0;
1404
1405    TRC2(rgTOMUtlInsSchInfo);
1406
1407    RG_TOM_INF_ALLOC(sfInfo, sizeof(RgInfUeDatInd), ueInfo, ret);
1408
1409    if(ROK != ret)
1410    {
1411       RETVALUE(RFAILED);
1412    }
1413
1414    ueInfo->rnti = rnti; 
1415       
1416    ueInfo->ceInfo = *ceInfo;
1417    ueInfo->ueLstEnt.node = (PTR)ueInfo;
1418    for (lcgId = 1, idx = 0; lcgId < RGINF_MAX_LCG_PER_UE; lcgId++)
1419    {
1420       if (lcgBytes[lcgId] != 0)
1421       {
1422          /* Only GBR bytes */
1423          ueInfo->lcgInfo[idx].lcgId     = lcgId;
1424          ueInfo->lcgInfo[idx++].bytesRcvd = lcgBytes[lcgId];
1425          lcgBytes[lcgId] = 0;
1426       }
1427    }
1428    cmLListAdd2Tail(&sfInfo->ueLst, &ueInfo->ueLstEnt);
1429    RETVALUE(ROK);
1430 } /* end of rgTOMUtlInsSchInfo */
1431
1432 #include <stdlib.h>
1433 /**
1434  * @brief Handler for processing data indication recieved from PHY for UEs.
1435  *
1436  * @details
1437  *
1438  *     Function: rgTOMDatInd
1439  *
1440  *     Handler for processing data indication recieved from PHY for UEs.
1441  *
1442  *     Invoked by: RgLiTfuDatInd of LIM 
1443  *
1444  *     Processing Steps: 
1445  *     For each DataInfo recieved
1446  *      - Validate the information received and retrieve cellCb 
1447  *        Validate cellId, rnti 
1448  *      - Call De-Mux module to decode the data rgDUXDemuxData
1449  *      - If  received a CRNTI control element 
1450  *          - Check if a CCCH SDU is present, if it is return failure
1451  *          - Check for the existence of UE, if its isnt present return failure.
1452  *          - Delegate the remaining processing to rgTOMUtlProcMsg3 which
1453  *          primarily informs the scheduler about the data received and
1454  *          generates Data indications towards the higher layer.
1455  *      - If only CCCH SDU is present
1456  *        - Invoke rgTOMUtlProcMsg3 for further processing.
1457  *      - If its a non-Msg3 PDU i.e. received outside of a RA procedure
1458  *        - Retrieve the UeCB 
1459  *        - Validate that the received PDU contains only configured Logical
1460  *        Channels.
1461  *        - Invoke rgTOMUtlProcDatPdu for further processing. It informs the
1462  *        scheduler with the information of the received Data and generates
1463  *        DatIndications towards the higher layers. 
1464  *           
1465  * @param  [in] Inst        inst
1466  *  @param[in]  TfuDatIndInfo *datInd
1467  *  @return  S16
1468  *      -# ROK 
1469  *      -# RFAILED 
1470  **/
1471 #ifdef ANSI
1472 PUBLIC S16 rgTOMDatInd
1473 (
1474 Inst           inst,
1475  TfuDatIndInfo *datInd
1476  )
1477 #else
1478 PUBLIC S16 rgTOMDatInd(inst,datInd)
1479 Inst             inst;
1480  TfuDatIndInfo *datInd;
1481 #endif
1482 {
1483    S16               ret = ROK;
1484    RgErrInfo         err;
1485    RgUeCb            *ueCb;
1486    RgUeCb            *prevUeCb = NULLP;
1487    RgCellCb          *cellCb;
1488    RgMacPdu          *pdu;
1489    RgInfSfDatInd     *sfInfo;
1490    RgInfCeInfo       ceInfo; 
1491    Pst               schPst;
1492    CmLList           *node;
1493    TfuDatInfo        *datInfo;
1494    RgLowSapCb        *tfuSap;
1495    U16               slot;
1496 #ifdef LTEMAC_SPS
1497    Bool              isSpsRnti=FALSE;
1498    Pst               schPst1;  
1499   // RgInfSpsRelInfo   relInfo;
1500         Bool              spsToBeActvtd = FALSE;
1501    U16               sduSize = 0;
1502 #endif
1503    U32               lcgBytes[RGINF_MAX_LCG_PER_UE];
1504
1505
1506    TRC2(rgTOMDatInd);
1507 #ifdef STUB_TTI_HANDLING_5GTF 
1508    node =  datInd->datIndLst.first;
1509    for (;node; node=node->next)
1510    {
1511       datInfo = (TfuDatInfo*)node->node;
1512       {
1513          MsgLen len;
1514          SFndLenMsg(datInfo->mBuf, &len);
1515          rgUlrate_tfu += len;
1516          if (rgUlrate_tfu > 100000)
1517          {
1518          printf("Sowmya:rgTOMDatInd datInfo->mBuf len =%d rgUlrate_tfu=%d",len,rgUlrate_tfu);
1519          rgUlrate_tfu = 0;
1520          }
1521       }
1522    }
1523       return(RFAILED);
1524 #endif      
1525
1526    cmMemset((U8 *)&lcgBytes, 0, sizeof(lcgBytes));
1527
1528    tfuSap = &(rgCb[inst].tfuSap);
1529    ueCb = NULLP;
1530    cellCb = rgCb[inst].cell;
1531    if((cellCb == NULLP) ||
1532       (cellCb->cellId != datInd->cellId))   
1533    {
1534        
1535       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"Unable to get the cellCb for cell");
1536       RETVALUE(RFAILED);
1537    }
1538    /* Avoiding memset as all the fields are getting initialized further */
1539
1540    if (rgTOMInfAllocPduEvnt (inst,&sfInfo) != ROK)
1541    {
1542       err.errType = RGERR_TOM_DATIND;
1543       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"Unable to Allocate PDU for DUX cell");
1544       node =  datInd->datIndLst.first;
1545       RETVALUE(RFAILED);
1546    }
1547    cmLListInit(&sfInfo->ueLst);
1548    sfInfo->cellId = datInd->cellId;
1549    sfInfo->timingInfo = datInd->timingInfo;
1550    slot = datInd->timingInfo.slot;
1551
1552    node =  datInd->datIndLst.first;
1553    for (;node; node=node->next)
1554    {
1555       datInfo = (TfuDatInfo*)node->node;
1556       {
1557          //extern U32 ulrate_tfu;
1558          MsgLen len;
1559          SFndLenMsg(datInfo->mBuf, &len);
1560 #ifdef STUB_TTI_HANDLING_5GTF         
1561        //  printf("Sowmya:rgTOMDatInd datInfo->mBuf len =%d",len);
1562 #endif
1563          rgUlrate_tfu += len;
1564 #ifdef EMTC_ENABLE
1565          grgUlrate_tfu += len;
1566 #endif
1567       }
1568 #ifdef STUB_TTI_HANDLING_5GTF         
1569       rgLIMUtlFreeDatIndEvnt(datInd,TRUE);
1570 #endif
1571       /* We shall call De-Mux to process the received buffer. We shall try and find
1572        * out the RaCb based on the following - 
1573        * 1. If the incoming PDU contained a CCCH SDU i.e. this is message 3.
1574        * 2. If the incoming PDU contained a CRNTI control element, i.e. we should
1575        * have a ueCb also for this 
1576        */
1577       /* Lets allocate the event that needs to be passed to DUX */
1578       if (rgTOMUtlAllocPduEvnt (inst,&pdu) != ROK)
1579       {
1580          err.errType = RGERR_TOM_DATIND;
1581          RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"Unable to Allocate PDU for DUX cell");
1582          rgTOMInfFreePduEvnt (sfInfo);
1583          RETVALUE(RFAILED);
1584       }
1585
1586       if ((ret = rgDUXDemuxData (inst,pdu, &ceInfo, 
1587                            &datInfo->mBuf, &err)) != ROK)
1588       {
1589          //exit(1);
1590          /* Fix: sriky memory corruption precautions */
1591          rgTOMUtlFreePduEvnt (pdu, TRUE);
1592          err.errType = RGERR_TOM_DATIND;
1593          RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"DUX processing failed");
1594          tfuSap->sapSts.numPduDrop++;
1595          continue; 
1596       }
1597       /* It could be that a non-msg3 pdu contains a CRNTI Control element. We
1598        * should check for CRNTI CE and if it exists the UECb must exist, also an
1599        * if the CRNTI in the CE and the one with which the message came in are
1600        * different we shall look for an raCb as well. 
1601        */
1602
1603       if (ceInfo.bitMask & RG_CCCH_SDU_PRSNT)
1604       {
1605         ret = rgTOMProcCCCHSduInDatInd(pdu, prevUeCb, \
1606                 cellCb, datInfo, &ceInfo, slot);
1607         if (ret == RFAILED)
1608         {
1609             rgTOMUtlFreePduEvnt (pdu, TRUE);
1610             err.errType = RGERR_TOM_DATIND;
1611             tfuSap->sapSts.numPduDrop++;
1612             continue; 
1613         }
1614       } /* end of Msg3 processing */
1615
1616       else if (ceInfo.bitMask & RG_CRNTI_CE_PRSNT)
1617       {
1618         ret = rgTOMProcCrntiCEInDatInd(pdu, prevUeCb, \
1619                 cellCb, datInfo, &ceInfo, slot);
1620         if (ret == RFAILED)
1621         {
1622             rgTOMUtlFreePduEvnt (pdu, TRUE);
1623             err.errType = RGERR_TOM_DATIND;
1624             tfuSap->sapSts.numPduDrop++;
1625             continue; 
1626         }
1627
1628       } /* end of CRNTI based message */
1629       else
1630       {
1631          ueCb = rgDBMGetUeCb (cellCb, datInfo->rnti);
1632          if (ueCb == NULLP)
1633          {
1634 #ifdef LTEMAC_SPS
1635             /* Try getting the UE using SPS-RNTI. */
1636             ueCb = rgDBMGetSpsUeCb (cellCb, datInfo->rnti);
1637             if (ueCb != NULLP)
1638             {
1639                isSpsRnti = TRUE;
1640                /* Increment implrelCntr for an empty transmission */
1641                if (pdu->sduLst.count == 0)
1642                {
1643                   ueCb->ul.implRelCntr++;
1644                   if (ueCb->ul.implRelCntr == ueCb->ul.implRelCnt)
1645                   {
1646                      /* Indicate scheduler for implicit release */
1647                      cmMemset((U8*)&schPst1, (U8)0, sizeof(Pst));
1648                      rgGetPstToInst(&schPst1,inst, cellCb->schInstMap.schInst);
1649
1650                      ueCb->ul.implRelCntr = 0;
1651                      ueCb->ul.explRelCntr = 0;
1652 #if 0                     
1653                                                         relInfo.cellSapId = cellCb->schInstMap.cellSapId;
1654                      relInfo.cRnti = ueCb->ueId;
1655                                                         relInfo.isExplRel= FALSE;
1656                      //TODO: commented for compilation without SCH RgMacSchSpsRel(&schPst1, &relInfo);
1657 #endif  
1658                   }
1659                }
1660                else
1661                {
1662                   /* Reset the implrelCntr */
1663                   ueCb->ul.implRelCntr = 0;
1664                }
1665             }
1666             else
1667 #endif 
1668             {
1669                /* Perform failure if ueCb is still NULLP */
1670                rgTOMUtlFreePduEvnt (pdu, TRUE);
1671                err.errType = RGERR_TOM_DATIND;
1672                RLOG_ARG1(L_ERROR,DBG_CELLID,datInd->cellId,"RNTI:%d Unable to get the UE CB", 
1673                   datInfo->rnti);
1674                tfuSap->sapSts.numPduDrop++;
1675                continue;
1676             }
1677          }
1678 #ifdef LTE_L2_MEAS         
1679      rgTOMUtlL2MStoreBufSz(ueCb, &ceInfo);
1680      rgTOML2MCompileActiveLCs (cellCb, ueCb, pdu, &ceInfo);
1681 #endif
1682 #ifdef LTEMAC_SPS
1683          if ((ret = rgTOMUtlProcMsg(cellCb, ueCb, pdu, isSpsRnti,&spsToBeActvtd,&sduSize, slot, (U32 *)&lcgBytes)) != ROK)
1684 #else
1685          if ((ret = rgTOMUtlProcMsg (cellCb, ueCb, pdu, slot, (U32 *)&lcgBytes)) != ROK)
1686 #endif /* LTEMAC_SPS */
1687          {
1688             rgTOMUtlFreePduEvnt (pdu, TRUE);
1689             err.errType = RGERR_TOM_DATIND;
1690             RLOG_ARG1(L_ERROR,DBG_CELLID,datInd->cellId,
1691                             "Unable to handle Data Indication CRNTI:%d",ueCb->ueId);
1692             tfuSap->sapSts.numPduDrop++;
1693             continue;
1694          }
1695       }
1696
1697       
1698 #ifdef LTEMAC_SPS
1699       if(rgTOMUtlInsSchInfo(pdu, sfInfo, &ceInfo, datInfo->rnti,spsToBeActvtd,sduSize, (U32 *)&lcgBytes) != ROK)
1700 #else
1701       if(rgTOMUtlInsSchInfo(pdu, sfInfo, &ceInfo, datInfo->rnti, (U32 *)&lcgBytes) != ROK)
1702 #endif
1703       
1704       {
1705          rgTOMInfFreePduEvnt (sfInfo);
1706          rgTOMUtlFreePduEvnt (pdu, FALSE);
1707          RETVALUE(RFAILED);
1708       }
1709       /* free up the PDU memory */
1710       rgTOMUtlFreePduEvnt (pdu, FALSE);
1711    }
1712    /* Free the allocated memory for ueUlAllocInfo here */
1713 #ifdef LTE_L2_MEAS
1714    if(cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)].ueUlAllocInfo != NULLP)
1715    {
1716       /*ccpu00117052 - MOD - Passing double for proper NULLP
1717                              assignment */
1718       rgFreeSBuf(inst,(Data **)&(cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)].ueUlAllocInfo), 
1719       ((cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)].numUe) * sizeof(RgUeUlAlloc)));
1720    }
1721 #endif
1722    /* RRM_RBC_X */
1723    /* Update PRB used for all GBR QCIs to scheduler */
1724     cmMemcpy((U8*) &sfInfo->qcisUlPrbCnt[0],
1725              (U8*) &cellCb->qcisUlPrbCnt[0],
1726              (RGM_MAX_QCI_REPORTS * sizeof(U32)));
1727     /* clear the cellCb ul prb value */
1728     cmMemset((U8*)&cellCb->qcisUlPrbCnt[0], 0, 
1729              (RGM_MAX_QCI_REPORTS * sizeof(U32)));
1730
1731    /* RRM_RBC_Y */
1732
1733    rgGetPstToInst(&schPst, inst,cellCb->schInstMap.schInst);
1734    sfInfo->cellSapId = cellCb->schInstMap.cellSapId;
1735    //TODO: commented for compilation without SCH RgMacSchSfRecp(&schPst, sfInfo);
1736    RETVALUE(ROK);
1737 }  /* rgTOMDatInd */
1738
1739 /**
1740  * @brief Function handles allocation for common channels i.e. BCCH-BCH,
1741  * BCCH-DLSCH, PCCH-DLSCH.
1742  *
1743  * @details
1744  *
1745  *     Function : rgHndlCmnChnl
1746  *     
1747  *     This function is invoked from RgSchMacSfAllocReq. This function handles
1748  *     allocations made for common channels like BCCH and PCCH. 
1749  *
1750  *     Processing steps:
1751  *     1. If BCCH on BCH has been scheduled, send StatusIndication on RGU.
1752  *     2. If PCCH is scheduled, send StatusIndication on RGU.
1753  *     3. If BCCH on DLSCH has been scheduled and sndStatInd is TRUE, send
1754  *     StatusIndication on RGU, else copy the bcch buffer onto the downlink
1755  *     subframe. 
1756  *     
1757  *           
1758  *  @param[in] RgCellCb          *cell,
1759  *  @param[in] CmLteTimingInfo   timingInfo,
1760  *  @param[in] RgInfCmnLcInfo    *cmnLcInfo,
1761  *  @param[in/out] RgErrInfo     *err,
1762  *  @return  S16
1763  *      -# ROK 
1764  *      -# RFAILED
1765  **/
1766 #ifdef ANSI
1767 PRIVATE S16 rgHndlCmnChnl
1768 (
1769 RgCellCb            *cell,
1770 CmLteTimingInfo     timingInfo,
1771 RgInfCmnLcInfo      *cmnLcInfo,
1772 RgErrInfo           *err
1773 )
1774 #else
1775 PRIVATE S16 rgHndlCmnChnl(cell, timingInfo, cmnLcInfo, err)
1776 RgCellCb            *cell;
1777 CmLteTimingInfo     timingInfo;
1778 RgInfCmnLcInfo      *cmnLcInfo;
1779 RgErrInfo           *err;
1780 #endif
1781 {
1782    #if (ERRCLASS & ERRCLS_DEBUG)
1783    RgPcchLcCb           *pcch;
1784    #endif
1785 #ifndef RGR_SI_SCH
1786    RgBcchDlschLcCb      *bcch;
1787 #if (ERRCLASS & ERRCLS_DEBUG)
1788    RgBcchBchLcCb        *bch;
1789 #endif
1790 #endif/*RGR_SI_SCH*/
1791    RguCStaIndInfo       *staInd;
1792    RgDlSf               *dlSf;
1793    Inst                 inst = cell->macInst - RG_INST_START;
1794
1795    TRC2(rgHndlCmnChnl)
1796
1797    dlSf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
1798
1799    if(cmnLcInfo->bitMask & RGINF_BCH_INFO)
1800    {
1801 #ifndef RGR_SI_SCH
1802       #if (ERRCLASS & ERRCLS_DEBUG) 
1803       if(NULLP == (bch = rgDBMGetBcchOnBch(cell)))
1804       {
1805          RETVALUE(RFAILED);
1806       }
1807       if(cmnLcInfo->bchInfo.lcId != bch->lcId)
1808       {
1809          RETVALUE(RFAILED);
1810       }
1811       #endif
1812
1813       if (rgAllocShrablSBuf (inst,(Data**)&staInd, sizeof(RguCStaIndInfo)) != ROK)
1814       {
1815          err->errCause = RGERR_TOM_MEM_EXHAUST;
1816          RETVALUE(RFAILED);
1817       }
1818       staInd->cellId = cell->cellId;
1819       staInd->rnti   = RG_INVALID_RNTI;
1820       staInd->lcId   = cmnLcInfo->bchInfo.lcId;
1821       staInd->transId = (timingInfo.sfn << 8) | (timingInfo.slot);
1822 /* ADD Changes for Downlink UE Timing Optimization */
1823 #ifdef LTEMAC_DLUE_TMGOPTMZ
1824       dlSf->remDatReqCnt++;
1825 #endif
1826       if (rgUIMSndCmnStaInd (inst,cell->rguDlSap,staInd) != ROK)
1827       {
1828          RETVALUE(RFAILED);
1829       }
1830 #else
1831       /*Store the received BCH Data in the scheduled subframe*/
1832       dlSf->bch.tb = cmnLcInfo->bchInfo.pdu;
1833 #endif/*RGR_SI_SCH*/
1834    }
1835
1836    if(cmnLcInfo->bitMask & RGINF_PCCH_INFO)
1837    {
1838       #if (ERRCLASS & ERRCLS_DEBUG) 
1839       if(NULLP == (pcch = rgDBMGetPcch(cell)))
1840       {
1841          RETVALUE(RFAILED);
1842       }
1843       if(cmnLcInfo->pcchInfo.lcId != pcch->lcId)
1844       {
1845          RETVALUE(RFAILED);
1846       }
1847       #endif
1848
1849       dlSf->pcch.pdcch.rnti = 
1850                cmnLcInfo->pcchInfo.rnti;
1851       dlSf->pcch.pdcch.dci = 
1852                cmnLcInfo->pcchInfo.dciInfo;
1853 #ifdef TFU_UPGRADE               
1854       /* ccpu00132314-ADD-Fill the tx Pwr offset from scheduler */         
1855       dlSf->pcch.txPwrOffset = cmnLcInfo->pcchInfo.txPwrOffset;         
1856 #endif
1857       if (rgAllocShrablSBuf (inst,(Data**)&staInd, sizeof(RguCStaIndInfo)) != ROK)
1858       {
1859          err->errCause = RGERR_TOM_MEM_EXHAUST;
1860          RETVALUE(RFAILED);
1861       }
1862       staInd->cellId = cell->cellId;
1863       staInd->rnti   = RG_INVALID_RNTI;
1864       staInd->lcId   = cmnLcInfo->pcchInfo.lcId;
1865       staInd->transId = (timingInfo.sfn << 8) | (timingInfo.slot);
1866 /* ADD Changes for Downlink UE Timing Optimization */
1867 #ifdef LTEMAC_DLUE_TMGOPTMZ
1868       dlSf->remDatReqCnt++;
1869 #endif
1870       /* for consolidated CmnStaInd calling below function from function 
1871        * rgHndlSchedUe once CmnStaInd prepared for all UEs
1872        */
1873       if (rgUIMSndCmnStaInd (inst,cell->rguDlSap,staInd) != ROK)
1874       {
1875          RETVALUE(RFAILED);
1876       }
1877    }
1878
1879    if(cmnLcInfo->bitMask & RGINF_BCCH_INFO)
1880    {
1881       dlSf->bcch.pdcch.rnti = 
1882                cmnLcInfo->bcchInfo.rnti;
1883       dlSf->bcch.pdcch.dci = 
1884                cmnLcInfo->bcchInfo.dciInfo;
1885 #ifdef TFU_UPGRADE               
1886       /* ccpu00132314-ADD-Fill the tx Pwr offset from scheduler */         
1887       dlSf->bcch.txPwrOffset = cmnLcInfo->bcchInfo.txPwrOffset;         
1888 #endif      
1889 #ifndef RGR_SI_SCH
1890       if(NULLP == 
1891          (bcch=rgDBMGetBcchOnDlsch(cell,cmnLcInfo->bcchInfo.lcId)))
1892       {
1893          RETVALUE(RFAILED);
1894       }
1895       if(TRUE == cmnLcInfo->bcchInfo.sndStatInd)
1896       {
1897          RG_FREE_MSG(bcch->tb);
1898          if (rgAllocShrablSBuf (inst,(Data**)&staInd, 
1899                   sizeof(RguCStaIndInfo)) != ROK)
1900          {
1901             err->errCause = RGERR_TOM_MEM_EXHAUST;
1902             RETVALUE(RFAILED);
1903          }
1904          staInd->cellId = cell->cellId;
1905          staInd->rnti   = RG_INVALID_RNTI;
1906          staInd->lcId   = cmnLcInfo->bcchInfo.lcId;
1907          staInd->transId = (timingInfo.sfn << 8) | (timingInfo.slot);
1908 /* ADD Changes for Downlink UE Timing Optimization */
1909 #ifdef LTEMAC_DLUE_TMGOPTMZ
1910          dlSf->remDatReqCnt++;
1911 #endif
1912          if (rgUIMSndCmnStaInd (inst,cell->rguDlSap,staInd) != ROK)
1913          {
1914             RETVALUE(RFAILED);
1915          }
1916       }
1917       else
1918       {
1919          SCpyMsgMsg(bcch->tb, RG_GET_MEM_REGION(rgCb[inst]),
1920                   RG_GET_MEM_POOL(rgCb[inst]), &dlSf->bcch.tb);
1921       }
1922 #else
1923       /*Store the received BCCH Data in the scheduled subframe*/
1924       dlSf->bcch.tb = cmnLcInfo->bcchInfo.pdu;
1925 #endif/*RGR_SI_SCH*/
1926    }
1927
1928    RETVALUE(ROK);
1929 } /* end of rgHndlCmnChnl */
1930
1931 /**
1932  * @brief Function for handling allocations for dedicated channels for a
1933  * subframe.
1934  *
1935  * @details
1936  *
1937  *     Function : rgHndlSchdUe
1938  *     
1939  *     This function shall be invoked whenever scheduler is done with the
1940  *     allocations of dedicated channels for a subframe. Invoked by the function
1941  *     RgSchMacSfAllocReq.
1942  *
1943  *     Processing steps :
1944  *     1. Loops through the list of UE's scheduled looking for the corresponding
1945  *     ueCb/raCb. 
1946  *     2. Finds the corresponding HARQ process.
1947  *     3. Invokes the DHM function to issue StatusIndications on RGU.
1948  *
1949  *           
1950  *  @param[in] RgCellCb            *cell,
1951  *  @param[in] CmLteTimingInfo     timingInfo,
1952  *  @param[in] RgInfUeInfo         *ueInfo
1953  *  @param[in/out] RgErrInfo       *err
1954  *  @return  S16
1955  *      -# ROK 
1956  *      -# RFAILED 
1957  **/
1958 #ifdef ANSI
1959 PRIVATE S16 rgHndlSchdUe
1960 (
1961 RgCellCb            *cell,
1962 CmLteTimingInfo     timingInfo,
1963 RgInfUeInfo         *ueInfo,
1964 RgErrInfo           *err
1965 )
1966 #else
1967 PRIVATE S16 rgHndlSchdUe(cell, timingInfo, ueInfo, err) /* laa_ut_fix */
1968 RgCellCb            *cell;
1969 CmLteTimingInfo     timingInfo;
1970 RgInfUeInfo         *ueInfo;
1971 RgErrInfo           *err;
1972 #endif
1973 {
1974
1975    TRC2(rgHndlSchdUe);
1976
1977    if(NULLP == ueInfo->allocInfo)
1978    {
1979       RETVALUE(RFAILED);
1980    }
1981
1982    rgDHMSndConsolidatedStaInd(cell, ueInfo, timingInfo, err);
1983
1984    RETVALUE(ROK);
1985 } /* end of rgHndlSchdUe */
1986
1987 #ifdef LTE_L2_MEAS
1988 /**
1989  * @brief Function for handling Uplink allocations for Ue for a
1990  * subframe.
1991  *
1992  * @details
1993  *
1994  *     Function : rgHndlUlUeInfo
1995  *     
1996  *  @param[in] RgCellCb            *cell,
1997  *  @param[in] CmLteTimingInfo     timingInfo,
1998  *  @param[in] RgInfUlUeInfo       *ueInfo
1999  *  @return  S16
2000  *      -# ROK 
2001  *      -# RFAILED 
2002  **/
2003 #ifdef ANSI
2004 PRIVATE S16 rgHndlUlUeInfo
2005 (
2006 RgCellCb            *cell,
2007 CmLteTimingInfo     timingInfo,
2008 RgInfUlUeInfo       *ueInfo
2009 )
2010 #else
2011 PRIVATE S16 rgHndlUlUeInfo(cell, timingInfo, ueInfo)
2012 RgCellCb            *cell;
2013 CmLteTimingInfo     timingInfo;
2014 RgInfUlUeInfo       *ueInfo;
2015 #endif
2016 {
2017    Inst           inst = cell->macInst - RG_INST_START;
2018    U8             idx;
2019    RgUlSf         *ulSf;
2020    S16            ret;
2021
2022    TRC2(rgHndlUlUeInfo)
2023    
2024    ulSf = &cell->ulSf[(timingInfo.slot % RGSCH_NUM_SUB_FRAMES)];
2025
2026    /* rg003.301-MOD- Corrected the purifier memory leak */
2027    if (ulSf->numUe != ueInfo->numUes)
2028    {
2029       if (ulSf->ueUlAllocInfo)
2030       {
2031          rgFreeSBuf(inst,(Data **)&(ulSf->ueUlAllocInfo),
2032                ulSf->numUe * sizeof(RgUeUlAlloc));
2033       }
2034    }
2035 #ifdef XEON_SPECIFIC_CHANGES
2036    CM_MEAS_TIME((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MEAS_FREE);
2037    CM_ADD_INFO((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES),  CM_DBG_MEAS_FREE, ulSf->numUe);
2038 #endif
2039    ulSf->numUe         = ueInfo->numUes;
2040    if((ulSf->ueUlAllocInfo == NULLP) && (ueInfo->numUes > 0))
2041    {
2042        /* Allocate memory for ulAllocInfo */
2043        if((ret = rgAllocSBuf(inst,(Data**)&(cell->ulSf[(timingInfo.slot % RGSCH_NUM_SUB_FRAMES)].
2044                  ueUlAllocInfo), ueInfo->numUes *  sizeof(RgUeUlAlloc))) != ROK)
2045        {
2046           RETVALUE(ret);
2047        }
2048    }
2049 #ifdef XEON_SPECIFIC_CHANGES
2050    CM_MEAS_TIME((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MEAS_ALLOC);
2051    CM_ADD_INFO((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES), CM_DBG_MEAS_ALLOC, ueInfo->numUes);
2052 #endif
2053    if (ulSf->ueUlAllocInfo != NULLP)
2054    {
2055       for(idx = 0; idx < ueInfo->numUes; idx++)
2056       {
2057          ulSf->ueUlAllocInfo[idx].rnti   = ueInfo->ulAllocInfo[idx].rnti;
2058          ulSf->ueUlAllocInfo[idx].numPrb = ueInfo->ulAllocInfo[idx].numPrb;
2059       }
2060    }
2061    RGCPYTIMEINFO(timingInfo, ulSf->schdTime);
2062    RETVALUE(ROK);
2063 } /* end of rgHndlUlUeInfo */
2064 #endif
2065 /**
2066  * @brief Function for handling RaResp request received from scheduler to MAC
2067  *
2068  * @details
2069  *
2070  *     Function : rgTOMRlsSf
2071  *     
2072  *     This function shall be invoked whenever scheduler is done with the
2073  *     allocations of random access responses for a subframe.
2074  *     This shall invoke RAM to create ueCbs for all the rapIds allocated and 
2075  *     shall invoke MUX to create RAR PDUs for raRntis allocated.
2076  *     
2077  *           
2078  *  @param[in] Inst        inst
2079  *  @param[in] CmLteCellId         cellId,
2080  *  @param[in] CmLteTimingInfo     timingInfo,
2081  *  @param[in] RaRespInfo          *rarInfo
2082  *  @return  S16
2083  *      -# ROK 
2084  **/
2085 #ifdef ANSI
2086 PUBLIC Void rgTOMRlsSf
2087 (
2088 Inst                inst,
2089 RgDlSf              *dlSf
2090 )
2091 #else
2092 PUBLIC Void rgTOMRlsSf(dlSf)
2093 Inst                inst;
2094 RgDlSf              *dlSf;
2095 #endif
2096 {
2097    U8               idx;
2098
2099    TRC2(rgTOMRlsSf)
2100
2101    if(dlSf->txDone == FALSE)
2102    {
2103       RLOG0(L_ERROR, "SUBFRAME Not pushed to the PHY");
2104
2105       if (dlSf->bch.tb != NULLP)
2106       {
2107          RG_FREE_MSG(dlSf->bch.tb);
2108       }
2109       if (dlSf->bcch.tb != NULLP)
2110       {
2111          RG_FREE_MSG(dlSf->bcch.tb);
2112       }
2113       if (dlSf->pcch.tb != NULLP)
2114       {
2115          RG_FREE_MSG(dlSf->pcch.tb);
2116       }
2117 #ifdef EMTC_ENABLE
2118       rgTOMEmtcRlsSf(dlSf);
2119 #endif
2120       for(idx=0; idx < dlSf->numRaRsp; idx++)
2121       {
2122          RG_FREE_MSG(dlSf->raRsp[idx].rar);
2123       }
2124    }
2125 /* ADD Changes for Downlink UE Timing Optimization */
2126 #ifdef LTEMAC_DLUE_TMGOPTMZ
2127    dlSf->remDatReqCnt = 0;
2128    /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
2129       RLC-MAC */
2130    dlSf->statIndDone = FALSE;
2131 #endif
2132          if (dlSf->tbs.count)
2133          {
2134       U8           i;
2135       CmLList      *node;
2136       RgDlHqProcCb *hqP;
2137        RGDBGERRNEW(inst, (rgPBuf(inst),
2138                 "Error Stale TBs in Subframes TBS list\n"));
2139       node = dlSf->tbs.first;
2140                   while(node)
2141                   {
2142          hqP = (RgDlHqProcCb*)node->node;
2143          node = node->next;
2144           if (hqP)
2145           {
2146                      for(i=0;i< RG_MAX_TB_PER_UE;i++)
2147                      {
2148                                     if (hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sf == dlSf)
2149                                     {
2150                                              cmLListDelFrm(&dlSf->tbs, &(hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sfLnk));
2151                                              hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sfLnk.node = NULLP;
2152                     printf("\n rgTOMRlsSf:: hqP %p \n", (Void *)hqP);
2153                                     }
2154                                     hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sf = NULLP;
2155                            }
2156                         }
2157          }
2158     }
2159     /*arjun: check if dlSf laaTb list has to be freed???*/
2160    cmLListInit(&dlSf->tbs);
2161    dlSf->txDone = FALSE;
2162    dlSf->numRaRsp = 0;
2163    RETVOID;
2164 }
2165
2166 /**
2167  * @brief Function is called by the scheduler once it has completed the
2168  * allocation for the subframe. 
2169  *
2170  * @details
2171  *
2172  *     Function : rgHndlFlowCntrl
2173  *     This function should fill and send Flow control 
2174  *     indication to RLC
2175  *
2176  *           
2177  *  @param[in] Pst                 *cell       
2178  *  @param[in] RgInfSfAlloc        *sfInfo   Carries all the allocation
2179  *  information.
2180  *  @return  S16
2181  *      -# ROK 
2182  **/
2183 #ifdef ANSI
2184 PUBLIC S16 rgHndlFlowCntrl
2185 (
2186 RgCellCb       *cell,
2187 RgInfSfAlloc        *sfInfo
2188 )
2189 #else
2190 PUBLIC S16 rgHndlFlowCntrl(cell, sfInfo)
2191 RgCellCb            *cell;
2192 RgInfSfAlloc        *sfInfo;
2193 #endif
2194 {
2195    RguFlowCntrlInd  *flowCntrlInd;
2196    Pst              *pst;
2197    U32              ueIdx;
2198    U32              lcIdx;
2199    TRC3(rgHndlFlowCntrl);
2200
2201    pst = &cell->rguDlSap->sapCfg.sapPst;
2202    /* flowCntrlInd is alloced in cell init time and will be re-used throughout */
2203    flowCntrlInd = cell->flowCntrlInd;
2204    flowCntrlInd->cellId = sfInfo->cellId;
2205    flowCntrlInd->numUes = sfInfo->flowCntrlInfo.numUes; 
2206   
2207    for (ueIdx = 0; ueIdx < sfInfo->flowCntrlInfo.numUes; ueIdx++)
2208    {
2209       flowCntrlInd->ueFlowCntrlInfo[ueIdx].ueId = sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].ueId;
2210       flowCntrlInd->ueFlowCntrlInfo[ueIdx].numLcs = sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].numLcs;
2211       
2212       for (lcIdx = 0; lcIdx < RGINF_MAX_NUM_DED_LC; lcIdx++)
2213       {
2214          flowCntrlInd->ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].lcId =
2215          sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].lcId;
2216          flowCntrlInd->ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].pktAdmitCnt = 
2217          sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].pktAdmitCnt;
2218         
2219          flowCntrlInd->ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].maxBo4FlowCtrl = 
2220          sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].maxBo4FlowCtrl;
2221       }
2222    }
2223    RgUiRguFlowCntrlInd(pst, cell->rguDlSap->sapCfg.spId,flowCntrlInd); /* TODO: Rishi confirm if the suId and pst pointer is correct */
2224    RETVALUE(ROK);
2225 }
2226 /**
2227  * @brief Function is called by the scheduler once it has completed the
2228  * allocation for the subframe. 
2229  *
2230  * @details
2231  *
2232  *     Function : RgSchMacSfAllocReq
2233  *     
2234  *     This function shall be invoked whenever scheduler is done with the
2235  *     allocations of for a subframe. The sfInfo carries all the allocation
2236  *     details for the common channels, RA responses and dedicated channel
2237  *     allocations. 
2238  *
2239  *     Processing steps :
2240  *     1. Reset the information present in the downlink subframe that is
2241  *     scheduled.
2242  *     2. Handle common channel allocations
2243  *     3. Handle RA Response allocations
2244  *     4. Handle dedicated channel allocations.
2245  *           
2246  *  @param[in] Pst                 *pst       
2247  *  @param[in] RgInfSfAlloc        *sfInfo   Carries all the allocation
2248  *  information.
2249  *  @return  S16
2250  *      -# ROK 
2251  **/
2252 #ifdef ANSI
2253 PUBLIC S16 RgSchMacSfAllocReq
2254 (
2255 Pst                 *pst,
2256 RgInfSfAlloc        *sfInfo
2257 )
2258 #else
2259 PUBLIC S16 RgSchMacSfAllocReq(pst, sfInfo)
2260 Pst                 *pst;
2261 RgInfSfAlloc        *sfInfo;
2262 #endif
2263 {
2264    RgCellCb       *cell;
2265    RgDlSf         *dlSf;
2266    RgErrInfo      err;
2267    VOLATILE U32   startTime=0;
2268    Inst           inst;
2269
2270    TRC2(RgSchMacSfAllocReq)
2271
2272    RG_IS_INST_VALID(pst->dstInst);
2273    inst = pst->dstInst - RG_INST_START;
2274    /*starting Task*/
2275    SStartTask(&startTime, PID_MAC_SF_ALLOC_REQ);
2276
2277    if(NULLP == sfInfo)
2278    {
2279       RETVALUE(RFAILED);
2280    }
2281
2282    if((cell = rgCb[inst].cell) == NULLP)
2283    {
2284       RLOG_ARG0(L_ERROR,DBG_CELLID,sfInfo->cellId, "No cellCb found with cell");
2285       RETVALUE(RFAILED);
2286    }
2287
2288    dlSf = &cell->subFrms[(sfInfo->timingInfo.slot % RG_NUM_SUB_FRAMES)];
2289
2290    rgTOMRlsSf(inst,dlSf);
2291    dlSf->schdTime = sfInfo->timingInfo;
2292
2293 #ifdef LTE_ADV
2294    rgLaaInitTbInfoLst(cell);
2295 #endif
2296
2297    /* Fix : syed Ignore Failure Returns and continue processing.
2298     * Incomplete processing results in state sync loss between MAC-SCH. */
2299 #ifdef EMTC_ENABLE
2300     if(TRUE == cell->emtcEnable)
2301     {
2302        rgEmtcHndl(cell, sfInfo);
2303     }
2304 #endif
2305    rgHndlCmnChnl(cell, sfInfo->timingInfo, &sfInfo->cmnLcInfo, &err);
2306
2307    rgHndlRaResp(cell, sfInfo->timingInfo, &sfInfo->rarInfo, &err);
2308
2309 #ifdef LTE_ADV
2310 #ifdef XEON_SPECIFIC_CHANGES
2311    CM_MEAS_TIME((cell->crntTime.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_B4_UE_SCHD);
2312 #endif
2313    rgHndlSchdUe(cell, sfInfo->timingInfo, &sfInfo->ueInfo, &err);
2314 #ifdef XEON_SPECIFIC_CHANGES
2315    CM_MEAS_TIME((cell->crntTime.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_UE_SCHD);
2316 #endif
2317    rgLaaChkAndReqTbs(dlSf,cell, inst);
2318
2319 #else
2320    rgHndlSchdUe(cell, sfInfo->timingInfo, &sfInfo->ueInfo, &err);
2321 #endif
2322
2323 #ifdef LTE_L2_MEAS
2324    if(rgHndlUlUeInfo(cell, sfInfo->ulUeInfo.timingInfo, 
2325                      &sfInfo->ulUeInfo) != ROK)
2326    {
2327       RETVALUE(RFAILED);
2328    }
2329 #endif
2330 #ifdef XEON_SPECIFIC_CHANGES
2331    CM_MEAS_TIME((cell->crntTime.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_MEAS);
2332 #endif
2333    /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
2334       RLC-MAC */
2335
2336
2337    /* Added the handling for pushing down
2338     * TFU Data request in the retransmission only scenario.*/ 
2339 #ifdef LTEMAC_DLUE_TMGOPTMZ
2340    dlSf->statIndDone = TRUE;
2341    /* Fix [ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
2342       RLC-MAC */
2343    if(!(dlSf->txDone) && 
2344 #ifdef LTE_ADV
2345          (TRUE == rgLaaChkAllRxTbs(dlSf)) && 
2346 #endif
2347          (0 == dlSf->remDatReqCnt) && (dlSf->statIndDone) && 
2348         (RG_TIMEINFO_SAME(cell->crntTime, dlSf->schdTime)))
2349    {
2350       /*This is the case of rettransmission, so no need
2351        * to wait for TTI Ind to push TFU Data Request. Send
2352        * it right away.*/
2353       if (ROK != rgTOMUtlProcDlSf (dlSf, cell, &err))
2354       {
2355          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Unable to process downlink subframe for cell");
2356          err.errType = RGERR_ROM_DEDDATREQ;
2357       }
2358       /* Mark this frame as sent */
2359       dlSf->txDone = TRUE;
2360    }
2361 #endif
2362    if (sfInfo->flowCntrlInfo.numUes > 0)
2363    {
2364      rgHndlFlowCntrl(cell,sfInfo);
2365    }
2366    /*stoping Task*/
2367    SStopTask(startTime, PID_MAC_SF_ALLOC_REQ);
2368    RETVALUE(ROK);
2369 } /* end of RgSchMacSfAllocReq */
2370 /**
2371  * @brief Handler for processing data indication recieved from PHY for UEs.
2372  *
2373  * @details
2374  *
2375  *     Function: rgTOMProcCrntiCEInDatInd
2376  *
2377  *     Handler for processing data indication recieved from PHY for UEs.
2378  *
2379  *     Invoked by: RgLiTfuDatInd of LIM 
2380  *
2381  *     Processing Steps: 
2382  *     For each DataInfo recieved
2383  *      - If  received a CRNTI control element 
2384  *          - Check if a CCCH SDU is present, if it is return failure
2385  *          - Check for the existence of UE, if its isnt present return failure.
2386  *          - Delegate the remaining processing to rgTOMUtlProcMsg3 which
2387  *          primarily informs the scheduler about the data received and
2388  *          generates Data indications towards the higher layer.
2389  *           
2390  *  @param      RgMacPdu          *pdu,
2391  *  @param      RgUeCb            *prevUeCb,
2392  *  @param      RgCellCb          *cellCb,
2393  *  @param      TfuDatInfo        *datInfo,
2394  *  @param      RgInfCeInfo       *ceInfo
2395  *  @return  S16
2396  *      -# ROK 
2397  *      -# RFAILED 
2398  **/
2399 #ifdef ANSI
2400 PRIVATE S16 rgTOMProcCrntiCEInDatInd
2401 (
2402 RgMacPdu          *pdu,
2403 RgUeCb            *prevUeCb,
2404 RgCellCb          *cellCb,
2405 TfuDatInfo        *datInfo,
2406 RgInfCeInfo       *ceInfo,
2407 U16               slot
2408 )
2409 #else
2410 PRIVATE S16 rgTOMProcCrntiCEInDatInd( pdu, prevUeCb, cellCb, datInfo, ceInfo, slot)
2411 RgMacPdu          *pdu;
2412 RgUeCb            *prevUeCb;
2413 RgCellCb          *cellCb;
2414 TfuDatInfo        *datInfo;
2415 RgInfCeInfo       *ceInfo;
2416 U16               slot;
2417 #endif
2418 {
2419    RgUeCb *ueCb = NULLP;
2420    Inst   inst  = cellCb->macInst - RG_INST_START;
2421
2422
2423 #ifdef LTEMAC_SPS
2424    Bool spsToBeActvtd;
2425    U16  sduSize;
2426 #endif
2427
2428    TRC2(rgTOMProcCrntiCEInDatInd)
2429
2430 #ifndef LTE_L2_MEAS      
2431       UNUSED(slot);
2432 #endif
2433
2434    ueCb = rgDBMGetUeCbFromRachLst (cellCb, datInfo->rnti);
2435
2436    if (ueCb == NULLP)
2437    {
2438        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2439                 "RNTI:%d Received MSG3 with CRNTI,unable to find ueCb", ceInfo->ces.cRnti);
2440        RETVALUE(RFAILED);
2441    }
2442
2443    prevUeCb = rgDBMGetUeCb (cellCb, ceInfo->ces.cRnti);
2444    if (prevUeCb == NULLP)
2445    {
2446        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2447                  "RNTI:%d Received MSG3 with CRNTI,unable to find ueCb", ceInfo->ces.cRnti);
2448        RETVALUE(RFAILED);
2449    }
2450    RLOG_ARG2(L_DEBUG,DBG_CELLID,cellCb->cellId,
2451             "CRNTI CE(%d) received through tmpCrnti(%d)",
2452             ceInfo->ces.cRnti, datInfo->rnti);
2453    rgDBMDelUeCbFromRachLst(cellCb, ueCb);
2454    rgRAMFreeUeCb(inst,ueCb);
2455    ueCb = prevUeCb;
2456 #ifdef LTEMAC_SPS
2457    if ((rgTOMUtlProcMsg(cellCb, ueCb, pdu, FALSE,&spsToBeActvtd,&sduSize, slot, NULLP)) != ROK)
2458 #else
2459    if ((rgTOMUtlProcMsg (cellCb, ueCb, pdu, slot, NULLP)) != ROK)
2460 #endif /* LTEMAC_SPS */
2461    {
2462        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2463                        "RNTI:%d Processing for MSG3 failed",datInfo->rnti);
2464        RETVALUE(RFAILED);
2465    }
2466    RETVALUE(ROK);
2467 }
2468 /**
2469  * @brief Handler for processing data indication recieved from PHY for UEs.
2470  *
2471  * @details
2472  *
2473  *     Function: rgTOMProcCCCHSduInDatInd
2474  *
2475  *     Handler for processing data indication recieved from PHY for UEs.
2476  *
2477  *     Invoked by: RgLiTfuDatInd of LIM 
2478  *
2479  *     Processing Steps: 
2480  *     For each DataInfo recieved
2481  *      - If only CCCH SDU is present
2482  *        - Invoke rgTOMUtlProcMsg3 for further processing.
2483  *      - If its a non-Msg3 PDU i.e. received outside of a RA procedure
2484  *        - Retrieve the UeCB 
2485  *        - Validate that the received PDU contains only configured Logical
2486  *        Channels.
2487  *        - Invoke rgTOMUtlProcDatPdu for further processing. It informs the
2488  *        scheduler with the information of the received Data and generates
2489  *        DatIndications towards the higher layers. 
2490  *           
2491  *  @param  TfuDatIndInfo *datInd
2492  *  @param  RgMacPdu          *pdu,
2493  *  @param  RgUeCb            *prevUeCb,
2494  *  @param  RgCellCb          *cellCb,
2495  *  @param  TfuDatInfo        *datInfo,
2496  *  @param  RgInfCeInfo       *ceInfo
2497  *  @return  S16
2498  *      -# ROK 
2499  *      -# RFAILED 
2500  **/
2501 #ifdef ANSI
2502 PRIVATE S16 rgTOMProcCCCHSduInDatInd
2503 (
2504 RgMacPdu          *pdu,
2505 RgUeCb            *prevUeCb,
2506 RgCellCb          *cellCb,
2507 TfuDatInfo        *datInfo,
2508 RgInfCeInfo       *ceInfo,
2509 U16               slot 
2510 )
2511 #else
2512 PRIVATE S16 rgTOMProcCCCHSduInDatInd( pdu, prevUeCb, cellCb, datInfo, ceInfo, slot)
2513 RgMacPdu          *pdu;
2514 RgUeCb            *prevUeCb;
2515 RgCellCb          *cellCb;
2516 TfuDatInfo        *datInfo;
2517 RgInfCeInfo       *ceInfo;
2518 U16               slot;
2519 #endif
2520 {
2521    RgUeCb *ueCb = NULLP;
2522    Inst   inst  = cellCb->macInst - RG_INST_START;
2523
2524 #ifdef LTEMAC_SPS
2525    Bool spsToBeActvtd;
2526    U16  sduSize;
2527 #endif
2528
2529
2530    TRC2(rgTOMProcCCCHSduInDatInd)
2531
2532 #ifndef LTE_L2_MEAS      
2533       UNUSED(slot);
2534 #endif
2535
2536    if (ceInfo->bitMask & RG_CRNTI_CE_PRSNT)
2537    {
2538        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2539                        "CRNTI:%d Received MSG3 with CCCH",ceInfo->ces.cRnti);
2540        RETVALUE(RFAILED);
2541    }
2542    
2543    ueCb = rgDBMGetUeCbFromRachLst (cellCb, datInfo->rnti);
2544    
2545    if (ueCb == NULLP)
2546    {
2547        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2548                        "RNTI:%d Processing for MSG3 failed", datInfo->rnti);
2549        RETVALUE(RFAILED);
2550    }
2551    /* Fix: syed Drop any duplicate Msg3(CCCH Sdu) */
2552    if (ueCb->dl.hqEnt.numHqProcs)
2553    {
2554       /* HqE is already initialized by a previuos Msg3 */ 
2555        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"RNTI:%d Processing for MSG3 failed. Duplicate "
2556           "MSG3 received. Dropping", datInfo->rnti);
2557        RETVALUE(RFAILED);
2558    }
2559    
2560    if(rgDHMHqEntInit(inst,&ueCb->dl.hqEnt,
2561                      cellCb->maxDlHqProcPerUe) != ROK)
2562    {
2563        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"RNTI:%d Harq Initialization failed ", 
2564           datInfo->rnti);
2565        RETVALUE(RFAILED);
2566    }
2567     RLOG_ARG1(L_DEBUG,DBG_CELLID,cellCb->cellId,
2568              "CCCH SDU received through tmpCrnti(%d)",datInfo->rnti);
2569 #ifdef LTEMAC_SPS
2570    if ((rgTOMUtlProcMsg(cellCb, ueCb, pdu, FALSE,&spsToBeActvtd,&sduSize, slot, NULLP)) != ROK)
2571 #else
2572    if ((rgTOMUtlProcMsg (cellCb, ueCb, pdu, slot, NULLP)) != ROK)
2573 #endif /* LTEMAC_SPS */
2574    {
2575        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"RNTI:%d Processing for MSG3 failed", 
2576           datInfo->rnti);
2577        RETVALUE(RFAILED);
2578    }
2579    RETVALUE(ROK);
2580 }
2581
2582 #ifdef LTE_L2_MEAS
2583
2584 /** @brief This function captures the BSR value from Control Element
2585  *  Info structure and updates the effective Buffer size into the 
2586  *  corresponding LCG ID. 
2587  *
2588  * @details 
2589  *
2590  *     Function: rgTOMUtlL2MStoreBufSz
2591  *
2592  *         Processing steps:
2593  *         - update/append the Data structure based on BSR type 
2594  *
2595  * @param  [in] RgUeCb     *ueCb
2596  * @param  [in] RgInfCeInfo *ceInfo
2597  * @return S16
2598  */
2599
2600 #ifdef ANSI
2601 PRIVATE S16 rgTOMUtlL2MStoreBufSz
2602 (
2603  RgUeCb      *ueCb,
2604  RgInfCeInfo *ceInfo
2605  )
2606 #else
2607 PRIVATE S16 rgTOMUtlL2MStoreBufSz (ueCb, ceInfo)
2608  RgUeCb      *ueCb;
2609  RgInfCeInfo *ceInfo;
2610 #endif
2611 {
2612    U8 lcgId;
2613    U8 bsr;
2614    TRC2(rgTOMUtlL2MStoreBufSz);
2615
2616    if(ceInfo->bitMask & RG_TRUNC_BSR_CE_PRSNT)
2617    {
2618       lcgId = ((ceInfo->ces.bsr.truncBsr >> 6) & 0x03);
2619       bsr = ceInfo->ces.bsr.truncBsr & 0x3F;
2620       ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = rgLwrBsrTbl[bsr];
2621    }
2622    else if(ceInfo->bitMask & RG_SHORT_BSR_CE_PRSNT)
2623    {
2624       lcgId = ((ceInfo->ces.bsr.shortBsr >> 6) & 0x03);
2625       bsr = ceInfo->ces.bsr.shortBsr & 0x3F;
2626       ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = rgLwrBsrTbl[bsr];
2627
2628    }
2629    else if(ceInfo->bitMask & RG_LONG_BSR_CE_PRSNT)
2630    {
2631       ueCb->ul.lcgArr[0].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs1];
2632       ueCb->ul.lcgArr[1].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs2];
2633       ueCb->ul.lcgArr[2].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs3];
2634       ueCb->ul.lcgArr[3].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs4];
2635    }
2636    RETVALUE(ROK);
2637 } /* end of rgTOMUtlL2MStoreBufSz*/
2638
2639 /** @brief : Compiles list of LCs received in UL data for DTCH RBs
2640  *
2641  * @details
2642  *
2643  * @param  [in] RgCellCb   *cellCb
2644  * @param  [in] RgUeCb     *ueCb
2645  * @param  [in] CmLteRnti  rnti
2646  * @param  [in] RgMacPdu   *pdu
2647  * @param 
2648  *  @return  S16
2649  *      -# ROK 
2650  *      -# RFAILED 
2651  */
2652 #ifdef ANSI
2653 PRIVATE Void rgTOML2MCompileActiveLCs
2654 (
2655  RgCellCb      *cellCb, 
2656  RgUeCb        *ueCb,
2657  RgMacPdu      *pdu,
2658  RgInfCeInfo   *ceInfo 
2659  )
2660 #else
2661 PRIVATE Void rgTOML2MCompileActiveLCs(cellCb, ueCb, pdu, ceInfo)
2662    RgCellCb      *cellCb; 
2663    RgUeCb        *ueCb;
2664    RgMacPdu      *pdu;
2665    RgInfCeInfo   *ceInfo; 
2666 #endif 
2667 {
2668    CmLList           *node;
2669    RgMacSdu          *sdu;
2670    RgUlLcCb          *ulLcCb;
2671
2672    TRC2(rgTOML2MCompileActiveLCs)
2673
2674    node =  pdu->sduLst.first;
2675    while (node)
2676    {
2677       sdu = (RgMacSdu*)node->node;
2678       
2679       if ((ulLcCb = rgDBMGetUlDedLcCb(ueCb, sdu->lcId)), ulLcCb != NULLP)
2680       {
2681          if (ulLcCb->lcgId != 0)
2682          {
2683             ceInfo->bitMask |= RG_ACTIVE_LC_PRSNT;
2684             ceInfo->ulActLCs[ulLcCb->lcId - 1] = TRUE;
2685          }
2686       }
2687       node = node->next;
2688    }
2689
2690 } /* end of */ 
2691
2692
2693
2694 #endif
2695 /**********************************************************************
2696  
2697          End of file
2698 **********************************************************************/