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->crnti = ueCfg->crnti;
76 GET_UE_ID(ueCfg->crnti, cfgRsp->ueId);
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.crnti = ueCfg->crnti;
263 if(ueCfg->macCellGrpCfgPres == true)
265 memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg));
266 ueCb->ueCfg.macCellGrpCfgPres = true;
269 if(ueCfg->phyCellGrpCfgPres == true)
271 memcpy(&ueCb->ueCfg.phyCellGrpCfg , &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
272 ueCb->ueCfg.phyCellGrpCfgPres = true;
275 if(ueCfg->spCellCfgPres == true)
277 memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
279 covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
281 memset(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
282 memcpy(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
284 ueCb->ueCfg.spCellCfgPres = true;
285 dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
290 BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
291 ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
292 dlDataToUlAck->dlDataToUlAckList);
293 ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1TblPrsnt = true;
294 BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
295 ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
296 NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
297 ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt = true;
302 ueCb->state = SCH_UE_STATE_ACTIVE;
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 */
528 GET_UE_ID(ueCfg->crnti, ueId);
529 ueCb = &cellCb->ueCb[ueId -1];
532 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
534 DU_LOG("\nDEBUG --> SCH : CRNTI %d already configured ", ueCfg->crnti);
535 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
541 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
542 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
546 /* Fill received Ue Configuration in UeCb */
547 memset(ueCb, 0, sizeof(SchUeCb));
549 ueCb->crnti = ueCfg->crnti;
550 ueCb->state = SCH_UE_STATE_ACTIVE;
551 ret = fillSchUeCb(inst, ueCb, ueCfg);
555 SET_ONE_BIT(ueCb->ueId, cellCb->actvUeBitMap);
556 ueCb->cellCb = cellCb;
557 ueCb->srRcvd = false;
558 ueCb->bsrRcvd = false;
559 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
560 ueCb->bsrInfo[lcIdx].dataVol = 0;
562 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
567 /*******************************************************************
569 * @brief Fills PUSCH UL allocation
573 * Function : schFillPuschAlloc
575 * Functionality: fills PUSCH info
578 * @return ROK - success
581 * ****************************************************************/
582 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize,
583 uint8_t startSymb, uint8_t symbLen, uint16_t startPrb)
586 SchCellCb *cellCb = NULLP;
587 SchUlSlotInfo *schUlSlotInfo = NULLP;
588 SchPuschInfo puschInfo;
592 DU_LOG("\nERROR --> SCH: UE CB is empty");
596 cellCb = ueCb->cellCb;
599 DU_LOG("\nERROR --> SCH: CELL CB is empty");
603 tbSize += UL_TX_BUFFER_SIZE; /* 2 bytes header + some buffer */
604 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
605 allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startPrb, numRb);
607 puschInfo.crnti = ueCb->crnti;
608 puschInfo.harqProcId = SCH_HARQ_PROC_ID;
609 puschInfo.resAllocType = SCH_ALLOC_TYPE_1;
610 puschInfo.fdAlloc.startPrb = startPrb;
611 puschInfo.fdAlloc.numPrb = numRb;
612 puschInfo.tdAlloc.startSymb = startSymb;
613 puschInfo.tdAlloc.numSymb = symbLen;
614 puschInfo.tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
615 puschInfo.tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
616 puschInfo.tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
617 puschInfo.tbInfo.ndi = 1; /* new transmission */
618 puschInfo.tbInfo.rv = 0;
619 puschInfo.tbInfo.tbSize = tbSize;
620 puschInfo.dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
621 puschInfo.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
622 puschInfo.dmrsAddPos = DMRS_ADDITIONAL_POS;
624 schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
625 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
626 if(!schUlSlotInfo->schPuschInfo)
628 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
631 memcpy(schUlSlotInfo->schPuschInfo, &puschInfo, sizeof(SchPuschInfo));
636 /*******************************************************************
638 * @brief Fills DCI for UL grant
642 * Function : schFillUlDci
644 * Functionality: fills DCI for UL grant in response to BSR
647 * @return ROK - success
650 * ****************************************************************/
651 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo)
653 SchCellCb *cellCb = ueCb->cellCb;
654 SchControlRsrcSet coreset1 ;
656 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
657 if(ueCb->ueCfg.spCellCfgPres == true)
659 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
662 dciInfo->cellId = cellCb->cellId;
663 dciInfo->crnti = ueCb->crnti;
666 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
667 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
668 dciInfo->bwpCfg.freqAlloc.startPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb;
669 dciInfo->bwpCfg.freqAlloc.numPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb;
671 /*fill coreset cfg */
672 //Considering number of RBs in coreset1 is same as coreset0
673 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
674 //Considering coreset1 also starts from same symbol as coreset0
675 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
676 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
677 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
679 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
680 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
681 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
682 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
683 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
684 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
685 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
686 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
688 dciInfo->formatType = FORMAT0_0;
691 dciInfo->format.format0_0.resourceAllocType = puschInfo->resAllocType;
692 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo->fdAlloc.startPrb;
693 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo->fdAlloc.numPrb;
694 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo->tdAlloc.startSymb;
695 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo->tdAlloc.numSymb;
696 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
697 dciInfo->format.format0_0.mcs = puschInfo->tbInfo.mcs;
698 dciInfo->format.format0_0.harqProcId = puschInfo->harqProcId;
699 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
700 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
701 dciInfo->format.format0_0.ndi = puschInfo->tbInfo.ndi; /* new transmission */
702 dciInfo->format.format0_0.rv = puschInfo->tbInfo.rv;
703 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
704 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
706 /* Fill DCI Structure */
707 dciInfo->dciInfo.rnti = ueCb->crnti;
708 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
709 dciInfo->dciInfo.scramblingRnti = 0;
710 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
711 dciInfo->dciInfo.aggregLevel = 4;
712 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
713 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
714 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
715 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
716 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
717 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
718 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
719 dciInfo->dciInfo.pdschCfg = NULL; /* No DL data being sent */
724 /*******************************************************************
726 * @brief Function to Modify Ue Config request from MAC
730 * Function : MacSchModUeConfigReq
732 * Functionality: Function to modify Ue Config request from MAC
735 * @return ROK - success
738 * ****************************************************************/
739 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
741 uint8_t ueId, lcIdx, ret = ROK;
742 SchCellCb *cellCb = NULLP;
743 SchUeCb *ueCb = NULLP;
745 Inst inst = pst->dstInst - SCH_INST_START;
746 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
748 #ifdef CALL_FLOW_DEBUG_LOG
749 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
754 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
757 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
758 cellCb = getSchCellCb(pst->event, inst, ueCfg);
760 /* Search if UE already configured */
761 GET_UE_ID(ueCfg->crnti, ueId);
762 ueCb = &cellCb->ueCb[ueId -1];
766 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
767 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
770 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
772 /* Found the UeCb to Reconfig */
773 ret = fillSchUeCb(inst, ueCb, ueCfg);
776 ueCb->cellCb = cellCb;
777 ueCb->srRcvd = false;
778 ueCb->bsrRcvd = false;
779 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
780 ueCb->bsrInfo[lcIdx].dataVol = 0;
782 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
788 /*******************************************************************
790 * @brief Fill and send UE delete response to MAC
794 * Function : SchSendUeDeleteRspToMac
796 * Functionality: Fill and send UE delete response to MAC
798 * @params[in] Inst inst, SchUeDelete *ueDelete, SchMacRsp result,
800 * @return ROK - success
803 * ****************************************************************/
804 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete *ueDelete, SchMacRsp result, ErrorCause cause)
807 SchUeDeleteRsp delRsp;
809 memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
810 delRsp.cellId = ueDelete->cellId;
811 delRsp.crnti = ueDelete->crnti;
813 delRsp.cause = cause;
815 /* Filling response post */
816 memset(&rspPst, 0, sizeof(Pst));
817 FILL_PST_SCH_TO_MAC(rspPst, inst);
818 rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
819 SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
822 /*******************************************************************
824 * @brief Function to delete Sch Pucch ResrcCfg
828 * Function : deleteSchPucchResrcCfg
830 * Functionality: Function to delete Sch Pucch ResrcCfg
832 * @params[in] SchPucchResrcCfg *resrc
835 * ****************************************************************/
837 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
840 for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
842 switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
846 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
847 sizeof(SchPucchFormat0));
852 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
853 sizeof(SchPucchFormat1));
858 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
859 sizeof(SchPucchFormat2_3));
864 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
865 sizeof(SchPucchFormat2_3));
870 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
871 sizeof(SchPucchFormat4));
878 /*******************************************************************
880 * @brief Function to delete SCH Pdsch ServCellCfg
884 * Function : deleteSchPdschServCellCfg
886 * Functionality: Function to delete SCH Pdsch ServCellCfg
888 * @params[in] SchPdschServCellCfg *pdschServCellCfg
891 * ****************************************************************/
893 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
895 SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
896 SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
897 SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
898 SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
901 /*******************************************************************
903 * @brief Function to delete SCH UeCb
907 * Function : deleteSchUeCb
909 * Functionality: Function to delete SCH UeCb
912 * @return ROK - success
915 * ****************************************************************/
916 void deleteSchUeCb(SchUeCb *ueCb)
918 uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
919 SchPucchCfg *pucchCfg = NULLP;
920 SchPdschConfig *pdschCfg = NULLP;
921 CmLListCp *lcLL = NULLP;
925 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
926 if(ueCb->ueCfg.spCellCfgPres)
928 if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
930 pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
931 for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
932 SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
935 if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
937 pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
938 SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
941 deleteSchPucchResrcCfg(pucchCfg->resrc);
942 SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
944 SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
945 SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
946 SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
947 SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
948 SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
949 SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
950 SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
951 SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
952 SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
954 SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
955 deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
957 /*Need to Free the memory allocated for S-NSSAI*/
958 for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
960 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
961 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
964 /*Clearing out Dedicated LC list*/
965 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
967 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
969 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
971 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
973 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
975 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
977 /*Deleteing the Default LC list*/
978 lcLL = &(ueCb->dlLcPrbEst.defLcList);
981 lcLL = &(ueCb->ulLcPrbEst.defLcList);
984 memset(ueCb, 0, sizeof(SchUeCb));
988 /*******************************************************************
990 * @brief Function for Ue Delete request from MAC to SCH
994 * Function : MacSchUeDeleteReq
996 * Functionality: Function for Ue Delete request from MAC to SCH
998 * @params[in] Pst *pst, SchUeDelete *ueDelete
999 * @return ROK - success
1002 * ****************************************************************/
1003 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete *ueDelete)
1005 uint8_t idx=0, ueId=0, ueIdToDel=0, ret=ROK;
1007 SchCellCb *cellCb = NULLP;
1008 Inst inst = pst->dstInst - SCH_INST_START;
1009 CmLList *node = NULL, *next = NULL;
1011 #ifdef CALL_FLOW_DEBUG_LOG
1012 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
1017 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): Ue Delete request failed");
1020 DU_LOG("\nDEBUG --> SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1022 cellCb = schCb[inst].cells[idx];
1024 if(cellCb->cellId != ueDelete->cellId)
1026 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): cell Id is not available");
1027 result = INVALID_CELLID;
1031 GET_UE_ID(ueDelete->crnti, ueId);
1032 if(( cellCb->ueCb[ueId-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueId-1].state == SCH_UE_STATE_ACTIVE))
1034 deleteSchUeCb(&cellCb->ueCb[ueId-1]);
1036 /* Remove UE from ueToBeScheduled list */
1037 node = cellCb->ueToBeScheduled.first;
1041 ueId = *(uint8_t *)node->node;
1042 if(ueId == ueIdToDel)
1044 SCH_FREE(node->node, sizeof(uint8_t));
1045 deleteNodeFromLList(&cellCb->ueToBeScheduled, node);
1050 cellCb->numActvUe--;
1051 result = NOT_APPLICABLE;
1055 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): SchUeCb not found");
1056 result = INVALID_UEID;
1060 if(result == NOT_APPLICABLE)
1062 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
1066 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
1072 /*******************************************************************
1074 * @brief Fill and send Cell delete response to MAC
1078 * Function : SchSendCellDeleteRspToMac
1080 * Functionality: Fill and send Cell delete response to MAC
1082 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
1083 * @return ROK - success
1086 * ****************************************************************/
1087 uint8_t SchSendCellDeleteRspToMac(SchCellDelete *ueDelete, Inst inst, SchMacRsp result)
1092 SchCellDeleteRsp delRsp;
1094 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
1095 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1096 delRsp.cellId = ueDelete->cellId;
1097 delRsp.rsp = result;
1099 /* Filling response post */
1100 memset(&rspPst, 0, sizeof(Pst));
1101 FILL_PST_SCH_TO_MAC(rspPst, inst);
1102 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1103 ret = SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1106 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1112 /*******************************************************************
1114 * @brief Function for cellCb Deletion
1118 * Function : deleteSchCellCb
1120 * Functionality: Function for cellCb Deletion
1122 * @params[in] SchCellDelete *cellDelete
1123 * @return ROK - success
1126 * ****************************************************************/
1127 void deleteSchCellCb(SchCellCb *cellCb)
1129 uint8_t sliceIdx=0, slotIdx=0;
1130 CmLListCp *list=NULL;
1131 CmLList *node=NULL, *next=NULL;
1133 if(cellCb->schDlSlotInfo)
1135 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1137 list = &cellCb->schDlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1142 SCH_FREE(node->node, sizeof(FreePrbBlock));
1143 deleteNodeFromLList(list, node);
1146 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1148 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1151 if(cellCb->schUlSlotInfo)
1153 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1155 list = &cellCb->schUlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1160 SCH_FREE(node->node, sizeof(FreePrbBlock));
1161 deleteNodeFromLList(list, node);
1164 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
1166 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
1169 if(cellCb->cellCfg.plmnInfoList.snssai)
1171 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.plmnInfoList.numSliceSupport; sliceIdx++)
1173 SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
1175 SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai, cellCb->cellCfg.plmnInfoList.numSliceSupport*sizeof(Snssai*));
1178 /* Remove all UE from ueToBeScheduled list and deallocate */
1179 node = cellCb->ueToBeScheduled.first;
1183 SCH_FREE(node->node, sizeof(uint8_t));
1184 cmLListDelFrm(&cellCb->ueToBeScheduled, node);
1185 SCH_FREE(node, sizeof(CmLList));
1189 memset(cellCb, 0, sizeof(SchCellCb));
1193 /*******************************************************************
1195 * @brief Function for cell Delete request from MAC to SCH
1199 * Function : MacSchCellDeleteReq
1201 * Functionality: Function for cell Delete request from MAC to SCH
1203 * @params[in] Pst *pst, SchCellDelete *cellDelete
1204 * @return ROK - success
1207 * ****************************************************************/
1209 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete *cellDelete)
1211 uint8_t cellIdx=0, ret = RFAILED;
1212 Inst inst = pst->dstInst - SCH_INST_START;
1213 SchMacRsp result= RSP_OK;
1215 #ifdef CALL_FLOW_DEBUG_LOG
1216 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1221 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1225 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1226 if(schCb[inst].cells[cellIdx] == NULLP)
1228 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1233 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1235 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1238 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1239 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1243 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1248 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1250 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1258 /**********************************************************************
1260 **********************************************************************/