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 */
41 /*******************************************************************
43 * @brief Fill and send UE cfg response to MAC
47 * Function : SchSendUeCfgRspToMac
49 * Functionality: Fill and send UE cfg response to MAC
52 * @return ROK - success
55 * ****************************************************************/
56 void SchSendUeCfgRspToMac(uint16_t event, SchUeCfg *ueCfg, Inst inst,\
57 SchMacRsp result, SchUeCfgRsp *cfgRsp)
61 cfgRsp->cellId = ueCfg->cellId;
62 cfgRsp->crnti = ueCfg->crnti;
63 GET_UE_IDX(ueCfg->crnti, cfgRsp->ueIdx);
66 /* Filling response post */
67 memset(&rspPst, 0, sizeof(Pst));
68 FILL_PST_SCH_TO_MAC(rspPst, inst);
69 if(event == EVENT_ADD_UE_CONFIG_REQ_TO_SCH)
71 rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
72 DU_LOG("\nINFO --> SCH : Sending UE Config response to MAC");
74 else if(event == EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH)
76 rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
77 DU_LOG("\nINFO --> SCH : Sending UE Reconfig response to MAC");
79 SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
82 /*******************************************************************
85 * @brief Function to fill Dl Lc Context in SCH Ue Cb
89 * Function : fillSchDlLcCtxt
91 * Functionality: Function to fill Dl Lc Context in SCH Ue Cb
93 * @params[in] SchDlLcCtxt pointer,
97 * ****************************************************************/
99 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
101 ueCbLcCfg->lcId = lcCfg->lcId;
102 ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
103 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
107 /*******************************************************************
109 * @brief Function to fill Ul Lc Context in SCH Ue Cb
113 * Function : fillSchUlLcCtxt
115 * Functionality: Function to fill Ul Lc Context in SCH Ue Cb
117 * @params[in] SchUlLcCtxt pointer,
121 * ****************************************************************/
123 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
125 ueCbLcCfg->lcId = lcCfg->lcId;
126 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
127 ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
128 ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
129 ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
130 ueCbLcCfg->pbr = lcCfg->ulLcCfg.pbr;
131 ueCbLcCfg->bsd = lcCfg->ulLcCfg.bsd;
135 /*******************************************************************
137 * @brief Function to update Sch Ul Lc Cb
141 * Function : updateSchUlCb
143 * Functionality: Function to update SCH Ul Lc Cb
147 * ****************************************************************/
149 void updateSchUlCb(uint8_t delIdx, SchUlCb *ulInfo)
153 for(lcIdx = delIdx; lcIdx < ulInfo->numUlLc; lcIdx++)
155 memcpy(&ulInfo->ulLcCtxt[lcIdx], &ulInfo->ulLcCtxt[lcIdx+1], sizeof(SchUlLcCtxt));
156 memset(&ulInfo->ulLcCtxt[lcIdx+1], 0, sizeof(SchUlLcCtxt));
160 /*******************************************************************
162 * @brief Function to update SCH Dl Lc Cb
166 * Function : updateSchDlCb
168 * Functionality: Function to update SCH DL Lc Cb
172 * ****************************************************************/
174 void updateSchDlCb(uint8_t delIdx, SchDlCb *dlInfo)
178 for(lcIdx = delIdx; lcIdx < dlInfo->numDlLc; lcIdx++)
180 memcpy(&dlInfo->dlLcCtxt[lcIdx], &dlInfo->dlLcCtxt[lcIdx+1], sizeof(SchDlLcCtxt));
181 memset(&dlInfo->dlLcCtxt[lcIdx+1], 0, sizeof(SchDlLcCtxt));
185 /*******************************************************************
187 * @brief Function to fill SchUeCb
191 * Function : fillSchUeCb
193 * Functionality: Function to fill SchUeCb
195 * @params[in] SchUeCb pointer,
197 * @return ROK/RFAILED
199 * ****************************************************************/
201 uint8_t fillSchUeCb(SchUeCb *ueCb, SchUeCfg *ueCfg)
203 uint8_t lcIdx, ueLcIdx;
205 ueCb->ueCfg.cellId = ueCfg->cellId;
206 ueCb->ueCfg.crnti = ueCfg->crnti;
207 if(ueCfg->macCellGrpCfgPres == true)
209 memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg));
210 ueCb->ueCfg.macCellGrpCfgPres = true;
213 if(ueCfg->phyCellGrpCfgPres == true)
215 memcpy(&ueCb->ueCfg.phyCellGrpCfg , &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
216 ueCb->ueCfg.phyCellGrpCfgPres = true;
219 if(ueCfg->spCellCfgPres == true)
221 memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
222 ueCb->ueCfg.spCellCfgPres = true;
224 ueCb->state = SCH_UE_STATE_ACTIVE;
225 if(ueCfg->ambrCfg != NULLP)
227 SCH_ALLOC(ueCb->ueCfg.ambrCfg , sizeof(SchAmbrCfg));
228 memcpy(&ueCb->ueCfg.ambrCfg->ulBr , &ueCfg->ambrCfg->ulBr, sizeof(SchAmbrCfg));
231 memcpy(&ueCb->ueCfg.dlModInfo, &ueCfg->dlModInfo , sizeof(SchModulationInfo));
232 memcpy(&ueCb->ueCfg.ulModInfo, &ueCfg->ulModInfo , sizeof(SchModulationInfo));
234 //Updating SchUlCb and SchDlCb DB in SchUeCb
235 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
237 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
239 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueCb->ulInfo.numUlLc], &ueCfg->schLcCfg[lcIdx]);
240 ueCb->ulInfo.numUlLc++;
241 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueCb->dlInfo.numDlLc], &ueCfg->schLcCfg[lcIdx]);
242 ueCb->dlInfo.numDlLc++;
246 for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++) //searching for Lc to be Mod
248 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
250 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
252 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
253 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
256 if(ueCfg->schLcCfg[ueLcIdx].configType == CONFIG_DEL)
258 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
259 ueCb->ulInfo.numUlLc--;
260 updateSchUlCb(ueLcIdx, &ueCb->ulInfo); //moving arr elements one idx ahead
261 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
262 ueCb->dlInfo.numDlLc--;
263 updateSchDlCb(ueLcIdx, &ueCb->dlInfo); //moving arr elements one idx ahead
267 }/*End of inner for loop */
269 }/* End of outer for loop */
273 /*******************************************************************
275 * @brief Function to get SCH Cell Cb
279 * Function : getSchCellCb
281 * Functionality: Function to get SCH Cell Cb
283 * @params[in] event, SchUeCfg pointer
284 * @return schUeCb pointer - success
287 * ****************************************************************/
289 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
292 SchCellCb *cellCb = NULLP;
294 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
296 /* Search of cell cb */
297 for(idx = 0; idx < MAX_NUM_CELL; idx++)
299 cellCb = schCb[inst].cells[idx];
300 if(cellCb->cellId == ueCfg->cellId)
303 if(idx == MAX_NUM_CELL)
305 DU_LOG("\nERROR --> SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
306 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
310 /* Check if max number of UE configured */
311 if(cellCb->numActvUe > MAX_NUM_UE)
313 DU_LOG("\nERROR --> SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
314 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
321 /*******************************************************************
323 * @brief Function to Add Ue Config Request from MAC
327 * Function : MacSchAddUeConfigReq
329 * Functionality: Function to Add Ue config request from MAC
332 * @return ROK - success
335 * ****************************************************************/
336 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
338 uint8_t ueIdx, lcIdx, ret = ROK;
339 SchCellCb *cellCb = NULLP;
340 SchUeCb *ueCb = NULLP;
342 Inst inst = pst->dstInst - 1;
343 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
347 DU_LOG("\nERROR --> SCH : Adding UE Config Request failed at MacSchAddUeConfigReq()");
350 DU_LOG("\nDEBUG --> SCH : Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
351 cellCb = getSchCellCb(pst->event, inst, ueCfg);
353 /* Search if UE already configured */
354 GET_UE_IDX(ueCfg->crnti, ueIdx);
355 ueCb = &cellCb->ueCb[ueIdx -1];
358 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
360 DU_LOG("\nDEBUG --> SCH : CRNTI %d already configured ", ueCfg->crnti);
361 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
367 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
368 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
372 /* Fill received Ue Configuration in UeCb */
373 memset(ueCb, 0, sizeof(SchUeCb));
374 GET_UE_IDX(ueCfg->crnti, ueIdx);
376 ueCb->crnti = ueCfg->crnti;
377 ueCb->state = SCH_UE_STATE_ACTIVE;
378 ret = fillSchUeCb(ueCb, ueCfg);
382 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
383 ueCb->cellCb = cellCb;
384 ueCb->srRcvd = false;
385 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
386 ueCb->bsrInfo[lcIdx].dataVol = 0;
388 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
393 /*******************************************************************
395 * @brief Fills PUSCH UL allocation
399 * Function : schFillPuschAlloc
401 * Functionality: fills PUSCH info
404 * @return ROK - success
407 * ****************************************************************/
408 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo)
410 uint16_t puschSlot = 0;
411 uint16_t startRb = 0;
413 uint8_t numPdschSymbols= 14;
417 SchCellCb *cellCb = ueCb->cellCb;
418 SchUlSlotInfo *schUlSlotInfo = NULLP;
419 uint8_t k2=0, startSymb=0 , symbLen=0;
421 if(ueCb->ueCfg.spCellCfgPres == true)
423 k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
424 startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
425 symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
427 puschSlot = (pdcchSlot + k2) % cellCb->numSlots;
429 startRb = cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb;
430 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
431 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, numPdschSymbols);
432 /* increment PUSCH PRB */
434 cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb += numRb;
436 puschInfo->crnti = ueCb->crnti;
437 puschInfo->harqProcId = SCH_HARQ_PROC_ID;
438 puschInfo->resAllocType = SCH_ALLOC_TYPE_1;
439 puschInfo->fdAlloc.startPrb = startRb;
440 puschInfo->fdAlloc.numPrb = numRb;
441 puschInfo->tdAlloc.startSymb = startSymb;
442 puschInfo->tdAlloc.numSymb = symbLen;
443 puschInfo->tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
444 puschInfo->tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
445 puschInfo->tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
446 puschInfo->tbInfo.ndi = 1; /* new transmission */
447 puschInfo->tbInfo.rv = 0;
448 puschInfo->tbInfo.tbSize = tbSize;
449 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
450 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
451 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
453 /* Update pusch in cell */
454 for(idx=startSymb; idx<symbLen; idx++)
456 cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
459 schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
461 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
462 if(!schUlSlotInfo->schPuschInfo)
464 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
467 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
472 /*******************************************************************
474 * @brief Fills DCI for UL grant
478 * Function : schFillUlDci
480 * Functionality: fills DCI for UL grant in response to BSR
483 * @return ROK - success
486 * ****************************************************************/
487 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
489 SchCellCb *cellCb = ueCb->cellCb;
490 SchControlRsrcSet coreset1 ;
492 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
493 if(ueCb->ueCfg.spCellCfgPres == true)
495 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
498 dciInfo->cellId = cellCb->cellId;
499 dciInfo->crnti = ueCb->crnti;
502 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
503 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
504 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
505 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
507 /*fill coreset cfg */
508 //Considering number of RBs in coreset1 is same as coreset0
509 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
510 //Considering coreset1 also starts from same symbol as coreset0
511 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
512 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
513 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
515 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
516 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
517 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
518 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
519 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
520 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
521 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
522 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
524 dciInfo->formatType = FORMAT0_0;
527 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
528 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
529 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
530 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
531 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
532 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
533 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
534 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
535 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
536 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
537 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
538 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
539 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
540 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
542 /* Fill DCI Structure */
543 dciInfo->dciInfo.rnti = ueCb->crnti;
544 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
545 dciInfo->dciInfo.scramblingRnti = 0;
546 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
547 dciInfo->dciInfo.aggregLevel = 4;
548 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
549 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
550 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
551 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
552 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
553 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
554 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
555 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
560 /*******************************************************************
562 * @brief Function to Modify Ue Config request from MAC
566 * Function : MacSchModUeConfigReq
568 * Functionality: Function to modify Ue Config request from MAC
571 * @return ROK - success
574 * ****************************************************************/
575 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
577 uint8_t ueIdx, lcIdx, ret = ROK;
578 SchCellCb *cellCb = NULLP;
579 SchUeCb *ueCb = NULLP;
581 Inst inst = pst->dstInst - 1;
582 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
586 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
589 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
590 cellCb = getSchCellCb(pst->event, inst, ueCfg);
592 /* Search if UE already configured */
593 GET_UE_IDX(ueCfg->crnti, ueIdx);
594 ueCb = &cellCb->ueCb[ueIdx -1];
598 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
599 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
602 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
604 /* Found the UeCb to Reconfig */
605 ret = fillSchUeCb(ueCb, ueCfg);
608 ueCb->cellCb = cellCb;
609 ueCb->srRcvd = false;
610 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
611 ueCb->bsrInfo[lcIdx].dataVol = 0;
613 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
619 /**********************************************************************
621 **********************************************************************/