* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fhi_lib / app / src / app_bbu_pool.h
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 Intel.
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 /**
20  * @brief Header file to implementation of BBU
21  * @file app_bbu.h
22  * @ingroup xran
23  * @author Intel Corporation
24  *
25  **/
26
27 #ifndef _APP_BBU_POOL_H_
28 #define _APP_BBU_POOL_H_
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include "ebbu_pool_api.h"
35 #include "ebbu_pool_cfg.h"
36
37 #include "config.h"
38 #include "xran_fh_o_du.h"
39 #include "xran_mlog_lnx.h"
40
41 #ifndef SUCCESS
42 /** SUCCESS = 0 */
43 #define SUCCESS     0
44 #endif /* #ifndef SUCCESS */
45
46 #ifndef FAILURE
47 /** FAILURE = 1 */
48 #define FAILURE     1
49 #endif /* #ifndef FAILURE */
50
51 #define MAX_NEXT_TASK_NUM  8
52 #define MAX_TEST_CTX       4
53 #define MAX_TEST_SPLIT_NUM 55 // then largest 1000 events per TTI by pre-defined event chain
54
55 #define  EVENT_NAME(EVENT_TYPE) #EVENT_TYPE
56
57 #define MAX_PHY_INSTANCES   ( 24 )
58 #define MAX_NUM_OF_SF_5G_CTX ( 8 )
59
60 /******Processing Latencies***/
61 #define DL_PROC_ADVANCE_MU0                 ( 1 )
62 #define DL_PROC_ADVANCE_MU1                 ( 2 )
63 #define DL_PROC_ADVANCE_MU3                 ( 2 )
64
65 #define UL_PROC_ADVANCE_MU0                 ( 1 )
66 #define UL_PROC_ADVANCE_MU1                 ( 1 )
67 #define UL_PROC_ADVANCE_MU3                 ( 1 )
68
69 extern uint32_t gMaxSlotNum[MAX_PHY_INSTANCES];
70 extern uint32_t gNumDLCtx[MAX_PHY_INSTANCES];
71 extern uint32_t gNumULCtx[MAX_PHY_INSTANCES];
72 extern uint32_t gNumDLBufferCtx[MAX_PHY_INSTANCES];
73 extern uint32_t gNumULBufferCtx[MAX_PHY_INSTANCES];
74 extern uint32_t gDLProcAdvance[MAX_PHY_INSTANCES];
75 extern int32_t gULProcAdvance[MAX_PHY_INSTANCES];
76
77 #define get_dl_sf_idx(nSlotNum, nCellIdx)     ((nSlotNum + gDLProcAdvance[nCellIdx]) % gMaxSlotNum[nCellIdx])
78 #define get_ul_sf_idx(nSlotNum, nCellIdx)     ((nSlotNum + gULProcAdvance[nCellIdx]) % gMaxSlotNum[nCellIdx])
79 #define get_dl_sf_ctx(nSlotNum, nCellIdx)     (nSlotNum % gNumDLCtx[nCellIdx])
80 #define get_ul_sf_ctx(nSlotNum, nCellIdx)     (nSlotNum % gNumULCtx[nCellIdx])
81
82 typedef enum
83 {
84     TTI_START = 0,              /* 0 First task that will schedule all the other tasks for all Cells */
85     SYM2_WAKE_UP,               /* 1 Sym2 Arrival which will wake up UL Tasks for all cells */
86     SYM6_WAKE_UP,               /* 2 Sym6 Arrival which will wake up UL Tasks for all cells */
87     SYM11_WAKE_UP,              /* 3 Sym11 Arrival which will wake up UL Tasks for all cells */
88     SYM13_WAKE_UP,              /* 4 Sym13 Arrival which will wake up UL Tasks for all cells */
89     PRACH_WAKE_UP,              /* 5 PRACH Arrival which will wake up will wake up PRACH for all cells */
90     SRS_WAKE_UP,                /* 6 (Massive MIMO) SRS Arrival which will wake up SRS Decompression for all cells */
91     DL_CONFIG,                  /* 7 */
92     DL_PDSCH_TB,                /* 8 */
93     DL_PDSCH_SCRM,              /* 9 */
94     DL_PDSCH_SYM,               /* 10 */
95     DL_PDSCH_RS,                /* 11 */
96     DL_CTRL,                    /* 12 */
97     UL_CONFIG,                  /* 13 */
98     UL_IQ_DECOMP2,              /* 14 */
99     UL_IQ_DECOMP6,              /* 15 */
100     UL_IQ_DECOMP11,             /* 16 */
101     UL_IQ_DECOMP13,             /* 17 */
102     UL_PUSCH_CE0,               /* 18 */
103     UL_PUSCH_CE7,               /* 19 */
104     UL_PUSCH_EQL0,              /* 20 */
105     UL_PUSCH_EQL7,              /* 21 */
106     UL_PUSCH_LLR,               /* 22 */
107     UL_PUSCH_DEC,               /* 23 */
108     UL_PUSCH_TB,                /* 24 */
109     UL_PUCCH,                   /* 25 */
110     UL_PRACH,                   /* 26 */
111     UL_SRS_DECOMP,              /* 27 */
112     UL_SRS_CE,                  /* 28 */
113     UL_SRS_POST,                /* 29 */
114     DL_POST,                    /* 30 */
115     UL_POST,                    /* 31 */
116     DL_BEAM_GEN,                /* 32 */
117     DL_BEAM_TX,                 /* 33 */
118     UL_BEAM_GEN,                /* 34 */
119     UL_BEAM_TX,                 /* 35 */
120     MAX_TASK_NUM_G_NB           /* 36 */
121 } TaskTypeEnum;
122
123 ///defines the parameters that multi-tasks are generated.
124 typedef struct
125 {
126     /*! Indicate how many tasks of the generating type. 1 means that no task splitting. */
127     uint16_t nTaskNum;
128     /*! the parameter list for each splitted task */
129     void *pTaskExePara[MAX_TEST_SPLIT_NUM];
130 } TaskPreGen;
131
132 typedef enum
133 {
134     RB_SPLIT = 0,
135     UE_GROUP_SPLIT = 1,
136     LAYER_SPLIT = 2,
137     UE_SPLIT = 3,
138     PORT_SPLIT = 4,
139     CE_RX_SPLIT = 5,
140     OFDM_SYMB_SPLIT = 6
141 } TaskSplitType;
142
143 typedef struct tSampleSplitStruct
144 {
145     int16_t nGroupStart;
146     int16_t nGroupNum;
147     int16_t nUeStart;
148     int16_t nUeNum;
149     int16_t nSymbStart;
150     int16_t nSymbNum;
151     int16_t nLayerStart;
152     int16_t nLayerNum;
153     int16_t nSplitIndex;
154     TaskSplitType eSplitType;
155 } SampleSplitStruct;
156
157 typedef struct
158 {
159     int32_t eventChainDepth;
160     int32_t nextEventChain[MAX_TASK_NUM_G_NB][MAX_NEXT_TASK_NUM];
161     int32_t nextEventCount[MAX_TASK_NUM_G_NB];
162     int32_t preEventCount[MAX_TASK_NUM_G_NB];
163     int32_t preEventCountSave[MAX_TASK_NUM_G_NB];
164     int32_t preEventStat[MAX_TASK_NUM_G_NB];
165 } __attribute__((aligned(IA_ALIGN))) EventChainDescStruct;
166
167 typedef void (*PreEventExeFunc) (uint32_t nSfIdx, uint16_t nCellIdx, TaskPreGen *pPara);
168
169 typedef struct
170 {
171     int32_t nEventId;
172     char sTaskName[32];
173     int32_t nEventPrio;
174     EventExeFunc pEventFunc;
175     PreEventExeFunc pPreEventFunc;
176     uint32_t nWakeOnExtrernalEvent;
177     uint32_t nPrefetchFlag;
178     uint32_t nCoreMaskType;
179     uint64_t nCoreMask0;
180     uint64_t nCoreMask1;
181     //uint64_t nCoreMask2;
182     //uint64_t nCoreMask3;
183     //uint64_t nCoreMask4;
184     //uint64_t nCoreMask5;
185     //uint64_t nCoreMask6;
186     //uint64_t nCoreMask7;
187 } __attribute__((aligned(IA_ALIGN))) EventConfigStruct;
188
189 typedef struct
190 {
191     int32_t nEventId;
192     int32_t nSplitIdx;
193     int32_t nCellIdx;
194     int32_t nSlotIdx;
195     void *pTaskPara;
196     void *pHandler;
197     float *dummy0;
198     uint64_t tSendTime;
199     uint8_t nBuffer[240];
200 } __attribute__((aligned(IA_ALIGN))) EventCtrlStruct;
201
202 typedef struct
203 {
204     int32_t nEventId;
205     int32_t nEventPrio;
206     EventExeFunc pEventFunc;
207 } __attribute__((aligned(IA_ALIGN))) EventInfo;
208
209 typedef struct
210 {
211     int32_t nCellInd;
212     EventStruct *pEventStruct;
213     int16_t *pCEtp;
214     int16_t *pMIMOouttp;
215     int16_t *pWeighttp;
216 } __attribute__((aligned(IA_ALIGN))) gNBCellStruct;
217
218 extern EventChainDescStruct gEventChain[EBBU_POOL_MAX_TEST_CELL][MAX_TEST_CTX];
219 extern EventCtrlStruct gEventCtrl[EBBU_POOL_MAX_TEST_CELL][MAX_TEST_CTX][MAX_TASK_NUM_G_NB][MAX_TEST_SPLIT_NUM];
220
221 int32_t event_chain_gen(EventChainDescStruct *psEventChain);
222 int32_t event_chain_reset(EventChainDescStruct *psEventChain);
223 int32_t test_buffer_create();
224
225 eBbuPoolHandler app_get_ebbu_pool_handler(void);
226
227 int32_t app_bbu_init(int argc, char *argv[], char cfgName[512], UsecaseConfig* p_use_cfg,  RuntimeConfig* p_o_xu_cfg[],
228                     uint64_t nActiveCoreMask[EBBUPOOL_MAX_CORE_MASK]);
229 int32_t app_bbu_close(void);
230
231
232 int32_t app_bbu_dl_tti_call_back(void * param);
233
234 int32_t test_func_gen(eBbuPoolHandler pHandler, int32_t nCell, int32_t nSlot, int32_t eventId);
235 int32_t next_event_unlock(void *pCookies);
236
237 /** tasks */
238 int32_t app_bbu_pool_task_dl_post(void *pCookies);
239 void app_bbu_pool_pre_task_dl_post(uint32_t nSubframe, uint16_t nCellIdx, TaskPreGen *pPara);
240 int32_t app_bbu_pool_task_dl_config(void *pCookies);
241 void app_bbu_pool_pre_task_dl_cfg(uint32_t nSubframe, uint16_t nCellIdx, TaskPreGen *pPara);
242 int32_t app_bbu_pool_task_ul_config(void * pCookies);
243 void app_bbu_pool_pre_task_ul_cfg(uint32_t nSubframe, uint16_t nCellIdx, TaskPreGen *pPara);
244
245 int32_t app_bbu_pool_task_sym2_wakeup(void *pCookies);
246 int32_t app_bbu_pool_task_sym6_wakeup(void *pCookies);
247 int32_t app_bbu_pool_task_sym11_wakeup(void *pCookies);
248 int32_t app_bbu_pool_task_sym13_wakeup(void *pCookies);
249 int32_t app_bbu_pool_task_prach_wakeup(void *pCookies);
250 int32_t app_bbu_pool_task_srs_wakeup(void *pCookies);
251
252 void app_io_xran_fh_bbu_rx_callback(void *pCallbackTag, xran_status_t status);
253 void app_io_xran_fh_bbu_rx_bfw_callback(void *pCallbackTag, xran_status_t status);
254 void app_io_xran_fh_bbu_rx_prach_callback(void *pCallbackTag, xran_status_t status);
255 void app_io_xran_fh_bbu_rx_srs_callback(void *pCallbackTag, xran_status_t status);
256
257
258 #ifdef __cplusplus
259 }
260 #endif
261 #endif /*_APP_BBU_POOL_H_*/