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 *******************************************************************************/
19 /************************************************************************
25 Desc: C source code for rach handling functions
29 **********************************************************************/
32 @brief This file implements the rach handling.
36 #include "envopt.h" /* environment options */
37 #include "envdep.h" /* environment dependent */
38 #include "envind.h" /* environment independent */
39 #include "gen.h" /* general layer */
40 #include "ssi.h" /* system service interface */
41 #include "cm_tkns.h" /* Common Token Defines */
42 #include "cm_llist.h" /* Common Link List Defines */
43 #include "cm_hash.h" /* Common Hash List Defines */
44 #include "cm_mblk.h" /* common memory link list library */
45 #include "cm_lte.h" /* Common LTE Defines */
49 #include "gen.x" /* general layer typedefs */
50 #include "ssi.x" /* system services typedefs */
51 #include "cm5.x" /* system services */
52 #include "cm_tkns.x" /* Common Token Definitions */
53 #include "cm_llist.x" /* Common Link List Definitions */
54 #include "cm_lib.x" /* Common Library Definitions */
55 #include "cm_hash.x" /* Common Hash List Definitions */
56 #include "cm_mblk.x" /* common memory link list library */
57 #include "cm_lte.x" /* Common LTE Defines */
61 #include "du_app_mac_inf.h"
62 #include "mac_sch_interface.h"
64 #include "sch_utils.h"
66 extern SchCb schCb[SCH_MAX_INST];
67 extern uint8_t puschDeltaTable[MAX_MU_PUSCH];
70 * @brief calculate ra-rnti function.
74 * Function : calculateRaRnti
76 * This function calculates ra-rnti
78 * @param[in] symbol index
79 * @param[in] slot index
80 * @param[in] frequency index
83 uint16_t calculateRaRnti(uint8_t symbolIdx, uint8_t slotIdx, uint8_t freqIdx)
86 uint8_t ulCarrierIdx = 0; /* configured to 0 */
87 raRnti = (1+symbolIdx+(14*slotIdx)+(14*80*freqIdx)+(14*80*8*ulCarrierIdx));
92 * @brief create raCb function.
96 * Function : createSchRaCb
98 * This function create raCb
101 * @param[in] shed instance
104 void createSchRaCb(uint16_t tcrnti, Inst schInst)
106 schCb[schInst].cells[schInst]->raCb[0].tcrnti = tcrnti;
110 * @brief resource allocation for msg3 PUSCH
114 * Function : schAllocMsg3Pusch
116 * This function handles msg3 PUSCH allocation
118 * @param[in] Inst schInst, SCH instance
119 * @param[in] slot, current slot
120 * @param[out] msg3StartRb
121 * @param[out] msg3NumRb
124 uint8_t schAllocMsg3Pusch(Inst schInst, uint16_t slot, uint16_t *msg3StartRb,
127 SchCellCb *cell = NULLP;
128 SchUlAlloc *ulAlloc = NULLP;
130 uint8_t msg3SlotAlloc = 0;
133 uint8_t startSymb = 0;
140 cell = schCb[schInst].cells[schInst];
141 puschMu = cell->cellCfg.puschMu;
142 delta = puschDeltaTable[puschMu];
143 k2 = cell->cellCfg.schInitialUlBwp.puschCommon.k2;
144 startSymb = cell->cellCfg.schInitialUlBwp.puschCommon.startSymbol;
145 symbLen = cell->cellCfg.schInitialUlBwp.puschCommon.lengthSymbol;
147 /* Slot allocation for msg3 based on 38.214 section 6.1.2.1 */
148 msg3SlotAlloc = slot + k2 + delta;
149 msg3SlotAlloc = msg3SlotAlloc % SCH_NUM_SLOTS;
151 startRb = PUSCH_START_RB;
153 /* formula used for calculation of rbSize, 38.214 section 6.1.4.2
154 * Ninfo = S.Nre.R.Qm.v
155 * Nre' = Nsc.NsymPdsch-NdmrsSymb-Noh
156 * Nre = min(156,Nre').nPrb */
157 numRb = 1; /* based on above calculation */
159 /* allocating 1 extra RB for now */
162 for(idx=startSymb; idx<symbLen; idx++)
164 cell->ulAlloc[msg3SlotAlloc]->assignedPrb[idx] = startRb + numRb;
166 ulAlloc = cell->ulAlloc[msg3SlotAlloc];
168 SCH_ALLOC(ulAlloc->schPuschInfo, sizeof(SchPuschInfo));
169 if(!ulAlloc->schPuschInfo)
171 DU_LOG("SCH: Memory allocation failed in schAllocMsg3Pusch");
174 ulAlloc->schPuschInfo->harqProcId = SCH_HARQ_PROC_ID;
175 ulAlloc->schPuschInfo->resAllocType = SCH_ALLOC_TYPE_1;
176 ulAlloc->schPuschInfo->fdAlloc.startPrb = startRb;
177 ulAlloc->schPuschInfo->fdAlloc.numPrb = numRb;
178 ulAlloc->schPuschInfo->tdAlloc.startSymb = startSymb;
179 ulAlloc->schPuschInfo->tdAlloc.numSymb = symbLen;
180 ulAlloc->schPuschInfo->tbInfo.mcs = 4;
181 ulAlloc->schPuschInfo->tbInfo.ndi = 1; /* new transmission */
182 ulAlloc->schPuschInfo->tbInfo.rv = 0;
183 ulAlloc->schPuschInfo->tbInfo.tbSize = 24; /*Considering 2 PRBs */
185 *msg3StartRb = startRb;
194 * @brief process rach indication function.
198 * Function : schProcessRachInd
200 * This function process rach indication
202 * @param[in] rachInd parameters
203 * @param[in] shed instance
206 uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst)
208 SchCellCb *cell = schCb[schInst].cells[schInst];
211 uint16_t msg3StartRb;
214 /* RAR will sent in the next slot */
215 slot = (rachInd->timingInfo.slot+SCHED_DELTA+RAR_DELAY)%SCH_NUM_SLOTS;
217 SchDlAlloc *dlAlloc = cell->dlAlloc[slot];
218 RarInfo *rarInfo = &(dlAlloc->rarInfo);
220 /* rar message presense in next slot ind and will be scheduled */
221 dlAlloc->rarPres = true;
223 /* calculate the ra-rnti value */
224 raRnti = calculateRaRnti(rachInd->symbolIdx,rachInd->slotIdx,rachInd->freqIdx);
226 /* create raCb at SCH */
227 createSchRaCb(rachInd->crnti,schInst);
229 /* allocate resources for msg3 */
230 ret = schAllocMsg3Pusch(schInst, slot, &msg3StartRb, &msg3NumRb);
235 rarInfo->raRnti = raRnti;
236 rarInfo->tcrnti = rachInd->crnti;
237 rarInfo->RAPID = rachInd->preambleIdx;
238 rarInfo->ta = rachInd->timingAdv;
239 rarInfo->msg3StartRb = msg3StartRb;
240 rarInfo->msg3NumRb = msg3NumRb;
246 * @brief fill RAR info function.
250 * Function : calculateRaRnti
252 * This function fills pdcch and pdsch info for RAR
254 * @param[in] rar Allocation info
257 * @param[in] offset to pointA to determine freq alloc
260 uint8_t schFillRar(RarAlloc *rarAlloc, uint16_t raRnti, uint16_t pci, uint8_t offsetPointA)
263 uint8_t coreset0Idx = 0;
265 uint8_t firstSymbol = 0;
266 uint8_t numSymbols = 0;
268 uint8_t FreqDomainResource[6] = {0};
269 SchBwpDlCfg *initialBwp = &schCb[inst].cells[inst]->cellCfg.schInitialDlBwp;
271 PdcchCfg *pdcch = &rarAlloc->rarPdcchCfg;
272 PdschCfg *pdsch = &rarAlloc->rarPdschCfg;
274 coreset0Idx = initialBwp->pdcchCommon.raSearchSpace.coresetId;
276 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
277 numRbs = coresetIdxTable[coreset0Idx][1];
278 numSymbols = coresetIdxTable[coreset0Idx][2];
279 offset = coresetIdxTable[coreset0Idx][3];
281 /* calculate time domain parameters */
282 // note: since slot value is made sl1, RAR can be sent at all slots
283 uint16_t mask = 0x2000;
284 for(firstSymbol=0; firstSymbol<14;firstSymbol++)
286 if(initialBwp->pdcchCommon.raSearchSpace.monitoringSymbol & mask)
292 /* calculate the PRBs */
293 calculatePRB( ((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
295 /* fill the PDCCH PDU */
296 pdcch->pdcchBwpCfg.BWPSize = initialBwp->bwp.numPrb;
297 pdcch->pdcchBwpCfg.BWPStart = initialBwp->bwp.firstPrb;
298 pdcch->pdcchBwpCfg.subcarrierSpacing = initialBwp->bwp.scs;
299 pdcch->pdcchBwpCfg.cyclicPrefix = initialBwp->bwp.cyclicPrefix;
300 pdcch->coreset0Cfg.startSymbolIndex = firstSymbol;
301 pdcch->coreset0Cfg.durationSymbols = numSymbols;
302 memcpy(pdcch->coreset0Cfg.freqDomainResource,FreqDomainResource,6);
303 pdcch->coreset0Cfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
304 pdcch->coreset0Cfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
305 pdcch->coreset0Cfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
306 pdcch->coreset0Cfg.coreSetType = 0;
307 pdcch->coreset0Cfg.shiftIndex = pci;
308 pdcch->coreset0Cfg.precoderGranularity = 0; /* sameAsRegBundle */
310 pdcch->dci.rnti = raRnti; /* RA-RNTI */
311 pdcch->dci.scramblingId = pci;
312 pdcch->dci.scramblingRnti = 0;
313 pdcch->dci.cceIndex = 4; /* considering SIB1 is sent at cce 0-1-2-3 */
314 pdcch->dci.aggregLevel = 4;
315 pdcch->dci.beamPdcchInfo.numPrgs = 1;
316 pdcch->dci.beamPdcchInfo.prgSize = 1;
317 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
318 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
319 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
320 pdcch->dci.txPdcchPower.powerValue = 0;
321 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
322 pdcch->dci.pdschCfg = pdsch;
324 /* fill the PDSCH PDU */
326 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
327 pdsch->rnti = raRnti; /* RA-RNTI */
329 pdsch->pdschBwpCfg.BWPSize = initialBwp->bwp.numPrb;
330 pdsch->pdschBwpCfg.BWPStart = initialBwp->bwp.firstPrb;
331 pdsch->numCodewords = 1;
332 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
334 pdsch->codeword[cwCount].targetCodeRate = 308;
335 pdsch->codeword[cwCount].qamModOrder = 2;
336 pdsch->codeword[cwCount].mcsIndex = 4; /* mcs configured to 4 */
337 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
338 pdsch->codeword[cwCount].rvIndex = 0;
339 pdsch->codeword[cwCount].tbSize = 80/8; /* 38.214: Table 5.1.3.2-1,
340 devided by 8 to get the value in bytes */
342 pdsch->dataScramblingId = pci;
343 pdsch->numLayers = 1;
344 pdsch->transmissionScheme = 0;
346 pdsch->dmrs.dlDmrsSymbPos = 2;
347 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
348 pdsch->dmrs.dlDmrsScramblingId = pci;
349 pdsch->dmrs.scid = 0;
350 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
351 pdsch->dmrs.dmrsPorts = 0;
352 pdsch->freqAlloc.resourceAlloc = 1; /* RAT type-1 RIV format */
353 pdsch->freqAlloc.rbStart = offset + SCH_SSB_PRB_DURATION; /* the RB numbering starts from coreset0, and PDSCH is always above SSB */
354 /* formula used for calculation of rbSize, 38.213 section 5.1.3.2 *
355 * Ninfo = S . Nre . R . Qm . v *
356 * Nre' = Nsc . NsymPdsch - NdmrsSymb - Noh *
357 * Nre = min(156,Nre') . nPrb */
358 pdsch->freqAlloc.rbSize = 1; /* This value is calculated from above formulae */
359 pdsch->freqAlloc.vrbPrbMapping = 0; /* non-interleaved */
360 pdsch->timeAlloc.startSymbolIndex = initialBwp->pdschCommon.startSymbol;
361 pdsch->timeAlloc.numSymbols = initialBwp->pdschCommon.lengthSymbol;
362 pdsch->beamPdschInfo.numPrgs = 1;
363 pdsch->beamPdschInfo.prgSize = 1;
364 pdsch->beamPdschInfo.digBfInterfaces = 0;
365 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
366 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
367 pdsch->txPdschPower.powerControlOffset = 0;
368 pdsch->txPdschPower.powerControlOffsetSS = 0;
373 /**********************************************************************
375 **********************************************************************/