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 *******************************************************************************/
18 /* This file contains UE management handling functionality for SCH */
20 #include "common_def.h"
27 #include "du_app_mac_inf.h"
28 #include "mac_sch_interface.h"
30 #include "sch_utils.h"
33 SchUeCfgRspFunc SchUeCfgRspOpts[] =
35 packSchUeCfgRsp, /* LC */
36 MacProcSchUeCfgRsp, /* TC */
37 packSchUeCfgRsp /* LWLC */
40 SchUeDeleteRspFunc SchUeDeleteRspOpts[] =
42 packSchUeDeleteRsp, /* LC */
43 MacProcSchUeDeleteRsp, /* TC */
44 packSchUeDeleteRsp /* LWLC */
47 SchCellDeleteRspFunc SchCellDeleteRspOpts[]=
49 packSchCellDeleteRsp, /* LC */
50 MacProcSchCellDeleteRsp, /* TC */
51 packSchCellDeleteRsp /* LWLC */
54 /*******************************************************************
56 * @brief Fill and send UE cfg response to MAC
60 * Function : SchSendUeCfgRspToMac
62 * Functionality: Fill and send UE cfg response to MAC
65 * @return ROK - success
68 * ****************************************************************/
69 void SchSendUeCfgRspToMac(uint16_t event, SchUeCfg *ueCfg, Inst inst,\
70 SchMacRsp result, SchUeCfgRsp *cfgRsp)
74 cfgRsp->cellId = ueCfg->cellId;
75 cfgRsp->ueId = ueCfg->ueId;
76 cfgRsp->crnti = ueCfg->crnti;
79 /* Filling response post */
80 memset(&rspPst, 0, sizeof(Pst));
81 FILL_PST_SCH_TO_MAC(rspPst, inst);
82 if(event == EVENT_ADD_UE_CONFIG_REQ_TO_SCH)
84 rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
85 DU_LOG("\nINFO --> SCH : Sending UE Config response to MAC");
87 else if(event == EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH)
89 rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
90 DU_LOG("\nINFO --> SCH : Sending UE Reconfig response to MAC");
92 SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
95 /*******************************************************************
98 * @brief Function to fill Dl Lc Context in SCH Ue Cb
102 * Function : fillSchDlLcCtxt
104 * Functionality: Function to fill Dl Lc Context in SCH Ue Cb
106 * @params[in] SchDlLcCtxt pointer,
110 * ****************************************************************/
112 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
114 ueCbLcCfg->lcId = lcCfg->lcId;
115 ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
116 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
120 ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
124 if(ueCbLcCfg->snssai == NULLP)/*In CONFIG_MOD case, no need to allocate SNSSAI memory*/
126 SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
128 memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
132 /*******************************************************************
134 * @brief Function to fill Ul Lc Context in SCH Ue Cb
138 * Function : fillSchUlLcCtxt
140 * Functionality: Function to fill Ul Lc Context in SCH Ue Cb
142 * @params[in] SchUlLcCtxt pointer,
146 * ****************************************************************/
148 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
150 ueCbLcCfg->lcId = lcCfg->lcId;
151 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
152 ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
153 ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
154 ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
155 ueCbLcCfg->pbr = lcCfg->ulLcCfg.pbr;
156 ueCbLcCfg->bsd = lcCfg->ulLcCfg.bsd;
160 ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
164 /*In CONFIG_MOD case, no need to allocate SNSSAI memory again*/
165 if(ueCbLcCfg->snssai == NULLP)
167 SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
169 memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
173 /*******************************************************************
175 * @brief Function to update/allocate dedLC Info
179 * Function : updateDedLcInfo
181 * Functionality: Function to fill DLDedLcInfo
183 * @params[arg] scheduler instance,
185 * SchRrmPolicy pointer,
186 * SchLcPrbEstimate pointer , It will be filled
187 * isDedicated pointer,(Address of isDedicated flag in LC Context)
189 * @return ROK >> This LC is part of RRM MemberList.
190 * RFAILED >> FATAL Error
191 * ROKIGNORE >> This LC is not part of this RRM MemberList
193 * ****************************************************************/
195 uint8_t updateDedLcInfo(Inst inst, Snssai *snssai, SchLcPrbEstimate *lcPrbEst, bool *isDedicated)
197 uint8_t sliceCfgIdx =0;
198 SchSliceCfg sliceCfg = schCb[inst].sliceCfg;
200 if(sliceCfg.numOfSliceConfigured)
202 for(sliceCfgIdx = 0; sliceCfgIdx<sliceCfg.numOfSliceConfigured; sliceCfgIdx++)
204 if(memcmp(snssai, &(sliceCfg.listOfConfirguration[sliceCfgIdx]->snssai), sizeof(Snssai)) == 0)
206 if(lcPrbEst->dedLcInfo == NULLP)
208 SCH_ALLOC(lcPrbEst->dedLcInfo, sizeof(DedicatedLCInfo));
209 if(lcPrbEst->dedLcInfo == NULLP)
211 DU_LOG("\nINFO --> SCH : Memory Allocation Failed");
215 if(sliceCfg.listOfConfirguration[sliceCfgIdx]->rrmPolicyRatioInfo)
217 /*Updating latest RrmPolicy*/
218 lcPrbEst->dedLcInfo->rsvdDedicatedPRB = \
219 (uint16_t)(((sliceCfg.listOfConfirguration[sliceCfgIdx]->rrmPolicyRatioInfo->policyDedicatedRatio)*(MAX_NUM_RB))/100);
221 DU_LOG("\nINFO --> SCH : Updated RRM policy, reservedPOOL:%d",lcPrbEst->dedLcInfo->rsvdDedicatedPRB);
225 /*case: This LcCtxt is either a Default LC or this LC is part of someother RRM_MemberList*/
226 if(*isDedicated != TRUE)
228 DU_LOG("\nINFO --> SCH : This SNSSAI is not a part of this RRMPolicy");
234 /*******************************************************************
236 * @brief Function to fill SchUeCb
240 * Function : fillSchUeCb
242 * Functionality: Function to fill SchUeCb
244 * @params[in] Scheduler instance,
247 * @return ROK/RFAILED
249 * ****************************************************************/
251 uint8_t fillSchUeCb(Inst inst, SchUeCb *ueCb, SchUeCfg *ueCfg)
253 uint8_t lcIdx, ueLcIdx;
254 uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
255 SchPdschCfgCmn pdschCfg;
256 SchPucchDlDataToUlAck *dlDataToUlAck;
257 CmLListCp *lcLL = NULLP;
258 uint8_t retDL = ROK, retUL = ROK;
259 bool isLcIdValid = FALSE;
261 ueCb->ueCfg.cellId = ueCfg->cellId;
262 ueCb->ueCfg.ueId = ueCfg->ueId;
263 ueCb->ueCfg.crnti = ueCfg->crnti;
264 ueCb->ueCfg.dataTransmissionAction = ueCfg->dataTransmissionInfo;
265 if(ueCfg->macCellGrpCfgPres == true)
267 memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg));
268 ueCb->ueCfg.macCellGrpCfgPres = true;
271 if(ueCfg->phyCellGrpCfgPres == true)
273 memcpy(&ueCb->ueCfg.phyCellGrpCfg , &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
274 ueCb->ueCfg.phyCellGrpCfgPres = true;
277 if(ueCfg->spCellCfgPres == true)
279 memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
281 covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
283 memset(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
284 memcpy(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
286 ueCb->ueCfg.spCellCfgPres = true;
287 dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
292 BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
293 ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
294 dlDataToUlAck->dlDataToUlAckList);
295 ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1TblPrsnt = true;
296 BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
297 ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
298 NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
299 ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt = true;
306 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
307 ueCb->ueCfg.ambrCfg = ueCfg->ambrCfg;
309 memcpy(&ueCb->ueCfg.dlModInfo, &ueCfg->dlModInfo , sizeof(SchModulationInfo));
310 memcpy(&ueCb->ueCfg.ulModInfo, &ueCfg->ulModInfo , sizeof(SchModulationInfo));
312 //Updating SchUlCb and SchDlCb DB in SchUeCb
313 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
315 isLcIdValid = FALSE; /*Re-Initializing*/
317 ueLcIdx = ueCfg->schLcCfg[lcIdx].lcId;
318 CHECK_LCID(ueLcIdx, isLcIdValid);
319 if(isLcIdValid == FALSE)
321 DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
324 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
326 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
327 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
329 /*Checking whether this LC belong to Dedicated S-NSSAI
330 * and Create the Dedicated LC List & Update the Reserve PRB number*/
331 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
333 retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlLcPrbEst),\
334 &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
336 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
338 retUL = updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulLcPrbEst),\
339 &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
342 if(retUL == RFAILED || retDL == RFAILED)/*FATAL error*/
344 DU_LOG("\nERROR --> SCH : Failure in updateDedLcInfo");
350 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
352 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
354 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
355 /*Updating the RRM reserved pool PRB count*/
356 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
358 retUL = updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulLcPrbEst),\
359 &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
363 DU_LOG("\nERROR --> SCH : Failed in updating Ded Lc info");
367 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
369 /*Delete the LC node from the UL LC List*/
370 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated)
372 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
374 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
375 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
376 if(lcLL->count == 0)/*IF No Node in DedicateLCList to be deleted*/
378 /*Free the Dedicated LC Info structure*/
379 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
383 else/*Default LC list*/
385 lcLL = &(ueCb->ulLcPrbEst.defLcList);
386 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
388 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
389 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
391 }/*End of UL LC Ctxt*/
393 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
395 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
397 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
398 /*Updating the RRM policy*/
399 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
401 retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlLcPrbEst), \
402 &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
406 DU_LOG("\nERROR --> SCH : Failed in updating Ded Lc info");
410 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
412 /*Delete the LC node from the DL LC List*/
413 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated)
415 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
417 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
418 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
419 if(lcLL->count == 0)/*Last Node in DedicateLCList to be deleted*/
421 /*Free the Dedicated LC Info structure*/
422 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
428 lcLL = &(ueCb->dlLcPrbEst.defLcList);
429 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
431 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
432 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
434 }/*End of DL LC ctxt*/
437 SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
438 SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
440 }/* End of outer for loop */
444 /*******************************************************************
446 * @brief Function to get SCH Cell Cb
450 * Function : getSchCellCb
452 * Functionality: Function to get SCH Cell Cb
454 * @params[in] event, SchUeCfg pointer
455 * @return schUeCb pointer - success
458 * ****************************************************************/
460 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
463 SchCellCb *cellCb = NULLP;
465 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
467 /* Search of cell cb */
468 for(idx = 0; idx < MAX_NUM_CELL; idx++)
470 cellCb = schCb[inst].cells[idx];
471 if(cellCb->cellId == ueCfg->cellId)
474 if(idx == MAX_NUM_CELL)
476 DU_LOG("\nERROR --> SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
477 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
481 /* Check if max number of UE configured */
482 if(cellCb->numActvUe > MAX_NUM_UE)
484 DU_LOG("\nERROR --> SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
485 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
492 /*******************************************************************
494 * @brief Function to Add Ue Config Request from MAC
498 * Function : MacSchAddUeConfigReq
500 * Functionality: Function to Add Ue config request from MAC
503 * @return ROK - success
506 * ****************************************************************/
507 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
509 uint8_t lcIdx = 0, ret = ROK;
510 SchCellCb *cellCb = NULLP;
511 SchUeCb *ueCb = NULLP;
513 Inst inst = pst->dstInst - SCH_INST_START;
514 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
516 #ifdef CALL_FLOW_DEBUG_LOG
517 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_ADD_UE_CONFIG_REQ_TO_SCH\n");
522 DU_LOG("\nERROR --> SCH : Adding UE Config Request failed at MacSchAddUeConfigReq()");
525 DU_LOG("\nDEBUG --> SCH : Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
526 cellCb = getSchCellCb(pst->event, inst, ueCfg);
528 /* Search if UE already configured */
529 ueCb = &cellCb->ueCb[ueCfg->ueId - 1];
531 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
533 DU_LOG("\nDEBUG --> SCH : CRNTI %d already configured ", ueCfg->crnti);
534 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
538 /* Fill received Ue Configuration in UeCb */
539 memset(ueCb, 0, sizeof(SchUeCb));
540 ueCb->ueId = ueCfg->ueId;
541 ueCb->crnti = ueCfg->crnti;
543 ret = fillSchUeCb(inst, ueCb, ueCfg);
546 /* If UE has initiated RACH and then UE context is created, it means UE is
548 * Else if UE context is created before RACH, this means that UE is being
549 * handed-in from source DU */
550 if(cellCb->raCb[ueCb->ueId-1].tcrnti == ueCb->crnti)
553 SET_ONE_BIT(ueCb->ueId, cellCb->actvUeBitMap);
554 ueCb->state = SCH_UE_STATE_ACTIVE;
558 ueCb->state = SCH_UE_HANDIN_IN_PROGRESS;
561 ueCb->cellCb = cellCb;
562 ueCb->srRcvd = false;
563 ueCb->bsrRcvd = false;
564 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
565 ueCb->bsrInfo[lcIdx].dataVol = 0;
567 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
572 /*******************************************************************
574 * @brief Fills PUSCH UL allocation
578 * Function : schFillPuschAlloc
580 * Functionality: fills PUSCH info
583 * @return ROK - success
586 * ****************************************************************/
587 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize,
588 uint8_t startSymb, uint8_t symbLen, uint16_t startPrb)
591 SchCellCb *cellCb = NULLP;
592 SchUlSlotInfo *schUlSlotInfo = NULLP;
593 SchPuschInfo puschInfo;
597 DU_LOG("\nERROR --> SCH: UE CB is empty");
601 cellCb = ueCb->cellCb;
604 DU_LOG("\nERROR --> SCH: CELL CB is empty");
608 tbSize += UL_TX_BUFFER_SIZE; /* 2 bytes header + some buffer */
609 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
610 allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startPrb, numRb);
612 puschInfo.crnti = ueCb->crnti;
613 puschInfo.harqProcId = SCH_HARQ_PROC_ID;
614 puschInfo.resAllocType = SCH_ALLOC_TYPE_1;
615 puschInfo.fdAlloc.startPrb = startPrb;
616 puschInfo.fdAlloc.numPrb = numRb;
617 puschInfo.tdAlloc.startSymb = startSymb;
618 puschInfo.tdAlloc.numSymb = symbLen;
619 puschInfo.tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
620 puschInfo.tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
621 puschInfo.tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
622 puschInfo.tbInfo.ndi = 1; /* new transmission */
623 puschInfo.tbInfo.rv = 0;
624 puschInfo.tbInfo.tbSize = tbSize;
625 puschInfo.dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
626 puschInfo.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
627 puschInfo.dmrsAddPos = DMRS_ADDITIONAL_POS;
629 schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
630 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
631 if(!schUlSlotInfo->schPuschInfo)
633 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
636 memcpy(schUlSlotInfo->schPuschInfo, &puschInfo, sizeof(SchPuschInfo));
641 /*******************************************************************
643 * @brief Fills DCI for UL grant
647 * Function : schFillUlDci
649 * Functionality: fills DCI for UL grant in response to BSR
652 * @return ROK - success
655 * ****************************************************************/
656 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo)
658 SchCellCb *cellCb = ueCb->cellCb;
659 SchControlRsrcSet coreset1 ;
661 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
662 if(ueCb->ueCfg.spCellCfgPres == true)
664 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
667 dciInfo->cellId = cellCb->cellId;
668 dciInfo->crnti = ueCb->crnti;
671 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
672 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
673 dciInfo->bwpCfg.freqAlloc.startPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb;
674 dciInfo->bwpCfg.freqAlloc.numPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb;
676 /*fill coreset cfg */
677 //Considering number of RBs in coreset1 is same as coreset0
678 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
679 //Considering coreset1 also starts from same symbol as coreset0
680 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
681 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
682 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
684 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
685 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
686 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
687 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
688 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
689 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
690 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
691 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
693 dciInfo->formatType = FORMAT0_0;
696 dciInfo->format.format0_0.resourceAllocType = puschInfo->resAllocType;
697 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo->fdAlloc.startPrb;
698 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo->fdAlloc.numPrb;
699 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo->tdAlloc.startSymb;
700 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo->tdAlloc.numSymb;
701 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
702 dciInfo->format.format0_0.mcs = puschInfo->tbInfo.mcs;
703 dciInfo->format.format0_0.harqProcId = puschInfo->harqProcId;
704 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
705 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
706 dciInfo->format.format0_0.ndi = puschInfo->tbInfo.ndi; /* new transmission */
707 dciInfo->format.format0_0.rv = puschInfo->tbInfo.rv;
708 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
709 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
711 /* Fill DCI Structure */
712 dciInfo->dciInfo.rnti = ueCb->crnti;
713 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
714 dciInfo->dciInfo.scramblingRnti = 0;
715 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
716 dciInfo->dciInfo.aggregLevel = 4;
717 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
718 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
719 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
720 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
721 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
722 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
723 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
724 dciInfo->dciInfo.pdschCfg = NULL; /* No DL data being sent */
729 /*******************************************************************
731 * @brief Function to Modify Ue Config request from MAC
735 * Function : MacSchModUeConfigReq
737 * Functionality: Function to modify Ue Config request from MAC
740 * @return ROK - success
743 * ****************************************************************/
744 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
746 uint8_t ueId, lcIdx, ret = ROK;
747 SchCellCb *cellCb = NULLP;
748 SchUeCb *ueCb = NULLP;
750 Inst inst = pst->dstInst - SCH_INST_START;
751 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
753 #ifdef CALL_FLOW_DEBUG_LOG
754 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
759 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
762 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
763 cellCb = getSchCellCb(pst->event, inst, ueCfg);
765 /* Search if UE already configured */
766 GET_UE_ID(ueCfg->crnti, ueId);
767 ueCb = &cellCb->ueCb[ueId -1];
771 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
772 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
775 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
777 /* Found the UeCb to Reconfig */
778 ret = fillSchUeCb(inst, ueCb, ueCfg);
781 ueCb->cellCb = cellCb;
782 ueCb->srRcvd = false;
783 ueCb->bsrRcvd = false;
784 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
785 ueCb->bsrInfo[lcIdx].dataVol = 0;
787 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
793 /*******************************************************************
795 * @brief Fill and send UE delete response to MAC
799 * Function : SchSendUeDeleteRspToMac
801 * Functionality: Fill and send UE delete response to MAC
803 * @params[in] Inst inst, SchUeDelete *ueDelete, SchMacRsp result,
805 * @return ROK - success
808 * ****************************************************************/
809 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete *ueDelete, SchMacRsp result, ErrorCause cause)
812 SchUeDeleteRsp delRsp;
814 memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
815 delRsp.cellId = ueDelete->cellId;
816 delRsp.crnti = ueDelete->crnti;
818 delRsp.cause = cause;
820 /* Filling response post */
821 memset(&rspPst, 0, sizeof(Pst));
822 FILL_PST_SCH_TO_MAC(rspPst, inst);
823 rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
824 SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
827 /*******************************************************************
829 * @brief Function to delete Sch Pucch ResrcCfg
833 * Function : deleteSchPucchResrcCfg
835 * Functionality: Function to delete Sch Pucch ResrcCfg
837 * @params[in] SchPucchResrcCfg *resrc
840 * ****************************************************************/
842 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
845 for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
847 switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
851 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
852 sizeof(SchPucchFormat0));
857 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
858 sizeof(SchPucchFormat1));
863 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
864 sizeof(SchPucchFormat2_3));
869 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
870 sizeof(SchPucchFormat2_3));
875 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
876 sizeof(SchPucchFormat4));
883 /*******************************************************************
885 * @brief Function to delete SCH Pdsch ServCellCfg
889 * Function : deleteSchPdschServCellCfg
891 * Functionality: Function to delete SCH Pdsch ServCellCfg
893 * @params[in] SchPdschServCellCfg *pdschServCellCfg
896 * ****************************************************************/
898 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
900 SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
901 SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
902 SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
903 SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
906 /*******************************************************************
908 * @brief Function to delete SCH UeCb
912 * Function : deleteSchUeCb
914 * Functionality: Function to delete SCH UeCb
917 * @return ROK - success
920 * ****************************************************************/
921 void deleteSchUeCb(SchUeCb *ueCb)
923 uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
924 SchPucchCfg *pucchCfg = NULLP;
925 SchPdschConfig *pdschCfg = NULLP;
926 CmLListCp *lcLL = NULLP;
930 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
931 if(ueCb->ueCfg.spCellCfgPres)
933 if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
935 pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
936 for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
937 SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
940 if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
942 pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
943 SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
946 deleteSchPucchResrcCfg(pucchCfg->resrc);
947 SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
949 SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
950 SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
951 SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
952 SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
953 SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
954 SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
955 SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
956 SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
957 SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
959 SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
960 deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
962 /*Need to Free the memory allocated for S-NSSAI*/
963 for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
965 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
966 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
969 /*Clearing out Dedicated LC list*/
970 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
972 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
974 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
976 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
978 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
980 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
982 /*Deleteing the Default LC list*/
983 lcLL = &(ueCb->dlLcPrbEst.defLcList);
986 lcLL = &(ueCb->ulLcPrbEst.defLcList);
989 memset(ueCb, 0, sizeof(SchUeCb));
993 /*******************************************************************
995 * @brief Function for Ue Delete request from MAC to SCH
999 * Function : MacSchUeDeleteReq
1001 * Functionality: Function for Ue Delete request from MAC to SCH
1003 * @params[in] Pst *pst, SchUeDelete *ueDelete
1004 * @return ROK - success
1007 * ****************************************************************/
1008 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete *ueDelete)
1010 uint8_t idx=0, ueId=0, ueIdToDel=0, ret=ROK;
1012 SchCellCb *cellCb = NULLP;
1013 Inst inst = pst->dstInst - SCH_INST_START;
1014 CmLList *node = NULL, *next = NULL;
1016 #ifdef CALL_FLOW_DEBUG_LOG
1017 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
1022 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): Ue Delete request failed");
1025 DU_LOG("\nDEBUG --> SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1027 cellCb = schCb[inst].cells[idx];
1029 if(cellCb->cellId != ueDelete->cellId)
1031 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): cell Id is not available");
1032 result = INVALID_CELLID;
1036 GET_UE_ID(ueDelete->crnti, ueId);
1037 if(( cellCb->ueCb[ueId-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueId-1].state == SCH_UE_STATE_ACTIVE))
1039 deleteSchUeCb(&cellCb->ueCb[ueId-1]);
1041 /* Remove UE from ueToBeScheduled list */
1042 node = cellCb->ueToBeScheduled.first;
1046 ueId = *(uint8_t *)node->node;
1047 if(ueId == ueIdToDel)
1049 SCH_FREE(node->node, sizeof(uint8_t));
1050 deleteNodeFromLList(&cellCb->ueToBeScheduled, node);
1055 cellCb->numActvUe--;
1056 result = NOT_APPLICABLE;
1060 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): SchUeCb not found");
1061 result = INVALID_UEID;
1065 if(result == NOT_APPLICABLE)
1067 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
1071 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
1077 /*******************************************************************
1079 * @brief Fill and send Cell delete response to MAC
1083 * Function : SchSendCellDeleteRspToMac
1085 * Functionality: Fill and send Cell delete response to MAC
1087 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
1088 * @return ROK - success
1091 * ****************************************************************/
1092 uint8_t SchSendCellDeleteRspToMac(SchCellDelete *ueDelete, Inst inst, SchMacRsp result)
1097 SchCellDeleteRsp delRsp;
1099 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
1100 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1101 delRsp.cellId = ueDelete->cellId;
1102 delRsp.rsp = result;
1104 /* Filling response post */
1105 memset(&rspPst, 0, sizeof(Pst));
1106 FILL_PST_SCH_TO_MAC(rspPst, inst);
1107 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1108 ret = SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1111 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1117 /*******************************************************************
1119 * @brief Function for cellCb Deletion
1123 * Function : deleteSchCellCb
1125 * Functionality: Function for cellCb Deletion
1127 * @params[in] SchCellDelete *cellDelete
1128 * @return ROK - success
1131 * ****************************************************************/
1132 void deleteSchCellCb(SchCellCb *cellCb)
1134 uint8_t sliceIdx=0, slotIdx=0;
1135 CmLListCp *list=NULL;
1136 CmLList *node=NULL, *next=NULL;
1138 if(cellCb->schDlSlotInfo)
1140 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1142 list = &cellCb->schDlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1147 SCH_FREE(node->node, sizeof(FreePrbBlock));
1148 deleteNodeFromLList(list, node);
1151 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1153 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1156 if(cellCb->schUlSlotInfo)
1158 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1160 list = &cellCb->schUlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1165 SCH_FREE(node->node, sizeof(FreePrbBlock));
1166 deleteNodeFromLList(list, node);
1169 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
1171 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
1174 if(cellCb->cellCfg.plmnInfoList.snssai)
1176 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.plmnInfoList.numSliceSupport; sliceIdx++)
1178 SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
1180 SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai, cellCb->cellCfg.plmnInfoList.numSliceSupport*sizeof(Snssai*));
1183 /* Remove all UE from ueToBeScheduled list and deallocate */
1184 node = cellCb->ueToBeScheduled.first;
1188 SCH_FREE(node->node, sizeof(uint8_t));
1189 cmLListDelFrm(&cellCb->ueToBeScheduled, node);
1190 SCH_FREE(node, sizeof(CmLList));
1194 memset(cellCb, 0, sizeof(SchCellCb));
1198 /*******************************************************************
1200 * @brief Function for cell Delete request from MAC to SCH
1204 * Function : MacSchCellDeleteReq
1206 * Functionality: Function for cell Delete request from MAC to SCH
1208 * @params[in] Pst *pst, SchCellDelete *cellDelete
1209 * @return ROK - success
1212 * ****************************************************************/
1214 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete *cellDelete)
1216 uint8_t cellIdx=0, ret = RFAILED;
1217 Inst inst = pst->dstInst - SCH_INST_START;
1218 SchMacRsp result= RSP_OK;
1220 #ifdef CALL_FLOW_DEBUG_LOG
1221 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1226 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1230 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1231 if(schCb[inst].cells[cellIdx] == NULLP)
1233 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1238 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1240 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1243 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1244 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1248 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1253 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1255 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1263 /**********************************************************************
1265 **********************************************************************/