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