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->duUeF1apId = ueCfg->duUeF1apId;
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.duUeF1apId = ueCfg->duUeF1apId;
263 ueCb->ueCfg.crnti = ueCfg->crnti;
264 if(ueCfg->macCellGrpCfgPres == true)
266 memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg));
267 ueCb->ueCfg.macCellGrpCfgPres = true;
270 if(ueCfg->phyCellGrpCfgPres == true)
272 memcpy(&ueCb->ueCfg.phyCellGrpCfg , &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
273 ueCb->ueCfg.phyCellGrpCfgPres = true;
276 if(ueCfg->spCellCfgPres == true)
278 memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
280 covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
282 memset(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
283 memcpy(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
285 ueCb->ueCfg.spCellCfgPres = true;
286 dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
291 BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
292 ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
293 dlDataToUlAck->dlDataToUlAckList);
294 ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1TblPrsnt = true;
295 BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
296 ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
297 NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
298 ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt = true;
305 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
306 ueCb->ueCfg.ambrCfg = ueCfg->ambrCfg;
308 memcpy(&ueCb->ueCfg.dlModInfo, &ueCfg->dlModInfo , sizeof(SchModulationInfo));
309 memcpy(&ueCb->ueCfg.ulModInfo, &ueCfg->ulModInfo , sizeof(SchModulationInfo));
311 //Updating SchUlCb and SchDlCb DB in SchUeCb
312 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
314 isLcIdValid = FALSE; /*Re-Initializing*/
316 ueLcIdx = ueCfg->schLcCfg[lcIdx].lcId;
317 CHECK_LCID(ueLcIdx, isLcIdValid);
318 if(isLcIdValid == FALSE)
320 DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
323 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
325 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
326 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
328 /*Checking whether this LC belong to Dedicated S-NSSAI
329 * and Create the Dedicated LC List & Update the Reserve PRB number*/
330 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
332 retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlLcPrbEst),\
333 &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
335 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
337 retUL = updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulLcPrbEst),\
338 &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
341 if(retUL == RFAILED || retDL == RFAILED)/*FATAL error*/
343 DU_LOG("\nERROR --> SCH : Failure in updateDedLcInfo");
349 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
351 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
353 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
354 /*Updating the RRM reserved pool PRB count*/
355 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
357 retUL = updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulLcPrbEst),\
358 &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
362 DU_LOG("\nERROR --> SCH : Failed in updating Ded Lc info");
366 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
368 /*Delete the LC node from the UL LC List*/
369 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated)
371 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
373 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
374 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
375 if(lcLL->count == 0)/*IF No Node in DedicateLCList to be deleted*/
377 /*Free the Dedicated LC Info structure*/
378 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
382 else/*Default LC list*/
384 lcLL = &(ueCb->ulLcPrbEst.defLcList);
385 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
387 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
388 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
390 }/*End of UL LC Ctxt*/
392 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
394 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
396 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
397 /*Updating the RRM policy*/
398 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
400 retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlLcPrbEst), \
401 &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
405 DU_LOG("\nERROR --> SCH : Failed in updating Ded Lc info");
409 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
411 /*Delete the LC node from the DL LC List*/
412 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated)
414 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
416 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
417 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
418 if(lcLL->count == 0)/*Last Node in DedicateLCList to be deleted*/
420 /*Free the Dedicated LC Info structure*/
421 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
427 lcLL = &(ueCb->dlLcPrbEst.defLcList);
428 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
430 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
431 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
433 }/*End of DL LC ctxt*/
436 SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
437 SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
439 }/* End of outer for loop */
443 /*******************************************************************
445 * @brief Function to get SCH Cell Cb
449 * Function : getSchCellCb
451 * Functionality: Function to get SCH Cell Cb
453 * @params[in] event, SchUeCfg pointer
454 * @return schUeCb pointer - success
457 * ****************************************************************/
459 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
462 SchCellCb *cellCb = NULLP;
464 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
466 /* Search of cell cb */
467 for(idx = 0; idx < MAX_NUM_CELL; idx++)
469 cellCb = schCb[inst].cells[idx];
470 if(cellCb->cellId == ueCfg->cellId)
473 if(idx == MAX_NUM_CELL)
475 DU_LOG("\nERROR --> SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
476 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
480 /* Check if max number of UE configured */
481 if(cellCb->numActvUe > MAX_NUM_UE)
483 DU_LOG("\nERROR --> SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
484 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
491 /*******************************************************************
493 * @brief Function to Add Ue Config Request from MAC
497 * Function : MacSchAddUeConfigReq
499 * Functionality: Function to Add Ue config request from MAC
502 * @return ROK - success
505 * ****************************************************************/
506 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
508 uint8_t ueId, lcIdx, ret = ROK;
509 SchCellCb *cellCb = NULLP;
510 SchUeCb *ueCb = NULLP;
512 Inst inst = pst->dstInst - SCH_INST_START;
513 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
515 #ifdef CALL_FLOW_DEBUG_LOG
516 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_ADD_UE_CONFIG_REQ_TO_SCH\n");
521 DU_LOG("\nERROR --> SCH : Adding UE Config Request failed at MacSchAddUeConfigReq()");
524 DU_LOG("\nDEBUG --> SCH : Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
525 cellCb = getSchCellCb(pst->event, inst, ueCfg);
527 /* Search if UE already configured */
530 GET_UE_ID(ueCfg->crnti, ueId);
531 ueCb = &cellCb->ueCb[ueId -1];
534 ueCb = &cellCb->hoUeCb[ueCfg->duUeF1apId - 1];
536 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
538 DU_LOG("\nDEBUG --> SCH : CRNTI %d already configured ", ueCfg->crnti);
539 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
543 /* Fill received Ue Configuration in UeCb */
544 memset(ueCb, 0, sizeof(SchUeCb));
546 ueCb->crnti = ueCfg->crnti;
548 ueCb->state = SCH_UE_STATE_ACTIVE;
550 ueCb->state = SCH_UE_HANDIN_IN_PROGRESS;
552 ret = fillSchUeCb(inst, ueCb, ueCfg);
555 if(ueCb->state == SCH_UE_STATE_ACTIVE)
558 SET_ONE_BIT(ueCb->ueId, cellCb->actvUeBitMap);
560 ueCb->cellCb = cellCb;
561 ueCb->srRcvd = false;
562 ueCb->bsrRcvd = false;
563 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
564 ueCb->bsrInfo[lcIdx].dataVol = 0;
566 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
571 /*******************************************************************
573 * @brief Fills PUSCH UL allocation
577 * Function : schFillPuschAlloc
579 * Functionality: fills PUSCH info
582 * @return ROK - success
585 * ****************************************************************/
586 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize,
587 uint8_t startSymb, uint8_t symbLen, uint16_t startPrb)
590 SchCellCb *cellCb = NULLP;
591 SchUlSlotInfo *schUlSlotInfo = NULLP;
592 SchPuschInfo puschInfo;
596 DU_LOG("\nERROR --> SCH: UE CB is empty");
600 cellCb = ueCb->cellCb;
603 DU_LOG("\nERROR --> SCH: CELL CB is empty");
607 tbSize += UL_TX_BUFFER_SIZE; /* 2 bytes header + some buffer */
608 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
609 allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startPrb, numRb);
611 puschInfo.crnti = ueCb->crnti;
612 puschInfo.harqProcId = SCH_HARQ_PROC_ID;
613 puschInfo.resAllocType = SCH_ALLOC_TYPE_1;
614 puschInfo.fdAlloc.startPrb = startPrb;
615 puschInfo.fdAlloc.numPrb = numRb;
616 puschInfo.tdAlloc.startSymb = startSymb;
617 puschInfo.tdAlloc.numSymb = symbLen;
618 puschInfo.tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
619 puschInfo.tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
620 puschInfo.tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
621 puschInfo.tbInfo.ndi = 1; /* new transmission */
622 puschInfo.tbInfo.rv = 0;
623 puschInfo.tbInfo.tbSize = tbSize;
624 puschInfo.dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
625 puschInfo.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
626 puschInfo.dmrsAddPos = DMRS_ADDITIONAL_POS;
628 schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
629 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
630 if(!schUlSlotInfo->schPuschInfo)
632 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
635 memcpy(schUlSlotInfo->schPuschInfo, &puschInfo, sizeof(SchPuschInfo));
640 /*******************************************************************
642 * @brief Fills DCI for UL grant
646 * Function : schFillUlDci
648 * Functionality: fills DCI for UL grant in response to BSR
651 * @return ROK - success
654 * ****************************************************************/
655 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo)
657 SchCellCb *cellCb = ueCb->cellCb;
658 SchControlRsrcSet coreset1 ;
660 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
661 if(ueCb->ueCfg.spCellCfgPres == true)
663 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
666 dciInfo->cellId = cellCb->cellId;
667 dciInfo->crnti = ueCb->crnti;
670 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
671 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
672 dciInfo->bwpCfg.freqAlloc.startPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb;
673 dciInfo->bwpCfg.freqAlloc.numPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb;
675 /*fill coreset cfg */
676 //Considering number of RBs in coreset1 is same as coreset0
677 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
678 //Considering coreset1 also starts from same symbol as coreset0
679 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
680 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
681 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
683 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
684 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
685 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
686 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
687 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
688 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
689 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
690 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
692 dciInfo->formatType = FORMAT0_0;
695 dciInfo->format.format0_0.resourceAllocType = puschInfo->resAllocType;
696 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo->fdAlloc.startPrb;
697 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo->fdAlloc.numPrb;
698 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo->tdAlloc.startSymb;
699 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo->tdAlloc.numSymb;
700 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
701 dciInfo->format.format0_0.mcs = puschInfo->tbInfo.mcs;
702 dciInfo->format.format0_0.harqProcId = puschInfo->harqProcId;
703 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
704 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
705 dciInfo->format.format0_0.ndi = puschInfo->tbInfo.ndi; /* new transmission */
706 dciInfo->format.format0_0.rv = puschInfo->tbInfo.rv;
707 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
708 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
710 /* Fill DCI Structure */
711 dciInfo->dciInfo.rnti = ueCb->crnti;
712 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
713 dciInfo->dciInfo.scramblingRnti = 0;
714 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
715 dciInfo->dciInfo.aggregLevel = 4;
716 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
717 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
718 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
719 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
720 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
721 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
722 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
723 dciInfo->dciInfo.pdschCfg = NULL; /* No DL data being sent */
728 /*******************************************************************
730 * @brief Function to Modify Ue Config request from MAC
734 * Function : MacSchModUeConfigReq
736 * Functionality: Function to modify Ue Config request from MAC
739 * @return ROK - success
742 * ****************************************************************/
743 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
745 uint8_t ueId, lcIdx, ret = ROK;
746 SchCellCb *cellCb = NULLP;
747 SchUeCb *ueCb = NULLP;
749 Inst inst = pst->dstInst - SCH_INST_START;
750 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
752 #ifdef CALL_FLOW_DEBUG_LOG
753 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
758 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
761 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
762 cellCb = getSchCellCb(pst->event, inst, ueCfg);
764 /* Search if UE already configured */
765 GET_UE_ID(ueCfg->crnti, ueId);
766 ueCb = &cellCb->ueCb[ueId -1];
770 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
771 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
774 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
776 /* Found the UeCb to Reconfig */
777 ret = fillSchUeCb(inst, ueCb, ueCfg);
780 ueCb->cellCb = cellCb;
781 ueCb->srRcvd = false;
782 ueCb->bsrRcvd = false;
783 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
784 ueCb->bsrInfo[lcIdx].dataVol = 0;
786 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
792 /*******************************************************************
794 * @brief Fill and send UE delete response to MAC
798 * Function : SchSendUeDeleteRspToMac
800 * Functionality: Fill and send UE delete response to MAC
802 * @params[in] Inst inst, SchUeDelete *ueDelete, SchMacRsp result,
804 * @return ROK - success
807 * ****************************************************************/
808 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete *ueDelete, SchMacRsp result, ErrorCause cause)
811 SchUeDeleteRsp delRsp;
813 memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
814 delRsp.cellId = ueDelete->cellId;
815 delRsp.crnti = ueDelete->crnti;
817 delRsp.cause = cause;
819 /* Filling response post */
820 memset(&rspPst, 0, sizeof(Pst));
821 FILL_PST_SCH_TO_MAC(rspPst, inst);
822 rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
823 SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
826 /*******************************************************************
828 * @brief Function to delete Sch Pucch ResrcCfg
832 * Function : deleteSchPucchResrcCfg
834 * Functionality: Function to delete Sch Pucch ResrcCfg
836 * @params[in] SchPucchResrcCfg *resrc
839 * ****************************************************************/
841 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
844 for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
846 switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
850 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
851 sizeof(SchPucchFormat0));
856 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
857 sizeof(SchPucchFormat1));
862 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
863 sizeof(SchPucchFormat2_3));
868 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
869 sizeof(SchPucchFormat2_3));
874 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
875 sizeof(SchPucchFormat4));
882 /*******************************************************************
884 * @brief Function to delete SCH Pdsch ServCellCfg
888 * Function : deleteSchPdschServCellCfg
890 * Functionality: Function to delete SCH Pdsch ServCellCfg
892 * @params[in] SchPdschServCellCfg *pdschServCellCfg
895 * ****************************************************************/
897 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
899 SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
900 SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
901 SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
902 SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
905 /*******************************************************************
907 * @brief Function to delete SCH UeCb
911 * Function : deleteSchUeCb
913 * Functionality: Function to delete SCH UeCb
916 * @return ROK - success
919 * ****************************************************************/
920 void deleteSchUeCb(SchUeCb *ueCb)
922 uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
923 SchPucchCfg *pucchCfg = NULLP;
924 SchPdschConfig *pdschCfg = NULLP;
925 CmLListCp *lcLL = NULLP;
929 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
930 if(ueCb->ueCfg.spCellCfgPres)
932 if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
934 pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
935 for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
936 SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
939 if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
941 pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
942 SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
945 deleteSchPucchResrcCfg(pucchCfg->resrc);
946 SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
948 SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
949 SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
950 SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
951 SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
952 SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
953 SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
954 SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
955 SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
956 SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
958 SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
959 deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
961 /*Need to Free the memory allocated for S-NSSAI*/
962 for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
964 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
965 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
968 /*Clearing out Dedicated LC list*/
969 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
971 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
973 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
975 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
977 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
979 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
981 /*Deleteing the Default LC list*/
982 lcLL = &(ueCb->dlLcPrbEst.defLcList);
985 lcLL = &(ueCb->ulLcPrbEst.defLcList);
988 memset(ueCb, 0, sizeof(SchUeCb));
992 /*******************************************************************
994 * @brief Function for Ue Delete request from MAC to SCH
998 * Function : MacSchUeDeleteReq
1000 * Functionality: Function for Ue Delete request from MAC to SCH
1002 * @params[in] Pst *pst, SchUeDelete *ueDelete
1003 * @return ROK - success
1006 * ****************************************************************/
1007 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete *ueDelete)
1009 uint8_t idx=0, ueId=0, ueIdToDel=0, ret=ROK;
1011 SchCellCb *cellCb = NULLP;
1012 Inst inst = pst->dstInst - SCH_INST_START;
1013 CmLList *node = NULL, *next = NULL;
1015 #ifdef CALL_FLOW_DEBUG_LOG
1016 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
1021 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): Ue Delete request failed");
1024 DU_LOG("\nDEBUG --> SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1026 cellCb = schCb[inst].cells[idx];
1028 if(cellCb->cellId != ueDelete->cellId)
1030 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): cell Id is not available");
1031 result = INVALID_CELLID;
1035 GET_UE_ID(ueDelete->crnti, ueId);
1036 if(( cellCb->ueCb[ueId-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueId-1].state == SCH_UE_STATE_ACTIVE))
1038 deleteSchUeCb(&cellCb->ueCb[ueId-1]);
1040 /* Remove UE from ueToBeScheduled list */
1041 node = cellCb->ueToBeScheduled.first;
1045 ueId = *(uint8_t *)node->node;
1046 if(ueId == ueIdToDel)
1048 SCH_FREE(node->node, sizeof(uint8_t));
1049 deleteNodeFromLList(&cellCb->ueToBeScheduled, node);
1054 cellCb->numActvUe--;
1055 result = NOT_APPLICABLE;
1059 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): SchUeCb not found");
1060 result = INVALID_UEID;
1064 if(result == NOT_APPLICABLE)
1066 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
1070 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
1076 /*******************************************************************
1078 * @brief Fill and send Cell delete response to MAC
1082 * Function : SchSendCellDeleteRspToMac
1084 * Functionality: Fill and send Cell delete response to MAC
1086 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
1087 * @return ROK - success
1090 * ****************************************************************/
1091 uint8_t SchSendCellDeleteRspToMac(SchCellDelete *ueDelete, Inst inst, SchMacRsp result)
1096 SchCellDeleteRsp delRsp;
1098 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
1099 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1100 delRsp.cellId = ueDelete->cellId;
1101 delRsp.rsp = result;
1103 /* Filling response post */
1104 memset(&rspPst, 0, sizeof(Pst));
1105 FILL_PST_SCH_TO_MAC(rspPst, inst);
1106 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1107 ret = SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1110 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1116 /*******************************************************************
1118 * @brief Function for cellCb Deletion
1122 * Function : deleteSchCellCb
1124 * Functionality: Function for cellCb Deletion
1126 * @params[in] SchCellDelete *cellDelete
1127 * @return ROK - success
1130 * ****************************************************************/
1131 void deleteSchCellCb(SchCellCb *cellCb)
1133 uint8_t sliceIdx=0, slotIdx=0;
1134 CmLListCp *list=NULL;
1135 CmLList *node=NULL, *next=NULL;
1137 if(cellCb->schDlSlotInfo)
1139 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1141 list = &cellCb->schDlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1146 SCH_FREE(node->node, sizeof(FreePrbBlock));
1147 deleteNodeFromLList(list, node);
1150 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1152 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1155 if(cellCb->schUlSlotInfo)
1157 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1159 list = &cellCb->schUlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1164 SCH_FREE(node->node, sizeof(FreePrbBlock));
1165 deleteNodeFromLList(list, node);
1168 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
1170 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
1173 if(cellCb->cellCfg.plmnInfoList.snssai)
1175 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.plmnInfoList.numSliceSupport; sliceIdx++)
1177 SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
1179 SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai, cellCb->cellCfg.plmnInfoList.numSliceSupport*sizeof(Snssai*));
1182 /* Remove all UE from ueToBeScheduled list and deallocate */
1183 node = cellCb->ueToBeScheduled.first;
1187 SCH_FREE(node->node, sizeof(uint8_t));
1188 cmLListDelFrm(&cellCb->ueToBeScheduled, node);
1189 SCH_FREE(node, sizeof(CmLList));
1193 memset(cellCb, 0, sizeof(SchCellCb));
1197 /*******************************************************************
1199 * @brief Function for cell Delete request from MAC to SCH
1203 * Function : MacSchCellDeleteReq
1205 * Functionality: Function for cell Delete request from MAC to SCH
1207 * @params[in] Pst *pst, SchCellDelete *cellDelete
1208 * @return ROK - success
1211 * ****************************************************************/
1213 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete *cellDelete)
1215 uint8_t cellIdx=0, ret = RFAILED;
1216 Inst inst = pst->dstInst - SCH_INST_START;
1217 SchMacRsp result= RSP_OK;
1219 #ifdef CALL_FLOW_DEBUG_LOG
1220 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1225 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1229 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1230 if(schCb[inst].cells[cellIdx] == NULLP)
1232 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1237 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1239 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1242 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1243 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1247 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1252 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1254 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1262 /**********************************************************************
1264 **********************************************************************/