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