[Epic-ID: ODUHIGH-405][Task-ID: ODUHIGH-425] Changes in Ue Context Modification
[o-du/l2.git] / src / 5gnrsch / sch.h
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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  *******************************************************************************/
18
19 /* macros */
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 */
34 #define SCHED_DELTA 1
35 #define BO_DELTA 1
36 #define RAR_DELAY   2
37 #define MSG4_DELAY  1
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
45 #define P_RNTI  0xFFFE
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
52
53 #define CRC_FAILED 0
54 #define CRC_PASSED 1
55
56 #define MAC_HDR_SIZE  3   /* 3 bytes of MAC Header */
57 #define UL_GRANT_SIZE 224
58
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)
61
62 typedef struct schCellCb SchCellCb;
63 typedef struct schUeCb SchUeCb;
64
65 typedef enum
66 {
67    SCH_NUMEROLOGY_0,
68    SCH_NUMEROLOGY_1,
69    SCH_NUMEROLOGY_2,
70    SCH_NUMEROLOGY_3,
71    SCH_NUMEROLOGY_4
72 }SchNumerology;
73
74 typedef enum
75 {
76    SCH_UE_STATE_INACTIVE,
77    SCH_UE_STATE_ACTIVE,
78    SCH_UE_HANDIN_IN_PROGRESS
79 }SchUeState;
80
81 typedef enum
82 {
83    SCH_LC_STATE_INACTIVE,
84    SCH_LC_STATE_ACTIVE
85 }SchLcState;
86
87 typedef enum
88 {
89    WINDOW_YET_TO_START,
90    WITHIN_WINDOW,
91    WINDOW_EXPIRED
92 }RaRspWindowStatus;
93
94 typedef enum 
95 {
96    SEARCH,
97    CREATE,
98    DELETE
99 }ActionTypeLcLL;
100
101 /**
102  * @brief
103  * Structure holding LTE MAC's General Configuration information.
104  */
105 typedef struct schGenCb
106 {
107    uint8_t         tmrRes;           /*!< Timer resolution */
108    uint8_t         startCellId;      /*!< Starting Cell Id */
109 #ifdef LTE_ADV
110    bool            forceCntrlSrbBoOnPCel; /*!< value 1 means force scheduling
111                                             of RLC control BO and SRB BO on
112                                             PCell. val 0 means don't force*/
113    bool            isSCellActDeactAlgoEnable; /*!< TRUE will enable activation/deactivation algo at Schd */
114 #endif
115 }SchGenCb;
116
117 typedef struct freePrbBlock
118 {
119    uint16_t numFreePrb;
120    uint16_t startPrb;
121    uint16_t endPrb;
122 }FreePrbBlock;
123
124 /**
125  * @brief
126  * PRB allocations for a symbol within a slot
127  */
128 typedef struct schPrbAlloc
129 {
130    CmLListCp freePrbBlockList;           /*!< List of continuous blocks for available PRB */
131    uint64_t  prbBitMap[ MAX_SYMB_PER_SLOT][PRB_BITMAP_MAX_IDX];  /*!< BitMap to store the allocated PRBs */
132 }SchPrbAlloc;
133
134 /**
135  * @brief
136  * scheduler allocationsfor DL per cell.
137  */
138 typedef struct schDlSlotInfo
139 {
140    SchPrbAlloc  prbAlloc;                 /*!< PRB allocated/available in this slot */
141    bool         ssbPres;                  /*!< Flag to determine if SSB is present in this slot */
142    uint8_t      ssbIdxSupported;          /*!< Max SSB index */
143    SsbInfo      ssbInfo[MAX_SSB_IDX];     /*!< SSB info */
144    bool         sib1Pres;                 /*!< Flag to determine if SIB1 is present in this slot */
145    uint8_t      pdcchUe;                  /*!< UE for which PDCCH is scheduled in this slot */
146    uint8_t      pdschUe;                  /*!< UE for which PDSCH is scheduled in this slot */
147    RarAlloc     *rarAlloc[MAX_NUM_UE];    /*!< RAR allocation per UE*/
148    DciInfo      *ulGrant;
149    DlMsgAlloc   *dlMsgAlloc[MAX_NUM_UE];  /*!< Dl msg allocation per UE*/
150 }SchDlSlotInfo;
151
152 typedef struct schRaCb
153 {
154    bool      msg4recvd;
155    uint16_t  tcrnti;
156    uint16_t  dlMsgPduLen;
157 }SchRaCb;
158
159 /**
160  * @brief
161  * scheduler allocationsfor UL per cell.
162  */
163 typedef struct schUlSlotInfo
164 {
165    SchPrbAlloc  prbAlloc;         /*!< PRB allocated/available per symbol */
166    uint8_t      puschCurrentPrb;  /*!< Current PRB for PUSCH allocation */
167    bool         puschPres;        /*!< PUSCH presence field */
168    SchPuschInfo *schPuschInfo;    /*!< PUSCH info */
169    bool         pucchPres;        /*!< PUCCH presence field */
170    SchPucchInfo schPucchInfo;     /*!< PUCCH info */
171    uint8_t      pucchUe;          /*!< Store UE id for which PUCCH is scheduled */
172    uint8_t      puschUe;          /*!< Store UE id for which PUSCH is scheduled */
173 }SchUlSlotInfo;
174
175 /**
176 @brief
177 * BSR info per slot per UE.
178 */
179 typedef struct bsrInfo
180 {
181    uint8_t    priority;  /* CG priority */
182    uint32_t   dataVol;   /* Data volume requested in bytes */
183 }BsrInfo;
184
185 typedef struct schLcCtxt
186 {
187    uint8_t lcId;     // logical Channel ID
188    uint8_t lcp;      // logical Channel Prioritization
189    SchLcState lcState;
190    uint32_t bo;
191    uint16_t   pduSessionId; /*Pdu Session Id*/
192    Snssai  *snssai;      /*S-NSSAI assoc with LCID*/
193    bool isDedicated;     /*Flag containing Dedicated S-NSSAI or not*/
194 }SchDlLcCtxt;
195
196 typedef struct schDlCb
197 {
198    SchDlLcCtxt   dlLcCtxt[MAX_NUM_LC];
199 }SchDlCb;
200
201 typedef struct schUlLcCtxt
202 {
203    SchLcState  lcState;
204    uint8_t lcId;       
205    uint8_t priority;
206    uint8_t lcGroup;
207    uint8_t schReqId;
208    uint8_t pbr;        // prioritisedBitRate
209    uint8_t bsd;        // bucketSizeDuration
210    uint16_t   pduSessionId; /*Pdu Session Id*/
211    Snssai  *snssai;      /*S-NSSAI assoc with LCID*/
212    bool isDedicated;     /*Flag containing Dedicated S-NSSAI or not*/
213 }SchUlLcCtxt;
214
215 typedef struct schUlCb
216 {
217    SchUlLcCtxt ulLcCtxt[MAX_NUM_LC];
218 }SchUlCb;
219
220 typedef struct schUeCfgCb
221 {
222    uint16_t        cellId;
223    uint8_t         duUeF1apId;
224    uint16_t        crnti;
225    bool macCellGrpCfgPres;
226    SchMacCellGrpCfg   macCellGrpCfg;
227    bool phyCellGrpCfgPres;
228    SchPhyCellGrpCfg   phyCellGrpCfg;
229    bool spCellCfgPres;
230    SchSpCellCfg       spCellCfg;
231    SchAmbrCfg         *ambrCfg;
232    SchModulationInfo  dlModInfo;
233    SchModulationInfo  ulModInfo;
234    SchDataTransmission dataTransmissionAction;
235 }SchUeCfgCb;
236
237 /*Following structures to keep record and estimations of PRB allocated for each
238  * LC taking into consideration the RRM policies*/
239 typedef struct lcInfo
240 {
241    uint8_t  lcId;     /*LCID for which BO are getting recorded*/
242    uint32_t reqBO;    /*Size of the BO requested/to be allocated for this LC*/
243    uint32_t allocBO;  /*TBS/BO Size which is actually allocated*/
244    uint8_t  allocPRB; /*PRB count which is allocated based on RRM policy/FreePRB*/
245 }LcInfo;
246
247 typedef struct dedicatedLCInfo
248 {
249    CmLListCp dedLcList;             /*Linklist of LC assoc with RRMPolicyMemberList*/
250    uint16_t      rsvdDedicatedPRB; /*Number of PRB reserved for this Dedicated S-NSSAI*/
251 }DedicatedLCInfo;
252
253 typedef struct schLcPrbEstimate
254 {
255    /* TODO: For Multiple RRMPolicies, Make DedicatedLcInfo as array/Double Pointer 
256     * and have separate DedLCInfo for each RRMPolcyMemberList*/
257    /* Dedicated LC List will be allocated, if any available*/
258    DedicatedLCInfo *dedLcInfo;  /*Contain LCInfo per RRMPolicy*/
259
260    CmLListCp defLcList; /*Linklist of LC assoc with Default S-NSSAI(s)*/
261
262    /* SharedPRB number can be used by any LC.
263     * Need to calculate in every Slot based on PRB availability*/
264    uint16_t sharedNumPrb;  
265 }SchLcPrbEstimate;
266
267 /**
268  * @brief
269  * UE control block
270  */
271 typedef struct schUeCb
272 {
273    uint16_t   ueId;
274    uint16_t   crnti;
275    SchUeCfgCb ueCfg;
276    SchUeState state;
277    SchCellCb  *cellCb;
278    bool       srRcvd;
279    bool       bsrRcvd;
280    BsrInfo    bsrInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS];
281    SchUlCb    ulInfo;
282    SchDlCb    dlInfo;
283    SchLcPrbEstimate dlLcPrbEst; /*DL PRB Alloc Estimate among different LC*/
284    SchLcPrbEstimate ulLcPrbEst; /*UL PRB Alloc Estimate among different LC*/
285 }SchUeCb;
286
287 /**
288  * @brief
289  * RA Request Info
290  */
291 typedef struct schRaReq
292 {
293    uint32_t        raRnti;
294    RachIndInfo     *rachInd;
295    SlotTimingInfo  winStartTime;
296    SlotTimingInfo  winEndTime;
297 }SchRaReq;
298
299 typedef struct schPageInfo
300 {
301   uint8_t        pf;       /*Value of Paging Frame received from DUAPP*/
302   uint8_t        i_s;      /*Value of Paging Occ Index received from DUAPP*/
303   SlotTimingInfo TxTime;   /*Start Paging window*/
304   uint8_t        crntSsbIdx; /*Counts the slot till totalSSB is receached*/
305   uint8_t        mcs;
306   uint8_t        nPRB;
307   uint16_t       msgLen;
308   uint8_t        *pagePdu;   
309 }SchPageInfo;
310
311 typedef struct schPagingOcc
312 {
313   uint8_t frameOffset;
314   uint8_t pagingOccSlot;
315 }SchPagingOcc;
316
317 typedef struct schPageCb
318 {
319    CmLListCp    pageReqInfoRecord[MAX_SFN];   /*List of Page Records received which are stored per sfn*/
320    SchPagingOcc pagMonOcc[MAX_PO_PER_PF]; /*Paging Occasion Slot/FrameOffset are stored*/ 
321    SchPageInfo  currPageInfo;   /*Page Req which is being currently processed */
322 }SchPageCb;
323
324 /**
325  * @brief
326  * Cell Control block per cell.
327  */
328 typedef struct schCellCb
329 {
330    uint16_t      cellId;                            /*!< Cell ID */
331    Inst          instIdx;                           /*!< Index of the scheduler instance */
332    Inst          macInst;                           /*!< Index of the MAC instance */
333    uint8_t       numSlots;                          /*!< Number of slots in current frame */
334    SlotTimingInfo   slotInfo;                          /*!< SFN, Slot info being processed*/
335    SchDlSlotInfo **schDlSlotInfo;                   /*!< SCH resource allocations in DL */
336    SchUlSlotInfo **schUlSlotInfo;                   /*!< SCH resource allocations in UL */
337    SchCellCfg    cellCfg;                           /*!< Cell ocnfiguration */
338    bool          firstSsbTransmitted;
339    bool          firstSib1Transmitted;
340    uint8_t       ssbStartSymbArr[SCH_MAX_SSB_BEAM]; /*!<start symbol per SSB beam */
341    SchRaReq      *raReq[MAX_NUM_UE];                /*!< Pending RA request */
342    SchRaCb       raCb[MAX_NUM_UE];                  /*!< RA Cb */
343    SchUeCb       hoUeCb[MAX_NUM_UE];                /*!<List of UE being handed-in to this DU */
344    uint16_t      numActvUe;                         /*!<Number of active UEs */
345    uint32_t      actvUeBitMap;                      /*!<Bit map to find active UEs */
346    uint32_t      boIndBitMap;                       /*!<Bit map to indicate UEs that have recevied BO */
347    SchUeCb       ueCb[MAX_NUM_UE];                  /*!<Pointer to UE contexts of this cell */
348    CmLListCp     ueToBeScheduled;                   /*!<Linked list to store UEs pending to be scheduled, */
349    SchPageCb     pageCb;        /*!<Page Record at Schedular*/
350 #ifdef NR_TDD
351    uint8_t       numSlotsInPeriodicity;             /*!< number of slots in configured periodicity and SCS */
352    uint32_t      slotFrmtBitMap;                    /*!< 2 bits must be read together to determine D/U/S slots. 00-D, 01-U, 10-S */
353    uint32_t      symbFrmtBitMap;                    /*!< 2 bits must be read together to determine D/U/S symbols. 00-D, 01-U, 10-S */
354 #endif
355 }SchCellCb;
356
357
358 typedef struct schSliceCfg
359 {
360    uint8_t        numOfSliceConfigured;
361    SchRrmPolicyOfSlice **listOfConfirguration;
362 }SchSliceCfg;
363
364 /**
365  * @brief
366  * Control block for sch
367  */
368 typedef struct schCb
369 {
370    TskInit       schInit;               /*!< Task Init info */
371    SchGenCb      genCfg;                /*!< General Config info */
372    CmTqCp        tmrTqCp;               /*!< Timer Task Queue Cntrl Point */
373    CmTqType      tmrTq[SCH_TQ_SIZE];    /*!< Timer Task Queue */
374    SchCellCb     *cells[MAX_NUM_CELL];  /* Array to store cellCb ptr */ 
375    SchSliceCfg   sliceCfg;
376 }SchCb;
377
378 /* Declaration for scheduler control blocks */
379 SchCb schCb[SCH_MAX_INST];
380
381 /* function declarations */
382 short int schActvTmr(Ent ent,Inst inst);
383
384 /* Configuration related function declarations */
385 void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo);
386 void schInitDlSlot(SchDlSlotInfo *schDlSlotInfo);
387 void BuildK0K1Table(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres, \
388    SchPdschCfgCmn pdschCmnCfg,SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl);
389 void BuildK2InfoTable(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], \
390    uint16_t puschSymTblSize, SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl);
391 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt *cfm);
392 SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti);
393 uint8_t addUeToBeScheduled(SchCellCb *cell, uint8_t ueId);
394
395 /* Incoming message handler function declarations */
396 uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst inst);
397 uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst);
398
399 /* DL scheduling related function declarations */
400 PduTxOccsaion schCheckSsbOcc(SchCellCb *cell, SlotTimingInfo slotTime);
401 PduTxOccsaion schCheckSib1Occ(SchCellCb *cell, SlotTimingInfo slotTime);
402 uint8_t schBroadcastSsbAlloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
403 uint8_t schBroadcastSib1Alloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
404 bool schProcessRaReq(Inst schInst, SchCellCb *cellCb, SlotTimingInfo currTime, uint8_t ueId);
405 bool schProcessMsg4Req(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId);
406 uint8_t schFillRar(SchCellCb *cell, SlotTimingInfo rarTime, uint16_t ueId, RarAlloc *rarAlloc, uint8_t k0Index);
407 uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t crnti,
408 uint32_t tbSize, DlMsgAlloc *dlMsgAlloc, uint16_t startPRB, uint8_t pdschStartSymbol, uint8_t pdschNumSymbols);
409 uint8_t schDlRsrcAllocMsg4(SchCellCb *cell, SlotTimingInfo msg4Time, uint8_t ueId, DlMsgAlloc *msg4Alloc,\
410 uint8_t pdschStartSymbol, uint8_t pdschNumSymbols);
411 uint8_t allocatePrbDl(SchCellCb *cell, SlotTimingInfo slotTime, uint8_t startSymbol, uint8_t symbolLength, \
412    uint16_t *startPrb, uint16_t numPrb);
413 void fillDlMsgInfo(DlMsgInfo *dlMsgInfo, uint8_t crnti);
414 bool findValidK0K1Value(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId, bool dedMsg, uint8_t *pdschStartSymbol,\
415 uint8_t *pdschSymblLen, SlotTimingInfo *pdcchTime,  SlotTimingInfo *pdschTime, SlotTimingInfo *pucchTime);
416
417 /* UL scheduling related function declarations */
418 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst);
419 bool schCheckPrachOcc(SchCellCb *cell, SlotTimingInfo prachOccasionTimingInfo);
420 uint8_t schCalcPrachNumRb(SchCellCb *cell);
421 void schPrachResAlloc(SchCellCb *cell, UlSchedInfo *ulSchedInfo, SlotTimingInfo prachOccasionTimingInfo);
422 uint16_t schAllocPucchResource(SchCellCb *cell, SlotTimingInfo pucchTime, uint16_t crnti);
423 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo);
424 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbsSize, \
425                            uint8_t startSymb, uint8_t symbLen, uint16_t startPrb);
426 uint8_t allocatePrbUl(SchCellCb *cell, SlotTimingInfo slotTime, uint8_t startSymbol, uint8_t symbolLength, \
427    uint16_t *startPrb, uint16_t numPrb);
428 bool schProcessSrOrBsrReq(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId);
429 bool schCalculateUlTbs(SchUeCb *ueCb, SlotTimingInfo puschTime, uint8_t symbLen,\
430                              uint16_t *startPrb, uint32_t *totTBS);
431
432 /*Generic Functions*/
433 void updateGrantSizeForBoRpt(CmLListCp *lcLL, DlMsgAlloc *dlMsgAlloc, BsrInfo *bsrInfo, uint32_t *accumalatedBOSize);
434 uint16_t searchLargestFreeBlock(SchCellCb *cell, SlotTimingInfo slotTime,uint16_t *startPrb, Direction dir);
435 LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLcLL action);
436 void prbAllocUsingRRMPolicy(CmLListCp *lcLL, bool dedicatedPRB, uint16_t mcsIdx,uint8_t numSymbols,\
437                       uint16_t *sharedPRB, uint16_t *reservedPRB, bool *isTxPayloadLenAdded, bool *srRcvd);
438 void updateBsrAndLcList(CmLListCp *lcLL, BsrInfo *bsrInfo, uint8_t status);
439
440 /*Paging Functions*/
441 void schProcPagingCfg(SchCellCb *cell);
442 void schCfgPdcchMonOccOfPO(SchCellCb *cell);
443 void schIncrSlot(SlotTimingInfo *timingInfo, uint8_t incr, uint16_t numSlotsPerRF);
444
445 /**********************************************************************
446   End of file
447  **********************************************************************/