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 ueCb->state = SCH_UE_STATE_ACTIVE;
545 ueCb->state = SCH_UE_HANDIN_IN_PROGRESS;
547 ret = fillSchUeCb(inst, ueCb, ueCfg);
550 if(ueCb->state == SCH_UE_STATE_ACTIVE)
553 SET_ONE_BIT(ueCb->ueId, cellCb->actvUeBitMap);
555 ueCb->cellCb = cellCb;
556 ueCb->srRcvd = false;
557 ueCb->bsrRcvd = false;
558 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
559 ueCb->bsrInfo[lcIdx].dataVol = 0;
561 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
566 /*******************************************************************
568 * @brief Fills PUSCH UL allocation
572 * Function : schFillPuschAlloc
574 * Functionality: fills PUSCH info
577 * @return ROK - success
580 * ****************************************************************/
581 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize,
582 uint8_t startSymb, uint8_t symbLen, uint16_t startPrb)
585 SchCellCb *cellCb = NULLP;
586 SchUlSlotInfo *schUlSlotInfo = NULLP;
587 SchPuschInfo puschInfo;
591 DU_LOG("\nERROR --> SCH: UE CB is empty");
595 cellCb = ueCb->cellCb;
598 DU_LOG("\nERROR --> SCH: CELL CB is empty");
602 tbSize += UL_TX_BUFFER_SIZE; /* 2 bytes header + some buffer */
603 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
604 allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startPrb, numRb);
606 puschInfo.crnti = ueCb->crnti;
607 puschInfo.harqProcId = SCH_HARQ_PROC_ID;
608 puschInfo.resAllocType = SCH_ALLOC_TYPE_1;
609 puschInfo.fdAlloc.startPrb = startPrb;
610 puschInfo.fdAlloc.numPrb = numRb;
611 puschInfo.tdAlloc.startSymb = startSymb;
612 puschInfo.tdAlloc.numSymb = symbLen;
613 puschInfo.tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
614 puschInfo.tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
615 puschInfo.tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
616 puschInfo.tbInfo.ndi = 1; /* new transmission */
617 puschInfo.tbInfo.rv = 0;
618 puschInfo.tbInfo.tbSize = tbSize;
619 puschInfo.dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
620 puschInfo.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
621 puschInfo.dmrsAddPos = DMRS_ADDITIONAL_POS;
623 schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
624 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
625 if(!schUlSlotInfo->schPuschInfo)
627 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
630 memcpy(schUlSlotInfo->schPuschInfo, &puschInfo, sizeof(SchPuschInfo));
635 /*******************************************************************
637 * @brief Fills DCI for UL grant
641 * Function : schFillUlDci
643 * Functionality: fills DCI for UL grant in response to BSR
646 * @return ROK - success
649 * ****************************************************************/
650 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo)
652 SchCellCb *cellCb = ueCb->cellCb;
653 SchControlRsrcSet coreset1 ;
655 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
656 if(ueCb->ueCfg.spCellCfgPres == true)
658 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
661 dciInfo->cellId = cellCb->cellId;
662 dciInfo->crnti = ueCb->crnti;
665 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
666 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
667 dciInfo->bwpCfg.freqAlloc.startPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb;
668 dciInfo->bwpCfg.freqAlloc.numPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb;
670 /*fill coreset cfg */
671 //Considering number of RBs in coreset1 is same as coreset0
672 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
673 //Considering coreset1 also starts from same symbol as coreset0
674 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
675 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
676 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
678 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
679 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
680 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
681 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
682 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
683 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
684 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
685 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
687 dciInfo->formatType = FORMAT0_0;
690 dciInfo->format.format0_0.resourceAllocType = puschInfo->resAllocType;
691 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo->fdAlloc.startPrb;
692 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo->fdAlloc.numPrb;
693 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo->tdAlloc.startSymb;
694 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo->tdAlloc.numSymb;
695 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
696 dciInfo->format.format0_0.mcs = puschInfo->tbInfo.mcs;
697 dciInfo->format.format0_0.harqProcId = puschInfo->harqProcId;
698 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
699 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
700 dciInfo->format.format0_0.ndi = puschInfo->tbInfo.ndi; /* new transmission */
701 dciInfo->format.format0_0.rv = puschInfo->tbInfo.rv;
702 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
703 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
705 /* Fill DCI Structure */
706 dciInfo->dciInfo.rnti = ueCb->crnti;
707 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
708 dciInfo->dciInfo.scramblingRnti = 0;
709 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
710 dciInfo->dciInfo.aggregLevel = 4;
711 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
712 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
713 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
714 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
715 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
716 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
717 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
718 dciInfo->dciInfo.pdschCfg = NULL; /* No DL data being sent */
723 /*******************************************************************
725 * @brief Function to Modify Ue Config request from MAC
729 * Function : MacSchModUeConfigReq
731 * Functionality: Function to modify Ue Config request from MAC
734 * @return ROK - success
737 * ****************************************************************/
738 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
740 uint8_t ueId, lcIdx, ret = ROK;
741 SchCellCb *cellCb = NULLP;
742 SchUeCb *ueCb = NULLP;
744 Inst inst = pst->dstInst - SCH_INST_START;
745 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
747 #ifdef CALL_FLOW_DEBUG_LOG
748 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
753 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
756 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
757 cellCb = getSchCellCb(pst->event, inst, ueCfg);
759 /* Search if UE already configured */
760 GET_UE_ID(ueCfg->crnti, ueId);
761 ueCb = &cellCb->ueCb[ueId -1];
765 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
766 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
769 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
771 /* Found the UeCb to Reconfig */
772 ret = fillSchUeCb(inst, ueCb, ueCfg);
775 ueCb->cellCb = cellCb;
776 ueCb->srRcvd = false;
777 ueCb->bsrRcvd = false;
778 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
779 ueCb->bsrInfo[lcIdx].dataVol = 0;
781 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
787 /*******************************************************************
789 * @brief Fill and send UE delete response to MAC
793 * Function : SchSendUeDeleteRspToMac
795 * Functionality: Fill and send UE delete response to MAC
797 * @params[in] Inst inst, SchUeDelete *ueDelete, SchMacRsp result,
799 * @return ROK - success
802 * ****************************************************************/
803 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete *ueDelete, SchMacRsp result, ErrorCause cause)
806 SchUeDeleteRsp delRsp;
808 memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
809 delRsp.cellId = ueDelete->cellId;
810 delRsp.crnti = ueDelete->crnti;
812 delRsp.cause = cause;
814 /* Filling response post */
815 memset(&rspPst, 0, sizeof(Pst));
816 FILL_PST_SCH_TO_MAC(rspPst, inst);
817 rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
818 SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
821 /*******************************************************************
823 * @brief Function to delete Sch Pucch ResrcCfg
827 * Function : deleteSchPucchResrcCfg
829 * Functionality: Function to delete Sch Pucch ResrcCfg
831 * @params[in] SchPucchResrcCfg *resrc
834 * ****************************************************************/
836 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
839 for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
841 switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
845 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
846 sizeof(SchPucchFormat0));
851 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
852 sizeof(SchPucchFormat1));
857 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
858 sizeof(SchPucchFormat2_3));
863 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
864 sizeof(SchPucchFormat2_3));
869 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
870 sizeof(SchPucchFormat4));
877 /*******************************************************************
879 * @brief Function to delete SCH Pdsch ServCellCfg
883 * Function : deleteSchPdschServCellCfg
885 * Functionality: Function to delete SCH Pdsch ServCellCfg
887 * @params[in] SchPdschServCellCfg *pdschServCellCfg
890 * ****************************************************************/
892 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
894 SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
895 SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
896 SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
897 SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
900 /*******************************************************************
902 * @brief Function to delete SCH UeCb
906 * Function : deleteSchUeCb
908 * Functionality: Function to delete SCH UeCb
911 * @return ROK - success
914 * ****************************************************************/
915 void deleteSchUeCb(SchUeCb *ueCb)
917 uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
918 SchPucchCfg *pucchCfg = NULLP;
919 SchPdschConfig *pdschCfg = NULLP;
920 CmLListCp *lcLL = NULLP;
924 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
925 if(ueCb->ueCfg.spCellCfgPres)
927 if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
929 pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
930 for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
931 SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
934 if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
936 pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
937 SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
940 deleteSchPucchResrcCfg(pucchCfg->resrc);
941 SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
943 SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
944 SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
945 SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
946 SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
947 SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
948 SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
949 SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
950 SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
951 SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
953 SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
954 deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
956 /*Need to Free the memory allocated for S-NSSAI*/
957 for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
959 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
960 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
963 /*Clearing out Dedicated LC list*/
964 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
966 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
968 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
970 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
972 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
974 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
976 /*Deleteing the Default LC list*/
977 lcLL = &(ueCb->dlLcPrbEst.defLcList);
980 lcLL = &(ueCb->ulLcPrbEst.defLcList);
983 memset(ueCb, 0, sizeof(SchUeCb));
987 /*******************************************************************
989 * @brief Function for Ue Delete request from MAC to SCH
993 * Function : MacSchUeDeleteReq
995 * Functionality: Function for Ue Delete request from MAC to SCH
997 * @params[in] Pst *pst, SchUeDelete *ueDelete
998 * @return ROK - success
1001 * ****************************************************************/
1002 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete *ueDelete)
1004 uint8_t idx=0, ueId=0, ueIdToDel=0, ret=ROK;
1006 SchCellCb *cellCb = NULLP;
1007 Inst inst = pst->dstInst - SCH_INST_START;
1008 CmLList *node = NULL, *next = NULL;
1010 #ifdef CALL_FLOW_DEBUG_LOG
1011 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
1016 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): Ue Delete request failed");
1019 DU_LOG("\nDEBUG --> SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1021 cellCb = schCb[inst].cells[idx];
1023 if(cellCb->cellId != ueDelete->cellId)
1025 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): cell Id is not available");
1026 result = INVALID_CELLID;
1030 GET_UE_ID(ueDelete->crnti, ueId);
1031 if(( cellCb->ueCb[ueId-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueId-1].state == SCH_UE_STATE_ACTIVE))
1033 deleteSchUeCb(&cellCb->ueCb[ueId-1]);
1035 /* Remove UE from ueToBeScheduled list */
1036 node = cellCb->ueToBeScheduled.first;
1040 ueId = *(uint8_t *)node->node;
1041 if(ueId == ueIdToDel)
1043 SCH_FREE(node->node, sizeof(uint8_t));
1044 deleteNodeFromLList(&cellCb->ueToBeScheduled, node);
1049 cellCb->numActvUe--;
1050 result = NOT_APPLICABLE;
1054 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): SchUeCb not found");
1055 result = INVALID_UEID;
1059 if(result == NOT_APPLICABLE)
1061 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
1065 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
1071 /*******************************************************************
1073 * @brief Fill and send Cell delete response to MAC
1077 * Function : SchSendCellDeleteRspToMac
1079 * Functionality: Fill and send Cell delete response to MAC
1081 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
1082 * @return ROK - success
1085 * ****************************************************************/
1086 uint8_t SchSendCellDeleteRspToMac(SchCellDelete *ueDelete, Inst inst, SchMacRsp result)
1091 SchCellDeleteRsp delRsp;
1093 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
1094 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1095 delRsp.cellId = ueDelete->cellId;
1096 delRsp.rsp = result;
1098 /* Filling response post */
1099 memset(&rspPst, 0, sizeof(Pst));
1100 FILL_PST_SCH_TO_MAC(rspPst, inst);
1101 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1102 ret = SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1105 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1111 /*******************************************************************
1113 * @brief Function for cellCb Deletion
1117 * Function : deleteSchCellCb
1119 * Functionality: Function for cellCb Deletion
1121 * @params[in] SchCellDelete *cellDelete
1122 * @return ROK - success
1125 * ****************************************************************/
1126 void deleteSchCellCb(SchCellCb *cellCb)
1128 uint8_t sliceIdx=0, slotIdx=0;
1129 CmLListCp *list=NULL;
1130 CmLList *node=NULL, *next=NULL;
1132 if(cellCb->schDlSlotInfo)
1134 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1136 list = &cellCb->schDlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1141 SCH_FREE(node->node, sizeof(FreePrbBlock));
1142 deleteNodeFromLList(list, node);
1145 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1147 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1150 if(cellCb->schUlSlotInfo)
1152 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1154 list = &cellCb->schUlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1159 SCH_FREE(node->node, sizeof(FreePrbBlock));
1160 deleteNodeFromLList(list, node);
1163 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
1165 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
1168 if(cellCb->cellCfg.plmnInfoList.snssai)
1170 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.plmnInfoList.numSliceSupport; sliceIdx++)
1172 SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
1174 SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai, cellCb->cellCfg.plmnInfoList.numSliceSupport*sizeof(Snssai*));
1177 /* Remove all UE from ueToBeScheduled list and deallocate */
1178 node = cellCb->ueToBeScheduled.first;
1182 SCH_FREE(node->node, sizeof(uint8_t));
1183 cmLListDelFrm(&cellCb->ueToBeScheduled, node);
1184 SCH_FREE(node, sizeof(CmLList));
1188 memset(cellCb, 0, sizeof(SchCellCb));
1192 /*******************************************************************
1194 * @brief Function for cell Delete request from MAC to SCH
1198 * Function : MacSchCellDeleteReq
1200 * Functionality: Function for cell Delete request from MAC to SCH
1202 * @params[in] Pst *pst, SchCellDelete *cellDelete
1203 * @return ROK - success
1206 * ****************************************************************/
1208 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete *cellDelete)
1210 uint8_t cellIdx=0, ret = RFAILED;
1211 Inst inst = pst->dstInst - SCH_INST_START;
1212 SchMacRsp result= RSP_OK;
1214 #ifdef CALL_FLOW_DEBUG_LOG
1215 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1220 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1224 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1225 if(schCb[inst].cells[cellIdx] == NULLP)
1227 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1232 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1234 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1237 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1238 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1242 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1247 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1249 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1257 /**********************************************************************
1259 **********************************************************************/