spectral_common.c 16 KB

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