spectral_common.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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_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. /**
  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. static 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_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  55. if (!vdev) {
  56. spectral_warn("Unable to get first vdev of pdev");
  57. return NULL;
  58. }
  59. return vdev;
  60. }
  61. #ifndef CONFIG_MCL
  62. /**
  63. * spectral_register_cfg80211_handlers() - Register spectral cfg80211 handlers
  64. * @pdev: Pointer to pdev
  65. *
  66. * Register spectral cfg80211 handlers
  67. * Handlers can be different for WIN and MCL
  68. *
  69. * Return: None
  70. */
  71. static void
  72. spectral_register_cfg80211_handlers(struct wlan_objmgr_pdev *pdev)
  73. {
  74. wlan_cfg80211_register_spectral_cmd_handler(
  75. pdev,
  76. SPECTRAL_SCAN_START_HANDLER_IDX,
  77. wlan_cfg80211_spectral_scan_config_and_start);
  78. wlan_cfg80211_register_spectral_cmd_handler(
  79. pdev,
  80. SPECTRAL_SCAN_STOP_HANDLER_IDX,
  81. wlan_cfg80211_spectral_scan_stop);
  82. wlan_cfg80211_register_spectral_cmd_handler(
  83. pdev,
  84. SPECTRAL_SCAN_GET_CONFIG_HANDLER_IDX,
  85. wlan_cfg80211_spectral_scan_get_config);
  86. wlan_cfg80211_register_spectral_cmd_handler(
  87. pdev,
  88. SPECTRAL_SCAN_GET_DIAG_STATS_HANDLER_IDX,
  89. wlan_cfg80211_spectral_scan_get_diag_stats);
  90. wlan_cfg80211_register_spectral_cmd_handler(
  91. pdev,
  92. SPECTRAL_SCAN_GET_CAP_HANDLER_IDX,
  93. wlan_cfg80211_spectral_scan_get_cap);
  94. wlan_cfg80211_register_spectral_cmd_handler(
  95. pdev,
  96. SPECTRAL_SCAN_GET_STATUS_HANDLER_IDX,
  97. wlan_cfg80211_spectral_scan_get_status);
  98. }
  99. #else
  100. static void
  101. spectral_register_cfg80211_handlers(struct wlan_objmgr_pdev *pdev)
  102. {
  103. }
  104. #endif
  105. int
  106. spectral_control_cmn(struct wlan_objmgr_pdev *pdev,
  107. u_int id,
  108. void *indata,
  109. uint32_t insize, void *outdata, uint32_t *outsize)
  110. {
  111. int error = 0;
  112. int temp_debug;
  113. struct spectral_config sp_out;
  114. struct spectral_config *sp_in;
  115. struct spectral_config *spectralparams;
  116. struct spectral_context *sc;
  117. struct wlan_objmgr_vdev *vdev = NULL;
  118. uint8_t vdev_rxchainmask = 0;
  119. if (!pdev) {
  120. spectral_err("PDEV is NULL!");
  121. error = -EINVAL;
  122. goto bad;
  123. }
  124. sc = spectral_get_spectral_ctx_from_pdev(pdev);
  125. if (!sc) {
  126. spectral_err("atf context is NULL!");
  127. error = -EINVAL;
  128. goto bad;
  129. }
  130. switch (id) {
  131. case SPECTRAL_SET_CONFIG:
  132. {
  133. if (insize < sizeof(struct spectral_config) ||
  134. !indata) {
  135. error = -EINVAL;
  136. break;
  137. }
  138. sp_in = (struct spectral_config *)indata;
  139. if (sp_in->ss_count !=
  140. SPECTRAL_PHYERR_PARAM_NOVAL) {
  141. if (sc->sptrlc_set_spectral_config(
  142. pdev,
  143. SPECTRAL_PARAM_SCAN_COUNT,
  144. sp_in->ss_count))
  145. error = -EINVAL;
  146. }
  147. if (sp_in->ss_fft_period !=
  148. SPECTRAL_PHYERR_PARAM_NOVAL) {
  149. if (sc->sptrlc_set_spectral_config(
  150. pdev,
  151. SPECTRAL_PARAM_FFT_PERIOD,
  152. sp_in->ss_fft_period))
  153. error = -EINVAL;
  154. }
  155. if (sp_in->ss_period != SPECTRAL_PHYERR_PARAM_NOVAL) {
  156. if (sc->sptrlc_set_spectral_config(
  157. pdev,
  158. SPECTRAL_PARAM_SCAN_PERIOD,
  159. sp_in->ss_period))
  160. error = -EINVAL;
  161. }
  162. if (sp_in->ss_short_report !=
  163. SPECTRAL_PHYERR_PARAM_NOVAL) {
  164. if (sc->sptrlc_set_spectral_config(
  165. pdev,
  166. SPECTRAL_PARAM_SHORT_REPORT,
  167. (uint32_t)
  168. (sp_in->ss_short_report ? 1 : 0)))
  169. error = -EINVAL;
  170. }
  171. if (sp_in->ss_spectral_pri !=
  172. SPECTRAL_PHYERR_PARAM_NOVAL) {
  173. if (sc->sptrlc_set_spectral_config(
  174. pdev,
  175. SPECTRAL_PARAM_SPECT_PRI,
  176. (uint32_t)(sp_in->ss_spectral_pri)))
  177. error = -EINVAL;
  178. }
  179. if (sp_in->ss_fft_size != SPECTRAL_PHYERR_PARAM_NOVAL) {
  180. if (sc->sptrlc_set_spectral_config(
  181. pdev,
  182. SPECTRAL_PARAM_FFT_SIZE,
  183. sp_in->ss_fft_size))
  184. error = -EINVAL;
  185. }
  186. if (sp_in->ss_gc_ena != SPECTRAL_PHYERR_PARAM_NOVAL) {
  187. if (sc->sptrlc_set_spectral_config(
  188. pdev,
  189. SPECTRAL_PARAM_GC_ENA,
  190. sp_in->ss_gc_ena))
  191. error = -EINVAL;
  192. }
  193. if (sp_in->ss_restart_ena !=
  194. SPECTRAL_PHYERR_PARAM_NOVAL) {
  195. if (sc->sptrlc_set_spectral_config(
  196. pdev,
  197. SPECTRAL_PARAM_RESTART_ENA,
  198. sp_in->ss_restart_ena))
  199. error = -EINVAL;
  200. }
  201. if (sp_in->ss_noise_floor_ref !=
  202. SPECTRAL_PHYERR_PARAM_NOVAL) {
  203. if (sc->sptrlc_set_spectral_config(
  204. pdev,
  205. SPECTRAL_PARAM_NOISE_FLOOR_REF,
  206. sp_in->ss_noise_floor_ref))
  207. error = -EINVAL;
  208. }
  209. if (sp_in->ss_init_delay !=
  210. SPECTRAL_PHYERR_PARAM_NOVAL) {
  211. if (sc->sptrlc_set_spectral_config(
  212. pdev,
  213. SPECTRAL_PARAM_INIT_DELAY,
  214. sp_in->ss_init_delay))
  215. error = -EINVAL;
  216. }
  217. if (sp_in->ss_nb_tone_thr !=
  218. SPECTRAL_PHYERR_PARAM_NOVAL) {
  219. if (sc->sptrlc_set_spectral_config(
  220. pdev,
  221. SPECTRAL_PARAM_NB_TONE_THR,
  222. sp_in->ss_nb_tone_thr))
  223. error = -EINVAL;
  224. }
  225. if (sp_in->ss_str_bin_thr !=
  226. SPECTRAL_PHYERR_PARAM_NOVAL) {
  227. if (sc->sptrlc_set_spectral_config(
  228. pdev,
  229. SPECTRAL_PARAM_STR_BIN_THR,
  230. sp_in->ss_str_bin_thr))
  231. error = -EINVAL;
  232. }
  233. if (sp_in->ss_wb_rpt_mode !=
  234. SPECTRAL_PHYERR_PARAM_NOVAL) {
  235. if (sc->sptrlc_set_spectral_config(
  236. pdev,
  237. SPECTRAL_PARAM_WB_RPT_MODE,
  238. sp_in->ss_wb_rpt_mode))
  239. error = -EINVAL;
  240. }
  241. if (sp_in->ss_rssi_rpt_mode !=
  242. SPECTRAL_PHYERR_PARAM_NOVAL) {
  243. if (sc->sptrlc_set_spectral_config(
  244. pdev,
  245. SPECTRAL_PARAM_RSSI_RPT_MODE,
  246. sp_in->ss_rssi_rpt_mode))
  247. error = -EINVAL;
  248. }
  249. if (sp_in->ss_rssi_thr != SPECTRAL_PHYERR_PARAM_NOVAL) {
  250. if (sc->sptrlc_set_spectral_config(
  251. pdev,
  252. SPECTRAL_PARAM_RSSI_THR,
  253. sp_in->ss_rssi_thr))
  254. error = -EINVAL;
  255. }
  256. if (sp_in->ss_pwr_format !=
  257. SPECTRAL_PHYERR_PARAM_NOVAL) {
  258. if (sc->sptrlc_set_spectral_config(
  259. pdev,
  260. SPECTRAL_PARAM_PWR_FORMAT,
  261. sp_in->ss_pwr_format))
  262. error = -EINVAL;
  263. }
  264. if (sp_in->ss_rpt_mode != SPECTRAL_PHYERR_PARAM_NOVAL) {
  265. if (sc->sptrlc_set_spectral_config(
  266. pdev,
  267. SPECTRAL_PARAM_RPT_MODE,
  268. sp_in->ss_rpt_mode))
  269. error = -EINVAL;
  270. }
  271. if (sp_in->ss_bin_scale !=
  272. SPECTRAL_PHYERR_PARAM_NOVAL) {
  273. if (sc->sptrlc_set_spectral_config(
  274. pdev,
  275. SPECTRAL_PARAM_BIN_SCALE,
  276. sp_in->ss_bin_scale))
  277. error = -EINVAL;
  278. }
  279. if (sp_in->ss_dbm_adj != SPECTRAL_PHYERR_PARAM_NOVAL) {
  280. if (sc->sptrlc_set_spectral_config(
  281. pdev,
  282. SPECTRAL_PARAM_DBM_ADJ,
  283. sp_in->ss_dbm_adj))
  284. error = -EINVAL;
  285. }
  286. if (sp_in->ss_chn_mask != SPECTRAL_PHYERR_PARAM_NOVAL) {
  287. /*
  288. * Check if any of the inactive Rx antenna
  289. * chains is set active in spectral chainmask
  290. */
  291. vdev = spectral_get_vdev(pdev);
  292. if (!vdev) {
  293. error = -ENOENT;
  294. break;
  295. }
  296. vdev_rxchainmask =
  297. wlan_vdev_mlme_get_rxchainmask(vdev);
  298. wlan_objmgr_vdev_release_ref(vdev,
  299. WLAN_SPECTRAL_ID);
  300. if (!(sp_in->ss_chn_mask & vdev_rxchainmask)) {
  301. spectral_err("Invalid Spectral Chainmask - Inactive Rx antenna chain cannot be an active spectral chain");
  302. error = -EINVAL;
  303. break;
  304. } else if (sc->sptrlc_set_spectral_config(
  305. pdev,
  306. SPECTRAL_PARAM_CHN_MASK,
  307. sp_in->ss_chn_mask)) {
  308. error = -EINVAL;
  309. }
  310. }
  311. }
  312. break;
  313. case SPECTRAL_GET_CONFIG:
  314. {
  315. if (!outdata || !outsize ||
  316. (*outsize < sizeof(struct spectral_config))) {
  317. error = -EINVAL;
  318. break;
  319. }
  320. *outsize = sizeof(struct spectral_config);
  321. sc->sptrlc_get_spectral_config(pdev, &sp_out);
  322. spectralparams = (struct spectral_config *)outdata;
  323. spectralparams->ss_fft_period = sp_out.ss_fft_period;
  324. spectralparams->ss_period = sp_out.ss_period;
  325. spectralparams->ss_count = sp_out.ss_count;
  326. spectralparams->ss_short_report =
  327. sp_out.ss_short_report;
  328. spectralparams->ss_spectral_pri =
  329. sp_out.ss_spectral_pri;
  330. spectralparams->ss_fft_size = sp_out.ss_fft_size;
  331. spectralparams->ss_gc_ena = sp_out.ss_gc_ena;
  332. spectralparams->ss_restart_ena = sp_out.ss_restart_ena;
  333. spectralparams->ss_noise_floor_ref =
  334. sp_out.ss_noise_floor_ref;
  335. spectralparams->ss_init_delay = sp_out.ss_init_delay;
  336. spectralparams->ss_nb_tone_thr = sp_out.ss_nb_tone_thr;
  337. spectralparams->ss_str_bin_thr = sp_out.ss_str_bin_thr;
  338. spectralparams->ss_wb_rpt_mode = sp_out.ss_wb_rpt_mode;
  339. spectralparams->ss_rssi_rpt_mode =
  340. sp_out.ss_rssi_rpt_mode;
  341. spectralparams->ss_rssi_thr = sp_out.ss_rssi_thr;
  342. spectralparams->ss_pwr_format = sp_out.ss_pwr_format;
  343. spectralparams->ss_rpt_mode = sp_out.ss_rpt_mode;
  344. spectralparams->ss_bin_scale = sp_out.ss_bin_scale;
  345. spectralparams->ss_dbm_adj = sp_out.ss_dbm_adj;
  346. spectralparams->ss_chn_mask = sp_out.ss_chn_mask;
  347. }
  348. break;
  349. case SPECTRAL_IS_ACTIVE:
  350. {
  351. if (!outdata || !outsize ||
  352. *outsize < sizeof(uint32_t)) {
  353. error = -EINVAL;
  354. break;
  355. }
  356. *outsize = sizeof(uint32_t);
  357. *((uint32_t *)outdata) =
  358. (uint32_t)sc->sptrlc_is_spectral_active(pdev);
  359. }
  360. break;
  361. case SPECTRAL_IS_ENABLED:
  362. {
  363. if (!outdata || !outsize ||
  364. *outsize < sizeof(uint32_t)) {
  365. error = -EINVAL;
  366. break;
  367. }
  368. *outsize = sizeof(uint32_t);
  369. *((uint32_t *)outdata) =
  370. (uint32_t)sc->sptrlc_is_spectral_enabled(pdev);
  371. }
  372. break;
  373. case SPECTRAL_SET_DEBUG_LEVEL:
  374. {
  375. if (insize < sizeof(uint32_t) || !indata) {
  376. error = -EINVAL;
  377. break;
  378. }
  379. temp_debug = *(uint32_t *)indata;
  380. sc->sptrlc_set_debug_level(pdev, temp_debug);
  381. }
  382. break;
  383. case SPECTRAL_GET_DEBUG_LEVEL:
  384. {
  385. if (!outdata || !outsize ||
  386. *outsize < sizeof(uint32_t)) {
  387. error = -EINVAL;
  388. break;
  389. }
  390. *outsize = sizeof(uint32_t);
  391. *((uint32_t *)outdata) =
  392. (uint32_t)sc->sptrlc_get_debug_level(pdev);
  393. }
  394. break;
  395. case SPECTRAL_ACTIVATE_SCAN:
  396. {
  397. sc->sptrlc_start_spectral_scan(pdev);
  398. }
  399. break;
  400. case SPECTRAL_STOP_SCAN:
  401. {
  402. sc->sptrlc_stop_spectral_scan(pdev);
  403. }
  404. break;
  405. case SPECTRAL_GET_CAPABILITY_INFO:
  406. {
  407. if (!outdata || !outsize ||
  408. *outsize < sizeof(struct spectral_caps)) {
  409. error = -EINVAL;
  410. break;
  411. }
  412. *outsize = sizeof(struct spectral_caps);
  413. sc->sptrlc_get_spectral_capinfo(pdev, outdata);
  414. }
  415. break;
  416. case SPECTRAL_GET_DIAG_STATS:
  417. {
  418. if (!outdata || !outsize ||
  419. (*outsize < sizeof(struct spectral_diag_stats))) {
  420. error = -EINVAL;
  421. break;
  422. }
  423. *outsize = sizeof(struct spectral_diag_stats);
  424. sc->sptrlc_get_spectral_diagstats(pdev, outdata);
  425. }
  426. break;
  427. case SPECTRAL_GET_CHAN_WIDTH:
  428. {
  429. uint32_t chan_width;
  430. vdev = spectral_get_vdev(pdev);
  431. if (!vdev)
  432. return -ENOENT;
  433. chan_width = spectral_vdev_get_ch_width(vdev);
  434. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  435. if (!outdata || !outsize ||
  436. *outsize < sizeof(chan_width)) {
  437. error = -EINVAL;
  438. break;
  439. }
  440. *outsize = sizeof(chan_width);
  441. *((uint32_t *)outdata) = (uint32_t)chan_width;
  442. }
  443. break;
  444. default:
  445. error = -EINVAL;
  446. break;
  447. }
  448. bad:
  449. return error;
  450. }
  451. /**
  452. * spectral_ctx_deinit() - De-initialize function pointers from spectral context
  453. * @sc - Reference to spectral_context object
  454. *
  455. * Return: None
  456. */
  457. static void
  458. spectral_ctx_deinit(struct spectral_context *sc)
  459. {
  460. if (sc) {
  461. sc->sptrlc_ucfg_phyerr_config = NULL;
  462. sc->sptrlc_pdev_spectral_init = NULL;
  463. sc->sptrlc_pdev_spectral_deinit = NULL;
  464. sc->sptrlc_set_spectral_config = NULL;
  465. sc->sptrlc_get_spectral_config = NULL;
  466. sc->sptrlc_start_spectral_scan = NULL;
  467. sc->sptrlc_stop_spectral_scan = NULL;
  468. sc->sptrlc_is_spectral_active = NULL;
  469. sc->sptrlc_is_spectral_enabled = NULL;
  470. sc->sptrlc_set_debug_level = NULL;
  471. sc->sptrlc_get_debug_level = NULL;
  472. sc->sptrlc_get_spectral_capinfo = NULL;
  473. sc->sptrlc_get_spectral_diagstats = NULL;
  474. }
  475. }
  476. #ifdef DA_SUPPORT
  477. /**
  478. * wlan_spectral_init_da() - init context of DA devices
  479. *
  480. * init context of DA device
  481. *
  482. * Return: void
  483. */
  484. static void
  485. wlan_spectral_init_da(struct spectral_context *sc)
  486. {
  487. spectral_ctx_init_da(sc);
  488. }
  489. #else
  490. static void
  491. wlan_spectral_init_da(struct spectral_context *sc)
  492. {
  493. }
  494. #endif
  495. QDF_STATUS
  496. wlan_spectral_psoc_obj_create_handler(struct wlan_objmgr_psoc *psoc, void *arg)
  497. {
  498. struct spectral_context *sc = NULL;
  499. if (!psoc) {
  500. spectral_err("PSOC is NULL");
  501. return QDF_STATUS_E_FAILURE;
  502. }
  503. sc = (struct spectral_context *)
  504. qdf_mem_malloc(sizeof(struct spectral_context));
  505. if (!sc) {
  506. spectral_err("Failed to allocate spectral_ctx object");
  507. return QDF_STATUS_E_NOMEM;
  508. }
  509. qdf_mem_zero(sc, sizeof(struct spectral_context));
  510. sc->psoc_obj = psoc;
  511. if (wlan_objmgr_psoc_get_dev_type(psoc) == WLAN_DEV_OL)
  512. spectral_ctx_init_ol(sc);
  513. else if (wlan_objmgr_psoc_get_dev_type(psoc) == WLAN_DEV_DA)
  514. wlan_spectral_init_da(sc);
  515. wlan_objmgr_psoc_component_obj_attach(psoc, WLAN_UMAC_COMP_SPECTRAL,
  516. (void *)sc, QDF_STATUS_SUCCESS);
  517. return QDF_STATUS_SUCCESS;
  518. }
  519. QDF_STATUS
  520. wlan_spectral_psoc_obj_destroy_handler(struct wlan_objmgr_psoc *psoc,
  521. void *arg)
  522. {
  523. struct spectral_context *sc = NULL;
  524. if (!psoc) {
  525. spectral_err("PSOC is NULL");
  526. return QDF_STATUS_E_FAILURE;
  527. }
  528. sc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
  529. WLAN_UMAC_COMP_SPECTRAL);
  530. if (sc) {
  531. wlan_objmgr_psoc_component_obj_detach(psoc,
  532. WLAN_UMAC_COMP_SPECTRAL,
  533. (void *)sc);
  534. /* Deinitilise function pointers from spectral context */
  535. spectral_ctx_deinit(sc);
  536. qdf_mem_free(sc);
  537. }
  538. return QDF_STATUS_SUCCESS;
  539. }
  540. QDF_STATUS
  541. wlan_spectral_pdev_obj_create_handler(struct wlan_objmgr_pdev *pdev, void *arg)
  542. {
  543. struct pdev_spectral *ps = NULL;
  544. struct spectral_context *sc = NULL;
  545. void *target_handle = NULL;
  546. if (!pdev) {
  547. spectral_err("PDEV is NULL");
  548. return QDF_STATUS_E_FAILURE;
  549. }
  550. ps = (struct pdev_spectral *)
  551. qdf_mem_malloc(sizeof(struct pdev_spectral));
  552. if (!ps) {
  553. spectral_err("Failed to allocate pdev_spectral object");
  554. return QDF_STATUS_E_NOMEM;
  555. }
  556. sc = spectral_get_spectral_ctx_from_pdev(pdev);
  557. if (!sc) {
  558. spectral_err("Spectral context is NULL!");
  559. goto cleanup;
  560. }
  561. qdf_mem_zero(ps, sizeof(struct pdev_spectral));
  562. ps->psptrl_pdev = pdev;
  563. spectral_register_cfg80211_handlers(pdev);
  564. if (sc->sptrlc_pdev_spectral_init) {
  565. target_handle = sc->sptrlc_pdev_spectral_init(pdev);
  566. if (!target_handle) {
  567. spectral_err("Spectral lmac object is NULL!");
  568. goto cleanup;
  569. }
  570. ps->psptrl_target_handle = target_handle;
  571. }
  572. wlan_objmgr_pdev_component_obj_attach(pdev, WLAN_UMAC_COMP_SPECTRAL,
  573. (void *)ps, QDF_STATUS_SUCCESS);
  574. return QDF_STATUS_SUCCESS;
  575. cleanup:
  576. qdf_mem_free(ps);
  577. return QDF_STATUS_E_FAILURE;
  578. }
  579. QDF_STATUS
  580. wlan_spectral_pdev_obj_destroy_handler(struct wlan_objmgr_pdev *pdev,
  581. void *arg)
  582. {
  583. struct pdev_spectral *ps = NULL;
  584. struct spectral_context *sc = NULL;
  585. if (!pdev) {
  586. spectral_err("PDEV is NULL");
  587. return QDF_STATUS_E_FAILURE;
  588. }
  589. sc = spectral_get_spectral_ctx_from_pdev(pdev);
  590. if (!sc) {
  591. spectral_err("Spectral context is NULL!");
  592. return QDF_STATUS_E_FAILURE;
  593. }
  594. ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
  595. WLAN_UMAC_COMP_SPECTRAL);
  596. if (ps) {
  597. if (sc->sptrlc_pdev_spectral_deinit)
  598. sc->sptrlc_pdev_spectral_deinit(pdev);
  599. ps->psptrl_target_handle = NULL;
  600. wlan_objmgr_pdev_component_obj_detach(pdev,
  601. WLAN_UMAC_COMP_SPECTRAL,
  602. (void *)ps);
  603. qdf_mem_free(ps);
  604. }
  605. return QDF_STATUS_SUCCESS;
  606. }