cfg.c 17 KB

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