Moving all common header file into common_def.h file
[o-du/l2.git] / src / 5gnrmac / rg_utl.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_utl.c
28   
29 **********************************************************************/
30
31 /** @file rg_utl.c
32 @brief This file implements utility functions for LTE MAC
33 */
34
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_MODULE_ID=4096;
37 static int RLOG_FILE_ID=179;
38
39 /* header include files (.h) */
40 #include "common_def.h"
41 #include "rg_env.h"        /* MAC Environment Defines */
42 #include "crg.h"           /* CRG Interface defines */
43 #include "rgu.h"           /* RGU Interface defines */
44 #include "tfu.h"           /* TFU Interface defines */
45 #include "rg_sch_inf.h"    /* RGR Interface defines */
46 #include "lrg.h"           /* LRG Interface defines */
47
48 #include "rg_prg.h"        /* PRG(MAC-MAC) Interface includes */
49 #include "rg.h"            /* MAC defines */
50 #include "rg_err.h"        /* MAC error defines */
51
52 /* header/extern include files (.x) */
53 #include "cm5.x"           /* Timer */
54
55 #include "crg.x"           /* CRG Interface includes */
56 #include "rgu.x"           /* RGU Interface includes */
57 #include "tfu.x"           /* TFU Interface includes */
58 #include "rg_sch_inf.x"    /* RGR Interface includes */
59 #include "lrg.x"           /* LRG Interface includes */
60 #include "rg_prg.x"        /* PRG(MAC-MAC) Interface includes */
61
62 #include "du_app_mac_inf.h"
63 #include "rg.x"            /* MAC includes */
64
65 /* local defines */
66 #define RG_NON_MIMO_IDX 0
67
68 /* local typedefs */
69  
70 /* local externs */
71  
72 /* forward references */
73 PRIVATE S16 rgUtlHndlCrntiChng ARGS((
74          Inst            inst,
75          RgCellCb        *cell,
76          CmLteRnti       rnti,
77          CmLteRnti       newRnti
78          ));
79 PRIVATE Void rgUtlHndlCrntiRls ARGS((
80          RgCellCb        *cell,
81          RgInfRlsRnti    *rlsRnti
82          ));
83
84 PUBLIC S16 rgDelUeFrmAllSCell ARGS((
85          RgCellCb       *cell,
86          RgUeCb         *ue
87          ));
88
89 #ifdef LTE_ADV
90 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs ARGS((
91          RgCellCb        *cell,
92          CmLteRnti       rnti,
93          CmLteRnti       newRnti
94          ));
95 #endif
96 /***********************************************************
97  *
98  *     Func : rgAllocShrablSBuf
99  *
100  *     Desc : Utility Function to Allocate static buffer which is 
101  *            sharable among different layers if YYYY flag is enabled. 
102  *            else it allocates from normal static region
103  *            Memory allocated is assumed contiguous.
104  *            
105  *
106  *     Ret  : ROK
107  *            RFAILED
108  *
109  *     Notes: Caller doesnt need to raise the alarm in case of memory
110  *            allocation gets failed. 
111  *
112  *     File : rg_utl.c
113  *
114  **********************************************************/
115 #ifdef ANSI
116 PUBLIC S16 rgAllocShrablSBuf
117 (
118 Inst    inst,
119 Data    **pData,            /* Pointer of the data to be returned */
120 Size    size                /* size */
121 )
122 #else
123 PUBLIC S16 rgAllocShrablSBuf(inst,pData, size)
124 Inst    inst;
125 Data    **pData;            /* Pointer of the data to be returned */
126 Size    size;               /* size */
127 #endif
128 {
129    RgUstaDgn dgn;      /* Alarm diagnostics structure */
130
131    TRC2(rgAllocShrablSBuf)
132
133    /* Initialize the param to NULLP */
134    *pData = NULLP;
135
136    if (size == 0)
137    {
138       RETVALUE(RFAILED);
139    }
140
141    /* allocate buffer */
142    if (SGetStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size, 0) != ROK)
143    {
144      dgn.type = LRG_USTA_DGNVAL_MEM;
145      dgn.u.mem.region = rgCb[inst].rgInit.region;
146      dgn.u.mem.pool = rgCb[inst].rgInit.pool;
147      /*  Send an alarm to Layer Manager */
148      rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
149                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
150       RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
151       RETVALUE(RFAILED);
152    }
153
154 #ifndef ALIGN_64BIT
155    RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%ld)), Data (0x%p))\n",
156              rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
157 #else
158    RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%d)), Data (0x%p))\n",
159              rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
160 #endif
161
162    /* zero out the allocated memory */
163    cmMemset((U8 *)*pData, 0x00, size);
164
165    RETVALUE(ROK);
166
167 } /* end of rgAllocSBuf */
168
169
170 /***********************************************************
171  *
172  *     Func : rgAllocSBuf
173  *
174  *     Desc : Utility Function to Allocate static buffer. 
175  *            Memory allocated is assumed contiguous.
176  *            
177  *
178  *     Ret  : ROK
179  *            RFAILED
180  *
181  *     Notes: Caller doesnt need to raise the alarm in case of memory
182  *            allocation gets failed. 
183  *
184  *     File : rg_utl.c
185  *
186  **********************************************************/
187 #ifdef ANSI
188 PUBLIC S16 rgAllocSBuf
189 (
190 Inst    inst,
191 Data    **pData,            /* Pointer of the data to be returned */
192 Size    size                /* size */
193 )
194 #else
195 PUBLIC S16 rgAllocSBuf(inst,pData, size)
196 Inst    inst;
197 Data    **pData;            /* Pointer of the data to be returned */
198 Size    size;               /* size */
199 #endif
200 {
201    RgUstaDgn dgn;      /* Alarm diagnostics structure */
202
203    TRC2(rgAllocSBuf)
204
205    /* Initialize the param to NULLP */
206    *pData = NULLP;
207
208    if (size == 0)
209    {
210       RETVALUE(RFAILED);
211    }
212
213    /* allocate buffer */
214 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
215    MS_BUF_ADD_ALLOC_CALLER();
216 #endif /* */
217    if (SGetSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size) != ROK)
218    {
219      dgn.type = LRG_USTA_DGNVAL_MEM;
220      dgn.u.mem.region = rgCb[inst].rgInit.region;
221      dgn.u.mem.pool = rgCb[inst].rgInit.pool;
222      /*  Send an alarm to Layer Manager */
223      rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
224                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
225       RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
226       RETVALUE(RFAILED);
227    }
228
229    /* zero out the allocated memory */
230    cmMemset((U8 *)*pData, 0x00, size);
231
232    RETVALUE(ROK);
233
234 } /* end of rgAllocSBuf */
235
236 /*
237 *
238 *       Fun:   rgFreeSharableSBuf
239 *
240 *       Desc:  The argument to rgFreeSBuf() is a pointer to a block
241 *              previously allocated by rgAllocSBuf() and size. It 
242 *              deallocates the memory. 
243 *
244 *       Ret:   RETVOID
245 *
246 *       Notes: ccpu00117052 - MOD- changed the Data parameter from 
247 *                             pointer to address of pointer so that
248 *                             the freed memory could be set to NULLP
249 *
250 *       File:  rg_utl.c
251 */
252 #ifdef ANSI
253 PUBLIC Void rgFreeSharableSBuf
254 (
255 Inst inst,
256 Data **data,         /* address of pointer to data */
257 Size size            /* size */
258 )
259 #else
260 PUBLIC Void rgFreeSharableSBuf(inst,data, size)
261 Inst inst;
262 Data **data;         /* address of pointer to data */
263 Size size;          /* size */
264 #endif
265 {
266
267    S16 ret;
268
269    TRC2(rgFreeSharableBuf)
270
271    if ((data == NULLP) || (*data == NULLP) || (size == 0))
272    {
273       RETVOID;
274    }
275
276    /* Deallocate buffer */
277    ret = SPutStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size, SS_SHARABLE_MEMORY);
278
279    if (ret != ROK)
280    {
281       RETVOID;
282    }
283
284    *data = NULLP;
285
286    RETVOID;
287
288 } /* end of rgFreeSharableBuf */
289
290
291
292 /*
293 *
294 *       Fun:   rgFreeSBuf
295 *
296 *       Desc:  The argument to rgFreeSBuf() is a pointer to a block
297 *              previously allocated by rgAllocSBuf() and size. It 
298 *              deallocates the memory. 
299 *
300 *       Ret:   RETVOID
301 *
302 *       Notes: ccpu00117052 - MOD- changed the Data parameter from 
303 *                             pointer to address of pointer so that
304 *                             the freed memory could be set to NULLP
305 *
306 *       File:  rg_utl.c
307 */
308 #ifdef ANSI
309 PUBLIC Void rgFreeSBuf
310 (
311 Inst inst,
312 Data **data,         /* address of pointer to data */
313 Size size            /* size */
314 )
315 #else
316 PUBLIC Void rgFreeSBuf(inst,data, size)
317 Inst  inst;
318 Data **data;         /* address of pointer to data */
319 Size size;          /* size */
320 #endif
321 {
322
323    S16 ret;
324
325    TRC2(rgFreeSBuf)
326
327    if ((data == NULLP) || (*data == NULLP) || (size == 0))
328    {
329       RETVOID;
330    }
331
332
333 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
334    MS_BUF_ADD_CALLER();
335 #endif /* */
336    /* Deallocate buffer */
337    ret = SPutSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size);
338
339    if (ret != ROK)
340    {
341       RGLOGERROR(inst,ERRCLS_DEBUG, ERG029, (ErrVal) 0, "rgFreeSBuf failed.\n");
342       RETVOID;
343    }
344
345    *data = NULLP;
346
347    RETVOID;
348
349 } /* end of rgFreeSBuf */
350
351
352 /***********************************************************
353  *
354  *     Func : rgGetMsg
355  *
356  *     Desc : Utility Function to Allocate message buffer. 
357  *            
358  *
359  *     Ret  : ROK
360  *            RFAILED
361  *
362  *     Notes: Caller doesnt need to raise the alarm in case of memory
363  *            allocation gets failed. 
364  *
365  *     File : rg_utl.c
366  *
367  **********************************************************/
368 #ifdef ANSI
369 PUBLIC S16 rgGetMsg
370 (
371 Inst    inst,
372 Buffer  **mBuf            /* Message Buffer pointer be returned */
373 )
374 #else
375 PUBLIC S16 rgGetMsg(inst,mBuf)
376 Inst    inst;
377 Buffer  **mBuf;           /* Message Buffer pointer be returned */
378 #endif
379 {
380    S16         ret;
381
382    TRC2(rgGetMsg)
383
384 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
385    MS_BUF_ADD_ALLOC_CALLER();
386 #endif /* */
387    ret = SGetMsg(RG_GET_MEM_REGION(rgCb[inst]), RG_GET_MEM_POOL(rgCb[inst]), mBuf);
388
389    if (ROK != ret) 
390    {
391       /* Moving diagnostics structure to limited scope for optimization */
392       RgUstaDgn   dgn;      /* Alarm diagnostics structure */
393
394       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
395
396       /*  Send an alarm to Layer Manager */
397       rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
398                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
399       RGLOGERROR(inst,ERRCLS_DEBUG, ERG030, 0, "Unable to Allocate Buffer");
400       RETVALUE(RFAILED);
401    }
402
403    RETVALUE(ROK);
404
405 } /* end of rgGetMsg */
406
407
408 /***********************************************************
409  *
410  *     Func : rgFillDgnParams
411  *
412  *     Desc : Utility Function to Fill Diagonostic params. 
413  *
414  *     Ret  : None.
415  *
416  *     Notes: None.
417  *
418  *     File : rg_utl.c
419  *
420  **********************************************************/
421 #ifdef ANSI
422 PUBLIC Void rgFillDgnParams
423 (
424 Inst        inst,
425 RgUstaDgn   *dgn,
426 U8          dgnType
427 )
428 #else
429 PUBLIC Void rgFillDgnParams(inst,dgn, dgnType)
430 Inst        inst;
431 RgUstaDgn   *dgn;
432 U8          dgnType;
433 #endif
434 {
435
436    TRC2(rgFillDgnParams)
437
438    switch(dgnType)
439    {
440       case LRG_USTA_DGNVAL_MEM:
441          dgn->type = (U8) LRG_USTA_DGNVAL_MEM;
442          dgn->u.mem.region  = rgCb[inst].rgInit.region;
443          dgn->u.mem.pool    = rgCb[inst].rgInit.pool;
444       break;
445
446       default:
447       break;
448    }
449
450    RETVOID;
451 } /* end of rgFillDgnParams */
452
453
454 /***********************************************************
455  *
456  *     Func : rgUpdtRguDedSts
457  *
458  *     Desc : Utility Function to update rgu sap statistics for dedicated
459  *            DatReqs.
460  *            
461  *
462  *     Ret  : ROK
463  *            RFAILED
464  *
465  *     Notes: 
466  *
467  *     File : rg_utl.c
468  *
469  **********************************************************/
470 #ifdef ANSI
471 PUBLIC Void rgUpdtRguDedSts
472 (
473 Inst           inst,
474 RgUpSapCb     *rguDlSap,
475 U8             stsType,   /* Statistics type to update */
476 RgRguDedDatReq *datReq    /* DatReq pointer */
477 )
478 #else
479 PUBLIC Void rgUpdtRguDedSts(inst,rguDlSap,stsType, datReq)
480 Inst           inst;
481 RgUpSapCb     *rguDlSap;
482 U8             stsType;   /* Statistics type to update */
483 RgRguDedDatReq *datReq;   /* DatReq pointer */
484 #endif
485 {
486    U8 idx1,idx2;
487    U32 idx;
488
489
490    TRC2(rgUpdtRguDedSts)
491
492
493    switch(stsType)
494    {
495       case RG_RGU_SDU_RCVD:
496       for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
497       {
498          RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
499          for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++) 
500          {
501             for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++) 
502             {
503                rguDlSap->sapSts.numPduRcvd +=
504                   datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
505             }
506          }
507       }
508
509          break;
510       case RG_RGU_SDU_DROP:
511       for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
512       {
513          RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
514          for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++) 
515          {
516             for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++) 
517             {
518                rguDlSap->sapSts.numPduRcvd +=
519                   datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
520                rguDlSap->sapSts.numPduDrop +=
521                   datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
522             }
523          }
524       }
525
526          break;
527    }
528    
529    RETVOID;
530 } /* rgUpdtRguDedSts */
531
532
533 /***********************************************************
534  *
535  *     Func : rgUpdtRguCmnSts
536  *
537  *     Desc : Utility Function to update rgu sap statistics for common
538  *            DatReqs.
539  *            
540  *
541  *     Ret  : ROK
542  *            RFAILED
543  *
544  *     Notes: 
545  *
546  *     File : rg_utl.c
547  *
548  **********************************************************/
549 #ifdef ANSI
550 PUBLIC Void rgUpdtRguCmnSts
551 (
552 Inst           inst,
553 RgUpSapCb     *rguDlSap,
554 U8             stsType   /* Statistics type to update */
555 )
556 #else
557 PUBLIC Void rgUpdtRguCmnSts(inst,rguDlSap,stsType)
558 Inst           inst;
559 RgUpSapCb     *rguDlSap;
560 U8             stsType;   /* Statistics type to update */
561 #endif
562 {
563    TRC2(rgUpdtRguCmnSts)
564
565
566
567    switch(stsType)
568    {
569       case RG_RGU_SDU_RCVD:
570          rguDlSap->sapSts.numPduRcvd ++;
571          break;
572       case RG_RGU_SDU_DROP:
573          rguDlSap->sapSts.numPduRcvd ++;
574          rguDlSap->sapSts.numPduDrop ++;
575          break;
576    }
577    
578    RETVOID;
579 } /* rgUpdtRguCmnSts */
580
581
582 /***********************************************************
583  *
584  *     Func : rgUpdtCellCnt
585  *
586  *     Desc : Utility Function to update cell count. It gives number of active
587  *     cells
588  *            
589  *
590  *     Ret  : ROK
591  *            RFAILED
592  *
593  *     Notes: This function should be called only after cell is added/deleted 
594  *     from the globlal hashlist
595  *
596  *     File : rg_utl.c
597  *
598  **********************************************************/
599 #ifdef ANSI
600 PUBLIC Void rgUpdtCellCnt
601 (
602 Inst inst,
603 U8 updtType
604 )
605 #else
606 PUBLIC Void rgUpdtCellCnt(inst,updtType)
607 Inst inst;
608 U8 updtType;
609 #endif
610 {
611    TRC2(rgUpdtCellCnt);
612
613    switch (updtType)
614    {
615       case RG_CFG_ADD:
616          rgCb[inst].genSts.numCellCfg++;
617          break;
618       case RG_CFG_DEL:
619          rgCb[inst].genSts.numCellCfg--;
620          break;
621       default:
622          break;
623    }
624
625    RETVOID;
626 } /* rgUpdtCellCnt */
627
628
629 /***********************************************************
630  *
631  *     Func : rgUpdtUeCnt
632  *
633  *     Desc : Utility Function to update ue count. It gives number of active
634  *     Ues.
635  *            
636  *
637  *     Ret  : ROK
638  *            RFAILED
639  *
640  *     Notes: This function should be called only after ue is added/deleted 
641  *     from the globlal hashlist
642  *
643  *     File : rg_utl.c
644  *
645  **********************************************************/
646 #ifdef ANSI
647 PUBLIC Void rgUpdtUeCnt
648 (
649 Inst inst,
650 U8 updtType
651 )
652 #else
653 PUBLIC Void rgUpdtUeCnt (inst,updtType)
654 Inst inst;
655 U8 updtType;
656 #endif
657 {
658    TRC2(rgUpdtUeCnt);
659
660    switch (updtType)
661    {
662       case RG_CFG_ADD:
663          rgCb[inst].genSts.numUeCfg++;
664          break;
665       case RG_CFG_DEL:
666          rgCb[inst].genSts.numUeCfg--;
667          break;
668       default:
669          break;
670    }
671    RETVOID;
672 } /* rgUpdtUeCnt */
673
674 /*
675 *
676 *       Fun:   rgAllocEventMem
677 *
678 *       Desc:  This function allocates event memory 
679 *
680 *       Ret:   ROK      - on success
681 *              RFAILED  - on failure
682 *
683 *       Notes: None
684 *
685 *       File:  rg_utl.c
686 *
687 */
688 #ifdef ANSI
689 PUBLIC S16 rgAllocEventMem
690 (
691 Inst     inst,
692 Ptr       *memPtr,
693 Size      memSize
694 )
695 #else
696 PUBLIC S16 rgAllocEventMem(inst,memPtr, memSize)
697 Inst     inst;
698 Ptr       *memPtr;
699 Size      memSize;
700 #endif
701 {
702    Mem              sMem;
703    VOLATILE U32     startTime=0;
704
705    TRC2(rgAllocEventMem)
706
707    sMem.region = rgCb[inst].rgInit.region;
708    sMem.pool = rgCb[inst].rgInit.pool;
709
710 #if (ERRCLASS & ERRCLS_DEBUG)
711    if (memSize<= 0)
712    {
713       RGLOGERROR(inst,ERRCLS_INT_PAR, ERG031, memSize,
714                    "rgAllocEventMem(): memSize invalid\n");
715       RETVALUE (RFAILED);
716    }
717 #endif /* ERRCLASS & ERRCLS_DEBUG */
718
719
720    /*starting Task*/
721    SStartTask(&startTime, PID_MACUTL_CMALLCEVT);
722
723 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
724    MS_BUF_ADD_ALLOC_CALLER();
725 #endif /* */
726 #ifdef TFU_ALLOC_EVENT_NO_INIT
727    if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
728 #else
729    if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
730 #endif /* */
731    {
732       RLOG0(L_ERROR,"cmAllocEvnt Failed"); 
733       RETVALUE(RFAILED);
734    }
735
736    /*stoping Task*/
737    SStopTask(startTime, PID_MACUTL_CMALLCEVT);
738
739    RETVALUE(ROK);
740 } /* end of rgAllocEventMem*/
741
742 /*
743 *
744 *       Fun:   rgGetEventMem
745 *
746 *       Desc:  This function allocates event memory 
747 *
748 *       Ret:   ROK      - on success
749 *              RFAILED  - on failure
750 *
751 *       Notes: None
752 *
753 *       File:  rg_utl.c
754 *
755 */
756 #ifdef ANSI
757 PUBLIC S16 rgGetEventMem
758 (
759 Inst      inst,
760 Ptr       *ptr,
761 Size      len,
762 Ptr       memCp
763 )
764 #else
765 PUBLIC S16 rgGetEventMem(inst,ptr, len, memCp)
766 Inst      inst;
767 Ptr       *ptr;
768 Size      len;
769 Ptr       memCp;
770 #endif
771 {
772    S16   ret;
773
774    TRC2(rgGetEventMem)
775 #ifdef TFU_ALLOC_EVENT_NO_INIT
776    ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
777 #else
778    ret = cmGetMem(memCp, len, (Ptr *)ptr);
779 #endif /* */
780    RETVALUE(ret);
781 } /* end of rgGetEventMem*/
782
783 /***********************************************************
784  *
785  *     Func : rgGetPstToInst
786  *
787  *     Desc : Utility Function to get the pst structure to post a message to
788  *     scheduler instance
789  *            
790  *
791  *     Ret  : ROK
792  *            RFAILED
793  *
794  *     Notes: This function should be called while sending a msg from 
795  *     MAC to a scheduler instance
796  *
797  *     File : rg_utl.c
798  *
799  **********************************************************/
800 #ifdef ANSI
801 PUBLIC Void rgGetPstToInst
802 (
803 Pst           *pst,
804 Inst          srcInst,
805 Inst          dstInst
806 )
807 #else
808 PUBLIC Void rgGetPstToInst (pst, srcInst, dstInst)
809 Pst           *pst;
810 Inst          srcInst;
811 Inst          dstInst;
812 #endif
813 {
814    TRC2(rgGetPstToInst);
815
816    pst->srcEnt = rgCb[srcInst].rgInit.ent; 
817    pst->srcInst = rgCb[srcInst].rgInit.inst;
818    pst->srcProcId = rgCb[srcInst].rgInit.procId;
819    pst->region = rgCb[srcInst].rgInit.region;
820    pst->pool = rgCb[srcInst].rgInit.pool;
821
822    pst->dstProcId = rgCb[dstInst].rgInit.procId;
823    pst->dstEnt = rgCb[dstInst].rgInit.ent; 
824    pst->dstInst = dstInst;
825    pst->selector = 0;
826    pst->prior     = PRIOR0;
827    pst->intfVer   = 0;
828    pst->route   = RTESPEC;
829
830    RETVOID; 
831 } /* end of rgGetPstToInst */
832
833 /***********************************************************
834  *
835  *     Func : RgSchMacLcgRegReq
836  *
837  *     Desc : Utility Function to register the set of GBR LCG.
838  *        Invoked at the time of LCG configuration/Reconfiguration at Schedular.
839  * 
840  *     Processing Steps: 
841  *           - Fetch the ueCb using the crnti given in lcInfo            
842  *           - Store the if LCG is GBR or not.
843  *
844  *     Ret  : ROK
845  *            RFAILED
846  *
847  *     Notes: This function should be called at the time of LCG 
848  *     configuration/Reconfiguration at Schedular. 
849  *     
850  *
851  *     File : rg_utl.c
852  *
853  **********************************************************/
854 #ifdef ANSI
855 PUBLIC S16 RgSchMacLcgRegReq
856 (
857 Pst            *pst,
858 RgInfLcgRegReq *lcgRegReq
859 )
860 #else
861 PUBLIC S16 RgSchMacLcgRegReq (pst, lcgRegReq)
862 Pst            *pst;
863 RgInfLcgRegReq *lcgRegReq;
864 #endif
865 {
866    Inst       inst;
867    RgCellCb   *cell = NULLP;
868    RgUeCb     *ue;
869
870    TRC2(RgSchMacLcgRegReq);
871
872    RG_IS_INST_VALID(pst->dstInst);
873    inst   = pst->dstInst - RG_INST_START;
874    cell   = rgCb[inst].cell;
875    /* Fetch the cell and then the UE */
876    if((cell == NULLP) ||
877       (cell->cellId != lcgRegReq->cellId))
878    {
879       
880       RLOG_ARG0(L_ERROR,DBG_CELLID,lcgRegReq->cellId,"Cell does not exist ");
881       RETVALUE(RFAILED);
882    }
883
884    if ((ue = rgDBMGetUeCb(cell, lcgRegReq->crnti)) == NULLP)
885    {
886       RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist", 
887                          lcgRegReq->crnti);
888       RETVALUE(RFAILED);
889    }
890    ue->ul.lcgArr[lcgRegReq->lcgId].isGbr = lcgRegReq->isGbr;
891
892    RETVALUE(ROK); 
893 } /* end of RgSchMacLcgRegReq */
894
895 #ifdef LTEMAC_SPS
896
897 /***********************************************************
898  *
899  *     Func : RgSchMacUlSpsResetReq
900  *
901  *     Desc : Utility Function to reset SPS params for a UE
902  * 
903  *     Processing Steps: 
904  *           - Fetch the ueCb using the crnti 
905  *           - reset implRelCnt and explRelCnt
906  *
907  *     Ret  : ROK
908  *            RFAILED
909  *
910  *     File : rg_utl.c
911  *
912  **********************************************************/
913 #ifdef ANSI
914 PUBLIC S16 RgSchMacUlSpsResetReq
915 (
916 Pst            *pst,
917 RgInfUlSpsReset *ulSpsResetInfo
918 )
919 #else
920 PUBLIC S16 RgSchMacUlSpsResetReq (pst, lcInfo)
921 Pst            *pst;
922 RgInfUlSpsReset *ulSpsResetInfo;
923 #endif
924 {
925    Inst       inst;
926    RgCellCb   *cell = NULLP;
927    RgUeCb     *ue;
928
929    TRC2(RgSchMacUlSpsResetReq);
930
931    RG_IS_INST_VALID(pst->dstInst);
932    inst   = pst->dstInst - RG_INST_START;
933    cell   = rgCb[inst].cell;
934    /* Fetch the cell and then the UE */
935    if((cell == NULLP)||
936       (cell->cellId != ulSpsResetInfo->cellId))
937    {
938       
939       RLOG_ARG0(L_ERROR, DBG_CELLID,ulSpsResetInfo->cellId,"Cell does not exist ");
940       RETVALUE(RFAILED);
941    }
942
943    if ((ue = rgDBMGetUeCb(cell, ulSpsResetInfo->crnti)) == NULLP)
944    {
945       RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist", 
946                       ulSpsResetInfo->crnti);
947       RETVALUE(RFAILED);
948    }
949
950    ue->ul.implRelCntr = 0;
951    ue->ul.explRelCntr = 0;
952
953    RETVALUE(ROK); 
954 } /* end of RgSchMacUlSpsResetReq */
955
956
957
958
959 /***********************************************************
960  *
961  *     Func : RgSchMacSpsLcRegReq
962  *
963  *     Desc : Utility Function to register the set of uplink SPS logical
964  *        channels for a SPS UE.
965  *        Invoked at the time of activation of a UE for UL-SPS.
966  *        Whenever there is data on these LCs MAC shall inform scheduler
967  * 
968  *     Processing Steps: 
969  *           - Fetch the ueCb using the crnti given in lcInfo            
970  *           - Store the sps-rnti and set the bits corresponding to the
971  *             logical channel ids in ueUlCb->spsLcMask.
972  *
973  *     Ret  : ROK
974  *            RFAILED
975  *
976  *     Notes: This function should be called at the time UL SPS is activated 
977  *     for a UE at scheduler
978  *     
979  *
980  *     File : rg_utl.c
981  *
982  **********************************************************/
983 #ifdef ANSI
984 PUBLIC S16 RgSchMacSpsLcRegReq
985 (
986 Pst            *pst,
987 RgInfSpsLcInfo *lcInfo
988 )
989 #else
990 PUBLIC S16 RgSchMacSpsLcRegReq (pst, lcInfo)
991 Pst            *pst;
992 RgInfSpsLcInfo *lcInfo;
993 #endif
994 {
995    Inst       inst;
996    RgCellCb   *cell= NULLP;
997    RgUeCb     *ue;
998    U8         idx;
999
1000    TRC2(RgSchMacSpsLcRegReq);
1001
1002    RG_IS_INST_VALID(pst->dstInst);
1003    inst   = pst->dstInst - RG_INST_START;
1004    cell   = rgCb[inst].cell;
1005    /* Fetch the cell and then the UE */
1006    if((cell == NULLP) ||
1007       (cell->cellId != lcInfo->cellId))
1008    {
1009       
1010       RLOG_ARG0(L_ERROR,DBG_CELLID,lcInfo->cellId, "Cell does not exist ");
1011       RETVALUE(RFAILED);
1012    }
1013
1014    if ((ue = rgDBMGetUeCb(cell, lcInfo->crnti)) == NULLP)
1015    {
1016       RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist", 
1017                       lcInfo->crnti);
1018       RETVALUE(RFAILED);
1019    }
1020
1021    /* Store the sps-rnti and SPS LC information in the UE */ 
1022    ue->spsRnti = lcInfo->spsRnti;
1023    for (idx=0; idx < lcInfo->spsLcCnt; idx++)
1024    {
1025       /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
1026       ue->ul.spsLcId[(lcInfo->spsLcId[idx])-1] = TRUE;
1027    }
1028    ue->ul.implRelCnt = lcInfo->implRelCnt;
1029    ue->ul.explRelCnt = ue->ul.implRelCnt + 1; /*(lcInfo->implRelCnt * lcInfo->spsPrd);*/
1030
1031    /* Insert the UE into SPS UE List */
1032    if (rgDBMInsSpsUeCb(cell, ue) == RFAILED)
1033    {
1034       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1035                     "Ue insertion into SPS list failed SPS CRNTI:%d", ue->spsRnti);
1036       RETVALUE(RFAILED);
1037    } 
1038
1039    RETVALUE(ROK); 
1040 } /* end of RgSchMacSpsLcRegReq */
1041
1042
1043 /***********************************************************
1044  *
1045  *     Func : RgSchMacSpsLcDeregReq
1046  *
1047  *     Desc : Utility Function to deregister the set of uplink SPS 
1048  *        logical channels for a UE.
1049  *        Invoked at the time of release of UL-SPS for an activated UE.
1050  * 
1051  *     Processing Steps: 
1052  *           - Fetch the ueCb using the crnti given
1053  *           - Reset the bits corresponding to the logical channel ids in
1054  *             ueUlCb->spsLcMask.
1055  *
1056  *     Ret  : ROK
1057  *            RFAILED
1058  *
1059  *     Notes: This function should be called at the time UL SPS is released 
1060  *     for a UE at scheduler
1061  *     
1062  *
1063  *     File : rg_utl.c
1064  *
1065  **********************************************************/
1066 #ifdef ANSI
1067 PUBLIC S16 RgSchMacSpsLcDeregReq
1068 (
1069 Pst            *pst,
1070 CmLteCellId    cellId,
1071 CmLteRnti      crnti
1072 )
1073 #else
1074 PUBLIC S16 RgSchMacSpsLcDeregReq (pst, cellId, crnti)
1075 Pst            *pst;
1076 CmLteCellId    cellId;
1077 CmLteRnti      crnti;
1078 #endif
1079 {
1080    Inst       inst;
1081    RgCellCb   *cell = NULLP;
1082    RgUeCb      *ue;
1083
1084    TRC2(RgSchMacSpsLcDeregReq);
1085
1086    RG_IS_INST_VALID(pst->dstInst);
1087    inst   = pst->dstInst - RG_INST_START;
1088    cell   = rgCb[inst].cell;
1089    /* Fetch the cell and then the UE */
1090    if((cell == NULLP) ||
1091       (cell->cellId != cellId))
1092    {
1093       
1094       RLOG_ARG0(L_ERROR,DBG_CELLID,cellId, "Cell does not exist ");
1095       RETVALUE(RFAILED);
1096    }
1097
1098    if ((ue = rgDBMGetUeCb(cell, crnti)) == NULLP)
1099    {
1100       RLOG_ARG1(L_ERROR, DBG_CELLID,cellId,"CRNTI:%d Ue does not exist", crnti);
1101       RETVALUE(RFAILED);
1102    }
1103
1104    /* No need to reset the SPS LC Ids as they will not be looked at*/
1105
1106    /* Delete UE from the SPS UE List */
1107    rgDBMDelSpsUeCb(cell, ue);
1108    
1109    RETVALUE(ROK); 
1110 } /* end of RgSchMacSpsLcDeregReq */
1111
1112 #endif /* LTEMAC_SPS */
1113
1114 /**
1115  * @brief Function for handling CRNTI change request 
1116  * received from scheduler to MAC.
1117  *
1118  * @details
1119  *
1120  *     Function : rgUtlHndlCrntiChng
1121  *     
1122  *        - Delete old UE from the list.
1123  *        - Update the new rnti and re-insert the UE in the list.
1124  *     
1125  *           
1126  *  @param[in] Inst        inst
1127  *  @param[in] RgCellCb      *cell,
1128  *  @param[in] CmLteRnti     rnti,
1129  *  @param[in] CmLteRnti     newRnti
1130  *  @return  S16
1131  *      -# ROK 
1132  *      -# RFAILED
1133  **/
1134 #ifdef ANSI
1135 PRIVATE S16 rgUtlHndlCrntiChng 
1136 (
1137 Inst            inst,
1138 RgCellCb        *cell,
1139 CmLteRnti       rnti,
1140 CmLteRnti       newRnti
1141 )
1142 #else
1143 PRIVATE S16 rgUtlHndlCrntiChng(inst,cell, rnti, newRnti)
1144 Inst            inst;
1145 RgCellCb        *cell;
1146 CmLteRnti       rnti;
1147 CmLteRnti       newRnti;
1148 #endif
1149 {
1150    RgUeCb         *ue = NULLP;
1151    RgUeCb         *newUe = NULLP;
1152
1153    TRC3(rgUtlHndlCrntiChng)
1154
1155    ue = rgDBMGetUeCb(cell, rnti);
1156    newUe = rgDBMGetUeCbFromRachLst(cell, newRnti);
1157    if ((ue == NULLP) || (newUe == NULLP))
1158    {
1159       RLOG_ARG4(L_ERROR,DBG_CELLID,cell->cellId,
1160                         "RNTI:%d Failed to get UECB[%lu:%lu] or NEW RNTI:%d", 
1161                rnti, ((PTR)ue), ((PTR)newUe), newRnti);
1162       RETVALUE(RFAILED);
1163    }
1164 #ifdef XEON_SPECIFIC_CHANGES
1165    CM_LOG_DEBUG(CM_LOG_ID_MAC, "MAC:UE[%d] id changed to %d\n", rnti, newRnti);
1166 #endif
1167    rgDBMDelUeCb(cell, ue);
1168
1169    ue->ueId = newRnti;
1170
1171    cmMemcpy((U8*)&(ue->contResId), (U8*)&(newUe->contResId), 
1172                    sizeof(newUe->contResId));
1173    /* Fix : syed MSG4 might be RETXing need to store the
1174     * HARQ context. */
1175    rgDHMFreeUe(inst,&ue->dl.hqEnt);
1176    ue->dl.hqEnt = newUe->dl.hqEnt;
1177        
1178    rgDBMInsUeCb(cell, ue);
1179
1180    rgDBMDelUeCbFromRachLst(cell, newUe);
1181    rgFreeSBuf(inst,(Data **)&newUe, sizeof(*newUe));
1182
1183    RETVALUE(ROK);
1184 } /* end of rgUtlHndlCrntiChng */
1185
1186 #ifdef LTE_ADV
1187 /**
1188  * @brief Function for handling UE  release for SCELL
1189  * triggered from SCH to MAC.
1190  *
1191  * @details
1192  *
1193  *     Function : rgDelUeFrmAllSCell
1194  *     
1195  *        - This Function should be invoked by PCell of UE
1196  *        - Remove the UE context from SCELL corresponding to rnti.
1197  *           
1198  *  @param[in] Inst      *macInst,
1199  *  @param[in] RgUeCb    *ue
1200  *  @return  ROK is SUCCESS 
1201  **/
1202 #ifdef ANSI
1203 PUBLIC S16 rgDelUeFrmAllSCell
1204 (
1205 RgCellCb      *cell,
1206 RgUeCb        *ue
1207 )
1208 #else
1209 PUBLIC S16 rgDelUeFrmAllSCell(cell, ue)
1210 RgCellCb      *cell;
1211 RgUeCb        *ue;
1212 #endif
1213 {
1214    Inst        inst     = cell->macInst - RG_INST_START;
1215    U8          idx      = 0;
1216    Inst        sCellInstIdx;
1217    Pst         dstInstPst;
1218    RgPrgUeSCellDelInfo ueSCellDelInfo;
1219
1220    TRC2(rgDelUeFrmAllSCell)
1221
1222    /* To Delete the SCells if exisits for that UE */
1223    for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1224    {
1225       if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1226       {
1227          sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1228
1229          rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1230          ueSCellDelInfo.ueId = ue->ueId;
1231          ueSCellDelInfo.sCellId = ue->sCelInfo[idx].sCellId;
1232
1233          /* Filling same ueId in newRnti so that SMAC will check if newRnti
1234           *and old UeId is same that means its a UeSCell delete request*/
1235          ueSCellDelInfo.newRnti = ue->ueId;
1236
1237          RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueSCellDelInfo);
1238          ue->sCelInfo[idx].isSCellAdded = FALSE;
1239       } /* loop of if */
1240    } /* loop of for */
1241
1242    RETVALUE(ROK);
1243 } /* rgDelUeFrmAllSCell */
1244
1245 /**
1246  * @brief Function to validate AddSCellCfg.
1247  *
1248  * @details
1249  *
1250  *     Function : rgUtlVltdAddSCellCfg
1251  *     
1252  *           
1253  *  @param[in] ueSCellCb   secondary cell CB for validation
1254  *  @param[in] cell        cell control block
1255  *  @param[in] inst        instance number to fetch rgCb instance
1256  *  @return  S16
1257  *      -# ROK 
1258  **/
1259 #ifdef ANSI
1260 PUBLIC S16 rgUtlVltdAddSCellCfg
1261 (
1262  RgPrgUeSCellCfgInfo *ueSCellCb,
1263  RgCellCb    *cell,
1264  Inst        inst
1265 )
1266 #else
1267 PUBLIC S16 rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst)
1268  RgPrgUeSCellCfgInfo *ueSCellCb;
1269  RgCellCb    *cell;
1270  Inst        inst;
1271 #endif
1272 {
1273   S16 ret = ROK; 
1274   
1275   TRC3(rgUtlVltdAddSCellCfg)
1276   
1277      /* To Validate the CellID presence */
1278   if((cell == NULLP) ||
1279         (cell->cellId != ueSCellCb->cellId))
1280   {
1281      RGDBGERRNEW(inst, (rgPBuf(inst),
1282               "[%d]Sec Cell does not exit %d\n",
1283               ueSCellCb->ueId, ueSCellCb->cellId));
1284      ret = RFAILED;
1285   }
1286 #ifdef TENB_MULT_CELL_SUPPRT
1287    if((ueSCellCb->rguDlSapId > rgCb[inst].numRguSaps) ||
1288       (ueSCellCb->rguUlSapId > rgCb[inst].numRguSaps))
1289    {
1290       RGDBGERRNEW(inst,(rgPBuf(inst), "Invald Sap Id: DL %d UL %d for ueId %d failed\n",
1291                ueSCellCb->rguDlSapId,
1292                ueSCellCb->rguUlSapId,
1293                ueSCellCb->cellId));
1294      ret = RFAILED;
1295    }
1296 #endif
1297    RETVALUE(ret);
1298 } /* rgUtlVltdAddSCellCfg */
1299
1300 /**
1301  * @brief Function to build CrntiChangeReq and send to all SMACs.
1302  *
1303  * @details
1304  *
1305  *     Function : rgUtlSndCrntiChngReq2AllSMacs
1306  *     
1307  *        - This Function should be invoked by PCell of UE
1308  *        - It sends RgPrgPMacSMacUeSCellDelReq to all SMACs with newRnti sent
1309  *          by SCH. SMAC will check if newRnti is not equal to old UeId then it
1310  *          do only UeId change else it will delete the UeScell context
1311  *           
1312  *  @param[in] cell    Cell CB to get Ue control block
1313  *  @param[in] rnti    Ue Identifier used to fill in UeId Change req
1314  *  @param[in] newRnti UE new identifier, to be used in UeId Change req
1315  *  @return  S16
1316  *      -# ROK 
1317  **/
1318 #ifdef ANSI
1319 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs
1320 (
1321 RgCellCb        *cell,
1322 CmLteRnti       rnti,
1323 CmLteRnti       newRnti
1324 )
1325 #else
1326 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs(cell, rnti, newRnti)
1327 RgCellCb        *cell;
1328 CmLteRnti       rnti;
1329 CmLteRnti       newRnti;
1330 #endif
1331 {
1332    Inst                inst = cell->macInst - RG_INST_START;
1333    Inst                sCellInstIdx;
1334    Pst                 dstInstPst;
1335    RgPrgUeSCellDelInfo ueIdChngReq;
1336    RgUeCb              *ue;
1337    U8                  idx;
1338 #ifdef L2_OPTMZ
1339 TfuDelDatReqInfo delDatReq;
1340 #endif
1341
1342    TRC2(rgUtlSndCrntiChngReq2AllSMacs)
1343
1344    /* use newRnti to get UeCb in PMac because rnti is already changed in PMac*/
1345    ue = rgDBMGetUeCb(cell, newRnti);
1346    if (ue == NULLP)
1347    {
1348       RGDBGERRNEW(inst,(rgPBuf(inst),"[%d]RNTI:Failed to get ueCb \
1349                newRnti=%d\n", rnti, newRnti));
1350       RETVALUE(RFAILED);
1351    }
1352    /* For all added SCells, prepare and send ueIdChngReq */
1353    for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1354    {
1355       if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1356       {
1357          sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1358
1359          rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1360          /* fill old rnti*/
1361          ueIdChngReq.ueId = rnti;
1362          ueIdChngReq.sCellId = ue->sCelInfo[idx].sCellId;
1363          
1364          /* Filling newRnti so that SMAC can check if old ueId and new UeId
1365           *(newRnti) is different then its a UeId change request from PMAC.
1366           * RgPrgPMacSMacUeSCellDelReq is being reused for UeId change req
1367           * from PMAC to SMAC*/
1368          ueIdChngReq.newRnti = newRnti;
1369          
1370          /* Re-using UeSCellDelReq API for UeId change*/
1371          RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueIdChngReq);
1372 #ifdef L2_OPTMZ
1373       /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1374       delDatReq.cellId = ueIdChngReq.sCellId;
1375       delDatReq.ueId = ueIdChngReq.ueId;
1376       rgLIMTfuDelDatReq(sCellInstIdx, &delDatReq);
1377 #endif
1378
1379       } /* loop of if */
1380    } /* loop of for */
1381
1382    RETVALUE(ROK);
1383 } /* rgUtlSndCrntiChngReq2AllSMacs */
1384
1385 #endif /* LTE_ADV */
1386
1387 /**
1388  * @brief Function for handling CRNTI Context release 
1389  * triggered from SCH to MAC.
1390  *
1391  * @details
1392  *
1393  *     Function : rgUtlHndlCrntiRls
1394  *     
1395  *        - Remove the UE context from MAC corresponding to rnti.
1396  *     
1397  *           
1398  *  @param[in] RgCellCb      *cell,
1399  *  @param[in] CmLteRnti     rnti
1400  *  @return  Void 
1401  **/
1402 #ifdef ANSI
1403 PRIVATE Void rgUtlHndlCrntiRls
1404 (
1405 RgCellCb        *cell,
1406 RgInfRlsRnti    *rlsRnti
1407 )
1408 #else
1409 PRIVATE Void rgUtlHndlCrntiRls(cell, rlsRnti)
1410 RgCellCb        *cell;
1411 CmLteRnti       *rlsRnti;
1412 #endif
1413 {
1414    Inst           inst = cell->macInst - RG_INST_START;
1415    RgUeCb        *ue = NULLP;
1416 #ifdef LTEMAC_SPS
1417    RgUeCb         *spsUeCb = NULLP;
1418 #endif
1419
1420    TRC3(rgUtlHndlCrntiRls)
1421
1422    if ((ue = rgDBMGetUeCb(cell, rlsRnti->rnti)) == NULLP)
1423    {
1424       /* Check in RachLst */
1425       if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1426       {
1427          /* Delete Ue from the UE list */
1428          rgDBMDelUeCbFromRachLst(cell, ue);
1429
1430          /* Free Ue */
1431          rgRAMFreeUeCb(inst,ue);
1432       }
1433       else
1434       {
1435          RLOG_ARG1(L_WARNING,DBG_CELLID,cell->cellId,
1436                    "RNTI:%d No ueCb found in RachLst",rlsRnti->rnti);
1437       }
1438    }
1439    else
1440    {
1441 #ifdef LTE_ADV
1442       if(FALSE == rlsRnti->isUeSCellDel)
1443       {
1444          rgDelUeFrmAllSCell(cell, ue);
1445       }
1446 #endif /* LTE_ADV */
1447
1448       /* Delete Ue from the UE list */
1449       rgDBMDelUeCb(cell, ue);
1450 #ifdef LTEMAC_SPS
1451       spsUeCb = rgDBMGetSpsUeCb (cell, ue->spsRnti);
1452       if (spsUeCb)
1453       {
1454          rgDBMDelSpsUeCb(cell, spsUeCb);
1455       }
1456 #endif
1457
1458       /* Free Ue */
1459       rgCFGFreeUeCb(cell, ue);     
1460       /* MS_REMOVE : syed Check in RachLst */
1461       {
1462          if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1463          {
1464             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1465                         "RNTI:%d STALE UE is still present", rlsRnti->rnti);         
1466          }
1467       }
1468    }
1469
1470    RETVOID;
1471 } /* end of rgUtlHndlCrntiRls */
1472
1473 /**
1474  * @brief Function for handling RaResp request received from scheduler to MAC.
1475  *
1476  * @details
1477  *
1478  *     Function : RgSchMacRlsRntiReq
1479  *     
1480  *     This function shall be invoked whenever scheduler is done with the
1481  *     allocations of random access responses for a subframe.
1482  *     This shall invoke RAM to create ueCbs for all the rapIds allocated and 
1483  *     shall invoke MUX to create RAR PDUs for raRntis allocated.
1484  *     
1485  *           
1486  *  @param[in] CmLteCellId         cellId,
1487  *  @param[in] CmLteTimingInfo     timingInfo,
1488  *  @param[in] RaRespInfo          *rarInfo
1489  *  @return  S16
1490  *      -# ROK 
1491  **/
1492 #ifdef ANSI
1493 PUBLIC S16 RgSchMacRlsRntiReq
1494 (
1495 Pst                 *pst,
1496 RgInfRlsRnti        *rlsRnti
1497 )
1498 #else
1499 PUBLIC S16 RgSchMacRlsRntiReq(pst, rlsRnti)
1500 Pst                 *pst;
1501 RgInfRlsRnti        *rlsRnti;
1502 #endif
1503 {
1504 //   Pst            schPst;
1505 //   RgInfUeDelInd  ueDelInd;
1506    Inst           macInst;
1507    RgCellCb       *cell;
1508 #ifdef L2_OPTMZ
1509 TfuDelDatReqInfo delDatReq;
1510 #endif
1511
1512    TRC3(RgSchMacRlsRntiReq)
1513
1514    RG_IS_INST_VALID(pst->dstInst);
1515    macInst   = pst->dstInst - RG_INST_START;
1516    cell   = rgCb[macInst].cell;
1517
1518    if(NULLP == rlsRnti)
1519    {
1520       RETVALUE(RFAILED);
1521    }
1522
1523    if((cell == NULLP) ||
1524       (cell->cellId != rlsRnti->cellId))
1525    {
1526       
1527       RLOG_ARG1(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1528                "No cellCb found with cellId for RNTI:%d", 
1529                          rlsRnti->rnti);
1530       RETVALUE(RFAILED);
1531    }
1532    /* Fix : syed Clearing UE context when SCH indicates to do so
1533     * UE DEL from CRG interface is now dummy. */
1534    if (rlsRnti->ueIdChng)
1535    {
1536       /* Fix : syed ueId change as part of reestablishment.
1537        * Now SCH to trigger this. CRG ueRecfg for ueId change 
1538        * is dummy */       
1539       if (rgUtlHndlCrntiChng(macInst,cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)        
1540       {
1541          RLOG_ARG2(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1542                         "CRNTI change failed for RNTI:%d new RNTI:%d",
1543                    rlsRnti->rnti,rlsRnti->newRnti);
1544          RETVALUE(RFAILED);
1545       }
1546
1547 #ifdef LTE_ADV
1548       /*PMAC_Reest: Prepare CrntiChngReq and then send to all SMACs to change
1549        *rnti in all Scells
1550        */
1551       if(rgUtlSndCrntiChngReq2AllSMacs(cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1552       {
1553          /* TODO: do we need to send DelInd to SCH in failure case*/ 
1554          RETVALUE(RFAILED);
1555       }
1556 #endif
1557 #ifdef L2_OPTMZ
1558       /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1559       delDatReq.cellId = cell->cellId;
1560       delDatReq.ueId = rlsRnti->rnti;
1561       rgLIMTfuDelDatReq(macInst, &delDatReq);
1562 #endif
1563    }
1564    else
1565    {
1566       rgUtlHndlCrntiRls(cell, rlsRnti);
1567    }
1568    /* Fix : syed Send delete confirmation to SCH */
1569    /* Send RgMacSchUeDelInd to SCH only if it is Rnti release to PMAC.
1570     * Basically dont send DelInd to SCH incase of Ue SCell Del*/
1571 #ifdef LTE_ADV
1572    if(FALSE == rlsRnti->isUeSCellDel)
1573 #endif
1574    {
1575       //TODO: commented for compilation without SCH 
1576 #if 0
1577       ueDelInd.cellSapId  = cell->schInstMap.cellSapId;
1578       ueDelInd.cellId  = rlsRnti->cellId;
1579       ueDelInd.rnti    = rlsRnti->rnti; 
1580       rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
1581       RgMacSchUeDel(&schPst, &ueDelInd);
1582 #endif
1583    }
1584
1585    RETVALUE(ROK);
1586 } /* end of RgSchMacRlsRntiReq */
1587
1588 #ifdef L2_OPTMZ
1589 #ifdef ANSI
1590 PUBLIC Bool RgUtlIsTbMuxed
1591 (
1592  TfuDatReqTbInfo *tb
1593 )
1594 #else
1595 PUBLIC Bool RgUtlIsTbMuxed()
1596    TfuDatReqTbInfo *tb
1597 #endif
1598 {
1599    MsgLen len = 0;
1600    SFndLenMsg(tb->macHdr, &len);
1601    RETVALUE(len?TRUE : FALSE);
1602 }
1603 #endif
1604
1605 /**********************************************************************
1606  
1607          End of file
1608 **********************************************************************/