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