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