spectral_common.c 16 KB

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