cfg.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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_INI
  240. #define __CFG_INI(_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_INI
  263. #define __CFG_INI(id, mtype, ctype, name, min, max, fallback, desc, def...) \
  264. ctype id = def;
  265. CFG_ALL
  266. #undef __CFG_INI_STRING
  267. #define __CFG_INI_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_INI
  270. #define __CFG_INI(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. QDF_STATUS cfg_parse_to_psoc_store(struct wlan_objmgr_psoc *psoc,
  416. const char *path)
  417. {
  418. return cfg_ini_parse_to_store(path, cfg_psoc_get_ctx(psoc)->store);
  419. }
  420. qdf_export_symbol(cfg_parse_to_psoc_store);
  421. QDF_STATUS cfg_parse_to_global_store(const char *path)
  422. {
  423. if (!__cfg_global_store) {
  424. cfg_err("Global INI store is not valid");
  425. return QDF_STATUS_E_NOMEM;
  426. }
  427. return cfg_ini_parse_to_store(path, __cfg_global_store);
  428. }
  429. qdf_export_symbol(cfg_parse_to_global_store);
  430. static QDF_STATUS
  431. cfg_on_psoc_create(struct wlan_objmgr_psoc *psoc, void *context)
  432. {
  433. QDF_STATUS status;
  434. struct cfg_psoc_ctx *psoc_ctx;
  435. cfg_enter();
  436. QDF_BUG(__cfg_global_store);
  437. if (!__cfg_global_store)
  438. return QDF_STATUS_E_FAILURE;
  439. psoc_ctx = qdf_mem_malloc(sizeof(*psoc_ctx));
  440. if (!psoc_ctx) {
  441. cfg_err("Out of memory");
  442. return QDF_STATUS_E_NOMEM;
  443. }
  444. qdf_atomic_inc(&__cfg_global_store->users);
  445. psoc_ctx->store = __cfg_global_store;
  446. status = cfg_psoc_set_priv(psoc, psoc_ctx);
  447. if (QDF_IS_STATUS_ERROR(status))
  448. goto put_store;
  449. return QDF_STATUS_SUCCESS;
  450. put_store:
  451. cfg_store_put(__cfg_global_store);
  452. qdf_mem_free(psoc_ctx);
  453. return status;
  454. }
  455. static QDF_STATUS
  456. cfg_on_psoc_destroy(struct wlan_objmgr_psoc *psoc, void *context)
  457. {
  458. QDF_STATUS status;
  459. struct cfg_psoc_ctx *psoc_ctx;
  460. cfg_enter();
  461. psoc_ctx = cfg_psoc_get_ctx(psoc);
  462. status = cfg_psoc_unset_priv(psoc, psoc_ctx);
  463. cfg_store_put(psoc_ctx->store);
  464. qdf_mem_free(psoc_ctx);
  465. return status;
  466. }
  467. QDF_STATUS cfg_dispatcher_init(void)
  468. {
  469. QDF_STATUS status;
  470. cfg_enter();
  471. QDF_BUG(!__cfg_is_init);
  472. if (__cfg_is_init)
  473. return QDF_STATUS_E_INVAL;
  474. qdf_list_create(&__cfg_stores_list, 0);
  475. qdf_spinlock_create(&__cfg_stores_lock);
  476. status = cfg_psoc_register_create(cfg_on_psoc_create);
  477. if (QDF_IS_STATUS_ERROR(status))
  478. return status;
  479. status = cfg_psoc_register_destroy(cfg_on_psoc_destroy);
  480. if (QDF_IS_STATUS_ERROR(status))
  481. goto unreg_create;
  482. __cfg_is_init = true;
  483. return QDF_STATUS_SUCCESS;
  484. unreg_create:
  485. cfg_assert_success(cfg_psoc_unregister_create(cfg_on_psoc_create));
  486. return status;
  487. }
  488. QDF_STATUS cfg_dispatcher_deinit(void)
  489. {
  490. cfg_enter();
  491. QDF_BUG(__cfg_is_init);
  492. if (!__cfg_is_init)
  493. return QDF_STATUS_E_INVAL;
  494. __cfg_is_init = false;
  495. cfg_assert_success(cfg_psoc_unregister_create(cfg_on_psoc_create));
  496. cfg_assert_success(cfg_psoc_unregister_destroy(cfg_on_psoc_destroy));
  497. qdf_spin_lock_bh(&__cfg_stores_lock);
  498. QDF_BUG(qdf_list_empty(&__cfg_stores_list));
  499. qdf_spin_unlock_bh(&__cfg_stores_lock);
  500. qdf_spinlock_destroy(&__cfg_stores_lock);
  501. qdf_list_destroy(&__cfg_stores_list);
  502. return QDF_STATUS_SUCCESS;
  503. }
  504. QDF_STATUS cfg_parse(const char *path)
  505. {
  506. QDF_STATUS status;
  507. struct cfg_value_store *store;
  508. cfg_enter();
  509. QDF_BUG(!__cfg_global_store);
  510. if (__cfg_global_store)
  511. return QDF_STATUS_E_INVAL;
  512. status = cfg_store_alloc(path, &store);
  513. if (QDF_IS_STATUS_ERROR(status))
  514. return status;
  515. cfg_store_set_defaults(store);
  516. status = cfg_ini_parse_to_store(path, store);
  517. if (QDF_IS_STATUS_ERROR(status))
  518. goto free_store;
  519. __cfg_global_store = store;
  520. return QDF_STATUS_SUCCESS;
  521. free_store:
  522. cfg_store_free(store);
  523. return status;
  524. }
  525. void cfg_release(void)
  526. {
  527. cfg_enter();
  528. QDF_BUG(__cfg_global_store);
  529. if (!__cfg_global_store)
  530. return;
  531. cfg_store_put(__cfg_global_store);
  532. __cfg_global_store = NULL;
  533. }
  534. QDF_STATUS cfg_psoc_parse(struct wlan_objmgr_psoc *psoc, const char *path)
  535. {
  536. QDF_STATUS status;
  537. struct cfg_value_store *store;
  538. struct cfg_psoc_ctx *psoc_ctx;
  539. cfg_enter();
  540. QDF_BUG(__cfg_global_store);
  541. if (!__cfg_global_store)
  542. return QDF_STATUS_E_INVAL;
  543. QDF_BUG(__cfg_is_init);
  544. if (!__cfg_is_init)
  545. return QDF_STATUS_E_INVAL;
  546. QDF_BUG(psoc);
  547. if (!psoc)
  548. return QDF_STATUS_E_INVAL;
  549. QDF_BUG(path);
  550. if (!path)
  551. return QDF_STATUS_E_INVAL;
  552. psoc_ctx = cfg_psoc_get_ctx(psoc);
  553. QDF_BUG(psoc_ctx->store == __cfg_global_store);
  554. if (psoc_ctx->store != __cfg_global_store)
  555. return QDF_STATUS_SUCCESS;
  556. /* check if @path has been parsed before */
  557. status = cfg_store_get(path, &store);
  558. if (QDF_IS_STATUS_ERROR(status)) {
  559. status = cfg_store_alloc(path, &store);
  560. if (QDF_IS_STATUS_ERROR(status))
  561. return status;
  562. /* inherit global configuration */
  563. qdf_mem_copy(&store->values, &__cfg_global_store->values,
  564. sizeof(store->values));
  565. status = cfg_ini_parse_to_store(path, store);
  566. if (QDF_IS_STATUS_ERROR(status))
  567. goto put_store;
  568. }
  569. psoc_ctx->store = store;
  570. cfg_store_put(__cfg_global_store);
  571. return QDF_STATUS_SUCCESS;
  572. put_store:
  573. cfg_store_put(store);
  574. return status;
  575. }
  576. qdf_export_symbol(cfg_psoc_parse);