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 *******************************************************************************/
20 #define SCH_INST_START 1
21 #define SCH_MAX_INST 1
22 #define SCH_MU0_NUM_SLOTS 10
23 #define SCH_MU1_NUM_SLOTS 20
24 #define SCH_MU2_NUM_SLOTS 30
25 #define SCH_MU3_NUM_SLOTS 40
26 #define SCH_MU4_NUM_SLOTS 50
27 #define SCH_MAX_SFN 1024
28 #define SCH_MIB_TRANS 8 /* MIB transmission as per 38.331 is every 80 ms */
29 #define SCH_SIB1_TRANS 16 /* SIB1 transmission as per 38.331 is every 160 ms */
30 #define SCH_NUM_SC_PRB 12 /* number of SCs in a PRB */
31 #define SCH_MAX_SSB_BEAM 8 /* since we are supporting only SCS=15KHz and 30KHz */
32 #define SCH_SSB_NUM_SYMB 4
33 #define SCH_SSB_NUM_PRB 21 /* One extra PRB as buffer */
38 #define PDSCH_START_RB 10
39 /* Considering pdsch region from 3 to 13, DMRS exclued.
40 * Overlapping of PDSCH DRMS and PDSCH not supported by Intel L1 */
41 #define NUM_PDSCH_SYMBOL 11
42 #define PUSCH_START_RB 15
43 #define PUCCH_NUM_PRB_FORMAT_0_1_4 1 /* number of PRBs in freq domain, spec 38.213 - 9.2.1 */
44 #define SI_RNTI 0xFFFF
46 #define DMRS_MAP_TYPE_A 1
47 #define NUM_DMRS_SYMBOLS 1
48 #define DMRS_ADDITIONAL_POS 0
49 #define SCH_DEFAULT_K1 1
50 #define SCH_TQ_SIZE 10
51 #define SSB_IDX_SUPPORTED 1
56 #define MAC_HDR_SIZE 3 /* 3 bytes of MAC Header */
57 #define UL_GRANT_SIZE 224
59 #define PRB_BITMAP_IDX_LEN 64
60 #define PRB_BITMAP_MAX_IDX ((MAX_NUM_RB + PRB_BITMAP_IDX_LEN-1) / PRB_BITMAP_IDX_LEN)
62 typedef struct schCellCb SchCellCb;
63 typedef struct schUeCb SchUeCb;
76 SCH_UE_STATE_INACTIVE,
78 SCH_UE_HANDIN_IN_PROGRESS
83 SCH_LC_STATE_INACTIVE,
96 * Structure holding LTE MAC's General Configuration information.
98 typedef struct schGenCb
100 uint8_t tmrRes; /*!< Timer resolution */
101 uint8_t startCellId; /*!< Starting Cell Id */
103 bool forceCntrlSrbBoOnPCel; /*!< value 1 means force scheduling
104 of RLC control BO and SRB BO on
105 PCell. val 0 means don't force*/
106 bool isSCellActDeactAlgoEnable; /*!< TRUE will enable activation/deactivation algo at Schd */
110 typedef struct freePrbBlock
119 * PRB allocations for a symbol within a slot
121 typedef struct schPrbAlloc
123 CmLListCp freePrbBlockList; /*!< List of continuous blocks for available PRB */
124 uint64_t prbBitMap[ MAX_SYMB_PER_SLOT][PRB_BITMAP_MAX_IDX]; /*!< BitMap to store the allocated PRBs */
129 * scheduler allocationsfor DL per cell.
131 typedef struct schDlSlotInfo
133 SchPrbAlloc prbAlloc; /*!< PRB allocated/available in this slot */
134 bool ssbPres; /*!< Flag to determine if SSB is present in this slot */
135 uint8_t ssbIdxSupported; /*!< Max SSB index */
136 SsbInfo ssbInfo[MAX_SSB_IDX]; /*!< SSB info */
137 bool sib1Pres; /*!< Flag to determine if SIB1 is present in this slot */
138 uint8_t pdcchUe; /*!< UE for which PDCCH is scheduled in this slot */
139 uint8_t pdschUe; /*!< UE for which PDSCH is scheduled in this slot */
140 RarAlloc *rarAlloc[MAX_NUM_UE]; /*!< RAR allocation per UE*/
142 DlMsgAlloc *dlMsgAlloc[MAX_NUM_UE]; /*!< Dl msg allocation per UE*/
145 typedef struct schRaCb
149 uint16_t dlMsgPduLen;
154 * scheduler allocationsfor UL per cell.
156 typedef struct schUlSlotInfo
158 SchPrbAlloc prbAlloc; /*!< PRB allocated/available per symbol */
159 uint8_t puschCurrentPrb; /*!< Current PRB for PUSCH allocation */
160 bool puschPres; /*!< PUSCH presence field */
161 SchPuschInfo *schPuschInfo; /*!< PUSCH info */
162 bool pucchPres; /*!< PUCCH presence field */
163 SchPucchInfo schPucchInfo; /*!< PUCCH info */
164 uint8_t pucchUe; /*!< Store UE id for which PUCCH is scheduled */
165 uint8_t puschUe; /*!< Store UE id for which PUSCH is scheduled */
170 * BSR info per slot per UE.
172 typedef struct bsrInfo
174 uint8_t priority; /* CG priority */
175 uint32_t dataVol; /* Data volume requested in bytes */
178 typedef struct schLcCtxt
180 uint8_t lcId; // logical Channel ID
181 uint8_t lcp; // logical Channel Prioritization
184 uint16_t pduSessionId; /*Pdu Session Id*/
185 Snssai *snssai; /*S-NSSAI assoc with LCID*/
186 bool isDedicated; /*Flag containing Dedicated S-NSSAI or not*/
189 typedef struct schDlCb
191 SchDlLcCtxt dlLcCtxt[MAX_NUM_LC];
194 typedef struct schUlLcCtxt
201 uint8_t pbr; // prioritisedBitRate
202 uint8_t bsd; // bucketSizeDuration
203 uint16_t pduSessionId; /*Pdu Session Id*/
204 Snssai *snssai; /*S-NSSAI assoc with LCID*/
205 bool isDedicated; /*Flag containing Dedicated S-NSSAI or not*/
208 typedef struct schUlCb
210 SchUlLcCtxt ulLcCtxt[MAX_NUM_LC];
213 typedef struct schUeCfgCb
218 bool macCellGrpCfgPres;
219 SchMacCellGrpCfg macCellGrpCfg;
220 bool phyCellGrpCfgPres;
221 SchPhyCellGrpCfg phyCellGrpCfg;
223 SchSpCellCfg spCellCfg;
225 SchModulationInfo dlModInfo;
226 SchModulationInfo ulModInfo;
227 SchDataTransmission dataTransmissionAction;
230 /*Following structures to keep record and estimations of PRB allocated for each
231 * LC taking into consideration the RRM policies*/
232 typedef struct lcInfo
234 uint8_t lcId; /*LCID for which BO are getting recorded*/
235 uint32_t reqBO; /*Size of the BO requested/to be allocated for this LC*/
236 uint32_t allocBO; /*TBS/BO Size which is actually allocated*/
237 uint8_t allocPRB; /*PRB count which is allocated based on RRM policy/FreePRB*/
240 typedef struct dedicatedLCInfo
242 CmLListCp dedLcList; /*Linklist of LC assoc with RRMPolicyMemberList*/
243 uint16_t rsvdDedicatedPRB; /*Number of PRB reserved for this Dedicated S-NSSAI*/
246 typedef struct schLcPrbEstimate
248 /* TODO: For Multiple RRMPolicies, Make DedicatedLcInfo as array/Double Pointer
249 * and have separate DedLCInfo for each RRMPolcyMemberList*/
250 /* Dedicated LC List will be allocated, if any available*/
251 DedicatedLCInfo *dedLcInfo; /*Contain LCInfo per RRMPolicy*/
253 CmLListCp defLcList; /*Linklist of LC assoc with Default S-NSSAI(s)*/
255 /* SharedPRB number can be used by any LC.
256 * Need to calculate in every Slot based on PRB availability*/
257 uint16_t sharedNumPrb;
264 typedef struct schUeCb
273 BsrInfo bsrInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS];
276 SchLcPrbEstimate dlLcPrbEst; /*DL PRB Alloc Estimate among different LC*/
277 SchLcPrbEstimate ulLcPrbEst; /*UL PRB Alloc Estimate among different LC*/
284 typedef struct schRaReq
287 RachIndInfo *rachInd;
288 SlotTimingInfo winStartTime;
289 SlotTimingInfo winEndTime;
292 typedef struct schPageInfo
294 uint8_t pf; /*Value of Paging Frame received from DUAPP*/
295 uint8_t i_s; /*Value of Paging Occ Index received from DUAPP*/
296 SlotTimingInfo TxTime; /*Start Paging window*/
297 uint8_t crntSsbIdx; /*Counts the slot till totalSSB is receached*/
304 typedef struct schPagingOcc
307 uint8_t pagingOccSlot;
310 typedef struct schPageCb
312 CmLListCp pageReqInfoRecord[MAX_SFN]; /*List of Page Records received which are stored per sfn*/
313 SchPagingOcc pagMonOcc[MAX_PO_PER_PF]; /*Paging Occasion Slot/FrameOffset are stored*/
314 SchPageInfo currPageInfo; /*Page Req which is being currently processed */
319 * Cell Control block per cell.
321 typedef struct schCellCb
323 uint16_t cellId; /*!< Cell ID */
324 Inst instIdx; /*!< Index of the scheduler instance */
325 Inst macInst; /*!< Index of the MAC instance */
326 uint8_t numSlots; /*!< Number of slots in current frame */
327 SlotTimingInfo slotInfo; /*!< SFN, Slot info being processed*/
328 SchDlSlotInfo **schDlSlotInfo; /*!< SCH resource allocations in DL */
329 SchUlSlotInfo **schUlSlotInfo; /*!< SCH resource allocations in UL */
330 SchCellCfg cellCfg; /*!< Cell ocnfiguration */
331 bool firstSsbTransmitted;
332 bool firstSib1Transmitted;
333 uint8_t ssbStartSymbArr[SCH_MAX_SSB_BEAM]; /*!<start symbol per SSB beam */
334 SchRaReq *raReq[MAX_NUM_UE]; /*!< Pending RA request */
335 SchRaCb raCb[MAX_NUM_UE]; /*!< RA Cb */
336 uint16_t numActvUe; /*!<Number of active UEs */
337 uint32_t actvUeBitMap; /*!<Bit map to find active UEs */
338 uint32_t boIndBitMap; /*!<Bit map to indicate UEs that have recevied BO */
339 SchUeCb ueCb[MAX_NUM_UE]; /*!<Pointer to UE contexts of this cell */
340 CmLListCp ueToBeScheduled; /*!<Linked list to store UEs pending to be scheduled, */
341 SchPageCb pageCb; /*!<Page Record at Schedular*/
343 uint8_t numSlotsInPeriodicity; /*!< number of slots in configured periodicity and SCS */
344 uint32_t slotFrmtBitMap; /*!< 2 bits must be read together to determine D/U/S slots. 00-D, 01-U, 10-S */
345 uint32_t symbFrmtBitMap; /*!< 2 bits must be read together to determine D/U/S symbols. 00-D, 01-U, 10-S */
350 typedef struct schSliceCfg
352 uint8_t numOfSliceConfigured;
353 SchRrmPolicyOfSlice **listOfConfirguration;
358 * Control block for sch
362 TskInit schInit; /*!< Task Init info */
363 SchGenCb genCfg; /*!< General Config info */
364 CmTqCp tmrTqCp; /*!< Timer Task Queue Cntrl Point */
365 CmTqType tmrTq[SCH_TQ_SIZE]; /*!< Timer Task Queue */
366 SchCellCb *cells[MAX_NUM_CELL]; /* Array to store cellCb ptr */
367 SchSliceCfg sliceCfg;
370 /* Declaration for scheduler control blocks */
371 SchCb schCb[SCH_MAX_INST];
373 /* function declarations */
374 short int schActvTmr(Ent ent,Inst inst);
376 /* Configuration related function declarations */
377 void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo);
378 void schInitDlSlot(SchDlSlotInfo *schDlSlotInfo);
379 void BuildK0K1Table(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres, \
380 SchPdschCfgCmn pdschCmnCfg,SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl);
381 void BuildK2InfoTable(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], \
382 uint16_t puschSymTblSize, SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl);
383 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt *cfm);
384 SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti);
385 uint8_t addUeToBeScheduled(SchCellCb *cell, uint8_t ueId);
387 /* Incoming message handler function declarations */
388 uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst inst);
389 uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst);
391 /* DL scheduling related function declarations */
392 PduTxOccsaion schCheckSsbOcc(SchCellCb *cell, SlotTimingInfo slotTime);
393 PduTxOccsaion schCheckSib1Occ(SchCellCb *cell, SlotTimingInfo slotTime);
394 uint8_t schBroadcastSsbAlloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
395 uint8_t schBroadcastSib1Alloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
396 bool schProcessRaReq(Inst schInst, SchCellCb *cellCb, SlotTimingInfo currTime, uint8_t ueId);
397 bool schProcessMsg4Req(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId);
398 uint8_t schFillRar(SchCellCb *cell, SlotTimingInfo rarTime, uint16_t ueId, RarAlloc *rarAlloc, uint8_t k0Index);
399 uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t crnti,
400 uint32_t tbSize, DlMsgAlloc *dlMsgAlloc, uint16_t startPRB, uint8_t pdschStartSymbol, uint8_t pdschNumSymbols);
401 uint8_t schDlRsrcAllocMsg4(SchCellCb *cell, SlotTimingInfo msg4Time, uint8_t ueId, DlMsgAlloc *msg4Alloc,\
402 uint8_t pdschStartSymbol, uint8_t pdschNumSymbols);
403 uint8_t allocatePrbDl(SchCellCb *cell, SlotTimingInfo slotTime, uint8_t startSymbol, uint8_t symbolLength, \
404 uint16_t *startPrb, uint16_t numPrb);
405 void fillDlMsgInfo(DlMsgInfo *dlMsgInfo, uint8_t crnti);
406 bool findValidK0K1Value(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId, bool dedMsg, uint8_t *pdschStartSymbol,\
407 uint8_t *pdschSymblLen, SlotTimingInfo *pdcchTime, SlotTimingInfo *pdschTime, SlotTimingInfo *pucchTime);
409 /* UL scheduling related function declarations */
410 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst);
411 bool schCheckPrachOcc(SchCellCb *cell, SlotTimingInfo prachOccasionTimingInfo);
412 uint8_t schCalcPrachNumRb(SchCellCb *cell);
413 void schPrachResAlloc(SchCellCb *cell, UlSchedInfo *ulSchedInfo, SlotTimingInfo prachOccasionTimingInfo);
414 uint16_t schAllocPucchResource(SchCellCb *cell, SlotTimingInfo pucchTime, uint16_t crnti);
415 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo);
416 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbsSize, \
417 uint8_t startSymb, uint8_t symbLen, uint16_t startPrb);
418 uint8_t allocatePrbUl(SchCellCb *cell, SlotTimingInfo slotTime, uint8_t startSymbol, uint8_t symbolLength, \
419 uint16_t *startPrb, uint16_t numPrb);
420 bool schProcessSrOrBsrReq(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId);
421 bool schCalculateUlTbs(SchUeCb *ueCb, SlotTimingInfo puschTime, uint8_t symbLen,\
422 uint16_t *startPrb, uint32_t *totTBS);
424 /*Generic Functions*/
425 void updateGrantSizeForBoRpt(CmLListCp *lcLL, DlMsgAlloc *dlMsgAlloc, BsrInfo *bsrInfo, uint32_t *accumalatedBOSize);
426 uint16_t searchLargestFreeBlock(SchCellCb *cell, SlotTimingInfo slotTime,uint16_t *startPrb, Direction dir);
427 LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLL action);
428 void prbAllocUsingRRMPolicy(CmLListCp *lcLL, bool dedicatedPRB, uint16_t mcsIdx,uint8_t numSymbols,\
429 uint16_t *sharedPRB, uint16_t *reservedPRB, bool *isTxPayloadLenAdded, bool *srRcvd);
430 void updateBsrAndLcList(CmLListCp *lcLL, BsrInfo *bsrInfo, uint8_t status);
433 void schProcPagingCfg(SchCellCb *cell);
434 void schCfgPdcchMonOccOfPO(SchCellCb *cell);
435 void schIncrSlot(SlotTimingInfo *timingInfo, uint8_t incr, uint16_t numSlotsPerRF);
437 /**********************************************************************
439 **********************************************************************/