Merge "[Epic-ID: ODUHIGH-517][Task-ID: ODUHIGH-540][SubTask-Id: ODUHIGH-549] Multi...
[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_MU0_NUM_SLOTS 10 
21 #define SCH_MU1_NUM_SLOTS 20 
22 #define SCH_MU2_NUM_SLOTS 30 
23 #define SCH_MU3_NUM_SLOTS 40 
24 #define SCH_MU4_NUM_SLOTS 50 
25 #define SCH_MAX_SFN 1024
26 #define SCH_MIB_TRANS 8  /* MIB transmission as per 38.331 is every 80 ms */
27 #define SCH_SIB1_TRANS 16 /* SIB1 transmission as per 38.331 is every 160 ms */
28 #define SCH_NUM_SC_PRB 12 /* number of SCs in a PRB */
29 #define SCH_MAX_SSB_BEAM 8 /* since we are supporting only SCS=15KHz and 30KHz */
30 #define SCH_SSB_NUM_SYMB 4
31 #define SCH_SSB_NUM_PRB 21 /* One extra PRB as buffer */
32 #define SCHED_DELTA 1
33 #define BO_DELTA 1
34 #define RAR_DELAY   2
35 #define MSG4_DELAY  1
36 #define PDSCH_START_RB 10
37 /* Considering pdsch region from 3 to 13, DMRS exclued.
38  * Overlapping of PDSCH DRMS and PDSCH not supported by Intel L1 */
39 #define NUM_PDSCH_SYMBOL 11
40 #define PUSCH_START_RB 15
41 #define PUCCH_NUM_PRB_FORMAT_0_1_4 1  /* number of PRBs in freq domain, spec 38.213 - 9.2.1 */
42 #define SI_RNTI 0xFFFF
43 #define P_RNTI  0xFFFE
44 #define DMRS_MAP_TYPE_A 1
45 #define NUM_DMRS_SYMBOLS 1
46 #define DMRS_ADDITIONAL_POS 0
47 #define SCH_DEFAULT_K1 1
48 #define SSB_IDX_SUPPORTED 1
49
50 #define CRC_FAILED 0
51 #define CRC_PASSED 1
52
53 #define MAC_HDR_SIZE  3   /* 3 bytes of MAC Header */
54 #define UL_GRANT_SIZE 224
55
56 #define PRB_BITMAP_IDX_LEN 64
57 #define PRB_BITMAP_MAX_IDX ((MAX_NUM_RB + PRB_BITMAP_IDX_LEN-1) / PRB_BITMAP_IDX_LEN)
58
59 #define SCH_MAX_NUM_UL_HQ_PROC 16
60 #define SCH_MAX_NUM_DL_HQ_PROC 16
61 #define SCH_MAX_NUM_MSG3_TX 2
62 #define SCH_MAX_NUM_DL_HQ_TX 3
63 #define SCH_MAX_NUM_UL_HQ_TX 3
64 #define SCH_MAX_NUM_MSG4_TX 2
65 #define HQ_ACK 0
66 #define HQ_NACK 1
67 #define HQ_DTX 2
68 #define ROOT_SEQ_LEN_1 139
69 #define ROOT_SEQ_LEN_2 839
70
71 #ifdef NR_DRX
72 /* As per 38.331 the largest offset which can be used in of size 10240.
73  * But using this much size of array can cause memory related issue so thats why
74  * taking this size which are a multiple of the larger size */
75 #define MAX_DRX_SIZE 512
76 #endif
77
78 #define NUM_SCH_TYPE 2  /*Supported number of Scheduler Algorithm types*/
79
80 #define SCH_TQ_SIZE 10
81
82 /*3GPP 38.331,'frequencyDomainResources' :Number of PRBs per Resource Block Group*/
83 #define NUM_PRBS_PER_RBG 6 
84
85 /*3GPP 38.214 Table 5.2.2.1-2*/
86 #define MAX_NUM_CQI_IDX 16
87
88 /*3GPP 38.211 Table 7.3.2.1-1*/
89 #define MAX_NUM_AGG_LVL 5
90
91 typedef struct schDlHqProcCb SchDlHqProcCb;
92 typedef struct schUlHqEnt SchUlHqEnt;
93 typedef struct schRaReq SchRaReq;
94 typedef struct schDlHqEnt SchDlHqEnt;
95 typedef struct schCellCb SchCellCb;
96 typedef struct schUeCb SchUeCb;
97
98 typedef enum
99 {
100    SCH_FCFS,
101    SCH_SLICE_BASED
102 }SchType;
103
104 typedef enum
105 {
106    SCH_NUMEROLOGY_0,
107    SCH_NUMEROLOGY_1,
108    SCH_NUMEROLOGY_2,
109    SCH_NUMEROLOGY_3,
110    SCH_NUMEROLOGY_4
111 }SchNumerology;
112
113 typedef enum
114 {
115    SCH_UE_STATE_INACTIVE,
116    SCH_UE_STATE_ACTIVE,
117    SCH_UE_HANDIN_IN_PROGRESS
118 }SchUeState;
119
120 typedef enum
121 {
122    SCH_RA_STATE_MSG2_HANDLE,
123    SCH_RA_STATE_MSG3_PENDING,
124    SCH_RA_STATE_MSG4_PENDING,
125    SCH_RA_STATE_MSG4_DONE
126 }SchRaState;
127
128 typedef enum
129 {
130    SCH_LC_STATE_INACTIVE,
131    SCH_LC_STATE_ACTIVE
132 }SchLcState;
133
134 typedef enum
135 {
136    WINDOW_YET_TO_START,
137    WITHIN_WINDOW,
138    WINDOW_EXPIRED
139 }RaRspWindowStatus;
140
141 typedef enum
142 {
143    HQ_TB_ACKED=0,
144    HQ_TB_NACKED,
145    HQ_TB_WAITING
146 }SchHqTbState;
147
148 #ifdef NR_TDD
149 typedef enum
150 {
151    DL_SLOT,
152    UL_SLOT,
153    FLEXI_SLOT
154 }SlotConfig;
155
156 typedef enum
157 {
158    DL_SYMBOL,
159    UL_SYMBOL,
160    FLEXI_SYMBOL
161 }SchSymbolConfig;
162 #endif
163
164 /*Following structures to keep record and estimations of PRB allocated for each
165  * LC taking into consideration the RRM policies*/
166 typedef struct lcInfo
167 {
168    uint8_t  lcId;     /*LCID for which BO are getting recorded*/
169    uint32_t reqBO;    /*Size of the BO requested/to be allocated for this LC*/
170    uint32_t allocBO;  /*TBS/BO Size which is actually allocated*/
171    uint8_t  allocPRB; /*PRB count which is allocated based on RRM policy/FreePRB*/
172 }LcInfo;
173
174 typedef struct schUlHqTbCb
175 {
176    uint32_t               tbSzReq;
177    uint32_t               tbSzAllc;
178    uint8_t                ndi;
179    uint8_t                rv;
180    uint8_t                rvIdx;
181    uint8_t                qamOrder;
182    SchMcsTable            mcsTable;
183    uint8_t                iMcs;
184    uint8_t                iMcsInDci;
185    uint8_t                numLyrs;
186    uint8_t                txCntr;
187    SchHqTbState           state;
188    uint8_t                cntrRetxAllocFail;
189    uint8_t                statsBitmap;
190 }SchUlHqTbCb;
191
192 typedef struct schDlHqTbCb
193 {
194    uint8_t                tbIdx;
195    Bool                   isEnabled;
196    uint32_t               tbSzReq;
197    uint8_t                txCntr;
198    uint8_t                ndi;
199    uint8_t                rv;
200    uint8_t                rvIdx;
201    uint8_t                iMcs;
202    uint8_t                iMcsInDci;
203    uint8_t                numLyrs;
204    SchHqTbState           state;
205    uint8_t                isAckNackDtx;
206    uint8_t                cntrRetxAllocFail;
207    //InfUeTbInfo          tbCompInfo;
208    uint8_t                statsBitmap;
209 }SchDlHqTbCb;
210
211 #ifdef NR_DRX
212 typedef struct schDrxHarqCb
213 {
214    uint32_t     rttExpIndex;
215    CmLList      *rttExpNode;
216    uint32_t     retxStrtIndex; 
217    CmLList      *retxStrtNode;
218    uint32_t     retxExpIndex;
219    CmLList      *retxExpNode;
220 }SchDrxHarqCb;
221 #endif
222
223 typedef struct schUlHqProcCb
224 {
225    uint8_t           procId;       /*!< HARQ Process ID */
226    SchUlHqEnt        *hqEnt;
227    uint8_t           maxHqTxPerHqP;
228    SchUlHqTbCb       tbInfo;
229    CmLList           ulHqEntLnk;
230    CmLList           ulSlotLnk;
231    uint8_t           strtSymbl;
232    uint8_t           numSymbl;
233    void              *schSpcUlHqProcCb;  /*!< Scheduler specific HARQ Proc CB */
234    CmLList           ulHqProcLink;
235    uint8_t           puschResType;       /*!< Resource allocation type */
236    uint16_t          puschStartPrb;
237    uint16_t          puschNumPrb;
238    uint8_t           dmrsMappingType;
239    uint8_t           nrOfDmrsSymbols;
240    uint8_t           dmrsAddPos;
241    SlotTimingInfo    puschTime;
242 #ifdef NR_DRX
243    SchDrxHarqCb      ulDrxHarqCb;
244 #endif
245 }SchUlHqProcCb;
246
247 struct schDlHqProcCb
248 {
249    uint8_t           procId;       /*!< HARQ Process ID */
250    SchDlHqEnt        *hqEnt;
251    uint8_t           maxHqTxPerHqP;
252    CmLList           dlHqEntLnk;
253    CmLList           ulSlotLnk;
254    SchDlHqTbCb       tbInfo[2];
255    uint8_t           k1;
256    void              *schSpcDlHqProcCb;  /*!< Scheduler specific HARQ Proc CB */
257    CmLList           dlHqProcLink;
258    SlotTimingInfo    pucchTime;
259 #ifdef NR_DRX
260    SchDrxHarqCb      dlDrxHarqCb;
261 #endif
262 };
263 struct schUlHqEnt
264 {
265    SchCellCb      *cell;     /*!< Contains the pointer to cell*/
266    SchUeCb        *ue;       /*!< Contains the pointer to ue*/
267    CmLListCp      free;      /*!< List of free HARQ processes */
268    CmLListCp      inUse;     /*!< List of in-use HARQ processes */
269    uint8_t        maxHqTx;   /*!< Maximum number of harq re-transmissions */
270    uint8_t        numHqPrcs; /*!< Number of HARQ Processes */
271    SchUlHqProcCb  procs[SCH_MAX_NUM_UL_HQ_PROC]; /*!< Uplink harq process info */
272 };
273 struct schDlHqEnt
274 {
275    SchCellCb      *cell;     /*!< Contains the pointer to cell */
276    SchUeCb        *ue;       /*!< Contains the pointer to UE */
277    CmLListCp      free;      /*!< List of free HARQ processes */
278    CmLListCp      inUse;     /*!< List of in-use HARQ processes */
279    uint8_t        maxHqTx;   /*!< Maximum number of harq transmissions */
280    uint8_t        numHqPrcs; /*!< Number of HARQ Processes */
281    SchDlHqProcCb  procs[SCH_MAX_NUM_DL_HQ_PROC];/*!< Downlink harq processes */
282 };
283
284 /**
285  * @brief
286  * Structure holding LTE MAC's General Configuration information.
287  */
288 typedef struct schGenCb
289 {
290    uint8_t         startCellId;      /*!< Starting Cell Id */
291 #ifdef LTE_ADV
292    bool            forceCntrlSrbBoOnPCel; /*!< value 1 means force scheduling
293                                             of RLC control BO and SRB BO on
294                                             PCell. val 0 means don't force*/
295    bool            isSCellActDeactAlgoEnable; /*!< TRUE will enable activation/deactivation algo at Schd */
296 #endif
297 }SchGenCb;
298
299 typedef struct freePrbBlock
300 {
301    uint16_t numFreePrb;
302    uint16_t startPrb;
303    uint16_t endPrb;
304 }FreePrbBlock;
305
306 /**
307  * @brief
308  * PRB allocations for a symbol within a slot
309  */
310 typedef struct schPrbAlloc
311 {
312    CmLListCp freePrbBlockList;           /*!< List of continuous blocks for available PRB */
313    uint64_t  prbBitMap[ MAX_SYMB_PER_SLOT][PRB_BITMAP_MAX_IDX];  /*!< BitMap to store the allocated PRBs */
314    uint16_t  numPrbAlloc;
315 }SchPrbAlloc;
316
317
318 typedef struct schPdcchAllocInfo
319 {
320    uint8_t  cRSetId;
321    uint8_t  ssId;
322    uint8_t  aggLvl;
323    uint16_t cceIndex; 
324 }SchPdcchAllocInfo;
325
326 /**
327  * @brief
328  * scheduler allocationsfor DL per cell.
329  */
330 typedef struct schDlSlotInfo
331 {
332    SchPrbAlloc  prbAlloc;                 /*!< PRB allocated/available in this slot */
333    bool         ssbPres;                  /*!< Flag to determine if SSB is present in this slot */
334    uint8_t      ssbIdxSupported;          /*!< Max SSB index */
335    SsbInfo      ssbInfo[MAX_SSB_IDX];     /*!< SSB info */
336    bool         sib1Pres;                 /*!< Flag to determine if SIB1 is present in this slot */
337    uint8_t      pdcchUe;                  /*!< UE for which PDCCH Common is scheduled in this slot */
338    RarAlloc     *rarAlloc[MAX_NUM_UE];    /*!< RAR allocation per UE*/
339    DciInfo      *ulGrant;
340    DlMsgSchInfo *dlMsgAlloc[MAX_NUM_UE];  /*!< Dl msg allocation per UE*/
341 }SchDlSlotInfo;
342
343 typedef struct schRaCb
344 {
345    uint8_t   ueId;
346    bool      msg4recvd;
347    uint16_t  tcrnti;
348    uint16_t  dlMsgPduLen;
349    SchUlHqProcCb msg3HqProc;
350    SchUlHqProcCb *retxMsg3HqProc;
351    SchRaState raState;
352    SchCellCb *cell;
353    SchRaReq  *raReq;
354 }SchRaCb;
355
356 /**
357  * @brief
358  * scheduler allocationsfor UL per cell.
359  */
360 typedef struct schUlSlotInfo
361 {
362    SchPrbAlloc  prbAlloc;         /*!< PRB allocated/available per symbol */
363    uint8_t      puschCurrentPrb;  /*!< Current PRB for PUSCH allocation */
364    bool         puschPres;        /*!< PUSCH presence field */
365    SchPuschInfo *schPuschInfo;    /*!< PUSCH info */
366    bool         pucchPres;        /*!< PUCCH presence field */
367    SchPucchInfo schPucchInfo;     /*!< PUCCH info */
368    uint8_t      pucchUe;          /*!< Store UE id for which PUCCH is scheduled */
369    uint8_t      puschUe;          /*!< Store UE id for which PUSCH is scheduled */
370 }SchUlSlotInfo;
371
372 /**
373 @brief
374 * BSR info per slot per UE.
375 */
376 typedef struct bsrInfo
377 {
378    uint8_t    priority;  /* CG priority */
379    uint32_t   dataVol;   /* Data volume requested in bytes */
380 }BsrInfo;
381
382 typedef struct schLcCtxt
383 {
384    uint8_t lcId;     // logical Channel ID
385    uint8_t lcp;      // logical Channel Prioritization
386    SchLcState lcState;
387    uint32_t bo;
388    uint16_t   pduSessionId; /*Pdu Session Id*/
389    Snssai  *snssai;      /*S-NSSAI assoc with LCID*/
390    bool isDedicated;     /*Flag containing Dedicated S-NSSAI or not*/
391    uint16_t rsvdDedicatedPRB;
392 }SchDlLcCtxt;
393
394 typedef struct schDlCb
395 {
396    SchDlLcCtxt   dlLcCtxt[MAX_NUM_LC];
397 }SchDlCb;
398
399 typedef struct schUlLcCtxt
400 {
401    SchLcState  lcState;
402    uint8_t lcId;
403    uint8_t priority;
404    uint8_t lcGroup;
405    uint8_t schReqId;
406    uint8_t pbr;        // prioritisedBitRate
407    uint8_t bsd;        // bucketSizeDuration
408    uint16_t   pduSessionId; /*Pdu Session Id*/
409    Snssai  *snssai;      /*S-NSSAI assoc with LCID*/
410    bool isDedicated;     /*Flag containing Dedicated S-NSSAI or not*/
411    uint16_t rsvdDedicatedPRB;
412 }SchUlLcCtxt;
413
414 typedef struct schUlCb
415 {
416    SchUlLcCtxt ulLcCtxt[MAX_NUM_LC];
417 }SchUlCb;
418
419 typedef struct schUeCfgCb
420 {
421    uint16_t        cellId;
422    uint8_t         ueId;
423    uint16_t        crnti;
424    bool macCellGrpCfgPres;
425    SchMacCellGrpCfg   macCellGrpCfg;
426    bool phyCellGrpCfgPres;
427    SchPhyCellGrpCfg   phyCellGrpCfg;
428    bool spCellCfgPres;
429    SchSpCellRecfg       spCellCfg;
430    SchAmbrCfg         *ambrCfg;
431    SchModulationInfo  dlModInfo;
432    SchModulationInfo  ulModInfo;
433    SchDataTransmission dataTransmissionAction;
434 }SchUeCfgCb;
435
436 typedef struct schHqDlMap
437 {
438    CmLListCp hqList;
439 }SchHqDlMap;
440
441 typedef struct schHqUlMap
442 {
443    CmLListCp hqList;
444 }SchHqUlMap;
445
446 #ifdef NR_DRX
447 typedef struct  schDrxUeCb
448 {
449    bool      drxDlUeActiveStatus;       /* Final Dl Ue status which is marked as true if drxDlUeActiveMask or drxDlUeActiveMaskForHarq is present */
450    bool      drxUlUeActiveStatus;       /* Final Ul Ue status which is marked as true if drxUlUeActiveMask or drxUlUeActiveMaskForHarq is present */
451    uint32_t  drxDlUeActiveMask;          /* variable is used to store the status about downlink active status of Ue for On-duration, inactive timer*/
452    uint32_t  drxUlUeActiveMask;          /* variable is used to store the status about uplink active status for on-duration inactive timer*/
453    uint32_t  drxDlUeActiveMaskForHarq;   /* variable is used to store the status about downlink active status for harq*/
454    uint32_t  drxUlUeActiveMaskForHarq;   /* variable is used to store the status about uplink active status for harq */
455    uint32_t  onDurationLen;          /* length of on duration which is received from ue cfg/recfg in form of ms and subms, informs about after how many slots on duration gets expire */
456    uint32_t  inActvTimerLen;         /* length of inActvTimer value received from ue cfg/recfg in form of ms, informs about after how many slots in active gets expire */
457    uint8_t   harqRttDlTimerLen;      /* length of harqRttDlTimer received from ue cfg/recfg in form of symbols, inform about after how many slots on the harq drx-HARQ-RTT-TimerDL expire */
458    uint8_t   harqRttUlTimerLen;      /* length of harqRttUlTimer received from ue cfg/recfg in form of symbols,informs about after how many slots on harq drx-HARQ-RTT-TimerUL expire*/
459    uint32_t  retransDlTimerLen;      /* length of retransDlTimer received from ue cfg/recfg in form of slot, informs about after how many slots on harq RetransmissionTimer dl timer expire*/
460    uint32_t  retransUlTimerLen;      /* length of retransUlTimer received from ue cfg/recfg in form of slot, informs about after how many slots on harq RetransmissionTimer ul timer expire*/
461    uint32_t  longCycleLen;           /* length of long Cycle value received from ue cfg/recfg in form of ms*/
462    bool      longCycleToBeUsed;      /* long cycle should be used once the short cycle gets expires */
463    uint32_t  drxStartOffset;         /* length of drxStartOffset value received from ue cfg/recfg in form of ms, which helps in getting on duration start point*/
464    bool      shortCyclePresent;      /* set this value if shortCycle is Present */
465    uint32_t  shortCycleLen;          /* length of short Cycle value received from ue cfg/recfg in form of ms*/
466    uint32_t  shortCycleTmrLen;       /* value shortCycleTmr is the multiple of shortCycle which is received from ue cfg/recfg in form of integer*/
467    uint32_t  drxSlotOffset;          /* drxSlotOffset value received from ue cfg/recfg which is used to delay before starting the drx-onDuration*/
468    uint32_t  onDurationStartIndex;   /* Index at which UE is stored in onDuration starts list */
469    uint32_t  onDurationExpiryIndex;  /* Index at which UE is stored in onDuration expires in the list */ 
470    uint32_t  inActvExpiryIndex;      /* Index at which UE is stored in inActvTimer expires in the list */
471    uint32_t  shortCycleExpiryIndex;  /* Index at which UE is stored in shortCycle expires in the list */
472    int32_t   shortCycleDistance;     /* Distance after how many slot short cycle tmr gets expire */ 
473    int32_t   onDurationStartDistance;/* Distance after how many slot on Duration Start tmr gets expire */
474    int32_t   onDurationExpiryDistance;/* Distance after how many slot on Duration tmr gets expire */
475    int32_t   inActiveTmrExpiryDistance;/* Distance after how many slot inActive tmr gets expire */
476    CmLList   *onDurationStartNodeInfo; /* Node present in on duration start list*/
477    CmLList   *onDurationExpiryNodeInfo;/* Node present in on duration exp list*/
478    CmLList   *inActvTimerExpiryNodeInfo; /* Node present in in active exp list*/
479    CmLList   *shortCycleTmrExpiryNodeInfo; /* Node present in short cycle exp list*/
480 }SchDrxUeCb;
481 #endif
482
483 typedef struct schPdcchInfo
484 {
485    SchControlRsrcSet *cRSetRef; /*Coreset Cfg reference from SchUeCfgCb*/
486    SchSearchSpace    *ssRef;    /*SearchSpace Cfg reference from SchUeCfgCb*/
487    uint16_t          totalPrbs; /*Total PRBs configured for this CORESET*/
488    uint8_t           nrOfPRBPerCce; /*CCE Size*/
489    uint8_t           totalCceCount; /*Count of CCE in this CORESET*/
490    uint8_t           cqiIndxAggLvlMap[MAX_NUM_CQI_IDX];/*Agg Level to be used for each CQI Index*/
491    uint32_t          *y; /*Coefficient variable to calculate CCE Index as per 3gpp Spec 38.213 Sec 10.1*/
492 }SchPdcchInfo;
493
494 /**
495  * @brief
496  * UE control block
497  */
498 typedef struct schUeCb
499 {
500    uint16_t   ueId;
501    uint16_t   crnti;
502    SchUeCfgCb ueCfg;
503    SchUeState state;
504    SchCellCb  *cellCb;
505    SchCfraResource cfraResource;
506    bool       srRcvd;
507    bool       bsrRcvd;
508    BsrInfo    bsrInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS];
509    SchUlCb    ulInfo;
510    SchDlCb    dlInfo;
511    SchUlHqEnt ulHqEnt;
512    SchDlHqEnt dlHqEnt;
513    SchDlHqProcCb *msg4HqProc;
514    SchDlHqProcCb *retxMsg4HqProc;
515    SchHqDlMap    **hqDlmap;
516    SchHqUlMap    **hqUlmap;
517    void          *schSpcUeCb;
518 #ifdef NR_DRX
519    bool          ueDrxInfoPres;
520    SchDrxUeCb    drxUeCb;
521 #endif
522    bool                 k0K1TblPrsnt;
523    SchK0K1TimingInfoTbl k0K1InfoTbl;
524    bool                 k2TblPrsnt;
525    SchK2TimingInfoTbl   k2InfoTbl;
526    SchPdcchInfo         pdcchInfo[MAX_NUM_CRSET];
527 }SchUeCb;
528
529 /**
530  * @brief
531  * RA Request Info
532  */
533 typedef struct schRaReq
534 {
535    uint32_t        raRnti;
536    RachIndInfo     *rachInd;
537    bool            isCFRA;
538    SchUeCb         *ueCb;          /* Filled only if isCFRA = true */
539    SlotTimingInfo  winStartTime;
540    SlotTimingInfo  winEndTime;
541 }SchRaReq;
542
543 typedef struct schPageInfo
544 {
545   uint16_t       pf;          /*Value of Paging Frame received from DUAPP*/
546   uint8_t        i_s;         /*Value of Paging Occ Index received from DUAPP*/
547   SlotTimingInfo pageTxTime;  /*Start Paging window*/
548   uint8_t        mcs;         /*MCS index*/
549   uint16_t       msgLen;      /*Pdu length */
550   uint8_t       *pagePdu;     /*RRC Page PDU bit string*/
551 }SchPageInfo;
552
553 typedef struct schPagingOcc
554 {
555   uint8_t frameOffset;
556   uint8_t pagingOccSlot;
557 }SchPagingOcc;
558
559 typedef struct schPageCb
560 {
561    CmLListCp    pageIndInfoRecord[MAX_SFN]; /*List of Page Records received which are stored per sfn*/
562    SchPagingOcc pagMonOcc[MAX_PO_PER_PF];   /*Paging Occasion Slot/FrameOffset are stored*/ 
563 }SchPageCb;
564
565 #ifdef NR_DRX
566 typedef struct schDrxCb
567 {
568    CmLListCp   onDurationStartList;   /*!< Tracks the start of onDuration Timer. */
569    CmLListCp   onDurationExpiryList;   /*!< Tracks the Expiry of onDuration Timer. */
570    CmLListCp   inActvTmrExpiryList;   /*!< Tracks the Expiry of drx-InactivityTimer. */
571    CmLListCp   shortCycleExpiryList;   /*!< Tracks the Expiry of DRX Short Cycle. */
572    CmLListCp   dlHarqRttExpiryList;   /*!< Tracks the Expiry of DL HARQ RTT timer. */
573    CmLListCp   dlRetransExpiryList;   /*!< Tracks the Expiry of DL Re-Transmission timer. */
574    CmLListCp   ulHarqRttExpiryList;   /*!< Tracks the Expiry of UL HARQ RTT timer. */
575    CmLListCp   ulRetransExpiryList;   /*!< Tracks the Expiry of UL Re-Transmission timer. */
576    CmLListCp   dlRetransTmrStartList; /*!< It has list of DL harq procs for */
577    CmLListCp   ulRetransTmrStartList; /*!< It has list of UL harq procs for */
578 }SchDrxCb;
579 #endif
580
581 typedef struct schAllApis
582 {
583    uint8_t (* SchCellCfgReq)(SchCellCb *cellCb);
584    void (* SchCellDeleteReq)(SchCellCb *cellCb);
585    uint8_t (* SchAddUeConfigReq)(SchUeCb  *ueCb);
586    void (* SchModUeConfigReq)(SchUeCb  *ueCb);
587    void (* SchUeDeleteReq)(SchUeCb  *ueCb);
588    void (* SchDlHarqInd)();
589    void (* SchPagingInd)();
590    void (* SchRachRsrcReq)();
591    void (* SchRachRsrcRel)();
592    void (* SchCrcInd)(SchCellCb *cellCb, uint16_t ueId);
593    void (* SchRachInd)(SchCellCb *cellCb, uint16_t ueId);
594    void (* SchDlRlcBoInfo)(SchCellCb *cellCb, uint16_t ueId);
595    void (* SchSrUciInd)(SchCellCb *cellCb, uint16_t ueId);
596    void (* SchBsr)(SchCellCb *cellCb, uint16_t ueId);
597    void (* SchHandleLcList)(void *ptr, CmLList *node, ActionTypeLL action);
598    void (* SchAddToDlHqRetxList)(SchDlHqProcCb *hqP);
599    void (* SchAddToUlHqRetxList)(SchUlHqProcCb *hqP);
600    void (* SchRemoveFrmDlHqRetxList)(SchUeCb *ueCb, CmLList *node);
601    void (* SchRemoveFrmUlHqRetxList)(SchUeCb *ueCb, CmLList *node);
602    uint8_t (* SchAddUeToSchedule)(SchCellCb *cellCb, uint16_t ueId);
603    void (* SchRemoveUeFrmScheduleLst)(SchCellCb *cell, CmLList *node);
604    uint8_t (* SchInitDlHqProcCb)(SchDlHqProcCb *hqP);
605    uint8_t (* SchInitUlHqProcCb)(SchUlHqProcCb *hqP);
606    void (* SchFreeDlHqProcCb)(SchDlHqProcCb *hqP);
607    void (* SchFreeUlHqProcCb)(SchUlHqProcCb *hqP);
608    void (* SchDeleteDlHqProcCb)(SchDlHqProcCb *hqP);
609    void (* SchDeleteUlHqProcCb)(SchUlHqProcCb *hqP);
610    void (* SchScheduleSlot)(SchCellCb *cell, SlotTimingInfo *slotInd, Inst schInst);
611    uint32_t (* SchScheduleDlLc)(SlotTimingInfo pdcchTime, SlotTimingInfo pdschTime, uint8_t pdschNumSymbols, \
612       uint16_t *startPrb, bool isRetx, SchDlHqProcCb **hqP);
613    uint8_t (* SchScheduleUlLc)(SlotTimingInfo dciTime, SlotTimingInfo puschTime, uint8_t startStmb, \
614       uint8_t symbLen, bool isRetx, SchUlHqProcCb **hqP);
615 }SchAllApis;
616
617 typedef struct schHqCfgParam
618 {
619    uint8_t maxDlDataHqTx;
620    uint8_t maxMsg4HqTx;
621    uint8_t maxUlDataHqTx;
622 }SchHqCfg;
623
624 typedef struct
625 {
626    /* parameters derived in scheduler */
627    uint8_t   n0;
628    BwpCfg    bwp;
629    PdcchCfg  sib1PdcchCfg;
630    PdschCfg  sib1PdschCfg;
631 }SchSib1Cfg;
632
633 typedef struct dlTotalPrbUsage
634 {
635    uint16_t numPrbUsedForTx;
636    uint16_t totalPrbAvailForTx;
637 }TotalPrbUsage;
638
639 typedef struct 
640 {
641    TotalPrbUsage *dlTotalPrbUsage;
642    TotalPrbUsage *ulTotalPrbUsage;
643 }SchKpiSupported;
644
645 typedef struct
646 {
647    CmLListCp  dlTotPrbUseList;
648    CmLListCp  ulTotPrbUseList;
649 }SchKpiActive;
650
651 typedef struct schStatsGrp
652 {
653    Inst       schInst;
654    uint64_t   subscriptionId;
655    uint8_t    groupId;
656    uint16_t   periodicity;  /* In milliseconds */
657    CmTimer    periodTimer;
658    SchKpiSupported kpiStats;
659 }SchStatsGrp;
660
661 typedef struct schStatistics
662 {
663    CmLListCp     statsGrpList;
664    SchKpiActive  activeKpiList;
665 }SchStatistics;
666
667 /**
668  * @brief
669  * Cell Control block per cell.
670  */
671 typedef struct schCellCb
672 {
673    uint16_t      cellId;                            /*!< Cell ID */
674    Inst          instIdx;                           /*!< Index of the scheduler instance */
675    Inst          macInst;                           /*!< Index of the MAC instance */
676    uint16_t       numSlots;                          /*!< Number of slots in current frame */
677    SlotTimingInfo   slotInfo;                          /*!< SFN, Slot info being processed*/
678    SchDlSlotInfo **schDlSlotInfo;                   /*!< SCH resource allocations in DL */
679    SchUlSlotInfo **schUlSlotInfo;                   /*!< SCH resource allocations in UL */
680    SchCellCfg    cellCfg;                           /*!< Cell ocnfiguration */
681    uint8_t       numerology;
682    bool          firstSsbTransmitted;
683    bool          firstSib1Transmitted;
684    uint8_t       ssbStartSymbArr[SCH_MAX_SSB_BEAM]; /*!< start symbol per SSB beam */
685    uint64_t      dedPreambleBitMap;                 /*!< Bit map to find used/free preambles index */
686    SchRaReq      *raReq[MAX_NUM_UE];                /*!< Pending RA request */
687    SchRaCb       raCb[MAX_NUM_UE];                  /*!< RA Cb */
688    uint16_t      numActvUe;                         /*!< Number of active UEs */
689    uint32_t      actvUeBitMap;                      /*!< Bit map to find active UEs */
690    uint32_t      boIndBitMap;                       /*!< Bit map to indicate UEs that have recevied BO */
691    SchUeCb       ueCb[MAX_NUM_UE];                  /*!< Pointer to UE contexts of this cell */
692    SchPageCb     pageCb;                            /*!< Page Record at Schedular*/
693 #ifdef NR_TDD
694    uint8_t       numSlotsInPeriodicity;             /*!< number of slots in configured periodicity and SCS */
695    uint32_t      slotFrmtBitMap;                    /*!< 2 bits must be read together to determine D/U/S slots. 00-D, 01-U, 10-S */
696    SchSymbolConfig       slotCfg[MAX_TDD_PERIODICITY_SLOTS][MAX_SYMB_PER_SLOT];
697 #endif
698 #ifdef NR_DRX
699    SchDrxCb      drxCb[MAX_DRX_SIZE];                           /*!< Drx cb*/
700 #endif
701    SchType       schAlgoType;                       /*!< The scheduler type which the cell is configured with.*/
702    SchAllApis    *api;                             /*!< Reference of sch APIs for this cell based on the SchType*/
703    void          *schSpcCell;                       /*Ref of Scheduler specific structure*/
704    SchHqCfg             schHqCfg;
705    SchK0K1TimingInfoTbl k0K1InfoTbl;
706    SchK2TimingInfoTbl   msg3K2InfoTbl;
707    SchK2TimingInfoTbl   k2InfoTbl;
708    SchSib1Cfg           sib1SchCfg;       /* SIB1 config */
709    uint8_t              maxMsg3Tx;         /* MAximum num of msg3 tx*/
710 }SchCellCb;
711
712 typedef struct schTimer
713 {
714    CmTqCp       tmrTqCp;               /*!< Timer Task Queue Cntrl Point */
715    CmTqType     tmrTq[SCH_TQ_SIZE];    /*!< Timer Task Queue */
716    uint8_t      tmrRes;              /*!< Timer resolution */
717 }SchTimer;
718
719 /**
720  * @brief
721  * Control block for sch
722  */
723 typedef struct schCb
724 {
725    TskInit                schInit;               /*!< Task Init info */
726    SchGenCb               genCfg;                /*!< General Config info */
727    SchTimer               schTimersInfo;         /*!< Sch timer queues and resolution */
728    SchAllApis             allApis[NUM_SCH_TYPE]; /*!<List of All Scheduler Type dependent Function pointers*/
729    SchCellCb              *cells[MAX_NUM_CELL];  /* Array to store cellCb ptr */
730    CmLListCp              sliceCfg;              /* Linklist to Store Slice configuration */
731    SchStatistics          statistics;            /* Statistics configuration and calculated values */
732 }SchCb;
733
734 /* Declaration for scheduler control blocks */
735 SchCb schCb[SCH_MAX_INST];
736
737 /* function declarations */
738 short int schActvTmr(Ent ent,Inst inst);
739 void SchFillCfmPst(Pst *reqPst,Pst *cfmPst,RgMngmt *cfm);
740
741 /* Configuration related function declarations */
742 void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo);
743 void schInitDlSlot(SchDlSlotInfo *schDlSlotInfo);
744 void BuildK0K1Table(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres, \
745    SchPdschCfgCmn pdschCmnCfg,SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl);
746 void BuildK2InfoTable(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], \
747    uint16_t puschSymTblSize, SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl);
748 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt *cfm);
749 SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti);
750 uint8_t addUeToBeScheduled(SchCellCb *cell, uint8_t ueId);
751
752 /* Incoming message handler function declarations */
753 uint8_t SchProcCellCfgReq(Pst *pst, SchCellCfg *schCellCfg);
754 uint8_t SchProcSlotInd(Pst *pst, SlotTimingInfo *slotInd);
755 uint8_t SchProcRachInd(Pst *pst, RachIndInfo *rachInd);
756 uint8_t SchProcCrcInd(Pst *pst, CrcIndInfo *crcInd);
757 uint8_t SchProcUlCqiInd(Pst *pst, SchUlCqiInd *ulCqiInd);
758 uint8_t SchProcDlCqiInd(Pst *pst, SchDlCqiInd *dlCqiInd);
759 uint8_t SchProcPhrInd(Pst *pst, SchPwrHeadroomInd *schPhrInd);
760 uint8_t SchProcDlRlcBoInfo(Pst *pst, DlRlcBoInfo *dlBoInfo);
761 uint8_t SchAddUeConfigReq(Pst *pst, SchUeCfgReq *ueCfgToSch);
762 uint8_t SchProcBsr(Pst *pst, UlBufferStatusRptInd *bsrInd);
763 uint8_t SchProcSrUciInd(Pst *pst, SrUciIndInfo *uciInd);
764 uint8_t SchModUeConfigReq(Pst *pst, SchUeRecfgReq *ueRecfgToSch);
765 uint8_t SchProcUeDeleteReq(Pst *pst, SchUeDelete  *ueDelete);
766 uint8_t SchProcCellDeleteReq(Pst *pst, SchCellDeleteReq  *schCellDelete);
767 uint8_t SchProcSliceCfgReq(Pst *pst, SchSliceCfgReq *schSliceCfgReq);
768 uint8_t SchProcSliceRecfgReq(Pst *pst, SchSliceRecfgReq *schSliceRecfgReq);
769 uint8_t SchProcRachRsrcReq(Pst *pst, SchRachRsrcReq *schRachRsrcReq);
770 uint8_t SchProcRachRsrcRel(Pst *pst, SchRachRsrcRel *schRachRsrcRel);
771 uint8_t SchProcPagingInd(Pst *pst,  SchPageInd *pageInd);
772 uint8_t SchProcDlHarqInd(Pst *pst, DlHarqInd *dlHarqInd);
773
774 /* DL scheduling related function declarations */
775 PduTxOccsaion schCheckSsbOcc(SchCellCb *cell, SlotTimingInfo slotTime);
776 PduTxOccsaion schCheckSib1Occ(SchCellCb *cell, SlotTimingInfo slotTime);
777 uint8_t schBroadcastSsbAlloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
778 uint8_t schBroadcastSib1Alloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
779 bool schProcessRaReq(Inst schInst, SchCellCb *cellCb, SlotTimingInfo currTime, uint8_t ueId);
780 uint8_t schProcessMsg4Req(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId,bool isRetxMsg4, SchDlHqProcCb **hqP);
781 uint8_t schFillRar(SchCellCb *cell, SlotTimingInfo rarTime, uint16_t ueId, RarAlloc *rarAlloc, uint8_t k0Index);
782 bool schFillBoGrantDlSchedInfo(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId, bool isRetx, SchDlHqProcCb **hqP);
783 uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t crnti, uint32_t tbSize, DlMsgSchInfo *dlMsgAlloc,\
784    uint16_t startPRB, uint8_t pdschStartSymbol, uint8_t pdschNumSymbols,bool isRetx, SchDlHqProcCb* hqP, SchPdcchAllocInfo pdcchAllocInfo);
785 uint8_t schDlRsrcAllocMsg4(SchCellCb *cell, SlotTimingInfo msg4Time, uint8_t ueId, DlMsgSchInfo *msg4Alloc,\
786 uint8_t pdschStartSymbol, uint8_t pdschNumSymbols, bool isRetx, SchDlHqProcCb *hqP);
787 uint8_t allocatePrbDl(SchCellCb *cell, SlotTimingInfo slotTime, uint8_t startSymbol, uint8_t symbolLength, \
788    uint16_t *startPrb, uint16_t numPrb);
789 void fillDlMsgInfo(DlMsgSchInfo *dlMsgInfo, uint16_t crnti, bool isRetx, SchDlHqProcCb* hqP); /*AS per 38.473 V15.3.0, Section 9.3.1.32 crnti value range is b/w 0..65535*/
790 bool findValidK0K1Value(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId, bool dedMsg, uint8_t *pdschStartSymbol, uint8_t *pdschSymblLen,\
791         SlotTimingInfo *pdcchTime,  SlotTimingInfo *pdschTime, SlotTimingInfo *pucchTime, bool isRetx, SchDlHqProcCb *hqP, SchPdcchAllocInfo *pdcchAllocInfo);
792 RaRspWindowStatus isInRaRspWindow(SchRaReq *raReq, SlotTimingInfo frameToCheck, uint16_t numSlotsPerSystemFrame);
793
794 /* UL scheduling related function declarations */
795 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst);
796 bool schCheckPrachOcc(SchCellCb *cell, SlotTimingInfo prachOccasionTimingInfo);
797 uint8_t schCalcPrachNumRb(SchCellCb *cell);
798 void schPrachResAlloc(SchCellCb *cell, UlSchedInfo *ulSchedInfo, SlotTimingInfo prachOccasionTimingInfo);
799 uint16_t schAllocPucchResource(SchCellCb *cell, SlotTimingInfo pucchTime, uint16_t crnti,SchUeCb *ueCb, bool isRetx, SchDlHqProcCb *hqP);
800 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo, bool isRetx, SchUlHqProcCb *hqP);
801 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize,
802                             uint8_t startSymb, uint8_t symbLen, uint16_t startPrb, bool isRetx, SchUlHqProcCb *hqP);
803 uint8_t allocatePrbUl(SchCellCb *cell, SlotTimingInfo slotTime, uint8_t startSymbol, uint8_t symbolLength, \
804    uint16_t *startPrb, uint16_t numPrb);
805 bool schProcessSrOrBsrReq(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId, bool isRetx, SchUlHqProcCb **hqP);
806
807 /*Generic Functions*/
808 void updateGrantSizeForBoRpt(CmLListCp *lcLL, DlMsgSchInfo *dlMsgAlloc, BsrInfo *bsrInfo, uint32_t *accumalatedBOSize);
809 uint16_t searchLargestFreeBlock(SchCellCb *cell, SlotTimingInfo slotTime,uint16_t *startPrb, Direction dir);
810 LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLL action);
811 void prbAllocUsingRRMPolicy(CmLListCp *lcLL, bool dedicatedPRB, uint16_t mcsIdx,uint8_t numSymbols,\
812                       uint16_t *sharedPRB, uint16_t *reservedPRB, bool *isTxPayloadLenAdded, bool *srRcvd);
813 void updateBsrAndLcList(CmLListCp *lcLL, BsrInfo *bsrInfo, uint8_t status);
814 uint8_t fillUeCoresetAndSsInfo(SchUeCb *ue);
815 bool schDlCandidateSelection(SchUeCb *ue,  SlotTimingInfo slotTime, SchPdcchAllocInfo *pdcchAllocInfo);
816
817 /*Paging Functions*/
818 void schProcPagingCfg(SchCellCb *cell);
819 void schCfgPdcchMonOccOfPO(SchCellCb *cell);
820 void schIncrSlot(SlotTimingInfo *timingInfo, uint8_t incr, uint16_t numSlotsPerRF);
821 uint8_t schFillPagePdschCfg(SchCellCb *cell, PageDlSch *pageDlSch, SlotTimingInfo slotTime, \
822                              uint16_t tbSize, uint8_t mcs, uint16_t startPrb);
823 /*DL HARQ Functions*/
824 void schDlHqEntInit(SchCellCb *cellCb, SchUeCb *ueCb);
825 void schMsg4FeedbackUpdate(SchDlHqProcCb *hqP, uint8_t fdbk);
826 void schDlHqFeedbackUpdate(SchDlHqProcCb *hqP, uint8_t fdbk1, uint8_t fdbk2);
827 uint8_t schDlGetAvlHqProcess(SchCellCb *cellCb, SchUeCb *ueCb, SchDlHqProcCb **hqP);
828 void schDlReleaseHqProcess(SchDlHqProcCb *hqP);
829 void schDlHqEntDelete(SchUeCb *ueCb);
830
831 /*UL HARQ Functions*/
832 void schUlHqEntInit(SchCellCb *cellCb, SchUeCb *ueCb);
833 uint8_t schMsg3RetxSchedulingForUe(SchRaCb *raCb);
834 void schUlHqProcessNack(SchUlHqProcCb *hqP);
835 void schUlHqProcessAck(SchUlHqProcCb *hqP);
836 uint8_t schUlGetAvlHqProcess(SchCellCb *cellCb, SchUeCb *ueCb, SchUlHqProcCb **hqP);
837 void schUlReleaseHqProcess(SchUlHqProcCb *hqP, Bool togNdi);
838 void schUlHqEntDelete(SchUeCb *ueCb);
839
840 /* UE Manager HARQ Fun*/
841 void schUpdateHarqFdbk(SchUeCb *ueCb, uint8_t numHarq, uint8_t *harqPayload,SlotTimingInfo *slotInd);
842
843 /* Round Robbin Scheduler funtions*/
844 uint8_t schFillUlDciForMsg3Retx(SchRaCb *raCb, SchPuschInfo *puschInfo, DciInfo *dciInfo);
845 bool schGetMsg3K2(SchCellCb *cell, SchUlHqProcCb* msg3HqProc, uint16_t dlTime, SlotTimingInfo *msg3Time, bool isRetx);
846 void schMsg4Complete(SchUeCb *ueCb);
847
848 /* Statistics Function */
849 uint8_t SchProcStatsReq(Pst *pst, SchStatsReq *statsReq);
850 uint8_t SchSendStatsIndToMac(Inst inst, SchStatsInd  *statsInd);
851 uint8_t schCalcAndSendGrpStats(SchStatsGrp *grpInfo);
852 uint8_t SchProcStatsDeleteReq(Pst *pst, SchStatsDeleteReq *statsDeleteReq);
853 uint8_t SchProcStatsModificationReq(Pst *pst, SchStatsModificationReq *statsModificationReq);
854 void deleteStatsGrpInfo(Inst inst, SchStatsGrp *statsGrpInfo);
855 /**********************************************************************
856   End of file
857  **********************************************************************/