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