[Jira Id - ODUHIGH-373 ] Implementation of RRM Policy Configuration Per Slice
[o-du/l2.git] / src / cm / common_def.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 #ifndef __COMMON_DEF_H__
19 #define __COMMON_DEF_H__
20
21 #include <stdio.h>
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27
28 #include "cm_mem.h"
29 #include "envopt.h"
30 #include "envdep.h"
31 #include "envind.h"
32 #include "gen.h" 
33 #include "ssi.h" 
34 #include "cm_math.h"
35 #include "cm5.h"
36 #include "cm_tkns.h"
37 #include "cm_mblk.h"
38 #include "cm_llist.h"
39 #include "cm_hash.h"
40 #include "cm_lte.h"
41 #include "cm_err.h"
42 #include "cm_tpt.h"
43 #include "cm.h"
44 #include "gen.x"           /* general */
45 #include "ssi.x"           /* system services */
46 #include "cm_tpt.x"
47 #include "cm_tkns.x" 
48 #include "cm_mblk.x"
49 #include "cm_llist.x"
50 #include "cm5.x" 
51 #include "cm_hash.x"
52 #include "cm_lte.x"
53 #include "cm_lib.x"
54 #include "du_log.h"
55
56 #define RADIO_FRAME_DURATION 10 /* Time duration of a radio frame in ms */
57 /* MAX values */
58 #define MAX_NUM_CELL 1
59 #define MAX_NUM_MU   4
60 #define MAX_NUM_UE   2
61 #define MAX_NUM_UE_PER_TTI 1
62 #define MAX_NUM_LC   32   /*Spec 38.331: Sec 6.4: maxLC-ID Keyword*/
63 #define MAX_NUM_SRB  3    /* Max. no of Srbs */
64 #define MAX_NUM_DRB  29   /* spec 38.331, maxDRB */
65
66 /* 5G ORAN phy delay */
67 #define PHY_DELTA_DL 1
68 #define PHY_DELTA_UL 0
69
70  /* SELECTORS */ 
71 #define ODU_SELECTOR_LC 0
72 #define ODU_SELECTOR_TC 1
73 #define ODU_SELECTOR_LWLC 2
74
75 #define ODU_START_CRNTI   100
76 #define ODU_END_CRNTI     500
77
78 /* LCID */
79 #define SRB0_LCID  0
80 #define SRB1_LCID  1
81 #define SRB2_LCID  2
82 #define SRB3_LCID  3
83 #define MIN_DRB_LCID 4
84 #define MAX_DRB_LCID 32
85
86 #define FREQ_DOM_RSRC_SIZE  6      /* i.e. 6 bytes because Size of frequency domain resource is 45 bits */
87 #define PUCCH_FORMAT_0 0
88 #define PUCCH_FORMAT_1 1
89 #define PUCCH_FORMAT_2 2
90 #define PUCCH_FORMAT_3 3 
91 #define PUCCH_FORMAT_4 4
92
93 #define BANDWIDTH_20MHZ 20
94 #define BANDWIDTH_100MHZ 100
95
96 /* PRB allocation as per 38.101, Section 5.3.2 */
97 #define TOTAL_PRB_20MHZ_MU0 106
98 #define TOTAL_PRB_100MHZ_MU1 273
99
100 #define ODU_THROUGHPUT_PRINT_TIME_INTERVAL  5 /* in milliseconds */
101
102 /* Defining macros for common utility functions */
103 #define ODU_GET_MSG_BUF SGetMsg
104 #define ODU_PUT_MSG_BUF SPutMsg
105 #define ODU_ADD_PRE_MSG_MULT SAddPreMsgMult
106 #define ODU_ADD_PRE_MSG_MULT_IN_ORDER SAddPreMsgMultInOrder
107 #define ODU_ADD_POST_MSG_MULT SAddPstMsgMult
108 #define ODU_START_TASK SStartTask
109 #define ODU_STOP_TASK SStopTask
110 #define ODU_ATTACH_TTSK SAttachTTsk
111 #define ODU_POST_TASK SPstTsk
112 #define ODU_COPY_MSG_TO_FIX_BUF SCpyMsgFix
113 #define ODU_COPY_FIX_BUF_TO_MSG SCpyFixMsg
114 #define ODU_REG_TTSK SRegTTsk
115 #define ODU_SET_PROC_ID SSetProcId
116 #define ODU_GET_MSG_LEN SFndLenMsg
117 #define ODU_EXIT_TASK SExitTsk
118 #define ODU_PRINT_MSG SPrntMsg
119 #define ODU_REM_PRE_MSG SRemPreMsg
120 #define ODU_REM_PRE_MSG_MULT SRemPreMsgMult
121 #define ODU_REG_TMR_MT SRegTmrMt
122 #define ODU_SEGMENT_MSG SSegMsg
123 #define ODU_CAT_MSG SCatMsg
124 #define ODU_GET_PROCID SFndProcId
125 #define ODU_SET_THREAD_AFFINITY SSetAffinity
126 #define ODU_CREATE_TASK SCreateSTsk
127
128 /* Slice */
129 #define SD_SIZE 3
130
131 #ifdef NR_TDD
132 /* Maximum slots for max periodicity and highest numerology is 320.
133  * However, aligning to fapi_interface.h, setting this macro to 160 */
134 #define MAX_TDD_PERIODICITY_SLOTS 160 
135 #define MAX_SYMB_PER_SLOT 14 
136 #endif
137
138 #define GET_UE_IDX( _crnti,_ueIdx)         \
139 {                                          \
140    _ueIdx = _crnti - ODU_START_CRNTI + 1;  \
141 }
142
143 #define GET_CRNTI( _crnti,_ueIdx)          \
144 {                                          \
145    _crnti = _ueIdx + ODU_START_CRNTI - 1;  \
146 }
147
148 /* Calculates cellIdx from cellId */
149 #define GET_CELL_IDX(_cellId, _cellIdx)   \
150 {                                         \
151    _cellIdx = _cellId - 1;                \
152 }
153
154 #define SET_BITS_MSB(_startBit, _numBits, _byte) \
155 {                                                \
156    _byte = (~((0xFF) >> _numBits));              \
157        _byte >>= _startBit;                          \
158 }
159
160 #define SET_BITS_LSB(_startBit, _numBits, _byte) \
161 {                                                \
162    _byte = (~((0xFF) << _numBits));              \
163        _byte <<= _startBit;                          \
164 }
165
166 /* this MACRO set 1 bit at the bit position */
167 #define SET_ONE_BIT(_bitPos, _out)            \
168 {                                             \
169    _out = ((1<<_bitPos) | _out);              \
170 }
171
172 /* this MACRO un-set 1 bit at the bit position */
173 #define UNSET_ONE_BIT(_bitPos, _out)            \
174 {                                               \
175    _out = (~(1<<_bitPos) & _out);               \
176 }
177
178 /* this MACRO finds the index of the rightmost set bit */
179 #define GET_RIGHT_MOST_SET_BIT( _in,_bitPos)        \
180 {                                                \
181    _bitPos = __builtin_ctz(_in);                 \
182 }
183
184 /* MACRO for checking CRNTI range*/
185 #define CHECK_CRNTI(_crnti, _isCrntiValid)                                         \
186 {                                                                   \
187   _isCrntiValid = ((_crnti >= ODU_START_CRNTI && _crnti <= ODU_END_CRNTI ) ? 1 : 0); \
188 }
189
190 typedef enum
191 {
192    UE_CFG_INACTIVE,
193    UE_CFG_INPROGRESS,
194    UE_CREATE_COMPLETE,
195    UE_DELETE_COMPLETE,
196    UE_RECFG_COMPLETE
197 }UeCfgState;
198
199 typedef enum
200 {
201    CONFIG_UNKNOWN,
202    CONFIG_ADD,
203    CONFIG_MOD,
204    CONFIG_DEL
205 }ConfigType;
206
207 #ifdef NR_TDD
208 typedef enum
209 {
210    DL_SLOT,
211    UL_SLOT,
212    FLEXI_SLOT
213 }SlotConfig;
214
215 typedef enum
216 {
217    TX_PRDCTY_MS_0P5,
218    TX_PRDCTY_MS_0P625,
219    TX_PRDCTY_MS_1,
220    TX_PRDCTY_MS_1P25,
221    TX_PRDCTY_MS_2,
222    TX_PRDCTY_MS_2P5,
223    TX_PRDCTY_MS_5,
224    TX_PRDCTY_MS_10
225 }DlUlTxPeriodicity;
226 #endif
227
228 typedef enum
229 {
230    SCS_15KHZ,
231    SCS_30KHZ,
232    SCS_60KHZ,
233    SCS_120KHZ,
234    SCS_240KHZ
235 }SCS;
236
237 typedef enum
238 {
239    CELL_UP,
240    CELL_DOWN
241 }OduCellStatus;
242
243 typedef struct slotTimingInfo
244 {
245    uint16_t cellId;
246    uint16_t sfn;
247    uint16_t slot;
248 }SlotTimingInfo;
249
250 typedef struct PlmnIdentity
251 {
252    uint8_t mcc[3];
253    uint8_t mnc[3];
254 }Plmn;
255
256 typedef struct snssai
257 {
258    uint8_t   sst;
259    uint8_t   sd[SD_SIZE];
260 }Snssai;
261
262 typedef struct oduCellId
263 {
264    uint16_t cellId;
265 }OduCellId;
266
267 #ifdef NR_TDD
268 typedef struct tddCfg
269 {
270    bool               pres;
271    DlUlTxPeriodicity  tddPeriod;      /* DL UL Transmission periodicity */
272    SlotConfig         slotCfg[MAX_TDD_PERIODICITY_SLOTS][MAX_SYMB_PER_SLOT]; 
273 }TDDCfg;
274 #endif
275
276 OduCellStatus gCellStatus;
277 uint64_t gSlotCount;
278 uint64_t gDlDataRcvdCnt;   /* Number of DL data received at EGTP */
279
280 void freqDomRscAllocType0(uint16_t startPrb, uint16_t prbSize, uint8_t *freqDomain);
281 void oduCpyFixBufToMsg(uint8_t *fixBuf, Buffer *mBuf, uint16_t len);
282 uint8_t buildPlmnId(Plmn plmn, uint8_t *buf);
283
284 uint8_t SGetSBufNewForDebug(char *file, char *func, char *line, Region region, Pool pool, Data **ptr, Size size);
285 uint8_t SPutSBufNewForDebug(char *file, char *func, char *line, Region region, Pool pool, Data *ptr, Size size);
286 uint8_t SGetStaticBufNewForDebug(char *file, char *func, char *line, \
287 Region region, Pool pool, Data **ptr, Size size, uint8_t memType);
288 uint8_t SPutStaticBufNewForDebug(char *file, char *func, char *line, \
289 Region region, Pool pool, Data *ptr, Size size, uint8_t memType);
290
291 #endif
292
293 /**********************************************************************
294   End of file
295 ***********************************************************************/