spectral_common.c 17 KB

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