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 DU_LOG("\nSCH: Sending UE Create response to MAC");
63 cfgRsp->cellId = ueCfg->cellId;
64 cfgRsp->crnti = ueCfg->crnti;
65 GET_UE_IDX(ueCfg->crnti, cfgRsp->ueIdx);
68 /* Filling response post */
69 memset(&rspPst, 0, sizeof(Pst));
70 FILL_PST_SCH_TO_MAC(rspPst, inst);
71 if(event == EVENT_UE_CREATE_REQ_TO_SCH)
73 rspPst.event = EVENT_UE_CREATE_RSP_TO_MAC;
75 else if(event == EVENT_UE_RECONFIG_REQ_TO_SCH)
77 rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
79 SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
82 /*******************************************************************
84 * @brief Function to fill Dl Lc Context in SCH Ue Cb
88 * Function : fillSchDlLcCtxt
90 * Functionality: Function to fill Dl Lc Context in SCH Ue Cb
92 * @params[in] SchDlLcCtxt pointer,
96 * ****************************************************************/
98 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
100 ueCbLcCfg->lcId = lcCfg->lcId;
101 ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
102 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
106 /*******************************************************************
108 * @brief Function to fill Ul Lc Context in SCH Ue Cb
112 * Function : fillSchUlLcCtxt
114 * Functionality: Function to fill Ul Lc Context in SCH Ue Cb
116 * @params[in] SchUlLcCtxt pointer,
120 * ****************************************************************/
122 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
124 ueCbLcCfg->lcId = lcCfg->lcId;
125 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
126 ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
127 ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
128 ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
129 ueCbLcCfg->pbr = lcCfg->ulLcCfg.pbr;
130 ueCbLcCfg->bsd = lcCfg->ulLcCfg.bsd;
134 /*******************************************************************
136 * @brief Function to update Sch Ul Lc Cb
140 * Function : updateSchUlCb
142 * Functionality: Function to update SCH Ul Lc Cb
146 * ****************************************************************/
148 void updateSchUlCb(uint8_t delIdx, SchUlCb *ulInfo)
152 for(lcIdx = delIdx; lcIdx < ulInfo->numUlLc; lcIdx++)
154 memcpy(&ulInfo->ulLcCtxt[lcIdx], &ulInfo->ulLcCtxt[lcIdx+1], sizeof(SchUlLcCtxt));
155 memset(&ulInfo->ulLcCtxt[lcIdx+1], 0, sizeof(SchUlLcCtxt));
159 /*******************************************************************
161 * @brief Function to update SCH Dl Lc Cb
165 * Function : updateSchDlCb
167 * Functionality: Function to update SCH DL Lc Cb
171 * ****************************************************************/
173 void updateSchDlCb(uint8_t delIdx, SchDlCb *dlInfo)
177 for(lcIdx = delIdx; lcIdx < dlInfo->numDlLc; lcIdx++)
179 memcpy(&dlInfo->dlLcCtxt[lcIdx], &dlInfo->dlLcCtxt[lcIdx+1], sizeof(SchDlLcCtxt));
180 memset(&dlInfo->dlLcCtxt[lcIdx+1], 0, sizeof(SchDlLcCtxt));
184 /*******************************************************************
186 * @brief Function to fill SchUeCb
190 * Function : fillSchUeCb
192 * Functionality: Function to fill SchUeCb
194 * @params[in] SchUeCb pointer,
196 * @return ROK/RFAILED
198 * ****************************************************************/
200 uint8_t fillSchUeCb(SchUeCb *ueCb, SchUeCfg *ueCfg)
202 uint8_t lcIdx, ueLcIdx;
204 memset(&ueCb->ueCfg, 0, sizeof(SchUeCfg));
205 memcpy(&ueCb->ueCfg, ueCfg, sizeof(SchUeCfg));
206 ueCb->state = SCH_UE_STATE_ACTIVE;
208 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
210 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
212 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueCb->ulInfo.numUlLc], &ueCfg->schLcCfg[lcIdx]);
213 ueCb->ulInfo.numUlLc++;
214 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueCb->dlInfo.numDlLc], &ueCfg->schLcCfg[lcIdx]);
215 ueCb->dlInfo.numDlLc++;
219 for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++) //searching for Lc to be Mod
221 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
223 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
225 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
226 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
229 if(ueCfg->schLcCfg[ueLcIdx].configType == CONFIG_DEL)
231 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
232 ueCb->ulInfo.numUlLc--;
233 updateSchUlCb(ueLcIdx, &ueCb->ulInfo); //moving arr elements one idx ahead
234 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
235 ueCb->dlInfo.numDlLc--;
236 updateSchDlCb(ueLcIdx, &ueCb->dlInfo); //moving arr elements one idx ahead
240 }/*End of inner for loop */
242 }/* End of outer for loop */
246 /*******************************************************************
248 * @brief Function to get SCH Cell Cb
252 * Function : getSchCellCb
254 * Functionality: Function to get SCH Cell Cb
256 * @params[in] event, SchUeCfg pointer
257 * @return schUeCb pointer - success
260 * ****************************************************************/
262 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
265 SchCellCb *cellCb = NULLP;
267 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
269 /* Search of cell cb */
270 for(idx = 0; idx < MAX_NUM_CELL; idx++)
272 cellCb = schCb[inst].cells[idx];
273 if(cellCb->cellId == ueCfg->cellId)
276 if(idx == MAX_NUM_CELL)
278 DU_LOG("\nSCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
279 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
283 /* Check if max number of UE configured */
284 if(cellCb->numActvUe > MAX_NUM_UE)
286 DU_LOG("SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
287 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
294 /*******************************************************************
296 * @brief Hanles Ue create request from MAC
300 * Function : MacSchUeCreateReq
302 * Functionality: Hanles Ue create request from MAC
305 * @return ROK - success
308 * ****************************************************************/
309 uint8_t MacSchUeCreateReq(Pst *pst, SchUeCfg *ueCfg)
311 uint8_t ueIdx, lcIdx, ret = ROK;
312 SchCellCb *cellCb = NULLP;
313 SchUeCb *ueCb = NULLP;
315 Inst inst = pst->dstInst - 1;
316 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
320 DU_LOG("\nSCH : UE create request failed at MacSchUeCreateReq()");
323 DU_LOG("\nSCH : UE Create Request for CRNTI[%d]", ueCfg->crnti);
324 cellCb = getSchCellCb(pst->event, inst, ueCfg);
326 /* Search if UE already configured */
327 GET_UE_IDX(ueCfg->crnti, ueIdx);
328 ueCb = &cellCb->ueCb[ueIdx -1];
331 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
333 DU_LOG("\n SCH : CRNTI %d already configured ", ueCfg->crnti);
334 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
340 DU_LOG("\n SCH : SchUeCb not found at MacSchUeCreateReq() ");
341 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
345 /* Fill received Ue Configuration in UeCb */
346 memset(ueCb, 0, sizeof(SchUeCb));
347 GET_UE_IDX(ueCfg->crnti, ueIdx);
349 ueCb->crnti = ueCfg->crnti;
350 ueCb->state = SCH_UE_STATE_ACTIVE;
351 ret = fillSchUeCb(ueCb, ueCfg);
355 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
356 ueCb->cellCb = cellCb;
357 ueCb->srRcvd = false;
358 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
359 ueCb->bsrInfo[lcIdx].dataVol = 0;
361 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
366 /*******************************************************************
368 * @brief Fills PUSCH UL allocation
372 * Function : schFillPuschAlloc
374 * Functionality: fills PUSCH info
377 * @return ROK - success
380 * ****************************************************************/
381 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo)
383 uint16_t puschSlot = 0;
384 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) % SCH_NUM_SLOTS;
399 startRb = cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb;
400 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
401 numRb = schCalcNumPrb(tbSize, mcs, 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.mcs = mcs;
414 puschInfo->tbInfo.ndi = 1; /* new transmission */
415 puschInfo->tbInfo.rv = 0;
416 puschInfo->tbInfo.tbSize = tbSize;
417 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
418 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
419 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
421 /* Update pusch in cell */
422 for(idx=startSymb; idx<symbLen; idx++)
424 cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
427 schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
429 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
430 if(!schUlSlotInfo->schPuschInfo)
432 DU_LOG("SCH: Memory allocation failed in schAllocMsg3Pusch");
435 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
440 /*******************************************************************
442 * @brief Fills DCI for UL grant
446 * Function : schFillUlDci
448 * Functionality: fills DCI for UL grant in response to BSR
451 * @return ROK - success
454 * ****************************************************************/
455 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
457 SchCellCb *cellCb = ueCb->cellCb;
458 SchControlRsrcSet coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
460 dciInfo->cellId = cellCb->cellId;
461 dciInfo->crnti = ueCb->crnti;
464 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
465 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
466 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
467 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
469 /*fill coreset cfg */
470 //Considering number of RBs in coreset1 is same as coreset0
471 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
472 //Considering coreset1 also starts from same symbol as coreset0
473 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
474 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
475 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
477 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
478 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
479 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
480 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
481 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
482 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
483 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
484 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
486 dciInfo->formatType = FORMAT0_0;
489 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
490 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
491 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
492 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
493 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
494 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
495 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
496 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
497 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
498 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
499 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
500 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
501 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
502 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
504 /* Fill DCI Structure */
505 dciInfo->dciInfo.rnti = ueCb->crnti;
506 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
507 dciInfo->dciInfo.scramblingRnti = 0;
508 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
509 dciInfo->dciInfo.aggregLevel = 4;
510 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
511 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
512 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
513 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
514 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
515 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
516 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
517 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
522 /*******************************************************************
524 * @brief Hanles Ue Reconfig request from MAC
528 * Function : MacSchUeReconfigReq
530 * Functionality: Hanles Ue Reconfig request from MAC
533 * @return ROK - success
536 * ****************************************************************/
537 uint8_t MacSchUeReconfigReq(Pst *pst, SchUeCfg *ueCfg)
539 uint8_t ueIdx, lcIdx, ret = ROK;
540 SchCellCb *cellCb = NULLP;
541 SchUeCb *ueCb = NULLP;
543 Inst inst = pst->dstInst - 1;
544 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
548 DU_LOG("\nSCH : Reconfig request failed at MacSchUeReconfigReq()");
551 DU_LOG("\nSCH : Reconfig Request for CRNTI[%d]", ueCfg->crnti);
552 cellCb = getSchCellCb(pst->event, inst, ueCfg);
554 /* Search if UE already configured */
555 GET_UE_IDX(ueCfg->crnti, ueIdx);
556 ueCb = &cellCb->ueCb[ueIdx -1];
560 DU_LOG("\n SCH : SchUeCb not found at MacSchUeReconfigReq() ");
561 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
564 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
566 /* Found the UeCb to Reconfig */
567 ret = fillSchUeCb(ueCb, ueCfg);
570 ueCb->cellCb = cellCb;
571 ueCb->srRcvd = false;
572 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
573 ueCb->bsrInfo[lcIdx].dataVol = 0;
575 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
581 /**********************************************************************
583 **********************************************************************/