Merge "Deleted the rlog folder"
[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 MAX_NUM_RB 106 /* value for numerology 0 15Khz */
29 #define SCH_MIB_TRANS 8  /* MIB transmission as per 38.331 is every 80 ms */
30 #define SCH_SIB1_TRANS 16 /* SIB1 transmission as per 38.331 is every 160 ms */
31 #define SCH_NUM_SC_PRB 12 /* number of SCs in a PRB */
32 #define SCH_MAX_SSB_BEAM 8 /* since we are supporting only SCS=15KHz and 30KHz */
33 #define SCH_SYMBOL_PER_SLOT 14
34 #define SCH_SSB_NUM_SYMB 4
35 #define SCH_SSB_NUM_PRB 20
36 #define SCHED_DELTA 1
37 #define BO_DELTA 1
38 #define RAR_DELAY   2
39 #define MSG4_DELAY  1
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 12
46 #define DMRS_ADDITIONAL_POS 2
47 #define SCH_DEFAULT_K1 1
48 #define SCH_TQ_SIZE 10
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 typedef struct schCellCb SchCellCb;
57 typedef struct schUeCb SchUeCb;
58
59 typedef enum
60 {
61    SCH_NUMEROLOGY_0,
62    SCH_NUMEROLOGY_1,
63    SCH_NUMEROLOGY_2,
64    SCH_NUMEROLOGY_3,
65    SCH_NUMEROLOGY_4
66 }SchNumerology;
67
68 typedef enum
69 {
70    SCH_UE_STATE_INACTIVE,
71    SCH_UE_STATE_ACTIVE
72 }SchUeState;
73
74 typedef enum
75 {
76    SCH_LC_STATE_INACTIVE,
77    SCH_LC_STATE_ACTIVE
78 }SchLcState;
79
80 /**
81  * @brief
82  * Structure holding LTE MAC's General Configuration information.
83  */
84 typedef struct schGenCb
85 {
86    uint8_t         tmrRes;           /*!< Timer resolution */
87    uint8_t         startCellId;      /*!< Starting Cell Id */
88 #ifdef LTE_ADV
89    bool            forceCntrlSrbBoOnPCel; /*!< value 1 means force scheduling
90                                             of RLC control BO and SRB BO on
91                                             PCell. val 0 means don't force*/
92    bool            isSCellActDeactAlgoEnable; /*!< TRUE will enable activation/deactivation algo at Schd */
93 #endif
94 }SchGenCb;
95
96 /**
97  * @brief
98  * scheduler allocationsfor DL per cell.
99  */
100 typedef struct schDlSlotInfo
101 {
102    uint16_t  totalPrb;                          /*!< Number of RBs in the cell */
103    uint16_t  assignedPrb[SCH_SYMBOL_PER_SLOT];  /*!< Num RBs and corresponding symbols allocated */
104    uint16_t  resAllocBitMap;                    /*!< Resource allocation bitmap */
105    bool      ssbPres;                           /*!< Flag to determine if SSB is present in this slot */
106    uint8_t   ssbIdxSupported;                   /*!< Max SSB index */
107    SsbInfo   ssbInfo[MAX_SSB_IDX];              /*!< SSB info */
108    bool      sib1Pres;                          /*!< Flag to determine if SIB1 is present in this slot */
109    RarInfo   *rarInfo;                          /*!< RAR info */
110    DlMsgInfo *dlMsgInfo;                       /*!< DL dedicated Msg info */
111 }SchDlSlotInfo;
112
113 typedef struct schRaCb
114 {
115    uint16_t tcrnti;
116 }SchRaCb;
117
118 /**
119  * @brief
120  * scheduler allocationsfor UL per cell.
121  */
122 typedef struct schUlSlotInfo
123 {
124    uint16_t     totalPrb;  /*!< Number of RBs in the cell */
125    uint16_t     assignedPrb[SCH_SYMBOL_PER_SLOT]; /*!< Num RBs and corresponding symbols allocated */
126    uint16_t     resAllocBitMap;                    /*!< Resource allocation bitmap */
127    uint8_t      puschCurrentPrb; /* Current PRB for PUSCH allocation */
128    bool         puschPres; /*!< PUSCH presence field */
129    SchPuschInfo *schPuschInfo; /*!< PUSCH info */
130    bool         pucchPres; /*!< PUCCH presence field */
131    SchPucchInfo schPucchInfo; /*!< PUCCH info */
132 }SchUlSlotInfo;
133
134 /**
135 @brief
136 * BSR info per slot per UE.
137 */
138 typedef struct bsrInfo
139 {
140    uint8_t    priority;  /* CG priority */
141    uint32_t   dataVol;   /* Data volume requested in bytes */
142 }BsrInfo;
143
144 typedef struct schLcCtxt
145 {
146    uint8_t lcId;     // logical Channel ID
147    uint8_t lcp;      // logical Channel Prioritization
148    SchLcState lcState;
149    uint32_t bo;
150 }SchDlLcCtxt;
151
152 typedef struct schDlCb
153 {
154    uint8_t       numDlLc;
155    SchDlLcCtxt   dlLcCtxt[MAX_NUM_LC];
156 }SchDlCb;
157
158 typedef struct schUlLcCtxt
159 {
160    SchLcState  lcState;
161    uint8_t lcId;       
162    uint8_t priority;
163    uint8_t lcGroup;
164    uint8_t schReqId;
165    uint8_t pbr;        // prioritisedBitRate
166    uint8_t bsd;        // bucketSizeDuration
167 }SchUlLcCtxt;
168
169 typedef struct schUlCb
170 {
171    uint8_t     numUlLc;
172    SchUlLcCtxt ulLcCtxt[MAX_NUM_LC];
173 }SchUlCb;
174
175 typedef struct schUeCfgCb
176 {
177    uint16_t        cellId;
178    uint16_t        crnti;
179    bool macCellGrpCfgPres;
180    SchMacCellGrpCfg   macCellGrpCfg;
181    bool phyCellGrpCfgPres;
182    SchPhyCellGrpCfg   phyCellGrpCfg;
183    bool spCellCfgPres;
184    SchSpCellCfg       spCellCfg;
185    SchAmbrCfg         *ambrCfg;
186    SchModulationInfo  dlModInfo;
187    SchModulationInfo  ulModInfo;
188 }SchUeCfgCb;
189
190 /**
191  * @brief
192  * UE control block
193  */
194 typedef struct schUeCb
195 {
196    uint16_t   ueIdx;
197    uint16_t   crnti;
198    SchUeCfgCb ueCfg;
199    SchUeState state;
200    SchCellCb  *cellCb;
201    bool       srRcvd;
202    BsrInfo    bsrInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS];
203    SchUlCb    ulInfo;
204    SchDlCb    dlInfo;
205 }SchUeCb;
206
207 /**
208  * @brief
209  * Cell Control block per cell.
210  */
211 typedef struct schCellCb
212 {
213    uint16_t      cellId;                            /*!< Cell ID */
214    Inst          instIdx;                           /*!< Index of the scheduler instance */
215    Inst          macInst;                           /*!< Index of the MAC instance */
216    uint8_t       numSlots;                          /*!< Number of slots in current frame */
217    SlotIndInfo   slotInfo;                          /*!< SFN, Slot info being processed*/
218    SchDlSlotInfo **schDlSlotInfo;                   /*!< SCH resource allocations in DL */
219    SchUlSlotInfo **schUlSlotInfo;                   /*!< SCH resource allocations in UL */
220    SchCellCfg    cellCfg;                           /*!< Cell ocnfiguration */
221    bool          firstSsbTransmitted;
222    bool          firstSib1Transmitted;
223    uint8_t       ssbStartSymbArr[SCH_MAX_SSB_BEAM]; /*!<start symbol per SSB beam */
224    SchRaCb       raCb[MAX_NUM_UE];                  /*!< Rach Cb */
225    uint16_t      numActvUe;                         /*!<Number of active UEs */
226    uint32_t      actvUeBitMap;                      /*!<Bit map to find active UEs */
227    uint32_t      boIndBitMap;                       /*!<Bit map to indicate UEs that have recevied BO */
228    SchUeCb       ueCb[MAX_NUM_UE];                  /*!<Pointer to UE contexts of this cell */
229 #ifdef NR_TDD
230    uint8_t       numSlotsInPeriodicity;             /*!< number of slots in configured periodicity and SCS */
231    uint32_t      slotFrmtBitMap;                    /*!< 2 bits must be read together to determine D/U/S slots. 00-D, 01-U, 10-S */
232    uint32_t      symbFrmtBitMap;                    /*!< 2 bits must be read together to determine D/U/S symbols. 00-D, 01-U, 10-S */
233 #endif
234 }SchCellCb;
235
236 /**
237  * @brief
238  * Control block for sch
239  */
240 typedef struct schCb
241 {
242    TskInit       schInit;               /*!< Task Init info */
243    SchGenCb      genCfg;                /*!< General Config info */
244    CmTqCp        tmrTqCp;               /*!< Timer Task Queue Cntrl Point */
245    CmTqType      tmrTq[SCH_TQ_SIZE];    /*!< Timer Task Queue */
246    SchCellCb     *cells[MAX_NUM_CELL];  /* Array to store cellCb ptr */  
247 }SchCb;
248
249 /* Declaration for scheduler control blocks */
250 SchCb schCb[SCH_MAX_INST];
251
252 /* function declarations */
253 short int schActvTmr(Ent ent,Inst inst);
254 uint8_t schBroadcastAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc,uint16_t slot);
255 uint8_t schProcessSlotInd(SlotIndInfo *slotInd, Inst inst);
256 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst);
257 uint8_t schDlRsrcAllocMsg4(DlMsgAlloc *msg4Alloc, SchCellCb *cell, uint16_t slot);
258 uint16_t schCalcTbSize(uint32_t payLoadSize);
259 uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols);
260 uint16_t schAllocPucchResource(SchCellCb *cell, uint16_t crnti, uint16_t slot);
261 uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst);
262 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo);
263 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo);
264 uint8_t schDlRsrcAllocDlMsg(DlMsgAlloc *dlMsgAlloc, SchCellCb *cell, uint16_t crnti,
265    uint32_t *accumalatedSize, uint16_t slot);
266 uint16_t schAccumalateLcBoSize(SchCellCb *cell, uint16_t ueIdx);
267
268 /**********************************************************************
269   End of file
270  **********************************************************************/