RLC BO, BO response and DL Data handling. [Issue-ID: ODUHIGH-181]
[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_NUM_SLOTS 10 /*forcing this to 10 */
23 #define SCH_MAX_SFN 1024
24 #define MAX_NUM_RB 106 /* value for numerology 0 15Khz */
25 #define SCH_MIB_TRANS 80 
26 #define SCH_NUM_SC_PRB 12 /* number of SCs in a PRB */
27 #define SCH_MAX_SSB_BEAM 4 /* since we are supporting only SCS=15KHz */
28 #define SCH_SCS_15KHZ 0 /* numerology 0 and 15Khz */
29 #define SCH_SYMBOL_PER_SLOT 14
30 #define SCH_SSB_NUM_SYMB 4
31 #define SCH_SSB_NUM_PRB 20
32 #define SCHED_DELTA 1
33 #define BO_DELTA 1
34 #define RAR_DELAY   2
35 #define MSG4_DELAY  1
36 #define PUSCH_START_RB 15
37 #define PUCCH_NUM_PRB_FORMAT_0 1  /* number of PRBs in freq domain, spec 38.213 - 9.2.1 */
38 #define SI_RNTI 0xFFFF
39 #define P_RNTI  0xFFFE
40 #define DMRS_MAP_TYPE_A 1
41 #define NUM_DMRS_SYMBOLS 12
42 #define DMRS_ADDITIONAL_POS 2
43
44 #define CRC_FAILED 0
45 #define CRC_PASSED 1
46
47 #define RLC_HDR_SIZE  3   /* 3 bytes of RLC Header size */
48 #define MAC_HDR_SIZE  3   /* 3 bytes of MAC Header */
49 #define UL_GRANT_SIZE 224
50
51 typedef struct schCellCb SchCellCb;
52 typedef struct schUeCb SchUeCb;
53
54 typedef enum
55 {
56    SCH_UE_STATE_INACTIVE,
57    SCH_UE_STATE_ACTIVE
58 }SchUeState;
59
60 typedef enum
61 {
62    SCH_LC_STATE_INACTIVE,
63    SCH_LC_STATE_ACTIVE
64 }SchLcState;
65
66 /**
67  * @brief
68  * Structure holding LTE MAC's General Configuration information.
69  */
70 typedef struct schGenCb
71 {
72    uint8_t         tmrRes;           /*!< Timer resolution */
73    uint8_t         startCellId;      /*!< Starting Cell Id */
74 #ifdef LTE_ADV
75    bool            forceCntrlSrbBoOnPCel; /*!< value 1 means force scheduling
76                                             of RLC control BO and SRB BO on
77                                             PCell. val 0 means don't force*/
78    bool            isSCellActDeactAlgoEnable; /*!< TRUE will enable activation/deactivation algo at Schd */
79 #endif
80 }SchGenCb;
81
82 /**
83  * @brief
84  * scheduler allocationsfor DL per cell.
85  */
86 typedef struct schDlSlotInfo
87 {
88    uint16_t  totalPrb;                          /*!< Number of RBs in the cell */
89    uint16_t  assignedPrb[SCH_SYMBOL_PER_SLOT];  /*!< Num RBs and corresponding symbols allocated */
90    bool      ssbPres;                           /*!< Flag to determine if SSB is present in this slot */
91    uint8_t   ssbIdxSupported;                   /*!< Max SSB index */
92    SsbInfo   ssbInfo[MAX_SSB_IDX];              /*!< SSB info */
93    bool      sib1Pres;                          /*!< Flag to determine if SIB1 is present in this slot */
94    RarInfo   *rarInfo;                          /*!< RAR info */
95    DlMsgInfo *dlMsgInfo;                       /*!< DL dedicated Msg info */
96 }SchDlSlotInfo;
97
98 typedef struct schRaCb
99 {
100    uint16_t tcrnti;
101 }SchRaCb;
102
103 /**
104  * @brief
105  * scheduler allocationsfor UL per cell.
106  */
107 typedef struct schUlSlotInfo
108 {
109    uint16_t     totalPrb;  /*!< Number of RBs in the cell */
110    uint16_t     assignedPrb[SCH_SYMBOL_PER_SLOT]; /*!< Num RBs and corresponding symbols allocated */
111    uint8_t      puschCurrentPrb; /* Current PRB for PUSCH allocation */
112    bool         puschPres; /*!< PUSCH presence field */
113    SchPuschInfo *schPuschInfo; /*!< PUSCH info */
114    bool         pucchPres; /*!< PUCCH presence field */
115    SchPucchInfo schPucchInfo; /*!< PUCCH info */
116 }SchUlSlotInfo;
117
118 /**
119 @brief
120 * BSR info per slot per UE.
121 */
122 typedef struct bsrInfo
123 {
124    uint8_t    priority;  /* CG priority */
125    uint32_t   dataVol;   /* Data volume requested in bytes */
126 }BsrInfo;
127
128 typedef struct schLcCtxt
129 {
130    uint8_t lcp;      // logical Channel Prioritization
131    SchLcState lcState;
132    uint16_t bo;
133 }SchDlLcCtxt;
134
135 typedef struct schUlLcCtxt
136 {
137    SchLcState lcState;
138    uint8_t priority;
139    uint8_t lcGroup;
140    uint8_t schReqId;
141    uint8_t pbr;        // prioritisedBitRate
142    uint8_t bsd;        // bucketSizeDuration
143 }SchUlLcCtxt;
144
145 /**
146  * @brief
147  * UE control block
148  */
149 typedef struct schUeCb
150 {
151    uint16_t   ueIdx;
152    uint16_t   crnti;
153    SchUeCfg   ueCfg;
154    SchUeState state;
155    SchCellCb  *cellCb;
156    bool       srRcvd;
157    BsrInfo    bsrInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS];
158    uint8_t       numUlLc;
159    SchUlLcCtxt   ulLcCtxt[MAX_NUM_LC];
160    uint8_t       numDlLc;
161    SchDlLcCtxt   dlLcCtxt[MAX_NUM_LC];
162 }SchUeCb;
163
164 /**
165  * @brief
166  * Cell Control block per cell.
167  */
168 typedef struct schCellCb
169 {
170    uint16_t      cellId;                            /*!< Cell ID */
171    Inst          instIdx;                           /*!< Index of the scheduler instance */
172    Inst          macInst;                           /*!< Index of the MAC instance */
173    uint8_t       numSlots;                          /*!< Number of slots in current frame */
174    SlotIndInfo   slotInfo;                          /*!< SFN, Slot info being processed*/
175    SchDlSlotInfo *schDlSlotInfo[SCH_NUM_SLOTS];     /*!< SCH resource allocations in DL */
176    SchUlSlotInfo *schUlSlotInfo[SCH_NUM_SLOTS];     /*!< SCH resource allocations in UL */
177    SchCellCfg    cellCfg;                           /*!< Cell ocnfiguration */
178    uint8_t       ssbStartSymbArr[SCH_MAX_SSB_BEAM]; /*!<start symbol per SSB beam */
179    SchRaCb       raCb[MAX_NUM_UE];                  /*!< Rach Cb */
180    uint16_t      numActvUe;
181    uint32_t      actvUeBitMap;
182    uint32_t      boIndBitMap;
183    SchUeCb       ueCb[MAX_NUM_UE];
184 }SchCellCb;
185
186 /**
187  * @brief
188  * Control block for sch
189  */
190 typedef struct schCb
191 {
192    TskInit       schInit;              /*!< Task Init info */
193    SchGenCb      genCfg;                 /*!< General Config info */
194    SchCellCb     *cells[MAX_NUM_CELL];  /* Array to store cellCb ptr */  
195 }SchCb;
196
197 /* Declaration for scheduler control blocks */
198 SchCb schCb[SCH_MAX_INST];
199
200 /* function declarations */
201 uint8_t schBroadcastAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc,uint16_t slot);
202 uint8_t schProcessSlotInd(SlotIndInfo *slotInd, Inst inst);
203 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst);
204 uint8_t schDlRsrcAllocMsg4(DlMsgAlloc *msg4Alloc, SchCellCb *cell, uint16_t slot);
205 uint16_t schCalcTbSize(uint16_t payLoadSize);
206 uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols);
207 uint16_t schAllocPucchResource(SchCellCb *cell, uint16_t crnti, uint16_t slot);
208 uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst);
209 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo);
210 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo);
211 uint8_t schDlRsrcAllocDlMsg(DlMsgAlloc *dlMsgAlloc, SchCellCb *cell, uint16_t crnti,
212    uint16_t accumalatedSize, uint16_t slot);
213 uint16_t schAccumalateLcBoSize(SchCellCb *cell, uint16_t ueIdx);
214
215 /**********************************************************************
216   End of file
217  **********************************************************************/