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 static S16 rgUtlHndlCrntiChng ARGS((
79 static Void rgUtlHndlCrntiRls ARGS((
84 S16 rgDelUeFrmAllSCell ARGS((
90 static 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 = (uint8_t) 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 uint8_t stsType, /* Statistics type to update */
464 RgRguDedDatReq *datReq /* DatReq pointer */
467 Void rgUpdtRguDedSts(inst,rguDlSap,stsType, datReq)
470 uint8_t 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 uint8_t stsType /* Statistics type to update */
541 Void rgUpdtRguCmnSts(inst,rguDlSap,stsType)
544 uint8_t 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 uint32_t startTime=0;
684 sMem.region = rgCb[inst].rgInit.region;
685 sMem.pool = rgCb[inst].rgInit.pool;
687 #if (ERRCLASS & ERRCLS_DEBUG)
690 RGLOGERROR(inst,ERRCLS_INT_PAR, ERG031, memSize,
691 "rgAllocEventMem(): memSize invalid\n");
694 #endif /* ERRCLASS & ERRCLS_DEBUG */
698 SStartTask(&startTime, PID_MACUTL_CMALLCEVT);
700 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
701 MS_BUF_ADD_ALLOC_CALLER();
703 #ifdef TFU_ALLOC_EVENT_NO_INIT
704 if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
706 if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
709 RLOG0(L_ERROR,"cmAllocEvnt Failed");
714 SStopTask(startTime, PID_MACUTL_CMALLCEVT);
717 } /* end of rgAllocEventMem*/
723 * Desc: This function allocates event memory
725 * Ret: ROK - on success
726 * RFAILED - on failure
742 S16 rgGetEventMem(inst,ptr, len, memCp)
751 #ifdef TFU_ALLOC_EVENT_NO_INIT
752 ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
754 ret = cmGetMem(memCp, len, (Ptr *)ptr);
757 } /* end of rgGetEventMem*/
759 /***********************************************************
761 * Func : rgGetPstToInst
763 * Desc : Utility Function to get the pst structure to post a message to
770 * Notes: This function should be called while sending a msg from
771 * MAC to a scheduler instance
775 **********************************************************/
784 Void rgGetPstToInst (pst, srcInst, dstInst)
791 pst->srcEnt = rgCb[srcInst].rgInit.ent;
792 pst->srcInst = rgCb[srcInst].rgInit.inst;
793 pst->srcProcId = rgCb[srcInst].rgInit.procId;
794 pst->region = rgCb[srcInst].rgInit.region;
795 pst->pool = rgCb[srcInst].rgInit.pool;
797 pst->dstProcId = rgCb[dstInst].rgInit.procId;
798 pst->dstEnt = rgCb[dstInst].rgInit.ent;
799 pst->dstInst = dstInst;
803 pst->route = RTESPEC;
806 } /* end of rgGetPstToInst */
808 /***********************************************************
810 * Func : RgSchMacLcgRegReq
812 * Desc : Utility Function to register the set of GBR LCG.
813 * Invoked at the time of LCG configuration/Reconfiguration at Schedular.
816 * - Fetch the ueCb using the crnti given in lcInfo
817 * - Store the if LCG is GBR or not.
822 * Notes: This function should be called at the time of LCG
823 * configuration/Reconfiguration at Schedular.
828 **********************************************************/
830 S16 RgSchMacLcgRegReq
833 RgInfLcgRegReq *lcgRegReq
836 S16 RgSchMacLcgRegReq (pst, lcgRegReq)
838 RgInfLcgRegReq *lcgRegReq;
842 RgCellCb *cell = NULLP;
845 RG_IS_INST_VALID(pst->dstInst);
846 inst = pst->dstInst - RG_INST_START;
847 cell = rgCb[inst].cell;
848 /* Fetch the cell and then the UE */
849 if((cell == NULLP) ||
850 (cell->cellId != lcgRegReq->cellId))
853 RLOG_ARG0(L_ERROR,DBG_CELLID,lcgRegReq->cellId,"Cell does not exist ");
857 if ((ue = rgDBMGetUeCb(cell, lcgRegReq->crnti)) == NULLP)
859 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
863 ue->ul.lcgArr[lcgRegReq->lcgId].isGbr = lcgRegReq->isGbr;
866 } /* end of RgSchMacLcgRegReq */
870 /***********************************************************
872 * Func : RgSchMacUlSpsResetReq
874 * Desc : Utility Function to reset SPS params for a UE
877 * - Fetch the ueCb using the crnti
878 * - reset implRelCnt and explRelCnt
885 **********************************************************/
887 S16 RgSchMacUlSpsResetReq
890 RgInfUlSpsReset *ulSpsResetInfo
893 S16 RgSchMacUlSpsResetReq (pst, lcInfo)
895 RgInfUlSpsReset *ulSpsResetInfo;
899 RgCellCb *cell = NULLP;
902 RG_IS_INST_VALID(pst->dstInst);
903 inst = pst->dstInst - RG_INST_START;
904 cell = rgCb[inst].cell;
905 /* Fetch the cell and then the UE */
907 (cell->cellId != ulSpsResetInfo->cellId))
910 RLOG_ARG0(L_ERROR, DBG_CELLID,ulSpsResetInfo->cellId,"Cell does not exist ");
914 if ((ue = rgDBMGetUeCb(cell, ulSpsResetInfo->crnti)) == NULLP)
916 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
917 ulSpsResetInfo->crnti);
921 ue->ul.implRelCntr = 0;
922 ue->ul.explRelCntr = 0;
925 } /* end of RgSchMacUlSpsResetReq */
930 /***********************************************************
932 * Func : RgSchMacSpsLcRegReq
934 * Desc : Utility Function to register the set of uplink SPS logical
935 * channels for a SPS UE.
936 * Invoked at the time of activation of a UE for UL-SPS.
937 * Whenever there is data on these LCs MAC shall inform scheduler
940 * - Fetch the ueCb using the crnti given in lcInfo
941 * - Store the sps-rnti and set the bits corresponding to the
942 * logical channel ids in ueUlCb->spsLcMask.
947 * Notes: This function should be called at the time UL SPS is activated
948 * for a UE at scheduler
953 **********************************************************/
955 S16 RgSchMacSpsLcRegReq
958 RgInfSpsLcInfo *lcInfo
961 S16 RgSchMacSpsLcRegReq (pst, lcInfo)
963 RgInfSpsLcInfo *lcInfo;
967 RgCellCb *cell= NULLP;
971 RG_IS_INST_VALID(pst->dstInst);
972 inst = pst->dstInst - RG_INST_START;
973 cell = rgCb[inst].cell;
974 /* Fetch the cell and then the UE */
975 if((cell == NULLP) ||
976 (cell->cellId != lcInfo->cellId))
979 RLOG_ARG0(L_ERROR,DBG_CELLID,lcInfo->cellId, "Cell does not exist ");
983 if ((ue = rgDBMGetUeCb(cell, lcInfo->crnti)) == NULLP)
985 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
990 /* Store the sps-rnti and SPS LC information in the UE */
991 ue->spsRnti = lcInfo->spsRnti;
992 for (idx=0; idx < lcInfo->spsLcCnt; idx++)
994 /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
995 ue->ul.spsLcId[(lcInfo->spsLcId[idx])-1] = TRUE;
997 ue->ul.implRelCnt = lcInfo->implRelCnt;
998 ue->ul.explRelCnt = ue->ul.implRelCnt + 1; /*(lcInfo->implRelCnt * lcInfo->spsPrd);*/
1000 /* Insert the UE into SPS UE List */
1001 if (rgDBMInsSpsUeCb(cell, ue) == RFAILED)
1003 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1004 "Ue insertion into SPS list failed SPS CRNTI:%d", ue->spsRnti);
1009 } /* end of RgSchMacSpsLcRegReq */
1012 /***********************************************************
1014 * Func : RgSchMacSpsLcDeregReq
1016 * Desc : Utility Function to deregister the set of uplink SPS
1017 * logical channels for a UE.
1018 * Invoked at the time of release of UL-SPS for an activated UE.
1021 * - Fetch the ueCb using the crnti given
1022 * - Reset the bits corresponding to the logical channel ids in
1023 * ueUlCb->spsLcMask.
1028 * Notes: This function should be called at the time UL SPS is released
1029 * for a UE at scheduler
1034 **********************************************************/
1036 S16 RgSchMacSpsLcDeregReq
1043 S16 RgSchMacSpsLcDeregReq (pst, cellId, crnti)
1050 RgCellCb *cell = NULLP;
1053 RG_IS_INST_VALID(pst->dstInst);
1054 inst = pst->dstInst - RG_INST_START;
1055 cell = rgCb[inst].cell;
1056 /* Fetch the cell and then the UE */
1057 if((cell == NULLP) ||
1058 (cell->cellId != cellId))
1061 RLOG_ARG0(L_ERROR,DBG_CELLID,cellId, "Cell does not exist ");
1065 if ((ue = rgDBMGetUeCb(cell, crnti)) == NULLP)
1067 RLOG_ARG1(L_ERROR, DBG_CELLID,cellId,"CRNTI:%d Ue does not exist", crnti);
1071 /* No need to reset the SPS LC Ids as they will not be looked at*/
1073 /* Delete UE from the SPS UE List */
1074 rgDBMDelSpsUeCb(cell, ue);
1077 } /* end of RgSchMacSpsLcDeregReq */
1079 #endif /* LTEMAC_SPS */
1082 * @brief Function for handling CRNTI change request
1083 * received from scheduler to MAC.
1087 * Function : rgUtlHndlCrntiChng
1089 * - Delete old UE from the list.
1090 * - Update the new rnti and re-insert the UE in the list.
1093 * @param[in] Inst inst
1094 * @param[in] RgCellCb *cell,
1095 * @param[in] CmLteRnti rnti,
1096 * @param[in] CmLteRnti newRnti
1102 static S16 rgUtlHndlCrntiChng
1110 static S16 rgUtlHndlCrntiChng(inst,cell, rnti, newRnti)
1118 RgUeCb *newUe = NULLP;
1120 ue = rgDBMGetUeCb(cell, rnti);
1121 newUe = rgDBMGetUeCbFromRachLst(cell, newRnti);
1122 if ((ue == NULLP) || (newUe == NULLP))
1124 RLOG_ARG4(L_ERROR,DBG_CELLID,cell->cellId,
1125 "RNTI:%d Failed to get UECB[%lu:%lu] or NEW RNTI:%d",
1126 rnti, ((PTR)ue), ((PTR)newUe), newRnti);
1129 #ifdef XEON_SPECIFIC_CHANGES
1130 CM_LOG_DEBUG(CM_LOG_ID_MAC, "MAC:UE[%d] id changed to %d\n", rnti, newRnti);
1132 rgDBMDelUeCb(cell, ue);
1136 memcpy(&(ue->contResId), &(newUe->contResId),
1137 sizeof(newUe->contResId));
1138 /* Fix : syed MSG4 might be RETXing need to store the
1140 rgDHMFreeUe(inst,&ue->dl.hqEnt);
1141 ue->dl.hqEnt = newUe->dl.hqEnt;
1143 rgDBMInsUeCb(cell, ue);
1145 rgDBMDelUeCbFromRachLst(cell, newUe);
1146 rgFreeSBuf(inst,(Data **)&newUe, sizeof(*newUe));
1149 } /* end of rgUtlHndlCrntiChng */
1153 * @brief Function for handling UE release for SCELL
1154 * triggered from SCH to MAC.
1158 * Function : rgDelUeFrmAllSCell
1160 * - This Function should be invoked by PCell of UE
1161 * - Remove the UE context from SCELL corresponding to rnti.
1163 * @param[in] Inst *macInst,
1164 * @param[in] RgUeCb *ue
1165 * @return ROK is SUCCESS
1168 S16 rgDelUeFrmAllSCell
1174 S16 rgDelUeFrmAllSCell(cell, ue)
1179 Inst inst = cell->macInst - RG_INST_START;
1183 RgPrgUeSCellDelInfo ueSCellDelInfo;
1185 /* To Delete the SCells if exisits for that UE */
1186 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1188 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1190 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1192 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1193 ueSCellDelInfo.ueId = ue->ueId;
1194 ueSCellDelInfo.sCellId = ue->sCelInfo[idx].sCellId;
1196 /* Filling same ueId in newRnti so that SMAC will check if newRnti
1197 *and old UeId is same that means its a UeSCell delete request*/
1198 ueSCellDelInfo.newRnti = ue->ueId;
1200 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueSCellDelInfo);
1201 ue->sCelInfo[idx].isSCellAdded = FALSE;
1206 } /* rgDelUeFrmAllSCell */
1209 * @brief Function to validate AddSCellCfg.
1213 * Function : rgUtlVltdAddSCellCfg
1216 * @param[in] ueSCellCb secondary cell CB for validation
1217 * @param[in] cell cell control block
1218 * @param[in] inst instance number to fetch rgCb instance
1223 S16 rgUtlVltdAddSCellCfg
1225 RgPrgUeSCellCfgInfo *ueSCellCb,
1230 S16 rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst)
1231 RgPrgUeSCellCfgInfo *ueSCellCb;
1238 /* To Validate the CellID presence */
1239 if((cell == NULLP) ||
1240 (cell->cellId != ueSCellCb->cellId))
1242 RGDBGERRNEW(inst, (rgPBuf(inst),
1243 "[%d]Sec Cell does not exit %d\n",
1244 ueSCellCb->ueId, ueSCellCb->cellId));
1247 #ifdef TENB_MULT_CELL_SUPPRT
1248 if((ueSCellCb->rguDlSapId > rgCb[inst].numRguSaps) ||
1249 (ueSCellCb->rguUlSapId > rgCb[inst].numRguSaps))
1251 RGDBGERRNEW(inst,(rgPBuf(inst), "Invald Sap Id: DL %d UL %d for ueId %d failed\n",
1252 ueSCellCb->rguDlSapId,
1253 ueSCellCb->rguUlSapId,
1254 ueSCellCb->cellId));
1259 } /* rgUtlVltdAddSCellCfg */
1262 * @brief Function to build CrntiChangeReq and send to all SMACs.
1266 * Function : rgUtlSndCrntiChngReq2AllSMacs
1268 * - This Function should be invoked by PCell of UE
1269 * - It sends RgPrgPMacSMacUeSCellDelReq to all SMACs with newRnti sent
1270 * by SCH. SMAC will check if newRnti is not equal to old UeId then it
1271 * do only UeId change else it will delete the UeScell context
1273 * @param[in] cell Cell CB to get Ue control block
1274 * @param[in] rnti Ue Identifier used to fill in UeId Change req
1275 * @param[in] newRnti UE new identifier, to be used in UeId Change req
1280 static S16 rgUtlSndCrntiChngReq2AllSMacs
1287 static S16 rgUtlSndCrntiChngReq2AllSMacs(cell, rnti, newRnti)
1293 Inst inst = cell->macInst - RG_INST_START;
1296 RgPrgUeSCellDelInfo ueIdChngReq;
1300 TfuDelDatReqInfo delDatReq;
1303 /* use newRnti to get UeCb in PMac because rnti is already changed in PMac*/
1304 ue = rgDBMGetUeCb(cell, newRnti);
1307 RGDBGERRNEW(inst,(rgPBuf(inst),"[%d]RNTI:Failed to get ueCb \
1308 newRnti=%d\n", rnti, newRnti));
1311 /* For all added SCells, prepare and send ueIdChngReq */
1312 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1314 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1316 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1318 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1320 ueIdChngReq.ueId = rnti;
1321 ueIdChngReq.sCellId = ue->sCelInfo[idx].sCellId;
1323 /* Filling newRnti so that SMAC can check if old ueId and new UeId
1324 *(newRnti) is different then its a UeId change request from PMAC.
1325 * RgPrgPMacSMacUeSCellDelReq is being reused for UeId change req
1326 * from PMAC to SMAC*/
1327 ueIdChngReq.newRnti = newRnti;
1329 /* Re-using UeSCellDelReq API for UeId change*/
1330 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueIdChngReq);
1332 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1333 delDatReq.cellId = ueIdChngReq.sCellId;
1334 delDatReq.ueId = ueIdChngReq.ueId;
1335 rgLIMTfuDelDatReq(sCellInstIdx, &delDatReq);
1342 } /* rgUtlSndCrntiChngReq2AllSMacs */
1344 #endif /* LTE_ADV */
1347 * @brief Function for handling CRNTI Context release
1348 * triggered from SCH to MAC.
1352 * Function : rgUtlHndlCrntiRls
1354 * - Remove the UE context from MAC corresponding to rnti.
1357 * @param[in] RgCellCb *cell,
1358 * @param[in] CmLteRnti rnti
1362 static Void rgUtlHndlCrntiRls
1365 RgInfRlsRnti *rlsRnti
1368 static Void rgUtlHndlCrntiRls(cell, rlsRnti)
1373 Inst inst = cell->macInst - RG_INST_START;
1376 RgUeCb *spsUeCb = NULLP;
1379 if ((ue = rgDBMGetUeCb(cell, rlsRnti->rnti)) == NULLP)
1381 /* Check in RachLst */
1382 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1384 /* Delete Ue from the UE list */
1385 rgDBMDelUeCbFromRachLst(cell, ue);
1388 rgRAMFreeUeCb(inst,ue);
1392 RLOG_ARG1(L_WARNING,DBG_CELLID,cell->cellId,
1393 "RNTI:%d No ueCb found in RachLst",rlsRnti->rnti);
1399 if(FALSE == rlsRnti->isUeSCellDel)
1401 rgDelUeFrmAllSCell(cell, ue);
1403 #endif /* LTE_ADV */
1405 /* Delete Ue from the UE list */
1406 rgDBMDelUeCb(cell, ue);
1408 spsUeCb = rgDBMGetSpsUeCb (cell, ue->spsRnti);
1411 rgDBMDelSpsUeCb(cell, spsUeCb);
1416 rgCFGFreeUeCb(cell, ue);
1417 /* MS_REMOVE : syed Check in RachLst */
1419 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1421 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1422 "RNTI:%d STALE UE is still present", rlsRnti->rnti);
1428 } /* end of rgUtlHndlCrntiRls */
1431 * @brief Function for handling RaResp request received from scheduler to MAC.
1435 * Function : RgSchMacRlsRntiReq
1437 * This function shall be invoked whenever scheduler is done with the
1438 * allocations of random access responses for a subframe.
1439 * This shall invoke RAM to create ueCbs for all the rapIds allocated and
1440 * shall invoke MUX to create RAR PDUs for raRntis allocated.
1443 * @param[in] CmLteCellId cellId,
1444 * @param[in] CmLteTimingInfo timingInfo,
1445 * @param[in] RaRespInfo *rarInfo
1450 S16 RgSchMacRlsRntiReq
1453 RgInfRlsRnti *rlsRnti
1456 S16 RgSchMacRlsRntiReq(pst, rlsRnti)
1458 RgInfRlsRnti *rlsRnti;
1462 // RgInfUeDelInd ueDelInd;
1466 TfuDelDatReqInfo delDatReq;
1469 RG_IS_INST_VALID(pst->dstInst);
1470 macInst = pst->dstInst - RG_INST_START;
1471 cell = rgCb[macInst].cell;
1473 if(NULLP == rlsRnti)
1478 if((cell == NULLP) ||
1479 (cell->cellId != rlsRnti->cellId))
1482 RLOG_ARG1(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1483 "No cellCb found with cellId for RNTI:%d",
1487 /* Fix : syed Clearing UE context when SCH indicates to do so
1488 * UE DEL from CRG interface is now dummy. */
1489 if (rlsRnti->ueIdChng)
1491 /* Fix : syed ueId change as part of reestablishment.
1492 * Now SCH to trigger this. CRG ueRecfg for ueId change
1494 if (rgUtlHndlCrntiChng(macInst,cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1496 RLOG_ARG2(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1497 "CRNTI change failed for RNTI:%d new RNTI:%d",
1498 rlsRnti->rnti,rlsRnti->newRnti);
1503 /*PMAC_Reest: Prepare CrntiChngReq and then send to all SMACs to change
1506 if(rgUtlSndCrntiChngReq2AllSMacs(cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1508 /* TODO: do we need to send DelInd to SCH in failure case*/
1513 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1514 delDatReq.cellId = cell->cellId;
1515 delDatReq.ueId = rlsRnti->rnti;
1516 rgLIMTfuDelDatReq(macInst, &delDatReq);
1521 rgUtlHndlCrntiRls(cell, rlsRnti);
1523 /* Fix : syed Send delete confirmation to SCH */
1524 /* Send RgMacSchUeDelInd to SCH only if it is Rnti release to PMAC.
1525 * Basically dont send DelInd to SCH incase of Ue SCell Del*/
1527 if(FALSE == rlsRnti->isUeSCellDel)
1530 //TODO: commented for compilation without SCH
1532 ueDelInd.cellSapId = cell->schInstMap.cellSapId;
1533 ueDelInd.cellId = rlsRnti->cellId;
1534 ueDelInd.rnti = rlsRnti->rnti;
1535 rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
1536 RgMacSchUeDel(&schPst, &ueDelInd);
1541 } /* end of RgSchMacRlsRntiReq */
1550 Bool RgUtlIsTbMuxed()
1555 SFndLenMsg(tb->macHdr, &len);
1556 return (len?TRUE : FALSE);
1560 /**********************************************************************
1563 **********************************************************************/