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
36 /* header include files (.h) */
37 #include "common_def.h"
38 #include "rg_env.h" /* MAC Environment Defines */
39 #include "crg.h" /* CRG Interface defines */
40 #include "rgu.h" /* RGU Interface defines */
41 #include "tfu.h" /* TFU Interface defines */
42 #include "rg_sch_inf.h" /* RGR Interface defines */
43 #include "lrg.h" /* LRG Interface defines */
45 #include "rg_prg.h" /* PRG(MAC-MAC) Interface includes */
46 #include "rg.h" /* MAC defines */
47 #include "rg_err.h" /* MAC error defines */
49 /* header/extern include files (.x) */
50 #include "cm5.x" /* Timer */
52 #include "crg.x" /* CRG Interface includes */
53 #include "rgu.x" /* RGU Interface includes */
54 #include "tfu.x" /* TFU Interface includes */
55 #include "rg_sch_inf.x" /* RGR Interface includes */
56 #include "lrg.x" /* LRG Interface includes */
57 #include "rg_prg.x" /* PRG(MAC-MAC) Interface includes */
59 #include "du_app_mac_inf.h"
60 #include "rg.x" /* MAC includes */
63 #define RG_NON_MIMO_IDX 0
69 /* forward references */
70 static S16 rgUtlHndlCrntiChng ARGS((
76 static Void rgUtlHndlCrntiRls ARGS((
81 S16 rgDelUeFrmAllSCell ARGS((
87 static S16 rgUtlSndCrntiChngReq2AllSMacs ARGS((
93 /***********************************************************
95 * Func : rgAllocShrablSBuf
97 * Desc : Utility Function to Allocate static buffer which is
98 * sharable among different layers if YYYY flag is enabled.
99 * else it allocates from normal static region
100 * Memory allocated is assumed contiguous.
106 * Notes: Caller doesnt need to raise the alarm in case of memory
107 * allocation gets failed.
111 **********************************************************/
112 S16 rgAllocShrablSBuf
115 Data **pData, /* Pointer of the data to be returned */
119 RgUstaDgn dgn; /* Alarm diagnostics structure */
121 /* Initialize the param to NULLP */
129 /* allocate buffer */
130 if (SGetStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size, 0) != ROK)
132 dgn.type = LRG_USTA_DGNVAL_MEM;
133 dgn.u.mem.region = rgCb[inst].rgInit.region;
134 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
135 /* Send an alarm to Layer Manager */
136 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
137 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
138 DU_LOG("\nERROR --> MAC : Unable to Allocate Buffer");
143 DU_LOG("\nDEBUG --> MAC : SGetSBuf(Region (%d), Pool (%d), Size (%ld)), Data (0x%p))\n",
144 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData);
146 DU_LOG("\nDEBUG --> MAC : SGetSBuf(Region (%d), Pool (%d), Size (%d)), Data (0x%p))\n",
147 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData);
150 /* zero out the allocated memory */
151 memset(*pData, 0x00, size);
155 } /* end of rgAllocSBuf */
158 /***********************************************************
162 * Desc : Utility Function to Allocate static buffer.
163 * Memory allocated is assumed contiguous.
169 * Notes: Caller doesnt need to raise the alarm in case of memory
170 * allocation gets failed.
174 **********************************************************/
178 Data **pData, /* Pointer of the data to be returned */
182 RgUstaDgn dgn; /* Alarm diagnostics structure */
184 /* Initialize the param to NULLP */
192 /* allocate buffer */
193 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
194 MS_BUF_ADD_ALLOC_CALLER();
196 if (SGetSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size) != ROK)
198 dgn.type = LRG_USTA_DGNVAL_MEM;
199 dgn.u.mem.region = rgCb[inst].rgInit.region;
200 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
201 /* Send an alarm to Layer Manager */
202 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
203 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
204 DU_LOG("\nERROR --> MAC : Unable to Allocate Buffer");
208 /* zero out the allocated memory */
209 memset(*pData, 0x00, size);
213 } /* end of rgAllocSBuf */
217 * Fun: rgFreeSharableSBuf
219 * Desc: The argument to rgFreeSBuf() is a pointer to a block
220 * previously allocated by rgAllocSBuf() and size. It
221 * deallocates the memory.
225 * Notes: ccpu00117052 - MOD- changed the Data parameter from
226 * pointer to address of pointer so that
227 * the freed memory could be set to NULLP
231 Void rgFreeSharableSBuf
234 Data **data, /* address of pointer to data */
241 if ((data == NULLP) || (*data == NULLP) || (size == 0))
246 /* Deallocate buffer */
247 ret = SPutStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size, SS_SHARABLE_MEMORY);
258 } /* end of rgFreeSharableBuf */
266 * Desc: The argument to rgFreeSBuf() is a pointer to a block
267 * previously allocated by rgAllocSBuf() and size. It
268 * deallocates the memory.
272 * Notes: ccpu00117052 - MOD- changed the Data parameter from
273 * pointer to address of pointer so that
274 * the freed memory could be set to NULLP
281 Data **data, /* address of pointer to data */
288 if ((data == NULLP) || (*data == NULLP) || (size == 0))
294 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
297 /* Deallocate buffer */
298 ret = SPutSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size);
302 DU_LOG("\nERROR --> MAC : rgFreeSBuf failed.\n");
310 } /* end of rgFreeSBuf */
313 /***********************************************************
317 * Desc : Utility Function to Allocate message buffer.
323 * Notes: Caller doesnt need to raise the alarm in case of memory
324 * allocation gets failed.
328 **********************************************************/
332 Buffer **mBuf /* Message Buffer pointer be returned */
337 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
338 MS_BUF_ADD_ALLOC_CALLER();
340 ret = SGetMsg(RG_GET_MEM_REGION(rgCb[inst]), RG_GET_MEM_POOL(rgCb[inst]), mBuf);
344 /* Moving diagnostics structure to limited scope for optimization */
345 RgUstaDgn dgn; /* Alarm diagnostics structure */
347 rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
349 /* Send an alarm to Layer Manager */
350 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
351 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
352 DU_LOG("\nERROR --> MAC : Unable to Allocate Buffer");
358 } /* end of rgGetMsg */
361 /***********************************************************
363 * Func : rgFillDgnParams
365 * Desc : Utility Function to Fill Diagonostic params.
373 **********************************************************/
384 case LRG_USTA_DGNVAL_MEM:
385 dgn->type = (uint8_t) LRG_USTA_DGNVAL_MEM;
386 dgn->u.mem.region = rgCb[inst].rgInit.region;
387 dgn->u.mem.pool = rgCb[inst].rgInit.pool;
395 } /* end of rgFillDgnParams */
398 /***********************************************************
400 * Func : rgUpdtRguDedSts
402 * Desc : Utility Function to update rgu sap statistics for dedicated
413 **********************************************************/
418 uint8_t stsType, /* Statistics type to update */
419 RgRguDedDatReq *datReq /* DatReq pointer */
427 case RG_RGU_SDU_RCVD:
428 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
430 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
431 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
433 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
435 rguDlSap->sapSts.numPduRcvd +=
436 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
442 case RG_RGU_SDU_DROP:
443 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
445 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
446 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
448 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
450 rguDlSap->sapSts.numPduRcvd +=
451 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
452 rguDlSap->sapSts.numPduDrop +=
453 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
462 } /* rgUpdtRguDedSts */
465 /***********************************************************
467 * Func : rgUpdtRguCmnSts
469 * Desc : Utility Function to update rgu sap statistics for common
480 **********************************************************/
485 uint8_t stsType /* Statistics type to update */
491 case RG_RGU_SDU_RCVD:
492 rguDlSap->sapSts.numPduRcvd ++;
494 case RG_RGU_SDU_DROP:
495 rguDlSap->sapSts.numPduRcvd ++;
496 rguDlSap->sapSts.numPduDrop ++;
501 } /* rgUpdtRguCmnSts */
504 /***********************************************************
506 * Func : rgUpdtCellCnt
508 * Desc : Utility Function to update cell count. It gives number of active
515 * Notes: This function should be called only after cell is added/deleted
516 * from the globlal hashlist
520 **********************************************************/
521 Void rgUpdtCellCnt(Inst inst,uint8_t updtType)
527 rgCb[inst].genSts.numCellCfg++;
530 rgCb[inst].genSts.numCellCfg--;
537 } /* rgUpdtCellCnt */
540 /***********************************************************
544 * Desc : Utility Function to update ue count. It gives number of active
551 * Notes: This function should be called only after ue is added/deleted
552 * from the globlal hashlist
556 **********************************************************/
557 Void rgUpdtUeCnt(Inst inst,uint8_t updtType)
562 rgCb[inst].genSts.numUeCfg++;
565 rgCb[inst].genSts.numUeCfg--;
575 * Fun: rgAllocEventMem
577 * Desc: This function allocates event memory
579 * Ret: ROK - on success
580 * RFAILED - on failure
595 volatile uint32_t startTime=0;
598 sMem.region = rgCb[inst].rgInit.region;
599 sMem.pool = rgCb[inst].rgInit.pool;
601 #if (ERRCLASS & ERRCLS_DEBUG)
604 DU_LOG("\nERROR --> MAC : rgAllocEventMem(): memSize invalid\n");
607 #endif /* ERRCLASS & ERRCLS_DEBUG */
611 SStartTask(&startTime, PID_MACUTL_CMALLCEVT);
613 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
614 MS_BUF_ADD_ALLOC_CALLER();
616 #ifdef TFU_ALLOC_EVENT_NO_INIT
617 if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
619 if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
622 DU_LOG("\nERROR --> MAC : cmAllocEvnt Failed");
627 SStopTask(startTime, PID_MACUTL_CMALLCEVT);
630 } /* end of rgAllocEventMem*/
636 * Desc: This function allocates event memory
638 * Ret: ROK - on success
639 * RFAILED - on failure
656 #ifdef TFU_ALLOC_EVENT_NO_INIT
657 ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
659 ret = cmGetMem(memCp, len, (Ptr *)ptr);
662 } /* end of rgGetEventMem*/
664 /***********************************************************
666 * Func : rgGetPstToInst
668 * Desc : Utility Function to get the pst structure to post a message to
675 * Notes: This function should be called while sending a msg from
676 * MAC to a scheduler instance
680 **********************************************************/
689 pst->srcEnt = rgCb[srcInst].rgInit.ent;
690 pst->srcInst = rgCb[srcInst].rgInit.inst;
691 pst->srcProcId = rgCb[srcInst].rgInit.procId;
692 pst->region = rgCb[srcInst].rgInit.region;
693 pst->pool = rgCb[srcInst].rgInit.pool;
695 pst->dstProcId = rgCb[dstInst].rgInit.procId;
696 pst->dstEnt = rgCb[dstInst].rgInit.ent;
697 pst->dstInst = dstInst;
701 pst->route = RTESPEC;
704 } /* end of rgGetPstToInst */
706 /***********************************************************
708 * Func : RgSchMacLcgRegReq
710 * Desc : Utility Function to register the set of GBR LCG.
711 * Invoked at the time of LCG configuration/Reconfiguration at Schedular.
714 * - Fetch the ueCb using the crnti given in lcInfo
715 * - Store the if LCG is GBR or not.
720 * Notes: This function should be called at the time of LCG
721 * configuration/Reconfiguration at Schedular.
726 **********************************************************/
727 S16 RgSchMacLcgRegReq(Pst *pst,RgInfLcgRegReq *lcgRegReq)
730 RgCellCb *cell = NULLP;
733 RG_IS_INST_VALID(pst->dstInst);
734 inst = pst->dstInst - RG_INST_START;
735 cell = rgCb[inst].cell;
736 /* Fetch the cell and then the UE */
737 if((cell == NULLP) ||
738 (cell->cellId != lcgRegReq->cellId))
741 DU_LOG("\nERROR --> MAC : Cell does not exist ");
745 if ((ue = rgDBMGetUeCb(cell, lcgRegReq->crnti)) == NULLP)
747 DU_LOG("\nERROR --> MAC : CRNTI:%d does not exist",
751 ue->ul.lcgArr[lcgRegReq->lcgId].isGbr = lcgRegReq->isGbr;
754 } /* end of RgSchMacLcgRegReq */
758 /***********************************************************
760 * Func : RgSchMacUlSpsResetReq
762 * Desc : Utility Function to reset SPS params for a UE
765 * - Fetch the ueCb using the crnti
766 * - reset implRelCnt and explRelCnt
773 **********************************************************/
774 S16 RgSchMacUlSpsResetReq(Pst *pst,RgInfUlSpsReset *ulSpsResetInfo)
777 RgCellCb *cell = NULLP;
780 RG_IS_INST_VALID(pst->dstInst);
781 inst = pst->dstInst - RG_INST_START;
782 cell = rgCb[inst].cell;
783 /* Fetch the cell and then the UE */
785 (cell->cellId != ulSpsResetInfo->cellId))
788 DU_LOG("\nERROR --> MAC : Cell does not exist ");
792 if ((ue = rgDBMGetUeCb(cell, ulSpsResetInfo->crnti)) == NULLP)
794 DU_LOG("\nERROR --> MAC : CRNTI:%d does not exist",
795 ulSpsResetInfo->crnti);
799 ue->ul.implRelCntr = 0;
800 ue->ul.explRelCntr = 0;
803 } /* end of RgSchMacUlSpsResetReq */
808 /***********************************************************
810 * Func : RgSchMacSpsLcRegReq
812 * Desc : Utility Function to register the set of uplink SPS logical
813 * channels for a SPS UE.
814 * Invoked at the time of activation of a UE for UL-SPS.
815 * Whenever there is data on these LCs MAC shall inform scheduler
818 * - Fetch the ueCb using the crnti given in lcInfo
819 * - Store the sps-rnti and set the bits corresponding to the
820 * logical channel ids in ueUlCb->spsLcMask.
825 * Notes: This function should be called at the time UL SPS is activated
826 * for a UE at scheduler
831 **********************************************************/
832 S16 RgSchMacSpsLcRegReq(Pst *pst,RgInfSpsLcInfo *lcInfo)
835 RgCellCb *cell= NULLP;
839 RG_IS_INST_VALID(pst->dstInst);
840 inst = pst->dstInst - RG_INST_START;
841 cell = rgCb[inst].cell;
842 /* Fetch the cell and then the UE */
843 if((cell == NULLP) ||
844 (cell->cellId != lcInfo->cellId))
847 DU_LOG("\nERROR --> MAC : Cell does not exist ");
851 if ((ue = rgDBMGetUeCb(cell, lcInfo->crnti)) == NULLP)
853 DU_LOG("\nERROR --> MAC : CRNTI:%d does not exist",
858 /* Store the sps-rnti and SPS LC information in the UE */
859 ue->spsRnti = lcInfo->spsRnti;
860 for (idx=0; idx < lcInfo->spsLcCnt; idx++)
862 /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
863 ue->ul.spsLcId[(lcInfo->spsLcId[idx])-1] = TRUE;
865 ue->ul.implRelCnt = lcInfo->implRelCnt;
866 ue->ul.explRelCnt = ue->ul.implRelCnt + 1; /*(lcInfo->implRelCnt * lcInfo->spsPrd);*/
868 /* Insert the UE into SPS UE List */
869 if (rgDBMInsSpsUeCb(cell, ue) == RFAILED)
871 DU_LOG("\nERROR --> MAC : Ue insertion into SPS list failed SPS CRNTI:%d", ue->spsRnti);
876 } /* end of RgSchMacSpsLcRegReq */
879 /***********************************************************
881 * Func : RgSchMacSpsLcDeregReq
883 * Desc : Utility Function to deregister the set of uplink SPS
884 * logical channels for a UE.
885 * Invoked at the time of release of UL-SPS for an activated UE.
888 * - Fetch the ueCb using the crnti given
889 * - Reset the bits corresponding to the logical channel ids in
895 * Notes: This function should be called at the time UL SPS is released
896 * for a UE at scheduler
901 **********************************************************/
902 S16 RgSchMacSpsLcDeregReq(Pst *pst,CmLteCellId cellId,CmLteRnti crnti)
905 RgCellCb *cell = NULLP;
908 RG_IS_INST_VALID(pst->dstInst);
909 inst = pst->dstInst - RG_INST_START;
910 cell = rgCb[inst].cell;
911 /* Fetch the cell and then the UE */
912 if((cell == NULLP) ||
913 (cell->cellId != cellId))
916 DU_LOG("\nERROR --> MAC : Cell does not exist ");
920 if ((ue = rgDBMGetUeCb(cell, crnti)) == NULLP)
922 DU_LOG("\nERROR --> MAC : CRNTI:%d Ue does not exist", crnti);
926 /* No need to reset the SPS LC Ids as they will not be looked at*/
928 /* Delete UE from the SPS UE List */
929 rgDBMDelSpsUeCb(cell, ue);
932 } /* end of RgSchMacSpsLcDeregReq */
934 #endif /* LTEMAC_SPS */
937 * @brief Function for handling CRNTI change request
938 * received from scheduler to MAC.
942 * Function : rgUtlHndlCrntiChng
944 * - Delete old UE from the list.
945 * - Update the new rnti and re-insert the UE in the list.
948 * @param[in] Inst inst
949 * @param[in] RgCellCb *cell,
950 * @param[in] CmLteRnti rnti,
951 * @param[in] CmLteRnti newRnti
956 static S16 rgUtlHndlCrntiChng
965 RgUeCb *newUe = NULLP;
967 ue = rgDBMGetUeCb(cell, rnti);
968 newUe = rgDBMGetUeCbFromRachLst(cell, newRnti);
969 if ((ue == NULLP) || (newUe == NULLP))
971 DU_LOG("\nERROR --> MAC : RNTI:%d Failed to get UECB[%lu:%lu] or NEW RNTI:%d",
972 rnti, ((PTR)ue), ((PTR)newUe), newRnti);
975 #ifdef XEON_SPECIFIC_CHANGES
976 DU_LOG("\nDEBUG --> MAC : MAC:UE[%d] id changed to %d\n", rnti, newRnti);
978 rgDBMDelUeCb(cell, ue);
982 memcpy(&(ue->contResId), &(newUe->contResId),
983 sizeof(newUe->contResId));
984 /* Fix : syed MSG4 might be RETXing need to store the
986 rgDHMFreeUe(inst,&ue->dl.hqEnt);
987 ue->dl.hqEnt = newUe->dl.hqEnt;
989 rgDBMInsUeCb(cell, ue);
991 rgDBMDelUeCbFromRachLst(cell, newUe);
992 rgFreeSBuf(inst,(Data **)&newUe, sizeof(*newUe));
995 } /* end of rgUtlHndlCrntiChng */
999 * @brief Function for handling UE release for SCELL
1000 * triggered from SCH to MAC.
1004 * Function : rgDelUeFrmAllSCell
1006 * - This Function should be invoked by PCell of UE
1007 * - Remove the UE context from SCELL corresponding to rnti.
1009 * @param[in] Inst *macInst,
1010 * @param[in] RgUeCb *ue
1011 * @return ROK is SUCCESS
1013 S16 rgDelUeFrmAllSCell(RgCellCb *cell,RgUeCb *ue)
1015 Inst inst = cell->macInst - RG_INST_START;
1019 RgPrgUeSCellDelInfo ueSCellDelInfo;
1021 /* To Delete the SCells if exisits for that UE */
1022 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1024 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1026 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1028 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1029 ueSCellDelInfo.ueId = ue->ueId;
1030 ueSCellDelInfo.sCellId = ue->sCelInfo[idx].sCellId;
1032 /* Filling same ueId in newRnti so that SMAC will check if newRnti
1033 *and old UeId is same that means its a UeSCell delete request*/
1034 ueSCellDelInfo.newRnti = ue->ueId;
1036 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueSCellDelInfo);
1037 ue->sCelInfo[idx].isSCellAdded = FALSE;
1042 } /* rgDelUeFrmAllSCell */
1045 * @brief Function to validate AddSCellCfg.
1049 * Function : rgUtlVltdAddSCellCfg
1052 * @param[in] ueSCellCb secondary cell CB for validation
1053 * @param[in] cell cell control block
1054 * @param[in] inst instance number to fetch rgCb instance
1058 S16 rgUtlVltdAddSCellCfg(RgPrgUeSCellCfgInfo *ueSCellCb,RgCellCb *cell,Inst inst)
1062 /* To Validate the CellID presence */
1063 if((cell == NULLP) ||
1064 (cell->cellId != ueSCellCb->cellId))
1066 DU_LOG("\nERROR --> MAC : [%d]Sec Cell does not exit %d\n",
1067 ueSCellCb->ueId, ueSCellCb->cellId);
1070 #ifdef TENB_MULT_CELL_SUPPRT
1071 if((ueSCellCb->rguDlSapId > rgCb[inst].numRguSaps) ||
1072 (ueSCellCb->rguUlSapId > rgCb[inst].numRguSaps))
1074 DU_LOG("\nERROR --> MAC : Invald Sap Id: DL %d UL %d for ueId %d failed\n",
1075 ueSCellCb->rguDlSapId,
1076 ueSCellCb->rguUlSapId,
1082 } /* rgUtlVltdAddSCellCfg */
1085 * @brief Function to build CrntiChangeReq and send to all SMACs.
1089 * Function : rgUtlSndCrntiChngReq2AllSMacs
1091 * - This Function should be invoked by PCell of UE
1092 * - It sends RgPrgPMacSMacUeSCellDelReq to all SMACs with newRnti sent
1093 * by SCH. SMAC will check if newRnti is not equal to old UeId then it
1094 * do only UeId change else it will delete the UeScell context
1096 * @param[in] cell Cell CB to get Ue control block
1097 * @param[in] rnti Ue Identifier used to fill in UeId Change req
1098 * @param[in] newRnti UE new identifier, to be used in UeId Change req
1102 static S16 rgUtlSndCrntiChngReq2AllSMacs
1109 Inst inst = cell->macInst - RG_INST_START;
1112 RgPrgUeSCellDelInfo ueIdChngReq;
1116 TfuDelDatReqInfo delDatReq;
1119 /* use newRnti to get UeCb in PMac because rnti is already changed in PMac*/
1120 ue = rgDBMGetUeCb(cell, newRnti);
1123 DU_LOG("\nERROR --> MAC : [%d]RNTI:Failed to get ueCb \
1124 newRnti=%d\n", rnti, newRnti);
1127 /* For all added SCells, prepare and send ueIdChngReq */
1128 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1130 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1132 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1134 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1136 ueIdChngReq.ueId = rnti;
1137 ueIdChngReq.sCellId = ue->sCelInfo[idx].sCellId;
1139 /* Filling newRnti so that SMAC can check if old ueId and new UeId
1140 *(newRnti) is different then its a UeId change request from PMAC.
1141 * RgPrgPMacSMacUeSCellDelReq is being reused for UeId change req
1142 * from PMAC to SMAC*/
1143 ueIdChngReq.newRnti = newRnti;
1145 /* Re-using UeSCellDelReq API for UeId change*/
1146 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueIdChngReq);
1148 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1149 delDatReq.cellId = ueIdChngReq.sCellId;
1150 delDatReq.ueId = ueIdChngReq.ueId;
1151 rgLIMTfuDelDatReq(sCellInstIdx, &delDatReq);
1158 } /* rgUtlSndCrntiChngReq2AllSMacs */
1160 #endif /* LTE_ADV */
1163 * @brief Function for handling CRNTI Context release
1164 * triggered from SCH to MAC.
1168 * Function : rgUtlHndlCrntiRls
1170 * - Remove the UE context from MAC corresponding to rnti.
1173 * @param[in] RgCellCb *cell,
1174 * @param[in] CmLteRnti rnti
1177 static Void rgUtlHndlCrntiRls(RgCellCb *cell,RgInfRlsRnti *rlsRnti)
1179 Inst inst = cell->macInst - RG_INST_START;
1182 RgUeCb *spsUeCb = NULLP;
1185 if ((ue = rgDBMGetUeCb(cell, rlsRnti->rnti)) == NULLP)
1187 /* Check in RachLst */
1188 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1190 /* Delete Ue from the UE list */
1191 rgDBMDelUeCbFromRachLst(cell, ue);
1194 rgRAMFreeUeCb(inst,ue);
1198 DU_LOG("\nERROR --> MAC : RNTI:%d No ueCb found in RachLst",rlsRnti->rnti);
1204 if(FALSE == rlsRnti->isUeSCellDel)
1206 rgDelUeFrmAllSCell(cell, ue);
1208 #endif /* LTE_ADV */
1210 /* Delete Ue from the UE list */
1211 rgDBMDelUeCb(cell, ue);
1213 spsUeCb = rgDBMGetSpsUeCb (cell, ue->spsRnti);
1216 rgDBMDelSpsUeCb(cell, spsUeCb);
1221 rgCFGFreeUeCb(cell, ue);
1222 /* MS_REMOVE : syed Check in RachLst */
1224 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1226 DU_LOG("\nERROR --> MAC : RNTI:%d STALE UE is still present", rlsRnti->rnti);
1232 } /* end of rgUtlHndlCrntiRls */
1235 * @brief Function for handling RaResp request received from scheduler to MAC.
1239 * Function : RgSchMacRlsRntiReq
1241 * This function shall be invoked whenever scheduler is done with the
1242 * allocations of random access responses for a subframe.
1243 * This shall invoke RAM to create ueCbs for all the rapIds allocated and
1244 * shall invoke MUX to create RAR PDUs for raRntis allocated.
1247 * @param[in] CmLteCellId cellId,
1248 * @param[in] CmLteTimingInfo timingInfo,
1249 * @param[in] RaRespInfo *rarInfo
1253 S16 RgSchMacRlsRntiReq(Pst *pst,RgInfRlsRnti *rlsRnti)
1256 // RgInfUeDelInd ueDelInd;
1260 TfuDelDatReqInfo delDatReq;
1263 RG_IS_INST_VALID(pst->dstInst);
1264 macInst = pst->dstInst - RG_INST_START;
1265 cell = rgCb[macInst].cell;
1267 if(NULLP == rlsRnti)
1272 if((cell == NULLP) ||
1273 (cell->cellId != rlsRnti->cellId))
1276 DU_LOG("\nERROR --> MAC : No cellCb found with cellId for RNTI:%d",
1280 /* Fix : syed Clearing UE context when SCH indicates to do so
1281 * UE DEL from CRG interface is now dummy. */
1282 if (rlsRnti->ueIdChng)
1284 /* Fix : syed ueId change as part of reestablishment.
1285 * Now SCH to trigger this. CRG ueRecfg for ueId change
1287 if (rgUtlHndlCrntiChng(macInst,cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1289 DU_LOG("\nERROR --> MAC : CRNTI change failed for RNTI:%d new RNTI:%d",
1290 rlsRnti->rnti,rlsRnti->newRnti);
1295 /*PMAC_Reest: Prepare CrntiChngReq and then send to all SMACs to change
1298 if(rgUtlSndCrntiChngReq2AllSMacs(cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1300 /* TODO: do we need to send DelInd to SCH in failure case*/
1305 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1306 delDatReq.cellId = cell->cellId;
1307 delDatReq.ueId = rlsRnti->rnti;
1308 rgLIMTfuDelDatReq(macInst, &delDatReq);
1313 rgUtlHndlCrntiRls(cell, rlsRnti);
1315 /* Fix : syed Send delete confirmation to SCH */
1316 /* Send RgMacSchUeDelInd to SCH only if it is Rnti release to PMAC.
1317 * Basically dont send DelInd to SCH incase of Ue SCell Del*/
1319 if(FALSE == rlsRnti->isUeSCellDel)
1322 //TODO: commented for compilation without SCH
1324 ueDelInd.cellSapId = cell->schInstMap.cellSapId;
1325 ueDelInd.cellId = rlsRnti->cellId;
1326 ueDelInd.rnti = rlsRnti->rnti;
1327 rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
1328 RgMacSchUeDel(&schPst, &ueDelInd);
1333 } /* end of RgSchMacRlsRntiReq */
1336 Bool RgUtlIsTbMuxed(TfuDatReqTbInfo *tb)
1339 SFndLenMsg(tb->macHdr, &len);
1340 return (len?TRUE : FALSE);
1344 /**********************************************************************
1347 **********************************************************************/