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