spectral_common.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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 CONFIG_WIN
  24. #include "spectral_da_api_i.h"
  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_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  57. if (!vdev) {
  58. spectral_warn("Unable to get first vdev of pdev");
  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!");
  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!");
  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. spectral_err("Invalid Spectral Chainmask - Inactive Rx antenna chain cannot be an active spectral chain");
  304. error = -EINVAL;
  305. break;
  306. } else if (sc->sptrlc_set_spectral_config(
  307. pdev,
  308. SPECTRAL_PARAM_CHN_MASK,
  309. sp_in->ss_chn_mask)) {
  310. error = -EINVAL;
  311. }
  312. }
  313. }
  314. break;
  315. case SPECTRAL_GET_CONFIG:
  316. {
  317. if (!outdata || !outsize ||
  318. (*outsize < sizeof(struct spectral_config))) {
  319. error = -EINVAL;
  320. break;
  321. }
  322. *outsize = sizeof(struct spectral_config);
  323. sc->sptrlc_get_spectral_config(pdev, &sp_out);
  324. spectralparams = (struct spectral_config *)outdata;
  325. spectralparams->ss_fft_period = sp_out.ss_fft_period;
  326. spectralparams->ss_period = sp_out.ss_period;
  327. spectralparams->ss_count = sp_out.ss_count;
  328. spectralparams->ss_short_report =
  329. sp_out.ss_short_report;
  330. spectralparams->ss_spectral_pri =
  331. sp_out.ss_spectral_pri;
  332. spectralparams->ss_fft_size = sp_out.ss_fft_size;
  333. spectralparams->ss_gc_ena = sp_out.ss_gc_ena;
  334. spectralparams->ss_restart_ena = sp_out.ss_restart_ena;
  335. spectralparams->ss_noise_floor_ref =
  336. sp_out.ss_noise_floor_ref;
  337. spectralparams->ss_init_delay = sp_out.ss_init_delay;
  338. spectralparams->ss_nb_tone_thr = sp_out.ss_nb_tone_thr;
  339. spectralparams->ss_str_bin_thr = sp_out.ss_str_bin_thr;
  340. spectralparams->ss_wb_rpt_mode = sp_out.ss_wb_rpt_mode;
  341. spectralparams->ss_rssi_rpt_mode =
  342. sp_out.ss_rssi_rpt_mode;
  343. spectralparams->ss_rssi_thr = sp_out.ss_rssi_thr;
  344. spectralparams->ss_pwr_format = sp_out.ss_pwr_format;
  345. spectralparams->ss_rpt_mode = sp_out.ss_rpt_mode;
  346. spectralparams->ss_bin_scale = sp_out.ss_bin_scale;
  347. spectralparams->ss_dbm_adj = sp_out.ss_dbm_adj;
  348. spectralparams->ss_chn_mask = sp_out.ss_chn_mask;
  349. }
  350. break;
  351. case SPECTRAL_IS_ACTIVE:
  352. {
  353. if (!outdata || !outsize ||
  354. *outsize < sizeof(uint32_t)) {
  355. error = -EINVAL;
  356. break;
  357. }
  358. *outsize = sizeof(uint32_t);
  359. *((uint32_t *)outdata) =
  360. (uint32_t)sc->sptrlc_is_spectral_active(pdev);
  361. }
  362. break;
  363. case SPECTRAL_IS_ENABLED:
  364. {
  365. if (!outdata || !outsize ||
  366. *outsize < sizeof(uint32_t)) {
  367. error = -EINVAL;
  368. break;
  369. }
  370. *outsize = sizeof(uint32_t);
  371. *((uint32_t *)outdata) =
  372. (uint32_t)sc->sptrlc_is_spectral_enabled(pdev);
  373. }
  374. break;
  375. case SPECTRAL_SET_DEBUG_LEVEL:
  376. {
  377. if (insize < sizeof(uint32_t) || !indata) {
  378. error = -EINVAL;
  379. break;
  380. }
  381. temp_debug = *(uint32_t *)indata;
  382. sc->sptrlc_set_debug_level(pdev, temp_debug);
  383. }
  384. break;
  385. case SPECTRAL_GET_DEBUG_LEVEL:
  386. {
  387. if (!outdata || !outsize ||
  388. *outsize < sizeof(uint32_t)) {
  389. error = -EINVAL;
  390. break;
  391. }
  392. *outsize = sizeof(uint32_t);
  393. *((uint32_t *)outdata) =
  394. (uint32_t)sc->sptrlc_get_debug_level(pdev);
  395. }
  396. break;
  397. case SPECTRAL_ACTIVATE_SCAN:
  398. {
  399. sc->sptrlc_start_spectral_scan(pdev);
  400. }
  401. break;
  402. case SPECTRAL_STOP_SCAN:
  403. {
  404. sc->sptrlc_stop_spectral_scan(pdev);
  405. }
  406. break;
  407. case SPECTRAL_GET_CAPABILITY_INFO:
  408. {
  409. if (!outdata || !outsize ||
  410. *outsize < sizeof(struct spectral_caps)) {
  411. error = -EINVAL;
  412. break;
  413. }
  414. *outsize = sizeof(struct spectral_caps);
  415. sc->sptrlc_get_spectral_capinfo(pdev, outdata);
  416. }
  417. break;
  418. case SPECTRAL_GET_DIAG_STATS:
  419. {
  420. if (!outdata || !outsize ||
  421. (*outsize < sizeof(struct spectral_diag_stats))) {
  422. error = -EINVAL;
  423. break;
  424. }
  425. *outsize = sizeof(struct spectral_diag_stats);
  426. sc->sptrlc_get_spectral_diagstats(pdev, outdata);
  427. }
  428. break;
  429. case SPECTRAL_GET_CHAN_WIDTH:
  430. {
  431. uint32_t chan_width;
  432. vdev = spectral_get_vdev(pdev);
  433. if (!vdev)
  434. return -ENOENT;
  435. chan_width = spectral_vdev_get_ch_width(vdev);
  436. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  437. if (!outdata || !outsize ||
  438. *outsize < sizeof(chan_width)) {
  439. error = -EINVAL;
  440. break;
  441. }
  442. *outsize = sizeof(chan_width);
  443. *((uint32_t *)outdata) = (uint32_t)chan_width;
  444. }
  445. break;
  446. default:
  447. error = -EINVAL;
  448. break;
  449. }
  450. bad:
  451. return error;
  452. }
  453. /**
  454. * spectral_ctx_deinit() - De-initialize function pointers from spectral context
  455. * @sc - Reference to spectral_context object
  456. *
  457. * Return: None
  458. */
  459. static void
  460. spectral_ctx_deinit(struct spectral_context *sc)
  461. {
  462. if (sc) {
  463. sc->sptrlc_ucfg_phyerr_config = NULL;
  464. sc->sptrlc_pdev_spectral_init = NULL;
  465. sc->sptrlc_pdev_spectral_deinit = NULL;
  466. sc->sptrlc_set_spectral_config = NULL;
  467. sc->sptrlc_get_spectral_config = NULL;
  468. sc->sptrlc_start_spectral_scan = NULL;
  469. sc->sptrlc_stop_spectral_scan = NULL;
  470. sc->sptrlc_is_spectral_active = NULL;
  471. sc->sptrlc_is_spectral_enabled = NULL;
  472. sc->sptrlc_set_debug_level = NULL;
  473. sc->sptrlc_get_debug_level = NULL;
  474. sc->sptrlc_get_spectral_capinfo = NULL;
  475. sc->sptrlc_get_spectral_diagstats = NULL;
  476. }
  477. }
  478. QDF_STATUS
  479. wlan_spectral_psoc_obj_create_handler(struct wlan_objmgr_psoc *psoc, void *arg)
  480. {
  481. struct spectral_context *sc = NULL;
  482. if (!psoc) {
  483. spectral_err("PSOC is NULL");
  484. return QDF_STATUS_E_FAILURE;
  485. }
  486. sc = (struct spectral_context *)
  487. qdf_mem_malloc(sizeof(struct spectral_context));
  488. if (!sc) {
  489. spectral_err("Failed to allocate spectral_ctx object");
  490. return QDF_STATUS_E_NOMEM;
  491. }
  492. qdf_mem_zero(sc, sizeof(struct spectral_context));
  493. sc->psoc_obj = psoc;
  494. if (wlan_objmgr_psoc_get_dev_type(psoc) == WLAN_DEV_OL)
  495. spectral_ctx_init_ol(sc);
  496. #ifdef CONFIG_WIN
  497. else if (wlan_objmgr_psoc_get_dev_type(psoc) == WLAN_DEV_DA)
  498. spectral_ctx_init_da(sc);
  499. #endif
  500. wlan_objmgr_psoc_component_obj_attach(psoc, WLAN_UMAC_COMP_SPECTRAL,
  501. (void *)sc, QDF_STATUS_SUCCESS);
  502. return QDF_STATUS_SUCCESS;
  503. }
  504. QDF_STATUS
  505. wlan_spectral_psoc_obj_destroy_handler(struct wlan_objmgr_psoc *psoc,
  506. void *arg)
  507. {
  508. struct spectral_context *sc = NULL;
  509. if (!psoc) {
  510. spectral_err("PSOC is NULL");
  511. return QDF_STATUS_E_FAILURE;
  512. }
  513. sc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
  514. WLAN_UMAC_COMP_SPECTRAL);
  515. if (sc) {
  516. wlan_objmgr_psoc_component_obj_detach(psoc,
  517. WLAN_UMAC_COMP_SPECTRAL,
  518. (void *)sc);
  519. /* Deinitilise function pointers from spectral context */
  520. spectral_ctx_deinit(sc);
  521. qdf_mem_free(sc);
  522. }
  523. return QDF_STATUS_SUCCESS;
  524. }
  525. QDF_STATUS
  526. wlan_spectral_pdev_obj_create_handler(struct wlan_objmgr_pdev *pdev, void *arg)
  527. {
  528. struct pdev_spectral *ps = NULL;
  529. struct spectral_context *sc = NULL;
  530. void *target_handle = NULL;
  531. if (!pdev) {
  532. spectral_err("PDEV is NULL");
  533. return QDF_STATUS_E_FAILURE;
  534. }
  535. ps = (struct pdev_spectral *)
  536. qdf_mem_malloc(sizeof(struct pdev_spectral));
  537. if (!ps) {
  538. spectral_err("Failed to allocate pdev_spectral object");
  539. return QDF_STATUS_E_NOMEM;
  540. }
  541. sc = spectral_get_spectral_ctx_from_pdev(pdev);
  542. if (!sc) {
  543. spectral_err("Spectral context is NULL!");
  544. goto cleanup;
  545. }
  546. qdf_mem_zero(ps, sizeof(struct pdev_spectral));
  547. ps->psptrl_pdev = pdev;
  548. spectral_register_cfg80211_handlers(pdev);
  549. if (sc->sptrlc_pdev_spectral_init) {
  550. target_handle = sc->sptrlc_pdev_spectral_init(pdev);
  551. if (!target_handle) {
  552. spectral_err("Spectral lmac object is NULL!");
  553. goto cleanup;
  554. }
  555. ps->psptrl_target_handle = target_handle;
  556. }
  557. wlan_objmgr_pdev_component_obj_attach(pdev, WLAN_UMAC_COMP_SPECTRAL,
  558. (void *)ps, QDF_STATUS_SUCCESS);
  559. return QDF_STATUS_SUCCESS;
  560. cleanup:
  561. qdf_mem_free(ps);
  562. return QDF_STATUS_E_FAILURE;
  563. }
  564. QDF_STATUS
  565. wlan_spectral_pdev_obj_destroy_handler(struct wlan_objmgr_pdev *pdev,
  566. void *arg)
  567. {
  568. struct pdev_spectral *ps = NULL;
  569. struct spectral_context *sc = NULL;
  570. if (!pdev) {
  571. spectral_err("PDEV is NULL");
  572. return QDF_STATUS_E_FAILURE;
  573. }
  574. sc = spectral_get_spectral_ctx_from_pdev(pdev);
  575. if (!sc) {
  576. spectral_err("Spectral context is NULL!");
  577. return QDF_STATUS_E_FAILURE;
  578. }
  579. ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
  580. WLAN_UMAC_COMP_SPECTRAL);
  581. if (ps) {
  582. if (sc->sptrlc_pdev_spectral_deinit)
  583. sc->sptrlc_pdev_spectral_deinit(pdev);
  584. ps->psptrl_target_handle = NULL;
  585. wlan_objmgr_pdev_component_obj_detach(pdev,
  586. WLAN_UMAC_COMP_SPECTRAL,
  587. (void *)ps);
  588. qdf_mem_free(ps);
  589. }
  590. return QDF_STATUS_SUCCESS;
  591. }