cfg.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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. status = qdf_uint32_parse(str_value, &value);
  113. if (QDF_IS_STATUS_ERROR(status)) {
  114. cfg_err("%s=%s - Invalid format (status %d); Using default %u",
  115. meta->name, str_value, status, *store_value);
  116. return;
  117. }
  118. QDF_BUG(meta->min >= 0);
  119. QDF_BUG(meta->min <= meta->max);
  120. if (meta->min < 0 || meta->min > meta->max) {
  121. cfg_err("Invalid config item meta for %s", meta->name);
  122. return;
  123. }
  124. if (value >= meta->min && value <= meta->max) {
  125. *store_value = value;
  126. return;
  127. }
  128. switch (meta->fallback) {
  129. default:
  130. QDF_DEBUG_PANIC();
  131. /* fall through */
  132. case CFG_VALUE_OR_DEFAULT:
  133. /* store already contains default */
  134. break;
  135. case CFG_VALUE_OR_CLAMP:
  136. *store_value = __cfg_clamp(value, meta->min, meta->max);
  137. break;
  138. }
  139. cfg_err("%s=%u - Out of range [%d, %d]; Using %u",
  140. meta->name, value, meta->min, meta->max, *store_value);
  141. }
  142. static void cfg_bool_item_handler(struct cfg_value_store *store,
  143. const struct cfg_meta *meta,
  144. const char *str_value)
  145. {
  146. QDF_STATUS status;
  147. bool *store_value = cfg_value_ptr(store, meta);
  148. status = qdf_bool_parse(str_value, store_value);
  149. if (QDF_IS_STATUS_SUCCESS(status))
  150. return;
  151. cfg_err("%s=%s - Invalid format (status %d); Using default '%s'",
  152. meta->name, str_value, status, *store_value ? "true" : "false");
  153. }
  154. static void cfg_string_item_handler(struct cfg_value_store *store,
  155. const struct cfg_meta *meta,
  156. const char *str_value)
  157. {
  158. char *store_value = cfg_value_ptr(store, meta);
  159. qdf_size_t len;
  160. QDF_BUG(meta->min >= 0);
  161. QDF_BUG(meta->min <= meta->max);
  162. if (meta->min < 0 || meta->min > meta->max) {
  163. cfg_err("Invalid config item meta for %s", meta->name);
  164. return;
  165. }
  166. /* ensure min length */
  167. len = qdf_str_nlen(str_value, meta->min);
  168. if (len < meta->min) {
  169. cfg_err("%s=%s - Too short; Using default '%s'",
  170. meta->name, str_value, store_value);
  171. return;
  172. }
  173. /* check max length */
  174. len += qdf_str_nlen(str_value + meta->min, meta->max - meta->min + 1);
  175. if (len > meta->max) {
  176. cfg_err("%s=%s - Too long; Using default '%s'",
  177. meta->name, str_value, store_value);
  178. return;
  179. }
  180. qdf_str_lcopy(store_value, str_value, meta->max + 1);
  181. }
  182. static void cfg_mac_item_handler(struct cfg_value_store *store,
  183. const struct cfg_meta *meta,
  184. const char *str_value)
  185. {
  186. QDF_STATUS status;
  187. struct qdf_mac_addr *store_value = cfg_value_ptr(store, meta);
  188. status = qdf_mac_parse(str_value, store_value);
  189. if (QDF_IS_STATUS_SUCCESS(status))
  190. return;
  191. cfg_err("%s=%s - Invalid format (status %d); Using default "
  192. QDF_MAC_ADDR_STR, meta->name, str_value, status,
  193. QDF_MAC_ADDR_ARRAY(store_value->bytes));
  194. }
  195. static void cfg_ipv4_item_handler(struct cfg_value_store *store,
  196. const struct cfg_meta *meta,
  197. const char *str_value)
  198. {
  199. QDF_STATUS status;
  200. struct qdf_ipv4_addr *store_value = cfg_value_ptr(store, meta);
  201. status = qdf_ipv4_parse(str_value, store_value);
  202. if (QDF_IS_STATUS_SUCCESS(status))
  203. return;
  204. cfg_err("%s=%s - Invalid format (status %d); Using default "
  205. QDF_IPV4_ADDR_STR, meta->name, str_value, status,
  206. QDF_IPV4_ADDR_ARRAY(store_value->bytes));
  207. }
  208. static void cfg_ipv6_item_handler(struct cfg_value_store *store,
  209. const struct cfg_meta *meta,
  210. const char *str_value)
  211. {
  212. QDF_STATUS status;
  213. struct qdf_ipv6_addr *store_value = cfg_value_ptr(store, meta);
  214. status = qdf_ipv6_parse(str_value, store_value);
  215. if (QDF_IS_STATUS_SUCCESS(status))
  216. return;
  217. cfg_err("%s=%s - Invalid format (status %d); Using default "
  218. QDF_IPV6_ADDR_STR, meta->name, str_value, status,
  219. QDF_IPV6_ADDR_ARRAY(store_value->bytes));
  220. }
  221. /* populate metadata lookup table */
  222. #undef __CFG_ANY
  223. #define __CFG_ANY(_id, _mtype, _ctype, _name, _min, _max, _fallback, ...) \
  224. { \
  225. .name = _name, \
  226. .field_offset = qdf_offsetof(struct cfg_values, _id##_internal), \
  227. .item_handler = cfg_ ## _mtype ## _item_handler, \
  228. .min = _min, \
  229. .max = _max, \
  230. .fallback = _fallback, \
  231. },
  232. #define cfg_INT_item_handler cfg_int_item_handler
  233. #define cfg_UINT_item_handler cfg_uint_item_handler
  234. #define cfg_BOOL_item_handler cfg_bool_item_handler
  235. #define cfg_STRING_item_handler cfg_string_item_handler
  236. #define cfg_MAC_item_handler cfg_mac_item_handler
  237. #define cfg_IPV4_item_handler cfg_ipv4_item_handler
  238. #define cfg_IPV6_item_handler cfg_ipv6_item_handler
  239. static const struct cfg_meta cfg_meta_lookup_table[] = {
  240. CFG_ALL
  241. };
  242. /* default store initializer */
  243. static void cfg_store_set_defaults(struct cfg_value_store *store)
  244. {
  245. #undef __CFG_ANY
  246. #define __CFG_ANY(id, mtype, ctype, name, min, max, fallback, desc, def...) \
  247. ctype id = def;
  248. CFG_ALL
  249. #undef __CFG_STRING
  250. #define __CFG_STRING(id, mtype, ctype, name, min_len, max_len, ...) \
  251. qdf_str_lcopy((char *)&store->values.id##_internal, id, max_len + 1);
  252. #undef __CFG_ANY
  253. #define __CFG_ANY(id, mtype, ctype, name, min, max, fallback, desc, def...) \
  254. *(ctype *)&store->values.id##_internal = id;
  255. CFG_ALL
  256. }
  257. static const struct cfg_meta *cfg_lookup_meta(const char *name)
  258. {
  259. int i;
  260. QDF_BUG(name);
  261. if (!name)
  262. return NULL;
  263. /* linear search for now; optimize in the future if needed */
  264. for (i = 0; i < QDF_ARRAY_SIZE(cfg_meta_lookup_table); i++) {
  265. const struct cfg_meta *meta = &cfg_meta_lookup_table[i];
  266. if (qdf_str_eq(name, meta->name))
  267. return meta;
  268. }
  269. return NULL;
  270. }
  271. static QDF_STATUS
  272. cfg_ini_item_handler(void *context, const char *key, const char *value)
  273. {
  274. struct cfg_value_store *store = context;
  275. const struct cfg_meta *meta;
  276. meta = cfg_lookup_meta(key);
  277. if (!meta) {
  278. /* TODO: promote to 'err' or 'warn' once legacy is ported */
  279. cfg_info("Unknown config item '%s'", key);
  280. return QDF_STATUS_SUCCESS;
  281. }
  282. QDF_BUG(meta->item_handler);
  283. if (!meta->item_handler)
  284. return QDF_STATUS_SUCCESS;
  285. meta->item_handler(store, meta, value);
  286. return QDF_STATUS_SUCCESS;
  287. }
  288. static QDF_STATUS cfg_ini_section_handler(void *context, const char *name)
  289. {
  290. cfg_err("Unexpected section '%s'. Sections are not supported.", name);
  291. return QDF_STATUS_SUCCESS;
  292. }
  293. #define cfg_assert_success(expr) \
  294. do { \
  295. QDF_STATUS __assert_status = (expr); \
  296. QDF_BUG(QDF_IS_STATUS_SUCCESS(__assert_status)); \
  297. } while (0)
  298. static bool __cfg_is_init;
  299. static struct cfg_value_store *__cfg_global_store;
  300. static qdf_list_t __cfg_stores_list;
  301. static qdf_spinlock_t __cfg_stores_lock;
  302. struct cfg_psoc_ctx {
  303. struct cfg_value_store *store;
  304. };
  305. static QDF_STATUS
  306. cfg_store_alloc(const char *path, struct cfg_value_store **out_store)
  307. {
  308. QDF_STATUS status;
  309. struct cfg_value_store *store;
  310. cfg_enter();
  311. store = qdf_mem_malloc(sizeof(*store));
  312. if (!store) {
  313. cfg_err("Out of memory");
  314. return QDF_STATUS_E_NOMEM;
  315. }
  316. status = qdf_str_dup(&store->path, path);
  317. if (QDF_IS_STATUS_ERROR(status))
  318. goto free_store;
  319. status = qdf_atomic_init(&store->users);
  320. if (QDF_IS_STATUS_ERROR(status))
  321. goto free_path;
  322. qdf_atomic_inc(&store->users);
  323. qdf_spin_lock_bh(&__cfg_stores_lock);
  324. status = qdf_list_insert_back(&__cfg_stores_list, &store->node);
  325. qdf_spin_unlock_bh(&__cfg_stores_lock);
  326. if (QDF_IS_STATUS_ERROR(status))
  327. goto free_path;
  328. *out_store = store;
  329. return QDF_STATUS_SUCCESS;
  330. free_path:
  331. qdf_mem_free(store->path);
  332. free_store:
  333. qdf_mem_free(store);
  334. return status;
  335. }
  336. static void cfg_store_free(struct cfg_value_store *store)
  337. {
  338. QDF_STATUS status;
  339. cfg_enter();
  340. qdf_spin_lock_bh(&__cfg_stores_lock);
  341. status = qdf_list_remove_node(&__cfg_stores_list, &store->node);
  342. qdf_spin_unlock_bh(&__cfg_stores_lock);
  343. if (QDF_IS_STATUS_ERROR(status)) {
  344. cfg_err("Failed config store list removal; status:%d", status);
  345. QDF_DEBUG_PANIC();
  346. }
  347. qdf_mem_free(store->path);
  348. qdf_mem_free(store);
  349. }
  350. static QDF_STATUS
  351. cfg_store_get(const char *path, struct cfg_value_store **out_store)
  352. {
  353. QDF_STATUS status;
  354. qdf_list_node_t *node;
  355. *out_store = NULL;
  356. qdf_spin_lock_bh(&__cfg_stores_lock);
  357. status = qdf_list_peek_front(&__cfg_stores_list, &node);
  358. while (QDF_IS_STATUS_SUCCESS(status)) {
  359. struct cfg_value_store *store =
  360. qdf_container_of(node, struct cfg_value_store, node);
  361. if (qdf_str_eq(path, store->path)) {
  362. qdf_atomic_inc(&store->users);
  363. *out_store = store;
  364. break;
  365. }
  366. status = qdf_list_peek_next(&__cfg_stores_list, node, &node);
  367. }
  368. qdf_spin_unlock_bh(&__cfg_stores_lock);
  369. return status;
  370. }
  371. static void cfg_store_put(struct cfg_value_store *store)
  372. {
  373. if (qdf_atomic_dec_and_test(&store->users))
  374. cfg_store_free(store);
  375. }
  376. static struct cfg_psoc_ctx *cfg_psoc_get_ctx(struct wlan_objmgr_psoc *psoc)
  377. {
  378. struct cfg_psoc_ctx *psoc_ctx;
  379. psoc_ctx = cfg_psoc_get_priv(psoc);
  380. QDF_BUG(psoc_ctx);
  381. return psoc_ctx;
  382. }
  383. struct cfg_values *cfg_psoc_get_values(struct wlan_objmgr_psoc *psoc)
  384. {
  385. return &cfg_psoc_get_ctx(psoc)->store->values;
  386. }
  387. qdf_export_symbol(cfg_psoc_get_values);
  388. static QDF_STATUS
  389. cfg_ini_parse_to_store(const char *path, struct cfg_value_store *store)
  390. {
  391. QDF_STATUS status;
  392. status = qdf_ini_parse(path, store, cfg_ini_item_handler,
  393. cfg_ini_section_handler);
  394. if (QDF_IS_STATUS_ERROR(status))
  395. cfg_err("Failed to parse *.ini file @ %s; status:%d",
  396. path, status);
  397. return status;
  398. }
  399. static void cfg_init(void)
  400. {
  401. qdf_list_create(&__cfg_stores_list, 0);
  402. qdf_spinlock_create(&__cfg_stores_lock);
  403. }
  404. static void cfg_deinit(void)
  405. {
  406. qdf_spinlock_destroy(&__cfg_stores_lock);
  407. qdf_list_destroy(&__cfg_stores_list);
  408. }
  409. static void cfg_try_deinit(void)
  410. {
  411. bool empty;
  412. qdf_spin_lock_bh(&__cfg_stores_lock);
  413. empty = qdf_list_empty(&__cfg_stores_list);
  414. qdf_spin_unlock_bh(&__cfg_stores_lock);
  415. if (empty)
  416. cfg_deinit();
  417. }
  418. static QDF_STATUS
  419. cfg_on_psoc_create(struct wlan_objmgr_psoc *psoc, void *context)
  420. {
  421. QDF_STATUS status;
  422. struct cfg_psoc_ctx *psoc_ctx;
  423. cfg_enter();
  424. QDF_BUG(__cfg_global_store);
  425. if (!__cfg_global_store)
  426. return QDF_STATUS_E_FAILURE;
  427. psoc_ctx = qdf_mem_malloc(sizeof(*psoc_ctx));
  428. if (!psoc_ctx) {
  429. cfg_err("Out of memory");
  430. return QDF_STATUS_E_NOMEM;
  431. }
  432. qdf_atomic_inc(&__cfg_global_store->users);
  433. psoc_ctx->store = __cfg_global_store;
  434. status = cfg_psoc_set_priv(psoc, psoc_ctx);
  435. if (QDF_IS_STATUS_ERROR(status))
  436. goto put_store;
  437. return QDF_STATUS_SUCCESS;
  438. put_store:
  439. cfg_store_put(__cfg_global_store);
  440. qdf_mem_free(psoc_ctx);
  441. return status;
  442. }
  443. static QDF_STATUS
  444. cfg_on_psoc_destroy(struct wlan_objmgr_psoc *psoc, void *context)
  445. {
  446. QDF_STATUS status;
  447. struct cfg_psoc_ctx *psoc_ctx;
  448. cfg_enter();
  449. psoc_ctx = cfg_psoc_get_ctx(psoc);
  450. status = cfg_psoc_unset_priv(psoc, psoc_ctx);
  451. cfg_store_put(psoc_ctx->store);
  452. qdf_mem_free(psoc_ctx);
  453. return status;
  454. }
  455. QDF_STATUS cfg_dispatcher_init(void)
  456. {
  457. QDF_STATUS status;
  458. cfg_enter();
  459. QDF_BUG(!__cfg_is_init);
  460. if (__cfg_is_init)
  461. return QDF_STATUS_E_INVAL;
  462. status = cfg_psoc_register_create(cfg_on_psoc_create);
  463. if (QDF_IS_STATUS_ERROR(status))
  464. return status;
  465. status = cfg_psoc_register_destroy(cfg_on_psoc_destroy);
  466. if (QDF_IS_STATUS_ERROR(status))
  467. goto unreg_create;
  468. __cfg_is_init = true;
  469. return QDF_STATUS_SUCCESS;
  470. unreg_create:
  471. cfg_assert_success(cfg_psoc_unregister_create(cfg_on_psoc_create));
  472. return status;
  473. }
  474. QDF_STATUS cfg_dispatcher_deinit(void)
  475. {
  476. cfg_enter();
  477. QDF_BUG(__cfg_is_init);
  478. if (!__cfg_is_init)
  479. return QDF_STATUS_E_INVAL;
  480. __cfg_is_init = false;
  481. cfg_assert_success(cfg_psoc_unregister_create(cfg_on_psoc_create));
  482. cfg_assert_success(cfg_psoc_unregister_destroy(cfg_on_psoc_destroy));
  483. cfg_try_deinit();
  484. return QDF_STATUS_SUCCESS;
  485. }
  486. QDF_STATUS cfg_parse(const char *path)
  487. {
  488. QDF_STATUS status;
  489. struct cfg_value_store *store;
  490. cfg_enter();
  491. QDF_BUG(!__cfg_global_store);
  492. if (__cfg_global_store)
  493. return QDF_STATUS_E_INVAL;
  494. cfg_init();
  495. status = cfg_store_alloc(path, &store);
  496. if (QDF_IS_STATUS_ERROR(status))
  497. goto deinit;
  498. cfg_store_set_defaults(store);
  499. status = cfg_ini_parse_to_store(path, store);
  500. if (QDF_IS_STATUS_ERROR(status))
  501. goto free_store;
  502. __cfg_global_store = store;
  503. return QDF_STATUS_SUCCESS;
  504. free_store:
  505. cfg_store_free(store);
  506. deinit:
  507. cfg_deinit();
  508. return status;
  509. }
  510. void cfg_release(void)
  511. {
  512. cfg_enter();
  513. QDF_BUG(__cfg_global_store);
  514. if (!__cfg_global_store)
  515. return;
  516. cfg_store_put(__cfg_global_store);
  517. __cfg_global_store = NULL;
  518. cfg_try_deinit();
  519. }
  520. QDF_STATUS cfg_psoc_parse(struct wlan_objmgr_psoc *psoc, const char *path)
  521. {
  522. QDF_STATUS status;
  523. struct cfg_value_store *store;
  524. struct cfg_psoc_ctx *psoc_ctx;
  525. cfg_enter();
  526. QDF_BUG(__cfg_global_store);
  527. if (!__cfg_global_store)
  528. return QDF_STATUS_E_INVAL;
  529. QDF_BUG(__cfg_is_init);
  530. if (!__cfg_is_init)
  531. return QDF_STATUS_E_INVAL;
  532. QDF_BUG(psoc);
  533. if (!psoc)
  534. return QDF_STATUS_E_INVAL;
  535. QDF_BUG(path);
  536. if (!path)
  537. return QDF_STATUS_E_INVAL;
  538. psoc_ctx = cfg_psoc_get_ctx(psoc);
  539. QDF_BUG(psoc_ctx->store == __cfg_global_store);
  540. if (psoc_ctx->store != __cfg_global_store)
  541. return QDF_STATUS_SUCCESS;
  542. /* check if @path has been parsed before */
  543. status = cfg_store_get(path, &store);
  544. if (QDF_IS_STATUS_ERROR(status)) {
  545. status = cfg_store_alloc(path, &store);
  546. if (QDF_IS_STATUS_ERROR(status))
  547. return status;
  548. /* inherit global configuration */
  549. qdf_mem_copy(&store->values, &__cfg_global_store->values,
  550. sizeof(store->values));
  551. status = cfg_ini_parse_to_store(path, store);
  552. if (QDF_IS_STATUS_ERROR(status))
  553. goto put_store;
  554. }
  555. psoc_ctx->store = store;
  556. cfg_store_put(__cfg_global_store);
  557. return QDF_STATUS_SUCCESS;
  558. put_store:
  559. cfg_store_put(store);
  560. return status;
  561. }