cfg.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. * Copyright (c) 2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "cfg_all.h"
  19. #include "cfg_define.h"
  20. #include "cfg_dispatcher.h"
  21. #include "cfg_ucfg_api.h"
  22. #include "i_cfg.h"
  23. #include "i_cfg_objmgr.h"
  24. #include "qdf_atomic.h"
  25. #include "qdf_list.h"
  26. #include "qdf_mem.h"
  27. #include "qdf_module.h"
  28. #include "qdf_parse.h"
  29. #include "qdf_status.h"
  30. #include "qdf_str.h"
  31. #include "qdf_trace.h"
  32. #include "qdf_types.h"
  33. #include "wlan_objmgr_psoc_obj.h"
  34. /**
  35. * struct cfg_value_store - backing store for an ini file
  36. * @path: file path of the ini file
  37. * @node: internal list node for keeping track of all the allocated stores
  38. * @users: number of references on the store
  39. * @values: a values struct containing the parsed values from the ini file
  40. */
  41. struct cfg_value_store {
  42. char *path;
  43. qdf_list_node_t node;
  44. qdf_atomic_t users;
  45. struct cfg_values values;
  46. };
  47. /* define/populate dynamic metadata lookup table */
  48. /**
  49. * struct cfg_meta - configuration item metadata for dynamic lookup during parse
  50. * @name: name of the config item used in the ini file (i.e. "gScanDwellTime")
  51. * @item_handler: parsing callback based on the type of the config item
  52. * @min: minimum value for use in bounds checking (min_len for strings)
  53. * @max: maximum value for use in bounds checking (max_len for strings)
  54. * @fallback: the fallback behavior to use when configured values are invalid
  55. */
  56. struct cfg_meta {
  57. const char *name;
  58. const uint32_t field_offset;
  59. void (*const item_handler)(struct cfg_value_store *store,
  60. const struct cfg_meta *meta,
  61. const char *value);
  62. const int32_t min;
  63. const int32_t max;
  64. const enum cfg_fallback_behavior fallback;
  65. };
  66. /* ini item handler functions */
  67. #define cfg_value_ptr(store, meta) \
  68. ((void *)&(store)->values + (meta)->field_offset)
  69. static void cfg_int_item_handler(struct cfg_value_store *store,
  70. const struct cfg_meta *meta,
  71. const char *str_value)
  72. {
  73. QDF_STATUS status;
  74. int32_t *store_value = cfg_value_ptr(store, meta);
  75. int32_t value;
  76. status = qdf_int32_parse(str_value, &value);
  77. if (QDF_IS_STATUS_ERROR(status)) {
  78. cfg_err("%s=%s - Invalid format (status %d); Using default %d",
  79. meta->name, str_value, status, *store_value);
  80. return;
  81. }
  82. QDF_BUG(meta->min <= meta->max);
  83. if (meta->min > meta->max) {
  84. cfg_err("Invalid config item meta for %s", meta->name);
  85. return;
  86. }
  87. if (value >= meta->min && value <= meta->max) {
  88. *store_value = value;
  89. return;
  90. }
  91. switch (meta->fallback) {
  92. default:
  93. QDF_DEBUG_PANIC();
  94. /* fall through */
  95. case CFG_VALUE_OR_DEFAULT:
  96. /* store already contains default */
  97. break;
  98. case CFG_VALUE_OR_CLAMP:
  99. *store_value = __cfg_clamp(value, meta->min, meta->max);
  100. break;
  101. }
  102. cfg_err("%s=%d - Out of range [%d, %d]; Using %d",
  103. meta->name, value, meta->min, meta->max, *store_value);
  104. }
  105. static void cfg_uint_item_handler(struct cfg_value_store *store,
  106. const struct cfg_meta *meta,
  107. const char *str_value)
  108. {
  109. QDF_STATUS status;
  110. uint32_t *store_value = cfg_value_ptr(store, meta);
  111. uint32_t value;
  112. uint32_t min;
  113. uint32_t max;
  114. /**
  115. * Since meta min and max are of type int32_t
  116. * We need explicit type casting to avoid
  117. * implicit wrap around for uint32_t type cfg data.
  118. */
  119. min = (uint32_t)meta->min;
  120. max = (uint32_t)meta->max;
  121. status = qdf_uint32_parse(str_value, &value);
  122. if (QDF_IS_STATUS_ERROR(status)) {
  123. cfg_err("%s=%s - Invalid format (status %d); Using default %u",
  124. meta->name, str_value, status, *store_value);
  125. return;
  126. }
  127. QDF_BUG(min <= max);
  128. if (min > max) {
  129. cfg_err("Invalid config item meta for %s", meta->name);
  130. return;
  131. }
  132. if (value >= min && value <= max) {
  133. *store_value = value;
  134. return;
  135. }
  136. switch (meta->fallback) {
  137. default:
  138. QDF_DEBUG_PANIC();
  139. /* fall through */
  140. case CFG_VALUE_OR_DEFAULT:
  141. /* store already contains default */
  142. break;
  143. case CFG_VALUE_OR_CLAMP:
  144. *store_value = __cfg_clamp(value, min, max);
  145. break;
  146. }
  147. cfg_err("%s=%u - Out of range [%d, %d]; Using %u",
  148. meta->name, value, min, max, *store_value);
  149. }
  150. static void cfg_bool_item_handler(struct cfg_value_store *store,
  151. const struct cfg_meta *meta,
  152. const char *str_value)
  153. {
  154. QDF_STATUS status;
  155. bool *store_value = cfg_value_ptr(store, meta);
  156. status = qdf_bool_parse(str_value, store_value);
  157. if (QDF_IS_STATUS_SUCCESS(status))
  158. return;
  159. cfg_err("%s=%s - Invalid format (status %d); Using default '%s'",
  160. meta->name, str_value, status, *store_value ? "true" : "false");
  161. }
  162. static void cfg_string_item_handler(struct cfg_value_store *store,
  163. const struct cfg_meta *meta,
  164. const char *str_value)
  165. {
  166. char *store_value = cfg_value_ptr(store, meta);
  167. qdf_size_t len;
  168. QDF_BUG(meta->min >= 0);
  169. QDF_BUG(meta->min <= meta->max);
  170. if (meta->min < 0 || meta->min > meta->max) {
  171. cfg_err("Invalid config item meta for %s", meta->name);
  172. return;
  173. }
  174. /* ensure min length */
  175. len = qdf_str_nlen(str_value, meta->min);
  176. if (len < meta->min) {
  177. cfg_err("%s=%s - Too short; Using default '%s'",
  178. meta->name, str_value, store_value);
  179. return;
  180. }
  181. /* check max length */
  182. len += qdf_str_nlen(str_value + meta->min, meta->max - meta->min + 1);
  183. if (len > meta->max) {
  184. cfg_err("%s=%s - Too long; Using default '%s'",
  185. meta->name, str_value, store_value);
  186. return;
  187. }
  188. qdf_str_lcopy(store_value, str_value, meta->max + 1);
  189. }
  190. static void cfg_mac_item_handler(struct cfg_value_store *store,
  191. const struct cfg_meta *meta,
  192. const char *str_value)
  193. {
  194. QDF_STATUS status;
  195. struct qdf_mac_addr *store_value = cfg_value_ptr(store, meta);
  196. status = qdf_mac_parse(str_value, store_value);
  197. if (QDF_IS_STATUS_SUCCESS(status))
  198. return;
  199. cfg_err("%s=%s - Invalid format (status %d); Using default "
  200. QDF_MAC_ADDR_STR, meta->name, str_value, status,
  201. QDF_MAC_ADDR_ARRAY(store_value->bytes));
  202. }
  203. static void cfg_ipv4_item_handler(struct cfg_value_store *store,
  204. const struct cfg_meta *meta,
  205. const char *str_value)
  206. {
  207. QDF_STATUS status;
  208. struct qdf_ipv4_addr *store_value = cfg_value_ptr(store, meta);
  209. status = qdf_ipv4_parse(str_value, store_value);
  210. if (QDF_IS_STATUS_SUCCESS(status))
  211. return;
  212. cfg_err("%s=%s - Invalid format (status %d); Using default "
  213. QDF_IPV4_ADDR_STR, meta->name, str_value, status,
  214. QDF_IPV4_ADDR_ARRAY(store_value->bytes));
  215. }
  216. static void cfg_ipv6_item_handler(struct cfg_value_store *store,
  217. const struct cfg_meta *meta,
  218. const char *str_value)
  219. {
  220. QDF_STATUS status;
  221. struct qdf_ipv6_addr *store_value = cfg_value_ptr(store, meta);
  222. status = qdf_ipv6_parse(str_value, store_value);
  223. if (QDF_IS_STATUS_SUCCESS(status))
  224. return;
  225. cfg_err("%s=%s - Invalid format (status %d); Using default "
  226. QDF_IPV6_ADDR_STR, meta->name, str_value, status,
  227. QDF_IPV6_ADDR_ARRAY(store_value->bytes));
  228. }
  229. /* populate metadata lookup table */
  230. #undef __CFG_ANY
  231. #define __CFG_ANY(_id, _mtype, _ctype, _name, _min, _max, _fallback, ...) \
  232. { \
  233. .name = _name, \
  234. .field_offset = qdf_offsetof(struct cfg_values, _id##_internal), \
  235. .item_handler = cfg_ ## _mtype ## _item_handler, \
  236. .min = _min, \
  237. .max = _max, \
  238. .fallback = _fallback, \
  239. },
  240. #define cfg_INT_item_handler cfg_int_item_handler
  241. #define cfg_UINT_item_handler cfg_uint_item_handler
  242. #define cfg_BOOL_item_handler cfg_bool_item_handler
  243. #define cfg_STRING_item_handler cfg_string_item_handler
  244. #define cfg_MAC_item_handler cfg_mac_item_handler
  245. #define cfg_IPV4_item_handler cfg_ipv4_item_handler
  246. #define cfg_IPV6_item_handler cfg_ipv6_item_handler
  247. static const struct cfg_meta cfg_meta_lookup_table[] = {
  248. CFG_ALL
  249. };
  250. /* default store initializer */
  251. static void cfg_store_set_defaults(struct cfg_value_store *store)
  252. {
  253. #undef __CFG_ANY
  254. #define __CFG_ANY(id, mtype, ctype, name, min, max, fallback, desc, def...) \
  255. ctype id = def;
  256. CFG_ALL
  257. #undef __CFG_STRING
  258. #define __CFG_STRING(id, mtype, ctype, name, min_len, max_len, ...) \
  259. qdf_str_lcopy((char *)&store->values.id##_internal, id, max_len + 1);
  260. #undef __CFG_ANY
  261. #define __CFG_ANY(id, mtype, ctype, name, min, max, fallback, desc, def...) \
  262. *(ctype *)&store->values.id##_internal = id;
  263. CFG_ALL
  264. }
  265. static const struct cfg_meta *cfg_lookup_meta(const char *name)
  266. {
  267. int i;
  268. QDF_BUG(name);
  269. if (!name)
  270. return NULL;
  271. /* linear search for now; optimize in the future if needed */
  272. for (i = 0; i < QDF_ARRAY_SIZE(cfg_meta_lookup_table); i++) {
  273. const struct cfg_meta *meta = &cfg_meta_lookup_table[i];
  274. if (qdf_str_eq(name, meta->name))
  275. return meta;
  276. }
  277. return NULL;
  278. }
  279. static QDF_STATUS
  280. cfg_ini_item_handler(void *context, const char *key, const char *value)
  281. {
  282. struct cfg_value_store *store = context;
  283. const struct cfg_meta *meta;
  284. meta = cfg_lookup_meta(key);
  285. if (!meta) {
  286. /* TODO: promote to 'err' or 'warn' once legacy is ported */
  287. cfg_info("Unknown config item '%s'", key);
  288. return QDF_STATUS_SUCCESS;
  289. }
  290. QDF_BUG(meta->item_handler);
  291. if (!meta->item_handler)
  292. return QDF_STATUS_SUCCESS;
  293. meta->item_handler(store, meta, value);
  294. return QDF_STATUS_SUCCESS;
  295. }
  296. static QDF_STATUS cfg_ini_section_handler(void *context, const char *name)
  297. {
  298. cfg_err("Unexpected section '%s'. Sections are not supported.", name);
  299. return QDF_STATUS_SUCCESS;
  300. }
  301. #define cfg_assert_success(expr) \
  302. do { \
  303. QDF_STATUS __assert_status = (expr); \
  304. QDF_BUG(QDF_IS_STATUS_SUCCESS(__assert_status)); \
  305. } while (0)
  306. static bool __cfg_is_init;
  307. static struct cfg_value_store *__cfg_global_store;
  308. static qdf_list_t __cfg_stores_list;
  309. static qdf_spinlock_t __cfg_stores_lock;
  310. struct cfg_psoc_ctx {
  311. struct cfg_value_store *store;
  312. };
  313. static QDF_STATUS
  314. cfg_store_alloc(const char *path, struct cfg_value_store **out_store)
  315. {
  316. QDF_STATUS status;
  317. struct cfg_value_store *store;
  318. cfg_enter();
  319. store = qdf_mem_malloc(sizeof(*store));
  320. if (!store) {
  321. cfg_err("Out of memory");
  322. return QDF_STATUS_E_NOMEM;
  323. }
  324. status = qdf_str_dup(&store->path, path);
  325. if (QDF_IS_STATUS_ERROR(status))
  326. goto free_store;
  327. status = qdf_atomic_init(&store->users);
  328. if (QDF_IS_STATUS_ERROR(status))
  329. goto free_path;
  330. qdf_atomic_inc(&store->users);
  331. qdf_spin_lock_bh(&__cfg_stores_lock);
  332. status = qdf_list_insert_back(&__cfg_stores_list, &store->node);
  333. qdf_spin_unlock_bh(&__cfg_stores_lock);
  334. if (QDF_IS_STATUS_ERROR(status))
  335. goto free_path;
  336. *out_store = store;
  337. return QDF_STATUS_SUCCESS;
  338. free_path:
  339. qdf_mem_free(store->path);
  340. free_store:
  341. qdf_mem_free(store);
  342. return status;
  343. }
  344. static void cfg_store_free(struct cfg_value_store *store)
  345. {
  346. QDF_STATUS status;
  347. cfg_enter();
  348. qdf_spin_lock_bh(&__cfg_stores_lock);
  349. status = qdf_list_remove_node(&__cfg_stores_list, &store->node);
  350. qdf_spin_unlock_bh(&__cfg_stores_lock);
  351. if (QDF_IS_STATUS_ERROR(status)) {
  352. cfg_err("Failed config store list removal; status:%d", status);
  353. QDF_DEBUG_PANIC();
  354. }
  355. qdf_mem_free(store->path);
  356. qdf_mem_free(store);
  357. }
  358. static QDF_STATUS
  359. cfg_store_get(const char *path, struct cfg_value_store **out_store)
  360. {
  361. QDF_STATUS status;
  362. qdf_list_node_t *node;
  363. *out_store = NULL;
  364. qdf_spin_lock_bh(&__cfg_stores_lock);
  365. status = qdf_list_peek_front(&__cfg_stores_list, &node);
  366. while (QDF_IS_STATUS_SUCCESS(status)) {
  367. struct cfg_value_store *store =
  368. qdf_container_of(node, struct cfg_value_store, node);
  369. if (qdf_str_eq(path, store->path)) {
  370. qdf_atomic_inc(&store->users);
  371. *out_store = store;
  372. break;
  373. }
  374. status = qdf_list_peek_next(&__cfg_stores_list, node, &node);
  375. }
  376. qdf_spin_unlock_bh(&__cfg_stores_lock);
  377. return status;
  378. }
  379. static void cfg_store_put(struct cfg_value_store *store)
  380. {
  381. if (qdf_atomic_dec_and_test(&store->users))
  382. cfg_store_free(store);
  383. }
  384. static struct cfg_psoc_ctx *cfg_psoc_get_ctx(struct wlan_objmgr_psoc *psoc)
  385. {
  386. struct cfg_psoc_ctx *psoc_ctx;
  387. psoc_ctx = cfg_psoc_get_priv(psoc);
  388. QDF_BUG(psoc_ctx);
  389. return psoc_ctx;
  390. }
  391. struct cfg_values *cfg_psoc_get_values(struct wlan_objmgr_psoc *psoc)
  392. {
  393. return &cfg_psoc_get_ctx(psoc)->store->values;
  394. }
  395. qdf_export_symbol(cfg_psoc_get_values);
  396. static QDF_STATUS
  397. cfg_ini_parse_to_store(const char *path, struct cfg_value_store *store)
  398. {
  399. QDF_STATUS status;
  400. status = qdf_ini_parse(path, store, cfg_ini_item_handler,
  401. cfg_ini_section_handler);
  402. if (QDF_IS_STATUS_ERROR(status))
  403. cfg_err("Failed to parse *.ini file @ %s; status:%d",
  404. path, status);
  405. return status;
  406. }
  407. static void cfg_init(void)
  408. {
  409. qdf_list_create(&__cfg_stores_list, 0);
  410. qdf_spinlock_create(&__cfg_stores_lock);
  411. }
  412. static void cfg_deinit(void)
  413. {
  414. qdf_spinlock_destroy(&__cfg_stores_lock);
  415. qdf_list_destroy(&__cfg_stores_list);
  416. }
  417. static void cfg_try_deinit(void)
  418. {
  419. bool empty;
  420. qdf_spin_lock_bh(&__cfg_stores_lock);
  421. empty = qdf_list_empty(&__cfg_stores_list);
  422. qdf_spin_unlock_bh(&__cfg_stores_lock);
  423. if (empty)
  424. cfg_deinit();
  425. }
  426. static QDF_STATUS
  427. cfg_on_psoc_create(struct wlan_objmgr_psoc *psoc, void *context)
  428. {
  429. QDF_STATUS status;
  430. struct cfg_psoc_ctx *psoc_ctx;
  431. cfg_enter();
  432. QDF_BUG(__cfg_global_store);
  433. if (!__cfg_global_store)
  434. return QDF_STATUS_E_FAILURE;
  435. psoc_ctx = qdf_mem_malloc(sizeof(*psoc_ctx));
  436. if (!psoc_ctx) {
  437. cfg_err("Out of memory");
  438. return QDF_STATUS_E_NOMEM;
  439. }
  440. qdf_atomic_inc(&__cfg_global_store->users);
  441. psoc_ctx->store = __cfg_global_store;
  442. status = cfg_psoc_set_priv(psoc, psoc_ctx);
  443. if (QDF_IS_STATUS_ERROR(status))
  444. goto put_store;
  445. return QDF_STATUS_SUCCESS;
  446. put_store:
  447. cfg_store_put(__cfg_global_store);
  448. qdf_mem_free(psoc_ctx);
  449. return status;
  450. }
  451. static QDF_STATUS
  452. cfg_on_psoc_destroy(struct wlan_objmgr_psoc *psoc, void *context)
  453. {
  454. QDF_STATUS status;
  455. struct cfg_psoc_ctx *psoc_ctx;
  456. cfg_enter();
  457. psoc_ctx = cfg_psoc_get_ctx(psoc);
  458. status = cfg_psoc_unset_priv(psoc, psoc_ctx);
  459. cfg_store_put(psoc_ctx->store);
  460. qdf_mem_free(psoc_ctx);
  461. return status;
  462. }
  463. QDF_STATUS cfg_dispatcher_init(void)
  464. {
  465. QDF_STATUS status;
  466. cfg_enter();
  467. QDF_BUG(!__cfg_is_init);
  468. if (__cfg_is_init)
  469. return QDF_STATUS_E_INVAL;
  470. status = cfg_psoc_register_create(cfg_on_psoc_create);
  471. if (QDF_IS_STATUS_ERROR(status))
  472. return status;
  473. status = cfg_psoc_register_destroy(cfg_on_psoc_destroy);
  474. if (QDF_IS_STATUS_ERROR(status))
  475. goto unreg_create;
  476. __cfg_is_init = true;
  477. return QDF_STATUS_SUCCESS;
  478. unreg_create:
  479. cfg_assert_success(cfg_psoc_unregister_create(cfg_on_psoc_create));
  480. return status;
  481. }
  482. QDF_STATUS cfg_dispatcher_deinit(void)
  483. {
  484. cfg_enter();
  485. QDF_BUG(__cfg_is_init);
  486. if (!__cfg_is_init)
  487. return QDF_STATUS_E_INVAL;
  488. __cfg_is_init = false;
  489. cfg_assert_success(cfg_psoc_unregister_create(cfg_on_psoc_create));
  490. cfg_assert_success(cfg_psoc_unregister_destroy(cfg_on_psoc_destroy));
  491. cfg_try_deinit();
  492. return QDF_STATUS_SUCCESS;
  493. }
  494. QDF_STATUS cfg_parse(const char *path)
  495. {
  496. QDF_STATUS status;
  497. struct cfg_value_store *store;
  498. cfg_enter();
  499. QDF_BUG(!__cfg_global_store);
  500. if (__cfg_global_store)
  501. return QDF_STATUS_E_INVAL;
  502. cfg_init();
  503. status = cfg_store_alloc(path, &store);
  504. if (QDF_IS_STATUS_ERROR(status))
  505. goto deinit;
  506. cfg_store_set_defaults(store);
  507. status = cfg_ini_parse_to_store(path, store);
  508. if (QDF_IS_STATUS_ERROR(status))
  509. goto free_store;
  510. __cfg_global_store = store;
  511. return QDF_STATUS_SUCCESS;
  512. free_store:
  513. cfg_store_free(store);
  514. deinit:
  515. cfg_deinit();
  516. return status;
  517. }
  518. void cfg_release(void)
  519. {
  520. cfg_enter();
  521. QDF_BUG(__cfg_global_store);
  522. if (!__cfg_global_store)
  523. return;
  524. cfg_store_put(__cfg_global_store);
  525. __cfg_global_store = NULL;
  526. cfg_try_deinit();
  527. }
  528. QDF_STATUS cfg_psoc_parse(struct wlan_objmgr_psoc *psoc, const char *path)
  529. {
  530. QDF_STATUS status;
  531. struct cfg_value_store *store;
  532. struct cfg_psoc_ctx *psoc_ctx;
  533. cfg_enter();
  534. QDF_BUG(__cfg_global_store);
  535. if (!__cfg_global_store)
  536. return QDF_STATUS_E_INVAL;
  537. QDF_BUG(__cfg_is_init);
  538. if (!__cfg_is_init)
  539. return QDF_STATUS_E_INVAL;
  540. QDF_BUG(psoc);
  541. if (!psoc)
  542. return QDF_STATUS_E_INVAL;
  543. QDF_BUG(path);
  544. if (!path)
  545. return QDF_STATUS_E_INVAL;
  546. psoc_ctx = cfg_psoc_get_ctx(psoc);
  547. QDF_BUG(psoc_ctx->store == __cfg_global_store);
  548. if (psoc_ctx->store != __cfg_global_store)
  549. return QDF_STATUS_SUCCESS;
  550. /* check if @path has been parsed before */
  551. status = cfg_store_get(path, &store);
  552. if (QDF_IS_STATUS_ERROR(status)) {
  553. status = cfg_store_alloc(path, &store);
  554. if (QDF_IS_STATUS_ERROR(status))
  555. return status;
  556. /* inherit global configuration */
  557. qdf_mem_copy(&store->values, &__cfg_global_store->values,
  558. sizeof(store->values));
  559. status = cfg_ini_parse_to_store(path, store);
  560. if (QDF_IS_STATUS_ERROR(status))
  561. goto put_store;
  562. }
  563. psoc_ctx->store = store;
  564. cfg_store_put(__cfg_global_store);
  565. return QDF_STATUS_SUCCESS;
  566. put_store:
  567. cfg_store_put(store);
  568. return status;
  569. }