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