ODUHIGH-199:Addressing mux review comments
[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    buildAndSendMuxPdu(slotInd);
601
602    /* Trigger for DL TTI REQ */
603    handleDlTtiReq(slotInd);
604
605    /* Trigger for UL TTI REQ */
606    handleUlTtiReq(slotInd);
607
608    dlSf = &cellCb->subFrms[(slotInd.slot % RG_NUM_SUB_FRAMES)];
609
610    if((dlSf->txDone == TRUE) ||
611       (!RG_TIMEINFO_SAME(slotInd,dlSf->schdTime)))
612    {
613    /* MS_WORKAROUND */
614 #ifndef LTEMAC_DLUE_TMGOPTMZ
615       TfuDatReqInfo     *datInfo;
616      CmLteTimingInfo   timingInfo;
617 #ifdef TFU_DL_DELTA_CHANGE
618          RGADDTOCRNTTIME(cellCb->crntTime, timingInfo, TFU_DLDATA_DLDELTA);
619 #else
620          RGADDTOCRNTTIME(cellCb->crntTime, timingInfo, TFU_DELTA);
621 #endif
622      /* Fill Data Request from MAC for BCH  */
623      if ((timingInfo.sfn % 4 == 0) && (timingInfo.slot == 0))
624      {
625          if (ROK != rgAllocEventMem(inst,(Ptr *)&datInfo, 
626                             sizeof(TfuDatReqInfo)))
627          {
628             RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
629                 "rgTOMUtlProcDlSf() Unable to Allocate TfuDatReqInfo for cell");
630             RETVALUE(RFAILED);
631          }
632          else
633          {
634             cmLListInit(&datInfo->pdus);
635             datInfo->cellId = cellCb->cellId;
636             datInfo->bchDat.pres = NOTPRSNT;
637             datInfo->timingInfo = timingInfo;
638             
639                                    
640           /* sending the dummy data req to Phy */
641             if (rgLIMTfuDatReq(inst,datInfo) != ROK)
642             {
643                RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
644                          "rgTOMUtlProcDlSf() Unable to send data info for cell");
645             }
646          
647          }
648      }      
649 #endif
650       /* Freeing as the part of CL Non RT Indication */
651       /* TDOD : Generalize for all SOCs */
652 #if !(defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD))
653       rgDHMFreeTbBufs(inst);
654 #endif
655       RETVALUE(ROK);
656    }
657
658    /*Return if there is still some data to be received
659      from RLC for this DL SF. */
660 /* ADD Changes for Downlink UE Timing Optimization */
661 #ifdef LTEMAC_DLUE_TMGOPTMZ
662    if(0 != dlSf->remDatReqCnt) 
663    {
664       /* Freeing as the part of CL Non RT Indication */
665       /* TODO : Generalize for all SOCs and remove this flag */
666 #if !(defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD))
667       rgDHMFreeTbBufs(inst);
668 #endif
669       RETVALUE(ROK);
670    }
671 #endif
672
673 #ifdef XEON_SPECIFIC_CHANGES
674    CM_MEAS_TIME((slotInd.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_DL_BR_PRC);
675 #endif
676
677    if (ROK != rgTOMUtlProcDlSf (dlSf, cellCb, &err))
678    {
679       //RLOG_ARG0(L_ERROR,DBG_CELLID,slotInd->cellId,
680       //              "Unable to process downlink subframe for cell");
681       err.errType = RGERR_TOM_TTIIND;
682    }
683 #ifdef XEON_SPECIFIC_CHANGES
684    CM_MEAS_TIME((slotInd->slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_DL_AFTER_PRC);
685 #endif
686
687    /* Mark this frame as sent */
688    dlSf->txDone = TRUE;
689
690    /* Freeing as the part of CL Non RT Indication */
691    /* TODO : Generalize for all SOCs and remove this flag */
692 #if !(defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD))
693    rgDHMFreeTbBufs(inst);
694 #endif 
695    RETVALUE(ROK);
696 }  /* macProcessSlotInd */
697
698 /** @brief This function allocates the RgMacPdu that will be populated by DEMUX
699  * with the SubHeaders list and the values of the Control elements.
700  *
701  * @details
702  *
703  *     Function: rgTOMUtlAllocPduEvnt
704  *
705  *         Processing steps:
706  *  @param[in]  Inst        inst
707  * @param  [out] RgMacPdu   **pdu
708  *
709  *  @return  S16
710  *      -# ROK 
711  *      -# RFAILED 
712  */
713 #ifdef ANSI
714 PRIVATE S16 rgTOMUtlAllocPduEvnt 
715 (
716 Inst             inst,
717  RgMacPdu         **pdu
718  )
719 #else
720 PRIVATE S16 rgTOMUtlAllocPduEvnt (inst,pdu)
721 Inst             inst;
722    RgMacPdu         **pdu;
723 #endif
724 {
725
726    Mem               evntMem;
727    RgUstaDgn         dgn;      /* Alarm diagnostics structure */
728    VOLATILE U32      startTime=0;
729
730    TRC2(rgTOMUtlAllocPduEvnt);
731
732    evntMem.region = rgCb[inst].rgInit.region;
733    evntMem.pool   = rgCb[inst].rgInit.pool;
734
735    /*starting Task*/
736    SStartTask(&startTime, PID_TOMUTL_CMALLCEVT);
737
738 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
739    MS_BUF_ADD_ALLOC_CALLER();
740 #endif /* */
741
742    if (cmAllocEvnt (sizeof (RgMacPdu), RG_BLKSZ, &evntMem, (Ptr*)pdu) != ROK)
743    {
744       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
745       rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
746                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
747       RLOG0(L_ERROR,"Allocation of DUX event failed");
748       RETVALUE(RFAILED);
749    }
750
751    /*stoping Task*/
752    SStopTask(startTime, PID_TOMUTL_CMALLCEVT);
753
754    RETVALUE(ROK);
755 } /* end of */ 
756
757 /** @brief This function frees up the RgMacPdu structure that has been
758  * populated by demux.
759  *
760  * @details
761  *
762  *     Function: rgTOMUtlFreePduEvnt
763  *       - Function frees up the RgMacPdu structure, in case of error it shall
764  *       free up the buffer's present in the different sdu.
765  *
766  *         Processing steps:
767  * @param  [in]  Inst        inst
768  * @param  [in] RgMacPdu   *pdu
769  * @param  [in] Bool       *error
770  * @return 
771  */
772 #ifdef ANSI
773 PRIVATE Void rgTOMUtlFreePduEvnt
774 (
775  RgMacPdu *pdu,
776  Bool      error
777  )
778 #else
779 PRIVATE Void rgTOMUtlFreePduEvnt (pdu, error)
780    RgMacPdu *pdu;
781    Bool      error;
782 #endif
783 {
784
785    RgMacSdu       *sdu;
786    CmLList        *node;
787
788    TRC2(rgTOMUtlFreePduEvnt);
789    /* Steps of freeing up the PDU.
790     * 1. loop through the subHdrLst and free up all the buffers.
791     * 2. free up the whole event
792     */
793    if ((error == TRUE) && (pdu->sduLst.count > 0))
794    {
795       node =  pdu->sduLst.first;
796       while (node)
797       {
798          sdu = (RgMacSdu*)node->node;
799          RG_FREE_MSG(sdu->mBuf);
800          node = node->next;
801       }
802    }
803    RG_FREE_MEM(pdu);
804    RETVOID;
805 } /* end of rgTOMUtlFreePduEvnt */ 
806
807 /** @brief This function allocates the RgMacPdu that will be populated by DEMUX
808  * with the SubHeaders list and the values of the Control elements.
809  *
810  * @details
811  *
812  *     Function: rgTOMInfAllocPduEvnt
813  *
814  *         Processing steps:
815  * @param  [in] Inst        inst
816  * @param  [out] RgMacPdu   **pdu
817  *
818  *  @return  S16
819  *      -# ROK 
820  *      -# RFAILED 
821  */
822 #ifdef ANSI
823 PRIVATE S16 rgTOMInfAllocPduEvnt 
824 (
825 Inst           inst,
826 RgInfSfDatInd **sfInfo
827  )
828 #else
829 PRIVATE S16 rgTOMInfAllocPduEvnt (inst,sfInfo)
830 Inst             inst;
831 RgInfSfDatInd **sfInfo;
832 #endif
833 {
834
835    Mem               evntMem;
836    RgUstaDgn         dgn;      /* Alarm diagnostics structure */
837    VOLATILE U32      startTime=0;
838
839    TRC2(rgTOMInfAllocPduEvnt);
840
841    evntMem.region = rgCb[inst].rgInit.region;
842    evntMem.pool   = rgCb[inst].rgInit.pool;
843
844    /*starting Task*/
845    SStartTask(&startTime, PID_TOMINF_CMALLCEVT);
846
847 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
848    MS_BUF_ADD_ALLOC_CALLER();
849 #endif /* */
850    if (cmAllocEvnt (sizeof (RgInfSfDatInd), RG_BLKSZ, &evntMem, (Ptr*)sfInfo) != ROK)
851    {
852       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
853       rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
854                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
855       RLOG0(L_ERROR,"Allocation failed");
856       RETVALUE(RFAILED);
857    }
858
859    /*stoping Task*/
860    SStopTask(startTime, PID_TOMINF_CMALLCEVT);
861
862    RETVALUE(ROK);
863 } /* end of */ 
864
865 /** @brief This function frees up the RgMacPdu structure that has been
866  * populated by demux.
867  *
868  * @details
869  *
870  *     Function: rgTOMInfFreePduEvnt
871  *       - Function frees up the RgMacPdu structure, in case of error it shall
872  *       free up the buffer's present in the different sdu.
873  *
874  *         Processing steps:
875  * @param  [in] RgMacPdu   *pdu
876  * @param  [in] Bool       *error
877  * @return 
878  */
879 #ifdef ANSI
880 PRIVATE Void rgTOMInfFreePduEvnt
881 (
882 RgInfSfDatInd *sfInfo
883  )
884 #else
885 PRIVATE Void rgTOMInfFreePduEvnt (sfInfo)
886 RgInfSfDatInd *sfInfo;
887 #endif
888 {
889    TRC2(rgTOMInfFreePduEvnt);
890
891    RG_FREE_MEM(sfInfo);
892    RETVOID;
893 } /* end of rgTOMUtlFreePduEvnt */
894
895 #ifdef LTE_L2_MEAS
896
897 /** @brief This function performs the preparation of information needed to set
898  * L2M Scheduled UL Throughput Information for a particular UE.
899  *
900  * @details
901  *
902  *     Function: rgTomUtlPrepareL2MUlThrpInfo
903  *      This function performs the preparation of information needed to set
904  *       L2M Scheduled UL Throughput Information for a particular UE.
905  *
906  *
907  *         Processing steps:
908  * @param  [in] RgCellCb   *cellCb
909  * @param  [in] RgUeCb       *ueCb
910  * @param  [out] RgRguDedDatInd *dDatInd
911  * @return 
912  */
913 #ifdef ANSI
914 PRIVATE S16 rgTomUtlPrepareL2MUlThrpInfo
915 (
916    RgCellCb *cellCb,
917    RgUeCb  *ueCb,
918    RgRguDedDatInd  *dDatInd
919  )
920 #else
921 PRIVATE S16 rgTomUtlPrepareL2MUlThrpInfo(cellCb,ueCb,dDatInd)
922    RgCellCb *cellCb;
923    RgUeCb *ueCb;
924    RgRguDedDatInd    *dDatInd;
925 #endif
926 {
927    U8 lcId;
928    U8 lcgId;
929    U8 loop;
930    TRC2(rgTomUtlPrepareL2MUlThrpInfo);
931
932    dDatInd->burstInd = RGU_L2M_UL_BURST_END;
933    for(loop=0;loop<dDatInd->numLch;loop++)
934    {
935       lcId=dDatInd->lchData[loop].lcId;
936       if (lcId)
937       {
938          lcgId = ueCb->ul.lcCb[lcId - 1].lcgId;
939          if(ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs > 0)
940          {
941             dDatInd->burstInd = RGU_L2M_UL_BURST_START;
942             break;
943                   }
944                }
945    }
946
947    RETVALUE(ROK);
948 }
949
950 #endif
951
952 /** @brief This function is called by rgTOMDatInd. This function invokes the
953  * scheduler with the information of the received Data and any Control Elements
954  * if present. Also it generates Data indications towards the higher layers.
955  *
956  * @details
957  *
958  *     Function: 
959  *
960  *         Processing steps:
961  *         - Retrieves the RaCb with the rnti provided, if it doesnt exist
962  *         return failure. 
963  *         - If UE exists then update the Schduler with any MAC CEs if present. 
964  *         - Invoke RAM module to do Msg3 related processing rgRAMProcMsg3
965  *         - Loop through the SDU subheaders and invoke either a common data
966  *         indication (rgUIMSndCmnDatInd) or dedicated data indication
967  *         (rgUIMSndDedDatInd) towards the higher layers. 
968  *
969  * @param  [in] RgCellCb   *cellCb
970  * @param  [in] RgUeCb     *ueCb
971  * @param  [in] CmLteRnti  rnti
972  * @param  [in] RgMacPdu   *pdu
973  * @param  [out] U32       *lcgBytes
974  *  
975  *  @return  S16
976  *      -# ROK 
977  *      -# RFAILED 
978  */
979  RgUeCb  *glblueCb4;
980  RgUeCb  *glblueCb5;
981
982 #ifdef LTEMAC_SPS
983 #ifdef ANSI
984 PRIVATE S16 rgTOMUtlProcMsg
985 (
986  RgCellCb      *cellCb, 
987  RgUeCb        *ueCb,
988  RgMacPdu      *pdu,
989  Bool          isSpsRnti,
990  Bool          *spsToBeActvtd,
991  U16           *sduSize,
992  U16           slot,
993  U32           *lcgBytes
994  )
995 #else
996 PRIVATE S16 rgTOMUtlProcMsg(cellCb, ueCb, pdu, isSpsRnti,spsToBeActvtd,sduSize, slot, lcgBytes)
997    RgCellCb      *cellCb; 
998    RgUeCb        *ueCb;
999    RgMacPdu      *pdu;
1000    Bool          isSpsRnti;
1001    Bool          *spsToBeActvtd;
1002    U16           *sduSize;
1003    U16           slot;
1004    U32           *lcgBytes;
1005 #endif   
1006 #else /* LTEMAC_SPS */
1007 #ifdef ANSI
1008 PRIVATE S16 rgTOMUtlProcMsg
1009 (
1010  RgCellCb      *cellCb, 
1011  RgUeCb        *ueCb,
1012  RgMacPdu      *pdu,
1013  U16           slot,
1014  U32           *lcgBytes
1015  )
1016 #else
1017 PRIVATE S16 rgTOMUtlProcMsg(cellCb, ueCb, pdu, slot, lcgBytes)
1018    RgCellCb      *cellCb; 
1019    RgUeCb        *ueCb;
1020    RgMacPdu      *pdu;
1021    U16           slot;
1022    U32           *lcgByes;
1023 #endif  
1024 #endif
1025 {
1026    Inst              inst = cellCb->macInst - RG_INST_START;
1027    S16               ret;
1028    RgRguCmnDatInd    *cDatInd;
1029    RgRguDedDatInd    *dDatInd;
1030    CmLList           *node;
1031    RgMacSdu          *sdu;
1032    MsgLen            ccchSz;
1033    MsgLen            cpySz;
1034 #ifdef LTEMAC_SPS
1035    Pst               schPst1;  
1036 //   RgInfSpsRelInfo   relInfo;
1037 #endif
1038
1039 #ifdef LTE_L2_MEAS
1040    U8                idx1;
1041    U8                idx2;
1042    RgUlSf            *ulSf;
1043    U16               totalBytesRcvd = 0;
1044    U16               sduLen[RGU_MAX_LC] = {0};
1045    U8                qciVal[RGU_MAX_LC] = {0};
1046    U8                numPrb = 0;
1047
1048 #endif
1049    U8                lcgId;
1050    MsgLen            bufSz;
1051
1052   /* Moved outside of LTE_L2_MEAS
1053     *          scope as this pointer will now be used to 
1054     *          check for valid Logical Channel ID
1055    */
1056    RgUlLcCb          *ulLcCb;
1057    
1058    cDatInd  = NULLP;
1059    dDatInd  = NULLP;
1060 #ifdef LTE_L2_MEAS
1061    ulSf   = NULLP;
1062    idx1   = 0;
1063    idx2   = 0;
1064 #endif
1065 #ifdef SS_RBUF 
1066    Void *elem = NULLP;
1067 #endif
1068   
1069    ulLcCb = NULLP;
1070    
1071    TRC2(rgTOMUtlProcMsg)
1072
1073 #ifndef LTE_L2_MEAS      
1074       UNUSED(slot);
1075 #endif
1076
1077    if(pdu->sduLst.first)
1078    {
1079       sdu = (RgMacSdu*)(pdu->sduLst.first->node);
1080                         glblueCb4 = ueCb;
1081       if ((sdu->lcId == RG_CCCH_LCID))
1082       {
1083          /* code for common channel dat indications */
1084          if ((ret = rgAllocShrablSBuf (inst,(Data**)&cDatInd, sizeof(RgRguCmnDatInd))) != ROK)
1085          {
1086             RETVALUE(RFAILED);
1087          }
1088          cDatInd->cellId   = cellCb->cellId;
1089          cDatInd->rnti     = ueCb->ueId;
1090          /* rg001.101: Corrected lcId value for common data indication */
1091          cDatInd->lcId     = cellCb->ulCcchId;
1092          cDatInd->pdu      = sdu->mBuf;
1093          SFndLenMsg (sdu->mBuf, &ccchSz);
1094          /* Fix : syed Contention resolution ID copy should consider only
1095           * 6 bytes of information from sdu->mBuf. Incase of CCCH sdu for reest
1096           * message/psuedo reest message, ccchSz can go beyond 6 and can corrupt 
1097           * other fields of ueCb. */
1098          if (ccchSz >= RG_CRES_LEN)
1099          {
1100             SCpyMsgFix (sdu->mBuf, (MsgLen)0, RG_CRES_LEN, ueCb->contResId.resId,
1101                         &cpySz);
1102          }
1103 #ifdef XEON_SPECIFIC_CHANGES
1104          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);
1105 #endif
1106          sdu->mBuf = NULLP;
1107          rgUIMSndCmnDatInd(inst,cellCb->rguUlSap,cDatInd);
1108          RETVALUE(ROK);
1109       } /* end of common channel processing */
1110 #ifndef SS_RBUF 
1111       if ((ret = rgAllocShrablSBuf (inst,(Data**)&dDatInd, sizeof(RgRguDedDatInd))) != ROK)
1112       {
1113          RETVALUE(RFAILED);
1114       }
1115 #else
1116                         glblueCb5 = ueCb;
1117       elem = SRngGetWIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
1118       if (NULLP == elem)
1119       { 
1120          RETVALUE(RFAILED);
1121       }
1122       dDatInd = (RgRguDedDatInd *)elem;
1123       cmMemset((U8 *)dDatInd, 0x00, sizeof(RgRguDedDatInd));
1124 #endif
1125       dDatInd->cellId   = cellCb->cellId;
1126       dDatInd->rnti     = ueCb->ueId;
1127       dDatInd->numLch   = 0;
1128    }
1129 #ifdef LTE_L2_MEAS
1130    ulSf = &cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)];
1131    if(ulSf->ueUlAllocInfo != NULLP)
1132    {
1133      for(idx1 = 0; idx1 < ulSf->numUe; idx1++)
1134      {
1135         if(ulSf->ueUlAllocInfo[idx1].rnti == ueCb->ueId)
1136         {
1137            numPrb = ulSf->ueUlAllocInfo[idx1].numPrb;
1138            break;
1139         }
1140      }
1141    }
1142 #endif
1143    node =  pdu->sduLst.first;
1144    while (node)
1145    {
1146       sdu = (RgMacSdu*)node->node;
1147       
1148       ulLcCb = rgDBMGetUlDedLcCb (ueCb, sdu->lcId);
1149       
1150       if(ulLcCb == NULLP)
1151       {
1152          RLOG_ARG2(L_ERROR,DBG_CELLID,cellCb->cellId,"Unconfigured LCID:%d CRNTI:%d"
1153                          ,sdu->lcId,ueCb->ueId);
1154          /* ccpu00128443: Fix for memory leak */
1155          /* Fix : syed Neccessary to set sdu->mBuf = NULLP */
1156          RG_FREE_MSG(sdu->mBuf);         
1157          node = node->next;
1158          continue;
1159       }
1160 #ifdef RLC_STA_PROC_IN_MAC/* RLC Status PDU Processing */
1161       {
1162          extern S16 kwProcDlStatusPdu(Pst       *udxPst,SuId      suId,
1163                CmLteCellId cellId,CmLteRnti rnti,CmLteLcId lcId,Buffer *rlcSdu);
1164
1165          if(ROK == kwProcDlStatusPdu(&(cellCb->rguDlSap->sapCfg.sapPst),
1166                   cellCb->rguDlSap->sapCfg.suId,
1167                   cellCb->cellId,ueCb->ueId,sdu->lcId,sdu->mBuf))
1168          {
1169             RG_FREE_MSG(sdu->mBuf);           
1170             node = node->next;
1171             continue;
1172          }
1173       }
1174 #endif
1175
1176       /* ccpu00116477- Fixed the rgUIMSndDedDatInd condition when we receive 11 sdus in the 
1177        * list we are losing 11th sdu and sending the first 10 sdus again which
1178        * is causing the duplicate packets and eNB crashing due to access
1179        * of the freed memory */
1180       if (dDatInd->numLch >= RGU_MAX_LC)
1181       {
1182          if ((ret = rgUIMSndDedDatInd(inst,ueCb->rguUlSap,dDatInd)) != ROK)
1183          {
1184             RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
1185                 "Failed to send datIndication to RGU CRNTI:%d",ueCb->ueId);
1186             RETVALUE(ret);
1187          }
1188 #ifndef SS_RBUF
1189          if ((ret = rgAllocShrablSBuf (inst,(Data**)&dDatInd, sizeof(RgRguDedDatInd))) != ROK)
1190          {
1191             RETVALUE(RFAILED);
1192          }
1193 #else
1194       elem = SRngGetWIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
1195       if (NULLP == elem)
1196       { 
1197          RETVALUE(RFAILED);
1198       }
1199       dDatInd = (RgRguDedDatInd *)elem;
1200       cmMemset((U8 *)dDatInd, 0x00, sizeof(RgRguDedDatInd));
1201 #endif
1202          dDatInd->cellId   = cellCb->cellId;
1203          dDatInd->rnti     = ueCb->ueId;
1204          dDatInd->numLch   = 0;
1205       }
1206       dDatInd->lchData[dDatInd->numLch].lcId = sdu->lcId;
1207       dDatInd->lchData[dDatInd->numLch].pdu.mBuf[dDatInd->lchData[dDatInd->numLch].pdu.numPdu] = sdu->mBuf;
1208       dDatInd->lchData[dDatInd->numLch].pdu.numPdu++;
1209       lcgId = ulLcCb->lcgId;
1210       SFndLenMsg(sdu->mBuf, &bufSz);
1211 #ifdef LTE_L2_MEAS
1212       if(ulLcCb->measOn)
1213       {
1214          ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs -= bufSz; 
1215       }
1216 #endif
1217       //if ((lcgBytes != NULLP) && (ueCb->ul.lcgArr[lcgId].isGbr == TRUE))
1218       if (lcgBytes != NULLP)
1219       {
1220          lcgBytes[lcgId] += bufSz;
1221       }
1222       sdu->mBuf = NULLP;
1223       dDatInd->numLch++;
1224 #ifdef LTEMAC_SPS
1225       /* Check if data has come on SPS LC */
1226       /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
1227       if (ueCb->ul.spsLcId[sdu->lcId-1] == TRUE)
1228       {
1229          ueCb->ul.spsDatRcvd++;
1230       }
1231             
1232       if(isSpsRnti)
1233       {
1234          /* Data rcvd on CRNTI*/
1235          /* Retrieve the LCG ID of the LCID*/
1236          /* SPS LCG has data whose size > SID Size */
1237          /* Activate SPS if data recvd on SPS LCID and size > SID Packet Size */
1238          if((ueCb->ul.spsLcId[sdu->lcId-1] == TRUE) &&
1239             (sdu->len > RG_SPS_SID_PACKET_SIZE))
1240          {
1241              *spsToBeActvtd = TRUE;
1242              *sduSize = sdu->len;
1243          }
1244       }
1245       
1246 #endif  
1247
1248 #ifdef LTE_L2_MEAS
1249       if(cellCb->qciArray[ulLcCb->qci].mask == TRUE)
1250       {
1251            sduLen[ulLcCb->qci] = sdu->len;
1252            totalBytesRcvd += sdu->len;
1253            qciVal[ulLcCb->qci] = ulLcCb->qci;
1254       }
1255 #endif
1256       node = node->next;
1257    } /* end of while for SubHeaders */
1258 #ifdef LTE_L2_MEAS
1259    for(idx2 = 0; idx2 < RGU_MAX_LC; idx2++)
1260    {
1261       if((cellCb->qciArray[qciVal[idx2]].mask == TRUE) &&
1262           totalBytesRcvd > 0)
1263       {
1264          cellCb->qciArray[qciVal[idx2]].prbCount += 
1265          ((numPrb * sduLen[idx2]) / totalBytesRcvd);
1266       }
1267       
1268       /* RRM_RBC_X */
1269       if(totalBytesRcvd > 0 && qciVal[idx2] > 0)
1270       {
1271          RG_UPD_GBR_PRB(cellCb, qciVal[idx2], ((numPrb * sduLen[idx2])/totalBytesRcvd));
1272       }
1273       /* RRM_RBC_Y */
1274    }
1275 #endif
1276 /*Added for explicit release - start*/
1277 #ifdef LTEMAC_SPS
1278
1279    if(isSpsRnti && dDatInd && dDatInd->numLch)
1280    {
1281       if(ueCb->ul.spsDatRcvd != 0)
1282       {
1283          ueCb->ul.explRelCntr = 0;
1284          ueCb->ul.spsDatRcvd = 0;
1285       }
1286       else
1287       {
1288          ueCb->ul.explRelCntr++;
1289          if (ueCb->ul.explRelCntr == ueCb->ul.explRelCnt)
1290          {
1291             ueCb->ul.explRelCntr = 0;
1292             /* Indicate scheduler for explicit release */
1293             cmMemset((U8*)&schPst1, (U8)0, sizeof(Pst));
1294             rgGetPstToInst(&schPst1,inst, cellCb->schInstMap.schInst);
1295            //TODO: commented for compilation without SCH 
1296 #if 0
1297             relInfo.cellSapId = cellCb->schInstMap.cellSapId;
1298             relInfo.cRnti = ueCb->ueId;
1299             relInfo.isExplRel = TRUE;
1300             /* Release indicator is called now through the matrix in the function below */
1301             //TODO: commented for compilation without SCH RgMacSchSpsRel( &schPst1, &relInfo );
1302 #endif
1303             ueCb->ul.implRelCntr = 0;
1304          }
1305       }
1306    } 
1307    else
1308    {
1309       /* SPS_FIX */
1310       if(ueCb->ul.spsDatRcvd != 0)
1311       {
1312          //ueCb->ul.implRelCntr = 0;
1313          ueCb->ul.explRelCntr = 0;
1314          ueCb->ul.spsDatRcvd = 0;
1315       }
1316    }
1317 #endif
1318    /*Added for explicit release - end */
1319
1320    if((dDatInd) && (dDatInd->numLch))
1321    {
1322 #ifdef LTE_L2_MEAS
1323       rgTomUtlPrepareL2MUlThrpInfo(cellCb, ueCb,dDatInd);
1324
1325       RG_CALC_TTI_CNT(cellCb, dDatInd->ttiCnt); 
1326 #endif
1327       if ((ret = rgUIMSndDedDatInd(inst,ueCb->rguUlSap,dDatInd)) != ROK)
1328       {
1329          RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
1330                 "Failed to send datIndication to RGU CRNTI:%d",ueCb->ueId);
1331          RETVALUE(ret);
1332       }
1333    }
1334 #ifndef SS_RBUF
1335    else if((dDatInd) && (0 == dDatInd->numLch))
1336    {
1337       /* Free the memory allocated for dDatInd if we 
1338        * have no valid LCH PDU to send to RLC.*/
1339       rgFreeSharableSBuf(inst,(Data **)&dDatInd,sizeof(RgRguDedDatInd)); 
1340    }
1341 #endif
1342    RETVALUE(ROK);
1343 } /* end of */ 
1344
1345 /** @brief This function frees up the RgMacPdu structure that has been
1346  * populated by demux.
1347  *
1348  * @details
1349  *
1350  *     Function: rgTOMUtlInsSchInfo
1351  *       - Function frees up the RgMacPdu structure, in case of error it shall
1352  *       free up the buffer's present in the different sdu.
1353  *
1354  *         Processing steps:
1355  * @param  [in] RgMacPdu   *pdu
1356  * @param  [in] Bool       *error
1357  * @return 
1358  */
1359 #ifdef LTEMAC_SPS
1360 #ifdef ANSI
1361 PRIVATE S16 rgTOMUtlInsSchInfo
1362 (
1363 RgMacPdu *pdu,
1364 RgInfSfDatInd *sfInfo,
1365 RgInfCeInfo *ceInfo,
1366 CmLteRnti   rnti,
1367 Bool        spsToBeActvtd,
1368 U16         sduSize,
1369 U32         *lcgBytes
1370 )
1371 #else
1372 PRIVATE S16 rgTOMUtlInsSchInfo (pdu, sfInfo, ceInfo, rnti,spsToBeActvtd,sduSize, lcgBytes)
1373 RgMacPdu *pdu;
1374 RgInfSfDatInd *sfInfo;
1375 RgInfCeInfo *ceInfo;
1376 CmLteRnti   rnti;
1377 Bool        spsToBeActvtd;
1378 U16         sduSize;
1379 U32         *lcgBytes;
1380 #endif
1381
1382 #else
1383 #ifdef ANSI
1384 PRIVATE S16 rgTOMUtlInsSchInfo
1385 (
1386 RgMacPdu *pdu,
1387 RgInfSfDatInd *sfInfo,
1388 RgInfCeInfo *ceInfo,
1389 CmLteRnti   rnti,
1390 U32         *lcgBytes
1391 )
1392 #else
1393 PRIVATE S16 rgTOMUtlInsSchInfo (pdu, sfInfo, ceInfo, rnti, lcgBytes)
1394 RgMacPdu *pdu;
1395 RgInfSfDatInd *sfInfo;
1396 RgInfCeInfo *ceInfo;
1397 CmLteRnti   rnti;
1398 U32         *lcgBytes;
1399 #endif
1400 #endif
1401 {
1402    S16            ret;
1403    RgInfUeDatInd *ueInfo;
1404    U32           lcgId = 0;
1405    U32           idx = 0;
1406
1407    TRC2(rgTOMUtlInsSchInfo);
1408
1409    RG_TOM_INF_ALLOC(sfInfo, sizeof(RgInfUeDatInd), ueInfo, ret);
1410
1411    if(ROK != ret)
1412    {
1413       RETVALUE(RFAILED);
1414    }
1415
1416    ueInfo->rnti = rnti; 
1417       
1418    ueInfo->ceInfo = *ceInfo;
1419    ueInfo->ueLstEnt.node = (PTR)ueInfo;
1420    for (lcgId = 1, idx = 0; lcgId < RGINF_MAX_LCG_PER_UE; lcgId++)
1421    {
1422       if (lcgBytes[lcgId] != 0)
1423       {
1424          /* Only GBR bytes */
1425          ueInfo->lcgInfo[idx].lcgId     = lcgId;
1426          ueInfo->lcgInfo[idx++].bytesRcvd = lcgBytes[lcgId];
1427          lcgBytes[lcgId] = 0;
1428       }
1429    }
1430    cmLListAdd2Tail(&sfInfo->ueLst, &ueInfo->ueLstEnt);
1431    RETVALUE(ROK);
1432 } /* end of rgTOMUtlInsSchInfo */
1433
1434 #include <stdlib.h>
1435 /**
1436  * @brief Handler for processing data indication recieved from PHY for UEs.
1437  *
1438  * @details
1439  *
1440  *     Function: rgTOMDatInd
1441  *
1442  *     Handler for processing data indication recieved from PHY for UEs.
1443  *
1444  *     Invoked by: RgLiTfuDatInd of LIM 
1445  *
1446  *     Processing Steps: 
1447  *     For each DataInfo recieved
1448  *      - Validate the information received and retrieve cellCb 
1449  *        Validate cellId, rnti 
1450  *      - Call De-Mux module to decode the data rgDUXDemuxData
1451  *      - If  received a CRNTI control element 
1452  *          - Check if a CCCH SDU is present, if it is return failure
1453  *          - Check for the existence of UE, if its isnt present return failure.
1454  *          - Delegate the remaining processing to rgTOMUtlProcMsg3 which
1455  *          primarily informs the scheduler about the data received and
1456  *          generates Data indications towards the higher layer.
1457  *      - If only CCCH SDU is present
1458  *        - Invoke rgTOMUtlProcMsg3 for further processing.
1459  *      - If its a non-Msg3 PDU i.e. received outside of a RA procedure
1460  *        - Retrieve the UeCB 
1461  *        - Validate that the received PDU contains only configured Logical
1462  *        Channels.
1463  *        - Invoke rgTOMUtlProcDatPdu for further processing. It informs the
1464  *        scheduler with the information of the received Data and generates
1465  *        DatIndications towards the higher layers. 
1466  *           
1467  * @param  [in] Inst        inst
1468  *  @param[in]  TfuDatIndInfo *datInd
1469  *  @return  S16
1470  *      -# ROK 
1471  *      -# RFAILED 
1472  **/
1473 #ifdef ANSI
1474 PUBLIC S16 rgTOMDatInd
1475 (
1476 Inst           inst,
1477  TfuDatIndInfo *datInd
1478  )
1479 #else
1480 PUBLIC S16 rgTOMDatInd(inst,datInd)
1481 Inst             inst;
1482  TfuDatIndInfo *datInd;
1483 #endif
1484 {
1485    S16               ret = ROK;
1486    RgErrInfo         err;
1487    RgUeCb            *ueCb;
1488    RgUeCb            *prevUeCb = NULLP;
1489    RgCellCb          *cellCb;
1490    RgMacPdu          *pdu;
1491    RgInfSfDatInd     *sfInfo;
1492    RgInfCeInfo       ceInfo; 
1493    Pst               schPst;
1494    CmLList           *node;
1495    TfuDatInfo        *datInfo;
1496    RgLowSapCb        *tfuSap;
1497    U16               slot;
1498 #ifdef LTEMAC_SPS
1499    Bool              isSpsRnti=FALSE;
1500    Pst               schPst1;  
1501   // RgInfSpsRelInfo   relInfo;
1502         Bool              spsToBeActvtd = FALSE;
1503    U16               sduSize = 0;
1504 #endif
1505    U32               lcgBytes[RGINF_MAX_LCG_PER_UE];
1506
1507
1508    TRC2(rgTOMDatInd);
1509 #ifdef STUB_TTI_HANDLING_5GTF 
1510    node =  datInd->datIndLst.first;
1511    for (;node; node=node->next)
1512    {
1513       datInfo = (TfuDatInfo*)node->node;
1514       {
1515          MsgLen len;
1516          SFndLenMsg(datInfo->mBuf, &len);
1517          rgUlrate_tfu += len;
1518          if (rgUlrate_tfu > 100000)
1519          {
1520          printf("Sowmya:rgTOMDatInd datInfo->mBuf len =%d rgUlrate_tfu=%d",len,rgUlrate_tfu);
1521          rgUlrate_tfu = 0;
1522          }
1523       }
1524    }
1525       return(RFAILED);
1526 #endif      
1527
1528    cmMemset((U8 *)&lcgBytes, 0, sizeof(lcgBytes));
1529
1530    tfuSap = &(rgCb[inst].tfuSap);
1531    ueCb = NULLP;
1532    cellCb = rgCb[inst].cell;
1533    if((cellCb == NULLP) ||
1534       (cellCb->cellId != datInd->cellId))   
1535    {
1536        
1537       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"Unable to get the cellCb for cell");
1538       RETVALUE(RFAILED);
1539    }
1540    /* Avoiding memset as all the fields are getting initialized further */
1541
1542    if (rgTOMInfAllocPduEvnt (inst,&sfInfo) != ROK)
1543    {
1544       err.errType = RGERR_TOM_DATIND;
1545       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"Unable to Allocate PDU for DUX cell");
1546       node =  datInd->datIndLst.first;
1547       RETVALUE(RFAILED);
1548    }
1549    cmLListInit(&sfInfo->ueLst);
1550    sfInfo->cellId = datInd->cellId;
1551    sfInfo->timingInfo = datInd->timingInfo;
1552    slot = datInd->timingInfo.slot;
1553
1554    node =  datInd->datIndLst.first;
1555    for (;node; node=node->next)
1556    {
1557       datInfo = (TfuDatInfo*)node->node;
1558       {
1559          //extern U32 ulrate_tfu;
1560          MsgLen len;
1561          SFndLenMsg(datInfo->mBuf, &len);
1562 #ifdef STUB_TTI_HANDLING_5GTF         
1563        //  printf("Sowmya:rgTOMDatInd datInfo->mBuf len =%d",len);
1564 #endif
1565          rgUlrate_tfu += len;
1566 #ifdef EMTC_ENABLE
1567          grgUlrate_tfu += len;
1568 #endif
1569       }
1570 #ifdef STUB_TTI_HANDLING_5GTF         
1571       rgLIMUtlFreeDatIndEvnt(datInd,TRUE);
1572 #endif
1573       /* We shall call De-Mux to process the received buffer. We shall try and find
1574        * out the RaCb based on the following - 
1575        * 1. If the incoming PDU contained a CCCH SDU i.e. this is message 3.
1576        * 2. If the incoming PDU contained a CRNTI control element, i.e. we should
1577        * have a ueCb also for this 
1578        */
1579       /* Lets allocate the event that needs to be passed to DUX */
1580       if (rgTOMUtlAllocPduEvnt (inst,&pdu) != ROK)
1581       {
1582          err.errType = RGERR_TOM_DATIND;
1583          RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"Unable to Allocate PDU for DUX cell");
1584          rgTOMInfFreePduEvnt (sfInfo);
1585          RETVALUE(RFAILED);
1586       }
1587
1588       if ((ret = rgDUXDemuxData (inst,pdu, &ceInfo, 
1589                            &datInfo->mBuf, &err)) != ROK)
1590       {
1591          //exit(1);
1592          /* Fix: sriky memory corruption precautions */
1593          rgTOMUtlFreePduEvnt (pdu, TRUE);
1594          err.errType = RGERR_TOM_DATIND;
1595          RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"DUX processing failed");
1596          tfuSap->sapSts.numPduDrop++;
1597          continue; 
1598       }
1599       /* It could be that a non-msg3 pdu contains a CRNTI Control element. We
1600        * should check for CRNTI CE and if it exists the UECb must exist, also an
1601        * if the CRNTI in the CE and the one with which the message came in are
1602        * different we shall look for an raCb as well. 
1603        */
1604
1605       if (ceInfo.bitMask & RG_CCCH_SDU_PRSNT)
1606       {
1607         ret = rgTOMProcCCCHSduInDatInd(pdu, prevUeCb, \
1608                 cellCb, datInfo, &ceInfo, slot);
1609         if (ret == RFAILED)
1610         {
1611             rgTOMUtlFreePduEvnt (pdu, TRUE);
1612             err.errType = RGERR_TOM_DATIND;
1613             tfuSap->sapSts.numPduDrop++;
1614             continue; 
1615         }
1616       } /* end of Msg3 processing */
1617
1618       else if (ceInfo.bitMask & RG_CRNTI_CE_PRSNT)
1619       {
1620         ret = rgTOMProcCrntiCEInDatInd(pdu, prevUeCb, \
1621                 cellCb, datInfo, &ceInfo, slot);
1622         if (ret == RFAILED)
1623         {
1624             rgTOMUtlFreePduEvnt (pdu, TRUE);
1625             err.errType = RGERR_TOM_DATIND;
1626             tfuSap->sapSts.numPduDrop++;
1627             continue; 
1628         }
1629
1630       } /* end of CRNTI based message */
1631       else
1632       {
1633          ueCb = rgDBMGetUeCb (cellCb, datInfo->rnti);
1634          if (ueCb == NULLP)
1635          {
1636 #ifdef LTEMAC_SPS
1637             /* Try getting the UE using SPS-RNTI. */
1638             ueCb = rgDBMGetSpsUeCb (cellCb, datInfo->rnti);
1639             if (ueCb != NULLP)
1640             {
1641                isSpsRnti = TRUE;
1642                /* Increment implrelCntr for an empty transmission */
1643                if (pdu->sduLst.count == 0)
1644                {
1645                   ueCb->ul.implRelCntr++;
1646                   if (ueCb->ul.implRelCntr == ueCb->ul.implRelCnt)
1647                   {
1648                      /* Indicate scheduler for implicit release */
1649                      cmMemset((U8*)&schPst1, (U8)0, sizeof(Pst));
1650                      rgGetPstToInst(&schPst1,inst, cellCb->schInstMap.schInst);
1651
1652                      ueCb->ul.implRelCntr = 0;
1653                      ueCb->ul.explRelCntr = 0;
1654 #if 0                     
1655                                                         relInfo.cellSapId = cellCb->schInstMap.cellSapId;
1656                      relInfo.cRnti = ueCb->ueId;
1657                                                         relInfo.isExplRel= FALSE;
1658                      //TODO: commented for compilation without SCH RgMacSchSpsRel(&schPst1, &relInfo);
1659 #endif  
1660                   }
1661                }
1662                else
1663                {
1664                   /* Reset the implrelCntr */
1665                   ueCb->ul.implRelCntr = 0;
1666                }
1667             }
1668             else
1669 #endif 
1670             {
1671                /* Perform failure if ueCb is still NULLP */
1672                rgTOMUtlFreePduEvnt (pdu, TRUE);
1673                err.errType = RGERR_TOM_DATIND;
1674                RLOG_ARG1(L_ERROR,DBG_CELLID,datInd->cellId,"RNTI:%d Unable to get the UE CB", 
1675                   datInfo->rnti);
1676                tfuSap->sapSts.numPduDrop++;
1677                continue;
1678             }
1679          }
1680 #ifdef LTE_L2_MEAS         
1681      rgTOMUtlL2MStoreBufSz(ueCb, &ceInfo);
1682      rgTOML2MCompileActiveLCs (cellCb, ueCb, pdu, &ceInfo);
1683 #endif
1684 #ifdef LTEMAC_SPS
1685          if ((ret = rgTOMUtlProcMsg(cellCb, ueCb, pdu, isSpsRnti,&spsToBeActvtd,&sduSize, slot, (U32 *)&lcgBytes)) != ROK)
1686 #else
1687          if ((ret = rgTOMUtlProcMsg (cellCb, ueCb, pdu, slot, (U32 *)&lcgBytes)) != ROK)
1688 #endif /* LTEMAC_SPS */
1689          {
1690             rgTOMUtlFreePduEvnt (pdu, TRUE);
1691             err.errType = RGERR_TOM_DATIND;
1692             RLOG_ARG1(L_ERROR,DBG_CELLID,datInd->cellId,
1693                             "Unable to handle Data Indication CRNTI:%d",ueCb->ueId);
1694             tfuSap->sapSts.numPduDrop++;
1695             continue;
1696          }
1697       }
1698
1699       
1700 #ifdef LTEMAC_SPS
1701       if(rgTOMUtlInsSchInfo(pdu, sfInfo, &ceInfo, datInfo->rnti,spsToBeActvtd,sduSize, (U32 *)&lcgBytes) != ROK)
1702 #else
1703       if(rgTOMUtlInsSchInfo(pdu, sfInfo, &ceInfo, datInfo->rnti, (U32 *)&lcgBytes) != ROK)
1704 #endif
1705       
1706       {
1707          rgTOMInfFreePduEvnt (sfInfo);
1708          rgTOMUtlFreePduEvnt (pdu, FALSE);
1709          RETVALUE(RFAILED);
1710       }
1711       /* free up the PDU memory */
1712       rgTOMUtlFreePduEvnt (pdu, FALSE);
1713    }
1714    /* Free the allocated memory for ueUlAllocInfo here */
1715 #ifdef LTE_L2_MEAS
1716    if(cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)].ueUlAllocInfo != NULLP)
1717    {
1718       /*ccpu00117052 - MOD - Passing double for proper NULLP
1719                              assignment */
1720       rgFreeSBuf(inst,(Data **)&(cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)].ueUlAllocInfo), 
1721       ((cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)].numUe) * sizeof(RgUeUlAlloc)));
1722    }
1723 #endif
1724    /* RRM_RBC_X */
1725    /* Update PRB used for all GBR QCIs to scheduler */
1726     cmMemcpy((U8*) &sfInfo->qcisUlPrbCnt[0],
1727              (U8*) &cellCb->qcisUlPrbCnt[0],
1728              (RGM_MAX_QCI_REPORTS * sizeof(U32)));
1729     /* clear the cellCb ul prb value */
1730     cmMemset((U8*)&cellCb->qcisUlPrbCnt[0], 0, 
1731              (RGM_MAX_QCI_REPORTS * sizeof(U32)));
1732
1733    /* RRM_RBC_Y */
1734
1735    rgGetPstToInst(&schPst, inst,cellCb->schInstMap.schInst);
1736    sfInfo->cellSapId = cellCb->schInstMap.cellSapId;
1737    //TODO: commented for compilation without SCH RgMacSchSfRecp(&schPst, sfInfo);
1738    RETVALUE(ROK);
1739 }  /* rgTOMDatInd */
1740
1741 /**
1742  * @brief Function handles allocation for common channels i.e. BCCH-BCH,
1743  * BCCH-DLSCH, PCCH-DLSCH.
1744  *
1745  * @details
1746  *
1747  *     Function : rgHndlCmnChnl
1748  *     
1749  *     This function is invoked from RgSchMacSfAllocReq. This function handles
1750  *     allocations made for common channels like BCCH and PCCH. 
1751  *
1752  *     Processing steps:
1753  *     1. If BCCH on BCH has been scheduled, send StatusIndication on RGU.
1754  *     2. If PCCH is scheduled, send StatusIndication on RGU.
1755  *     3. If BCCH on DLSCH has been scheduled and sndStatInd is TRUE, send
1756  *     StatusIndication on RGU, else copy the bcch buffer onto the downlink
1757  *     subframe. 
1758  *     
1759  *           
1760  *  @param[in] RgCellCb          *cell,
1761  *  @param[in] CmLteTimingInfo   timingInfo,
1762  *  @param[in] RgInfCmnLcInfo    *cmnLcInfo,
1763  *  @param[in/out] RgErrInfo     *err,
1764  *  @return  S16
1765  *      -# ROK 
1766  *      -# RFAILED
1767  **/
1768 #ifdef ANSI
1769 PRIVATE S16 rgHndlCmnChnl
1770 (
1771 RgCellCb            *cell,
1772 CmLteTimingInfo     timingInfo,
1773 RgInfCmnLcInfo      *cmnLcInfo,
1774 RgErrInfo           *err
1775 )
1776 #else
1777 PRIVATE S16 rgHndlCmnChnl(cell, timingInfo, cmnLcInfo, err)
1778 RgCellCb            *cell;
1779 CmLteTimingInfo     timingInfo;
1780 RgInfCmnLcInfo      *cmnLcInfo;
1781 RgErrInfo           *err;
1782 #endif
1783 {
1784    #if (ERRCLASS & ERRCLS_DEBUG)
1785    RgPcchLcCb           *pcch;
1786    #endif
1787 #ifndef RGR_SI_SCH
1788    RgBcchDlschLcCb      *bcch;
1789 #if (ERRCLASS & ERRCLS_DEBUG)
1790    RgBcchBchLcCb        *bch;
1791 #endif
1792 #endif/*RGR_SI_SCH*/
1793    RguCStaIndInfo       *staInd;
1794    RgDlSf               *dlSf;
1795    Inst                 inst = cell->macInst - RG_INST_START;
1796
1797    TRC2(rgHndlCmnChnl)
1798
1799    dlSf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
1800
1801    if(cmnLcInfo->bitMask & RGINF_BCH_INFO)
1802    {
1803 #ifndef RGR_SI_SCH
1804       #if (ERRCLASS & ERRCLS_DEBUG) 
1805       if(NULLP == (bch = rgDBMGetBcchOnBch(cell)))
1806       {
1807          RETVALUE(RFAILED);
1808       }
1809       if(cmnLcInfo->bchInfo.lcId != bch->lcId)
1810       {
1811          RETVALUE(RFAILED);
1812       }
1813       #endif
1814
1815       if (rgAllocShrablSBuf (inst,(Data**)&staInd, sizeof(RguCStaIndInfo)) != ROK)
1816       {
1817          err->errCause = RGERR_TOM_MEM_EXHAUST;
1818          RETVALUE(RFAILED);
1819       }
1820       staInd->cellId = cell->cellId;
1821       staInd->rnti   = RG_INVALID_RNTI;
1822       staInd->lcId   = cmnLcInfo->bchInfo.lcId;
1823       staInd->transId = (timingInfo.sfn << 8) | (timingInfo.slot);
1824 /* ADD Changes for Downlink UE Timing Optimization */
1825 #ifdef LTEMAC_DLUE_TMGOPTMZ
1826       dlSf->remDatReqCnt++;
1827 #endif
1828       if (rgUIMSndCmnStaInd (inst,cell->rguDlSap,staInd) != ROK)
1829       {
1830          RETVALUE(RFAILED);
1831       }
1832 #else
1833       /*Store the received BCH Data in the scheduled subframe*/
1834       dlSf->bch.tb = cmnLcInfo->bchInfo.pdu;
1835 #endif/*RGR_SI_SCH*/
1836    }
1837
1838    if(cmnLcInfo->bitMask & RGINF_PCCH_INFO)
1839    {
1840       #if (ERRCLASS & ERRCLS_DEBUG) 
1841       if(NULLP == (pcch = rgDBMGetPcch(cell)))
1842       {
1843          RETVALUE(RFAILED);
1844       }
1845       if(cmnLcInfo->pcchInfo.lcId != pcch->lcId)
1846       {
1847          RETVALUE(RFAILED);
1848       }
1849       #endif
1850
1851       dlSf->pcch.pdcch.rnti = 
1852                cmnLcInfo->pcchInfo.rnti;
1853       dlSf->pcch.pdcch.dci = 
1854                cmnLcInfo->pcchInfo.dciInfo;
1855 #ifdef TFU_UPGRADE               
1856       /* ccpu00132314-ADD-Fill the tx Pwr offset from scheduler */         
1857       dlSf->pcch.txPwrOffset = cmnLcInfo->pcchInfo.txPwrOffset;         
1858 #endif
1859       if (rgAllocShrablSBuf (inst,(Data**)&staInd, sizeof(RguCStaIndInfo)) != ROK)
1860       {
1861          err->errCause = RGERR_TOM_MEM_EXHAUST;
1862          RETVALUE(RFAILED);
1863       }
1864       staInd->cellId = cell->cellId;
1865       staInd->rnti   = RG_INVALID_RNTI;
1866       staInd->lcId   = cmnLcInfo->pcchInfo.lcId;
1867       staInd->transId = (timingInfo.sfn << 8) | (timingInfo.slot);
1868 /* ADD Changes for Downlink UE Timing Optimization */
1869 #ifdef LTEMAC_DLUE_TMGOPTMZ
1870       dlSf->remDatReqCnt++;
1871 #endif
1872       /* for consolidated CmnStaInd calling below function from function 
1873        * rgHndlSchedUe once CmnStaInd prepared for all UEs
1874        */
1875       if (rgUIMSndCmnStaInd (inst,cell->rguDlSap,staInd) != ROK)
1876       {
1877          RETVALUE(RFAILED);
1878       }
1879    }
1880
1881    if(cmnLcInfo->bitMask & RGINF_BCCH_INFO)
1882    {
1883       dlSf->bcch.pdcch.rnti = 
1884                cmnLcInfo->bcchInfo.rnti;
1885       dlSf->bcch.pdcch.dci = 
1886                cmnLcInfo->bcchInfo.dciInfo;
1887 #ifdef TFU_UPGRADE               
1888       /* ccpu00132314-ADD-Fill the tx Pwr offset from scheduler */         
1889       dlSf->bcch.txPwrOffset = cmnLcInfo->bcchInfo.txPwrOffset;         
1890 #endif      
1891 #ifndef RGR_SI_SCH
1892       if(NULLP == 
1893          (bcch=rgDBMGetBcchOnDlsch(cell,cmnLcInfo->bcchInfo.lcId)))
1894       {
1895          RETVALUE(RFAILED);
1896       }
1897       if(TRUE == cmnLcInfo->bcchInfo.sndStatInd)
1898       {
1899          RG_FREE_MSG(bcch->tb);
1900          if (rgAllocShrablSBuf (inst,(Data**)&staInd, 
1901                   sizeof(RguCStaIndInfo)) != ROK)
1902          {
1903             err->errCause = RGERR_TOM_MEM_EXHAUST;
1904             RETVALUE(RFAILED);
1905          }
1906          staInd->cellId = cell->cellId;
1907          staInd->rnti   = RG_INVALID_RNTI;
1908          staInd->lcId   = cmnLcInfo->bcchInfo.lcId;
1909          staInd->transId = (timingInfo.sfn << 8) | (timingInfo.slot);
1910 /* ADD Changes for Downlink UE Timing Optimization */
1911 #ifdef LTEMAC_DLUE_TMGOPTMZ
1912          dlSf->remDatReqCnt++;
1913 #endif
1914          if (rgUIMSndCmnStaInd (inst,cell->rguDlSap,staInd) != ROK)
1915          {
1916             RETVALUE(RFAILED);
1917          }
1918       }
1919       else
1920       {
1921          SCpyMsgMsg(bcch->tb, RG_GET_MEM_REGION(rgCb[inst]),
1922                   RG_GET_MEM_POOL(rgCb[inst]), &dlSf->bcch.tb);
1923       }
1924 #else
1925       /*Store the received BCCH Data in the scheduled subframe*/
1926       dlSf->bcch.tb = cmnLcInfo->bcchInfo.pdu;
1927 #endif/*RGR_SI_SCH*/
1928    }
1929
1930    RETVALUE(ROK);
1931 } /* end of rgHndlCmnChnl */
1932
1933 /**
1934  * @brief Function for handling allocations for dedicated channels for a
1935  * subframe.
1936  *
1937  * @details
1938  *
1939  *     Function : rgHndlSchdUe
1940  *     
1941  *     This function shall be invoked whenever scheduler is done with the
1942  *     allocations of dedicated channels for a subframe. Invoked by the function
1943  *     RgSchMacSfAllocReq.
1944  *
1945  *     Processing steps :
1946  *     1. Loops through the list of UE's scheduled looking for the corresponding
1947  *     ueCb/raCb. 
1948  *     2. Finds the corresponding HARQ process.
1949  *     3. Invokes the DHM function to issue StatusIndications on RGU.
1950  *
1951  *           
1952  *  @param[in] RgCellCb            *cell,
1953  *  @param[in] CmLteTimingInfo     timingInfo,
1954  *  @param[in] RgInfUeInfo         *ueInfo
1955  *  @param[in/out] RgErrInfo       *err
1956  *  @return  S16
1957  *      -# ROK 
1958  *      -# RFAILED 
1959  **/
1960 #ifdef ANSI
1961 PRIVATE S16 rgHndlSchdUe
1962 (
1963 RgCellCb            *cell,
1964 CmLteTimingInfo     timingInfo,
1965 RgInfUeInfo         *ueInfo,
1966 RgErrInfo           *err
1967 )
1968 #else
1969 PRIVATE S16 rgHndlSchdUe(cell, timingInfo, ueInfo, err) /* laa_ut_fix */
1970 RgCellCb            *cell;
1971 CmLteTimingInfo     timingInfo;
1972 RgInfUeInfo         *ueInfo;
1973 RgErrInfo           *err;
1974 #endif
1975 {
1976
1977    TRC2(rgHndlSchdUe);
1978
1979    if(NULLP == ueInfo->allocInfo)
1980    {
1981       RETVALUE(RFAILED);
1982    }
1983
1984    rgDHMSndConsolidatedStaInd(cell, ueInfo, timingInfo, err);
1985
1986    RETVALUE(ROK);
1987 } /* end of rgHndlSchdUe */
1988
1989 #ifdef LTE_L2_MEAS
1990 /**
1991  * @brief Function for handling Uplink allocations for Ue for a
1992  * subframe.
1993  *
1994  * @details
1995  *
1996  *     Function : rgHndlUlUeInfo
1997  *     
1998  *  @param[in] RgCellCb            *cell,
1999  *  @param[in] CmLteTimingInfo     timingInfo,
2000  *  @param[in] RgInfUlUeInfo       *ueInfo
2001  *  @return  S16
2002  *      -# ROK 
2003  *      -# RFAILED 
2004  **/
2005 #ifdef ANSI
2006 PRIVATE S16 rgHndlUlUeInfo
2007 (
2008 RgCellCb            *cell,
2009 CmLteTimingInfo     timingInfo,
2010 RgInfUlUeInfo       *ueInfo
2011 )
2012 #else
2013 PRIVATE S16 rgHndlUlUeInfo(cell, timingInfo, ueInfo)
2014 RgCellCb            *cell;
2015 CmLteTimingInfo     timingInfo;
2016 RgInfUlUeInfo       *ueInfo;
2017 #endif
2018 {
2019    Inst           inst = cell->macInst - RG_INST_START;
2020    U8             idx;
2021    RgUlSf         *ulSf;
2022    S16            ret;
2023
2024    TRC2(rgHndlUlUeInfo)
2025    
2026    ulSf = &cell->ulSf[(timingInfo.slot % RGSCH_NUM_SUB_FRAMES)];
2027
2028    /* rg003.301-MOD- Corrected the purifier memory leak */
2029    if (ulSf->numUe != ueInfo->numUes)
2030    {
2031       if (ulSf->ueUlAllocInfo)
2032       {
2033          rgFreeSBuf(inst,(Data **)&(ulSf->ueUlAllocInfo),
2034                ulSf->numUe * sizeof(RgUeUlAlloc));
2035       }
2036    }
2037 #ifdef XEON_SPECIFIC_CHANGES
2038    CM_MEAS_TIME((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MEAS_FREE);
2039    CM_ADD_INFO((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES),  CM_DBG_MEAS_FREE, ulSf->numUe);
2040 #endif
2041    ulSf->numUe         = ueInfo->numUes;
2042    if((ulSf->ueUlAllocInfo == NULLP) && (ueInfo->numUes > 0))
2043    {
2044        /* Allocate memory for ulAllocInfo */
2045        if((ret = rgAllocSBuf(inst,(Data**)&(cell->ulSf[(timingInfo.slot % RGSCH_NUM_SUB_FRAMES)].
2046                  ueUlAllocInfo), ueInfo->numUes *  sizeof(RgUeUlAlloc))) != ROK)
2047        {
2048           RETVALUE(ret);
2049        }
2050    }
2051 #ifdef XEON_SPECIFIC_CHANGES
2052    CM_MEAS_TIME((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MEAS_ALLOC);
2053    CM_ADD_INFO((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES), CM_DBG_MEAS_ALLOC, ueInfo->numUes);
2054 #endif
2055    if (ulSf->ueUlAllocInfo != NULLP)
2056    {
2057       for(idx = 0; idx < ueInfo->numUes; idx++)
2058       {
2059          ulSf->ueUlAllocInfo[idx].rnti   = ueInfo->ulAllocInfo[idx].rnti;
2060          ulSf->ueUlAllocInfo[idx].numPrb = ueInfo->ulAllocInfo[idx].numPrb;
2061       }
2062    }
2063    RGCPYTIMEINFO(timingInfo, ulSf->schdTime);
2064    RETVALUE(ROK);
2065 } /* end of rgHndlUlUeInfo */
2066 #endif
2067 /**
2068  * @brief Function for handling RaResp request received from scheduler to MAC
2069  *
2070  * @details
2071  *
2072  *     Function : rgTOMRlsSf
2073  *     
2074  *     This function shall be invoked whenever scheduler is done with the
2075  *     allocations of random access responses for a subframe.
2076  *     This shall invoke RAM to create ueCbs for all the rapIds allocated and 
2077  *     shall invoke MUX to create RAR PDUs for raRntis allocated.
2078  *     
2079  *           
2080  *  @param[in] Inst        inst
2081  *  @param[in] CmLteCellId         cellId,
2082  *  @param[in] CmLteTimingInfo     timingInfo,
2083  *  @param[in] RaRespInfo          *rarInfo
2084  *  @return  S16
2085  *      -# ROK 
2086  **/
2087 #ifdef ANSI
2088 PUBLIC Void rgTOMRlsSf
2089 (
2090 Inst                inst,
2091 RgDlSf              *dlSf
2092 )
2093 #else
2094 PUBLIC Void rgTOMRlsSf(dlSf)
2095 Inst                inst;
2096 RgDlSf              *dlSf;
2097 #endif
2098 {
2099    U8               idx;
2100
2101    TRC2(rgTOMRlsSf)
2102
2103    if(dlSf->txDone == FALSE)
2104    {
2105       RLOG0(L_ERROR, "SUBFRAME Not pushed to the PHY");
2106
2107       if (dlSf->bch.tb != NULLP)
2108       {
2109          RG_FREE_MSG(dlSf->bch.tb);
2110       }
2111       if (dlSf->bcch.tb != NULLP)
2112       {
2113          RG_FREE_MSG(dlSf->bcch.tb);
2114       }
2115       if (dlSf->pcch.tb != NULLP)
2116       {
2117          RG_FREE_MSG(dlSf->pcch.tb);
2118       }
2119 #ifdef EMTC_ENABLE
2120       rgTOMEmtcRlsSf(dlSf);
2121 #endif
2122       for(idx=0; idx < dlSf->numRaRsp; idx++)
2123       {
2124          RG_FREE_MSG(dlSf->raRsp[idx].rar);
2125       }
2126    }
2127 /* ADD Changes for Downlink UE Timing Optimization */
2128 #ifdef LTEMAC_DLUE_TMGOPTMZ
2129    dlSf->remDatReqCnt = 0;
2130    /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
2131       RLC-MAC */
2132    dlSf->statIndDone = FALSE;
2133 #endif
2134          if (dlSf->tbs.count)
2135          {
2136       U8           i;
2137       CmLList      *node;
2138       RgDlHqProcCb *hqP;
2139        RGDBGERRNEW(inst, (rgPBuf(inst),
2140                 "Error Stale TBs in Subframes TBS list\n"));
2141       node = dlSf->tbs.first;
2142                   while(node)
2143                   {
2144          hqP = (RgDlHqProcCb*)node->node;
2145          node = node->next;
2146           if (hqP)
2147           {
2148                      for(i=0;i< RG_MAX_TB_PER_UE;i++)
2149                      {
2150                                     if (hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sf == dlSf)
2151                                     {
2152                                              cmLListDelFrm(&dlSf->tbs, &(hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sfLnk));
2153                                              hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sfLnk.node = NULLP;
2154                     printf("\n rgTOMRlsSf:: hqP %p \n", (Void *)hqP);
2155                                     }
2156                                     hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sf = NULLP;
2157                            }
2158                         }
2159          }
2160     }
2161     /*arjun: check if dlSf laaTb list has to be freed???*/
2162    cmLListInit(&dlSf->tbs);
2163    dlSf->txDone = FALSE;
2164    dlSf->numRaRsp = 0;
2165    RETVOID;
2166 }
2167
2168 /**
2169  * @brief Function is called by the scheduler once it has completed the
2170  * allocation for the subframe. 
2171  *
2172  * @details
2173  *
2174  *     Function : rgHndlFlowCntrl
2175  *     This function should fill and send Flow control 
2176  *     indication to RLC
2177  *
2178  *           
2179  *  @param[in] Pst                 *cell       
2180  *  @param[in] RgInfSfAlloc        *sfInfo   Carries all the allocation
2181  *  information.
2182  *  @return  S16
2183  *      -# ROK 
2184  **/
2185 #ifdef ANSI
2186 PUBLIC S16 rgHndlFlowCntrl
2187 (
2188 RgCellCb       *cell,
2189 RgInfSfAlloc        *sfInfo
2190 )
2191 #else
2192 PUBLIC S16 rgHndlFlowCntrl(cell, sfInfo)
2193 RgCellCb            *cell;
2194 RgInfSfAlloc        *sfInfo;
2195 #endif
2196 {
2197    RguFlowCntrlInd  *flowCntrlInd;
2198    Pst              *pst;
2199    U32              ueIdx;
2200    U32              lcIdx;
2201    TRC3(rgHndlFlowCntrl);
2202
2203    pst = &cell->rguDlSap->sapCfg.sapPst;
2204    /* flowCntrlInd is alloced in cell init time and will be re-used throughout */
2205    flowCntrlInd = cell->flowCntrlInd;
2206    flowCntrlInd->cellId = sfInfo->cellId;
2207    flowCntrlInd->numUes = sfInfo->flowCntrlInfo.numUes; 
2208   
2209    for (ueIdx = 0; ueIdx < sfInfo->flowCntrlInfo.numUes; ueIdx++)
2210    {
2211       flowCntrlInd->ueFlowCntrlInfo[ueIdx].ueId = sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].ueId;
2212       flowCntrlInd->ueFlowCntrlInfo[ueIdx].numLcs = sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].numLcs;
2213       
2214       for (lcIdx = 0; lcIdx < RGINF_MAX_NUM_DED_LC; lcIdx++)
2215       {
2216          flowCntrlInd->ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].lcId =
2217          sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].lcId;
2218          flowCntrlInd->ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].pktAdmitCnt = 
2219          sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].pktAdmitCnt;
2220         
2221          flowCntrlInd->ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].maxBo4FlowCtrl = 
2222          sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].maxBo4FlowCtrl;
2223       }
2224    }
2225    RgUiRguFlowCntrlInd(pst, cell->rguDlSap->sapCfg.spId,flowCntrlInd); /* TODO: Rishi confirm if the suId and pst pointer is correct */
2226    RETVALUE(ROK);
2227 }
2228 /**
2229  * @brief Function is called by the scheduler once it has completed the
2230  * allocation for the subframe. 
2231  *
2232  * @details
2233  *
2234  *     Function : RgSchMacSfAllocReq
2235  *     
2236  *     This function shall be invoked whenever scheduler is done with the
2237  *     allocations of for a subframe. The sfInfo carries all the allocation
2238  *     details for the common channels, RA responses and dedicated channel
2239  *     allocations. 
2240  *
2241  *     Processing steps :
2242  *     1. Reset the information present in the downlink subframe that is
2243  *     scheduled.
2244  *     2. Handle common channel allocations
2245  *     3. Handle RA Response allocations
2246  *     4. Handle dedicated channel allocations.
2247  *           
2248  *  @param[in] Pst                 *pst       
2249  *  @param[in] RgInfSfAlloc        *sfInfo   Carries all the allocation
2250  *  information.
2251  *  @return  S16
2252  *      -# ROK 
2253  **/
2254 #ifdef ANSI
2255 PUBLIC S16 RgSchMacSfAllocReq
2256 (
2257 Pst                 *pst,
2258 RgInfSfAlloc        *sfInfo
2259 )
2260 #else
2261 PUBLIC S16 RgSchMacSfAllocReq(pst, sfInfo)
2262 Pst                 *pst;
2263 RgInfSfAlloc        *sfInfo;
2264 #endif
2265 {
2266    RgCellCb       *cell;
2267    RgDlSf         *dlSf;
2268    RgErrInfo      err;
2269    VOLATILE U32   startTime=0;
2270    Inst           inst;
2271
2272    TRC2(RgSchMacSfAllocReq)
2273
2274    RG_IS_INST_VALID(pst->dstInst);
2275    inst = pst->dstInst - RG_INST_START;
2276    /*starting Task*/
2277    SStartTask(&startTime, PID_MAC_SF_ALLOC_REQ);
2278
2279    if(NULLP == sfInfo)
2280    {
2281       RETVALUE(RFAILED);
2282    }
2283
2284    if((cell = rgCb[inst].cell) == NULLP)
2285    {
2286       RLOG_ARG0(L_ERROR,DBG_CELLID,sfInfo->cellId, "No cellCb found with cell");
2287       RETVALUE(RFAILED);
2288    }
2289
2290    dlSf = &cell->subFrms[(sfInfo->timingInfo.slot % RG_NUM_SUB_FRAMES)];
2291
2292    rgTOMRlsSf(inst,dlSf);
2293    dlSf->schdTime = sfInfo->timingInfo;
2294
2295 #ifdef LTE_ADV
2296    rgLaaInitTbInfoLst(cell);
2297 #endif
2298
2299    /* Fix : syed Ignore Failure Returns and continue processing.
2300     * Incomplete processing results in state sync loss between MAC-SCH. */
2301 #ifdef EMTC_ENABLE
2302     if(TRUE == cell->emtcEnable)
2303     {
2304        rgEmtcHndl(cell, sfInfo);
2305     }
2306 #endif
2307    rgHndlCmnChnl(cell, sfInfo->timingInfo, &sfInfo->cmnLcInfo, &err);
2308
2309    rgHndlRaResp(cell, sfInfo->timingInfo, &sfInfo->rarInfo, &err);
2310
2311 #ifdef LTE_ADV
2312 #ifdef XEON_SPECIFIC_CHANGES
2313    CM_MEAS_TIME((cell->crntTime.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_B4_UE_SCHD);
2314 #endif
2315    rgHndlSchdUe(cell, sfInfo->timingInfo, &sfInfo->ueInfo, &err);
2316 #ifdef XEON_SPECIFIC_CHANGES
2317    CM_MEAS_TIME((cell->crntTime.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_UE_SCHD);
2318 #endif
2319    rgLaaChkAndReqTbs(dlSf,cell, inst);
2320
2321 #else
2322    rgHndlSchdUe(cell, sfInfo->timingInfo, &sfInfo->ueInfo, &err);
2323 #endif
2324
2325 #ifdef LTE_L2_MEAS
2326    if(rgHndlUlUeInfo(cell, sfInfo->ulUeInfo.timingInfo, 
2327                      &sfInfo->ulUeInfo) != ROK)
2328    {
2329       RETVALUE(RFAILED);
2330    }
2331 #endif
2332 #ifdef XEON_SPECIFIC_CHANGES
2333    CM_MEAS_TIME((cell->crntTime.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_MEAS);
2334 #endif
2335    /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
2336       RLC-MAC */
2337
2338
2339    /* Added the handling for pushing down
2340     * TFU Data request in the retransmission only scenario.*/ 
2341 #ifdef LTEMAC_DLUE_TMGOPTMZ
2342    dlSf->statIndDone = TRUE;
2343    /* Fix [ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
2344       RLC-MAC */
2345    if(!(dlSf->txDone) && 
2346 #ifdef LTE_ADV
2347          (TRUE == rgLaaChkAllRxTbs(dlSf)) && 
2348 #endif
2349          (0 == dlSf->remDatReqCnt) && (dlSf->statIndDone) && 
2350         (RG_TIMEINFO_SAME(cell->crntTime, dlSf->schdTime)))
2351    {
2352       /*This is the case of rettransmission, so no need
2353        * to wait for TTI Ind to push TFU Data Request. Send
2354        * it right away.*/
2355       if (ROK != rgTOMUtlProcDlSf (dlSf, cell, &err))
2356       {
2357          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Unable to process downlink subframe for cell");
2358          err.errType = RGERR_ROM_DEDDATREQ;
2359       }
2360       /* Mark this frame as sent */
2361       dlSf->txDone = TRUE;
2362    }
2363 #endif
2364    if (sfInfo->flowCntrlInfo.numUes > 0)
2365    {
2366      rgHndlFlowCntrl(cell,sfInfo);
2367    }
2368    /*stoping Task*/
2369    SStopTask(startTime, PID_MAC_SF_ALLOC_REQ);
2370    RETVALUE(ROK);
2371 } /* end of RgSchMacSfAllocReq */
2372 /**
2373  * @brief Handler for processing data indication recieved from PHY for UEs.
2374  *
2375  * @details
2376  *
2377  *     Function: rgTOMProcCrntiCEInDatInd
2378  *
2379  *     Handler for processing data indication recieved from PHY for UEs.
2380  *
2381  *     Invoked by: RgLiTfuDatInd of LIM 
2382  *
2383  *     Processing Steps: 
2384  *     For each DataInfo recieved
2385  *      - If  received a CRNTI control element 
2386  *          - Check if a CCCH SDU is present, if it is return failure
2387  *          - Check for the existence of UE, if its isnt present return failure.
2388  *          - Delegate the remaining processing to rgTOMUtlProcMsg3 which
2389  *          primarily informs the scheduler about the data received and
2390  *          generates Data indications towards the higher layer.
2391  *           
2392  *  @param      RgMacPdu          *pdu,
2393  *  @param      RgUeCb            *prevUeCb,
2394  *  @param      RgCellCb          *cellCb,
2395  *  @param      TfuDatInfo        *datInfo,
2396  *  @param      RgInfCeInfo       *ceInfo
2397  *  @return  S16
2398  *      -# ROK 
2399  *      -# RFAILED 
2400  **/
2401 #ifdef ANSI
2402 PRIVATE S16 rgTOMProcCrntiCEInDatInd
2403 (
2404 RgMacPdu          *pdu,
2405 RgUeCb            *prevUeCb,
2406 RgCellCb          *cellCb,
2407 TfuDatInfo        *datInfo,
2408 RgInfCeInfo       *ceInfo,
2409 U16               slot
2410 )
2411 #else
2412 PRIVATE S16 rgTOMProcCrntiCEInDatInd( pdu, prevUeCb, cellCb, datInfo, ceInfo, slot)
2413 RgMacPdu          *pdu;
2414 RgUeCb            *prevUeCb;
2415 RgCellCb          *cellCb;
2416 TfuDatInfo        *datInfo;
2417 RgInfCeInfo       *ceInfo;
2418 U16               slot;
2419 #endif
2420 {
2421    RgUeCb *ueCb = NULLP;
2422    Inst   inst  = cellCb->macInst - RG_INST_START;
2423
2424
2425 #ifdef LTEMAC_SPS
2426    Bool spsToBeActvtd;
2427    U16  sduSize;
2428 #endif
2429
2430    TRC2(rgTOMProcCrntiCEInDatInd)
2431
2432 #ifndef LTE_L2_MEAS      
2433       UNUSED(slot);
2434 #endif
2435
2436    ueCb = rgDBMGetUeCbFromRachLst (cellCb, datInfo->rnti);
2437
2438    if (ueCb == NULLP)
2439    {
2440        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2441                 "RNTI:%d Received MSG3 with CRNTI,unable to find ueCb", ceInfo->ces.cRnti);
2442        RETVALUE(RFAILED);
2443    }
2444
2445    prevUeCb = rgDBMGetUeCb (cellCb, ceInfo->ces.cRnti);
2446    if (prevUeCb == NULLP)
2447    {
2448        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2449                  "RNTI:%d Received MSG3 with CRNTI,unable to find ueCb", ceInfo->ces.cRnti);
2450        RETVALUE(RFAILED);
2451    }
2452    RLOG_ARG2(L_DEBUG,DBG_CELLID,cellCb->cellId,
2453             "CRNTI CE(%d) received through tmpCrnti(%d)",
2454             ceInfo->ces.cRnti, datInfo->rnti);
2455    rgDBMDelUeCbFromRachLst(cellCb, ueCb);
2456    rgRAMFreeUeCb(inst,ueCb);
2457    ueCb = prevUeCb;
2458 #ifdef LTEMAC_SPS
2459    if ((rgTOMUtlProcMsg(cellCb, ueCb, pdu, FALSE,&spsToBeActvtd,&sduSize, slot, NULLP)) != ROK)
2460 #else
2461    if ((rgTOMUtlProcMsg (cellCb, ueCb, pdu, slot, NULLP)) != ROK)
2462 #endif /* LTEMAC_SPS */
2463    {
2464        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2465                        "RNTI:%d Processing for MSG3 failed",datInfo->rnti);
2466        RETVALUE(RFAILED);
2467    }
2468    RETVALUE(ROK);
2469 }
2470 /**
2471  * @brief Handler for processing data indication recieved from PHY for UEs.
2472  *
2473  * @details
2474  *
2475  *     Function: rgTOMProcCCCHSduInDatInd
2476  *
2477  *     Handler for processing data indication recieved from PHY for UEs.
2478  *
2479  *     Invoked by: RgLiTfuDatInd of LIM 
2480  *
2481  *     Processing Steps: 
2482  *     For each DataInfo recieved
2483  *      - If only CCCH SDU is present
2484  *        - Invoke rgTOMUtlProcMsg3 for further processing.
2485  *      - If its a non-Msg3 PDU i.e. received outside of a RA procedure
2486  *        - Retrieve the UeCB 
2487  *        - Validate that the received PDU contains only configured Logical
2488  *        Channels.
2489  *        - Invoke rgTOMUtlProcDatPdu for further processing. It informs the
2490  *        scheduler with the information of the received Data and generates
2491  *        DatIndications towards the higher layers. 
2492  *           
2493  *  @param  TfuDatIndInfo *datInd
2494  *  @param  RgMacPdu          *pdu,
2495  *  @param  RgUeCb            *prevUeCb,
2496  *  @param  RgCellCb          *cellCb,
2497  *  @param  TfuDatInfo        *datInfo,
2498  *  @param  RgInfCeInfo       *ceInfo
2499  *  @return  S16
2500  *      -# ROK 
2501  *      -# RFAILED 
2502  **/
2503 #ifdef ANSI
2504 PRIVATE S16 rgTOMProcCCCHSduInDatInd
2505 (
2506 RgMacPdu          *pdu,
2507 RgUeCb            *prevUeCb,
2508 RgCellCb          *cellCb,
2509 TfuDatInfo        *datInfo,
2510 RgInfCeInfo       *ceInfo,
2511 U16               slot 
2512 )
2513 #else
2514 PRIVATE S16 rgTOMProcCCCHSduInDatInd( pdu, prevUeCb, cellCb, datInfo, ceInfo, slot)
2515 RgMacPdu          *pdu;
2516 RgUeCb            *prevUeCb;
2517 RgCellCb          *cellCb;
2518 TfuDatInfo        *datInfo;
2519 RgInfCeInfo       *ceInfo;
2520 U16               slot;
2521 #endif
2522 {
2523    RgUeCb *ueCb = NULLP;
2524    Inst   inst  = cellCb->macInst - RG_INST_START;
2525
2526 #ifdef LTEMAC_SPS
2527    Bool spsToBeActvtd;
2528    U16  sduSize;
2529 #endif
2530
2531
2532    TRC2(rgTOMProcCCCHSduInDatInd)
2533
2534 #ifndef LTE_L2_MEAS      
2535       UNUSED(slot);
2536 #endif
2537
2538    if (ceInfo->bitMask & RG_CRNTI_CE_PRSNT)
2539    {
2540        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2541                        "CRNTI:%d Received MSG3 with CCCH",ceInfo->ces.cRnti);
2542        RETVALUE(RFAILED);
2543    }
2544    
2545    ueCb = rgDBMGetUeCbFromRachLst (cellCb, datInfo->rnti);
2546    
2547    if (ueCb == NULLP)
2548    {
2549        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2550                        "RNTI:%d Processing for MSG3 failed", datInfo->rnti);
2551        RETVALUE(RFAILED);
2552    }
2553    /* Fix: syed Drop any duplicate Msg3(CCCH Sdu) */
2554    if (ueCb->dl.hqEnt.numHqProcs)
2555    {
2556       /* HqE is already initialized by a previuos Msg3 */ 
2557        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"RNTI:%d Processing for MSG3 failed. Duplicate "
2558           "MSG3 received. Dropping", datInfo->rnti);
2559        RETVALUE(RFAILED);
2560    }
2561    
2562    if(rgDHMHqEntInit(inst,&ueCb->dl.hqEnt,
2563                      cellCb->maxDlHqProcPerUe) != ROK)
2564    {
2565        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"RNTI:%d Harq Initialization failed ", 
2566           datInfo->rnti);
2567        RETVALUE(RFAILED);
2568    }
2569     RLOG_ARG1(L_DEBUG,DBG_CELLID,cellCb->cellId,
2570              "CCCH SDU received through tmpCrnti(%d)",datInfo->rnti);
2571 #ifdef LTEMAC_SPS
2572    if ((rgTOMUtlProcMsg(cellCb, ueCb, pdu, FALSE,&spsToBeActvtd,&sduSize, slot, NULLP)) != ROK)
2573 #else
2574    if ((rgTOMUtlProcMsg (cellCb, ueCb, pdu, slot, NULLP)) != ROK)
2575 #endif /* LTEMAC_SPS */
2576    {
2577        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"RNTI:%d Processing for MSG3 failed", 
2578           datInfo->rnti);
2579        RETVALUE(RFAILED);
2580    }
2581    RETVALUE(ROK);
2582 }
2583
2584 #ifdef LTE_L2_MEAS
2585
2586 /** @brief This function captures the BSR value from Control Element
2587  *  Info structure and updates the effective Buffer size into the 
2588  *  corresponding LCG ID. 
2589  *
2590  * @details 
2591  *
2592  *     Function: rgTOMUtlL2MStoreBufSz
2593  *
2594  *         Processing steps:
2595  *         - update/append the Data structure based on BSR type 
2596  *
2597  * @param  [in] RgUeCb     *ueCb
2598  * @param  [in] RgInfCeInfo *ceInfo
2599  * @return S16
2600  */
2601
2602 #ifdef ANSI
2603 PRIVATE S16 rgTOMUtlL2MStoreBufSz
2604 (
2605  RgUeCb      *ueCb,
2606  RgInfCeInfo *ceInfo
2607  )
2608 #else
2609 PRIVATE S16 rgTOMUtlL2MStoreBufSz (ueCb, ceInfo)
2610  RgUeCb      *ueCb;
2611  RgInfCeInfo *ceInfo;
2612 #endif
2613 {
2614    U8 lcgId;
2615    U8 bsr;
2616    TRC2(rgTOMUtlL2MStoreBufSz);
2617
2618    if(ceInfo->bitMask & RG_TRUNC_BSR_CE_PRSNT)
2619    {
2620       lcgId = ((ceInfo->ces.bsr.truncBsr >> 6) & 0x03);
2621       bsr = ceInfo->ces.bsr.truncBsr & 0x3F;
2622       ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = rgLwrBsrTbl[bsr];
2623    }
2624    else if(ceInfo->bitMask & RG_SHORT_BSR_CE_PRSNT)
2625    {
2626       lcgId = ((ceInfo->ces.bsr.shortBsr >> 6) & 0x03);
2627       bsr = ceInfo->ces.bsr.shortBsr & 0x3F;
2628       ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = rgLwrBsrTbl[bsr];
2629
2630    }
2631    else if(ceInfo->bitMask & RG_LONG_BSR_CE_PRSNT)
2632    {
2633       ueCb->ul.lcgArr[0].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs1];
2634       ueCb->ul.lcgArr[1].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs2];
2635       ueCb->ul.lcgArr[2].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs3];
2636       ueCb->ul.lcgArr[3].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs4];
2637    }
2638    RETVALUE(ROK);
2639 } /* end of rgTOMUtlL2MStoreBufSz*/
2640
2641 /** @brief : Compiles list of LCs received in UL data for DTCH RBs
2642  *
2643  * @details
2644  *
2645  * @param  [in] RgCellCb   *cellCb
2646  * @param  [in] RgUeCb     *ueCb
2647  * @param  [in] CmLteRnti  rnti
2648  * @param  [in] RgMacPdu   *pdu
2649  * @param 
2650  *  @return  S16
2651  *      -# ROK 
2652  *      -# RFAILED 
2653  */
2654 #ifdef ANSI
2655 PRIVATE Void rgTOML2MCompileActiveLCs
2656 (
2657  RgCellCb      *cellCb, 
2658  RgUeCb        *ueCb,
2659  RgMacPdu      *pdu,
2660  RgInfCeInfo   *ceInfo 
2661  )
2662 #else
2663 PRIVATE Void rgTOML2MCompileActiveLCs(cellCb, ueCb, pdu, ceInfo)
2664    RgCellCb      *cellCb; 
2665    RgUeCb        *ueCb;
2666    RgMacPdu      *pdu;
2667    RgInfCeInfo   *ceInfo; 
2668 #endif 
2669 {
2670    CmLList           *node;
2671    RgMacSdu          *sdu;
2672    RgUlLcCb          *ulLcCb;
2673
2674    TRC2(rgTOML2MCompileActiveLCs)
2675
2676    node =  pdu->sduLst.first;
2677    while (node)
2678    {
2679       sdu = (RgMacSdu*)node->node;
2680       
2681       if ((ulLcCb = rgDBMGetUlDedLcCb(ueCb, sdu->lcId)), ulLcCb != NULLP)
2682       {
2683          if (ulLcCb->lcgId != 0)
2684          {
2685             ceInfo->bitMask |= RG_ACTIVE_LC_PRSNT;
2686             ceInfo->ulActLCs[ulLcCb->lcId - 1] = TRUE;
2687          }
2688       }
2689       node = node->next;
2690    }
2691
2692 } /* end of */ 
2693
2694
2695
2696 #endif
2697 /**********************************************************************
2698  
2699          End of file
2700 **********************************************************************/