* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fhi_lib / app / src / ebbu_pool_cfg.c
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 This file consists of parameters that are to be read from ebbu_pool_cfg.xml
21  * to configure the application at system initialization
22  * @file ebbu_pool_cfg.h
23  * @ingroup xran
24  * @author Intel Corporation
25  **/
26
27
28 #include "ebbu_pool_cfg.h"
29
30 #include <sys/param.h>
31 #include <stdio.h>
32 #include <string.h>
33
34 static eBbuPoolCfgVarsStruct geBbuPoolCfgVars;
35 char eBbuPoolCfgFileName[512];
36
37 uint32_t nD2USwitch[EBBU_POOL_MAX_FRAME_FORMAT][EBBU_POOL_TDD_PERIOD] =
38 {
39     {0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3}, //FDD
40     {0x1, 0x1, 0x1, 0x3, 0x2, 0x1, 0x1, 0x1, 0x3, 0x2}, //DDDSU
41     {0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2, 0x2}  //DDDDDDDSUU
42 };
43
44 //-------------------------------------------------------------------------------------------
45 /** @ingroup group_test_ebbu_pool
46  *
47  *  @param   void
48  *
49  *  @return  eBBUPool Config Local Context Structure Pointer
50  *
51  *  @description
52  *  Returns the eBBUPool Config Local Context Structure Pointer
53  *
54 **/
55 //-------------------------------------------------------------------------------------------
56 peBbuPoolCfgVarsStruct ebbu_pool_cfg_get_ctx(void)
57 {
58     return &geBbuPoolCfgVars;
59 }
60
61
62
63 //-------------------------------------------------------------------------------------------
64 /** @ingroup group_test_ebbu_pool
65  *
66  *  @param   void
67  *
68  *  @return  void
69  *
70  *  @description
71  *  Initialize the geBbuPoolCfgVars. This is called at application bootup
72  *
73 **/
74 //-------------------------------------------------------------------------------------------
75 void ebbu_pool_cfg_init_vars(void)
76 {
77     memset(&geBbuPoolCfgVars, 0, sizeof(eBbuPoolCfgVarsStruct));
78 }
79
80
81
82 //-------------------------------------------------------------------------------------------
83 /** @ingroup group_test_ebbu_pool
84  *
85  *  @param[in]   *pCfgFile Pointer to FILE descriptor to read from
86  *
87  *  @return  0 if SUCCESS
88  *
89  *  @description
90  *  This function parses the XML file that was opened and reads all the tags and associated
91  *  values and stores them
92  *
93 **/
94 //-------------------------------------------------------------------------------------------
95 uint32_t ebbu_pool_cfg_parse_xml(FILE *pCfgFile)
96 {
97     // peBbuPoolCfgVarsStruct geBbuPoolCfgVars = ebbu_pool_cfg_get_ctx();
98     uint32_t lineNum = 0, retCode;
99     char string[1024];
100
101     while(!feof(pCfgFile))
102     {
103         fgets(string, 1024, pCfgFile);
104         lineNum++;
105         retCode = cline_parse_line(string);
106
107         if (retCode != EBBU_POOL_CFG_ERRORCODE__SUCCESS)
108         {
109             printf("Something wrong in file %s ErrorCode[%d] at line[%d]: %s\n", eBbuPoolCfgFileName, (int) retCode, (int)lineNum, string);
110             return EBBU_POOL_CFG_ERRORCODE__FAIL;
111         }
112     }
113
114     return EBBU_POOL_CFG_ERRORCODE__SUCCESS;
115 }
116
117
118 //-------------------------------------------------------------------------------------------
119 /** @ingroup group_test_ebbu_pool
120  *
121  *  @param   void
122  *
123  *  @return  0 if SUCCESS
124  *
125  *  @description
126  *  This function searches for tags from xml and applies the values to the eBBUPool test
127  *
128 **/
129 //-------------------------------------------------------------------------------------------
130 uint32_t ebbu_pool_cfg_apply(void)
131 {
132     printf("ebbu_pool_cfg_apply\n");
133     peBbuPoolCfgVarsStruct geBbuPoolCfgVars = ebbu_pool_cfg_get_ctx();
134     int rc = EBBU_POOL_CFG_ERRORCODE__SUCCESS;
135     int32_t coreNum, cellNum, iCell;
136     uint32_t cellFrameCfg[EBBU_POOL_MAX_TEST_CELL], cellTtiCfg[EBBU_POOL_MAX_TEST_CELL], cellEventCfg[EBBU_POOL_MAX_TEST_CELL];
137
138     cline_print_info();
139
140     //----------------------------------------------------
141     // eBbuPool general config
142     //----------------------------------------------------
143     rc |= cline_set_int((const char *) "eBbuPoolMainThreadCore", (int *) &geBbuPoolCfgVars->mainThreadCoreId, 0);
144     rc |= cline_set_int((const char *) "eBbuPoolConsumerSleep",  (int *) &geBbuPoolCfgVars->sleepFlag, 1);
145
146     //----------------------------------------------------
147     // Queue config
148     //----------------------------------------------------
149     rc |= cline_set_int((const char *) "QueueDepth",  (int *) &geBbuPoolCfgVars->queueDepth, 1024);
150     rc |= cline_set_int((const char *) "QueueNum",    (int *) &geBbuPoolCfgVars->queueNum, 3);
151     rc |= cline_set_int((const char *) "QueuCtxNum",  (int *) &geBbuPoolCfgVars->ququeCtxNum, 1);
152
153     //----------------------------------------------------
154     // Test Config
155     //----------------------------------------------------
156     rc |= cline_set_int((const char *) "TimerThreadCore",   (int *) &geBbuPoolCfgVars->timerCoreId, 0);
157     rc |= cline_set_int((const char *) "CtrlThreadNum",     (int *) &geBbuPoolCfgVars->ctrlThreadNum, 0);
158     rc |= cline_set_int_array((const char *) "CtrlThreadCoreList",  EBBU_POOL_MAX_CTRL_THREAD,(int *) &geBbuPoolCfgVars->ctrlThreadCoreId[0], &coreNum);
159     rc |= cline_set_int((const char *) "TestCellNum",       (int *) &geBbuPoolCfgVars->testCellNum, 0);
160     rc |= cline_set_int((const char *) "TestCoreNum",       (int *) &geBbuPoolCfgVars->testCoreNum, 0);
161     rc |= cline_set_int_array((const char *) "TestCoreList",        EBBU_POOL_MAX_TEST_CORE,  (int *) &geBbuPoolCfgVars->testCoreList[0], &coreNum);
162     rc |= cline_set_int_array((const char *) "TestCellFrameFormat", EBBU_POOL_MAX_TEST_CELL,  (int *) &cellFrameCfg[0], &cellNum);
163     rc |= cline_set_int_array((const char *) "TestCellTti",         EBBU_POOL_MAX_TEST_CELL,  (int *) &cellTtiCfg[0], &cellNum);
164     rc |= cline_set_int_array((const char *) "TestCellEventNum",    EBBU_POOL_MAX_TEST_CELL,  (int *) &cellEventCfg[0], &cellNum);
165     rc |= cline_set_int((const char *) "MlogEnable",        (int *) &geBbuPoolCfgVars->mlogEnable, 0);
166
167     if(cellNum > geBbuPoolCfgVars->testCellNum)
168         cellNum = geBbuPoolCfgVars->testCellNum;
169
170     for(iCell = 0; iCell < cellNum; iCell ++)
171     {
172         geBbuPoolCfgVars->sTestCell[iCell].frameFormat = cellFrameCfg[iCell];
173         geBbuPoolCfgVars->sTestCell[iCell].tti = cellTtiCfg[iCell];
174         geBbuPoolCfgVars->sTestCell[iCell].eventPerTti = cellEventCfg[iCell];
175     }
176
177
178     printf("eBbuPool config completely read: %x\n", rc);
179
180     printf("\n");
181
182     return rc;
183 }
184
185
186
187
188 //-------------------------------------------------------------------------------------------
189 /** @ingroup group_test_ebbu_pool
190  *
191  *  @param   void
192  *
193  *  @return  0 if SUCCESS
194  *
195  *  @description
196  *  This function is called from main() and initializes the EBBU_POOL_CFG layer. It reads the xml
197  *  file and configures the application based on xml tags and values from file.
198  *
199 **/
200 //-------------------------------------------------------------------------------------------
201 uint32_t ebbu_pool_cfg_init_from_xml(void)
202 {
203     // peBbuPoolCfgVarsStruct geBbuPoolCfgVars = ebbu_pool_cfg_get_ctx();
204     FILE *pCfgFile;
205     pCfgFile = fopen(eBbuPoolCfgFileName, "r");
206
207     ebbu_pool_cfg_init_vars();
208
209     cline_init();
210
211     if (pCfgFile == NULL)
212     {
213         printf("ERROR: %s file is not found in directory\n", eBbuPoolCfgFileName);
214         printf("       Please contact Intel to get the correct config file\n");
215         return EBBU_POOL_CFG_ERRORCODE__FAIL;
216     }
217
218     if (ebbu_pool_cfg_parse_xml(pCfgFile) != EBBU_POOL_CFG_ERRORCODE__SUCCESS)
219     {
220         printf("Could not Parse the XML File.\n");
221         fclose(pCfgFile);
222         return EBBU_POOL_CFG_ERRORCODE__FAIL;
223     }
224     printf("PhyCfg XML file parsed\n");
225
226     if (ebbu_pool_cfg_apply() != EBBU_POOL_CFG_ERRORCODE__SUCCESS)
227     {
228         printf("Could not Apply the settings from XML File.\n");
229         fclose(pCfgFile);
230         return EBBU_POOL_CFG_ERRORCODE__FAIL;
231     }
232
233     fclose(pCfgFile);
234     return EBBU_POOL_CFG_ERRORCODE__SUCCESS;
235 }
236
237
238 //-------------------------------------------------------------------------------------------
239 /** @ingroup group_test_ebbu_pool
240  *
241  *  @param[in]   argc Number of command line arguments
242  *  @param[in]   *argv[] Array of command line arguments
243  *
244  *  @return  void
245  *
246  *  @description
247  *  This function parses the command line parameters entered while running the eBbuPool test application
248  *  and searches for string "cfgfile" and takes the immediate next field and uses it as the
249  *  xml file name. If it is not found, it uses default file name "bbdev_cfg.xml" and tries to open
250  *  this.
251  *
252 **/
253 //-------------------------------------------------------------------------------------------
254 void ebbu_pool_cfg_set_cfg_filename(int argc, char *argv[], char filename[512])
255 {
256     // peBbuPoolCfgVarsStruct geBbuPoolCfgVars = ebbu_pool_cfg_get_ctx();
257 #if 0
258     uint32_t ret;
259     ret = cline_get_string(argc, argv, "cfgfile", eBbuPoolCfgFileName);
260
261     if (ret != AUX_SUCCESS)
262     {
263         printf("ebbu_pool_cfg_set_cfg_filename: Coult not find string 'cfgfile' in command line. Using default File: %s\n", EBBU_POOL_FILE_NAME);
264         strcpy(eBbuPoolCfgFileName, EBBU_POOL_FILE_NAME);
265     }
266     strcpy(filename, eBbuPoolCfgFileName);
267 #else
268     strncpy(eBbuPoolCfgFileName, filename, MIN(strnlen(filename, 511),511) );
269     eBbuPoolCfgFileName[511] = '\0';
270     printf("eBbuPoolCfgFileName %s\n", eBbuPoolCfgFileName);
271 #endif
272     return;
273 }
274