1 /******************************************************************************
3 * Copyright (c) 2019 Intel.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 *******************************************************************************/
18 #include "nr5g_fapi_config_loader.h"
19 #include "nr5g_fapi_dpdk.h"
22 #define NR5G_FAPI_MAX_SHMSIZE (2126512128)
28 p_nr5g_fapi_cfg_t nr5g_fapi_config_loader(
30 const char *cfg_fname)
32 struct rte_cfgfile *cfg_file;
33 p_nr5g_fapi_cfg_t cfg;
36 unsigned int num_cpus = 0;
37 char check_core_count[255], *max_core;
40 if (cfg_fname == NULL) {
41 printf("Error: Configuration filename was not passed.");
45 cfg_file = rte_cfgfile_load(cfg_fname, 0);
46 if (cfg_file == NULL) {
47 printf("Error: Cofiguration file loading failed.");
51 cfg = (p_nr5g_fapi_cfg_t) calloc(1, sizeof(nr5g_fapi_cfg_t));
53 printf("Error: not enough memory in the system");
56 cfg->prgname = prgname;
57 fp = popen("cat /proc/cpuinfo | grep processor | wc -l", "r");
59 printf("Error: In getting maximum number of lcores in the system.");
63 max_core = fgets_s(check_core_count, 255, fp);
64 if (NULL == max_core) {
65 printf("Error: In getting maximum number of lcores in the system.");
70 num_cpus = atoi(max_core);
71 entry = rte_cfgfile_get_entry(cfg_file, "MAC2PHY_WORKER", "core_id");
73 cfg->mac2phy_worker.core_id = (uint8_t) atoi(entry);
74 if (cfg->mac2phy_worker.core_id >= (uint8_t) num_cpus) {
75 printf("Core Id is not in the range 0 to %d: configured: %d\n",
76 num_cpus, cfg->mac2phy_worker.core_id);
82 rte_cfgfile_get_entry(cfg_file, "MAC2PHY_WORKER", "thread_sched_policy");
84 cfg->mac2phy_worker.thread_sched_policy = (uint8_t) atoi(entry);
85 if (cfg->mac2phy_worker.thread_sched_policy != SCHED_FIFO &&
86 cfg->mac2phy_worker.thread_sched_policy != SCHED_RR) {
87 printf("Thread Poicy valid range is Schedule Policy [0: SCHED_FIFO"
88 " 1: SCHED_RR]: configured: %d\n",
89 cfg->mac2phy_worker.thread_sched_policy);
95 sched_get_priority_min(cfg->mac2phy_worker.thread_sched_policy);
97 sched_get_priority_max(cfg->mac2phy_worker.thread_sched_policy);
99 rte_cfgfile_get_entry(cfg_file, "MAC2PHY_WORKER", "thread_priority");
101 cfg->mac2phy_worker.thread_priority = (uint8_t) atoi(entry);
102 if (cfg->mac2phy_worker.thread_priority < min_prio &&
103 cfg->mac2phy_worker.thread_priority > max_prio) {
104 printf("Thread priority valid range is %d to %d: configured: %d\n",
105 min_prio, max_prio, cfg->mac2phy_worker.thread_priority);
110 entry = rte_cfgfile_get_entry(cfg_file, "PHY2MAC_WORKER", "core_id");
112 cfg->phy2mac_worker.core_id = (uint8_t) atoi(entry);
113 if (cfg->phy2mac_worker.core_id >= (uint8_t) num_cpus) {
114 printf("Core Id is not in the range 0 to %d configured: %d\n",
115 num_cpus, cfg->phy2mac_worker.core_id);
121 rte_cfgfile_get_entry(cfg_file, "PHY2MAC_WORKER", "thread_sched_policy");
123 cfg->phy2mac_worker.thread_sched_policy = (uint8_t) atoi(entry);
124 if (cfg->phy2mac_worker.thread_sched_policy != SCHED_FIFO &&
125 cfg->phy2mac_worker.thread_sched_policy != SCHED_RR) {
126 printf("Thread Poicy valid range is Schedule Policy [0: SCHED_FIFO"
127 " 1: SCHED_RR] configured: %d\n",
128 cfg->phy2mac_worker.thread_sched_policy);
134 rte_cfgfile_get_entry(cfg_file, "PHY2MAC_WORKER", "thread_priority");
136 cfg->phy2mac_worker.thread_priority = (uint8_t) atoi(entry);
137 if (cfg->phy2mac_worker.thread_priority < min_prio &&
138 cfg->phy2mac_worker.thread_priority > max_prio) {
139 printf("Thread priority valid range is %d to %d configured: %d\n",
140 min_prio, max_prio, cfg->phy2mac_worker.thread_priority);
145 entry = rte_cfgfile_get_entry(cfg_file, "WLS_CFG", "device_name");
147 dev_name_len = (strlen(entry) > (NR5G_FAPI_DEVICE_NAME_LEN)) ?
148 (NR5G_FAPI_DEVICE_NAME_LEN) : strlen(entry);
149 rte_strlcpy(cfg->wls.device_name, entry, dev_name_len + 1);
152 entry = rte_cfgfile_get_entry(cfg_file, "WLS_CFG", "shmem_size");
154 cfg->wls.shmem_size = (uint64_t) atoll(entry);
155 if (cfg->wls.shmem_size > NR5G_FAPI_MAX_SHMSIZE) {
156 printf("The memory range cannot exceed %d", NR5G_FAPI_MAX_SHMSIZE);
161 entry = rte_cfgfile_get_entry(cfg_file, "LOGGER", "level");
163 if (!strcmp(entry, "info"))
164 cfg->logger.level = INFO_LOG;
165 else if (!strcmp(entry, "debug"))
166 cfg->logger.level = DEBUG_LOG;
167 else if (!strcmp(entry, "error"))
168 cfg->logger.level = ERROR_LOG;
169 else if (!strcmp(entry, "trace"))
170 cfg->logger.level = TRACE_LOG;
171 else if (!strcmp(entry, "hexdump"))
172 cfg->logger.level = HEXDUMP_LOG;
174 cfg->logger.level = NONE_LOG;
187 if (fgets(string, len, fp) != 0) {
188 string[strcspn(string, "\n")] = '\0';