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.
34 #include "common_def.h"
40 #include "du_app_mac_inf.h"
41 #include "mac_sch_interface.h"
43 #include "sch_utils.h"
46 * @brief Checks if PRACH can be scheduled in current slot
50 * Function : schCheckPrachOcc
52 * This function checks if PRACH can be scheduled in
60 bool schCheckPrachOcc(SchCellCb *cell, SlotTimingInfo prachOccasionTimingInfo)
62 uint8_t prachCfgIdx = 0;
66 uint16_t prachSubframe = 0;
68 prachCfgIdx = cell->cellCfg.schRachCfg.prachCfgIdx;
70 /* derive the prachCfgIdx table paramters */
71 x = prachCfgIdxTable[prachCfgIdx][1];
72 y = prachCfgIdxTable[prachCfgIdx][2];
73 prachSubframe = prachCfgIdxTable[prachCfgIdx][3];
75 if((prachOccasionTimingInfo.sfn%x) == y)
77 subFrame = prachOccasionTimingInfo.slot/pow(2, cell->cellCfg.numerology);
79 /* check for subFrame number */
80 if ((1 << subFrame) & prachSubframe)
82 /* prach ocassion present in this subframe */
84 if(UL_SLOT != schGetSlotSymbFrmt(prachOccasionTimingInfo.slot % cell->numSlotsInPeriodicity,\
85 cell->slotFrmtBitMap))
87 DU_LOG("\nERROR --> SCH : PrachCfgIdx %d doesn't support UL slot", prachCfgIdx);
98 * @brief Calculate number of PRBs to be allocated for PRACH
102 * Function : schCalcPrachNumRb
104 * Calculate number of PRBs to be allocated for PRACH
106 * @param[in] SchCellCb *cell, cell cb
107 * @return Number of PRBs
109 uint8_t schCalcPrachNumRb(SchCellCb *cell)
111 uint8_t tableIdx = 0;
112 uint16_t puschScs = fetchScsValue(cell->cellCfg.schInitialUlBwp.bwp.scs);
114 for(tableIdx=0; tableIdx < MAX_RACH_NUM_RB_IDX; tableIdx++)
116 if((numRbForPrachTable[tableIdx][0] == cell->cellCfg.schRachCfg.rootSeqLen) &&
117 (numRbForPrachTable[tableIdx][1] == cell->cellCfg.schRachCfg.prachSubcSpacing) &&
118 (numRbForPrachTable[tableIdx][2] == puschScs))
120 return numRbForPrachTable[tableIdx][3];
127 * @brief resource allocation for PRACH
131 * Function : schPrachResAlloc
133 * This function handles PRACH allocation
135 * @param[in] SchCellCb *cell, cell cb
136 * @param[in] UlSchedInfo *ulSchedInfo, UL scheduling info
139 void schPrachResAlloc(SchCellCb *cell, UlSchedInfo *ulSchedInfo, SlotTimingInfo prachOccasionTimingInfo)
141 uint8_t numPrachRb = 0;
143 uint8_t prachCfgIdx = 0;
144 uint8_t prachFormat = 0;
145 uint8_t prachStartSymbol = 0;
146 uint8_t prachDuration = 0;
147 uint8_t prachOcas = 0;
148 uint8_t dataType = 0;
149 uint16_t freqStart = 0;
151 /* If this slot is not a PRACH occassion, return */
152 if(!schCheckPrachOcc(cell, prachOccasionTimingInfo))
155 prachCfgIdx = cell->cellCfg.schRachCfg.prachCfgIdx;
156 prachFormat = prachCfgIdxTable[prachCfgIdx][0];
157 prachStartSymbol = prachCfgIdxTable[prachCfgIdx][4];
158 prachOcas = prachCfgIdxTable[prachCfgIdx][6];
159 prachDuration = prachCfgIdxTable[prachCfgIdx][7];
161 /* numRa determined as 𝑛 belonging {0,1,.., M − 1},
162 * where M is given by msg1Fdm */
163 numRa = (cell->cellCfg.schRachCfg.msg1Fdm - 1);
165 /* freq domain resource determination for RACH*/
166 freqStart = cell->cellCfg.schRachCfg.msg1FreqStart;
167 numPrachRb = schCalcPrachNumRb(cell);
168 /* Allocate PRACH resources from the UL resource bitmap */
169 allocatePrbUl(cell, prachOccasionTimingInfo, prachStartSymbol, prachDuration, &freqStart, numPrachRb);
172 dataType |= SCH_DATATYPE_PRACH;
173 ulSchedInfo->dataType = dataType;
174 ulSchedInfo->prachSchInfo.numPrachOcas = prachOcas;
175 ulSchedInfo->prachSchInfo.prachFormat = prachFormat;
176 ulSchedInfo->prachSchInfo.numRa = numRa;
177 ulSchedInfo->prachSchInfo.prachStartSymb = prachStartSymbol;
178 DU_LOG("\nINFO --> SCH : RACH occassion set for slot %d", prachOccasionTimingInfo.slot);
182 * @brief calculate ra-rnti function.
186 * Function : calculateRaRnti
188 * This function calculates ra-rnti
190 * @param[in] symbol index
191 * @param[in] slot index
192 * @param[in] frequency index
195 uint16_t calculateRaRnti(uint8_t symbolIdx, uint8_t slotIdx, uint8_t freqIdx)
198 uint8_t ulCarrierIdx = 0; /* Uplink carrier used for MSG1 transmission. 0:NUL carrier; 1:SUL carrier */
200 /* Refer to spec 38.321, section 5.1.3 */
201 raRnti = (1 + symbolIdx + (14*slotIdx) + (14*80*freqIdx) + (14*80*8*ulCarrierIdx));
206 * @brief create raCb function.
210 * Function : createSchRaCb
212 * This function create raCb
215 * @param[in] shed instance
218 void createSchRaCb(uint16_t tcrnti, Inst schInst)
222 GET_UE_IDX(tcrnti, ueIdx);
223 schCb[schInst].cells[schInst]->raCb[ueIdx -1].tcrnti = tcrnti;
224 schCb[schInst].cells[schInst]->raCb[ueIdx -1].msg4recvd = FALSE;
228 * @brief resource allocation for msg3 PUSCH
232 * Function : schAllocMsg3Pusch
234 * This function handles msg3 PUSCH allocation
236 * @param[in] Inst schInst, SCH instance
237 * @param[in] slot, current slot
238 * @param[out] msg3StartRb
239 * @param[out] msg3NumRb
242 SchPuschInfo* schAllocMsg3Pusch(Inst schInst, uint16_t crnti, uint8_t k2Index, SlotTimingInfo msg3SlotTime)
244 SchCellCb *cell = NULLP;
245 SchUlSlotInfo *schUlSlotInfo = NULLP;
246 uint8_t mcs = DEFAULT_MCS;
247 uint8_t startSymb = 0;
249 uint16_t startRb = 0;
253 cell = schCb[schInst].cells[schInst];
256 DU_LOG("\n\nERROR --> SCH : Failed to find cell in schAllocMsg3Pusch");
260 /* Allocate time-domain and frequency-domain resource for MSG3 PUSCH */
261 startSymb = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].startSymbol;
262 symbLen = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].symbolLength;
264 startRb = MAX_NUM_RB;
265 tbSize = schCalcTbSize(8); /* 6 bytes msg3 and 2 bytes header */
266 numRb = schCalcNumPrb(tbSize, mcs, symbLen);
267 numRb++; /* allocating 1 extra RB for now */
268 allocatePrbUl(cell, msg3SlotTime, startSymb, symbLen, &startRb, numRb);
270 /* Fill PUSCH scheduling details in Slot structure */
271 schUlSlotInfo = cell->schUlSlotInfo[msg3SlotTime.slot];
272 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
273 if(!schUlSlotInfo->schPuschInfo)
275 DU_LOG("\nERROR --> SCH : Memory allocation failed in schAllocMsg3Pusch");
279 tbSize = 0; /* since nPrb has been incremented, recalculating tbSize */
280 tbSize = schCalcTbSizeFromNPrb(numRb, mcs, NUM_PDSCH_SYMBOL);
281 tbSize = tbSize / 8 ; /*bits to byte conversion*/
283 schUlSlotInfo->schPuschInfo->crnti = crnti;
284 schUlSlotInfo->schPuschInfo->harqProcId = SCH_HARQ_PROC_ID;
285 schUlSlotInfo->schPuschInfo->resAllocType = SCH_ALLOC_TYPE_1;
286 schUlSlotInfo->schPuschInfo->fdAlloc.startPrb = startRb;
287 schUlSlotInfo->schPuschInfo->fdAlloc.numPrb = numRb;
288 schUlSlotInfo->schPuschInfo->tdAlloc.startSymb = startSymb;
289 schUlSlotInfo->schPuschInfo->tdAlloc.numSymb = symbLen;
290 schUlSlotInfo->schPuschInfo->tbInfo.qamOrder = QPSK_MODULATION; /* QPSK modulation */
291 schUlSlotInfo->schPuschInfo->tbInfo.mcs = mcs;
292 schUlSlotInfo->schPuschInfo->tbInfo.mcsTable = SCH_MCS_TABLE_QAM_64;
293 schUlSlotInfo->schPuschInfo->tbInfo.ndi = NEW_TRANSMISSION; /* new transmission */
294 schUlSlotInfo->schPuschInfo->tbInfo.rv = 0;
295 schUlSlotInfo->schPuschInfo->tbInfo.tbSize = tbSize;
296 schUlSlotInfo->schPuschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
297 schUlSlotInfo->schPuschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
298 schUlSlotInfo->schPuschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
300 return schUlSlotInfo->schPuschInfo;
304 * @brief Check if a time frame is in RA Response window
308 * Function : isInRaRspWindow
310 * Check if a time frame is in RA Response window
312 * @param[in] RA request
313 * @param[in] Time frame to check
314 * @param[in] Total number of slot per radio frame
318 RaRspWindowStatus isInRaRspWindow(SchRaReq *raReq, SlotTimingInfo frameToCheck, uint16_t numSlotsPerSystemFrame)
320 uint32_t winStartTime, winEndTime, timeToCheck;
322 winStartTime = (raReq->winStartTime.sfn * numSlotsPerSystemFrame) + raReq->winStartTime.slot;
323 winEndTime = (raReq->winEndTime.sfn * numSlotsPerSystemFrame) + raReq->winEndTime.slot;
324 timeToCheck = (frameToCheck.sfn * numSlotsPerSystemFrame) + frameToCheck.slot;
326 /* TODO : check how to handle the wrap around scenario of MAX_SFN */
327 if((timeToCheck >= winStartTime) && (timeToCheck <= winEndTime))
328 return WITHIN_WINDOW;
329 else if(timeToCheck < winStartTime)
330 return WINDOW_YET_TO_START;
332 return WINDOW_EXPIRED;
336 * @brief Processes any pending RA request
340 * Function : schProcessRaReq
342 * This function process pending RA request
344 * @param[in] Current timing of the cell
347 void schProcessRaReq(SlotTimingInfo currTime, SchCellCb *cell)
349 bool k2Found = false;
350 uint8_t ueIdx = 0, k0TblIdx = 0, k2TblIdx = 0;
351 uint8_t k0Index = 0, k2Index = 0;
352 uint8_t k0 = 0, k2 = 0;
354 uint8_t msg3Delta = 0, msg3MinSchTime = 0;
356 uint8_t totalCfgSlot = 0;
358 uint16_t dciSlot = 0, rarSlot = 0;
359 SlotTimingInfo dciTime, rarTime, msg3Time;
360 RarAlloc *dciSlotAlloc = NULLP; /* Stores info for transmission of PDCCH for RAR */
361 RarAlloc *rarSlotAlloc = NULLP; /* Stores info for transmission of RAR PDSCH */
362 SchPuschInfo *msg3PuschInfo = NULLP; /* Stores MSG3 PUSCH scheduling information */
363 SchK0K1TimingInfoTbl *k0K1InfoTbl=NULLP;
364 SchK2TimingInfoTbl *msg3K2InfoTbl=NULLP;
365 RaRspWindowStatus windowStatus=0;
367 while(ueIdx < MAX_NUM_UE)
369 if(cell->raReq[ueIdx] == NULLP)
376 totalCfgSlot = calculateSlotPatternLength(cell->cellCfg.ssbSchCfg.scsCommon, cell->cellCfg.tddCfg.tddPeriod);
378 k0K1InfoTbl = &cell->cellCfg.schInitialDlBwp.k0K1InfoTbl;
379 msg3K2InfoTbl = &cell->cellCfg.schInitialUlBwp.msg3K2InfoTbl;
380 puschMu = cell->cellCfg.numerology;
381 msg3Delta = puschDeltaTable[puschMu];
382 msg3MinSchTime = minMsg3SchTime[cell->cellCfg.numerology];
384 /* Calculating time frame to send DCI for RAR */
385 ADD_DELTA_TO_TIME(currTime, dciTime, PHY_DELTA_DL + SCHED_DELTA);
386 dciSlot = dciTime.slot;
388 /* Consider this slot for sending DCI, only if it is a DL slot */
389 if(schGetSlotSymbFrmt(dciSlot, cell->slotFrmtBitMap) == DL_SLOT)
393 /* Check if this slot is within RA response window */
394 windowStatus = isInRaRspWindow(cell->raReq[ueIdx], dciTime, cell->numSlots);
395 if(windowStatus == WITHIN_WINDOW)
397 /* For all k0 values, search for a suitable k2 value to schedule MSG3.
398 * RAR DCI, RAR PDSCH and MSG3 is scheduled only if one such k0-k2 combination
399 * is found. Else no scheduling happens.
401 for(k0TblIdx = 0; k0TblIdx < k0K1InfoTbl->k0k1TimingInfo[dciSlot].numK0; k0TblIdx++)
403 k0Index = k0K1InfoTbl->k0k1TimingInfo[dciSlot].k0Indexes[k0TblIdx].k0Index;
404 k0 = cell->cellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[k0Index].k0;
406 /* Calculating time frame to send RAR PDSCH */
407 ADD_DELTA_TO_TIME(dciTime, rarTime, k0);
408 rarSlot = rarTime.slot;
410 for(k2TblIdx = 0; k2TblIdx < msg3K2InfoTbl->k2TimingInfo[rarSlot].numK2; k2TblIdx++)
412 k2Index = msg3K2InfoTbl->k2TimingInfo[rarSlot].k2Indexes[k2TblIdx];
413 k2 = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].k2;
415 /* Delta is added to the slot allocation for msg3 based on 38.214 section 6.1.2.1 */
417 if(k2 >= msg3MinSchTime)
419 ADD_DELTA_TO_TIME(rarTime, msg3Time, k2);
421 if(schGetSlotSymbFrmt(msg3Time.slot % totalCfgSlot, cell->slotFrmtBitMap) == DL_SLOT)
432 else if(windowStatus == WINDOW_EXPIRED)
434 SCH_FREE(cell->raReq[ueIdx]->rachInd, sizeof(RachIndInfo));
435 SCH_FREE(cell->raReq[ueIdx], sizeof(SchRaReq));
440 /* If K0-K2 combination not found, no scheduling happens */
447 /* Allocate memory for RAR PDCCH slot, pointer will be checked at schProcessSlotInd() */
448 SCH_ALLOC(dciSlotAlloc, sizeof(RarAlloc));
449 if(dciSlotAlloc == NULLP)
451 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciSlotAlloc");
454 cell->schDlSlotInfo[dciSlot]->rarAlloc = dciSlotAlloc;
456 /* Fill PDCCH and PDSCH scheduling information for RAR */
457 if((schFillRar(cell, rarTime, ueIdx, dciSlotAlloc, k0Index)) != ROK)
459 DU_LOG("\nERROR --> SCH: Scheduling of RAR failed in slot [%d]", rarSlot);
460 SCH_FREE(dciSlotAlloc, sizeof(RarAlloc));
461 cell->schDlSlotInfo[dciSlot]->rarAlloc = NULLP;
465 /* Allocate resources for msg3 */
466 msg3PuschInfo = schAllocMsg3Pusch(cell->instIdx, cell->raReq[ueIdx]->rachInd->crnti, k2Index, msg3Time);
470 dciSlotAlloc->rarInfo.raRnti = cell->raReq[ueIdx]->raRnti;
471 dciSlotAlloc->rarInfo.tcrnti = cell->raReq[ueIdx]->rachInd->crnti;
472 dciSlotAlloc->rarInfo.RAPID = cell->raReq[ueIdx]->rachInd->preambleIdx;
473 dciSlotAlloc->rarInfo.ta = cell->raReq[ueIdx]->rachInd->timingAdv;
474 dciSlotAlloc->rarInfo.ulGrant.bwpSize = cell->cellCfg.schInitialUlBwp.bwp.freqAlloc.numPrb;
475 /* Spec 38.213, section 8.2, 0 : MSG3 PUSCH will be transmitted without frequency hopping */
476 dciSlotAlloc->rarInfo.ulGrant.freqHopFlag = 0;
477 dciSlotAlloc->rarInfo.ulGrant.msg3FreqAlloc.startPrb = msg3PuschInfo->fdAlloc.startPrb;
478 dciSlotAlloc->rarInfo.ulGrant.msg3FreqAlloc.numPrb = msg3PuschInfo->fdAlloc.numPrb;
479 dciSlotAlloc->rarInfo.ulGrant.k2Index = k2Index;
480 dciSlotAlloc->rarInfo.ulGrant.mcs = msg3PuschInfo->tbInfo.mcs;
481 dciSlotAlloc->rarInfo.ulGrant.tpc = 3; /* TODO : Check appropriate value to be filled */
482 /* Spec 38.213, section 8.2 : In a contention based random access
483 * procedure, the CSI request field is reserved. */
484 dciSlotAlloc->rarInfo.ulGrant.csiReq = 0;
487 /* Check if both DCI and RAR are sent in the same slot.
488 * If not, allocate memory RAR PDSCH slot to store RAR info
490 if(dciSlot == rarSlot)
491 dciSlotAlloc->pduPres = BOTH;
494 /* Allocate memory to schedule rarSlot to send RAR, pointer will be checked at schProcessSlotInd() */
495 SCH_ALLOC(rarSlotAlloc, sizeof(RarAlloc));
496 if(rarSlotAlloc == NULLP)
498 DU_LOG("\nERROR --> SCH : Memory Allocation failed for rarSlotAlloc");
499 SCH_FREE(dciSlotAlloc, sizeof(RarAlloc));
500 cell->schDlSlotInfo[dciSlot]->rarAlloc = NULLP;
503 cell->schDlSlotInfo[rarSlot]->rarAlloc = rarSlotAlloc;
505 /* Copy all RAR info */
506 memcpy(rarSlotAlloc, dciSlotAlloc, sizeof(RarAlloc));
507 rarSlotAlloc->rarPdcchCfg.dci.pdschCfg = &rarSlotAlloc->rarPdschCfg;
509 /* Assign correct PDU types in corresponding slots */
510 rarSlotAlloc->pduPres = PDSCH_PDU;
511 dciSlotAlloc->pduPres = PDCCH_PDU;
512 dciSlotAlloc->pdschSlot = rarSlot;
515 /* Create raCb at SCH */
516 createSchRaCb(cell->raReq[ueIdx]->rachInd->crnti, cell->instIdx);
518 SCH_FREE(cell->raReq[ueIdx]->rachInd, sizeof(RachIndInfo));
519 SCH_FREE(cell->raReq[ueIdx], sizeof(SchRaReq));
522 } /* End of while(ueIdx < MAX_NUM_UE) */
526 * @brief process rach indication function.
530 * Function : schProcessRachInd
532 * This function process rach indication
534 * @param[in] rachInd parameters
535 * @param[in] shed instance
538 uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst)
540 SchCellCb *cell = schCb[schInst].cells[schInst];
541 SchRaReq *raReq = NULLP;
548 DU_LOG("\nERROR --> SCH: Failed to find cell in schProcessRachInd");
552 /* Storing RA request in cellCb */
553 GET_UE_IDX(rachInd->crnti, ueIdx);
556 DU_LOG("\nERROR --> SCH: Invalid CRNTI [%d]", rachInd->crnti);
560 SCH_ALLOC(raReq, sizeof(SchRaReq));
563 DU_LOG("\nERROR --> SCH : Memory allocation failure in schProcessRachInd");
564 SCH_FREE(rachInd, sizeof(RachIndInfo));
568 /* calculate the ra-rnti value */
569 raReq->raRnti = calculateRaRnti(rachInd->symbolIdx, rachInd->slotIdx, rachInd->freqIdx);
570 raReq->rachInd = rachInd;
571 raReq->winStartTime.sfn = rachInd->timingInfo.sfn;
572 raReq->winStartTime.slot = rachInd->timingInfo.slot;
574 /* Converting window size from ms to number of slots */
575 slotDuration = (1 / pow(2, cell->cellCfg.numerology));
576 winNumSlots = (float)cell->cellCfg.schRachCfg.raRspWindow / slotDuration;
578 /* Adding window size to window start time to get window end time */
579 ADD_DELTA_TO_TIME(raReq->winStartTime, raReq->winEndTime, winNumSlots);
581 cell->raReq[ueIdx -1] = raReq;
587 * @brief fill RAR info function.
591 * Function : calculateRaRnti
593 * This function fills pdcch and pdsch info for RAR
595 * @param[in] rar Allocation info
598 * @param[in] offset to pointA to determine freq alloc
601 uint8_t schFillRar(SchCellCb *cell, SlotTimingInfo rarTime, uint16_t ueIdx, RarAlloc *rarAlloc, uint8_t k0Index)
603 uint8_t coreset0Idx = 0;
604 uint8_t firstSymbol = 0, numSymbols = 0;
605 uint8_t mcs = DEFAULT_MCS; /* MCS fixed to 4 */
606 uint8_t dmrsStartSymbol, startSymbol, numSymbol ;
610 SchBwpDlCfg *initialBwp = &cell->cellCfg.schInitialDlBwp;
611 PdcchCfg *pdcch = &rarAlloc->rarPdcchCfg;
612 PdschCfg *pdsch = &rarAlloc->rarPdschCfg;
613 BwpCfg *bwp = &rarAlloc->bwp;
615 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
616 coreset0Idx = initialBwp->pdcchCommon.commonSearchSpace.coresetId;
617 numRbs = coresetIdxTable[coreset0Idx][1];
618 numSymbols = coresetIdxTable[coreset0Idx][2];
620 /* calculate time domain parameters */
621 // note: since slot value is made sl1, RAR can be sent at all slots
622 uint16_t mask = 0x2000;
623 for(firstSymbol=0; firstSymbol<MAX_SYMB_PER_SLOT; firstSymbol++)
625 if(initialBwp->pdcchCommon.commonSearchSpace.monitoringSymbol & mask)
632 bwp->freqAlloc.numPrb = initialBwp->bwp.freqAlloc.numPrb;
633 bwp->freqAlloc.startPrb = initialBwp->bwp.freqAlloc.startPrb;
634 bwp->subcarrierSpacing = initialBwp->bwp.scs;
635 bwp->cyclicPrefix = initialBwp->bwp.cyclicPrefix;
637 /* fill the PDCCH PDU */
638 pdcch->coresetCfg.startSymbolIndex = firstSymbol;
639 pdcch->coresetCfg.durationSymbols = numSymbols;
640 memcpy(pdcch->coresetCfg.freqDomainResource, \
641 cell->cellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
643 pdcch->coresetCfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
644 pdcch->coresetCfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
645 pdcch->coresetCfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
646 pdcch->coresetCfg.coreSetType = 0;
647 pdcch->coresetCfg.coreSetSize = numRbs;
648 pdcch->coresetCfg.shiftIndex = cell->cellCfg.phyCellId;
649 pdcch->coresetCfg.precoderGranularity = 0; /* sameAsRegBundle */
651 pdcch->dci.rnti = cell->raReq[ueIdx]->raRnti; /* RA-RNTI */
652 pdcch->dci.scramblingId = cell->cellCfg.phyCellId;
653 pdcch->dci.scramblingRnti = 0;
654 pdcch->dci.cceIndex = 4; /* considering SIB1 is sent at cce 0-1-2-3 */
655 pdcch->dci.aggregLevel = 4;
656 pdcch->dci.beamPdcchInfo.numPrgs = 1;
657 pdcch->dci.beamPdcchInfo.prgSize = 1;
658 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
659 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
660 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
661 pdcch->dci.txPdcchPower.powerValue = 0;
662 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
663 pdcch->dci.pdschCfg = pdsch;
665 /* fill the PDSCH PDU */
667 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
668 pdsch->rnti = cell->raReq[ueIdx]->raRnti; /* RA-RNTI */
670 pdsch->numCodewords = 1;
671 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
673 pdsch->codeword[cwCount].targetCodeRate = 308;
674 pdsch->codeword[cwCount].qamModOrder = 2;
675 pdsch->codeword[cwCount].mcsIndex = mcs; /* mcs configured to 4 */
676 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
677 pdsch->codeword[cwCount].rvIndex = 0;
678 /* RAR PDU length and FAPI payload header length */
679 tbSize = schCalcTbSize(RAR_PAYLOAD_SIZE + TX_PAYLOAD_HDR_LEN);
680 pdsch->codeword[cwCount].tbSize = tbSize;
682 pdsch->dataScramblingId = cell->cellCfg.phyCellId;
683 pdsch->numLayers = 1;
684 pdsch->transmissionScheme = 0;
686 pdsch->dmrs.dlDmrsSymbPos = 4; /* Bitmap value 00000000000100 i.e. using 3rd symbol for PDSCH DMRS */
687 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
688 pdsch->dmrs.dlDmrsScramblingId = cell->cellCfg.phyCellId;
689 pdsch->dmrs.scid = 0;
690 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
691 pdsch->dmrs.dmrsPorts = 0;
692 pdsch->dmrs.mappingType = DMRS_MAP_TYPE_A; /* Type-A */
693 pdsch->dmrs.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
694 pdsch->dmrs.dmrsAddPos = DMRS_ADDITIONAL_POS;
696 pdsch->pdschTimeAlloc.timeAlloc.startSymb = initialBwp->pdschCommon.timeDomRsrcAllocList[k0Index].startSymbol;
697 pdsch->pdschTimeAlloc.timeAlloc.numSymb = initialBwp->pdschCommon.timeDomRsrcAllocList[k0Index].lengthSymbol;
699 pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
700 pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
701 pdsch->pdschFreqAlloc.freqAlloc.startPrb = MAX_NUM_RB;
702 pdsch->pdschFreqAlloc.freqAlloc.numPrb = \
703 schCalcNumPrb(tbSize, mcs, initialBwp->pdschCommon.timeDomRsrcAllocList[k0Index].lengthSymbol);
705 /* Find total symbols occupied including DMRS */
706 dmrsStartSymbol = findDmrsStartSymbol(pdsch->dmrs.dlDmrsSymbPos);
707 /* If there are no DRMS symbols, findDmrsStartSymbol() returns MAX_SYMB_PER_SLOT,
708 * in that case only PDSCH symbols are marked as occupied */
709 if(dmrsStartSymbol == MAX_SYMB_PER_SLOT)
711 startSymbol = pdsch->pdschTimeAlloc.timeAlloc.startSymb;
712 numSymbol = pdsch->pdschTimeAlloc.timeAlloc.numSymb;
714 /* If DMRS symbol is found, mark DMRS and PDSCH symbols as occupied */
717 startSymbol = dmrsStartSymbol;
718 numSymbol = pdsch->dmrs.nrOfDmrsSymbols + pdsch->pdschTimeAlloc.timeAlloc.numSymb;
721 /* Allocate the number of PRBs required for RAR PDSCH */
722 if((allocatePrbDl(cell, rarTime, startSymbol, numSymbol,\
723 &pdsch->pdschFreqAlloc.freqAlloc.startPrb, pdsch->pdschFreqAlloc.freqAlloc.numPrb)) != ROK)
725 DU_LOG("\nERROR --> SCH : allocatePrbDl() failed for RAR");
729 pdsch->beamPdschInfo.numPrgs = 1;
730 pdsch->beamPdschInfo.prgSize = 1;
731 pdsch->beamPdschInfo.digBfInterfaces = 0;
732 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
733 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
734 pdsch->txPdschPower.powerControlOffset = 0;
735 pdsch->txPdschPower.powerControlOffsetSS = 0;
740 /**********************************************************************
742 **********************************************************************/