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