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