spectral_common.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /*
  2. * Copyright (c) 2011,2017-2018 The Linux Foundation. All rights reserved.
  3. *
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include "spectral_cmn_api_i.h"
  20. #include "spectral_da_api_i.h"
  21. #include "spectral_ol_api_i.h"
  22. #include <qdf_mem.h>
  23. #include <qdf_types.h>
  24. #ifdef CONFIG_WIN
  25. #include <osif_private.h>
  26. #include <wlan_mlme_dispatcher.h>
  27. #endif /*CONFIG_WIN*/
  28. #include <wlan_spectral_public_structs.h>
  29. #include <wlan_cfg80211_spectral.h>
  30. /**
  31. * spectral_get_vdev() - Get pointer to vdev to be used for Spectral
  32. * operations
  33. * @pdev: Pointer to pdev
  34. *
  35. * Spectral operates on pdev. However, in order to retrieve some WLAN
  36. * properties, a vdev is required. To facilitate this, the function returns the
  37. * first vdev in our pdev. The caller should release the reference to the vdev
  38. * once it is done using it. Additionally, the caller should ensure it has a
  39. * reference to the pdev at the time of calling this function, and should
  40. * release the pdev reference either after this function returns or at a later
  41. * time when the caller is done using pdev.
  42. * TODO:
  43. * - If the framework later provides an API to obtain the first active
  44. * vdev, then it would be preferable to use this API.
  45. * - Use a common get_vdev() handler for core and target_if using Rx ops. This
  46. * is deferred till details emerge on framework providing API to get first
  47. * active vdev.
  48. *
  49. * Return: Pointer to vdev on success, NULL on failure
  50. */
  51. static struct wlan_objmgr_vdev*
  52. spectral_get_vdev(struct wlan_objmgr_pdev *pdev)
  53. {
  54. struct wlan_objmgr_vdev *vdev = NULL;
  55. qdf_assert_always(pdev);
  56. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, 0, WLAN_SPECTRAL_ID);
  57. if (!vdev) {
  58. qdf_print("%s: Unable to get first vdev of pdev.\n", __func__);
  59. return NULL;
  60. }
  61. return vdev;
  62. }
  63. #ifndef CONFIG_MCL
  64. /**
  65. * spectral_register_cfg80211_handlers() - Register spectral cfg80211 handlers
  66. * @pdev: Pointer to pdev
  67. *
  68. * Register spectral cfg80211 handlers
  69. * Handlers can be different for WIN and MCL
  70. *
  71. * Return: None
  72. */
  73. static void
  74. spectral_register_cfg80211_handlers(struct wlan_objmgr_pdev *pdev)
  75. {
  76. wlan_cfg80211_register_spectral_cmd_handler(
  77. pdev,
  78. SPECTRAL_SCAN_START_HANDLER_IDX,
  79. wlan_cfg80211_spectral_scan_config_and_start);
  80. wlan_cfg80211_register_spectral_cmd_handler(
  81. pdev,
  82. SPECTRAL_SCAN_STOP_HANDLER_IDX,
  83. wlan_cfg80211_spectral_scan_stop);
  84. wlan_cfg80211_register_spectral_cmd_handler(
  85. pdev,
  86. SPECTRAL_SCAN_GET_CONFIG_HANDLER_IDX,
  87. wlan_cfg80211_spectral_scan_get_config);
  88. wlan_cfg80211_register_spectral_cmd_handler(
  89. pdev,
  90. SPECTRAL_SCAN_GET_DIAG_STATS_HANDLER_IDX,
  91. wlan_cfg80211_spectral_scan_get_diag_stats);
  92. wlan_cfg80211_register_spectral_cmd_handler(
  93. pdev,
  94. SPECTRAL_SCAN_GET_CAP_HANDLER_IDX,
  95. wlan_cfg80211_spectral_scan_get_cap);
  96. wlan_cfg80211_register_spectral_cmd_handler(
  97. pdev,
  98. SPECTRAL_SCAN_GET_STATUS_HANDLER_IDX,
  99. wlan_cfg80211_spectral_scan_get_status);
  100. }
  101. #else
  102. static void
  103. spectral_register_cfg80211_handlers(struct wlan_objmgr_pdev *pdev)
  104. {
  105. }
  106. #endif
  107. int
  108. spectral_control_cmn(struct wlan_objmgr_pdev *pdev,
  109. u_int id,
  110. void *indata,
  111. uint32_t insize, void *outdata, uint32_t *outsize)
  112. {
  113. int error = 0;
  114. int temp_debug;
  115. struct spectral_config sp_out;
  116. struct spectral_config *sp_in;
  117. struct spectral_config *spectralparams;
  118. struct spectral_context *sc;
  119. struct wlan_objmgr_vdev *vdev = NULL;
  120. uint8_t vdev_rxchainmask = 0;
  121. if (!pdev) {
  122. spectral_err("PDEV is NULL!\n");
  123. error = -EINVAL;
  124. goto bad;
  125. }
  126. sc = spectral_get_spectral_ctx_from_pdev(pdev);
  127. if (!sc) {
  128. spectral_err("atf context is NULL!\n");
  129. error = -EINVAL;
  130. goto bad;
  131. }
  132. switch (id) {
  133. case SPECTRAL_SET_CONFIG:
  134. {
  135. if (insize < sizeof(struct spectral_config) ||
  136. !indata) {
  137. error = -EINVAL;
  138. break;
  139. }
  140. sp_in = (struct spectral_config *)indata;
  141. if (sp_in->ss_count !=
  142. SPECTRAL_PHYERR_PARAM_NOVAL) {
  143. if (sc->sptrlc_set_spectral_config(
  144. pdev,
  145. SPECTRAL_PARAM_SCAN_COUNT,
  146. sp_in->ss_count))
  147. error = -EINVAL;
  148. }
  149. if (sp_in->ss_fft_period !=
  150. SPECTRAL_PHYERR_PARAM_NOVAL) {
  151. if (sc->sptrlc_set_spectral_config(
  152. pdev,
  153. SPECTRAL_PARAM_FFT_PERIOD,
  154. sp_in->ss_fft_period))
  155. error = -EINVAL;
  156. }
  157. if (sp_in->ss_period != SPECTRAL_PHYERR_PARAM_NOVAL) {
  158. if (sc->sptrlc_set_spectral_config(
  159. pdev,
  160. SPECTRAL_PARAM_SCAN_PERIOD,
  161. sp_in->ss_period))
  162. error = -EINVAL;
  163. }
  164. if (sp_in->ss_short_report !=
  165. SPECTRAL_PHYERR_PARAM_NOVAL) {
  166. if (sc->sptrlc_set_spectral_config(
  167. pdev,
  168. SPECTRAL_PARAM_SHORT_REPORT,
  169. (uint32_t)
  170. (sp_in->ss_short_report ? 1 : 0)))
  171. error = -EINVAL;
  172. }
  173. if (sp_in->ss_spectral_pri !=
  174. SPECTRAL_PHYERR_PARAM_NOVAL) {
  175. if (sc->sptrlc_set_spectral_config(
  176. pdev,
  177. SPECTRAL_PARAM_SPECT_PRI,
  178. (uint32_t)(sp_in->ss_spectral_pri)))
  179. error = -EINVAL;
  180. }
  181. if (sp_in->ss_fft_size != SPECTRAL_PHYERR_PARAM_NOVAL) {
  182. if (sc->sptrlc_set_spectral_config(
  183. pdev,
  184. SPECTRAL_PARAM_FFT_SIZE,
  185. sp_in->ss_fft_size))
  186. error = -EINVAL;
  187. }
  188. if (sp_in->ss_gc_ena != SPECTRAL_PHYERR_PARAM_NOVAL) {
  189. if (sc->sptrlc_set_spectral_config(
  190. pdev,
  191. SPECTRAL_PARAM_GC_ENA,
  192. sp_in->ss_gc_ena))
  193. error = -EINVAL;
  194. }
  195. if (sp_in->ss_restart_ena !=
  196. SPECTRAL_PHYERR_PARAM_NOVAL) {
  197. if (sc->sptrlc_set_spectral_config(
  198. pdev,
  199. SPECTRAL_PARAM_RESTART_ENA,
  200. sp_in->ss_restart_ena))
  201. error = -EINVAL;
  202. }
  203. if (sp_in->ss_noise_floor_ref !=
  204. SPECTRAL_PHYERR_PARAM_NOVAL) {
  205. if (sc->sptrlc_set_spectral_config(
  206. pdev,
  207. SPECTRAL_PARAM_NOISE_FLOOR_REF,
  208. sp_in->ss_noise_floor_ref))
  209. error = -EINVAL;
  210. }
  211. if (sp_in->ss_init_delay !=
  212. SPECTRAL_PHYERR_PARAM_NOVAL) {
  213. if (sc->sptrlc_set_spectral_config(
  214. pdev,
  215. SPECTRAL_PARAM_INIT_DELAY,
  216. sp_in->ss_init_delay))
  217. error = -EINVAL;
  218. }
  219. if (sp_in->ss_nb_tone_thr !=
  220. SPECTRAL_PHYERR_PARAM_NOVAL) {
  221. if (sc->sptrlc_set_spectral_config(
  222. pdev,
  223. SPECTRAL_PARAM_NB_TONE_THR,
  224. sp_in->ss_nb_tone_thr))
  225. error = -EINVAL;
  226. }
  227. if (sp_in->ss_str_bin_thr !=
  228. SPECTRAL_PHYERR_PARAM_NOVAL) {
  229. if (sc->sptrlc_set_spectral_config(
  230. pdev,
  231. SPECTRAL_PARAM_STR_BIN_THR,
  232. sp_in->ss_str_bin_thr))
  233. error = -EINVAL;
  234. }
  235. if (sp_in->ss_wb_rpt_mode !=
  236. SPECTRAL_PHYERR_PARAM_NOVAL) {
  237. if (sc->sptrlc_set_spectral_config(
  238. pdev,
  239. SPECTRAL_PARAM_WB_RPT_MODE,
  240. sp_in->ss_wb_rpt_mode))
  241. error = -EINVAL;
  242. }
  243. if (sp_in->ss_rssi_rpt_mode !=
  244. SPECTRAL_PHYERR_PARAM_NOVAL) {
  245. if (sc->sptrlc_set_spectral_config(
  246. pdev,
  247. SPECTRAL_PARAM_RSSI_RPT_MODE,
  248. sp_in->ss_rssi_rpt_mode))
  249. error = -EINVAL;
  250. }
  251. if (sp_in->ss_rssi_thr != SPECTRAL_PHYERR_PARAM_NOVAL) {
  252. if (sc->sptrlc_set_spectral_config(
  253. pdev,
  254. SPECTRAL_PARAM_RSSI_THR,
  255. sp_in->ss_rssi_thr))
  256. error = -EINVAL;
  257. }
  258. if (sp_in->ss_pwr_format !=
  259. SPECTRAL_PHYERR_PARAM_NOVAL) {
  260. if (sc->sptrlc_set_spectral_config(
  261. pdev,
  262. SPECTRAL_PARAM_PWR_FORMAT,
  263. sp_in->ss_pwr_format))
  264. error = -EINVAL;
  265. }
  266. if (sp_in->ss_rpt_mode != SPECTRAL_PHYERR_PARAM_NOVAL) {
  267. if (sc->sptrlc_set_spectral_config(
  268. pdev,
  269. SPECTRAL_PARAM_RPT_MODE,
  270. sp_in->ss_rpt_mode))
  271. error = -EINVAL;
  272. }
  273. if (sp_in->ss_bin_scale !=
  274. SPECTRAL_PHYERR_PARAM_NOVAL) {
  275. if (sc->sptrlc_set_spectral_config(
  276. pdev,
  277. SPECTRAL_PARAM_BIN_SCALE,
  278. sp_in->ss_bin_scale))
  279. error = -EINVAL;
  280. }
  281. if (sp_in->ss_dbm_adj != SPECTRAL_PHYERR_PARAM_NOVAL) {
  282. if (sc->sptrlc_set_spectral_config(
  283. pdev,
  284. SPECTRAL_PARAM_DBM_ADJ,
  285. sp_in->ss_dbm_adj))
  286. error = -EINVAL;
  287. }
  288. if (sp_in->ss_chn_mask != SPECTRAL_PHYERR_PARAM_NOVAL) {
  289. /*
  290. * Check if any of the inactive Rx antenna
  291. * chains is set active in spectral chainmask
  292. */
  293. vdev = spectral_get_vdev(pdev);
  294. if (!vdev) {
  295. error = -ENOENT;
  296. break;
  297. }
  298. vdev_rxchainmask =
  299. wlan_vdev_mlme_get_rxchainmask(vdev);
  300. wlan_objmgr_vdev_release_ref(vdev,
  301. WLAN_SPECTRAL_ID);
  302. if (!(sp_in->ss_chn_mask & vdev_rxchainmask)) {
  303. qdf_print
  304. ("Invalid Spectral Chainmask - "
  305. "Inactive Rx antenna chain cannot "
  306. "be an active spectral chain\n");
  307. error = -EINVAL;
  308. break;
  309. } else if (sc->sptrlc_set_spectral_config(
  310. pdev,
  311. SPECTRAL_PARAM_CHN_MASK,
  312. sp_in->ss_chn_mask)) {
  313. error = -EINVAL;
  314. }
  315. }
  316. }
  317. break;
  318. case SPECTRAL_GET_CONFIG:
  319. {
  320. if (!outdata || !outsize ||
  321. (*outsize < sizeof(struct spectral_config))) {
  322. error = -EINVAL;
  323. break;
  324. }
  325. *outsize = sizeof(struct spectral_config);
  326. sc->sptrlc_get_spectral_config(pdev, &sp_out);
  327. spectralparams = (struct spectral_config *)outdata;
  328. spectralparams->ss_fft_period = sp_out.ss_fft_period;
  329. spectralparams->ss_period = sp_out.ss_period;
  330. spectralparams->ss_count = sp_out.ss_count;
  331. spectralparams->ss_short_report =
  332. sp_out.ss_short_report;
  333. spectralparams->ss_spectral_pri =
  334. sp_out.ss_spectral_pri;
  335. spectralparams->ss_fft_size = sp_out.ss_fft_size;
  336. spectralparams->ss_gc_ena = sp_out.ss_gc_ena;
  337. spectralparams->ss_restart_ena = sp_out.ss_restart_ena;
  338. spectralparams->ss_noise_floor_ref =
  339. sp_out.ss_noise_floor_ref;
  340. spectralparams->ss_init_delay = sp_out.ss_init_delay;
  341. spectralparams->ss_nb_tone_thr = sp_out.ss_nb_tone_thr;
  342. spectralparams->ss_str_bin_thr = sp_out.ss_str_bin_thr;
  343. spectralparams->ss_wb_rpt_mode = sp_out.ss_wb_rpt_mode;
  344. spectralparams->ss_rssi_rpt_mode =
  345. sp_out.ss_rssi_rpt_mode;
  346. spectralparams->ss_rssi_thr = sp_out.ss_rssi_thr;
  347. spectralparams->ss_pwr_format = sp_out.ss_pwr_format;
  348. spectralparams->ss_rpt_mode = sp_out.ss_rpt_mode;
  349. spectralparams->ss_bin_scale = sp_out.ss_bin_scale;
  350. spectralparams->ss_dbm_adj = sp_out.ss_dbm_adj;
  351. spectralparams->ss_chn_mask = sp_out.ss_chn_mask;
  352. }
  353. break;
  354. case SPECTRAL_IS_ACTIVE:
  355. {
  356. if (!outdata || !outsize ||
  357. *outsize < sizeof(uint32_t)) {
  358. error = -EINVAL;
  359. break;
  360. }
  361. *outsize = sizeof(uint32_t);
  362. *((uint32_t *)outdata) =
  363. (uint32_t)sc->sptrlc_is_spectral_active(pdev);
  364. }
  365. break;
  366. case SPECTRAL_IS_ENABLED:
  367. {
  368. if (!outdata || !outsize ||
  369. *outsize < sizeof(uint32_t)) {
  370. error = -EINVAL;
  371. break;
  372. }
  373. *outsize = sizeof(uint32_t);
  374. *((uint32_t *)outdata) =
  375. (uint32_t)sc->sptrlc_is_spectral_enabled(pdev);
  376. }
  377. break;
  378. case SPECTRAL_SET_DEBUG_LEVEL:
  379. {
  380. if (insize < sizeof(uint32_t) || !indata) {
  381. error = -EINVAL;
  382. break;
  383. }
  384. temp_debug = *(uint32_t *)indata;
  385. sc->sptrlc_set_debug_level(pdev, temp_debug);
  386. }
  387. break;
  388. case SPECTRAL_GET_DEBUG_LEVEL:
  389. {
  390. if (!outdata || !outsize ||
  391. *outsize < sizeof(uint32_t)) {
  392. error = -EINVAL;
  393. break;
  394. }
  395. *outsize = sizeof(uint32_t);
  396. *((uint32_t *)outdata) =
  397. (uint32_t)sc->sptrlc_get_debug_level(pdev);
  398. }
  399. break;
  400. case SPECTRAL_ACTIVATE_SCAN:
  401. {
  402. sc->sptrlc_start_spectral_scan(pdev);
  403. }
  404. break;
  405. case SPECTRAL_STOP_SCAN:
  406. {
  407. sc->sptrlc_stop_spectral_scan(pdev);
  408. }
  409. break;
  410. case SPECTRAL_GET_CAPABILITY_INFO:
  411. {
  412. if (!outdata || !outsize ||
  413. *outsize < sizeof(struct spectral_caps)) {
  414. error = -EINVAL;
  415. break;
  416. }
  417. *outsize = sizeof(struct spectral_caps);
  418. sc->sptrlc_get_spectral_capinfo(pdev, outdata);
  419. }
  420. break;
  421. case SPECTRAL_GET_DIAG_STATS:
  422. {
  423. if (!outdata || !outsize ||
  424. (*outsize < sizeof(struct spectral_diag_stats))) {
  425. error = -EINVAL;
  426. break;
  427. }
  428. *outsize = sizeof(struct spectral_diag_stats);
  429. sc->sptrlc_get_spectral_diagstats(pdev, outdata);
  430. }
  431. break;
  432. case SPECTRAL_GET_CHAN_WIDTH:
  433. {
  434. uint32_t chan_width;
  435. vdev = spectral_get_vdev(pdev);
  436. if (!vdev)
  437. return -ENOENT;
  438. chan_width = spectral_vdev_get_ch_width(vdev);
  439. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  440. if (!outdata || !outsize ||
  441. *outsize < sizeof(chan_width)) {
  442. error = -EINVAL;
  443. break;
  444. }
  445. *outsize = sizeof(chan_width);
  446. *((uint32_t *)outdata) = (uint32_t)chan_width;
  447. }
  448. break;
  449. default:
  450. error = -EINVAL;
  451. break;
  452. }
  453. bad:
  454. return error;
  455. }
  456. /**
  457. * spectral_ctx_deinit() - De-initialize function pointers from spectral context
  458. * @sc - Reference to spectral_context object
  459. *
  460. * Return: None
  461. */
  462. static void
  463. spectral_ctx_deinit(struct spectral_context *sc)
  464. {
  465. if (sc) {
  466. sc->sptrlc_ucfg_phyerr_config = NULL;
  467. sc->sptrlc_pdev_spectral_init = NULL;
  468. sc->sptrlc_pdev_spectral_deinit = NULL;
  469. sc->sptrlc_set_spectral_config = NULL;
  470. sc->sptrlc_get_spectral_config = NULL;
  471. sc->sptrlc_start_spectral_scan = NULL;
  472. sc->sptrlc_stop_spectral_scan = NULL;
  473. sc->sptrlc_is_spectral_active = NULL;
  474. sc->sptrlc_is_spectral_enabled = NULL;
  475. sc->sptrlc_set_debug_level = NULL;
  476. sc->sptrlc_get_debug_level = NULL;
  477. sc->sptrlc_get_spectral_capinfo = NULL;
  478. sc->sptrlc_get_spectral_diagstats = NULL;
  479. }
  480. }
  481. QDF_STATUS
  482. wlan_spectral_psoc_obj_create_handler(struct wlan_objmgr_psoc *psoc, void *arg)
  483. {
  484. struct spectral_context *sc = NULL;
  485. if (!psoc) {
  486. spectral_err("PSOC is NULL\n");
  487. return QDF_STATUS_E_FAILURE;
  488. }
  489. sc = (struct spectral_context *)
  490. qdf_mem_malloc(sizeof(struct spectral_context));
  491. if (!sc) {
  492. spectral_err("Failed to allocate spectral_ctx object\n");
  493. return QDF_STATUS_E_NOMEM;
  494. }
  495. qdf_mem_zero(sc, sizeof(struct spectral_context));
  496. sc->psoc_obj = psoc;
  497. if (wlan_objmgr_psoc_get_dev_type(psoc) == WLAN_DEV_OL)
  498. spectral_ctx_init_ol(sc);
  499. #ifdef CONFIG_WIN
  500. else if (wlan_objmgr_psoc_get_dev_type(psoc) == WLAN_DEV_DA)
  501. spectral_ctx_init_da(sc);
  502. #endif
  503. wlan_objmgr_psoc_component_obj_attach(psoc, WLAN_UMAC_COMP_SPECTRAL,
  504. (void *)sc, QDF_STATUS_SUCCESS);
  505. return QDF_STATUS_SUCCESS;
  506. }
  507. QDF_STATUS
  508. wlan_spectral_psoc_obj_destroy_handler(struct wlan_objmgr_psoc *psoc,
  509. void *arg)
  510. {
  511. struct spectral_context *sc = NULL;
  512. if (!psoc) {
  513. spectral_err("PSOC is NULL\n");
  514. return QDF_STATUS_E_FAILURE;
  515. }
  516. sc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
  517. WLAN_UMAC_COMP_SPECTRAL);
  518. if (sc) {
  519. wlan_objmgr_psoc_component_obj_detach(psoc,
  520. WLAN_UMAC_COMP_SPECTRAL,
  521. (void *)sc);
  522. /* Deinitilise function pointers from spectral context */
  523. spectral_ctx_deinit(sc);
  524. qdf_mem_free(sc);
  525. }
  526. return QDF_STATUS_SUCCESS;
  527. }
  528. QDF_STATUS
  529. wlan_spectral_pdev_obj_create_handler(struct wlan_objmgr_pdev *pdev, void *arg)
  530. {
  531. struct pdev_spectral *ps = NULL;
  532. struct spectral_context *sc = NULL;
  533. void *target_handle = NULL;
  534. if (!pdev) {
  535. spectral_err("PDEV is NULL\n");
  536. return QDF_STATUS_E_FAILURE;
  537. }
  538. ps = (struct pdev_spectral *)
  539. qdf_mem_malloc(sizeof(struct pdev_spectral));
  540. if (!ps) {
  541. spectral_err("Failed to allocate pdev_spectral object\n");
  542. return QDF_STATUS_E_NOMEM;
  543. }
  544. sc = spectral_get_spectral_ctx_from_pdev(pdev);
  545. if (!sc) {
  546. spectral_err("Spectral context is NULL!\n");
  547. goto cleanup;
  548. }
  549. qdf_mem_zero(ps, sizeof(struct pdev_spectral));
  550. ps->psptrl_pdev = pdev;
  551. spectral_register_cfg80211_handlers(pdev);
  552. if (sc->sptrlc_pdev_spectral_init) {
  553. target_handle = sc->sptrlc_pdev_spectral_init(pdev);
  554. if (!target_handle) {
  555. spectral_err("Spectral lmac object is NULL!\n");
  556. goto cleanup;
  557. }
  558. ps->psptrl_target_handle = target_handle;
  559. }
  560. wlan_objmgr_pdev_component_obj_attach(pdev, WLAN_UMAC_COMP_SPECTRAL,
  561. (void *)ps, QDF_STATUS_SUCCESS);
  562. return QDF_STATUS_SUCCESS;
  563. cleanup:
  564. qdf_mem_free(ps);
  565. return QDF_STATUS_E_FAILURE;
  566. }
  567. QDF_STATUS
  568. wlan_spectral_pdev_obj_destroy_handler(struct wlan_objmgr_pdev *pdev,
  569. void *arg)
  570. {
  571. struct pdev_spectral *ps = NULL;
  572. struct spectral_context *sc = NULL;
  573. if (!pdev) {
  574. spectral_err("PDEV is NULL\n");
  575. return QDF_STATUS_E_FAILURE;
  576. }
  577. sc = spectral_get_spectral_ctx_from_pdev(pdev);
  578. if (!sc) {
  579. spectral_err("Spectral context is NULL!\n");
  580. return QDF_STATUS_E_FAILURE;
  581. }
  582. ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
  583. WLAN_UMAC_COMP_SPECTRAL);
  584. if (ps) {
  585. if (sc->sptrlc_pdev_spectral_deinit)
  586. sc->sptrlc_pdev_spectral_deinit(pdev);
  587. ps->psptrl_target_handle = NULL;
  588. wlan_objmgr_pdev_component_obj_detach(pdev,
  589. WLAN_UMAC_COMP_SPECTRAL,
  590. (void *)ps);
  591. qdf_mem_free(ps);
  592. }
  593. return QDF_STATUS_SUCCESS;
  594. }