Merge "Restructure O1 module to run as a thread in O-DU High binary [Issue-Id: ODUHIG...
[o-du/l2.git] / src / du_app / du_mgr_main.c
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 /* This file is the entry point for DU APP */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lrg.x"
24 #include "lkw.x"
25 #include "du_app_mac_inf.h"
26 #include "du_app_rlc_inf.h"
27 #include "du_cfg.h"
28 #include "du_mgr.h"
29 #include "du_mgr_main.h"
30 #include "du_sctp.h"
31 #include "du_egtp.h"
32
33 #ifdef O1_ENABLE
34
35 #include "O1Interface.h"
36
37 #endif
38
39 uint8_t rlcUlActvTsk (Pst *, Buffer *);
40 uint8_t rlcUlActvInit (Ent, Inst, Region, Reason);
41 uint8_t rlcDlActvTsk (Pst *, Buffer *);
42 uint8_t rlcDlActvInit (Ent, Inst, Region, Reason);
43 uint8_t rgActvTsk (Pst *, Buffer *);
44 uint8_t rgActvInit (Ent, Inst, Region, Reason);
45 uint8_t lwrMacActvTsk(Pst *, Buffer *);
46 uint8_t lwrMacActvInit(Ent, Inst, Region, Reason);
47
48 /* Global variable */
49 DuCfgParams duCfgParam;
50
51 /*******************************************************************
52  *
53  * @brief Initializes DU APP
54  *
55  * @details
56  *
57  *    Function : duAppInit
58  *
59  *    Functionality:
60  *       - Registers and attaches TAPA tasks belonging to 
61  *         DU_APP sys task
62  *
63  * @params[in] system task ID
64  * @return ROK     - success
65  *         RFAILED - failure
66  *
67  * ****************************************************************/
68 uint8_t duAppInit(SSTskId sysTskId)
69 {
70    /* Register DU APP TAPA Task for DU */
71    if(ODU_REG_TTSK((Ent)ENTDUAPP, (Inst)DU_INST, (Ttype)TTNORM, (Prior)PRIOR0,
72       duActvInit, (ActvTsk)duActvTsk) != ROK)
73    {
74       return RFAILED;
75    }
76    /* Attach DU APP TAPA Task for DU */
77    if (ODU_ATTACH_TTSK((Ent)ENTDUAPP, (Inst)0, sysTskId)!= ROK)
78    {
79       return RFAILED;
80    }
81
82    DU_LOG("\nINFO   -->  DU_APP : DU APP created and registered \
83    to %d sys task", sysTskId);
84    return ROK;
85 }
86
87 /*******************************************************************
88  *
89  * @brief Initializes EGTP
90  *
91  * @details
92  *
93  *    Function : egtpInit
94  *
95  *    Functionality:
96  *       - Registers and attaches TAPA tasks belonging to 
97  *         DU_APP sys task
98  *
99  * @params[in] system task ID
100  * @return ROK     - success
101  *         RFAILED - failure
102  *
103  * ****************************************************************/
104 uint8_t egtpInit(SSTskId sysTskId)
105 {
106    /* Register DU APP TAPA Task for DU */
107    if(ODU_REG_TTSK((Ent)ENTEGTP, (Inst)EGTP_INST, (Ttype)TTNORM, (Prior)PRIOR0,
108              egtpActvInit, (ActvTsk)egtpActvTsk) != ROK)
109    {
110       return RFAILED;
111    }
112    /* Attach DU APP TAPA Task for DU */
113    if (ODU_ATTACH_TTSK((Ent)ENTEGTP, (Inst)0, sysTskId)!= ROK)
114    {
115       return RFAILED;
116    }
117  
118     DU_LOG("\nINFO   -->  DU_APP : EGTP created and registered \
119     to %d sys task", sysTskId);
120     return ROK;
121 }
122  
123
124 /*******************************************************************
125  *
126  * @brief Initializes SCTP task
127  *
128  * @details
129  *
130  *    Function : sctpInit
131  *
132  *    Functionality:
133  *       - Registers and attaches TAPA tasks for SCTP receiver 
134  *
135  * @params[in] system task ID
136  * @return ROK     - success
137  *         RFAILED - failure
138  *
139  * ****************************************************************/
140 uint8_t sctpInit(SSTskId sysTskId)
141 {
142    /* Register SCTP TAPA Task */
143    if(ODU_REG_TTSK((Ent)ENTSCTP, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
144             sctpActvInit, (ActvTsk)sctpActvTsk) != ROK)
145    {
146       return RFAILED;
147    }
148    /* Attach SCTP TAPA Task */
149    if (ODU_ATTACH_TTSK((Ent)ENTSCTP, (Inst)SCTP_INST, sysTskId)!= ROK)
150    {
151       return RFAILED;
152    }
153
154    DU_LOG("\nINFO   -->  DU_APP : SCTP TAPA task created and registered to %d sys task", 
155          sysTskId);
156    return ROK;
157 }
158 /*******************************************************************
159  *
160  * @brief Initializes RLC DL, MAC TAPA task
161  *
162  * @details
163  *
164  *    Function : rlcDlInit
165  *
166  *    Functionality:
167  *       - Registers and attaches TAPA tasks for MAC and RLC DL
168  *
169  * @params[in] system task ID
170  * @return ROK     - success
171  *         RFAILED - failure
172  *
173  * ****************************************************************/
174 uint8_t rlcDlInit(SSTskId sysTskId)
175 {
176    /* Register RLC DL TAPA Task */
177    if(ODU_REG_TTSK((Ent)ENTRLC, (Inst)1, (Ttype)TTNORM, (Prior)PRIOR0,
178             rlcDlActvInit, (ActvTsk)rlcDlActvTsk) != ROK)
179    {
180       return RFAILED;
181    }
182    /* Attach RLC DL Task */
183    if (ODU_ATTACH_TTSK((Ent)ENTRLC, (Inst)1, sysTskId)!= ROK)
184    {
185       return RFAILED;
186    }
187
188    /* Register MAC TAPA Task */
189    if(ODU_REG_TTSK((Ent)ENTMAC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
190             rgActvInit, (ActvTsk)rgActvTsk) != ROK)
191    {
192       return RFAILED;
193    }
194    /* Attach MAC Task */
195    if (ODU_ATTACH_TTSK((Ent)ENTMAC, (Inst)0, sysTskId)!= ROK)
196    {
197       return RFAILED;
198    }
199
200    DU_LOG("\nINFO   -->  DU_APP : RLC DL and MAC TAPA task created and registered to \
201    %d sys task", sysTskId);
202    return ROK;
203 }
204
205 /*******************************************************************
206  *
207  * @brief Initializes RLC UL TAPA task
208  *
209  * @details
210  *
211  *    Function : rlcUlInit
212  *
213  *    Functionality:
214  *       - Registers and attaches TAPA task for RLC UL
215  *
216  * @params[in] system task ID
217  * @return ROK     - success
218  *         RFAILED - failure
219  *
220  * ****************************************************************/
221 uint8_t rlcUlInit(SSTskId sysTskId)
222 {
223    /* Register RLC UL TAPA Task */
224    if(ODU_REG_TTSK((Ent)ENTRLC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
225             rlcUlActvInit, (ActvTsk)rlcUlActvTsk) != ROK)
226    {
227       return RFAILED;
228    }
229    /* Attach RLC DL Task */
230    if (ODU_ATTACH_TTSK((Ent)ENTRLC, (Inst)0, sysTskId)!= ROK)
231    {
232       return RFAILED;
233    }
234    DU_LOG("\nINFO   -->  DU_APP : RLC UL TAPA task created and registered to \
235    %d sys task", sysTskId);
236    return ROK;
237 }
238
239 /*******************************************************************
240  *
241  * @brief Initializes Lower MAC receiver task
242  *
243  * @details
244  *
245  *    Function : lwrMacInit
246  *
247  *    Functionality:
248  *       - Registers and attaches TAPA tasks for Lower MAC receiver
249  *
250  * @params[in] system task ID
251  * @return ROK     - success
252  *         RFAILED - failure
253  *
254  * ****************************************************************/
255 uint8_t lwrMacInit(SSTskId sysTskId)
256 {
257    /* Register SCTP TAPA Task */
258    if(ODU_REG_TTSK((Ent)ENTLWRMAC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
259             lwrMacActvInit, (ActvTsk)lwrMacActvTsk) != ROK)
260    {
261       return RFAILED;
262    }
263    /* Attach SCTP TAPA Task */
264    if (ODU_ATTACH_TTSK((Ent)ENTLWRMAC, (Inst)0, sysTskId)!= ROK)
265    {
266       return RFAILED;
267    }
268
269    DU_LOG("\nINFO   -->  DU_APP : LWR MAC TAPA task created and registered to %d sys task",
270          sysTskId);
271    return ROK;
272 }
273
274 /*******************************************************************
275  *
276  * @brief Initializes system and TAPA tasks
277  *
278  * @details
279  *
280  *    Function : commonInit
281  *
282  *    Functionality:
283  *       - Registers and attaches system and TAPA tasks
284  *
285  * @params[in] void
286  * @return ROK     - success
287  *         RFAILED - failure
288  *
289  * ****************************************************************/
290 uint8_t commonInit()
291 {
292    /* Declare system task Ids */
293    SSTskId du_app_stsk, egtp_stsk, sctp_stsk, rlc_ul_stsk, rlc_mac_cl_stsk, lwr_mac_stsk;
294
295    pthread_attr_t attr;
296
297    ODU_SET_PROC_ID(DU_PROC);
298
299    /* Intel L1 using core 0-15. ODU-High using 16-21 */
300    /* system task for DU APP */
301    if(ODU_CREATE_TASK(PRIOR0, &du_app_stsk) != ROK)
302    {
303       DU_LOG("\nERROR  -->  DU_APP : System Task creation for DU APP failed");
304       return RFAILED;
305    }
306    ODU_SET_THREAD_AFFINITY(&du_app_stsk, SS_AFFINITY_MODE_EXCL, 16, 0);
307
308    /* system task for EGTP */
309    if(ODU_CREATE_TASK(PRIOR0, &egtp_stsk) != ROK)
310    {
311       DU_LOG("\nERROR  -->  DU_APP : System Task creation for EGTP failed");
312       return RFAILED;
313    }
314    ODU_SET_THREAD_AFFINITY(&egtp_stsk, SS_AFFINITY_MODE_EXCL, 17, 0);
315
316    /* system task for RLC_DL and MAC */
317    if(ODU_CREATE_TASK(PRIOR0, &rlc_mac_cl_stsk) != ROK)
318    {
319       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC DL/MAC failed");
320       return RFAILED;
321    }
322    pthread_attr_init(&attr);
323    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
324    ODU_SET_THREAD_AFFINITY(&rlc_mac_cl_stsk, SS_AFFINITY_MODE_EXCL, 18, 0);
325
326    /* system task for RLC UL */
327    if(ODU_CREATE_TASK(PRIOR1, &rlc_ul_stsk) != ROK)
328    {
329       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC UL failed");
330       return RFAILED;
331    }
332    ODU_SET_THREAD_AFFINITY(&rlc_ul_stsk, SS_AFFINITY_MODE_EXCL, 19, 0);
333
334    /* system task for SCTP receiver thread */
335    if(ODU_CREATE_TASK(PRIOR0, &sctp_stsk) != ROK)
336    {
337       DU_LOG("\nERROR  -->  DU_APP : System Task creation for SCTP failed");
338       return RFAILED;
339    }
340    ODU_SET_THREAD_AFFINITY(&sctp_stsk, SS_AFFINITY_MODE_EXCL, 20, 0);
341
342    /* system task for lower-mac receiver thread */
343    if(ODU_CREATE_TASK(PRIOR0, &lwr_mac_stsk) != ROK)
344    {
345       DU_LOG("\nERROR  -->  DU_APP : System Task creation for Lower MAC failed");
346       return RFAILED;
347    }
348    ODU_SET_THREAD_AFFINITY(&lwr_mac_stsk, SS_AFFINITY_MODE_EXCL, 21, 0);
349
350    /* Create TAPA tasks */
351    if(duAppInit(du_app_stsk) != ROK)
352    {
353       DU_LOG("\nERROR  -->  DU_APP : DU APP TAPA Task initialization failed");
354       return RFAILED;
355    }
356
357    if(egtpInit(egtp_stsk) != ROK)
358    {
359       DU_LOG("\nERROR  -->  DU_APP : EGTP TAPA Task initialization failed");
360       return RFAILED;
361    }
362
363    if(sctpInit(sctp_stsk) != ROK)
364    {
365       DU_LOG("\nERROR  -->  DU_APP : SCTP TAPA Task initialization failed");
366       return RFAILED;
367    }
368
369    if(rlcDlInit(rlc_mac_cl_stsk) != ROK)
370    {
371       DU_LOG("\nERROR  -->  DU_APP : RLC DL Tapa Task initialization failed");
372       return RFAILED;
373    } 
374
375    if(rlcUlInit(rlc_ul_stsk) != ROK)
376    {
377      DU_LOG("\nERROR  -->  DU_APP : RLC UL Tapa Task initialization failed");
378      return RFAILED;
379    } 
380
381    if(lwrMacInit(lwr_mac_stsk) != ROK)
382    {
383       DU_LOG("\nERROR  -->  DU_APP : Lower MAC Tapa Task initialization failed");
384       return RFAILED;
385    }
386
387    return ROK;
388 }
389
390 /*******************************************************************
391  *
392  * @brief Initializes the DU
393  *
394  * @details
395  *
396  *    Function : duInit
397  *
398  *    Functionality:
399  *       - Calls commonInit
400  *       - Registers DU Layers
401  *
402  * @params[in] void
403  * @return ROK     - success
404  *         RFAILED - failure
405  *
406  * ****************************************************************/
407 uint8_t duInit()
408 {
409    int ret = ROK;
410    if(commonInit() != ROK)
411    {
412       ret = RFAILED;
413    } 
414    return ret;
415 }
416
417 void init_log()
418 {
419         openlog("ODU",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
420 }
421
422 /*******************************************************************
423  *
424  * @brief Entry point for the DU APP 
425  *
426  * @details
427  *
428  *    Function : main
429  *
430  *    Functionality:
431  *      - Read config params into duCfgParams
432  *      - Initiate the init functions
433  *
434  * @params[in] void
435  * @return ROK     - success
436  *         RFAILED - failure
437  *
438  * ****************************************************************/
439 uint8_t tst(void)
440 {
441    init_log();
442
443 #ifdef O1_ENABLE
444    if(start_O1_module() != ROK)
445       return RFAILED;
446 #endif
447
448    //Initialize TAPA layers
449    if(duInit() != ROK)
450    {
451       return RFAILED;
452    } 
453
454    //Read all the configs from du_utils.c into duCfgParams
455    duReadCfg();
456
457    return ROK;
458 }/* end of main()*/
459
460 /**********************************************************************
461          End of file
462 **********************************************************************/