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