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("\nSCH: 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("\nSCH: 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 memset(&ueCb->ueCfg, 0, sizeof(SchUeCfg));
206 memcpy(&ueCb->ueCfg, ueCfg, sizeof(SchUeCfg));
207 ueCb->state = SCH_UE_STATE_ACTIVE;
209 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
211 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
213 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueCb->ulInfo.numUlLc], &ueCfg->schLcCfg[lcIdx]);
214 ueCb->ulInfo.numUlLc++;
215 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueCb->dlInfo.numDlLc], &ueCfg->schLcCfg[lcIdx]);
216 ueCb->dlInfo.numDlLc++;
220 for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++) //searching for Lc to be Mod
222 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
224 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
226 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
227 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
230 if(ueCfg->schLcCfg[ueLcIdx].configType == CONFIG_DEL)
232 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
233 ueCb->ulInfo.numUlLc--;
234 updateSchUlCb(ueLcIdx, &ueCb->ulInfo); //moving arr elements one idx ahead
235 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
236 ueCb->dlInfo.numDlLc--;
237 updateSchDlCb(ueLcIdx, &ueCb->dlInfo); //moving arr elements one idx ahead
241 }/*End of inner for loop */
243 }/* End of outer for loop */
247 /*******************************************************************
249 * @brief Function to get SCH Cell Cb
253 * Function : getSchCellCb
255 * Functionality: Function to get SCH Cell Cb
257 * @params[in] event, SchUeCfg pointer
258 * @return schUeCb pointer - success
261 * ****************************************************************/
263 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
266 SchCellCb *cellCb = NULLP;
268 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
270 /* Search of cell cb */
271 for(idx = 0; idx < MAX_NUM_CELL; idx++)
273 cellCb = schCb[inst].cells[idx];
274 if(cellCb->cellId == ueCfg->cellId)
277 if(idx == MAX_NUM_CELL)
279 DU_LOG("\nSCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
280 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
284 /* Check if max number of UE configured */
285 if(cellCb->numActvUe > MAX_NUM_UE)
287 DU_LOG("SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
288 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
295 /*******************************************************************
297 * @brief Function to Add Ue Config Request from MAC
301 * Function : MacSchAddUeConfigReq
303 * Functionality: Function to Add Ue config request from MAC
306 * @return ROK - success
309 * ****************************************************************/
310 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
312 uint8_t ueIdx, lcIdx, ret = ROK;
313 SchCellCb *cellCb = NULLP;
314 SchUeCb *ueCb = NULLP;
316 Inst inst = pst->dstInst - 1;
317 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
321 DU_LOG("\nSCH : Adding UE Config Request failed at MacSchAddUeConfigReq()");
324 DU_LOG("\nSCH : Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
325 cellCb = getSchCellCb(pst->event, inst, ueCfg);
327 /* Search if UE already configured */
328 GET_UE_IDX(ueCfg->crnti, ueIdx);
329 ueCb = &cellCb->ueCb[ueIdx -1];
332 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
334 DU_LOG("\n SCH : CRNTI %d already configured ", ueCfg->crnti);
335 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
341 DU_LOG("\n SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
342 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
346 /* Fill received Ue Configuration in UeCb */
347 memset(ueCb, 0, sizeof(SchUeCb));
348 GET_UE_IDX(ueCfg->crnti, ueIdx);
350 ueCb->crnti = ueCfg->crnti;
351 ueCb->state = SCH_UE_STATE_ACTIVE;
352 ret = fillSchUeCb(ueCb, ueCfg);
356 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
357 ueCb->cellCb = cellCb;
358 ueCb->srRcvd = false;
359 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
360 ueCb->bsrInfo[lcIdx].dataVol = 0;
362 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
367 /*******************************************************************
369 * @brief Fills PUSCH UL allocation
373 * Function : schFillPuschAlloc
375 * Functionality: fills PUSCH info
378 * @return ROK - success
381 * ****************************************************************/
382 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo)
384 uint16_t puschSlot = 0;
385 uint16_t startRb = 0;
387 uint8_t numPdschSymbols= 14;
391 SchCellCb *cellCb = ueCb->cellCb;
392 SchUlSlotInfo *schUlSlotInfo = NULLP;
393 uint8_t k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
394 uint8_t startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
395 uint8_t symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
397 puschSlot = (pdcchSlot + k2) % cellCb->numSlots;
399 startRb = cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb;
400 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
401 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, numPdschSymbols);
402 /* increment PUSCH PRB */
404 cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb += numRb;
406 puschInfo->crnti = ueCb->crnti;
407 puschInfo->harqProcId = SCH_HARQ_PROC_ID;
408 puschInfo->resAllocType = SCH_ALLOC_TYPE_1;
409 puschInfo->fdAlloc.startPrb = startRb;
410 puschInfo->fdAlloc.numPrb = numRb;
411 puschInfo->tdAlloc.startSymb = startSymb;
412 puschInfo->tdAlloc.numSymb = symbLen;
413 puschInfo->tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
414 puschInfo->tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
415 puschInfo->tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
416 puschInfo->tbInfo.ndi = 1; /* new transmission */
417 puschInfo->tbInfo.rv = 0;
418 puschInfo->tbInfo.tbSize = tbSize;
419 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
420 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
421 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
423 /* Update pusch in cell */
424 for(idx=startSymb; idx<symbLen; idx++)
426 cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
429 schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
431 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
432 if(!schUlSlotInfo->schPuschInfo)
434 DU_LOG("SCH: Memory allocation failed in schAllocMsg3Pusch");
437 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
442 /*******************************************************************
444 * @brief Fills DCI for UL grant
448 * Function : schFillUlDci
450 * Functionality: fills DCI for UL grant in response to BSR
453 * @return ROK - success
456 * ****************************************************************/
457 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
459 SchCellCb *cellCb = ueCb->cellCb;
460 SchControlRsrcSet coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
462 dciInfo->cellId = cellCb->cellId;
463 dciInfo->crnti = ueCb->crnti;
466 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
467 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
468 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
469 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
471 /*fill coreset cfg */
472 //Considering number of RBs in coreset1 is same as coreset0
473 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
474 //Considering coreset1 also starts from same symbol as coreset0
475 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
476 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
477 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
479 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
480 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
481 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
482 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
483 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
484 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
485 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
486 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
488 dciInfo->formatType = FORMAT0_0;
491 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
492 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
493 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
494 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
495 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
496 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
497 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
498 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
499 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
500 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
501 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
502 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
503 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
504 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
506 /* Fill DCI Structure */
507 dciInfo->dciInfo.rnti = ueCb->crnti;
508 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
509 dciInfo->dciInfo.scramblingRnti = 0;
510 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
511 dciInfo->dciInfo.aggregLevel = 4;
512 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
513 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
514 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
515 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
516 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
517 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
518 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
519 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
524 /*******************************************************************
526 * @brief Function to Modify Ue Config request from MAC
530 * Function : MacSchModUeConfigReq
532 * Functionality: Function to modify Ue Config request from MAC
535 * @return ROK - success
538 * ****************************************************************/
539 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
541 uint8_t ueIdx, lcIdx, ret = ROK;
542 SchCellCb *cellCb = NULLP;
543 SchUeCb *ueCb = NULLP;
545 Inst inst = pst->dstInst - 1;
546 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
550 DU_LOG("\nSCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
553 DU_LOG("\nSCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
554 cellCb = getSchCellCb(pst->event, inst, ueCfg);
556 /* Search if UE already configured */
557 GET_UE_IDX(ueCfg->crnti, ueIdx);
558 ueCb = &cellCb->ueCb[ueIdx -1];
562 DU_LOG("\n SCH : SchUeCb not found at MacSchModUeConfigReq() ");
563 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
566 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
568 /* Found the UeCb to Reconfig */
569 ret = fillSchUeCb(ueCb, ueCfg);
572 ueCb->cellCb = cellCb;
573 ueCb->srRcvd = false;
574 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
575 ueCb->bsrInfo[lcIdx].dataVol = 0;
577 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
583 /**********************************************************************
585 **********************************************************************/