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 "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 */
48 #include "rg_prg.h" /* PRG(MAC-MAC) Interface includes */
49 #include "rg.h" /* MAC defines */
50 #include "rg_err.h" /* MAC error defines */
52 /* header/extern include files (.x) */
53 #include "cm5.x" /* Timer */
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 */
62 #include "du_app_mac_inf.h"
63 #include "rg.x" /* MAC includes */
66 #define RG_NON_MIMO_IDX 0
72 /* forward references */
73 PRIVATE S16 rgUtlHndlCrntiChng ARGS((
79 PRIVATE Void rgUtlHndlCrntiRls ARGS((
84 S16 rgDelUeFrmAllSCell ARGS((
90 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs ARGS((
96 /***********************************************************
98 * Func : rgAllocShrablSBuf
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.
109 * Notes: Caller doesnt need to raise the alarm in case of memory
110 * allocation gets failed.
114 **********************************************************/
116 S16 rgAllocShrablSBuf
119 Data **pData, /* Pointer of the data to be returned */
123 S16 rgAllocShrablSBuf(inst,pData, size)
125 Data **pData; /* Pointer of the data to be returned */
126 Size size; /* size */
129 RgUstaDgn dgn; /* Alarm diagnostics structure */
131 /* Initialize the param to NULLP */
139 /* allocate buffer */
140 if (SGetStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size, 0) != ROK)
142 dgn.type = LRG_USTA_DGNVAL_MEM;
143 dgn.u.mem.region = rgCb[inst].rgInit.region;
144 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
145 /* Send an alarm to Layer Manager */
146 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
147 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
148 RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
153 RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%ld)), Data (0x%p))\n",
154 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
156 RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%d)), Data (0x%p))\n",
157 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
160 /* zero out the allocated memory */
161 memset(*pData, 0x00, size);
165 } /* end of rgAllocSBuf */
168 /***********************************************************
172 * Desc : Utility Function to Allocate static buffer.
173 * Memory allocated is assumed contiguous.
179 * Notes: Caller doesnt need to raise the alarm in case of memory
180 * allocation gets failed.
184 **********************************************************/
189 Data **pData, /* Pointer of the data to be returned */
193 S16 rgAllocSBuf(inst,pData, size)
195 Data **pData; /* Pointer of the data to be returned */
196 Size size; /* size */
199 RgUstaDgn dgn; /* Alarm diagnostics structure */
201 /* Initialize the param to NULLP */
209 /* allocate buffer */
210 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
211 MS_BUF_ADD_ALLOC_CALLER();
213 if (SGetSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size) != ROK)
215 dgn.type = LRG_USTA_DGNVAL_MEM;
216 dgn.u.mem.region = rgCb[inst].rgInit.region;
217 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
218 /* Send an alarm to Layer Manager */
219 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
220 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
221 RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
225 /* zero out the allocated memory */
226 memset(*pData, 0x00, size);
230 } /* end of rgAllocSBuf */
234 * Fun: rgFreeSharableSBuf
236 * Desc: The argument to rgFreeSBuf() is a pointer to a block
237 * previously allocated by rgAllocSBuf() and size. It
238 * deallocates the memory.
242 * Notes: ccpu00117052 - MOD- changed the Data parameter from
243 * pointer to address of pointer so that
244 * the freed memory could be set to NULLP
249 Void rgFreeSharableSBuf
252 Data **data, /* address of pointer to data */
256 Void rgFreeSharableSBuf(inst,data, size)
258 Data **data; /* address of pointer to data */
259 Size size; /* size */
265 if ((data == NULLP) || (*data == NULLP) || (size == 0))
270 /* Deallocate buffer */
271 ret = SPutStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size, SS_SHARABLE_MEMORY);
282 } /* end of rgFreeSharableBuf */
290 * Desc: The argument to rgFreeSBuf() is a pointer to a block
291 * previously allocated by rgAllocSBuf() and size. It
292 * deallocates the memory.
296 * Notes: ccpu00117052 - MOD- changed the Data parameter from
297 * pointer to address of pointer so that
298 * the freed memory could be set to NULLP
306 Data **data, /* address of pointer to data */
310 Void rgFreeSBuf(inst,data, size)
312 Data **data; /* address of pointer to data */
313 Size size; /* size */
319 if ((data == NULLP) || (*data == NULLP) || (size == 0))
325 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
328 /* Deallocate buffer */
329 ret = SPutSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size);
333 RGLOGERROR(inst,ERRCLS_DEBUG, ERG029, (ErrVal) 0, "rgFreeSBuf failed.\n");
341 } /* end of rgFreeSBuf */
344 /***********************************************************
348 * Desc : Utility Function to Allocate message buffer.
354 * Notes: Caller doesnt need to raise the alarm in case of memory
355 * allocation gets failed.
359 **********************************************************/
364 Buffer **mBuf /* Message Buffer pointer be returned */
367 S16 rgGetMsg(inst,mBuf)
369 Buffer **mBuf; /* Message Buffer pointer be returned */
374 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
375 MS_BUF_ADD_ALLOC_CALLER();
377 ret = SGetMsg(RG_GET_MEM_REGION(rgCb[inst]), RG_GET_MEM_POOL(rgCb[inst]), mBuf);
381 /* Moving diagnostics structure to limited scope for optimization */
382 RgUstaDgn dgn; /* Alarm diagnostics structure */
384 rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
386 /* Send an alarm to Layer Manager */
387 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
388 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
389 RGLOGERROR(inst,ERRCLS_DEBUG, ERG030, 0, "Unable to Allocate Buffer");
395 } /* end of rgGetMsg */
398 /***********************************************************
400 * Func : rgFillDgnParams
402 * Desc : Utility Function to Fill Diagonostic params.
410 **********************************************************/
419 Void rgFillDgnParams(inst,dgn, dgnType)
428 case LRG_USTA_DGNVAL_MEM:
429 dgn->type = (U8) LRG_USTA_DGNVAL_MEM;
430 dgn->u.mem.region = rgCb[inst].rgInit.region;
431 dgn->u.mem.pool = rgCb[inst].rgInit.pool;
439 } /* end of rgFillDgnParams */
442 /***********************************************************
444 * Func : rgUpdtRguDedSts
446 * Desc : Utility Function to update rgu sap statistics for dedicated
457 **********************************************************/
463 U8 stsType, /* Statistics type to update */
464 RgRguDedDatReq *datReq /* DatReq pointer */
467 Void rgUpdtRguDedSts(inst,rguDlSap,stsType, datReq)
470 U8 stsType; /* Statistics type to update */
471 RgRguDedDatReq *datReq; /* DatReq pointer */
479 case RG_RGU_SDU_RCVD:
480 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
482 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
483 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
485 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
487 rguDlSap->sapSts.numPduRcvd +=
488 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
494 case RG_RGU_SDU_DROP:
495 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
497 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
498 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
500 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
502 rguDlSap->sapSts.numPduRcvd +=
503 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
504 rguDlSap->sapSts.numPduDrop +=
505 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
514 } /* rgUpdtRguDedSts */
517 /***********************************************************
519 * Func : rgUpdtRguCmnSts
521 * Desc : Utility Function to update rgu sap statistics for common
532 **********************************************************/
538 U8 stsType /* Statistics type to update */
541 Void rgUpdtRguCmnSts(inst,rguDlSap,stsType)
544 U8 stsType; /* Statistics type to update */
550 case RG_RGU_SDU_RCVD:
551 rguDlSap->sapSts.numPduRcvd ++;
553 case RG_RGU_SDU_DROP:
554 rguDlSap->sapSts.numPduRcvd ++;
555 rguDlSap->sapSts.numPduDrop ++;
560 } /* rgUpdtRguCmnSts */
563 /***********************************************************
565 * Func : rgUpdtCellCnt
567 * Desc : Utility Function to update cell count. It gives number of active
574 * Notes: This function should be called only after cell is added/deleted
575 * from the globlal hashlist
579 **********************************************************/
587 Void rgUpdtCellCnt(inst,updtType)
596 rgCb[inst].genSts.numCellCfg++;
599 rgCb[inst].genSts.numCellCfg--;
606 } /* rgUpdtCellCnt */
609 /***********************************************************
613 * Desc : Utility Function to update ue count. It gives number of active
620 * Notes: This function should be called only after ue is added/deleted
621 * from the globlal hashlist
625 **********************************************************/
633 Void rgUpdtUeCnt (inst,updtType)
641 rgCb[inst].genSts.numUeCfg++;
644 rgCb[inst].genSts.numUeCfg--;
654 * Fun: rgAllocEventMem
656 * Desc: This function allocates event memory
658 * Ret: ROK - on success
659 * RFAILED - on failure
674 S16 rgAllocEventMem(inst,memPtr, memSize)
681 VOLATILE U32 startTime=0;
683 sMem.region = rgCb[inst].rgInit.region;
684 sMem.pool = rgCb[inst].rgInit.pool;
686 #if (ERRCLASS & ERRCLS_DEBUG)
689 RGLOGERROR(inst,ERRCLS_INT_PAR, ERG031, memSize,
690 "rgAllocEventMem(): memSize invalid\n");
693 #endif /* ERRCLASS & ERRCLS_DEBUG */
697 SStartTask(&startTime, PID_MACUTL_CMALLCEVT);
699 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
700 MS_BUF_ADD_ALLOC_CALLER();
702 #ifdef TFU_ALLOC_EVENT_NO_INIT
703 if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
705 if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
708 RLOG0(L_ERROR,"cmAllocEvnt Failed");
713 SStopTask(startTime, PID_MACUTL_CMALLCEVT);
716 } /* end of rgAllocEventMem*/
722 * Desc: This function allocates event memory
724 * Ret: ROK - on success
725 * RFAILED - on failure
741 S16 rgGetEventMem(inst,ptr, len, memCp)
750 #ifdef TFU_ALLOC_EVENT_NO_INIT
751 ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
753 ret = cmGetMem(memCp, len, (Ptr *)ptr);
756 } /* end of rgGetEventMem*/
758 /***********************************************************
760 * Func : rgGetPstToInst
762 * Desc : Utility Function to get the pst structure to post a message to
769 * Notes: This function should be called while sending a msg from
770 * MAC to a scheduler instance
774 **********************************************************/
783 Void rgGetPstToInst (pst, srcInst, dstInst)
790 pst->srcEnt = rgCb[srcInst].rgInit.ent;
791 pst->srcInst = rgCb[srcInst].rgInit.inst;
792 pst->srcProcId = rgCb[srcInst].rgInit.procId;
793 pst->region = rgCb[srcInst].rgInit.region;
794 pst->pool = rgCb[srcInst].rgInit.pool;
796 pst->dstProcId = rgCb[dstInst].rgInit.procId;
797 pst->dstEnt = rgCb[dstInst].rgInit.ent;
798 pst->dstInst = dstInst;
802 pst->route = RTESPEC;
805 } /* end of rgGetPstToInst */
807 /***********************************************************
809 * Func : RgSchMacLcgRegReq
811 * Desc : Utility Function to register the set of GBR LCG.
812 * Invoked at the time of LCG configuration/Reconfiguration at Schedular.
815 * - Fetch the ueCb using the crnti given in lcInfo
816 * - Store the if LCG is GBR or not.
821 * Notes: This function should be called at the time of LCG
822 * configuration/Reconfiguration at Schedular.
827 **********************************************************/
829 S16 RgSchMacLcgRegReq
832 RgInfLcgRegReq *lcgRegReq
835 S16 RgSchMacLcgRegReq (pst, lcgRegReq)
837 RgInfLcgRegReq *lcgRegReq;
841 RgCellCb *cell = NULLP;
844 RG_IS_INST_VALID(pst->dstInst);
845 inst = pst->dstInst - RG_INST_START;
846 cell = rgCb[inst].cell;
847 /* Fetch the cell and then the UE */
848 if((cell == NULLP) ||
849 (cell->cellId != lcgRegReq->cellId))
852 RLOG_ARG0(L_ERROR,DBG_CELLID,lcgRegReq->cellId,"Cell does not exist ");
856 if ((ue = rgDBMGetUeCb(cell, lcgRegReq->crnti)) == NULLP)
858 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
862 ue->ul.lcgArr[lcgRegReq->lcgId].isGbr = lcgRegReq->isGbr;
865 } /* end of RgSchMacLcgRegReq */
869 /***********************************************************
871 * Func : RgSchMacUlSpsResetReq
873 * Desc : Utility Function to reset SPS params for a UE
876 * - Fetch the ueCb using the crnti
877 * - reset implRelCnt and explRelCnt
884 **********************************************************/
886 S16 RgSchMacUlSpsResetReq
889 RgInfUlSpsReset *ulSpsResetInfo
892 S16 RgSchMacUlSpsResetReq (pst, lcInfo)
894 RgInfUlSpsReset *ulSpsResetInfo;
898 RgCellCb *cell = NULLP;
901 RG_IS_INST_VALID(pst->dstInst);
902 inst = pst->dstInst - RG_INST_START;
903 cell = rgCb[inst].cell;
904 /* Fetch the cell and then the UE */
906 (cell->cellId != ulSpsResetInfo->cellId))
909 RLOG_ARG0(L_ERROR, DBG_CELLID,ulSpsResetInfo->cellId,"Cell does not exist ");
913 if ((ue = rgDBMGetUeCb(cell, ulSpsResetInfo->crnti)) == NULLP)
915 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
916 ulSpsResetInfo->crnti);
920 ue->ul.implRelCntr = 0;
921 ue->ul.explRelCntr = 0;
924 } /* end of RgSchMacUlSpsResetReq */
929 /***********************************************************
931 * Func : RgSchMacSpsLcRegReq
933 * Desc : Utility Function to register the set of uplink SPS logical
934 * channels for a SPS UE.
935 * Invoked at the time of activation of a UE for UL-SPS.
936 * Whenever there is data on these LCs MAC shall inform scheduler
939 * - Fetch the ueCb using the crnti given in lcInfo
940 * - Store the sps-rnti and set the bits corresponding to the
941 * logical channel ids in ueUlCb->spsLcMask.
946 * Notes: This function should be called at the time UL SPS is activated
947 * for a UE at scheduler
952 **********************************************************/
954 S16 RgSchMacSpsLcRegReq
957 RgInfSpsLcInfo *lcInfo
960 S16 RgSchMacSpsLcRegReq (pst, lcInfo)
962 RgInfSpsLcInfo *lcInfo;
966 RgCellCb *cell= NULLP;
970 RG_IS_INST_VALID(pst->dstInst);
971 inst = pst->dstInst - RG_INST_START;
972 cell = rgCb[inst].cell;
973 /* Fetch the cell and then the UE */
974 if((cell == NULLP) ||
975 (cell->cellId != lcInfo->cellId))
978 RLOG_ARG0(L_ERROR,DBG_CELLID,lcInfo->cellId, "Cell does not exist ");
982 if ((ue = rgDBMGetUeCb(cell, lcInfo->crnti)) == NULLP)
984 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
989 /* Store the sps-rnti and SPS LC information in the UE */
990 ue->spsRnti = lcInfo->spsRnti;
991 for (idx=0; idx < lcInfo->spsLcCnt; idx++)
993 /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
994 ue->ul.spsLcId[(lcInfo->spsLcId[idx])-1] = TRUE;
996 ue->ul.implRelCnt = lcInfo->implRelCnt;
997 ue->ul.explRelCnt = ue->ul.implRelCnt + 1; /*(lcInfo->implRelCnt * lcInfo->spsPrd);*/
999 /* Insert the UE into SPS UE List */
1000 if (rgDBMInsSpsUeCb(cell, ue) == RFAILED)
1002 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1003 "Ue insertion into SPS list failed SPS CRNTI:%d", ue->spsRnti);
1008 } /* end of RgSchMacSpsLcRegReq */
1011 /***********************************************************
1013 * Func : RgSchMacSpsLcDeregReq
1015 * Desc : Utility Function to deregister the set of uplink SPS
1016 * logical channels for a UE.
1017 * Invoked at the time of release of UL-SPS for an activated UE.
1020 * - Fetch the ueCb using the crnti given
1021 * - Reset the bits corresponding to the logical channel ids in
1022 * ueUlCb->spsLcMask.
1027 * Notes: This function should be called at the time UL SPS is released
1028 * for a UE at scheduler
1033 **********************************************************/
1035 S16 RgSchMacSpsLcDeregReq
1042 S16 RgSchMacSpsLcDeregReq (pst, cellId, crnti)
1049 RgCellCb *cell = NULLP;
1052 RG_IS_INST_VALID(pst->dstInst);
1053 inst = pst->dstInst - RG_INST_START;
1054 cell = rgCb[inst].cell;
1055 /* Fetch the cell and then the UE */
1056 if((cell == NULLP) ||
1057 (cell->cellId != cellId))
1060 RLOG_ARG0(L_ERROR,DBG_CELLID,cellId, "Cell does not exist ");
1064 if ((ue = rgDBMGetUeCb(cell, crnti)) == NULLP)
1066 RLOG_ARG1(L_ERROR, DBG_CELLID,cellId,"CRNTI:%d Ue does not exist", crnti);
1070 /* No need to reset the SPS LC Ids as they will not be looked at*/
1072 /* Delete UE from the SPS UE List */
1073 rgDBMDelSpsUeCb(cell, ue);
1076 } /* end of RgSchMacSpsLcDeregReq */
1078 #endif /* LTEMAC_SPS */
1081 * @brief Function for handling CRNTI change request
1082 * received from scheduler to MAC.
1086 * Function : rgUtlHndlCrntiChng
1088 * - Delete old UE from the list.
1089 * - Update the new rnti and re-insert the UE in the list.
1092 * @param[in] Inst inst
1093 * @param[in] RgCellCb *cell,
1094 * @param[in] CmLteRnti rnti,
1095 * @param[in] CmLteRnti newRnti
1101 PRIVATE S16 rgUtlHndlCrntiChng
1109 PRIVATE S16 rgUtlHndlCrntiChng(inst,cell, rnti, newRnti)
1117 RgUeCb *newUe = NULLP;
1119 ue = rgDBMGetUeCb(cell, rnti);
1120 newUe = rgDBMGetUeCbFromRachLst(cell, newRnti);
1121 if ((ue == NULLP) || (newUe == NULLP))
1123 RLOG_ARG4(L_ERROR,DBG_CELLID,cell->cellId,
1124 "RNTI:%d Failed to get UECB[%lu:%lu] or NEW RNTI:%d",
1125 rnti, ((PTR)ue), ((PTR)newUe), newRnti);
1128 #ifdef XEON_SPECIFIC_CHANGES
1129 CM_LOG_DEBUG(CM_LOG_ID_MAC, "MAC:UE[%d] id changed to %d\n", rnti, newRnti);
1131 rgDBMDelUeCb(cell, ue);
1135 memcpy(&(ue->contResId), &(newUe->contResId),
1136 sizeof(newUe->contResId));
1137 /* Fix : syed MSG4 might be RETXing need to store the
1139 rgDHMFreeUe(inst,&ue->dl.hqEnt);
1140 ue->dl.hqEnt = newUe->dl.hqEnt;
1142 rgDBMInsUeCb(cell, ue);
1144 rgDBMDelUeCbFromRachLst(cell, newUe);
1145 rgFreeSBuf(inst,(Data **)&newUe, sizeof(*newUe));
1148 } /* end of rgUtlHndlCrntiChng */
1152 * @brief Function for handling UE release for SCELL
1153 * triggered from SCH to MAC.
1157 * Function : rgDelUeFrmAllSCell
1159 * - This Function should be invoked by PCell of UE
1160 * - Remove the UE context from SCELL corresponding to rnti.
1162 * @param[in] Inst *macInst,
1163 * @param[in] RgUeCb *ue
1164 * @return ROK is SUCCESS
1167 S16 rgDelUeFrmAllSCell
1173 S16 rgDelUeFrmAllSCell(cell, ue)
1178 Inst inst = cell->macInst - RG_INST_START;
1182 RgPrgUeSCellDelInfo ueSCellDelInfo;
1184 /* To Delete the SCells if exisits for that UE */
1185 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1187 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1189 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1191 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1192 ueSCellDelInfo.ueId = ue->ueId;
1193 ueSCellDelInfo.sCellId = ue->sCelInfo[idx].sCellId;
1195 /* Filling same ueId in newRnti so that SMAC will check if newRnti
1196 *and old UeId is same that means its a UeSCell delete request*/
1197 ueSCellDelInfo.newRnti = ue->ueId;
1199 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueSCellDelInfo);
1200 ue->sCelInfo[idx].isSCellAdded = FALSE;
1205 } /* rgDelUeFrmAllSCell */
1208 * @brief Function to validate AddSCellCfg.
1212 * Function : rgUtlVltdAddSCellCfg
1215 * @param[in] ueSCellCb secondary cell CB for validation
1216 * @param[in] cell cell control block
1217 * @param[in] inst instance number to fetch rgCb instance
1222 S16 rgUtlVltdAddSCellCfg
1224 RgPrgUeSCellCfgInfo *ueSCellCb,
1229 S16 rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst)
1230 RgPrgUeSCellCfgInfo *ueSCellCb;
1237 /* To Validate the CellID presence */
1238 if((cell == NULLP) ||
1239 (cell->cellId != ueSCellCb->cellId))
1241 RGDBGERRNEW(inst, (rgPBuf(inst),
1242 "[%d]Sec Cell does not exit %d\n",
1243 ueSCellCb->ueId, ueSCellCb->cellId));
1246 #ifdef TENB_MULT_CELL_SUPPRT
1247 if((ueSCellCb->rguDlSapId > rgCb[inst].numRguSaps) ||
1248 (ueSCellCb->rguUlSapId > rgCb[inst].numRguSaps))
1250 RGDBGERRNEW(inst,(rgPBuf(inst), "Invald Sap Id: DL %d UL %d for ueId %d failed\n",
1251 ueSCellCb->rguDlSapId,
1252 ueSCellCb->rguUlSapId,
1253 ueSCellCb->cellId));
1258 } /* rgUtlVltdAddSCellCfg */
1261 * @brief Function to build CrntiChangeReq and send to all SMACs.
1265 * Function : rgUtlSndCrntiChngReq2AllSMacs
1267 * - This Function should be invoked by PCell of UE
1268 * - It sends RgPrgPMacSMacUeSCellDelReq to all SMACs with newRnti sent
1269 * by SCH. SMAC will check if newRnti is not equal to old UeId then it
1270 * do only UeId change else it will delete the UeScell context
1272 * @param[in] cell Cell CB to get Ue control block
1273 * @param[in] rnti Ue Identifier used to fill in UeId Change req
1274 * @param[in] newRnti UE new identifier, to be used in UeId Change req
1279 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs
1286 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs(cell, rnti, newRnti)
1292 Inst inst = cell->macInst - RG_INST_START;
1295 RgPrgUeSCellDelInfo ueIdChngReq;
1299 TfuDelDatReqInfo delDatReq;
1302 /* use newRnti to get UeCb in PMac because rnti is already changed in PMac*/
1303 ue = rgDBMGetUeCb(cell, newRnti);
1306 RGDBGERRNEW(inst,(rgPBuf(inst),"[%d]RNTI:Failed to get ueCb \
1307 newRnti=%d\n", rnti, newRnti));
1310 /* For all added SCells, prepare and send ueIdChngReq */
1311 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1313 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1315 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1317 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1319 ueIdChngReq.ueId = rnti;
1320 ueIdChngReq.sCellId = ue->sCelInfo[idx].sCellId;
1322 /* Filling newRnti so that SMAC can check if old ueId and new UeId
1323 *(newRnti) is different then its a UeId change request from PMAC.
1324 * RgPrgPMacSMacUeSCellDelReq is being reused for UeId change req
1325 * from PMAC to SMAC*/
1326 ueIdChngReq.newRnti = newRnti;
1328 /* Re-using UeSCellDelReq API for UeId change*/
1329 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueIdChngReq);
1331 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1332 delDatReq.cellId = ueIdChngReq.sCellId;
1333 delDatReq.ueId = ueIdChngReq.ueId;
1334 rgLIMTfuDelDatReq(sCellInstIdx, &delDatReq);
1341 } /* rgUtlSndCrntiChngReq2AllSMacs */
1343 #endif /* LTE_ADV */
1346 * @brief Function for handling CRNTI Context release
1347 * triggered from SCH to MAC.
1351 * Function : rgUtlHndlCrntiRls
1353 * - Remove the UE context from MAC corresponding to rnti.
1356 * @param[in] RgCellCb *cell,
1357 * @param[in] CmLteRnti rnti
1361 PRIVATE Void rgUtlHndlCrntiRls
1364 RgInfRlsRnti *rlsRnti
1367 PRIVATE Void rgUtlHndlCrntiRls(cell, rlsRnti)
1372 Inst inst = cell->macInst - RG_INST_START;
1375 RgUeCb *spsUeCb = NULLP;
1378 if ((ue = rgDBMGetUeCb(cell, rlsRnti->rnti)) == NULLP)
1380 /* Check in RachLst */
1381 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1383 /* Delete Ue from the UE list */
1384 rgDBMDelUeCbFromRachLst(cell, ue);
1387 rgRAMFreeUeCb(inst,ue);
1391 RLOG_ARG1(L_WARNING,DBG_CELLID,cell->cellId,
1392 "RNTI:%d No ueCb found in RachLst",rlsRnti->rnti);
1398 if(FALSE == rlsRnti->isUeSCellDel)
1400 rgDelUeFrmAllSCell(cell, ue);
1402 #endif /* LTE_ADV */
1404 /* Delete Ue from the UE list */
1405 rgDBMDelUeCb(cell, ue);
1407 spsUeCb = rgDBMGetSpsUeCb (cell, ue->spsRnti);
1410 rgDBMDelSpsUeCb(cell, spsUeCb);
1415 rgCFGFreeUeCb(cell, ue);
1416 /* MS_REMOVE : syed Check in RachLst */
1418 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1420 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1421 "RNTI:%d STALE UE is still present", rlsRnti->rnti);
1427 } /* end of rgUtlHndlCrntiRls */
1430 * @brief Function for handling RaResp request received from scheduler to MAC.
1434 * Function : RgSchMacRlsRntiReq
1436 * This function shall be invoked whenever scheduler is done with the
1437 * allocations of random access responses for a subframe.
1438 * This shall invoke RAM to create ueCbs for all the rapIds allocated and
1439 * shall invoke MUX to create RAR PDUs for raRntis allocated.
1442 * @param[in] CmLteCellId cellId,
1443 * @param[in] CmLteTimingInfo timingInfo,
1444 * @param[in] RaRespInfo *rarInfo
1449 S16 RgSchMacRlsRntiReq
1452 RgInfRlsRnti *rlsRnti
1455 S16 RgSchMacRlsRntiReq(pst, rlsRnti)
1457 RgInfRlsRnti *rlsRnti;
1461 // RgInfUeDelInd ueDelInd;
1465 TfuDelDatReqInfo delDatReq;
1468 RG_IS_INST_VALID(pst->dstInst);
1469 macInst = pst->dstInst - RG_INST_START;
1470 cell = rgCb[macInst].cell;
1472 if(NULLP == rlsRnti)
1477 if((cell == NULLP) ||
1478 (cell->cellId != rlsRnti->cellId))
1481 RLOG_ARG1(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1482 "No cellCb found with cellId for RNTI:%d",
1486 /* Fix : syed Clearing UE context when SCH indicates to do so
1487 * UE DEL from CRG interface is now dummy. */
1488 if (rlsRnti->ueIdChng)
1490 /* Fix : syed ueId change as part of reestablishment.
1491 * Now SCH to trigger this. CRG ueRecfg for ueId change
1493 if (rgUtlHndlCrntiChng(macInst,cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1495 RLOG_ARG2(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1496 "CRNTI change failed for RNTI:%d new RNTI:%d",
1497 rlsRnti->rnti,rlsRnti->newRnti);
1502 /*PMAC_Reest: Prepare CrntiChngReq and then send to all SMACs to change
1505 if(rgUtlSndCrntiChngReq2AllSMacs(cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1507 /* TODO: do we need to send DelInd to SCH in failure case*/
1512 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1513 delDatReq.cellId = cell->cellId;
1514 delDatReq.ueId = rlsRnti->rnti;
1515 rgLIMTfuDelDatReq(macInst, &delDatReq);
1520 rgUtlHndlCrntiRls(cell, rlsRnti);
1522 /* Fix : syed Send delete confirmation to SCH */
1523 /* Send RgMacSchUeDelInd to SCH only if it is Rnti release to PMAC.
1524 * Basically dont send DelInd to SCH incase of Ue SCell Del*/
1526 if(FALSE == rlsRnti->isUeSCellDel)
1529 //TODO: commented for compilation without SCH
1531 ueDelInd.cellSapId = cell->schInstMap.cellSapId;
1532 ueDelInd.cellId = rlsRnti->cellId;
1533 ueDelInd.rnti = rlsRnti->rnti;
1534 rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
1535 RgMacSchUeDel(&schPst, &ueDelInd);
1540 } /* end of RgSchMacRlsRntiReq */
1549 Bool RgUtlIsTbMuxed()
1554 SFndLenMsg(tb->macHdr, &len);
1555 return (len?TRUE : FALSE);
1559 /**********************************************************************
1562 **********************************************************************/