1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 /************************************************************************
25 Desc: C source code for Entry point fucntions
29 **********************************************************************/
32 @brief This file implements utility functions for LTE MAC
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_MODULE_ID=4096;
37 static int RLOG_FILE_ID=179;
39 /* header include files (.h) */
40 #include "envopt.h" /* environment options */
41 #include "envdep.h" /* environment dependent */
42 #include "envind.h" /* environment independent */
44 #include "gen.h" /* general */
45 #include "ssi.h" /* system services */
46 #include "cm_tkns.h" /* Common Token Defines */
47 #include "cm_llist.h" /* Common Link List Defines */
48 #include "cm_hash.h" /* Common Hash List Defines */
49 #include "cm_mblk.h" /* common memory link list library */
50 #include "cm_lte.h" /* Common LTE */
52 #include "rg_env.h" /* MAC Environment Defines */
53 #include "crg.h" /* CRG Interface defines */
54 #include "rgu.h" /* RGU Interface defines */
55 #include "tfu.h" /* TFU Interface defines */
56 #include "rg_sch_inf.h" /* RGR Interface defines */
57 #include "lrg.h" /* LRG Interface defines */
59 #include "rg_prg.h" /* PRG(MAC-MAC) Interface includes */
60 #include "rg.h" /* MAC defines */
61 #include "rg_err.h" /* MAC error defines */
63 /* header/extern include files (.x) */
64 #include "gen.x" /* general */
65 #include "ssi.x" /* system services */
66 #include "cm5.x" /* Timer */
67 #include "cm_tkns.x" /* Common Token Definitions */
68 #include "cm_llist.x" /* Common Link List Definitions */
69 #include "cm_lib.x" /* Common Library Definitions */
70 #include "cm_hash.x" /* Common Hash List Definitions */
71 #include "cm_mblk.x" /* common memory link list library */
72 #include "cm_lte.x" /* Common LTE */
74 #include "crg.x" /* CRG Interface includes */
75 #include "rgu.x" /* RGU Interface includes */
76 #include "tfu.x" /* TFU Interface includes */
77 #include "rg_sch_inf.x" /* RGR Interface includes */
78 #include "lrg.x" /* LRG Interface includes */
79 #include "rg_prg.x" /* PRG(MAC-MAC) Interface includes */
81 #include "du_app_mac_inf.h"
82 #include "rg.x" /* MAC includes */
85 #define RG_NON_MIMO_IDX 0
91 /* forward references */
92 PRIVATE S16 rgUtlHndlCrntiChng ARGS((
98 PRIVATE Void rgUtlHndlCrntiRls ARGS((
100 RgInfRlsRnti *rlsRnti
103 PUBLIC S16 rgDelUeFrmAllSCell ARGS((
109 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs ARGS((
115 /***********************************************************
117 * Func : rgAllocShrablSBuf
119 * Desc : Utility Function to Allocate static buffer which is
120 * sharable among different layers if YYYY flag is enabled.
121 * else it allocates from normal static region
122 * Memory allocated is assumed contiguous.
128 * Notes: Caller doesnt need to raise the alarm in case of memory
129 * allocation gets failed.
133 **********************************************************/
135 PUBLIC S16 rgAllocShrablSBuf
138 Data **pData, /* Pointer of the data to be returned */
142 PUBLIC S16 rgAllocShrablSBuf(inst,pData, size)
144 Data **pData; /* Pointer of the data to be returned */
145 Size size; /* size */
148 RgUstaDgn dgn; /* Alarm diagnostics structure */
150 TRC2(rgAllocShrablSBuf)
152 /* Initialize the param to NULLP */
160 /* allocate buffer */
161 if (SGetStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size, 0) != ROK)
163 dgn.type = LRG_USTA_DGNVAL_MEM;
164 dgn.u.mem.region = rgCb[inst].rgInit.region;
165 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
166 /* Send an alarm to Layer Manager */
167 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
168 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
169 RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
174 RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%ld)), Data (0x%p))\n",
175 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
177 RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%d)), Data (0x%p))\n",
178 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
181 /* zero out the allocated memory */
182 cmMemset((U8 *)*pData, 0x00, size);
186 } /* end of rgAllocSBuf */
189 /***********************************************************
193 * Desc : Utility Function to Allocate static buffer.
194 * Memory allocated is assumed contiguous.
200 * Notes: Caller doesnt need to raise the alarm in case of memory
201 * allocation gets failed.
205 **********************************************************/
207 PUBLIC S16 rgAllocSBuf
210 Data **pData, /* Pointer of the data to be returned */
214 PUBLIC S16 rgAllocSBuf(inst,pData, size)
216 Data **pData; /* Pointer of the data to be returned */
217 Size size; /* size */
220 RgUstaDgn dgn; /* Alarm diagnostics structure */
224 /* Initialize the param to NULLP */
232 /* allocate buffer */
233 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
234 MS_BUF_ADD_ALLOC_CALLER();
236 if (SGetSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size) != ROK)
238 dgn.type = LRG_USTA_DGNVAL_MEM;
239 dgn.u.mem.region = rgCb[inst].rgInit.region;
240 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
241 /* Send an alarm to Layer Manager */
242 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
243 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
244 RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
248 /* zero out the allocated memory */
249 cmMemset((U8 *)*pData, 0x00, size);
253 } /* end of rgAllocSBuf */
257 * Fun: rgFreeSharableSBuf
259 * Desc: The argument to rgFreeSBuf() is a pointer to a block
260 * previously allocated by rgAllocSBuf() and size. It
261 * deallocates the memory.
265 * Notes: ccpu00117052 - MOD- changed the Data parameter from
266 * pointer to address of pointer so that
267 * the freed memory could be set to NULLP
272 PUBLIC Void rgFreeSharableSBuf
275 Data **data, /* address of pointer to data */
279 PUBLIC Void rgFreeSharableSBuf(inst,data, size)
281 Data **data; /* address of pointer to data */
282 Size size; /* size */
288 TRC2(rgFreeSharableBuf)
290 if ((data == NULLP) || (*data == NULLP) || (size == 0))
295 /* Deallocate buffer */
296 ret = SPutStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size, SS_SHARABLE_MEMORY);
307 } /* end of rgFreeSharableBuf */
315 * Desc: The argument to rgFreeSBuf() is a pointer to a block
316 * previously allocated by rgAllocSBuf() and size. It
317 * deallocates the memory.
321 * Notes: ccpu00117052 - MOD- changed the Data parameter from
322 * pointer to address of pointer so that
323 * the freed memory could be set to NULLP
328 PUBLIC Void rgFreeSBuf
331 Data **data, /* address of pointer to data */
335 PUBLIC Void rgFreeSBuf(inst,data, size)
337 Data **data; /* address of pointer to data */
338 Size size; /* size */
346 if ((data == NULLP) || (*data == NULLP) || (size == 0))
352 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
355 /* Deallocate buffer */
356 ret = SPutSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size);
360 RGLOGERROR(inst,ERRCLS_DEBUG, ERG029, (ErrVal) 0, "rgFreeSBuf failed.\n");
368 } /* end of rgFreeSBuf */
371 /***********************************************************
375 * Desc : Utility Function to Allocate message buffer.
381 * Notes: Caller doesnt need to raise the alarm in case of memory
382 * allocation gets failed.
386 **********************************************************/
391 Buffer **mBuf /* Message Buffer pointer be returned */
394 PUBLIC S16 rgGetMsg(inst,mBuf)
396 Buffer **mBuf; /* Message Buffer pointer be returned */
403 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
404 MS_BUF_ADD_ALLOC_CALLER();
406 ret = SGetMsg(RG_GET_MEM_REGION(rgCb[inst]), RG_GET_MEM_POOL(rgCb[inst]), mBuf);
410 /* Moving diagnostics structure to limited scope for optimization */
411 RgUstaDgn dgn; /* Alarm diagnostics structure */
413 rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
415 /* Send an alarm to Layer Manager */
416 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
417 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
418 RGLOGERROR(inst,ERRCLS_DEBUG, ERG030, 0, "Unable to Allocate Buffer");
424 } /* end of rgGetMsg */
427 /***********************************************************
429 * Func : rgFillDgnParams
431 * Desc : Utility Function to Fill Diagonostic params.
439 **********************************************************/
441 PUBLIC Void rgFillDgnParams
448 PUBLIC Void rgFillDgnParams(inst,dgn, dgnType)
455 TRC2(rgFillDgnParams)
459 case LRG_USTA_DGNVAL_MEM:
460 dgn->type = (U8) LRG_USTA_DGNVAL_MEM;
461 dgn->u.mem.region = rgCb[inst].rgInit.region;
462 dgn->u.mem.pool = rgCb[inst].rgInit.pool;
470 } /* end of rgFillDgnParams */
473 /***********************************************************
475 * Func : rgUpdtRguDedSts
477 * Desc : Utility Function to update rgu sap statistics for dedicated
488 **********************************************************/
490 PUBLIC Void rgUpdtRguDedSts
494 U8 stsType, /* Statistics type to update */
495 RgRguDedDatReq *datReq /* DatReq pointer */
498 PUBLIC Void rgUpdtRguDedSts(inst,rguDlSap,stsType, datReq)
501 U8 stsType; /* Statistics type to update */
502 RgRguDedDatReq *datReq; /* DatReq pointer */
509 TRC2(rgUpdtRguDedSts)
514 case RG_RGU_SDU_RCVD:
515 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
517 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
518 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
520 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
522 rguDlSap->sapSts.numPduRcvd +=
523 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
529 case RG_RGU_SDU_DROP:
530 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
532 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
533 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
535 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
537 rguDlSap->sapSts.numPduRcvd +=
538 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
539 rguDlSap->sapSts.numPduDrop +=
540 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
549 } /* rgUpdtRguDedSts */
552 /***********************************************************
554 * Func : rgUpdtRguCmnSts
556 * Desc : Utility Function to update rgu sap statistics for common
567 **********************************************************/
569 PUBLIC Void rgUpdtRguCmnSts
573 U8 stsType /* Statistics type to update */
576 PUBLIC Void rgUpdtRguCmnSts(inst,rguDlSap,stsType)
579 U8 stsType; /* Statistics type to update */
582 TRC2(rgUpdtRguCmnSts)
588 case RG_RGU_SDU_RCVD:
589 rguDlSap->sapSts.numPduRcvd ++;
591 case RG_RGU_SDU_DROP:
592 rguDlSap->sapSts.numPduRcvd ++;
593 rguDlSap->sapSts.numPduDrop ++;
598 } /* rgUpdtRguCmnSts */
601 /***********************************************************
603 * Func : rgUpdtCellCnt
605 * Desc : Utility Function to update cell count. It gives number of active
612 * Notes: This function should be called only after cell is added/deleted
613 * from the globlal hashlist
617 **********************************************************/
619 PUBLIC Void rgUpdtCellCnt
625 PUBLIC Void rgUpdtCellCnt(inst,updtType)
635 rgCb[inst].genSts.numCellCfg++;
638 rgCb[inst].genSts.numCellCfg--;
645 } /* rgUpdtCellCnt */
648 /***********************************************************
652 * Desc : Utility Function to update ue count. It gives number of active
659 * Notes: This function should be called only after ue is added/deleted
660 * from the globlal hashlist
664 **********************************************************/
666 PUBLIC Void rgUpdtUeCnt
672 PUBLIC Void rgUpdtUeCnt (inst,updtType)
682 rgCb[inst].genSts.numUeCfg++;
685 rgCb[inst].genSts.numUeCfg--;
695 * Fun: rgAllocEventMem
697 * Desc: This function allocates event memory
699 * Ret: ROK - on success
700 * RFAILED - on failure
708 PUBLIC S16 rgAllocEventMem
715 PUBLIC S16 rgAllocEventMem(inst,memPtr, memSize)
722 VOLATILE U32 startTime=0;
724 TRC2(rgAllocEventMem)
726 sMem.region = rgCb[inst].rgInit.region;
727 sMem.pool = rgCb[inst].rgInit.pool;
729 #if (ERRCLASS & ERRCLS_DEBUG)
732 RGLOGERROR(inst,ERRCLS_INT_PAR, ERG031, memSize,
733 "rgAllocEventMem(): memSize invalid\n");
736 #endif /* ERRCLASS & ERRCLS_DEBUG */
740 SStartTask(&startTime, PID_MACUTL_CMALLCEVT);
742 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
743 MS_BUF_ADD_ALLOC_CALLER();
745 #ifdef TFU_ALLOC_EVENT_NO_INIT
746 if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
748 if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
751 RLOG0(L_ERROR,"cmAllocEvnt Failed");
756 SStopTask(startTime, PID_MACUTL_CMALLCEVT);
759 } /* end of rgAllocEventMem*/
765 * Desc: This function allocates event memory
767 * Ret: ROK - on success
768 * RFAILED - on failure
776 PUBLIC S16 rgGetEventMem
784 PUBLIC S16 rgGetEventMem(inst,ptr, len, memCp)
794 #ifdef TFU_ALLOC_EVENT_NO_INIT
795 ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
797 ret = cmGetMem(memCp, len, (Ptr *)ptr);
800 } /* end of rgGetEventMem*/
802 /***********************************************************
804 * Func : rgGetPstToInst
806 * Desc : Utility Function to get the pst structure to post a message to
813 * Notes: This function should be called while sending a msg from
814 * MAC to a scheduler instance
818 **********************************************************/
820 PUBLIC Void rgGetPstToInst
827 PUBLIC Void rgGetPstToInst (pst, srcInst, dstInst)
833 TRC2(rgGetPstToInst);
835 pst->srcEnt = rgCb[srcInst].rgInit.ent;
836 pst->srcInst = rgCb[srcInst].rgInit.inst;
837 pst->srcProcId = rgCb[srcInst].rgInit.procId;
838 pst->region = rgCb[srcInst].rgInit.region;
839 pst->pool = rgCb[srcInst].rgInit.pool;
841 pst->dstProcId = rgCb[dstInst].rgInit.procId;
842 pst->dstEnt = rgCb[dstInst].rgInit.ent;
843 pst->dstInst = dstInst;
847 pst->route = RTESPEC;
850 } /* end of rgGetPstToInst */
852 /***********************************************************
854 * Func : RgSchMacLcgRegReq
856 * Desc : Utility Function to register the set of GBR LCG.
857 * Invoked at the time of LCG configuration/Reconfiguration at Schedular.
860 * - Fetch the ueCb using the crnti given in lcInfo
861 * - Store the if LCG is GBR or not.
866 * Notes: This function should be called at the time of LCG
867 * configuration/Reconfiguration at Schedular.
872 **********************************************************/
874 PUBLIC S16 RgSchMacLcgRegReq
877 RgInfLcgRegReq *lcgRegReq
880 PUBLIC S16 RgSchMacLcgRegReq (pst, lcgRegReq)
882 RgInfLcgRegReq *lcgRegReq;
886 RgCellCb *cell = NULLP;
889 TRC2(RgSchMacLcgRegReq);
891 RG_IS_INST_VALID(pst->dstInst);
892 inst = pst->dstInst - RG_INST_START;
893 cell = rgCb[inst].cell;
894 /* Fetch the cell and then the UE */
895 if((cell == NULLP) ||
896 (cell->cellId != lcgRegReq->cellId))
899 RLOG_ARG0(L_ERROR,DBG_CELLID,lcgRegReq->cellId,"Cell does not exist ");
903 if ((ue = rgDBMGetUeCb(cell, lcgRegReq->crnti)) == NULLP)
905 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
909 ue->ul.lcgArr[lcgRegReq->lcgId].isGbr = lcgRegReq->isGbr;
912 } /* end of RgSchMacLcgRegReq */
916 /***********************************************************
918 * Func : RgSchMacUlSpsResetReq
920 * Desc : Utility Function to reset SPS params for a UE
923 * - Fetch the ueCb using the crnti
924 * - reset implRelCnt and explRelCnt
931 **********************************************************/
933 PUBLIC S16 RgSchMacUlSpsResetReq
936 RgInfUlSpsReset *ulSpsResetInfo
939 PUBLIC S16 RgSchMacUlSpsResetReq (pst, lcInfo)
941 RgInfUlSpsReset *ulSpsResetInfo;
945 RgCellCb *cell = NULLP;
948 TRC2(RgSchMacUlSpsResetReq);
950 RG_IS_INST_VALID(pst->dstInst);
951 inst = pst->dstInst - RG_INST_START;
952 cell = rgCb[inst].cell;
953 /* Fetch the cell and then the UE */
955 (cell->cellId != ulSpsResetInfo->cellId))
958 RLOG_ARG0(L_ERROR, DBG_CELLID,ulSpsResetInfo->cellId,"Cell does not exist ");
962 if ((ue = rgDBMGetUeCb(cell, ulSpsResetInfo->crnti)) == NULLP)
964 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
965 ulSpsResetInfo->crnti);
969 ue->ul.implRelCntr = 0;
970 ue->ul.explRelCntr = 0;
973 } /* end of RgSchMacUlSpsResetReq */
978 /***********************************************************
980 * Func : RgSchMacSpsLcRegReq
982 * Desc : Utility Function to register the set of uplink SPS logical
983 * channels for a SPS UE.
984 * Invoked at the time of activation of a UE for UL-SPS.
985 * Whenever there is data on these LCs MAC shall inform scheduler
988 * - Fetch the ueCb using the crnti given in lcInfo
989 * - Store the sps-rnti and set the bits corresponding to the
990 * logical channel ids in ueUlCb->spsLcMask.
995 * Notes: This function should be called at the time UL SPS is activated
996 * for a UE at scheduler
1001 **********************************************************/
1003 PUBLIC S16 RgSchMacSpsLcRegReq
1006 RgInfSpsLcInfo *lcInfo
1009 PUBLIC S16 RgSchMacSpsLcRegReq (pst, lcInfo)
1011 RgInfSpsLcInfo *lcInfo;
1015 RgCellCb *cell= NULLP;
1019 TRC2(RgSchMacSpsLcRegReq);
1021 RG_IS_INST_VALID(pst->dstInst);
1022 inst = pst->dstInst - RG_INST_START;
1023 cell = rgCb[inst].cell;
1024 /* Fetch the cell and then the UE */
1025 if((cell == NULLP) ||
1026 (cell->cellId != lcInfo->cellId))
1029 RLOG_ARG0(L_ERROR,DBG_CELLID,lcInfo->cellId, "Cell does not exist ");
1033 if ((ue = rgDBMGetUeCb(cell, lcInfo->crnti)) == NULLP)
1035 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
1040 /* Store the sps-rnti and SPS LC information in the UE */
1041 ue->spsRnti = lcInfo->spsRnti;
1042 for (idx=0; idx < lcInfo->spsLcCnt; idx++)
1044 /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
1045 ue->ul.spsLcId[(lcInfo->spsLcId[idx])-1] = TRUE;
1047 ue->ul.implRelCnt = lcInfo->implRelCnt;
1048 ue->ul.explRelCnt = ue->ul.implRelCnt + 1; /*(lcInfo->implRelCnt * lcInfo->spsPrd);*/
1050 /* Insert the UE into SPS UE List */
1051 if (rgDBMInsSpsUeCb(cell, ue) == RFAILED)
1053 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1054 "Ue insertion into SPS list failed SPS CRNTI:%d", ue->spsRnti);
1059 } /* end of RgSchMacSpsLcRegReq */
1062 /***********************************************************
1064 * Func : RgSchMacSpsLcDeregReq
1066 * Desc : Utility Function to deregister the set of uplink SPS
1067 * logical channels for a UE.
1068 * Invoked at the time of release of UL-SPS for an activated UE.
1071 * - Fetch the ueCb using the crnti given
1072 * - Reset the bits corresponding to the logical channel ids in
1073 * ueUlCb->spsLcMask.
1078 * Notes: This function should be called at the time UL SPS is released
1079 * for a UE at scheduler
1084 **********************************************************/
1086 PUBLIC S16 RgSchMacSpsLcDeregReq
1093 PUBLIC S16 RgSchMacSpsLcDeregReq (pst, cellId, crnti)
1100 RgCellCb *cell = NULLP;
1103 TRC2(RgSchMacSpsLcDeregReq);
1105 RG_IS_INST_VALID(pst->dstInst);
1106 inst = pst->dstInst - RG_INST_START;
1107 cell = rgCb[inst].cell;
1108 /* Fetch the cell and then the UE */
1109 if((cell == NULLP) ||
1110 (cell->cellId != cellId))
1113 RLOG_ARG0(L_ERROR,DBG_CELLID,cellId, "Cell does not exist ");
1117 if ((ue = rgDBMGetUeCb(cell, crnti)) == NULLP)
1119 RLOG_ARG1(L_ERROR, DBG_CELLID,cellId,"CRNTI:%d Ue does not exist", crnti);
1123 /* No need to reset the SPS LC Ids as they will not be looked at*/
1125 /* Delete UE from the SPS UE List */
1126 rgDBMDelSpsUeCb(cell, ue);
1129 } /* end of RgSchMacSpsLcDeregReq */
1131 #endif /* LTEMAC_SPS */
1134 * @brief Function for handling CRNTI change request
1135 * received from scheduler to MAC.
1139 * Function : rgUtlHndlCrntiChng
1141 * - Delete old UE from the list.
1142 * - Update the new rnti and re-insert the UE in the list.
1145 * @param[in] Inst inst
1146 * @param[in] RgCellCb *cell,
1147 * @param[in] CmLteRnti rnti,
1148 * @param[in] CmLteRnti newRnti
1154 PRIVATE S16 rgUtlHndlCrntiChng
1162 PRIVATE S16 rgUtlHndlCrntiChng(inst,cell, rnti, newRnti)
1170 RgUeCb *newUe = NULLP;
1172 TRC3(rgUtlHndlCrntiChng)
1174 ue = rgDBMGetUeCb(cell, rnti);
1175 newUe = rgDBMGetUeCbFromRachLst(cell, newRnti);
1176 if ((ue == NULLP) || (newUe == NULLP))
1178 RLOG_ARG4(L_ERROR,DBG_CELLID,cell->cellId,
1179 "RNTI:%d Failed to get UECB[%lu:%lu] or NEW RNTI:%d",
1180 rnti, ((PTR)ue), ((PTR)newUe), newRnti);
1183 #ifdef XEON_SPECIFIC_CHANGES
1184 CM_LOG_DEBUG(CM_LOG_ID_MAC, "MAC:UE[%d] id changed to %d\n", rnti, newRnti);
1186 rgDBMDelUeCb(cell, ue);
1190 cmMemcpy((U8*)&(ue->contResId), (U8*)&(newUe->contResId),
1191 sizeof(newUe->contResId));
1192 /* Fix : syed MSG4 might be RETXing need to store the
1194 rgDHMFreeUe(inst,&ue->dl.hqEnt);
1195 ue->dl.hqEnt = newUe->dl.hqEnt;
1197 rgDBMInsUeCb(cell, ue);
1199 rgDBMDelUeCbFromRachLst(cell, newUe);
1200 rgFreeSBuf(inst,(Data **)&newUe, sizeof(*newUe));
1203 } /* end of rgUtlHndlCrntiChng */
1207 * @brief Function for handling UE release for SCELL
1208 * triggered from SCH to MAC.
1212 * Function : rgDelUeFrmAllSCell
1214 * - This Function should be invoked by PCell of UE
1215 * - Remove the UE context from SCELL corresponding to rnti.
1217 * @param[in] Inst *macInst,
1218 * @param[in] RgUeCb *ue
1219 * @return ROK is SUCCESS
1222 PUBLIC S16 rgDelUeFrmAllSCell
1228 PUBLIC S16 rgDelUeFrmAllSCell(cell, ue)
1233 Inst inst = cell->macInst - RG_INST_START;
1237 RgPrgUeSCellDelInfo ueSCellDelInfo;
1239 TRC2(rgDelUeFrmAllSCell)
1241 /* To Delete the SCells if exisits for that UE */
1242 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1244 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1246 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1248 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1249 ueSCellDelInfo.ueId = ue->ueId;
1250 ueSCellDelInfo.sCellId = ue->sCelInfo[idx].sCellId;
1252 /* Filling same ueId in newRnti so that SMAC will check if newRnti
1253 *and old UeId is same that means its a UeSCell delete request*/
1254 ueSCellDelInfo.newRnti = ue->ueId;
1256 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueSCellDelInfo);
1257 ue->sCelInfo[idx].isSCellAdded = FALSE;
1262 } /* rgDelUeFrmAllSCell */
1265 * @brief Function to validate AddSCellCfg.
1269 * Function : rgUtlVltdAddSCellCfg
1272 * @param[in] ueSCellCb secondary cell CB for validation
1273 * @param[in] cell cell control block
1274 * @param[in] inst instance number to fetch rgCb instance
1279 PUBLIC S16 rgUtlVltdAddSCellCfg
1281 RgPrgUeSCellCfgInfo *ueSCellCb,
1286 PUBLIC S16 rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst)
1287 RgPrgUeSCellCfgInfo *ueSCellCb;
1294 TRC3(rgUtlVltdAddSCellCfg)
1296 /* To Validate the CellID presence */
1297 if((cell == NULLP) ||
1298 (cell->cellId != ueSCellCb->cellId))
1300 RGDBGERRNEW(inst, (rgPBuf(inst),
1301 "[%d]Sec Cell does not exit %d\n",
1302 ueSCellCb->ueId, ueSCellCb->cellId));
1305 #ifdef TENB_MULT_CELL_SUPPRT
1306 if((ueSCellCb->rguDlSapId > rgCb[inst].numRguSaps) ||
1307 (ueSCellCb->rguUlSapId > rgCb[inst].numRguSaps))
1309 RGDBGERRNEW(inst,(rgPBuf(inst), "Invald Sap Id: DL %d UL %d for ueId %d failed\n",
1310 ueSCellCb->rguDlSapId,
1311 ueSCellCb->rguUlSapId,
1312 ueSCellCb->cellId));
1317 } /* rgUtlVltdAddSCellCfg */
1320 * @brief Function to build CrntiChangeReq and send to all SMACs.
1324 * Function : rgUtlSndCrntiChngReq2AllSMacs
1326 * - This Function should be invoked by PCell of UE
1327 * - It sends RgPrgPMacSMacUeSCellDelReq to all SMACs with newRnti sent
1328 * by SCH. SMAC will check if newRnti is not equal to old UeId then it
1329 * do only UeId change else it will delete the UeScell context
1331 * @param[in] cell Cell CB to get Ue control block
1332 * @param[in] rnti Ue Identifier used to fill in UeId Change req
1333 * @param[in] newRnti UE new identifier, to be used in UeId Change req
1338 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs
1345 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs(cell, rnti, newRnti)
1351 Inst inst = cell->macInst - RG_INST_START;
1354 RgPrgUeSCellDelInfo ueIdChngReq;
1358 TfuDelDatReqInfo delDatReq;
1361 TRC2(rgUtlSndCrntiChngReq2AllSMacs)
1363 /* use newRnti to get UeCb in PMac because rnti is already changed in PMac*/
1364 ue = rgDBMGetUeCb(cell, newRnti);
1367 RGDBGERRNEW(inst,(rgPBuf(inst),"[%d]RNTI:Failed to get ueCb \
1368 newRnti=%d\n", rnti, newRnti));
1371 /* For all added SCells, prepare and send ueIdChngReq */
1372 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1374 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1376 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1378 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1380 ueIdChngReq.ueId = rnti;
1381 ueIdChngReq.sCellId = ue->sCelInfo[idx].sCellId;
1383 /* Filling newRnti so that SMAC can check if old ueId and new UeId
1384 *(newRnti) is different then its a UeId change request from PMAC.
1385 * RgPrgPMacSMacUeSCellDelReq is being reused for UeId change req
1386 * from PMAC to SMAC*/
1387 ueIdChngReq.newRnti = newRnti;
1389 /* Re-using UeSCellDelReq API for UeId change*/
1390 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueIdChngReq);
1392 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1393 delDatReq.cellId = ueIdChngReq.sCellId;
1394 delDatReq.ueId = ueIdChngReq.ueId;
1395 rgLIMTfuDelDatReq(sCellInstIdx, &delDatReq);
1402 } /* rgUtlSndCrntiChngReq2AllSMacs */
1404 #endif /* LTE_ADV */
1407 * @brief Function for handling CRNTI Context release
1408 * triggered from SCH to MAC.
1412 * Function : rgUtlHndlCrntiRls
1414 * - Remove the UE context from MAC corresponding to rnti.
1417 * @param[in] RgCellCb *cell,
1418 * @param[in] CmLteRnti rnti
1422 PRIVATE Void rgUtlHndlCrntiRls
1425 RgInfRlsRnti *rlsRnti
1428 PRIVATE Void rgUtlHndlCrntiRls(cell, rlsRnti)
1433 Inst inst = cell->macInst - RG_INST_START;
1436 RgUeCb *spsUeCb = NULLP;
1439 TRC3(rgUtlHndlCrntiRls)
1441 if ((ue = rgDBMGetUeCb(cell, rlsRnti->rnti)) == NULLP)
1443 /* Check in RachLst */
1444 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1446 /* Delete Ue from the UE list */
1447 rgDBMDelUeCbFromRachLst(cell, ue);
1450 rgRAMFreeUeCb(inst,ue);
1454 RLOG_ARG1(L_WARNING,DBG_CELLID,cell->cellId,
1455 "RNTI:%d No ueCb found in RachLst",rlsRnti->rnti);
1461 if(FALSE == rlsRnti->isUeSCellDel)
1463 rgDelUeFrmAllSCell(cell, ue);
1465 #endif /* LTE_ADV */
1467 /* Delete Ue from the UE list */
1468 rgDBMDelUeCb(cell, ue);
1470 spsUeCb = rgDBMGetSpsUeCb (cell, ue->spsRnti);
1473 rgDBMDelSpsUeCb(cell, spsUeCb);
1478 rgCFGFreeUeCb(cell, ue);
1479 /* MS_REMOVE : syed Check in RachLst */
1481 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1483 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1484 "RNTI:%d STALE UE is still present", rlsRnti->rnti);
1490 } /* end of rgUtlHndlCrntiRls */
1493 * @brief Function for handling RaResp request received from scheduler to MAC.
1497 * Function : RgSchMacRlsRntiReq
1499 * This function shall be invoked whenever scheduler is done with the
1500 * allocations of random access responses for a subframe.
1501 * This shall invoke RAM to create ueCbs for all the rapIds allocated and
1502 * shall invoke MUX to create RAR PDUs for raRntis allocated.
1505 * @param[in] CmLteCellId cellId,
1506 * @param[in] CmLteTimingInfo timingInfo,
1507 * @param[in] RaRespInfo *rarInfo
1512 PUBLIC S16 RgSchMacRlsRntiReq
1515 RgInfRlsRnti *rlsRnti
1518 PUBLIC S16 RgSchMacRlsRntiReq(pst, rlsRnti)
1520 RgInfRlsRnti *rlsRnti;
1524 // RgInfUeDelInd ueDelInd;
1528 TfuDelDatReqInfo delDatReq;
1531 TRC3(RgSchMacRlsRntiReq)
1533 RG_IS_INST_VALID(pst->dstInst);
1534 macInst = pst->dstInst - RG_INST_START;
1535 cell = rgCb[macInst].cell;
1537 if(NULLP == rlsRnti)
1542 if((cell == NULLP) ||
1543 (cell->cellId != rlsRnti->cellId))
1546 RLOG_ARG1(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1547 "No cellCb found with cellId for RNTI:%d",
1551 /* Fix : syed Clearing UE context when SCH indicates to do so
1552 * UE DEL from CRG interface is now dummy. */
1553 if (rlsRnti->ueIdChng)
1555 /* Fix : syed ueId change as part of reestablishment.
1556 * Now SCH to trigger this. CRG ueRecfg for ueId change
1558 if (rgUtlHndlCrntiChng(macInst,cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1560 RLOG_ARG2(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1561 "CRNTI change failed for RNTI:%d new RNTI:%d",
1562 rlsRnti->rnti,rlsRnti->newRnti);
1567 /*PMAC_Reest: Prepare CrntiChngReq and then send to all SMACs to change
1570 if(rgUtlSndCrntiChngReq2AllSMacs(cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1572 /* TODO: do we need to send DelInd to SCH in failure case*/
1577 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1578 delDatReq.cellId = cell->cellId;
1579 delDatReq.ueId = rlsRnti->rnti;
1580 rgLIMTfuDelDatReq(macInst, &delDatReq);
1585 rgUtlHndlCrntiRls(cell, rlsRnti);
1587 /* Fix : syed Send delete confirmation to SCH */
1588 /* Send RgMacSchUeDelInd to SCH only if it is Rnti release to PMAC.
1589 * Basically dont send DelInd to SCH incase of Ue SCell Del*/
1591 if(FALSE == rlsRnti->isUeSCellDel)
1594 //TODO: commented for compilation without SCH
1596 ueDelInd.cellSapId = cell->schInstMap.cellSapId;
1597 ueDelInd.cellId = rlsRnti->cellId;
1598 ueDelInd.rnti = rlsRnti->rnti;
1599 rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
1600 RgMacSchUeDel(&schPst, &ueDelInd);
1605 } /* end of RgSchMacRlsRntiReq */
1609 PUBLIC Bool RgUtlIsTbMuxed
1614 PUBLIC Bool RgUtlIsTbMuxed()
1619 SFndLenMsg(tb->macHdr, &len);
1620 RETVALUE(len?TRUE : FALSE);
1624 /**********************************************************************
1627 **********************************************************************/