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(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 rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
73 SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
76 /*******************************************************************
78 * @brief Hanles Ue create request from MAC
82 * Function : MacSchUeCreateReq
84 * Functionality: Hanles Ue create request from MAC
87 * @return ROK - success
90 * ****************************************************************/
91 uint8_t MacSchUeCreateReq(Pst *pst, SchUeCfg *ueCfg)
100 Inst inst = pst->dstInst - 1;
102 DU_LOG("\nSCH : UE Create Request for CRNTI[%d]", ueCfg->crnti);
104 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
108 DU_LOG("\nSCH : UE create request failed");
112 /* Search of cell cb */
113 for(idx = 0; idx < MAX_NUM_CELL; idx++)
115 cellCb = schCb[inst].cells[idx];
116 if(cellCb->cellId == ueCfg->cellId)
119 if(idx == MAX_NUM_CELL)
121 DU_LOG("\nSCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
122 SchSendUeCfgRspToMac(ueCfg, inst, RSP_NOK, &cfgRsp);
126 /* Check if max number of UE configured */
127 if(cellCb->numActvUe > MAX_NUM_UE)
129 DU_LOG("SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
130 SchSendUeCfgRspToMac(ueCfg, inst, RSP_NOK, &cfgRsp);
134 /* Search if UE already configured */
135 GET_UE_IDX(ueCfg->crnti, ueIdx);
136 ueCb = &cellCb->ueCb[ueIdx -1];
139 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
141 DU_LOG("\n SCH : CRNTI %d already configured ", ueCfg->crnti);
142 SchSendUeCfgRspToMac(ueCfg, inst, RSP_OK, &cfgRsp);
147 /* Fill received Ue Configuration in UeCb */
148 memset(ueCb, 0, sizeof(SchUeCb));
150 ueCb->crnti = ueCfg->crnti;
151 memcpy(&ueCb->ueCfg, ueCfg, sizeof(SchUeCfg));
152 ueCb->state = SCH_UE_STATE_ACTIVE;
155 for(lcIdx = 0; lcIdx < ueCfg->numLc; lcIdx++)
157 lcId = ueCfg->lcCfgList[lcIdx].lcId;
158 ueCb->dlLcCtxt[lcId].lcp = ueCfg->lcCfgList[lcIdx].dlLcCfg.lcp;
159 ueCb->dlLcCtxt[lcId].lcState = SCH_LC_STATE_ACTIVE;
160 ueCb->dlLcCtxt[lcId].bo = 0;
165 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
167 ueCb->cellCb = cellCb;
168 ueCb->srRcvd = false;
169 for(idx=0; idx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; idx++)
170 ueCb->bsrInfo[idx].dataVol = 0;
172 SchSendUeCfgRspToMac(ueCfg, inst, RSP_OK, &cfgRsp);
176 /*******************************************************************
178 * @brief Fills PUSCH UL allocation
182 * Function : schFillPuschAlloc
184 * Functionality: fills PUSCH info
187 * @return ROK - success
190 * ****************************************************************/
191 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo)
193 uint16_t puschSlot = 0;
194 uint16_t startRb = 0;
197 uint8_t numPdschSymbols= 14;
201 SchCellCb *cellCb = ueCb->cellCb;
202 SchUlSlotInfo *schUlSlotInfo = NULLP;
203 uint8_t k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
204 uint8_t startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
205 uint8_t symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
207 puschSlot = (pdcchSlot + k2) % SCH_NUM_SLOTS;
209 startRb = cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb;
210 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
211 numRb = schCalcNumPrb(tbSize, mcs, numPdschSymbols);
212 /* increment PUSCH PRB */
214 cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb += numRb;
216 puschInfo->crnti = ueCb->crnti;
217 puschInfo->harqProcId = SCH_HARQ_PROC_ID;
218 puschInfo->resAllocType = SCH_ALLOC_TYPE_1;
219 puschInfo->fdAlloc.startPrb = startRb;
220 puschInfo->fdAlloc.numPrb = numRb;
221 puschInfo->tdAlloc.startSymb = startSymb;
222 puschInfo->tdAlloc.numSymb = symbLen;
223 puschInfo->tbInfo.mcs = mcs;
224 puschInfo->tbInfo.ndi = 1; /* new transmission */
225 puschInfo->tbInfo.rv = 0;
226 puschInfo->tbInfo.tbSize = tbSize;
227 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
228 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
229 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
231 /* Update pusch in cell */
232 for(idx=startSymb; idx<symbLen; idx++)
234 cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
237 schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
239 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
240 if(!schUlSlotInfo->schPuschInfo)
242 DU_LOG("SCH: Memory allocation failed in schAllocMsg3Pusch");
245 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
250 /*******************************************************************
252 * @brief Fills DCI for UL grant
256 * Function : schFillUlDci
258 * Functionality: fills DCI for UL grant in response to BSR
261 * @return ROK - success
264 * ****************************************************************/
265 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
267 SchCellCb *cellCb = ueCb->cellCb;
268 SchControlRsrcSet coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
270 dciInfo->cellId = cellCb->cellId;
271 dciInfo->crnti = ueCb->crnti;
274 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
275 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
276 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
277 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
279 /*fill coreset cfg */
280 //Considering number of RBs in coreset1 is same as coreset0
281 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
282 //Considering coreset1 also starts from same symbol as coreset0
283 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
284 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
285 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
287 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
288 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
289 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
290 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
291 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
292 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
293 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
294 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
296 dciInfo->formatType = FORMAT0_0;
299 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
300 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
301 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
302 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
303 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
304 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
305 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
306 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
307 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
308 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
309 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
310 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
311 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
312 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
314 /* Fill DCI Structure */
315 dciInfo->dciInfo.rnti = ueCb->crnti;
316 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
317 dciInfo->dciInfo.scramblingRnti = 0;
318 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
319 dciInfo->dciInfo.aggregLevel = 4;
320 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
321 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
322 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
323 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
324 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
325 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
326 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
327 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
333 /*******************************************************************
335 * @brief Hanles Ue Reconfig request from MAC
339 * Function : MacSchUeReconfigReq
341 * Functionality: Hanles Ue Reconfig request from MAC
344 * @return ROK - success
347 * ****************************************************************/
348 uint8_t MacSchUeReconfigReq(Pst *pst, SchUeCfg *ueCfg)
353 /**********************************************************************
355 **********************************************************************/