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_CREATE_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;
163 if(ueCfg->lcCfgList[lcIdx].ulLcCfg)
165 /* TODO : Fill UL LC Cfg. As of now for SRB1, it is null */
170 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
172 ueCb->cellCb = cellCb;
173 ueCb->srRcvd = false;
174 for(idx=0; idx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; idx++)
175 ueCb->bsrInfo[idx].dataVol = 0;
177 SchSendUeCfgRspToMac(ueCfg, inst, RSP_OK, &cfgRsp);
181 /*******************************************************************
183 * @brief Fills PUSCH UL allocation
187 * Function : schFillPuschAlloc
189 * Functionality: fills PUSCH info
192 * @return ROK - success
195 * ****************************************************************/
196 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo)
198 uint16_t puschSlot = 0;
199 uint16_t startRb = 0;
202 uint8_t numPdschSymbols= 14;
206 SchCellCb *cellCb = ueCb->cellCb;
207 SchUlSlotInfo *schUlSlotInfo = NULLP;
208 uint8_t k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
209 uint8_t startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
210 uint8_t symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
212 puschSlot = (pdcchSlot + k2) % SCH_NUM_SLOTS;
214 startRb = cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb;
215 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
216 numRb = schCalcNumPrb(tbSize, mcs, numPdschSymbols);
217 /* increment PUSCH PRB */
219 cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb += numRb;
221 puschInfo->crnti = ueCb->crnti;
222 puschInfo->harqProcId = SCH_HARQ_PROC_ID;
223 puschInfo->resAllocType = SCH_ALLOC_TYPE_1;
224 puschInfo->fdAlloc.startPrb = startRb;
225 puschInfo->fdAlloc.numPrb = numRb;
226 puschInfo->tdAlloc.startSymb = startSymb;
227 puschInfo->tdAlloc.numSymb = symbLen;
228 puschInfo->tbInfo.mcs = mcs;
229 puschInfo->tbInfo.ndi = 1; /* new transmission */
230 puschInfo->tbInfo.rv = 0;
231 puschInfo->tbInfo.tbSize = tbSize;
232 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
233 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
234 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
236 /* Update pusch in cell */
237 for(idx=startSymb; idx<symbLen; idx++)
239 cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
242 schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
244 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
245 if(!schUlSlotInfo->schPuschInfo)
247 DU_LOG("SCH: Memory allocation failed in schAllocMsg3Pusch");
250 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
255 /*******************************************************************
257 * @brief Fills DCI for UL grant
261 * Function : schFillUlDci
263 * Functionality: fills DCI for UL grant in response to BSR
266 * @return ROK - success
269 * ****************************************************************/
270 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
272 SchCellCb *cellCb = ueCb->cellCb;
273 SchControlRsrcSet coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
275 dciInfo->cellId = cellCb->cellId;
276 dciInfo->crnti = ueCb->crnti;
279 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
280 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
281 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
282 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
284 /*fill coreset cfg */
285 //Considering number of RBs in coreset1 is same as coreset0
286 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
287 //Considering coreset1 also starts from same symbol as coreset0
288 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
289 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
290 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
292 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
293 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
294 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
295 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
296 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
297 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
298 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
299 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
301 dciInfo->formatType = FORMAT0_0;
304 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
305 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
306 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
307 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
308 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
309 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
310 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
311 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
312 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
313 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
314 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
315 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
316 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
317 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
319 /* Fill DCI Structure */
320 dciInfo->dciInfo.rnti = ueCb->crnti;
321 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
322 dciInfo->dciInfo.scramblingRnti = 0;
323 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
324 dciInfo->dciInfo.aggregLevel = 4;
325 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
326 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
327 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
328 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
329 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
330 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
331 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
332 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
338 /**********************************************************************
340 **********************************************************************/