+/*******************************************************************
+ *
+ * @brief Fills k0 and k1 information table for FDD
+ *
+ * @details
+ *
+ * Function : BuildK0K1TableForFdd
+ *
+ * Functionality:
+ * Fills k0 and k1 information table for FDD
+ *
+ * @params[in] SchCellCb *cell,SchK0K1TimingInfoTbl *k0K1InfoTbl,bool
+ * pdschCfgCmnPres,uint8_t numTimeDomAlloc, SchPdschCfgCmnTimeDomRsrcAlloc
+ * cmnTimeDomRsrcAllocList[], SchPdschTimeDomRsrcAlloc
+ * dedTimeDomRsrcAllocList[], uint8_t ulAckListCount, uint8_t *UlAckTbl
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+void BuildK0K1TableForFdd(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres,SchPdschCfgCmn pdschCmnCfg,\
+SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl)
+{
+
+ uint8_t k1TmpVal =0, cfgIdx=0;
+ uint8_t slotIdx=0, k0Index=0, k1Index=0, numK0=0, numK1=0, numTimeDomAlloc=0;
+
+ /* TODO Commented these below lines for resolving warnings. Presently these variable are not
+ * required but this will require for harq processing */
+ // uint8_t k0TmpVal = 0;
+ // SchPdschCfgCmnTimeDomRsrcAlloc cmnTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
+ // SchPdschTimeDomRsrcAlloc dedTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
+
+ /* Initialization the structure and storing the total slot values. */
+ memset(k0K1InfoTbl, 0, sizeof(SchK0K1TimingInfoTbl));
+ k0K1InfoTbl->tblSize = cell->numSlots;
+
+ /* Storing time domain resource allocation list based on common or dedicated configuration. */
+ if(pdschCfgCmnPres == true)
+ {
+ numTimeDomAlloc = pdschCmnCfg.numTimeDomAlloc;
+ for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
+ {
+ /*TODO uncomment this line during harq processing */
+ //cmnTimeDomRsrcAllocList[cfgIdx] = pdschCmnCfg.timeDomRsrcAllocList[cfgIdx];
+ }
+ }
+ else
+ {
+ numTimeDomAlloc = pdschDedCfg.numTimeDomRsrcAlloc;
+ for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
+ {
+ /*TODO uncomment this line during harq processing */
+ //dedTimeDomRsrcAllocList[cfgIdx] = pdschDedCfg.timeDomRsrcAllociList[cfgIdx];
+ }
+ }
+
+ /* Checking all the slots for K0 and K1 values. */
+ for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
+ {
+ numK0 = 0;
+ /* Storing the values of k0 based on time domain resource
+ * allocation list. If the value is unavailable then fill default values,
+ * As per 38.331 PDSCH-TimeDomainResourceAllocation field descriptions. */
+ for(k0Index = 0; ((k0Index < numTimeDomAlloc) && (k0Index < MAX_NUM_K0_IDX)); k0Index++)
+ {
+ /* TODO These if 0 we will remove during harq processing */
+#if 0
+ if(pdschCfgCmnPres == true)
+ {
+ k0TmpVal = cmnTimeDomRsrcAllocList[k0Index].k0;
+ }
+ else
+ {
+ if(dedTimeDomRsrcAllocList[k0Index].k0 != NULLP)
+ {
+ k0TmpVal = *(dedTimeDomRsrcAllocList[k0Index].k0);
+ }
+ else
+ {
+ k0TmpVal = DEFAULT_K0_VALUE;
+ }
+ }
+#endif
+ /* Checking all the Ul Alloc values. If value is less than MIN_NUM_K1_IDX
+ * then skip else continue storing the values. */
+ numK1 = 0;
+ for(k1Index = 0; k1Index < ulAckListCount; k1Index++)
+ {
+ k1TmpVal = UlAckTbl[k1Index];
+ if(k1TmpVal <= MIN_NUM_K1_IDX)
+ {
+ continue;
+ }
+
+ k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.k1Indexes[numK1++] = k1Index;
+ /* TODO Store K1 index where harq feedback will be received in harq table. */
+ }
+ if(numK1)
+ {
+ k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.numK1 = numK1;
+ k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k0Index = k0Index;
+ numK0++;
+ }
+ }
+ if(numK0)
+ {
+ k0K1InfoTbl->k0k1TimingInfo[slotIdx].numK0 = numK0;
+ }
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Fills k0 and k1 information table
+ *
+ * @details
+ *
+ * Function : BuildK0K1Table
+ *
+ * Functionality:
+ * Fills K0 and k1 information table
+ *
+ * @params[in] SchCellCb *cell,SchK0K1TimingInfoTbl *k0K1InfoTbl,bool
+ * pdschCfgCmnPres,uint8_t numTimeDomAlloc, SchPdschCfgCmnTimeDomRsrcAlloc
+ * cmnTimeDomRsrcAllocList[], SchPdschTimeDomRsrcAlloc
+ * dedTimeDomRsrcAllocList[], uint8_t ulAckListCount, uint8_t *UlAckTbl
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+void BuildK0K1Table(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres, SchPdschCfgCmn pdschCmnCfg,\
+SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl)
+{
+
+#ifdef NR_TDD
+ SlotConfig slotCfg;
+ bool ulSlotPresent = false;
+ uint8_t k0TmpVal = 0, k1TmpVal =0, tmpSlot=0, startSymbol=0, endSymbol=0, checkSymbol=0;
+ uint8_t slotIdx=0, k0Index=0, k1Index=0, numK0=0, numK1=0, cfgIdx=0, numTimeDomAlloc =0, totalCfgSlot =0;
+ SchPdschCfgCmnTimeDomRsrcAlloc cmnTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
+ SchPdschTimeDomRsrcAlloc dedTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
+#endif
+
+ if(cell->cellCfg.dupMode == DUPLEX_MODE_FDD)
+ {
+ BuildK0K1TableForFdd(cell, k0K1InfoTbl, pdschCfgCmnPres, pdschCmnCfg, pdschDedCfg, ulAckListCount, UlAckTbl);
+ }
+ else
+ {
+#ifdef NR_TDD
+
+ /* Initialization the K0K1 structure, total num of slot and calculating the slot pattern length. */
+ memset(k0K1InfoTbl, 0, sizeof(SchK0K1TimingInfoTbl));
+ k0K1InfoTbl->tblSize = cell->numSlots;
+ totalCfgSlot = calculateSlotPatternLength(cell->cellCfg.ssbSchCfg.scsCommon, cell->cellCfg.tddCfg.tddPeriod);
+
+ /* Storing time domain resource allocation list based on common or
+ * dedicated configuration availability. */
+ if(pdschCfgCmnPres == true)
+ {
+ numTimeDomAlloc = pdschCmnCfg.numTimeDomAlloc;
+ for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
+ {
+ cmnTimeDomRsrcAllocList[cfgIdx] = pdschCmnCfg.timeDomRsrcAllocList[cfgIdx];
+ }
+ }
+ else
+ {
+ numTimeDomAlloc = pdschDedCfg.numTimeDomRsrcAlloc;
+ for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
+ {
+ dedTimeDomRsrcAllocList[cfgIdx] = pdschDedCfg.timeDomRsrcAllociList[cfgIdx];
+ }
+ }
+
+ /* Checking all possible indexes for K0 and K1 values. */
+ for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
+ {
+ /* If current slot is UL or FLEXI then Skip because PDCCH is sent only in DL slots. */
+ slotCfg = schGetSlotSymbFrmt(slotIdx%totalCfgSlot, cell->slotFrmtBitMap);
+ if(slotCfg == UL_SLOT || slotCfg == FLEXI_SLOT)
+ {
+ continue;
+ }
+
+ /* Storing K0 , start symbol and length symbol for further processing.
+ * If K0 value is not available then we can fill the default values
+ * given in spec 38.331. */
+ numK0 = 0;
+ for(k0Index = 0; ((k0Index < numTimeDomAlloc) && (k0Index < MAX_NUM_K0_IDX)); k0Index++)
+ {
+ if(pdschCfgCmnPres == true)
+ {
+ k0TmpVal = cmnTimeDomRsrcAllocList[k0Index].k0;
+ startSymbol = cmnTimeDomRsrcAllocList[k0Index].startSymbol;
+ endSymbol = startSymbol + cmnTimeDomRsrcAllocList[k0Index].lengthSymbol;
+ }
+ else
+ {
+ if(dedTimeDomRsrcAllocList[k0Index].k0 != NULLP)
+ {
+ k0TmpVal = *(dedTimeDomRsrcAllocList[k0Index].k0);
+ }
+ else
+ {
+ k0TmpVal = DEFAULT_K0_VALUE;
+ }
+ startSymbol = dedTimeDomRsrcAllocList[k0Index].startSymbol;
+ endSymbol = startSymbol + dedTimeDomRsrcAllocList[k0Index].symbolLength;
+ }
+
+ /* If current slot + k0 is UL then skip the slot
+ * else if it is DL slot then continue the next steps
+ * else if it is a FLEXI slot then check symbols of slot, It should not
+ * contain any UL slot. */
+ tmpSlot = (slotIdx+k0TmpVal) % totalCfgSlot;
+ slotCfg = schGetSlotSymbFrmt(tmpSlot, cell->slotFrmtBitMap);
+ if(slotCfg == UL_SLOT)
+ {
+ continue;
+ }
+ if(slotCfg == FLEXI_SLOT)
+ {
+ for(checkSymbol = startSymbol; checkSymbol<endSymbol; checkSymbol ++)
+ {
+ slotCfg = cell->cellCfg.tddCfg.slotCfg[tmpSlot][checkSymbol];
+ if(slotCfg == UL_SLOT)
+ {
+ continue;
+ }
+ }
+ }
+
+ /* If current slot + k0 + k1 is a DL slot then skip the slot
+ * else if it is UL slot then store the information
+ * else if it is FLEXI slot then check the symbols, it must have
+ * at least one UL symbol. */
+ numK1 = 0;
+ for(k1Index = 0; k1Index < ulAckListCount; k1Index++)
+ {
+ k1TmpVal = UlAckTbl[k1Index];
+ if(k1TmpVal > MIN_NUM_K1_IDX)
+ {
+ tmpSlot = (slotIdx+k0TmpVal+k1TmpVal) % totalCfgSlot;
+ slotCfg = schGetSlotSymbFrmt(tmpSlot, cell->slotFrmtBitMap);
+ if(slotCfg == DL_SLOT)
+ {
+ continue;
+ }
+ if(slotCfg == FLEXI_SLOT)
+ {
+ for(checkSymbol = 0; checkSymbol< MAX_SYMB_PER_SLOT;checkSymbol++)
+ {
+ if(cell->cellCfg.tddCfg.slotCfg[tmpSlot][checkSymbol] == UL_SLOT)
+ {
+ ulSlotPresent = true;
+ break;
+ }
+ }
+ }
+ if(ulSlotPresent == true || slotCfg == UL_SLOT)
+ {
+ k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.k1Indexes[numK1++] = k1Index;
+ /* TODO Store K1 index where harq feedback will be received
+ * in harq table. */
+ }
+ }
+ }
+
+ /* Store all the values if all condition satisfies. */
+ if(numK1)
+ {
+ k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.numK1 = numK1;
+ k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k0Index = k0Index;
+ numK0++;
+ }
+ }
+ if(numK0)
+ {
+ k0K1InfoTbl->k0k1TimingInfo[slotIdx].numK0 = numK0;
+ }
+ }
+#endif
+ }
+}
+
+/*******************************************************************
+*
+* @brief Fills K2 information table for FDD
+*
+* @details
+*
+* Function : BuildK2InfoTableForFdd
+*
+* Functionality:
+* Fills K2 information table for FDD
+*
+* @params[in] SchCellCb *cell,SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[],
+* uint16_t puschSymTblSize,SchK2TimingInfoTbl *k2InfoTbl
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+void BuildK2InfoTableForFdd(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], uint16_t puschSymTblSize,\
+SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl)
+{
+ uint16_t slotIdx=0, k2Index=0, k2TmpIdx=0, msg3K2TmpIdx=0;
+
+ /* Initialization the structure and storing the total slot values. */
+ memset(k2InfoTbl, 0, sizeof(SchK2TimingInfoTbl));
+ k2InfoTbl->tblSize = cell->numSlots;
+ if(msg3K2InfoTbl)
+ msg3K2InfoTbl->tblSize = cell->numSlots;
+
+ /* Checking all possible indexes for K2. */
+ for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
+ {
+ /* Storing K2 values. */
+ for(k2Index = 0; ((k2Index < puschSymTblSize) && (k2Index < MAX_NUM_K2_IDX)); k2Index++)
+ {
+ k2TmpIdx= k2InfoTbl->k2TimingInfo[slotIdx].numK2;
+ k2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[k2TmpIdx] = k2Index;
+ k2InfoTbl->k2TimingInfo[slotIdx].numK2++;
+
+ /* Updating K2 values for MSG3 */
+ if(msg3K2InfoTbl)
+ {
+ msg3K2TmpIdx = msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2;
+ msg3K2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[msg3K2TmpIdx] = k2Index;
+ msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2++;
+ }
+ }
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Fills K2 information table
+ *
+ * @details
+ *
+ * Function : BuildK2InfoTable
+ *
+ * Functionality:
+ * Fills K2 information table
+ *
+ * @params[in] SchCellCb *cell,SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[],
+ * uint16_t puschSymTblSize, SchK2TimingInfoTbl *k2InfoTbl
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+void BuildK2InfoTable(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], uint16_t puschSymTblSize,\
+SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl)
+{
+
+#ifdef NR_TDD
+ bool dlSymbolPresent = false;
+ uint8_t slotIdx=0, k2Index=0, k2Val=0, k2TmpVal=0, msg3K2TmpVal=0, msg3Delta=0, numK2 =0, currentSymbol =0;
+ uint8_t startSymbol =0, endSymbol =0, checkSymbol=0, totalCfgSlot=0, slotCfg=0;
+ SlotConfig currentSlot;
+#endif
+
+ if(cell->cellCfg.dupMode == DUPLEX_MODE_FDD)
+ {
+ BuildK2InfoTableForFdd(cell, timeDomRsrcAllocList, puschSymTblSize, msg3K2InfoTbl, k2InfoTbl);
+ }
+ else
+ {
+#ifdef NR_TDD
+
+ /* Initialization the structure and storing the total slot values. */
+ memset(k2InfoTbl, 0, sizeof(SchK2TimingInfoTbl));
+ k2InfoTbl->tblSize = cell->numSlots;
+ if(msg3K2InfoTbl)
+ msg3K2InfoTbl->tblSize = cell->numSlots;
+ totalCfgSlot = calculateSlotPatternLength(cell->cellCfg.ssbSchCfg.scsCommon, cell->cellCfg.tddCfg.tddPeriod);
+
+ /* Checking all possible indexes for K2. */
+ for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
+ {
+ currentSlot = schGetSlotSymbFrmt(slotIdx % totalCfgSlot, cell->slotFrmtBitMap);
+
+ /* If current slot is UL then skip because PDCCH is sent only in DL slots */
+ if(currentSlot != UL_SLOT)
+ {
+ for(k2Index = 0; ((k2Index < puschSymTblSize) && (k2Index < MAX_NUM_K2_IDX)); k2Index++)
+ {
+ /* Storing k2, startSymbol, endSymbol information for further processing.
+ * If k2 is absent then fill the default values given in spec 38.331
+ * PUSCH-TimeDomainResourceAllocationList field descriptions */
+ k2Val = timeDomRsrcAllocList[k2Index].k2;
+ if(!k2Val)
+ {
+ switch(cell->cellCfg.ssbSchCfg.scsCommon)
+ {
+ case SCS_15KHZ:
+ k2Val = DEFAULT_K2_VALUE_FOR_SCS15;
+ break;
+ case SCS_30KHZ:
+ k2Val = DEFAULT_K2_VALUE_FOR_SCS30;
+ break;
+ case SCS_60KHZ:
+ k2Val = DEFAULT_K2_VALUE_FOR_SCS60;
+ break;
+ case SCS_120KHZ:
+ k2Val = DEFAULT_K2_VALUE_FOR_SCS120;
+ break;
+ }
+ }
+
+ /* Current slot + k2 should be either UL or FLEXI slot.
+ * If slot is FLEXI then check all the symbols of that slot,
+ * it should not contain any DL or FLEXI slot */
+ k2TmpVal = (slotIdx + k2Val) % totalCfgSlot;
+ slotCfg = schGetSlotSymbFrmt(k2TmpVal, cell->slotFrmtBitMap);
+ if(slotCfg != DL_SLOT)
+ {
+ if(slotCfg == FLEXI_SLOT)
+ {
+ startSymbol = timeDomRsrcAllocList[k2Index].startSymbol;
+ endSymbol = startSymbol+ timeDomRsrcAllocList[k2Index].symbolLength;
+ dlSymbolPresent = false;
+ for(checkSymbol= startSymbol; checkSymbol<endSymbol; checkSymbol++)
+ {
+ currentSymbol = cell->cellCfg.tddCfg.slotCfg[k2TmpVal][checkSymbol];
+ if(currentSymbol == DL_SLOT || currentSymbol == FLEXI_SLOT)
+ {
+ dlSymbolPresent = true;
+ break;
+ }
+ }
+ }
+ /* Store all the values if all condition satisfies. */
+ if(dlSymbolPresent != true || slotCfg == UL_SLOT)
+ {
+ numK2 = k2InfoTbl->k2TimingInfo[slotIdx].numK2;
+ k2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[numK2] = k2Index;
+ k2InfoTbl->k2TimingInfo[slotIdx].numK2++;
+ }
+ }
+
+ if(msg3K2InfoTbl)
+ {
+ msg3Delta = puschDeltaTable[cell->cellCfg.numerology];
+
+ /* Check for K2 for MSG3 */
+ /* Current slot + k2 should be either UL or FLEXI slot.
+ * If slot is FLEXI then check all the symbols of that slot,
+ * it should not contain any DL or FLEXI slot */
+ msg3K2TmpVal = (slotIdx + k2Val + msg3Delta) % totalCfgSlot;
+ slotCfg = schGetSlotSymbFrmt(msg3K2TmpVal, cell->slotFrmtBitMap);
+ if(slotCfg != DL_SLOT)
+ {
+ if(slotCfg == FLEXI_SLOT)
+ {
+ startSymbol = timeDomRsrcAllocList[k2Index].startSymbol;
+ endSymbol = startSymbol+ timeDomRsrcAllocList[k2Index].symbolLength;
+ dlSymbolPresent = false;
+ for(checkSymbol= startSymbol; checkSymbol<endSymbol; checkSymbol++)
+ {
+ currentSymbol = cell->cellCfg.tddCfg.slotCfg[msg3K2TmpVal][checkSymbol];
+ if(currentSymbol == DL_SLOT || currentSymbol == FLEXI_SLOT)
+ {
+ dlSymbolPresent = true;
+ break;
+ }
+ }
+ }
+ /* Store all the values if all condition satisfies. */
+ if(dlSymbolPresent != true || slotCfg == UL_SLOT)
+ {
+ numK2 = msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2;
+ msg3K2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[numK2] = k2Index;
+ msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2++;
+ }
+ }
+ }
+ }
+ }
+ }
+#endif
+ }
+}
+
+/*******************************************************************************************
+ *
+ * @brief Allocate the PRB using RRM policy
+ *
+ * @details
+ *
+ * Function : prbAllocUsingRRMPolicy
+ *
+ * Functionality:
+ * [Step1]: Traverse each Node in the LC list
+ * [Step2]: Check whether the LC has ZERO requirement then clean this LC
+ * [Step3]: Calcualte the maxPRB for this LC.
+ * a. For Dedicated LC, maxPRB = sum of remainingReservedPRB and
+ * sharedPRB
+ * b. For Default, just SharedPRB count
+ * [Step4]: If the LC is the First one to be allocated for this UE then add
+ * TX_PAYLODN_LEN to reqBO
+ * [Step5]: Calculate the estimate PRB and estimate BO to be allocated
+ * based on reqBO and maxPRB left.
+ * [Step6]: Based on calculated PRB, Update Reserved PRB and Shared PRB counts
+ * [Step7]: Deduce the reqBO based on allocBO and move the LC node to last.
+ * [Step8]: Continue the next loop from List->head
+ *
+ * [Loop Exit]:
+ * [Exit1]: If all the LCs are allocated in list
+ * [Exit2]: If PRBs are exhausted
+ *
+ * @params[in] I/P > lcLinkList pointer (LcInfo list)
+ * I/P > IsDedicatedPRB (Flag to indicate that RESERVED PRB to use
+ * I/P > mcsIdx and PDSCH symbols count
+ * I/P & O/P > Shared PRB , reserved PRB Count
+ * I/P & O/P > Total TBS size accumulated
+ * I/P & O/P > isTxPayloadLenAdded[For DL] : Decision flag to add the TX_PAYLOAD_HDR_LEN
+ * I/P & O/P > srRcvd Flag[For UL] : Decision flag to add UL_GRANT_SIZE
+ *
+ * @return void
+ *
+ * *******************************************************************************************/
+void prbAllocUsingRRMPolicy(CmLListCp *lcLL, bool isDedicatedPRB, uint16_t mcsIdx,uint8_t numSymbols,\
+ uint16_t *sharedPRB, uint16_t *reservedPRB, bool *isTxPayloadLenAdded, bool *srRcvd)
+{
+ CmLList *node = NULLP;
+ LcInfo *lcNode = NULLP;
+ uint16_t remReservedPRB = 0, estPrb = 0, maxPRB = 0;
+
+ if(lcLL == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH: LcList not present");
+ return;
+ }
+ node = lcLL->first;
+
+ /*Only for Dedicated LcList, Valid value will be assigned to remReservedPRB
+ * For Other LcList, remReservedPRB = 0*/
+ if(reservedPRB != NULLP && isDedicatedPRB == TRUE)
+ {
+ remReservedPRB = *reservedPRB;
+ }
+
+ /*[Step1]*/
+ while(node)
+ {
+#if 0
+ /*For Debugging purpose*/
+ printLcLL(lcLL);
+#endif
+ lcNode = (LcInfo *)node->node;
+
+ /* [Step2]: Below condition will hit in rare case as it has been taken care during the cleaning
+ * process of LCID which was fully allocated. Check is just for safety purpose*/
+ if(lcNode->reqBO == 0 && lcNode->allocBO == 0)
+ {
+ DU_LOG("\nERROR --> SCH: LCID:%d has no requirement, clearing this node",\
+ lcNode->lcId);
+ deleteNodeFromLList(lcLL, node);
+ SCH_FREE(lcNode, sizeof(LcInfo));
+ node = lcLL->first;
+ continue;
+ }
+
+ /*[Exit1]: All LCs are allocated(allocBO = 0 for fully unallocated LC)*/
+ if(lcNode->allocBO != 0)
+ {
+ DU_LOG("\nDEBUG --> SCH: All LC are allocated [SharedPRB:%d]",*sharedPRB);
+ return;
+ }
+
+ /*[Exit2]: If PRBs are exhausted*/
+ if(isDedicatedPRB)
+ {
+ /*Loop Exit: All resources exhausted*/
+ if(remReservedPRB == 0 && *sharedPRB == 0)
+ {
+ DU_LOG("\nDEBUG --> SCH: Dedicated resources exhausted for LC:%d",lcNode->lcId);
+ return;
+ }
+ }
+ else
+ {
+ /*Loop Exit: All resources exhausted*/
+ if(*sharedPRB == 0)
+ {
+ DU_LOG("\nDEBUG --> SCH: Default resources exhausted for LC:%d",lcNode->lcId);
+ return;
+ }
+ }
+
+ /*[Step3]*/
+ maxPRB = remReservedPRB + *sharedPRB;
+
+ /*[Step4]*/
+ if((isTxPayloadLenAdded != NULLP) && (*isTxPayloadLenAdded == FALSE))
+ {
+ DU_LOG("\nDEBUG --> SCH: LC:%d is the First node to be allocated which includes TX_PAYLOAD_HDR_LEN",\
+ lcNode->lcId);
+ *isTxPayloadLenAdded = TRUE;
+ lcNode->allocBO = calculateEstimateTBSize((lcNode->reqBO + TX_PAYLOAD_HDR_LEN),\
+ mcsIdx, numSymbols, maxPRB, &estPrb);
+ lcNode->allocBO -=TX_PAYLOAD_HDR_LEN;
+ }
+ else if((srRcvd != NULLP) && (*srRcvd == TRUE))
+ {
+ DU_LOG("\nDEBUG --> SCH: LC:%d is the First node to be allocated which includes UL_GRANT_SIZE",\
+ lcNode->lcId);
+ *srRcvd = FALSE;
+ lcNode->reqBO += UL_GRANT_SIZE;
+ lcNode->allocBO = calculateEstimateTBSize(lcNode->reqBO, mcsIdx, numSymbols, maxPRB, &estPrb);
+ }
+ else
+ {
+ /*[Step4]*/
+ lcNode->allocBO = calculateEstimateTBSize(lcNode->reqBO,\
+ mcsIdx, numSymbols, maxPRB, &estPrb);
+ }
+
+ /*[Step6]:Re-adjust the reservedPRB pool count and *SharedPRB Count based on
+ * estimated PRB allocated*/
+ if((isDedicatedPRB == TRUE) && (estPrb <= remReservedPRB))
+ {
+ remReservedPRB = remReservedPRB - estPrb;
+ }
+ else /*LC requirement need PRB share from SharedPRB*/
+ {
+ if(*sharedPRB <= (estPrb - remReservedPRB))
+ {
+ DU_LOG("\nDEBUG --> SCH: SharedPRB is less");
+ *sharedPRB = 0;
+ }
+ else
+ {
+ *sharedPRB = *sharedPRB - (estPrb - remReservedPRB);
+ }
+ remReservedPRB = 0;
+ }
+
+ /*[Step7]*/
+ lcNode->reqBO -= lcNode->allocBO; /*Update the reqBO with remaining bytes unallocated*/
+ lcNode->allocPRB = estPrb;
+ cmLListAdd2Tail(lcLL, cmLListDelFrm(lcLL, node));
+
+ /*[Step8]:Next loop: First LC to be picked from the list
+ * because Allocated Nodes are moved to the last*/
+ node = lcLL->first;
+
+ }
+ return;
+}
+
+/*******************************************************************************************
+ *
+ * @brief Check the LC List and fill the LC and GrantSize to be sent to MAC as
+ * BO Report
+ *
+ * @details
+ *
+ * Function : updateGrantSizeForBoRpt
+ *
+ * Functionality:
+ * Check the LC List and fill the LC and GrantSize to be sent to MAC as
+ * BO Report in dlMsgAlloc Pointer
+ *
+ * @params[in] I/P > lcLinkList pointer (LcInfo list)
+ * I/P & O/P > dlMsgAlloc[for DL](Pending LC to be added in this context)
+ * I/P & O/P > BsrInfo (applicable for UL)
+ * I/P & O/P > accumalatedBOSize
+ * @return void
+ *
+ * *******************************************************************************************/
+void updateGrantSizeForBoRpt(CmLListCp *lcLL, DlMsgAlloc *dlMsgAlloc,\
+ BsrInfo *bsrInfo, uint32_t *accumalatedBOSize)
+{
+ CmLList *node = NULLP, *next = NULLP;
+ LcInfo *lcNode = NULLP;
+ DlMsgSchInfo *dlMsgSchInfo = NULLP;
+
+ if(lcLL == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH: LcList not present");
+ return;
+ }
+
+ if(lcLL->count)
+ {
+ node = lcLL->first;
+ }
+ else
+ {
+ /*lcLL is empty*/
+ return;
+ }
+
+ /*Traverse List*/
+ while(node)
+ {
+ next = node->next;
+ lcNode = (LcInfo *)node->node;
+ if(lcNode != NULLP)
+ {
+ DU_LOG("\nINFO --> SCH : LcID:%d, [reqBO, allocBO, allocPRB]:[%d,%d,%d]",\
+ lcNode->lcId, lcNode->reqBO, lcNode->allocBO, lcNode->allocPRB);
+ if(dlMsgAlloc != NULLP)
+ {
+ dlMsgSchInfo = &dlMsgAlloc->dlMsgSchedInfo[dlMsgAlloc->numSchedInfo];
+
+ /*Add this LC to dlMsgAlloc so that if this LC gets allocated, BO
+ * report for allocation can be sent to MAC*/
+ dlMsgSchInfo->lcSchInfo[dlMsgSchInfo->numLc].lcId = lcNode->lcId;
+ dlMsgSchInfo->lcSchInfo[dlMsgSchInfo->numLc].schBytes = lcNode->allocBO;
+
+ /*Calculate the Total Payload/BO size allocated*/
+ *accumalatedBOSize += dlMsgSchInfo->lcSchInfo[dlMsgSchInfo->numLc].schBytes;
+
+ DU_LOG("\nINFO --> SCH: Added in MAC BO report: LCID:%d,reqBO:%d,Idx:%d, TotalBO Size:%d",\
+ lcNode->lcId,lcNode->reqBO, dlMsgSchInfo->numLc, *accumalatedBOSize);
+
+ dlMsgSchInfo->numLc++;
+ /*The LC has been fully allocated, clean it*/
+ if(lcNode->reqBO == 0)
+ {
+ handleLcLList(lcLL, lcNode->lcId, DELETE);
+ }
+ }
+ else if(bsrInfo != NULLP)
+ {
+ *accumalatedBOSize += lcNode->allocBO;
+ DU_LOG("\nINFO --> SCH: UL : LCID:%d,reqBO:%d, TotalBO Size:%d",\
+ lcNode->lcId,lcNode->reqBO, *accumalatedBOSize);
+ }
+ }
+ node = next;
+ }/*End of while*/
+ return;
+}
+
+/*******************************************************************
+*
+* @brief fill DL message information for MSG4 and Dedicated DL Msg
+*
+* @details
+*
+* Function : fillDlMsgInfo
+*
+* Functionality:
+* fill DL message information for MSG4 and Dedicated DL Msg
+*
+* @params[in] DlMsgInfo *dlMsgInfo, uint8_t crnti
+* @params[in] bool isRetx, SchDlHqProcCb *hqP
+* @return void
+*
+*******************************************************************/
+void fillDlMsgInfo(DlMsgInfo *dlMsgInfo, uint8_t crnti, bool isRetx, SchDlHqProcCb *hqP)
+{
+ hqP->tbInfo[0].isEnabled = TRUE;
+ hqP->tbInfo[0].state = HQ_TB_WAITING;
+ hqP->tbInfo[0].txCntr++;
+ hqP->tbInfo[1].isEnabled = TRUE;
+ hqP->tbInfo[1].state = HQ_TB_WAITING;
+ hqP->tbInfo[1].txCntr++;
+ dlMsgInfo->crnti = crnti;
+ dlMsgInfo->ndi = hqP->tbInfo[0].ndi; /*How to handle two tb case?TBD*/
+ dlMsgInfo->harqProcNum = hqP->procId;
+ dlMsgInfo->dlAssignIdx = 0;
+ dlMsgInfo->pucchTpc = 0;
+ dlMsgInfo->pucchResInd = 0;
+ dlMsgInfo->harqFeedbackInd = hqP->k1;
+ dlMsgInfo->dciFormatId = 1;
+}
+
+/*******************************************************************
+ *
+ * @brief sch Process pending Msg4 Req
+ *
+ * @details
+ *
+ * Function : schProcessMsg4Req
+ *
+ * Functionality:
+ * sch Process pending Msg4 Req
+ *
+ * @params[in] SchCellCb *cell, cell cb struct pointer
+ * @params[in] SlotTimingInfo currTime, current timing info
+ * @params[in] uint8_t ueId, ue ID
+ * @params[in] bool isRetxMsg4, indicator to MSG4 retransmission
+ * @params[in] SchDlHqProcCb **msg4HqProc, address of MSG4 HARQ proc pointer
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *******************************************************************/
+
+uint8_t schProcessMsg4Req(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId, bool isRetxMsg4, SchDlHqProcCb **msg4HqProc)
+{
+ uint8_t pdschStartSymbol = 0, pdschNumSymbols = 0;
+ SlotTimingInfo pdcchTime, pdschTime, pucchTime;
+ DlMsgAlloc *dciSlotAlloc = NULLP; /* Stores info for transmission of PDCCH for Msg4 */
+ DlMsgAlloc *msg4SlotAlloc = NULLP; /* Stores info for transmission of PDSCH for Msg4 */
+
+ if(cell == NULL)
+ {
+ DU_LOG("\nERROR --> SCH: schDlRsrcAllocMsg4() : Cell is NULL");
+ return RFAILED;
+ }
+
+ if (isRetxMsg4 == FALSE)
+ {
+ if (RFAILED == schDlGetAvlHqProcess(cell, &cell->ueCb[ueId - 1], msg4HqProc))
+ {
+ DU_LOG("\nERROR --> SCH: schDlRsrcAllocMsg4() : No process");
+ return RFAILED;
+ }
+ }
+
+ if(findValidK0K1Value(cell, currTime, ueId, false, &pdschStartSymbol, &pdschNumSymbols, &pdcchTime, &pdschTime,\
+ &pucchTime, isRetxMsg4, *msg4HqProc) != true )
+ {
+ DU_LOG("\nERROR --> SCH: schDlRsrcAllocMsg4() : k0 k1 not found");
+ return RFAILED;
+ }
+
+ if(cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1] == NULL)
+ {
+ SCH_ALLOC(dciSlotAlloc, sizeof(DlMsgAlloc));
+ if(dciSlotAlloc == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciSlotAlloc");
+ return RFAILED;
+ }
+ cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1] = dciSlotAlloc;
+ memset(dciSlotAlloc, 0, sizeof(DlMsgAlloc));
+ GET_CRNTI(dciSlotAlloc->crnti, ueId);
+ }
+ else
+ dciSlotAlloc = cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1];
+
+ /* Fill PDCCH and PDSCH scheduling information for Msg4 */
+ if((schDlRsrcAllocMsg4(cell, pdschTime, ueId, dciSlotAlloc, pdschStartSymbol, pdschNumSymbols, isRetxMsg4, *msg4HqProc)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCH: Scheduling of Msg4 failed in slot [%d]", pdschTime.slot);
+ if(dciSlotAlloc->numSchedInfo == 0)
+ {
+ SCH_FREE(dciSlotAlloc, sizeof(DlMsgAlloc));
+ cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1] = NULLP;
+ }
+ else
+ memset(&dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo], 0, sizeof(DlMsgSchInfo));
+ return RFAILED;
+ }
+
+ /* Check if both DCI and RAR are sent in the same slot.
+ * If not, allocate memory RAR PDSCH slot to store RAR info
+ */
+ if(pdcchTime.slot == pdschTime.slot)
+ {
+ dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo].pduPres = BOTH;
+ dciSlotAlloc->numSchedInfo++;
+ }
+ else
+ {
+ /* Allocate memory to schedule rarSlot to send RAR, pointer will be checked at schProcessSlotInd() */
+ if(cell->schDlSlotInfo[pdschTime.slot]->dlMsgAlloc[ueId-1] == NULL)
+ {
+ SCH_ALLOC(msg4SlotAlloc, sizeof(DlMsgAlloc));
+ if(msg4SlotAlloc == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH : Memory Allocation failed for msg4SlotAlloc");
+ if(dciSlotAlloc->numSchedInfo == 0)
+ {
+ SCH_FREE(dciSlotAlloc, sizeof(DlMsgAlloc));
+ cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1] = NULLP;
+ }
+ else
+ memset(&dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo], 0, sizeof(DlMsgSchInfo));
+ return RFAILED;
+ }
+ cell->schDlSlotInfo[pdschTime.slot]->dlMsgAlloc[ueId-1] = msg4SlotAlloc;
+ memset(msg4SlotAlloc, 0, sizeof(DlMsgAlloc));
+ msg4SlotAlloc->crnti = dciSlotAlloc->crnti;
+ }
+ else
+ msg4SlotAlloc = cell->schDlSlotInfo[pdschTime.slot]->dlMsgAlloc[ueId-1];
+
+ /* Copy all RAR info */
+ memcpy(&msg4SlotAlloc->dlMsgSchedInfo[msg4SlotAlloc->numSchedInfo], \
+ &dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo], sizeof(DlMsgSchInfo));
+ msg4SlotAlloc->dlMsgSchedInfo[msg4SlotAlloc->numSchedInfo].dlMsgPdcchCfg.dci.pdschCfg = \
+ &msg4SlotAlloc->dlMsgSchedInfo[msg4SlotAlloc->numSchedInfo].dlMsgPdschCfg;
+
+ /* Assign correct PDU types in corresponding slots */
+ msg4SlotAlloc->dlMsgSchedInfo[msg4SlotAlloc->numSchedInfo].pduPres = PDSCH_PDU;
+ dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo].pduPres = PDCCH_PDU;
+ dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo].pdschSlot = pdschTime.slot;
+
+ dciSlotAlloc->numSchedInfo++;
+ msg4SlotAlloc->numSchedInfo++;
+ }
+
+ /* PUCCH resource */
+ schAllocPucchResource(cell, pucchTime, cell->raCb[ueId-1].tcrnti, &cell->ueCb[ueId-1], isRetxMsg4, *msg4HqProc);
+
+ cell->schDlSlotInfo[pdcchTime.slot]->pdcchUe = ueId;
+ cell->schDlSlotInfo[pdschTime.slot]->pdschUe = ueId;
+ cell->schUlSlotInfo[pucchTime.slot]->pucchUe = ueId;
+ cell->raCb[ueId-1].msg4recvd = FALSE;
+ if(isRetxMsg4)
+ {
+ cell->ueCb[ueId-1].retxMsg4HqProc= NULLP;
+ }
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Handler to calculate TBS size for BSR requested
+ *
+ * @details
+ *
+ * Function : schCalculateUlTbs
+ *
+ * Functionality: Function will note the required TBS for each LCGIDX and use
+ * the Priority LCG List and RRM policy to allocate the TBS size
+ *
+ * @params [in] ueCb (Pointer to UE CB)
+ * [in] puschTime (Time slot where PUSCH will be sent)
+ * [in] symbLen (No of Symbols used for PUSCH transmission)
+ * [out] startPrb(Pointer to startPRB which will be calculated while
+ * finding the best Free Block)
+ * [out] totTBS(Pointer to total TBS size)
+ * [in] isRetx (to indicate retransmission)
+ * [in] hqP (UL Harq process pointer)
+ *
+ * @return uint8_t : ROK > Scheduling of UL grant is successful
+ * RFAILED > vice versa
+ *
+ * ****************************************************************/
+uint8_t schCalculateUlTbs(SchUeCb *ueCb, SlotTimingInfo puschTime, uint8_t symbLen,\
+ uint16_t *startPrb, uint32_t *totTBS, bool isRetx, SchUlHqProcCb *hqP)
+{
+ uint16_t mcsIdx = 0;
+ CmLListCp *lcLL = NULLP;
+ uint16_t lcgIdx = 0, lcId =0, maxFreePRB = 0;
+ uint16_t rsvdDedicatedPRB;
+ *startPrb = 0;
+ *totTBS = 0;
+
+ /* check for BSR */
+ for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
+ {
+ if(ueCb->bsrInfo[lcgIdx].dataVol == 0)
+ {
+ continue;
+ }
+
+ /*TODO: lcgIdx and LCID has been implemented as one to one mapping.
+ * Need to check the mapping to figure out the LCID and lcgIdx once L2
+ * spec specifies any logic*/
+ lcId = lcgIdx;
+ if(ueCb->ulInfo.ulLcCtxt[lcId].isDedicated)
+ {
+ lcLL = &(hqP->ulLcPrbEst.dedLcList);
+ rsvdDedicatedPRB = ueCb->ulInfo.ulLcCtxt[lcId].rsvdDedicatedPRB;
+ }
+ else
+ {
+ lcLL = &(hqP->ulLcPrbEst.defLcList);
+ }
+
+ /*[Step2]: Update the reqPRB and Payloadsize for this LC in the appropriate List*/
+ if(updateLcListReqPRB(lcLL, lcId, ueCb->bsrInfo[lcgIdx].dataVol) != ROK)
+ {
+ DU_LOG("\nERROR --> SCH: LcgId:%d updation failed",lcId);
+ return RFAILED;
+ }
+ }
+
+ if ((hqP->ulLcPrbEst.defLcList.count == 0) && (hqP->ulLcPrbEst.dedLcList.count == 0))
+ {
+ if( (ueCb->srRcvd) || (isRetx) )
+ {
+ *startPrb = MAX_NUM_RB;
+ *totTBS = schCalcTbSize(UL_GRANT_SIZE);
+ }
+ /*Returning true when NO Grant is there for UE as this is not scheduling
+ * error*/
+ return ROK;
+ }
+
+ maxFreePRB = searchLargestFreeBlock(ueCb->cellCb, puschTime, startPrb, DIR_UL);
+
+ /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
+ * the list based on RRM policy*/
+
+ /*Either this UE contains no reservedPRB pool fir dedicated S-NSSAI or
+ * Num of Free PRB available is not enough to reserve Dedicated PRBs*/
+ if(maxFreePRB != 0)
+ {
+ mcsIdx = ueCb->ueCfg.ulModInfo.mcsIndex;
+ if((hqP->ulLcPrbEst.dedLcList.count == 0) || ((maxFreePRB < rsvdDedicatedPRB)))
+ {
+ hqP->ulLcPrbEst.sharedNumPrb = maxFreePRB;
+ DU_LOG("\nDEBUG --> SCH : UL Only Default Slice is scheduled, sharedPRB Count:%d",\
+ hqP->ulLcPrbEst.sharedNumPrb);
+
+ /*PRB Alloc for Default LCs*/
+ prbAllocUsingRRMPolicy(&(hqP->ulLcPrbEst.defLcList), FALSE, mcsIdx, symbLen,\
+ &(hqP->ulLcPrbEst.sharedNumPrb), NULLP, NULLP,&(ueCb->srRcvd));
+ }
+ else
+ {
+ hqP->ulLcPrbEst.sharedNumPrb = maxFreePRB - rsvdDedicatedPRB;
+
+ /*PRB Alloc for Dedicated LCs*/
+ prbAllocUsingRRMPolicy(&(hqP->ulLcPrbEst.dedLcList), TRUE, mcsIdx, symbLen,\
+ &(hqP->ulLcPrbEst.sharedNumPrb), &(rsvdDedicatedPRB),\
+ NULLP,&(ueCb->srRcvd));
+
+ /*PRB Alloc for Default LCs*/
+ prbAllocUsingRRMPolicy(&(hqP->ulLcPrbEst.defLcList), FALSE, mcsIdx, symbLen, \
+ &(hqP->ulLcPrbEst.sharedNumPrb), &(rsvdDedicatedPRB),\
+ NULLP,&(ueCb->srRcvd));
+ }
+ }
+ /*[Step5]:Traverse each LCID in LcList to calculate the exact Scheduled Bytes
+ * using allocated BO per LC and Update dlMsgAlloc(BO report for MAC*/
+ if(hqP->ulLcPrbEst.dedLcList.count != 0)
+ updateGrantSizeForBoRpt(&(hqP->ulLcPrbEst.dedLcList), NULLP, ueCb->bsrInfo, totTBS);
+
+ updateGrantSizeForBoRpt(&(hqP->ulLcPrbEst.defLcList), NULLP, ueCb->bsrInfo, totTBS);
+
+ /*Below case will hit if NO LC(s) are allocated due to resource crunch*/
+ if (*totTBS == 0)
+ {
+ if(maxFreePRB == 0)
+ {
+ DU_LOG("\nERROR --> SCH : NO FREE PRB!!");
+ }
+ else
+ {
+ /*Schedule the LC for next slot*/
+ DU_LOG("\nDEBUG --> SCH : No LC has been scheduled");
+ }
+ return RFAILED;
+ }
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief sch Process pending Sr or Bsr Req
+ *
+ * @details
+ *
+ * Function : schProcessSrOrBsrReq
+ *
+ * Functionality:
+ * sch Process pending Sr or Bsr Req
+ *
+ * @params[in] SchCellCb *cell, SlotTimingInfo currTime
+ * @params[in] uint8_t ueId, Bool isRetx, SchUlHqProcCb **hqP
+ * @return true - success
+ * false - failure
+ *
+ *******************************************************************/
+bool schProcessSrOrBsrReq(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId, bool isRetx, SchUlHqProcCb **hqP)
+{
+ bool k2Found = FALSE, ret = RFAILED;
+ uint8_t startSymb = 0, symbLen = 0;
+ uint8_t k2TblIdx = 0, k2Index = 0, k2Val = 0;
+ uint16_t startPrb = 0;
+ uint32_t totDataReq = 0; /* in bytes */
+ SchUeCb *ueCb;
+ SchPuschInfo *puschInfo;
+ DciInfo *dciInfo = NULLP;
+ SchK2TimingInfoTbl *k2InfoTbl=NULLP;
+ SlotTimingInfo dciTime, puschTime;
+
+ if(cell == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH: schProcessSrOrBsrReq() : Cell is NULL");
+ return false;
+ }
+
+ ueCb = &cell->ueCb[ueId-1];
+
+ if(ueCb == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH: schProcessSrOrBsrReq() : UE is NULL");
+ return false;
+ }
+
+ if (isRetx == FALSE)
+ {
+ if (schUlGetAvlHqProcess(cell, ueCb, hqP) != ROK)
+ {
+ return RFAILED;
+ }
+ }
+
+ /* Calculating time frame to send DCI for SR */
+ ADD_DELTA_TO_TIME(currTime, dciTime, PHY_DELTA_DL + SCHED_DELTA);
+#ifdef NR_TDD
+ if(schGetSlotSymbFrmt(dciTime.slot, cell->slotFrmtBitMap) == DL_SLOT)
+#endif
+ {
+ if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt)
+ k2InfoTbl = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl;
+ else
+ k2InfoTbl = &cell->cellCfg.schInitialUlBwp.k2InfoTbl;
+
+ for(k2TblIdx = 0; k2TblIdx < k2InfoTbl->k2TimingInfo[dciTime.slot].numK2; k2TblIdx++)
+ {
+ k2Index = k2InfoTbl->k2TimingInfo[dciTime.slot].k2Indexes[k2TblIdx];
+
+ if(!ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt)
+ {
+ k2Val = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].k2;
+ startSymb = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].startSymbol;
+ symbLen = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].symbolLength;
+ }
+ else
+ {
+ k2Val = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[k2Index].k2;
+ startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[k2Index].startSymbol;
+ symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[k2Index].symbolLength;
+ }
+ /* Check for number of Symbol of PUSCH should be same as original in case of transmisson*/
+ /* Calculating time frame to send PUSCH for SR */
+ ADD_DELTA_TO_TIME(dciTime, puschTime, k2Val);
+#ifdef NR_TDD
+ if(schGetSlotSymbFrmt(puschTime.slot, cell->slotFrmtBitMap) == DL_SLOT)
+ continue;
+#endif
+ if(cell->schUlSlotInfo[puschTime.slot]->puschUe != 0)
+ {
+ continue;
+ }
+ k2Found = true;
+ break;
+ }
+ }
+
+ if(k2Found == true)
+ {
+ ret = schCalculateUlTbs(ueCb, puschTime, symbLen, &startPrb, &totDataReq, isRetx, *hqP);
+
+ if(totDataReq > 0 && ret == ROK)
+ {
+ SCH_ALLOC(dciInfo, sizeof(DciInfo));
+ if(!dciInfo)
+ {
+ DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
+ if(isRetx != TRUE)
+ {
+ if((*hqP)->ulLcPrbEst.dedLcList.count != 0)
+ updateBsrAndLcList(&((*hqP)->ulLcPrbEst.dedLcList), ueCb->bsrInfo, RFAILED);
+
+ updateBsrAndLcList(&((*hqP)->ulLcPrbEst.defLcList), ueCb->bsrInfo, RFAILED);
+ }
+ return false;
+ }
+ cell->schDlSlotInfo[dciTime.slot]->ulGrant = dciInfo;
+ memset(dciInfo,0,sizeof(DciInfo));
+
+ /* Update PUSCH allocation */
+ if(schFillPuschAlloc(ueCb, puschTime, totDataReq, startSymb, symbLen, startPrb, isRetx, *hqP) == ROK)
+ {
+ if(cell->schUlSlotInfo[puschTime.slot]->schPuschInfo)
+ {
+ puschInfo = cell->schUlSlotInfo[puschTime.slot]->schPuschInfo;
+ if(puschInfo != NULLP)
+ {
+ /* Fill DCI for UL grant */
+ schFillUlDci(ueCb, puschInfo, dciInfo, isRetx, *hqP);
+ memcpy(&dciInfo->slotIndInfo, &dciTime, sizeof(SlotTimingInfo));
+ ueCb->srRcvd = false;
+ ueCb->bsrRcvd = false;
+ cell->schUlSlotInfo[puschTime.slot]->puschUe = ueId;
+ if((*hqP)->ulLcPrbEst.dedLcList.count != 0)
+ updateBsrAndLcList(&((*hqP)->ulLcPrbEst.dedLcList), ueCb->bsrInfo, ROK);
+ updateBsrAndLcList(&((*hqP)->ulLcPrbEst.defLcList), ueCb->bsrInfo, ROK);
+ cmLListAdd2Tail(&(ueCb->hqUlmap[puschTime.slot]->hqList), &(*hqP)->ulSlotLnk);
+ return true;
+ }
+ }
+ }
+ if((*hqP)->ulLcPrbEst.dedLcList.count != 0)
+ updateBsrAndLcList(&((*hqP)->ulLcPrbEst.dedLcList), ueCb->bsrInfo, RFAILED);
+ updateBsrAndLcList(&((*hqP)->ulLcPrbEst.defLcList), ueCb->bsrInfo, RFAILED);
+ }
+ }
+ return (ret);
+}
+
+
+/*******************************************************************
+ *
+ * @brief sch Process pending Sr or Bsr Req
+ *
+ * @details
+ *
+ * Function : updateBsrAndLcList
+ *
+ * Functionality:
+ * Updating the BSRInfo in UECB and Lclist
+ *
+ * @params[in] SchCellCb *cell, SlotTimingInfo currTime
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *******************************************************************/
+void updateBsrAndLcList(CmLListCp *lcLL, BsrInfo *bsrInfo, uint8_t status)
+{
+ CmLList *node = NULLP, *next = NULLP;
+ LcInfo *lcNode = NULLP;
+
+ if(lcLL == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH: LcList not present");
+ return;
+ }
+
+ if(lcLL->count)
+ {
+ node = lcLL->first;
+ }
+ else
+ {
+ /*lcLL is empty*/
+ return;
+ }
+
+ while(node)
+ {
+ next = node->next;
+ lcNode = (LcInfo *)node->node;
+ if(lcNode != NULLP)
+ {
+ /*Only when Status is OK then allocation is marked as ZERO and reqBO
+ * is updated in UE's DB. If Failure, then allocation is added to reqBO
+ * and same is updated in Ue's DB inside BSR Info structure*/
+ if(status == ROK)
+ {
+ lcNode->allocBO = 0;
+ }
+
+ lcNode->reqBO += lcNode->allocBO;
+ bsrInfo[lcNode->lcId].dataVol = lcNode->reqBO;
+ if(lcNode->reqBO == 0)
+ {
+ handleLcLList(lcLL, lcNode->lcId, DELETE);
+ }
+ }
+ node = next;
+ }
+}
+
+/********************************************************************************
+ *
+ * @brief Increment the Slot by a input factor
+ *
+ * @details
+ *
+ * Function : schIncrSlot
+ *
+ * Functionality:
+ * Increment the slot by a input factor till num of Slots configured in a
+ * Radio Frame. If it exceeds, move to next sfn.
+ *
+ * @params[in/out] SlotTimingInfo timingInfo
+ * [in] uint8_t incr [Increment factor]
+ * [in] numSlotsPerRF [Number of Slots configured per RF as per
+ * numerology]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *******************************************************************/
+void schIncrSlot(SlotTimingInfo *timingInfo, uint8_t incr, uint16_t numSlotsPerRF)
+{
+ timingInfo->slot += incr;
+ if(timingInfo->slot >= numSlotsPerRF)
+ {
+ timingInfo->sfn += timingInfo->slot/numSlotsPerRF;
+ timingInfo->slot %= numSlotsPerRF;
+ if(timingInfo->sfn > MAX_SFN)
+ {
+ timingInfo->sfn %= MAX_SFN;
+ }
+ }
+}
+
+/*******************************************************************
+*
+* @brief Fill PDSCH info in Page Alloc
+*
+* @details
+*
+* Function : schFillPagePdschCfg
+*
+* Functionality: Fill PDSCH info in Page Alloc
+*
+* @params[in] SchCellCb *cell, PdschCfg *pagePdschCfg, SlotTimingInfo slotTime,
+* uint16_t tbsSize, uint8_t mcs, uint16_t startPrb
+*
+* @return pointer to return Value(ROK, RFAILED)
+*
+* ****************************************************************/
+uint8_t schFillPagePdschCfg(SchCellCb *cell, PdschCfg *pagePdschCfg, SlotTimingInfo slotTime, uint16_t tbSize, uint8_t mcs, uint16_t startPrb)
+{
+ uint8_t cwCount = 0;
+ uint8_t dmrsStartSymbol, startSymbol, numSymbol;
+
+ /* fill the PDSCH PDU */
+
+ pagePdschCfg->pduBitmap = 0; /* PTRS and CBG params are excluded */
+ pagePdschCfg->rnti = P_RNTI; /* SI-RNTI */
+ pagePdschCfg->pduIndex = 0;
+ pagePdschCfg->numCodewords = 1;
+ for(cwCount = 0; cwCount < pagePdschCfg->numCodewords; cwCount++)
+ {
+ pagePdschCfg->codeword[cwCount].targetCodeRate = 308;
+ pagePdschCfg->codeword[cwCount].qamModOrder = 2;
+ pagePdschCfg->codeword[cwCount].mcsIndex = mcs;
+ pagePdschCfg->codeword[cwCount].mcsTable = 0; /* notqam256 */
+ pagePdschCfg->codeword[cwCount].rvIndex = 0;
+ tbSize = tbSize + TX_PAYLOAD_HDR_LEN;
+ pagePdschCfg->codeword[cwCount].tbSize = tbSize;
+ }
+ pagePdschCfg->dataScramblingId = cell->cellCfg.phyCellId;
+ pagePdschCfg->numLayers = 1;
+ pagePdschCfg->transmissionScheme = 0;
+ pagePdschCfg->refPoint = 0;
+ pagePdschCfg->dmrs.dlDmrsSymbPos = 4; /* Bitmap value 00000000000100 i.e. using 3rd symbol for PDSCH DMRS */
+ pagePdschCfg->dmrs.dmrsConfigType = 0; /* type-1 */
+ pagePdschCfg->dmrs.dlDmrsScramblingId = cell->cellCfg.phyCellId;
+ pagePdschCfg->dmrs.scid = 0;
+ pagePdschCfg->dmrs.numDmrsCdmGrpsNoData = 1;
+ pagePdschCfg->dmrs.dmrsPorts = 0x0001;
+ pagePdschCfg->dmrs.mappingType = DMRS_MAP_TYPE_A; /* Type-A */
+ pagePdschCfg->dmrs.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
+ pagePdschCfg->dmrs.dmrsAddPos = DMRS_ADDITIONAL_POS;
+
+ pagePdschCfg->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
+ /* the RB numbering starts from coreset0, and PDSCH is always above SSB */
+ pagePdschCfg->pdschFreqAlloc.freqAlloc.startPrb = startPrb;
+ pagePdschCfg->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize, mcs, NUM_PDSCH_SYMBOL);
+ pagePdschCfg->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
+ pagePdschCfg->pdschTimeAlloc.rowIndex = 1;
+ /* This is Intel's requirement. PDSCH should start after PDSCH DRMS symbol */
+ pagePdschCfg->pdschTimeAlloc.timeAlloc.startSymb = 3; /* spec-38.214, Table 5.1.2.1-1 */
+ pagePdschCfg->pdschTimeAlloc.timeAlloc.numSymb = NUM_PDSCH_SYMBOL;
+
+ /* Find total symbols occupied including DMRS */
+ dmrsStartSymbol = findDmrsStartSymbol(pagePdschCfg->dmrs.dlDmrsSymbPos);
+ /* If there are no DRMS symbols, findDmrsStartSymbol() returns MAX_SYMB_PER_SLOT,
+ * in that case only PDSCH symbols are marked as occupied */
+ if(dmrsStartSymbol == MAX_SYMB_PER_SLOT)
+ {
+ startSymbol = pagePdschCfg->pdschTimeAlloc.timeAlloc.startSymb;
+ numSymbol = pagePdschCfg->pdschTimeAlloc.timeAlloc.numSymb;
+ }
+ /* If DMRS symbol is found, mark DMRS and PDSCH symbols as occupied */
+ else
+ {
+ startSymbol = dmrsStartSymbol;
+ numSymbol = pagePdschCfg->dmrs.nrOfDmrsSymbols + pagePdschCfg->pdschTimeAlloc.timeAlloc.numSymb;
+ }
+
+ /* Allocate the number of PRBs required for DL PDSCH */
+ if((allocatePrbDl(cell, slotTime, startSymbol, numSymbol,\
+ &pagePdschCfg->pdschFreqAlloc.freqAlloc.startPrb, pagePdschCfg->pdschFreqAlloc.freqAlloc.numPrb)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCH : allocatePrbDl() failed for DL MSG");
+ return RFAILED;
+ }
+
+ pagePdschCfg->beamPdschInfo.numPrgs = 1;
+ pagePdschCfg->beamPdschInfo.prgSize = 1;
+ pagePdschCfg->beamPdschInfo.digBfInterfaces = 0;
+ pagePdschCfg->beamPdschInfo.prg[0].pmIdx = 0;
+ pagePdschCfg->beamPdschInfo.prg[0].beamIdx[0] = 0;
+ pagePdschCfg->txPdschPower.powerControlOffset = 0;
+ pagePdschCfg->txPdschPower.powerControlOffsetSS = 0;
+
+ return ROK;
+}
+