UE CB creation at MAC and SCH [Issue-ID: ODUHIGH-177]
[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_CELLS 1
22 #define SCH_MAX_INST 1
23 #define SCH_NUM_SLOTS 10 /*forcing this to 10 */
24 #define SCH_MAX_SFN 1024
25 #define MAX_NUM_RB 106 /* value for numerology 0 15Khz */
26 #define SCH_MIB_TRANS 80 
27 #define SCH_NUM_SC_PRB 12 /* number of SCs in a PRB */
28 #define SCH_MAX_SSB_BEAM 4 /* since we are supporting only SCS=15KHz */
29 #define SCH_SCS_15KHZ 0 /* numerology 0 and 15Khz */
30 #define SCH_SYMBOL_PER_SLOT 14
31 #define SCH_SSB_NUM_SYMB 4
32 #define SCH_SSB_NUM_PRB 20
33 #define SCH_MEM_REGION     4
34 #define SCH_POOL           1
35 #define SCHED_DELTA 1
36 #define BO_DELTA 1
37 #define RAR_DELAY   2
38 #define MSG4_DELAY  1
39 #define SCH_MAX_UE  1
40 #define PUSCH_START_RB 15
41 #define PUCCH_NUM_PRB_FORMAT_0 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
48 #define CRC_FAILED 0
49 #define CRC_PASSED 1
50
51 /* allocate and zero out a static buffer */
52 #define SCH_ALLOC(_datPtr, _size)                               \
53 {                                                               \
54    S16 _ret;                                                    \
55    _ret = SGetSBuf(SCH_MEM_REGION, SCH_POOL,                    \
56          (Data **)&_datPtr, _size);                             \
57    if(_ret == ROK)                                              \
58    {                                                            \
59       cmMemset((U8*)_datPtr, 0, _size);                         \
60    }                                                            \
61    else                                                         \
62    {                                                            \
63       _datPtr = NULLP;                                          \
64    }                                                            \
65 }
66
67 /* free a static buffer */
68 #define SCH_FREE(_datPtr, _size)                                \
69 {                                                               \
70    if(_datPtr)                                                  \
71    {                                                            \
72       SPutSBuf(SCH_MEM_REGION, SCH_POOL,                        \
73             (Data *)_datPtr, _size);                            \
74    }                                                            \
75 }
76
77 #define SCH_FILL_RSP_PST(_rspPst, _inst)\
78 {                                  \
79    _rspPst.srcProcId = SFndProcId(); \
80    _rspPst.dstProcId = SFndProcId();\
81    _rspPst.srcEnt    = ENTRG;\
82    _rspPst.dstEnt    = ENTRG;\
83    _rspPst.srcInst   = 1;\
84    _rspPst.dstInst   = 0;\
85    _rspPst.selector  = ODU_SELECTOR_TC;\
86 }       
87 extern uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst);
88
89 typedef enum
90 {
91    SCH_UE_STATE_INACTIVE,
92    SCH_UE_STATE_ACTIVE
93 }SchUeState;
94
95 /**
96  * @brief
97  * Structure holding LTE MAC's General Configuration information.
98  */
99 typedef struct schGenCb
100 {
101    uint8_t         tmrRes;           /*!< Timer resolution */
102    uint8_t         startCellId;      /*!< Starting Cell Id */
103 #ifdef LTE_ADV
104    bool            forceCntrlSrbBoOnPCel; /*!< value 1 means force scheduling
105                                             of RLC control BO and SRB BO on
106                                             PCell. val 0 means don't force*/
107    bool            isSCellActDeactAlgoEnable; /*!< TRUE will enable activation/deactivation algo at Schd */
108 #endif
109 }SchGenCb;
110
111 /**
112  * @brief
113  * scheduler allocationsfor DL per cell.
114  */
115 typedef struct schDlSlotInfo
116 {
117    uint16_t  totalPrb;                          /*!< Number of RBs in the cell */
118    uint16_t  assignedPrb[SCH_SYMBOL_PER_SLOT];  /*!< Num RBs and corresponding symbols allocated */
119    bool      ssbPres;                           /*!< Flag to determine if SSB is present in this slot */
120    uint8_t   ssbIdxSupported;                   /*!< Max SSB index */
121    SsbInfo   ssbInfo[MAX_SSB_IDX];              /*!< SSB info */
122    bool      sib1Pres;                          /*!< Flag to determine if SIB1 is present in this slot */
123    RarInfo   *rarInfo;                          /*!< RAR info */
124    Msg4Info  *msg4Info;                         /*!< msg4 info */
125 }SchDlSlotInfo;
126
127 typedef struct schRaCb
128 {
129    uint16_t tcrnti;
130 }SchRaCb;
131
132 /**
133  * @brief
134  * scheduler allocationsfor UL per cell.
135  */
136 typedef struct schUlSlotInfo
137 {
138    uint16_t     totalPrb;  /*!< Number of RBs in the cell */
139    uint16_t     assignedPrb[SCH_SYMBOL_PER_SLOT]; /*!< Num RBs and corresponding symbols allocated */
140    bool         puschPres; /*!< PUSCH presence field */
141    SchPuschInfo *schPuschInfo; /*!< PUSCH info */
142    bool         pucchPres; /*!< PUCCH presence field */
143    SchPucchInfo schPucchInfo; /*!< PUCCH info */
144 }SchUlSlotInfo;
145
146 /**
147  * @brief
148  * UE control block
149  */
150 typedef struct schUeCb
151 {
152    uint16_t  ueIdx;
153    uint16_t  crnti;
154    SchUeCfg  ueCfg;
155    SchUeState  state;
156 }SchUeCb;
157
158 /**
159  * @brief
160  * Cell Control block per cell.
161  */
162 typedef struct schCellCb
163 {
164    uint16_t      cellId;                            /*!< Cell ID */
165    Inst          instIdx;                           /*!< Index of the scheduler instance */
166    Inst          macInst;                           /*!< Index of the MAC instance */
167    uint8_t       numSlots;                          /*!< Number of slots in current frame */
168    SlotIndInfo   slotInfo;                          /*!< SFN, Slot info being processed*/
169    SchDlSlotInfo *schDlSlotInfo[SCH_NUM_SLOTS];     /*!< SCH resource allocations in DL */
170    SchUlSlotInfo *schUlSlotInfo[SCH_NUM_SLOTS];     /*!< SCH resource allocations in UL */
171    SchCellCfg    cellCfg;                           /*!< Cell ocnfiguration */
172    uint8_t       ssbStartSymbArr[SCH_MAX_SSB_BEAM]; /*!<start symbol per SSB beam */
173    SchRaCb       raCb[SCH_MAX_UE];                  /*!< Rach Cb */
174    uint16_t      numActvUe;
175    SchUeCb       ueCb[SCH_MAX_UE];
176 }SchCellCb;
177
178 /**
179  * @brief
180  * Control block for sch
181  */
182 typedef struct schCb
183 {
184    TskInit       schInit;              /*!< Task Init info */
185    SchGenCb      genCfg;                 /*!< General Config info */
186    SchCellCb     *cells[SCH_MAX_CELLS];  /* Array to store cellCb ptr */  
187 }SchCb;
188
189 /* Declaration for scheduler control blocks */
190 SchCb schCb[SCH_MAX_INST];
191
192 /* function declarations */
193 uint8_t schBroadcastAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc,uint16_t slot);
194 uint8_t schProcessSlotInd(SlotIndInfo *slotInd, Inst inst);
195 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst);
196 uint8_t schDlRsrcAllocMsg4(Msg4Alloc *msg4Alloc, SchCellCb *cell, uint16_t slot);
197 uint16_t schCalcTbSize(uint16_t payLoadSize);
198 uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols);
199 uint16_t schAllocPucchResource(SchCellCb *cell, uint16_t crnti, uint16_t slot);
200 /**********************************************************************
201   End of file
202  **********************************************************************/