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