Restructure O1 module to run as a thread in O-DU High binary [Issue-Id: ODUHIGH-297]
[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    /* system task for DU APP */
300    if(ODU_CREATE_TASK(PRIOR0, &du_app_stsk) != ROK)
301    {
302       DU_LOG("\nERROR  -->  DU_APP : System Task creation for DU APP failed");
303       return RFAILED;
304    }
305    ODU_SET_THREAD_AFFINITY(&du_app_stsk, SS_AFFINITY_MODE_EXCL, 15, 0);
306
307    /* system task for EGTP */
308    if(ODU_CREATE_TASK(PRIOR0, &egtp_stsk) != ROK)
309    {
310       DU_LOG("\nERROR  -->  DU_APP : System Task creation for EGTP failed");
311       return RFAILED;
312    }
313    ODU_SET_THREAD_AFFINITY(&egtp_stsk, SS_AFFINITY_MODE_EXCL, 16, 0);
314
315    /* system task for RLC_DL and MAC */
316    if(ODU_CREATE_TASK(PRIOR0, &rlc_mac_cl_stsk) != ROK)
317    {
318       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC DL/MAC failed");
319       return RFAILED;
320    }
321    pthread_attr_init(&attr);
322    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
323    ODU_SET_THREAD_AFFINITY(&rlc_mac_cl_stsk, SS_AFFINITY_MODE_EXCL, 17, 0);
324
325    /* system task for RLC UL */
326    if(ODU_CREATE_TASK(PRIOR1, &rlc_ul_stsk) != ROK)
327    {
328       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC UL failed");
329       return RFAILED;
330    }
331    ODU_SET_THREAD_AFFINITY(&rlc_ul_stsk, SS_AFFINITY_MODE_EXCL, 18, 0);
332
333    /* system task for SCTP receiver thread */
334    if(ODU_CREATE_TASK(PRIOR0, &sctp_stsk) != ROK)
335    {
336       DU_LOG("\nERROR  -->  DU_APP : System Task creation for SCTP failed");
337       return RFAILED;
338    }
339    ODU_SET_THREAD_AFFINITY(&sctp_stsk, SS_AFFINITY_MODE_EXCL, 19, 0);
340
341    /* system task for lower-mac receiver thread */
342    if(ODU_CREATE_TASK(PRIOR0, &lwr_mac_stsk) != ROK)
343    {
344       DU_LOG("\nERROR  -->  DU_APP : System Task creation for Lower MAC failed");
345       return RFAILED;
346    }
347    ODU_SET_THREAD_AFFINITY(&lwr_mac_stsk, SS_AFFINITY_MODE_EXCL, 20, 0);
348
349    /* Create TAPA tasks */
350    if(duAppInit(du_app_stsk) != ROK)
351    {
352       DU_LOG("\nERROR  -->  DU_APP : DU APP TAPA Task initialization failed");
353       return RFAILED;
354    }
355
356    if(egtpInit(egtp_stsk) != ROK)
357    {
358       DU_LOG("\nERROR  -->  DU_APP : EGTP TAPA Task initialization failed");
359       return RFAILED;
360    }
361
362    if(sctpInit(sctp_stsk) != ROK)
363    {
364       DU_LOG("\nERROR  -->  DU_APP : SCTP TAPA Task initialization failed");
365       return RFAILED;
366    }
367
368    if(rlcDlInit(rlc_mac_cl_stsk) != ROK)
369    {
370       DU_LOG("\nERROR  -->  DU_APP : RLC DL Tapa Task initialization failed");
371       return RFAILED;
372    } 
373
374    if(rlcUlInit(rlc_ul_stsk) != ROK)
375    {
376      DU_LOG("\nERROR  -->  DU_APP : RLC UL Tapa Task initialization failed");
377      return RFAILED;
378    } 
379
380    if(lwrMacInit(lwr_mac_stsk) != ROK)
381    {
382       DU_LOG("\nERROR  -->  DU_APP : Lower MAC Tapa Task initialization failed");
383       return RFAILED;
384    }
385
386    return ROK;
387 }
388
389 /*******************************************************************
390  *
391  * @brief Initializes the DU
392  *
393  * @details
394  *
395  *    Function : duInit
396  *
397  *    Functionality:
398  *       - Calls commonInit
399  *       - Registers DU Layers
400  *
401  * @params[in] void
402  * @return ROK     - success
403  *         RFAILED - failure
404  *
405  * ****************************************************************/
406 uint8_t duInit()
407 {
408    int ret = ROK;
409    if(commonInit() != ROK)
410    {
411       ret = RFAILED;
412    } 
413    return ret;
414 }
415
416 void init_log()
417 {
418         openlog("ODU",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
419 }
420
421 /*******************************************************************
422  *
423  * @brief Entry point for the DU APP 
424  *
425  * @details
426  *
427  *    Function : main
428  *
429  *    Functionality:
430  *      - Read config params into duCfgParams
431  *      - Initiate the init functions
432  *
433  * @params[in] void
434  * @return ROK     - success
435  *         RFAILED - failure
436  *
437  * ****************************************************************/
438 uint8_t tst(void)
439 {
440    init_log();
441
442 #ifdef O1_ENABLE
443    if(start_O1_module() != ROK)
444       return RFAILED;
445 #endif
446
447    //Initialize TAPA layers
448    if(duInit() != ROK)
449    {
450       return RFAILED;
451    } 
452
453    //Read all the configs from du_utils.c into duCfgParams
454    duReadCfg();
455
456    return ROK;
457 }/* end of main()*/
458
459 /**********************************************************************
460          End of file
461 **********************************************************************/