MAC Clean-up [Issue-ID: ODUHIGH-212]
[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 extern uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst);
48
49 typedef enum
50 {
51    SCH_UE_STATE_INACTIVE,
52    SCH_UE_STATE_ACTIVE
53 }SchUeState;
54
55 /**
56  * @brief
57  * Structure holding LTE MAC's General Configuration information.
58  */
59 typedef struct schGenCb
60 {
61    uint8_t         tmrRes;           /*!< Timer resolution */
62    uint8_t         startCellId;      /*!< Starting Cell Id */
63 #ifdef LTE_ADV
64    bool            forceCntrlSrbBoOnPCel; /*!< value 1 means force scheduling
65                                             of RLC control BO and SRB BO on
66                                             PCell. val 0 means don't force*/
67    bool            isSCellActDeactAlgoEnable; /*!< TRUE will enable activation/deactivation algo at Schd */
68 #endif
69 }SchGenCb;
70
71 /**
72  * @brief
73  * scheduler allocationsfor DL per cell.
74  */
75 typedef struct schDlSlotInfo
76 {
77    uint16_t  totalPrb;                          /*!< Number of RBs in the cell */
78    uint16_t  assignedPrb[SCH_SYMBOL_PER_SLOT];  /*!< Num RBs and corresponding symbols allocated */
79    bool      ssbPres;                           /*!< Flag to determine if SSB is present in this slot */
80    uint8_t   ssbIdxSupported;                   /*!< Max SSB index */
81    SsbInfo   ssbInfo[MAX_SSB_IDX];              /*!< SSB info */
82    bool      sib1Pres;                          /*!< Flag to determine if SIB1 is present in this slot */
83    RarInfo   *rarInfo;                          /*!< RAR info */
84    Msg4Info  *msg4Info;                         /*!< msg4 info */
85 }SchDlSlotInfo;
86
87 typedef struct schRaCb
88 {
89    uint16_t tcrnti;
90 }SchRaCb;
91
92 /**
93  * @brief
94  * scheduler allocationsfor UL per cell.
95  */
96 typedef struct schUlSlotInfo
97 {
98    uint16_t     totalPrb;  /*!< Number of RBs in the cell */
99    uint16_t     assignedPrb[SCH_SYMBOL_PER_SLOT]; /*!< Num RBs and corresponding symbols allocated */
100    bool         puschPres; /*!< PUSCH presence field */
101    SchPuschInfo *schPuschInfo; /*!< PUSCH info */
102    bool         pucchPres; /*!< PUCCH presence field */
103    SchPucchInfo schPucchInfo; /*!< PUCCH info */
104 }SchUlSlotInfo;
105
106 /**
107  * @brief
108  * UE control block
109  */
110 typedef struct schUeCb
111 {
112    uint16_t  ueIdx;
113    uint16_t  crnti;
114    SchUeCfg  ueCfg;
115    SchUeState  state;
116 }SchUeCb;
117
118 /**
119  * @brief
120  * Cell Control block per cell.
121  */
122 typedef struct schCellCb
123 {
124    uint16_t      cellId;                            /*!< Cell ID */
125    Inst          instIdx;                           /*!< Index of the scheduler instance */
126    Inst          macInst;                           /*!< Index of the MAC instance */
127    uint8_t       numSlots;                          /*!< Number of slots in current frame */
128    SlotIndInfo   slotInfo;                          /*!< SFN, Slot info being processed*/
129    SchDlSlotInfo *schDlSlotInfo[SCH_NUM_SLOTS];     /*!< SCH resource allocations in DL */
130    SchUlSlotInfo *schUlSlotInfo[SCH_NUM_SLOTS];     /*!< SCH resource allocations in UL */
131    SchCellCfg    cellCfg;                           /*!< Cell ocnfiguration */
132    uint8_t       ssbStartSymbArr[SCH_MAX_SSB_BEAM]; /*!<start symbol per SSB beam */
133    SchRaCb       raCb[MAX_NUM_UE];                  /*!< Rach Cb */
134    uint16_t      numActvUe;
135    SchUeCb       ueCb[MAX_NUM_UE];
136 }SchCellCb;
137
138 /**
139  * @brief
140  * Control block for sch
141  */
142 typedef struct schCb
143 {
144    TskInit       schInit;              /*!< Task Init info */
145    SchGenCb      genCfg;                 /*!< General Config info */
146    SchCellCb     *cells[MAX_NUM_CELL];  /* Array to store cellCb ptr */  
147 }SchCb;
148
149 /* Declaration for scheduler control blocks */
150 SchCb schCb[SCH_MAX_INST];
151
152 /* function declarations */
153 uint8_t schBroadcastAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc,uint16_t slot);
154 uint8_t schProcessSlotInd(SlotIndInfo *slotInd, Inst inst);
155 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst);
156 uint8_t schDlRsrcAllocMsg4(Msg4Alloc *msg4Alloc, SchCellCb *cell, uint16_t slot);
157 uint16_t schCalcTbSize(uint16_t payLoadSize);
158 uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols);
159 uint16_t schAllocPucchResource(SchCellCb *cell, uint16_t crnti, uint16_t slot);
160 /**********************************************************************
161   End of file
162  **********************************************************************/