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"
65 #include "common_def.h"
67 extern SchCb schCb[SCH_MAX_INST];
68 extern uint8_t puschDeltaTable[MAX_MU_PUSCH];
71 * @brief calculate ra-rnti function.
75 * Function : calculateRaRnti
77 * This function calculates ra-rnti
79 * @param[in] symbol index
80 * @param[in] slot index
81 * @param[in] frequency index
84 uint16_t calculateRaRnti(uint8_t symbolIdx, uint8_t slotIdx, uint8_t freqIdx)
87 uint8_t ulCarrierIdx = 0; /* configured to 0 */
88 raRnti = (1+symbolIdx+(14*slotIdx)+(14*80*freqIdx)+(14*80*8*ulCarrierIdx));
93 * @brief create raCb function.
97 * Function : createSchRaCb
99 * This function create raCb
102 * @param[in] shed instance
105 void createSchRaCb(uint16_t tcrnti, Inst schInst)
107 schCb[schInst].cells[schInst]->raCb[0].tcrnti = tcrnti;
111 * @brief resource allocation for msg3 PUSCH
115 * Function : schAllocMsg3Pusch
117 * This function handles msg3 PUSCH allocation
119 * @param[in] Inst schInst, SCH instance
120 * @param[in] slot, current slot
121 * @param[out] msg3StartRb
122 * @param[out] msg3NumRb
125 uint8_t schAllocMsg3Pusch(Inst schInst, uint16_t slot, uint16_t *msg3StartRb,
128 SchCellCb *cell = NULLP;
129 SchUlSlotInfo *schUlSlotInfo = NULLP;
131 uint8_t msg3SlotAlloc = 0;
134 uint8_t startSymb = 0;
141 cell = schCb[schInst].cells[schInst];
142 // puschMu = cell->cellCfg.puschMu;
143 delta = puschDeltaTable[puschMu];
144 k2 = cell->cellCfg.schInitialUlBwp.puschCommon.k2;
145 startSymb = cell->cellCfg.schInitialUlBwp.puschCommon.startSymbol;
146 symbLen = cell->cellCfg.schInitialUlBwp.puschCommon.lengthSymbol;
148 /* Slot allocation for msg3 based on 38.214 section 6.1.2.1 */
149 msg3SlotAlloc = slot + k2 + delta;
150 msg3SlotAlloc = msg3SlotAlloc % SCH_NUM_SLOTS;
152 startRb = PUSCH_START_RB;
154 /* formula used for calculation of rbSize, 38.214 section 6.1.4.2
155 * Ninfo = S.Nre.R.Qm.v
156 * Nre' = Nsc.NsymPdsch-NdmrsSymb-Noh
157 * Nre = min(156,Nre').nPrb */
158 numRb = 1; /* based on above calculation */
160 /* allocating 1 extra RB for now */
163 for(idx=startSymb; idx<symbLen; idx++)
165 cell->schUlSlotInfo[msg3SlotAlloc]->assignedPrb[idx] = startRb + numRb;
167 schUlSlotInfo = cell->schUlSlotInfo[msg3SlotAlloc];
169 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
170 if(!schUlSlotInfo->schPuschInfo)
172 DU_LOG("SCH: Memory allocation failed in schAllocMsg3Pusch");
175 schUlSlotInfo->schPuschInfo->harqProcId = SCH_HARQ_PROC_ID;
176 schUlSlotInfo->schPuschInfo->resAllocType = SCH_ALLOC_TYPE_1;
177 schUlSlotInfo->schPuschInfo->fdAlloc.startPrb = startRb;
178 schUlSlotInfo->schPuschInfo->fdAlloc.numPrb = numRb;
179 schUlSlotInfo->schPuschInfo->tdAlloc.startSymb = startSymb;
180 schUlSlotInfo->schPuschInfo->tdAlloc.numSymb = symbLen;
181 schUlSlotInfo->schPuschInfo->tbInfo.mcs = 4;
182 schUlSlotInfo->schPuschInfo->tbInfo.ndi = 1; /* new transmission */
183 schUlSlotInfo->schPuschInfo->tbInfo.rv = 0;
184 schUlSlotInfo->schPuschInfo->tbInfo.tbSize = 24; /*Considering 2 PRBs */
186 *msg3StartRb = startRb;
195 * @brief process rach indication function.
199 * Function : schProcessRachInd
201 * This function process rach indication
203 * @param[in] rachInd parameters
204 * @param[in] shed instance
207 uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst)
209 SchCellCb *cell = schCb[schInst].cells[schInst];
210 RarInfo *rarInfo = NULLP;
212 uint16_t rarSlot = 0;
213 uint16_t msg3StartRb;
217 /* RAR will sent with a delay of RAR_DELAY */
218 rarSlot = (rachInd->timingInfo.slot+RAR_DELAY+PHY_DELTA)%SCH_NUM_SLOTS;
220 SchDlSlotInfo *schDlSlotInfo = cell->schDlSlotInfo[rarSlot]; /* RAR will sent in the next slot */
222 /* Allocate the rarInfo, this pointer will be checked at schProcessSlotInd function */
223 SCH_ALLOC(rarInfo, sizeof(RarInfo));
226 DU_LOG("\nMAC: Memory Allocation failed for rarInfo");
230 schDlSlotInfo->rarInfo = rarInfo;
232 /* calculate the ra-rnti value */
233 raRnti = calculateRaRnti(rachInd->symbolIdx,rachInd->slotIdx,rachInd->freqIdx);
235 /* create raCb at SCH */
236 createSchRaCb(rachInd->crnti,schInst);
238 /* allocate resources for msg3 */
239 ret = schAllocMsg3Pusch(schInst, rarSlot, &msg3StartRb, &msg3NumRb);
243 rarInfo->raRnti = raRnti;
244 rarInfo->tcrnti = rachInd->crnti;
245 rarInfo->RAPID = rachInd->preambleIdx;
246 rarInfo->ta = rachInd->timingAdv;
247 rarInfo->msg3StartRb = msg3StartRb;
248 rarInfo->msg3NumRb = msg3NumRb;
254 * @brief fill RAR info function.
258 * Function : calculateRaRnti
260 * This function fills pdcch and pdsch info for RAR
262 * @param[in] rar Allocation info
265 * @param[in] offset to pointA to determine freq alloc
268 uint8_t schFillRar(RarAlloc *rarAlloc, uint16_t raRnti, uint16_t pci, uint8_t offsetPointA)
271 uint8_t coreset0Idx = 0;
273 uint8_t firstSymbol = 0;
274 uint8_t numSymbols = 0;
276 uint8_t FreqDomainResource[6] = {0};
278 uint8_t numPdschSymbols = 12; /* considering pdsch region from 2 to 13 */
279 uint8_t mcs = 4; /* MCS fixed to 4 */
281 SchBwpDlCfg *initialBwp = &schCb[inst].cells[inst]->cellCfg.schInitialDlBwp;
283 PdcchCfg *pdcch = &rarAlloc->rarPdcchCfg;
284 PdschCfg *pdsch = &rarAlloc->rarPdschCfg;
285 BwpCfg *bwp = &rarAlloc->bwp;
287 coreset0Idx = initialBwp->pdcchCommon.commonSearchSpace.coresetId;
289 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
290 numRbs = coresetIdxTable[coreset0Idx][1];
291 numSymbols = coresetIdxTable[coreset0Idx][2];
292 offset = coresetIdxTable[coreset0Idx][3];
294 /* calculate time domain parameters */
295 // note: since slot value is made sl1, RAR can be sent at all slots
296 uint16_t mask = 0x2000;
297 for(firstSymbol=0; firstSymbol<14;firstSymbol++)
299 if(initialBwp->pdcchCommon.commonSearchSpace.monitoringSymbol & mask)
305 /* calculate the PRBs */
306 calculatePRB( ((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
309 bwp->BWPSize = initialBwp->bwp.numPrb;
310 bwp->BWPStart = initialBwp->bwp.firstPrb;
311 bwp->subcarrierSpacing = initialBwp->bwp.scs;
312 bwp->cyclicPrefix = initialBwp->bwp.cyclicPrefix;
314 /* fill the PDCCH PDU */
315 pdcch->coreset0Cfg.startSymbolIndex = firstSymbol;
316 pdcch->coreset0Cfg.durationSymbols = numSymbols;
317 memcpy(pdcch->coreset0Cfg.freqDomainResource,FreqDomainResource,6);
318 pdcch->coreset0Cfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
319 pdcch->coreset0Cfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
320 pdcch->coreset0Cfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
321 pdcch->coreset0Cfg.coreSetType = 0;
322 pdcch->coreset0Cfg.shiftIndex = pci;
323 pdcch->coreset0Cfg.precoderGranularity = 0; /* sameAsRegBundle */
325 pdcch->dci.rnti = raRnti; /* RA-RNTI */
326 pdcch->dci.scramblingId = pci;
327 pdcch->dci.scramblingRnti = 0;
328 pdcch->dci.cceIndex = 4; /* considering SIB1 is sent at cce 0-1-2-3 */
329 pdcch->dci.aggregLevel = 4;
330 pdcch->dci.beamPdcchInfo.numPrgs = 1;
331 pdcch->dci.beamPdcchInfo.prgSize = 1;
332 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
333 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
334 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
335 pdcch->dci.txPdcchPower.powerValue = 0;
336 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
337 pdcch->dci.pdschCfg = pdsch;
339 /* fill the PDSCH PDU */
341 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
342 pdsch->rnti = raRnti; /* RA-RNTI */
344 pdsch->numCodewords = 1;
345 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
347 pdsch->codeword[cwCount].targetCodeRate = 308;
348 pdsch->codeword[cwCount].qamModOrder = 2;
349 pdsch->codeword[cwCount].mcsIndex = mcs; /* mcs configured to 4 */
350 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
351 pdsch->codeword[cwCount].rvIndex = 0;
352 tbSize = schCalcTbSize(10); /* 8 bytes RAR and 2 bytes padding */
353 pdsch->codeword[cwCount].tbSize = tbSize;
355 pdsch->dataScramblingId = pci;
356 pdsch->numLayers = 1;
357 pdsch->transmissionScheme = 0;
359 pdsch->dmrs.dlDmrsSymbPos = 2;
360 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
361 pdsch->dmrs.dlDmrsScramblingId = pci;
362 pdsch->dmrs.scid = 0;
363 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
364 pdsch->dmrs.dmrsPorts = 0;
365 pdsch->freqAlloc.resourceAlloc = 1; /* RAT type-1 RIV format */
366 pdsch->freqAlloc.rbStart = offset + SCH_SSB_PRB_DURATION; /* the RB numbering starts from coreset0, and PDSCH is always above SSB */
367 pdsch->freqAlloc.rbSize = schCalcNumPrb(tbSize,mcs,numPdschSymbols);
368 pdsch->freqAlloc.vrbPrbMapping = 0; /* non-interleaved */
369 pdsch->timeAlloc.startSymbolIndex = initialBwp->pdschCommon.startSymbol;
370 pdsch->timeAlloc.numSymbols = initialBwp->pdschCommon.lengthSymbol;
371 pdsch->beamPdschInfo.numPrgs = 1;
372 pdsch->beamPdschInfo.prgSize = 1;
373 pdsch->beamPdschInfo.digBfInterfaces = 0;
374 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
375 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
376 pdsch->txPdschPower.powerControlOffset = 0;
377 pdsch->txPdschPower.powerControlOffsetSS = 0;
382 /**********************************************************************
384 **********************************************************************/