9e7bef4cb79f70c030a2bb28986ffe6a2467e9b1
[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 SCH_INST_START 1
57 #define SCH_MAX_INST 1
58
59 #define RADIO_FRAME_DURATION 10 /* Time duration of a radio frame in ms */
60 /* MAX values */
61 #define MAX_NUM_CELL 2 /* Changed to 2 to support cell Id 2 even if there is only one cell in DU */
62 #define MAX_NUM_MU   4
63 #define MAX_NUM_UE   3
64 #define MAX_NUM_UE_PER_TTI 1
65 #define MAX_NUM_LC   MAX_DRB_LCID + 1   /*Spec 38.331: Sec 6.4: maxLC-ID Keyword*/
66 #define MAX_NUM_SRB  3    /* Max. no of Srbs */
67 #define MAX_NUM_DRB  29   /* spec 38.331, maxDRB */
68 #define MAX_NUM_SSB  64   /* spec 28.331, maxNrofSSBs */
69 #define MAX_NUM_HARQ_PROC 16 /* spec 38.331, nrofHARQ-ProcessesForPDSCH */
70 #define MAX_NUM_TB_PER_UE 2  /* spec 38.331, maxNrofCodeWordsScheduledByDCI */
71
72 /* 5G ORAN phy delay */
73 #ifdef NR_TDD
74 #define PHY_DELTA_DL 2
75 #define PHY_DELTA_UL 0
76 #else
77 #define PHY_DELTA_DL 1
78 #define PHY_DELTA_UL 0
79 #endif
80
81  /* SELECTORS */ 
82 #define ODU_SELECTOR_LC 0
83 #define ODU_SELECTOR_TC 1
84 #define ODU_SELECTOR_LWLC 2
85
86 #define ODU_START_CRNTI   100
87 #define ODU_END_CRNTI     500
88
89 /* LCID */
90 #define SRB0_LCID  0
91 #define SRB1_LCID  1
92 #define SRB2_LCID  2
93 #define SRB3_LCID  3
94 #define MIN_DRB_LCID 4
95 #define MAX_DRB_LCID 32
96
97 #define FREQ_DOM_RSRC_SIZE  6      /* i.e. 6 bytes because Size of frequency domain resource is 45 bits */
98 #define PUCCH_FORMAT_0 0
99 #define PUCCH_FORMAT_1 1
100 #define PUCCH_FORMAT_2 2
101 #define PUCCH_FORMAT_3 3 
102 #define PUCCH_FORMAT_4 4
103
104 #define DEFAULT_MCS 4
105
106 #define BANDWIDTH_20MHZ 20
107 #define BANDWIDTH_100MHZ 100
108
109 /* PRB allocation as per 38.101, Section 5.3.2 */
110 #define TOTAL_PRB_20MHZ_MU0 106
111 #define TOTAL_PRB_100MHZ_MU1 273
112 #ifdef NR_TDD
113 #define MAX_NUM_RB TOTAL_PRB_100MHZ_MU1  /* value for numerology 1, 100 MHz */
114 #else
115 #define MAX_NUM_RB TOTAL_PRB_20MHZ_MU0 /* value for numerology 0, 20 MHz */
116 #endif
117
118 #define ODU_UE_THROUGHPUT_PRINT_TIME_INTERVAL      5     /* in milliseconds */
119 #define ODU_SNSSAI_THROUGHPUT_PRINT_TIME_INTERVAL  60000 /* in milliseconds */
120
121 /*Spec 38.331 Sec 6.4: Maximum number of paging occasion per paging frame*/
122 #define MAX_PO_PER_PF 4
123
124 #ifdef NR_TDD
125 #define MAX_SLOTS 20
126 #else
127 #define MAX_SLOTS 10
128 #endif
129
130 #define MAX_SFN   1024
131
132 /*First SCS in kHz as per 3gpp spec 38.211 Table 4.2-1 */
133 #define BASE_SCS 15
134
135 #define MAX_NUM_STATS_CFG 2 /* Max number of statistics configuration/Subscription supported */
136 #define MAX_NUM_STATS_GRP 5 /* Max number of statistics group per configuration request */
137 #define MAX_NUM_STATS 10    /* Max number of statistics per group */
138
139 /* Defining macros for common utility functions */
140 #define ODU_GET_MSG_BUF SGetMsg
141 #define ODU_PUT_MSG_BUF SPutMsg
142 #define ODU_ADD_PRE_MSG_MULT SAddPreMsgMult
143 #define ODU_ADD_PRE_MSG_MULT_IN_ORDER SAddPreMsgMultInOrder
144 #define ODU_ADD_POST_MSG_MULT SAddPstMsgMult
145 #define ODU_START_TASK SStartTask
146 #define ODU_STOP_TASK SStopTask
147 #define ODU_ATTACH_TTSK SAttachTTsk
148 #define ODU_POST_TASK SPstTsk
149 #define ODU_COPY_MSG_TO_FIX_BUF SCpyMsgFix
150 #define ODU_COPY_FIX_BUF_TO_MSG SCpyFixMsg
151 #define ODU_REG_TTSK SRegTTsk
152 #define ODU_SET_PROC_ID SSetProcId
153 #define ODU_GET_MSG_LEN SFndLenMsg
154 #define ODU_EXIT_TASK SExitTsk
155 #define ODU_PRINT_MSG SPrntMsg
156 #define ODU_REM_PRE_MSG SRemPreMsg
157 #define ODU_REM_PRE_MSG_MULT SRemPreMsgMult
158 #define ODU_REM_POST_MSG_MULT SRemPstMsgMult
159 #define ODU_REG_TMR_MT SRegTmrMt
160 #define ODU_SEGMENT_MSG SSegMsg
161 #define ODU_CAT_MSG SCatMsg
162 #define ODU_GET_PROCID SFndProcId
163 #define ODU_SET_THREAD_AFFINITY SSetAffinity
164 #define ODU_CREATE_TASK SCreateSTsk
165
166 #define MAX_SYMB_PER_SLOT 14 
167
168 /* Slice */
169 #define SD_SIZE 3
170
171 #ifdef NR_TDD
172 /* Maximum slots for max periodicity and highest numerology is 320.
173  * However, aligning to fapi_interface.h, setting this macro to 160.
174  * TODO : To support 160, FAPI_MAX_NUM_TLVS_CONFIG in fapi_interface.h
175  * of Intel L1 must be incremented to a higher number */
176 #define MAX_TDD_PERIODICITY_SLOTS 10 
177 #endif
178
179 #define GET_UE_ID( _crnti,_ueId)           \
180 {                                          \
181    _ueId = _crnti - ODU_START_CRNTI + 1;  \
182 }
183
184 #define GET_CRNTI( _crnti, _ueId)          \
185 {                                          \
186    _crnti = _ueId + ODU_START_CRNTI - 1;  \
187 }
188
189 /* Calculates cellIdx from cellId */
190 #define GET_CELL_IDX(_cellId, _cellIdx)   \
191 {                                         \
192    _cellIdx = _cellId - 1;                \
193 }
194
195 #define SET_BITS_MSB(_startBit, _numBits, _byte) \
196 {                                                \
197    _byte = (~((0xFF) >> _numBits));              \
198        _byte >>= _startBit;                          \
199 }
200
201 #define SET_BITS_LSB(_startBit, _numBits, _byte) \
202 {                                                \
203    _byte = (~((0xFF) << _numBits));              \
204        _byte <<= _startBit;                          \
205 }
206
207 /* this MACRO set 1 bit at the bit position */
208 #define SET_ONE_BIT(_bitPos, _out)            \
209 {                                             \
210    _out = ((1<<_bitPos) | _out);              \
211 }
212
213 /* this MACRO un-set 1 bit at the bit position */
214 #define UNSET_ONE_BIT(_bitPos, _out)            \
215 {                                               \
216    _out = (~(1<<_bitPos) & _out);               \
217 }
218
219 /* this MACRO finds the index of the rightmost set bit */
220 #define GET_RIGHT_MOST_SET_BIT( _in,_bitPos)        \
221 {                                                \
222    _bitPos = __builtin_ctz(_in);                 \
223 }
224
225 /* MACRO for checking CRNTI range*/
226 #define CHECK_CRNTI(_crnti, _isCrntiValid)                                         \
227 {                                                                   \
228   _isCrntiValid = ((_crnti >= ODU_START_CRNTI && _crnti <= ODU_END_CRNTI ) ? 1 : 0); \
229 }
230
231 #define CHECK_LCID(_lcId, _isLcidValid)      \
232 {\
233    _isLcidValid = ((_lcId >= SRB0_LCID && _lcId <= MAX_DRB_LCID) ? 1 : 0);\
234 }
235
236 /**
237  * @def TMR_CALCUATE_WAIT
238  *
239  *    This macro calculates and assigns wait time based on the value of the
240  *    timer and the timer resolution. Timer value of 0 signifies that the
241  *    timer is not configured
242  *
243  * @param[out] _wait   Time for which to arm the timer changed to proper
244  *                     value according to the resolution
245  * @param[in] _tmrVal   Value of the timer
246  * @param[in] _timerRes   Resolution of the timer
247  *
248 */
249 #define TMR_CALCUATE_WAIT(_wait, _tmrVal, _timerRes)          \
250 {                                                             \
251    (_wait) = ((_tmrVal) * SS_TICKS_SEC)/((_timerRes) * 1000); \
252    if((0 != (_tmrVal)) && (0 == (_wait)))                     \
253    {                                                          \
254       (_wait) = 1;                                            \
255    }                                                          \
256 }
257
258 typedef enum
259 {
260    SUCCESSFUL, 
261    CELLID_INVALID, 
262    UEID_INVALID, 
263    RESOURCE_UNAVAILABLE,  
264    SLICE_NOT_FOUND,
265    DUPLICATE_ENTRY,
266    PARAM_INVALID,
267    STATS_ID_NOT_FOUND
268 }CauseOfResult ;
269
270 typedef enum
271 {
272    UE_CFG_INACTIVE,
273    UE_CFG_INPROGRESS,
274    UE_CREATE_COMPLETE,
275    UE_DELETE_COMPLETE,
276    UE_RECFG_COMPLETE,
277    UE_RESET_COMPLETE
278 }UeCfgState;
279
280 typedef enum
281 {
282    CONFIG_UNKNOWN,
283    CONFIG_ADD,
284    CONFIG_MOD,
285    CONFIG_DEL,
286    CONFIG_REESTABLISH
287 }ConfigType;
288
289 #ifdef NR_TDD
290 typedef enum
291 {
292    TX_PRDCTY_MS_0P5,
293    TX_PRDCTY_MS_0P625,
294    TX_PRDCTY_MS_1,
295    TX_PRDCTY_MS_1P25,
296    TX_PRDCTY_MS_2,
297    TX_PRDCTY_MS_2P5,
298    TX_PRDCTY_MS_5,
299    TX_PRDCTY_MS_10
300 }DlUlTxPeriodicity;
301 #endif
302
303 typedef enum
304 {
305    SCS_15KHZ,
306    SCS_30KHZ,
307    SCS_60KHZ,
308    SCS_120KHZ,
309    SCS_240KHZ
310 }SCS;
311
312 typedef enum
313 {
314    SSB_5MS,
315    SSB_10MS,
316    SSB_20MS,
317    SSB_40MS,
318    SSB_80MS,
319    SSB_160MS
320 }SSBPeriodicity;
321
322 typedef enum
323 {
324    CELL_UP,
325    CELL_DOWN
326 }OduCellStatus;
327
328
329 typedef enum
330 {
331    DIR_NONE,
332    DIR_UL,
333    DIR_DL,
334    DIR_BOTH
335 }Direction;
336
337 typedef enum 
338 {
339    SEARCH,
340    CREATE,
341    DELETE,
342    PRINT,
343    TRAVERSE_ALL
344 }ActionTypeLL;
345
346 typedef struct slotTimingInfo
347 {
348    uint16_t cellId;
349    uint16_t sfn;
350    uint16_t slot;
351 }SlotTimingInfo;
352
353 typedef struct PlmnIdentity
354 {
355    uint8_t mcc[3];
356    uint8_t mnc[3];
357 }Plmn;
358
359 typedef struct snssai
360 {
361    uint8_t   sst;
362    uint8_t   sd[SD_SIZE];
363 }Snssai;
364
365 typedef struct oduCellId
366 {
367    uint16_t cellId;
368 }OduCellId;
369
370 #ifdef NR_TDD
371 typedef struct tddCfg
372 {
373    DlUlTxPeriodicity  tddPeriod;     /*DL UL Transmission periodicity */
374    uint8_t            nrOfDlSlots;   /*No. of consecultive full DL slots at beginning of DL-UL pattern*/
375    uint8_t            nrOfDlSymbols; /*No. of consecultive DL symbol at beginning of slot after last full DL slot*/ 
376    uint8_t            nrOfUlSlots;   /*No. of consecutive full UL slots at the end of each DL-UL pattern*/
377    uint8_t            nrOfUlSymbols; /*No. of consecutive UL symbols in the end of the slot before the first full UL slot*/
378 }TDDCfg;
379 #endif
380
381 OduCellStatus gCellStatus;
382 uint64_t gSlotCount;
383 uint64_t gDlDataRcvdCnt;   /* Number of DL data received at EGTP */
384
385 void fillCoresetFeqDomAllocMap(uint16_t startPrb, uint16_t prbSize, uint8_t *freqDomain);
386 void oduCpyFixBufToMsg(uint8_t *fixBuf, Buffer *mBuf, uint16_t len);
387 uint8_t buildPlmnId(Plmn plmn, uint8_t *buf);
388 uint16_t convertScsEnumValToScsVal(uint8_t scsEnumValue);
389 uint8_t convertScsValToScsEnum(uint32_t num);
390 uint8_t convertSSBPeriodicityToEnum(uint32_t num);
391
392 uint8_t SGetSBufNewForDebug(char *file, const char *func, int line, Region region, Pool pool, Data **ptr, Size size);
393 uint8_t SPutSBufNewForDebug(char *file, const char *func, int line, Region region, Pool pool, Data *ptr, Size size);
394 uint8_t SGetStaticBufNewForDebug(char *file, const char *func, int line, \
395 Region region, Pool pool, Data **ptr, Size size, uint8_t memType);
396 uint8_t SPutStaticBufNewForDebug(char *file, const char *func, int line, \
397 Region region, Pool pool, Data *ptr, Size size, uint8_t memType);
398 uint8_t countSetBits(uint32_t num);
399 uint32_t convertArfcnToFreqKhz(uint32_t arfcn);
400 #endif
401
402 /**********************************************************************
403   End of file
404 ***********************************************************************/