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