[Epic-ID: ODUHIGH-462][Task-ID: ODUHIGH-472] Implementation of drx timer
[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 #define SCH_MAX_NUM_UL_HQ_PROC 16
63 #define SCH_MAX_NUM_DL_HQ_PROC 16
64 #define SCH_MAX_NUM_MSG3_TX 2
65 #define SCH_MAX_NUM_DL_HQ_TX 3
66 #define SCH_MAX_NUM_UL_HQ_TX 3
67 #define SCH_MAX_NUM_MSG4_TX 2
68 #define HQ_ACK 0
69 #define HQ_NACK 1
70 #define HQ_DTX 2
71
72 #ifdef NR_DRX
73 /* As per 38.331 the largest offset which can be used in of size 10240.
74  * But using this much size of array can cause memory related issue so thats why
75  * taking this size which are a multiple of the larger size */
76 #define MAX_DRX_SIZE 512
77 #endif
78
79 typedef struct schDlHqProcCb SchDlHqProcCb;
80 typedef struct schUlHqEnt SchUlHqEnt;
81 typedef struct schRaReq SchRaReq;
82 typedef struct schDlHqEnt SchDlHqEnt;
83 typedef struct schCellCb SchCellCb;
84 typedef struct schUeCb SchUeCb;
85
86 typedef enum
87 {
88    SCH_NUMEROLOGY_0,
89    SCH_NUMEROLOGY_1,
90    SCH_NUMEROLOGY_2,
91    SCH_NUMEROLOGY_3,
92    SCH_NUMEROLOGY_4
93 }SchNumerology;
94
95 typedef enum
96 {
97    SCH_UE_STATE_INACTIVE,
98    SCH_UE_STATE_ACTIVE,
99    SCH_UE_HANDIN_IN_PROGRESS
100 }SchUeState;
101
102
103 typedef enum
104 {
105    SCH_RA_STATE_MSG2_HANDLE,
106    SCH_RA_STATE_MSG3_PENDING,
107    SCH_RA_STATE_MSG4_PENDING,
108    SCH_RA_STATE_MSG4_DONE
109 }SchRaState;
110
111 typedef enum
112 {
113    SCH_LC_STATE_INACTIVE,
114    SCH_LC_STATE_ACTIVE
115 }SchLcState;
116
117 typedef enum
118 {
119    WINDOW_YET_TO_START,
120    WITHIN_WINDOW,
121    WINDOW_EXPIRED
122 }RaRspWindowStatus;
123
124 typedef enum
125 {
126    HQ_TB_ACKED=0,
127    HQ_TB_NACKED,
128    HQ_TB_WAITING
129 }SchHqTbState;
130
131 /*Following structures to keep record and estimations of PRB allocated for each
132  * LC taking into consideration the RRM policies*/
133 typedef struct lcInfo
134 {
135    uint8_t  lcId;     /*LCID for which BO are getting recorded*/
136    uint32_t reqBO;    /*Size of the BO requested/to be allocated for this LC*/
137    uint32_t allocBO;  /*TBS/BO Size which is actually allocated*/
138    uint8_t  allocPRB; /*PRB count which is allocated based on RRM policy/FreePRB*/
139 }LcInfo;
140
141 typedef struct schLcPrbEstimate
142 {
143    /* TODO: For Multiple RRMPolicies, Make DedicatedLcInfo as array/Double Pointer 
144     * and have separate DedLCInfo for each RRMPolcyMemberList*/
145    /* Dedicated LC List will be allocated, if any available*/
146    CmLListCp dedLcList; /*Contain LCInfo per RRMPolicy*/
147    CmLListCp defLcList; /*Linklist of LC assoc with Default S-NSSAI(s)*/
148    /* SharedPRB number can be used by any LC.
149     * Need to calculate in every Slot based on PRB availability*/
150    uint16_t sharedNumPrb;
151 }SchLcPrbEstimate;
152 typedef struct schUlHqTbCb
153 {
154    uint32_t               tbSzReq;
155    uint32_t               tbSzAllc;
156    uint8_t                ndi;
157    uint8_t                rv;
158    uint8_t                rvIdx;
159    uint8_t                qamOrder;
160    SchMcsTable            mcsTable;
161    uint8_t                iMcs;
162    uint8_t                iMcsInDci;
163    uint8_t                numLyrs;
164    uint8_t                txCntr;
165    SchHqTbState           state;
166    uint8_t                cntrRetxAllocFail;
167    uint8_t                statsBitmap;
168 }SchUlHqTbCb;
169
170 typedef struct schDlHqTbCb
171 {
172    uint8_t                tbIdx;
173    Bool                   isEnabled;
174    uint32_t               tbSzReq;
175    uint8_t                txCntr;
176    uint8_t                ndi;
177    uint8_t                rv;
178    uint8_t                rvIdx;
179    uint8_t                iMcs;
180    uint8_t                iMcsInDci;
181    uint8_t                numLyrs;
182    SchHqTbState           state;
183    uint8_t                isAckNackDtx;
184    uint8_t                cntrRetxAllocFail;
185    //InfUeTbInfo          tbCompInfo;
186    uint8_t                statsBitmap;
187 }SchDlHqTbCb;
188
189 #ifdef NR_DRX
190 typedef struct schDrxHarqCb
191 {
192    uint32_t     retxStrtIndex;     
193    uint32_t     rttIndex;                  
194    uint32_t     retxIndex;        
195    int16_t      retxExpDistance; 
196    uint8_t      retxTmrReduction;     
197 }SchDrxHarqCb;
198 #endif
199
200 typedef struct schUlHqProcCb
201 {
202    uint8_t           procId;       /*!< HARQ Process ID */
203    SchUlHqEnt        *hqEnt;
204    uint8_t           maxHqTxPerHqP;
205    SchUlHqTbCb       tbInfo;
206    CmLList           ulHqEntLnk;
207    CmLList           ulSlotLnk;
208    uint8_t           strtSymbl;
209    uint8_t           numSymbl;
210    SchLcPrbEstimate  ulLcPrbEst; /*UL PRB Alloc Estimate among different LC*/
211    CmLList           ulHqProcLink;
212    uint8_t           puschResType; /* Resource allocation type */
213    uint16_t          puschStartPrb;
214    uint16_t          puschNumPrb;
215    uint8_t           dmrsMappingType;
216    uint8_t           nrOfDmrsSymbols;
217    uint8_t           dmrsAddPos;
218 #ifdef NR_DRX
219    SchDrxHarqCb      drxHarqCb;
220 #endif
221 }SchUlHqProcCb;
222
223 struct schDlHqProcCb
224 {
225    uint8_t           procId;       /*!< HARQ Process ID */
226    SchDlHqEnt        *hqEnt;
227    uint8_t           maxHqTxPerHqP;
228    CmLList           dlHqEntLnk;
229    CmLList           ulSlotLnk;
230    SchDlHqTbCb       tbInfo[2];
231    uint8_t           k1;
232    SchLcPrbEstimate  dlLcPrbEst; /*DL PRB Alloc Estimate among different LC*/
233    CmLList           dlHqProcLink;
234 #ifdef NR_DRX
235    SchDrxHarqCb      drxHarqCb;
236 #endif
237 };
238 struct schUlHqEnt
239 {
240    SchCellCb      *cell;     /*!< Contains the pointer to cell*/
241    SchUeCb        *ue;       /*!< Contains the pointer to ue*/
242    CmLListCp      free;      /*!< List of free HARQ processes */
243    CmLListCp      inUse;     /*!< List of in-use HARQ processes */
244    uint8_t        maxHqTx;   /*!< Maximum number of harq re-transmissions */
245    uint8_t        numHqPrcs; /*!< Number of HARQ Processes */
246    SchUlHqProcCb  procs[SCH_MAX_NUM_UL_HQ_PROC]; /*!< Uplink harq process info */
247 };
248 struct schDlHqEnt
249 {
250    SchCellCb      *cell;     /*!< Contains the pointer to cell */
251    SchUeCb        *ue;       /*!< Contains the pointer to UE */
252    CmLListCp      free;      /*!< List of free HARQ processes */
253    CmLListCp      inUse;     /*!< List of in-use HARQ processes */
254    uint8_t        maxHqTx;   /*!< Maximum number of harq transmissions */
255    uint8_t        numHqPrcs; /*!< Number of HARQ Processes */
256    SchDlHqProcCb  procs[SCH_MAX_NUM_DL_HQ_PROC];/*!< Downlink harq processes */
257 };
258
259 /**
260  * @brief
261  * Structure holding LTE MAC's General Configuration information.
262  */
263 typedef struct schGenCb
264 {
265    uint8_t         tmrRes;           /*!< Timer resolution */
266    uint8_t         startCellId;      /*!< Starting Cell Id */
267 #ifdef LTE_ADV
268    bool            forceCntrlSrbBoOnPCel; /*!< value 1 means force scheduling
269                                             of RLC control BO and SRB BO on
270                                             PCell. val 0 means don't force*/
271    bool            isSCellActDeactAlgoEnable; /*!< TRUE will enable activation/deactivation algo at Schd */
272 #endif
273 }SchGenCb;
274
275 typedef struct freePrbBlock
276 {
277    uint16_t numFreePrb;
278    uint16_t startPrb;
279    uint16_t endPrb;
280 }FreePrbBlock;
281
282 /**
283  * @brief
284  * PRB allocations for a symbol within a slot
285  */
286 typedef struct schPrbAlloc
287 {
288    CmLListCp freePrbBlockList;           /*!< List of continuous blocks for available PRB */
289    uint64_t  prbBitMap[ MAX_SYMB_PER_SLOT][PRB_BITMAP_MAX_IDX];  /*!< BitMap to store the allocated PRBs */
290 }SchPrbAlloc;
291
292 /**
293  * @brief
294  * scheduler allocationsfor DL per cell.
295  */
296 typedef struct schDlSlotInfo
297 {
298    SchPrbAlloc  prbAlloc;                 /*!< PRB allocated/available in this slot */
299    bool         ssbPres;                  /*!< Flag to determine if SSB is present in this slot */
300    uint8_t      ssbIdxSupported;          /*!< Max SSB index */
301    SsbInfo      ssbInfo[MAX_SSB_IDX];     /*!< SSB info */
302    bool         sib1Pres;                 /*!< Flag to determine if SIB1 is present in this slot */
303    uint8_t      pdcchUe;                  /*!< UE for which PDCCH is scheduled in this slot */
304    uint8_t      pdschUe;                  /*!< UE for which PDSCH is scheduled in this slot */
305    RarAlloc     *rarAlloc[MAX_NUM_UE];    /*!< RAR allocation per UE*/
306    DciInfo      *ulGrant;
307    DlMsgAlloc   *dlMsgAlloc[MAX_NUM_UE];  /*!< Dl msg allocation per UE*/
308 }SchDlSlotInfo;
309
310 typedef struct schRaCb
311 {
312    uint8_t   ueId;
313    bool      msg4recvd;
314    uint16_t  tcrnti;
315    uint16_t  dlMsgPduLen;
316    SchUlHqProcCb msg3HqProc;
317    SchUlHqProcCb *retxMsg3HqProc;
318    SchRaState raState;
319    SchCellCb *cell;
320    SchRaReq  *raReq;
321 }SchRaCb;
322
323 /**
324  * @brief
325  * scheduler allocationsfor UL per cell.
326  */
327 typedef struct schUlSlotInfo
328 {
329    SchPrbAlloc  prbAlloc;         /*!< PRB allocated/available per symbol */
330    uint8_t      puschCurrentPrb;  /*!< Current PRB for PUSCH allocation */
331    bool         puschPres;        /*!< PUSCH presence field */
332    SchPuschInfo *schPuschInfo;    /*!< PUSCH info */
333    bool         pucchPres;        /*!< PUCCH presence field */
334    SchPucchInfo schPucchInfo;     /*!< PUCCH info */
335    uint8_t      pucchUe;          /*!< Store UE id for which PUCCH is scheduled */
336    uint8_t      puschUe;          /*!< Store UE id for which PUSCH is scheduled */
337 }SchUlSlotInfo;
338
339 /**
340 @brief
341 * BSR info per slot per UE.
342 */
343 typedef struct bsrInfo
344 {
345    uint8_t    priority;  /* CG priority */
346    uint32_t   dataVol;   /* Data volume requested in bytes */
347 }BsrInfo;
348
349 typedef struct schLcCtxt
350 {
351    uint8_t lcId;     // logical Channel ID
352    uint8_t lcp;      // logical Channel Prioritization
353    SchLcState lcState;
354    uint32_t bo;
355    uint16_t   pduSessionId; /*Pdu Session Id*/
356    Snssai  *snssai;      /*S-NSSAI assoc with LCID*/
357    bool isDedicated;     /*Flag containing Dedicated S-NSSAI or not*/
358    uint16_t rsvdDedicatedPRB;
359 }SchDlLcCtxt;
360
361 typedef struct schDlCb
362 {
363    SchDlLcCtxt   dlLcCtxt[MAX_NUM_LC];
364 }SchDlCb;
365
366 typedef struct schUlLcCtxt
367 {
368    SchLcState  lcState;
369    uint8_t lcId;
370    uint8_t priority;
371    uint8_t lcGroup;
372    uint8_t schReqId;
373    uint8_t pbr;        // prioritisedBitRate
374    uint8_t bsd;        // bucketSizeDuration
375    uint16_t   pduSessionId; /*Pdu Session Id*/
376    Snssai  *snssai;      /*S-NSSAI assoc with LCID*/
377    bool isDedicated;     /*Flag containing Dedicated S-NSSAI or not*/
378    uint16_t rsvdDedicatedPRB;
379 }SchUlLcCtxt;
380
381 typedef struct schUlCb
382 {
383    SchUlLcCtxt ulLcCtxt[MAX_NUM_LC];
384 }SchUlCb;
385
386 typedef struct schUeCfgCb
387 {
388    uint16_t        cellId;
389    uint8_t         ueId;
390    uint16_t        crnti;
391    bool macCellGrpCfgPres;
392    SchMacCellGrpCfg   macCellGrpCfg;
393    bool phyCellGrpCfgPres;
394    SchPhyCellGrpCfg   phyCellGrpCfg;
395    bool spCellCfgPres;
396    SchSpCellCfg       spCellCfg;
397    SchAmbrCfg         *ambrCfg;
398    SchModulationInfo  dlModInfo;
399    SchModulationInfo  ulModInfo;
400    SchDataTransmission dataTransmissionAction;
401 }SchUeCfgCb;
402
403 typedef struct schHqDlMap
404 {
405    CmLListCp hqList;
406 }SchHqDlMap;
407
408 typedef struct schHqUlMap
409 {
410    CmLListCp hqList;
411 }SchHqUlMap;
412
413 #ifdef NR_DRX
414 typedef struct  schDrxUeCb
415 {
416    bool      drxDlUeActiveStatus;    /* This variable is used to store the status about downlink active status */
417    bool      drxUlUeActiveStatus;    /* This variable is used to store the status about uplink active status */
418    uint32_t  onDurationLen;          /* on duration value recived from ue cfg/recfg */
419    uint32_t  inActvTimerLen;         /* inActvTimer value recived from ue cfg/recfg */
420    uint8_t   harqRttDlTimerLen;      /* harqRttDlTimer value recived from ue cfg/recfg */
421    uint8_t   harqRttUlTimerLen;      /* harqRttUlTimer value recived from ue cfg/recfg */
422    uint32_t  retransDlTimerLen;      /* retransDlTimer value recived from ue cfg/recfg */
423    uint32_t  retransUlTimerLen;      /* retransUlTimer  value recived from ue cfg/recfg */
424    uint32_t  longCycleLen;           /* long Cycle value recived from ue cfg/recfg */
425    bool      longCycleToBeUsed;      /* long cycle should be used once the short cycle gets expires */
426    uint32_t  drxStartOffset;         /* drxStartOffset value recived from ue cfg/recfg */
427    bool      shortCyclePresent;      /* shortCyclePresent value recived from ue cfg/recfg */
428    uint32_t  shortCycleLen;          /* short Cycle value recived from ue cfg/recfg */
429    uint32_t  shortCycleTmrLen;       /* shortCycleTmr value recived from ue cfg/recfg */
430    uint32_t  drxSlotOffset;          /* drxSlotOffset value recived from ue cfg/recfg */
431    uint32_t  onDurationStartIndex;   /* Index at which UE is stored in onDuration starts list */
432    uint32_t  onDurationExpiryIndex;  /* Index at which UE is stored in onDuration expires in the list */ 
433    uint32_t  inActvExpiryIndex;      /* Index at which UE is stored in inActvTimer expires in the list */
434    uint32_t  shortCycleExpiryIndex;  /* Index at which UE is stored in shortCycle expires in the list */
435    int32_t   shortCycleDistance;     /* Distance after how many slot short cycle tmr gets expire */ 
436    int32_t   onDurationStartDistance;/* Distance after how many slot on Duration Start tmr gets expire */
437    int32_t   onDurationExpiryDistance;/* Distance after how many slot on Duration tmr gets expire */
438    int32_t   inActiveTmrExpiryDistance;/* Distance after how many slot inActive tmr gets expire */
439    CmLList   *onDurationStartNodeInfo;
440    CmLList   *onDurationExpiryNodeInfo;
441    CmLList   *inActvTimerExpiryNodeInfo;
442    CmLList   *shortCycleTmrExpiryNodeInfo;
443 }SchDrxUeCb;
444 #endif
445 /**
446  * @brief
447  * UE control block
448  */
449 typedef struct schUeCb
450 {
451    uint16_t   ueId;
452    uint16_t   crnti;
453    SchUeCfgCb ueCfg;
454    SchUeState state;
455    SchCellCb  *cellCb;
456    SchCfraResource cfraResource;
457    bool       srRcvd;
458    bool       bsrRcvd;
459    BsrInfo    bsrInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS];
460    SchUlCb    ulInfo;
461    SchDlCb    dlInfo;
462    SchUlHqEnt ulHqEnt;
463    SchDlHqEnt dlHqEnt;
464    SchDlHqProcCb *msg4Proc;
465    SchDlHqProcCb *retxMsg4HqProc;
466    SchHqDlMap   **hqDlmap;
467    SchHqUlMap   **hqUlmap;
468    CmLListCp  ulRetxHqList;
469    CmLListCp  dlRetxHqList;
470 #ifdef NR_DRX
471    bool           ueDrxInfoPres;
472    SchDrxUeCb     drxUeCb;
473 #endif
474 }SchUeCb;
475
476 /**
477  * @brief
478  * RA Request Info
479  */
480 typedef struct schRaReq
481 {
482    uint32_t        raRnti;
483    RachIndInfo     *rachInd;
484    bool            isCFRA;
485    SchUeCb         *ueCb;          /* Filled only if isCFRA = true */
486    SlotTimingInfo  winStartTime;
487    SlotTimingInfo  winEndTime;
488 }SchRaReq;
489
490 typedef struct schPageInfo
491 {
492   uint16_t       pf;          /*Value of Paging Frame received from DUAPP*/
493   uint8_t        i_s;         /*Value of Paging Occ Index received from DUAPP*/
494   SlotTimingInfo pageTxTime;  /*Start Paging window*/
495   uint8_t        mcs;         /*MCS index*/
496   uint16_t       msgLen;      /*Pdu length */
497   uint8_t       *pagePdu;     /*RRC Page PDU bit string*/
498 }SchPageInfo;
499
500 typedef struct schPagingOcc
501 {
502   uint8_t frameOffset;
503   uint8_t pagingOccSlot;
504 }SchPagingOcc;
505
506 typedef struct schPageCb
507 {
508    CmLListCp    pageIndInfoRecord[MAX_SFN]; /*List of Page Records received which are stored per sfn*/
509    SchPagingOcc pagMonOcc[MAX_PO_PER_PF];   /*Paging Occasion Slot/FrameOffset are stored*/ 
510 }SchPageCb;
511
512 #ifdef NR_DRX
513 typedef struct schDrxCb
514 {
515    CmLListCp   onDurationStartList;   /*!< Tracks the start of onDuration Timer. */
516    CmLListCp   onDurationExpiryList;   /*!< Tracks the Expiry of onDuration Timer. */
517    CmLListCp   inActvTmrExpiryList;   /*!< Tracks the Expiry of drx-InactivityTimer. */
518    CmLListCp   shortCycleExpiryList;   /*!< Tracks the Expiry of DRX Short Cycle. */
519    CmLListCp   dlHarqRttExpiryList;   /*!< Tracks the Expiry of DL HARQ RTT timer. */
520    CmLListCp   dlRetransExpiryList;   /*!< Tracks the Expiry of DL Re-Transmission timer. */
521    CmLListCp   ulHarqRttExpiryList;   /*!< Tracks the Expiry of UL HARQ RTT timer. */
522    CmLListCp   ulRetransExpiryList;   /*!< Tracks the Expiry of UL Re-Transmission timer. */
523    CmLListCp   dlRetransTmrStartList; /*!< It has list of DL harq procs for */
524    CmLListCp   ulRetransTmrStartList; /*!< It has list of UL harq procs for */
525 }SchDrxCb;
526 #endif
527
528 /**
529  * @brief
530  * Cell Control block per cell.
531  */
532 typedef struct schCellCb
533 {
534    uint16_t      cellId;                            /*!< Cell ID */
535    Inst          instIdx;                           /*!< Index of the scheduler instance */
536    Inst          macInst;                           /*!< Index of the MAC instance */
537    uint8_t       numSlots;                          /*!< Number of slots in current frame */
538    SlotTimingInfo   slotInfo;                          /*!< SFN, Slot info being processed*/
539    SchDlSlotInfo **schDlSlotInfo;                   /*!< SCH resource allocations in DL */
540    SchUlSlotInfo **schUlSlotInfo;                   /*!< SCH resource allocations in UL */
541    SchCellCfg    cellCfg;                           /*!< Cell ocnfiguration */
542    bool          firstSsbTransmitted;
543    bool          firstSib1Transmitted;
544    uint8_t       ssbStartSymbArr[SCH_MAX_SSB_BEAM]; /*!< start symbol per SSB beam */
545    uint64_t      dedPreambleBitMap;                 /*!< Bit map to find used/free preambles index */
546    SchRaReq      *raReq[MAX_NUM_UE];                /*!< Pending RA request */
547    SchRaCb       raCb[MAX_NUM_UE];                  /*!< RA Cb */
548    uint16_t      numActvUe;                         /*!< Number of active UEs */
549    uint32_t      actvUeBitMap;                      /*!< Bit map to find active UEs */
550    uint32_t      boIndBitMap;                       /*!< Bit map to indicate UEs that have recevied BO */
551    SchUeCb       ueCb[MAX_NUM_UE];                  /*!< Pointer to UE contexts of this cell */
552    CmLListCp     ueToBeScheduled;                   /*!< Linked list to store UEs pending to be scheduled, */
553    SchPageCb     pageCb;                            /*!< Page Record at Schedular*/
554 #ifdef NR_TDD
555    uint8_t       numSlotsInPeriodicity;             /*!< number of slots in configured periodicity and SCS */
556    uint32_t      slotFrmtBitMap;                    /*!< 2 bits must be read together to determine D/U/S slots. 00-D, 01-U, 10-S */
557    uint32_t      symbFrmtBitMap;                    /*!< 2 bits must be read together to determine D/U/S symbols. 00-D, 01-U, 10-S */
558 #endif
559 #ifdef NR_DRX
560    SchDrxCb      drxCb[MAX_DRX_SIZE];                           /*!< Drx cb*/
561 #endif
562 }SchCellCb;
563
564
565 typedef struct schSliceCfg
566 {
567    uint8_t        numOfSliceConfigured;
568    SchRrmPolicyOfSlice **listOfConfirguration;
569 }SchSliceCfg;
570
571 /**
572  * @brief
573  * Control block for sch
574  */
575 typedef struct schCb
576 {
577    TskInit       schInit;               /*!< Task Init info */
578    SchGenCb      genCfg;                /*!< General Config info */
579    CmTqCp        tmrTqCp;               /*!< Timer Task Queue Cntrl Point */
580    CmTqType      tmrTq[SCH_TQ_SIZE];    /*!< Timer Task Queue */
581    SchCellCb     *cells[MAX_NUM_CELL];  /* Array to store cellCb ptr */
582    SchSliceCfg   sliceCfg;
583 }SchCb;
584
585 /* Declaration for scheduler control blocks */
586 SchCb schCb[SCH_MAX_INST];
587
588 /* function declarations */
589 short int schActvTmr(Ent ent,Inst inst);
590
591 /* Configuration related function declarations */
592 void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo);
593 void schInitDlSlot(SchDlSlotInfo *schDlSlotInfo);
594 void BuildK0K1Table(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres, \
595    SchPdschCfgCmn pdschCmnCfg,SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl);
596 void BuildK2InfoTable(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], \
597    uint16_t puschSymTblSize, SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl);
598 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt *cfm);
599 SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti);
600 uint8_t addUeToBeScheduled(SchCellCb *cell, uint8_t ueId);
601
602 /* Incoming message handler function declarations */
603 uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst inst);
604 uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst);
605 uint8_t schProcessCrcInd(CrcIndInfo *crcInd, Inst schInst);
606
607 /* DL scheduling related function declarations */
608 PduTxOccsaion schCheckSsbOcc(SchCellCb *cell, SlotTimingInfo slotTime);
609 PduTxOccsaion schCheckSib1Occ(SchCellCb *cell, SlotTimingInfo slotTime);
610 uint8_t schBroadcastSsbAlloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
611 uint8_t schBroadcastSib1Alloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
612 bool schProcessRaReq(Inst schInst, SchCellCb *cellCb, SlotTimingInfo currTime, uint8_t ueId);
613 uint8_t schProcessMsg4Req(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId,bool isRetxMsg4, SchDlHqProcCb **hqP);
614 uint8_t schFillRar(SchCellCb *cell, SlotTimingInfo rarTime, uint16_t ueId, RarAlloc *rarAlloc, uint8_t k0Index);
615 uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t crnti,
616 uint32_t tbSize, DlMsgAlloc *dlMsgAlloc, uint16_t startPRB, uint8_t pdschStartSymbol, uint8_t pdschNumSymbols,bool isRetx, SchDlHqProcCb* hqP);
617 uint8_t schDlRsrcAllocMsg4(SchCellCb *cell, SlotTimingInfo msg4Time, uint8_t ueId, DlMsgAlloc *msg4Alloc,\
618 uint8_t pdschStartSymbol, uint8_t pdschNumSymbols, bool isRetx, SchDlHqProcCb *hqP);
619 uint8_t allocatePrbDl(SchCellCb *cell, SlotTimingInfo slotTime, uint8_t startSymbol, uint8_t symbolLength, \
620    uint16_t *startPrb, uint16_t numPrb);
621 void fillDlMsgInfo(DlMsgInfo *dlMsgInfo, uint8_t crnti, bool isRetx, SchDlHqProcCb* hqP);
622 bool findValidK0K1Value(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId, bool dedMsg, uint8_t *pdschStartSymbol,\
623 uint8_t *pdschSymblLen, SlotTimingInfo *pdcchTime,  SlotTimingInfo *pdschTime, SlotTimingInfo *pucchTime, bool isRetx, SchDlHqProcCb *hqP);
624 RaRspWindowStatus isInRaRspWindow(SchRaReq *raReq, SlotTimingInfo frameToCheck, uint16_t numSlotsPerSystemFrame);
625 /* UL scheduling related function declarations */
626 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst);
627 bool schCheckPrachOcc(SchCellCb *cell, SlotTimingInfo prachOccasionTimingInfo);
628 uint8_t schCalcPrachNumRb(SchCellCb *cell);
629 void schPrachResAlloc(SchCellCb *cell, UlSchedInfo *ulSchedInfo, SlotTimingInfo prachOccasionTimingInfo);
630 uint16_t schAllocPucchResource(SchCellCb *cell, SlotTimingInfo pucchTime, uint16_t crnti,SchUeCb *ueCb, bool isRetx, SchDlHqProcCb *hqP);
631 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo, bool isRetx, SchUlHqProcCb *hqP);
632 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize,
633                             uint8_t startSymb, uint8_t symbLen, uint16_t startPrb, bool isRetx, SchUlHqProcCb *hqP);
634 uint8_t allocatePrbUl(SchCellCb *cell, SlotTimingInfo slotTime, uint8_t startSymbol, uint8_t symbolLength, \
635    uint16_t *startPrb, uint16_t numPrb);
636 bool schProcessSrOrBsrReq(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId, bool isRetx, SchUlHqProcCb **hqP);
637 uint8_t schCalculateUlTbs(SchUeCb *ueCb, SlotTimingInfo puschTime, uint8_t symbLen,\
638                              uint16_t *startPrb, uint32_t *totTBS, bool isRetx, SchUlHqProcCb *hqP);
639
640 /*Generic Functions*/
641 void updateGrantSizeForBoRpt(CmLListCp *lcLL, DlMsgAlloc *dlMsgAlloc, BsrInfo *bsrInfo, uint32_t *accumalatedBOSize);
642 uint16_t searchLargestFreeBlock(SchCellCb *cell, SlotTimingInfo slotTime,uint16_t *startPrb, Direction dir);
643 LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLL action);
644 void prbAllocUsingRRMPolicy(CmLListCp *lcLL, bool dedicatedPRB, uint16_t mcsIdx,uint8_t numSymbols,\
645                       uint16_t *sharedPRB, uint16_t *reservedPRB, bool *isTxPayloadLenAdded, bool *srRcvd);
646 void updateBsrAndLcList(CmLListCp *lcLL, BsrInfo *bsrInfo, uint8_t status);
647
648 /*Paging Functions*/
649 void schProcPagingCfg(SchCellCb *cell);
650 void schCfgPdcchMonOccOfPO(SchCellCb *cell);
651 void schIncrSlot(SlotTimingInfo *timingInfo, uint8_t incr, uint16_t numSlotsPerRF);
652 uint8_t schFillPagePdschCfg(SchCellCb *cell, PdschCfg *pagePdschCfg, SlotTimingInfo slotTime, \
653                              uint16_t tbSize, uint8_t mcs, uint16_t startPrb);
654 /*DL HARQ Functions*/
655 void schDlHqEntInit(SchCellCb *cellCb, SchUeCb *ueCb);
656 void schMsg4FeedbackUpdate(SchDlHqProcCb *hqP, uint8_t fdbk);
657 void schDlHqFeedbackUpdate(SchDlHqProcCb *hqP, uint8_t fdbk1, uint8_t fdbk2);
658 uint8_t schDlGetAvlHqProcess(SchCellCb *cellCb, SchUeCb *ueCb, SchDlHqProcCb **hqP);
659 void schDlReleaseHqProcess(SchDlHqProcCb *hqP);
660
661 /*UL HARQ Functions*/
662 void schUlHqEntInit(SchCellCb *cellCb, SchUeCb *ueCb);
663 uint8_t schMsg3RetxSchedulingForUe(SchRaCb *raCb);
664 void schUlHqProcessNack(SchUlHqProcCb *hqP);
665 void schUlHqProcessAck(SchUlHqProcCb *hqP);
666 uint8_t schUlGetAvlHqProcess(SchCellCb *cellCb, SchUeCb *ueCb, SchUlHqProcCb **hqP);
667 void schUlReleaseHqProcess(SchUlHqProcCb *hqP, Bool togNdi);
668
669 /* UE Manager HARQ Fun*/
670 void schUpdateHarqFdbk(SchUeCb *ueCb, uint8_t numHarq, uint8_t *harqPayload,SlotTimingInfo *slotInd);
671
672 /* Round Robbin Scheduler funtions*/
673 uint8_t schFillUlDciForMsg3Retx(SchRaCb *raCb, SchPuschInfo *puschInfo, DciInfo *dciInfo);
674 bool schGetMsg3K2(SchCellCb *cell, SchUlHqProcCb* msg3HqProc, uint16_t dlTime, SlotTimingInfo *msg3Time, bool isRetx);
675 void schMsg4Complete(SchUeCb *ueCb);
676 /**********************************************************************
677   End of file
678  **********************************************************************/