1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /************************************************************************
25 Desc: C source code for Entry point fucntions
29 **********************************************************************/
32 @brief This file implements utility functions for LTE MAC
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_MODULE_ID=4096;
37 static int RLOG_FILE_ID=179;
39 /* header include files (.h) */
40 #include "envopt.h" /* environment options */
41 #include "envdep.h" /* environment dependent */
42 #include "envind.h" /* environment independent */
44 #include "gen.h" /* general */
45 #include "ssi.h" /* system services */
46 #include "cm_tkns.h" /* Common Token Defines */
47 #include "cm_llist.h" /* Common Link List Defines */
48 #include "cm_hash.h" /* Common Hash List Defines */
49 #include "cm_mblk.h" /* common memory link list library */
50 #include "cm_lte.h" /* Common LTE */
52 #include "rg_env.h" /* MAC Environment Defines */
53 #include "crg.h" /* CRG Interface defines */
54 #include "rgu.h" /* RGU Interface defines */
55 #include "tfu.h" /* TFU Interface defines */
56 #include "rg_sch_inf.h" /* RGR Interface defines */
57 #include "lrg.h" /* LRG Interface defines */
59 #include "rg_prg.h" /* PRG(MAC-MAC) Interface includes */
60 #include "rg.h" /* MAC defines */
61 #include "rg_err.h" /* MAC error defines */
63 /* header/extern include files (.x) */
64 #include "gen.x" /* general */
65 #include "ssi.x" /* system services */
66 #include "cm5.x" /* Timer */
67 #include "cm_tkns.x" /* Common Token Definitions */
68 #include "cm_llist.x" /* Common Link List Definitions */
69 #include "cm_lib.x" /* Common Library Definitions */
70 #include "cm_hash.x" /* Common Hash List Definitions */
71 #include "cm_mblk.x" /* common memory link list library */
72 #include "cm_lte.x" /* Common LTE */
74 #include "crg.x" /* CRG Interface includes */
75 #include "rgu.x" /* RGU Interface includes */
76 #include "tfu.x" /* TFU Interface includes */
77 #include "rg_sch_inf.x" /* RGR Interface includes */
78 #include "lrg.x" /* LRG Interface includes */
79 #include "rg_prg.x" /* PRG(MAC-MAC) Interface includes */
81 #include "rg.x" /* MAC includes */
84 #define RG_NON_MIMO_IDX 0
90 /* forward references */
91 PRIVATE S16 rgUtlHndlCrntiChng ARGS((
97 PRIVATE Void rgUtlHndlCrntiRls ARGS((
102 PUBLIC S16 rgDelUeFrmAllSCell ARGS((
108 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs ARGS((
114 /***********************************************************
116 * Func : rgAllocShrablSBuf
118 * Desc : Utility Function to Allocate static buffer which is
119 * sharable among different layers if YYYY flag is enabled.
120 * else it allocates from normal static region
121 * Memory allocated is assumed contiguous.
127 * Notes: Caller doesnt need to raise the alarm in case of memory
128 * allocation gets failed.
132 **********************************************************/
134 PUBLIC S16 rgAllocShrablSBuf
137 Data **pData, /* Pointer of the data to be returned */
141 PUBLIC S16 rgAllocShrablSBuf(inst,pData, size)
143 Data **pData; /* Pointer of the data to be returned */
144 Size size; /* size */
147 RgUstaDgn dgn; /* Alarm diagnostics structure */
149 TRC2(rgAllocShrablSBuf)
151 /* Initialize the param to NULLP */
159 /* allocate buffer */
160 if (SGetStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size, 0) != ROK)
162 dgn.type = LRG_USTA_DGNVAL_MEM;
163 dgn.u.mem.region = rgCb[inst].rgInit.region;
164 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
165 /* Send an alarm to Layer Manager */
166 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
167 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
168 RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
173 RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%ld)), Data (0x%p))\n",
174 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
176 RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%d)), Data (0x%p))\n",
177 rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
180 /* zero out the allocated memory */
181 cmMemset((U8 *)*pData, 0x00, size);
185 } /* end of rgAllocSBuf */
188 /***********************************************************
192 * Desc : Utility Function to Allocate static buffer.
193 * Memory allocated is assumed contiguous.
199 * Notes: Caller doesnt need to raise the alarm in case of memory
200 * allocation gets failed.
204 **********************************************************/
206 PUBLIC S16 rgAllocSBuf
209 Data **pData, /* Pointer of the data to be returned */
213 PUBLIC S16 rgAllocSBuf(inst,pData, size)
215 Data **pData; /* Pointer of the data to be returned */
216 Size size; /* size */
219 RgUstaDgn dgn; /* Alarm diagnostics structure */
223 /* Initialize the param to NULLP */
231 /* allocate buffer */
232 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
233 MS_BUF_ADD_ALLOC_CALLER();
235 if (SGetSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size) != ROK)
237 dgn.type = LRG_USTA_DGNVAL_MEM;
238 dgn.u.mem.region = rgCb[inst].rgInit.region;
239 dgn.u.mem.pool = rgCb[inst].rgInit.pool;
240 /* Send an alarm to Layer Manager */
241 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
242 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
243 RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
247 /* zero out the allocated memory */
248 cmMemset((U8 *)*pData, 0x00, size);
252 } /* end of rgAllocSBuf */
256 * Fun: rgFreeSharableSBuf
258 * Desc: The argument to rgFreeSBuf() is a pointer to a block
259 * previously allocated by rgAllocSBuf() and size. It
260 * deallocates the memory.
264 * Notes: ccpu00117052 - MOD- changed the Data parameter from
265 * pointer to address of pointer so that
266 * the freed memory could be set to NULLP
271 PUBLIC Void rgFreeSharableSBuf
274 Data **data, /* address of pointer to data */
278 PUBLIC Void rgFreeSharableSBuf(inst,data, size)
280 Data **data; /* address of pointer to data */
281 Size size; /* size */
287 TRC2(rgFreeSharableBuf)
289 if ((data == NULLP) || (*data == NULLP) || (size == 0))
294 /* Deallocate buffer */
295 ret = SPutStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size, SS_SHARABLE_MEMORY);
306 } /* end of rgFreeSharableBuf */
314 * Desc: The argument to rgFreeSBuf() is a pointer to a block
315 * previously allocated by rgAllocSBuf() and size. It
316 * deallocates the memory.
320 * Notes: ccpu00117052 - MOD- changed the Data parameter from
321 * pointer to address of pointer so that
322 * the freed memory could be set to NULLP
327 PUBLIC Void rgFreeSBuf
330 Data **data, /* address of pointer to data */
334 PUBLIC Void rgFreeSBuf(inst,data, size)
336 Data **data; /* address of pointer to data */
337 Size size; /* size */
345 if ((data == NULLP) || (*data == NULLP) || (size == 0))
351 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
354 /* Deallocate buffer */
355 ret = SPutSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size);
359 RGLOGERROR(inst,ERRCLS_DEBUG, ERG029, (ErrVal) 0, "rgFreeSBuf failed.\n");
367 } /* end of rgFreeSBuf */
370 /***********************************************************
374 * Desc : Utility Function to Allocate message buffer.
380 * Notes: Caller doesnt need to raise the alarm in case of memory
381 * allocation gets failed.
385 **********************************************************/
390 Buffer **mBuf /* Message Buffer pointer be returned */
393 PUBLIC S16 rgGetMsg(inst,mBuf)
395 Buffer **mBuf; /* Message Buffer pointer be returned */
402 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
403 MS_BUF_ADD_ALLOC_CALLER();
405 ret = SGetMsg(RG_GET_MEM_REGION(rgCb[inst]), RG_GET_MEM_POOL(rgCb[inst]), mBuf);
409 /* Moving diagnostics structure to limited scope for optimization */
410 RgUstaDgn dgn; /* Alarm diagnostics structure */
412 rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
414 /* Send an alarm to Layer Manager */
415 rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
416 LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
417 RGLOGERROR(inst,ERRCLS_DEBUG, ERG030, 0, "Unable to Allocate Buffer");
423 } /* end of rgGetMsg */
426 /***********************************************************
428 * Func : rgFillDgnParams
430 * Desc : Utility Function to Fill Diagonostic params.
438 **********************************************************/
440 PUBLIC Void rgFillDgnParams
447 PUBLIC Void rgFillDgnParams(inst,dgn, dgnType)
454 TRC2(rgFillDgnParams)
458 case LRG_USTA_DGNVAL_MEM:
459 dgn->type = (U8) LRG_USTA_DGNVAL_MEM;
460 dgn->u.mem.region = rgCb[inst].rgInit.region;
461 dgn->u.mem.pool = rgCb[inst].rgInit.pool;
469 } /* end of rgFillDgnParams */
472 /***********************************************************
474 * Func : rgUpdtRguDedSts
476 * Desc : Utility Function to update rgu sap statistics for dedicated
487 **********************************************************/
489 PUBLIC Void rgUpdtRguDedSts
493 U8 stsType, /* Statistics type to update */
494 RgRguDedDatReq *datReq /* DatReq pointer */
497 PUBLIC Void rgUpdtRguDedSts(inst,rguDlSap,stsType, datReq)
500 U8 stsType; /* Statistics type to update */
501 RgRguDedDatReq *datReq; /* DatReq pointer */
508 TRC2(rgUpdtRguDedSts)
513 case RG_RGU_SDU_RCVD:
514 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
516 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
517 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
519 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
521 rguDlSap->sapSts.numPduRcvd +=
522 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
528 case RG_RGU_SDU_DROP:
529 for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
531 RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
532 for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++)
534 for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++)
536 rguDlSap->sapSts.numPduRcvd +=
537 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
538 rguDlSap->sapSts.numPduDrop +=
539 datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
548 } /* rgUpdtRguDedSts */
551 /***********************************************************
553 * Func : rgUpdtRguCmnSts
555 * Desc : Utility Function to update rgu sap statistics for common
566 **********************************************************/
568 PUBLIC Void rgUpdtRguCmnSts
572 U8 stsType /* Statistics type to update */
575 PUBLIC Void rgUpdtRguCmnSts(inst,rguDlSap,stsType)
578 U8 stsType; /* Statistics type to update */
581 TRC2(rgUpdtRguCmnSts)
587 case RG_RGU_SDU_RCVD:
588 rguDlSap->sapSts.numPduRcvd ++;
590 case RG_RGU_SDU_DROP:
591 rguDlSap->sapSts.numPduRcvd ++;
592 rguDlSap->sapSts.numPduDrop ++;
597 } /* rgUpdtRguCmnSts */
600 /***********************************************************
602 * Func : rgUpdtCellCnt
604 * Desc : Utility Function to update cell count. It gives number of active
611 * Notes: This function should be called only after cell is added/deleted
612 * from the globlal hashlist
616 **********************************************************/
618 PUBLIC Void rgUpdtCellCnt
624 PUBLIC Void rgUpdtCellCnt(inst,updtType)
634 rgCb[inst].genSts.numCellCfg++;
637 rgCb[inst].genSts.numCellCfg--;
644 } /* rgUpdtCellCnt */
647 /***********************************************************
651 * Desc : Utility Function to update ue count. It gives number of active
658 * Notes: This function should be called only after ue is added/deleted
659 * from the globlal hashlist
663 **********************************************************/
665 PUBLIC Void rgUpdtUeCnt
671 PUBLIC Void rgUpdtUeCnt (inst,updtType)
681 rgCb[inst].genSts.numUeCfg++;
684 rgCb[inst].genSts.numUeCfg--;
694 * Fun: rgAllocEventMem
696 * Desc: This function allocates event memory
698 * Ret: ROK - on success
699 * RFAILED - on failure
707 PUBLIC S16 rgAllocEventMem
714 PUBLIC S16 rgAllocEventMem(inst,memPtr, memSize)
721 VOLATILE U32 startTime=0;
723 TRC2(rgAllocEventMem)
725 sMem.region = rgCb[inst].rgInit.region;
726 sMem.pool = rgCb[inst].rgInit.pool;
728 #if (ERRCLASS & ERRCLS_DEBUG)
731 RGLOGERROR(inst,ERRCLS_INT_PAR, ERG031, memSize,
732 "rgAllocEventMem(): memSize invalid\n");
735 #endif /* ERRCLASS & ERRCLS_DEBUG */
739 SStartTask(&startTime, PID_MACUTL_CMALLCEVT);
741 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
742 MS_BUF_ADD_ALLOC_CALLER();
744 #ifdef TFU_ALLOC_EVENT_NO_INIT
745 if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
747 if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
750 RLOG0(L_ERROR,"cmAllocEvnt Failed");
755 SStopTask(startTime, PID_MACUTL_CMALLCEVT);
758 } /* end of rgAllocEventMem*/
764 * Desc: This function allocates event memory
766 * Ret: ROK - on success
767 * RFAILED - on failure
775 PUBLIC S16 rgGetEventMem
783 PUBLIC S16 rgGetEventMem(inst,ptr, len, memCp)
793 #ifdef TFU_ALLOC_EVENT_NO_INIT
794 ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
796 ret = cmGetMem(memCp, len, (Ptr *)ptr);
799 } /* end of rgGetEventMem*/
801 /***********************************************************
803 * Func : rgGetPstToInst
805 * Desc : Utility Function to get the pst structure to post a message to
812 * Notes: This function should be called while sending a msg from
813 * MAC to a scheduler instance
817 **********************************************************/
819 PUBLIC Void rgGetPstToInst
826 PUBLIC Void rgGetPstToInst (pst, srcInst, dstInst)
832 TRC2(rgGetPstToInst);
834 pst->srcEnt = rgCb[srcInst].rgInit.ent;
835 pst->srcInst = rgCb[srcInst].rgInit.inst;
836 pst->srcProcId = rgCb[srcInst].rgInit.procId;
837 pst->region = rgCb[srcInst].rgInit.region;
838 pst->pool = rgCb[srcInst].rgInit.pool;
840 pst->dstProcId = rgCb[dstInst].rgInit.procId;
841 pst->dstEnt = rgCb[dstInst].rgInit.ent;
842 pst->dstInst = dstInst;
846 pst->route = RTESPEC;
849 } /* end of rgGetPstToInst */
851 /***********************************************************
853 * Func : RgSchMacLcgRegReq
855 * Desc : Utility Function to register the set of GBR LCG.
856 * Invoked at the time of LCG configuration/Reconfiguration at Schedular.
859 * - Fetch the ueCb using the crnti given in lcInfo
860 * - Store the if LCG is GBR or not.
865 * Notes: This function should be called at the time of LCG
866 * configuration/Reconfiguration at Schedular.
871 **********************************************************/
873 PUBLIC S16 RgSchMacLcgRegReq
876 RgInfLcgRegReq *lcgRegReq
879 PUBLIC S16 RgSchMacLcgRegReq (pst, lcgRegReq)
881 RgInfLcgRegReq *lcgRegReq;
885 RgCellCb *cell = NULLP;
888 TRC2(RgSchMacLcgRegReq);
890 RG_IS_INST_VALID(pst->dstInst);
891 inst = pst->dstInst - RG_INST_START;
892 cell = rgCb[inst].cell;
893 /* Fetch the cell and then the UE */
894 if((cell == NULLP) ||
895 (cell->cellId != lcgRegReq->cellId))
898 RLOG_ARG0(L_ERROR,DBG_CELLID,lcgRegReq->cellId,"Cell does not exist ");
902 if ((ue = rgDBMGetUeCb(cell, lcgRegReq->crnti)) == NULLP)
904 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
908 ue->ul.lcgArr[lcgRegReq->lcgId].isGbr = lcgRegReq->isGbr;
911 } /* end of RgSchMacLcgRegReq */
915 /***********************************************************
917 * Func : RgSchMacUlSpsResetReq
919 * Desc : Utility Function to reset SPS params for a UE
922 * - Fetch the ueCb using the crnti
923 * - reset implRelCnt and explRelCnt
930 **********************************************************/
932 PUBLIC S16 RgSchMacUlSpsResetReq
935 RgInfUlSpsReset *ulSpsResetInfo
938 PUBLIC S16 RgSchMacUlSpsResetReq (pst, lcInfo)
940 RgInfUlSpsReset *ulSpsResetInfo;
944 RgCellCb *cell = NULLP;
947 TRC2(RgSchMacUlSpsResetReq);
949 RG_IS_INST_VALID(pst->dstInst);
950 inst = pst->dstInst - RG_INST_START;
951 cell = rgCb[inst].cell;
952 /* Fetch the cell and then the UE */
954 (cell->cellId != ulSpsResetInfo->cellId))
957 RLOG_ARG0(L_ERROR, DBG_CELLID,ulSpsResetInfo->cellId,"Cell does not exist ");
961 if ((ue = rgDBMGetUeCb(cell, ulSpsResetInfo->crnti)) == NULLP)
963 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
964 ulSpsResetInfo->crnti);
968 ue->ul.implRelCntr = 0;
969 ue->ul.explRelCntr = 0;
972 } /* end of RgSchMacUlSpsResetReq */
977 /***********************************************************
979 * Func : RgSchMacSpsLcRegReq
981 * Desc : Utility Function to register the set of uplink SPS logical
982 * channels for a SPS UE.
983 * Invoked at the time of activation of a UE for UL-SPS.
984 * Whenever there is data on these LCs MAC shall inform scheduler
987 * - Fetch the ueCb using the crnti given in lcInfo
988 * - Store the sps-rnti and set the bits corresponding to the
989 * logical channel ids in ueUlCb->spsLcMask.
994 * Notes: This function should be called at the time UL SPS is activated
995 * for a UE at scheduler
1000 **********************************************************/
1002 PUBLIC S16 RgSchMacSpsLcRegReq
1005 RgInfSpsLcInfo *lcInfo
1008 PUBLIC S16 RgSchMacSpsLcRegReq (pst, lcInfo)
1010 RgInfSpsLcInfo *lcInfo;
1014 RgCellCb *cell= NULLP;
1018 TRC2(RgSchMacSpsLcRegReq);
1020 RG_IS_INST_VALID(pst->dstInst);
1021 inst = pst->dstInst - RG_INST_START;
1022 cell = rgCb[inst].cell;
1023 /* Fetch the cell and then the UE */
1024 if((cell == NULLP) ||
1025 (cell->cellId != lcInfo->cellId))
1028 RLOG_ARG0(L_ERROR,DBG_CELLID,lcInfo->cellId, "Cell does not exist ");
1032 if ((ue = rgDBMGetUeCb(cell, lcInfo->crnti)) == NULLP)
1034 RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist",
1039 /* Store the sps-rnti and SPS LC information in the UE */
1040 ue->spsRnti = lcInfo->spsRnti;
1041 for (idx=0; idx < lcInfo->spsLcCnt; idx++)
1043 /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
1044 ue->ul.spsLcId[(lcInfo->spsLcId[idx])-1] = TRUE;
1046 ue->ul.implRelCnt = lcInfo->implRelCnt;
1047 ue->ul.explRelCnt = ue->ul.implRelCnt + 1; /*(lcInfo->implRelCnt * lcInfo->spsPrd);*/
1049 /* Insert the UE into SPS UE List */
1050 if (rgDBMInsSpsUeCb(cell, ue) == RFAILED)
1052 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1053 "Ue insertion into SPS list failed SPS CRNTI:%d", ue->spsRnti);
1058 } /* end of RgSchMacSpsLcRegReq */
1061 /***********************************************************
1063 * Func : RgSchMacSpsLcDeregReq
1065 * Desc : Utility Function to deregister the set of uplink SPS
1066 * logical channels for a UE.
1067 * Invoked at the time of release of UL-SPS for an activated UE.
1070 * - Fetch the ueCb using the crnti given
1071 * - Reset the bits corresponding to the logical channel ids in
1072 * ueUlCb->spsLcMask.
1077 * Notes: This function should be called at the time UL SPS is released
1078 * for a UE at scheduler
1083 **********************************************************/
1085 PUBLIC S16 RgSchMacSpsLcDeregReq
1092 PUBLIC S16 RgSchMacSpsLcDeregReq (pst, cellId, crnti)
1099 RgCellCb *cell = NULLP;
1102 TRC2(RgSchMacSpsLcDeregReq);
1104 RG_IS_INST_VALID(pst->dstInst);
1105 inst = pst->dstInst - RG_INST_START;
1106 cell = rgCb[inst].cell;
1107 /* Fetch the cell and then the UE */
1108 if((cell == NULLP) ||
1109 (cell->cellId != cellId))
1112 RLOG_ARG0(L_ERROR,DBG_CELLID,cellId, "Cell does not exist ");
1116 if ((ue = rgDBMGetUeCb(cell, crnti)) == NULLP)
1118 RLOG_ARG1(L_ERROR, DBG_CELLID,cellId,"CRNTI:%d Ue does not exist", crnti);
1122 /* No need to reset the SPS LC Ids as they will not be looked at*/
1124 /* Delete UE from the SPS UE List */
1125 rgDBMDelSpsUeCb(cell, ue);
1128 } /* end of RgSchMacSpsLcDeregReq */
1130 #endif /* LTEMAC_SPS */
1133 * @brief Function for handling CRNTI change request
1134 * received from scheduler to MAC.
1138 * Function : rgUtlHndlCrntiChng
1140 * - Delete old UE from the list.
1141 * - Update the new rnti and re-insert the UE in the list.
1144 * @param[in] Inst inst
1145 * @param[in] RgCellCb *cell,
1146 * @param[in] CmLteRnti rnti,
1147 * @param[in] CmLteRnti newRnti
1153 PRIVATE S16 rgUtlHndlCrntiChng
1161 PRIVATE S16 rgUtlHndlCrntiChng(inst,cell, rnti, newRnti)
1169 RgUeCb *newUe = NULLP;
1171 TRC3(rgUtlHndlCrntiChng)
1173 ue = rgDBMGetUeCb(cell, rnti);
1174 newUe = rgDBMGetUeCbFromRachLst(cell, newRnti);
1175 if ((ue == NULLP) || (newUe == NULLP))
1177 RLOG_ARG4(L_ERROR,DBG_CELLID,cell->cellId,
1178 "RNTI:%d Failed to get UECB[%lu:%lu] or NEW RNTI:%d",
1179 rnti, ((PTR)ue), ((PTR)newUe), newRnti);
1182 #ifdef XEON_SPECIFIC_CHANGES
1183 CM_LOG_DEBUG(CM_LOG_ID_MAC, "MAC:UE[%d] id changed to %d\n", rnti, newRnti);
1185 rgDBMDelUeCb(cell, ue);
1189 cmMemcpy((U8*)&(ue->contResId), (U8*)&(newUe->contResId),
1190 sizeof(newUe->contResId));
1191 /* Fix : syed MSG4 might be RETXing need to store the
1193 rgDHMFreeUe(inst,&ue->dl.hqEnt);
1194 ue->dl.hqEnt = newUe->dl.hqEnt;
1196 rgDBMInsUeCb(cell, ue);
1198 rgDBMDelUeCbFromRachLst(cell, newUe);
1199 rgFreeSBuf(inst,(Data **)&newUe, sizeof(*newUe));
1202 } /* end of rgUtlHndlCrntiChng */
1206 * @brief Function for handling UE release for SCELL
1207 * triggered from SCH to MAC.
1211 * Function : rgDelUeFrmAllSCell
1213 * - This Function should be invoked by PCell of UE
1214 * - Remove the UE context from SCELL corresponding to rnti.
1216 * @param[in] Inst *macInst,
1217 * @param[in] RgUeCb *ue
1218 * @return ROK is SUCCESS
1221 PUBLIC S16 rgDelUeFrmAllSCell
1227 PUBLIC S16 rgDelUeFrmAllSCell(cell, ue)
1232 Inst inst = cell->macInst - RG_INST_START;
1236 RgPrgUeSCellDelInfo ueSCellDelInfo;
1238 TRC2(rgDelUeFrmAllSCell)
1240 /* To Delete the SCells if exisits for that UE */
1241 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1243 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1245 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1247 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1248 ueSCellDelInfo.ueId = ue->ueId;
1249 ueSCellDelInfo.sCellId = ue->sCelInfo[idx].sCellId;
1251 /* Filling same ueId in newRnti so that SMAC will check if newRnti
1252 *and old UeId is same that means its a UeSCell delete request*/
1253 ueSCellDelInfo.newRnti = ue->ueId;
1255 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueSCellDelInfo);
1256 ue->sCelInfo[idx].isSCellAdded = FALSE;
1261 } /* rgDelUeFrmAllSCell */
1264 * @brief Function to validate AddSCellCfg.
1268 * Function : rgUtlVltdAddSCellCfg
1271 * @param[in] ueSCellCb secondary cell CB for validation
1272 * @param[in] cell cell control block
1273 * @param[in] inst instance number to fetch rgCb instance
1278 PUBLIC S16 rgUtlVltdAddSCellCfg
1280 RgPrgUeSCellCfgInfo *ueSCellCb,
1285 PUBLIC S16 rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst)
1286 RgPrgUeSCellCfgInfo *ueSCellCb;
1293 TRC3(rgUtlVltdAddSCellCfg)
1295 /* To Validate the CellID presence */
1296 if((cell == NULLP) ||
1297 (cell->cellId != ueSCellCb->cellId))
1299 RGDBGERRNEW(inst, (rgPBuf(inst),
1300 "[%d]Sec Cell does not exit %d\n",
1301 ueSCellCb->ueId, ueSCellCb->cellId));
1304 #ifdef TENB_MULT_CELL_SUPPRT
1305 if((ueSCellCb->rguDlSapId > rgCb[inst].numRguSaps) ||
1306 (ueSCellCb->rguUlSapId > rgCb[inst].numRguSaps))
1308 RGDBGERRNEW(inst,(rgPBuf(inst), "Invald Sap Id: DL %d UL %d for ueId %d failed\n",
1309 ueSCellCb->rguDlSapId,
1310 ueSCellCb->rguUlSapId,
1311 ueSCellCb->cellId));
1316 } /* rgUtlVltdAddSCellCfg */
1319 * @brief Function to build CrntiChangeReq and send to all SMACs.
1323 * Function : rgUtlSndCrntiChngReq2AllSMacs
1325 * - This Function should be invoked by PCell of UE
1326 * - It sends RgPrgPMacSMacUeSCellDelReq to all SMACs with newRnti sent
1327 * by SCH. SMAC will check if newRnti is not equal to old UeId then it
1328 * do only UeId change else it will delete the UeScell context
1330 * @param[in] cell Cell CB to get Ue control block
1331 * @param[in] rnti Ue Identifier used to fill in UeId Change req
1332 * @param[in] newRnti UE new identifier, to be used in UeId Change req
1337 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs
1344 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs(cell, rnti, newRnti)
1350 Inst inst = cell->macInst - RG_INST_START;
1353 RgPrgUeSCellDelInfo ueIdChngReq;
1357 TfuDelDatReqInfo delDatReq;
1360 TRC2(rgUtlSndCrntiChngReq2AllSMacs)
1362 /* use newRnti to get UeCb in PMac because rnti is already changed in PMac*/
1363 ue = rgDBMGetUeCb(cell, newRnti);
1366 RGDBGERRNEW(inst,(rgPBuf(inst),"[%d]RNTI:Failed to get ueCb \
1367 newRnti=%d\n", rnti, newRnti));
1370 /* For all added SCells, prepare and send ueIdChngReq */
1371 for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1373 if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1375 sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1377 rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1379 ueIdChngReq.ueId = rnti;
1380 ueIdChngReq.sCellId = ue->sCelInfo[idx].sCellId;
1382 /* Filling newRnti so that SMAC can check if old ueId and new UeId
1383 *(newRnti) is different then its a UeId change request from PMAC.
1384 * RgPrgPMacSMacUeSCellDelReq is being reused for UeId change req
1385 * from PMAC to SMAC*/
1386 ueIdChngReq.newRnti = newRnti;
1388 /* Re-using UeSCellDelReq API for UeId change*/
1389 RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueIdChngReq);
1391 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1392 delDatReq.cellId = ueIdChngReq.sCellId;
1393 delDatReq.ueId = ueIdChngReq.ueId;
1394 rgLIMTfuDelDatReq(sCellInstIdx, &delDatReq);
1401 } /* rgUtlSndCrntiChngReq2AllSMacs */
1403 #endif /* LTE_ADV */
1406 * @brief Function for handling CRNTI Context release
1407 * triggered from SCH to MAC.
1411 * Function : rgUtlHndlCrntiRls
1413 * - Remove the UE context from MAC corresponding to rnti.
1416 * @param[in] RgCellCb *cell,
1417 * @param[in] CmLteRnti rnti
1421 PRIVATE Void rgUtlHndlCrntiRls
1424 RgInfRlsRnti *rlsRnti
1427 PRIVATE Void rgUtlHndlCrntiRls(cell, rlsRnti)
1432 Inst inst = cell->macInst - RG_INST_START;
1435 RgUeCb *spsUeCb = NULLP;
1438 TRC3(rgUtlHndlCrntiRls)
1440 if ((ue = rgDBMGetUeCb(cell, rlsRnti->rnti)) == NULLP)
1442 /* Check in RachLst */
1443 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1445 /* Delete Ue from the UE list */
1446 rgDBMDelUeCbFromRachLst(cell, ue);
1449 rgRAMFreeUeCb(inst,ue);
1453 RLOG_ARG1(L_WARNING,DBG_CELLID,cell->cellId,
1454 "RNTI:%d No ueCb found in RachLst",rlsRnti->rnti);
1460 if(FALSE == rlsRnti->isUeSCellDel)
1462 rgDelUeFrmAllSCell(cell, ue);
1464 #endif /* LTE_ADV */
1466 /* Delete Ue from the UE list */
1467 rgDBMDelUeCb(cell, ue);
1469 spsUeCb = rgDBMGetSpsUeCb (cell, ue->spsRnti);
1472 rgDBMDelSpsUeCb(cell, spsUeCb);
1477 rgCFGFreeUeCb(cell, ue);
1478 /* MS_REMOVE : syed Check in RachLst */
1480 if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1482 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1483 "RNTI:%d STALE UE is still present", rlsRnti->rnti);
1489 } /* end of rgUtlHndlCrntiRls */
1492 * @brief Function for handling RaResp request received from scheduler to MAC.
1496 * Function : RgSchMacRlsRntiReq
1498 * This function shall be invoked whenever scheduler is done with the
1499 * allocations of random access responses for a subframe.
1500 * This shall invoke RAM to create ueCbs for all the rapIds allocated and
1501 * shall invoke MUX to create RAR PDUs for raRntis allocated.
1504 * @param[in] CmLteCellId cellId,
1505 * @param[in] CmLteTimingInfo timingInfo,
1506 * @param[in] RaRespInfo *rarInfo
1511 PUBLIC S16 RgSchMacRlsRntiReq
1514 RgInfRlsRnti *rlsRnti
1517 PUBLIC S16 RgSchMacRlsRntiReq(pst, rlsRnti)
1519 RgInfRlsRnti *rlsRnti;
1523 // RgInfUeDelInd ueDelInd;
1527 TfuDelDatReqInfo delDatReq;
1530 TRC3(RgSchMacRlsRntiReq)
1532 RG_IS_INST_VALID(pst->dstInst);
1533 macInst = pst->dstInst - RG_INST_START;
1534 cell = rgCb[macInst].cell;
1536 if(NULLP == rlsRnti)
1541 if((cell == NULLP) ||
1542 (cell->cellId != rlsRnti->cellId))
1545 RLOG_ARG1(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1546 "No cellCb found with cellId for RNTI:%d",
1550 /* Fix : syed Clearing UE context when SCH indicates to do so
1551 * UE DEL from CRG interface is now dummy. */
1552 if (rlsRnti->ueIdChng)
1554 /* Fix : syed ueId change as part of reestablishment.
1555 * Now SCH to trigger this. CRG ueRecfg for ueId change
1557 if (rgUtlHndlCrntiChng(macInst,cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1559 RLOG_ARG2(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1560 "CRNTI change failed for RNTI:%d new RNTI:%d",
1561 rlsRnti->rnti,rlsRnti->newRnti);
1566 /*PMAC_Reest: Prepare CrntiChngReq and then send to all SMACs to change
1569 if(rgUtlSndCrntiChngReq2AllSMacs(cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1571 /* TODO: do we need to send DelInd to SCH in failure case*/
1576 /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1577 delDatReq.cellId = cell->cellId;
1578 delDatReq.ueId = rlsRnti->rnti;
1579 rgLIMTfuDelDatReq(macInst, &delDatReq);
1584 rgUtlHndlCrntiRls(cell, rlsRnti);
1586 /* Fix : syed Send delete confirmation to SCH */
1587 /* Send RgMacSchUeDelInd to SCH only if it is Rnti release to PMAC.
1588 * Basically dont send DelInd to SCH incase of Ue SCell Del*/
1590 if(FALSE == rlsRnti->isUeSCellDel)
1593 //TODO: commented for compilation without SCH
1595 ueDelInd.cellSapId = cell->schInstMap.cellSapId;
1596 ueDelInd.cellId = rlsRnti->cellId;
1597 ueDelInd.rnti = rlsRnti->rnti;
1598 rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
1599 RgMacSchUeDel(&schPst, &ueDelInd);
1604 } /* end of RgSchMacRlsRntiReq */
1608 PUBLIC Bool RgUtlIsTbMuxed
1613 PUBLIC Bool RgUtlIsTbMuxed()
1618 SFndLenMsg(tb->macHdr, &len);
1619 RETVALUE(len?TRUE : FALSE);
1623 /**********************************************************************
1626 **********************************************************************/