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 TRC2(rgAllocShrablSBuf)
133 /* Initialize the param to NULLP */
141 /* allocate buffer */
142 if (SGetStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size, 0) != ROK)
144 dgn.type = LRG_USTA_DGNVAL_MEM;
145 dgn.u.mem.region = rgCb[inst].rgInit.region;
146 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
147 /* Send an alarm to Layer Manager */
148 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
149 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
150 RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
155 RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%ld)), Data (0x%p))\n",
156 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
158 RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%d)), Data (0x%p))\n",
159 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
162 /* zero out the allocated memory */
163 cmMemset((U8 *)*pData, 0x00, size);
167 } /* end of rgAllocSBuf */
170 /***********************************************************
174 * Desc : Utility Function to Allocate static buffer.
175 * Memory allocated is assumed contiguous.
181 * Notes: Caller doesnt need to raise the alarm in case of memory
182 * allocation gets failed.
186 **********************************************************/
191 Data **pData, /* Pointer of the data to be returned */
195 S16 rgAllocSBuf(inst,pData, size)
197 Data **pData; /* Pointer of the data to be returned */
198 Size size; /* size */
201 RgUstaDgn dgn; /* Alarm diagnostics structure */
205 /* Initialize the param to NULLP */
213 /* allocate buffer */
214 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
215 MS_BUF_ADD_ALLOC_CALLER();
217 if (SGetSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size) != ROK)
219 dgn.type = LRG_USTA_DGNVAL_MEM;
220 dgn.u.mem.region = rgCb[inst].rgInit.region;
221 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
222 /* Send an alarm to Layer Manager */
223 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
224 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
225 RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
229 /* zero out the allocated memory */
230 cmMemset((U8 *)*pData, 0x00, size);
234 } /* end of rgAllocSBuf */
238 * Fun: rgFreeSharableSBuf
240 * Desc: The argument to rgFreeSBuf() is a pointer to a block
241 * previously allocated by rgAllocSBuf() and size. It
242 * deallocates the memory.
246 * Notes: ccpu00117052 - MOD- changed the Data parameter from
247 * pointer to address of pointer so that
248 * the freed memory could be set to NULLP
253 Void rgFreeSharableSBuf
256 Data **data, /* address of pointer to data */
260 Void rgFreeSharableSBuf(inst,data, size)
262 Data **data; /* address of pointer to data */
263 Size size; /* size */
269 TRC2(rgFreeSharableBuf)
271 if ((data == NULLP) || (*data == NULLP) || (size == 0))
276 /* Deallocate buffer */
277 ret = SPutStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size, SS_SHARABLE_MEMORY);
288 } /* end of rgFreeSharableBuf */
296 * Desc: The argument to rgFreeSBuf() is a pointer to a block
297 * previously allocated by rgAllocSBuf() and size. It
298 * deallocates the memory.
302 * Notes: ccpu00117052 - MOD- changed the Data parameter from
303 * pointer to address of pointer so that
304 * the freed memory could be set to NULLP
312 Data **data, /* address of pointer to data */
316 Void rgFreeSBuf(inst,data, size)
318 Data **data; /* address of pointer to data */
319 Size size; /* size */
327 if ((data == NULLP) || (*data == NULLP) || (size == 0))
333 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
336 /* Deallocate buffer */
337 ret = SPutSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size);
341 RGLOGERROR(inst,ERRCLS_DEBUG, ERG029, (ErrVal) 0, "rgFreeSBuf failed.\n");
349 } /* end of rgFreeSBuf */
352 /***********************************************************
356 * Desc : Utility Function to Allocate message buffer.
362 * Notes: Caller doesnt need to raise the alarm in case of memory
363 * allocation gets failed.
367 **********************************************************/
372 Buffer **mBuf /* Message Buffer pointer be returned */
375 S16 rgGetMsg(inst,mBuf)
377 Buffer **mBuf; /* Message Buffer pointer be returned */
384 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
385 MS_BUF_ADD_ALLOC_CALLER();
387 ret = SGetMsg(RG_GET_MEM_REGION(rgCb[inst]), RG_GET_MEM_POOL(rgCb[inst]), mBuf);
391 /* Moving diagnostics structure to limited scope for optimization */
392 RgUstaDgn dgn; /* Alarm diagnostics structure */
394 rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
396 /* Send an alarm to Layer Manager */
397 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
398 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
399 RGLOGERROR(inst,ERRCLS_DEBUG, ERG030, 0, "Unable to Allocate Buffer");
405 } /* end of rgGetMsg */
408 /***********************************************************
410 * Func : rgFillDgnParams
412 * Desc : Utility Function to Fill Diagonostic params.
420 **********************************************************/
429 Void rgFillDgnParams(inst,dgn, dgnType)
436 TRC2(rgFillDgnParams)
440 case LRG_USTA_DGNVAL_MEM:
441 dgn->type = (U8) LRG_USTA_DGNVAL_MEM;
442 dgn->u.mem.region = rgCb[inst].rgInit.region;
443 dgn->u.mem.pool = rgCb[inst].rgInit.pool;
451 } /* end of rgFillDgnParams */
454 /***********************************************************
456 * Func : rgUpdtRguDedSts
458 * Desc : Utility Function to update rgu sap statistics for dedicated
469 **********************************************************/
475 U8 stsType, /* Statistics type to update */
476 RgRguDedDatReq *datReq /* DatReq pointer */
479 Void rgUpdtRguDedSts(inst,rguDlSap,stsType, datReq)
482 U8 stsType; /* Statistics type to update */
483 RgRguDedDatReq *datReq; /* DatReq pointer */
490 TRC2(rgUpdtRguDedSts)
495 case RG_RGU_SDU_RCVD:
496 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
498 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
499 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
501 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
503 rguDlSap->sapSts.numPduRcvd +=
504 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
510 case RG_RGU_SDU_DROP:
511 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
513 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
514 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
516 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
518 rguDlSap->sapSts.numPduRcvd +=
519 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
520 rguDlSap->sapSts.numPduDrop +=
521 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
530 } /* rgUpdtRguDedSts */
533 /***********************************************************
535 * Func : rgUpdtRguCmnSts
537 * Desc : Utility Function to update rgu sap statistics for common
548 **********************************************************/
554 U8 stsType /* Statistics type to update */
557 Void rgUpdtRguCmnSts(inst,rguDlSap,stsType)
560 U8 stsType; /* Statistics type to update */
563 TRC2(rgUpdtRguCmnSts)
569 case RG_RGU_SDU_RCVD:
570 rguDlSap->sapSts.numPduRcvd ++;
572 case RG_RGU_SDU_DROP:
573 rguDlSap->sapSts.numPduRcvd ++;
574 rguDlSap->sapSts.numPduDrop ++;
579 } /* rgUpdtRguCmnSts */
582 /***********************************************************
584 * Func : rgUpdtCellCnt
586 * Desc : Utility Function to update cell count. It gives number of active
593 * Notes: This function should be called only after cell is added/deleted
594 * from the globlal hashlist
598 **********************************************************/
606 Void rgUpdtCellCnt(inst,updtType)
616 rgCb[inst].genSts.numCellCfg++;
619 rgCb[inst].genSts.numCellCfg--;
626 } /* rgUpdtCellCnt */
629 /***********************************************************
633 * Desc : Utility Function to update ue count. It gives number of active
640 * Notes: This function should be called only after ue is added/deleted
641 * from the globlal hashlist
645 **********************************************************/
653 Void rgUpdtUeCnt (inst,updtType)
663 rgCb[inst].genSts.numUeCfg++;
666 rgCb[inst].genSts.numUeCfg--;
676 * Fun: rgAllocEventMem
678 * Desc: This function allocates event memory
680 * Ret: ROK - on success
681 * RFAILED - on failure
696 S16 rgAllocEventMem(inst,memPtr, memSize)
703 VOLATILE U32 startTime=0;
705 TRC2(rgAllocEventMem)
707 sMem.region = rgCb[inst].rgInit.region;
708 sMem.pool = rgCb[inst].rgInit.pool;
710 #if (ERRCLASS & ERRCLS_DEBUG)
713 RGLOGERROR(inst,ERRCLS_INT_PAR, ERG031, memSize,
714 "rgAllocEventMem(): memSize invalid\n");
717 #endif /* ERRCLASS & ERRCLS_DEBUG */
721 SStartTask(&startTime, PID_MACUTL_CMALLCEVT);
723 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
724 MS_BUF_ADD_ALLOC_CALLER();
726 #ifdef TFU_ALLOC_EVENT_NO_INIT
727 if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
729 if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
732 RLOG0(L_ERROR,"cmAllocEvnt Failed");
737 SStopTask(startTime, PID_MACUTL_CMALLCEVT);
740 } /* end of rgAllocEventMem*/
746 * Desc: This function allocates event memory
748 * Ret: ROK - on success
749 * RFAILED - on failure
765 S16 rgGetEventMem(inst,ptr, len, memCp)
775 #ifdef TFU_ALLOC_EVENT_NO_INIT
776 ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
778 ret = cmGetMem(memCp, len, (Ptr *)ptr);
781 } /* end of rgGetEventMem*/
783 /***********************************************************
785 * Func : rgGetPstToInst
787 * Desc : Utility Function to get the pst structure to post a message to
794 * Notes: This function should be called while sending a msg from
795 * MAC to a scheduler instance
799 **********************************************************/
808 Void rgGetPstToInst (pst, srcInst, dstInst)
814 TRC2(rgGetPstToInst);
816 pst->srcEnt = rgCb[srcInst].rgInit.ent;
817 pst->srcInst = rgCb[srcInst].rgInit.inst;
818 pst->srcProcId = rgCb[srcInst].rgInit.procId;
819 pst->region = rgCb[srcInst].rgInit.region;
820 pst->pool = rgCb[srcInst].rgInit.pool;
822 pst->dstProcId = rgCb[dstInst].rgInit.procId;
823 pst->dstEnt = rgCb[dstInst].rgInit.ent;
824 pst->dstInst = dstInst;
828 pst->route = RTESPEC;
831 } /* end of rgGetPstToInst */
833 /***********************************************************
835 * Func : RgSchMacLcgRegReq
837 * Desc : Utility Function to register the set of GBR LCG.
838 * Invoked at the time of LCG configuration/Reconfiguration at Schedular.
841 * - Fetch the ueCb using the crnti given in lcInfo
842 * - Store the if LCG is GBR or not.
847 * Notes: This function should be called at the time of LCG
848 * configuration/Reconfiguration at Schedular.
853 **********************************************************/
855 S16 RgSchMacLcgRegReq
858 RgInfLcgRegReq *lcgRegReq
861 S16 RgSchMacLcgRegReq (pst, lcgRegReq)
863 RgInfLcgRegReq *lcgRegReq;
867 RgCellCb *cell = NULLP;
870 TRC2(RgSchMacLcgRegReq);
872 RG_IS_INST_VALID(pst->dstInst);
873 inst = pst->dstInst - RG_INST_START;
874 cell = rgCb[inst].cell;
875 /* Fetch the cell and then the UE */
876 if((cell == NULLP) ||
877 (cell->cellId != lcgRegReq->cellId))
880 RLOG_ARG0(L_ERROR,DBG_CELLID,lcgRegReq->cellId,"Cell does not exist ");
884 if ((ue = rgDBMGetUeCb(cell, lcgRegReq->crnti)) == NULLP)
886 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
890 ue->ul.lcgArr[lcgRegReq->lcgId].isGbr = lcgRegReq->isGbr;
893 } /* end of RgSchMacLcgRegReq */
897 /***********************************************************
899 * Func : RgSchMacUlSpsResetReq
901 * Desc : Utility Function to reset SPS params for a UE
904 * - Fetch the ueCb using the crnti
905 * - reset implRelCnt and explRelCnt
912 **********************************************************/
914 S16 RgSchMacUlSpsResetReq
917 RgInfUlSpsReset *ulSpsResetInfo
920 S16 RgSchMacUlSpsResetReq (pst, lcInfo)
922 RgInfUlSpsReset *ulSpsResetInfo;
926 RgCellCb *cell = NULLP;
929 TRC2(RgSchMacUlSpsResetReq);
931 RG_IS_INST_VALID(pst->dstInst);
932 inst = pst->dstInst - RG_INST_START;
933 cell = rgCb[inst].cell;
934 /* Fetch the cell and then the UE */
936 (cell->cellId != ulSpsResetInfo->cellId))
939 RLOG_ARG0(L_ERROR, DBG_CELLID,ulSpsResetInfo->cellId,"Cell does not exist ");
943 if ((ue = rgDBMGetUeCb(cell, ulSpsResetInfo->crnti)) == NULLP)
945 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
946 ulSpsResetInfo->crnti);
950 ue->ul.implRelCntr = 0;
951 ue->ul.explRelCntr = 0;
954 } /* end of RgSchMacUlSpsResetReq */
959 /***********************************************************
961 * Func : RgSchMacSpsLcRegReq
963 * Desc : Utility Function to register the set of uplink SPS logical
964 * channels for a SPS UE.
965 * Invoked at the time of activation of a UE for UL-SPS.
966 * Whenever there is data on these LCs MAC shall inform scheduler
969 * - Fetch the ueCb using the crnti given in lcInfo
970 * - Store the sps-rnti and set the bits corresponding to the
971 * logical channel ids in ueUlCb->spsLcMask.
976 * Notes: This function should be called at the time UL SPS is activated
977 * for a UE at scheduler
982 **********************************************************/
984 S16 RgSchMacSpsLcRegReq
987 RgInfSpsLcInfo *lcInfo
990 S16 RgSchMacSpsLcRegReq (pst, lcInfo)
992 RgInfSpsLcInfo *lcInfo;
996 RgCellCb *cell= NULLP;
1000 TRC2(RgSchMacSpsLcRegReq);
1002 RG_IS_INST_VALID(pst->dstInst);
1003 inst = pst->dstInst - RG_INST_START;
1004 cell = rgCb[inst].cell;
1005 /* Fetch the cell and then the UE */
1006 if((cell == NULLP) ||
1007 (cell->cellId != lcInfo->cellId))
1010 RLOG_ARG0(L_ERROR,DBG_CELLID,lcInfo->cellId, "Cell does not exist ");
1014 if ((ue = rgDBMGetUeCb(cell, lcInfo->crnti)) == NULLP)
1016 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
1021 /* Store the sps-rnti and SPS LC information in the UE */
1022 ue->spsRnti = lcInfo->spsRnti;
1023 for (idx=0; idx < lcInfo->spsLcCnt; idx++)
1025 /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
1026 ue->ul.spsLcId[(lcInfo->spsLcId[idx])-1] = TRUE;
1028 ue->ul.implRelCnt = lcInfo->implRelCnt;
1029 ue->ul.explRelCnt = ue->ul.implRelCnt + 1; /*(lcInfo->implRelCnt * lcInfo->spsPrd);*/
1031 /* Insert the UE into SPS UE List */
1032 if (rgDBMInsSpsUeCb(cell, ue) == RFAILED)
1034 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1035 "Ue insertion into SPS list failed SPS CRNTI:%d", ue->spsRnti);
1040 } /* end of RgSchMacSpsLcRegReq */
1043 /***********************************************************
1045 * Func : RgSchMacSpsLcDeregReq
1047 * Desc : Utility Function to deregister the set of uplink SPS
1048 * logical channels for a UE.
1049 * Invoked at the time of release of UL-SPS for an activated UE.
1052 * - Fetch the ueCb using the crnti given
1053 * - Reset the bits corresponding to the logical channel ids in
1054 * ueUlCb->spsLcMask.
1059 * Notes: This function should be called at the time UL SPS is released
1060 * for a UE at scheduler
1065 **********************************************************/
1067 S16 RgSchMacSpsLcDeregReq
1074 S16 RgSchMacSpsLcDeregReq (pst, cellId, crnti)
1081 RgCellCb *cell = NULLP;
1084 TRC2(RgSchMacSpsLcDeregReq);
1086 RG_IS_INST_VALID(pst->dstInst);
1087 inst = pst->dstInst - RG_INST_START;
1088 cell = rgCb[inst].cell;
1089 /* Fetch the cell and then the UE */
1090 if((cell == NULLP) ||
1091 (cell->cellId != cellId))
1094 RLOG_ARG0(L_ERROR,DBG_CELLID,cellId, "Cell does not exist ");
1098 if ((ue = rgDBMGetUeCb(cell, crnti)) == NULLP)
1100 RLOG_ARG1(L_ERROR, DBG_CELLID,cellId,"CRNTI:%d Ue does not exist", crnti);
1104 /* No need to reset the SPS LC Ids as they will not be looked at*/
1106 /* Delete UE from the SPS UE List */
1107 rgDBMDelSpsUeCb(cell, ue);
1110 } /* end of RgSchMacSpsLcDeregReq */
1112 #endif /* LTEMAC_SPS */
1115 * @brief Function for handling CRNTI change request
1116 * received from scheduler to MAC.
1120 * Function : rgUtlHndlCrntiChng
1122 * - Delete old UE from the list.
1123 * - Update the new rnti and re-insert the UE in the list.
1126 * @param[in] Inst inst
1127 * @param[in] RgCellCb *cell,
1128 * @param[in] CmLteRnti rnti,
1129 * @param[in] CmLteRnti newRnti
1135 PRIVATE S16 rgUtlHndlCrntiChng
1143 PRIVATE S16 rgUtlHndlCrntiChng(inst,cell, rnti, newRnti)
1151 RgUeCb *newUe = NULLP;
1153 TRC3(rgUtlHndlCrntiChng)
1155 ue = rgDBMGetUeCb(cell, rnti);
1156 newUe = rgDBMGetUeCbFromRachLst(cell, newRnti);
1157 if ((ue == NULLP) || (newUe == NULLP))
1159 RLOG_ARG4(L_ERROR,DBG_CELLID,cell->cellId,
1160 "RNTI:%d Failed to get UECB[%lu:%lu] or NEW RNTI:%d",
1161 rnti, ((PTR)ue), ((PTR)newUe), newRnti);
1164 #ifdef XEON_SPECIFIC_CHANGES
1165 CM_LOG_DEBUG(CM_LOG_ID_MAC, "MAC:UE[%d] id changed to %d\n", rnti, newRnti);
1167 rgDBMDelUeCb(cell, ue);
1171 cmMemcpy((U8*)&(ue->contResId), (U8*)&(newUe->contResId),
1172 sizeof(newUe->contResId));
1173 /* Fix : syed MSG4 might be RETXing need to store the
1175 rgDHMFreeUe(inst,&ue->dl.hqEnt);
1176 ue->dl.hqEnt = newUe->dl.hqEnt;
1178 rgDBMInsUeCb(cell, ue);
1180 rgDBMDelUeCbFromRachLst(cell, newUe);
1181 rgFreeSBuf(inst,(Data **)&newUe, sizeof(*newUe));
1184 } /* end of rgUtlHndlCrntiChng */
1188 * @brief Function for handling UE release for SCELL
1189 * triggered from SCH to MAC.
1193 * Function : rgDelUeFrmAllSCell
1195 * - This Function should be invoked by PCell of UE
1196 * - Remove the UE context from SCELL corresponding to rnti.
1198 * @param[in] Inst *macInst,
1199 * @param[in] RgUeCb *ue
1200 * @return ROK is SUCCESS
1203 S16 rgDelUeFrmAllSCell
1209 S16 rgDelUeFrmAllSCell(cell, ue)
1214 Inst inst = cell->macInst - RG_INST_START;
1218 RgPrgUeSCellDelInfo ueSCellDelInfo;
1220 TRC2(rgDelUeFrmAllSCell)
1222 /* To Delete the SCells if exisits for that UE */
1223 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1225 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1227 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1229 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1230 ueSCellDelInfo.ueId = ue->ueId;
1231 ueSCellDelInfo.sCellId = ue->sCelInfo[idx].sCellId;
1233 /* Filling same ueId in newRnti so that SMAC will check if newRnti
1234 *and old UeId is same that means its a UeSCell delete request*/
1235 ueSCellDelInfo.newRnti = ue->ueId;
1237 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueSCellDelInfo);
1238 ue->sCelInfo[idx].isSCellAdded = FALSE;
1243 } /* rgDelUeFrmAllSCell */
1246 * @brief Function to validate AddSCellCfg.
1250 * Function : rgUtlVltdAddSCellCfg
1253 * @param[in] ueSCellCb secondary cell CB for validation
1254 * @param[in] cell cell control block
1255 * @param[in] inst instance number to fetch rgCb instance
1260 S16 rgUtlVltdAddSCellCfg
1262 RgPrgUeSCellCfgInfo *ueSCellCb,
1267 S16 rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst)
1268 RgPrgUeSCellCfgInfo *ueSCellCb;
1275 TRC3(rgUtlVltdAddSCellCfg)
1277 /* To Validate the CellID presence */
1278 if((cell == NULLP) ||
1279 (cell->cellId != ueSCellCb->cellId))
1281 RGDBGERRNEW(inst, (rgPBuf(inst),
1282 "[%d]Sec Cell does not exit %d\n",
1283 ueSCellCb->ueId, ueSCellCb->cellId));
1286 #ifdef TENB_MULT_CELL_SUPPRT
1287 if((ueSCellCb->rguDlSapId > rgCb[inst].numRguSaps) ||
1288 (ueSCellCb->rguUlSapId > rgCb[inst].numRguSaps))
1290 RGDBGERRNEW(inst,(rgPBuf(inst), "Invald Sap Id: DL %d UL %d for ueId %d failed\n",
1291 ueSCellCb->rguDlSapId,
1292 ueSCellCb->rguUlSapId,
1293 ueSCellCb->cellId));
1298 } /* rgUtlVltdAddSCellCfg */
1301 * @brief Function to build CrntiChangeReq and send to all SMACs.
1305 * Function : rgUtlSndCrntiChngReq2AllSMacs
1307 * - This Function should be invoked by PCell of UE
1308 * - It sends RgPrgPMacSMacUeSCellDelReq to all SMACs with newRnti sent
1309 * by SCH. SMAC will check if newRnti is not equal to old UeId then it
1310 * do only UeId change else it will delete the UeScell context
1312 * @param[in] cell Cell CB to get Ue control block
1313 * @param[in] rnti Ue Identifier used to fill in UeId Change req
1314 * @param[in] newRnti UE new identifier, to be used in UeId Change req
1319 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs
1326 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs(cell, rnti, newRnti)
1332 Inst inst = cell->macInst - RG_INST_START;
1335 RgPrgUeSCellDelInfo ueIdChngReq;
1339 TfuDelDatReqInfo delDatReq;
1342 TRC2(rgUtlSndCrntiChngReq2AllSMacs)
1344 /* use newRnti to get UeCb in PMac because rnti is already changed in PMac*/
1345 ue = rgDBMGetUeCb(cell, newRnti);
1348 RGDBGERRNEW(inst,(rgPBuf(inst),"[%d]RNTI:Failed to get ueCb \
1349 newRnti=%d\n", rnti, newRnti));
1352 /* For all added SCells, prepare and send ueIdChngReq */
1353 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1355 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1357 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1359 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1361 ueIdChngReq.ueId = rnti;
1362 ueIdChngReq.sCellId = ue->sCelInfo[idx].sCellId;
1364 /* Filling newRnti so that SMAC can check if old ueId and new UeId
1365 *(newRnti) is different then its a UeId change request from PMAC.
1366 * RgPrgPMacSMacUeSCellDelReq is being reused for UeId change req
1367 * from PMAC to SMAC*/
1368 ueIdChngReq.newRnti = newRnti;
1370 /* Re-using UeSCellDelReq API for UeId change*/
1371 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueIdChngReq);
1373 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1374 delDatReq.cellId = ueIdChngReq.sCellId;
1375 delDatReq.ueId = ueIdChngReq.ueId;
1376 rgLIMTfuDelDatReq(sCellInstIdx, &delDatReq);
1383 } /* rgUtlSndCrntiChngReq2AllSMacs */
1385 #endif /* LTE_ADV */
1388 * @brief Function for handling CRNTI Context release
1389 * triggered from SCH to MAC.
1393 * Function : rgUtlHndlCrntiRls
1395 * - Remove the UE context from MAC corresponding to rnti.
1398 * @param[in] RgCellCb *cell,
1399 * @param[in] CmLteRnti rnti
1403 PRIVATE Void rgUtlHndlCrntiRls
1406 RgInfRlsRnti *rlsRnti
1409 PRIVATE Void rgUtlHndlCrntiRls(cell, rlsRnti)
1414 Inst inst = cell->macInst - RG_INST_START;
1417 RgUeCb *spsUeCb = NULLP;
1420 TRC3(rgUtlHndlCrntiRls)
1422 if ((ue = rgDBMGetUeCb(cell, rlsRnti->rnti)) == NULLP)
1424 /* Check in RachLst */
1425 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1427 /* Delete Ue from the UE list */
1428 rgDBMDelUeCbFromRachLst(cell, ue);
1431 rgRAMFreeUeCb(inst,ue);
1435 RLOG_ARG1(L_WARNING,DBG_CELLID,cell->cellId,
1436 "RNTI:%d No ueCb found in RachLst",rlsRnti->rnti);
1442 if(FALSE == rlsRnti->isUeSCellDel)
1444 rgDelUeFrmAllSCell(cell, ue);
1446 #endif /* LTE_ADV */
1448 /* Delete Ue from the UE list */
1449 rgDBMDelUeCb(cell, ue);
1451 spsUeCb = rgDBMGetSpsUeCb (cell, ue->spsRnti);
1454 rgDBMDelSpsUeCb(cell, spsUeCb);
1459 rgCFGFreeUeCb(cell, ue);
1460 /* MS_REMOVE : syed Check in RachLst */
1462 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1464 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1465 "RNTI:%d STALE UE is still present", rlsRnti->rnti);
1471 } /* end of rgUtlHndlCrntiRls */
1474 * @brief Function for handling RaResp request received from scheduler to MAC.
1478 * Function : RgSchMacRlsRntiReq
1480 * This function shall be invoked whenever scheduler is done with the
1481 * allocations of random access responses for a subframe.
1482 * This shall invoke RAM to create ueCbs for all the rapIds allocated and
1483 * shall invoke MUX to create RAR PDUs for raRntis allocated.
1486 * @param[in] CmLteCellId cellId,
1487 * @param[in] CmLteTimingInfo timingInfo,
1488 * @param[in] RaRespInfo *rarInfo
1493 S16 RgSchMacRlsRntiReq
1496 RgInfRlsRnti *rlsRnti
1499 S16 RgSchMacRlsRntiReq(pst, rlsRnti)
1501 RgInfRlsRnti *rlsRnti;
1505 // RgInfUeDelInd ueDelInd;
1509 TfuDelDatReqInfo delDatReq;
1512 TRC3(RgSchMacRlsRntiReq)
1514 RG_IS_INST_VALID(pst->dstInst);
1515 macInst = pst->dstInst - RG_INST_START;
1516 cell = rgCb[macInst].cell;
1518 if(NULLP == rlsRnti)
1523 if((cell == NULLP) ||
1524 (cell->cellId != rlsRnti->cellId))
1527 RLOG_ARG1(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1528 "No cellCb found with cellId for RNTI:%d",
1532 /* Fix : syed Clearing UE context when SCH indicates to do so
1533 * UE DEL from CRG interface is now dummy. */
1534 if (rlsRnti->ueIdChng)
1536 /* Fix : syed ueId change as part of reestablishment.
1537 * Now SCH to trigger this. CRG ueRecfg for ueId change
1539 if (rgUtlHndlCrntiChng(macInst,cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1541 RLOG_ARG2(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1542 "CRNTI change failed for RNTI:%d new RNTI:%d",
1543 rlsRnti->rnti,rlsRnti->newRnti);
1548 /*PMAC_Reest: Prepare CrntiChngReq and then send to all SMACs to change
1551 if(rgUtlSndCrntiChngReq2AllSMacs(cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1553 /* TODO: do we need to send DelInd to SCH in failure case*/
1558 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1559 delDatReq.cellId = cell->cellId;
1560 delDatReq.ueId = rlsRnti->rnti;
1561 rgLIMTfuDelDatReq(macInst, &delDatReq);
1566 rgUtlHndlCrntiRls(cell, rlsRnti);
1568 /* Fix : syed Send delete confirmation to SCH */
1569 /* Send RgMacSchUeDelInd to SCH only if it is Rnti release to PMAC.
1570 * Basically dont send DelInd to SCH incase of Ue SCell Del*/
1572 if(FALSE == rlsRnti->isUeSCellDel)
1575 //TODO: commented for compilation without SCH
1577 ueDelInd.cellSapId = cell->schInstMap.cellSapId;
1578 ueDelInd.cellId = rlsRnti->cellId;
1579 ueDelInd.rnti = rlsRnti->rnti;
1580 rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
1581 RgMacSchUeDel(&schPst, &ueDelInd);
1586 } /* end of RgSchMacRlsRntiReq */
1595 Bool RgUtlIsTbMuxed()
1600 SFndLenMsg(tb->macHdr, &len);
1601 return (len?TRUE : FALSE);
1605 /**********************************************************************
1608 **********************************************************************/